[NFC][DebugInfo] Use iterator moveBefore at many call-sites (#123583)

As part of the "RemoveDIs" project, BasicBlock::iterator now carries a
debug-info bit that's needed when getFirstNonPHI and similar feed into
instruction insertion positions. Call-sites where that's necessary were
updated a year ago; but to ensure some type safety however, we'd like to
have all calls to moveBefore use iterators.

This patch adds a (guaranteed dereferenceable) iterator-taking
moveBefore, and changes a bunch of call-sites where it's obviously safe
to change to use it by just calling getIterator() on an instruction
pointer. A follow-up patch will contain less-obviously-safe changes.

We'll eventually deprecate and remove the instruction-pointer
insertBefore, but not before adding concise documentation of what
considerations are needed (very few).
This commit is contained in:
Jeremy Morse 2025-01-24 10:53:11 +00:00 committed by GitHub
parent e6030d3895
commit 8e70273509
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
89 changed files with 275 additions and 201 deletions

View File

@ -626,7 +626,7 @@ struct CallCoroDelete final : public EHScopeStack::Cleanup {
// Get back to the block we were originally and move coro.free there.
auto *InsertPt = SaveInsertBlock->getTerminator();
CoroFree->moveBefore(InsertPt);
CoroFree->moveBefore(InsertPt->getIterator());
CGF.Builder.SetInsertPoint(InsertPt);
// Add if (auto *mem = coro.free) Deallocate;

View File

@ -1858,7 +1858,7 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
"expected alloca or localrecover in parent LocalDeclMap");
RecoverCall = cast<llvm::CallInst>(ParentRecover->clone());
RecoverCall->setArgOperand(1, ParentFP);
RecoverCall->insertBefore(AllocaInsertPt);
RecoverCall->insertBefore(AllocaInsertPt->getIterator());
}
// Bitcast the variable, rename it, and insert it in the local decl map.

View File

@ -1332,7 +1332,7 @@ void CGOpenMPRuntime::setLocThreadIdInsertPt(CodeGenFunction &CGF,
CGF.Builder.GetInsertBlock());
} else {
Elem.ServiceInsertPt = new llvm::BitCastInst(Undef, CGF.Int32Ty, "svcpt");
Elem.ServiceInsertPt->insertAfter(CGF.AllocaInsertPt);
Elem.ServiceInsertPt->insertAfter(CGF.AllocaInsertPt->getIterator());
}
}

View File

@ -194,6 +194,7 @@ public:
// debug-info attachments.
friend void Instruction::insertBefore(BasicBlock::iterator InsertPos);
friend void Instruction::insertAfter(Instruction *InsertPos);
friend void Instruction::insertAfter(BasicBlock::iterator InsertPos);
friend void Instruction::insertBefore(BasicBlock &BB,
InstListType::iterator InsertPos);
friend void Instruction::moveBeforeImpl(BasicBlock &BB,

View File

@ -192,11 +192,19 @@ public:
DbgRecord *getNextNode() { return &*std::next(getIterator()); }
DbgRecord *getPrevNode() { return &*std::prev(getIterator()); }
// Some generic lambdas supporting intrinsic-based debug-info mean we need
// to support both iterator and instruction position based insertion.
void insertBefore(DbgRecord *InsertBefore);
void insertAfter(DbgRecord *InsertAfter);
void moveBefore(DbgRecord *MoveBefore);
void moveAfter(DbgRecord *MoveAfter);
void insertBefore(self_iterator InsertBefore);
void insertAfter(self_iterator InsertAfter);
void moveBefore(self_iterator MoveBefore);
void moveAfter(self_iterator MoveAfter);
DebugLoc getDebugLoc() const { return DbgLoc; }
void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); }

View File

