1 //===- PassManager.cpp - Infrastructure for managing & running IR passes --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/IR/LLVMContext.h"
12 #include "llvm/IR/PassManager.h"
15 using llvm::detail::DebugPM;
17 cl::opt<bool> llvm::detail::DebugPM(
18 "debug-pass-manager", cl::Hidden,
19 cl::desc("Print pass management debugging information"));
21 PreservedAnalyses ModulePassManager::run(Module &M, ModuleAnalysisManager *AM) {
22 PreservedAnalyses PA = PreservedAnalyses::all();
25 dbgs() << "Starting module pass manager run.\n";
27 for (unsigned Idx = 0, Size = Passes.size(); Idx != Size; ++Idx) {
29 dbgs() << "Running module pass: " << Passes[Idx]->name() << "\n";
31 PreservedAnalyses PassPA = Passes[Idx]->run(M, AM);
33 // If we have an active analysis manager at this level we want to ensure we
34 // update it as each pass runs and potentially invalidates analyses. We
35 // also update the preserved set of analyses based on what analyses we have
36 // already handled the invalidation for here and don't need to invalidate
39 PassPA = AM->invalidate(M, std::move(PassPA));
41 // Finally, we intersect the final preserved analyses to compute the
42 // aggregate preserved set for this pass manager.
43 PA.intersect(std::move(PassPA));
45 M.getContext().yield();
49 dbgs() << "Finished module pass manager run.\n";
54 PreservedAnalyses FunctionPassManager::run(Function &F,
55 FunctionAnalysisManager *AM) {
56 PreservedAnalyses PA = PreservedAnalyses::all();
59 dbgs() << "Starting function pass manager run.\n";
61 for (unsigned Idx = 0, Size = Passes.size(); Idx != Size; ++Idx) {
63 dbgs() << "Running function pass: " << Passes[Idx]->name() << "\n";
65 PreservedAnalyses PassPA = Passes[Idx]->run(F, AM);
67 // If we have an active analysis manager at this level we want to ensure we
68 // update it as each pass runs and potentially invalidates analyses. We
69 // also update the preserved set of analyses based on what analyses we have
70 // already handled the invalidation for here and don't need to invalidate
73 PassPA = AM->invalidate(F, std::move(PassPA));
75 // Finally, we intersect the final preserved analyses to compute the
76 // aggregate preserved set for this pass manager.
77 PA.intersect(std::move(PassPA));
79 F.getContext().yield();
83 dbgs() << "Finished function pass manager run.\n";
88 char FunctionAnalysisManagerModuleProxy::PassID;
90 FunctionAnalysisManagerModuleProxy::Result
91 FunctionAnalysisManagerModuleProxy::run(Module &M) {
92 assert(FAM->empty() && "Function analyses ran prior to the module proxy!");
96 FunctionAnalysisManagerModuleProxy::Result::~Result() {
97 // Clear out the analysis manager if we're being destroyed -- it means we
98 // didn't even see an invalidate call when we got invalidated.
102 bool FunctionAnalysisManagerModuleProxy::Result::invalidate(
103 Module &M, const PreservedAnalyses &PA) {
104 // If this proxy isn't marked as preserved, then we can't even invalidate
105 // individual function analyses, there may be an invalid set of Function
106 // objects in the cache making it impossible to incrementally preserve them.
107 // Just clear the entire manager.
108 if (!PA.preserved(ID()))
111 // Return false to indicate that this result is still a valid proxy.
115 char ModuleAnalysisManagerFunctionProxy::PassID;