llvm.org GIT mirror llvm / b246ace
[PM] Switch the new pass manager to use a reference-based API for IR units. This was debated back and forth a bunch, but using references is now clearly cleaner. Of all the code written using pointers thus far, in only one place did it really make more sense to have a pointer. In most cases, this just removes immediate dereferencing from the code. I think it is much better to get errors on null IR units earlier, potentially at compile time, than to delay it. Most notably, the legacy pass manager uses references for its routines and so as more and more code works with both, the use of pointers was likely to become really annoying. I noticed this when I ported the domtree analysis over and wrote the entire thing with references only to have it fail to compile. =/ It seemed better to switch now than to delay. We can, of course, revisit this is we learn that references are really problematic in the API. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225145 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 4 years ago
15 changed file(s) with 143 addition(s) and 144 deletion(s). Raw diff Collapse all Expand all
3939 }
4040
4141 /// \brief Run all of the CGSCC passes in this pass manager over a SCC.
42 PreservedAnalyses run(LazyCallGraph::SCC *C,
42 PreservedAnalyses run(LazyCallGraph::SCC &C,
4343 CGSCCAnalysisManager *AM = nullptr);
4444
4545 template void addPass(CGSCCPassT Pass) {
5050
5151 private:
5252 // Pull in the concept type and model template specialized for SCCs.
53 typedef detail::PassConcept*, CGSCCAnalysisManager>
53 typedef detail::PassConcept&, CGSCCAnalysisManager>
5454 CGSCCPassConcept;
5555 template
5656 struct CGSCCPassModel
57 : detail::PassModel*, CGSCCAnalysisManager, PassT> {
57 : detail::PassModel&, CGSCCAnalysisManager, PassT> {
5858 CGSCCPassModel(PassT Pass)
59 : detail::PassModel*, CGSCCAnalysisManager, PassT>(
59 : detail::PassModel&, CGSCCAnalysisManager, PassT>(
6060 std::move(Pass)) {}
6161 };
6262
6969 /// \brief A function analysis manager to coordinate and cache analyses run over
7070 /// a module.
7171 class CGSCCAnalysisManager : public detail::AnalysisManagerBase<
72 CGSCCAnalysisManager, LazyCallGraph::SCC *> {
72 CGSCCAnalysisManager, LazyCallGraph::SCC &> {
7373 friend class detail::AnalysisManagerBase
74 LazyCallGraph::SCC *>;
74 LazyCallGraph::SCC &>;
7575 typedef detail::AnalysisManagerBase
76 LazyCallGraph::SCC *> BaseT;
76 LazyCallGraph::SCC &> BaseT;
7777 typedef BaseT::ResultConceptT ResultConceptT;
7878 typedef BaseT::PassConceptT PassConceptT;
7979
109109 operator=(const CGSCCAnalysisManager &) LLVM_DELETED_FUNCTION;
110110
111111 /// \brief Get a function pass result, running the pass if necessary.
112 ResultConceptT &getResultImpl(void *PassID, LazyCallGraph::SCC *C);
112 ResultConceptT &getResultImpl(void *PassID, LazyCallGraph::SCC &C);
113113
114114 /// \brief Get a cached function pass result or return null.
115115 ResultConceptT *getCachedResultImpl(void *PassID,
116 LazyCallGraph::SCC *C) const;
116 LazyCallGraph::SCC &C) const;
117117
118118 /// \brief Invalidate a function pass result.
119 void invalidateImpl(void *PassID, LazyCallGraph::SCC *C);
119 void invalidateImpl(void *PassID, LazyCallGraph::SCC &C);
120120
121121 /// \brief Invalidate the results for a function..
122 void invalidateImpl(LazyCallGraph::SCC *C, const PreservedAnalyses &PA);
122 void invalidateImpl(LazyCallGraph::SCC &C, const PreservedAnalyses &PA);
123123
124124 /// \brief List of function analysis pass IDs and associated concept pointers.
125125 ///
128128 /// half of a bijection and provides storage for the actual result concept.
129129 typedef std::list<
130130 std::pair
131 LazyCallGraph::SCC *>>>> CGSCCAnalysisResultListT;
131 LazyCallGraph::SCC &>>>> CGSCCAnalysisResultListT;
132132
133133 /// \brief Map type from function pointer to our custom list type.
134134 typedef DenseMap
186186 /// Regardless of whether this analysis is marked as preserved, all of the
187187 /// analyses in the \c CGSCCAnalysisManager are potentially invalidated
188188 /// based on the set of preserved analyses.
189 bool invalidate(Module *M, const PreservedAnalyses &PA);
189 bool invalidate(Module &M, const PreservedAnalyses &PA);
190190
191191 private:
192192 CGSCCAnalysisManager *CGAM;
218218 /// In debug builds, it will also assert that the analysis manager is empty
219219 /// as no queries should arrive at the CGSCC analysis manager prior to
220220 /// this analysis being requested.
221 Result run(Module *M);
221 Result run(Module &M);
222222
223223 private:
224224 static char PassID;
256256 const ModuleAnalysisManager &getManager() const { return *MAM; }
257257
258258 /// \brief Handle invalidation by ignoring it, this pass is immutable.
259 bool invalidate(LazyCallGraph::SCC *) { return false; }
259 bool invalidate(LazyCallGraph::SCC &) { return false; }
260260
261261 private:
262262 const ModuleAnalysisManager *MAM;
282282 /// \brief Run the analysis pass and create our proxy result object.
283283 /// Nothing to see here, it just forwards the \c MAM reference into the
284284 /// result.
285 Result run(LazyCallGraph::SCC *) { return Result(*MAM); }
285 Result run(LazyCallGraph::SCC &) { return Result(*MAM); }
286286
287287 private:
288288 static char PassID;
322322 }
323323
324324 /// \brief Runs the CGSCC pass across every SCC in the module.
325 PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM) {
325 PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) {
326326 assert(AM && "We need analyses to compute the call graph!");
327327
328328 // Setup the CGSCC analysis manager from its proxy.
334334
335335 PreservedAnalyses PA = PreservedAnalyses::all();
336336 for (LazyCallGraph::SCC &C : CG.postorder_sccs()) {
337 PreservedAnalyses PassPA = Pass.run(&C, &CGAM);
337 PreservedAnalyses PassPA = Pass.run(C, &CGAM);
338338
339339 // We know that the CGSCC pass couldn't have invalidated any other
340340 // SCC's analyses (that's the contract of a CGSCC pass), so
342342 // FIXME: This isn't quite correct. We need to handle the case where the
343343 // pass updated the CG, particularly some child of the current SCC, and
344344 // invalidate its analyses.
345 CGAM.invalidate(&C, PassPA);
345 CGAM.invalidate(C, PassPA);
346346
347347 // Then intersect the preserved set so that invalidation of module
348348 // analyses will eventually occur when the module pass completes.
408408 /// Regardless of whether this analysis is marked as preserved, all of the
409409 /// analyses in the \c FunctionAnalysisManager are potentially invalidated
410410 /// based on the set of preserved analyses.
411 bool invalidate(LazyCallGraph::SCC *C, const PreservedAnalyses &PA);
411 bool invalidate(LazyCallGraph::SCC &C, const PreservedAnalyses &PA);
412412
413413 private:
414414 FunctionAnalysisManager *FAM;
440440 /// In debug builds, it will also assert that the analysis manager is empty
441441 /// as no queries should arrive at the function analysis manager prior to
442442 /// this analysis being requested.
443 Result run(LazyCallGraph::SCC *C);
443 Result run(LazyCallGraph::SCC &C);
444444
445445 private:
446446 static char PassID;
478478 const CGSCCAnalysisManager &getManager() const { return *CGAM; }
479479
480480 /// \brief Handle invalidation by ignoring it, this pass is immutable.
481 bool invalidate(Function *) { return false; }
481 bool invalidate(Function &) { return false; }
482482
483483 private:
484484 const CGSCCAnalysisManager *CGAM;
504504 /// \brief Run the analysis pass and create our proxy result object.
505505 /// Nothing to see here, it just forwards the \c CGAM reference into the
506506 /// result.
507 Result run(Function *) { return Result(*CGAM); }
507 Result run(Function &) { return Result(*CGAM); }
508508
509509 private:
510510 static char PassID;
540540 }
541541
542542 /// \brief Runs the function pass across every function in the module.
543 PreservedAnalyses run(LazyCallGraph::SCC *C, CGSCCAnalysisManager *AM) {
543 PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager *AM) {
544544 FunctionAnalysisManager *FAM = nullptr;
545545 if (AM)
546546 // Setup the function analysis manager from its proxy.
547547 FAM = &AM->getResult(C).getManager();
548548
549549 PreservedAnalyses PA = PreservedAnalyses::all();
550 for (LazyCallGraph::Node *N : *C) {
551 PreservedAnalyses PassPA = Pass.run(&N->getFunction(), FAM);
550 for (LazyCallGraph::Node *N : C) {
551 PreservedAnalyses PassPA = Pass.run(N->getFunction(), FAM);
552552
553553 // We know that the function pass couldn't have invalidated any other
554554 // function's analyses (that's the contract of a function pass), so
555555 // directly handle the function analysis manager's invalidation here.
556556 if (FAM)
557 FAM->invalidate(&N->getFunction(), PassPA);
557 FAM->invalidate(N->getFunction(), PassPA);
558558
559559 // Then intersect the preserved set so that invalidation of module
560560 // analyses will eventually occur when the module pass completes.
540540 ///
541541 /// This just builds the set of entry points to the call graph. The rest is
542542 /// built lazily as it is walked.
543 LazyCallGraph run(Module *M) { return LazyCallGraph(*M); }
543 LazyCallGraph run(Module &M) { return LazyCallGraph(M); }
544544
545545 private:
546546 static char PassID;
555555 public:
556556 explicit LazyCallGraphPrinterPass(raw_ostream &OS);
557557
558 PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM);
558 PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM);
559559
560560 static StringRef name() { return "LazyCallGraphPrinterPass"; }
561561 };
4040
4141 /// \brief Run the bitcode writer pass, and output the module to the selected
4242 /// output stream.
43 PreservedAnalyses run(Module *M);
43 PreservedAnalyses run(Module &M);
4444
4545 static StringRef name() { return "BitcodeWriterPass"; }
4646 };
5757 PrintModulePass();
5858 PrintModulePass(raw_ostream &OS, const std::string &Banner = "");
5959
60 PreservedAnalyses run(Module *M);
60 PreservedAnalyses run(Module &M);
6161
6262 static StringRef name() { return "PrintModulePass"; }
6363 };
7474 PrintFunctionPass();
7575 PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
7676
77 PreservedAnalyses run(Function *F);
77 PreservedAnalyses run(Function &F);
7878
7979 static StringRef name() { return "PrintFunctionPass"; }
8080 };
185185 ///
186186 /// This method should only be called for a single module as there is the
187187 /// expectation that the lifetime of a pass is bounded to that of a module.
188 PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM = nullptr);
188 PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM = nullptr);
189189
190190 template void addPass(ModulePassT Pass) {
191191 Passes.emplace_back(new ModulePassModel(std::move(Pass)));
195195
196196 private:
197197 // Pull in the concept type and model template specialized for modules.
198 typedef detail::PassConcept*, ModuleAnalysisManager>
198 typedef detail::PassConcept&, ModuleAnalysisManager>
199199 ModulePassConcept;
200200 template
201201 struct ModulePassModel
202 : detail::PassModel*, ModuleAnalysisManager, PassT> {
202 : detail::PassModel&, ModuleAnalysisManager, PassT> {
203203 ModulePassModel(PassT Pass)
204 : detail::PassModel*, ModuleAnalysisManager, PassT>(
204 : detail::PassModel&, ModuleAnalysisManager, PassT>(
205205 std::move(Pass)) {}
206206 };
207207
254254 Passes.emplace_back(new FunctionPassModel(std::move(Pass)));
255255 }
256256
257 PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM = nullptr);
257 PreservedAnalyses run(Function &F, FunctionAnalysisManager *AM = nullptr);
258258
259259 static StringRef name() { return "FunctionPassManager"; }
260260
261261 private:
262262 // Pull in the concept type and model template specialized for functions.
263 typedef detail::PassConcept*, FunctionAnalysisManager>
263 typedef detail::PassConcept&, FunctionAnalysisManager>
264264 FunctionPassConcept;
265265 template
266266 struct FunctionPassModel
267 : detail::PassModel*, FunctionAnalysisManager, PassT> {
267 : detail::PassModel&, FunctionAnalysisManager, PassT> {
268268 FunctionPassModel(PassT Pass)
269 : detail::PassModel*, FunctionAnalysisManager, PassT>(
269 : detail::PassModel&, FunctionAnalysisManager, PassT>(
270270 std::move(Pass)) {}
271271 };
272272
368368 /// \brief Invalidate a specific analysis pass for an IR module.
369369 ///
370370 /// Note that the analysis result can disregard invalidation.
371 template void invalidate(Module *M) {
371 template void invalidate(Module &M) {
372372 assert(AnalysisPasses.count(PassT::ID()) &&
373373 "This analysis pass was not registered prior to being invalidated");
374374 derived_this()->invalidateImpl(PassT::ID(), M);
412412 /// \brief A module analysis pass manager with lazy running and caching of
413413 /// results.
414414 class ModuleAnalysisManager
415 : public detail::AnalysisManagerBase {
416 friend class detail::AnalysisManagerBase;
417 typedef detail::AnalysisManagerBase BaseT;
415 : public detail::AnalysisManagerBase {
416 friend class detail::AnalysisManagerBase;
417 typedef detail::AnalysisManagerBase BaseT;
418418 typedef BaseT::ResultConceptT ResultConceptT;
419419 typedef BaseT::PassConceptT PassConceptT;
420420
437437 operator=(const ModuleAnalysisManager &) LLVM_DELETED_FUNCTION;
438438
439439 /// \brief Get a module pass result, running the pass if necessary.
440 ResultConceptT &getResultImpl(void *PassID, Module *M);
440 ResultConceptT &getResultImpl(void *PassID, Module &M);
441441
442442 /// \brief Get a cached module pass result or return null.
443 ResultConceptT *getCachedResultImpl(void *PassID, Module *M) const;
443 ResultConceptT *getCachedResultImpl(void *PassID, Module &M) const;
444444
445445 /// \brief Invalidate a module pass result.
446 void invalidateImpl(void *PassID, Module *M);
446 void invalidateImpl(void *PassID, Module &M);
447447
448448 /// \brief Invalidate results across a module.
449 void invalidateImpl(Module *M, const PreservedAnalyses &PA);
449 void invalidateImpl(Module &M, const PreservedAnalyses &PA);
450450
451451 /// \brief Map type from module analysis pass ID to pass result concept
452452 /// pointer.
453453 typedef DenseMap
454 std::unique_ptr*>>>
454 std::unique_ptr&>>>
455455 ModuleAnalysisResultMapT;
456456
457457 /// \brief Cache of computed module analysis results for this module.
461461 /// \brief A function analysis manager to coordinate and cache analyses run over
462462 /// a module.
463463 class FunctionAnalysisManager
464 : public detail::AnalysisManagerBase {
465 friend class detail::AnalysisManagerBase;
466 typedef detail::AnalysisManagerBase
464 : public detail::AnalysisManagerBase {
465 friend class detail::AnalysisManagerBase;
466 typedef detail::AnalysisManagerBase
467467 BaseT;
468468 typedef BaseT::ResultConceptT ResultConceptT;
469469 typedef BaseT::PassConceptT PassConceptT;
501501 operator=(const FunctionAnalysisManager &) LLVM_DELETED_FUNCTION;
502502
503503 /// \brief Get a function pass result, running the pass if necessary.
504 ResultConceptT &getResultImpl(void *PassID, Function *F);
504 ResultConceptT &getResultImpl(void *PassID, Function &F);
505505
506506 /// \brief Get a cached function pass result or return null.
507 ResultConceptT *getCachedResultImpl(void *PassID, Function *F) const;
507 ResultConceptT *getCachedResultImpl(void *PassID, Function &F) const;
508508
509509 /// \brief Invalidate a function pass result.
510 void invalidateImpl(void *PassID, Function *F);
510 void invalidateImpl(void *PassID, Function &F);
511511
512512 /// \brief Invalidate the results for a function..
513 void invalidateImpl(Function *F, const PreservedAnalyses &PA);
513 void invalidateImpl(Function &F, const PreservedAnalyses &PA);
514514
515515 /// \brief List of function analysis pass IDs and associated concept pointers.
516516 ///
518518 /// erases. Provides both the pass ID and concept pointer such that it is
519519 /// half of a bijection and provides storage for the actual result concept.
520520 typedef std::list
521 void *, std::unique_ptr*>>>>
521 void *, std::unique_ptr&>>>>
522522 FunctionAnalysisResultListT;
523523
524524 /// \brief Map type from function pointer to our custom list type.
580580 /// In debug builds, it will also assert that the analysis manager is empty
581581 /// as no queries should arrive at the function analysis manager prior to
582582 /// this analysis being requested.
583 Result run(Module *M);
583 Result run(Module &M);
584584
585585 private:
586586 static char PassID;
618618 /// Regardless of whether this analysis is marked as preserved, all of the
619619 /// analyses in the \c FunctionAnalysisManager are potentially invalidated
620620 /// based on the set of preserved analyses.
621 bool invalidate(Module *M, const PreservedAnalyses &PA);
621 bool invalidate(Module &M, const PreservedAnalyses &PA);
622622
623623 private:
624624 FunctionAnalysisManager *FAM;
654654 const ModuleAnalysisManager &getManager() const { return *MAM; }
655655
656656 /// \brief Handle invalidation by ignoring it, this pass is immutable.
657 bool invalidate(Function *) { return false; }
657 bool invalidate(Function &) { return false; }
658658
659659 private:
660660 const ModuleAnalysisManager *MAM;
680680 /// \brief Run the analysis pass and create our proxy result object.
681681 /// Nothing to see here, it just forwards the \c MAM reference into the
682682 /// result.
683 Result run(Function *) { return Result(*MAM); }
683 Result run(Function &) { return Result(*MAM); }
684684
685685 private:
686686 static char PassID;
717717 }
718718
719719 /// \brief Runs the function pass across every function in the module.
720 PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM) {
720 PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) {
721721 FunctionAnalysisManager *FAM = nullptr;
722722 if (AM)
723723 // Setup the function analysis manager from its proxy.
724724 FAM = &AM->getResult(M).getManager();
725725
726726 PreservedAnalyses PA = PreservedAnalyses::all();
727 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {
728 PreservedAnalyses PassPA = Pass.run(I, FAM);
727 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
728 PreservedAnalyses PassPA = Pass.run(*I, FAM);
729729
730730 // We know that the function pass couldn't have invalidated any other
731731 // function's analyses (that's the contract of a function pass), so
732732 // directly handle the function analysis manager's invalidation here.
733733 if (FAM)
734 FAM->invalidate(I, PassPA);
734 FAM->invalidate(*I, PassPA);
735735
736736 // Then intersect the preserved set so that invalidation of module
737737 // analyses will eventually occur when the module pass completes.
7676 public:
7777 explicit VerifierPass(bool FatalErrors = true) : FatalErrors(FatalErrors) {}
7878
79 PreservedAnalyses run(Module *M);
80 PreservedAnalyses run(Function *F);
79 PreservedAnalyses run(Module &M);
80 PreservedAnalyses run(Function &F);
8181
8282 static StringRef name() { return "VerifierPass"; }
8383 };
1616 DebugPM("debug-cgscc-pass-manager", cl::Hidden,
1717 cl::desc("Print CGSCC pass management debugging information"));
1818
19 PreservedAnalyses CGSCCPassManager::run(LazyCallGraph::SCC *C,
19 PreservedAnalyses CGSCCPassManager::run(LazyCallGraph::SCC &C,
2020 CGSCCAnalysisManager *AM) {
2121 PreservedAnalyses PA = PreservedAnalyses::all();
2222
5252 }
5353
5454 CGSCCAnalysisManager::ResultConceptT &
55 CGSCCAnalysisManager::getResultImpl(void *PassID, LazyCallGraph::SCC *C) {
55 CGSCCAnalysisManager::getResultImpl(void *PassID, LazyCallGraph::SCC &C) {
5656 CGSCCAnalysisResultMapT::iterator RI;
5757 bool Inserted;
5858 std::tie(RI, Inserted) = CGSCCAnalysisResults.insert(std::make_pair(
59 std::make_pair(PassID, C), CGSCCAnalysisResultListT::iterator()));
59 std::make_pair(PassID, &C), CGSCCAnalysisResultListT::iterator()));
6060
6161 // If we don't have a cached result for this function, look up the pass and
6262 // run it to produce a result, which we then add to the cache.
6363 if (Inserted) {
64 CGSCCAnalysisResultListT &ResultList = CGSCCAnalysisResultLists[C];
64 CGSCCAnalysisResultListT &ResultList = CGSCCAnalysisResultLists[&C];
6565 ResultList.emplace_back(PassID, lookupPass(PassID).run(C, this));
6666 RI->second = std::prev(ResultList.end());
6767 }
7171
7272 CGSCCAnalysisManager::ResultConceptT *
7373 CGSCCAnalysisManager::getCachedResultImpl(void *PassID,
74 LazyCallGraph::SCC *C) const {
74 LazyCallGraph::SCC &C) const {
7575 CGSCCAnalysisResultMapT::const_iterator RI =
76 CGSCCAnalysisResults.find(std::make_pair(PassID, C));
76 CGSCCAnalysisResults.find(std::make_pair(PassID, &C));
7777 return RI == CGSCCAnalysisResults.end() ? nullptr : &*RI->second->second;
7878 }
7979
80 void CGSCCAnalysisManager::invalidateImpl(void *PassID, LazyCallGraph::SCC *C) {
80 void CGSCCAnalysisManager::invalidateImpl(void *PassID, LazyCallGraph::SCC &C) {
8181 CGSCCAnalysisResultMapT::iterator RI =
82 CGSCCAnalysisResults.find(std::make_pair(PassID, C));
82 CGSCCAnalysisResults.find(std::make_pair(PassID, &C));
8383 if (RI == CGSCCAnalysisResults.end())
8484 return;
8585
86 CGSCCAnalysisResultLists[C].erase(RI->second);
86 CGSCCAnalysisResultLists[&C].erase(RI->second);
8787 }
8888
89 void CGSCCAnalysisManager::invalidateImpl(LazyCallGraph::SCC *C,
89 void CGSCCAnalysisManager::invalidateImpl(LazyCallGraph::SCC &C,
9090 const PreservedAnalyses &PA) {
9191 // Clear all the invalidated results associated specifically with this
9292 // function.
9393 SmallVector InvalidatedPassIDs;
94 CGSCCAnalysisResultListT &ResultsList = CGSCCAnalysisResultLists[C];
94 CGSCCAnalysisResultListT &ResultsList = CGSCCAnalysisResultLists[&C];
9595 for (CGSCCAnalysisResultListT::iterator I = ResultsList.begin(),
9696 E = ResultsList.end();
9797 I != E;)
103103 }
104104 while (!InvalidatedPassIDs.empty())
105105 CGSCCAnalysisResults.erase(
106 std::make_pair(InvalidatedPassIDs.pop_back_val(), C));
107 CGSCCAnalysisResultLists.erase(C);
106 std::make_pair(InvalidatedPassIDs.pop_back_val(), &C));
107 CGSCCAnalysisResultLists.erase(&C);
108108 }
109109
110110 char CGSCCAnalysisManagerModuleProxy::PassID;
111111
112112 CGSCCAnalysisManagerModuleProxy::Result
113 CGSCCAnalysisManagerModuleProxy::run(Module *M) {
113 CGSCCAnalysisManagerModuleProxy::run(Module &M) {
114114 assert(CGAM->empty() && "CGSCC analyses ran prior to the module proxy!");
115115 return Result(*CGAM);
116116 }
122122 }
123123
124124 bool CGSCCAnalysisManagerModuleProxy::Result::invalidate(
125 Module *M, const PreservedAnalyses &PA) {
125 Module &M, const PreservedAnalyses &PA) {
126126 // If this proxy isn't marked as preserved, then we can't even invalidate
127127 // individual CGSCC analyses, there may be an invalid set of SCC objects in
128128 // the cache making it impossible to incrementally preserve them.
139139 char FunctionAnalysisManagerCGSCCProxy::PassID;
140140
141141 FunctionAnalysisManagerCGSCCProxy::Result
142 FunctionAnalysisManagerCGSCCProxy::run(LazyCallGraph::SCC *C) {
142 FunctionAnalysisManagerCGSCCProxy::run(LazyCallGraph::SCC &C) {
143143 assert(FAM->empty() && "Function analyses ran prior to the CGSCC proxy!");
144144 return Result(*FAM);
145145 }
151151 }
152152
153153 bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate(
154 LazyCallGraph::SCC *C, const PreservedAnalyses &PA) {
154 LazyCallGraph::SCC &C, const PreservedAnalyses &PA) {
155155 // If this proxy isn't marked as preserved, then we can't even invalidate
156156 // individual function analyses, there may be an invalid set of Function
157157 // objects in the cache making it impossible to incrementally preserve them.
707707 OS << "\n";
708708 }
709709
710 PreservedAnalyses LazyCallGraphPrinterPass::run(Module *M,
710 PreservedAnalyses LazyCallGraphPrinterPass::run(Module &M,
711711 ModuleAnalysisManager *AM) {
712712 LazyCallGraph &G = AM->getResult(M);
713713
714 OS << "Printing the call graph for module: " << M->getModuleIdentifier()
714 OS << "Printing the call graph for module: " << M.getModuleIdentifier()
715715 << "\n\n";
716716
717717 SmallPtrSet Printed;
723723 printSCC(OS, SCC);
724724
725725 return PreservedAnalyses::all();
726
727 }
726 }
1717 #include "llvm/Pass.h"
1818 using namespace llvm;
1919
20 PreservedAnalyses BitcodeWriterPass::run(Module *M) {
21 WriteBitcodeToFile(M, OS);
20 PreservedAnalyses BitcodeWriterPass::run(Module &M) {
21 WriteBitcodeToFile(&M, OS);
2222 return PreservedAnalyses::all();
2323 }
2424
2323 PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner)
2424 : OS(OS), Banner(Banner) {}
2525
26 PreservedAnalyses PrintModulePass::run(Module *M) {
27 OS << Banner << *M;
26 PreservedAnalyses PrintModulePass::run(Module &M) {
27 OS << Banner << M;
2828 return PreservedAnalyses::all();
2929 }
3030
3232 PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, const std::string &Banner)
3333 : OS(OS), Banner(Banner) {}
3434
35 PreservedAnalyses PrintFunctionPass::run(Function *F) {
36 OS << Banner << static_cast(*F);
35 PreservedAnalyses PrintFunctionPass::run(Function &F) {
36 OS << Banner << static_cast(F);
3737 return PreservedAnalyses::all();
3838 }
3939
4949 : ModulePass(ID), P(OS, Banner) {}
5050
5151 bool runOnModule(Module &M) override {
52 P.run(&M);
52 P.run(M);
5353 return false;
5454 }
5555
6969
7070 // This pass just prints a banner followed by the function as it's processed.
7171 bool runOnFunction(Function &F) override {
72 P.run(&F);
72 P.run(F);
7373 return false;
7474 }
7575
1818 DebugPM("debug-pass-manager", cl::Hidden,
1919 cl::desc("Print pass management debugging information"));
2020
21 PreservedAnalyses ModulePassManager::run(Module *M, ModuleAnalysisManager *AM) {
21 PreservedAnalyses ModulePassManager::run(Module &M, ModuleAnalysisManager *AM) {
2222 PreservedAnalyses PA = PreservedAnalyses::all();
2323
2424 if (DebugPM)
3333 AM->invalidate(M, PassPA);
3434 PA.intersect(std::move(PassPA));
3535
36 M->getContext().yield();
36 M.getContext().yield();
3737 }
3838
3939 if (DebugPM)
4343 }
4444
4545 ModuleAnalysisManager::ResultConceptT &
46 ModuleAnalysisManager::getResultImpl(void *PassID, Module *M) {
46 ModuleAnalysisManager::getResultImpl(void *PassID, Module &M) {
4747 ModuleAnalysisResultMapT::iterator RI;
4848 bool Inserted;
4949 std::tie(RI, Inserted) = ModuleAnalysisResults.insert(std::make_pair(
50 PassID, std::unique_ptr*>>()));
50 PassID, std::unique_ptr&>>()));
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.
5858 }
5959
6060 ModuleAnalysisManager::ResultConceptT *
61 ModuleAnalysisManager::getCachedResultImpl(void *PassID, Module *M) const {
61 ModuleAnalysisManager::getCachedResultImpl(void *PassID, Module &M) const {
6262 ModuleAnalysisResultMapT::const_iterator RI =
6363 ModuleAnalysisResults.find(PassID);
6464 return RI == ModuleAnalysisResults.end() ? nullptr : &*RI->second;
6565 }
6666
67 void ModuleAnalysisManager::invalidateImpl(void *PassID, Module *M) {
67 void ModuleAnalysisManager::invalidateImpl(void *PassID, Module &M) {
6868 ModuleAnalysisResults.erase(PassID);
6969 }
7070
71 void ModuleAnalysisManager::invalidateImpl(Module *M,
71 void ModuleAnalysisManager::invalidateImpl(Module &M,
7272 const PreservedAnalyses &PA) {
7373 // FIXME: This is a total hack based on the fact that erasure doesn't
7474 // invalidate iteration for DenseMap.
7979 ModuleAnalysisResults.erase(I);
8080 }
8181
82 PreservedAnalyses FunctionPassManager::run(Function *F,
82 PreservedAnalyses FunctionPassManager::run(Function &F,
8383 FunctionAnalysisManager *AM) {
8484 PreservedAnalyses PA = PreservedAnalyses::all();
8585
9595 AM->invalidate(F, PassPA);
9696 PA.intersect(std::move(PassPA));
9797
98 F->getContext().yield();
98 F.getContext().yield();
9999 }
100100
101101 if (DebugPM)
118118 }
119119
120120 FunctionAnalysisManager::ResultConceptT &
121 FunctionAnalysisManager::getResultImpl(void *PassID, Function *F) {
121 FunctionAnalysisManager::getResultImpl(void *PassID, Function &F) {
122122 FunctionAnalysisResultMapT::iterator RI;
123123 bool Inserted;
124124 std::tie(RI, Inserted) = FunctionAnalysisResults.insert(std::make_pair(
125 std::make_pair(PassID, F), FunctionAnalysisResultListT::iterator()));
125 std::make_pair(PassID, &F), FunctionAnalysisResultListT::iterator()));
126126
127127 // If we don't have a cached result for this function, look up the pass and
128128 // run it to produce a result, which we then add to the cache.
129129 if (Inserted) {
130 FunctionAnalysisResultListT &ResultList = FunctionAnalysisResultLists[F];
130 FunctionAnalysisResultListT &ResultList = FunctionAnalysisResultLists[&F];
131131 ResultList.emplace_back(PassID, lookupPass(PassID).run(F, this));
132132 RI->second = std::prev(ResultList.end());
133133 }
136136 }
137137
138138 FunctionAnalysisManager::ResultConceptT *
139 FunctionAnalysisManager::getCachedResultImpl(void *PassID, Function *F) const {
139 FunctionAnalysisManager::getCachedResultImpl(void *PassID, Function &F) const {
140140 FunctionAnalysisResultMapT::const_iterator RI =
141 FunctionAnalysisResults.find(std::make_pair(PassID, F));
141 FunctionAnalysisResults.find(std::make_pair(PassID, &F));
142142 return RI == FunctionAnalysisResults.end() ? nullptr : &*RI->second->second;
143143 }
144144
145 void FunctionAnalysisManager::invalidateImpl(void *PassID, Function *F) {
145 void FunctionAnalysisManager::invalidateImpl(void *PassID, Function &F) {
146146 FunctionAnalysisResultMapT::iterator RI =
147 FunctionAnalysisResults.find(std::make_pair(PassID, F));
147 FunctionAnalysisResults.find(std::make_pair(PassID, &F));
148148 if (RI == FunctionAnalysisResults.end())
149149 return;
150150
151 FunctionAnalysisResultLists[F].erase(RI->second);
152 }
153
154 void FunctionAnalysisManager::invalidateImpl(Function *F,
151 FunctionAnalysisResultLists[&F].erase(RI->second);
152 }
153
154 void FunctionAnalysisManager::invalidateImpl(Function &F,
155155 const PreservedAnalyses &PA) {
156156 // Clear all the invalidated results associated specifically with this
157157 // function.
158158 SmallVector InvalidatedPassIDs;
159 FunctionAnalysisResultListT &ResultsList = FunctionAnalysisResultLists[F];
159 FunctionAnalysisResultListT &ResultsList = FunctionAnalysisResultLists[&F];
160160 for (FunctionAnalysisResultListT::iterator I = ResultsList.begin(),
161161 E = ResultsList.end();
162162 I != E;)
168168 }
169169 while (!InvalidatedPassIDs.empty())
170170 FunctionAnalysisResults.erase(
171 std::make_pair(InvalidatedPassIDs.pop_back_val(), F));
171 std::make_pair(InvalidatedPassIDs.pop_back_val(), &F));
172172 if (ResultsList.empty())
173 FunctionAnalysisResultLists.erase(F);
173 FunctionAnalysisResultLists.erase(&F);
174174 }
175175
176176 char FunctionAnalysisManagerModuleProxy::PassID;
177177
178178 FunctionAnalysisManagerModuleProxy::Result
179 FunctionAnalysisManagerModuleProxy::run(Module *M) {
179 FunctionAnalysisManagerModuleProxy::run(Module &M) {
180180 assert(FAM->empty() && "Function analyses ran prior to the module proxy!");
181181 return Result(*FAM);
182182 }
188188 }
189189
190190 bool FunctionAnalysisManagerModuleProxy::Result::invalidate(
191 Module *M, const PreservedAnalyses &PA) {
191 Module &M, const PreservedAnalyses &PA) {
192192 // If this proxy isn't marked as preserved, then we can't even invalidate
193193 // individual function analyses, there may be an invalid set of Function
194194 // objects in the cache making it impossible to incrementally preserve them.
29012901 return new DebugInfoVerifierLegacyPass(FatalErrors);
29022902 }
29032903
2904 PreservedAnalyses VerifierPass::run(Module *M) {
2905 if (verifyModule(*M, &dbgs()) && FatalErrors)
2904 PreservedAnalyses VerifierPass::run(Module &M) {
2905 if (verifyModule(M, &dbgs()) && FatalErrors)
29062906 report_fatal_error("Broken module found, compilation aborted!");
29072907
29082908 return PreservedAnalyses::all();
29092909 }
29102910
2911 PreservedAnalyses VerifierPass::run(Function *F) {
2912 if (verifyFunction(*F, &dbgs()) && FatalErrors)
2911 PreservedAnalyses VerifierPass::run(Function &F) {
2912 if (verifyFunction(F, &dbgs()) && FatalErrors)
29132913 report_fatal_error("Broken function found, compilation aborted!");
29142914
29152915 return PreservedAnalyses::all();
8585 cl::PrintOptionValues();
8686
8787 // Now that we have all of the passes ready, run them.
88 MPM.run(&M, &MAM);
88 MPM.run(M, &MAM);
8989
9090 // Declare success.
9191 if (OK != OK_NoOutput)
2727
2828 /// \brief No-op module pass which does nothing.
2929 struct NoOpModulePass {
30 PreservedAnalyses run(Module *M) { return PreservedAnalyses::all(); }
30 PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); }
3131 static StringRef name() { return "NoOpModulePass"; }
3232 };
3333
3434 /// \brief No-op CGSCC pass which does nothing.
3535 struct NoOpCGSCCPass {
36 PreservedAnalyses run(LazyCallGraph::SCC *C) {
36 PreservedAnalyses run(LazyCallGraph::SCC &C) {
3737 return PreservedAnalyses::all();
3838 }
3939 static StringRef name() { return "NoOpCGSCCPass"; }
4141
4242 /// \brief No-op function pass which does nothing.
4343 struct NoOpFunctionPass {
44 PreservedAnalyses run(Function *F) { return PreservedAnalyses::all(); }
44 PreservedAnalyses run(Function &F) { return PreservedAnalyses::all(); }
4545 static StringRef name() { return "NoOpFunctionPass"; }
4646 };
4747
3131 TestFunctionAnalysis(int &Runs) : Runs(Runs) {}
3232
3333 /// \brief Run the analysis pass over the function and return a result.
34 Result run(Function *F, FunctionAnalysisManager *AM) {
34 Result run(Function &F, FunctionAnalysisManager *AM) {
3535 ++Runs;
3636 int Count = 0;
37 for (Function::iterator BBI = F->begin(), BBE = F->end(); BBI != BBE; ++BBI)
37 for (Function::iterator BBI = F.begin(), BBE = F.end(); BBI != BBE; ++BBI)
3838 for (BasicBlock::iterator II = BBI->begin(), IE = BBI->end(); II != IE;
3939 ++II)
4040 ++Count;
6161
6262 TestModuleAnalysis(int &Runs) : Runs(Runs) {}
6363
64 Result run(Module *M, ModuleAnalysisManager *AM) {
64 Result run(Module &M, ModuleAnalysisManager *AM) {
6565 ++Runs;
6666 int Count = 0;
67 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
67 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
6868 ++Count;
6969 return Result(Count);
7070 }
8080 struct TestModulePass {
8181 TestModulePass(int &RunCount) : RunCount(RunCount) {}
8282
83 PreservedAnalyses run(Module *M) {
83 PreservedAnalyses run(Module &M) {
8484 ++RunCount;
8585 return PreservedAnalyses::none();
8686 }
9191 };
9292
9393 struct TestPreservingModulePass {
94 PreservedAnalyses run(Module *M) { return PreservedAnalyses::all(); }
94 PreservedAnalyses run(Module &M) { return PreservedAnalyses::all(); }
9595
9696 static StringRef name() { return "TestPreservingModulePass"; }
9797 };
9898
9999 struct TestMinPreservingModulePass {
100 PreservedAnalyses run(Module *M, ModuleAnalysisManager *AM) {
100 PreservedAnalyses run(Module &M, ModuleAnalysisManager *AM) {
101101 PreservedAnalyses PA;
102102
103103 // Force running an analysis.
118118 AnalyzedFunctionCount(AnalyzedFunctionCount),
119119 OnlyUseCachedResults(OnlyUseCachedResults) {}
120120
121 PreservedAnalyses run(Function *F, FunctionAnalysisManager *AM) {
121 PreservedAnalyses run(Function &F, FunctionAnalysisManager *AM) {
122122 ++RunCount;
123123
124124 const ModuleAnalysisManager &MAM =
125125 AM->getResult(F).getManager();
126126 if (TestModuleAnalysis::Result *TMA =
127 MAM.getCachedResult(F->getParent()))
127 MAM.getCachedResult(*F.getParent()))
128128 AnalyzedFunctionCount += TMA->FunctionCount;
129129
130130 if (OnlyUseCachedResults) {
154154 struct TestInvalidationFunctionPass {
155155 TestInvalidationFunctionPass(StringRef FunctionName) : Name(FunctionName) {}
156156
157 PreservedAnalyses run(Function *F) {
158 return F->getName() == Name ? PreservedAnalyses::none()
159 : PreservedAnalyses::all();
157 PreservedAnalyses run(Function &F) {
158 return F.getName() == Name ? PreservedAnalyses::none()
159 : PreservedAnalyses::all();
160160 }
161161
162162 static StringRef name() { return "TestInvalidationFunctionPass"; }
164164 StringRef Name;
165165 };
166166
167 Module *parseIR(const char *IR) {
167 std::unique_ptr parseIR(const char *IR) {
168168 LLVMContext &C = getGlobalContext();
169169 SMDiagnostic Err;
170 return parseAssemblyString(IR, Err, C).release();
170 return parseAssemblyString(IR, Err, C);
171171 }
172172
173173 class PassManagerTest : public ::testing::Test {
309309 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
310310 }
311311
312 MPM.run(M.get(), &MAM);
312 MPM.run(*M, &MAM);
313313
314314 // Validate module pass counters.
315315 EXPECT_EQ(1, ModulePassRunCount);