diff options
-rw-r--r-- | include/llvm/IR/Instruction.h | 5 | ||||
-rw-r--r-- | lib/IR/Instruction.cpp | 9 | ||||
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 6 |
3 files changed, 15 insertions, 5 deletions
diff --git a/include/llvm/IR/Instruction.h b/include/llvm/IR/Instruction.h index df4f8df78b1..bd2e0fe2c96 100644 --- a/include/llvm/IR/Instruction.h +++ b/include/llvm/IR/Instruction.h @@ -94,6 +94,11 @@ public: /// the basic block that MovePos lives in, right before MovePos. void moveBefore(Instruction *MovePos); + /// Unlink this instruction and insert into BB before I. + /// + /// \pre I is a valid iterator into BB. + void moveBefore(BasicBlock &BB, SymbolTableList<Instruction>::iterator I); + //===--------------------------------------------------------------------===// // Subclass classification. //===--------------------------------------------------------------------===// diff --git a/lib/IR/Instruction.cpp b/lib/IR/Instruction.cpp index ed08f85c60b..cfddbf78f0c 100644 --- a/lib/IR/Instruction.cpp +++ b/lib/IR/Instruction.cpp @@ -92,8 +92,13 @@ void Instruction::insertAfter(Instruction *InsertPos) { /// Unlink this instruction from its current basic block and insert it into the /// basic block that MovePos lives in, right before MovePos. void Instruction::moveBefore(Instruction *MovePos) { - MovePos->getParent()->getInstList().splice( - MovePos->getIterator(), getParent()->getInstList(), getIterator()); + moveBefore(*MovePos->getParent(), MovePos->getIterator()); +} + +void Instruction::moveBefore(BasicBlock &BB, + SymbolTableList<Instruction>::iterator I) { + assert(I == BB.end() || I->getParent() == &BB); + BB.getInstList().splice(I, getParent()->getInstList(), getIterator()); } void Instruction::setHasNoUnsignedWrap(bool b) { diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index b014747cbc1..a11bef5d784 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -2058,7 +2058,7 @@ void IndVarSimplify::sinkUnusedInvariants(Loop *L) { BasicBlock *Preheader = L->getLoopPreheader(); if (!Preheader) return; - Instruction *InsertPt = &*ExitBlock->getFirstInsertionPt(); + BasicBlock::iterator InsertPt = ExitBlock->getFirstInsertionPt(); BasicBlock::iterator I(Preheader->getTerminator()); while (I != Preheader->begin()) { --I; @@ -2127,9 +2127,9 @@ void IndVarSimplify::sinkUnusedInvariants(Loop *L) { Done = true; } - ToMove->moveBefore(InsertPt); + ToMove->moveBefore(*ExitBlock, InsertPt); if (Done) break; - InsertPt = ToMove; + InsertPt = ToMove->getIterator(); } } |