aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorJeremy Morse <jeremy.morse@sony.com>2024-03-19 16:36:29 +0000
committerGitHub <noreply@github.com>2024-03-19 16:36:29 +0000
commitb9d83eff254668385fd3d9d5ddb5af762f378d7f (patch)
treefa2871855343dcb93484267f2c9abda6561e8f7d /llvm/lib/CodeGen
parentc63a291c64852a086cb447c7078e5312aac1a05c (diff)
downloadllvm-b9d83eff254668385fd3d9d5ddb5af762f378d7f.zip
llvm-b9d83eff254668385fd3d9d5ddb5af762f378d7f.tar.gz
llvm-b9d83eff254668385fd3d9d5ddb5af762f378d7f.tar.bz2
[NFC][RemoveDIs] Use iterators for insertion at various call-sites (#84736)
These are the last remaining "trivial" changes to passes that use Instruction pointers for insertion. All of this should be NFC, it's just changing the spelling of how we identify a position. In one or two locations, I'm also switching uses of getNextNode etc to using std::next with iterators. This too should be NFC. --------- Merged by: Stephen Tozer <stephen.tozer@sony.com>
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp25
-rw-r--r--llvm/lib/CodeGen/DwarfEHPrepare.cpp5
-rw-r--r--llvm/lib/CodeGen/GCRootLowering.cpp9
-rw-r--r--llvm/lib/CodeGen/IndirectBrExpandPass.cpp13
-rw-r--r--llvm/lib/CodeGen/InterleavedAccessPass.cpp7
-rw-r--r--llvm/lib/CodeGen/IntrinsicLowering.cpp2
-rw-r--r--llvm/lib/CodeGen/JMCInstrumenter.cpp2
-rw-r--r--llvm/lib/CodeGen/SjLjEHPrepare.cpp17
-rw-r--r--llvm/lib/CodeGen/WinEHPrepare.cpp16
9 files changed, 51 insertions, 45 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 921a5b7..e7bf656 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2057,9 +2057,9 @@ static bool sinkAndCmp0Expression(Instruction *AndI, const TargetLowering &TLI,
// Keep the 'and' in the same place if the use is already in the same block.
Instruction *InsertPt =
User->getParent() == AndI->getParent() ? AndI : User;
- Instruction *InsertedAnd =
- BinaryOperator::Create(Instruction::And, AndI->getOperand(0),
- AndI->getOperand(1), "", InsertPt);
+ Instruction *InsertedAnd = BinaryOperator::Create(
+ Instruction::And, AndI->getOperand(0), AndI->getOperand(1), "",
+ InsertPt->getIterator());
// Propagate the debug info.
InsertedAnd->setDebugLoc(AndI->getDebugLoc());
@@ -4153,9 +4153,10 @@ private:
if (SelectInst *CurrentSelect = dyn_cast<SelectInst>(Current)) {
// Is it OK to get metadata from OrigSelect?!
// Create a Select placeholder with dummy value.
- SelectInst *Select = SelectInst::Create(
- CurrentSelect->getCondition(), Dummy, Dummy,
- CurrentSelect->getName(), CurrentSelect, CurrentSelect);
+ SelectInst *Select =
+ SelectInst::Create(CurrentSelect->getCondition(), Dummy, Dummy,
+ CurrentSelect->getName(),
+ CurrentSelect->getIterator(), CurrentSelect);
Map[Current] = Select;
ST.insertNewSelect(Select);
// We are interested in True and False values.
@@ -6466,8 +6467,8 @@ bool CodeGenPrepare::optimizePhiType(
ValMap[D] = D->getOperand(0);
DeletedInstrs.insert(D);
} else {
- ValMap[D] =
- new BitCastInst(D, ConvertTy, D->getName() + ".bc", D->getNextNode());
+ BasicBlock::iterator insertPt = std::next(D->getIterator());
+ ValMap[D] = new BitCastInst(D, ConvertTy, D->getName() + ".bc", insertPt);
}
}
for (PHINode *Phi : PhiNodes)
@@ -6487,8 +6488,8 @@ bool CodeGenPrepare::optimizePhiType(
DeletedInstrs.insert(U);
replaceAllUsesWith(U, ValMap[U->getOperand(0)], FreshBBs, IsHugeFunc);
} else {
- U->setOperand(0,
- new BitCastInst(ValMap[U->getOperand(0)], PhiTy, "bc", U));
+ U->setOperand(0, new BitCastInst(ValMap[U->getOperand(0)], PhiTy, "bc",
+ U->getIterator()));
}
}
@@ -8384,7 +8385,7 @@ bool CodeGenPrepare::optimizeInst(Instruction *I, ModifyDT &ModifiedDT) {
if (GEPI->hasAllZeroIndices()) {
/// The GEP operand must be a pointer, so must its result -> BitCast
Instruction *NC = new BitCastInst(GEPI->getOperand(0), GEPI->getType(),
- GEPI->getName(), GEPI);
+ GEPI->getName(), GEPI->getIterator());
NC->setDebugLoc(GEPI->getDebugLoc());
replaceAllUsesWith(GEPI, NC, FreshBBs, IsHugeFunc);
RecursivelyDeleteTriviallyDeadInstructions(
@@ -8416,7 +8417,7 @@ bool CodeGenPrepare::optimizeInst(Instruction *I, ModifyDT &ModifiedDT) {
isa<ConstantPointerNull>(Op1);
if (Const0 || Const1) {
if (!Const0 || !Const1) {
- auto *F = new FreezeInst(Const0 ? Op1 : Op0, "", CmpI);
+ auto *F = new FreezeInst(Const0 ? Op1 : Op0, "", CmpI->getIterator());
F->takeName(FI);
CmpI->setOperand(Const0 ? 1 : 0, F);
}
diff --git a/llvm/lib/CodeGen/DwarfEHPrepare.cpp b/llvm/lib/CodeGen/DwarfEHPrepare.cpp
index e7eb34d..09e7cfb 100644
--- a/llvm/lib/CodeGen/DwarfEHPrepare.cpp
+++ b/llvm/lib/CodeGen/DwarfEHPrepare.cpp
@@ -111,7 +111,8 @@ Value *DwarfEHPrepare::GetExceptionObject(ResumeInst *RI) {
}
if (!ExnObj)
- ExnObj = ExtractValueInst::Create(RI->getOperand(0), 0, "exn.obj", RI);
+ ExnObj = ExtractValueInst::Create(RI->getOperand(0), 0, "exn.obj",
+ RI->getIterator());
RI->eraseFromParent();
@@ -158,7 +159,7 @@ size_t DwarfEHPrepare::pruneUnreachableResumes(
Resumes[ResumesLeft++] = RI;
} else {
BasicBlock *BB = RI->getParent();
- new UnreachableInst(Ctx, RI);
+ new UnreachableInst(Ctx, RI->getIterator());
RI->eraseFromParent();
simplifyCFG(BB, *TTI, DTU);
}
diff --git a/llvm/lib/CodeGen/GCRootLowering.cpp b/llvm/lib/CodeGen/GCRootLowering.cpp
index 0d82f2b..700714d 100644
--- a/llvm/lib/CodeGen/GCRootLowering.cpp
+++ b/llvm/lib/CodeGen/GCRootLowering.cpp
@@ -181,7 +181,7 @@ static bool InsertRootInitializers(Function &F, ArrayRef<AllocaInst *> Roots) {
if (!InitedRoots.count(Root)) {
new StoreInst(
ConstantPointerNull::get(cast<PointerType>(Root->getAllocatedType())),
- Root, Root->getNextNode());
+ Root, std::next(Root->getIterator()));
MadeChange = true;
}
@@ -216,8 +216,8 @@ bool DoLowering(Function &F, GCStrategy &S) {
default: break;
case Intrinsic::gcwrite: {
// Replace a write barrier with a simple store.
- Value *St = new StoreInst(CI->getArgOperand(0),
- CI->getArgOperand(2), CI);
+ Value *St = new StoreInst(CI->getArgOperand(0), CI->getArgOperand(2),
+ CI->getIterator());
CI->replaceAllUsesWith(St);
CI->eraseFromParent();
MadeChange = true;
@@ -225,7 +225,8 @@ bool DoLowering(Function &F, GCStrategy &S) {
}
case Intrinsic::gcread: {
// Replace a read barrier with a simple load.
- Value *Ld = new LoadInst(CI->getType(), CI->getArgOperand(1), "", CI);
+ Value *Ld = new LoadInst(CI->getType(), CI->getArgOperand(1), "",
+ CI->getIterator());
Ld->takeName(CI);
CI->replaceAllUsesWith(Ld);
CI->eraseFromParent();
diff --git a/llvm/lib/CodeGen/IndirectBrExpandPass.cpp b/llvm/lib/CodeGen/IndirectBrExpandPass.cpp
index f7b931a..13f595b 100644
--- a/llvm/lib/CodeGen/IndirectBrExpandPass.cpp
+++ b/llvm/lib/CodeGen/IndirectBrExpandPass.cpp
@@ -113,7 +113,7 @@ bool runImpl(Function &F, const TargetLowering *TLI, DomTreeUpdater *DTU) {
// Handle the degenerate case of no successors by replacing the indirectbr
// with unreachable as there is no successor available.
if (IBr->getNumSuccessors() == 0) {
- (void)new UnreachableInst(F.getContext(), IBr);
+ (void)new UnreachableInst(F.getContext(), IBr->getIterator());
IBr->eraseFromParent();
continue;
}
@@ -183,7 +183,7 @@ bool runImpl(Function &F, const TargetLowering *TLI, DomTreeUpdater *DTU) {
for (BasicBlock *SuccBB : IBr->successors())
Updates.push_back({DominatorTree::Delete, IBr->getParent(), SuccBB});
}
- (void)new UnreachableInst(F.getContext(), IBr);
+ (void)new UnreachableInst(F.getContext(), IBr->getIterator());
IBr->eraseFromParent();
}
if (DTU) {
@@ -207,9 +207,10 @@ bool runImpl(Function &F, const TargetLowering *TLI, DomTreeUpdater *DTU) {
}
auto GetSwitchValue = [CommonITy](IndirectBrInst *IBr) {
- return CastInst::CreatePointerCast(
- IBr->getAddress(), CommonITy,
- Twine(IBr->getAddress()->getName()) + ".switch_cast", IBr);
+ return CastInst::CreatePointerCast(IBr->getAddress(), CommonITy,
+ Twine(IBr->getAddress()->getName()) +
+ ".switch_cast",
+ IBr->getIterator());
};
SmallVector<DominatorTree::UpdateType, 8> Updates;
@@ -243,7 +244,7 @@ bool runImpl(Function &F, const TargetLowering *TLI, DomTreeUpdater *DTU) {
Updates.reserve(IndirectBrs.size() + 2 * IndirectBrSuccs.size());
for (auto *IBr : IndirectBrs) {
SwitchPN->addIncoming(GetSwitchValue(IBr), IBr->getParent());
- BranchInst::Create(SwitchBB, IBr);
+ BranchInst::Create(SwitchBB, IBr->getIterator());
if (DTU) {
Updates.push_back({DominatorTree::Insert, IBr->getParent(), SwitchBB});
for (BasicBlock *SuccBB : IBr->successors())
diff --git a/llvm/lib/CodeGen/InterleavedAccessPass.cpp b/llvm/lib/CodeGen/InterleavedAccessPass.cpp
index 2a0daf4..438ac1c 100644
--- a/llvm/lib/CodeGen/InterleavedAccessPass.cpp
+++ b/llvm/lib/CodeGen/InterleavedAccessPass.cpp
@@ -388,14 +388,15 @@ bool InterleavedAccessImpl::replaceBinOpShuffles(
return Idx < (int)cast<FixedVectorType>(BIOp0Ty)->getNumElements();
}));
+ BasicBlock::iterator insertPos = SVI->getIterator();
auto *NewSVI1 =
new ShuffleVectorInst(BI->getOperand(0), PoisonValue::get(BIOp0Ty),
- Mask, SVI->getName(), SVI);
+ Mask, SVI->getName(), insertPos);
auto *NewSVI2 = new ShuffleVectorInst(
BI->getOperand(1), PoisonValue::get(BI->getOperand(1)->getType()), Mask,
- SVI->getName(), SVI);
+ SVI->getName(), insertPos);
BinaryOperator *NewBI = BinaryOperator::CreateWithCopiedFlags(
- BI->getOpcode(), NewSVI1, NewSVI2, BI, BI->getName(), SVI);
+ BI->getOpcode(), NewSVI1, NewSVI2, BI, BI->getName(), insertPos);
SVI->replaceAllUsesWith(NewBI);
LLVM_DEBUG(dbgs() << " Replaced: " << *BI << "\n And : " << *SVI
<< "\n With : " << *NewSVI1 << "\n And : "
diff --git a/llvm/lib/CodeGen/IntrinsicLowering.cpp b/llvm/lib/CodeGen/IntrinsicLowering.cpp
index fe450cb..09d282d 100644
--- a/llvm/lib/CodeGen/IntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/IntrinsicLowering.cpp
@@ -472,7 +472,7 @@ bool IntrinsicLowering::LowerToByteSwap(CallInst *CI) {
Function *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty);
Value *Op = CI->getArgOperand(0);
- Op = CallInst::Create(Int, Op, CI->getName(), CI);
+ Op = CallInst::Create(Int, Op, CI->getName(), CI->getIterator());
CI->replaceAllUsesWith(Op);
CI->eraseFromParent();
diff --git a/llvm/lib/CodeGen/JMCInstrumenter.cpp b/llvm/lib/CodeGen/JMCInstrumenter.cpp
index 62a3819..e2aaebe 100644
--- a/llvm/lib/CodeGen/JMCInstrumenter.cpp
+++ b/llvm/lib/CodeGen/JMCInstrumenter.cpp
@@ -227,7 +227,7 @@ bool runImpl(Module &M) {
// FIXME: it would be nice to make CI scheduling boundary, although in
// practice it does not matter much.
auto *CI = CallInst::Create(getCheckFunctionType(Ctx), CheckFunction,
- {Flag}, "", &*F.begin()->getFirstInsertionPt());
+ {Flag}, "", F.begin()->getFirstInsertionPt());
CI->addParamAttr(0, Attribute::NoUndef);
if (UseX86FastCall) {
CI->setCallingConv(CallingConv::X86_FastCall);
diff --git a/llvm/lib/CodeGen/SjLjEHPrepare.cpp b/llvm/lib/CodeGen/SjLjEHPrepare.cpp
index 4bad57d..20c827c 100644
--- a/llvm/lib/CodeGen/SjLjEHPrepare.cpp
+++ b/llvm/lib/CodeGen/SjLjEHPrepare.cpp
@@ -202,7 +202,7 @@ SjLjEHPrepareImpl::setupFunctionContext(Function &F,
auto &DL = F.getParent()->getDataLayout();
const Align Alignment = DL.getPrefTypeAlign(FunctionContextTy);
FuncCtx = new AllocaInst(FunctionContextTy, DL.getAllocaAddrSpace(), nullptr,
- Alignment, "fn_context", &EntryBB->front());
+ Alignment, "fn_context", EntryBB->begin());
// Fill in the function context structure.
for (LandingPadInst *LPI : LPads) {
@@ -271,7 +271,7 @@ void SjLjEHPrepareImpl::lowerIncomingArguments(Function &F) {
Value *TrueValue = ConstantInt::getTrue(F.getContext());
Value *UndefValue = UndefValue::get(Ty);
Instruction *SI = SelectInst::Create(
- TrueValue, &AI, UndefValue, AI.getName() + ".tmp", &*AfterAllocaInsPt);
+ TrueValue, &AI, UndefValue, AI.getName() + ".tmp", AfterAllocaInsPt);
AI.replaceAllUsesWith(SI);
// Reset the operand, because it was clobbered by the RAUW above.
@@ -386,7 +386,7 @@ bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
if (Function *Callee = II->getCalledFunction())
if (Callee->getIntrinsicID() == Intrinsic::donothing) {
// Remove the NOP invoke.
- BranchInst::Create(II->getNormalDest(), II);
+ BranchInst::Create(II->getNormalDest(), II->getIterator());
II->eraseFromParent();
continue;
}
@@ -445,7 +445,7 @@ bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
// Record the call site value for the back end so it stays associated with
// the invoke.
- CallInst::Create(CallSiteFn, CallSiteNum, "", Invokes[I]);
+ CallInst::Create(CallSiteFn, CallSiteNum, "", Invokes[I]->getIterator());
}
// Mark call instructions that aren't nounwind as no-action (call_site ==
@@ -462,8 +462,8 @@ bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
}
// Register the function context and make sure it's known to not throw
- CallInst *Register =
- CallInst::Create(RegisterFn, FuncCtx, "", EntryBB->getTerminator());
+ CallInst *Register = CallInst::Create(
+ RegisterFn, FuncCtx, "", EntryBB->getTerminator()->getIterator());
Register->setDoesNotThrow();
// Following any allocas not in the entry block, update the saved SP in the
@@ -480,7 +480,8 @@ bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
}
Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp");
StackAddr->insertAfter(&I);
- new StoreInst(StackAddr, StackPtr, true, StackAddr->getNextNode());
+ new StoreInst(StackAddr, StackPtr, true,
+ std::next(StackAddr->getIterator()));
}
}
@@ -490,7 +491,7 @@ bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
Instruction *InsertPoint = Return;
if (CallInst *CI = Return->getParent()->getTerminatingMustTailCall())
InsertPoint = CI;
- CallInst::Create(UnregisterFn, FuncCtx, "", InsertPoint);
+ CallInst::Create(UnregisterFn, FuncCtx, "", InsertPoint->getIterator());
}
return true;
diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp
index 95976c2..93a18f5 100644
--- a/llvm/lib/CodeGen/WinEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WinEHPrepare.cpp
@@ -1234,10 +1234,10 @@ AllocaInst *WinEHPrepareImpl::insertPHILoads(PHINode *PN, Function &F) {
// that will dominate all uses.
SpillSlot = new AllocaInst(PN->getType(), DL->getAllocaAddrSpace(), nullptr,
Twine(PN->getName(), ".wineh.spillslot"),
- &F.getEntryBlock().front());
+ F.getEntryBlock().begin());
Value *V = new LoadInst(PN->getType(), SpillSlot,
Twine(PN->getName(), ".wineh.reload"),
- &*PHIBlock->getFirstInsertionPt());
+ PHIBlock->getFirstInsertionPt());
PN->replaceAllUsesWith(V);
return SpillSlot;
}
@@ -1309,7 +1309,7 @@ void WinEHPrepareImpl::insertPHIStore(
}
// Otherwise, insert the store at the end of the basic block.
- new StoreInst(PredVal, SpillSlot, PredBlock->getTerminator());
+ new StoreInst(PredVal, SpillSlot, PredBlock->getTerminator()->getIterator());
}
void WinEHPrepareImpl::replaceUseWithLoad(
@@ -1319,7 +1319,7 @@ void WinEHPrepareImpl::replaceUseWithLoad(
if (!SpillSlot)
SpillSlot = new AllocaInst(V->getType(), DL->getAllocaAddrSpace(), nullptr,
Twine(V->getName(), ".wineh.spillslot"),
- &F.getEntryBlock().front());
+ F.getEntryBlock().begin());
auto *UsingInst = cast<Instruction>(U.getUser());
if (auto *UsingPHI = dyn_cast<PHINode>(UsingInst)) {
@@ -1376,16 +1376,16 @@ void WinEHPrepareImpl::replaceUseWithLoad(
Value *&Load = Loads[IncomingBlock];
// Insert the load into the predecessor block
if (!Load)
- Load = new LoadInst(V->getType(), SpillSlot,
- Twine(V->getName(), ".wineh.reload"),
- /*isVolatile=*/false, IncomingBlock->getTerminator());
+ Load = new LoadInst(
+ V->getType(), SpillSlot, Twine(V->getName(), ".wineh.reload"),
+ /*isVolatile=*/false, IncomingBlock->getTerminator()->getIterator());
U.set(Load);
} else {
// Reload right before the old use.
auto *Load = new LoadInst(V->getType(), SpillSlot,
Twine(V->getName(), ".wineh.reload"),
- /*isVolatile=*/false, UsingInst);
+ /*isVolatile=*/false, UsingInst->getIterator());
U.set(Load);
}
}