[PM] Fold all three analysis managers into a single AnalysisManager
[oota-llvm.git] / lib / Analysis / CGSCCPassManager.cpp
1 //===- CGSCCPassManager.cpp - Managing & running CGSCC passes -------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/Analysis/CGSCCPassManager.h"
11 #include "llvm/Support/CommandLine.h"
12 #include "llvm/Support/Debug.h"
13
14 using namespace llvm;
15
16 static cl::opt<bool>
17     DebugPM("debug-cgscc-pass-manager", cl::Hidden,
18             cl::desc("Print CGSCC pass management debugging information"));
19
20 PreservedAnalyses CGSCCPassManager::run(LazyCallGraph::SCC &C,
21                                         CGSCCAnalysisManager *AM) {
22   PreservedAnalyses PA = PreservedAnalyses::all();
23
24   if (DebugPM)
25     dbgs() << "Starting CGSCC pass manager run.\n";
26
27   for (unsigned Idx = 0, Size = Passes.size(); Idx != Size; ++Idx) {
28     if (DebugPM)
29       dbgs() << "Running CGSCC pass: " << Passes[Idx]->name() << "\n";
30
31     PreservedAnalyses PassPA = Passes[Idx]->run(C, AM);
32
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
37     // when finished.
38     if (AM)
39       PassPA = AM->invalidate(C, std::move(PassPA));
40
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));
44   }
45
46   if (DebugPM)
47     dbgs() << "Finished CGSCC pass manager run.\n";
48
49   return PA;
50 }
51
52 char CGSCCAnalysisManagerModuleProxy::PassID;
53
54 CGSCCAnalysisManagerModuleProxy::Result
55 CGSCCAnalysisManagerModuleProxy::run(Module &M) {
56   assert(CGAM->empty() && "CGSCC analyses ran prior to the module proxy!");
57   return Result(*CGAM);
58 }
59
60 CGSCCAnalysisManagerModuleProxy::Result::~Result() {
61   // Clear out the analysis manager if we're being destroyed -- it means we
62   // didn't even see an invalidate call when we got invalidated.
63   CGAM->clear();
64 }
65
66 bool CGSCCAnalysisManagerModuleProxy::Result::invalidate(
67     Module &M, const PreservedAnalyses &PA) {
68   // If this proxy isn't marked as preserved, then we can't even invalidate
69   // individual CGSCC analyses, there may be an invalid set of SCC objects in
70   // the cache making it impossible to incrementally preserve them.
71   // Just clear the entire manager.
72   if (!PA.preserved(ID()))
73     CGAM->clear();
74
75   // Return false to indicate that this result is still a valid proxy.
76   return false;
77 }
78
79 char ModuleAnalysisManagerCGSCCProxy::PassID;
80
81 char FunctionAnalysisManagerCGSCCProxy::PassID;
82
83 FunctionAnalysisManagerCGSCCProxy::Result
84 FunctionAnalysisManagerCGSCCProxy::run(LazyCallGraph::SCC &C) {
85   assert(FAM->empty() && "Function analyses ran prior to the CGSCC proxy!");
86   return Result(*FAM);
87 }
88
89 FunctionAnalysisManagerCGSCCProxy::Result::~Result() {
90   // Clear out the analysis manager if we're being destroyed -- it means we
91   // didn't even see an invalidate call when we got invalidated.
92   FAM->clear();
93 }
94
95 bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate(
96     LazyCallGraph::SCC &C, const PreservedAnalyses &PA) {
97   // If this proxy isn't marked as preserved, then we can't even invalidate
98   // individual function analyses, there may be an invalid set of Function
99   // objects in the cache making it impossible to incrementally preserve them.
100   // Just clear the entire manager.
101   if (!PA.preserved(ID()))
102     FAM->clear();
103
104   // Return false to indicate that this result is still a valid proxy.
105   return false;
106 }
107
108 char CGSCCAnalysisManagerFunctionProxy::PassID;