aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorJeremy Morse <jeremy.morse@sony.com>2025-01-24 10:53:11 +0000
committerGitHub <noreply@github.com>2025-01-24 10:53:11 +0000
commit8e702735090388a3231a863e343f880d0f96fecb (patch)
tree0de8577ecae863327fe271a2e56f3705af105e5e /llvm/lib/CodeGen/CodeGenPrepare.cpp
parente6030d389571b3f1b0f0c5a35b7fa45937ed0f6c (diff)
downloadllvm-8e702735090388a3231a863e343f880d0f96fecb.zip
llvm-8e702735090388a3231a863e343f880d0f96fecb.tar.gz
llvm-8e702735090388a3231a863e343f880d0f96fecb.tar.bz2
[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).
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 7106e53..7e9d705 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -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