[llvm-commits] [llvm] r100131 - in /llvm/trunk: include/llvm/Transforms/Utils/SSAUpdater.h lib/Transforms/Utils/SSAUpdater.cpp

Bob Wilson bob.wilson at apple.com
Thu Apr 1 13:04:30 PDT 2010


Author: bwilson
Date: Thu Apr  1 15:04:30 2010
New Revision: 100131

URL: http://llvm.org/viewvc/llvm-project?rev=100131&view=rev
Log:
Change another SSAUpdater function to avoid recursion.

Modified:
    llvm/trunk/include/llvm/Transforms/Utils/SSAUpdater.h
    llvm/trunk/lib/Transforms/Utils/SSAUpdater.cpp

Modified: llvm/trunk/include/llvm/Transforms/Utils/SSAUpdater.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/SSAUpdater.h?rev=100131&r1=100130&r2=100131&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/SSAUpdater.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/SSAUpdater.h Thu Apr  1 15:04:30 2010
@@ -110,7 +110,7 @@
   void FindAvailableVal(BasicBlock *BB, BBInfo *Info, unsigned Counter);
   void FindExistingPHI(BasicBlock *BB, BBInfo *Info);
   bool CheckIfPHIMatches(BasicBlock *BB, BBInfo *Info, Value *Val);
-  void RecordMatchingPHI(BasicBlock *BB, BBInfo *Info, PHINode *PHI);
+  void RecordMatchingPHI(PHINode *PHI);
   void ClearPHITags(PHINode *PHI);
 
   void operator=(const SSAUpdater&); // DO NOT IMPLEMENT

Modified: llvm/trunk/lib/Transforms/Utils/SSAUpdater.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SSAUpdater.cpp?rev=100131&r1=100130&r2=100131&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SSAUpdater.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SSAUpdater.cpp Thu Apr  1 15:04:30 2010
@@ -406,7 +406,7 @@
   for (BasicBlock::iterator It = BB->begin();
        (SomePHI = dyn_cast<PHINode>(It)); ++It) {
     if (CheckIfPHIMatches(BB, Info, SomePHI)) {
-      RecordMatchingPHI(BB, Info, SomePHI);
+      RecordMatchingPHI(SomePHI);
       break;
     }
     ClearPHITags(SomePHI);
@@ -449,25 +449,31 @@
   return IsMatch;
 }
 
-/// RecordMatchingPHI - For a PHI node that matches, record it in both the
-/// BBMap and the AvailableVals mapping.  Recursively record its input PHIs
-/// as well.
-void SSAUpdater::RecordMatchingPHI(BasicBlock *BB, BBInfo *Info, PHINode *PHI) {
-  if (!Info || Info->AvailableVal)
-    return;
-
-  // Record the PHI.
+/// RecordMatchingPHI - For a PHI node that matches, record it and its input
+/// PHIs in both the BBMap and the AvailableVals mapping.
+void SSAUpdater::RecordMatchingPHI(PHINode *PHI) {
+  BBMapTy *BBMap = getBBMap(BM);
   AvailableValsTy &AvailableVals = getAvailableVals(AV);
-  AvailableVals[BB] = PHI;
-  Info->AvailableVal = PHI;
+  SmallVector<PHINode*, 20> WorkList;
+  WorkList.push_back(PHI);
 
-  // Iterate through the predecessors.
-  BBMapTy *BBMap = getBBMap(BM);
-  for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) {
-    PHINode *PHIVal = dyn_cast<PHINode>(PHI->getIncomingValue(i));
-    if (!PHIVal) continue;
-    BasicBlock *Pred = PHIVal->getParent();
-    RecordMatchingPHI(Pred, (*BBMap)[Pred], PHIVal);
+  while (!WorkList.empty()) {
+    PHI = WorkList.pop_back_val();
+    BasicBlock *BB = PHI->getParent();
+    BBInfo *Info = (*BBMap)[BB];
+    if (!Info || Info->AvailableVal)
+      return;
+
+    // Record the PHI.
+    AvailableVals[BB] = PHI;
+    Info->AvailableVal = PHI;
+
+    // Iterate through the PHI's incoming values.
+    for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) {
+      PHINode *IncomingVal = dyn_cast<PHINode>(PHI->getIncomingValue(i));
+      if (!IncomingVal) continue;
+      WorkList.push_back(IncomingVal);
+    }
   }
 }
 





More information about the llvm-commits mailing list