Make GVN more memory efficient, particularly on code that contains a large number of
authorOwen Anderson <resistor@mac.com>
Mon, 7 Apr 2008 09:59:07 +0000 (09:59 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 7 Apr 2008 09:59:07 +0000 (09:59 +0000)
allocations, which GVN can't optimize anyways.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49329 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/Dominators.h
lib/Transforms/Scalar/GVN.cpp

index 8d333de6b0be64e40236e6b641c74827a8014025..65cfb569aaa870e97174da53d5e384adaa4672a3 100644 (file)
@@ -103,6 +103,10 @@ public:
     return C;
   }
   
+  size_t getNumChildren() const {
+    return Children.size();
+  }
+  
   void setIDom(DomTreeNodeBase<NodeT> *NewIDom) {
     assert(IDom && "No immediate dominator?");
     if (IDom != NewIDom) {
index c966311c9e6be453d5cdb8f4000f3a4fbaeaba55..9a03c21593cc98b9197328c317bcf69904abb172 100644 (file)
@@ -1593,6 +1593,11 @@ bool GVN::processInstruction(Instruction *I, ValueNumberedSet &currAvail,
   if (StoreInst *SI = dyn_cast<StoreInst>(I))
     return processStore(SI, toErase);
   
+  // Allocations are always uniquely numbered, so we can save time and memory
+  // by fast failing them.
+  if (isa<AllocationInst>(I))
+    return false;
+  
   if (MemCpyInst* M = dyn_cast<MemCpyInst>(I)) {
     MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
 
@@ -1692,6 +1697,7 @@ bool GVN::iterateOnFunction(Function &F) {
   
   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()),
@@ -1704,8 +1710,16 @@ bool GVN::iterateOnFunction(Function &F) {
     BasicBlock* BB = DI->getBlock();
   
     // A block inherits AVAIL_OUT from its dominator
-    if (DI->getIDom() != 0)
+    if (DI->getIDom() != 0) {
       currAvail = availableOut[DI->getIDom()->getBlock()];
+      
+      numChildrenVisited[DI->getIDom()]++;
+      
+      if (numChildrenVisited[DI->getIDom()] == DI->getIDom()->getNumChildren()) {
+        availableOut.erase(DI->getIDom()->getBlock());
+        numChildrenVisited.erase(DI->getIDom());
+      }
+    }
 
     for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();
          BI != BE;) {