Skip to content

Commit 76f6b12

Browse files
committed
Revert "[llvm] Use BasicBlock::phis() (NFC)"
Reverting because this causes crashes on the 2-stage buildbots, for example http://lab.llvm.org:8011/#/builders/7/builds/1140. This reverts commit 9b228f1.
1 parent d0fa7a0 commit 76f6b12

File tree

6 files changed

+46
-18
lines changed

6 files changed

+46
-18
lines changed

llvm/lib/IR/BasicBlock.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,12 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
440440
void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {
441441
// N.B. This might not be a complete BasicBlock, so don't assume
442442
// that it ends with a non-phi instruction.
443-
for (PHINode &PN : phis())
444-
PN.replaceIncomingBlockWith(Old, New);
443+
for (iterator II = begin(), IE = end(); II != IE; ++II) {
444+
PHINode *PN = dyn_cast<PHINode>(II);
445+
if (!PN)
446+
break;
447+
PN->replaceIncomingBlockWith(Old, New);
448+
}
445449
}
446450

447451
void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *Old,

llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,10 +2199,13 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
21992199
if (ParentL)
22002200
ParentL->addBasicBlockToLoop(NewPreheader, *LF);
22012201
IRBuilder<>(NewPreheader).CreateBr(Header);
2202-
for (PHINode &PN : Header->phis()) {
2203-
int bx = PN.getBasicBlockIndex(Preheader);
2202+
for (auto &In : *Header) {
2203+
PHINode *PN = dyn_cast<PHINode>(&In);
2204+
if (!PN)
2205+
break;
2206+
int bx = PN->getBasicBlockIndex(Preheader);
22042207
if (bx >= 0)
2205-
PN.setIncomingBlock(bx, NewPreheader);
2208+
PN->setIncomingBlock(bx, NewPreheader);
22062209
}
22072210
DT->addNewBlock(NewPreheader, Preheader);
22082211
DT->changeImmediateDominator(Header, NewPreheader);

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,20 +483,24 @@ static Optional<EstimatedUnrollCost> analyzeLoopUnrollCost(
483483

484484
// Prepare for the iteration by collecting any simplified entry or backedge
485485
// inputs.
486-
for (PHINode &PHI : L->getHeader()->phis()) {
486+
for (Instruction &I : *L->getHeader()) {
487+
auto *PHI = dyn_cast<PHINode>(&I);
488+
if (!PHI)
489+
break;
490+
487491
// The loop header PHI nodes must have exactly two input: one from the
488492
// loop preheader and one from the loop latch.
489493
assert(
490-
PHI.getNumIncomingValues() == 2 &&
494+
PHI->getNumIncomingValues() == 2 &&
491495
"Must have an incoming value only for the preheader and the latch.");
492496

493-
Value *V = PHI.getIncomingValueForBlock(
497+
Value *V = PHI->getIncomingValueForBlock(
494498
Iteration == 0 ? L->getLoopPreheader() : L->getLoopLatch());
495499
Constant *C = dyn_cast<Constant>(V);
496500
if (Iteration != 0 && !C)
497501
C = SimplifiedValues.lookup(V);
498502
if (C)
499-
SimplifiedInputValues.push_back({&PHI, C});
503+
SimplifiedInputValues.push_back({PHI, C});
500504
}
501505

502506
// Now clear and re-populate the map for the next iteration.
@@ -621,8 +625,12 @@ static Optional<EstimatedUnrollCost> analyzeLoopUnrollCost(
621625
BasicBlock *ExitingBB, *ExitBB;
622626
std::tie(ExitingBB, ExitBB) = ExitWorklist.pop_back_val();
623627

624-
for (PHINode &PN : ExitBB->phis()) {
625-
Value *Op = PN.getIncomingValueForBlock(ExitingBB);
628+
for (Instruction &I : *ExitBB) {
629+
auto *PN = dyn_cast<PHINode>(&I);
630+
if (!PN)
631+
break;
632+
633+
Value *Op = PN->getIncomingValueForBlock(ExitingBB);
626634
if (auto *OpI = dyn_cast<Instruction>(Op))
627635
if (L->contains(OpI))
628636
AddCostRecursively(*OpI, TripCount - 1);

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,8 +2843,12 @@ static void computeLiveInValues(BasicBlock::reverse_iterator Begin,
28432843

28442844
static void computeLiveOutSeed(BasicBlock *BB, SetVector<Value *> &LiveTmp) {
28452845
for (BasicBlock *Succ : successors(BB)) {
2846-
for (PHINode &PN : Succ->phis()) {
2847-
Value *V = PN.getIncomingValueForBlock(BB);
2846+
for (auto &I : *Succ) {
2847+
PHINode *PN = dyn_cast<PHINode>(&I);
2848+
if (!PN)
2849+
break;
2850+
2851+
Value *V = PN->getIncomingValueForBlock(BB);
28482852
assert(!isUnhandledGCPointerType(V->getType()) &&
28492853
"support for FCA unimplemented");
28502854
if (isHandledGCPointerType(V->getType()) && !isa<Constant>(V))

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,13 @@ static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock,
657657
// edge from this block.
658658
SmallVector<Value *, 8> UnwindDestPHIValues;
659659
BasicBlock *InvokeBB = II->getParent();
660-
for (PHINode &PHI : UnwindDest->phis())
660+
for (Instruction &I : *UnwindDest) {
661661
// Save the value to use for this edge.
662-
UnwindDestPHIValues.push_back(PHI.getIncomingValueForBlock(InvokeBB));
662+
PHINode *PHI = dyn_cast<PHINode>(&I);
663+
if (!PHI)
664+
break;
665+
UnwindDestPHIValues.push_back(PHI->getIncomingValueForBlock(InvokeBB));
666+
}
663667

664668
// Add incoming-PHI values to the unwind destination block for the given basic
665669
// block, using the values for the original invoke's source block.

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7529,9 +7529,14 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
75297529

75307530
// Collect the incoming values from the PHIs.
75317531
Incoming.clear();
7532-
for (PHINode &P : BB->phis())
7533-
if (!VisitedInstrs.count(&P) && !R.isDeleted(&P))
7534-
Incoming.push_back(&P);
7532+
for (Instruction &I : *BB) {
7533+
PHINode *P = dyn_cast<PHINode>(&I);
7534+
if (!P)
7535+
break;
7536+
7537+
if (!VisitedInstrs.count(P) && !R.isDeleted(P))
7538+
Incoming.push_back(P);
7539+
}
75357540

75367541
// Sort by type.
75377542
llvm::stable_sort(Incoming, PhiTypeSorterFunc);

0 commit comments

Comments
 (0)