LLVM 20.0.0git
Public Types | Public Member Functions | Public Attributes | List of all members
llvm::lto::Config Struct Reference

LTO configuration. More...

#include "llvm/LTO/Config.h"

Public Types

enum  VisScheme { FromPrevailing , ELF }
 
using ModuleHookFn = std::function< bool(unsigned Task, const Module &)>
 The following callbacks deal with tasks, which normally represent the entire optimization and code generation pipeline for what will become a single native object file.
 
using CombinedIndexHookFn = std::function< bool(const ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)>
 A combined index hook is called after all per-module indexes have been combined (ThinLTO-specific).
 

Public Member Functions

Error addSaveTemps (std::string OutputFileName, bool UseInputModulePath=false, const DenseSet< StringRef > &SaveTempsArgs={})
 This is a convenience function that configures this Config object to write temporary files named after the given OutputFileName for each of the LTO phases to disk.
 

Public Attributes

std::string CPU
 
TargetOptions Options
 
std::vector< std::string > MAttrs
 
std::vector< std::string > MllvmArgs
 
std::vector< std::string > PassPlugins
 
std::function< void(legacy::PassManager &)> PreCodeGenPassesHook
 For adding passes that run right before codegen.
 
std::optional< Reloc::ModelRelocModel = Reloc::PIC_
 
std::optional< CodeModel::ModelCodeModel
 
CodeGenOptLevel CGOptLevel = CodeGenOptLevel::Default
 
CodeGenFileType CGFileType = CodeGenFileType::ObjectFile
 
unsigned OptLevel = 2
 
bool VerifyEach = false
 
bool DisableVerify = false
 
bool Freestanding = false
 Flag to indicate that the optimizer should not assume builtins are present on the target.
 
bool CodeGenOnly = false
 Disable entirely the optimizer, including importing for ThinLTO.
 
bool RunCSIRInstr = false
 Run PGO context sensitive IR instrumentation.
 
bool PGOWarnMismatch = true
 Turn on/off the warning about a hash mismatch in the PGO profile data.
 
bool HasWholeProgramVisibility = false
 Asserts whether we can assume whole program visibility during the LTO link.
 
bool ValidateAllVtablesHaveTypeInfos = false
 We're validating that all native vtables have corresponding type infos.
 
bool AllVtablesHaveTypeInfos = false
 If all native vtables have corresponding type infos, allow usage of RTTI to block devirtualization on types used in native files.
 
bool AlwaysEmitRegularLTOObj = false
 Always emit a Regular LTO object even when it is empty because no Regular LTO modules were linked.
 
bool KeepSymbolNameCopies = true
 If true, the LTO instance creates copies of the symbol names for LTO::run.
 
VisScheme VisibilityScheme = FromPrevailing
 Allows non-imported definitions to get the potentially more constraining visibility from the prevailing definition.
 
std::string OptPipeline
 If this field is set, the set of passes run in the middle-end optimizer will be the one specified by the string.
 
std::string AAPipeline
 
std::string OverrideTriple
 Setting this field will replace target triples in input files with this triple.
 
std::string DefaultTriple
 Setting this field will replace unspecified target triples in input files with this triple.
 
std::string CSIRProfile
 Context Sensitive PGO profile path.
 
std::string SampleProfile
 Sample PGO profile path.
 
std::string ProfileRemapping
 Name remapping file for profile data.
 
std::string DwoDir
 The directory to store .dwo files.
 
std::string SplitDwarfFile
 The name for the split debug info file used for the DW_AT_[GNU_]dwo_name attribute in the skeleton CU.
 
std::string SplitDwarfOutput
 The path to write a .dwo file to.
 
std::string RemarksFilename
 Optimization remarks file path.
 
std::string RemarksPasses
 Optimization remarks pass filter.
 
bool RemarksWithHotness = false
 Whether to emit optimization remarks with hotness informations.
 
std::optional< uint64_tRemarksHotnessThreshold = 0
 The minimum hotness value a diagnostic needs in order to be included in optimization diagnostics.
 
std::string RemarksFormat
 The format used for serializing remarks (default: YAML).
 
bool DebugPassManager = false
 Whether to emit the pass manager debuggging informations.
 
std::string StatsFile
 Statistics output file path.
 
std::vector< std::string > ThinLTOModulesToCompile
 Specific thinLTO modules to compile.
 
bool TimeTraceEnabled = false
 Time trace enabled.
 
unsigned TimeTraceGranularity = 500
 Time trace granularity.
 
