From 556720d293fc2f9338aae3342d9a4662489114ba Mon Sep 17 00:00:00 2001 From: Vasileios Porpodas Date: Tue, 24 Sep 2024 08:48:02 -0700 Subject: [PATCH] [SandboxIR] Implement a few Instruction member functions This patch implements a few sandboxir::Instruction predicate functions. --- llvm/include/llvm/SandboxIR/SandboxIR.h | 16 ++++++++++++++++ llvm/unittests/SandboxIR/SandboxIRTest.cpp | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h index 84c32aeb0451f..f81917bd50797 100644 --- a/llvm/include/llvm/SandboxIR/SandboxIR.h +++ b/llvm/include/llvm/SandboxIR/SandboxIR.h @@ -1931,6 +1931,22 @@ class Instruction : public sandboxir::User { /// \Returns this Instruction's opcode. Note that SandboxIR has its own opcode /// state to allow for new SandboxIR-specific instructions. Opcode getOpcode() const { return Opc; } + + // TODO: Missing function getOpcodeName(). + + bool isTerminator() const { + return cast(Val)->isTerminator(); + } + bool isUnaryOp() const { return cast(Val)->isUnaryOp(); } + bool isBinaryOp() const { return cast(Val)->isBinaryOp(); } + bool isIntDivRem() const { + return cast(Val)->isIntDivRem(); + } + bool isShift() const { return cast(Val)->isShift(); } + bool isCast() const { return cast(Val)->isCast(); } + + // TODO: More missing functions + /// Detach this from its parent BasicBlock without deleting it. void removeFromParent(); /// Detach this Value from its parent and delete it. diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp index 1fcc9cbea152c..42df09609b675 100644 --- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp +++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp @@ -1769,6 +1769,7 @@ define void @foo(i8 %v1, ptr %ptr) { store volatile i8 %ld0, ptr %ptr %atomicrmw = atomicrmw add ptr %ptr, i8 %v1 acquire %udiv = udiv i8 %ld0, %v1 + %urem = urem i8 %ld0, %v1 call void @foo() ret void } @@ -1861,6 +1862,18 @@ define void @foo(i8 %v1, ptr %ptr) { for (auto &LLVMI : *LLVMBB1) { auto &I = cast(*Ctx.getValue(&LLVMI)); + // Check isTerminator(). + EXPECT_EQ(LLVMI.isTerminator(), I.isTerminator()); + // Check isUnaryOp(). + EXPECT_EQ(LLVMI.isUnaryOp(), I.isUnaryOp()); + // Check isBinaryOp(). + EXPECT_EQ(LLVMI.isBinaryOp(), I.isBinaryOp()); + // Check isIntDivRem(). + EXPECT_EQ(LLVMI.isIntDivRem(), I.isIntDivRem()); + // Check isShift(). + EXPECT_EQ(LLVMI.isShift(), I.isShift()); + // Check isCast(). + EXPECT_EQ(LLVMI.isCast(), I.isCast()); // Check isAssociative(). EXPECT_EQ(LLVMI.isAssociative(), I.isAssociative()); // Check isCommutative().