[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>
This commit is contained in:
Jeremy Morse 2024-03-19 16:36:29 +00:00 committed by GitHub
parent c63a291c64
commit b9d83eff25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
31 changed files with 152 additions and 123 deletions

View File

@ -369,7 +369,7 @@ Value *PHITransAddr::insertTranslatedSubExpr(
// Otherwise insert a cast at the end of PredBB. // Otherwise insert a cast at the end of PredBB.
CastInst *New = CastInst::Create(Cast->getOpcode(), OpVal, InVal->getType(), CastInst *New = CastInst::Create(Cast->getOpcode(), OpVal, InVal->getType(),
InVal->getName() + ".phi.trans.insert", InVal->getName() + ".phi.trans.insert",
PredBB->getTerminator()); PredBB->getTerminator()->getIterator());
New->setDebugLoc(Inst->getDebugLoc()); New->setDebugLoc(Inst->getDebugLoc());
NewInsts.push_back(New); NewInsts.push_back(New);
return New; return New;
@ -387,7 +387,8 @@ Value *PHITransAddr::insertTranslatedSubExpr(
GetElementPtrInst *Result = GetElementPtrInst::Create( GetElementPtrInst *Result = GetElementPtrInst::Create(
GEP->getSourceElementType(), GEPOps[0], ArrayRef(GEPOps).slice(1), 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->setDebugLoc(Inst->getDebugLoc());
Result->setIsInBounds(GEP->isInBounds()); Result->setIsInBounds(GEP->isInBounds());
NewInsts.push_back(Result); NewInsts.push_back(Result);
@ -408,9 +409,9 @@ Value *PHITransAddr::insertTranslatedSubExpr(
if (OpVal == nullptr) if (OpVal == nullptr)
return nullptr; return nullptr;
BinaryOperator *Res = BinaryOperator::CreateAdd(OpVal, Inst->getOperand(1), BinaryOperator *Res = BinaryOperator::CreateAdd(
InVal->getName()+".phi.trans.insert", OpVal, Inst->getOperand(1), InVal->getName() + ".phi.trans.insert",
PredBB->getTerminator()); PredBB->getTerminator()->getIterator());
Res->setHasNoSignedWrap(cast<BinaryOperator>(Inst)->hasNoSignedWrap()); Res->setHasNoSignedWrap(cast<BinaryOperator>(Inst)->hasNoSignedWrap());
Res->setHasNoUnsignedWrap(cast<BinaryOperator>(Inst)->hasNoUnsignedWrap()); Res->setHasNoUnsignedWrap(cast<BinaryOperator>(Inst)->hasNoUnsignedWrap());
NewInsts.push_back(Res); NewInsts.push_back(Res);

View File

@ -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. // Keep the 'and' in the same place if the use is already in the same block.
Instruction *InsertPt = Instruction *InsertPt =
User->getParent() == AndI->getParent() ? AndI : User; User->getParent() == AndI->getParent() ? AndI : User;
Instruction *InsertedAnd = Instruction *InsertedAnd = BinaryOperator::Create(
BinaryOperator::Create(Instruction::And, AndI->getOperand(0), Instruction::And, AndI->getOperand(0), AndI->getOperand(1), "",
AndI->getOperand(1), "", InsertPt); InsertPt->getIterator());
// Propagate the debug info. // Propagate the debug info.
InsertedAnd->setDebugLoc(AndI->getDebugLoc()); InsertedAnd->setDebugLoc(AndI->getDebugLoc());
@ -4153,9 +4153,10 @@ private:
if (SelectInst *CurrentSelect = dyn_cast<SelectInst>(Current)) { if (SelectInst *CurrentSelect = dyn_cast<SelectInst>(Current)) {
// Is it OK to get metadata from OrigSelect?! // Is it OK to get metadata from OrigSelect?!
// Create a Select placeholder with dummy value. // Create a Select placeholder with dummy value.
SelectInst *Select = SelectInst::Create( SelectInst *Select =
CurrentSelect->getCondition(), Dummy, Dummy, SelectInst::Create(CurrentSelect->getCondition(), Dummy, Dummy,
CurrentSelect->getName(), CurrentSelect, CurrentSelect); CurrentSelect->getName(),
CurrentSelect->getIterator(), CurrentSelect);
Map[Current] = Select; Map[Current] = Select;
ST.insertNewSelect(Select); ST.insertNewSelect(Select);
// We are interested in True and False values. // We are interested in True and False values.
@ -6466,8 +6467,8 @@ bool CodeGenPrepare::optimizePhiType(
ValMap[D] = D->getOperand(0); ValMap[D] = D->getOperand(0);
DeletedInstrs.insert(D); DeletedInstrs.insert(D);
} else { } else {
ValMap[D] = BasicBlock::iterator insertPt = std::next(D->getIterator());
new BitCastInst(D, ConvertTy, D->getName() + ".bc", D->getNextNode()); ValMap[D] = new BitCastInst(D, ConvertTy, D->getName() + ".bc", insertPt);
} }
} }
for (PHINode *Phi : PhiNodes) for (PHINode *Phi : PhiNodes)
@ -6487,8 +6488,8 @@ bool CodeGenPrepare::optimizePhiType(
DeletedInstrs.insert(U); DeletedInstrs.insert(U);
replaceAllUsesWith(U, ValMap[U->getOperand(0)], FreshBBs, IsHugeFunc); replaceAllUsesWith(U, ValMap[U->getOperand(0)], FreshBBs, IsHugeFunc);
} else { } else {
U->setOperand(0, U->setOperand(0, new BitCastInst(ValMap[U->getOperand(0)], PhiTy, "bc",
new BitCastInst(ValMap[U->getOperand(0)], PhiTy, "bc", U)); U->getIterator()));
} }
} }
@ -8384,7 +8385,7 @@ bool CodeGenPrepare::optimizeInst(Instruction *I, ModifyDT &ModifiedDT) {
if (GEPI->hasAllZeroIndices()) { if (GEPI->hasAllZeroIndices()) {
/// The GEP operand must be a pointer, so must its result -> BitCast /// The GEP operand must be a pointer, so must its result -> BitCast
Instruction *NC = new BitCastInst(GEPI->getOperand(0), GEPI->getType(), Instruction *NC = new BitCastInst(GEPI->getOperand(0), GEPI->getType(),
GEPI->getName(), GEPI); GEPI->getName(), GEPI->getIterator());
NC->setDebugLoc(GEPI->getDebugLoc()); NC->setDebugLoc(GEPI->getDebugLoc());
replaceAllUsesWith(GEPI, NC, FreshBBs, IsHugeFunc); replaceAllUsesWith(GEPI, NC, FreshBBs, IsHugeFunc);
RecursivelyDeleteTriviallyDeadInstructions( RecursivelyDeleteTriviallyDeadInstructions(
@ -8416,7 +8417,7 @@ bool CodeGenPrepare::optimizeInst(Instruction *I, ModifyDT &ModifiedDT) {
isa<ConstantPointerNull>(Op1); isa<ConstantPointerNull>(Op1);
if (Const0 || Const1) { if (Const0 || Const1) {
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); F->takeName(FI);
CmpI->setOperand(Const0 ? 1 : 0, F); CmpI->setOperand(Const0 ? 1 : 0, F);
} }

View File

@ -111,7 +111,8 @@ Value *DwarfEHPrepare::GetExceptionObject(ResumeInst *RI) {
} }
if (!ExnObj) 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(); RI->eraseFromParent();
@ -158,7 +159,7 @@ size_t DwarfEHPrepare::pruneUnreachableResumes(
Resumes[ResumesLeft++] = RI; Resumes[ResumesLeft++] = RI;
} else { } else {
BasicBlock *BB = RI->getParent(); BasicBlock *BB = RI->getParent();
new UnreachableInst(Ctx, RI); new UnreachableInst(Ctx, RI->getIterator());
RI->eraseFromParent(); RI->eraseFromParent();
simplifyCFG(BB, *TTI, DTU); simplifyCFG(BB, *TTI, DTU);
} }

View File

@ -181,7 +181,7 @@ static bool InsertRootInitializers(Function &F, ArrayRef<AllocaInst *> Roots) {
if (!InitedRoots.count(Root)) { if (!InitedRoots.count(Root)) {
new StoreInst( new StoreInst(
ConstantPointerNull::get(cast<PointerType>(Root->getAllocatedType())), ConstantPointerNull::get(cast<PointerType>(Root->getAllocatedType())),
Root, Root->getNextNode()); Root, std::next(Root->getIterator()));
MadeChange = true; MadeChange = true;
} }
@ -216,8 +216,8 @@ bool DoLowering(Function &F, GCStrategy &S) {
default: break; default: break;
case Intrinsic::gcwrite: { case Intrinsic::gcwrite: {
// Replace a write barrier with a simple store. // Replace a write barrier with a simple store.
Value *St = new StoreInst(CI->getArgOperand(0), Value *St = new StoreInst(CI->getArgOperand(0), CI->getArgOperand(2),
CI->getArgOperand(2), CI); CI->getIterator());
CI->replaceAllUsesWith(St); CI->replaceAllUsesWith(St);
CI->eraseFromParent(); CI->eraseFromParent();
MadeChange = true; MadeChange = true;
@ -225,7 +225,8 @@ bool DoLowering(Function &F, GCStrategy &S) {
} }
case Intrinsic::gcread: { case Intrinsic::gcread: {
// Replace a read barrier with a simple load. // 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); Ld->takeName(CI);
CI->replaceAllUsesWith(Ld); CI->replaceAllUsesWith(Ld);
CI->eraseFromParent(); CI->eraseFromParent();

View File

@ -113,7 +113,7 @@ bool runImpl(Function &F, const TargetLowering *TLI, DomTreeUpdater *DTU) {
// Handle the degenerate case of no successors by replacing the indirectbr // Handle the degenerate case of no successors by replacing the indirectbr
// with unreachable as there is no successor available. // with unreachable as there is no successor available.
if (IBr->getNumSuccessors() == 0) { if (IBr->getNumSuccessors() == 0) {
(void)new UnreachableInst(F.getContext(), IBr); (void)new UnreachableInst(F.getContext(), IBr->getIterator());
IBr->eraseFromParent(); IBr->eraseFromParent();
continue; continue;
} }
@ -183,7 +183,7 @@ bool runImpl(Function &F, const TargetLowering *TLI, DomTreeUpdater *DTU) {
for (BasicBlock *SuccBB : IBr->successors()) for (BasicBlock *SuccBB : IBr->successors())
Updates.push_back({DominatorTree::Delete, IBr->getParent(), SuccBB}); Updates.push_back({DominatorTree::Delete, IBr->getParent(), SuccBB});
} }
(void)new UnreachableInst(F.getContext(), IBr); (void)new UnreachableInst(F.getContext(), IBr->getIterator());
IBr->eraseFromParent(); IBr->eraseFromParent();
} }
if (DTU) { if (DTU) {
@ -207,9 +207,10 @@ bool runImpl(Function &F, const TargetLowering *TLI, DomTreeUpdater *DTU) {
} }
auto GetSwitchValue = [CommonITy](IndirectBrInst *IBr) { auto GetSwitchValue = [CommonITy](IndirectBrInst *IBr) {
return CastInst::CreatePointerCast( return CastInst::CreatePointerCast(IBr->getAddress(), CommonITy,
IBr->getAddress(), CommonITy, Twine(IBr->getAddress()->getName()) +
Twine(IBr->getAddress()->getName()) + ".switch_cast", IBr); ".switch_cast",
IBr->getIterator());
}; };
SmallVector<DominatorTree::UpdateType, 8> Updates; 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()); Updates.reserve(IndirectBrs.size() + 2 * IndirectBrSuccs.size());
for (auto *IBr : IndirectBrs) { for (auto *IBr : IndirectBrs) {
SwitchPN->addIncoming(GetSwitchValue(IBr), IBr->getParent()); SwitchPN->addIncoming(GetSwitchValue(IBr), IBr->getParent());
BranchInst::Create(SwitchBB, IBr); BranchInst::Create(SwitchBB, IBr->getIterator());
if (DTU) { if (DTU) {
Updates.push_back({DominatorTree::Insert, IBr->getParent(), SwitchBB}); Updates.push_back({DominatorTree::Insert, IBr->getParent(), SwitchBB});
for (BasicBlock *SuccBB : IBr->successors()) for (BasicBlock *SuccBB : IBr->successors())

View File

@ -388,14 +388,15 @@ bool InterleavedAccessImpl::replaceBinOpShuffles(
return Idx < (int)cast<FixedVectorType>(BIOp0Ty)->getNumElements(); return Idx < (int)cast<FixedVectorType>(BIOp0Ty)->getNumElements();
})); }));
BasicBlock::iterator insertPos = SVI->getIterator();
auto *NewSVI1 = auto *NewSVI1 =
new ShuffleVectorInst(BI->getOperand(0), PoisonValue::get(BIOp0Ty), new ShuffleVectorInst(BI->getOperand(0), PoisonValue::get(BIOp0Ty),
Mask, SVI->getName(), SVI); Mask, SVI->getName(), insertPos);
auto *NewSVI2 = new ShuffleVectorInst( auto *NewSVI2 = new ShuffleVectorInst(
BI->getOperand(1), PoisonValue::get(BI->getOperand(1)->getType()), Mask, BI->getOperand(1), PoisonValue::get(BI->getOperand(1)->getType()), Mask,
SVI->getName(), SVI); SVI->getName(), insertPos);
BinaryOperator *NewBI = BinaryOperator::CreateWithCopiedFlags( BinaryOperator *NewBI = BinaryOperator::CreateWithCopiedFlags(
BI->getOpcode(), NewSVI1, NewSVI2, BI, BI->getName(), SVI); BI->getOpcode(), NewSVI1, NewSVI2, BI, BI->getName(), insertPos);
SVI->replaceAllUsesWith(NewBI); SVI->replaceAllUsesWith(NewBI);
LLVM_DEBUG(dbgs() << " Replaced: " << *BI << "\n And : " << *SVI LLVM_DEBUG(dbgs() << " Replaced: " << *BI << "\n And : " << *SVI
<< "\n With : " << *NewSVI1 << "\n And : " << "\n With : " << *NewSVI1 << "\n And : "

View File

@ -472,7 +472,7 @@ bool IntrinsicLowering::LowerToByteSwap(CallInst *CI) {
Function *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty); Function *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty);
Value *Op = CI->getArgOperand(0); 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->replaceAllUsesWith(Op);
CI->eraseFromParent(); CI->eraseFromParent();

View File

@ -227,7 +227,7 @@ bool runImpl(Module &M) {
// FIXME: it would be nice to make CI scheduling boundary, although in // FIXME: it would be nice to make CI scheduling boundary, although in
// practice it does not matter much. // practice it does not matter much.
auto *CI = CallInst::Create(getCheckFunctionType(Ctx), CheckFunction, auto *CI = CallInst::Create(getCheckFunctionType(Ctx), CheckFunction,
{Flag}, "", &*F.begin()->getFirstInsertionPt()); {Flag}, "", F.begin()->getFirstInsertionPt());
CI->addParamAttr(0, Attribute::NoUndef); CI->addParamAttr(0, Attribute::NoUndef);
if (UseX86FastCall) { if (UseX86FastCall) {
CI->setCallingConv(CallingConv::X86_FastCall); CI->setCallingConv(CallingConv::X86_FastCall);

View File

@ -202,7 +202,7 @@ SjLjEHPrepareImpl::setupFunctionContext(Function &F,
auto &DL = F.getParent()->getDataLayout(); auto &DL = F.getParent()->getDataLayout();
const Align Alignment = DL.getPrefTypeAlign(FunctionContextTy); const Align Alignment = DL.getPrefTypeAlign(FunctionContextTy);
FuncCtx = new AllocaInst(FunctionContextTy, DL.getAllocaAddrSpace(), nullptr, FuncCtx = new AllocaInst(FunctionContextTy, DL.getAllocaAddrSpace(), nullptr,
Alignment, "fn_context", &EntryBB->front()); Alignment, "fn_context", EntryBB->begin());
// Fill in the function context structure. // Fill in the function context structure.
for (LandingPadInst *LPI : LPads) { for (LandingPadInst *LPI : LPads) {
@ -271,7 +271,7 @@ void SjLjEHPrepareImpl::lowerIncomingArguments(Function &F) {
Value *TrueValue = ConstantInt::getTrue(F.getContext()); Value *TrueValue = ConstantInt::getTrue(F.getContext());
Value *UndefValue = UndefValue::get(Ty); Value *UndefValue = UndefValue::get(Ty);
Instruction *SI = SelectInst::Create( Instruction *SI = SelectInst::Create(
TrueValue, &AI, UndefValue, AI.getName() + ".tmp", &*AfterAllocaInsPt); TrueValue, &AI, UndefValue, AI.getName() + ".tmp", AfterAllocaInsPt);
AI.replaceAllUsesWith(SI); AI.replaceAllUsesWith(SI);
// Reset the operand, because it was clobbered by the RAUW above. // 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 (Function *Callee = II->getCalledFunction())
if (Callee->getIntrinsicID() == Intrinsic::donothing) { if (Callee->getIntrinsicID() == Intrinsic::donothing) {
// Remove the NOP invoke. // Remove the NOP invoke.
BranchInst::Create(II->getNormalDest(), II); BranchInst::Create(II->getNormalDest(), II->getIterator());
II->eraseFromParent(); II->eraseFromParent();
continue; continue;
} }
@ -445,7 +445,7 @@ bool SjLjEHPrepareImpl::setupEntryBlockAndCallSites(Function &F) {
// Record the call site value for the back end so it stays associated with // Record the call site value for the back end so it stays associated with
// the invoke. // 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 == // 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 // Register the function context and make sure it's known to not throw
CallInst *Register = CallInst *Register = CallInst::Create(
CallInst::Create(RegisterFn, FuncCtx, "", EntryBB->getTerminator()); RegisterFn, FuncCtx, "", EntryBB->getTerminator()->getIterator());
Register->setDoesNotThrow(); Register->setDoesNotThrow();
// Following any allocas not in the entry block, update the saved SP in the // 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"); Instruction *StackAddr = CallInst::Create(StackAddrFn, "sp");
StackAddr->insertAfter(&I); 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; Instruction *InsertPoint = Return;
if (CallInst *CI = Return->getParent()->getTerminatingMustTailCall()) if (CallInst *CI = Return->getParent()->getTerminatingMustTailCall())
InsertPoint = CI; InsertPoint = CI;
CallInst::Create(UnregisterFn, FuncCtx, "", InsertPoint); CallInst::Create(UnregisterFn, FuncCtx, "", InsertPoint->getIterator());
} }
return true; return true;

View File

@ -1234,10 +1234,10 @@ AllocaInst *WinEHPrepareImpl::insertPHILoads(PHINode *PN, Function &F) {
// that will dominate all uses. // that will dominate all uses.
SpillSlot = new AllocaInst(PN->getType(), DL->getAllocaAddrSpace(), nullptr, SpillSlot = new AllocaInst(PN->getType(), DL->getAllocaAddrSpace(), nullptr,
Twine(PN->getName(), ".wineh.spillslot"), Twine(PN->getName(), ".wineh.spillslot"),
&F.getEntryBlock().front()); F.getEntryBlock().begin());
Value *V = new LoadInst(PN->getType(), SpillSlot, Value *V = new LoadInst(PN->getType(), SpillSlot,
Twine(PN->getName(), ".wineh.reload"), Twine(PN->getName(), ".wineh.reload"),
&*PHIBlock->getFirstInsertionPt()); PHIBlock->getFirstInsertionPt());
PN->replaceAllUsesWith(V); PN->replaceAllUsesWith(V);
return SpillSlot; return SpillSlot;
} }
@ -1309,7 +1309,7 @@ void WinEHPrepareImpl::insertPHIStore(
} }
// Otherwise, insert the store at the end of the basic block. // 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( void WinEHPrepareImpl::replaceUseWithLoad(
@ -1319,7 +1319,7 @@ void WinEHPrepareImpl::replaceUseWithLoad(
if (!SpillSlot) if (!SpillSlot)
SpillSlot = new AllocaInst(V->getType(), DL->getAllocaAddrSpace(), nullptr, SpillSlot = new AllocaInst(V->getType(), DL->getAllocaAddrSpace(), nullptr,
Twine(V->getName(), ".wineh.spillslot"), Twine(V->getName(), ".wineh.spillslot"),
&F.getEntryBlock().front()); F.getEntryBlock().begin());
auto *UsingInst = cast<Instruction>(U.getUser()); auto *UsingInst = cast<Instruction>(U.getUser());
if (auto *UsingPHI = dyn_cast<PHINode>(UsingInst)) { if (auto *UsingPHI = dyn_cast<PHINode>(UsingInst)) {
@ -1376,16 +1376,16 @@ void WinEHPrepareImpl::replaceUseWithLoad(
Value *&Load = Loads[IncomingBlock]; Value *&Load = Loads[IncomingBlock];
// Insert the load into the predecessor block // Insert the load into the predecessor block
if (!Load) if (!Load)
Load = new LoadInst(V->getType(), SpillSlot, Load = new LoadInst(
Twine(V->getName(), ".wineh.reload"), V->getType(), SpillSlot, Twine(V->getName(), ".wineh.reload"),
/*isVolatile=*/false, IncomingBlock->getTerminator()); /*isVolatile=*/false, IncomingBlock->getTerminator()->getIterator());
U.set(Load); U.set(Load);
} else { } else {
// Reload right before the old use. // Reload right before the old use.
auto *Load = new LoadInst(V->getType(), SpillSlot, auto *Load = new LoadInst(V->getType(), SpillSlot,
Twine(V->getName(), ".wineh.reload"), Twine(V->getName(), ".wineh.reload"),
/*isVolatile=*/false, UsingInst); /*isVolatile=*/false, UsingInst->getIterator());
U.set(Load); U.set(Load);
} }
} }

View File

@ -358,7 +358,7 @@ public:
// Intentionally break the Function by inserting a terminator // Intentionally break the Function by inserting a terminator
// instruction in the middle of a basic block. // instruction in the middle of a basic block.
BasicBlock &BB = F.getEntryBlock(); BasicBlock &BB = F.getEntryBlock();
new UnreachableInst(F.getContext(), BB.getTerminator()); new UnreachableInst(F.getContext(), BB.getTerminator()->getIterator());
return PreservedAnalyses::none(); return PreservedAnalyses::none();
} }

View File

@ -1129,7 +1129,7 @@ static std::optional<Instruction *> instCombineSVELast(InstCombiner &IC,
auto *NewRHS = auto *NewRHS =
IC.Builder.CreateIntrinsic(IntrinsicID, {Vec->getType()}, {Pg, RHS}); IC.Builder.CreateIntrinsic(IntrinsicID, {Vec->getType()}, {Pg, RHS});
auto *NewBinOp = BinaryOperator::CreateWithCopiedFlags( auto *NewBinOp = BinaryOperator::CreateWithCopiedFlags(
OpC, NewLHS, NewRHS, OldBinOp, OldBinOp->getName(), &II); OpC, NewLHS, NewRHS, OldBinOp, OldBinOp->getName(), II.getIterator());
return IC.replaceInstUsesWith(II, NewBinOp); return IC.replaceInstUsesWith(II, NewBinOp);
} }
} }

View File

@ -470,9 +470,11 @@ bool AMDGPULibCalls::sincosUseNative(CallInst *aCI, const FuncInfo &FInfo) {
nf.setId(AMDGPULibFunc::EI_COS); nf.setId(AMDGPULibFunc::EI_COS);
FunctionCallee cosExpr = getFunction(M, nf); FunctionCallee cosExpr = getFunction(M, nf);
if (sinExpr && cosExpr) { if (sinExpr && cosExpr) {
Value *sinval = CallInst::Create(sinExpr, opr0, "splitsin", aCI); Value *sinval =
Value *cosval = CallInst::Create(cosExpr, opr0, "splitcos", aCI); CallInst::Create(sinExpr, opr0, "splitsin", aCI->getIterator());
new StoreInst(cosval, aCI->getArgOperand(1), aCI); 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 DEBUG_WITH_TYPE("usenative", dbgs() << "<useNative> replace " << *aCI
<< " with native version of sin/cos"); << " with native version of sin/cos");
@ -1655,7 +1657,7 @@ bool AMDGPULibCalls::evaluateCall(CallInst *aCI, const FuncInfo &FInfo) {
// sincos // sincos
assert(FInfo.getId() == AMDGPULibFunc::EI_SINCOS && assert(FInfo.getId() == AMDGPULibFunc::EI_SINCOS &&
"math function with ptr arg not supported yet"); "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); replaceCall(aCI, nval0);

View File

@ -290,8 +290,8 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
Value *sumC = ConstantInt::get(SizetTy, Sum, false); Value *sumC = ConstantInt::get(SizetTy, Sum, false);
SmallVector<Value *, 1> alloc_args; SmallVector<Value *, 1> alloc_args;
alloc_args.push_back(sumC); alloc_args.push_back(sumC);
CallInst *pcall = CallInst *pcall = CallInst::Create(PrintfAllocFn, alloc_args,
CallInst::Create(PrintfAllocFn, alloc_args, "printf_alloc_fn", CI); "printf_alloc_fn", CI->getIterator());
// //
// Insert code to split basicblock with a // Insert code to split basicblock with a
@ -309,25 +309,27 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
SplitBlock(CI->getParent(), cmp); SplitBlock(CI->getParent(), cmp);
Instruction *Brnch = Instruction *Brnch =
SplitBlockAndInsertIfThen(cmp, cmp->getNextNode(), false); SplitBlockAndInsertIfThen(cmp, cmp->getNextNode(), false);
BasicBlock::iterator BrnchPoint = Brnch->getIterator();
Builder.SetInsertPoint(Brnch); Builder.SetInsertPoint(Brnch);
// store unique printf id in the buffer // store unique printf id in the buffer
// //
GetElementPtrInst *BufferIdx = GetElementPtrInst::Create( GetElementPtrInst *BufferIdx = GetElementPtrInst::Create(
I8Ty, pcall, ConstantInt::get(Ctx, APInt(32, 0)), "PrintBuffID", Brnch); I8Ty, pcall, ConstantInt::get(Ctx, APInt(32, 0)), "PrintBuffID",
BrnchPoint);
Type *idPointer = PointerType::get(I32Ty, AMDGPUAS::GLOBAL_ADDRESS); Type *idPointer = PointerType::get(I32Ty, AMDGPUAS::GLOBAL_ADDRESS);
Value *id_gep_cast = Value *id_gep_cast =
new BitCastInst(BufferIdx, idPointer, "PrintBuffIdCast", Brnch); new BitCastInst(BufferIdx, idPointer, "PrintBuffIdCast", BrnchPoint);
new StoreInst(ConstantInt::get(I32Ty, UniqID), id_gep_cast, Brnch); new StoreInst(ConstantInt::get(I32Ty, UniqID), id_gep_cast, BrnchPoint);
// 1st 4 bytes hold the printf_id // 1st 4 bytes hold the printf_id
// the following GEP is the buffer pointer // the following GEP is the buffer pointer
BufferIdx = GetElementPtrInst::Create(I8Ty, pcall, BufferIdx = GetElementPtrInst::Create(I8Ty, pcall,
ConstantInt::get(Ctx, APInt(32, 4)), ConstantInt::get(Ctx, APInt(32, 4)),
"PrintBuffGep", Brnch); "PrintBuffGep", BrnchPoint);
Type *Int32Ty = Type::getInt32Ty(Ctx); Type *Int32Ty = Type::getInt32Ty(Ctx);
for (unsigned ArgCount = 1; for (unsigned ArgCount = 1;
@ -405,7 +407,7 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
for (unsigned I = 0, E = WhatToStore.size(); I != E; ++I) { for (unsigned I = 0, E = WhatToStore.size(); I != E; ++I) {
Value *TheBtCast = WhatToStore[I]; Value *TheBtCast = WhatToStore[I];
unsigned ArgSize = TD->getTypeAllocSize(TheBtCast->getType()); unsigned ArgSize = TD->getTypeAllocSize(TheBtCast->getType());
StoreInst *StBuff = new StoreInst(TheBtCast, BufferIdx, Brnch); StoreInst *StBuff = new StoreInst(TheBtCast, BufferIdx, BrnchPoint);
LLVM_DEBUG(dbgs() << "inserting store to printf buffer:\n" LLVM_DEBUG(dbgs() << "inserting store to printf buffer:\n"
<< *StBuff << '\n'); << *StBuff << '\n');
(void)StBuff; (void)StBuff;
@ -413,7 +415,7 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
break; break;
BufferIdx = GetElementPtrInst::Create( BufferIdx = GetElementPtrInst::Create(
I8Ty, BufferIdx, {ConstantInt::get(I32Ty, ArgSize)}, I8Ty, BufferIdx, {ConstantInt::get(I32Ty, ArgSize)},
"PrintBuffNextPtr", Brnch); "PrintBuffNextPtr", BrnchPoint);
LLVM_DEBUG(dbgs() << "inserting gep to the printf buffer:\n" LLVM_DEBUG(dbgs() << "inserting gep to the printf buffer:\n"
<< *BufferIdx << '\n'); << *BufferIdx << '\n');
} }

View File

@ -780,8 +780,9 @@ Instruction *MVEGatherScatterLowering::tryCreateIncrementingGatScat(
// Make sure the offsets are scaled correctly // Make sure the offsets are scaled correctly
Instruction *ScaledOffsets = BinaryOperator::Create( Instruction *ScaledOffsets = BinaryOperator::Create(
Instruction::Shl, OffsetsIncoming, Instruction::Shl, OffsetsIncoming,
Builder.CreateVectorSplat(Ty->getNumElements(), Builder.getInt32(TypeScale)), Builder.CreateVectorSplat(Ty->getNumElements(),
"ScaledIndex", I); Builder.getInt32(TypeScale)),
"ScaledIndex", I->getIterator());
// Add the base to the offsets // Add the base to the offsets
OffsetsIncoming = BinaryOperator::Create( OffsetsIncoming = BinaryOperator::Create(
Instruction::Add, ScaledOffsets, Instruction::Add, ScaledOffsets,
@ -790,7 +791,7 @@ Instruction *MVEGatherScatterLowering::tryCreateIncrementingGatScat(
Builder.CreatePtrToInt( Builder.CreatePtrToInt(
BasePtr, BasePtr,
cast<VectorType>(ScaledOffsets->getType())->getElementType())), cast<VectorType>(ScaledOffsets->getType())->getElementType())),
"StartIndex", I); "StartIndex", I->getIterator());
if (I->getIntrinsicID() == Intrinsic::masked_gather) if (I->getIntrinsicID() == Intrinsic::masked_gather)
return tryCreateMaskedGatherBase(I, OffsetsIncoming, Builder, Immediate); return tryCreateMaskedGatherBase(I, OffsetsIncoming, Builder, Immediate);
@ -838,7 +839,8 @@ Instruction *MVEGatherScatterLowering::tryCreateIncrementingWBGatScat(
Instruction *ScaledOffsets = BinaryOperator::Create( Instruction *ScaledOffsets = BinaryOperator::Create(
Instruction::Shl, Phi->getIncomingValue(1 - IncrementIndex), Instruction::Shl, Phi->getIncomingValue(1 - IncrementIndex),
Builder.CreateVectorSplat(NumElems, Builder.getInt32(TypeScale)), Builder.CreateVectorSplat(NumElems, Builder.getInt32(TypeScale)),
"ScaledIndex", &Phi->getIncomingBlock(1 - IncrementIndex)->back()); "ScaledIndex",
Phi->getIncomingBlock(1 - IncrementIndex)->back().getIterator());
// Add the base to the offsets // Add the base to the offsets
OffsetsIncoming = BinaryOperator::Create( OffsetsIncoming = BinaryOperator::Create(
Instruction::Add, ScaledOffsets, Instruction::Add, ScaledOffsets,
@ -847,13 +849,14 @@ Instruction *MVEGatherScatterLowering::tryCreateIncrementingWBGatScat(
Builder.CreatePtrToInt( Builder.CreatePtrToInt(
BasePtr, BasePtr,
cast<VectorType>(ScaledOffsets->getType())->getElementType())), cast<VectorType>(ScaledOffsets->getType())->getElementType())),
"StartIndex", &Phi->getIncomingBlock(1 - IncrementIndex)->back()); "StartIndex",
Phi->getIncomingBlock(1 - IncrementIndex)->back().getIterator());
// The gather is pre-incrementing // The gather is pre-incrementing
OffsetsIncoming = BinaryOperator::Create( OffsetsIncoming = BinaryOperator::Create(
Instruction::Sub, OffsetsIncoming, Instruction::Sub, OffsetsIncoming,
Builder.CreateVectorSplat(NumElems, Builder.getInt32(Immediate)), Builder.CreateVectorSplat(NumElems, Builder.getInt32(Immediate)),
"PreIncrementStartIndex", "PreIncrementStartIndex",
&Phi->getIncomingBlock(1 - IncrementIndex)->back()); Phi->getIncomingBlock(1 - IncrementIndex)->back().getIterator());
Phi->setIncomingValue(1 - IncrementIndex, OffsetsIncoming); Phi->setIncomingValue(1 - IncrementIndex, OffsetsIncoming);
Builder.SetInsertPoint(I); Builder.SetInsertPoint(I);
@ -886,8 +889,8 @@ void MVEGatherScatterLowering::pushOutAdd(PHINode *&Phi,
Value *OffsSecondOperand, Value *OffsSecondOperand,
unsigned StartIndex) { unsigned StartIndex) {
LLVM_DEBUG(dbgs() << "masked gathers/scatters: optimising add instruction\n"); LLVM_DEBUG(dbgs() << "masked gathers/scatters: optimising add instruction\n");
Instruction *InsertionPoint = BasicBlock::iterator InsertionPoint =
&cast<Instruction>(Phi->getIncomingBlock(StartIndex)->back()); Phi->getIncomingBlock(StartIndex)->back().getIterator();
// Initialize the phi with a vector that contains a sum of the constants // Initialize the phi with a vector that contains a sum of the constants
Instruction *NewIndex = BinaryOperator::Create( Instruction *NewIndex = BinaryOperator::Create(
Instruction::Add, Phi->getIncomingValue(StartIndex), OffsSecondOperand, Instruction::Add, Phi->getIncomingValue(StartIndex), OffsSecondOperand,
@ -911,8 +914,8 @@ void MVEGatherScatterLowering::pushOutMulShl(unsigned Opcode, PHINode *&Phi,
// Create a new scalar add outside of the loop and transform it to a splat // Create a new scalar add outside of the loop and transform it to a splat
// by which loop variable can be incremented // by which loop variable can be incremented
Instruction *InsertionPoint = &cast<Instruction>( BasicBlock::iterator InsertionPoint =
Phi->getIncomingBlock(LoopIncrement == 1 ? 0 : 1)->back()); Phi->getIncomingBlock(LoopIncrement == 1 ? 0 : 1)->back().getIterator();
// Create a new index // Create a new index
Value *StartIndex = Value *StartIndex =
@ -923,11 +926,14 @@ void MVEGatherScatterLowering::pushOutMulShl(unsigned Opcode, PHINode *&Phi,
Instruction *Product = Instruction *Product =
BinaryOperator::Create((Instruction::BinaryOps)Opcode, IncrementPerRound, BinaryOperator::Create((Instruction::BinaryOps)Opcode, IncrementPerRound,
OffsSecondOperand, "Product", InsertionPoint); OffsSecondOperand, "Product", InsertionPoint);
BasicBlock::iterator NewIncrInsertPt =
Phi->getIncomingBlock(LoopIncrement)->back().getIterator();
NewIncrInsertPt = std::prev(NewIncrInsertPt);
// Increment NewIndex by Product instead of the multiplication // Increment NewIndex by Product instead of the multiplication
Instruction *NewIncrement = BinaryOperator::Create( Instruction *NewIncrement = BinaryOperator::Create(
Instruction::Add, Phi, Product, "IncrementPushedOutMul", Instruction::Add, Phi, Product, "IncrementPushedOutMul", NewIncrInsertPt);
cast<Instruction>(Phi->getIncomingBlock(LoopIncrement)->back())
.getPrevNode());
Phi->addIncoming(StartIndex, Phi->addIncoming(StartIndex,
Phi->getIncomingBlock(LoopIncrement == 1 ? 0 : 1)); Phi->getIncomingBlock(LoopIncrement == 1 ? 0 : 1));
@ -1054,7 +1060,7 @@ bool MVEGatherScatterLowering::optimiseOffsets(Value *Offsets, BasicBlock *BB,
// our phi, we need to copy it // our phi, we need to copy it
IncInstruction = BinaryOperator::Create( IncInstruction = BinaryOperator::Create(
Instruction::BinaryOps(IncInstruction->getOpcode()), Phi, Instruction::BinaryOps(IncInstruction->getOpcode()), Phi,
IncrementPerRound, "LoopIncrement", IncInstruction); IncrementPerRound, "LoopIncrement", IncInstruction->getIterator());
Phi->setIncomingValue(IncrementingBlock, IncInstruction); Phi->setIncomingValue(IncrementingBlock, IncInstruction);
} }
NewPhi = Phi; NewPhi = Phi;
@ -1066,7 +1072,7 @@ bool MVEGatherScatterLowering::optimiseOffsets(Value *Offsets, BasicBlock *BB,
Phi->getIncomingBlock(IncrementingBlock == 1 ? 0 : 1)); Phi->getIncomingBlock(IncrementingBlock == 1 ? 0 : 1));
IncInstruction = BinaryOperator::Create( IncInstruction = BinaryOperator::Create(
Instruction::BinaryOps(IncInstruction->getOpcode()), NewPhi, Instruction::BinaryOps(IncInstruction->getOpcode()), NewPhi,
IncrementPerRound, "LoopIncrement", IncInstruction); IncrementPerRound, "LoopIncrement", IncInstruction->getIterator());
NewPhi->addIncoming(IncInstruction, NewPhi->addIncoming(IncInstruction,
Phi->getIncomingBlock(IncrementingBlock)); Phi->getIncomingBlock(IncrementingBlock));
IncrementingBlock = 1; IncrementingBlock = 1;
@ -1229,7 +1235,7 @@ bool MVEGatherScatterLowering::optimiseAddress(Value *Address, BasicBlock *BB,
BaseTy = FixedVectorType::get(BaseTy, VecTy); BaseTy = FixedVectorType::get(BaseTy, VecTy);
GetElementPtrInst *NewAddress = GetElementPtrInst::Create( GetElementPtrInst *NewAddress = GetElementPtrInst::Create(
Builder.getInt8Ty(), Builder.CreateBitCast(Base, BaseTy), Offsets, Builder.getInt8Ty(), Builder.CreateBitCast(Base, BaseTy), Offsets,
"gep.merged", GEP); "gep.merged", GEP->getIterator());
LLVM_DEBUG(dbgs() << "Folded GEP: " << *GEP LLVM_DEBUG(dbgs() << "Folded GEP: " << *GEP
<< "\n new : " << *NewAddress << "\n"); << "\n new : " << *NewAddress << "\n");
GEP->replaceAllUsesWith( GEP->replaceAllUsesWith(

View File

@ -426,8 +426,9 @@ static void replaceWithGEP(CallInst *Call, uint32_t DimensionIndex,
IdxList.push_back(Zero); IdxList.push_back(Zero);
IdxList.push_back(Call->getArgOperand(GEPIndex)); IdxList.push_back(Call->getArgOperand(GEPIndex));
auto *GEP = GetElementPtrInst::CreateInBounds( auto *GEP = GetElementPtrInst::CreateInBounds(getBaseElementType(Call),
getBaseElementType(Call), Call->getArgOperand(0), IdxList, "", Call); Call->getArgOperand(0), IdxList,
"", Call->getIterator());
Call->replaceAllUsesWith(GEP); Call->replaceAllUsesWith(GEP);
Call->eraseFromParent(); Call->eraseFromParent();
} }
@ -1091,9 +1092,11 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
// Load the global variable which represents the returned field info. // Load the global variable which represents the returned field info.
LoadInst *LDInst; LoadInst *LDInst;
if (IsInt32Ret) if (IsInt32Ret)
LDInst = new LoadInst(Type::getInt32Ty(BB->getContext()), GV, "", Call); LDInst = new LoadInst(Type::getInt32Ty(BB->getContext()), GV, "",
Call->getIterator());
else else
LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call); LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "",
Call->getIterator());
Instruction *PassThroughInst = Instruction *PassThroughInst =
BPFCoreSharedInfo::insertPassThrough(M, BB, LDInst, Call); BPFCoreSharedInfo::insertPassThrough(M, BB, LDInst, Call);
@ -1113,7 +1116,8 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
// The original Call inst is removed. // The original Call inst is removed.
// Load the global variable. // Load the global variable.
auto *LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call); auto *LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "",
Call->getIterator());
// Generate a BitCast // Generate a BitCast
auto *BCInst = auto *BCInst =

View File

@ -116,8 +116,8 @@ static bool BPFPreserveDITypeImpl(Function &F) {
GV->setMetadata(LLVMContext::MD_preserve_access_index, MD); GV->setMetadata(LLVMContext::MD_preserve_access_index, MD);
// Load the global variable which represents the type info. // Load the global variable which represents the type info.
auto *LDInst = auto *LDInst = new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "",
new LoadInst(Type::getInt64Ty(BB->getContext()), GV, "", Call); Call->getIterator());
Instruction *PassThroughInst = Instruction *PassThroughInst =
BPFCoreSharedInfo::insertPassThrough(M, BB, LDInst, Call); BPFCoreSharedInfo::insertPassThrough(M, BB, LDInst, Call);
Call->replaceAllUsesWith(PassThroughInst); Call->replaceAllUsesWith(PassThroughInst);

View File

@ -1109,7 +1109,7 @@ Value *HexagonCommonGEP::fabricateGEP(NodeVect &NA, BasicBlock::iterator At,
break; break;
} }
} }
NewInst = GetElementPtrInst::Create(InpTy, Input, IdxList, "cgep", &*At); NewInst = GetElementPtrInst::Create(InpTy, Input, IdxList, "cgep", At);
NewInst->setIsInBounds(RN->Flags & GepNode::InBounds); NewInst->setIsInBounds(RN->Flags & GepNode::InBounds);
LLVM_DEBUG(dbgs() << "new GEP: " << *NewInst << '\n'); LLVM_DEBUG(dbgs() << "new GEP: " << *NewInst << '\n');
if (Idx < Num) { if (Idx < Num) {

View File

@ -414,7 +414,7 @@ static bool fixupFPReturnAndCall(Function &F, Module *M,
C, Attribute::getWithMemoryEffects(C, MemoryEffects::none())); C, Attribute::getWithMemoryEffects(C, MemoryEffects::none()));
A = A.addFnAttribute(C, Attribute::NoInline); A = A.addFnAttribute(C, Attribute::NoInline);
FunctionCallee F = (M->getOrInsertFunction(Name, A, MyVoid, T)); FunctionCallee F = (M->getOrInsertFunction(Name, A, MyVoid, T));
CallInst::Create(F, Params, "", &I); CallInst::Create(F, Params, "", I.getIterator());
} else if (const CallInst *CI = dyn_cast<CallInst>(&I)) { } else if (const CallInst *CI = dyn_cast<CallInst>(&I)) {
FunctionType *FT = CI->getFunctionType(); FunctionType *FT = CI->getFunctionType();
Function *F_ = CI->getCalledFunction(); Function *F_ = CI->getCalledFunction();

View File

@ -157,7 +157,7 @@ void NVPTXImageOptimizer::replaceWith(Instruction *From, ConstantInt *To) {
else else
// Get true block // Get true block
Dest = BI->getSuccessor(0); Dest = BI->getSuccessor(0);
BranchInst::Create(Dest, BI); BranchInst::Create(Dest, BI->getIterator());
InstrToDelete.push_back(BI); InstrToDelete.push_back(BI);
} }
} }

View File

@ -183,16 +183,16 @@ static void convertToParamAS(Value *OldUser, Value *Param) {
} }
if (auto *GEP = dyn_cast<GetElementPtrInst>(I.OldInstruction)) { if (auto *GEP = dyn_cast<GetElementPtrInst>(I.OldInstruction)) {
SmallVector<Value *, 4> Indices(GEP->indices()); SmallVector<Value *, 4> Indices(GEP->indices());
auto *NewGEP = GetElementPtrInst::Create(GEP->getSourceElementType(), auto *NewGEP = GetElementPtrInst::Create(
I.NewParam, Indices, GEP->getSourceElementType(), I.NewParam, Indices, GEP->getName(),
GEP->getName(), GEP); GEP->getIterator());
NewGEP->setIsInBounds(GEP->isInBounds()); NewGEP->setIsInBounds(GEP->isInBounds());
return NewGEP; return NewGEP;
} }
if (auto *BC = dyn_cast<BitCastInst>(I.OldInstruction)) { if (auto *BC = dyn_cast<BitCastInst>(I.OldInstruction)) {
auto *NewBCType = PointerType::get(BC->getContext(), ADDRESS_SPACE_PARAM); auto *NewBCType = PointerType::get(BC->getContext(), ADDRESS_SPACE_PARAM);
return BitCastInst::Create(BC->getOpcode(), I.NewParam, NewBCType, return BitCastInst::Create(BC->getOpcode(), I.NewParam, NewBCType,
BC->getName(), BC); BC->getName(), BC->getIterator());
} }
if (auto *ASC = dyn_cast<AddrSpaceCastInst>(I.OldInstruction)) { if (auto *ASC = dyn_cast<AddrSpaceCastInst>(I.OldInstruction)) {
assert(ASC->getDestAddressSpace() == ADDRESS_SPACE_PARAM); assert(ASC->getDestAddressSpace() == ADDRESS_SPACE_PARAM);
@ -316,7 +316,7 @@ static void adjustByValArgAlignment(Argument *Arg, Value *ArgInParamAS,
void NVPTXLowerArgs::handleByValParam(const NVPTXTargetMachine &TM, void NVPTXLowerArgs::handleByValParam(const NVPTXTargetMachine &TM,
Argument *Arg) { Argument *Arg) {
Function *Func = Arg->getParent(); Function *Func = Arg->getParent();
Instruction *FirstInst = &(Func->getEntryBlock().front()); BasicBlock::iterator FirstInst = Func->getEntryBlock().begin();
Type *StructType = Arg->getParamByValType(); Type *StructType = Arg->getParamByValType();
assert(StructType && "Missing byval type"); assert(StructType && "Missing byval type");
@ -407,9 +407,9 @@ void NVPTXLowerArgs::markPointerAsGlobal(Value *Ptr) {
Instruction *PtrInGlobal = new AddrSpaceCastInst( Instruction *PtrInGlobal = new AddrSpaceCastInst(
Ptr, PointerType::get(Ptr->getContext(), ADDRESS_SPACE_GLOBAL), Ptr, PointerType::get(Ptr->getContext(), ADDRESS_SPACE_GLOBAL),
Ptr->getName(), &*InsertPt); Ptr->getName(), InsertPt);
Value *PtrInGeneric = new AddrSpaceCastInst(PtrInGlobal, Ptr->getType(), Value *PtrInGeneric = new AddrSpaceCastInst(PtrInGlobal, Ptr->getType(),
Ptr->getName(), &*InsertPt); Ptr->getName(), InsertPt);
// Replace with PtrInGeneric all uses of Ptr except PtrInGlobal. // Replace with PtrInGeneric all uses of Ptr except PtrInGlobal.
Ptr->replaceAllUsesWith(PtrInGeneric); Ptr->replaceAllUsesWith(PtrInGeneric);
PtrInGlobal->setOperand(0, Ptr); PtrInGlobal->setOperand(0, Ptr);

View File

@ -143,7 +143,7 @@ bool NVPTXLowerUnreachable::runOnFunction(Function &F) {
if (auto unreachableInst = dyn_cast<UnreachableInst>(&I)) { if (auto unreachableInst = dyn_cast<UnreachableInst>(&I)) {
if (isLoweredToTrap(*unreachableInst)) if (isLoweredToTrap(*unreachableInst))
continue; // trap is emitted as `trap; exit;`. continue; // trap is emitted as `trap; exit;`.
CallInst::Create(ExitFTy, Exit, "", unreachableInst); CallInst::Create(ExitFTy, Exit, "", unreachableInst->getIterator());
Changed = true; Changed = true;
} }
} }

View File

@ -263,7 +263,8 @@ class PPCBoolRetToInt : public FunctionPass {
Value *IntRetVal = BoolToIntMap[U]; Value *IntRetVal = BoolToIntMap[U];
Type *Int1Ty = Type::getInt1Ty(U->getContext()); Type *Int1Ty = Type::getInt1Ty(U->getContext());
auto *I = cast<Instruction>(U.getUser()); auto *I = cast<Instruction>(U.getUser());
Value *BackToBool = new TruncInst(IntRetVal, Int1Ty, "backToBool", I); Value *BackToBool =
new TruncInst(IntRetVal, Int1Ty, "backToBool", I->getIterator());
U.set(BackToBool); U.set(BackToBool);
return true; return true;

View File

@ -725,7 +725,7 @@ PPCLoopInstrFormPrep::rewriteForBase(Loop *L, const SCEVAddRecExpr *BasePtrSCEV,
Instruction *PtrInc = nullptr; Instruction *PtrInc = nullptr;
Instruction *NewBasePtr = nullptr; Instruction *NewBasePtr = nullptr;
if (CanPreInc) { if (CanPreInc) {
Instruction *InsPoint = &*Header->getFirstInsertionPt(); BasicBlock::iterator InsPoint = Header->getFirstInsertionPt();
PtrInc = GetElementPtrInst::Create( PtrInc = GetElementPtrInst::Create(
I8Ty, NewPHI, IncNode, getInstrName(BaseMemI, GEPNodeIncNameSuffix), I8Ty, NewPHI, IncNode, getInstrName(BaseMemI, GEPNodeIncNameSuffix),
InsPoint); InsPoint);
@ -752,7 +752,7 @@ PPCLoopInstrFormPrep::rewriteForBase(Loop *L, const SCEVAddRecExpr *BasePtrSCEV,
// For the latch predecessor, we need to insert a GEP just before the // For the latch predecessor, we need to insert a GEP just before the
// terminator to increase the address. // terminator to increase the address.
BasicBlock *BB = PI; BasicBlock *BB = PI;
Instruction *InsPoint = BB->getTerminator(); BasicBlock::iterator InsPoint = BB->getTerminator()->getIterator();
PtrInc = GetElementPtrInst::Create( PtrInc = GetElementPtrInst::Create(
I8Ty, NewPHI, IncNode, getInstrName(BaseMemI, GEPNodeIncNameSuffix), I8Ty, NewPHI, IncNode, getInstrName(BaseMemI, GEPNodeIncNameSuffix),
InsPoint); InsPoint);
@ -764,7 +764,7 @@ PPCLoopInstrFormPrep::rewriteForBase(Loop *L, const SCEVAddRecExpr *BasePtrSCEV,
if (NewPHI->getType() != BasePtr->getType()) if (NewPHI->getType() != BasePtr->getType())
NewBasePtr = new BitCastInst(NewPHI, BasePtr->getType(), NewBasePtr = new BitCastInst(NewPHI, BasePtr->getType(),
getInstrName(NewPHI, CastNodeNameSuffix), getInstrName(NewPHI, CastNodeNameSuffix),
&*Header->getFirstInsertionPt()); Header->getFirstInsertionPt());
else else
NewBasePtr = NewPHI; NewBasePtr = NewPHI;
} }
@ -794,20 +794,25 @@ Instruction *PPCLoopInstrFormPrep::rewriteForBucketElement(
cast<SCEVConstant>(Element.Offset)->getValue()->isZero())) { cast<SCEVConstant>(Element.Offset)->getValue()->isZero())) {
RealNewPtr = NewBasePtr; RealNewPtr = NewBasePtr;
} else { } else {
Instruction *PtrIP = dyn_cast<Instruction>(Ptr); std::optional<BasicBlock::iterator> PtrIP = std::nullopt;
if (Instruction *I = dyn_cast<Instruction>(Ptr))
PtrIP = I->getIterator();
if (PtrIP && isa<Instruction>(NewBasePtr) && if (PtrIP && isa<Instruction>(NewBasePtr) &&
cast<Instruction>(NewBasePtr)->getParent() == PtrIP->getParent()) cast<Instruction>(NewBasePtr)->getParent() == (*PtrIP)->getParent())
PtrIP = nullptr; PtrIP = std::nullopt;
else if (PtrIP && isa<PHINode>(PtrIP)) else if (PtrIP && isa<PHINode>(*PtrIP))
PtrIP = &*PtrIP->getParent()->getFirstInsertionPt(); PtrIP = (*PtrIP)->getParent()->getFirstInsertionPt();
else if (!PtrIP) else if (!PtrIP)
PtrIP = Element.Instr; PtrIP = Element.Instr->getIterator();
assert(OffToBase && "There should be an offset for non base element!\n"); assert(OffToBase && "There should be an offset for non base element!\n");
GetElementPtrInst *NewPtr = GetElementPtrInst::Create( GetElementPtrInst *NewPtr = GetElementPtrInst::Create(
I8Ty, PtrInc, OffToBase, I8Ty, PtrInc, OffToBase,
getInstrName(Element.Instr, GEPNodeOffNameSuffix), PtrIP); getInstrName(Element.Instr, GEPNodeOffNameSuffix));
if (!PtrIP) if (PtrIP)
NewPtr->insertBefore(*(*PtrIP)->getParent(), *PtrIP);
else
NewPtr->insertAfter(cast<Instruction>(PtrInc)); NewPtr->insertAfter(cast<Instruction>(PtrInc));
NewPtr->setIsInBounds(IsPtrInBounds(Ptr)); NewPtr->setIsInBounds(IsPtrInBounds(Ptr));
RealNewPtr = NewPtr; RealNewPtr = NewPtr;

View File

@ -231,7 +231,7 @@ bool RISCVGatherScatterLowering::matchStridedRecurrence(Value *Index, Loop *L,
BasePtr = BasePtr =
PHINode::Create(Start->getType(), 2, Phi->getName() + ".scalar", Phi->getIterator()); PHINode::Create(Start->getType(), 2, Phi->getName() + ".scalar", Phi->getIterator());
Inc = BinaryOperator::CreateAdd(BasePtr, Step, Inc->getName() + ".scalar", Inc = BinaryOperator::CreateAdd(BasePtr, Step, Inc->getName() + ".scalar",
Inc); Inc->getIterator());
BasePtr->addIncoming(Start, Phi->getIncomingBlock(1 - IncrementingBlock)); BasePtr->addIncoming(Start, Phi->getIncomingBlock(1 - IncrementingBlock));
BasePtr->addIncoming(Inc, Phi->getIncomingBlock(IncrementingBlock)); BasePtr->addIncoming(Inc, Phi->getIncomingBlock(IncrementingBlock));

View File

@ -1283,9 +1283,9 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function &F) {
DebugLoc FirstDL = getOrCreateDebugLoc(&*Entry->begin(), F.getSubprogram()); DebugLoc FirstDL = getOrCreateDebugLoc(&*Entry->begin(), F.getSubprogram());
SplitBlock(Entry, &*Entry->getFirstInsertionPt()); SplitBlock(Entry, &*Entry->getFirstInsertionPt());
BinaryOperator *SetjmpTableSize = BinaryOperator *SetjmpTableSize = BinaryOperator::Create(
BinaryOperator::Create(Instruction::Add, IRB.getInt32(4), IRB.getInt32(0), Instruction::Add, IRB.getInt32(4), IRB.getInt32(0), "setjmpTableSize",
"setjmpTableSize", Entry->getTerminator()); Entry->getTerminator()->getIterator());
SetjmpTableSize->setDebugLoc(FirstDL); SetjmpTableSize->setDebugLoc(FirstDL);
// setjmpTable = (int *) malloc(40); // setjmpTable = (int *) malloc(40);
Type *IntPtrTy = getAddrIntType(&M); Type *IntPtrTy = getAddrIntType(&M);

View File

@ -73,7 +73,7 @@ bool WebAssemblyLowerRefTypesIntPtrConv::runOnFunction(Function &F) {
Function *TrapIntrin = Function *TrapIntrin =
Intrinsic::getDeclaration(F.getParent(), Intrinsic::debugtrap); Intrinsic::getDeclaration(F.getParent(), Intrinsic::debugtrap);
CallInst::Create(TrapIntrin, {}, "", &*I); CallInst::Create(TrapIntrin, {}, "", I->getIterator());
worklist.insert(&*I); worklist.insert(&*I);
} }

View File

@ -102,7 +102,7 @@ static AllocaInst *createAllocaInstAtEntry(IRBuilder<> &Builder, BasicBlock *BB,
auto AllocaAlignment = DL.getPrefTypeAlign(Type::getX86_AMXTy(Ctx)); auto AllocaAlignment = DL.getPrefTypeAlign(Type::getX86_AMXTy(Ctx));
unsigned AllocaAS = DL.getAllocaAddrSpace(); unsigned AllocaAS = DL.getAllocaAddrSpace();
AllocaInst *AllocaRes = AllocaInst *AllocaRes =
new AllocaInst(Ty, AllocaAS, "", &F.getEntryBlock().front()); new AllocaInst(Ty, AllocaAS, "", F.getEntryBlock().begin());
AllocaRes->setAlignment(AllocaAlignment); AllocaRes->setAlignment(AllocaAlignment);
return AllocaRes; return AllocaRes;
} }
@ -453,7 +453,7 @@ static Value *getAllocaPos(BasicBlock *BB) {
unsigned AllocaAS = DL.getAllocaAddrSpace(); unsigned AllocaAS = DL.getAllocaAddrSpace();
Type *V256I32Ty = VectorType::get(Builder.getInt32Ty(), 256, false); Type *V256I32Ty = VectorType::get(Builder.getInt32Ty(), 256, false);
AllocaInst *AllocaRes = AllocaInst *AllocaRes =
new AllocaInst(V256I32Ty, AllocaAS, "", &F->getEntryBlock().front()); new AllocaInst(V256I32Ty, AllocaAS, "", F->getEntryBlock().begin());
BasicBlock::iterator Iter = AllocaRes->getIterator(); BasicBlock::iterator Iter = AllocaRes->getIterator();
++Iter; ++Iter;
Builder.SetInsertPoint(&*Iter); Builder.SetInsertPoint(&*Iter);

View File

@ -1212,7 +1212,7 @@ bool IslNodeBuilder::preloadInvariantEquivClass(
BasicBlock *EntryBB = &Builder.GetInsertBlock()->getParent()->getEntryBlock(); BasicBlock *EntryBB = &Builder.GetInsertBlock()->getParent()->getEntryBlock();
auto *Alloca = new AllocaInst(AccInstTy, DL.getAllocaAddrSpace(), auto *Alloca = new AllocaInst(AccInstTy, DL.getAllocaAddrSpace(),
AccInst->getName() + ".preload.s2a", AccInst->getName() + ".preload.s2a",
&*EntryBB->getFirstInsertionPt()); EntryBB->getFirstInsertionPt());
Builder.CreateStore(PreloadVal, Alloca); Builder.CreateStore(PreloadVal, Alloca);
ValueMapT PreloadedPointer; ValueMapT PreloadedPointer;
PreloadedPointer[PreloadVal] = AccInst; PreloadedPointer[PreloadVal] = AccInst;
@ -1308,10 +1308,11 @@ void IslNodeBuilder::allocateNewArrays(BBPair StartExitBlocks) {
auto InstIt = Builder.GetInsertBlock() auto InstIt = Builder.GetInsertBlock()
->getParent() ->getParent()
->getEntryBlock() ->getEntryBlock()
.getTerminator(); .getTerminator()
->getIterator();
auto *CreatedArray = new AllocaInst(NewArrayType, DL.getAllocaAddrSpace(), auto *CreatedArray = new AllocaInst(NewArrayType, DL.getAllocaAddrSpace(),
SAI->getName(), &*InstIt); SAI->getName(), InstIt);
if (PollyTargetFirstLevelCacheLineSize) if (PollyTargetFirstLevelCacheLineSize)
CreatedArray->setAlignment(Align(PollyTargetFirstLevelCacheLineSize)); CreatedArray->setAlignment(Align(PollyTargetFirstLevelCacheLineSize));
SAI->setBasePtr(CreatedArray); SAI->setBasePtr(CreatedArray);

View File

@ -225,7 +225,7 @@ ParallelLoopGenerator::storeValuesIntoStruct(SetVector<Value *> &Values) {
// in the entry block of the function and use annotations to denote the actual // in the entry block of the function and use annotations to denote the actual
// live span (similar to clang). // live span (similar to clang).
BasicBlock &EntryBB = Builder.GetInsertBlock()->getParent()->getEntryBlock(); BasicBlock &EntryBB = Builder.GetInsertBlock()->getParent()->getEntryBlock();
Instruction *IP = &*EntryBB.getFirstInsertionPt(); BasicBlock::iterator IP = EntryBB.getFirstInsertionPt();
StructType *Ty = StructType::get(Builder.getContext(), Members); StructType *Ty = StructType::get(Builder.getContext(), Members);
AllocaInst *Struct = new AllocaInst(Ty, DL.getAllocaAddrSpace(), nullptr, AllocaInst *Struct = new AllocaInst(Ty, DL.getAllocaAddrSpace(), nullptr,
"polly.par.userContext", IP); "polly.par.userContext", IP);

View File

@ -328,8 +328,9 @@ private:
Value *LHS = expandCodeFor(LHSScev, E->getType(), IP); Value *LHS = expandCodeFor(LHSScev, E->getType(), IP);
Value *RHS = expandCodeFor(RHSScev, E->getType(), IP); Value *RHS = expandCodeFor(RHSScev, E->getType(), IP);
Inst = BinaryOperator::Create((Instruction::BinaryOps)Inst->getOpcode(), Inst =
LHS, RHS, Inst->getName() + Name, IP); BinaryOperator::Create((Instruction::BinaryOps)Inst->getOpcode(), LHS,
RHS, Inst->getName() + Name, IP->getIterator());
return SE.getSCEV(Inst); return SE.getSCEV(Inst);
} }