diff options
author | Chris Lattner <sabre@nondot.org> | 2007-08-05 00:02:00 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-08-05 00:02:00 +0000 |
commit | 77e05fe20de9870f183709235e76516bf907eeed (patch) | |
tree | 30f863d5ed38b5d5b0115fa37ea4f87e6665481d /llvm/lib/Analysis/PostDominators.cpp | |
parent | bd0fe01dafb7f115a882865494d139edd8a7f0a2 (diff) | |
download | bcm5719-llvm-77e05fe20de9870f183709235e76516bf907eeed.tar.gz bcm5719-llvm-77e05fe20de9870f183709235e76516bf907eeed.zip |
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.
llvm-svn: 40827
Diffstat (limited to 'llvm/lib/Analysis/PostDominators.cpp')
-rw-r--r-- | llvm/lib/Analysis/PostDominators.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/llvm/lib/Analysis/PostDominators.cpp b/llvm/lib/Analysis/PostDominators.cpp index e3169a5c838..244f8cdff52 100644 --- a/llvm/lib/Analysis/PostDominators.cpp +++ b/llvm/lib/Analysis/PostDominators.cpp @@ -27,28 +27,25 @@ char PostDominanceFrontier::ID = 0; 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 @@ unsigned PostDominatorTree::DFSPass(BasicBlock *V, InfoRec &VInfo, 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 @@ void PostDominatorTree::calculate(Function &F) { // 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]; |