Revert "Introduce analysis pass to compute PostDominators in the new pass manager...
authorHongbin Zheng <etherzhhb@gmail.com>
Thu, 25 Feb 2016 16:45:53 +0000 (16:45 +0000)
committerHongbin Zheng <etherzhhb@gmail.com>
Thu, 25 Feb 2016 16:45:53 +0000 (16:45 +0000)
This reverts commit a3e5cc6a51ab5ad88d1760c63284294a4e34c018.

llvm-svn: 261891

12 files changed:
llvm/include/llvm/Analysis/PostDominators.h
llvm/include/llvm/InitializePasses.h
llvm/lib/Analysis/Analysis.cpp
llvm/lib/Analysis/DivergenceAnalysis.cpp
llvm/lib/Analysis/DomPrinter.cpp
llvm/lib/Analysis/PostDominators.cpp
llvm/lib/Analysis/RegionInfo.cpp
llvm/lib/CodeGen/MachineRegionInfo.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/test/Analysis/PostDominators/pr1098.ll
llvm/unittests/IR/DominatorTreeTest.cpp

index 07d1a86..0f7e2b8 100644 (file)
 #include "llvm/IR/Dominators.h"
 
 namespace llvm {
-// FIXME: Replace this brittle forward declaration with the include of the new
-// PassManager.h when doing so doesn't break the PassManagerBuilder.
-class PreservedAnalyses;
 
 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
 /// compute the post-dominator tree.
 ///
-struct PostDominatorTree : public DominatorTreeBase<BasicBlock> {
-  PostDominatorTree() : DominatorTreeBase<BasicBlock>(true) {}
-};
+struct PostDominatorTree : public FunctionPass {
+  static char ID; // Pass identification, replacement for typeid
+  DominatorTreeBase<BasicBlock>* DT;
 
-/// \brief Analysis pass which computes a \c PostDominatorTree.
-class PostDominatorTreeAnalysis {
-public:
-  /// \brief Provide the result typedef for this analysis pass.
-  typedef PostDominatorTree Result;
+  PostDominatorTree() : FunctionPass(ID) {
+    initializePostDominatorTreePass(*PassRegistry::getPassRegistry());
+    DT = new DominatorTreeBase<BasicBlock>(true);
+  }
 
-  /// \brief Opaque, unique identifier for this analysis pass.
-  static void *ID() { return (void *)&PassID; }
+  ~PostDominatorTree() override;
 
-  /// \brief Run the analysis pass over a function and produce a post dominator
-  ///        tree.
-  PostDominatorTree run(Function &F);
+  bool runOnFunction(Function &F) override;
 
-  /// \brief Provide access to a name for this pass for debugging purposes.
-  static StringRef name() { return "PostDominatorTreeAnalysis"; }
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+    AU.setPreservesAll();
+  }
 
-private:
-  static char PassID;
-};
+  inline const std::vector<BasicBlock*> &getRoots() const {
+    return DT->getRoots();
+  }
 
-/// \brief Printer pass for the \c PostDominatorTree.
-class PostDominatorTreePrinterPass {
-  raw_ostream &OS;
+  inline DomTreeNode *getRootNode() const {
+    return DT->getRootNode();
+  }
 
-public:
-  explicit PostDominatorTreePrinterPass(raw_ostream &OS);
-  PreservedAnalyses run(Function &F, AnalysisManager<Function> *AM);
+  inline DomTreeNode *operator[](BasicBlock *BB) const {
+    return DT->getNode(BB);
+  }
 
-  static StringRef name() { return "PostDominatorTreePrinterPass"; }
-};
+  inline DomTreeNode *getNode(BasicBlock *BB) const {
+    return DT->getNode(BB);
+  }
 
-struct PostDominatorTreeWrapperPass : public FunctionPass {
-  static char ID; // Pass identification, replacement for typeid
-  PostDominatorTree DT;
+  inline bool dominates(DomTreeNode* A, DomTreeNode* B) const {
+    return DT->dominates(A, B);
+  }
 
-  PostDominatorTreeWrapperPass() : FunctionPass(ID) {
-    initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
+  inline bool dominates(const BasicBlock* A, const BasicBlock* B) const {
+    return DT->dominates(A, B);
   }
 
-  PostDominatorTree &getPostDomTree() { return DT; }
-  const PostDominatorTree &getPostDomTree() const { return DT; }
+  inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
+    return DT->properlyDominates(A, B);
+  }
 
-  bool runOnFunction(Function &F) override;
+  inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
+    return DT->properlyDominates(A, B);
+  }
 
-  void getAnalysisUsage(AnalysisUsage &AU) const override {
-    AU.setPreservesAll();
+  inline BasicBlock *findNearestCommonDominator(BasicBlock *A, BasicBlock *B) {
+    return DT->findNearestCommonDominator(A, B);
+  }
+
+  inline const BasicBlock *findNearestCommonDominator(const BasicBlock *A,
+                                                      const BasicBlock *B) {
+    return DT->findNearestCommonDominator(A, B);
+  }
+
+  /// Get all nodes post-dominated by R, including R itself.
+  void getDescendants(BasicBlock *R,
+                      SmallVectorImpl<BasicBlock *> &Result) const {
+    DT->getDescendants(R, Result);
   }
 
   void releaseMemory() override {
-    DT.releaseMemory();
+    DT->releaseMemory();
   }
 
   void print(raw_ostream &OS, const Module*) const override;
index 5f2b886..296962b 100644 (file)
@@ -232,7 +232,7 @@ void initializePostDomOnlyPrinterPass(PassRegistry&);
 void initializePostDomOnlyViewerPass(PassRegistry&);
 void initializePostDomPrinterPass(PassRegistry&);
 void initializePostDomViewerPass(PassRegistry&);
-void initializePostDominatorTreeWrapperPassPass(PassRegistry&);
+void initializePostDominatorTreePass(PassRegistry&);
 void initializePostOrderFunctionAttrsLegacyPassPass(PassRegistry&);
 void initializePostRASchedulerPass(PassRegistry&);
 void initializePostMachineSchedulerPass(PassRegistry&);
index 9c53ded..8117419 100644 (file)
@@ -60,7 +60,7 @@ void llvm::initializeAnalysis(PassRegistry &Registry) {
   initializeMemoryDependenceAnalysisPass(Registry);
   initializeModuleDebugInfoPrinterPass(Registry);
   initializeObjCARCAAWrapperPassPass(Registry);
-  initializePostDominatorTreeWrapperPassPass(Registry);
+  initializePostDominatorTreePass(Registry);
   initializeRegionInfoPassPass(Registry);
   initializeRegionViewerPass(Registry);
   initializeRegionPrinterPass(Registry);
index 0e1cfcf..343fe61 100644 (file)
@@ -258,7 +258,7 @@ char DivergenceAnalysis::ID = 0;
 INITIALIZE_PASS_BEGIN(DivergenceAnalysis, "divergence", "Divergence Analysis",
                       false, true)
 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(PostDominatorTree)
 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<PostDominatorTreeWrapperPass>();
+  AU.addRequired<PostDominatorTree>();
   AU.setPreservesAll();
 }
 
@@ -284,10 +284,9 @@ bool DivergenceAnalysis::runOnFunction(Function &F) {
     return false;
 
   DivergentValues.clear();
-  auto &PDT = getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
   DivergencePropagator DP(F, TTI,
                           getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
-                          PDT, DivergentValues);
+                          getAnalysis<PostDominatorTree>(), DivergentValues);
   DP.populateWithSourcesOfDivergence();
   DP.propagate();
   return false;
index 7acfb41..0c880df 100644 (file)
@@ -111,36 +111,20 @@ struct DomOnlyViewer : public DOTGraphTraitsViewer<
   }
 };
 
