Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/include/llvm/SandboxIR/SandboxIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,14 @@ class Instruction : public sandboxir::User {
void moveAfter(Instruction *After) {
moveBefore(*After->getParent(), std::next(After->getIterator()));
}
// TODO: This currently relies on LLVM IR Instruction::comesBefore which is
// can be linear-time.
/// Given an instruction Other in the same basic block as this instruction,
/// return true if this instruction comes before Other.
bool comesBefore(const Instruction *Other) const {
return cast<llvm::Instruction>(Val)->comesBefore(
cast<llvm::Instruction>(Other->Val));
}
/// \Returns the BasicBlock containing this Instruction, or null if it is
/// detached.
BasicBlock *getParent() const;
Expand Down
4 changes: 4 additions & 0 deletions llvm/unittests/SandboxIR/SandboxIRTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,10 @@ define void @foo(i8 %v1) {
EXPECT_EQ(I0->getNextNode(), I1);
EXPECT_EQ(I1->getPrevNode(), I0);

// Check comesBefore(I).
EXPECT_TRUE(I0->comesBefore(I1));
EXPECT_FALSE(I1->comesBefore(I0));

// Check moveBefore(BB, It).
I1->moveBefore(*BB, BB->begin());
EXPECT_EQ(I1->getPrevNode(), nullptr);
Expand Down
Loading