aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Morse <jeremy.morse@sony.com>2023-12-13 14:04:35 +0000
committerGitHub <noreply@github.com>2023-12-13 14:04:35 +0000
commit4b64138ba485fd0fca69613e429e585ee4b67575 (patch)
tree35d5d8efcfe7660266ef6a85118c30268a0f551c
parent7f55d7de1a7511dcfaa37c9f1665bfd8aea5f764 (diff)
downloadllvm-4b64138ba485fd0fca69613e429e585ee4b67575.zip
llvm-4b64138ba485fd0fca69613e429e585ee4b67575.tar.gz
llvm-4b64138ba485fd0fca69613e429e585ee4b67575.tar.bz2
[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.
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp24
-rw-r--r--llvm/lib/Transforms/Scalar/LICM.cpp19
-rw-r--r--llvm/lib/Transforms/Utils/LoopRotationUtils.cpp5
3 files changed, 28 insertions, 20 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index aa5cdd2..f9e791c 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1384,7 +1384,8 @@ static bool SinkCast(CastInst *CI) {
BasicBlock::iterator InsertPt = UserBB->getFirstInsertionPt();
assert(InsertPt != UserBB->end());
InsertedCast = CastInst::Create(CI->getOpcode(), CI->getOperand(0),
- CI->getType(), "", &*InsertPt);
+ CI->getType(), "");
+ InsertedCast->insertBefore(*UserBB, InsertPt);
InsertedCast->setDebugLoc(CI->getDebugLoc());
}
@@ -2058,12 +2059,13 @@ SinkShiftAndTruncate(BinaryOperator *ShiftI, Instruction *User, ConstantInt *CI,
assert(InsertPt != TruncUserBB->end());
// Sink the shift
if (ShiftI->getOpcode() == Instruction::AShr)
- InsertedShift = BinaryOperator::CreateAShr(ShiftI->getOperand(0), CI,
- "", &*InsertPt);
+ InsertedShift =
+ BinaryOperator::CreateAShr(ShiftI->getOperand(0), CI, "");
else
- InsertedShift = BinaryOperator::CreateLShr(ShiftI->getOperand(0), CI,
- "", &*InsertPt);
+ InsertedShift =
+ BinaryOperator::CreateLShr(ShiftI->getOperand(0), CI, "");
InsertedShift->setDebugLoc(ShiftI->getDebugLoc());
+ InsertedShift->insertBefore(*TruncUserBB, InsertPt);
// Sink the trunc
BasicBlock::iterator TruncInsertPt = TruncUserBB->getFirstInsertionPt();
@@ -2162,11 +2164,12 @@ static bool OptimizeExtractBits(BinaryOperator *ShiftI, ConstantInt *CI,
assert(InsertPt != UserBB->end());
if (ShiftI->getOpcode() == Instruction::AShr)
- InsertedShift = BinaryOperator::CreateAShr(ShiftI->getOperand(0), CI,
- "", &*InsertPt);
+ InsertedShift =
+ BinaryOperator::CreateAShr(ShiftI->getOperand(0), CI, "");
else
- InsertedShift = BinaryOperator::CreateLShr(ShiftI->getOperand(0), CI,
- "", &*InsertPt);
+ InsertedShift =
+ BinaryOperator::CreateLShr(ShiftI->getOperand(0), CI, "");
+ InsertedShift->insertBefore(*UserBB, InsertPt);
InsertedShift->setDebugLoc(ShiftI->getDebugLoc());
MadeChange = true;
@@ -6628,7 +6631,8 @@ bool CodeGenPrepare::optimizeExtUses(Instruction *I) {
if (!InsertedTrunc) {
BasicBlock::iterator InsertPt = UserBB->getFirstInsertionPt();
assert(InsertPt != UserBB->end());
- InsertedTrunc = new TruncInst(I, Src->getType(), "", &*InsertPt);
+ InsertedTrunc = new TruncInst(I, Src->getType(), "");
+ InsertedTrunc->insertBefore(*UserBB, InsertPt);
InsertedInsts.insert(InsertedTrunc);
}
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index d0afe09..9117378 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -193,7 +193,7 @@ static Instruction *cloneInstructionInExitBlock(
static void eraseInstruction(Instruction &I, ICFLoopSafetyInfo &SafetyInfo,
MemorySSAUpdater &MSSAU);
-static void moveInstructionBefore(Instruction &I, Instruction &Dest,
+static void moveInstructionBefore(Instruction &I, BasicBlock::iterator Dest,
ICFLoopSafetyInfo &SafetyInfo,
MemorySSAUpdater &MSSAU, ScalarEvolution *SE);
@@ -1011,7 +1011,8 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
LLVM_DEBUG(dbgs() << "LICM rehoisting to "
<< HoistPoint->getParent()->getNameOrAsOperand()
<< ": " << *I << "\n");
- moveInstructionBefore(*I, *HoistPoint, *SafetyInfo, MSSAU, SE);
+ moveInstructionBefore(*I, HoistPoint->getIterator(), *SafetyInfo, MSSAU,
+ SE);
HoistPoint = I;
Changed = true;
}
@@ -1491,16 +1492,17 @@ static void eraseInstruction(Instruction &I, ICFLoopSafetyInfo &SafetyInfo,
I.eraseFromParent();
}
-static void moveInstructionBefore(Instruction &I, Instruction &Dest,
+static void moveInstructionBefore(Instruction &I, BasicBlock::iterator Dest,
ICFLoopSafetyInfo &SafetyInfo,
MemorySSAUpdater &MSSAU,
ScalarEvolution *SE) {
SafetyInfo.removeInstruction(&I);
- SafetyInfo.insertInstructionTo(&I, Dest.getParent());
- I.moveBefore(&Dest);
+ SafetyInfo.insertInstructionTo(&I, Dest->getParent());
+ I.moveBefore(*Dest->getParent(), Dest);
if (MemoryUseOrDef *OldMemAcc = cast_or_null<MemoryUseOrDef>(
MSSAU.getMemorySSA()->getMemoryAccess(&I)))
- MSSAU.moveToPlace(OldMemAcc, Dest.getParent(), MemorySSA::BeforeTerminator);
+ MSSAU.moveToPlace(OldMemAcc, Dest->getParent(),
+ MemorySSA::BeforeTerminator);
if (SE)
SE->forgetBlockAndLoopDispositions(&I);
}
@@ -1747,10 +1749,11 @@ static void hoist(Instruction &I, const DominatorTree *DT, const Loop *CurLoop,
if (isa<PHINode>(I))
// Move the new node to the end of the phi list in the destination block.
- moveInstructionBefore(I, *Dest->getFirstNonPHI(), *SafetyInfo, MSSAU, SE);
+ moveInstructionBefore(I, Dest->getFirstNonPHIIt(), *SafetyInfo, MSSAU, SE);
else
// Move the new node to the destination block, before its terminator.
- moveInstructionBefore(I, *Dest->getTerminator(), *SafetyInfo, MSSAU, SE);
+ moveInstructionBefore(I, Dest->getTerminator()->getIterator(), *SafetyInfo,
+ MSSAU, SE);
I.updateLocationAfterHoist();
diff --git a/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp b/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
index 76280ed..504f443 100644
--- a/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
@@ -708,12 +708,13 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
// as U1'' and U1' scopes will not be compatible wrt to the local restrict
// Clone the llvm.experimental.noalias.decl again for the NewHeader.
- Instruction *NewHeaderInsertionPoint = &(*NewHeader->getFirstNonPHI());
+ BasicBlock::iterator NewHeaderInsertionPoint =
+ NewHeader->getFirstNonPHIIt();
for (NoAliasScopeDeclInst *NAD : NoAliasDeclInstructions) {
LLVM_DEBUG(dbgs() << " Cloning llvm.experimental.noalias.scope.decl:"
<< *NAD << "\n");
Instruction *NewNAD = NAD->clone();
- NewNAD->insertBefore(NewHeaderInsertionPoint);
+ NewNAD->insertBefore(*NewHeader, NewHeaderInsertionPoint);
}
// Scopes must now be duplicated, once for OrigHeader and once for