Skip to content

Commit be4d8cb

Browse files
committed
Scalar: Remove remaining ilist iterator implicit conversions
Remove remaining `ilist_iterator` implicit conversions from LLVMScalarOpts. This change exposed some scary behaviour in lib/Transforms/Scalar/SCCP.cpp around line 1770. This patch changes a call from `Function::begin()` to `&Function::front()`, since the return was immediately being passed into another function that takes a `Function*`. `Function::front()` started to assert, since the function was empty. Note that `Function::end()` does not point at a legal `Function*` -- it points at an `ilist_half_node` -- so the other function was getting garbage before. (I added the missing check for `Function::isDeclaration()`.) Otherwise, no functionality change intended. llvm-svn: 250211
1 parent ea244fc commit be4d8cb

27 files changed

+240
-240
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ static Instruction *CloneInstructionInExitBlock(const Instruction &I,
587587
if (!OLoop->contains(&PN)) {
588588
PHINode *OpPN =
589589
PHINode::Create(OInst->getType(), PN.getNumIncomingValues(),
590-
OInst->getName() + ".lcssa", ExitBlock.begin());
590+
OInst->getName() + ".lcssa", &ExitBlock.front());
591591
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
592592
OpPN->addIncoming(OInst, PN.getIncomingBlock(i));
593593
*OI = OpPN;
@@ -751,9 +751,9 @@ namespace {
751751
if (!L->contains(BB)) {
752752
// We need to create an LCSSA PHI node for the incoming value and
753753
// store that.
754-
PHINode *PN = PHINode::Create(
755-
I->getType(), PredCache.size(BB),
756-
I->getName() + ".lcssa", BB->begin());
754+
PHINode *PN =
755+
PHINode::Create(I->getType(), PredCache.size(BB),
756+
I->getName() + ".lcssa", &BB->front());
757757
for (BasicBlock *Pred : PredCache.get(BB))
758758
PN->addIncoming(I, Pred);
759759
return PN;
@@ -963,7 +963,7 @@ bool llvm::promoteLoopAccessesToScalars(AliasSet &AS,
963963
CurLoop->getUniqueExitBlocks(ExitBlocks);
964964
InsertPts.resize(ExitBlocks.size());
965965
for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
966-
InsertPts[i] = ExitBlocks[i]->getFirstInsertionPt();
966+
InsertPts[i] = &*ExitBlocks[i]->getFirstInsertionPt();
967967
}
968968

969969
// We use the SSAUpdater interface to insert phi nodes as required.

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ bool LoopIdiomRecognize::runOnLoopBlock(
258258

259259
bool MadeChange = false;
260260
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
261-
Instruction *Inst = I++;
261+
Instruction *Inst = &*I++;
262262
// Look for store instructions, which may be optimized to memset/memcpy.
263263
if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
264-
WeakVH InstPtr(I);
264+
WeakVH InstPtr(&*I);
265265
if (!processLoopStore(SI, BECount))
266266
continue;
267267
MadeChange = true;
@@ -275,7 +275,7 @@ bool LoopIdiomRecognize::runOnLoopBlock(
275275

276276
// Look for memset instructions, which may be optimized to a larger memset.
277277
if (MemSetInst *MSI = dyn_cast<MemSetInst>(Inst)) {
278-
WeakVH InstPtr(I);
278+
WeakVH InstPtr(&*I);
279279
if (!processLoopMemSet(MSI, BECount))
280280
continue;
281281
MadeChange = true;
@@ -416,7 +416,7 @@ static bool mayLoopAccessLocation(Value *Ptr, ModRefInfo Access, Loop *L,
416416
for (Loop::block_iterator BI = L->block_begin(), E = L->block_end(); BI != E;
417417
++BI)
418418
for (BasicBlock::iterator I = (*BI)->begin(), E = (*BI)->end(); I != E; ++I)
419-
if (&*I != IgnoredStore && (AA.getModRefInfo(I, StoreLoc) & Access))
419+
if (&*I != IgnoredStore && (AA.getModRefInfo(&*I, StoreLoc) & Access))
420420
return true;
421421

422422
return false;
@@ -777,10 +777,10 @@ static bool detectPopcountIdiom(Loop *CurLoop, BasicBlock *PreCondBB,
777777
// step 4: Find the instruction which count the population: cnt2 = cnt1 + 1
778778
{
779779
CountInst = nullptr;
780-
for (BasicBlock::iterator Iter = LoopEntry->getFirstNonPHI(),
780+
for (BasicBlock::iterator Iter = LoopEntry->getFirstNonPHI()->getIterator(),
781781
IterE = LoopEntry->end();
782782
Iter != IterE; Iter++) {
783-
Instruction *Inst = Iter;
783+
Instruction *Inst = &*Iter;
784784
if (Inst->getOpcode() != Instruction::Add)
785785
continue;
786786

@@ -972,7 +972,7 @@ void LoopIdiomRecognize::transformLoopToPopcount(BasicBlock *PreCondBB,
972972
ICmpInst *LbCond = cast<ICmpInst>(LbBr->getCondition());
973973
Type *Ty = TripCnt->getType();
974974

975-
PHINode *TcPhi = PHINode::Create(Ty, 2, "tcphi", Body->begin());
975+
PHINode *TcPhi = PHINode::Create(Ty, 2, "tcphi", &Body->front());
976976

977977
Builder.SetInsertPoint(LbCond);
978978
Instruction *TcDec = cast<Instruction>(

llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ bool LoopInstSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
112112

113113
// Simplify instructions in the current basic block.
114114
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
115-
Instruction *I = BI++;
115+
Instruction *I = &*BI++;
116116

117117
// The first time through the loop ToSimplify is empty and we try to
118118
// simplify all instructions. On later iterations ToSimplify is not

llvm/lib/Transforms/Scalar/LoopInterchange.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
9999
return false;
100100
if (St && !St->isSimple())
101101
return false;
102-
MemInstr.push_back(I);
102+
MemInstr.push_back(&*I);
103103
}
104104
}
105105

@@ -1113,8 +1113,8 @@ static void moveBBContents(BasicBlock *FromBB, Instruction *InsertBefore) {
11131113
auto &ToList = InsertBefore->getParent()->getInstList();
11141114
auto &FromList = FromBB->getInstList();
11151115

1116-
ToList.splice(InsertBefore, FromList, FromList.begin(),
1117-
FromBB->getTerminator());
1116+
ToList.splice(InsertBefore->getIterator(), FromList, FromList.begin(),
1117+
FromBB->getTerminator()->getIterator());
11181118
}
11191119

11201120
void LoopInterchangeTransform::adjustOuterLoopPreheader() {

llvm/lib/Transforms/Scalar/LoopRerollPass.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ void LoopReroll::collectPossibleIVs(Loop *L,
484484
continue;
485485

486486
if (const SCEVAddRecExpr *PHISCEV =
487-
dyn_cast<SCEVAddRecExpr>(SE->getSCEV(I))) {
487+
dyn_cast<SCEVAddRecExpr>(SE->getSCEV(&*I))) {
488488
if (PHISCEV->getLoop() != L)
489489
continue;
490490
if (!PHISCEV->isAffine())
@@ -494,10 +494,10 @@ void LoopReroll::collectPossibleIVs(Loop *L,
494494
const APInt &AInt = IncSCEV->getValue()->getValue().abs();
495495
if (IncSCEV->getValue()->isZero() || AInt.uge(MaxInc))
496496
continue;
497-
IVToIncMap[I] = IncSCEV->getValue()->getSExtValue();
497+
IVToIncMap[&*I] = IncSCEV->getValue()->getSExtValue();
498498
DEBUG(dbgs() << "LRR: Possible IV: " << *I << " = " << *PHISCEV
499499
<< "\n");
500-
PossibleIVs.push_back(I);
500+
PossibleIVs.push_back(&*I);
501501
}
502502
}
503503
}
@@ -558,7 +558,7 @@ void LoopReroll::collectPossibleReductions(Loop *L,
558558
if (!I->getType()->isSingleValueType())
559559
continue;
560560

561-
SimpleLoopReduction SLR(I, L);
561+
SimpleLoopReduction SLR(&*I, L);
562562
if (!SLR.valid())
563563
continue;
564564

@@ -1297,7 +1297,7 @@ void LoopReroll::DAGRootTracker::replace(const SCEV *IterCount) {
12971297
SCEV::FlagAnyWrap));
12981298
{ // Limit the lifetime of SCEVExpander.
12991299
SCEVExpander Expander(*SE, DL, "reroll");
1300-
Value *NewIV = Expander.expandCodeFor(H, IV->getType(), Header->begin());
1300+
Value *NewIV = Expander.expandCodeFor(H, IV->getType(), &Header->front());
13011301

13021302
for (auto &KV : Uses) {
13031303
if (KV.second.find_first() == 0)

llvm/lib/Transforms/Scalar/LoopRotation.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader,
158158
// as necessary.
159159
SSAUpdater SSA;
160160
for (I = OrigHeader->begin(); I != E; ++I) {
161-
Value *OrigHeaderVal = I;
161+
Value *OrigHeaderVal = &*I;
162162

163163
// If there are no uses of the value (e.g. because it returns void), there
164164
// is nothing to rewrite.
@@ -221,7 +221,7 @@ static bool shouldSpeculateInstrs(BasicBlock::iterator Begin,
221221

222222
for (BasicBlock::iterator I = Begin; I != End; ++I) {
223223

224-
if (!isSafeToSpeculativelyExecute(I))
224+
if (!isSafeToSpeculativelyExecute(&*I))
225225
return false;
226226

227227
if (isa<DbgInfoIntrinsic>(I))
@@ -301,14 +301,15 @@ bool LoopRotate::simplifyLoopLatch(Loop *L) {
301301
if (!BI)
302302
return false;
303303

304-
if (!shouldSpeculateInstrs(Latch->begin(), Jmp, L))
304+
if (!shouldSpeculateInstrs(Latch->begin(), Jmp->getIterator(), L))
305305
return false;
306306

307307
DEBUG(dbgs() << "Folding loop latch " << Latch->getName() << " into "
308308
<< LastExit->getName() << "\n");
309309

310310
// Hoist the instructions from Latch into LastExit.
311-
LastExit->getInstList().splice(BI, Latch->getInstList(), Latch->begin(), Jmp);
311+
LastExit->getInstList().splice(BI->getIterator(), Latch->getInstList(),
312+
Latch->begin(), Jmp->getIterator());
312313

313314
unsigned FallThruPath = BI->getSuccessor(0) == Latch ? 0 : 1;
314315
BasicBlock *Header = Jmp->getSuccessor(0);
@@ -431,7 +432,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
431432
// possible or create a clone in the OldPreHeader if not.
432433
TerminatorInst *LoopEntryBranch = OrigPreheader->getTerminator();
433434
while (I != E) {
434-
Instruction *Inst = I++;
435+
Instruction *Inst = &*I++;
435436

436437
// If the instruction's operands are invariant and it doesn't read or write
437438
// memory, then it is safe to hoist. Doing this doesn't change the order of

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

+22-19
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ LSRInstance::OptimizeLoopTermCond() {
21912191
ICmpInst *OldCond = Cond;
21922192
Cond = cast<ICmpInst>(Cond->clone());
21932193
Cond->setName(L->getHeader()->getName() + ".termcond");
2194-
ExitingBlock->getInstList().insert(TermBr, Cond);
2194+
ExitingBlock->getInstList().insert(TermBr->getIterator(), Cond);
21952195

21962196
// Clone the IVUse, as the old use still exists!
21972197
CondUse = &IU.AddUser(Cond, CondUse->getOperandValToReplace());
@@ -2765,19 +2765,19 @@ void LSRInstance::CollectChains() {
27652765
for (BasicBlock::iterator I = (*BBIter)->begin(), E = (*BBIter)->end();
27662766
I != E; ++I) {
27672767
// Skip instructions that weren't seen by IVUsers analysis.
2768-
if (isa<PHINode>(I) || !IU.isIVUserOrOperand(I))
2768+
if (isa<PHINode>(I) || !IU.isIVUserOrOperand(&*I))
27692769
continue;
27702770

27712771
// Ignore users that are part of a SCEV expression. This way we only
27722772
// consider leaf IV Users. This effectively rediscovers a portion of
27732773
// IVUsers analysis but in program order this time.
2774-
if (SE.isSCEVable(I->getType()) && !isa<SCEVUnknown>(SE.getSCEV(I)))
2774+
if (SE.isSCEVable(I->getType()) && !isa<SCEVUnknown>(SE.getSCEV(&*I)))
27752775
continue;
27762776

27772777
// Remove this instruction from any NearUsers set it may be in.
27782778
for (unsigned ChainIdx = 0, NChains = IVChainVec.size();
27792779
ChainIdx < NChains; ++ChainIdx) {
2780-
ChainUsersVec[ChainIdx].NearUsers.erase(I);
2780+
ChainUsersVec[ChainIdx].NearUsers.erase(&*I);
27812781
}
27822782
// Search for operands that can be chained.
27832783
SmallPtrSet<Instruction*, 4> UniqueOperands;
@@ -2786,7 +2786,7 @@ void LSRInstance::CollectChains() {
27862786
while (IVOpIter != IVOpEnd) {
27872787
Instruction *IVOpInst = cast<Instruction>(*IVOpIter);
27882788
if (UniqueOperands.insert(IVOpInst).second)
2789-
ChainInstruction(I, IVOpInst, ChainUsersVec);
2789+
ChainInstruction(&*I, IVOpInst, ChainUsersVec);
27902790
IVOpIter = findIVOperand(std::next(IVOpIter), IVOpEnd, L, SE);
27912791
}
27922792
} // Continue walking down the instructions.
@@ -4368,14 +4368,14 @@ LSRInstance::HoistInsertPosition(BasicBlock::iterator IP,
43684368
// instead of at the end, so that it can be used for other expansions.
43694369
if (IDom == Inst->getParent() &&
43704370
(!BetterPos || !DT.dominates(Inst, BetterPos)))
4371-
BetterPos = std::next(BasicBlock::iterator(Inst));
4371+
BetterPos = &*std::next(BasicBlock::iterator(Inst));
43724372
}
43734373
if (!AllDominate)
43744374
break;
43754375
if (BetterPos)
4376-
IP = BetterPos;
4376+
IP = BetterPos->getIterator();
43774377
else
4378-
IP = Tentative;
4378+
IP = Tentative->getIterator();
43794379
}
43804380

43814381
return IP;
@@ -4440,7 +4440,8 @@ LSRInstance::AdjustInsertPositionForExpand(BasicBlock::iterator LowestIP,
44404440
// Set IP below instructions recently inserted by SCEVExpander. This keeps the
44414441
// IP consistent across expansions and allows the previously inserted
44424442
// instructions to be reused by subsequent expansion.
4443-
while (Rewriter.isInsertedInstruction(IP) && IP != LowestIP) ++IP;
4443+
while (Rewriter.isInsertedInstruction(&*IP) && IP != LowestIP)
4444+
++IP;
44444445

44454446
return IP;
44464447
}
@@ -4490,7 +4491,7 @@ Value *LSRInstance::Expand(const LSRFixup &LF,
44904491
LF.UserInst, LF.OperandValToReplace,
44914492
Loops, SE, DT);
44924493

4493-
Ops.push_back(SE.getUnknown(Rewriter.expandCodeFor(Reg, nullptr, IP)));
4494+
Ops.push_back(SE.getUnknown(Rewriter.expandCodeFor(Reg, nullptr, &*IP)));
44944495
}
44954496

44964497
// Expand the ScaledReg portion.
@@ -4508,14 +4509,14 @@ Value *LSRInstance::Expand(const LSRFixup &LF,
45084509
// Expand ScaleReg as if it was part of the base regs.
45094510
if (F.Scale == 1)
45104511
Ops.push_back(
4511-
SE.getUnknown(Rewriter.expandCodeFor(ScaledS, nullptr, IP)));
4512+
SE.getUnknown(Rewriter.expandCodeFor(ScaledS, nullptr, &*IP)));
45124513
else {
45134514
// An interesting way of "folding" with an icmp is to use a negated
45144515
// scale, which we'll implement by inserting it into the other operand
45154516
// of the icmp.
45164517
assert(F.Scale == -1 &&
45174518
"The only scale supported by ICmpZero uses is -1!");
4518-
ICmpScaledV = Rewriter.expandCodeFor(ScaledS, nullptr, IP);
4519+
ICmpScaledV = Rewriter.expandCodeFor(ScaledS, nullptr, &*IP);
45194520
}
45204521
} else {
45214522
// Otherwise just expand the scaled register and an explicit scale,
@@ -4525,11 +4526,11 @@ Value *LSRInstance::Expand(const LSRFixup &LF,
45254526
// Unless the addressing mode will not be folded.
45264527
if (!Ops.empty() && LU.Kind == LSRUse::Address &&
45274528
isAMCompletelyFolded(TTI, LU, F)) {
4528-
Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, IP);
4529+
Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, &*IP);
45294530
Ops.clear();
45304531
Ops.push_back(SE.getUnknown(FullV));
45314532
}
4532-
ScaledS = SE.getUnknown(Rewriter.expandCodeFor(ScaledS, nullptr, IP));
4533+
ScaledS = SE.getUnknown(Rewriter.expandCodeFor(ScaledS, nullptr, &*IP));
45334534
if (F.Scale != 1)
45344535
ScaledS =
45354536
SE.getMulExpr(ScaledS, SE.getConstant(ScaledS->getType(), F.Scale));
@@ -4541,7 +4542,7 @@ Value *LSRInstance::Expand(const LSRFixup &LF,
45414542
if (F.BaseGV) {
45424543
// Flush the operand list to suppress SCEVExpander hoisting.
45434544
if (!Ops.empty()) {
4544-
Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, IP);
4545+
Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, &*IP);
45454546
Ops.clear();
45464547
Ops.push_back(SE.getUnknown(FullV));
45474548
}
@@ -4551,7 +4552,7 @@ Value *LSRInstance::Expand(const LSRFixup &LF,
45514552
// Flush the operand list to suppress SCEVExpander hoisting of both folded and
45524553
// unfolded offsets. LSR assumes they both live next to their uses.
45534554
if (!Ops.empty()) {
4554-
Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, IP);
4555+
Value *FullV = Rewriter.expandCodeFor(SE.getAddExpr(Ops), Ty, &*IP);
45554556
Ops.clear();
45564557
Ops.push_back(SE.getUnknown(FullV));
45574558
}
@@ -4587,7 +4588,7 @@ Value *LSRInstance::Expand(const LSRFixup &LF,
45874588
const SCEV *FullS = Ops.empty() ?
45884589
SE.getConstant(IntTy, 0) :
45894590
SE.getAddExpr(Ops);
4590-
Value *FullV = Rewriter.expandCodeFor(FullS, Ty, IP);
4591+
Value *FullV = Rewriter.expandCodeFor(FullS, Ty, &*IP);
45914592

45924593
// We're done expanding now, so reset the rewriter.
45934594
Rewriter.clearPostInc();
@@ -4687,7 +4688,8 @@ void LSRInstance::RewriteForPHI(PHINode *PN,
46874688
if (!Pair.second)
46884689
PN->setIncomingValue(i, Pair.first->second);
46894690
else {
4690-
Value *FullV = Expand(LF, F, BB->getTerminator(), Rewriter, DeadInsts);
4691+
Value *FullV = Expand(LF, F, BB->getTerminator()->getIterator(),
4692+
Rewriter, DeadInsts);
46914693

46924694
// If this is reuse-by-noop-cast, insert the noop cast.
46934695
Type *OpTy = LF.OperandValToReplace->getType();
@@ -4717,7 +4719,8 @@ void LSRInstance::Rewrite(const LSRFixup &LF,
47174719
if (PHINode *PN = dyn_cast<PHINode>(LF.UserInst)) {
47184720
RewriteForPHI(PN, LF, F, Rewriter, DeadInsts, P);
47194721
} else {
4720-
Value *FullV = Expand(LF, F, LF.UserInst, Rewriter, DeadInsts);
4722+
Value *FullV =
4723+
Expand(LF, F, LF.UserInst->getIterator(), Rewriter, DeadInsts);
47214724

47224725
// If this is reuse-by-noop-cast, insert the noop cast.
47234726
Type *OpTy = LF.OperandValToReplace->getType();

0 commit comments

Comments
 (0)