LLVM 24.0.0git
RunCodeGen.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
10#include "PassesOptions.h"
21#include "llvm/IR/PassManager.h"
25#include "llvm/Support/Error.h"
28
29using namespace llvm;
30
33 raw_pwrite_stream *DwoOS,
34 CodeGenFileType CGFT, bool DisableVerify,
35 const ModuleSummaryIndex *MSI,
36 bool DisableSimplifyLibCalls) {
37 legacy::PassManager CodeGenPasses;
38 CodeGenPasses.add(
40 // Add LibraryInfo.
42 if (DisableSimplifyLibCalls)
44 CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
45 if (MSI)
47
48 const TargetOptions &Options = TM.Options;
49 CodeGenPasses.add(
50 new RuntimeLibraryInfoWrapper(Options.MCOptions.ABIName, Options.VecLib));
51
52 if (TM.addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT, DisableVerify))
53 return createStringError("Failed to construct CodeGen pipeline");
54 CodeGenPasses.run(M);
55
56 return Error::success();
57}
58
61 raw_pwrite_stream *DwoOS,
62 CodeGenFileType CGFT, bool DisableVerify,
63 const ModuleSummaryIndex *MSI,
72 Opt.DisableVerify = DisableVerify;
73 MachineModuleInfo MMI(&TM);
75 PipelineTuningOptions PTOptions;
76 PassBuilder PB(M.getContext(), &TM, PTOptions, std::nullopt, &PIC, VFS);
77
78 MAM.registerPass([&] { return MachineModuleAnalysis(MMI); });
79 if (MSI) {
80 MAM.registerPass(
81 [&]() { return ImmutableModuleSummaryIndexAnalysis(MSI); });
82 MPM.addPass(
84 }
85
86 PB.registerModuleAnalyses(MAM);
87 PB.registerCGSCCAnalyses(CGAM);
88 PB.registerFunctionAnalyses(FAM);
89 PB.registerLoopAnalyses(LAM);
90 PB.registerMachineFunctionAnalyses(MFAM);
91 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM, &MFAM);
92
93 StandardInstrumentations SI(M.getContext(), /*DebugLogging=*/false);
94 SI.registerCallbacks(PIC, &MAM);
95
96 Error BuildPipelineError = TM.buildCodeGenPipeline(
97 MPM, MAM, OS, DwoOS, CGFT, Opt, MMI.getContext(), &PIC);
98 if (BuildPipelineError)
99 return BuildPipelineError;
100
101 MPM.run(M, MAM);
102 return Error::success();
103}
104
107 CodeGenFileType CGFT, bool DisableVerify,
108 bool DisableSimplifyLibCalls,
109 const ModuleSummaryIndex *MSI,
111 const PassesOptions &Opts = getPassesOptions(M.getContext());
112 if (valueOr(Opts.force_new_pm_codegen, TM.shouldDefaultToNewPM())) {
113 return runCodeGenPipelineNewPM(TM, M, OS, DwoOS, CGFT, DisableVerify, MSI,
114 VFS);
115 }
116
117 return runCodeGenPipelineLegacy(TM, M, OS, DwoOS, CGFT, DisableVerify, MSI,
118 DisableSimplifyLibCalls);
119}
This header provides classes for managing passes over SCCs of the call graph.
This header defines various interfaces for pass management in LLVM.
static LVOptions Options
Definition LVOptions.cpp:25
This header provides classes for managing per-loop analyses.
This is the interface to build a ModuleSummaryIndex for a module.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
CGSCCAnalysisManager CGAM
LoopAnalysisManager LAM
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
PassInstrumentationCallbacks PIC
static Error runCodeGenPipelineNewPM(TargetMachine &TM, Module &M, raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS, CodeGenFileType CGFT, bool DisableVerify, const ModuleSummaryIndex *MSI, IntrusiveRefCntPtr< vfs::FileSystem > VFS)
static Error runCodeGenPipelineLegacy(TargetMachine &TM, Module &M, raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS, CodeGenFileType CGFT, bool DisableVerify, const ModuleSummaryIndex *MSI, bool DisableSimplifyLibCalls)
This header defines a class that provides bookkeeping for all standard (i.e in-tree) pass instrumenta...
This pass exposes codegen information to IR-level passes.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
NPM analysis to provide an externally-built ModuleSummaryIndex (e.g.
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
An analysis that produces MachineModuleInfo for a module.
This class contains meta information specific to a module.
const MCContext & getContext() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
This class provides access to building LLVM's passes.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Tunable parameters for passes in the default pipelines.
Definition PassBuilder.h:48
This class provides an interface to register all the standard pass instrumentations and manages their...
Implementation of the target library information.
LLVM_ABI void disableAllFunctions()
Disables all builtins.
Primary interface to the complete machine description for the target machine.
virtual bool shouldDefaultToNewPM() const
Returns true if frontends should default to using the NewPM for this specific target.
virtual bool addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &, raw_pwrite_stream *, CodeGenFileType, bool=true, MachineModuleInfoWrapperPass *MMIWP=nullptr)
Add passes to the specified pass manager to get the specified file emitted.
virtual Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, const CGPassBuilderOption &Opt, MCContext &Ctx, PassInstrumentationCallbacks *PIC)
const Triple & getTargetTriple() const
TargetIRAnalysis getTargetIRAnalysis() const
Get a TargetIRAnalysis appropriate for the target.
TargetOptions Options
VectorLibrary VecLib
Vector math library to use.
PassManager manages ModulePassManagers.
void add(Pass *P) override
Add a pass to the queue of passes to run.
bool run(Module &M)
run - Execute all of the passes scheduled for execution.
An abstract base class for streams implementations that also support a pwrite operation.
Interfaces for registering analysis passes, producing common pass manager configurations,...
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
LLVM_ABI Error runCodeGenPipeline(TargetMachine &TM, Module &M, raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS, CodeGenFileType CGFT, bool DisableVerify=true, bool DisableSimplifyLibCalls=false, const ModuleSummaryIndex *MSI=nullptr, IntrusiveRefCntPtr< vfs::FileSystem > VFS=vfs::getRealFileSystem())
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:309
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
LLVM_ABI CGPassBuilderOption getCGPassBuilderOption(const TargetMachine &TM)
LLVM_ABI ImmutablePass * createTargetTransformInfoWrapperPass(TargetIRAnalysis TIRA)
Create an analysis pass wrapper around a TTI object.
LLVM_ABI ImmutablePass * createImmutableModuleSummaryIndexWrapperPass(const ModuleSummaryIndex *Index)
constexpr bool valueOr(BoolOrDefault X, bool Default)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
const PassesOptions & getPassesOptions(const LLVMContext &C)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
A utility pass template to force an analysis result to be available.