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
17
18using namespace llvm;
19
20namespace llvm {
21
23
25template class PassManager<MachineFunction>;
27 Module>;
30
34 // MachineFunction passes should not invalidate Function analyses.
35 // TODO: verify that PA doesn't invalidate Function analyses.
36 return false;
37}
38
39template <>
40bool MachineFunctionAnalysisManagerModuleProxy::Result::invalidate(
41 Module &M, const PreservedAnalyses &PA,
43 // If literally everything is preserved, we're done.
44 if (PA.areAllPreserved())
45 return false; // This is still a valid proxy.
46
47 // If this proxy isn't marked as preserved, then even if the result remains
48 // valid, the key itself may no longer be valid, so we clear everything.
49 //
50 // Note that in order to preserve this proxy, a module pass must ensure that
51 // the MFAM has been completely updated to handle the deletion of functions.
52 // Specifically, any MFAM-cached results for those functions need to have been
53 // forcibly cleared. When preserved, this proxy will only invalidate results
54 // cached on functions *still in the module* at the end of the module pass.
56 if (!PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Module>>()) {
57 InnerAM->clear();
58 return true;
59 }
60
61 // FIXME: be more precise, see
62 // FunctionAnalysisManagerModuleProxy::Result::invalidate.
64 InnerAM->clear();
65 return true;
66 }
67
68 // Return false to indicate that this result is still a valid proxy.
69 return false;
70}
71
74 auto &MMI = AM.getResult<MachineModuleAnalysis>(M).getMMI();
79 for (Function &F : M) {
80 // Do not codegen any 'available_externally' functions at all, they have
81 // definitions outside the translation unit.
82 if (F.isDeclaration() || F.hasAvailableExternallyLinkage())
83 continue;
84
85 MachineFunction &MF = MMI.getOrCreateMachineFunction(F);
86
87 if (!PI.runBeforePass<MachineFunction>(*Pass, MF))
88 continue;
89 PreservedAnalyses PassPA = Pass->run(MF, MFAM);
90 if (MMI.getMachineFunction(F)) {
91 MFAM.invalidate(MF, PassPA);
92 PI.runAfterPass(*Pass, MF, PassPA);
93 } else {
94 MFAM.clear(MF, F.getName());
96 }
97 PA.intersect(std::move(PassPA));
98 }
99
100 return PA;
101}
102
104 raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
105 OS << "machine-function(";
106 Pass->printPipeline(OS, MapClassName2PassName);
107 OS << ')';
108}
109
110template <>
115 Function &F = MF.getFunction();
116 MachineModuleInfo &MMI =
118 .getCachedResult<MachineModuleAnalysis>(*F.getParent())
119 ->getMMI();
121 for (auto &Pass : Passes) {
122 if (!PI.runBeforePass<MachineFunction>(*Pass, MF))
123 continue;
124
125 PreservedAnalyses PassPA = Pass->run(MF, MFAM);
126 if (MMI.getMachineFunction(F)) {
127 MFAM.invalidate(MF, PassPA);
128 PI.runAfterPass(*Pass, MF, PassPA);
129 } else {
130 MFAM.clear(MF, F.getName());
132 }
133 PA.intersect(std::move(PassPA));
134 }
135 return PA;
136}
137
138} // namespace llvm
Legalize the Machine IR a function s Machine IR
Definition: Legalizer.cpp:81
#define F(x, y, z)
Definition: MD5.cpp:55
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:387
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:348
void clear(IRUnitT &IR, llvm::StringRef Name)
Clear any cached analysis results for a single unit of IR.
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:500
bool invalidate(MachineFunction &IR, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &Inv)
Handler for invalidation of the outer IR unit, IRUnitT.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:658
Function & getFunction()
Return the LLVM function that this machine code represents.
An analysis that produces MachineModuleInfo for a module.
This class contains meta information specific to a module.
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Runs the function pass across every function in the module.
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:783
Pseudo-analysis pass that exposes the PassInstrumentation to pass managers.
Definition: PassManager.h:323
This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...
void runAfterPassInvalidated(const PassT &Pass, const PreservedAnalyses &PA) const
AfterPassInvalidated instrumentation point - takes Pass instance that has just been executed.
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:190
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:218
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
void intersect(const PreservedAnalyses &Arg)
Intersect this set with another in place.
Definition: Analysis.h:180
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
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition: PassManager.h:632
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:26