diff options
author | Hongbin Zheng <etherzhhb@gmail.com> | 2016-02-25 16:33:06 +0000 |
---|---|---|
committer | Hongbin Zheng <etherzhhb@gmail.com> | 2016-02-25 16:33:06 +0000 |
commit | a0273a04f53e89c6ef771a73ddedc4c25bbf62d9 (patch) | |
tree | acc9cc0cde44a120159c5678c46f6adcdb8f51cc /llvm/lib/Analysis | |
parent | 148445ef985eedf7d2d05467b5b8d634fc156bd6 (diff) | |
download | bcm5719-llvm-a0273a04f53e89c6ef771a73ddedc4c25bbf62d9.tar.gz bcm5719-llvm-a0273a04f53e89c6ef771a73ddedc4c25bbf62d9.zip |
Introduce analysis pass to compute PostDominators in the new pass manager. NFC
Differential Revision: http://reviews.llvm.org/D17537
llvm-svn: 261882
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/Analysis.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Analysis/DivergenceAnalysis.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/Analysis/DomPrinter.cpp | 48 | ||||
-rw-r--r-- | llvm/lib/Analysis/PostDominators.cpp | 34 | ||||
-rw-r--r-- | llvm/lib/Analysis/RegionInfo.cpp | 6 |
5 files changed, 70 insertions, 27 deletions
diff --git a/llvm/lib/Analysis/Analysis.cpp b/llvm/lib/Analysis/Analysis.cpp index 811741962aa..9c53dedad03 100644 --- a/llvm/lib/Analysis/Analysis.cpp +++ b/llvm/lib/Analysis/Analysis.cpp @@ -60,7 +60,7 @@ void llvm::initializeAnalysis(PassRegistry &Registry) { initializeMemoryDependenceAnalysisPass(Registry); initializeModuleDebugInfoPrinterPass(Registry); initializeObjCARCAAWrapperPassPass(Registry); - initializePostDominatorTreePass(Registry); + initializePostDominatorTreeWrapperPassPass(Registry); initializeRegionInfoPassPass(Registry); initializeRegionViewerPass(Registry); initializeRegionPrinterPass(Registry); diff --git a/llvm/lib/Analysis/DivergenceAnalysis.cpp b/llvm/lib/Analysis/DivergenceAnalysis.cpp index 343fe613b7e..0e1cfcfe259 100644 --- a/llvm/lib/Analysis/DivergenceAnalysis.cpp +++ b/llvm/lib/Analysis/DivergenceAnalysis.cpp @@ -258,7 +258,7 @@ char DivergenceAnalysis::ID = 0; 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 @@ FunctionPass *llvm::createDivergenceAnalysisPass() { void DivergenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<DominatorTreeWrapperPass>(); - AU.addRequired<PostDominatorTree>(); + AU.addRequired<PostDominatorTreeWrapperPass>(); AU.setPreservesAll(); } @@ -284,9 +284,10 @@ bool DivergenceAnalysis::runOnFunction(Function &F) { return false; DivergentValues.clear(); + auto &PDT = getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree(); DivergencePropagator DP(F, TTI, getAnalysis<DominatorTreeWrapperPass>().getDomTree(), - getAnalysis<PostDominatorTree>(), DivergentValues); + PDT, DivergentValues); DP.populateWithSourcesOfDivergence(); DP.propagate(); return false; diff --git a/llvm/lib/Analysis/DomPrinter.cpp b/llvm/lib/Analysis/DomPrinter.cpp index 0c880df54f8..7acfb41500d 100644 --- a/llvm/lib/Analysis/DomPrinter.cpp +++ b/llvm/lib/Analysis/DomPrinter.cpp @@ -111,20 +111,36 @@ struct DomOnlyViewer : public DOTGraphTraitsViewer< } }; -struct PostDomViewer - : public DOTGraphTraitsViewer<PostDominatorTree, false> { +struct PostDominatorTreeWrapperPassAnalysisGraphTraits { + static PostDominatorTree *getGraph(PostDominatorTreeWrapperPass *PDTWP) { + return &PDTWP->getPostDomTree(); + } +}; + +struct PostDomViewer : public DOTGraphTraitsViewer< + PostDominatorTreeWrapperPass, false, + PostDominatorTree *, + PostDominatorTreeWrapperPassAnalysisGraphTraits> { static char ID; PostDomViewer() : - DOTGraphTraitsViewer<PostDominatorTree, false>("postdom", ID){ + DOTGraphTraitsViewer<PostDominatorTreeWrapperPass, false, + PostDominatorTree *, + PostDominatorTreeWrapperPassAnalysisGraphTraits>( + "postdom", ID){ initializePostDomViewerPass(*PassRegistry::getPassRegistry()); } }; -struct PostDomOnlyViewer - : public DOTGraphTraitsViewer<PostDominatorTree, true> { +struct PostDomOnlyViewer : public DOTGraphTraitsViewer< + PostDominatorTreeWrapperPass, true, + PostDominatorTree *, + PostDominatorTreeWrapperPassAnalysisGraphTraits> { static char ID; PostDomOnlyViewer() : - DOTGraphTraitsViewer<PostDominatorTree, true>("postdomonly", ID){ + DOTGraphTraitsViewer<PostDominatorTreeWrapperPass, true, + PostDominatorTree *, + PostDominatorTreeWrapperPassAnalysisGraphTraits>( + "postdomonly", ID){ initializePostDomOnlyViewerPass(*PassRegistry::getPassRegistry()); } }; @@ -175,19 +191,31 @@ struct DomOnlyPrinter : public DOTGraphTraitsPrinter< }; struct PostDomPrinter - : public DOTGraphTraitsPrinter<PostDominatorTree, false> { + : public DOTGraphTraitsPrinter< + PostDominatorTreeWrapperPass, false, + PostDominatorTree *, + PostDominatorTreeWrapperPassAnalysisGraphTraits> { static char ID; PostDomPrinter() : - DOTGraphTraitsPrinter<PostDominatorTree, false>("postdom", ID) { + DOTGraphTraitsPrinter<PostDominatorTreeWrapperPass, false, + PostDominatorTree *, + PostDominatorTreeWrapperPassAnalysisGraphTraits>( + "postdom", ID) { initializePostDomPrinterPass(*PassRegistry::getPassRegistry()); } }; struct PostDomOnlyPrinter - : public DOTGraphTraitsPrinter<PostDominatorTree, true> { + : public DOTGraphTraitsPrinter< + PostDominatorTreeWrapperPass, true, + PostDominatorTree *, + PostDominatorTreeWrapperPassAnalysisGraphTraits> { static char ID; PostDomOnlyPrinter() : - DOTGraphTraitsPrinter<PostDominatorTree, true>("postdomonly", ID) { + DOTGraphTraitsPrinter<PostDominatorTreeWrapperPass, true, + PostDominatorTree *, + PostDominatorTreeWrapperPassAnalysisGraphTraits>( + "postdomonly", ID) { initializePostDomOnlyPrinterPass(*PassRegistry::getPassRegistry()); } }; diff --git a/llvm/lib/Analysis/PostDominators.cpp b/llvm/lib/Analysis/PostDominators.cpp index 6d929091e3d..b515108fafb 100644 --- a/llvm/lib/Analysis/PostDominators.cpp +++ b/llvm/lib/Analysis/PostDominators.cpp @@ -16,6 +16,7 @@ #include "llvm/ADT/SetOperations.h" #include "llvm/IR/CFG.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/PassManager.h" #include "llvm/Support/Debug.h" #include "llvm/Support/GenericDomTreeConstruction.h" using namespace llvm; @@ -26,25 +27,38 @@ using namespace llvm; // PostDominatorTree Implementation //===----------------------------------------------------------------------===// -char PostDominatorTree::ID = 0; -INITIALIZE_PASS(PostDominatorTree, "postdomtree", +char PostDominatorTreeWrapperPass::ID = 0; +INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree", "Post-Dominator Tree Construction", true, true) -bool PostDominatorTree::runOnFunction(Function &F) { - DT->recalculate(F); +bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) { + DT.recalculate(F); return false; } -PostDominatorTree::~PostDominatorTree() { - delete DT; +void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const { + DT.print(OS); } -void PostDominatorTree::print(raw_ostream &OS, const Module *) const { - DT->print(OS); +FunctionPass* llvm::createPostDomTree() { + return new PostDominatorTreeWrapperPass(); } +char PostDominatorTreeAnalysis::PassID; -FunctionPass* llvm::createPostDomTree() { - return new PostDominatorTree(); +PostDominatorTree PostDominatorTreeAnalysis::run(Function &F) { + PostDominatorTree PDT; + PDT.recalculate(F); + return PDT; } +PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS) + : OS(OS) {} + +PreservedAnalyses +PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager *AM) { + OS << "PostDominatorTree for function: " << F.getName() << "\n"; + AM->getResult<PostDominatorTreeAnalysis>(F).print(OS); + + return PreservedAnalyses::all(); +} diff --git a/llvm/lib/Analysis/RegionInfo.cpp b/llvm/lib/Analysis/RegionInfo.cpp index b6277bb6c12..dac0cddc168 100644 --- a/llvm/lib/Analysis/RegionInfo.cpp +++ b/llvm/lib/Analysis/RegionInfo.cpp @@ -128,7 +128,7 @@ bool RegionInfoPass::runOnFunction(Function &F) { releaseMemory(); auto DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); - auto PDT = &getAnalysis<PostDominatorTree>(); + auto PDT = &getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree(); auto DF = &getAnalysis<DominanceFrontier>(); RI.recalculate(F, DT, PDT, DF); @@ -146,8 +146,8 @@ void RegionInfoPass::verifyAnalysis() const { void RegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); AU.addRequiredTransitive<DominatorTreeWrapperPass>(); - AU.addRequired<PostDominatorTree>(); AU.addRequired<DominanceFrontier>(); + AU.addRequired<PostDominatorTreeWrapperPass>(); } void RegionInfoPass::print(raw_ostream &OS, const Module *) const { @@ -165,8 +165,8 @@ char RegionInfoPass::ID = 0; INITIALIZE_PASS_BEGIN(RegionInfoPass, "regions", "Detect single entry single exit regions", true, true) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) -INITIALIZE_PASS_DEPENDENCY(PostDominatorTree) INITIALIZE_PASS_DEPENDENCY(DominanceFrontier) +INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass) INITIALIZE_PASS_END(RegionInfoPass, "regions", "Detect single entry single exit regions", true, true) |