llvm.org GIT mirror llvm / 040ca44
[PM] Add names and debug logging for analysis passes to the new pass manager. This starts to allow us to test analyses more easily, but it's really only the beginning. Some of the code here is still untestable without manual changes to create analysis passes, but I wanted to factor it into a small of chunks as possible. Next up in order to be able to test things are, in no particular order: - No-op analyses passes so we don't have to use real ones to exercise the pass maneger itself. - Automatic way of generating dummy passes that require an analysis be run, including a variant that calls a 'print' method on a pass to make it even easier to print out the results of an analysis. - Dummy passes that invalidate all analyses for their IR unit so we can test invalidation and re-runs. - Automatic way to print each analysis pass as it is re-run. - Automatic but optional verification of analysis passes everywhere possible. I'm not claiming I'll get to all of these immediately, but that's what is in the pipeline at some stage. I'm fleshing out exactly what I need and what to prioritize by working on converting analyses and then trying to test the conversion. =] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225162 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 4 years ago
8 changed file(s) with 93 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
194194
195195 static void *ID() { return (void *)&PassID; }
196196
197 static StringRef name() { return "CGSCCAnalysisManagerModuleProxy"; }
198
197199 explicit CGSCCAnalysisManagerModuleProxy(CGSCCAnalysisManager &CGAM)
198200 : CGAM(&CGAM) {}
199201 // We have to explicitly define all the special member functions because MSVC
264266
265267 static void *ID() { return (void *)&PassID; }
266268
269 static StringRef name() { return "ModuleAnalysisManagerCGSCCProxy"; }
270
267271 ModuleAnalysisManagerCGSCCProxy(const ModuleAnalysisManager &MAM)
268272 : MAM(&MAM) {}
269273 // We have to explicitly define all the special member functions because MSVC
416420
417421 static void *ID() { return (void *)&PassID; }
418422
423 static StringRef name() { return "FunctionAnalysisManagerCGSCCProxy"; }
424
419425 explicit FunctionAnalysisManagerCGSCCProxy(FunctionAnalysisManager &FAM)
420426 : FAM(&FAM) {}
421427 // We have to explicitly define all the special member functions because MSVC
486492
487493 static void *ID() { return (void *)&PassID; }
488494
495 static StringRef name() { return "CGSCCAnalysisManagerFunctionProxy"; }
496
489497 CGSCCAnalysisManagerFunctionProxy(const CGSCCAnalysisManager &CGAM)
490498 : CGAM(&CGAM) {}
491499 // We have to explicitly define all the special member functions because MSVC
251251 /// \brief Test if this SCC is a descendant of \a C.
252252 bool isDescendantOf(const SCC &C) const;
253253
254 /// \brief Short name useful for debugging or logging.
255 ///
256 /// We use the name of the first function in the SCC to name the SCC for
257 /// the purposes of debugging and logging.
258 StringRef getName() const { return (*begin())->getFunction().getName(); }
259
254260 ///@{
255261 /// \name Mutation API
256262 ///
536542
537543 static void *ID() { return (void *)&PassID; }
538544
545 static StringRef name() { return "Lazy CallGraph Analysis"; }
546
539547 /// \brief Compute the \c LazyCallGraph for the module \c M.
540548 ///
541549 /// This just builds the set of entry points to the call graph. The rest is
556556
557557 static void *ID() { return (void *)&PassID; }
558558
559 static StringRef name() { return "FunctionAnalysisManagerModuleProxy"; }
560
559561 explicit FunctionAnalysisManagerModuleProxy(FunctionAnalysisManager &FAM)
560562 : FAM(&FAM) {}
561563 // We have to explicitly define all the special member functions because MSVC
662664
663665 static void *ID() { return (void *)&PassID; }
664666
667 static StringRef name() { return "ModuleAnalysisManagerFunctionProxy"; }
668
665669 ModuleAnalysisManagerFunctionProxy(const ModuleAnalysisManager &MAM)
666670 : MAM(&MAM) {}
667671 // We have to explicitly define all the special member functions because MSVC
255255 /// users.
256256 virtual std::unique_ptr>
257257 run(IRUnitT IR, AnalysisManagerT *AM) = 0;
258
259 /// \brief Polymorphic method to access the name of a pass.
260 virtual StringRef name() = 0;
258261 };
259262
260263 /// \brief Wrapper to model the analysis pass concept.
298301 return make_unique(Pass.run(IR, AM));
299302 }
300303
304 /// \brief The model delegates to a static \c PassT::name method.
305 ///
306 /// The returned string ref must point to constant immutable data!
307 StringRef name() override { return PassT::name(); }
308
301309 PassT Pass;
302310 };
303311
332340 return make_unique(Pass.run(IR));
333341 }
334342
343 /// \brief The model delegates to a static \c PassT::name method.
344 ///
345 /// The returned string ref must point to constant immutable data!
346 StringRef name() override { return PassT::name(); }
347
335348 PassT Pass;
336349 };
337350
8383 if (RI == CGSCCAnalysisResults.end())
8484 return;
8585
86 if (DebugPM)
87 dbgs() << "Invalidating CGSCC analysis: " << lookupPass(PassID).name()
88 << "\n";
8689 CGSCCAnalysisResultLists[&C].erase(RI->second);
8790 }
8891
8992 void CGSCCAnalysisManager::invalidateImpl(LazyCallGraph::SCC &C,
9093 const PreservedAnalyses &PA) {
94 if (DebugPM)
95 dbgs() << "Invalidating all non-preserved analyses for SCC: " << C.getName()
96 << "\n";
97
9198 // Clear all the invalidated results associated specifically with this
9299 // function.
93100 SmallVector InvalidatedPassIDs;
96103 E = ResultsList.end();
97104 I != E;)
98105 if (I->second->invalidate(C, PA)) {
106 if (DebugPM)
107 dbgs() << "Invalidating CGSCC analysis: " << lookupPass(I->first).name()
108 << "\n";
109
99110 InvalidatedPassIDs.push_back(I->first);
100111 I = ResultsList.erase(I);
101112 } else {
5151
5252 // If we don't have a cached result for this module, look up the pass and run
5353 // it to produce a result, which we then add to the cache.
54 if (Inserted)
55 RI->second = lookupPass(PassID).run(M, this);
54 if (Inserted) {
55 auto &P = lookupPass(PassID);
56 if (DebugPM)
57 dbgs() << "Running module analysis: " << P.name() << "\n";
58 RI->second = P.run(M, this);
59 }
5660
5761 return *RI->second;
5862 }
6569 }
6670
6771 void ModuleAnalysisManager::invalidateImpl(void *PassID, Module &M) {
72 if (DebugPM)
73 dbgs() << "Invalidating module analysis: " << lookupPass(PassID).name()
74 << "\n";
6875 ModuleAnalysisResults.erase(PassID);
6976 }
7077
7178 void ModuleAnalysisManager::invalidateImpl(Module &M,
7279 const PreservedAnalyses &PA) {
80 if (DebugPM)
81 dbgs() << "Invalidating all non-preserved analyses for module: "
82 << M.getModuleIdentifier() << "\n";
83
7384 // FIXME: This is a total hack based on the fact that erasure doesn't
7485 // invalidate iteration for DenseMap.
7586 for (ModuleAnalysisResultMapT::iterator I = ModuleAnalysisResults.begin(),
7687 E = ModuleAnalysisResults.end();
7788 I != E; ++I)
78 if (I->second->invalidate(M, PA))
89 if (I->second->invalidate(M, PA)) {
90 if (DebugPM)
91 dbgs() << "Invalidating module analysis: "
92 << lookupPass(I->first).name() << "\n";
93
7994 ModuleAnalysisResults.erase(I);
95 }
8096 }
8197
8298 PreservedAnalyses FunctionPassManager::run(Function &F,
127143 // If we don't have a cached result for this function, look up the pass and
128144 // run it to produce a result, which we then add to the cache.
129145 if (Inserted) {
146 auto &P = lookupPass(PassID);
147 if (DebugPM)
148 dbgs() << "Running function analysis: " << P.name() << "\n";
130149 FunctionAnalysisResultListT &ResultList = FunctionAnalysisResultLists[&F];
131 ResultList.emplace_back(PassID, lookupPass(PassID).run(F, this));
150 ResultList.emplace_back(PassID, P.run(F, this));
132151 RI->second = std::prev(ResultList.end());
133152 }
134153
148167 if (RI == FunctionAnalysisResults.end())
149168 return;
150169
170 if (DebugPM)
171 dbgs() << "Invalidating function analysis: " << lookupPass(PassID).name()
172 << "\n";
151173 FunctionAnalysisResultLists[&F].erase(RI->second);
152174 }
153175
154176 void FunctionAnalysisManager::invalidateImpl(Function &F,
155177 const PreservedAnalyses &PA) {
178 if (DebugPM)
179 dbgs() << "Invalidating all non-preserved analyses for function: "
180 << F.getName() << "\n";
181
156182 // Clear all the invalidated results associated specifically with this
157183 // function.
158184 SmallVector InvalidatedPassIDs;
161187 E = ResultsList.end();
162188 I != E;)
163189 if (I->second->invalidate(F, PA)) {
190 if (DebugPM)
191 dbgs() << "Invalidating function analysis: "
192 << lookupPass(I->first).name() << "\n";
193
164194 InvalidatedPassIDs.push_back(I->first);
165195 I = ResultsList.erase(I);
166196 } else {
2727 ; RUN: | FileCheck %s --check-prefix=CHECK-FUNCTION-PRINT
2828 ; CHECK-FUNCTION-PRINT: Starting module pass manager
2929 ; CHECK-FUNCTION-PRINT: Running module pass: VerifierPass
30 ; CHECK-FUNCTION-PRINT: Running module pass: ModuleToFunctionPassAdaptor
31 ; CHECK-FUNCTION-PRINT: Running module analysis: FunctionAnalysisManagerModuleProxy
3032 ; CHECK-FUNCTION-PRINT: Starting function pass manager
3133 ; CHECK-FUNCTION-PRINT: Running function pass: PrintFunctionPass
3234 ; CHECK-FUNCTION-PRINT-NOT: ModuleID
8385 ; CHECK-NO-VERIFY-NOT: VerifierPass
8486 ; CHECK-NO-VERIFY: Finished module pass manager
8587
88 ; RUN: opt -disable-output -debug-pass-manager -debug-cgscc-pass-manager -passes='cgscc(no-op-cgscc)' %s 2>&1 \
89 ; RUN: | FileCheck %s --check-prefix=CHECK-LCG-ANALYSIS
90 ; CHECK-LCG-ANALYSIS: Starting module pass manager
91 ; CHECK-LCG-ANALYSIS: Running module pass: ModuleToPostOrderCGSCCPassAdaptor
92 ; CHECK-LCG-ANALYSIS: Running module analysis: CGSCCAnalysisManagerModuleProxy
93 ; CHECK-LCG-ANALYSIS: Running module analysis: Lazy CallGraph Analysis
94 ; CHECK-LCG-ANALYSIS: Starting CGSCC pass manager run.
95
8696 define void @foo() {
8797 ret void
8898 }
2727
2828 /// \brief Returns an opaque, unique ID for this pass type.
2929 static void *ID() { return (void *)&PassID; }
30
31 /// \brief Returns the name of the analysis.
32 static StringRef name() { return "TestFunctionAnalysis"; }
3033
3134 TestFunctionAnalysis(int &Runs) : Runs(Runs) {}
3235
5861 };
5962
6063 static void *ID() { return (void *)&PassID; }
64
65 static StringRef name() { return "TestModuleAnalysis"; }
6166
6267 TestModuleAnalysis(int &Runs) : Runs(Runs) {}
6368