bool ShouldDiscardValueNames = true
 
DiagnosticHandlerFunction DiagHandler
 
bool AddFSDiscriminator = false
 Add FSAFDO discriminators.
 
std::unique_ptr< raw_ostreamResolutionFile
 If this field is set, LTO will write input file paths and symbol resolutions here in llvm-lto2 command line flag format.
 
PipelineTuningOptions PTO
 Tunable parameters for passes in the default pipelines.
 
ModuleHookFn PreOptModuleHook
 This module hook is called after linking (regular LTO) or loading (ThinLTO) the module, before modifying it.
 
ModuleHookFn PostPromoteModuleHook
 This hook is called after promoting any internal functions (ThinLTO-specific).
 
ModuleHookFn PostInternalizeModuleHook
 This hook is called after internalizing the module.
 
ModuleHookFn PostImportModuleHook
 This hook is called after importing from other modules (ThinLTO-specific).
 
ModuleHookFn PostOptModuleHook
 This module hook is called after optimization is complete.
 
ModuleHookFn PreCodeGenModuleHook
 This module hook is called before code generation.
 
CombinedIndexHookFn CombinedIndexHook
 

Detailed Description

LTO configuration.

A linker can configure LTO by setting fields in this data structure and passing it to the lto::LTO constructor.

Definition at line 41 of file Config.h.

Member Typedef Documentation

◆ CombinedIndexHookFn

A combined index hook is called after all per-module indexes have been combined (ThinLTO-specific).

It can be used to implement -save-temps for the combined index.

If this function returns false, any further processing for ThinLTO tasks is aborted.

It is called regardless of whether the backend is in-process, although it is not called from individual backend processes.

Definition at line 257 of file Config.h.

◆ ModuleHookFn

using llvm::lto::Config::ModuleHookFn = std::function<bool(unsigned Task, const Module &)>

The following callbacks deal with tasks, which normally represent the entire optimization and code generation pipeline for what will become a single native object file.

Each task has a unique identifier between 0 and getMaxTasks()-1, which is supplied to the callback via the Task parameter. A task represents the entire pipeline for ThinLTO and regular (non-parallel) LTO, but a parallel code generation task will be split into N tasks before code generation, where N is the parallelism level.

LTO may decide to stop processing a task at any time, for example if the module is empty or if a module hook (see below) returns false. For this reason, the client should not expect to receive exactly getMaxTasks() native object files. A module hook may be used by a linker to perform actions during the LTO pipeline. For example, a linker may use this function to implement -save-temps. If this function returns false, any further processing for that task is aborted.

Module hooks must be thread safe with respect to the linker's internal data structures. A module hook will never be called concurrently from multiple threads with the same task ID, or the same module.

Note that in out-of-process backend scenarios, none of the hooks will be called for ThinLTO tasks.

Definition at line 224 of file Config.h.

Member Enumeration Documentation

◆ VisScheme

Enumerator
FromPrevailing 
ELF 

Definition at line 42 of file Config.h.

Member Function Documentation

◆ addSaveTemps()

Error Config::addSaveTemps ( std::string  OutputFileName,
bool  UseInputModulePath = false,
const DenseSet< StringRef > &  SaveTempsArgs = {} 
)

This is a convenience function that configures this Config object to write temporary files named after the given OutputFileName for each of the LTO phases to disk.

A client can use this function to implement -save-temps.

FIXME: Temporary files derived from ThinLTO backends are currently named after the input file name, rather than the output file name, when UseInputModulePath is set to true.

Specifically, it (1) sets each of the above module hooks and the combined index hook to a function that calls the hook function (if any) that was present in the appropriate field when the addSaveTemps function was called, and writes the module to a bitcode file with a name prefixed by the given output file name, and (2) creates a resolution file whose name is prefixed by the given output file name and sets ResolutionFile to its file handle.

SaveTempsArgs can be specified to select which temps to save. If SaveTempsArgs is not provided, all temps are saved.

Definition at line 88 of file LTOBackend.cpp.

