Skip to content

Commit

Permalink
[SandboxIR] Implement a few Instruction member functions (#109820)
Browse files Browse the repository at this point in the history
This patch implements a few sandboxir::Instruction predicate functions.
  • Loading branch information
vporpo authored Sep 24, 2024
1 parent 0907552 commit f404207
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions llvm/include/llvm/SandboxIR/SandboxIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,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<llvm::Instruction>(Val)->isTerminator();
}
bool isUnaryOp() const { return cast<llvm::Instruction>(Val)->isUnaryOp(); }
bool isBinaryOp() const { return cast<llvm::Instruction>(Val)->isBinaryOp(); }
bool isIntDivRem() const {
return cast<llvm::Instruction>(Val)->isIntDivRem();
}
bool isShift() const { return cast<llvm::Instruction>(Val)->isShift(); }
bool isCast() const { return cast<llvm::Instruction>(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.
Expand Down
13 changes: 13 additions & 0 deletions llvm/unittests/SandboxIR/SandboxIRTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -1861,6 +1862,18 @@ define void @foo(i8 %v1, ptr %ptr) {

for (auto &LLVMI : *LLVMBB1) {
auto &I = cast<sandboxir::Instruction>(*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().
Expand Down

0 comments on commit f404207

Please sign in to comment.