[llvm-commits] [llvm] r50995 - /llvm/trunk/lib/Transforms/Scalar/GVN.cpp

Owen Anderson resistor at mac.com
Mon May 12 13:15:57 PDT 2008


Author: resistor
Date: Mon May 12 15:15:55 2008
New Revision: 50995

URL: http://llvm.org/viewvc/llvm-project?rev=50995&view=rev
Log:
Go back to passing the analyses around as parameters.

Modified:
    llvm/trunk/lib/Transforms/Scalar/GVN.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=50995&r1=50994&r2=50995&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Mon May 12 15:15:55 2008
@@ -42,10 +42,6 @@
 //                         ValueTable Class
 //===----------------------------------------------------------------------===//
 
-static DominatorTree* DT;
-static AliasAnalysis* AA;
-static MemoryDependenceAnalysis* MD;
-
 /// This class holds the mapping between values and value numbers.  It is used
 /// as an efficient mechanism to determine the expression-wise equivalence of
 /// two values.
@@ -133,6 +129,9 @@
     private:
       DenseMap<Value*, uint32_t> valueNumbering;
       DenseMap<Expression, uint32_t> expressionNumbering;
+      AliasAnalysis* AA;
+      MemoryDependenceAnalysis* MD;
+      DominatorTree* DT;
   
       uint32_t nextValueNumber;
     
@@ -156,6 +155,9 @@
       void clear();
       void erase(Value* v);
       unsigned size();
+      void setAliasAnalysis(AliasAnalysis* A) { AA = A; }
+      void setMemDep(MemoryDependenceAnalysis* M) { MD = M; }
+      void setDomTree(DominatorTree* D) { DT = D; }
   };
 }
 
@@ -734,6 +736,7 @@
 }
 
 Value* GVN::CollapsePhi(PHINode* p) {
+  DominatorTree &DT = getAnalysis<DominatorTree>();
   Value* constVal = p->hasConstantValue();
   
   if (!constVal) return 0;
@@ -742,7 +745,7 @@
   if (!inst)
     return constVal;
     
-  if (DT->dominates(inst, p))
+  if (DT.dominates(inst, p))
     if (isSafeReplacement(p, inst))
       return inst;
   return 0;
@@ -793,7 +796,8 @@
     PN->addIncoming(val, *PI);
   }
   
-  AA->copyValue(orig, PN);
+  AliasAnalysis& AA = getAnalysis<AliasAnalysis>();
+  AA.copyValue(orig, PN);
   
   // Attempt to collapse PHI nodes that are trivially redundant
   Value* v = CollapsePhi(PN);
@@ -802,8 +806,10 @@
     phiMap[orig->getPointerOperand()].insert(PN);
     return PN;
   }
+    
+  MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
 
-  MD->removeInstruction(PN);
+  MD.removeInstruction(PN);
   PN->replaceAllUsesWith(v);
 
   for (DenseMap<BasicBlock*, Value*>::iterator I = Phis.begin(),
@@ -821,9 +827,11 @@
 /// non-local by performing PHI construction.
 bool GVN::processNonLocalLoad(LoadInst* L,
                               SmallVectorImpl<Instruction*> &toErase) {
+  MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
+  
   // Find the non-local dependencies of the load
   DenseMap<BasicBlock*, Value*> deps;
-  MD->getNonLocalDependency(L, deps);
+  MD.getNonLocalDependency(L, deps);
   
   DenseMap<BasicBlock*, Value*> repl;
   
@@ -854,7 +862,7 @@
   for (SmallPtrSet<Instruction*, 4>::iterator I = p.begin(), E = p.end();
        I != E; ++I) {
     if ((*I)->getParent() == L->getParent()) {
-      MD->removeInstruction(L);
+      MD.removeInstruction(L);
       L->replaceAllUsesWith(*I);
       toErase.push_back(L);
       NumGVNLoad++;
@@ -868,7 +876,7 @@
   SmallPtrSet<BasicBlock*, 4> visited;
   Value* v = GetValueForBlock(L->getParent(), L, repl, true);
   
-  MD->removeInstruction(L);
+  MD.removeInstruction(L);
   L->replaceAllUsesWith(v);
   toErase.push_back(L);
   NumGVNLoad++;
@@ -889,8 +897,9 @@
   LoadInst*& last = lastLoad[pointer];
   
   // ... to a pointer that has been loaded from before...
+  MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
   bool removedNonLocal = false;
-  Instruction* dep = MD->getDependency(L);
+  Instruction* dep = MD.getDependency(L);
   if (dep == MemoryDependenceAnalysis::NonLocal &&
       L->getParent() != &L->getParent()->getParent()->getEntryBlock()) {
     removedNonLocal = processNonLocalLoad(L, toErase);
@@ -913,7 +922,7 @@
     if (StoreInst* S = dyn_cast<StoreInst>(dep)) {
       if (S->getPointerOperand() == pointer) {
         // Remove it!
-        MD->removeInstruction(L);
+        MD.removeInstruction(L);
         
         L->replaceAllUsesWith(S->getOperand(0));
         toErase.push_back(L);
@@ -930,7 +939,7 @@
       break;
     } else if (dep == last) {
       // Remove it!
-      MD->removeInstruction(L);
+      MD.removeInstruction(L);
       
       L->replaceAllUsesWith(last);
       toErase.push_back(L);
@@ -939,7 +948,7 @@
         
       break;
     } else {
-      dep = MD->getDependency(L, dep);
+      dep = MD.getDependency(L, dep);
     }
   }
 
@@ -961,7 +970,7 @@
       // If this load depends directly on an allocation, there isn't
       // anything stored there; therefore, we can optimize this load
       // to undef.
-      MD->removeInstruction(L);
+      MD.removeInstruction(L);
 
       L->replaceAllUsesWith(UndefValue::get(L->getType()));
       toErase.push_back(L);
@@ -1009,7 +1018,8 @@
     Value* repl = find_leader(currAvail, num);
     
     // Remove it!
-    MD->removeInstruction(I);
+    MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
+    MD.removeInstruction(I);
     
     VN.erase(I);
     I->replaceAllUsesWith(repl);
@@ -1027,9 +1037,9 @@
 // function.
 //
 bool GVN::runOnFunction(Function& F) {
-  DT = &getAnalysis<DominatorTree>();
-  AA = &getAnalysis<AliasAnalysis>();
-  MD = &getAnalysis<MemoryDependenceAnalysis>();
+  VN.setAliasAnalysis(&getAnalysis<AliasAnalysis>());
+  VN.setMemDep(&getAnalysis<MemoryDependenceAnalysis>());
+  VN.setDomTree(&getAnalysis<DominatorTree>());
   
   bool changed = false;
   bool shouldContinue = true;
@@ -1052,13 +1062,15 @@
  
   bool changed_function = false;
   
+  DominatorTree &DT = getAnalysis<DominatorTree>();   
+  
   SmallVector<Instruction*, 8> toErase;
   DenseMap<Value*, LoadInst*> lastSeenLoad;
   DenseMap<DomTreeNode*, size_t> numChildrenVisited;
 
   // Top-down walk of the dominator tree
-  for (df_iterator<DomTreeNode*> DI = df_begin(DT->getRootNode()),
-         E = df_end(DT->getRootNode()); DI != E; ++DI) {
+  for (df_iterator<DomTreeNode*> DI = df_begin(DT.getRootNode()),
+         E = df_end(DT.getRootNode()); DI != E; ++DI) {
     
     // Get the set to update for this block
     ValueNumberedSet& currAvail = availableOut[DI->getBlock()];     





More information about the llvm-commits mailing list