-struct PostDominatorTreeWrapperPassAnalysisGraphTraits {
-  static PostDominatorTree *getGraph(PostDominatorTreeWrapperPass *PDTWP) {
-    return &PDTWP->getPostDomTree();
-  }
-};
-
-struct PostDomViewer : public DOTGraphTraitsViewer<
-                          PostDominatorTreeWrapperPass, false,
-                          PostDominatorTree *,
-                          PostDominatorTreeWrapperPassAnalysisGraphTraits> {
+struct PostDomViewer
+  : public DOTGraphTraitsViewer<PostDominatorTree, false> {
   static char ID;
   PostDomViewer() :
-    DOTGraphTraitsViewer<PostDominatorTreeWrapperPass, false,
-                         PostDominatorTree *,
-                         PostDominatorTreeWrapperPassAnalysisGraphTraits>(
-        "postdom", ID){
+    DOTGraphTraitsViewer<PostDominatorTree, false>("postdom", ID){
       initializePostDomViewerPass(*PassRegistry::getPassRegistry());
     }
 };
 
-struct PostDomOnlyViewer : public DOTGraphTraitsViewer<
-                            PostDominatorTreeWrapperPass, true,
-                            PostDominatorTree *,
-                            PostDominatorTreeWrapperPassAnalysisGraphTraits> {
+struct PostDomOnlyViewer
+  : public DOTGraphTraitsViewer<PostDominatorTree, true> {
   static char ID;
   PostDomOnlyViewer() :
-    DOTGraphTraitsViewer<PostDominatorTreeWrapperPass, true,
-                         PostDominatorTree *,
-                         PostDominatorTreeWrapperPassAnalysisGraphTraits>(
-        "postdomonly", ID){
+    DOTGraphTraitsViewer<PostDominatorTree, true>("postdomonly", ID){
       initializePostDomOnlyViewerPass(*PassRegistry::getPassRegistry());
     }
 };
@@ -191,31 +175,19 @@ struct DomOnlyPrinter : public DOTGraphTraitsPrinter<
 };
 
 struct PostDomPrinter
-  : public DOTGraphTraitsPrinter<
-                            PostDominatorTreeWrapperPass, false,
-                            PostDominatorTree *,
-                            PostDominatorTreeWrapperPassAnalysisGraphTraits> {
+  : public DOTGraphTraitsPrinter<PostDominatorTree, false> {
   static char ID;
   PostDomPrinter() :
-    DOTGraphTraitsPrinter<PostDominatorTreeWrapperPass, false,
-                          PostDominatorTree *,
-                          PostDominatorTreeWrapperPassAnalysisGraphTraits>(
-        "postdom", ID) {
+    DOTGraphTraitsPrinter<PostDominatorTree, false>("postdom", ID) {
       initializePostDomPrinterPass(*PassRegistry::getPassRegistry());
     }
 };
 
 struct PostDomOnlyPrinter
-  : public DOTGraphTraitsPrinter<
-                            PostDominatorTreeWrapperPass, true,
-                            PostDominatorTree *,
-                            PostDominatorTreeWrapperPassAnalysisGraphTraits> {
+  : public DOTGraphTraitsPrinter<PostDominatorTree, true> {
   static char ID;
   PostDomOnlyPrinter() :
-    DOTGraphTraitsPrinter<PostDominatorTreeWrapperPass, true,
-                          PostDominatorTree *,
-                          PostDominatorTreeWrapperPassAnalysisGraphTraits>(
-        "postdomonly", ID) {
+    DOTGraphTraitsPrinter<PostDominatorTree, true>("postdomonly", ID) {
       initializePostDomOnlyPrinterPass(*PassRegistry::getPassRegistry());
     }
 };
index b515108..6d92909 100644 (file)
@@ -16,7 +16,6 @@
 #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;
@@ -27,38 +26,25 @@ using namespace llvm;
 //  PostDominatorTree Implementation
 //===----------------------------------------------------------------------===//
 
-char PostDominatorTreeWrapperPass::ID = 0;
-INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
+char PostDominatorTree::ID = 0;
+INITIALIZE_PASS(PostDominatorTree, "postdomtree",
                 "Post-Dominator Tree Construction", true, true)
 
-bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
-  DT.recalculate(F);
+bool PostDominatorTree::runOnFunction(Function &F) {
+  DT->recalculate(F);
   return false;
 }
 
-void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
-  DT.print(OS);
+PostDominatorTree::~PostDominatorTree() {
+  delete DT;
 }
 
-FunctionPass* llvm::createPostDomTree() {
-  return new PostDominatorTreeWrapperPass();
+void PostDominatorTree::print(raw_ostream &OS, const Module *) const {
+  DT->print(OS);
 }
 
-char PostDominatorTreeAnalysis::PassID;
 
-PostDominatorTree PostDominatorTreeAnalysis::run(Function &F) {
-  PostDominatorTree PDT;
-  PDT.recalculate(F);
-  return PDT;
+FunctionPass* llvm::createPostDomTree() {
+  return new PostDominatorTree();
 }
 
-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();
-}
index dac0cdd..b6277bb 100644 (file)
@@ -128,7 +128,7 @@ bool RegionInfoPass::runOnFunction(Function &F) {
   releaseMemory();
 
   auto DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
-  auto PDT = &getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
+  auto PDT = &getAnalysis<PostDominatorTree>();
   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)
 
index 0f7ebb3..7d61792 100644 (file)
@@ -104,7 +104,7 @@ void MachineRegionInfoPass::verifyAnalysis() const {
 void MachineRegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.setPreservesAll();
   AU.addRequiredTransitive<DominatorTreeWrapperPass>();
-  AU.addRequired<PostDominatorTreeWrapperPass>();
+  AU.addRequired<PostDominatorTree>();
   AU.addRequired<DominanceFrontier>();
 }
 
index bd30fce..f043c92 100644 (file)
@@ -24,7 +24,6 @@
 #include "llvm/Analysis/CGSCCPassManager.h"
 #include "llvm/Analysis/LazyCallGraph.h"
 #include "llvm/Analysis/LoopInfo.h"
-#include "llvm/Analysis/PostDominators.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
 #include "llvm/Analysis/ScopedNoAliasAA.h"
index ccb4006..1721fa1 100644 (file)
@@ -57,7 +57,6 @@ CGSCC_PASS("no-op-cgscc", NoOpCGSCCPass())
 FUNCTION_ANALYSIS("aa", AAManager())
 FUNCTION_ANALYSIS("assumptions", AssumptionAnalysis())
 FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis())
-FUNCTION_ANALYSIS("postdomtree", PostDominatorTreeAnalysis())
 FUNCTION_ANALYSIS("loops", LoopAnalysis())
 FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
 FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
@@ -90,7 +89,6 @@ FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
 FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
 FUNCTION_PASS("print<assumptions>", AssumptionPrinterPass(dbgs()))
 FUNCTION_PASS("print<domtree>", DominatorTreePrinterPass(dbgs()))
-FUNCTION_PASS("print<postdomtree>", PostDominatorTreePrinterPass(dbgs()))
 FUNCTION_PASS("print<loops>", LoopPrinterPass(dbgs()))
 FUNCTION_PASS("print<scalar-evolution>", ScalarEvolutionPrinterPass(dbgs()))
 FUNCTION_PASS("simplify-cfg", SimplifyCFGPass())
index 1dae0c5..2eed213 100644 (file)
@@ -1,5 +1,4 @@
 ; RUN: opt < %s -postdomtree -analyze | FileCheck %s
-; RUN: opt < %s -passes='print<postdomtree>' 2>&1 | FileCheck %s
 ; PR932
 
 define void @foo(i1 %x) {
index fcd6b9c..3aef4d6 100644 (file)
@@ -29,8 +29,7 @@ namespace llvm {
       bool runOnFunction(Function &F) override {
         DominatorTree *DT =
             &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
-        PostDominatorTree *PDT =
-            &getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
+        PostDominatorTree *PDT = &getAnalysis<PostDominatorTree>();
         Function::iterator FI = F.begin();
 
         BasicBlock *BB0 = &*FI++;
@@ -207,7 +206,7 @@ namespace llvm {
       }
       void getAnalysisUsage(AnalysisUsage &AU) const override {
         AU.addRequired<DominatorTreeWrapperPass>();
-        AU.addRequired<PostDominatorTreeWrapperPass>();
+        AU.addRequired<PostDominatorTree>();
       }
       DPass() : FunctionPass(ID) {
         initializeDPassPass(*PassRegistry::getPassRegistry());
@@ -256,5 +255,5 @@ namespace llvm {
 
 INITIALIZE_PASS_BEGIN(DPass, "dpass", "dpass", false, false)
 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(PostDominatorTree)
 INITIALIZE_PASS_END(DPass, "dpass", "dpass", false, false)