Skip to content

Commit 6cbb245

Browse files
authored
[SandboxIR] Implement missng Instruction::comesBefore() (#108635)
1 parent c3fda44 commit 6cbb245

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,14 @@ class Instruction : public sandboxir::User {
16431643
void moveAfter(Instruction *After) {
16441644
moveBefore(*After->getParent(), std::next(After->getIterator()));
16451645
}
1646+
// TODO: This currently relies on LLVM IR Instruction::comesBefore which is
1647+
// can be linear-time.
1648+
/// Given an instruction Other in the same basic block as this instruction,
1649+
/// return true if this instruction comes before Other.
1650+
bool comesBefore(const Instruction *Other) const {
1651+
return cast<llvm::Instruction>(Val)->comesBefore(
1652+
cast<llvm::Instruction>(Other->Val));
1653+
}
16461654
/// \Returns the BasicBlock containing this Instruction, or null if it is
16471655
/// detached.
16481656
BasicBlock *getParent() const;

llvm/unittests/SandboxIR/SandboxIRTest.cpp

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

1476+
// Check comesBefore(I).
1477+
EXPECT_TRUE(I0->comesBefore(I1));
1478+
EXPECT_FALSE(I1->comesBefore(I0));
1479+
14761480
// Check moveBefore(BB, It).
14771481
I1->moveBefore(*BB, BB->begin());
14781482
EXPECT_EQ(I1->getPrevNode(), nullptr);

0 commit comments

Comments
 (0)