References CombinedIndexHook, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::contains(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::empty(), llvm::errorCodeToError(), llvm::sys::fs::OF_None, llvm::sys::fs::OF_Text, llvm::sys::fs::OF_TextWithCRLF, OS, PostImportModuleHook, PostInternalizeModuleHook, PostOptModuleHook, PostPromoteModuleHook, PreCodeGenModuleHook, PreOptModuleHook, reportOpenError(), ResolutionFile, ShouldDiscardValueNames, llvm::Error::success(), llvm::WriteBitcodeToFile(), and llvm::writeIndexToFile().

Member Data Documentation

◆ AAPipeline

std::string llvm::lto::Config::AAPipeline

Definition at line 110 of file Config.h.

Referenced by llvm::computeLTOCacheKey(), and runNewPMPasses().

◆ AddFSDiscriminator

bool llvm::lto::Config::AddFSDiscriminator = false

Add FSAFDO discriminators.

Definition at line 189 of file Config.h.

Referenced by runNewPMPasses().

◆ AllVtablesHaveTypeInfos

bool llvm::lto::Config::AllVtablesHaveTypeInfos = false

If all native vtables have corresponding type infos, allow usage of RTTI to block devirtualization on types used in native files.

Definition at line 84 of file Config.h.

◆ AlwaysEmitRegularLTOObj

bool llvm::lto::Config::AlwaysEmitRegularLTOObj = false

Always emit a Regular LTO object even when it is empty because no Regular LTO modules were linked.

This option is useful for some build system which want to know a priori all possible output files.

Definition at line 89 of file Config.h.

◆ CGFileType

CodeGenFileType llvm::lto::Config::CGFileType = CodeGenFileType::ObjectFile

Definition at line 58 of file Config.h.

Referenced by codegen(), llvm::computeLTOCacheKey(), and llvm::LTOCodeGenerator::setFileType().

◆ CGOptLevel

CodeGenOptLevel llvm::lto::Config::CGOptLevel = CodeGenOptLevel::Default

◆ CodeGenOnly

bool llvm::lto::Config::CodeGenOnly = false

Disable entirely the optimizer, including importing for ThinLTO.

Definition at line 68 of file Config.h.

Referenced by llvm::LTOCodeGenerator::compileOptimized().

◆ CodeModel

std::optional<CodeModel::Model> llvm::lto::Config::CodeModel

◆ CombinedIndexHook

CombinedIndexHookFn llvm::lto::Config::CombinedIndexHook

Definition at line 260 of file Config.h.

Referenced by addSaveTemps().

◆ CPU

std::string llvm::lto::Config::CPU

◆ CSIRProfile

std::string llvm::lto::Config::CSIRProfile

Context Sensitive PGO profile path.

Definition at line 121 of file Config.h.

Referenced by llvm::LTOCodeGenerator::LTOCodeGenerator(), and runNewPMPasses().

◆ DebugPassManager

bool llvm::lto::Config::DebugPassManager = false

Whether to emit the pass manager debuggging informations.

Definition at line 171 of file Config.h.

Referenced by runNewPMPasses(), and llvm::LTOCodeGenerator::setDebugPassManager().

◆ DefaultTriple

std::string llvm::lto::Config::DefaultTriple

Setting this field will replace unspecified target triples in input files with this triple.

Definition at line 118 of file Config.h.

Referenced by llvm::computeLTOCacheKey().

◆ DiagHandler

DiagnosticHandlerFunction llvm::lto::Config::DiagHandler

Definition at line 186 of file Config.h.

◆ DisableVerify

bool llvm::lto::Config::DisableVerify = false

Definition at line 61 of file Config.h.

Referenced by runNewPMPasses(), and llvm::LTOCodeGenerator::setDisableVerify().

◆ DwoDir

std::string llvm::lto::Config::DwoDir

The directory to store .dwo files.

Definition at line 130 of file Config.h.

Referenced by codegen(), and llvm::computeLTOCacheKey().

◆ Freestanding

bool llvm::lto::Config::Freestanding = false

Flag to indicate that the optimizer should not assume builtins are present on the target.

Definition at line 65 of file Config.h.

Referenced by llvm::computeLTOCacheKey(), runNewPMPasses(), and llvm::LTOCodeGenerator::setFreestanding().

◆ HasWholeProgramVisibility

bool llvm::lto::Config::HasWholeProgramVisibility = false

Asserts whether we can assume whole program visibility during the LTO link.

Definition at line 78 of file Config.h.

◆ KeepSymbolNameCopies

bool llvm::lto::Config::KeepSymbolNameCopies = true

If true, the LTO instance creates copies of the symbol names for LTO::run.

The lld linker uses string saver to keep symbol names alive and doesn't need to create copies, so it can set this field to false.

Definition at line 94 of file Config.h.

Referenced by llvm::lto::LTO::LTO().

◆ MAttrs

std::vector<std::string> llvm::lto::Config::MAttrs

◆ MllvmArgs

std::vector<std::string> llvm::lto::Config::MllvmArgs

Definition at line 51 of file Config.h.

Referenced by llvm::computeLTOCacheKey().

◆ Options

TargetOptions llvm::lto::Config::Options

◆ OptLevel

unsigned llvm::lto::Config::OptLevel = 2

◆ OptPipeline

std::string llvm::lto::Config::OptPipeline

If this field is set, the set of passes run in the middle-end optimizer will be the one specified by the string.

Only works with the new pass manager as the old one doesn't have this ability.

Definition at line 105 of file Config.h.

Referenced by llvm::computeLTOCacheKey(), and runNewPMPasses().

◆ OverrideTriple

std::string llvm::lto::Config::OverrideTriple

Setting this field will replace target triples in input files with this triple.

Definition at line 114 of file Config.h.

Referenced by llvm::computeLTOCacheKey().

◆ PassPlugins

std::vector<std::string> llvm::lto::Config::PassPlugins

Definition at line 52 of file Config.h.

Referenced by runNewPMPasses().

◆ PGOWarnMismatch

bool llvm::lto::Config::PGOWarnMismatch = true

Turn on/off the warning about a hash mismatch in the PGO profile data.

Definition at line 74 of file Config.h.

Referenced by runNewPMPasses().

◆ PostImportModuleHook

ModuleHookFn llvm::lto::Config::PostImportModuleHook

This hook is called after importing from other modules (ThinLTO-specific).

Definition at line 238 of file Config.h.

Referenced by addSaveTemps(), and llvm::lto::thinBackend().

◆ PostInternalizeModuleHook

ModuleHookFn llvm::lto::Config::PostInternalizeModuleHook

This hook is called after internalizing the module.

Definition at line 235 of file Config.h.

Referenced by addSaveTemps(), and llvm::lto::thinBackend().

◆ PostOptModuleHook

ModuleHookFn llvm::lto::Config::PostOptModuleHook

This module hook is called after optimization is complete.

Definition at line 241 of file Config.h.

Referenced by addSaveTemps(), and llvm::lto::opt().

◆ PostPromoteModuleHook

ModuleHookFn llvm::lto::Config::PostPromoteModuleHook

This hook is called after promoting any internal functions (ThinLTO-specific).

Definition at line 232 of file Config.h.

Referenced by addSaveTemps(), and llvm::lto::thinBackend().

◆ PreCodeGenModuleHook

ModuleHookFn llvm::lto::Config::PreCodeGenModuleHook

This module hook is called before code generation.

It is similar to the PostOptModuleHook, but for parallel code generation it is called after splitting the module.

Definition at line 246 of file Config.h.

Referenced by addSaveTemps(), and codegen().

◆ PreCodeGenPassesHook

std::function<void(legacy::PassManager &)> llvm::lto::Config::PreCodeGenPassesHook

For adding passes that run right before codegen.

Definition at line 54 of file Config.h.

Referenced by codegen().

◆ PreOptModuleHook

ModuleHookFn llvm::lto::Config::PreOptModuleHook

This module hook is called after linking (regular LTO) or loading (ThinLTO) the module, before modifying it.

Definition at line 228 of file Config.h.

Referenced by addSaveTemps(), and llvm::lto::thinBackend().

◆ ProfileRemapping

std::string llvm::lto::Config::ProfileRemapping

Name remapping file for profile data.

Definition at line 127 of file Config.h.

Referenced by llvm::computeLTOCacheKey(), and runNewPMPasses().

◆ PTO

PipelineTuningOptions llvm::lto::Config::PTO

Tunable parameters for passes in the default pipelines.

Definition at line 198 of file Config.h.

Referenced by runNewPMPasses(), and llvm::LTOCodeGenerator::setOptLevel().

◆ RelocModel

std::optional<Reloc::Model> llvm::lto::Config::RelocModel = Reloc::PIC_

◆ RemarksFilename

std::string llvm::lto::Config::RemarksFilename

Optimization remarks file path.

Definition at line 144 of file Config.h.

Referenced by llvm::lto::thinBackend().

◆ RemarksFormat

std::string llvm::lto::Config::RemarksFormat

The format used for serializing remarks (default: YAML).

Definition at line 168 of file Config.h.

Referenced by llvm::lto::thinBackend().

◆ RemarksHotnessThreshold

std::optional<uint64_t> llvm::lto::Config::RemarksHotnessThreshold = 0

The minimum hotness value a diagnostic needs in order to be included in optimization diagnostics.

The threshold is an Optional value, which maps to one of the 3 states:

  1. 0 => threshold disabled. All emarks will be printed.
  2. positive int => manual threshold by user. Remarks with hotness exceed threshold will be printed.
  3. None => 'auto' threshold by user. The actual value is not available at command line, but will be synced with hotness threhold from profile summary during compilation.

If threshold option is not specified, it is disabled by default.

Definition at line 165 of file Config.h.

Referenced by llvm::lto::thinBackend().

◆ RemarksPasses

std::string llvm::lto::Config::RemarksPasses

Optimization remarks pass filter.

Definition at line 147 of file Config.h.

Referenced by llvm::lto::thinBackend().

◆ RemarksWithHotness

bool llvm::lto::Config::RemarksWithHotness = false

Whether to emit optimization remarks with hotness informations.

Definition at line 150 of file Config.h.

Referenced by llvm::lto::thinBackend().

◆ ResolutionFile

std::unique_ptr<raw_ostream> llvm::lto::Config::ResolutionFile

If this field is set, LTO will write input file paths and symbol resolutions here in llvm-lto2 command line flag format.

This can be used for testing and for running the LTO pipeline outside of the linker with llvm-lto2.

Definition at line 195 of file Config.h.

Referenced by llvm::lto::LTO::add(), and addSaveTemps().

◆ RunCSIRInstr

bool llvm::lto::Config::RunCSIRInstr = false

Run PGO context sensitive IR instrumentation.

Definition at line 71 of file Config.h.

Referenced by llvm::LTOCodeGenerator::LTOCodeGenerator(), and runNewPMPasses().

◆ SampleProfile

std::string llvm::lto::Config::SampleProfile

Sample PGO profile path.

Definition at line 124 of file Config.h.

Referenced by llvm::computeLTOCacheKey(), and runNewPMPasses().

◆ ShouldDiscardValueNames

bool llvm::lto::Config::ShouldDiscardValueNames = true

Definition at line 185 of file Config.h.

Referenced by addSaveTemps().

◆ SplitDwarfFile

std::string llvm::lto::Config::SplitDwarfFile

The name for the split debug info file used for the DW_AT_[GNU_]dwo_name attribute in the skeleton CU.

This should generally only be used when running an individual backend directly via thinBackend(), as otherwise all objects would use the same .dwo file. Not used as output path.

Definition at line 136 of file Config.h.

Referenced by codegen().

◆ SplitDwarfOutput

std::string llvm::lto::Config::SplitDwarfOutput

The path to write a .dwo file to.

This should generally only be used when running an individual backend directly via thinBackend(), as otherwise all .dwo files will be written to the same path. Not used in skeleton CU.

Definition at line 141 of file Config.h.

Referenced by codegen().

◆ StatsFile

std::string llvm::lto::Config::StatsFile

Statistics output file path.

Definition at line 174 of file Config.h.

Referenced by llvm::LTOCodeGenerator::LTOCodeGenerator(), and llvm::lto::LTO::run().

◆ ThinLTOModulesToCompile

std::vector<std::string> llvm::lto::Config::ThinLTOModulesToCompile

Specific thinLTO modules to compile.

Definition at line 177 of file Config.h.

◆ TimeTraceEnabled

bool llvm::lto::Config::TimeTraceEnabled = false

Time trace enabled.

Definition at line 180 of file Config.h.

◆ TimeTraceGranularity

unsigned llvm::lto::Config::TimeTraceGranularity = 500

Time trace granularity.

Definition at line 183 of file Config.h.

◆ ValidateAllVtablesHaveTypeInfos

bool llvm::lto::Config::ValidateAllVtablesHaveTypeInfos = false

We're validating that all native vtables have corresponding type infos.

Definition at line 81 of file Config.h.

◆ VerifyEach

bool llvm::lto::Config::VerifyEach = false

Definition at line 60 of file Config.h.

Referenced by runNewPMPasses().

◆ VisibilityScheme

VisScheme llvm::lto::Config::VisibilityScheme = FromPrevailing

Allows non-imported definitions to get the potentially more constraining visibility from the prevailing definition.

FromPrevailing is the default because it works for many binary formats. ELF can use the more optimized 'ELF' scheme.

Definition at line 100 of file Config.h.

Referenced by llvm::lto::LTO::add().


The documentation for this struct was generated from the following files: