Skip to content

Commit 9b228f1

Browse files
[llvm] Use BasicBlock::phis() (NFC)
1 parent 1d0bc05 commit 9b228f1

File tree

6 files changed

+18
-46
lines changed

6 files changed

+18
-46
lines changed

llvm/lib/IR/BasicBlock.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,8 @@ 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 (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-
}
443+
for (PHINode &PN : phis())
444+
PN.replaceIncomingBlockWith(Old, New);
449445
}
450446

451447
void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *Old,

llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp

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

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

+6-14
Original file line numberDiff line numberDiff line change
@@ -483,24 +483,20 @@ static Optional<EstimatedUnrollCost> analyzeLoopUnrollCost(
483483

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

497-
Value *V = PHI->getIncomingValueForBlock(
493+
Value *V = PHI.getIncomingValueForBlock(
498494
Iteration == 0 ? L->getLoopPreheader() : L->getLoopLatch());
499495
Constant *C = dyn_cast<Constant>(V);
500496
if (Iteration != 0 && !C)
501497
C = SimplifiedValues.lookup(V);
502498
if (C)
503-
SimplifiedInputValues.push_back({PHI, C});
499+
SimplifiedInputValues.push_back({&PHI, C});
504500
}
505501

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

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

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -2843,12 +2843,8 @@ 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 (auto &I : *Succ) {
2847-
PHINode *PN = dyn_cast<PHINode>(&I);
2848-
if (!PN)
2849-
break;
2850-
2851-
Value *V = PN->getIncomingValueForBlock(BB);
2846+
for (PHINode &PN : Succ->phis()) {
2847+
Value *V = PN.getIncomingValueForBlock(BB);
28522848
assert(!isUnhandledGCPointerType(V->getType()) &&
28532849
"support for FCA unimplemented");
28542850
if (isHandledGCPointerType(V->getType()) && !isa<Constant>(V))

llvm/lib/Transforms/Utils/InlineFunction.cpp

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

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

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -7531,14 +7531,9 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
75317531

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

75437538
// Sort by type.
75447539
llvm::stable_sort(Incoming, PhiTypeSorterFunc);

0 commit comments

Comments
 (0)