[llvm-commits] CVS: llvm/lib/Transforms/Scalar/Mem2Reg.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Jun 25 10:00:01 PDT 2003


Changes in directory llvm/lib/Transforms/Scalar:

Mem2Reg.cpp updated: 1.3 -> 1.4

---
Log message:

Fix bug: Mem2Reg/2003-06-26-IterativePromote.ll


---
Diffs of the changes:

Index: llvm/lib/Transforms/Scalar/Mem2Reg.cpp
diff -u llvm/lib/Transforms/Scalar/Mem2Reg.cpp:1.3 llvm/lib/Transforms/Scalar/Mem2Reg.cpp:1.4
--- llvm/lib/Transforms/Scalar/Mem2Reg.cpp:1.3	Wed Apr 23 11:37:42 2003
+++ llvm/lib/Transforms/Scalar/Mem2Reg.cpp	Wed Jun 25 09:58:56 2003
@@ -40,19 +40,26 @@
 
   BasicBlock &BB = F.getEntryNode();  // Get the entry node for the function
 
-  // Find allocas that are safe to promote, by looking at all instructions in
-  // the entry node
-  for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I)
-    if (AllocaInst *AI = dyn_cast<AllocaInst>(I))       // Is it an alloca?
-      if (isAllocaPromotable(AI, TD))
-        Allocas.push_back(AI);
+  bool Changed  = false;
+  
+  while (1) {
+    Allocas.clear();
+
+    // Find allocas that are safe to promote, by looking at all instructions in
+    // the entry node
+    for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I)
+      if (AllocaInst *AI = dyn_cast<AllocaInst>(I))       // Is it an alloca?
+        if (isAllocaPromotable(AI, TD))
+          Allocas.push_back(AI);
+
+    if (Allocas.empty()) break;
 
-  if (!Allocas.empty()) {
     PromoteMemToReg(Allocas, getAnalysis<DominanceFrontier>(), TD);
     NumPromoted += Allocas.size();
-    return true;
+    Changed = true;
   }
-  return false;
+
+  return Changed;
 }
 
 // createPromoteMemoryToRegister - Provide an entry point to create this pass.





More information about the llvm-commits mailing list