Deleted Added
full compact
CGSCCPassManager.cpp (276479) CGSCCPassManager.cpp (280031)
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
14using namespace llvm;
15
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
14using namespace llvm;
15
16static cl::opt<bool>
17DebugPM("debug-cgscc-pass-manager", cl::Hidden,
18 cl::desc("Print CGSCC pass management debugging information"));
19
20PreservedAnalyses 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 if (AM)
33 AM->invalidate(C, PassPA);
34 PA.intersect(std::move(PassPA));
35 }
36
37 if (DebugPM)
38 dbgs() << "Finished CGSCC pass manager run.\n";
39
40 return PA;
41}
42
43bool CGSCCAnalysisManager::empty() const {
44 assert(CGSCCAnalysisResults.empty() == CGSCCAnalysisResultLists.empty() &&
45 "The storage and index of analysis results disagree on how many there "
46 "are!");
47 return CGSCCAnalysisResults.empty();
48}
49
50void CGSCCAnalysisManager::clear() {
51 CGSCCAnalysisResults.clear();
52 CGSCCAnalysisResultLists.clear();
53}
54
55CGSCCAnalysisManager::ResultConceptT &
56CGSCCAnalysisManager::getResultImpl(void *PassID, LazyCallGraph::SCC *C) {
57 CGSCCAnalysisResultMapT::iterator RI;
58 bool Inserted;
59 std::tie(RI, Inserted) = CGSCCAnalysisResults.insert(std::make_pair(
60 std::make_pair(PassID, C), CGSCCAnalysisResultListT::iterator()));
61
62 // If we don't have a cached result for this function, look up the pass and
63 // run it to produce a result, which we then add to the cache.
64 if (Inserted) {
65 CGSCCAnalysisResultListT &ResultList = CGSCCAnalysisResultLists[C];
66 ResultList.emplace_back(PassID, lookupPass(PassID).run(C, this));
67 RI->second = std::prev(ResultList.end());
68 }
69
70 return *RI->second->second;
71}
72
73CGSCCAnalysisManager::ResultConceptT *
74CGSCCAnalysisManager::getCachedResultImpl(void *PassID,
75 LazyCallGraph::SCC *C) const {
76 CGSCCAnalysisResultMapT::const_iterator RI =
77 CGSCCAnalysisResults.find(std::make_pair(PassID, C));
78 return RI == CGSCCAnalysisResults.end() ? nullptr : &*RI->second->second;
79}
80
81void CGSCCAnalysisManager::invalidateImpl(void *PassID, LazyCallGraph::SCC *C) {
82 CGSCCAnalysisResultMapT::iterator RI =
83 CGSCCAnalysisResults.find(std::make_pair(PassID, C));
84 if (RI == CGSCCAnalysisResults.end())
85 return;
86
87 CGSCCAnalysisResultLists[C].erase(RI->second);
88}
89
90void CGSCCAnalysisManager::invalidateImpl(LazyCallGraph::SCC *C,
91 const PreservedAnalyses &PA) {
92 // Clear all the invalidated results associated specifically with this
93 // function.
94 SmallVector<void *, 8> InvalidatedPassIDs;
95 CGSCCAnalysisResultListT &ResultsList = CGSCCAnalysisResultLists[C];
96 for (CGSCCAnalysisResultListT::iterator I = ResultsList.begin(),
97 E = ResultsList.end();
98 I != E;)
99 if (I->second->invalidate(C, PA)) {
100 InvalidatedPassIDs.push_back(I->first);
101 I = ResultsList.erase(I);
102 } else {
103 ++I;
104 }
105 while (!InvalidatedPassIDs.empty())
106 CGSCCAnalysisResults.erase(
107 std::make_pair(InvalidatedPassIDs.pop_back_val(), C));
108 CGSCCAnalysisResultLists.erase(C);
109}
110
111char CGSCCAnalysisManagerModuleProxy::PassID;
112
113CGSCCAnalysisManagerModuleProxy::Result
16char CGSCCAnalysisManagerModuleProxy::PassID;
17
18CGSCCAnalysisManagerModuleProxy::Result
114CGSCCAnalysisManagerModuleProxy::run(Module *M) {
19CGSCCAnalysisManagerModuleProxy::run(Module &M) {
115 assert(CGAM->empty() && "CGSCC analyses ran prior to the module proxy!");
116 return Result(*CGAM);
117}
118
119CGSCCAnalysisManagerModuleProxy::Result::~Result() {
120 // Clear out the analysis manager if we're being destroyed -- it means we
121 // didn't even see an invalidate call when we got invalidated.
122 CGAM->clear();
123}
124
125bool CGSCCAnalysisManagerModuleProxy::Result::invalidate(
20 assert(CGAM->empty() && "CGSCC analyses ran prior to the module proxy!");
21 return Result(*CGAM);
22}
23
24CGSCCAnalysisManagerModuleProxy::Result::~Result() {
25 // Clear out the analysis manager if we're being destroyed -- it means we
26 // didn't even see an invalidate call when we got invalidated.
27 CGAM->clear();
28}
29
30bool CGSCCAnalysisManagerModuleProxy::Result::invalidate(
126 Module *M, const PreservedAnalyses &PA) {
31 Module &M, const PreservedAnalyses &PA) {
127 // If this proxy isn't marked as preserved, then we can't even invalidate
128 // individual CGSCC analyses, there may be an invalid set of SCC objects in
129 // the cache making it impossible to incrementally preserve them.
130 // Just clear the entire manager.
131 if (!PA.preserved(ID()))
132 CGAM->clear();
133
134 // Return false to indicate that this result is still a valid proxy.
135 return false;
136}
137
138char ModuleAnalysisManagerCGSCCProxy::PassID;
139
140char FunctionAnalysisManagerCGSCCProxy::PassID;
141
142FunctionAnalysisManagerCGSCCProxy::Result
32 // If this proxy isn't marked as preserved, then we can't even invalidate
33 // individual CGSCC analyses, there may be an invalid set of SCC objects in
34 // the cache making it impossible to incrementally preserve them.
35 // Just clear the entire manager.
36 if (!PA.preserved(ID()))
37 CGAM->clear();
38
39 // Return false to indicate that this result is still a valid proxy.
40 return false;
41}
42
43char ModuleAnalysisManagerCGSCCProxy::PassID;
44
45char FunctionAnalysisManagerCGSCCProxy::PassID;
46
47FunctionAnalysisManagerCGSCCProxy::Result
143FunctionAnalysisManagerCGSCCProxy::run(LazyCallGraph::SCC *C) {
48FunctionAnalysisManagerCGSCCProxy::run(LazyCallGraph::SCC &C) {
144 assert(FAM->empty() && "Function analyses ran prior to the CGSCC proxy!");
145 return Result(*FAM);
146}
147
148FunctionAnalysisManagerCGSCCProxy::Result::~Result() {
149 // Clear out the analysis manager if we're being destroyed -- it means we
150 // didn't even see an invalidate call when we got invalidated.
151 FAM->clear();
152}
153
154bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate(
49 assert(FAM->empty() && "Function analyses ran prior to the CGSCC proxy!");
50 return Result(*FAM);
51}
52
53FunctionAnalysisManagerCGSCCProxy::Result::~Result() {
54 // Clear out the analysis manager if we're being destroyed -- it means we
55 // didn't even see an invalidate call when we got invalidated.
56 FAM->clear();
57}
58
59bool FunctionAnalysisManagerCGSCCProxy::Result::invalidate(
155 LazyCallGraph::SCC *C, const PreservedAnalyses &PA) {
60 LazyCallGraph::SCC &C, const PreservedAnalyses &PA) {
156 // If this proxy isn't marked as preserved, then we can't even invalidate
157 // individual function analyses, there may be an invalid set of Function
158 // objects in the cache making it impossible to incrementally preserve them.
159 // Just clear the entire manager.
160 if (!PA.preserved(ID()))
161 FAM->clear();
162
163 // Return false to indicate that this result is still a valid proxy.
164 return false;
165}
166
167char CGSCCAnalysisManagerFunctionProxy::PassID;
61 // If this proxy isn't marked as preserved, then we can't even invalidate
62 // individual function analyses, there may be an invalid set of Function
63 // objects in the cache making it impossible to incrementally preserve them.
64 // Just clear the entire manager.
65 if (!PA.preserved(ID()))
66 FAM->clear();
67
68 // Return false to indicate that this result is still a valid proxy.
69 return false;
70}
71
72char CGSCCAnalysisManagerFunctionProxy::PassID;