llvm.org GIT mirror llvm / 8c3a02f
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225969 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 4 years ago
6 changed file(s) with 90 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
3030
3131 namespace llvm {
3232
33 // FIXME: Replace this brittle forward declaration with the include of the new
34 // PassManager.h when doing so doesn't break the PassManagerBuilder.
35 template class AnalysisManager;
36 class PreservedAnalyses;
37
3338 EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase);
3439 EXTERN_TEMPLATE_INSTANTIATION(class DominatorTreeBase);
3540
161166 };
162167
163168 /// \brief Analysis pass which computes a \c DominatorTree.
169 class DominatorTreeAnalysis {
170 public:
171 /// \brief Provide the result typedef for this analysis pass.
172 typedef DominatorTree Result;
173
174 /// \brief Opaque, unique identifier for this analysis pass.
175 static void *ID() { return (void *)&PassID; }
176
177 /// \brief Run the analysis pass over a function and produce a dominator tree.
178 DominatorTree run(Function &F);
179
180 /// \brief Provide access to a name for this pass for debugging purposes.
181 static StringRef name() { return "DominatorTreeAnalysis"; }
182
183 private:
184 static char PassID;
185 };
186
187 /// \brief Printer pass for the \c DominatorTree.
188 class DominatorTreePrinterPass {
189 raw_ostream &OS;
190
191 public:
192 explicit DominatorTreePrinterPass(raw_ostream &OS);
193 PreservedAnalyses run(Function &F, AnalysisManager *AM);
194
195 static StringRef name() { return "DominatorTreePrinterPass"; }
196 };
197
198 /// \brief Verifier pass for the \c DominatorTree.
199 struct DominatorTreeVerifierPass {
200 PreservedAnalyses run(Function &F, AnalysisManager *AM);
201
202 static StringRef name() { return "DominatorTreeVerifierPass"; }
203 };
204
205 /// \brief Legacy analysis pass which computes a \c DominatorTree.
164206 class DominatorTreeWrapperPass : public FunctionPass {
165207 DominatorTree DT;
166208
1919 #include "llvm/ADT/SmallVector.h"
2020 #include "llvm/IR/CFG.h"
2121 #include "llvm/IR/Instructions.h"
22 #include "llvm/IR/PassManager.h"
2223 #include "llvm/Support/CommandLine.h"
2324 #include "llvm/Support/Compiler.h"
2425 #include "llvm/Support/Debug.h"
297298 }
298299
299300 //===----------------------------------------------------------------------===//
301 // DominatorTreeAnalysis and related pass implementations
302 //===----------------------------------------------------------------------===//
303 //
304 // This implements the DominatorTreeAnalysis which is used with the new pass
305 // manager. It also implements some methods from utility passes.
306 //
307 //===----------------------------------------------------------------------===//
308
309 DominatorTree DominatorTreeAnalysis::run(Function &F) {
310 DominatorTree DT;
311 DT.recalculate(F);
312 return DT;
313 }
314
315 char DominatorTreeAnalysis::PassID;
316
317 DominatorTreePrinterPass::DominatorTreePrinterPass(raw_ostream &OS) : OS(OS) {}
318
319 PreservedAnalyses DominatorTreePrinterPass::run(Function &F,
320 FunctionAnalysisManager *AM) {
321 OS << "DominatorTree for function: " << F.getName() << "\n";
322 AM->getResult(F).print(OS);
323
324 return PreservedAnalyses::all();
325 }
326
327 PreservedAnalyses DominatorTreeVerifierPass::run(Function &F,
328 FunctionAnalysisManager *AM) {
329 AM->getResult(F).verifyDomTree();
330
331 return PreservedAnalyses::all();
332 }
333
334 //===----------------------------------------------------------------------===//
300335 // DominatorTreeWrapperPass Implementation
301336 //===----------------------------------------------------------------------===//
302337 //
303 // The implementation details of the wrapper pass that holds a DominatorTree.
338 // The implementation details of the wrapper pass that holds a DominatorTree
339 // suitable for use with the legacy pass manager.
304340 //
305341 //===----------------------------------------------------------------------===//
306342
None ; RUN: opt < %s -domtree -analyze | FileCheck %s
0 ; RUN: opt < %s -domtree -analyze | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-OLDPM
1 ; RUN: opt < %s -disable-output -passes='print' 2>&1 | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-NEWPM
12
23 define void @test1() {
3 ; CHECK-LABEL: 'Dominator Tree Construction' for function 'test1':
4 ; CHECK-OLDPM-LABEL: 'Dominator Tree Construction' for function 'test1':
5 ; CHECK-NEWPM-LABEL: DominatorTree for function: test1
46 ; CHECK: [1] %entry
57 ; CHECK-NEXT: [2] %a
68 ; CHECK-NEXT: [2] %c
2830 }
2931
3032 define void @test2() {
31 ; CHECK-LABEL: 'Dominator Tree Construction' for function 'test2':
33 ; CHECK-OLDPM-LABEL: 'Dominator Tree Construction' for function 'test2':
34 ; CHECK-NEWPM-LABEL: DominatorTree for function: test2
3235 ; CHECK: [1] %entry
3336 ; CHECK-NEXT: [2] %a
3437 ; CHECK-NEXT: [3] %b
1717 #include "llvm/ADT/StringRef.h"
1818 #include "llvm/Analysis/CGSCCPassManager.h"
1919 #include "llvm/Bitcode/BitcodeWriterPass.h"
20 #include "llvm/IR/Dominators.h"
2021 #include "llvm/IR/IRPrintingPasses.h"
2122 #include "llvm/IR/LLVMContext.h"
2223 #include "llvm/IR/Module.h"
4848 #ifndef FUNCTION_ANALYSIS
4949 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS)
5050 #endif
51 FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis())
5152 FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
5253 #undef FUNCTION_ANALYSIS
5354
5758 FUNCTION_PASS("invalidate", InvalidateAllAnalysesPass())
5859 FUNCTION_PASS("no-op-function", NoOpFunctionPass())
5960 FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
61 FUNCTION_PASS("print", DominatorTreePrinterPass(dbgs()))
6062 FUNCTION_PASS("verify", VerifierPass())
63 FUNCTION_PASS("verify", DominatorTreeVerifierPass())
6164 #undef FUNCTION_PASS
1616 #include "Passes.h"
1717 #include "llvm/Analysis/CGSCCPassManager.h"
1818 #include "llvm/Analysis/LazyCallGraph.h"
19 #include "llvm/IR/Dominators.h"
1920 #include "llvm/IR/IRPrintingPasses.h"
2021 #include "llvm/IR/PassManager.h"
2122 #include "llvm/IR/Verifier.h"