[llvm-commits] [llvm] r40827 - in /llvm/trunk: include/llvm/Analysis/Dominators.h include/llvm/Analysis/PostDominators.h lib/Analysis/PostDominators.cpp lib/VMCore/Dominators.cpp

Chris Lattner sabre at nondot.org
Sat Aug 4 17:02:02 PDT 2007


Author: lattner
Date: Sat Aug  4 19:02:00 2007
New Revision: 40827

URL: http://llvm.org/viewvc/llvm-project?rev=40827&view=rev
Log:
Switch the internal "Info" map from an std::map to a DenseMap.  This
speeds up idom by about 45% and postidom by about 33%.

Some extra precautions must be taken not to invalidate densemap iterators.


Modified:
    llvm/trunk/include/llvm/Analysis/Dominators.h
    llvm/trunk/include/llvm/Analysis/PostDominators.h
    llvm/trunk/lib/Analysis/PostDominators.cpp
    llvm/trunk/lib/VMCore/Dominators.cpp

Modified: llvm/trunk/include/llvm/Analysis/Dominators.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Dominators.h?rev=40827&r1=40826&r2=40827&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/Dominators.h (original)
+++ llvm/trunk/include/llvm/Analysis/Dominators.h Sat Aug  4 19:02:00 2007
@@ -127,7 +127,7 @@
   std::vector<BasicBlock*> Vertex;
 
   // Info - Collection of information used during the computation of idoms.
-  std::map<BasicBlock*, InfoRec> Info;
+  DenseMap<BasicBlock*, InfoRec> Info;
 
   void updateDFSNumbers();
 
@@ -298,7 +298,7 @@
 private:
   void calculate(Function& F);
   DomTreeNode *getNodeForBlock(BasicBlock *BB);
-  unsigned DFSPass(BasicBlock *V, InfoRec &VInfo, unsigned N);
+  unsigned DFSPass(BasicBlock *V, unsigned N);
   void Compress(BasicBlock *V);
   BasicBlock *Eval(BasicBlock *v);
   void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);

Modified: llvm/trunk/include/llvm/Analysis/PostDominators.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/PostDominators.h?rev=40827&r1=40826&r2=40827&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/PostDominators.h (original)
+++ llvm/trunk/include/llvm/Analysis/PostDominators.h Sat Aug  4 19:02:00 2007
@@ -39,7 +39,7 @@
 private:
   void calculate(Function &F);
   DomTreeNode *getNodeForBlock(BasicBlock *BB);
-  unsigned DFSPass(BasicBlock *V, InfoRec &VInfo,unsigned N);
+  unsigned DFSPass(BasicBlock *V, unsigned N);
   void Compress(BasicBlock *V, InfoRec &VInfo);
   BasicBlock *Eval(BasicBlock *V);
   void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);

Modified: llvm/trunk/lib/Analysis/PostDominators.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/PostDominators.cpp?rev=40827&r1=40826&r2=40827&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/PostDominators.cpp (original)
+++ llvm/trunk/lib/Analysis/PostDominators.cpp Sat Aug  4 19:02:00 2007
@@ -27,28 +27,25 @@
 static RegisterPass<PostDominatorTree>
 F("postdomtree", "Post-Dominator Tree Construction", true);
 
-unsigned PostDominatorTree::DFSPass(BasicBlock *V, InfoRec &VInfo,
-                                    unsigned N) {
-  std::vector<std::pair<BasicBlock *, InfoRec *> > workStack;
+unsigned PostDominatorTree::DFSPass(BasicBlock *V, unsigned N) {
+  std::vector<BasicBlock *> workStack;
   std::set<BasicBlock *> visited;
-  workStack.push_back(std::make_pair(V, &VInfo));
+  workStack.push_back(V);
 
   do {
-    BasicBlock *currentBB = workStack.back().first; 
-    InfoRec *currentVInfo = workStack.back().second;
+    BasicBlock *currentBB = workStack.back();
+    InfoRec &CurVInfo = Info[currentBB];
 
     // Visit each block only once.
-    if (visited.count(currentBB) == 0) {
-
-      visited.insert(currentBB);
-      currentVInfo->Semi = ++N;
-      currentVInfo->Label = currentBB;
+    if (visited.insert(currentBB).second) {
+      CurVInfo.Semi = ++N;
+      CurVInfo.Label = currentBB;
       
       Vertex.push_back(currentBB);  // Vertex[n] = current;
       // Info[currentBB].Ancestor = 0;     
       // Ancestor[n] = 0
       // Child[currentBB] = 0;
-      currentVInfo->Size = 1;       // Size[currentBB] = 1
+      CurVInfo.Size = 1;       // Size[currentBB] = 1
     }
 
     // Visit children
@@ -58,8 +55,8 @@
       InfoRec &SuccVInfo = Info[*PI];
       if (SuccVInfo.Semi == 0) {
         SuccVInfo.Parent = currentBB;
-        if (visited.count (*PI) == 0) {
-          workStack.push_back(std::make_pair(*PI, &SuccVInfo));   
+        if (!visited.count(*PI)) {
+          workStack.push_back(*PI);   
           visitChild = true;
         }
       }
@@ -130,7 +127,7 @@
   // in later stages of the algorithm.
   unsigned N = 0;
   for (unsigned i = 0, e = Roots.size(); i != e; ++i)
-    N = DFSPass(Roots[i], Info[Roots[i]], N);
+    N = DFSPass(Roots[i], N);
   
   for (unsigned i = N; i >= 2; --i) {
     BasicBlock *W = Vertex[i];

Modified: llvm/trunk/lib/VMCore/Dominators.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Dominators.cpp?rev=40827&r1=40826&r2=40827&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Dominators.cpp (original)
+++ llvm/trunk/lib/VMCore/Dominators.cpp Sat Aug  4 19:02:00 2007
@@ -146,12 +146,12 @@
   }
 }
 
-unsigned DominatorTree::DFSPass(BasicBlock *V, InfoRec &VInfo,
-                                      unsigned N) {
+unsigned DominatorTree::DFSPass(BasicBlock *V, unsigned N) {
   // This is more understandable as a recursive algorithm, but we can't use the
   // recursive algorithm due to stack depth issues.  Keep it here for
   // documentation purposes.
 #if 0
+  InfoRec &VInfo = Info[Roots[i]];
   VInfo.Semi = ++N;
   VInfo.Label = V;
 
@@ -164,7 +164,7 @@
     InfoRec &SuccVInfo = Info[*SI];
     if (SuccVInfo.Semi == 0) {
       SuccVInfo.Parent = V;
-      N = DFSPass(*SI, SuccVInfo, N);
+      N = DFSPass(*SI, N);
     }
   }
 #else
@@ -313,7 +313,7 @@
 #endif
 }
 
-void DominatorTree::calculate(Function& F) {
+void DominatorTree::calculate(Function &F) {
   BasicBlock* Root = Roots[0];
 
   // Add a node for the root...
@@ -323,9 +323,7 @@
 
   // Step #1: Number blocks in depth-first order and initialize variables used
   // in later stages of the algorithm.
-  unsigned N = 0;
-  for (unsigned i = 0, e = Roots.size(); i != e; ++i)
-    N = DFSPass(Roots[i], Info[Roots[i]], 0);
+  unsigned N = DFSPass(Root, 0);
 
   for (unsigned i = N; i >= 2; --i) {
     BasicBlock *W = Vertex[i];





More information about the llvm-commits mailing list