Skip to content

Commit 939eda7

Browse files
committed
[NFC][DebugInfo] Switch more call-sites to using iterator-insertion
To finalise the "RemoveDIs" work removing debug intrinsics, we're updating call sites that insert instructions to use iterators instead. This set of changes are those where it's not immediately obvious that just calling getIterator to fetch an iterator is correct, and one or two places where more than one line needs to change. Overall the same rule holds though: iterators generated for the start of a block such as getFirstNonPHIIt need to be passed into insert/move methods without being unwrapped/rewrapped, everything else can use getIterator.
1 parent c546b53 commit 939eda7

File tree

16 files changed

+49
-50
lines changed

16 files changed

+49
-50
lines changed

llvm/include/llvm/Transforms/Coroutines/CoroInstr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class CoroIdInst : public AnyCoroIdInst {
170170
Inst->eraseFromParent();
171171
return;
172172
}
173-
Inst->moveBefore(getCoroBegin()->getNextNode());
173+
Inst->moveBefore(std::next(getCoroBegin()->getIterator()));
174174
}
175175

176176
// Info argument of coro.id is

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ void OpenMPIRBuilder::initialize() { initializeTypes(M); }
678678
static void raiseUserConstantDataAllocasToEntryBlock(IRBuilderBase &Builder,
679679
Function *Function) {
680680
BasicBlock &EntryBlock = Function->getEntryBlock();
681-
Instruction *MoveLocInst = EntryBlock.getFirstNonPHI();
681+
BasicBlock::iterator MoveLocInst = EntryBlock.getFirstNonPHIIt();
682682

683683
// Loop over blocks looking for constant allocas, skipping the entry block
684684
// as any allocas there are already in the desired location.
@@ -6916,7 +6916,7 @@ static Expected<Function *> createOutlinedFunction(
69166916
Builder.CreateRetVoid();
69176917

69186918
// New Alloca IP at entry point of created device function.
6919-
Builder.SetInsertPoint(EntryBB->getFirstNonPHI());
6919+
Builder.SetInsertPoint(EntryBB->getFirstNonPHIIt());
69206920
auto AllocaIP = Builder.saveIP();
69216921

69226922
Builder.SetInsertPoint(UserCodeEntryBB->getFirstNonPHIOrDbg());

llvm/lib/IR/BasicBlock.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ void BasicBlock::removePredecessor(BasicBlock *Pred,
543543
}
544544

545545
bool BasicBlock::canSplitPredecessors() const {
546-
const Instruction *FirstNonPHI = getFirstNonPHI();
546+
const_iterator FirstNonPHI = getFirstNonPHIIt();
547547
if (isa<LandingPadInst>(FirstNonPHI))
548548
return true;
549549
// This is perhaps a little conservative because constructs like
@@ -675,11 +675,11 @@ void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
675675
}
676676

677677
bool BasicBlock::isLandingPad() const {
678-
return isa<LandingPadInst>(getFirstNonPHI());
678+
return isa<LandingPadInst>(getFirstNonPHIIt());
679679
}
680680

681681
const LandingPadInst *BasicBlock::getLandingPadInst() const {
682-
return dyn_cast<LandingPadInst>(getFirstNonPHI());
682+
return dyn_cast<LandingPadInst>(getFirstNonPHIIt());
683683
}
684684

685685
std::optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {

llvm/lib/Target/Hexagon/HexagonOptimizeSZextends.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ bool HexagonOptimizeSZextends::runOnFunction(Function &F) {
8181
assert (EVT::getEVT(SI->getType()) ==
8282
(EVT::getEVT(Use->getType())));
8383
Use->replaceAllUsesWith(SI);
84-
Instruction* First = &F.getEntryBlock().front();
84+
BasicBlock::iterator First = F.getEntryBlock().begin();
8585
SI->insertBefore(First);
8686
Use->eraseFromParent();
8787
}

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,7 +3414,7 @@ void FunctionStackPoisoner::processStaticAllocas() {
34143414
assert(InsBeforeB == &F.getEntryBlock());
34153415
for (auto *AI : StaticAllocasToMoveUp)
34163416
if (AI->getParent() == InsBeforeB)
3417-
AI->moveBefore(InsBefore);
3417+
AI->moveBefore(InsBefore->getIterator());
34183418

34193419
// Move stores of arguments into entry-block allocas as well. This prevents
34203420
// extra stack slots from being generated (to house the argument values until
@@ -3423,10 +3423,10 @@ void FunctionStackPoisoner::processStaticAllocas() {
34233423
SmallVector<Instruction *, 8> ArgInitInsts;
34243424
findStoresToUninstrumentedArgAllocas(ASan, *InsBefore, ArgInitInsts);
34253425
for (Instruction *ArgInitInst : ArgInitInsts)
3426-
ArgInitInst->moveBefore(InsBefore);
3426+
ArgInitInst->moveBefore(InsBefore->getIterator());
34273427

34283428
// If we have a call to llvm.localescape, keep it in the entry block.
3429-
if (LocalEscapeCall) LocalEscapeCall->moveBefore(InsBefore);
3429+
if (LocalEscapeCall) LocalEscapeCall->moveBefore(InsBefore->getIterator());
34303430

34313431
SmallVector<ASanStackVariableDescription, 16> SVD;
34323432
SVD.reserve(AllocaVec.size());

llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static bool canSplitCallSite(CallBase &CB, TargetTransformInfo &TTI) {
218218
return true;
219219
}
220220

221-
static Instruction *cloneInstForMustTail(Instruction *I, Instruction *Before,
221+
static Instruction *cloneInstForMustTail(Instruction *I, BasicBlock::iterator Before,
222222
Value *V) {
223223
Instruction *Copy = I->clone();
224224
Copy->setName(I->getName());
@@ -251,8 +251,8 @@ static void copyMustTailReturn(BasicBlock *SplitBB, Instruction *CI,
251251
Instruction *TI = SplitBB->getTerminator();
252252
Value *V = NewCI;
253253
if (BCI)
254-
V = cloneInstForMustTail(BCI, TI, V);
255-
cloneInstForMustTail(RI, TI, IsVoid ? nullptr : V);
254+
V = cloneInstForMustTail(BCI, TI->getIterator(), V);
255+
cloneInstForMustTail(RI, TI->getIterator(), IsVoid ? nullptr : V);
256256

257257
// FIXME: remove TI here, `DuplicateInstructionsInSplitBetween` has a bug
258258
// that prevents doing this now.

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6176,11 +6176,11 @@ LSRInstance::LSRInstance(Loop *L, IVUsers &IU, ScalarEvolution &SE,
61766176
// CatchSwitchInst. Because the CatchSwitchInst cannot be split, there is
61776177
// no good place to stick any instructions.
61786178
if (auto *PN = dyn_cast<PHINode>(U.getUser())) {
6179-
auto *FirstNonPHI = PN->getParent()->getFirstNonPHI();
6179+
auto FirstNonPHI = PN->getParent()->getFirstNonPHIIt();
61806180
if (isa<FuncletPadInst>(FirstNonPHI) ||
61816181
isa<CatchSwitchInst>(FirstNonPHI))
61826182
for (BasicBlock *PredBB : PN->blocks())
6183-
if (isa<CatchSwitchInst>(PredBB->getFirstNonPHI()))
6183+
if (isa<CatchSwitchInst>(PredBB->getFirstNonPHIIt()))
61846184
return;
61856185
}
61866186
}

llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void MergedLoadStoreMotion::sinkStoresAndGEPs(BasicBlock *BB, StoreInst *S0,
281281
auto *GEP0 = cast<GetElementPtrInst>(Ptr0);
282282
auto *GEP1 = cast<GetElementPtrInst>(Ptr1);
283283
Instruction *GEPNew = GEP0->clone();
284-
GEPNew->insertBefore(SNew);
284+
GEPNew->insertBefore(SNew->getIterator());
285285
GEPNew->applyMergedLocation(GEP0->getDebugLoc(), GEP1->getDebugLoc());
286286
SNew->setOperand(1, GEPNew);
287287
GEP0->replaceAllUsesWith(GEPNew);

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ static void recomputeLiveInValues(
13711371
// and inserts them before "InsertBefore". Returns rematerialized value
13721372
// which should be used after statepoint.
13731373
static Instruction *rematerializeChain(ArrayRef<Instruction *> ChainToBase,
1374-
Instruction *InsertBefore,
1374+
BasicBlock::iterator InsertBefore,
13751375
Value *RootOfChain,
13761376
Value *AlternateLiveBase) {
13771377
Instruction *LastClonedValue = nullptr;
@@ -2185,16 +2185,16 @@ static void relocationViaAlloca(
21852185
// InvokeInst is a terminator so the store need to be inserted into its
21862186
// normal destination block.
21872187
BasicBlock *NormalDest = Invoke->getNormalDest();
2188-
Store->insertBefore(NormalDest->getFirstNonPHI());
2188+
Store->insertBefore(NormalDest->getFirstNonPHIIt());
21892189
} else {
21902190
assert(!Inst->isTerminator() &&
21912191
"The only terminator that can produce a value is "
21922192
"InvokeInst which is handled above.");
2193-
Store->insertAfter(Inst);
2193+
Store->insertAfter(Inst->getIterator());
21942194
}
21952195
} else {
21962196
assert(isa<Argument>(Def));
2197-
Store->insertAfter(cast<Instruction>(Alloca));
2197+
Store->insertAfter(cast<Instruction>(Alloca)->getIterator());
21982198
}
21992199
}
22002200

@@ -2500,7 +2500,7 @@ static void rematerializeLiveValuesAtUses(
25002500
while (!Cand->user_empty()) {
25012501
Instruction *UserI = cast<Instruction>(*Cand->user_begin());
25022502
Instruction *RematChain = rematerializeChain(
2503-
Record.ChainToBase, UserI, Record.RootOfChain, PointerToBase[Cand]);
2503+
Record.ChainToBase, UserI->getIterator(), Record.RootOfChain, PointerToBase[Cand]);
25042504
UserI->replaceUsesOfWith(Cand, RematChain);
25052505
PointerToBase[RematChain] = PointerToBase[Cand];
25062506
}
@@ -2573,16 +2573,16 @@ static void rematerializeLiveValues(CallBase *Call,
25732573
Instruction *InsertBefore = Call->getNextNode();
25742574
assert(InsertBefore);
25752575
Instruction *RematerializedValue =
2576-
rematerializeChain(Record.ChainToBase, InsertBefore,
2576+
rematerializeChain(Record.ChainToBase, InsertBefore->getIterator(),
25772577
Record.RootOfChain, PointerToBase[LiveValue]);
25782578
Info.RematerializedValues[RematerializedValue] = LiveValue;
25792579
} else {
25802580
auto *Invoke = cast<InvokeInst>(Call);
25812581

2582-
Instruction *NormalInsertBefore =
2583-
&*Invoke->getNormalDest()->getFirstInsertionPt();
2584-
Instruction *UnwindInsertBefore =
2585-
&*Invoke->getUnwindDest()->getFirstInsertionPt();
2582+
BasicBlock::iterator NormalInsertBefore =
2583+
Invoke->getNormalDest()->getFirstInsertionPt();
2584+
BasicBlock::iterator UnwindInsertBefore =
2585+
Invoke->getUnwindDest()->getFirstInsertionPt();
25862586

25872587
Instruction *NormalRematerializedValue =
25882588
rematerializeChain(Record.ChainToBase, NormalInsertBefore,
@@ -3131,7 +3131,7 @@ bool RewriteStatepointsForGC::runOnFunction(Function &F, DominatorTree &DT,
31313131
// most instructions without side effects or memory access.
31323132
if (isa<ICmpInst>(Cond) && Cond->hasOneUse()) {
31333133
MadeChange = true;
3134-
Cond->moveBefore(TI);
3134+
Cond->moveBefore(TI->getIterator());
31353135
}
31363136
}
31373137

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static void migrateDebugInfo(AllocaInst *OldAlloca, bool IsSplit,
480480
// noted as slightly offset (in code) from the store. In practice this
481481
// should have little effect on the debugging experience due to the fact
482482
// that all the split stores should get the same line number.
483-
NewAssign->moveBefore(DbgAssign);
483+
NewAssign->moveBefore(DbgAssign->getIterator());
484484

485485
NewAssign->setDebugLoc(DbgAssign->getDebugLoc());
486486
LLVM_DEBUG(dbgs() << "Created new assign: " << *NewAssign << "\n");
@@ -1843,7 +1843,7 @@ static void rewriteMemOpOfSelect(SelectInst &SI, T &I,
18431843
CondMemOp.dropUBImplyingAttrsAndMetadata();
18441844
++NumLoadsSpeculated;
18451845
}
1846-
CondMemOp.insertBefore(NewMemOpBB->getTerminator());
1846+
CondMemOp.insertBefore(NewMemOpBB->getTerminator()->getIterator());
18471847
Value *Ptr = SI.getOperand(1 + SuccIdx);
18481848
CondMemOp.setOperand(I.getPointerOperandIndex(), Ptr);
18491849
if (isa<LoadInst>(I)) {

0 commit comments

Comments
 (0)