[llvm-commits] [llvm] r60255 - in /llvm/trunk: include/llvm/Analysis/MemoryDependenceAnalysis.h lib/Analysis/MemoryDependenceAnalysis.cpp lib/Transforms/Scalar/GVN.cpp

Chris Lattner sabre at nondot.org
Sat Nov 29 13:33:22 PST 2008


Author: lattner
Date: Sat Nov 29 15:33:22 2008
New Revision: 60255

URL: http://llvm.org/viewvc/llvm-project?rev=60255&view=rev
Log:
Change MemDep::getNonLocalDependency to return its results as
a smallvector instead of a DenseMap.  This speeds up GVN by 5%
on 403.gcc.

Modified:
    llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
    llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
    llvm/trunk/lib/Transforms/Scalar/GVN.cpp

Modified: llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h?rev=60255&r1=60254&r2=60255&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h Sat Nov 29 15:33:22 2008
@@ -175,7 +175,8 @@
     /// This method assumes the instruction returns a "nonlocal" dependency
     /// within its own block.
     void getNonLocalDependency(Instruction *QueryInst,
-                               DenseMap<BasicBlock*, MemDepResult> &Result);
+                               SmallVectorImpl<std::pair<BasicBlock*, 
+                                                       MemDepResult> > &Result);
     
     /// removeInstruction - Remove an instruction from the dependence analysis,
     /// updating the dependence of instructions that previously depended on it.

Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=60255&r1=60254&r2=60255&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Sat Nov 29 15:33:22 2008
@@ -104,8 +104,10 @@
 /// This method assumes the instruction returns a "nonlocal" dependency
 /// within its own block.
 ///
-void MemoryDependenceAnalysis::getNonLocalDependency(Instruction *QueryInst,
-                                  DenseMap<BasicBlock*, MemDepResult> &Result) {
+void MemoryDependenceAnalysis::
+getNonLocalDependency(Instruction *QueryInst,
+                      SmallVectorImpl<std::pair<BasicBlock*, 
+                                                      MemDepResult> > &Result) {
   assert(getDependency(QueryInst).isNonLocal() &&
      "getNonLocalDependency should only be used on insts with non-local deps!");
   DenseMap<BasicBlock*, DepResultTy> &Cache = NonLocalDeps[QueryInst];
@@ -128,10 +130,7 @@
   } else {
     // Seed DirtyBlocks with each of the preds of QueryInst's block.
     BasicBlock *QueryBB = QueryInst->getParent();
-    // FIXME: use range insertion/append.
-    for (pred_iterator PI = pred_begin(QueryBB), E = pred_end(QueryBB);
-         PI != E; ++PI)
-      DirtyBlocks.push_back(*PI);
+    DirtyBlocks.append(pred_begin(QueryBB), pred_end(QueryBB));
     NumUncacheNonlocal++;
   }
 
@@ -173,7 +172,7 @@
   // Copy the result into the output set.
   for (DenseMap<BasicBlock*, DepResultTy>::iterator I = Cache.begin(),
        E = Cache.end(); I != E; ++I)
-    Result[I->first] = ConvToResult(I->second);
+    Result.push_back(std::make_pair(I->first, ConvToResult(I->second)));
 }
 
 /// getDependency - Return the instruction on which a memory operation

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

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Sat Nov 29 15:33:22 2008
@@ -495,11 +495,11 @@
       }
       
       
-      DenseMap<BasicBlock*, MemDepResult> deps;
+      SmallVector<std::pair<BasicBlock*, MemDepResult>, 32> deps;
       MD->getNonLocalDependency(C, deps);
       CallInst* cdep = 0;
       
-      for (DenseMap<BasicBlock*, MemDepResult>
+      for (SmallVector<std::pair<BasicBlock*, MemDepResult>, 32>
              ::iterator I = deps.begin(), E = deps.end(); I != E; ++I) {
         if (I->second.isNone()) {
           valueNumbering.insert(std::make_pair(V, nextValueNumber));
@@ -871,7 +871,7 @@
   MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
   
   // Find the non-local dependencies of the load
-  DenseMap<BasicBlock*, MemDepResult> deps;
+  SmallVector<std::pair<BasicBlock*, MemDepResult>, 32> deps;
   MD.getNonLocalDependency(L, deps);
   
   // If we had to process more than one hundred blocks to find the
@@ -885,8 +885,8 @@
   DenseMap<BasicBlock*, Value*> repl;
   
   // Filter out useless results (non-locals, etc)
-  for (DenseMap<BasicBlock*, MemDepResult>::iterator I = deps.begin(),
-       E = deps.end(); I != E; ++I) {
+  for (SmallVector<std::pair<BasicBlock*, MemDepResult>, 32>::iterator
+       I = deps.begin(), E = deps.end(); I != E; ++I) {
     if (I->second.isNone()) {
       repl[I->first] = UndefValue::get(L->getType());
       continue;





More information about the llvm-commits mailing list