summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2015-01-14 10:19:28 +0000
committerChandler Carruth <chandlerc@gmail.com>2015-01-14 10:19:28 +0000
commit64764b446b9339ef14ac0b9b7b5063b8abc3190a (patch)
tree75a0920c51242ded55ea0acb4cd7d6150578ef65
parent755b6e8a42b23c853d804b6fef7847d9365c4786 (diff)
downloadbcm5719-llvm-64764b446b9339ef14ac0b9b7b5063b8abc3190a.tar.gz
bcm5719-llvm-64764b446b9339ef14ac0b9b7b5063b8abc3190a.zip
[PM] Port domtree to the new pass manager (at last).
This adds the domtree analysis to the new pass manager. The analysis returns the same DominatorTree result entity used by the old pass manager and essentially all of the code is shared. We just have different boilerplate for running and printing the analysis. I've converted one test to run in both modes just to make sure this is exercised while both are live in the tree. llvm-svn: 225969
-rw-r--r--llvm/include/llvm/IR/Dominators.h42
-rw-r--r--llvm/lib/IR/Dominators.cpp38
-rw-r--r--llvm/test/Analysis/Dominators/basic.ll9
-rw-r--r--llvm/tools/opt/NewPMDriver.cpp1
-rw-r--r--llvm/tools/opt/PassRegistry.def3
-rw-r--r--llvm/tools/opt/Passes.cpp1
6 files changed, 90 insertions, 4 deletions
diff --git a/llvm/include/llvm/IR/Dominators.h b/llvm/include/llvm/IR/Dominators.h
index 4e7dacc1a37..c1f208e3d72 100644
--- a/llvm/include/llvm/IR/Dominators.h
+++ b/llvm/include/llvm/IR/Dominators.h
@@ -31,6 +31,11 @@
namespace llvm {
+// FIXME: Replace this brittle forward declaration with the include of the new
+// PassManager.h when doing so doesn't break the PassManagerBuilder.
+template <typename IRUnitT> class AnalysisManager;
+class PreservedAnalyses;
+
EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<BasicBlock>);
EXTERN_TEMPLATE_INSTANTIATION(class DominatorTreeBase<BasicBlock>);
@@ -162,6 +167,43 @@ template <> struct GraphTraits<DominatorTree*>
};
/// \brief Analysis pass which computes a \c DominatorTree.
+class DominatorTreeAnalysis {
+public:
+ /// \brief Provide the result typedef for this analysis pass.
+ typedef DominatorTree 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 dominator tree.
+ DominatorTree run(Function &F);
+
+ /// \brief Provide access to a name for this pass for debugging purposes.
+ static StringRef name() { return "DominatorTreeAnalysis"; }
+
+private:
+ static char PassID;
+};
+
+/// \brief Printer pass for the \c DominatorTree.
+class DominatorTreePrinterPass {
+ raw_ostream &OS;
+
+public:
+ explicit DominatorTreePrinterPass(raw_ostream &OS);
+ PreservedAnalyses run(Function &F, AnalysisManager<Function> *AM);
+
+ static StringRef name() { return "DominatorTreePrinterPass"; }
+};
+
+/// \brief Verifier pass for the \c DominatorTree.
+struct DominatorTreeVerifierPass {
+ PreservedAnalyses run(Function &F, AnalysisManager<Function> *AM);
+
+ static StringRef name() { return "DominatorTreeVerifierPass"; }
+};
+
+/// \brief Legacy analysis pass which computes a \c DominatorTree.
class DominatorTreeWrapperPass : public FunctionPass {
DominatorTree DT;
diff --git a/llvm/lib/IR/Dominators.cpp b/llvm/lib/IR/Dominators.cpp
index d6649d6c706..9b6ff1eb136 100644
--- a/llvm/lib/IR/Dominators.cpp
+++ b/llvm/lib/IR/Dominators.cpp
@@ -20,6 +20,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Instructions.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
@@ -298,10 +299,45 @@ void DominatorTree::verifyDomTree() const {
}
//===----------------------------------------------------------------------===//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+DominatorTree DominatorTreeAnalysis::run(Function &F) {
+ DominatorTree DT;
+ DT.recalculate(F);
+ return DT;
+}
+
+char DominatorTreeAnalysis::PassID;
+
+DominatorTreePrinterPass::DominatorTreePrinterPass(raw_ostream &OS) : OS(OS) {}
+
+PreservedAnalyses DominatorTreePrinterPass::run(Function &F,
+ FunctionAnalysisManager *AM) {
+ OS << "DominatorTree for function: " << F.getName() << "\n";
+ AM->getResult<DominatorTreeAnalysis>(F).print(OS);
+
+ return PreservedAnalyses::all();
+}
+
+PreservedAnalyses DominatorTreeVerifierPass::run(Function &F,
+ FunctionAnalysisManager *AM) {
+ AM->getResult<DominatorTreeAnalysis>(F).verifyDomTree();
+
+ return PreservedAnalyses::all();
+}
+
+//===----------------------------------------------------------------------===//
// DominatorTreeWrapperPass Implementation
//===----------------------------------------------------------------------===//
//
-// The implementation details of the wrapper pass that holds a DominatorTree.
+// The implementation details of the wrapper pass that holds a DominatorTree
+// suitable for use with the legacy pass manager.
//
//===----------------------------------------------------------------------===//
diff --git a/llvm/test/Analysis/Dominators/basic.ll b/llvm/test/Analysis/Dominators/basic.ll
index 8627a87b557..353c3397b5d 100644
--- a/llvm/test/Analysis/Dominators/basic.ll
+++ b/llvm/test/Analysis/Dominators/basic.ll
@@ -1,7 +1,9 @@
-; RUN: opt < %s -domtree -analyze | FileCheck %s
+; RUN: opt < %s -domtree -analyze | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-OLDPM
+; RUN: opt < %s -disable-output -passes='print<domtree>' 2>&1 | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-NEWPM
define void @test1() {
-; CHECK-LABEL: 'Dominator Tree Construction' for function 'test1':
+; CHECK-OLDPM-LABEL: 'Dominator Tree Construction' for function 'test1':
+; CHECK-NEWPM-LABEL: DominatorTree for function: test1
; CHECK: [1] %entry
; CHECK-NEXT: [2] %a
; CHECK-NEXT: [2] %c
@@ -29,7 +31,8 @@ e:
}
define void @test2() {
-; CHECK-LABEL: 'Dominator Tree Construction' for function 'test2':
+; CHECK-OLDPM-LABEL: 'Dominator Tree Construction' for function 'test2':
+; CHECK-NEWPM-LABEL: DominatorTree for function: test2
; CHECK: [1] %entry
; CHECK-NEXT: [2] %a
; CHECK-NEXT: [3] %b
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index d37211faf6d..f215c77459a 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -18,6 +18,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/Bitcode/BitcodeWriterPass.h"
+#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
diff --git a/llvm/tools/opt/PassRegistry.def b/llvm/tools/opt/PassRegistry.def
index e05dae871b8..c98de60b570 100644
--- a/llvm/tools/opt/PassRegistry.def
+++ b/llvm/tools/opt/PassRegistry.def
@@ -49,6 +49,7 @@ CGSCC_PASS("no-op-cgscc", NoOpCGSCCPass())
#ifndef FUNCTION_ANALYSIS
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS)
#endif
+FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis())
FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
#undef FUNCTION_ANALYSIS
@@ -58,5 +59,7 @@ FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
FUNCTION_PASS("invalidate<all>", InvalidateAllAnalysesPass())
FUNCTION_PASS("no-op-function", NoOpFunctionPass())
FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
+FUNCTION_PASS("print<domtree>", DominatorTreePrinterPass(dbgs()))
FUNCTION_PASS("verify", VerifierPass())
+FUNCTION_PASS("verify<domtree>", DominatorTreeVerifierPass())
#undef FUNCTION_PASS
diff --git a/llvm/tools/opt/Passes.cpp b/llvm/tools/opt/Passes.cpp
index c81c5633684..518112a1c88 100644
--- a/llvm/tools/opt/Passes.cpp
+++ b/llvm/tools/opt/Passes.cpp
@@ -17,6 +17,7 @@
#include "Passes.h"
#include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/Analysis/LazyCallGraph.h"
+#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Verifier.h"
OpenPOWER on IntegriCloud