Change another SSAUpdater function to avoid recursion.
authorBob Wilson <bob.wilson@apple.com>
Thu, 1 Apr 2010 20:04:30 +0000 (20:04 +0000)
committerBob Wilson <bob.wilson@apple.com>
Thu, 1 Apr 2010 20:04:30 +0000 (20:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100131 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Utils/SSAUpdater.h
lib/Transforms/Utils/SSAUpdater.cpp

index f353840cd59ae1b3ceef5a633fe197753a0d9ad6..f550d0285b8f96557f9c8f30bfab7d40abc8915c 100644 (file)
@@ -110,7 +110,7 @@ private:
   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
index a8fbf6f4140c58e35244e2f44f15f9c0472fc519..4460381b30ac662721146b8c9a5d360d0e9c5e9a 100644 (file)
@@ -406,7 +406,7 @@ void SSAUpdater::FindExistingPHI(BasicBlock *BB, BBInfo *Info) {
   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 @@ bool SSAUpdater::CheckIfPHIMatches(BasicBlock *BB, BBInfo *Info, Value *Val) {
   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);
+    }
   }
 }