OSDN Git Service

[Dominators] Teach IDF to use level information
authorJakub Kuderski <kubakuderski@gmail.com>
Fri, 30 Jun 2017 21:51:43 +0000 (21:51 +0000)
committerJakub Kuderski <kubakuderski@gmail.com>
Fri, 30 Jun 2017 21:51:43 +0000 (21:51 +0000)
Summary: This patch teaches IteratedDominanceFrontier to use the level information stored in DomTreeNodes instead of calculating it manually.

Reviewers: dberlin, sanjoy, davide

Reviewed By: davide

Subscribers: davide, llvm-commits

Differential Revision: https://reviews.llvm.org/D34703

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

include/llvm/Analysis/IteratedDominanceFrontier.h
lib/Analysis/IteratedDominanceFrontier.cpp

index af788c8..bd74d6b 100644 (file)
@@ -86,7 +86,6 @@ public:
 private:
   DominatorTreeBase<BasicBlock> &DT;
   bool useLiveIn;
-  DenseMap<DomTreeNode *, unsigned> DomLevels;
   const SmallPtrSetImpl<BasicBlock *> *LiveInBlocks;
   const SmallPtrSetImpl<BasicBlock *> *DefBlocks;
 };
index 2a736ec..0e02850 100644 (file)
@@ -20,14 +20,6 @@ namespace llvm {
 template <class NodeTy>
 void IDFCalculator<NodeTy>::calculate(
     SmallVectorImpl<BasicBlock *> &PHIBlocks) {
-  // If we haven't computed dominator tree levels, do so now.
-  if (DomLevels.empty()) {
-    for (auto DFI = df_begin(DT.getRootNode()), DFE = df_end(DT.getRootNode());
-         DFI != DFE; ++DFI) {
-      DomLevels[*DFI] = DFI.getPathLength() - 1;
-    }
-  }
-
   // Use a priority queue keyed on dominator tree level so that inserted nodes
   // are handled from the bottom of the dominator tree upwards.
   typedef std::pair<DomTreeNode *, unsigned> DomTreeNodePair;
@@ -37,7 +29,7 @@ void IDFCalculator<NodeTy>::calculate(
 
   for (BasicBlock *BB : *DefBlocks) {
     if (DomTreeNode *Node = DT.getNode(BB))
-      PQ.push(std::make_pair(Node, DomLevels.lookup(Node)));
+      PQ.push({Node, Node->getLevel()});
   }
 
   SmallVector<DomTreeNode *, 32> Worklist;
@@ -72,7 +64,7 @@ void IDFCalculator<NodeTy>::calculate(
         if (SuccNode->getIDom() == Node)
           continue;
 
-        unsigned SuccLevel = DomLevels.lookup(SuccNode);
+        const unsigned SuccLevel = SuccNode->getLevel();
         if (SuccLevel > RootLevel)
           continue;