Skip to content

Commit f404207

Browse files
authored
[SandboxIR] Implement a few Instruction member functions (#109820)
This patch implements a few sandboxir::Instruction predicate functions.
1 parent 0907552 commit f404207

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,22 @@ class Instruction : public sandboxir::User {
19351935
/// \Returns this Instruction's opcode. Note that SandboxIR has its own opcode
19361936
/// state to allow for new SandboxIR-specific instructions.
19371937
Opcode getOpcode() const { return Opc; }
1938+
1939+
// TODO: Missing function getOpcodeName().
1940+
1941+
bool isTerminator() const {
1942+
return cast<llvm::Instruction>(Val)->isTerminator();
1943+
}
1944+
bool isUnaryOp() const { return cast<llvm::Instruction>(Val)->isUnaryOp(); }
1945+
bool isBinaryOp() const { return cast<llvm::Instruction>(Val)->isBinaryOp(); }
1946+
bool isIntDivRem() const {
1947+
return cast<llvm::Instruction>(Val)->isIntDivRem();
1948+
}
1949+
bool isShift() const { return cast<llvm::Instruction>(Val)->isShift(); }
1950+
bool isCast() const { return cast<llvm::Instruction>(Val)->isCast(); }
1951+
1952+
// TODO: More missing functions
1953+
19381954
/// Detach this from its parent BasicBlock without deleting it.
19391955
void removeFromParent();
19401956
/// Detach this Value from its parent and delete it.

llvm/unittests/SandboxIR/SandboxIRTest.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,7 @@ define void @foo(i8 %v1, ptr %ptr) {
17691769
store volatile i8 %ld0, ptr %ptr
17701770
%atomicrmw = atomicrmw add ptr %ptr, i8 %v1 acquire
17711771
%udiv = udiv i8 %ld0, %v1
1772+
%urem = urem i8 %ld0, %v1
17721773
call void @foo()
17731774
ret void
17741775
}
@@ -1861,6 +1862,18 @@ define void @foo(i8 %v1, ptr %ptr) {
18611862

18621863
for (auto &LLVMI : *LLVMBB1) {
18631864
auto &I = cast<sandboxir::Instruction>(*Ctx.getValue(&LLVMI));
1865+
// Check isTerminator().
1866+
EXPECT_EQ(LLVMI.isTerminator(), I.isTerminator());
1867+
// Check isUnaryOp().
1868+
EXPECT_EQ(LLVMI.isUnaryOp(), I.isUnaryOp());
1869+
// Check isBinaryOp().
1870+
EXPECT_EQ(LLVMI.isBinaryOp(), I.isBinaryOp());
1871+
// Check isIntDivRem().
1872+
EXPECT_EQ(LLVMI.isIntDivRem(), I.isIntDivRem());
1873+
// Check isShift().
1874+
EXPECT_EQ(LLVMI.isShift(), I.isShift());
1875+
// Check isCast().
1876+
EXPECT_EQ(LLVMI.isCast(), I.isCast());
18641877
// Check isAssociative().
18651878
EXPECT_EQ(LLVMI.isAssociative(), I.isAssociative());
18661879
// Check isCommutative().

0 commit comments

Comments
 (0)