llvm.org GIT mirror llvm / 9137eb3
Revert "Introduce analysis pass to compute PostDominators in the new pass manager. NFC" This reverts commit a3e5cc6a51ab5ad88d1760c63284294a4e34c018. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261891 91177308-0d34-0410-b5e6-96231b3b80d8 Hongbin Zheng 4 years ago
12 changed file(s) with 87 addition(s) and 126 deletion(s). Raw diff Collapse all Expand all
1616 #include "llvm/IR/Dominators.h"
1717
1818 namespace llvm {
19 // FIXME: Replace this brittle forward declaration with the include of the new
20 // PassManager.h when doing so doesn't break the PassManagerBuilder.
21 class PreservedAnalyses;
2219
2320 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
2421 /// compute the post-dominator tree.
2522 ///
26 struct PostDominatorTree : public DominatorTreeBase {
27 PostDominatorTree() : DominatorTreeBase(true) {}
28 };
23 struct PostDominatorTree : public FunctionPass {
24 static char ID; // Pass identification, replacement for typeid
25 DominatorTreeBase* DT;
2926
30 /// \brief Analysis pass which computes a \c PostDominatorTree.
31 class PostDominatorTreeAnalysis {
32 public:
33 /// \brief Provide the result typedef for this analysis pass.
34 typedef PostDominatorTree Result;
35
36 /// \brief Opaque, unique identifier for this analysis pass.
37 static void *ID() { return (void *)&PassID; }
38
39 /// \brief Run the analysis pass over a function and produce a post dominator
40 /// tree.
41 PostDominatorTree run(Function &F);
42
43 /// \brief Provide access to a name for this pass for debugging purposes.
44 static StringRef name() { return "PostDominatorTreeAnalysis"; }
45
46 private:
47 static char PassID;
48 };
49
50 /// \brief Printer pass for the \c PostDominatorTree.
51 class PostDominatorTreePrinterPass {
52 raw_ostream &OS;
53
54 public:
55 explicit PostDominatorTreePrinterPass(raw_ostream &OS);
56 PreservedAnalyses run(Function &F, AnalysisManager *AM);
57
58 static StringRef name() { return "PostDominatorTreePrinterPass"; }
59 };
60
61 struct PostDominatorTreeWrapperPass : public FunctionPass {
62 static char ID; // Pass identification, replacement for typeid
63 PostDominatorTree DT;
64
65 PostDominatorTreeWrapperPass() : FunctionPass(ID) {
66 initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
27 PostDominatorTree() : FunctionPass(ID) {
28 initializePostDominatorTreePass(*PassRegistry::getPassRegistry());
29 DT = new DominatorTreeBase(true);
6730 }
6831
69 PostDominatorTree &getPostDomTree() { return DT; }
70 const PostDominatorTree &getPostDomTree() const { return DT; }
32 ~PostDominatorTree() override;
7133
7234 bool runOnFunction(Function &F) override;
7335
7537 AU.setPreservesAll();
7638 }
7739
40 inline const std::vector &getRoots() const {
41 return DT->getRoots();
42 }
43
44 inline DomTreeNode *getRootNode() const {
45 return DT->getRootNode();
46 }
47
48 inline DomTreeNode *operator[](BasicBlock *BB) const {
49 return DT->getNode(BB);
50 }
51
52 inline DomTreeNode *getNode(BasicBlock *BB) const {
53 return DT->getNode(BB);
54 }
55
56 inline bool dominates(DomTreeNode* A, DomTreeNode* B) const {
57 return DT->dominates(A, B);
58 }
59
60 inline bool dominates(const BasicBlock* A, const BasicBlock* B) const {
61 return DT->dominates(A, B);
62 }
63
64 inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
65 return DT->properlyDominates(A, B);
66 }
67
68 inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
69 return DT->properlyDominates(A, B);
70 }
71
72 inline BasicBlock *findNearestCommonDominator(BasicBlock *A, BasicBlock *B) {
73 return DT->findNearestCommonDominator(A, B);
74 }
75
76 inline const BasicBlock *findNearestCommonDominator(const BasicBlock *A,
77 const BasicBlock *B) {
78 return DT->findNearestCommonDominator(A, B);
79 }
80
81 /// Get all nodes post-dominated by R, including R itself.
82 void getDescendants(BasicBlock *R,
83 SmallVectorImpl &Result) const {
84 DT->getDescendants(R, Result);
85 }
86
7887 void releaseMemory() override {
79 DT.releaseMemory();
88 DT->releaseMemory();
8089 }
8190
8291 void print(raw_ostream &OS, const Module*) const override;
231231 void initializePostDomOnlyViewerPass(PassRegistry&);
232232 void initializePostDomPrinterPass(PassRegistry&);
233233 void initializePostDomViewerPass(PassRegistry&);
234 void initializePostDominatorTreeWrapperPassPass(PassRegistry&);
234 void initializePostDominatorTreePass(PassRegistry&);
235235 void initializePostOrderFunctionAttrsLegacyPassPass(PassRegistry&);
236236 void initializePostRASchedulerPass(PassRegistry&);
237237 void initializePostMachineSchedulerPass(PassRegistry&);
5959 initializeMemoryDependenceAnalysisPass(Registry);
6060 initializeModuleDebugInfoPrinterPass(Registry);
6161 initializeObjCARCAAWrapperPassPass(Registry);
62 initializePostDominatorTreeWrapperPassPass(Registry);
62 initializePostDominatorTreePass(Registry);
6363 initializeRegionInfoPassPass(Registry);
6464 initializeRegionViewerPass(Registry);
6565 initializeRegionPrinterPass(Registry);
257257 INITIALIZE_PASS_BEGIN(DivergenceAnalysis, "divergence", "Divergence Analysis",
258258 false, true)
259259 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
260 INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)
260 INITIALIZE_PASS_DEPENDENCY(PostDominatorTree)
261261 INITIALIZE_PASS_END(DivergenceAnalysis, "divergence", "Divergence Analysis",
262262 false, true)
263263
267267
268268 void DivergenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
269269 AU.addRequired();
270 AU.addRequiredWrapperPass>();
270 AU.addRequired>();
271271 AU.setPreservesAll();
272272 }
273273
283283 return false;
284284
285285 DivergentValues.clear();
286 auto &PDT = getAnalysis().getPostDomTree();
287286 DivergencePropagator DP(F, TTI,
288287 getAnalysis().getDomTree(),
289 PDT, DivergentValues);
288 getAnalysis(), DivergentValues);
290289 DP.populateWithSourcesOfDivergence();
291290 DP.propagate();
292291 return false;
110110 }
111111 };
112112
113 struct PostDominatorTreeWrapperPassAnalysisGraphTraits {
114 static PostDominatorTree *getGraph(PostDominatorTreeWrapperPass *PDTWP) {
115 return &PDTWP->getPostDomTree();
116 }
117 };
118
119 struct PostDomViewer : public DOTGraphTraitsViewer<
120 PostDominatorTreeWrapperPass, false,
121 PostDominatorTree *,
122 PostDominatorTreeWrapperPassAnalysisGraphTraits> {
113 struct PostDomViewer
114 : public DOTGraphTraitsViewer {
123115 static char ID;
124116 PostDomViewer() :
125 DOTGraphTraitsViewer
126 PostDominatorTree *,
127 PostDominatorTreeWrapperPassAnalysisGraphTraits>(
128 "postdom", ID){
117 DOTGraphTraitsViewer("postdom", ID){
129118 initializePostDomViewerPass(*PassRegistry::getPassRegistry());
130119 }
131120 };
132121
133 struct PostDomOnlyViewer : public DOTGraphTraitsViewer<
134 PostDominatorTreeWrapperPass, true,
135 PostDominatorTree *,
136 PostDominatorTreeWrapperPassAnalysisGraphTraits> {
122 struct PostDomOnlyViewer
123 : public DOTGraphTraitsViewer {
137124 static char ID;
138125 PostDomOnlyViewer() :
139 DOTGraphTraitsViewer
140 PostDominatorTree *,
141 PostDominatorTreeWrapperPassAnalysisGraphTraits>(
142 "postdomonly", ID){
126 DOTGraphTraitsViewer("postdomonly", ID){
143127 initializePostDomOnlyViewerPass(*PassRegistry::getPassRegistry());
144128 }
145129 };
190174 };
191175
192176 struct PostDomPrinter
193 : public DOTGraphTraitsPrinter<
194 PostDominatorTreeWrapperPass, false,
195 PostDominatorTree *,
196 PostDominatorTreeWrapperPassAnalysisGraphTraits> {
177 : public DOTGraphTraitsPrinter> {
197178 static char ID;
198179 PostDomPrinter() :
199 DOTGraphTraitsPrinter
200 PostDominatorTree *,
201 PostDominatorTreeWrapperPassAnalysisGraphTraits>(
202 "postdom", ID) {
180 DOTGraphTraitsPrinter("postdom", ID) {
203181 initializePostDomPrinterPass(*PassRegistry::getPassRegistry());
204182 }
205183 };
206184
207185 struct PostDomOnlyPrinter
208 : public DOTGraphTraitsPrinter<
209 PostDominatorTreeWrapperPass, true,
210 PostDominatorTree *,
211 PostDominatorTreeWrapperPassAnalysisGraphTraits> {
186 : public DOTGraphTraitsPrinter> {
212187 static char ID;
213188 PostDomOnlyPrinter() :
214 DOTGraphTraitsPrinter
215 PostDominatorTree *,
216 PostDominatorTreeWrapperPassAnalysisGraphTraits>(
217 "postdomonly", ID) {
189 DOTGraphTraitsPrinter("postdomonly", ID) {
218190 initializePostDomOnlyPrinterPass(*PassRegistry::getPassRegistry());
219191 }
220192 };
1515 #include "llvm/ADT/SetOperations.h"
1616 #include "llvm/IR/CFG.h"
1717 #include "llvm/IR/Instructions.h"
18 #include "llvm/IR/PassManager.h"
1918 #include "llvm/Support/Debug.h"
2019 #include "llvm/Support/GenericDomTreeConstruction.h"
2120 using namespace llvm;
2625 // PostDominatorTree Implementation
2726 //===----------------------------------------------------------------------===//
2827
29 char PostDominatorTreeWrapperPass::ID = 0;
30 INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
28 char PostDominatorTree::ID = 0;
29 INITIALIZE_PASS(PostDominatorTree, "postdomtree",
3130 "Post-Dominator Tree Construction", true, true)
3231
33 bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
34 DT.recalculate(F);
32 bool PostDominatorTree::runOnFunction(Function &F) {
33 DT->recalculate(F);
3534 return false;
3635 }
3736
38 void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
39 DT.print(OS);
37 PostDominatorTree::~PostDominatorTree() {
38 delete DT;
4039 }
4140
42 FunctionPass* llvm::createPostDomTree() {
43 return new PostDominatorTreeWrapperPass();
41 void PostDominatorTree::print(raw_ostream &OS, const Module *) const {
42 DT->print(OS);
4443 }
4544
46 char PostDominatorTreeAnalysis::PassID;
4745
48 PostDominatorTree PostDominatorTreeAnalysis::run(Function &F) {
49 PostDominatorTree PDT;
50 PDT.recalculate(F);
51 return PDT;
46 FunctionPass* llvm::createPostDomTree() {
47 return new PostDominatorTree();
5248 }
5349
54 PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
55 : OS(OS) {}
56
57 PreservedAnalyses
58 PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager *AM) {
59 OS << "PostDominatorTree for function: " << F.getName() << "\n";
60 AM->getResult(F).print(OS);
61
62 return PreservedAnalyses::all();
63 }
127127 releaseMemory();
128128
129129 auto DT = &getAnalysis().getDomTree();
130 auto PDT = &getAnalysisWrapperPass>().getPostDomTree();
130 auto PDT = &getAnalysis>();
131131 auto DF = &getAnalysis();
132132
133133 RI.recalculate(F, DT, PDT, DF);
145145 void RegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
146146 AU.setPreservesAll();
147147 AU.addRequiredTransitive();
148 AU.addRequired();
148149 AU.addRequired();
149 AU.addRequired();
150150 }
151151
152152 void RegionInfoPass::print(raw_ostream &OS, const Module *) const {
164164 INITIALIZE_PASS_BEGIN(RegionInfoPass, "regions",
165165 "Detect single entry single exit regions", true, true)
166166 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
167 INITIALIZE_PASS_DEPENDENCY(PostDominatorTree)
167168 INITIALIZE_PASS_DEPENDENCY(DominanceFrontier)
168 INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)
169169 INITIALIZE_PASS_END(RegionInfoPass, "regions",
170170 "Detect single entry single exit regions", true, true)
171171
103103 void MachineRegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
104104 AU.setPreservesAll();
105105 AU.addRequiredTransitive();
106 AU.addRequiredWrapperPass>();
106 AU.addRequired>();
107107 AU.addRequired();
108108 }
109109
2323 #include "llvm/Analysis/CGSCCPassManager.h"
2424 #include "llvm/Analysis/LazyCallGraph.h"
2525 #include "llvm/Analysis/LoopInfo.h"
26 #include "llvm/Analysis/PostDominators.h"
2726 #include "llvm/Analysis/ScalarEvolution.h"
2827 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
2928 #include "llvm/Analysis/ScopedNoAliasAA.h"
5656 FUNCTION_ANALYSIS("aa", AAManager())
5757 FUNCTION_ANALYSIS("assumptions", AssumptionAnalysis())
5858 FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis())
59 FUNCTION_ANALYSIS("postdomtree", PostDominatorTreeAnalysis())
6059 FUNCTION_ANALYSIS("loops", LoopAnalysis())
6160 FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
6261 FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
8988 FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
9089 FUNCTION_PASS("print", AssumptionPrinterPass(dbgs()))
9190 FUNCTION_PASS("print", DominatorTreePrinterPass(dbgs()))
92 FUNCTION_PASS("print", PostDominatorTreePrinterPass(dbgs()))
9391 FUNCTION_PASS("print", LoopPrinterPass(dbgs()))
9492 FUNCTION_PASS("print", ScalarEvolutionPrinterPass(dbgs()))
9593 FUNCTION_PASS("simplify-cfg", SimplifyCFGPass())
0 ; RUN: opt < %s -postdomtree -analyze | FileCheck %s
1 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
21 ; PR932
32
43 define void @foo(i1 %x) {
2828 bool runOnFunction(Function &F) override {
2929 DominatorTree *DT =
3030 &getAnalysis().getDomTree();
31 PostDominatorTree *PDT =
32 &getAnalysis().getPostDomTree();
31 PostDominatorTree *PDT = &getAnalysis();
3332 Function::iterator FI = F.begin();
3433
3534 BasicBlock *BB0 = &*FI++;
206205 }
207206 void getAnalysisUsage(AnalysisUsage &AU) const override {
208207 AU.addRequired();
209 AU.addRequiredWrapperPass>();
208 AU.addRequired>();
210209 }
211210 DPass() : FunctionPass(ID) {
212211 initializeDPassPass(*PassRegistry::getPassRegistry());
255254
256255 INITIALIZE_PASS_BEGIN(DPass, "dpass", "dpass", false, false)
257256 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
258 INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)
257 INITIALIZE_PASS_DEPENDENCY(PostDominatorTree)
259258 INITIALIZE_PASS_END(DPass, "dpass", "dpass", false, false)