LLVM  14.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 
18 using namespace llvm;
19 
20 namespace llvm {
21 template class AllAnalysesOn<MachineFunction>;
23 template class PassManager<MachineFunction>;
24 
27  // MachineModuleAnalysis is a module analysis pass that is never invalidated
28  // because we don't run any module pass in codegen pipeline. This is very
29  // important because the codegen state is stored in MMI which is the analysis
30  // result of MachineModuleAnalysis. MMI should not be recomputed.
31  auto &MMI = MFAM.getResult<MachineModuleAnalysis>(M);
32 
33  (void)RequireCodeGenSCCOrder;
34  assert(!RequireCodeGenSCCOrder && "not implemented");
35 
36  // Add a PIC to verify machine functions.
37  if (VerifyMachineFunction) {
39 
40  // No need to pop this callback later since MIR pipeline is flat which means
41  // current pipeline is the top-level pipeline. Callbacks are not used after
42  // current pipeline.
43  PI.pushBeforeNonSkippedPassCallback([&MFAM](StringRef PassID, Any IR) {
44  assert(any_isa<const MachineFunction *>(IR));
45  const MachineFunction *MF = any_cast<const MachineFunction *>(IR);
46  assert(MF && "Machine function should be valid for printing");
47  std::string Banner = std::string("After ") + std::string(PassID);
48  verifyMachineFunction(&MFAM, Banner, *MF);
49  });
50  }
51 
52  for (auto &F : InitializationFuncs) {
53  if (auto Err = F(M, MFAM))
54  return Err;
55  }
56 
57  unsigned Idx = 0;
58  size_t Size = Passes.size();
59  do {
60  // Run machine module passes
61  for (; MachineModulePasses.count(Idx) && Idx != Size; ++Idx) {
62  if (auto Err = MachineModulePasses.at(Idx)(M, MFAM))
63  return Err;
64  }
65 
66  // Finish running all passes.
67  if (Idx == Size)
68  break;
69 
70  // Run machine function passes
71 
72  // Get index range of machine function passes.
73  unsigned Begin = Idx;
74  for (; !MachineModulePasses.count(Idx) && Idx != Size; ++Idx)
75  ;
76 
77  for (Function &F : M) {
78  // Do not codegen any 'available_externally' functions at all, they have
79  // definitions outside the translation unit.
80  if (F.hasAvailableExternallyLinkage())
81  continue;
82 
83  MachineFunction &MF = MMI.getOrCreateMachineFunction(F);
85 
86  for (unsigned I = Begin, E = Idx; I != E; ++I) {
87  auto *P = Passes[I].get();
88 
89  if (!PI.runBeforePass<MachineFunction>(*P, MF))
90  continue;
91 
92  // TODO: EmitSizeRemarks
93  PreservedAnalyses PassPA = P->run(MF, MFAM);
94  PI.runAfterPass(*P, MF, PassPA);
95  MFAM.invalidate(MF, PassPA);
96  }
97  }
98  } while (true);
99 
100  for (auto &F : FinalizationFuncs) {
101  if (auto Err = F(M, MFAM))
102  return Err;
103  }
104 
105  return Error::success();
106 }
107 
108 } // namespace llvm
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::MachineFunctionAnalysisManager::getResult
PassT::Result & getResult(Function &F)
Get the result of an analysis pass for a Function.
Definition: MachinePassManager.h:54
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::Function
Definition: Function.h:61
llvm::AnalysisManager::invalidate
void invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Invalidate cached analyses for an IR unit.
Definition: PassManagerImpl.h:89
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::AllAnalysesOn
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
Definition: PassManager.h:93
llvm::PassInstrumentation::pushBeforeNonSkippedPassCallback
void pushBeforeNonSkippedPassCallback(CallableT C)
Definition: PassInstrumentation.h:308
llvm::MachineModuleAnalysis
An analysis that produces MachineInfo for a module.
Definition: MachineModuleInfo.h:298
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::verifyMachineFunction
void verifyMachineFunction(MachineFunctionAnalysisManager *, const std::string &Banner, const MachineFunction &MF)
Definition: MachineVerifier.cpp:313
PassManagerImpl.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
IR
Statically lint checks LLVM IR
Definition: Lint.cpp:744
llvm::PassManager< MachineFunction, MachineFunctionAnalysisManager >::Passes
std::vector< std::unique_ptr< PassConceptT > > Passes
Definition: PassManager.h:581
llvm::MachineFunctionAnalysisManager
An AnalysisManager<MachineFunction> that also exposes IR analysis results.
Definition: MachinePassManager.h:39
llvm::PassInstrumentation::runAfterPass
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...
Definition: PassInstrumentation.h:242
llvm::MachineFunctionPassManager::run
Error run(Module &M, MachineFunctionAnalysisManager &MFAM)
Run machine passes for a Module.
Definition: MachinePassManager.cpp:25
I
#define I(x, y, z)
Definition: MD5.cpp:59
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::PassInstrumentation
This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...
Definition: PassInstrumentation.h:180
MachineModuleInfo.h
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::PassManager
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:472
MachinePassManager.h
llvm::Any
Definition: Any.h:26
llvm::PassInstrumentation::runBeforePass
bool runBeforePass(const PassT &Pass, const IRUnitT &IR) const
BeforePass instrumentation point - takes Pass instance to be executed and constant reference to IR it...
Definition: PassInstrumentation.h:217
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::AnalysisManager< MachineFunction >
llvm::PassInstrumentationAnalysis
Pseudo-analysis pass that exposes the PassInstrumentation to pass managers.
Definition: PassManager.h:599
MachineFunction.h