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

Devang Patel dpatel at apple.com
Thu Jun 7 14:57:32 PDT 2007



Changes in directory llvm/lib/Transforms/Utils:

Mem2Reg.cpp updated: 1.30 -> 1.31
PromoteMemoryToRegister.cpp updated: 1.100 -> 1.101
---
Log message:

Use DominatorTree instead of ETForest.
This allows faster immediate domiantor walk.


---
Diffs of the changes:  (+15 -13)

 Mem2Reg.cpp                 |    6 +++---
 PromoteMemoryToRegister.cpp |   22 ++++++++++++----------
 2 files changed, 15 insertions(+), 13 deletions(-)


Index: llvm/lib/Transforms/Utils/Mem2Reg.cpp
diff -u llvm/lib/Transforms/Utils/Mem2Reg.cpp:1.30 llvm/lib/Transforms/Utils/Mem2Reg.cpp:1.31
--- llvm/lib/Transforms/Utils/Mem2Reg.cpp:1.30	Sun May  6 08:37:16 2007
+++ llvm/lib/Transforms/Utils/Mem2Reg.cpp	Thu Jun  7 16:57:03 2007
@@ -38,7 +38,7 @@
     // getAnalysisUsage - We need dominance frontiers
     //
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.addRequired<ETForest>();
+      AU.addRequired<DominatorTree>();
       AU.addRequired<DominanceFrontier>();
       AU.setPreservesCFG();
       // This is a cluster of orthogonal Transforms
@@ -61,7 +61,7 @@
 
   bool Changed  = false;
 
-  ETForest     &ET = getAnalysis<ETForest>();
+  DominatorTree &DT = getAnalysis<DominatorTree>();
   DominanceFrontier &DF = getAnalysis<DominanceFrontier>();
 
   while (1) {
@@ -76,7 +76,7 @@
 
     if (Allocas.empty()) break;
 
-    PromoteMemToReg(Allocas, ET, DF);
+    PromoteMemToReg(Allocas, DT, DF);
     NumPromoted += Allocas.size();
     Changed = true;
   }


Index: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
diff -u llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.100 llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.101
--- llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.100	Wed Apr 25 13:32:35 2007
+++ llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp	Thu Jun  7 16:57:03 2007
@@ -88,7 +88,7 @@
     ///
     std::vector<AllocaInst*> Allocas;
     SmallVector<AllocaInst*, 16> &RetryList;
-    ETForest &ET;
+    DominatorTree &DT;
     DominanceFrontier &DF;
 
     /// AST - An AliasSetTracker object to update.  If null, don't update it.
@@ -126,9 +126,9 @@
 
   public:
     PromoteMem2Reg(const std::vector<AllocaInst*> &A,
-                   SmallVector<AllocaInst*, 16> &Retry, ETForest &et,
+                   SmallVector<AllocaInst*, 16> &Retry, DominatorTree &dt,
                    DominanceFrontier &df, AliasSetTracker *ast)
-      : Allocas(A), RetryList(Retry), ET(et), DF(df), AST(ast) {}
+      : Allocas(A), RetryList(Retry), DT(dt), DF(df), AST(ast) {}
 
     void run();
 
@@ -137,13 +137,13 @@
     bool properlyDominates(Instruction *I1, Instruction *I2) const {
       if (InvokeInst *II = dyn_cast<InvokeInst>(I1))
         I1 = II->getNormalDest()->begin();
-      return ET.properlyDominates(I1->getParent(), I2->getParent());
+      return DT.properlyDominates(I1->getParent(), I2->getParent());
     }
     
-    /// dominates - Return true if BB1 dominates BB2 using the ETForest.
+    /// dominates - Return true if BB1 dominates BB2 using the DominatorTree.
     ///
     bool dominates(BasicBlock *BB1, BasicBlock *BB2) const {
-      return ET.dominates(BB1, BB2);
+      return DT.dominates(BB1, BB2);
     }
 
   private:
@@ -532,7 +532,9 @@
                                       SmallPtrSet<PHINode*, 16> &DeadPHINodes) {
   // Scan the immediate dominators of this block looking for a block which has a
   // PHI node for Alloca num.  If we find it, mark the PHI node as being alive!
-  for (BasicBlock* DomBB = BB; DomBB; DomBB = ET.getIDom(DomBB)) {
+  DomTreeNode *IDomNode = DT.getNode(BB);
+  for (DomTreeNode *IDom = IDomNode; IDom; IDom = IDom->getIDom()) {
+    BasicBlock *DomBB = IDom->getBlock();
     DenseMap<std::pair<BasicBlock*, unsigned>, PHINode*>::iterator
       I = NewPhiNodes.find(std::make_pair(DomBB, AllocaNum));
     if (I != NewPhiNodes.end()) {
@@ -803,13 +805,13 @@
 /// made to the IR.
 ///
 void llvm::PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
-                           ETForest &ET, DominanceFrontier &DF,
+                           DominatorTree &DT, DominanceFrontier &DF,
                            AliasSetTracker *AST) {
   // If there is nothing to do, bail out...
   if (Allocas.empty()) return;
 
   SmallVector<AllocaInst*, 16> RetryList;
-  PromoteMem2Reg(Allocas, RetryList, ET, DF, AST).run();
+  PromoteMem2Reg(Allocas, RetryList, DT, DF, AST).run();
 
   // PromoteMem2Reg may not have been able to promote all of the allocas in one
   // pass, run it again if needed.
@@ -827,7 +829,7 @@
 
     NewAllocas.assign(RetryList.begin(), RetryList.end());
     RetryList.clear();
-    PromoteMem2Reg(NewAllocas, RetryList, ET, DF, AST).run();
+    PromoteMem2Reg(NewAllocas, RetryList, DT, DF, AST).run();
     NewAllocas.clear();
   }
 }






More information about the llvm-commits mailing list