@ -207,12 +207,19 @@ public:
/// Insert an unlinked instruction into a basic block immediately before
/// the specified instruction.
void insertBefore(Instruction *InsertPos);
/// Insert an unlinked instruction into a basic block immediately before
/// the specified position.
void insertBefore(InstListType::iterator InsertPos);
/// Insert an unlinked instruction into a basic block immediately after the
/// specified instruction.
void insertAfter(Instruction *InsertPos);
/// Insert an unlinked instruction into a basic block immediately after the
/// specified position.
void insertAfter(InstListType::iterator InsertPos);
/// Inserts an unlinked instruction into \p ParentBB at position \p It and
/// returns the iterator of the inserted instruction.
InstListType::iterator insertInto(BasicBlock *ParentBB,
@ -224,11 +231,15 @@ public:
/// the basic block that MovePos lives in, right before MovePos.
void moveBefore(Instruction *MovePos);
/// Unlink this instruction from its current basic block and insert it into
/// the basic block that MovePos lives in, right before MovePos.
void moveBefore(InstListType::iterator InsertPos);
/// Perform a \ref moveBefore operation, while signalling that the caller
/// intends to preserve the original ordering of instructions. This implicitly
/// means that any adjacent debug-info should move with this instruction.
/// This method is currently a no-op placeholder, but it will become meaningful
/// when the "RemoveDIs" project is enabled.
/// This method is currently a no-op placeholder, but it will become
/// meaningful when the "RemoveDIs" project is enabled.
void moveBeforePreserving(Instruction *MovePos);
private:
@ -242,13 +253,19 @@ public:
/// \pre I is a valid iterator into BB.
void moveBefore(BasicBlock &BB, InstListType::iterator I);
/// (See other overload for moveBeforePreserving).
void moveBeforePreserving(BasicBlock &BB, InstListType::iterator I);
/// Unlink this instruction from its current basic block and insert it into
/// the basic block that MovePos lives in, right before MovePos.
void moveBeforePreserving(InstListType::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);
/// Unlink this instruction from its current basic block and insert it into
/// the basic block that MovePos lives in, right after MovePos.
void moveAfter(InstListType::iterator MovePos);
/// See \ref moveBeforePreserving .
void moveAfterPreserving(Instruction *MovePos);

View File

@ -103,7 +103,7 @@ bool Loop::makeLoopInvariant(Instruction *I, bool &Changed,
return false;
// Hoist.
I->moveBefore(InsertPt);
I->moveBefore(InsertPt->getIterator());
if (MSSAU)
if (auto *MUD = MSSAU->getMemorySSA()->getMemoryAccess(I))
MSSAU->moveToPlace(MUD, InsertPt->getParent(),

View File

@ -1264,7 +1264,7 @@ simplifyRelocatesOffABase(GCRelocateInst *RelocatedBase,
if (auto *RI = dyn_cast<GCRelocateInst>(R))
if (RI->getStatepoint() == RelocatedBase->getStatepoint())
if (RI->getBasePtrIndex() == RelocatedBase->getBasePtrIndex()) {
RelocatedBase->moveBefore(RI);
RelocatedBase->moveBefore(RI->getIterator());
MadeChange = true;
break;
}
@ -2690,7 +2690,7 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, ModifyDT &ModifiedDT) {
ExtVal->getParent() == CI->getParent())
return false;
// Sink a zext feeding stlxr/stxr before it, so it can be folded into it.
ExtVal->moveBefore(CI);
ExtVal->moveBefore(CI->getIterator());
// Mark this instruction as "inserted by CGP", so that other
// optimizations don't touch it.
InsertedInsts.insert(ExtVal);
@ -3036,7 +3036,7 @@ bool CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB,
for (auto *CI : CallInsts) {
for (auto const *FakeUse : FakeUses) {
auto *ClonedInst = FakeUse->clone();
ClonedInst->insertBefore(CI);
ClonedInst->insertBefore(CI->getIterator());
}
}
BB->eraseFromParent();
@ -7552,9 +7552,9 @@ bool CodeGenPrepare::optimizeSelectInst(SelectInst *SI) {
// Sink expensive instructions into the conditional blocks to avoid executing
// them speculatively.
for (Instruction *I : TrueInstrs)
I->moveBefore(TrueBranch);
I->moveBefore(TrueBranch->getIterator());
for (Instruction *I : FalseInstrs)
I->moveBefore(FalseBranch);
I->moveBefore(FalseBranch->getIterator());
// If we did not create a new block for one of the 'true' or 'false' paths
// of the condition, it means that side of the branch goes to the end block
@ -7682,7 +7682,7 @@ bool CodeGenPrepare::tryToSinkFreeOperands(Instruction *I) {
NewInstructions[UI] = NI;
MaybeDead.insert(UI);
LLVM_DEBUG(dbgs() << "Sinking " << *UI << " to user " << *I << "\n");
NI->insertBefore(InsertPoint);
NI->insertBefore(InsertPoint->getIterator());
InsertPoint = NI;
InsertedInsts.insert(NI);
@ -7744,7 +7744,7 @@ bool CodeGenPrepare::optimizeSwitchType(SwitchInst *SI) {
}
auto *ExtInst = CastInst::Create(ExtType, Cond, NewType);
ExtInst->insertBefore(SI);
ExtInst->insertBefore(SI->getIterator());
ExtInst->setDebugLoc(SI->getDebugLoc());
SI->setCondition(ExtInst);
for (auto Case : SI->cases()) {
@ -8556,7 +8556,7 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI,
match(UI, m_Shr(m_Specific(X), m_SpecificInt(CmpC.logBase2())))) {
IRBuilder<> Builder(Branch);
if (UI->getParent() != Branch->getParent())
UI->moveBefore(Branch);
UI->moveBefore(Branch->getIterator());
UI->dropPoisonGeneratingFlags();
Value *NewCmp = Builder.CreateCmp(ICmpInst::ICMP_EQ, UI,
ConstantInt::get(UI->getType(), 0));
@ -8570,7 +8570,7 @@ static bool optimizeBranch(BranchInst *Branch, const TargetLowering &TLI,
match(UI, m_Sub(m_Specific(X), m_SpecificInt(CmpC))))) {
IRBuilder<> Builder(Branch);
if (UI->getParent() != Branch->getParent())
UI->moveBefore(Branch);
UI->moveBefore(Branch->getIterator());
UI->dropPoisonGeneratingFlags();
Value *NewCmp = Builder.CreateCmp(Cmp->getPredicate(), UI,
ConstantInt::get(UI->getType(), 0));
@ -8890,21 +8890,21 @@ bool CodeGenPrepare::fixupDbgVariableRecord(DbgVariableRecord &DVR) {
return AnyChange;
}
static void DbgInserterHelper(DbgValueInst *DVI, Instruction *VI) {
static void DbgInserterHelper(DbgValueInst *DVI, BasicBlock::iterator VI) {
DVI->removeFromParent();
if (isa<PHINode>(VI))
DVI->insertBefore(&*VI->getParent()->getFirstInsertionPt());
DVI->insertBefore(VI->getParent()->getFirstInsertionPt());
else
DVI->insertAfter(VI);
}
static void DbgInserterHelper(DbgVariableRecord *DVR, Instruction *VI) {
static void DbgInserterHelper(DbgVariableRecord *DVR, BasicBlock::iterator VI) {
DVR->removeFromParent();
BasicBlock *VIBB = VI->getParent();
if (isa<PHINode>(VI))
VIBB->insertDbgRecordBefore(DVR, VIBB->getFirstInsertionPt());
else
VIBB->insertDbgRecordAfter(DVR, VI);
VIBB->insertDbgRecordAfter(DVR, &*VI);
}
// A llvm.dbg.value may be using a value before its definition, due to
@ -8954,7 +8954,7 @@ bool CodeGenPrepare::placeDbgValues(Function &F) {
LLVM_DEBUG(dbgs() << "Moving Debug Value before :\n"
<< *DbgItem << ' ' << *VI);
DbgInserterHelper(DbgItem, VI);
DbgInserterHelper(DbgItem, VI->getIterator());
MadeChange = true;
++NumDbgValueMoved;
}
@ -8997,7 +8997,7 @@ bool CodeGenPrepare::placePseudoProbes(Function &F) {
I++;
while (I != Block.end()) {
if (auto *II = dyn_cast<PseudoProbeInst>(I++)) {
II->moveBefore(&*FirstInst);
II->moveBefore(FirstInst);
MadeChange = true;
}
}
@ -9105,7 +9105,7 @@ bool CodeGenPrepare::splitBranchCondition(Function &F, ModifyDT &ModifiedDT) {
auto *Br2 = IRBuilder<>(TmpBB).CreateCondBr(Cond2, TBB, FBB);
if (auto *I = dyn_cast<Instruction>(Cond2)) {
I->removeFromParent();
I->insertBefore(Br2);
I->insertBefore(Br2->getIterator());
}
// Update PHI nodes in both successors. The original BB needs to be

View File

@ -512,7 +512,7 @@ static Value *getTrueOrFalseValue(
CBO->setOperand(OtherIdx,
isTrue ? OptSelects[IV].first : OptSelects[IV].second);
}
CBO->insertBefore(B->getTerminator());
CBO->insertBefore(B->getTerminator()->getIterator());
return CBO;
}
@ -637,7 +637,7 @@ void SelectOptimizeImpl::convertProfitableSIGroups(SelectGroups &ProfSIGroups) {
}
auto InsertionPoint = EndBlock->getFirstInsertionPt();
for (auto *DI : SinkInstrs)
DI->moveBeforePreserving(&*InsertionPoint);
DI->moveBeforePreserving(InsertionPoint);
// Duplicate implementation for DbgRecords, the non-instruction debug-info
// format. Helper lambda for moving DbgRecords to the end block.
@ -675,7 +675,7 @@ void SelectOptimizeImpl::convertProfitableSIGroups(SelectGroups &ProfSIGroups) {
TrueBranch = BranchInst::Create(EndBlock, TrueBlock);
TrueBranch->setDebugLoc(LastSI.getI()->getDebugLoc());
for (Instruction *TrueInst : TrueSlicesInterleaved)
TrueInst->moveBefore(TrueBranch);
TrueInst->moveBefore(TrueBranch->getIterator());
}
if (!FalseSlicesInterleaved.empty() || HasSelectLike(ASI, false)) {
FalseBlock =
@ -684,7 +684,7 @@ void SelectOptimizeImpl::convertProfitableSIGroups(SelectGroups &ProfSIGroups) {
FalseBranch = BranchInst::Create(EndBlock, FalseBlock);
FalseBranch->setDebugLoc(LastSI.getI()->getDebugLoc());
for (Instruction *FalseInst : FalseSlicesInterleaved)
FalseInst->moveBefore(FalseBranch);
FalseInst->moveBefore(FalseBranch->getIterator());
}
// If there was nothing to sink, then arbitrarily choose the 'false' side
// for a new input value to the PHI.

View File

@ -368,7 +368,7 @@ void SjLjEHPrepareImpl::lowerAcrossUnwindEdges(Function &F,
DemotePHIToStack(PN);
// Move the landingpad instruction back to the top of the landing pad block.
LPI->moveBefore(&UnwindBlock->front());
LPI->moveBefore(UnwindBlock->begin());
}
}
@ -478,7 +478,7 @@ bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
continue;
}
Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp");
StackAddr->insertAfter(&I);
StackAddr->insertAfter(I.getIterator());
new StoreInst(StackAddr, StackPtr, true,
std::next(StackAddr->getIterator()));
}

View File

@ -937,7 +937,8 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
// If From is before wo, its possible that there is a use of From between
// them.
if (From->comesBefore(To))
const_cast<AllocaInst*>(To)->moveBefore(const_cast<AllocaInst*>(From));
const_cast<AllocaInst *>(To)->moveBefore(
const_cast<AllocaInst *>(From)->getIterator());
// AA might be used later for instruction scheduling, and we need it to be
// able to deduce the correct aliasing releationships between pointers
@ -948,7 +949,7 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
Instruction *Inst = const_cast<AllocaInst *>(To);
if (From->getType() != To->getType()) {
BitCastInst *Cast = new BitCastInst(Inst, From->getType());
Cast->insertAfter(Inst);
Cast->insertAfter(Inst->getIterator());
Inst = Cast;
}

View File

@ -436,7 +436,7 @@ void IRPromoter::ReplaceAllUsersOfWith(Value *From, Value *To) {
void IRPromoter::ExtendSources() {
IRBuilder<> Builder{Ctx};
auto InsertZExt = [&](Value *V, Instruction *InsertPt) {
auto InsertZExt = [&](Value *V, BasicBlock::iterator InsertPt) {
assert(V->getType() != ExtTy && "zext already extends to i32");
LLVM_DEBUG(dbgs() << "IR Promotion: Inserting ZExt for " << *V << "\n");
Builder.SetInsertPoint(InsertPt);
@ -448,7 +448,7 @@ void IRPromoter::ExtendSources() {
if (isa<Argument>(V))
I->moveBefore(InsertPt);
else
I->moveAfter(InsertPt);
I->moveAfter(&*InsertPt);
NewInsts.insert(I);
}
@ -460,10 +460,10 @@ void IRPromoter::ExtendSources() {
for (auto *V : Sources) {
LLVM_DEBUG(dbgs() << " - " << *V << "\n");
if (auto *I = dyn_cast<Instruction>(V))
InsertZExt(I, I);
InsertZExt(I, I->getIterator());
else if (auto *Arg = dyn_cast<Argument>(V)) {
BasicBlock &BB = Arg->getParent()->front();
InsertZExt(Arg, &*BB.getFirstInsertionPt());
InsertZExt(Arg, BB.getFirstInsertionPt());
} else {
llvm_unreachable("unhandled source that needs extending");
}
@ -552,7 +552,7 @@ void IRPromoter::TruncateSinks() {
Value *Arg = Call->getArgOperand(i);
Type *Ty = TruncTysMap[Call][i];
if (Instruction *Trunc = InsertTrunc(Arg, Ty)) {
Trunc->moveBefore(Call);
Trunc->moveBefore(Call->getIterator());
Call->setArgOperand(i, Trunc);
}
}
@ -563,7 +563,7 @@ void IRPromoter::TruncateSinks() {
if (auto *Switch = dyn_cast<SwitchInst>(I)) {
Type *Ty = TruncTysMap[Switch][0];
if (Instruction *Trunc = InsertTrunc(Switch->getCondition(), Ty)) {
Trunc->moveBefore(Switch);
Trunc->moveBefore(Switch->getIterator());
Switch->setCondition(Trunc);
}
continue;
@ -583,7 +583,7 @@ void IRPromoter::TruncateSinks() {
for (unsigned i = 0; i < I->getNumOperands(); ++i) {
Type *Ty = TruncTysMap[I][i];
if (Instruction *Trunc = InsertTrunc(I->getOperand(i), Ty)) {
Trunc->moveBefore(I);
Trunc->moveBefore(I->getIterator());
I->setOperand(i, Trunc);
}
}

View File

@ -1488,12 +1488,12 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createParallel(
// Add additional casts to enforce pointers in zero address space
TIDAddr = new AddrSpaceCastInst(
TIDAddrAlloca, PointerType ::get(M.getContext(), 0), "tid.addr.ascast");
TIDAddr->insertAfter(TIDAddrAlloca);
TIDAddr->insertAfter(TIDAddrAlloca->getIterator());
ToBeDeleted.push_back(TIDAddr);
ZeroAddr = new AddrSpaceCastInst(ZeroAddrAlloca,
PointerType ::get(M.getContext(), 0),
"zero.addr.ascast");
ZeroAddr->insertAfter(ZeroAddrAlloca);
ZeroAddr->insertAfter(ZeroAddrAlloca->getIterator());
ToBeDeleted.push_back(ZeroAddr);
}

View File

@ -660,7 +660,7 @@ void ShuffleBlockStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
Instruction *Terminator = BB.getTerminator();
// Then put instructions back.
for (Instruction *I : Insts) {
I->insertBefore(Terminator);
I->insertBefore(Terminator->getIterator());
}
}

View File

@ -1013,7 +1013,7 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
B.SetCurrentDebugLocation(DL);
auto *DVI = cast<DbgAssignIntrinsic>(B.CreateCall(AssignFn, Args));
DVI->insertAfter(LinkedInstr);
DVI->insertAfter(LinkedInstr->getIterator());
return DVI;
}

View File

@ -451,7 +451,7 @@ DbgVariableRecord::createDebugIntrinsic(Module *M,
DVI->setTailCall();
DVI->setDebugLoc(getDebugLoc());
if (InsertBefore)
DVI->insertBefore(InsertBefore);
DVI->insertBefore(InsertBefore->getIterator());
return DVI;
}
@ -467,7 +467,7 @@ DbgLabelRecord::createDebugIntrinsic(Module *M,
DbgLabel->setTailCall();
DbgLabel->setDebugLoc(getDebugLoc());
if (InsertBefore)
DbgLabel->insertBefore(InsertBefore);
DbgLabel->insertBefore(InsertBefore->getIterator());
return DbgLabel;
}
@ -548,6 +548,24 @@ void DbgRecord::insertAfter(DbgRecord *InsertAfter) {
"DbgMarker!");
InsertAfter->getMarker()->insertDbgRecordAfter(this, InsertAfter);
}
void DbgRecord::insertBefore(self_iterator InsertBefore) {
assert(!getMarker() &&
"Cannot insert a DbgRecord that is already has a DbgMarker!");
assert(InsertBefore->getMarker() &&
"Cannot insert a DbgRecord before a DbgRecord that does not have a "
"DbgMarker!");
InsertBefore->getMarker()->insertDbgRecord(this, &*InsertBefore);
}
void DbgRecord::insertAfter(self_iterator InsertAfter) {
assert(!getMarker() &&
"Cannot insert a DbgRecord that is already has a DbgMarker!");
assert(InsertAfter->getMarker() &&
"Cannot insert a DbgRecord after a DbgRecord that does not have a "
"DbgMarker!");
InsertAfter->getMarker()->insertDbgRecordAfter(this, &*InsertAfter);
}
void DbgRecord::moveBefore(DbgRecord *MoveBefore) {
assert(getMarker() &&
"Canot move a DbgRecord that does not currently have a DbgMarker!");
@ -561,6 +579,19 @@ void DbgRecord::moveAfter(DbgRecord *MoveAfter) {
insertAfter(MoveAfter);
}
void DbgRecord::moveBefore(self_iterator MoveBefore) {
assert(getMarker() &&
"Canot move a DbgRecord that does not currently have a DbgMarker!");
removeFromParent();
insertBefore(MoveBefore);
}
void DbgRecord::moveAfter(self_iterator MoveAfter) {
assert(getMarker() &&
"Canot move a DbgRecord that does not currently have a DbgMarker!");
removeFromParent();
insertAfter(MoveAfter);
}
///////////////////////////////////////////////////////////////////////////////
// An empty, global, DbgMarker for the purpose of describing empty ranges of

View File

@ -114,6 +114,12 @@ void Instruction::insertAfter(Instruction *InsertPos) {
DestParent->getInstList().insertAfter(InsertPos->getIterator(), this);
}
void Instruction::insertAfter(BasicBlock::iterator InsertPos) {
BasicBlock *DestParent = InsertPos->getParent();
DestParent->getInstList().insertAfter(InsertPos, this);
}
BasicBlock::iterator Instruction::insertInto(BasicBlock *ParentBB,
BasicBlock::iterator It) {
assert(getParent() == nullptr && "Expected detached instruction");
@ -170,10 +176,18 @@ void Instruction::moveBefore(Instruction *MovePos) {
moveBeforeImpl(*MovePos->getParent(), MovePos->getIterator(), false);
}
void Instruction::moveBefore(BasicBlock::iterator MovePos) {
moveBeforeImpl(*MovePos->getParent(), MovePos, false);
}
void Instruction::moveBeforePreserving(Instruction *MovePos) {
moveBeforeImpl(*MovePos->getParent(), MovePos->getIterator(), true);
}
void Instruction::moveBeforePreserving(BasicBlock::iterator MovePos) {
moveBeforeImpl(*MovePos->getParent(), MovePos, true);
}
void Instruction::moveAfter(Instruction *MovePos) {
auto NextIt = std::next(MovePos->getIterator());
// We want this instruction to be moved to before NextIt in the instruction

View File

@ -1204,7 +1204,7 @@ static std::optional<Instruction *> instCombineSVEDup(InstCombiner &IC,
auto *IdxTy = Type::getInt64Ty(II.getContext());
auto *Insert = InsertElementInst::Create(
II.getArgOperand(0), II.getArgOperand(2), ConstantInt::get(IdxTy, 0));
Insert->insertBefore(&II);
Insert->insertBefore(II.getIterator());
Insert->takeName(&II);
return IC.replaceInstUsesWith(II, Insert);
@ -1357,7 +1357,7 @@ static std::optional<Instruction *> instCombineSVELast(InstCombiner &IC,
// The intrinsic is extracting lane 0 so use an extract instead.
auto *IdxTy = Type::getInt64Ty(II.getContext());
auto *Extract = ExtractElementInst::Create(Vec, ConstantInt::get(IdxTy, 0));
Extract->insertBefore(&II);
Extract->insertBefore(II.getIterator());
Extract->takeName(&II);
return IC.replaceInstUsesWith(II, Extract);
}
@ -1393,7 +1393,7 @@ static std::optional<Instruction *> instCombineSVELast(InstCombiner &IC,
// The intrinsic is extracting a fixed lane so use an extract instead.
auto *IdxTy = Type::getInt64Ty(II.getContext());
auto *Extract = ExtractElementInst::Create(Vec, ConstantInt::get(IdxTy, Idx));
Extract->insertBefore(&II);
Extract->insertBefore(II.getIterator());
Extract->takeName(&II);
return IC.replaceInstUsesWith(II, Extract);
}

View File

@ -683,7 +683,7 @@ void AMDGPUAtomicOptimizerImpl::optimizeAtomic(Instruction &I,
// Record I's new position as the exit block.
PixelExitBB = I.getParent();
I.moveBefore(NonHelperTerminator);
I.moveBefore(NonHelperTerminator->getIterator());
B.SetInsertPoint(&I);
}

View File

@ -752,7 +752,7 @@ LoadInst* ARMParallelDSP::CreateWideLoad(MemInstList &Loads,
isa<PHINode>(Source) || isa<PHINode>(Sink))
return;
Source->moveBefore(Sink);
Source->moveBefore(Sink->getIterator());
for (auto &Op : Source->operands())
MoveBefore(Op, Source);
};

View File

@ -54,7 +54,7 @@ struct CastGEPCast {
unsigned AS = OuterCast->getDestAddressSpace();
auto *NewGEP = cast<GetElementPtrInst>(GEP->clone());
NewGEP->setName(GEP->getName());
NewGEP->insertAfter(OuterCast);
NewGEP->insertAfter(OuterCast->getIterator());
NewGEP->setOperand(0, InnerCast->getPointerOperand());
auto *GEPTy = cast<PointerType>(GEP->getType());
NewGEP->mutateType(changeAddressSpace(GEPTy, AS));

View File

@ -109,7 +109,7 @@ Instruction *BPFCoreSharedInfo::insertPassThrough(Module *M, BasicBlock *BB,
BPFCoreSharedInfo::SeqNum++);
auto *NewInst = CallInst::Create(Fn, {SeqNumVal, Input});
NewInst->insertBefore(Before);
NewInst->insertBefore(Before->getIterator());
return NewInst;
}
} // namespace llvm
@ -1115,16 +1115,16 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
// Generate a BitCast
auto *BCInst =
new BitCastInst(Base, PointerType::getUnqual(BB->getContext()));
BCInst->insertBefore(Call);
BCInst->insertBefore(Call->getIterator());
// Generate a GetElementPtr
auto *GEP = GetElementPtrInst::Create(Type::getInt8Ty(BB->getContext()),
BCInst, LDInst);
GEP->insertBefore(Call);
GEP->insertBefore(Call->getIterator());
// Generate a BitCast
auto *BCInst2 = new BitCastInst(GEP, Call->getType());
BCInst2->insertBefore(Call);
BCInst2->insertBefore(Call->getIterator());
// For the following code,
// Block0:

View File

@ -128,7 +128,7 @@ bool BPFAdjustOptImpl::adjustICmpToBuiltin() {
Function *Fn = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::bpf_compare, {Op0->getType(), ConstOp1->getType()});
auto *NewInst = CallInst::Create(Fn, {Opcode, Op0, ConstOp1});
NewInst->insertBefore(&I);
NewInst->insertBefore(I.getIterator());
Icmp->replaceAllUsesWith(NewInst);
Changed = true;
ToBeDeleted = Icmp;

View File

@ -161,7 +161,7 @@ bool BPFCheckAndAdjustIR::removeCompareBuiltin(Module &M) {
CmpInst::Predicate Opcode = (CmpInst::Predicate)OpVal;
auto *ICmp = new ICmpInst(Opcode, Arg1, Arg2);
ICmp->insertBefore(Call);
ICmp->insertBefore(Call->getIterator());
Call->replaceAllUsesWith(ICmp);
ToBeDeleted = Call;
@ -367,16 +367,16 @@ void BPFCheckAndAdjustIR::getAnalysisUsage(AnalysisUsage &AU) const {
static void unrollGEPLoad(CallInst *Call) {
auto [GEP, Load] = BPFPreserveStaticOffsetPass::reconstructLoad(Call);
GEP->insertBefore(Call);
Load->insertBefore(Call);
GEP->insertBefore(Call->getIterator());
Load->insertBefore(Call->getIterator());
Call->replaceAllUsesWith(Load);
Call->eraseFromParent();
}
static void unrollGEPStore(CallInst *Call) {
auto [GEP, Store] = BPFPreserveStaticOffsetPass::reconstructStore(Call);
GEP->insertBefore(Call);
Store->insertBefore(Call);
GEP->insertBefore(Call->getIterator());
Store->insertBefore(Call->getIterator());
Call->eraseFromParent();
}
@ -436,7 +436,7 @@ static Value *aspaceWrapValue(DenseMap<Value *, Value *> &Cache, Function *F,
Value *WrappedPtr = aspaceWrapValue(Cache, F, Ptr);
auto *GEPTy = cast<PointerType>(GEP->getType());
auto *NewGEP = GEP->clone();
NewGEP->insertAfter(GEP);
NewGEP->insertAfter(GEP->getIterator());
NewGEP->mutateType(PointerType::getUnqual(GEPTy->getContext()));
NewGEP->setOperand(GEP->getPointerOperandIndex(), WrappedPtr);
NewGEP->setName(GEP->getName());

View File

@ -421,12 +421,12 @@ static bool tryToReplaceWithGEPBuiltin(Instruction *LoadOrStoreTemplate,
Module *M = InsnToReplace->getModule();
if (auto *Load = dyn_cast<LoadInst>(LoadOrStoreTemplate)) {
Instruction *Replacement = makeGEPAndLoad(M, GEPChain, Load);
Replacement->insertBefore(InsnToReplace);
Replacement->insertBefore(InsnToReplace->getIterator());
InsnToReplace->replaceAllUsesWith(Replacement);
}
if (auto *Store = dyn_cast<StoreInst>(LoadOrStoreTemplate)) {
Instruction *Replacement = makeGEPAndStore(M, GEPChain, Store);
Replacement->insertBefore(InsnToReplace);
Replacement->insertBefore(InsnToReplace->getIterator());
}
return true;
}

View File

@ -543,7 +543,7 @@ void HexagonVectorLoopCarriedReuse::reuseValue() {
}
InstsInPreheader.push_back(InstInPreheader);
InstInPreheader->setName(Inst2Replace->getName() + ".hexagon.vlcr");
InstInPreheader->insertBefore(LoopPH->getTerminator());
InstInPreheader->insertBefore(LoopPH->getTerminator()->getIterator());
LLVM_DEBUG(dbgs() << "Added " << *InstInPreheader << " to "
<< LoopPH->getName() << "\n");
}

View File

@ -46,7 +46,7 @@ bool NVPTXAllocaHoisting::runOnFunction(Function &function) {
for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE;) {
AllocaInst *allocaInst = dyn_cast<AllocaInst>(BI++);
if (allocaInst && isa<ConstantInt>(allocaInst->getArraySize())) {
allocaInst->moveBefore(firstTerminatorInst);
allocaInst->moveBefore(firstTerminatorInst->getIterator());
functionModified = true;
}
}

View File

@ -92,14 +92,14 @@ bool NVPTXLowerAlloca::runOnFunction(Function &F) {
auto ASCastToLocalAS = new AddrSpaceCastInst(
allocaInst,
PointerType::get(ETy->getContext(), ADDRESS_SPACE_LOCAL), "");
ASCastToLocalAS->insertAfter(allocaInst);
ASCastToLocalAS->insertAfter(allocaInst->getIterator());
AllocaInLocalAS = ASCastToLocalAS;
}
auto AllocaInGenericAS = new AddrSpaceCastInst(
AllocaInLocalAS,
PointerType::get(ETy->getContext(), ADDRESS_SPACE_GENERIC), "");
AllocaInGenericAS->insertAfter(AllocaInLocalAS);
AllocaInGenericAS->insertAfter(AllocaInLocalAS->getIterator());
for (Use &AllocaUse : llvm::make_early_inc_range(allocaInst->uses())) {
// Check Load, Store, GEP, and BitCast Uses on alloca and make them

View File

@ -939,10 +939,10 @@ bool X86LowerAMXCast::optimizeAMXCastFromPhi(
BasicBlock::iterator Iter = Block->getTerminator()->getIterator();
Instruction *NewInst = Builder.CreateIntrinsic(
Intrinsic::x86_tilezero_internal, {}, {Row, Col});
NewInst->moveBefore(&*Iter);
NewInst->moveBefore(Iter);
NewInst = Builder.CreateIntrinsic(Intrinsic::x86_cast_tile_to_vector,
{IncValue->getType()}, {NewInst});
NewInst->moveBefore(&*Iter);
NewInst->moveBefore(Iter);
// Replace InValue with new Value.
OldPN->setIncomingValue(I, NewInst);
IncValue = NewInst;

View File

@ -1377,7 +1377,7 @@ static void rewritePHIsForCleanupPad(BasicBlock *CleanupPadBB,
auto *SetDispatchValuePN =
Builder.CreatePHI(SwitchType, pred_size(CleanupPadBB));
CleanupPad->removeFromParent();
CleanupPad->insertAfter(SetDispatchValuePN);
CleanupPad->insertAfter(SetDispatchValuePN->getIterator());
auto *SwitchOnDispatch = Builder.CreateSwitch(SetDispatchValuePN, UnreachBB,
pred_size(CleanupPadBB));
@ -1833,7 +1833,7 @@ static void sinkLifetimeStartMarkers(Function &F, coro::Shape &Shape,
if (Valid && Lifetimes.size() != 0) {
auto *NewLifetime = Lifetimes[0]->clone();
NewLifetime->replaceUsesOfWith(NewLifetime->getOperand(1), AI);
NewLifetime->insertBefore(DomBB->getTerminator());
NewLifetime->insertBefore(DomBB->getTerminator()->getIterator());
// All the outsided lifetime.start markers are no longer necessary.
for (Instruction *S : Lifetimes)

View File

@ -580,7 +580,7 @@ void sinkSpillUsesAfterCoroBegin(const DominatorTree &Dom,
Instruction *InsertPt = CoroBegin->getNextNode();
for (Instruction *Inst : InsertionList)
Inst->moveBefore(InsertPt);
Inst->moveBefore(InsertPt->getIterator());
}
BasicBlock::iterator getSpillInsertionPt(const coro::Shape &Shape, Value *Def,

View File

@ -6219,7 +6219,7 @@ struct AAValueSimplifyImpl : AAValueSimplify {
// TODO: Try to salvage debug information here.
CloneI->setDebugLoc(DebugLoc());
VMap[&I] = CloneI;
CloneI->insertBefore(CtxI);
CloneI->insertBefore(CtxI->getIterator());
RemapInstruction(CloneI, VMap);
return CloneI;
}
@ -12421,7 +12421,7 @@ struct AAIndirectCallInfoCallSite : public AAIndirectCallInfo {
CallInst *NewCall = nullptr;
if (isLegalToPromote(*CB, NewCallee)) {
auto *CBClone = cast<CallBase>(CB->clone());
CBClone->insertBefore(ThenTI);
CBClone->insertBefore(ThenTI->getIterator());
NewCall = &cast<CallInst>(promoteCall(*CBClone, NewCallee, &RetBC));
NumIndirectCallsPromoted++;
} else {
@ -12546,7 +12546,7 @@ static bool makeChange(Attributor &A, InstType *MemInst, const Use &U,
}
Instruction *CastInst = new AddrSpaceCastInst(OriginalValue, NewPtrTy);
CastInst->insertBefore(MemInst);
CastInst->insertBefore(MemInst->getIterator());
A.changeUseAfterManifest(const_cast<Use &>(U), *CastInst);
return true;
}

View File

@ -1864,7 +1864,7 @@ private:
if (!ReplVal)
return false;
assert(IP && "Expected insertion point!");
cast<Instruction>(ReplVal)->moveBefore(IP);
cast<Instruction>(ReplVal)->moveBefore(IP->getIterator());
}
// If we use a call as a replacement value we need to make sure the ident is
@ -4122,7 +4122,7 @@ struct AAKernelInfoFunction : AAKernelInfo {
LastEffect = &*IP;
}
for (auto &Reorder : Reorders)
Reorder.first->moveBefore(Reorder.second);
Reorder.first->moveBefore(Reorder.second->getIterator());
}
SmallVector<std::pair<Instruction *, Instruction *>, 4> GuardedRegions;

View File

@ -3259,7 +3259,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
if (auto *Replacement = buildAssumeFromKnowledge(
{RetainedKnowledge{Attribute::NonNull, 0, A}}, Next, &AC, &DT)) {
Replacement->insertBefore(Next);
Replacement->insertBefore(Next->getIterator());
AC.registerAssumption(Replacement);
return RemoveConditionFromAssume(II);
}
@ -3292,7 +3292,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
if (auto *Replacement =
buildAssumeFromKnowledge(RK, Next, &AC, &DT)) {
Replacement->insertAfter(II);
Replacement->insertAfter(II->getIterator());
AC.registerAssumption(Replacement);
}
return RemoveConditionFromAssume(II);
@ -3376,7 +3376,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
while (MoveI != NextInst) {
auto *Temp = MoveI;
MoveI = MoveI->getNextNonDebugInstruction();
Temp->moveBefore(II);
Temp->moveBefore(II->getIterator());
}
replaceOperand(*II, 0, Builder.CreateAnd(CurrCond, NextCond));
}

View File

@ -683,7 +683,7 @@ static Value *foldShiftedShift(BinaryOperator *InnerShift, unsigned OuterShAmt,
Value *And = Builder.CreateAnd(InnerShift->getOperand(0),
ConstantInt::get(ShType, Mask));
if (auto *AndI = dyn_cast<Instruction>(And)) {
AndI->moveBefore(InnerShift);
AndI->moveBefore(InnerShift->getIterator());
AndI->takeName(InnerShift);
}
return And;

View File

@ -747,7 +747,7 @@ static bool replaceExtractElements(InsertElementInst *InsElt,
// extract, so any subsequent extracts in the same basic block can use it.
// TODO: Insert before the earliest ExtractElementInst that is replaced.
if (ExtVecOpInst && !isa<PHINode>(ExtVecOpInst))
WideVec->insertAfter(ExtVecOpInst);
WideVec->insertAfter(ExtVecOpInst->getIterator());
else
IC.InsertNewInstWith(WideVec, ExtElt->getParent()->getFirstInsertionPt());

View File

@ -3517,7 +3517,7 @@ static Instruction *tryToMoveFreeBeforeNullTest(CallInst &FI,
for (Instruction &Instr : llvm::make_early_inc_range(*FreeInstrBB)) {
if (&Instr == FreeInstrBBTerminator)
break;
Instr.moveBeforePreserving(TI);
Instr.moveBeforePreserving(TI->getIterator());
}
assert(FreeInstrBB->size() == 1 &&
"Only the branch instruction should remain");
@ -4980,7 +4980,7 @@ void InstCombinerImpl::tryToSinkInstructionDbgValues(
// The clones are in reverse order of original appearance, reverse again to
// maintain the original order.
for (auto &DIIClone : llvm::reverse(DIIClones)) {
DIIClone->insertBefore(&*InsertPos);
DIIClone->insertBefore(InsertPos);
LLVM_DEBUG(dbgs() << "SINK: " << *DIIClone << '\n');
}
}

View File

@ -1468,7 +1468,7 @@ static void hoistValue(Value *V, Instruction *HoistPoint, Region *R,
for (Value *Op : I->operands()) {
hoistValue(Op, HoistPoint, R, HoistStopMap, HoistedSet, TrivialPHIs, DT);
}
I->moveBefore(HoistPoint);
I->moveBefore(HoistPoint->getIterator());
HoistedSet.insert(I);
CHR_DEBUG(dbgs() << "hoistValue " << *I << "\n");
}

View File

@ -775,7 +775,7 @@ void InstrLowerer::doSampling(Instruction *I) {
NewSamplingVarVal =
IncBuilder.CreateAdd(LoadSamplingVar, GetConstant(IncBuilder, 1));
SamplingVarIncr = IncBuilder.CreateStore(NewSamplingVarVal, SamplingVar);
I->moveBefore(ThenTerm);
I->moveBefore(ThenTerm->getIterator());
}
if (config.IsFastSampling)
@ -792,11 +792,11 @@ void InstrLowerer::doSampling(Instruction *I) {
// For the simple sampling, the counter update happens in sampling var reset.
if (config.IsSimpleSampling)
I->moveBefore(ThenTerm);
I->moveBefore(ThenTerm->getIterator());
IRBuilder<> ResetBuilder(ThenTerm);
ResetBuilder.CreateStore(GetConstant(ResetBuilder, 0), SamplingVar);
SamplingVarIncr->moveBefore(ElseTerm);
SamplingVarIncr->moveBefore(ElseTerm->getIterator());
}
bool InstrLowerer::lowerIntrinsics(Function *F) {

View File

@ -1110,7 +1110,7 @@ PHINode *NumericalStabilitySanitizer::maybeCreateShadowPhi(
// created. They will be populated in a final phase, once all shadow values
// have been created.
PHINode *Shadow = PHINode::Create(ExtendedVT, Phi.getNumIncomingValues());
Shadow->insertAfter(&Phi);
Shadow->insertAfter(Phi.getIterator());
return Shadow;
}

View File

@ -776,7 +776,7 @@ void ConstantHoistingPass::emitBaseConstants(Instruction *Base,
if (!ClonedCastInst) {
ClonedCastInst = CastInst->clone();
ClonedCastInst->setOperand(0, Mat);
ClonedCastInst->insertAfter(CastInst);
ClonedCastInst->insertAfter(CastInst->getIterator());
// Use the same debug location as the original cast instruction.
ClonedCastInst->setDebugLoc(CastInst->getDebugLoc());
LLVM_DEBUG(dbgs() << "Clone instruction: " << *CastInst << '\n'

View File

@ -1353,7 +1353,7 @@ static void generateReproducer(CmpInst *Cond, Module *M,
Instruction *Cloned = I->clone();
Old2New[I] = Cloned;
Old2New[I]->setName(I->getName());
Cloned->insertBefore(&*Builder.GetInsertPoint());
Cloned->insertBefore(Builder.GetInsertPoint());
Cloned->dropUnknownNonDebugMetadata();
Cloned->setDebugLoc({});
}

View File

@ -553,7 +553,7 @@ static void shortenAssignment(Instruction *Inst, Value *OriginalDest,
// Fragments overlap: insert a new dbg.assign for this dead part.
auto *NewAssign = static_cast<decltype(Assign)>(Assign->clone());
NewAssign->insertAfter(Assign);
NewAssign->insertAfter(Assign->getIterator());
NewAssign->setAssignId(GetDeadLink());
if (NewFragment)
SetDeadFragExpr(NewAssign, *NewFragment);

View File

@ -209,7 +209,7 @@ static bool optimizeDivRem(Function &F, const TargetTransformInfo &TTI,
// Note that we place it right next to the original expanded instruction,
// and letting further handling to move it if needed.
RealRem->setName(RemInst->getName() + ".recomposed");
RealRem->insertAfter(RemInst);
RealRem->insertAfter(RemInst->getIterator());
Instruction *OrigRemInst = RemInst;
// Update AssertingVH<> with new instruction so it doesn't assert.
RemInst = RealRem;
@ -296,10 +296,10 @@ static bool optimizeDivRem(Function &F, const TargetTransformInfo &TTI,
all_of(predecessors(DivBB),
[&](BasicBlock *BB) { return BB == RemBB || BB == PredBB; })) {
DivDominates = true;
DivInst->moveBefore(PredBB->getTerminator());
DivInst->moveBefore(PredBB->getTerminator()->getIterator());
Changed = true;
if (HasDivRemOp) {
RemInst->moveBefore(PredBB->getTerminator());
RemInst->moveBefore(PredBB->getTerminator()->getIterator());
continue;
}
} else
@ -365,10 +365,10 @@ static bool optimizeDivRem(Function &F, const TargetTransformInfo &TTI,
// but any code movement would be within the same block.
if (!DivDominates)
DivInst->moveBefore(RemInst);
Mul->insertAfter(RemInst);
DivInst->moveBefore(RemInst->getIterator());
Mul->insertAfter(RemInst->getIterator());
Mul->setDebugLoc(RemInst->getDebugLoc());
Sub->insertAfter(Mul);
Sub->insertAfter(Mul->getIterator());
Sub->setDebugLoc(RemInst->getDebugLoc());
// If DivInst has the exact flag, remove it. Otherwise this optimization

View File

@ -2890,7 +2890,7 @@ bool GVNPass::performScalarPREInsertion(Instruction *Instr, BasicBlock *Pred,
if (!success)
return false;
Instr->insertBefore(Pred->getTerminator());
Instr->insertBefore(Pred->getTerminator()->getIterator());
Instr->setName(Instr->getName() + ".pre");
Instr->setDebugLoc(Instr->getDebugLoc());

View File

@ -922,7 +922,7 @@ void GVNHoist::makeGepsAvailable(Instruction *Repl, BasicBlock *HoistPt,
}
// Copy Gep and replace its uses in Repl with ClonedGep.
ClonedGep->insertBefore(HoistPt->getTerminator());
ClonedGep->insertBefore(HoistPt->getTerminator()->getIterator());
// Conservatively discard any optimization hints, they may differ on the
// other paths.
@ -1108,7 +1108,7 @@ std::pair<unsigned, unsigned> GVNHoist::hoist(HoistingPointList &HPL) {
// Move the instruction at the end of HoistPt.
Instruction *Last = DestBB->getTerminator();
MD->removeInstruction(Repl);
Repl->moveBefore(Last);
Repl->moveBefore(Last->getIterator());
DFSNumber[Repl] = DFSNumber[Last]++;
}

View File

@ -619,7 +619,7 @@ static Value *operandWithNewAddressSpaceOrCreatePoison(
unsigned NewAS = I->second;
Type *NewPtrTy = getPtrOrVecOfPtrsWithNewAS(Operand->getType(), NewAS);
auto *NewI = new AddrSpaceCastInst(Operand, NewPtrTy);
NewI->insertBefore(Inst);
NewI->insertBefore(Inst->getIterator());
NewI->setDebugLoc(Inst->getDebugLoc());
return NewI;
}
@ -681,7 +681,7 @@ Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace(
// explicit.
Type *NewPtrTy = getPtrOrVecOfPtrsWithNewAS(I->getType(), AS);
auto *NewI = new AddrSpaceCastInst(I, NewPtrTy);
NewI->insertAfter(I);
NewI->insertAfter(I->getIterator());
NewI->setDebugLoc(I->getDebugLoc());
return NewI;
}
@ -833,7 +833,7 @@ Value *InferAddressSpacesImpl::cloneValueWithNewAddressSpace(
I, NewAddrSpace, ValueWithNewAddrSpace, PredicatedAS, PoisonUsesToFix);
if (Instruction *NewI = dyn_cast_or_null<Instruction>(NewV)) {
if (NewI->getParent() == nullptr) {
NewI->insertBefore(I);
NewI->insertBefore(I->getIterator());
NewI->takeName(I);
NewI->setDebugLoc(I->getDebugLoc());
}

View File

@ -933,14 +933,14 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
auto ReciprocalDivisor = BinaryOperator::CreateFDiv(One, Divisor);
ReciprocalDivisor->setFastMathFlags(I.getFastMathFlags());
SafetyInfo->insertInstructionTo(ReciprocalDivisor, I.getParent());
ReciprocalDivisor->insertBefore(&I);
ReciprocalDivisor->insertBefore(I.getIterator());
ReciprocalDivisor->setDebugLoc(I.getDebugLoc());
auto Product =
BinaryOperator::CreateFMul(I.getOperand(0), ReciprocalDivisor);
Product->setFastMathFlags(I.getFastMathFlags());
SafetyInfo->insertInstructionTo(Product, I.getParent());
Product->insertAfter(&I);
Product->insertAfter(I.getIterator());
Product->setDebugLoc(I.getDebugLoc());
I.replaceAllUsesWith(Product);
eraseInstruction(I, *SafetyInfo, MSSAU);

View File

@ -1662,7 +1662,7 @@ private:
if (SE.isSCEVable(PHI->getType()))
SE.forgetValue(PHI);
if (PHI->hasNUsesOrMore(1))
PHI->moveBefore(&*FC0.Header->getFirstInsertionPt());
PHI->moveBefore(FC0.Header->getFirstInsertionPt());
else
PHI->eraseFromParent();
}
@ -1947,7 +1947,7 @@ private:
if (SE.isSCEVable(PHI->getType()))
SE.forgetValue(PHI);
if (PHI->hasNUsesOrMore(1))
PHI->moveBefore(&*FC0.Header->getFirstInsertionPt());
PHI->moveBefore(FC0.Header->getFirstInsertionPt());
else
PHI->eraseFromParent();
}

View File

@ -1405,7 +1405,7 @@ bool LoopInterchangeTransform::transform() {
for (Instruction &I :
make_early_inc_range(make_range(InnerLoopPreHeader->begin(),
std::prev(InnerLoopPreHeader->end()))))
I.moveBeforePreserving(OuterLoopHeader->getTerminator());
I.moveBeforePreserving(OuterLoopHeader->getTerminator()->getIterator());
}
Transformed |= adjustLoopLinks();
@ -1440,7 +1440,7 @@ static void swapBBContents(BasicBlock *BB1, BasicBlock *BB2) {
// Move instructions from TempInstrs to BB2.
for (Instruction *I : TempInstrs)
I->insertBefore(BB2->getTerminator());
I->insertBefore(BB2->getTerminator()->getIterator());
}
// Update BI to jump to NewBB instead of OldBB. Records updates to the

View File

@ -252,7 +252,7 @@ static bool sinkInstruction(
// Clone I and replace its uses.
Instruction *IC = I.clone();
IC->setName(I.getName());
IC->insertBefore(&*N->getFirstInsertionPt());
IC->insertBefore(N->getFirstInsertionPt());
if (MSSAU && MSSAU->getMemorySSA()->getMemoryAccess(&I)) {
// Create a new MemoryAccess and let MemorySSA set its defining access.
@ -282,7 +282,7 @@ static bool sinkInstruction(
}
LLVM_DEBUG(dbgs() << "Sinking " << I << " To: " << MoveBB->getName() << '\n');
NumLoopSunk++;
I.moveBefore(&*MoveBB->getFirstInsertionPt());
I.moveBefore(MoveBB->getFirstInsertionPt());
if (MSSAU)
if (MemoryUseOrDef *OldMemAcc = cast_or_null<MemoryUseOrDef>(

View File

@ -2719,7 +2719,7 @@ LSRInstance::OptimizeLoopTermCond() {
// the exiting block branch, move it.
if (Cond->getNextNonDebugInstruction() != TermBr) {
if (Cond->hasOneUse()) {
Cond->moveBefore(TermBr);
Cond->moveBefore(TermBr->getIterator());
} else {
// Clone the terminating condition and insert into the loopend.
ICmpInst *OldCond = Cond;

View File

@ -1979,7 +1979,7 @@ public:
return DT->dominates(A, B);
});
for (Instruction *I : ToHoist)
I->moveBefore(MatMul);
I->moveBefore(MatMul->getIterator());
// Deal with lifetime.end calls that might be between Load0/Load1 and the
// store. To avoid introducing loads to dead objects (i.e. after the

View File

@ -611,7 +611,7 @@ bool MemCpyOptPass::moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI) {
// We made it, we need to lift.
for (auto *I : llvm::reverse(ToLift)) {
LLVM_DEBUG(dbgs() << "Lifting " << *I << " before " << *P << "\n");
I->moveBefore(P);
I->moveBefore(P->getIterator());
assert(MemInsertPoint && "Must have found insert point");
if (MemoryUseOrDef *MA = MSSA->getMemoryAccess(I)) {
MSSAU->moveAfter(MA, MemInsertPoint);
@ -1082,11 +1082,11 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpyLoad,
if (NeedMoveGEP) {
auto *GEP = dyn_cast<GetElementPtrInst>(cpyDest);
GEP->moveBefore(C);
GEP->moveBefore(C->getIterator());
}
if (SkippedLifetimeStart) {
SkippedLifetimeStart->moveBefore(C);
SkippedLifetimeStart->moveBefore(C->getIterator());
MSSAU->moveBefore(MSSA->getMemoryAccess(SkippedLifetimeStart),
MSSA->getMemoryAccess(C));
}

View File

@ -2800,7 +2800,7 @@ NewGVN::makePossiblePHIOfOps(Instruction *I,
Instruction *ValueOp = I->clone();
// Emit the temporal instruction in the predecessor basic block where the
// corresponding value is defined.
ValueOp->insertBefore(PredBB->getTerminator());
ValueOp->insertBefore(PredBB->getTerminator()->getIterator());
if (MemAccess)
TempToMemory.insert({ValueOp, MemAccess});
bool SafeForPHIOfOps = true;
@ -4012,7 +4012,7 @@ bool NewGVN::eliminateInstructions(Function &F) {
LLVM_DEBUG(dbgs() << "Inserting fully real phi of ops" << *Def
<< " into block "
<< getBlockName(getBlockForValue(Def)) << "\n");
PN->insertBefore(&DefBlock->front());
PN->insertBefore(DefBlock->begin());
Def = PN;
NumGVNPHIOfOpsEliminations++;
}

View File

@ -755,7 +755,7 @@ void ReassociatePass::RewriteExprTree(BinaryOperator *I,
if (ClearFlags)
replaceDbgUsesWithUndef(ExpressionChangedStart);
ExpressionChangedStart->moveBefore(I);
ExpressionChangedStart->moveBefore(I->getIterator());
ExpressionChangedStart =
cast<BinaryOperator>(*ExpressionChangedStart->user_begin());
} while (true);
@ -808,7 +808,7 @@ static Value *NegateValue(Value *V, Instruction *BI,
// assured that the neg instructions we just inserted dominate the
// instruction we are about to insert after them.
//
I->moveBefore(BI);
I->moveBefore(BI->getIterator());
I->setName(I->getName()+".neg");
// Add the intermediate negates to the redo list as processing them later

View File

@ -1115,7 +1115,7 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
};
Instruction *BaseInst = I->clone();
BaseInst->insertBefore(I);
BaseInst->insertBefore(I->getIterator());
BaseInst->setName(getMangledName(I));
// Add metadata marking this as a base value
BaseInst->setMetadata("is_base_value", MDNode::get(I->getContext(), {}));

View File

@ -1147,7 +1147,7 @@ bool SeparateConstOffsetFromGEP::splitGEP(GetElementPtrInst *GEP) {
// %new.gep = gep i8, %gep2, %offset
// ... %new.gep ...
Instruction *NewGEP = GEP->clone();
NewGEP->insertBefore(GEP);
NewGEP->insertBefore(GEP->getIterator());
Type *PtrIdxTy = DL->getIndexType(GEP->getType());
IRBuilder<> Builder(GEP);

View File

@ -2786,7 +2786,7 @@ static BranchInst *turnGuardIntoBranch(IntrinsicInst *GI, Loop &L,
if (MSSAU)
MSSAU->moveAllAfterSpliceBlocks(CheckBB, GuardedBlock, GI);
GI->moveBefore(DeoptBlockTerm);
GI->moveBefore(DeoptBlockTerm->getIterator());
GI->setArgOperand(0, ConstantInt::getFalse(GI->getContext()));
if (MSSAU) {

View File

@ -168,7 +168,7 @@ static bool SinkInstruction(Instruction *Inst,
SuccToSinkTo->printAsOperand(dbgs(), false); dbgs() << ")\n");
// Move the instruction.
Inst->moveBefore(&*SuccToSinkTo->getFirstInsertionPt());
Inst->moveBefore(SuccToSinkTo->getFirstInsertionPt());
return true;
}

View File

@ -328,7 +328,7 @@ bool SpeculativeExecutionPass::considerHoistingFromTo(
auto Current = I;
++I;
if (!NotHoisted.count(&*Current)) {
Current->moveBefore(ToBlock.getTerminator());
Current->moveBefore(ToBlock.getTerminator()->getIterator());
Current->dropLocation();
}
}

View File

@ -526,7 +526,7 @@ void TailRecursionEliminator::createTailRecurseLoopHeader(CallInst *CI) {
OEBI != E;)
if (AllocaInst *AI = dyn_cast<AllocaInst>(OEBI++))
if (isa<ConstantInt>(AI->getArraySize()))
AI->moveBefore(&*NEBI);
AI->moveBefore(NEBI);
// Now that we have created a new block, which jumps to the entry
// block, insert a PHI node for each argument of the function.
@ -784,7 +784,7 @@ void TailRecursionEliminator::cleanupAndFinalize() {
AccRecInstrNew->setName("accumulator.ret.tr");
AccRecInstrNew->setOperand(AccRecInstr->getOperand(0) == AccPN,
RI->getOperand(0));
AccRecInstrNew->insertBefore(RI);
AccRecInstrNew->insertBefore(RI->getIterator());
AccRecInstrNew->dropLocation();
RI->setOperand(0, AccRecInstrNew);
}
@ -813,7 +813,7 @@ void TailRecursionEliminator::cleanupAndFinalize() {
AccRecInstrNew->setName("accumulator.ret.tr");
AccRecInstrNew->setOperand(AccRecInstr->getOperand(0) == AccPN,
SI->getFalseValue());
AccRecInstrNew->insertBefore(SI);
AccRecInstrNew->insertBefore(SI->getIterator());
AccRecInstrNew->dropLocation();
SI->setFalseValue(AccRecInstrNew);
}

View File

@ -298,7 +298,7 @@ bool llvm::salvageKnowledge(Instruction *I, AssumptionCache *AC,
AssumeBuilderState Builder(I->getModule(), I, AC, DT);
Builder.addInstruction(I);
if (auto *Intr = Builder.build()) {
Intr->insertBefore(I);
Intr->insertBefore(I->getIterator());
Changed = true;
if (AC)
AC->registerAssumption(Intr);

View File

@ -886,7 +886,7 @@ BasicBlock *llvm::ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ,
if (LandingPadReplacement) {
auto *NewLP = OriginalPad->clone();
auto *Terminator = BranchInst::Create(Succ, NewBB);
NewLP->insertBefore(Terminator);
NewLP->insertBefore(Terminator->getIterator());
LandingPadReplacement->addIncoming(NewLP, NewBB);
} else {
Value *ParentPad = nullptr;

View File

@ -299,7 +299,7 @@ static CallBase &versionCallSiteWithCond(CallBase &CB, Value *Cond,
BasicBlock *ThenBlock = ThenTerm->getParent();
ThenBlock->setName("if.true.direct_targ");
CallBase *NewInst = cast<CallBase>(OrigInst->clone());
NewInst->insertBefore(ThenTerm);
NewInst->insertBefore(ThenTerm->getIterator());
// Place a clone of the optional bitcast after the new call site.
Value *NewRetVal = NewInst;
@ -309,7 +309,7 @@ static CallBase &versionCallSiteWithCond(CallBase &CB, Value *Cond,
"bitcast following musttail call must use the call");
auto NewBitCast = BitCast->clone();
NewBitCast->replaceUsesOfWith(OrigInst, NewInst);
NewBitCast->insertBefore(ThenTerm);
NewBitCast->insertBefore(ThenTerm->getIterator());
NewRetVal = NewBitCast;
Next = BitCast->getNextNode();
}
@ -320,7 +320,7 @@ static CallBase &versionCallSiteWithCond(CallBase &CB, Value *Cond,
auto NewRet = Ret->clone();
if (Ret->getReturnValue())
NewRet->replaceUsesOfWith(Ret->getReturnValue(), NewRetVal);
NewRet->insertBefore(ThenTerm);
NewRet->insertBefore(ThenTerm->getIterator());
// A return instructions is terminating, so we don't need the terminator
// instruction just created.
@ -344,8 +344,8 @@ static CallBase &versionCallSiteWithCond(CallBase &CB, Value *Cond,
MergeBlock->setName("if.end.icp");
CallBase *NewInst = cast<CallBase>(OrigInst->clone());
OrigInst->moveBefore(ElseTerm);
NewInst->insertBefore(ThenTerm);
OrigInst->moveBefore(ElseTerm->getIterator());
NewInst->insertBefore(ThenTerm->getIterator());
// If the original call site is an invoke instruction, we have extra work to
// do since invoke instructions are terminating. We have to fix-up phi nodes
@ -589,12 +589,12 @@ CallBase *llvm::promoteCallWithIfThenElse(CallBase &CB, Function &Callee,
CallBase &DirectCall = promoteCall(
versionCallSite(CB, &Callee, /*BranchWeights=*/nullptr), &Callee);
CSInstr->moveBefore(&CB);
CSInstr->moveBefore(CB.getIterator());
const auto NewCSID = CtxProf.allocateNextCallsiteIndex(Caller);
auto *NewCSInstr = cast<InstrProfCallsite>(CSInstr->clone());
NewCSInstr->setIndex(NewCSID);
NewCSInstr->setCallee(&Callee);
NewCSInstr->insertBefore(&DirectCall);
NewCSInstr->insertBefore(DirectCall.getIterator());
auto &DirectBB = *DirectCall.getParent();
auto &IndirectBB = *CB.getParent();

View File

@ -1144,7 +1144,7 @@ BasicBlock *llvm::DuplicateInstructionsInSplitBetween(
for (; StopAt != &*BI && BB->getTerminator() != &*BI; ++BI) {
Instruction *New = BI->clone();
New->setName(BI->getName());
New->insertBefore(NewTerm);
New->insertBefore(NewTerm->getIterator());
New->cloneDebugInfoFrom(&*BI);
ValueMapping[&*BI] = New;

View File

@ -1124,9 +1124,9 @@ static void insertLifetimeMarkersSurroundingCall(
Intrinsic::getOrInsertDeclaration(M, MarkerFunc, Mem->getType());
auto Marker = CallInst::Create(Func, {NegativeOne, Mem});
if (InsertBefore)
Marker->insertBefore(TheCall);
Marker->insertBefore(TheCall->getIterator());
else
Marker->insertBefore(Term);
Marker->insertBefore(Term->getIterator());
}
};
@ -1441,7 +1441,7 @@ CodeExtractor::extractCodeRegion(const CodeExtractorAnalysisCache &CEAC,
auto *HoistToBlock = findOrCreateBlockForHoisting(CommonExit);
Instruction *TI = HoistToBlock->getTerminator();
for (auto *II : HoistingCands)
cast<Instruction>(II)->moveBefore(TI);
cast<Instruction>(II)->moveBefore(TI->getIterator());
computeExtractedFuncRetVals();
}
@ -1815,7 +1815,7 @@ CallInst *CodeExtractor::emitReplacerCall(
if (ArgsInZeroAddressSpace && DL.getAllocaAddrSpace() != 0) {
auto *StructSpaceCast = new AddrSpaceCastInst(
Struct, PointerType ::get(Context, 0), "structArg.ascast");
StructSpaceCast->insertAfter(Struct);
StructSpaceCast->insertAfter(Struct->getIterator());
params.push_back(StructSpaceCast);
} else {
params.push_back(Struct);

View File

@ -442,7 +442,7 @@ void llvm::moveInstructionsToTheEnd(BasicBlock &FromBB, BasicBlock &ToBB,
while (FromBB.size() > 1) {
Instruction &I = FromBB.front();
if (isSafeToMoveBefore(I, *MovePos, DT, &PDT, &DI))
I.moveBeforePreserving(MovePos);
I.moveBeforePreserving(MovePos->getIterator());
}
}

View File

@ -100,7 +100,7 @@ void llvm::widenWidenableBranch(BranchInst *WidenableBR, Value *NewCond) {
C->set(B.CreateAnd(NewCond, C->get()));
Instruction *WCAnd = cast<Instruction>(WidenableBR->getCondition());
// Condition is only guaranteed to dominate branch
WCAnd->moveBefore(WidenableBR);
WCAnd->moveBefore(WidenableBR->getIterator());
}
assert(isWidenableBranch(WidenableBR) && "preserve widenabiliy");
}
@ -119,7 +119,7 @@ void llvm::setWidenableBranchCond(BranchInst *WidenableBR, Value *NewCond) {
// br (wc & C), ... form
Instruction *WCAnd = cast<Instruction>(WidenableBR->getCondition());
// Condition is only guaranteed to dominate branch
WCAnd->moveBefore(WidenableBR);
WCAnd->moveBefore(WidenableBR->getIterator());
C->set(NewCond);
}
assert(isWidenableBranch(WidenableBR) && "preserve widenabiliy");

View File

@ -48,7 +48,7 @@ static BasicBlock::iterator moveBeforeInsertPoint(BasicBlock::iterator I,
++IP;
} else {
// Otherwise, move I before IP and return IP.
I->moveBefore(&*IP);
I->moveBefore(IP);
}
return IP;
}

View File

@ -1715,7 +1715,7 @@ static void insertDbgValueOrDbgVariableRecordAfter(
if (!UseNewDbgInfoFormat) {
auto DbgVal = Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
(Instruction *)nullptr);
cast<Instruction *>(DbgVal)->insertAfter(&*Instr);
cast<Instruction *>(DbgVal)->insertAfter(Instr);
} else {
// RemoveDIs: if we're using the new debug-info format, allocate a
// DbgVariableRecord directly instead of a dbg.value intrinsic.
@ -2197,7 +2197,7 @@ void llvm::insertDebugValuesForPHIs(BasicBlock *BB,
auto *NewDbgII = DI.second;
auto InsertionPt = Parent->getFirstInsertionPt();
assert(InsertionPt != Parent->end() && "Ill-formed basic block");
NewDbgII->insertBefore(&*InsertionPt);
NewDbgII->insertBefore(InsertionPt);
}
}
@ -2975,7 +2975,7 @@ CallInst *llvm::createCallMatchingInvoke(InvokeInst *II) {
CallInst *llvm::changeToCall(InvokeInst *II, DomTreeUpdater *DTU) {
CallInst *NewCall = createCallMatchingInvoke(II);
NewCall->takeName(II);
NewCall->insertBefore(II);
NewCall->insertBefore(II->getIterator());
II->replaceAllUsesWith(NewCall);
// Follow the call by a branch to the normal destination.
@ -4307,9 +4307,9 @@ Value *llvm::invertCondition(Value *Condition) {
auto *Inverted =
BinaryOperator::CreateNot(Condition, Condition->getName() + ".inv");
if (Inst && !isa<PHINode>(Inst))
Inverted->insertAfter(Inst);
Inverted->insertAfter(Inst->getIterator());
else
Inverted->insertBefore(&*Parent->getFirstInsertionPt());
Inverted->insertBefore(Parent->getFirstInsertionPt());
return Inverted;
}

View File

@ -650,7 +650,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
NextDbgInsts = I->getDbgRecordRange();
Inst->moveBefore(LoopEntryBranch);
Inst->moveBefore(LoopEntryBranch->getIterator());
++NumInstrsHoisted;
continue;
@ -658,7 +658,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
// Otherwise, create a duplicate of the instruction.
Instruction *C = Inst->clone();
C->insertBefore(LoopEntryBranch);
C->insertBefore(LoopEntryBranch->getIterator());
++NumInstrsDuplicated;

View File

@ -447,9 +447,9 @@ static void addAssumeNonNull(AssumptionCache *AC, LoadInst *LI) {
Intrinsic::getOrInsertDeclaration(LI->getModule(), Intrinsic::assume);
ICmpInst *LoadNotNull = new ICmpInst(ICmpInst::ICMP_NE, LI,
Constant::getNullValue(LI->getType()));
LoadNotNull->insertAfter(LI);
LoadNotNull->insertAfter(LI->getIterator());
CallInst *CI = CallInst::Create(AssumeIntrinsic, {LoadNotNull});
CI->insertAfter(LoadNotNull);
CI->insertAfter(LoadNotNull->getIterator());
AC->registerAssumption(cast<AssumeInst>(CI));
}

View File

@ -845,7 +845,7 @@ bool SCEVExpander::hoistIVInc(Instruction *IncV, Instruction *InsertPos,
}
for (Instruction *I : llvm::reverse(IVIncs)) {
fixupInsertPoints(I);
I->moveBefore(InsertPos);
I->moveBefore(InsertPos->getIterator());
if (RecomputePoisonFlags)
FixupPoisonFlags(I);
}

View File

@ -2004,11 +2004,11 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(Instruction *TI,
// We've just hoisted DbgVariableRecords; move I1 after them (before TI)
// and leave any that were not hoisted behind (by calling moveBefore
// rather than moveBeforePreserving).
I1->moveBefore(TI);
I1->moveBefore(TI->getIterator());
for (auto &SuccIter : OtherSuccIterRange) {
auto *I2 = &*SuccIter++;
assert(isa<DbgInfoIntrinsic>(I2));
I2->moveBefore(TI);
I2->moveBefore(TI->getIterator());
}
} else {
// For a normal instruction, we just move one to right before the
@ -2018,7 +2018,7 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(Instruction *TI,
// We've just hoisted DbgVariableRecords; move I1 after them (before TI)
// and leave any that were not hoisted behind (by calling moveBefore
// rather than moveBeforePreserving).
I1->moveBefore(TI);
I1->moveBefore(TI->getIterator());
for (auto &SuccIter : OtherSuccIterRange) {
Instruction *I2 = &*SuccIter++;
assert(I2 != I1);

View File

@ -232,7 +232,7 @@ void reorder(Instruction *I) {
Instruction *IM = &*(BBI++);
if (!InstructionsToMove.contains(IM))
continue;
IM->moveBefore(I);
IM->moveBefore(I->getIterator());
}
}

View File

@ -1914,12 +1914,14 @@ public:
MemCheckBlock->replaceAllUsesWith(Preheader);
if (SCEVCheckBlock) {
SCEVCheckBlock->getTerminator()->moveBefore(Preheader->getTerminator());
SCEVCheckBlock->getTerminator()->moveBefore(
Preheader->getTerminator()->getIterator());
new UnreachableInst(Preheader->getContext(), SCEVCheckBlock);
Preheader->getTerminator()->eraseFromParent();
}
if (MemCheckBlock) {
MemCheckBlock->getTerminator()->moveBefore(Preheader->getTerminator());
MemCheckBlock->getTerminator()->moveBefore(
Preheader->getTerminator()->getIterator());
new UnreachableInst(Preheader->getContext(), MemCheckBlock);
Preheader->getTerminator()->eraseFromParent();
}
@ -2998,7 +3000,7 @@ void InnerLoopVectorizer::sinkScalarOperands(Instruction *PredInst) {
// Move the instruction to the beginning of the predicated block, and add
// it's operands to the worklist.
I->moveBefore(&*PredBB->getFirstInsertionPt());
I->moveBefore(PredBB->getFirstInsertionPt());
Worklist.insert(I->op_begin(), I->op_end());
// The sinking may have enabled other instructions to be sunk, so we will

View File

@ -4516,7 +4516,7 @@ BoUpSLP::~BoUpSLP() {
I->insertBefore(F->getEntryBlock(),
F->getEntryBlock().getFirstNonPHIIt());
else
I->insertBefore(F->getEntryBlock().getTerminator());
I->insertBefore(F->getEntryBlock().getTerminator()->getIterator());
continue;
}
for (Use &U : I->operands()) {
@ -16534,7 +16534,7 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,
Ex = EE;
} else {
auto *CloneInst = Inst->clone();
CloneInst->insertBefore(Inst);
CloneInst->insertBefore(Inst->getIterator());
if (Inst->hasName())
CloneInst->takeName(Inst);
Ex = CloneInst;
@ -16991,7 +16991,7 @@ void BoUpSLP::optimizeGatherSequence() {
continue;
// We can hoist this instruction. Move it to the pre-header.
I->moveBefore(PreHeader->getTerminator());
I->moveBefore(PreHeader->getTerminator()->getIterator());
CSEBlocks.insert(PreHeader);
}

View File

@ -975,7 +975,7 @@ void VPlan::execute(VPTransformState *State) {
BasicBlock *MiddleBB = State->CFG.ExitBB;
BasicBlock *ScalarPh = MiddleBB->getSingleSuccessor();
auto *BrInst = new UnreachableInst(MiddleBB->getContext());
BrInst->insertBefore(MiddleBB->getTerminator());
BrInst->insertBefore(MiddleBB->getTerminator()->getIterator());
MiddleBB->getTerminator()->eraseFromParent();
State->CFG.DTU.applyUpdates({{DominatorTree::Delete, MiddleBB, ScalarPh}});
// Disconnect scalar preheader and scalar header, as the dominator tree edge

View File

@ -707,7 +707,7 @@ static void IntroduceControlFlow(Function *F, Random &R) {
BasicBlock *Curr = Instr->getParent();
BasicBlock::iterator Loc = Instr->getIterator();
BasicBlock *Next = Curr->splitBasicBlock(Loc, "CF");
Instr->moveBefore(Curr->getTerminator());
Instr->moveBefore(Curr->getTerminator()->getIterator());
if (Curr != &F->getEntryBlock()) {
BranchInst::Create(Curr, Next, Instr,
Curr->getTerminator()->getIterator());

View File

@ -87,7 +87,7 @@ TEST(AssumeQueryAPI, hasAttributeInAssume) {
"8 noalias %P1, i32* align 8 noundef %P2)\n",
[](Instruction *I) {
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
ASSERT_TRUE(hasMatchesExactlyAttributes(Assume, I->getOperand(0),
"(nonnull|align|dereferenceable)"));
ASSERT_TRUE(hasMatchesExactlyAttributes(Assume, I->getOperand(1),
@ -109,7 +109,7 @@ TEST(AssumeQueryAPI, hasAttributeInAssume) {
"%P, i32* nonnull align 16 dereferenceable(12) %P)\n",
[](Instruction *I) {
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
ASSERT_TRUE(hasMatchesExactlyAttributes(Assume, I->getOperand(0),
"(nonnull|align|dereferenceable)"));
ASSERT_TRUE(hasMatchesExactlyAttributes(Assume, I->getOperand(1),
@ -129,7 +129,7 @@ TEST(AssumeQueryAPI, hasAttributeInAssume) {
"call void @func_many(i32* align 8 noundef %P1) cold\n", [](Instruction *I) {
ShouldPreserveAllAttributes.setValue(true);
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
ASSERT_TRUE(hasMatchesExactlyAttributes(
Assume, nullptr,
"(align|nounwind|norecurse|noundef|willreturn|cold)"));
@ -148,7 +148,7 @@ TEST(AssumeQueryAPI, hasAttributeInAssume) {
"%P2, i32* nonnull align 16 dereferenceable(12) %P3)\n",
[](Instruction *I) {
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
ASSERT_TRUE(hasMatchesExactlyAttributes(
Assume, I->getOperand(0),
"(align|dereferenceable)"));
@ -184,7 +184,7 @@ TEST(AssumeQueryAPI, hasAttributeInAssume) {
"%P2, i32* nonnull align 16 dereferenceable(12) %P3)\n",
[](Instruction *I) {
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
I->getOperand(1)->dropDroppableUses();
I->getOperand(2)->dropDroppableUses();
I->getOperand(3)->dropDroppableUses();
@ -207,7 +207,7 @@ TEST(AssumeQueryAPI, hasAttributeInAssume) {
"8 noalias %P1, i32* %P1)\n",
[](Instruction *I) {
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
Value *New = I->getFunction()->getArg(3);
Value *Old = I->getOperand(0);
ASSERT_TRUE(hasMatchesExactlyAttributes(Assume, New, ""));
@ -264,7 +264,7 @@ TEST(AssumeQueryAPI, fillMapFromAssume) {
"8 noalias %P1, i32* align 8 dereferenceable(8) %P2)\n",
[](Instruction *I) {
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
RetainedKnowledgeMap Map;
fillMapFromAssume(*Assume, Map);
@ -289,7 +289,7 @@ TEST(AssumeQueryAPI, fillMapFromAssume) {
"%P, i32* nonnull align 16 dereferenceable(12) %P)\n",
[](Instruction *I) {
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
RetainedKnowledgeMap Map;
fillMapFromAssume(*Assume, Map);
@ -312,7 +312,7 @@ TEST(AssumeQueryAPI, fillMapFromAssume) {
"call void @func_many(i32* align 8 %P1) cold\n", [](Instruction *I) {
ShouldPreserveAllAttributes.setValue(true);
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
RetainedKnowledgeMap Map;
fillMapFromAssume(*Assume, Map);
@ -337,7 +337,7 @@ TEST(AssumeQueryAPI, fillMapFromAssume) {
"%P2, i32* nonnull align 16 dereferenceable(12) %P3)\n",
[](Instruction *I) {
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
RetainedKnowledgeMap Map;
fillMapFromAssume(*Assume, Map);
@ -374,7 +374,7 @@ TEST(AssumeQueryAPI, fillMapFromAssume) {
"8 noalias %P1, i32* %P2)\n",
[](Instruction *I) {
auto *Assume = buildAssumeFromInst(I);
Assume->insertBefore(I);
Assume->insertBefore(I->getIterator());
RetainedKnowledgeMap Map;
fillMapFromAssume(*Assume, Map);
@ -468,7 +468,7 @@ static void RunRandTest(uint64_t Seed, int Size, int MinCount, int MaxCount,
auto *Assume = cast<AssumeInst>(CallInst::Create(
FnAssume, ArrayRef<Value *>({ConstantInt::getTrue(C)}), OpBundle));
Assume->insertBefore(&F->begin()->front());
Assume->insertBefore(F->begin()->begin());
RetainedKnowledgeMap Map;
fillMapFromAssume(*Assume, Map);
for (int i = 0; i < (Size * 2); i++) {

View File

@ -1629,7 +1629,7 @@ TEST_F(CGSCCPassManagerTest, TestUpdateCGAndAnalysisManagerForPasses8) {
BasicBlock *BB = BasicBlock::Create(FnewF->getContext(), "", FnewF);
auto *RI = ReturnInst::Create(FnewF->getContext(), BB);
while (FnF->getEntryBlock().size() > 1)
FnF->getEntryBlock().front().moveBefore(RI);
FnF->getEntryBlock().front().moveBefore(RI->getIterator());
ASSERT_NE(FnF, nullptr);
// Create an unused constant that is referencing the old (=replaced)

View File

@ -315,7 +315,7 @@ TEST_F(MemorySSATest, MoveAStore) {
MemorySSA &MSSA = *Analyses->MSSA;
MemorySSAUpdater Updater(&MSSA);
// Move the store
SideStore->moveBefore(Entry->getTerminator());
SideStore->moveBefore(Entry->getTerminator()->getIterator());
MemoryAccess *EntryStoreAccess = MSSA.getMemoryAccess(EntryStore);
MemoryAccess *SideStoreAccess = MSSA.getMemoryAccess(SideStore);
MemoryAccess *NewStoreAccess = Updater.createMemoryAccessAfter(
@ -351,7 +351,7 @@ TEST_F(MemorySSATest, MoveAStoreUpdater) {
MemorySSAUpdater Updater(&MSSA);
// Move the store
SideStore->moveBefore(Entry->getTerminator());
SideStore->moveBefore(Entry->getTerminator()->getIterator());
auto *EntryStoreAccess = MSSA.getMemoryAccess(EntryStore);
auto *SideStoreAccess = MSSA.getMemoryAccess(SideStore);
auto *NewStoreAccess = Updater.createMemoryAccessAfter(
@ -461,7 +461,7 @@ TEST_F(MemorySSATest, MoveAStoreAllAround) {
EXPECT_EQ(MergePhi->getIncomingValue(0), EntryStoreAccess);
EXPECT_EQ(MergePhi->getIncomingValue(1), SideStoreAccess);
// Now move it before the load
SideStore->moveBefore(MergeLoad);
SideStore->moveBefore(MergeLoad->getIterator());
Updater.moveBefore(SideStoreAccess, LoadAccess);
EXPECT_EQ(MergePhi->getIncomingValue(0), EntryStoreAccess);
EXPECT_EQ(MergePhi->getIncomingValue(1), EntryStoreAccess);
@ -840,7 +840,7 @@ TEST_F(MemorySSATest, MoveAboveMemoryDef) {
MemorySSAWalker &Walker = *Analyses->Walker;
MemorySSAUpdater Updater(&MSSA);
StoreC->moveBefore(StoreB);
StoreC->moveBefore(StoreB->getIterator());
Updater.moveBefore(cast<MemoryDef>(MSSA.getMemoryAccess(StoreC)),
cast<MemoryDef>(MSSA.getMemoryAccess(StoreB)));
@ -1702,7 +1702,7 @@ TEST_F(MemorySSATest, TestVisitedBlocks) {
// Move %v1 before the terminator of %header.i.check
BasicBlock *BB = getBasicBlockByName(*F, "header.i.check");
Instruction *LI = getInstructionByName(*F, "v1");
LI->moveBefore(BB->getTerminator());
LI->moveBefore(BB->getTerminator()->getIterator());
if (MemoryUseOrDef *MUD = MSSA.getMemoryAccess(LI))
Updater.moveToPlace(MUD, BB, MemorySSA::BeforeTerminator);
@ -1725,7 +1725,7 @@ TEST_F(MemorySSATest, TestVisitedBlocks) {
// Move %v2 before the terminator of %preheader.i
BasicBlock *BB = getBasicBlockByName(*F, "preheader.i");
Instruction *LI = getInstructionByName(*F, "v2");
LI->moveBefore(BB->getTerminator());
LI->moveBefore(BB->getTerminator()->getIterator());
// Check that there is no assertion of "Incomplete phi during partial
// rename"
if (MemoryUseOrDef *MUD = MSSA.getMemoryAccess(LI))

View File

@ -363,7 +363,7 @@ TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
EXPECT_EQ(CInst->getNextNode(), DInst);
// Move back.
CInst->moveBefore(BInst);
CInst->moveBefore(BInst->getIterator());
EXPECT_EQ(&*BB.begin(), DInst);
// Current order of insts: "D -> C -> B -> Ret". DbgVariableRecords on "D".
@ -1259,7 +1259,7 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsert) {
EXPECT_EQ(std::distance(R3.begin(), R3.end()), 2u);
// Re-insert and re-insert.
AddInst->insertAfter(SubInst);
AddInst->insertAfter(SubInst->getIterator());
Entry.reinsertInstInDbgRecords(AddInst, Pos);
// We should be back into a position of having one DbgVariableRecord on add
// and ret.
@ -1331,7 +1331,7 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsertForOneDbgVariableRecord) {
EXPECT_EQ(std::distance(R2.begin(), R2.end()), 1u);
// Re-insert and re-insert.
AddInst->insertAfter(SubInst);
AddInst->insertAfter(SubInst->getIterator());
Entry.reinsertInstInDbgRecords(AddInst, Pos);
// We should be back into a position of having one DbgVariableRecord on the
// AddInst.

View File

@ -225,7 +225,7 @@ TEST_F(InstrOrderInvalidationTest, SpliceInvalidation) {
EXPECT_TRUE(BB->isInstrOrderValid());
// Use Instruction::moveBefore, which uses splice.
I2->moveBefore(I1);
I2->moveBefore(I1->getIterator());
EXPECT_FALSE(BB->isInstrOrderValid());
EXPECT_TRUE(I2->comesBefore(I1));

View File

@ -601,7 +601,7 @@ namespace llvm {
CallBase *NewCB = cast<CallBase>(OldCB->clone());
NewCB->insertBefore(OldCB);
NewCB->insertBefore(OldCB->getIterator());
NewCB->takeName(OldCB);
CallerCGN->replaceCallEdge(*OldCB, *NewCB, CG[F]);

View File

@ -60,7 +60,7 @@ TEST(VerifierTest, Freeze) {
// Valid type : freeze(<2 x i32>)
Constant *CV = ConstantVector::getSplat(ElementCount::getFixed(2), CI);
FreezeInst *FI_vec = new FreezeInst(CV);
FI_vec->insertBefore(RI);
FI_vec->insertBefore(RI->getIterator());
EXPECT_FALSE(verifyFunction(*F));
@ -69,7 +69,7 @@ TEST(VerifierTest, Freeze) {
// Valid type : freeze(float)
Constant *CFP = ConstantFP::get(Type::getDoubleTy(C), 0.0);
FreezeInst *FI_dbl = new FreezeInst(CFP);
FI_dbl->insertBefore(RI);
FI_dbl->insertBefore(RI->getIterator());
EXPECT_FALSE(verifyFunction(*F));
@ -79,7 +79,7 @@ TEST(VerifierTest, Freeze) {
PointerType *PT = PointerType::get(C, 0);
ConstantPointerNull *CPN = ConstantPointerNull::get(PT);
FreezeInst *FI_ptr = new FreezeInst(CPN);
FI_ptr->insertBefore(RI);
FI_ptr->insertBefore(RI->getIterator());
EXPECT_FALSE(verifyFunction(*F));
@ -87,7 +87,7 @@ TEST(VerifierTest, Freeze) {
// Valid type : freeze(int)
FreezeInst *FI = new FreezeInst(CI);
FI->insertBefore(RI);
FI->insertBefore(RI->getIterator());
EXPECT_FALSE(verifyFunction(*F));
@ -403,7 +403,7 @@ TEST(VerifierTest, GetElementPtrInst) {
ConstantInt::get(Type::getInt64Ty(C), 0))},
Entry);
GEPVec->insertBefore(RI);
GEPVec->insertBefore(RI->getIterator());
// Break the address space of the source value
GEPVec->getOperandUse(0).set(ConstantAggregateZero::get(V2P2Ty));

View File

@ -1184,8 +1184,8 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT &LTS,
PHINode::Create(Builder.getInt32Ty(), 2, "polly.subregion.iv");
Instruction *LoopPHIInc = BinaryOperator::CreateAdd(
LoopPHI, Builder.getInt32(1), "polly.subregion.iv.inc");
LoopPHI->insertBefore(&BBCopy->front());
LoopPHIInc->insertBefore(BBCopy->getTerminator());
LoopPHI->insertBefore(BBCopy->begin());
LoopPHIInc->insertBefore(BBCopy->getTerminator()->getIterator());
for (auto *PredBB : predecessors(BB)) {
if (!R->contains(PredBB))

View File

@ -321,7 +321,7 @@ private:
}
InstClone->setName(Name + Inst->getName());
InstClone->insertBefore(IP);
InstClone->insertBefore(IP->getIterator());
return GenSE.getSCEV(InstClone);
}