1//===-LTOCodeGenerator.cpp - LLVM Link Time Optimizer ---------------------===// 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// This file implements the Link Time Optimization library. This library is 10// intended to be used by linker to optimize code at link time. 12//===----------------------------------------------------------------------===// 24#include "llvm/Config/config.h" 65#include <system_error> 69return PACKAGE_NAME
" version " PACKAGE_VERSION;
74"lto-discard-value-names",
75cl::desc(
"Strip names from Value during LTO (other than GlobalValue)."),
84"lto-pass-remarks-with-hotness",
85cl::desc(
"With PGO, include profile count in optimization remarks"),
90"lto-pass-remarks-hotness-threshold",
91cl::desc(
"Minimum profile count required for an " 92"optimization remark to be output." 93" Use 'auto' to apply the threshold from profile summary."),
98cl::desc(
"Output filename for pass remarks"),
103cl::desc(
"Only record optimization remarks from passes whose " 104"names match the given regular expression"),
108"lto-pass-remarks-format",
109cl::desc(
"The format used for serializing remarks (default: YAML)"),
114cl::desc(
"Save statistics to the specified file"),
118"lto-aix-system-assembler",
119cl::desc(
"Path to a system assembler, picked up on AIX only"),
124cl::desc(
"Perform context sensitive PGO instrumentation"));
128cl::desc(
"Context sensitive profile file path"));
132 : Context(Context), MergedModule(new
Module(
"ld-temp.o", Context)),
133 TheLinker(new
Linker(*MergedModule)) {
147 AsmUndefinedRefs.
insert(Undef);
151assert(&
Mod->getModule().getContext() == &Context &&
152"Expected module in same context");
154bool ret = TheLinker->linkInModule(
Mod->takeModule());
157// We've just changed the input, so let's make sure we verify it. 158 HasVerifiedInput =
false;
164assert(&
Mod->getModule().getContext() == &Context &&
165"Expected module in same context");
167 AsmUndefinedRefs.
clear();
169 MergedModule =
Mod->takeModule();
170 TheLinker = std::make_unique<Linker>(*MergedModule);
173// We've just changed the input, so let's make sure we verify it. 174 HasVerifiedInput =
false;
184 EmitDwarfDebugInfo =
false;
188 EmitDwarfDebugInfo =
true;
198 std::optional<CodeGenOptLevel> CGOptLevelOrNone =
200assert(CGOptLevelOrNone &&
"Unknown optimization level!");
205if (!determineTarget())
208// We always run the verifier once on the merged module. 209 verifyMergedModuleOnce();
211// mark which symbols can not be internalized 212 applyScopeRestrictions();
218 std::string ErrMsg =
"could not open bitcode file for writing: ";
219 ErrMsg += Path.str() +
": " + EC.message();
224// write bitcode to it 229 std::string ErrMsg =
"could not write bitcode file: ";
230 ErrMsg += Path.str() +
": " + Out.
os().
error().message();
240bool LTOCodeGenerator::useAIXSystemAssembler() {
241constauto &
Triple = TargetMach->getTargetTriple();
246assert(useAIXSystemAssembler() &&
247"Runing AIX system assembler when integrated assembler is available!");
249// Set the system assembler path. 253/* expand_tilde */true)) {
255"Cannot find the assembler specified by lto-aix-system-assembler");
260// Setup the LDR_CNTRL variable 261 std::string LDR_CNTRL_var =
"LDR_CNTRL=MAXDATA32=0xA0000000@DSA";
263 LDR_CNTRL_var += (
"@" + *
V);
265// Prepare inputs for the assember. 266constauto &
Triple = TargetMach->getTargetTriple();
269 ObjectFileName[ObjectFileName.size() - 1] =
'o';
271"/bin/env", LDR_CNTRL_var,
276// Invoke the assembler. 281 emitError(
"LTO assembler exited abnormally");
285 emitError(
"Unable to invoke LTO assembler");
289 emitError(
"LTO assembler invocation returned non-zero");
296// Fix the output file name. 302bool LTOCodeGenerator::compileOptimizedToFile(
constchar **
Name) {
303if (useAIXSystemAssembler())
306// make unique temp output file to put generated code 319 emitError(
EC.message());
321return std::make_unique<CachedFileStream>(
322 std::make_unique<llvm::raw_fd_ostream>(FD,
true));
332// If statistics were requested, save them to the specified file or 333// print them out after codegen. 339if (useAIXSystemAssembler())
340if (!runAIXSystemAssembler(Filename))
344 *
Name = NativeObjectPath.c_str();
348std::unique_ptr<MemoryBuffer>
351if (!compileOptimizedToFile(&
name))
354// read .o file into memory buffer 356name,
/*IsText=*/false,
/*RequiresNullTerminator=*/false);
357if (std::error_code EC = BufferOrErr.
getError()) {
358 emitError(EC.message());
366return std::move(*BufferOrErr);
373return compileOptimizedToFile(
Name);
383bool LTOCodeGenerator::determineTarget() {
387 TripleStr = MergedModule->getTargetTriple();
388if (TripleStr.empty()) {
390 MergedModule->setTargetTriple(TripleStr);
394// create target machine from info for merged modules 402// Construct LTOModule, hand over ownership of module and target. Use MAttr as 403// the default set of features. 405 Features.getDefaultSubtargetFeatures(
Triple);
406 FeatureStr = Features.getString();
407if (Config.
CPU.empty())
410// If data-sections is not explicitly set or unset, set data-sections by 411// default to match the behaviour of lld and gold plugin. 415 TargetMach = createTargetMachine();
416assert(TargetMach &&
"Unable to create target machine");
421std::unique_ptr<TargetMachine> LTOCodeGenerator::createTargetMachine() {
422assert(MArch &&
"MArch is not set!");
428// If a linkonce global is present in the MustPreserveSymbols, we need to make 429// sure we honor this. To force the compiler to not drop it, we add it to the 430// "llvm.compiler.used" global. 431void LTOCodeGenerator::preserveDiscardableGVs(
434 std::vector<GlobalValue *>
Used;
436if (!GV.isDiscardableIfUnused() || GV.isDeclaration() ||
439if (GV.hasAvailableExternallyLinkage())
441 (
Twine(
"Linker asked to preserve available_externally global: '") +
442 GV.getName() +
"'").str());
443if (GV.hasInternalLinkage())
444return emitWarning((
Twine(
"Linker asked to preserve internal global: '") +
445 GV.getName() +
"'").str());
448for (
auto &GV : TheModule)
449 mayPreserveGlobal(GV);
450for (
auto &GV : TheModule.globals())
451 mayPreserveGlobal(GV);
452for (
auto &GV : TheModule.aliases())
453 mayPreserveGlobal(GV);
461void LTOCodeGenerator::applyScopeRestrictions() {
462if (ScopeRestrictionsDone)
465// Declare a callback for the internalize pass that will ask for every 466// candidate GlobalValue if it can be internalized or not. 470// Unnamed globals can't be mangled, but they can't be preserved either. 474// Need to mangle the GV as the "MustPreserveSymbols" StringSet is filled 475// with the linker supplied name, which on Darwin includes a leading 478 MangledName.
reserve(GV.getName().size() + 1);
480return MustPreserveSymbols.
count(MangledName);
483// Preserve linkonce value on linker request 486if (!ShouldInternalize)
489if (ShouldRestoreGlobalsLinkage) {
490// Record the linkage type of non-local symbols so they can be restored 492// to module splitting. 494if (!GV.hasAvailableExternallyLinkage() && !GV.hasLocalLinkage() &&
496 ExternalSymbols.
insert(std::make_pair(GV.getName(), GV.getLinkage()));
498for (
auto &GV : *MergedModule)
500for (
auto &GV : MergedModule->globals())
502for (
auto &GV : MergedModule->aliases())
506// Update the llvm.compiler_used globals to force preserving libcalls and 507// symbols referenced from asm 512 ScopeRestrictionsDone =
true;
515/// Restore original linkage for symbols that may have been internalized 516void LTOCodeGenerator::restoreLinkageForExternals() {
517if (!ShouldInternalize || !ShouldRestoreGlobalsLinkage)
520assert(ScopeRestrictionsDone &&
521"Cannot externalize without internalization!");
523if (ExternalSymbols.
empty())
527if (!GV.hasLocalLinkage() || !GV.hasName())
530autoI = ExternalSymbols.
find(GV.getName());
531if (
I == ExternalSymbols.
end())
534 GV.setLinkage(
I->second);
542void LTOCodeGenerator::verifyMergedModuleOnce() {
543// Only run on the first call. 546 HasVerifiedInput =
true;
548bool BrokenDebugInfo =
false;
551if (BrokenDebugInfo) {
552 emitWarning(
"Invalid debug info found, debug info will be stripped");
557void LTOCodeGenerator::finishOptimizationRemarks() {
558if (DiagnosticOutputFile) {
559 DiagnosticOutputFile->keep();
560// FIXME: LTOCodeGenerator dtor is not invoked on Darwin 561 DiagnosticOutputFile->os().flush();
565/// Optimize merged modules using various IPO passes 567if (!this->determineTarget())
570// libLTO parses options late, so re-set them here. 577errs() <<
"Error: " <<
toString(DiagFileOrErr.takeError()) <<
"\n";
580 DiagnosticOutputFile = std::move(*DiagFileOrErr);
582// Setup output file to emit statistics. 584if (!StatsFileOrErr) {
585errs() <<
"Error: " <<
toString(StatsFileOrErr.takeError()) <<
"\n";
588 StatsFile = std::move(StatsFileOrErr.get());
590// Currently there is no support for enabling whole program visibility via a 591// linker option in the old LTO API, but this call allows it to be specified 592// via the internal option. Must be done before WPD invoked via the optimizer 593// pipeline run below. 595/* WholeProgramVisibilityEnabledInLTO */false);
598/* WholeProgramVisibilityEnabledInLTO */false,
599// FIXME: These need linker information via a 601/*DynamicExportSymbols=*/{},
602/*ValidateAllVtablesHaveTypeInfos=*/false,
603/*IsVisibleToRegularObj=*/[](
StringRef) {
returntrue; });
605// We always run the verifier once on the merged module, the `DisableVerify` 606// parameter only applies to subsequent verify. 607 verifyMergedModuleOnce();
609// Mark which symbols can not be internalized 610 this->applyScopeRestrictions();
612// Add an appropriate DataLayout instance for this module... 613 MergedModule->setDataLayout(TargetMach->createDataLayout());
615if (!SaveIRBeforeOptPath.empty()) {
620" to save optimized bitcode\n");
622/* ShouldPreserveUseListOrder */true);
626 TargetMach = createTargetMachine();
627if (!
opt(Config, TargetMach.get(), 0, *MergedModule,
/*IsThinLTO=*/false,
628/*ExportSummary=*/&CombinedIndex,
/*ImportSummary=*/nullptr,
629/*CmdArgs*/ std::vector<uint8_t>())) {
630 emitError(
"LTO middle-end optimizations failed");
638unsigned ParallelismLevel) {
639if (!this->determineTarget())
642// We always run the verifier once on the merged module. If it has already 643// been called in optimize(), this call will return early. 644 verifyMergedModuleOnce();
646// Re-externalize globals that may have been internalized to increase scope 648 restoreLinkageForExternals();
653Error Err = backend(Config, AddStream, ParallelismLevel, *MergedModule,
655assert(!Err &&
"unexpected code-generation failure");
658// If statistics were requested, save them to the specified file or 659// print them out after codegen. 667 finishOptimizationRemarks();
674 CodegenOptions.push_back(Option.str());
678if (!CodegenOptions.empty())
684// ParseCommandLineOptions() expects argv[0] to be program name. 685 std::vector<const char *> CodegenArgv(1,
"libLLVMLTO");
687 CodegenArgv.push_back(Arg.c_str());
693// Map the LLVM internal diagnostic severity to the LTO diagnostic severity. 709// Create the string that will be reported to the external diagnostic handler. 710 std::string MsgStorage;
716// If this method has been called it means someone has set up an external 717// diagnostic handler. Assert on that. 718assert(DiagHandler &&
"Invalid diagnostic handler");
719 (*DiagHandler)(Severity, MsgStorage.c_str(), DiagContext);
726 : CodeGenerator(CodeGenPtr) {}
737 this->DiagHandler = DiagHandler;
738 this->DiagContext = Ctxt;
741// Register the LTOCodeGenerator stub in the LLVMContext to forward the 742// diagnostic to the external DiagHandler. 757void LTOCodeGenerator::emitError(
const std::string &ErrMsg) {
759 (*DiagHandler)(
LTO_DS_ERROR, ErrMsg.c_str(), DiagContext);
761 Context.
diagnose(LTODiagnosticInfo(ErrMsg));
764void LTOCodeGenerator::emitWarning(
const std::string &ErrMsg) {
static bool mustPreserveGV(const GlobalValue &GV)
Predicate for Internalize pass.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug
This file implements a simple parser to decode commandline option for remarks hotness threshold that ...
Module.h This file contains the declarations for the Module class.
This header defines classes/functions to handle pass execution timing information with interfaces for...
Provides a library for accessing information about this process and other processes on the operating ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static void externalize(GlobalValue *GV)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
This file contains some functions that are useful when dealing with strings.
This pass exposes codegen information to IR-level passes.
static void DiagHandler(const SMDiagnostic &Diag, void *Context)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This is the base abstract class for diagnostic reporting in the backend.
DiagnosticSeverity getSeverity() const
virtual void print(DiagnosticPrinter &DP) const =0
Print using the given DP a user-friendly message.
Basic diagnostic printer that uses an underlying raw_ostream.
Interface for custom diagnostic printing.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
This is an important class for using LLVM in a threaded context.
void enableDebugTypeODRUniquing()
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
void setDiscardValueNames(bool Discard)
Set the Context runtime configuration to discard all value name (but GlobalValue).
void setDiagnosticHandler(std::unique_ptr< DiagnosticHandler > &&DH, bool RespectFilters=false)
setDiagnosticHandler - This method sets unique_ptr to object of DiagnosticHandler to provide custom d...
This class provides the core functionality of linking in LLVM.
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
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.
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void reserve(size_type N)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
iterator find(StringRef Key)
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringRef - Represent a constant reference to a string, i.e.
std::pair< typename Base::iterator, bool > insert(StringRef key)
Manages the enabling and disabling of subtarget specific features.
unsigned DataSections
Emit data into separate sections.
unsigned DisableIntegratedAS
Disable the integrated assembler.
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOptLevel OL=CodeGenOptLevel::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
This class contains a raw_fd_ostream and adds a few extra features commonly needed for compiler-like ...
void keep()
Indicate that the tool's job wrt this output file has been successful and the file should not be dele...
raw_fd_ostream & os()
Return the contained raw_fd_ostream.
Triple - Helper class for working with autoconf configuration names.
bool isOSAIX() const
Tests whether the OS is AIX.
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
An efficient, type-erasing, non-owning reference to a callable.
A raw_ostream that writes to a file descriptor.
bool has_error() const
Return the value of the flag in this raw_fd_ostream indicating whether an output error has been encou...
std::error_code error() const
void close()
Manually flush the stream and close the file.
void clear_error()
Set the flag read by has_error() to false.
A raw_ostream that writes to an std::string.
static std::optional< std::string > GetEnv(StringRef name)
lto_codegen_diagnostic_severity_t
Diagnostic severity.
void(* lto_diagnostic_handler_t)(lto_codegen_diagnostic_severity_t severity, const char *diag, void *ctxt)
Diagnostic handler type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
std::optional< CodeGenOptLevel > getLevel(int OL)
Get the Level identified by the integer OL.
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
initializer< Ty > init(const Ty &Val)
std::optional< bool > getExplicitDataSections()
StringLiteral getThinLTODefaultCPU(const Triple &TheTriple)
Expected< std::unique_ptr< ToolOutputFile > > setupStatsFile(StringRef StatsFilename)
Setups the output file for saving statistics.
Expected< std::unique_ptr< ToolOutputFile > > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, std::optional< uint64_t > RemarksHotnessThreshold=0, int Count=-1)
Setup optimization remarks.
std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None)
Create a file in the system temporary directory.
int ExecuteAndWait(StringRef Program, ArrayRef< StringRef > Args, std::optional< ArrayRef< StringRef > > Env=std::nullopt, ArrayRef< std::optional< StringRef > > Redirects={}, unsigned SecondsToWait=0, unsigned MemoryLimit=0, std::string *ErrMsg=nullptr, bool *ExecutionFailed=nullptr, std::optional< ProcessStatistics > *ProcStat=nullptr, BitVector *AffinityMask=nullptr)
This function executes the program using the arguments provided.
std::string getDefaultTargetTriple()
getDefaultTargetTriple() - Return the default target triple the compiler has been configured to produ...
This is an optimization pass for GlobalISel generic memory operations.
cl::opt< std::string > RemarksFormat("lto-pass-remarks-format", cl::desc("The format used for serializing remarks (default: YAML)"), cl::value_desc("format"), cl::init("yaml"))
UnaryFunction for_each(R &&Range, UnaryFunction F)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly.
cl::opt< bool > LTODiscardValueNames("lto-discard-value-names", cl::desc("Strip names from Value during LTO (other than GlobalValue)."), cl::init(false), cl::Hidden)
void WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
bool internalizeModule(Module &TheModule, std::function< bool(const GlobalValue &)> MustPreserveGV)
Helper function to internalize functions and variables in a Module.
cl::opt< std::string > LTOCSIRProfile("cs-profile-path", cl::desc("Context sensitive profile file path"))
cl::opt< std::string > RemarksPasses("lto-pass-remarks-filter", cl::desc("Only record optimization remarks from passes whose " "names match the given regular expression"), cl::value_desc("regex"))
std::function< Expected< std::unique_ptr< CachedFileStream > >(unsigned Task, const Twine &ModuleName)> AddStreamFn
This type defines the callback to add a file that is generated on the fly.
void updateCompilerUsed(Module &TheModule, const TargetMachine &TM, const StringSet<> &AsmUndefinedRefs)
Find all globals in TheModule that are referenced in AsmUndefinedRefs, as well as the user-supplied f...
void reportAndResetTimings(raw_ostream *OutStream=nullptr)
If -time-passes has been specified, report the timings immediately and then reset the timers to zero.
cl::opt< std::string > AIXSystemAssemblerPath("lto-aix-system-assembler", cl::desc("Path to a system assembler, picked up on AIX only"), cl::value_desc("path"))
void updatePublicTypeTestCalls(Module &M, bool WholeProgramVisibilityEnabledInLTO)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool AreStatisticsEnabled()
Check if statistics are enabled.
cl::opt< bool > RemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
cl::opt< std::string > RemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
void parseCommandLineOptions(std::vector< std::string > &Options)
A convenience function that calls cl::ParseCommandLineOptions on the given set of options.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
@ Mod
The access may modify the value stored in memory.
void PrintStatistics()
Print statistics to the file returned by CreateInfoOutputFile().
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
cl::opt< std::optional< uint64_t >, false, remarks::HotnessThresholdParser > RemarksHotnessThreshold("lto-pass-remarks-hotness-threshold", cl::desc("Minimum profile count required for an " "optimization remark to be output." " Use 'auto' to apply the threshold from profile summary."), cl::value_desc("uint or 'auto'"), cl::init(0), cl::Hidden)
const char * toString(DWARFSectionKind Kind)
cl::opt< std::string > LTOStatsFile("lto-stats-file", cl::desc("Save statistics to the specified file"), cl::Hidden)
void PrintStatisticsJSON(raw_ostream &OS)
Print statistics in JSON format.
cl::opt< bool > LTORunCSIRInstr("cs-profile-generate", cl::desc("Perform context sensitive PGO instrumentation"))
void updateVCallVisibilityInModule(Module &M, bool WholeProgramVisibilityEnabledInLTO, const DenseSet< GlobalValue::GUID > &DynamicExportSymbols, bool ValidateAllVtablesHaveTypeInfos, function_ref< bool(StringRef)> IsVisibleToRegularObj)
If whole program visibility asserted, then upgrade all public vcall visibility metadata on vtable def...
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
This is the base class for diagnostic handling in LLVM.
C++ class which implements the opaque lto_code_gen_t type.
bool optimize()
Optimizes the merged module.
std::unique_ptr< MemoryBuffer > compile()
As with compile_to_file(), this function compiles the merged module into single output file.
void setModule(std::unique_ptr< LTOModule > M)
Set the destination module.
bool compile_to_file(const char **Name)
Compile the merged module into a single output file; the path to output file is returned to the calle...
void parseCodeGenDebugOptions()
Parse the options set in setCodeGenDebugOptions.
void setOptLevel(unsigned OptLevel)
void setAsmUndefinedRefs(struct LTOModule *)
void setDiagnosticHandler(lto_diagnostic_handler_t, void *)
void setFileType(CodeGenFileType FT)
Set the file type to be emitted (assembly or object code).
void setTargetOptions(const TargetOptions &Options)
void setCodeGenDebugOptions(ArrayRef< StringRef > Opts)
Pass options to the driver and optimization passes.
LTOCodeGenerator(LLVMContext &Context)
std::unique_ptr< MemoryBuffer > compileOptimized()
Compiles the merged optimized module into a single output file.
bool addModule(struct LTOModule *)
Merge given module.
void setDebugInfo(lto_debug_model)
bool writeMergedModules(StringRef Path)
Write the merged module to the file specified by the given path.
void DiagnosticHandler(const DiagnosticInfo &DI)
static const char * getVersionString()
C++ class which implements the opaque lto_module_t type.
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
std::string StatsFile
Statistics output file path.
std::optional< CodeModel::Model > CodeModel
bool CodeGenOnly
Disable entirely the optimizer, including importing for ThinLTO.
std::vector< std::string > MAttrs
CodeGenOptLevel CGOptLevel
PipelineTuningOptions PTO
Tunable parameters for passes in the default pipelines.
bool RunCSIRInstr
Run PGO context sensitive IR instrumentation.
std::string CSIRProfile
Context Sensitive PGO profile path.
std::optional< Reloc::Model > RelocModel
CodeGenFileType CGFileType