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

Owen Anderson resistor at mac.com
Sun May 28 18:00:13 PDT 2006



Changes in directory llvm/lib/Transforms/Scalar:

LCSSA.cpp updated: 1.6 -> 1.7
---
Log message:

Add Use replacement.  Assuming there is nothing horribly wrong with this, LCSSA
is now theoretically feature-complete.  It has not, however, been thoroughly
test, and is still considered experimental.


---
Diffs of the changes:  (+35 -2)

 LCSSA.cpp |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)


Index: llvm/lib/Transforms/Scalar/LCSSA.cpp
diff -u llvm/lib/Transforms/Scalar/LCSSA.cpp:1.6 llvm/lib/Transforms/Scalar/LCSSA.cpp:1.7
--- llvm/lib/Transforms/Scalar/LCSSA.cpp:1.6	Sun May 28 14:33:28 2006
+++ llvm/lib/Transforms/Scalar/LCSSA.cpp	Sun May 28 20:00:00 2006
@@ -111,6 +111,7 @@
   
   // Iterate over all affected values for this loop and insert Phi nodes
   // for them in the appropriate exit blocks
+  std::map<BasicBlock*, PHINode*> ExitPhis;
   for (std::set<Instruction*>::iterator I = AffectedValues.begin(),
        E = AffectedValues.end(); I != E; ++I) {
     ++NumLCSSA; // We are applying the transformation
@@ -119,6 +120,7 @@
       PHINode *phi = new PHINode((*I)->getType(), "lcssa");
       (*BBI)->getInstList().insert((*BBI)->front(), phi);
       workList.push_back(phi);
+      ExitPhis[*BBI] = phi;
     
       // Since LoopSimplify has been run, we know that all of these predecessors
       // are in the loop, so just hook them up in the obvious manner.
@@ -166,9 +168,40 @@
             break;
           }
     }
-  
-    // FIXME: Should update all uses.
+    
+    
+    
+    // Find all uses of the affected value, and replace them with the
+    // appropriate Phi.
+    for (Instruction::use_iterator UI = (*I)->use_begin(), UE=(*I)->use_end();
+         UI != UE; ++UI) {
+      Instruction* use = cast<Instruction>(*UI);
+      
+      // Don't need to update uses within the loop body
+      if (!std::binary_search(LoopBlocks.begin(), LoopBlocks.end(),
+          use->getParent())) {
+          
+        for (std::map<BasicBlock*, PHINode*>::iterator DI = ExitPhis.begin(),
+             DE = ExitPhis.end(); DI != DE; ++DI) {
+          if (DT->getNode((*DI).first)->dominates( \
+              DT->getNode(use->getParent())) && use != (*DI).second) {
+            use->replaceUsesOfWith(*I, (*DI).second);
+            break;
+          }
+        }
+          
+        for (std::map<BasicBlock*, PHINode*>::iterator DI = DFPhis.begin(),
+             DE = DFPhis.end(); DI != DE; ++DI) {
+          if (DT->getNode((*DI).first)->dominates( \
+              DT->getNode(use->getParent()))) {
+            use->replaceUsesOfWith(*I, (*DI).second);
+            break;
+          }
+        }
+      }
+    }
   }
+  
   return true; // FIXME: Should be more intelligent in our return value.
 }
 






More information about the llvm-commits mailing list