As suggested in D37121, here's a wrapper for removeFromParent() + insertAfter(),
but implemented using moveBefore() for symmetry/efficiency.
Differential Revision: https://reviews.llvm.org/D37239
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312001
91177308-0d34-0410-b5e6-
96231b3b80d8
/// \pre I is a valid iterator into BB.
void moveBefore(BasicBlock &BB, SymbolTableList<Instruction>::iterator I);
+ /// Unlink this instruction from its current basic block and insert it into
+ /// the basic block that MovePos lives in, right after MovePos.
+ void moveAfter(Instruction *MovePos);
+
//===--------------------------------------------------------------------===//
// Subclass classification.
//===--------------------------------------------------------------------===//
auto LeadingFence = TLI->emitLeadingFence(Builder, I, Order);
auto TrailingFence = TLI->emitTrailingFence(Builder, I, Order);
- // The trailing fence is emitted before the instruction instead of after
- // because there is no easy way of setting Builder insertion point after
- // an instruction. So we must erase it from the BB, and insert it back
- // in the right place.
// We have a guard here because not every atomic operation generates a
// trailing fence.
- if (TrailingFence) {
- TrailingFence->removeFromParent();
- TrailingFence->insertAfter(I);
- }
+ if (TrailingFence)
+ TrailingFence->moveAfter(I);
return (LeadingFence || TrailingFence);
}
// Create the truncate now.
Value *Trunc = TPT.createTrunc(Ext, ExtOpnd->getType());
if (Instruction *ITrunc = dyn_cast<Instruction>(Trunc)) {
- ITrunc->removeFromParent();
// Insert it just after the definition.
- ITrunc->insertAfter(ExtOpnd);
+ ITrunc->moveAfter(ExtOpnd);
if (Truncs)
Truncs->push_back(ITrunc);
}
assert(LI && ExtFedByLoad && "Expect a valid load and extension");
TPT.commit();
// Move the extend into the same block as the load
- ExtFedByLoad->removeFromParent();
- ExtFedByLoad->insertAfter(LI);
+ ExtFedByLoad->moveAfter(LI);
// CGP does not check if the zext would be speculatively executed when moved
// to the same basic block as the load. Preserving its original location
// would pessimize the debugging experience, as well as negatively impact
"this?");
ToBePromoted->setOperand(U.getOperandNo(), NewVal);
}
- Transition->removeFromParent();
- Transition->insertAfter(ToBePromoted);
+ Transition->moveAfter(ToBePromoted);
Transition->setOperand(getTransitionOriginalValueIdx(), ToBePromoted);
}
moveBefore(*MovePos->getParent(), MovePos->getIterator());
}
+void Instruction::moveAfter(Instruction *MovePos) {
+ moveBefore(*MovePos->getParent(), ++MovePos->getIterator());
+}
+
void Instruction::moveBefore(BasicBlock &BB,
SymbolTableList<Instruction>::iterator I) {
assert(I == BB.end() || I->getParent() == &BB);
cast<Instruction>(Builder.CreateExtractElement(
VectorizedRoot, Builder.getInt32(VecIdx++)));
I->setOperand(1, Extract);
- I->removeFromParent();
- I->insertAfter(Extract);
+ I->moveAfter(Extract);
InsertAfter = I;
}
}