Skip to content

Commit 0c672dd

Browse files
committed
[SandboxIR] Implement missng Instruction::comesBefore()
1 parent 39f2d2f commit 0c672dd

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,13 @@ class Instruction : public sandboxir::User {
15581558
void moveAfter(Instruction *After) {
15591559
moveBefore(*After->getParent(), std::next(After->getIterator()));
15601560
}
1561+
// TODO: This currently relies on LLVM IR Instruction::comesBefore which is
1562+
// can be linear-time.
1563+
/// Given an instruction Other in the same basic block as this instruction,
1564+
/// return true if this instruction comes before Other.
1565+
bool comesBefore(const Instruction *Other) const {
1566+
return cast<Instruction>(Val)->comesBefore(Other);
1567+
}
15611568
/// \Returns the BasicBlock containing this Instruction, or null if it is
15621569
/// detached.
15631570
BasicBlock *getParent() const;

llvm/unittests/SandboxIR/SandboxIRTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,10 @@ define void @foo(i8 %v1) {
13661366
EXPECT_EQ(I0->getNextNode(), I1);
13671367
EXPECT_EQ(I1->getPrevNode(), I0);
13681368

1369+
// Check comesBefore(I).
1370+
EXPECT_TRUE(I0->comesBefore(I1));
1371+
EXPECT_FALSE(I1->comesBefore(I0));
1372+
13691373
// Check moveBefore(BB, It).
13701374
I1->moveBefore(*BB, BB->begin());
13711375
EXPECT_EQ(I1->getPrevNode(), nullptr);

0 commit comments

Comments
 (0)