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

Chris Lattner lattner at cs.uiuc.edu
Wed Aug 13 11:17:01 PDT 2003


Changes in directory llvm/lib/Transforms/Scalar:

Reassociate.cpp updated: 1.21 -> 1.22

---
Log message:

Assign arguments different ranks so they get grouped together


---
Diffs of the changes:

Index: llvm/lib/Transforms/Scalar/Reassociate.cpp
diff -u llvm/lib/Transforms/Scalar/Reassociate.cpp:1.21 llvm/lib/Transforms/Scalar/Reassociate.cpp:1.22
--- llvm/lib/Transforms/Scalar/Reassociate.cpp:1.21	Tue Aug 12 16:45:24 2003
+++ llvm/lib/Transforms/Scalar/Reassociate.cpp	Wed Aug 13 11:16:26 2003
@@ -37,7 +37,7 @@
 
   class Reassociate : public FunctionPass {
     std::map<BasicBlock*, unsigned> RankMap;
-    std::map<Instruction*, unsigned> InstRankMap;
+    std::map<Value*, unsigned> ValueRankMap;
   public:
     bool runOnFunction(Function &F);
 
@@ -58,6 +58,11 @@
 
 void Reassociate::BuildRankMap(Function &F) {
   unsigned i = 2;
+
+  // Assign distinct ranks to function arguments
+  for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I)
+    ValueRankMap[I] = ++i;
+
   ReversePostOrderTraversal<Function*> RPOT(&F);
   for (ReversePostOrderTraversal<Function*>::rpo_iterator I = RPOT.begin(),
          E = RPOT.end(); I != E; ++I)
@@ -65,7 +70,8 @@
 }
 
 unsigned Reassociate::getRank(Value *V) {
-  if (isa<Argument>(V)) return 1;   // Function argument...
+  if (isa<Argument>(V)) return ValueRankMap[V];   // Function argument...
+
   if (Instruction *I = dyn_cast<Instruction>(V)) {
     // If this is an expression, return the 1+MAX(rank(LHS), rank(RHS)) so that
     // we can reassociate expressions for code motion!  Since we do not recurse
@@ -78,7 +84,7 @@
         I->mayWriteToMemory())  // Cannot move inst if it writes to memory!
       return RankMap[I->getParent()];
 
-    unsigned &CachedRank = InstRankMap[I];
+    unsigned &CachedRank = ValueRankMap[I];
     if (CachedRank) return CachedRank;    // Rank already known?
 
     // If not, compute it!
@@ -278,6 +284,6 @@
 
   // We are done with the rank map...
   RankMap.clear();
-  InstRankMap.clear();
+  ValueRankMap.clear();
   return Changed;
 }





More information about the llvm-commits mailing list