Index: llvm/trunk/include/llvm/Analysis/DominanceFrontier.h =================================================================== --- llvm/trunk/include/llvm/Analysis/DominanceFrontier.h +++ llvm/trunk/include/llvm/Analysis/DominanceFrontier.h @@ -29,9 +29,9 @@ /// DominanceFrontierBase - Common base class for computing forward and inverse /// dominance frontiers for a function. /// -template +template class DominanceFrontierBase { -public: + public: typedef std::set DomSetType; // Dom set for a bb typedef std::map DomSetMapType; // Dom set map @@ -40,10 +40,10 @@ DomSetMapType Frontiers; std::vector Roots; - const bool IsPostDominators; + static constexpr bool IsPostDominators = IsPostDom; -public: - DominanceFrontierBase(bool isPostDom) : IsPostDominators(isPostDom) {} + public: + DominanceFrontierBase() = default; /// getRoots - Return the root blocks of the current CFG. This may include /// multiple blocks if we are computing post dominators. For forward @@ -96,7 +96,7 @@ /// compare - Return true if the other dominance frontier base matches /// this dominance frontier base. Otherwise return false. - bool compare(DominanceFrontierBase &Other) const; + bool compare(DominanceFrontierBase &Other) const; /// print - Convert to human readable form /// @@ -113,22 +113,21 @@ /// used to compute a forward dominator frontiers. /// template -class ForwardDominanceFrontierBase : public DominanceFrontierBase { -private: +class ForwardDominanceFrontierBase + : public DominanceFrontierBase { + private: typedef GraphTraits BlockTraits; public: - typedef DominatorTreeBase DomTreeT; - typedef DomTreeNodeBase DomTreeNodeT; - typedef typename DominanceFrontierBase::DomSetType DomSetType; - - ForwardDominanceFrontierBase() : DominanceFrontierBase(false) {} - - void analyze(DomTreeT &DT) { - this->Roots = DT.getRoots(); - assert(this->Roots.size() == 1 && - "Only one entry block for forward domfronts!"); - calculate(DT, DT[this->Roots[0]]); + typedef DomTreeBase DomTreeT; + typedef DomTreeNodeBase DomTreeNodeT; + typedef typename DominanceFrontierBase::DomSetType DomSetType; + + void analyze(DomTreeT &DT) { + this->Roots = DT.getRoots(); + assert(this->Roots.size() == 1 && + "Only one entry block for forward domfronts!"); + calculate(DT, DT[this->Roots[0]]); } const DomSetType &calculate(const DomTreeT &DT, const DomTreeNodeT *Node); @@ -136,15 +135,16 @@ class DominanceFrontier : public ForwardDominanceFrontierBase { public: - typedef DominatorTreeBase DomTreeT; - typedef DomTreeNodeBase DomTreeNodeT; - typedef DominanceFrontierBase::DomSetType DomSetType; - typedef DominanceFrontierBase::iterator iterator; - typedef DominanceFrontierBase::const_iterator const_iterator; - - /// Handle invalidation explicitly. - bool invalidate(Function &F, const PreservedAnalyses &PA, - FunctionAnalysisManager::Invalidator &); + typedef DomTreeBase DomTreeT; + typedef DomTreeNodeBase DomTreeNodeT; + typedef DominanceFrontierBase::DomSetType DomSetType; + typedef DominanceFrontierBase::iterator iterator; + typedef DominanceFrontierBase::const_iterator + const_iterator; + + /// Handle invalidation explicitly. + bool invalidate(Function &F, const PreservedAnalyses &PA, + FunctionAnalysisManager::Invalidator &); }; class DominanceFrontierWrapperPass : public FunctionPass { @@ -168,7 +168,8 @@ void dump() const; }; -extern template class DominanceFrontierBase; +extern template class DominanceFrontierBase; +extern template class DominanceFrontierBase; extern template class ForwardDominanceFrontierBase; /// \brief Analysis pass which computes a \c DominanceFrontier. Index: llvm/trunk/include/llvm/Analysis/DominanceFrontierImpl.h =================================================================== --- llvm/trunk/include/llvm/Analysis/DominanceFrontierImpl.h +++ llvm/trunk/include/llvm/Analysis/DominanceFrontierImpl.h @@ -39,33 +39,33 @@ const DomTreeNodeT *parentNode; }; -template -void DominanceFrontierBase::removeBlock(BlockT *BB) { +template +void DominanceFrontierBase::removeBlock(BlockT *BB) { assert(find(BB) != end() && "Block is not in DominanceFrontier!"); for (iterator I = begin(), E = end(); I != E; ++I) I->second.erase(BB); Frontiers.erase(BB); } -template -void DominanceFrontierBase::addToFrontier(iterator I, - BlockT *Node) { +template +void DominanceFrontierBase::addToFrontier(iterator I, + BlockT *Node) { assert(I != end() && "BB is not in DominanceFrontier!"); assert(I->second.count(Node) && "Node is not in DominanceFrontier of BB"); I->second.erase(Node); } -template -void DominanceFrontierBase::removeFromFrontier(iterator I, - BlockT *Node) { +template +void DominanceFrontierBase::removeFromFrontier( + iterator I, BlockT *Node) { assert(I != end() && "BB is not in DominanceFrontier!"); assert(I->second.count(Node) && "Node is not in DominanceFrontier of BB"); I->second.erase(Node); } -template -bool DominanceFrontierBase::compareDomSet(DomSetType &DS1, - const DomSetType &DS2) const { +template +bool DominanceFrontierBase::compareDomSet( + DomSetType &DS1, const DomSetType &DS2) const { std::set tmpSet; for (BlockT *BB : DS2) tmpSet.insert(BB); @@ -88,9 +88,9 @@ return false; } -template -bool DominanceFrontierBase::compare( - DominanceFrontierBase &Other) const { +template +bool DominanceFrontierBase::compare( + DominanceFrontierBase &Other) const { DomSetMapType tmpFrontiers; for (typename DomSetMapType::const_iterator I = Other.begin(), E = Other.end(); @@ -118,8 +118,8 @@ return false; } -template -void DominanceFrontierBase::print(raw_ostream &OS) const { +template +void DominanceFrontierBase::print(raw_ostream &OS) const { for (const_iterator I = begin(), E = end(); I != E; ++I) { OS << " DomFrontier for BB "; if (I->first) @@ -142,8 +142,8 @@ } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) -template -void DominanceFrontierBase::dump() const { +template +void DominanceFrontierBase::dump() const { print(dbgs()); } #endif Index: llvm/trunk/include/llvm/Analysis/IteratedDominanceFrontier.h =================================================================== --- llvm/trunk/include/llvm/Analysis/IteratedDominanceFrontier.h +++ llvm/trunk/include/llvm/Analysis/IteratedDominanceFrontier.h @@ -42,11 +42,11 @@ /// By default, liveness is not used to prune the IDF computation. /// The template parameters should be either BasicBlock* or Inverse, depending on if you want the forward or reverse IDF. -template +template class IDFCalculator { - -public: - IDFCalculator(DominatorTreeBase &DT) : DT(DT), useLiveIn(false) {} + public: + IDFCalculator(DominatorTreeBase &DT) + : DT(DT), useLiveIn(false) {} /// \brief Give the IDF calculator the set of blocks in which the value is /// defined. This is equivalent to the set of starting blocks it should be @@ -84,12 +84,12 @@ void calculate(SmallVectorImpl &IDFBlocks); private: - DominatorTreeBase &DT; - bool useLiveIn; - const SmallPtrSetImpl *LiveInBlocks; - const SmallPtrSetImpl *DefBlocks; + DominatorTreeBase &DT; + bool useLiveIn; + const SmallPtrSetImpl *LiveInBlocks; + const SmallPtrSetImpl *DefBlocks; }; -typedef IDFCalculator ForwardIDFCalculator; -typedef IDFCalculator> ReverseIDFCalculator; +typedef IDFCalculator ForwardIDFCalculator; +typedef IDFCalculator, true> ReverseIDFCalculator; } #endif Index: llvm/trunk/include/llvm/Analysis/LoopInfo.h =================================================================== --- llvm/trunk/include/llvm/Analysis/LoopInfo.h +++ llvm/trunk/include/llvm/Analysis/LoopInfo.h @@ -56,7 +56,8 @@ class MDNode; class PHINode; class raw_ostream; -template class DominatorTreeBase; +template +class DominatorTreeBase; template class LoopInfoBase; template class LoopBase; @@ -663,12 +664,12 @@ } /// Create the loop forest using a stable algorithm. - void analyze(const DominatorTreeBase &DomTree); + void analyze(const DominatorTreeBase &DomTree); // Debugging void print(raw_ostream &OS) const; - void verify(const DominatorTreeBase &DomTree) const; + void verify(const DominatorTreeBase &DomTree) const; }; // Implementation in LoopInfoImpl.h @@ -683,7 +684,7 @@ LoopInfo(const LoopInfo &) = delete; public: LoopInfo() {} - explicit LoopInfo(const DominatorTreeBase &DomTree); + explicit LoopInfo(const DominatorTreeBase &DomTree); LoopInfo(LoopInfo &&Arg) : BaseT(std::move(static_cast(Arg))) {} LoopInfo &operator=(LoopInfo &&RHS) { Index: llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h =================================================================== --- llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h +++ llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h @@ -340,10 +340,10 @@ /// Discover a subloop with the specified backedges such that: All blocks within /// this loop are mapped to this loop or a subloop. And all subloops within this /// loop have their parent loop set to this loop or a subloop. -template -static void discoverAndMapSubloop(LoopT *L, ArrayRef Backedges, - LoopInfoBase *LI, - const DominatorTreeBase &DomTree) { +template +static void discoverAndMapSubloop( + LoopT *L, ArrayRef Backedges, LoopInfoBase *LI, + const DomTreeBase &DomTree) { typedef GraphTraits > InvBlockTraits; unsigned NumBlocks = 0; @@ -462,10 +462,9 @@ /// /// The Block vectors are inclusive, so step 3 requires loop-depth number of /// insertions per block. -template -void LoopInfoBase:: -analyze(const DominatorTreeBase &DomTree) { - +template +void LoopInfoBase::analyze( + const DomTreeBase &DomTree) { // Postorder traversal of the dominator tree. const DomTreeNodeBase *DomRoot = DomTree.getRootNode(); for (auto DomNode : post_order(DomRoot)) { @@ -607,7 +606,7 @@ template void LoopInfoBase::verify( - const DominatorTreeBase &DomTree) const { + const DomTreeBase &DomTree) const { DenseSet Loops; for (iterator I = begin(), E = end(); I != E; ++I) { assert(!(*I)->getParentLoop() && "Top-level loop has a parent!"); Index: llvm/trunk/include/llvm/Analysis/PostDominators.h =================================================================== --- llvm/trunk/include/llvm/Analysis/PostDominators.h +++ llvm/trunk/include/llvm/Analysis/PostDominators.h @@ -22,10 +22,8 @@ /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to /// compute the post-dominator tree. /// -struct PostDominatorTree : public DominatorTreeBase { - typedef DominatorTreeBase Base; - - PostDominatorTree() : DominatorTreeBase(true) {} +struct PostDominatorTree : public PostDomTreeBase { + typedef PostDomTreeBase Base; /// Handle invalidation explicitly. bool invalidate(Function &F, const PreservedAnalyses &PA, Index: llvm/trunk/include/llvm/CodeGen/MachineDominanceFrontier.h =================================================================== --- llvm/trunk/include/llvm/CodeGen/MachineDominanceFrontier.h +++ llvm/trunk/include/llvm/CodeGen/MachineDominanceFrontier.h @@ -23,27 +23,24 @@ ForwardDominanceFrontierBase Base; public: - using DomTreeT = DominatorTreeBase; - using DomTreeNodeT = DomTreeNodeBase; - using DomSetType = DominanceFrontierBase::DomSetType; - using iterator = DominanceFrontierBase::iterator; - using const_iterator = - DominanceFrontierBase::const_iterator; + using DomTreeT = DomTreeBase; + using DomTreeNodeT = DomTreeNodeBase; + using DomSetType = DominanceFrontierBase::DomSetType; + using iterator = DominanceFrontierBase::iterator; + using const_iterator = + DominanceFrontierBase::const_iterator; - MachineDominanceFrontier(const MachineDominanceFrontier &) = delete; - MachineDominanceFrontier & - operator=(const MachineDominanceFrontier &) = delete; + MachineDominanceFrontier(const MachineDominanceFrontier &) = delete; + MachineDominanceFrontier &operator=(const MachineDominanceFrontier &) = delete; - static char ID; + static char ID; - MachineDominanceFrontier(); + MachineDominanceFrontier(); - DominanceFrontierBase &getBase() { - return Base; - } + DominanceFrontierBase &getBase() { return Base; } - inline const std::vector &getRoots() const { - return Base.getRoots(); + inline const std::vector &getRoots() const { + return Base.getRoots(); } MachineBasicBlock *getRoot() const { @@ -98,7 +95,7 @@ return Base.compareDomSet(DS1, DS2); } - bool compare(DominanceFrontierBase &Other) const { + bool compare(DominanceFrontierBase &Other) const { return Base.compare(Other); } Index: llvm/trunk/include/llvm/CodeGen/MachineDominators.h =================================================================== --- llvm/trunk/include/llvm/CodeGen/MachineDominators.h +++ llvm/trunk/include/llvm/CodeGen/MachineDominators.h @@ -28,13 +28,15 @@ namespace llvm { -template<> -inline void DominatorTreeBase::addRoot(MachineBasicBlock* MBB) { +template <> +inline void DominatorTreeBase::addRoot( + MachineBasicBlock *MBB) { this->Roots.push_back(MBB); } extern template class DomTreeNodeBase; -extern template class DominatorTreeBase; +extern template class DominatorTreeBase; // DomTree +extern template class DominatorTreeBase; // PostDomTree using MachineDomTreeNode = DomTreeNodeBase; @@ -65,7 +67,7 @@ mutable SmallSet NewBBs; /// The DominatorTreeBase that is used to compute a normal dominator tree - std::unique_ptr> DT; + std::unique_ptr> DT; /// \brief Apply all the recorded critical edges to the DT. /// This updates the underlying DT information in a way that uses @@ -79,9 +81,8 @@ MachineDominatorTree(); - DominatorTreeBase &getBase() { - if (!DT) - DT.reset(new DominatorTreeBase(false)); + DomTreeBase &getBase() { + if (!DT) DT.reset(new DomTreeBase()); applySplitCriticalEdges(); return *DT; } Index: llvm/trunk/include/llvm/CodeGen/MachinePostDominators.h =================================================================== --- llvm/trunk/include/llvm/CodeGen/MachinePostDominators.h +++ llvm/trunk/include/llvm/CodeGen/MachinePostDominators.h @@ -26,7 +26,7 @@ /// struct MachinePostDominatorTree : public MachineFunctionPass { private: - DominatorTreeBase *DT; + PostDomTreeBase *DT; public: static char ID; Index: llvm/trunk/include/llvm/IR/Dominators.h =================================================================== --- llvm/trunk/include/llvm/IR/Dominators.h +++ llvm/trunk/include/llvm/IR/Dominators.h @@ -34,14 +34,19 @@ class raw_ostream; extern template class DomTreeNodeBase; -extern template class DominatorTreeBase; +extern template class DominatorTreeBase; // DomTree +extern template class DominatorTreeBase; // PostDomTree namespace DomTreeBuilder { -using BBDomTree = DominatorTreeBase; +using BBDomTree = DomTreeBase; +using BBPostDomTree = PostDomTreeBase; extern template void Calculate(BBDomTree &DT, Function &F); +extern template void Calculate(BBPostDomTree &DT, + Function &F); extern template bool Verify(const BBDomTree &DT); +extern template bool Verify(const BBPostDomTree &DT); } // namespace DomTreeBuilder using DomTreeNode = DomTreeNodeBase; @@ -114,14 +119,12 @@ /// the dominator tree is initially constructed may still exist in the tree, /// even if the tree is properly updated. Calling code should not rely on the /// preceding statements; this is stated only to assist human understanding. -class DominatorTree : public DominatorTreeBase { -public: - using Base = DominatorTreeBase; +class DominatorTree : public DominatorTreeBase { + public: + using Base = DominatorTreeBase; - DominatorTree() : DominatorTreeBase(false) {} - explicit DominatorTree(Function &F) : DominatorTreeBase(false) { - recalculate(F); - } + DominatorTree() = default; + explicit DominatorTree(Function &F) { recalculate(F); } /// Handle invalidation explicitly. bool invalidate(Function &F, const PreservedAnalyses &PA, Index: llvm/trunk/include/llvm/Support/GenericDomTree.h =================================================================== --- llvm/trunk/include/llvm/Support/GenericDomTree.h +++ llvm/trunk/include/llvm/Support/GenericDomTree.h @@ -41,12 +41,14 @@ namespace llvm { -template class DominatorTreeBase; +template +class DominatorTreeBase; /// \brief Base class for the actual dominator tree node. template class DomTreeNodeBase { friend struct PostDominatorTree; - friend class DominatorTreeBase; + friend class DominatorTreeBase; + friend class DominatorTreeBase; NodeT *TheBB; DomTreeNodeBase *IDom; @@ -185,7 +187,7 @@ void Calculate(DomTreeT &DT, FuncT &F); // The verify function is provided in a separate header but referenced here. -template +template bool Verify(const DomTreeT &DT); } // namespace DomTreeBuilder @@ -193,10 +195,10 @@ /// /// This class is a generic template over graph nodes. It is instantiated for /// various graphs in the LLVM IR or in the code generator. -template class DominatorTreeBase { +template +class DominatorTreeBase { protected: std::vector Roots; - bool IsPostDominators; using DomTreeNodeMapType = DenseMap>>; @@ -213,11 +215,12 @@ "Currently DominatorTreeBase supports only pointer nodes"); using NodeType = NodeT; using NodePtr = NodeT *; - explicit DominatorTreeBase(bool isPostDom) : IsPostDominators(isPostDom) {} + static constexpr bool IsPostDominator = IsPostDom; + + DominatorTreeBase() = default; DominatorTreeBase(DominatorTreeBase &&Arg) : Roots(std::move(Arg.Roots)), - IsPostDominators(Arg.IsPostDominators), DomTreeNodes(std::move(Arg.DomTreeNodes)), RootNode(std::move(Arg.RootNode)), DFSInfoValid(std::move(Arg.DFSInfoValid)), @@ -227,7 +230,6 @@ DominatorTreeBase &operator=(DominatorTreeBase &&RHS) { Roots = std::move(RHS.Roots); - IsPostDominators = RHS.IsPostDominators; DomTreeNodes = std::move(RHS.DomTreeNodes); RootNode = std::move(RHS.RootNode); DFSInfoValid = std::move(RHS.DFSInfoValid); @@ -247,7 +249,7 @@ /// isPostDominator - Returns true if analysis based of postdoms /// - bool isPostDominator() const { return IsPostDominators; } + bool isPostDominator() const { return IsPostDominator; } /// compare - Return false if the other dominator tree base matches this /// dominator tree base. Otherwise return true. @@ -522,7 +524,7 @@ /// splitBlock - BB is split and now it has one successor. Update dominator /// tree to reflect this change. void splitBlock(NodeT *NewBB) { - if (this->IsPostDominators) + if (IsPostDominator) Split>(NewBB); else Split(NewBB); @@ -600,7 +602,7 @@ using TraitsTy = GraphTraits; reset(); - if (!IsPostDominators) { + if (!IsPostDominator) { // Initialize root NodeT *entry = TraitsTy::getEntryNode(&F); addRoot(entry); @@ -708,10 +710,17 @@ } }; +template +using DomTreeBase = DominatorTreeBase; + +template +using PostDomTreeBase = DominatorTreeBase; + // These two functions are declared out of line as a workaround for building // with old (< r147295) versions of clang because of pr11642. -template -bool DominatorTreeBase::dominates(const NodeT *A, const NodeT *B) const { +template +bool DominatorTreeBase::dominates(const NodeT *A, + const NodeT *B) const { if (A == B) return true; @@ -721,9 +730,9 @@ return dominates(getNode(const_cast(A)), getNode(const_cast(B))); } -template -bool DominatorTreeBase::properlyDominates(const NodeT *A, - const NodeT *B) const { +template +bool DominatorTreeBase::properlyDominates( + const NodeT *A, const NodeT *B) const { if (A == B) return false; Index: llvm/trunk/lib/Analysis/DominanceFrontier.cpp =================================================================== --- llvm/trunk/lib/Analysis/DominanceFrontier.cpp +++ llvm/trunk/lib/Analysis/DominanceFrontier.cpp @@ -14,7 +14,8 @@ using namespace llvm; namespace llvm { -template class DominanceFrontierBase; +template class DominanceFrontierBase; +template class DominanceFrontierBase; template class ForwardDominanceFrontierBase; } Index: llvm/trunk/lib/Analysis/IteratedDominanceFrontier.cpp =================================================================== --- llvm/trunk/lib/Analysis/IteratedDominanceFrontier.cpp +++ llvm/trunk/lib/Analysis/IteratedDominanceFrontier.cpp @@ -17,8 +17,8 @@ #include namespace llvm { -template -void IDFCalculator::calculate( +template +void IDFCalculator::calculate( SmallVectorImpl &PHIBlocks) { // Use a priority queue keyed on dominator tree level so that inserted nodes // are handled from the bottom of the dominator tree upwards. @@ -88,6 +88,6 @@ } } -template class IDFCalculator; -template class IDFCalculator>; +template class IDFCalculator; +template class IDFCalculator, true>; } Index: llvm/trunk/lib/Analysis/LoopInfo.cpp =================================================================== --- llvm/trunk/lib/Analysis/LoopInfo.cpp +++ llvm/trunk/lib/Analysis/LoopInfo.cpp @@ -609,7 +609,7 @@ return NearLoop; } -LoopInfo::LoopInfo(const DominatorTreeBase &DomTree) { +LoopInfo::LoopInfo(const DomTreeBase &DomTree) { analyze(DomTree); } Index: llvm/trunk/lib/Analysis/PostDominators.cpp =================================================================== --- llvm/trunk/lib/Analysis/PostDominators.cpp +++ llvm/trunk/lib/Analysis/PostDominators.cpp @@ -23,6 +23,8 @@ #define DEBUG_TYPE "postdomtree" +template class llvm::DominatorTreeBase; // PostDomTreeBase + //===----------------------------------------------------------------------===// // PostDominatorTree Implementation //===----------------------------------------------------------------------===// Index: llvm/trunk/lib/CodeGen/MachineDominanceFrontier.cpp =================================================================== --- llvm/trunk/lib/CodeGen/MachineDominanceFrontier.cpp +++ llvm/trunk/lib/CodeGen/MachineDominanceFrontier.cpp @@ -15,7 +15,8 @@ using namespace llvm; namespace llvm { -template class DominanceFrontierBase; +template class DominanceFrontierBase; +template class DominanceFrontierBase; template class ForwardDominanceFrontierBase; } Index: llvm/trunk/lib/CodeGen/MachineDominators.cpp =================================================================== --- llvm/trunk/lib/CodeGen/MachineDominators.cpp +++ llvm/trunk/lib/CodeGen/MachineDominators.cpp @@ -31,7 +31,7 @@ namespace llvm { template class DomTreeNodeBase; -template class DominatorTreeBase; +template class DominatorTreeBase; // DomTreeBase } char MachineDominatorTree::ID = 0; @@ -49,7 +49,7 @@ bool MachineDominatorTree::runOnMachineFunction(MachineFunction &F) { CriticalEdgesToSplit.clear(); NewBBs.clear(); - DT.reset(new DominatorTreeBase(false)); + DT.reset(new DomTreeBase()); DT->recalculate(F); return false; } @@ -144,7 +144,7 @@ return; MachineFunction &F = *getRoot()->getParent(); - DominatorTreeBase OtherDT(false); + DomTreeBase OtherDT; OtherDT.recalculate(F); if (getRootNode()->getBlock() != OtherDT.getRootNode()->getBlock() || DT->compare(OtherDT)) { Index: llvm/trunk/lib/CodeGen/MachinePostDominators.cpp =================================================================== --- llvm/trunk/lib/CodeGen/MachinePostDominators.cpp +++ llvm/trunk/lib/CodeGen/MachinePostDominators.cpp @@ -16,6 +16,10 @@ using namespace llvm; +namespace llvm { +template class DominatorTreeBase; // PostDomTreeBase +} + char MachinePostDominatorTree::ID = 0; //declare initializeMachinePostDominatorTreePass @@ -24,8 +28,7 @@ MachinePostDominatorTree::MachinePostDominatorTree() : MachineFunctionPass(ID) { initializeMachinePostDominatorTreePass(*PassRegistry::getPassRegistry()); - DT = new DominatorTreeBase(true); //true indicate - // postdominator + DT = new PostDomTreeBase(); } FunctionPass * Index: llvm/trunk/lib/IR/Dominators.cpp =================================================================== --- llvm/trunk/lib/IR/Dominators.cpp +++ llvm/trunk/lib/IR/Dominators.cpp @@ -61,14 +61,20 @@ //===----------------------------------------------------------------------===// template class llvm::DomTreeNodeBase; -template class llvm::DominatorTreeBase; +template class llvm::DominatorTreeBase; // DomTreeBase +template class llvm::DominatorTreeBase; // PostDomTreeBase template void llvm::DomTreeBuilder::Calculate( DomTreeBuilder::BBDomTree &DT, Function &F); +template void +llvm::DomTreeBuilder::Calculate( + DomTreeBuilder::BBPostDomTree &DT, Function &F); template bool llvm::DomTreeBuilder::Verify( const DomTreeBuilder::BBDomTree &DT); +template bool llvm::DomTreeBuilder::Verify( + const DomTreeBuilder::BBPostDomTree &DT); bool DominatorTree::invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &) { Index: llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp =================================================================== --- llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp +++ llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp @@ -173,8 +173,10 @@ void printBlockEquivalence(raw_ostream &OS, const BasicBlock *BB); bool computeBlockWeights(Function &F); void findEquivalenceClasses(Function &F); + template void findEquivalencesFor(BasicBlock *BB1, ArrayRef Descendants, - DominatorTreeBase *DomTree); + DominatorTreeBase *DomTree); + void propagateWeights(Function &F); uint64_t visitEdge(Edge E, unsigned *NumUnknownEdges, Edge *UnknownEdge); void buildEdges(Function &F); @@ -217,7 +219,7 @@ /// \brief Dominance, post-dominance and loop information. std::unique_ptr DT; - std::unique_ptr> PDT; + std::unique_ptr> PDT; std::unique_ptr LI; AssumptionCacheTracker *ACT; @@ -773,9 +775,10 @@ /// \param DomTree Opposite dominator tree. If \p Descendants is filled /// with blocks from \p BB1's dominator tree, then /// this is the post-dominator tree, and vice versa. +template void SampleProfileLoader::findEquivalencesFor( BasicBlock *BB1, ArrayRef Descendants, - DominatorTreeBase *DomTree) { + DominatorTreeBase *DomTree) { const BasicBlock *EC = EquivalenceClass[BB1]; uint64_t Weight = BlockWeights[EC]; for (const auto *BB2 : Descendants) { @@ -1283,7 +1286,7 @@ DT.reset(new DominatorTree); DT->recalculate(F); - PDT.reset(new DominatorTreeBase(true)); + PDT.reset(new PostDomTreeBase()); PDT->recalculate(F); LI.reset(new LoopInfo); Index: llvm/trunk/unittests/IR/DominatorTreeTest.cpp =================================================================== --- llvm/trunk/unittests/IR/DominatorTreeTest.cpp +++ llvm/trunk/unittests/IR/DominatorTreeTest.cpp @@ -19,18 +19,19 @@ using namespace llvm; +struct PostDomTree : PostDomTreeBase { + PostDomTree(Function &F) { recalculate(F); } +}; + /// Build the dominator tree for the function and run the Test. -static void -runWithDomTree(Module &M, StringRef FuncName, - function_ref *PDT)> - Test) { +static void runWithDomTree( + Module &M, StringRef FuncName, + function_ref Test) { auto *F = M.getFunction(FuncName); ASSERT_NE(F, nullptr) << "Could not find " << FuncName; // Compute the dominator tree for the function. DominatorTree DT(*F); - DominatorTreeBase PDT(/*isPostDom*/ true); - PDT.recalculate(*F); + PostDomTree PDT(*F); Test(*F, &DT, &PDT); } @@ -72,8 +73,7 @@ std::unique_ptr M = makeLLVMModule(Context, ModuleString); runWithDomTree( - *M, "f", - [&](Function &F, DominatorTree *DT, DominatorTreeBase *PDT) { + *M, "f", [&](Function &F, DominatorTree *DT, PostDomTree *PDT) { Function::iterator FI = F.begin(); BasicBlock *BB0 = &*FI++; @@ -293,8 +293,7 @@ std::unique_ptr M = makeLLVMModule(Context, ModuleString); runWithDomTree( - *M, "f", - [&](Function &F, DominatorTree *DT, DominatorTreeBase *PDT) { + *M, "f", [&](Function &F, DominatorTree *DT, PostDomTree *PDT) { Function::iterator FI = F.begin(); BasicBlock *BB0 = &*FI++;