1//===- PassManagerImpl.h - Pass management infrastructure -------*- C++ -*-===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9/// Provides implementations for PassManager and AnalysisManager template 10/// methods. These classes should be explicitly instantiated for any IR unit, 11/// and files doing the explicit instantiation should include this header. 13//===----------------------------------------------------------------------===// 15#ifndef LLVM_IR_PASSMANAGERIMPL_H 16#define LLVM_IR_PASSMANAGERIMPL_H 28template <
typename IRUnitT,
typename AnalysisManagerT,
typename... ExtraArgTs>
30 IRUnitT &
IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs) {
43OS <<
"Running pass \"";
59// Request PassInstrumentation from analysis manager, will use it to run 60// instrumenting callbacks for the passes later. 61// Here we use std::tuple wrapper over getResult which helps to extract 62// AnalysisManager's arguments out of the whole ExtraArgs set. 64 detail::getAnalysisResult<PassInstrumentationAnalysis>(
65 AM,
IR, std::tuple<ExtraArgTs...>(ExtraArgs...));
67// RemoveDIs: if requested, convert debug-info to DbgRecord representation 68// for duration of these passes. 71 StackTraceEntry Entry(PI,
IR);
73 Entry.setPass(&*
Pass);
75// Check the PassInstrumentation's BeforePass callbacks before running the 76// pass, skip its execution completely if asked to (callback returns 83// Update the analysis manager as each pass runs and potentially 84// invalidates analyses. 85 AM.invalidate(
IR, PassPA);
87// Call onto PassInstrumentation's AfterPass callbacks immediately after 91// Finally, intersect the preserved analyses to compute the aggregate 92// preserved set for this pass manager. 96// Invalidation was handled after each pass in the above loop for the 97// current unit of IR. Therefore, the remaining analysis results in the 98// AnalysisManager are preserved. We mark this with a set so that we don't 99// need to inspect each one individually. 105template <
typename IRUnitT,
typename... ExtraArgTs>
108template <
typename IRUnitT,
typename... ExtraArgTs>
112template <
typename IRUnitT,
typename... ExtraArgTs>
117template <
typename IRUnitT,
typename... ExtraArgTs>
121if (
auto *PI = getCachedResult<PassInstrumentationAnalysis>(
IR))
122 PI->runAnalysesCleared(
Name);
124auto ResultsListI = AnalysisResultLists.find(&
IR);
125if (ResultsListI == AnalysisResultLists.end())
127// Delete the map entries that point into the results list. 128for (
auto &IDAndResult : ResultsListI->second)
129 AnalysisResults.erase({IDAndResult.first, &
IR});
131// And actually destroy and erase the results associated with this IR. 132 AnalysisResultLists.erase(ResultsListI);
135template <
typename IRUnitT,
typename... ExtraArgTs>
139typename AnalysisResultMapT::iterator RI;
141 std::tie(RI, Inserted) = AnalysisResults.insert(std::make_pair(
142 std::make_pair(
ID, &
IR),
typename AnalysisResultListT::iterator()));
144// If we don't have a cached result for this function, look up the pass and 145// run it to produce a result, which we then add to the cache. 147auto &
P = this->lookUpPass(
ID);
151 PI = getResult<PassInstrumentationAnalysis>(
IR, ExtraArgs...);
155 AnalysisResultListT &ResultList = AnalysisResultLists[&
IR];
156 ResultList.emplace_back(
ID,
P.run(
IR, *
this, ExtraArgs...));
160// P.run may have inserted elements into AnalysisResults and invalidated 162 RI = AnalysisResults.find({
ID, &
IR});
163assert(RI != AnalysisResults.end() &&
"we just inserted it!");
165 RI->second = std::prev(ResultList.end());
168return *RI->second->second;
171template <
typename IRUnitT,
typename... ExtraArgTs>
174// We're done if all analyses on this IR unit are preserved. 178// Track whether each analysis's result is invalidated in 179// IsResultInvalidated. 181Invalidator Inv(IsResultInvalidated, AnalysisResults);
182 AnalysisResultListT &ResultsList = AnalysisResultLists[&
IR];
183for (
auto &AnalysisResultPair : ResultsList) {
184// This is basically the same thing as Invalidator::invalidate, but we 185// can't call it here because we're operating on the type-erased result. 186// Moreover if we instead called invalidate() directly, it would do an 187// unnecessary look up in ResultsList. 189auto &Result = *AnalysisResultPair.second;
191auto IMapI = IsResultInvalidated.
find(
ID);
192if (IMapI != IsResultInvalidated.
end())
193// This result was already handled via the Invalidator. 196// Try to invalidate the result, giving it the Invalidator so it can 197// recursively query for any dependencies it has and record the result. 198// Note that we cannot reuse 'IMapI' here or pre-insert the ID, as 199// Result.invalidate may insert things into the map, invalidating our 202 IsResultInvalidated.
insert({
ID, Result.invalidate(
IR, PA, Inv)}).second;
204assert(Inserted &&
"Should never have already inserted this ID, likely " 205"indicates a cycle!");
208// Now erase the results that were marked above as invalidated. 209if (!IsResultInvalidated.
empty()) {
210for (
autoI = ResultsList.begin(),
E = ResultsList.end();
I !=
E;) {
211 AnalysisKey *
ID =
I->first;
212if (!IsResultInvalidated.
lookup(
ID)) {
217if (
auto *PI = getCachedResult<PassInstrumentationAnalysis>(
IR))
220I = ResultsList.erase(
I);
221 AnalysisResults.erase({
ID, &
IR});
225if (ResultsList.empty())
226 AnalysisResultLists.erase(&
IR);
228}
// end namespace llvm 230#endif// LLVM_IR_PASSMANAGERIMPL_H 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::cl::opt< bool > UseNewDbgInfoFormat
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char PassName[]
This templated class represents "all analyses that operate over <a particular IR unit>" (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...