[llvm-branch-commits] [llvm] 9b228f1 - [llvm] Use BasicBlock::phis() (NFC)

Kazu Hirata via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 6 18:32:31 PST 2021


Author: Kazu Hirata
Date: 2021-01-06T18:27:35-08:00
New Revision: 9b228f107d43341ef73af92865f73a9a076c5a76

URL: https://github.com/llvm/llvm-project/commit/9b228f107d43341ef73af92865f73a9a076c5a76
DIFF: https://github.com/llvm/llvm-project/commit/9b228f107d43341ef73af92865f73a9a076c5a76.diff

LOG: [llvm] Use BasicBlock::phis() (NFC)

Added: 
    

Modified: 
    llvm/lib/IR/BasicBlock.cpp
    llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
    llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
    llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
    llvm/lib/Transforms/Utils/InlineFunction.cpp
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 7f34565f5cd8..688211877d18 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -440,12 +440,8 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
 void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {
   // N.B. This might not be a complete BasicBlock, so don't assume
   // that it ends with a non-phi instruction.
-  for (iterator II = begin(), IE = end(); II != IE; ++II) {
-    PHINode *PN = dyn_cast<PHINode>(II);
-    if (!PN)
-      break;
-    PN->replaceIncomingBlockWith(Old, New);
-  }
+  for (PHINode &PN : phis())
+    PN.replaceIncomingBlockWith(Old, New);
 }
 
 void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *Old,

diff  --git a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
index 68c79d2a113f..273d3ab97c7b 100644
--- a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
@@ -2199,13 +2199,10 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
     if (ParentL)
       ParentL->addBasicBlockToLoop(NewPreheader, *LF);
     IRBuilder<>(NewPreheader).CreateBr(Header);
-    for (auto &In : *Header) {
-      PHINode *PN = dyn_cast<PHINode>(&In);
-      if (!PN)
-        break;
-      int bx = PN->getBasicBlockIndex(Preheader);
+    for (PHINode &PN : Header->phis()) {
+      int bx = PN.getBasicBlockIndex(Preheader);
       if (bx >= 0)
-        PN->setIncomingBlock(bx, NewPreheader);
+        PN.setIncomingBlock(bx, NewPreheader);
     }
     DT->addNewBlock(NewPreheader, Preheader);
     DT->changeImmediateDominator(Header, NewPreheader);

diff  --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 4cce05d595a8..060ca4bcd8ee 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -483,24 +483,20 @@ static Optional<EstimatedUnrollCost> analyzeLoopUnrollCost(
 
     // Prepare for the iteration by collecting any simplified entry or backedge
     // inputs.
-    for (Instruction &I : *L->getHeader()) {
-      auto *PHI = dyn_cast<PHINode>(&I);
-      if (!PHI)
-        break;
-
+    for (PHINode &PHI : L->getHeader()->phis()) {
       // The loop header PHI nodes must have exactly two input: one from the
       // loop preheader and one from the loop latch.
       assert(
-          PHI->getNumIncomingValues() == 2 &&
+          PHI.getNumIncomingValues() == 2 &&
           "Must have an incoming value only for the preheader and the latch.");
 
-      Value *V = PHI->getIncomingValueForBlock(
+      Value *V = PHI.getIncomingValueForBlock(
           Iteration == 0 ? L->getLoopPreheader() : L->getLoopLatch());
       Constant *C = dyn_cast<Constant>(V);
       if (Iteration != 0 && !C)
         C = SimplifiedValues.lookup(V);
       if (C)
-        SimplifiedInputValues.push_back({PHI, C});
+        SimplifiedInputValues.push_back({&PHI, C});
     }
 
     // Now clear and re-populate the map for the next iteration.
@@ -625,12 +621,8 @@ static Optional<EstimatedUnrollCost> analyzeLoopUnrollCost(
     BasicBlock *ExitingBB, *ExitBB;
     std::tie(ExitingBB, ExitBB) = ExitWorklist.pop_back_val();
 
-    for (Instruction &I : *ExitBB) {
-      auto *PN = dyn_cast<PHINode>(&I);
-      if (!PN)
-        break;
-
-      Value *Op = PN->getIncomingValueForBlock(ExitingBB);
+    for (PHINode &PN : ExitBB->phis()) {
+      Value *Op = PN.getIncomingValueForBlock(ExitingBB);
       if (auto *OpI = dyn_cast<Instruction>(Op))
         if (L->contains(OpI))
           AddCostRecursively(*OpI, TripCount - 1);

diff  --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 68ddebf113d1..ed3f87a7d0e7 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -2843,12 +2843,8 @@ static void computeLiveInValues(BasicBlock::reverse_iterator Begin,
 
 static void computeLiveOutSeed(BasicBlock *BB, SetVector<Value *> &LiveTmp) {
   for (BasicBlock *Succ : successors(BB)) {
-    for (auto &I : *Succ) {
-      PHINode *PN = dyn_cast<PHINode>(&I);
-      if (!PN)
-        break;
-
-      Value *V = PN->getIncomingValueForBlock(BB);
+    for (PHINode &PN : Succ->phis()) {
+      Value *V = PN.getIncomingValueForBlock(BB);
       assert(!isUnhandledGCPointerType(V->getType()) &&
              "support for FCA unimplemented");
       if (isHandledGCPointerType(V->getType()) && !isa<Constant>(V))

diff  --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index e480d7b8d61f..521b2b2e5f49 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -657,13 +657,9 @@ static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock,
   // edge from this block.
   SmallVector<Value *, 8> UnwindDestPHIValues;
   BasicBlock *InvokeBB = II->getParent();
-  for (Instruction &I : *UnwindDest) {
+  for (PHINode &PHI : UnwindDest->phis())
     // Save the value to use for this edge.
-    PHINode *PHI = dyn_cast<PHINode>(&I);
-    if (!PHI)
-      break;
-    UnwindDestPHIValues.push_back(PHI->getIncomingValueForBlock(InvokeBB));
-  }
+    UnwindDestPHIValues.push_back(PHI.getIncomingValueForBlock(InvokeBB));
 
   // Add incoming-PHI values to the unwind destination block for the given basic
   // block, using the values for the original invoke's source block.

diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 7b77aef2a75c..c2d8117181b2 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -7531,14 +7531,9 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
 
     // Collect the incoming values from the PHIs.
     Incoming.clear();
-    for (Instruction &I : *BB) {
-      PHINode *P = dyn_cast<PHINode>(&I);
-      if (!P)
-        break;
-
-      if (!VisitedInstrs.count(P) && !R.isDeleted(P))
-        Incoming.push_back(P);
-    }
+    for (PHINode &P : BB->phis())
+      if (!VisitedInstrs.count(&P) && !R.isDeleted(&P))
+        Incoming.push_back(&P);
 
     // Sort by type.
     llvm::stable_sort(Incoming, PhiTypeSorterFunc);


        


More information about the llvm-branch-commits mailing list