The SSAUpdater should avoid recursive traversals of the CFG, since that may
authorBob Wilson <bob.wilson@apple.com>
Thu, 1 Apr 2010 18:46:59 +0000 (18:46 +0000)
committerBob Wilson <bob.wilson@apple.com>
Thu, 1 Apr 2010 18:46:59 +0000 (18:46 +0000)
blow out the stack for really big functions.  Start by fixing an easy case.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100126 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 748ded30e7b304b93974f2f755b137f5cbaf0fcd..f353840cd59ae1b3ceef5a633fe197753a0d9ad6 100644 (file)
@@ -111,7 +111,7 @@ private:
   void FindExistingPHI(BasicBlock *BB, BBInfo *Info);
   bool CheckIfPHIMatches(BasicBlock *BB, BBInfo *Info, Value *Val);
   void RecordMatchingPHI(BasicBlock *BB, BBInfo *Info, PHINode *PHI);
-  void ClearPHITags(BasicBlock *BB, BBInfo *Info, PHINode *PHI);
+  void ClearPHITags(PHINode *PHI);
 
   void operator=(const SSAUpdater&); // DO NOT IMPLEMENT
   SSAUpdater(const SSAUpdater&);     // DO NOT IMPLEMENT
index 20a92d690c27224fe3f24df5606bf6f77454b056..1431a86f71a459e9661744094463179c8dbf9319 100644 (file)
@@ -427,7 +427,7 @@ void SSAUpdater::FindExistingPHI(BasicBlock *BB, BBInfo *Info) {
       RecordMatchingPHI(BB, Info, SomePHI);
       break;
     }
-    ClearPHITags(BB, Info, SomePHI);
+    ClearPHITags(SomePHI);
   }
 }
 
@@ -490,20 +490,28 @@ void SSAUpdater::RecordMatchingPHI(BasicBlock *BB, BBInfo *Info, PHINode *PHI) {
 }
 
 /// ClearPHITags - When one of the existing PHI nodes fails to match, clear
-/// the PHITag values stored in the BBMap while checking to see if it matched.
-void SSAUpdater::ClearPHITags(BasicBlock *BB, BBInfo *Info, PHINode *PHI) {
-  if (!Info || Info->AvailableVal || !Info->PHITag)
-    return;
-
-  // Clear the tag.
-  Info->PHITag = 0;
-
-  // Iterate through the predecessors.
+/// the PHITag values that were stored in the BBMap when checking to see if
+/// it matched.
+void SSAUpdater::ClearPHITags(PHINode *PHI) {
   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();
-    ClearPHITags(Pred, (*BBMap)[Pred], PHIVal);
+  SmallVector<PHINode*, 20> WorkList;
+  WorkList.push_back(PHI);
+
+  while (!WorkList.empty()) {
+    PHI = WorkList.pop_back_val();
+    BasicBlock *BB = PHI->getParent();
+    BBInfo *Info = (*BBMap)[BB];
+    if (!Info || Info->AvailableVal || !Info->PHITag)
+      continue;
+
+    // Clear the tag.
+    Info->PHITag = 0;
+
+    // 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);
+    }
   }
 }