Index: include/llvm/Analysis/PostDominators.h =================================================================== --- include/llvm/Analysis/PostDominators.h +++ include/llvm/Analysis/PostDominators.h @@ -21,24 +21,29 @@ /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to /// compute the post-dominator tree. /// -struct PostDominatorTree : public FunctionPass { - static char ID; // Pass identification, replacement for typeid - DominatorTreeBase* DT; - - PostDominatorTree() : FunctionPass(ID) { - initializePostDominatorTreePass(*PassRegistry::getPassRegistry()); - DT = new DominatorTreeBase(true); - } - - ~PostDominatorTree() override; - - bool runOnFunction(Function &F) override; - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.setPreservesAll(); - } - - inline const std::vector &getRoots() const { +struct PostDominatorTree { + DominatorTreeBase *DT; + PostDominatorTree() : DT(new DominatorTreeBase(true)) { } + PostDominatorTree(PostDominatorTree &&PDT) { + DT = PDT.DT; + PDT.DT = nullptr; + } + PostDominatorTree & operator= (PostDominatorTree &&PDT) { + DT = PDT.DT; + PDT.DT = nullptr; + return *this; + } + void releaseMemory() { DT->releaseMemory(); } + + void print(raw_ostream &OS, const Module *) const; + + ~PostDominatorTree() { + if(DT) { + delete DT; + } + } + + inline const std::vector &getRoots() const { return DT->getRoots(); } @@ -84,12 +89,6 @@ SmallVectorImpl &Result) const { DT->getDescendants(R, Result); } - - void releaseMemory() override { - DT->releaseMemory(); - } - - void print(raw_ostream &OS, const Module*) const override; }; FunctionPass* createPostDomTree(); @@ -112,6 +111,54 @@ } }; +/// \brief Legacy analysis pass which computes a \c PostDominatorTree. +class PostDominatorTreeWrapperPass : public FunctionPass { + PostDominatorTree DT; + +public: + static char ID; + + PostDominatorTreeWrapperPass() : FunctionPass(ID) { + initializePostDominatorTreeWrapperPassPass( + *PassRegistry::getPassRegistry()); + } + + PostDominatorTree &getDomTree() { return DT; } + const PostDominatorTree &getDomTree() const { return DT; } + + bool runOnFunction(Function &F) override; + + void verifyAnalysis() const override; + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.setPreservesAll(); + } + + void releaseMemory() override { DT.DT->releaseMemory(); } + + void print(raw_ostream &OS, const Module *M = nullptr) const override; +}; + +/// \brief Analysis pass which computes a \c DominatorTree. +class PostDominatorTreeAnalysis { +public: + /// \brief Provide the result typedef for this analysis pass. + typedef PostDominatorTree Result; + + /// \brief Opaque, unique identifier for this analysis pass. + static void *ID() { return (void *)&PassID; } + + /// \brief Run the analysis pass over a function and produce a post-dominator + /// tree. + PostDominatorTree run(Function &F); + + /// \brief Provide access to a name for this pass for debugging purposes. + static StringRef name() { return "PostßDominatorTreeAnalysis"; } + +private: + static char PassID; +}; + } // End llvm namespace #endif Index: include/llvm/InitializePasses.h =================================================================== --- include/llvm/InitializePasses.h +++ include/llvm/InitializePasses.h @@ -229,7 +229,7 @@ void initializePostDomOnlyViewerPass(PassRegistry&); void initializePostDomPrinterPass(PassRegistry&); void initializePostDomViewerPass(PassRegistry&); -void initializePostDominatorTreePass(PassRegistry&); +void initializePostDominatorTreeWrapperPassPass(PassRegistry&); void initializePostOrderFunctionAttrsPass(PassRegistry&); void initializePostRASchedulerPass(PassRegistry&); void initializePostMachineSchedulerPass(PassRegistry&); Index: lib/Analysis/Analysis.cpp =================================================================== --- lib/Analysis/Analysis.cpp +++ lib/Analysis/Analysis.cpp @@ -60,7 +60,7 @@ initializeMemoryDependenceAnalysisPass(Registry); initializeModuleDebugInfoPrinterPass(Registry); initializeObjCARCAAWrapperPassPass(Registry); - initializePostDominatorTreePass(Registry); + initializePostDominatorTreeWrapperPassPass(Registry); initializeRegionInfoPassPass(Registry); initializeRegionViewerPass(Registry); initializeRegionPrinterPass(Registry); Index: lib/Analysis/DivergenceAnalysis.cpp =================================================================== --- lib/Analysis/DivergenceAnalysis.cpp +++ lib/Analysis/DivergenceAnalysis.cpp @@ -258,7 +258,7 @@ INITIALIZE_PASS_BEGIN(DivergenceAnalysis, "divergence", "Divergence Analysis", false, true) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) -INITIALIZE_PASS_DEPENDENCY(PostDominatorTree) +INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass) INITIALIZE_PASS_END(DivergenceAnalysis, "divergence", "Divergence Analysis", false, true) @@ -268,7 +268,7 @@ void DivergenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); - AU.addRequired(); + AU.addRequired(); AU.setPreservesAll(); } @@ -284,9 +284,10 @@ return false; DivergentValues.clear(); - DivergencePropagator DP(F, TTI, - getAnalysis().getDomTree(), - getAnalysis(), DivergentValues); + DivergencePropagator DP( + F, TTI, getAnalysis().getDomTree(), + getAnalysis().getDomTree(), + DivergentValues); DP.populateWithSourcesOfDivergence(); DP.propagate(); return false; Index: lib/Analysis/DomPrinter.cpp =================================================================== --- lib/Analysis/DomPrinter.cpp +++ lib/Analysis/DomPrinter.cpp @@ -111,22 +111,36 @@ } }; -struct PostDomViewer - : public DOTGraphTraitsViewer { +struct PostDominatorTreeWrapperPassAnalysisGraphTraits { + static PostDominatorTree *getGraph(PostDominatorTreeWrapperPass *DTWP) { + return &DTWP->getDomTree(); + } +}; + +struct PostDomViewer : public DOTGraphTraitsViewer< + PostDominatorTreeWrapperPass, false, PostDominatorTree *, + PostDominatorTreeWrapperPassAnalysisGraphTraits> { static char ID; - PostDomViewer() : - DOTGraphTraitsViewer("postdom", ID){ - initializePostDomViewerPass(*PassRegistry::getPassRegistry()); - } + PostDomViewer() + : DOTGraphTraitsViewer( + "postdom", ID) { + initializePostDomViewerPass(*PassRegistry::getPassRegistry()); + } }; struct PostDomOnlyViewer - : public DOTGraphTraitsViewer { + : public DOTGraphTraitsViewer< + PostDominatorTreeWrapperPass, true, PostDominatorTree *, + PostDominatorTreeWrapperPassAnalysisGraphTraits> { static char ID; - PostDomOnlyViewer() : - DOTGraphTraitsViewer("postdomonly", ID){ - initializePostDomOnlyViewerPass(*PassRegistry::getPassRegistry()); - } + PostDomOnlyViewer() + : DOTGraphTraitsViewer( + "postdomonly", ID) { + initializePostDomOnlyViewerPass(*PassRegistry::getPassRegistry()); + } }; } // end anonymous namespace @@ -175,19 +189,23 @@ }; struct PostDomPrinter - : public DOTGraphTraitsPrinter { + : public DOTGraphTraitsPrinter { static char ID; PostDomPrinter() : - DOTGraphTraitsPrinter("postdom", ID) { + DOTGraphTraitsPrinter("postdom", ID) { initializePostDomPrinterPass(*PassRegistry::getPassRegistry()); } }; struct PostDomOnlyPrinter - : public DOTGraphTraitsPrinter { + : public DOTGraphTraitsPrinter { static char ID; PostDomOnlyPrinter() : - DOTGraphTraitsPrinter("postdomonly", ID) { + DOTGraphTraitsPrinter("postdomonly", ID) { initializePostDomOnlyPrinterPass(*PassRegistry::getPassRegistry()); } }; Index: lib/Analysis/PostDominators.cpp =================================================================== --- lib/Analysis/PostDominators.cpp +++ lib/Analysis/PostDominators.cpp @@ -25,26 +25,57 @@ //===----------------------------------------------------------------------===// // PostDominatorTree Implementation //===----------------------------------------------------------------------===// +void PostDominatorTree::print(raw_ostream &OS, const Module *) const { + DT->print(OS); +} -char PostDominatorTree::ID = 0; -INITIALIZE_PASS(PostDominatorTree, "postdomtree", - "Post-Dominator Tree Construction", true, true) -bool PostDominatorTree::runOnFunction(Function &F) { - DT->recalculate(F); - return false; +//===----------------------------------------------------------------------===// +// DominatorTreeAnalysis and related pass implementations +//===----------------------------------------------------------------------===// +// +// This implements the DominatorTreeAnalysis which is used with the new pass +// manager. It also implements some methods from utility passes. +// +//===----------------------------------------------------------------------===// +PostDominatorTree PostDominatorTreeAnalysis::run(Function &F) { + PostDominatorTree DT; + DT.DT->recalculate(F); + return DT; } -PostDominatorTree::~PostDominatorTree() { - delete DT; +char PostDominatorTreeAnalysis::PassID; + +FunctionPass* llvm::createPostDomTree() { + return new PostDominatorTreeWrapperPass(); } -void PostDominatorTree::print(raw_ostream &OS, const Module *) const { - DT->print(OS); +//===----------------------------------------------------------------------===// +// DominatorTreeWrapperPass Implementation +//===----------------------------------------------------------------------===// +// +// The implementation details of the wrapper pass that holds a DominatorTree +// suitable for use with the legacy pass manager. +// +//===----------------------------------------------------------------------===// + +char PostDominatorTreeWrapperPass::ID = 0; +INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree", + "Post-Dominator Tree Construction", true, true) + +bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) { + DT.DT->recalculate(F); + return false; } +void PostDominatorTreeWrapperPass::verifyAnalysis() const { +#if 0 + if (VerifyDomInfo) + DT.DT->VerifyDomTree(); +#endif +} -FunctionPass* llvm::createPostDomTree() { - return new PostDominatorTree(); +void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const { + DT.DT->print(OS); } Index: lib/Analysis/RegionInfo.cpp =================================================================== --- lib/Analysis/RegionInfo.cpp +++ lib/Analysis/RegionInfo.cpp @@ -128,7 +128,7 @@ releaseMemory(); auto DT = &getAnalysis().getDomTree(); - auto PDT = &getAnalysis(); + auto PDT = &getAnalysis().getDomTree(); auto DF = &getAnalysis(); RI.recalculate(F, DT, PDT, DF); @@ -146,7 +146,7 @@ void RegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); AU.addRequiredTransitive(); - AU.addRequired(); + AU.addRequired(); AU.addRequired(); } @@ -165,7 +165,7 @@ INITIALIZE_PASS_BEGIN(RegionInfoPass, "regions", "Detect single entry single exit regions", true, true) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) -INITIALIZE_PASS_DEPENDENCY(PostDominatorTree) +INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(DominanceFrontier) INITIALIZE_PASS_END(RegionInfoPass, "regions", "Detect single entry single exit regions", true, true) Index: lib/CodeGen/MachineRegionInfo.cpp =================================================================== --- lib/CodeGen/MachineRegionInfo.cpp +++ lib/CodeGen/MachineRegionInfo.cpp @@ -104,7 +104,7 @@ void MachineRegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); AU.addRequiredTransitive(); - AU.addRequired(); + AU.addRequired(); AU.addRequired(); } Index: lib/Target/Hexagon/HexagonCommonGEP.cpp =================================================================== --- lib/Target/Hexagon/HexagonCommonGEP.cpp +++ lib/Target/Hexagon/HexagonCommonGEP.cpp @@ -90,13 +90,14 @@ virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); AU.addPreserved(); - AU.addRequired(); - AU.addPreserved(); + AU.addRequired(); + AU.addPreserved(); AU.addRequired(); AU.addPreserved(); FunctionPass::getAnalysisUsage(AU); } + private: typedef std::map ValueToNodeMap; typedef std::vector ValueVect; @@ -147,7 +148,7 @@ INITIALIZE_PASS_BEGIN(HexagonCommonGEP, "hcommgep", "Hexagon Common GEP", false, false) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) -INITIALIZE_PASS_DEPENDENCY(PostDominatorTree) +INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) INITIALIZE_PASS_END(HexagonCommonGEP, "hcommgep", "Hexagon Common GEP", false, false) @@ -1276,7 +1277,7 @@ Fn = &F; DT = &getAnalysis().getDomTree(); - PDT = &getAnalysis(); + PDT = &getAnalysis().getDomTree(); LI = &getAnalysis().getLoopInfo(); Ctx = &F.getContext(); Index: unittests/IR/DominatorTreeTest.cpp =================================================================== --- unittests/IR/DominatorTreeTest.cpp +++ unittests/IR/DominatorTreeTest.cpp @@ -29,7 +29,8 @@ bool runOnFunction(Function &F) override { DominatorTree *DT = &getAnalysis().getDomTree(); - PostDominatorTree *PDT = &getAnalysis(); + PostDominatorTree *PDT = + &getAnalysis().getDomTree(); Function::iterator FI = F.begin(); BasicBlock *BB0 = &*FI++; @@ -206,7 +207,7 @@ } void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired(); - AU.addRequired(); + AU.addRequired(); } DPass() : FunctionPass(ID) { initializeDPassPass(*PassRegistry::getPassRegistry()); @@ -255,5 +256,5 @@ INITIALIZE_PASS_BEGIN(DPass, "dpass", "dpass", false, false) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) -INITIALIZE_PASS_DEPENDENCY(PostDominatorTree) +INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass) INITIALIZE_PASS_END(DPass, "dpass", "dpass", false, false)