Skip to content

Commit 4b64138

Browse files
authored
[DebugInfo][RemoveDIs] Switch some insertion routines to use iterators (#75330)
As part of RemoveDIs, we need instruction insertion to be done with iterators rather than instruction pointers, so that we can communicate some debug-info facts about the position. This patch is an entirely mechanical replacement of Instruction * with BasicBlock::iterator, plus using insertBefore to insert some instructions because we don't have iterator-taking constructors yet. Sadly it's not NFC because it causes dbg.value intrinsics / their DPValue equivalents to shift location.
1 parent 7f55d7d commit 4b64138

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,8 @@ static bool SinkCast(CastInst *CI) {
13841384
BasicBlock::iterator InsertPt = UserBB->getFirstInsertionPt();
13851385
assert(InsertPt != UserBB->end());
13861386
InsertedCast = CastInst::Create(CI->getOpcode(), CI->getOperand(0),
1387-
CI->getType(), "", &*InsertPt);
1387+
CI->getType(), "");
1388+
InsertedCast->insertBefore(*UserBB, InsertPt);
13881389
InsertedCast->setDebugLoc(CI->getDebugLoc());
13891390
}
13901391

@@ -2058,12 +2059,13 @@ SinkShiftAndTruncate(BinaryOperator *ShiftI, Instruction *User, ConstantInt *CI,
20582059
assert(InsertPt != TruncUserBB->end());
20592060
// Sink the shift
20602061
if (ShiftI->getOpcode() == Instruction::AShr)
2061-
InsertedShift = BinaryOperator::CreateAShr(ShiftI->getOperand(0), CI,
2062-
"", &*InsertPt);
2062+
InsertedShift =
2063+
BinaryOperator::CreateAShr(ShiftI->getOperand(0), CI, "");
20632064
else
2064-
InsertedShift = BinaryOperator::CreateLShr(ShiftI->getOperand(0), CI,
2065-
"", &*InsertPt);
2065+
InsertedShift =
2066+
BinaryOperator::CreateLShr(ShiftI->getOperand(0), CI, "");
20662067
InsertedShift->setDebugLoc(ShiftI->getDebugLoc());
2068+
InsertedShift->insertBefore(*TruncUserBB, InsertPt);
20672069

20682070
// Sink the trunc
20692071
BasicBlock::iterator TruncInsertPt = TruncUserBB->getFirstInsertionPt();
@@ -2162,11 +2164,12 @@ static bool OptimizeExtractBits(BinaryOperator *ShiftI, ConstantInt *CI,
21622164
assert(InsertPt != UserBB->end());
21632165

21642166
if (ShiftI->getOpcode() == Instruction::AShr)
2165-
InsertedShift = BinaryOperator::CreateAShr(ShiftI->getOperand(0), CI,
2166-
"", &*InsertPt);
2167+
InsertedShift =
2168+
BinaryOperator::CreateAShr(ShiftI->getOperand(0), CI, "");
21672169
else
2168-
InsertedShift = BinaryOperator::CreateLShr(ShiftI->getOperand(0), CI,
2169-
"", &*InsertPt);
2170+
InsertedShift =
2171+
BinaryOperator::CreateLShr(ShiftI->getOperand(0), CI, "");
2172+
InsertedShift->insertBefore(*UserBB, InsertPt);
21702173
InsertedShift->setDebugLoc(ShiftI->getDebugLoc());
21712174

21722175
MadeChange = true;
@@ -6628,7 +6631,8 @@ bool CodeGenPrepare::optimizeExtUses(Instruction *I) {
66286631
if (!InsertedTrunc) {
66296632
BasicBlock::iterator InsertPt = UserBB->getFirstInsertionPt();
66306633
assert(InsertPt != UserBB->end());
6631-
InsertedTrunc = new TruncInst(I, Src->getType(), "", &*InsertPt);
6634+
InsertedTrunc = new TruncInst(I, Src->getType(), "");
6635+
InsertedTrunc->insertBefore(*UserBB, InsertPt);
66326636
InsertedInsts.insert(InsertedTrunc);
66336637
}
66346638

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static Instruction *cloneInstructionInExitBlock(
193193
static void eraseInstruction(Instruction &I, ICFLoopSafetyInfo &SafetyInfo,
194194
MemorySSAUpdater &MSSAU);
195195

196-
static void moveInstructionBefore(Instruction &I, Instruction &Dest,
196+
static void moveInstructionBefore(Instruction &I, BasicBlock::iterator Dest,
197197
ICFLoopSafetyInfo &SafetyInfo,
198198
MemorySSAUpdater &MSSAU, ScalarEvolution *SE);
199199

@@ -1011,7 +1011,8 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
10111011
LLVM_DEBUG(dbgs() << "LICM rehoisting to "
10121012
<< HoistPoint->getParent()->getNameOrAsOperand()
10131013
<< ": " << *I << "\n");
1014-
moveInstructionBefore(*I, *HoistPoint, *SafetyInfo, MSSAU, SE);
1014+
moveInstructionBefore(*I, HoistPoint->getIterator(), *SafetyInfo, MSSAU,
1015+
SE);
10151016
HoistPoint = I;
10161017
Changed = true;
10171018
}
@@ -1491,16 +1492,17 @@ static void eraseInstruction(Instruction &I, ICFLoopSafetyInfo &SafetyInfo,
14911492
I.eraseFromParent();
14921493
}
14931494

1494-
static void moveInstructionBefore(Instruction &I, Instruction &Dest,
1495+
static void moveInstructionBefore(Instruction &I, BasicBlock::iterator Dest,
14951496
ICFLoopSafetyInfo &SafetyInfo,
14961497
MemorySSAUpdater &MSSAU,
14971498
ScalarEvolution *SE) {
14981499
SafetyInfo.removeInstruction(&I);
1499-
SafetyInfo.insertInstructionTo(&I, Dest.getParent());
1500-
I.moveBefore(&Dest);
1500+
SafetyInfo.insertInstructionTo(&I, Dest->getParent());
1501+
I.moveBefore(*Dest->getParent(), Dest);
15011502
if (MemoryUseOrDef *OldMemAcc = cast_or_null<MemoryUseOrDef>(
15021503
MSSAU.getMemorySSA()->getMemoryAccess(&I)))
1503-
MSSAU.moveToPlace(OldMemAcc, Dest.getParent(), MemorySSA::BeforeTerminator);
1504+
MSSAU.moveToPlace(OldMemAcc, Dest->getParent(),
1505+
MemorySSA::BeforeTerminator);
15041506
if (SE)
15051507
SE->forgetBlockAndLoopDispositions(&I);
15061508
}
@@ -1747,10 +1749,11 @@ static void hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop,
17471749

17481750
if (isa<PHINode>(I))
17491751
// Move the new node to the end of the phi list in the destination block.
1750-
moveInstructionBefore(I, *Dest->getFirstNonPHI(), *SafetyInfo, MSSAU, SE);
1752+
moveInstructionBefore(I, Dest->getFirstNonPHIIt(), *SafetyInfo, MSSAU, SE);
17511753
else
17521754
// Move the new node to the destination block, before its terminator.
1753-
moveInstructionBefore(I, *Dest->getTerminator(), *SafetyInfo, MSSAU, SE);
1755+
moveInstructionBefore(I, Dest->getTerminator()->getIterator(), *SafetyInfo,
1756+
MSSAU, SE);
17541757

17551758
I.updateLocationAfterHoist();
17561759

llvm/lib/Transforms/Utils/LoopRotationUtils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,12 +708,13 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
708708
// as U1'' and U1' scopes will not be compatible wrt to the local restrict
709709

710710
// Clone the llvm.experimental.noalias.decl again for the NewHeader.
711-
Instruction *NewHeaderInsertionPoint = &(*NewHeader->getFirstNonPHI());
711+
BasicBlock::iterator NewHeaderInsertionPoint =
712+
NewHeader->getFirstNonPHIIt();
712713
for (NoAliasScopeDeclInst *NAD : NoAliasDeclInstructions) {
713714
LLVM_DEBUG(dbgs() << " Cloning llvm.experimental.noalias.scope.decl:"
714715
<< *NAD << "\n");
715716
Instruction *NewNAD = NAD->clone();
716-
NewNAD->insertBefore(NewHeaderInsertionPoint);
717+
NewNAD->insertBefore(*NewHeader, NewHeaderInsertionPoint);
717718
}
718719

719720
// Scopes must now be duplicated, once for OrigHeader and once for

0 commit comments

Comments
 (0)