Skip to content

Commit 34b1395

Browse files
authored
[NFC][DebugInfo] Switch more call-sites to using iterator-insertion (#124283)
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 038b42b commit 34b1395

File tree

16 files changed

+55
-53
lines changed

16 files changed

+55
-53
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.
@@ -6918,7 +6918,7 @@ static Expected<Function *> createOutlinedFunction(
69186918
Builder.CreateRetVoid();
69196919

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

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

llvm/lib/IR/BasicBlock.cpp

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

557557
bool BasicBlock::canSplitPredecessors() const {
558-
const Instruction *FirstNonPHI = getFirstNonPHI();
558+
const_iterator FirstNonPHI = getFirstNonPHIIt();
559559
if (isa<LandingPadInst>(FirstNonPHI))
560560
return true;
561561
// This is perhaps a little conservative because constructs like
@@ -687,11 +687,11 @@ void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
687687
}
688688

689689
bool BasicBlock::isLandingPad() const {
690-
return isa<LandingPadInst>(getFirstNonPHI());
690+
return isa<LandingPadInst>(getFirstNonPHIIt());
691691
}
692692

693693
const LandingPadInst *BasicBlock::getLandingPadInst() const {
694-
return dyn_cast<LandingPadInst>(getFirstNonPHI());
694+
return dyn_cast<LandingPadInst>(getFirstNonPHIIt());
695695
}
696696

697697
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: 4 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,11 @@ 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)
3430+
LocalEscapeCall->moveBefore(InsBefore->getIterator());
34303431

34313432
SmallVector<ASanStackVariableDescription, 16> SVD;
34323433
SVD.reserve(AllocaVec.size());

llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp

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

221-
static Instruction *cloneInstForMustTail(Instruction *I, Instruction *Before,
222-
Value *V) {
221+
static Instruction *
222+
cloneInstForMustTail(Instruction *I, BasicBlock::iterator Before, Value *V) {
223223
Instruction *Copy = I->clone();
224224
Copy->setName(I->getName());
225225
Copy->insertBefore(Before);
@@ -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: 13 additions & 12 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

@@ -2499,8 +2499,9 @@ static void rematerializeLiveValuesAtUses(
24992499
// statepoint between uses in the block.
25002500
while (!Cand->user_empty()) {
25012501
Instruction *UserI = cast<Instruction>(*Cand->user_begin());
2502-
Instruction *RematChain = rematerializeChain(
2503-
Record.ChainToBase, UserI, Record.RootOfChain, PointerToBase[Cand]);
2502+
Instruction *RematChain =
2503+
rematerializeChain(Record.ChainToBase, UserI->getIterator(),
2504+
Record.RootOfChain, PointerToBase[Cand]);
25042505
UserI->replaceUsesOfWith(Cand, RematChain);
25052506
PointerToBase[RematChain] = PointerToBase[Cand];
25062507
}
@@ -2573,16 +2574,16 @@ static void rematerializeLiveValues(CallBase *Call,
25732574
Instruction *InsertBefore = Call->getNextNode();
25742575
assert(InsertBefore);
25752576
Instruction *RematerializedValue =
2576-
rematerializeChain(Record.ChainToBase, InsertBefore,
2577+
rematerializeChain(Record.ChainToBase, InsertBefore->getIterator(),
25772578
Record.RootOfChain, PointerToBase[LiveValue]);
25782579
Info.RematerializedValues[RematerializedValue] = LiveValue;
25792580
} else {
25802581
auto *Invoke = cast<InvokeInst>(Call);
25812582

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

25872588
Instruction *NormalRematerializedValue =
25882589
rematerializeChain(Record.ChainToBase, NormalInsertBefore,
@@ -3131,7 +3132,7 @@ bool RewriteStatepointsForGC::runOnFunction(Function &F, DominatorTree &DT,
31313132
// most instructions without side effects or memory access.
31323133
if (isa<ICmpInst>(Cond) && Cond->hasOneUse()) {
31333134
MadeChange = true;
3134-
Cond->moveBefore(TI);
3135+
Cond->moveBefore(TI->getIterator());
31353136
}
31363137
}
31373138

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)