LLVM: include/llvm/IR/PassManagerImpl.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_IR_PASSMANAGERIMPL_H
16#define LLVM_IR_PASSMANAGERIMPL_H
17
23
25
26namespace llvm {
27
28template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
30 IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs) {
33 IRUnitT &IR;
35
36 public:
39
41
43 OS << "Running pass \"";
48 });
49 else
50 OS << "unknown";
51 OS << "\" on ";
53 OS << "\n";
54 }
55 };
56
58
59
60
61
62
64 detail::getAnalysisResult(
65 AM, IR, std::tuple<ExtraArgTs...>(ExtraArgs...));
66
67
68
70
71 StackTraceEntry Entry(PI, IR);
73 Entry.setPass(&*Pass);
74
75
76
77
79 continue;
80
82
83
84
85 AM.invalidate(IR, PassPA);
86
87
88
90
91
92
94 }
95
96
97
98
99
101
102 return PA;
103}
104
105template <typename IRUnitT, typename... ExtraArgTs>
107
108template <typename IRUnitT, typename... ExtraArgTs>
111
112template <typename IRUnitT, typename... ExtraArgTs>
115 default;
116
117template <typename IRUnitT, typename... ExtraArgTs>
118inline void
121 if (auto *PI = getCachedResult(IR))
122 PI->runAnalysesCleared(Name);
123
124 auto ResultsListI = AnalysisResultLists.find(&IR);
125 if (ResultsListI == AnalysisResultLists.end())
126 return;
127
128 for (auto &IDAndResult : ResultsListI->second)
129 AnalysisResults.erase({IDAndResult.first, &IR});
130
131
132 AnalysisResultLists.erase(ResultsListI);
133}
134
135template <typename IRUnitT, typename... ExtraArgTs>
136inline typename AnalysisManager<IRUnitT, ExtraArgTs...>::ResultConceptT &
139 typename AnalysisResultMapT::iterator RI;
140 bool Inserted;
141 std::tie(RI, Inserted) = AnalysisResults.insert(std::make_pair(
142 std::make_pair(ID, &IR), typename AnalysisResultListT::iterator()));
143
144
145
146 if (Inserted) {
147 auto &P = this->lookUpPass(ID);
148
151 PI = getResult(IR, ExtraArgs...);
153 }
154
155 AnalysisResultListT &ResultList = AnalysisResultLists[&IR];
156 ResultList.emplace_back(ID, P.run(IR, *this, ExtraArgs...));
157
159
160
161
162 RI = AnalysisResults.find({ID, &IR});
163 assert(RI != AnalysisResults.end() && "we just inserted it!");
164
165 RI->second = std::prev(ResultList.end());
166 }
167
168 return *RI->second->second;
169}
170
171template <typename IRUnitT, typename... ExtraArgTs>
174
176 return;
177
178
179
181 Invalidator Inv(IsResultInvalidated, AnalysisResults);
182 AnalysisResultListT &ResultsList = AnalysisResultLists[&IR];
183 for (auto &AnalysisResultPair : ResultsList) {
184
185
186
187
189 auto &Result = *AnalysisResultPair.second;
191 auto IMapI = IsResultInvalidated.find(ID);
192 if (IMapI != IsResultInvalidated.end())
193
194 continue;
195
196
197
198
199
200
201 bool Inserted =
202 IsResultInvalidated.insert({ID, Result.invalidate(IR, PA, Inv)}).second;
203 (void)Inserted;
204 assert(Inserted && "Should never have already inserted this ID, likely "
205 "indicates a cycle!");
206 }
207
208
209 if (!IsResultInvalidated.empty()) {
210 for (auto I = ResultsList.begin(), E = ResultsList.end(); I != E;) {
211 AnalysisKey *ID = I->first;
212 if (!IsResultInvalidated.lookup(ID)) {
213 ++I;
214 continue;
215 }
216
217 if (auto *PI = getCachedResult(IR))
219
221 AnalysisResults.erase({ID, &IR});
222 }
223 }
224
225 if (ResultsList.empty())
226 AnalysisResultLists.erase(&IR);
227}
228}
229
230#endif
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This header defines various interfaces for pass management in LLVM.
Legalize the Machine IR a function s Machine IR
Function const char * Passes
This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...
llvm:🆑:opt< bool > UseNewDbgInfoFormat
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char PassName[]
This templated class represents "all analyses that operate over " (e....
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
AnalysisManager()
Construct an empty analysis manager.
void clear()
Clear all analysis results cached by this AnalysisManager.
AnalysisManager & operator=(AnalysisManager &&)
void invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Invalidate cached analyses for an IR unit.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...
void runBeforeAnalysis(const PassT &Analysis, const IRUnitT &IR) const
BeforeAnalysis instrumentation point - takes Analysis instance to be executed and constant reference ...
void runAnalysisInvalidated(const PassT &Analysis, const IRUnitT &IR) const
AnalysisInvalidated instrumentation point - takes Analysis instance that has just been invalidated an...
StringRef getPassNameForClassName(StringRef ClassName) const
Get the pass name for a given pass class name.
void runAfterPass(const PassT &Pass, const IRUnitT &IR, const PreservedAnalyses &PA) const
AfterPass instrumentation point - takes Pass instance that has just been executed and constant refere...
void runAfterAnalysis(const PassT &Analysis, const IRUnitT &IR) const
AfterAnalysis instrumentation point - takes Analysis instance that has just been executed and constan...
bool runBeforePass(const PassT &Pass, const IRUnitT &IR) const
BeforePass instrumentation point - takes Pass instance to be executed and constant reference to IR it...
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Pass interface - Implemented by all 'passes'.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
bool allAnalysesInSetPreserved() const
Directly test whether a set of analyses is preserved.
void intersect(const PreservedAnalyses &Arg)
Intersect this set with another in place.
void preserveSet()
Mark an analysis set as preserved.
PrettyStackTraceEntry - This class is used to represent a frame of the "pretty" stack trace that is d...
Used to temporarily set the debug info format of a function, module, or basic block for the duration ...
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
void printIRUnitNameForStackTrace(raw_ostream &OS, const IRUnitT &IR)
static AnalysisKey * ID()
Returns an opaque, unique ID for this analysis type.
A special type used by analysis passes to provide an address that identifies that particular analysis...