File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -1643,6 +1643,14 @@ class Instruction : public sandboxir::User {
1643
1643
void moveAfter (Instruction *After) {
1644
1644
moveBefore (*After->getParent (), std::next (After->getIterator ()));
1645
1645
}
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
+ }
1646
1654
// / \Returns the BasicBlock containing this Instruction, or null if it is
1647
1655
// / detached.
1648
1656
BasicBlock *getParent () const ;
Original file line number Diff line number Diff line change @@ -1473,6 +1473,10 @@ define void @foo(i8 %v1) {
1473
1473
EXPECT_EQ (I0->getNextNode (), I1);
1474
1474
EXPECT_EQ (I1->getPrevNode (), I0);
1475
1475
1476
+ // Check comesBefore(I).
1477
+ EXPECT_TRUE (I0->comesBefore (I1));
1478
+ EXPECT_FALSE (I1->comesBefore (I0));
1479
+
1476
1480
// Check moveBefore(BB, It).
1477
1481
I1->moveBefore (*BB, BB->begin ());
1478
1482
EXPECT_EQ (I1->getPrevNode (), nullptr );
You can’t perform that action at this time.
0 commit comments