LLVM 19.0.0git
MachinePassManager.cpp
Go to the documentation of this file.
1//===---------- MachinePassManager.cpp ------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the pass management machinery for machine functions.
10//
11//===----------------------------------------------------------------------===//
12
18
19using namespace llvm;
20
22
23namespace llvm {
25template class PassManager<MachineFunction>;
27 Module>;
29 Function>;
32} // namespace llvm
33
37 // MachineFunction passes should not invalidate Function analyses.
38 // TODO: verify that PA doesn't invalidate Function analyses.
39 return false;
40}
41
42template <>
43bool MachineFunctionAnalysisManagerModuleProxy::Result::invalidate(
44 Module &M, const PreservedAnalyses &PA,
46 // If literally everything is preserved, we're done.
47 if (PA.areAllPreserved())
48 return false; // This is still a valid proxy.
49
50 // If this proxy isn't marked as preserved, then even if the result remains
51 // valid, the key itself may no longer be valid, so we clear everything.
52 //
53 // Note that in order to preserve this proxy, a module pass must ensure that
54 // the MFAM has been completely updated to handle the deletion of functions.
55 // Specifically, any MFAM-cached results for those functions need to have been
56 // forcibly cleared. When preserved, this proxy will only invalidate results
57 // cached on functions *still in the module* at the end of the module pass.
59 if (!PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Module>>()) {
60 InnerAM->clear();
61 return true;
62 }
63
64 // FIXME: be more precise, see
65 // FunctionAnalysisManagerModuleProxy::Result::invalidate.
67 InnerAM->clear();
68 return true;
69 }
70
71 // Return false to indicate that this result is still a valid proxy.
72 return false;
73}
74
75template <>
76bool MachineFunctionAnalysisManagerFunctionProxy::Result::invalidate(
77 Function &F, const PreservedAnalyses &PA,
79 // If literally everything is preserved, we're done.
80 if (PA.areAllPreserved())
81 return false; // This is still a valid proxy.
82
83 // If this proxy isn't marked as preserved, then even if the result remains
84 // valid, the key itself may no longer be valid, so we clear everything.
85 //
86 // Note that in order to preserve this proxy, a module pass must ensure that
87 // the MFAM has been completely updated to handle the deletion of functions.
88 // Specifically, any MFAM-cached results for those functions need to have been
89 // forcibly cleared. When preserved, this proxy will only invalidate results
90 // cached on functions *still in the module* at the end of the module pass.
92 if (!PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Function>>()) {
93 InnerAM->clear();
94 return true;
95 }
96
97 // FIXME: be more precise, see
98 // FunctionAnalysisManagerModuleProxy::Result::invalidate.
100 InnerAM->clear();
101 return true;
102 }
103
104 // Return false to indicate that this result is still a valid proxy.
105 return false;
106}
107
113 .getManager();
116 // Do not codegen any 'available_externally' functions at all, they have
117 // definitions outside the translation unit.
118 if (F.isDeclaration() || F.hasAvailableExternallyLinkage())
119 return PreservedAnalyses::all();
120
122
123 if (!PI.runBeforePass<MachineFunction>(*Pass, MF))
124 return PreservedAnalyses::all();
125 PreservedAnalyses PassPA = Pass->run(MF, MFAM);
126 MFAM.invalidate(MF, PassPA);
127 PI.runAfterPass(*Pass, MF, PassPA);
128 PA.intersect(std::move(PassPA));
129
130 return PA;
131}
132
134 raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
135 OS << "machine-function(";
136 Pass->printPipeline(OS, MapClassName2PassName);
137 OS << ')';
138}
139
140template <>
146 for (auto &Pass : Passes) {
147 if (!PI.runBeforePass<MachineFunction>(*Pass, MF))
148 continue;
149
150 PreservedAnalyses PassPA = Pass->run(MF, MFAM);
151 MFAM.invalidate(MF, PassPA);
152 PI.runAfterPass(*Pass, MF, PassPA);
153 PA.intersect(std::move(PassPA));
154 }
155 return PA;
156}
157
160 // Machine function passes are not allowed to modify the LLVM
161 // representation, therefore we should preserve all IR analyses.
162 PA.template preserveSet<AllAnalysesOn<Module>>();
163 PA.template preserveSet<AllAnalysesOn<Function>>();
164 return PA;
165}
Legalize the Machine IR a function s Machine IR
Definition: Legalizer.cpp:81
#define F(x, y, z)
Definition: MD5.cpp:55
FunctionAnalysisManager FAM
const char * Passes
Provides implementations for PassManager and AnalysisManager template methods.
raw_pwrite_stream & OS
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
Definition: Analysis.h:47
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:360
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:321
void invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Invalidate cached analyses for an IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:473
bool invalidate(MachineFunction &IR, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &Inv)
Handler for invalidation of the outer IR unit, IRUnitT.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
Runs the function pass across every function in the function.
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:631
This analysis create MachineFunction for given Function.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:756
Pseudo-analysis pass that exposes the PassInstrumentation to pass managers.
Definition: PassManager.h:296
This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...
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...
bool runBeforePass(const PassT &Pass, const IRUnitT &IR) const
BeforePass instrumentation point - takes Pass instance to be executed and constant reference to IR it...
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:173
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Definition: PassManager.h:201
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
bool areAllPreserved() const
Test whether all analyses are preserved (and none are abandoned).
Definition: Analysis.h:281
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
bool allAnalysesInSetPreserved() const
Directly test whether a set of analyses is preserved.
Definition: Analysis.h:289
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: Analysis.h:264
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition: MIRParser.h:38
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:26