Skip to content

Commit 6c7805d

Browse files
committed
Revert "[NFC][RemoveDIs] Bulk update utilities to insert with iterators"
This reverts commit 3fda50d. Apparently I've missed a hunk while staging this; will back out for now. Picked up here: https://lab.llvm.org/buildbot/#/builders/139/builds/60429/steps/6/logs/stdio
1 parent c4c35d9 commit 6c7805d

32 files changed

+120
-120
lines changed

llvm/include/llvm/IR/Instructions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,14 +1298,14 @@ class ICmpInst: public CmpInst {
12981298

12991299
/// Constructor with insert-at-end semantics.
13001300
ICmpInst(
1301-
BasicBlock *InsertAtEnd, ///< Block to insert into.
1301+
BasicBlock &InsertAtEnd, ///< Block to insert into.
13021302
Predicate pred, ///< The predicate to use for the comparison
13031303
Value *LHS, ///< The left-hand-side of the expression
13041304
Value *RHS, ///< The right-hand-side of the expression
13051305
const Twine &NameStr = "" ///< Name of the instruction
13061306
) : CmpInst(makeCmpResultType(LHS->getType()),
13071307
Instruction::ICmp, pred, LHS, RHS, NameStr,
1308-
InsertAtEnd) {
1308+
&InsertAtEnd) {
13091309
#ifndef NDEBUG
13101310
AssertOK();
13111311
#endif
@@ -1481,14 +1481,14 @@ class FCmpInst: public CmpInst {
14811481

14821482
/// Constructor with insert-at-end semantics.
14831483
FCmpInst(
1484-
BasicBlock *InsertAtEnd, ///< Block to insert into.
1484+
BasicBlock &InsertAtEnd, ///< Block to insert into.
14851485
Predicate pred, ///< The predicate to use for the comparison
14861486
Value *LHS, ///< The left-hand-side of the expression
14871487
Value *RHS, ///< The right-hand-side of the expression
14881488
const Twine &NameStr = "" ///< Name of the instruction
14891489
) : CmpInst(makeCmpResultType(LHS->getType()),
14901490
Instruction::FCmp, pred, LHS, RHS, NameStr,
1491-
InsertAtEnd) {
1491+
&InsertAtEnd) {
14921492
AssertOK();
14931493
}
14941494

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ bool FoldBranchToCommonDest(BranchInst *BI, llvm::DomTreeUpdater *DTU = nullptr,
206206
/// to create a stack slot for X.
207207
AllocaInst *DemoteRegToStack(Instruction &X,
208208
bool VolatileLoads = false,
209-
std::optional<BasicBlock::iterator> AllocaPoint = std::nullopt);
209+
Instruction *AllocaPoint = nullptr);
210210

211211
/// This function takes a virtual register computed by a phi node and replaces
212212
/// it with a slot in the stack frame, allocated via alloca. The phi node is
213213
/// deleted and it returns the pointer to the alloca inserted.
214-
AllocaInst *DemotePHIToStack(PHINode *P, std::optional<BasicBlock::iterator> AllocaPoint = std::nullopt);
214+
AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
215215

216216
/// If the specified pointer points to an object that we control, try to modify
217217
/// the object's alignment to PrefAlign. Returns a minimum known alignment of

llvm/lib/IR/Instructions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4608,10 +4608,10 @@ CmpInst *
46084608
CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
46094609
const Twine &Name, BasicBlock *InsertAtEnd) {
46104610
if (Op == Instruction::ICmp) {
4611-
return new ICmpInst(InsertAtEnd, CmpInst::Predicate(predicate),
4611+
return new ICmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
46124612
S1, S2, Name);
46134613
}
4614-
return new FCmpInst(InsertAtEnd, CmpInst::Predicate(predicate),
4614+
return new FCmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
46154615
S1, S2, Name);
46164616
}
46174617

llvm/lib/Transforms/CFGuard/CFGuard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void CFGuardImpl::insertCFGuardDispatch(CallBase *CB) {
219219
// Create a copy of the call/invoke instruction and add the new bundle.
220220
assert((isa<CallInst>(CB) || isa<InvokeInst>(CB)) &&
221221
"Unknown indirect call type");
222-
CallBase *NewCB = CallBase::Create(CB, Bundles, CB->getIterator());
222+
CallBase *NewCB = CallBase::Create(CB, Bundles, CB);
223223

224224
// Change the target of the call to be the guard dispatch function.
225225
NewCB->setCalledOperand(GuardDispatchLoad);

llvm/lib/Transforms/Scalar/Reg2Mem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static bool runPass(Function &F) {
6464

6565
CastInst *AllocaInsertionPoint = new BitCastInst(
6666
Constant::getNullValue(Type::getInt32Ty(F.getContext())),
67-
Type::getInt32Ty(F.getContext()), "reg2mem alloca point", I);
67+
Type::getInt32Ty(F.getContext()), "reg2mem alloca point", &*I);
6868

6969
// Find the escaped instructions. But don't create stack slots for
7070
// allocas in entry block.
@@ -76,7 +76,7 @@ static bool runPass(Function &F) {
7676
// Demote escaped instructions
7777
NumRegsDemoted += WorkList.size();
7878
for (Instruction *I : WorkList)
79-
DemoteRegToStack(*I, false, AllocaInsertionPoint->getIterator());
79+
DemoteRegToStack(*I, false, AllocaInsertionPoint);
8080

8181
WorkList.clear();
8282

@@ -88,7 +88,7 @@ static bool runPass(Function &F) {
8888
// Demote phi nodes
8989
NumPhisDemoted += WorkList.size();
9090
for (Instruction *I : WorkList)
91-
DemotePHIToStack(cast<PHINode>(I), AllocaInsertionPoint->getIterator());
91+
DemotePHIToStack(cast<PHINode>(I), AllocaInsertionPoint);
9292

9393
return true;
9494
}

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB,
12971297
// PHI.
12981298
// Create the new PHI node, insert it into NewBB at the end of the block
12991299
PHINode *NewPHI =
1300-
PHINode::Create(PN->getType(), Preds.size(), PN->getName() + ".ph", BI->getIterator());
1300+
PHINode::Create(PN->getType(), Preds.size(), PN->getName() + ".ph", BI);
13011301

13021302
// NOTE! This loop walks backwards for a reason! First off, this minimizes
13031303
// the cost of removal if we end up removing a large number of values, and
@@ -1517,7 +1517,7 @@ static void SplitLandingPadPredecessorsImpl(
15171517
assert(!LPad->getType()->isTokenTy() &&
15181518
"Split cannot be applied if LPad is token type. Otherwise an "
15191519
"invalid PHINode of token type would be created.");
1520-
PHINode *PN = PHINode::Create(LPad->getType(), 2, "lpad.phi", LPad->getIterator());
1520+
PHINode *PN = PHINode::Create(LPad->getType(), 2, "lpad.phi", LPad);
15211521
PN->addIncoming(Clone1, NewBB1);
15221522
PN->addIncoming(Clone2, NewBB2);
15231523
LPad->replaceAllUsesWith(PN);
@@ -1904,7 +1904,7 @@ static void reconnectPhis(BasicBlock *Out, BasicBlock *GuardBlock,
19041904
auto Phi = cast<PHINode>(I);
19051905
auto NewPhi =
19061906
PHINode::Create(Phi->getType(), Incoming.size(),
1907-
Phi->getName() + ".moved", FirstGuardBlock->begin());
1907+
Phi->getName() + ".moved", &FirstGuardBlock->front());
19081908
for (auto *In : Incoming) {
19091909
Value *V = UndefValue::get(Phi->getType());
19101910
if (In == Out) {
@@ -2023,7 +2023,7 @@ static void calcPredicateUsingInteger(
20232023
Value *Id1 = ConstantInt::get(Type::getInt32Ty(Context),
20242024
std::distance(Outgoing.begin(), Succ1Iter));
20252025
IncomingId = SelectInst::Create(Condition, Id0, Id1, "target.bb.idx",
2026-
In->getTerminator()->getIterator());
2026+
In->getTerminator());
20272027
} else {
20282028
// Get the index of the non-null successor.
20292029
auto SuccIter = Succ0 ? find(Outgoing, Succ0) : find(Outgoing, Succ1);

llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ bool llvm::SplitIndirectBrCriticalEdges(Function &F,
420420
// (b) Leave that as the only edge in the "Indirect" PHI.
421421
// (c) Merge the two in the body block.
422422
BasicBlock::iterator Indirect = Target->begin(),
423-
End = Target->getFirstNonPHIIt();
423+
End = Target->getFirstNonPHI()->getIterator();
424424
BasicBlock::iterator Direct = DirectSucc->begin();
425425
BasicBlock::iterator MergeInsert = BodyBlock->getFirstInsertionPt();
426426

@@ -430,7 +430,6 @@ bool llvm::SplitIndirectBrCriticalEdges(Function &F,
430430
while (Indirect != End) {
431431
PHINode *DirPHI = cast<PHINode>(Direct);
432432
PHINode *IndPHI = cast<PHINode>(Indirect);
433-
BasicBlock::iterator InsertPt = Indirect;
434433

435434
// Now, clean up - the direct block shouldn't get the indirect value,
436435
// and vice versa.
@@ -441,7 +440,7 @@ bool llvm::SplitIndirectBrCriticalEdges(Function &F,
441440
// PHI is erased.
442441
Indirect++;
443442

444-
PHINode *NewIndPHI = PHINode::Create(IndPHI->getType(), 1, "ind", InsertPt);
443+
PHINode *NewIndPHI = PHINode::Create(IndPHI->getType(), 1, "ind", IndPHI);
445444
NewIndPHI->addIncoming(IndPHI->getIncomingValueForBlock(IBRPred),
446445
IBRPred);
447446

llvm/lib/Transforms/Utils/CallPromotionUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ static void createRetBitCast(CallBase &CB, Type *RetTy, CastInst **RetBitCast) {
168168

169169
// Determine an appropriate location to create the bitcast for the return
170170
// value. The location depends on if we have a call or invoke instruction.
171-
BasicBlock::iterator InsertBefore;
171+
Instruction *InsertBefore = nullptr;
172172
if (auto *Invoke = dyn_cast<InvokeInst>(&CB))
173173
InsertBefore =
174-
SplitEdge(Invoke->getParent(), Invoke->getNormalDest())->begin();
174+
&SplitEdge(Invoke->getParent(), Invoke->getNormalDest())->front();
175175
else
176-
InsertBefore = std::next(CB.getIterator());
176+
InsertBefore = &*std::next(CB.getIterator());
177177

178178
// Bitcast the return value to the correct type.
179179
auto *Cast = CastInst::CreateBitOrPointerCast(&CB, RetTy, "", InsertBefore);
@@ -509,7 +509,7 @@ CallBase &llvm::promoteCall(CallBase &CB, Function *Callee,
509509
Type *FormalTy = CalleeType->getParamType(ArgNo);
510510
Type *ActualTy = Arg->getType();
511511
if (FormalTy != ActualTy) {
512-
auto *Cast = CastInst::CreateBitOrPointerCast(Arg, FormalTy, "", CB.getIterator());
512+
auto *Cast = CastInst::CreateBitOrPointerCast(Arg, FormalTy, "", &CB);
513513
CB.setArgOperand(ArgNo, Cast);
514514

515515
// Remove any incompatible attributes for the argument.

llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void CanonicalizeFreezeInLoopsImpl::InsertFreezeAndForgetFromSCEV(Use &U) {
144144
LLVM_DEBUG(dbgs() << "\tOperand: " << *U.get() << "\n");
145145

146146
U.set(new FreezeInst(ValueToFr, ValueToFr->getName() + ".frozen",
147-
PH->getTerminator()->getIterator()));
147+
PH->getTerminator()));
148148

149149
SE.forgetValue(UserI);
150150
}

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void CodeExtractor::findAllocas(const CodeExtractorAnalysisCache &CEAC,
570570
LLVMContext &Ctx = M->getContext();
571571
auto *Int8PtrTy = PointerType::getUnqual(Ctx);
572572
CastInst *CastI =
573-
CastInst::CreatePointerCast(AI, Int8PtrTy, "lt.cast", I->getIterator());
573+
CastInst::CreatePointerCast(AI, Int8PtrTy, "lt.cast", I);
574574
I->replaceUsesOfWith(I->getOperand(1), CastI);
575575
}
576576

@@ -1024,7 +1024,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
10241024
Value *Idx[2];
10251025
Idx[0] = Constant::getNullValue(Type::getInt32Ty(header->getContext()));
10261026
Idx[1] = ConstantInt::get(Type::getInt32Ty(header->getContext()), aggIdx);
1027-
BasicBlock::iterator TI = newFunction->begin()->getTerminator()->getIterator();
1027+
Instruction *TI = newFunction->begin()->getTerminator();
10281028
GetElementPtrInst *GEP = GetElementPtrInst::Create(
10291029
StructTy, &*AggAI, Idx, "gep_" + inputs[i]->getName(), TI);
10301030
RewriteVal = new LoadInst(StructTy->getElementType(aggIdx), GEP,
@@ -1173,7 +1173,7 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction,
11731173
AllocaInst *alloca =
11741174
new AllocaInst(output->getType(), DL.getAllocaAddrSpace(),
11751175
nullptr, output->getName() + ".loc",
1176-
codeReplacer->getParent()->front().begin());
1176+
&codeReplacer->getParent()->front().front());
11771177
ReloadOutputs.push_back(alloca);
11781178
params.push_back(alloca);
11791179
++ScalarOutputArgNo;
@@ -1192,8 +1192,8 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction,
11921192
StructArgTy = StructType::get(newFunction->getContext(), ArgTypes);
11931193
Struct = new AllocaInst(
11941194
StructArgTy, DL.getAllocaAddrSpace(), nullptr, "structArg",
1195-
AllocationBlock ? AllocationBlock->getFirstInsertionPt()
1196-
: codeReplacer->getParent()->front().begin());
1195+
AllocationBlock ? &*AllocationBlock->getFirstInsertionPt()
1196+
: &codeReplacer->getParent()->front().front());
11971197

11981198
if (ArgsInZeroAddressSpace && DL.getAllocaAddrSpace() != 0) {
11991199
auto *StructSpaceCast = new AddrSpaceCastInst(
@@ -1358,8 +1358,9 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction,
13581358
else
13591359
InsertPt = std::next(OutI->getIterator());
13601360

1361-
assert((InsertPt->getFunction() == newFunction ||
1362-
Blocks.count(InsertPt->getParent())) &&
1361+
Instruction *InsertBefore = &*InsertPt;
1362+
assert((InsertBefore->getFunction() == newFunction ||
1363+
Blocks.count(InsertBefore->getParent())) &&
13631364
"InsertPt should be in new function");
13641365
if (AggregateArgs && StructValues.contains(outputs[i])) {
13651366
assert(AggOutputArgBegin != newFunction->arg_end() &&
@@ -1370,8 +1371,8 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction,
13701371
Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), aggIdx);
13711372
GetElementPtrInst *GEP = GetElementPtrInst::Create(
13721373
StructArgTy, &*AggOutputArgBegin, Idx, "gep_" + outputs[i]->getName(),
1373-
InsertPt);
1374-
new StoreInst(outputs[i], GEP, InsertPt);
1374+
InsertBefore);
1375+
new StoreInst(outputs[i], GEP, InsertBefore);
13751376
++aggIdx;
13761377
// Since there should be only one struct argument aggregating
13771378
// all the output values, we shouldn't increment AggOutputArgBegin, which
@@ -1380,7 +1381,7 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction,
13801381
assert(ScalarOutputArgBegin != newFunction->arg_end() &&
13811382
"Number of scalar output arguments should match "
13821383
"the number of defined values");
1383-
new StoreInst(outputs[i], &*ScalarOutputArgBegin, InsertPt);
1384+
new StoreInst(outputs[i], &*ScalarOutputArgBegin, InsertBefore);
13841385
++ScalarOutputArgBegin;
13851386
}
13861387
}
@@ -1395,28 +1396,28 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction,
13951396

13961397
// Check if the function should return a value
13971398
if (OldFnRetTy->isVoidTy()) {
1398-
ReturnInst::Create(Context, nullptr, TheSwitch->getIterator()); // Return void
1399+
ReturnInst::Create(Context, nullptr, TheSwitch); // Return void
13991400
} else if (OldFnRetTy == TheSwitch->getCondition()->getType()) {
14001401
// return what we have
1401-
ReturnInst::Create(Context, TheSwitch->getCondition(), TheSwitch->getIterator());
1402+
ReturnInst::Create(Context, TheSwitch->getCondition(), TheSwitch);
14021403
} else {
14031404
// Otherwise we must have code extracted an unwind or something, just
14041405
// return whatever we want.
14051406
ReturnInst::Create(Context,
1406-
Constant::getNullValue(OldFnRetTy), TheSwitch->getIterator());
1407+
Constant::getNullValue(OldFnRetTy), TheSwitch);
14071408
}
14081409

14091410
TheSwitch->eraseFromParent();
14101411
break;
14111412
case 1:
14121413
// Only a single destination, change the switch into an unconditional
14131414
// branch.
1414-
BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch->getIterator());
1415+
BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch);
14151416
TheSwitch->eraseFromParent();
14161417
break;
14171418
case 2:
14181419
BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch->getSuccessor(2),
1419-
call, TheSwitch->getIterator());
1420+
call, TheSwitch);
14201421
TheSwitch->eraseFromParent();
14211422
break;
14221423
default:

0 commit comments

Comments
 (0)