LLVM  16.0.0git
Config.h
Go to the documentation of this file.
1 //===-Config.h - LLVM Link Time Optimizer Configuration ---------*- C++ -*-===//
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 defines the lto::Config data structure, which allows clients to
10 // configure LTO.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LTO_CONFIG_H
15 #define LLVM_LTO_CONFIG_H
16 
17 #include "llvm/ADT/DenseSet.h"
18 #include "llvm/Config/llvm-config.h"
19 #include "llvm/IR/DiagnosticInfo.h"
20 #include "llvm/IR/GlobalValue.h"
21 #include "llvm/IR/LLVMContext.h"
24 #include "llvm/Support/CodeGen.h"
26 
27 #include <functional>
28 
29 namespace llvm {
30 
31 class Error;
32 class Module;
33 class ModuleSummaryIndex;
34 class raw_pwrite_stream;
35 
36 namespace lto {
37 
38 /// LTO configuration. A linker can configure LTO by setting fields in this data
39 /// structure and passing it to the lto::LTO constructor.
40 struct Config {
41  enum VisScheme {
43  ELF,
44  };
45  // Note: when adding fields here, consider whether they need to be added to
46  // computeCacheKey in LTO.cpp.
47  std::string CPU;
49  std::vector<std::string> MAttrs;
50  std::vector<std::string> MllvmArgs;
51  std::vector<std::string> PassPlugins;
52  /// For adding passes that run right before codegen.
58  unsigned OptLevel = 2;
59  bool DisableVerify = false;
60 
61  /// Use the standard optimization pipeline.
62  bool UseDefaultPipeline = false;
63 
64  /// Flag to indicate that the optimizer should not assume builtins are present
65  /// on the target.
66  bool Freestanding = false;
67 
68  /// Disable entirely the optimizer, including importing for ThinLTO
69  bool CodeGenOnly = false;
70 
71  /// Run PGO context sensitive IR instrumentation.
72  bool RunCSIRInstr = false;
73 
74  /// Turn on/off the warning about a hash mismatch in the PGO profile data.
75  bool PGOWarnMismatch = true;
76 
77  /// Asserts whether we can assume whole program visibility during the LTO
78  /// link.
80 
81  /// Always emit a Regular LTO object even when it is empty because no Regular
82  /// LTO modules were linked. This option is useful for some build system which
83  /// want to know a priori all possible output files.
85 
86  /// Allows non-imported definitions to get the potentially more constraining
87  /// visibility from the prevailing definition. FromPrevailing is the default
88  /// because it works for many binary formats. ELF can use the more optimized
89  /// 'ELF' scheme.
91 
92  /// If this field is set, the set of passes run in the middle-end optimizer
93  /// will be the one specified by the string. Only works with the new pass
94  /// manager as the old one doesn't have this ability.
95  std::string OptPipeline;
96 
97  // If this field is set, it has the same effect of specifying an AA pipeline
98  // identified by the string. Only works with the new pass manager, in
99  // conjunction OptPipeline.
100  std::string AAPipeline;
101 
102  /// Setting this field will replace target triples in input files with this
103  /// triple.
104  std::string OverrideTriple;
105 
106  /// Setting this field will replace unspecified target triples in input files
107  /// with this triple.
108  std::string DefaultTriple;
109 
110  /// Context Sensitive PGO profile path.
111  std::string CSIRProfile;
112 
113  /// Sample PGO profile path.
114  std::string SampleProfile;
115 
116  /// Name remapping file for profile data.
117  std::string ProfileRemapping;
118 
119  /// The directory to store .dwo files.
120  std::string DwoDir;
121 
122  /// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
123  /// attribute in the skeleton CU. This should generally only be used when
124  /// running an individual backend directly via thinBackend(), as otherwise
125  /// all objects would use the same .dwo file. Not used as output path.
126  std::string SplitDwarfFile;
127 
128  /// The path to write a .dwo file to. This should generally only be used when
129  /// running an individual backend directly via thinBackend(), as otherwise
130  /// all .dwo files will be written to the same path. Not used in skeleton CU.
131  std::string SplitDwarfOutput;
132 
133  /// Optimization remarks file path.
134  std::string RemarksFilename;
135 
136  /// Optimization remarks pass filter.
137  std::string RemarksPasses;
138 
139  /// Whether to emit optimization remarks with hotness informations.
140  bool RemarksWithHotness = false;
141 
142  /// The minimum hotness value a diagnostic needs in order to be included in
143  /// optimization diagnostics.
144  ///
145  /// The threshold is an Optional value, which maps to one of the 3 states:
146  /// 1. 0 => threshold disabled. All emarks will be printed.
147  /// 2. positive int => manual threshold by user. Remarks with hotness exceed
148  /// threshold will be printed.
149  /// 3. None => 'auto' threshold by user. The actual value is not
150  /// available at command line, but will be synced with
151  /// hotness threhold from profile summary during
152  /// compilation.
153  ///
154  /// If threshold option is not specified, it is disabled by default.
156 
157  /// The format used for serializing remarks (default: YAML).
158  std::string RemarksFormat;
159 
160  /// Whether to emit the pass manager debuggging informations.
161  bool DebugPassManager = false;
162 
163  /// Statistics output file path.
164  std::string StatsFile;
165 
166  /// Specific thinLTO modules to compile.
167  std::vector<std::string> ThinLTOModulesToCompile;
168 
169  /// Time trace enabled.
170  bool TimeTraceEnabled = false;
171 
172  /// Time trace granularity.
173  unsigned TimeTraceGranularity = 500;
174 
177 
178  /// Add FSAFDO discriminators.
179  bool AddFSDiscriminator = false;
180 
181  /// Use opaque pointer types. Used to call LLVMContext::setOpaquePointers
182  /// unless already set by the `-opaque-pointers` commandline option.
183  bool OpaquePointers = true;
184 
185  /// If this field is set, LTO will write input file paths and symbol
186  /// resolutions here in llvm-lto2 command line flag format. This can be
187  /// used for testing and for running the LTO pipeline outside of the linker
188  /// with llvm-lto2.
189  std::unique_ptr<raw_ostream> ResolutionFile;
190 
191  /// Tunable parameters for passes in the default pipelines.
193 
194  /// The following callbacks deal with tasks, which normally represent the
195  /// entire optimization and code generation pipeline for what will become a
196  /// single native object file. Each task has a unique identifier between 0 and
197  /// getMaxTasks()-1, which is supplied to the callback via the Task parameter.
198  /// A task represents the entire pipeline for ThinLTO and regular
199  /// (non-parallel) LTO, but a parallel code generation task will be split into
200  /// N tasks before code generation, where N is the parallelism level.
201  ///
202  /// LTO may decide to stop processing a task at any time, for example if the
203  /// module is empty or if a module hook (see below) returns false. For this
204  /// reason, the client should not expect to receive exactly getMaxTasks()
205  /// native object files.
206 
207  /// A module hook may be used by a linker to perform actions during the LTO
208  /// pipeline. For example, a linker may use this function to implement
209  /// -save-temps. If this function returns false, any further processing for
210  /// that task is aborted.
211  ///
212  /// Module hooks must be thread safe with respect to the linker's internal
213  /// data structures. A module hook will never be called concurrently from
214  /// multiple threads with the same task ID, or the same module.
215  ///
216  /// Note that in out-of-process backend scenarios, none of the hooks will be
217  /// called for ThinLTO tasks.
218  using ModuleHookFn = std::function<bool(unsigned Task, const Module &)>;
219 
220  /// This module hook is called after linking (regular LTO) or loading
221  /// (ThinLTO) the module, before modifying it.
223 
224  /// This hook is called after promoting any internal functions
225  /// (ThinLTO-specific).
227 
228  /// This hook is called after internalizing the module.
230 
231  /// This hook is called after importing from other modules (ThinLTO-specific).
233 
234  /// This module hook is called after optimization is complete.
236 
237  /// This module hook is called before code generation. It is similar to the
238  /// PostOptModuleHook, but for parallel code generation it is called after
239  /// splitting the module.
241 
242  /// A combined index hook is called after all per-module indexes have been
243  /// combined (ThinLTO-specific). It can be used to implement -save-temps for
244  /// the combined index.
245  ///
246  /// If this function returns false, any further processing for ThinLTO tasks
247  /// is aborted.
248  ///
249  /// It is called regardless of whether the backend is in-process, although it
250  /// is not called from individual backend processes.
251  using CombinedIndexHookFn = std::function<bool(
252  const ModuleSummaryIndex &Index,
253  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols)>;
255 
256  /// This is a convenience function that configures this Config object to write
257  /// temporary files named after the given OutputFileName for each of the LTO
258  /// phases to disk. A client can use this function to implement -save-temps.
259  ///
260  /// FIXME: Temporary files derived from ThinLTO backends are currently named
261  /// after the input file name, rather than the output file name, when
262  /// UseInputModulePath is set to true.
263  ///
264  /// Specifically, it (1) sets each of the above module hooks and the combined
265  /// index hook to a function that calls the hook function (if any) that was
266  /// present in the appropriate field when the addSaveTemps function was
267  /// called, and writes the module to a bitcode file with a name prefixed by
268  /// the given output file name, and (2) creates a resolution file whose name
269  /// is prefixed by the given output file name and sets ResolutionFile to its
270  /// file handle.
271  ///
272  /// SaveTempsArgs can be specified to select which temps to save.
273  /// If SaveTempsArgs is not provided, all temps are saved.
274  Error addSaveTemps(std::string OutputFileName,
275  bool UseInputModulePath = false,
276  const DenseSet<StringRef> &SaveTempsArgs = {});
277 };
278 
282  : Fn(DiagHandlerFn) {}
283  bool handleDiagnostics(const DiagnosticInfo &DI) override {
284  (*Fn)(DI);
285  return true;
286  }
287 };
288 /// A derived class of LLVMContext that initializes itself according to a given
289 /// Config object. The purpose of this class is to tie ownership of the
290 /// diagnostic handler to the context, as opposed to the Config object (which
291 /// may be ephemeral).
292 // FIXME: This should not be required as diagnostic handler is not callback.
294 
296  setDiscardValueNames(C.ShouldDiscardValueNames);
299  std::make_unique<LTOLLVMDiagnosticHandler>(&DiagHandler), true);
301  setOpaquePointers(C.OpaquePointers);
302  }
304 };
305 
306 }
307 }
308 
309 #endif
llvm::LLVMContext::enableDebugTypeODRUniquing
void enableDebugTypeODRUniquing()
Definition: LLVMContext.cpp:342
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::lto::Config::UseDefaultPipeline
bool UseDefaultPipeline
Use the standard optimization pipeline.
Definition: Config.h:62
PassBuilder.h
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
llvm::CGFT_ObjectFile
@ CGFT_ObjectFile
Definition: CodeGen.h:65
llvm::TargetOptions
Definition: TargetOptions.h:124
llvm::lto::Config::DisableVerify
bool DisableVerify
Definition: Config.h:59
llvm::lto::Config::CGOptLevel
CodeGenOpt::Level CGOptLevel
Definition: Config.h:56
llvm::lto::Config::DiagHandler
DiagnosticHandlerFunction DiagHandler
Definition: Config.h:176
llvm::lto::Config::TimeTraceGranularity
unsigned TimeTraceGranularity
Time trace granularity.
Definition: Config.h:173
llvm::lto::Config::RemarksFormat
std::string RemarksFormat
The format used for serializing remarks (default: YAML).
Definition: Config.h:158
llvm::lto::Config::CodeModel
Optional< CodeModel::Model > CodeModel
Definition: Config.h:55
llvm::lto::Config::RemarksWithHotness
bool RemarksWithHotness
Whether to emit optimization remarks with hotness informations.
Definition: Config.h:140
llvm::PipelineTuningOptions
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:38
llvm::lto::Config::ThinLTOModulesToCompile
std::vector< std::string > ThinLTOModulesToCompile
Specific thinLTO modules to compile.
Definition: Config.h:167
llvm::lto::Config::OpaquePointers
bool OpaquePointers
Use opaque pointer types.
Definition: Config.h:183
llvm::LLVMContext::hasSetOpaquePointersValue
bool hasSetOpaquePointersValue() const
Whether we've decided on using opaque pointers or typed pointers yet.
Definition: LLVMContext.cpp:371
llvm::DiagnosticHandler
This is the base class for diagnostic handling in LLVM.
Definition: DiagnosticHandler.h:24
llvm::lto::Config
LTO configuration.
Definition: Config.h:40
llvm::Optional< Reloc::Model >
llvm::lto::Config::Freestanding
bool Freestanding
Flag to indicate that the optimizer should not assume builtins are present on the target.
Definition: Config.h:66
llvm::lto::LTOLLVMDiagnosticHandler::LTOLLVMDiagnosticHandler
LTOLLVMDiagnosticHandler(DiagnosticHandlerFunction *DiagHandlerFn)
Definition: Config.h:281
llvm::lto::Config::ShouldDiscardValueNames
bool ShouldDiscardValueNames
Definition: Config.h:175
llvm::LLVMContext::setOpaquePointers
void setOpaquePointers(bool Enable) const
Set whether opaque pointers are enabled.
Definition: LLVMContext.cpp:375
llvm::lto::Config::PostImportModuleHook
ModuleHookFn PostImportModuleHook
This hook is called after importing from other modules (ThinLTO-specific).
Definition: Config.h:232
llvm::lto::Config::CodeGenOnly
bool CodeGenOnly
Disable entirely the optimizer, including importing for ThinLTO.
Definition: Config.h:69
LegacyPassManager.h
llvm::lto::Config::CombinedIndexHook
CombinedIndexHookFn CombinedIndexHook
Definition: Config.h:254
llvm::lto::Config::VisScheme
VisScheme
Definition: Config.h:41
llvm::lto::Config::FromPrevailing
@ FromPrevailing
Definition: Config.h:42
llvm::lto::Config::SplitDwarfFile
std::string SplitDwarfFile
The name for the split debug info file used for the DW_AT_[GNU_]dwo_name attribute in the skeleton CU...
Definition: Config.h:126
llvm::lto::Config::RunCSIRInstr
bool RunCSIRInstr
Run PGO context sensitive IR instrumentation.
Definition: Config.h:72
GlobalValue.h
llvm::lto::Config::PostPromoteModuleHook
ModuleHookFn PostPromoteModuleHook
This hook is called after promoting any internal functions (ThinLTO-specific).
Definition: Config.h:226
llvm::lto::Config::SampleProfile
std::string SampleProfile
Sample PGO profile path.
Definition: Config.h:114
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::lto::Config::Options
TargetOptions Options
Definition: Config.h:48
llvm::lto::LTOLLVMDiagnosticHandler::Fn
DiagnosticHandlerFunction * Fn
Definition: Config.h:280
llvm::lto::Config::PreCodeGenPassesHook
std::function< void(legacy::PassManager &)> PreCodeGenPassesHook
For adding passes that run right before codegen.
Definition: Config.h:53
llvm::lto::Config::VisibilityScheme
VisScheme VisibilityScheme
Allows non-imported definitions to get the potentially more constraining visibility from the prevaili...
Definition: Config.h:90
llvm::lto::Config::ELF
@ ELF
Definition: Config.h:43
DenseSet.h
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
llvm::DiagnosticHandlerFunction
std::function< void(const DiagnosticInfo &)> DiagnosticHandlerFunction
Definition: DiagnosticInfo.h:134
llvm::lto::Config::ResolutionFile
std::unique_ptr< raw_ostream > ResolutionFile
If this field is set, LTO will write input file paths and symbol resolutions here in llvm-lto2 comman...
Definition: Config.h:189
llvm::lto::LTOLLVMDiagnosticHandler
Definition: Config.h:279
llvm::lto::LTOLLVMContext::LTOLLVMContext
LTOLLVMContext(const Config &C)
Definition: Config.h:295
llvm::DiagnosticInfo
This is the base abstract class for diagnostic reporting in the backend.
Definition: DiagnosticInfo.h:108
llvm::lto::Config::ModuleHookFn
std::function< bool(unsigned Task, const Module &)> ModuleHookFn
The following callbacks deal with tasks, which normally represent the entire optimization and code ge...
Definition: Config.h:218
llvm::lto::Config::DebugPassManager
bool DebugPassManager
Whether to emit the pass manager debuggging informations.
Definition: Config.h:161
llvm::LLVMContext::setDiagnosticHandler
void setDiagnosticHandler(std::unique_ptr< DiagnosticHandler > &&DH, bool RespectFilters=false)
setDiagnosticHandler - This method sets unique_ptr to object of DiagnosticHandler to provide custom d...
Definition: LLVMContext.cpp:130
llvm::None
const NoneType None
Definition: None.h:24
llvm::lto::Config::StatsFile
std::string StatsFile
Statistics output file path.
Definition: Config.h:164
llvm::lto::Config::PostInternalizeModuleHook
ModuleHookFn PostInternalizeModuleHook
This hook is called after internalizing the module.
Definition: Config.h:229
llvm::lto::Config::OverrideTriple
std::string OverrideTriple
Setting this field will replace target triples in input files with this triple.
Definition: Config.h:104
llvm::lto::Config::PreCodeGenModuleHook
ModuleHookFn PreCodeGenModuleHook
This module hook is called before code generation.
Definition: Config.h:240
llvm::lto::Config::OptLevel
unsigned OptLevel
Definition: Config.h:58
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
llvm::lto::Config::RemarksFilename
std::string RemarksFilename
Optimization remarks file path.
Definition: Config.h:134
llvm::lto::Config::DefaultTriple
std::string DefaultTriple
Setting this field will replace unspecified target triples in input files with this triple.
Definition: Config.h:108
llvm::lto::LTOLLVMDiagnosticHandler::handleDiagnostics
bool handleDiagnostics(const DiagnosticInfo &DI) override
Override handleDiagnostics to provide custom implementation.
Definition: Config.h:283
llvm::CodeGenOpt::Default
@ Default
Definition: CodeGen.h:55
llvm::lto::Config::DwoDir
std::string DwoDir
The directory to store .dwo files.
Definition: Config.h:120
llvm::lto::Config::AddFSDiscriminator
bool AddFSDiscriminator
Add FSAFDO discriminators.
Definition: Config.h:179
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
llvm::lto::LTOLLVMContext
A derived class of LLVMContext that initializes itself according to a given Config object.
Definition: Config.h:293
llvm::lto::Config::SplitDwarfOutput
std::string SplitDwarfOutput
The path to write a .dwo file to.
Definition: Config.h:131
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::lto::Config::MAttrs
std::vector< std::string > MAttrs
Definition: Config.h:49
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::lto::Config::ProfileRemapping
std::string ProfileRemapping
Name remapping file for profile data.
Definition: Config.h:117
TargetOptions.h
llvm::lto::Config::RelocModel
Optional< Reloc::Model > RelocModel
Definition: Config.h:54
llvm::lto::Config::PostOptModuleHook
ModuleHookFn PostOptModuleHook
This module hook is called after optimization is complete.
Definition: Config.h:235
llvm::lto::Config::RemarksHotnessThreshold
llvm::Optional< uint64_t > RemarksHotnessThreshold
The minimum hotness value a diagnostic needs in order to be included in optimization diagnostics.
Definition: Config.h:155
llvm::lto::Config::HasWholeProgramVisibility
bool HasWholeProgramVisibility
Asserts whether we can assume whole program visibility during the LTO link.
Definition: Config.h:79
llvm::Reloc::PIC_
@ PIC_
Definition: CodeGen.h:22
llvm::CodeGenFileType
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition: CodeGen.h:63
llvm::lto::Config::TimeTraceEnabled
bool TimeTraceEnabled
Time trace enabled.
Definition: Config.h:170
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::lto::Config::AlwaysEmitRegularLTOObj
bool AlwaysEmitRegularLTOObj
Always emit a Regular LTO object even when it is empty because no Regular LTO modules were linked.
Definition: Config.h:84
llvm::lto::Config::OptPipeline
std::string OptPipeline
If this field is set, the set of passes run in the middle-end optimizer will be the one specified by ...
Definition: Config.h:95
llvm::CodeGenOpt::Level
Level
Definition: CodeGen.h:52
llvm::lto::Config::MllvmArgs
std::vector< std::string > MllvmArgs
Definition: Config.h:50
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::legacy::PassManager
PassManager manages ModulePassManagers.
Definition: LegacyPassManager.h:52
llvm::lto::LTOLLVMContext::DiagHandler
DiagnosticHandlerFunction DiagHandler
Definition: Config.h:303
DiagnosticInfo.h
llvm::lto::Config::AAPipeline
std::string AAPipeline
Definition: Config.h:100
llvm::LLVMContext::setDiscardValueNames
void setDiscardValueNames(bool Discard)
Set the Context runtime configuration to discard all value name (but GlobalValue).
Definition: LLVMContext.cpp:351
llvm::lto::Config::PreOptModuleHook
ModuleHookFn PreOptModuleHook
This module hook is called after linking (regular LTO) or loading (ThinLTO) the module,...
Definition: Config.h:222
llvm::lto::Config::PTO
PipelineTuningOptions PTO
Tunable parameters for passes in the default pipelines.
Definition: Config.h:192
llvm::lto::Config::CSIRProfile
std::string CSIRProfile
Context Sensitive PGO profile path.
Definition: Config.h:111
llvm::lto::Config::CombinedIndexHookFn
std::function< bool(const ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)> CombinedIndexHookFn
A combined index hook is called after all per-module indexes have been combined (ThinLTO-specific).
Definition: Config.h:253
CodeGen.h
llvm::lto::Config::CGFileType
CodeGenFileType CGFileType
Definition: Config.h:57
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1087
llvm::lto::Config::addSaveTemps
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 afte...
Definition: LTOBackend.cpp:85
llvm::lto::Config::PassPlugins
std::vector< std::string > PassPlugins
Definition: Config.h:51
llvm::lto::Config::CPU
std::string CPU
Definition: Config.h:47
LLVMContext.h
llvm::lto::Config::RemarksPasses
std::string RemarksPasses
Optimization remarks pass filter.
Definition: Config.h:137
llvm::lto::Config::PGOWarnMismatch
bool PGOWarnMismatch
Turn on/off the warning about a hash mismatch in the PGO profile data.
Definition: Config.h:75