[llvm-commits] CVS: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Oct 4 23:34:00 PDT 2003


Changes in directory llvm/lib/Transforms/Utils:

PromoteMemoryToRegister.cpp updated: 1.49 -> 1.50

---
Log message:

The VersionNumbers vector is only used during PHI placement.  Turn it into an argument, allowing us to get rid of the vector.


---
Diffs of the changes:

Index: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff -u llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.49 llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.50
--- llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.49	Sat Oct  4 23:26:39 2003
+++ llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp	Sat Oct  4 23:33:22 2003
@@ -49,9 +49,6 @@
     // AllocaLookup - Reverse mapping of Allocas
     std::map<AllocaInst*, unsigned>  AllocaLookup;
 
-    // VersionNumbers - Current version counters for each alloca
-    std::vector<unsigned> VersionNumbers;
-    
     // NewPhiNodes - The PhiNodes we're adding.
     std::map<BasicBlock*, std::vector<PHINode*> > NewPhiNodes;
 
@@ -67,15 +64,13 @@
   private:
     void RenamePass(BasicBlock *BB, BasicBlock *Pred,
                     std::vector<Value*> &IncVals);
-    bool QueuePhiNode(BasicBlock *BB, unsigned AllocaIdx);
+    bool QueuePhiNode(BasicBlock *BB, unsigned AllocaIdx, unsigned &Version);
   };
 }  // end of anonymous namespace
 
 void PromoteMem2Reg::run() {
   Function &F = *DF.getRoot()->getParent();
 
-  VersionNumbers.resize(Allocas.size());
-
   for (unsigned i = 0; i != Allocas.size(); ++i) {
     AllocaInst *AI = Allocas[i];
 
@@ -101,6 +96,7 @@
     // Compute the locations where PhiNodes need to be inserted.  Look at the
     // dominance frontier of EACH basic-block we have a write in.
     //
+    unsigned CurrentVersion = 0;
     while (!DefiningBlocks.empty()) {
       BasicBlock *BB = DefiningBlocks.back();
       DefiningBlocks.pop_back();
@@ -111,7 +107,7 @@
         const DominanceFrontier::DomSetType &S = it->second;
         for (DominanceFrontier::DomSetType::iterator P = S.begin(),PE = S.end();
              P != PE; ++P)
-          if (QueuePhiNode(*P, i))
+          if (QueuePhiNode(*P, i, CurrentVersion))
             DefiningBlocks.push_back(*P);
       }
     }
@@ -199,7 +195,8 @@
 // QueuePhiNode - queues a phi-node to be added to a basic-block for a specific
 // Alloca returns true if there wasn't already a phi-node for that variable
 //
-bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo) {
+bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo,
+                                  unsigned &Version) {
   // Look up the basic-block in question
   std::vector<PHINode*> &BBPNs = NewPhiNodes[BB];
   if (BBPNs.empty()) BBPNs.resize(Allocas.size());
@@ -211,8 +208,7 @@
   // BasicBlock.
   BBPNs[AllocaNo] = new PHINode(Allocas[AllocaNo]->getAllocatedType(),
                                 Allocas[AllocaNo]->getName() + "." +
-                                         utostr(VersionNumbers[AllocaNo]++),
-                                BB->begin());
+                                        utostr(Version++), BB->begin());
   return true;
 }
 





More information about the llvm-commits mailing list