Skip to content

[NFC][RemoveDIs] Use iterators for insertion at various call-sites #84736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions llvm/lib/Analysis/PHITransAddr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ Value *PHITransAddr::insertTranslatedSubExpr(
// Otherwise insert a cast at the end of PredBB.
CastInst *New = CastInst::Create(Cast->getOpcode(), OpVal, InVal->getType(),
InVal->getName() + ".phi.trans.insert",
PredBB->getTerminator());
PredBB->getTerminator()->getIterator());
New->setDebugLoc(Inst->getDebugLoc());
NewInsts.push_back(New);
return New;
Expand All @@ -387,7 +387,8 @@ Value *PHITransAddr::insertTranslatedSubExpr(

GetElementPtrInst *Result = GetElementPtrInst::Create(
GEP->getSourceElementType(), GEPOps[0], ArrayRef(GEPOps).slice(1),
InVal->getName() + ".phi.trans.insert", PredBB->getTerminator());
InVal->getName() + ".phi.trans.insert",
PredBB->getTerminator()->getIterator());
Result->setDebugLoc(Inst->getDebugLoc());
Result->setIsInBounds(GEP->isInBounds());
NewInsts.push_back(Result);
Expand All @@ -408,9 +409,9 @@ Value *PHITransAddr::insertTranslatedSubExpr(
if (OpVal == nullptr)
return nullptr;

BinaryOperator *Res = BinaryOperator::CreateAdd(OpVal, Inst->getOperand(1),
InVal->getName()+".phi.trans.insert",
PredBB->getTerminator());
BinaryOperator *Res = BinaryOperator::CreateAdd(
OpVal, Inst->getOperand(1), InVal->getName() + ".phi.trans.insert",
PredBB->getTerminator()->getIterator());
Res->setHasNoSignedWrap(cast<BinaryOperator>(Inst)->hasNoSignedWrap());
Res->setHasNoUnsignedWrap(cast<BinaryOperator>(Inst)->hasNoUnsignedWrap());
NewInsts.push_back(Res);
Expand Down
25 changes: 13 additions & 12 deletions llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2021,9 +2021,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());

Expand Down Expand Up @@ -4117,9 +4117,10 @@ class AddressingModeCombiner {
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.
Expand Down Expand Up @@ -6430,8 +6431,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)
Expand All @@ -6451,8 +6452,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()));
}
}

Expand Down Expand Up @@ -8348,7 +8349,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(
Expand Down Expand Up @@ -8380,7 +8381,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);
}
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/CodeGen/DwarfEHPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/CodeGen/GCRootLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,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;
}

Expand Down Expand Up @@ -213,16 +213,17 @@ 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;
break;
}
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();
Expand Down
13 changes: 7 additions & 6 deletions llvm/lib/CodeGen/IndirectBrExpandPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/CodeGen/InterleavedAccessPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 : "
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/IntrinsicLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/JMCInstrumenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 9 additions & 8 deletions llvm/lib/CodeGen/SjLjEHPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,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) {
Expand Down Expand Up @@ -273,7 +273,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.
Expand Down Expand Up @@ -388,7 +388,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;
}
Expand Down Expand Up @@ -447,7 +447,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 ==
Expand All @@ -464,8 +464,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
Expand All @@ -482,7 +482,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()));
}
}

Expand All @@ -492,7 +493,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;
Expand Down
16 changes: 8 additions & 8 deletions llvm/lib/CodeGen/WinEHPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class TriggerVerifierErrorPass
// Intentionally break the Function by inserting a terminator
// instruction in the middle of a basic block.
BasicBlock &BB = F.getEntryBlock();
new UnreachableInst(F.getContext(), BB.getTerminator());
new UnreachableInst(F.getContext(), BB.getTerminator()->getIterator());
return PreservedAnalyses::none();
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ static std::optional<Instruction *> instCombineSVELast(InstCombiner &IC,
auto *NewRHS =
IC.Builder.CreateIntrinsic(IntrinsicID, {Vec->getType()}, {Pg, RHS});
auto *NewBinOp = BinaryOperator::CreateWithCopiedFlags(
OpC, NewLHS, NewRHS, OldBinOp, OldBinOp->getName(), &II);
OpC, NewLHS, NewRHS, OldBinOp, OldBinOp->getName(), II.getIterator());
return IC.replaceInstUsesWith(II, NewBinOp);
}
}
Expand Down
10 changes: 6 additions & 4 deletions llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,11 @@ bool AMDGPULibCalls::sincosUseNative(CallInst *aCI, const FuncInfo &FInfo) {
nf.setId(AMDGPULibFunc::EI_COS);
FunctionCallee cosExpr = getFunction(M, nf);
if (sinExpr && cosExpr) {
Value *sinval = CallInst::Create(sinExpr, opr0, "splitsin", aCI);
Value *cosval = CallInst::Create(cosExpr, opr0, "splitcos", aCI);
new StoreInst(cosval, aCI->getArgOperand(1), aCI);
Value *sinval =
CallInst::Create(sinExpr, opr0, "splitsin", aCI->getIterator());
Value *cosval =
CallInst::Create(cosExpr, opr0, "splitcos", aCI->getIterator());
new StoreInst(cosval, aCI->getArgOperand(1), aCI->getIterator());

DEBUG_WITH_TYPE("usenative", dbgs() << "<useNative> replace " << *aCI
<< " with native version of sin/cos");
Expand Down Expand Up @@ -1655,7 +1657,7 @@ bool AMDGPULibCalls::evaluateCall(CallInst *aCI, const FuncInfo &FInfo) {
// sincos
assert(FInfo.getId() == AMDGPULibFunc::EI_SINCOS &&
"math function with ptr arg not supported yet");
new StoreInst(nval1, aCI->getArgOperand(1), aCI);
new StoreInst(nval1, aCI->getArgOperand(1), aCI->getIterator());
}

replaceCall(aCI, nval0);
Expand Down
Loading