Move more passes to using ETForest instead of DominatorTree.
authorOwen Anderson <resistor@mac.com>
Fri, 20 Apr 2007 06:27:13 +0000 (06:27 +0000)
committerOwen Anderson <resistor@mac.com>
Fri, 20 Apr 2007 06:27:13 +0000 (06:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36271 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Utils/PromoteMemToReg.h
lib/Transforms/Scalar/LICM.cpp
lib/Transforms/Scalar/ScalarReplAggregates.cpp
lib/Transforms/Utils/Mem2Reg.cpp
lib/Transforms/Utils/PromoteMemoryToRegister.cpp

index 44b11d7203ef5084b6d083f0bdb9437c54dfa615..a17e98c1f51fb7c3a0f213f94348f3a1816dedbd 100644 (file)
@@ -20,7 +20,7 @@
 namespace llvm {
 
 class AllocaInst;
-class DominatorTree;
+class ETForest;
 class DominanceFrontier;
 class TargetData;
 class AliasSetTracker;
@@ -39,7 +39,7 @@ bool isAllocaPromotable(const AllocaInst *AI, const TargetData &TD);
 /// made to the IR.
 ///
 void PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
-                     DominatorTree &DT, DominanceFrontier &DF,
+                     ETForest &ET, DominanceFrontier &DF,
                      const TargetData &TD, AliasSetTracker *AST = 0);
 
 } // End llvm namespace
index c9ade92804aecce006093ffbfe7561dafe49a949..3b71497dcb181111ecde458f7575ba493417ff51 100644 (file)
@@ -73,7 +73,6 @@ namespace {
       AU.addRequiredID(LoopSimplifyID);
       AU.addRequired<LoopInfo>();
       AU.addRequired<ETForest>();
-      AU.addRequired<DominatorTree>();      // For scalar promotion (mem2reg)
       AU.addRequired<DominanceFrontier>();  // For scalar promotion (mem2reg)
       AU.addRequired<AliasAnalysis>();
     }
@@ -88,7 +87,6 @@ namespace {
     AliasAnalysis *AA;       // Current AliasAnalysis information
     LoopInfo      *LI;       // Current LoopInfo
     ETForest *ET;       // ETForest for the current Loop...
-    DominatorTree *DT;       // Dominator Tree for the current Loop...
     DominanceFrontier *DF;   // Current Dominance Frontier
 
     // State that is updated as we process loops
@@ -215,7 +213,6 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
   AA = &getAnalysis<AliasAnalysis>();
   DF = &getAnalysis<DominanceFrontier>();
   ET = &getAnalysis<ETForest>();
-  DT = &getAnalysis<DominatorTree>();
 
   CurAST = new AliasSetTracker(*AA);
   // Collect Alias info frmo subloops
@@ -554,7 +551,7 @@ void LICM::sink(Instruction &I) {
     if (AI) {
       std::vector<AllocaInst*> Allocas;
       Allocas.push_back(AI);
-      PromoteMemToReg(Allocas, *DT, *DF, AA->getTargetData(), CurAST);
+      PromoteMemToReg(Allocas, *ET, *DF, AA->getTargetData(), CurAST);
     }
   }
 }
@@ -735,7 +732,7 @@ void LICM::PromoteValuesInLoop() {
   PromotedAllocas.reserve(PromotedValues.size());
   for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i)
     PromotedAllocas.push_back(PromotedValues[i].first);
-  PromoteMemToReg(PromotedAllocas, *DT, *DF, AA->getTargetData(), CurAST);
+  PromoteMemToReg(PromotedAllocas, *ET, *DF, AA->getTargetData(), CurAST);
 }
 
 /// FindPromotableValuesInLoop - Check the current loop for stores to definite
index 5bbb5aef03f0ccfccf741d3db0ed0079db7a3901..6e9dc035c227910fe11ea816d111eec757760f01 100644 (file)
@@ -53,7 +53,7 @@ namespace {
     // getAnalysisUsage - This pass does not require any passes, but we know it
     // will not alter the CFG, so say so.
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.addRequired<DominatorTree>();
+      AU.addRequired<ETForest>();
       AU.addRequired<DominanceFrontier>();
       AU.addRequired<TargetData>();
       AU.setPreservesCFG();
@@ -100,7 +100,7 @@ bool SROA::runOnFunction(Function &F) {
 bool SROA::performPromotion(Function &F) {
   std::vector<AllocaInst*> Allocas;
   const TargetData &TD = getAnalysis<TargetData>();
-  DominatorTree     &DT = getAnalysis<DominatorTree>();
+  ETForest         &ET = getAnalysis<ETForest>();
   DominanceFrontier &DF = getAnalysis<DominanceFrontier>();
 
   BasicBlock &BB = F.getEntryBlock();  // Get the entry node for the function
@@ -119,7 +119,7 @@ bool SROA::performPromotion(Function &F) {
 
     if (Allocas.empty()) break;
 
-    PromoteMemToReg(Allocas, DT, DF, TD);
+    PromoteMemToReg(Allocas, ET, DF, TD);
     NumPromoted += Allocas.size();
     Changed = true;
   }
index 6e2bcb08fe36ece74fa9b5bb741757efebde8ee0..9bcf0ab64867cb155bfd4b8342b630ae7e1e8618 100644 (file)
@@ -36,7 +36,7 @@ namespace {
     // getAnalysisUsage - We need dominance frontiers
     //
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.addRequired<DominatorTree>();
+      AU.addRequired<ETForest>();
       AU.addRequired<DominanceFrontier>();
       AU.addRequired<TargetData>();
       AU.setPreservesCFG();
@@ -60,7 +60,7 @@ bool PromotePass::runOnFunction(Function &F) {
 
   bool Changed  = false;
 
-  DominatorTree     &DT = getAnalysis<DominatorTree>();
+  ETForest     &ET = getAnalysis<ETForest>();
   DominanceFrontier &DF = getAnalysis<DominanceFrontier>();
 
   while (1) {
@@ -75,7 +75,7 @@ bool PromotePass::runOnFunction(Function &F) {
 
     if (Allocas.empty()) break;
 
-    PromoteMemToReg(Allocas, DT, DF, TD);
+    PromoteMemToReg(Allocas, ET, DF, TD);
     NumPromoted += Allocas.size();
     Changed = true;
   }
index be80423852592c988b8070336de13693acbf809b..25d9ef50ecac35490a4efaafa5203d37e0ceaed5 100644 (file)
@@ -88,7 +88,7 @@ namespace {
     ///
     std::vector<AllocaInst*> Allocas;
     SmallVector<AllocaInst*, 16> &RetryList;
-    DominatorTree &DT;
+    ETForest &ET;
     DominanceFrontier &DF;
     const TargetData &TD;
 
@@ -127,10 +127,10 @@ namespace {
 
   public:
     PromoteMem2Reg(const std::vector<AllocaInst*> &A,
-                   SmallVector<AllocaInst*, 16> &Retry, DominatorTree &dt,
+                   SmallVector<AllocaInst*, 16> &Retry, ETForest &et,
                    DominanceFrontier &df, const TargetData &td,
                    AliasSetTracker *ast)
-      : Allocas(A), RetryList(Retry), DT(dt), DF(df), TD(td), AST(ast) {}
+      : Allocas(A), RetryList(Retry), ET(et), DF(df), TD(td), AST(ast) {}
 
     void run();
 
@@ -139,13 +139,13 @@ namespace {
     bool properlyDominates(Instruction *I1, Instruction *I2) const {
       if (InvokeInst *II = dyn_cast<InvokeInst>(I1))
         I1 = II->getNormalDest()->begin();
-      return DT[I1->getParent()]->properlyDominates(DT[I2->getParent()]);
+      return ET.properlyDominates(I1->getParent(), I2->getParent());
     }
     
     /// dominates - Return true if BB1 dominates BB2 using the DominatorTree.
     ///
     bool dominates(BasicBlock *BB1, BasicBlock *BB2) const {
-      return DT[BB1]->dominates(DT[BB2]);
+      return ET.dominates(BB1, BB2);
     }
 
   private:
@@ -534,8 +534,7 @@ void PromoteMem2Reg::MarkDominatingPHILive(BasicBlock *BB, unsigned AllocaNum,
                                       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 (DominatorTree::Node *N = DT[BB]; N; N = N->getIDom()) {
-    BasicBlock *DomBB = N->getBlock();
+  for (BasicBlock* DomBB = BB; DomBB; DomBB = ET.getIDom(DomBB)) {
     DenseMap<std::pair<BasicBlock*, unsigned>, PHINode*>::iterator
       I = NewPhiNodes.find(std::make_pair(DomBB, AllocaNum));
     if (I != NewPhiNodes.end()) {
@@ -806,13 +805,13 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
 /// made to the IR.
 ///
 void llvm::PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
-                           DominatorTree &DT, DominanceFrontier &DF,
+                           ETForest &ET, DominanceFrontier &DF,
                            const TargetData &TD, AliasSetTracker *AST) {
   // If there is nothing to do, bail out...
   if (Allocas.empty()) return;
 
   SmallVector<AllocaInst*, 16> RetryList;
-  PromoteMem2Reg(Allocas, RetryList, DT, DF, TD, AST).run();
+  PromoteMem2Reg(Allocas, RetryList, ET, DF, TD, AST).run();
 
   // PromoteMem2Reg may not have been able to promote all of the allocas in one
   // pass, run it again if needed.
@@ -830,7 +829,7 @@ void llvm::PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
 
     NewAllocas.assign(RetryList.begin(), RetryList.end());
     RetryList.clear();
-    PromoteMem2Reg(NewAllocas, RetryList, DT, DF, TD, AST).run();
+    PromoteMem2Reg(NewAllocas, RetryList, ET, DF, TD, AST).run();
     NewAllocas.clear();
   }
 }