1 //===--- CodeGenOptions.h ---------------------------------------*- C++ -*-===//
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 defines the CodeGenOptions interface.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H
14 #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H
16 #include "clang/Basic/DebugInfoOptions.h"
17 #include "clang/Basic/Sanitizers.h"
18 #include "clang/Basic/XRayInstr.h"
19 #include "llvm/Support/CodeGen.h"
20 #include "llvm/Support/Regex.h"
21 #include "llvm/Target/TargetOptions.h"
29 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
30 /// that this large collection of bitfields is a trivial class type.
31 class CodeGenOptionsBase {
33 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
34 #define ENUM_CODEGENOPT(Name, Type, Bits, Default)
35 #include "clang/Basic/CodeGenOptions.def"
38 #define CODEGENOPT(Name, Bits, Default)
39 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
40 #include "clang/Basic/CodeGenOptions.def"
43 /// CodeGenOptions - Track various options which control how the code
44 /// is optimized and passed to the backend.
45 class CodeGenOptions : public CodeGenOptionsBase {
48 NormalInlining, // Use the standard function inlining pass.
49 OnlyHintInlining, // Inline only (implicitly) hinted functions.
50 OnlyAlwaysInlining // Only run the always inlining pass.
54 NoLibrary, // Don't use any vector library.
55 Accelerate, // Use the Accelerate framework.
56 MASSV, // IBM MASS vector library.
57 SVML // Intel short vector math library.
61 enum ObjCDispatchMethodKind {
68 GeneralDynamicTLSModel,
74 /// Clang versions with different platform ABI conformance.
76 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
77 /// (SVN r257626). This causes <1 x long long> to be passed in an
78 /// integer register instead of an SSE register on x64_64.
81 /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
82 /// (SVN r291814). This causes move operations to be ignored when
83 /// determining whether a class type can be passed or returned directly.
86 /// Conform to the underlying platform's C and C++ ABIs as closely
91 enum StructReturnConventionKind {
92 SRCK_Default, // No special option was passed.
93 SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return).
94 SRCK_InRegs // Small structs in registers (-freg-struct-return).
97 enum ProfileInstrKind {
98 ProfileNone, // Profile instrumentation is turned off.
99 ProfileClangInstr, // Clang instrumentation to generate execution counts
101 ProfileIRInstr, // IR level PGO instrumentation in LLVM.
102 ProfileCSIRInstr, // IR level PGO context sensitive instrumentation in LLVM.
105 enum EmbedBitcodeKind {
106 Embed_Off, // No embedded bitcode.
107 Embed_All, // Embed both bitcode and commandline in the output.
108 Embed_Bitcode, // Embed just the bitcode in the output.
109 Embed_Marker // Embed a marker as a placeholder for bitcode.
112 enum SignReturnAddressScope {
113 None, // No signing for any function
114 NonLeaf, // Sign the return address of functions that spill LR
115 All // Sign the return address of all functions
118 enum SignReturnAddressKeyValue { AKey, BKey };
120 /// The code model to use (-mcmodel).
121 std::string CodeModel;
123 /// The filename with path we use for coverage data files. The runtime
124 /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
125 /// environment variables.
126 std::string CoverageDataFile;
128 /// The filename with path we use for coverage notes files.
129 std::string CoverageNotesFile;
131 /// Regexes separated by a semi-colon to filter the files to instrument.
132 std::string ProfileFilterFiles;
134 /// Regexes separated by a semi-colon to filter the files to not instrument.
135 std::string ProfileExcludeFiles;
137 /// The version string to put into coverage files.
138 char CoverageVersion[4];
140 /// Enable additional debugging information.
141 std::string DebugPass;
143 /// The string to embed in debug information as the current working directory.
144 std::string DebugCompilationDir;
146 /// The string to embed in the debug information for the compile unit, if
148 std::string DwarfDebugFlags;
150 /// The string containing the commandline for the llvm.commandline metadata,
152 std::string RecordCommandLine;
154 std::map<std::string, std::string> DebugPrefixMap;
156 /// The ABI to use for passing floating point arguments.
157 std::string FloatABI;
159 /// The floating-point denormal mode to use.
160 std::string FPDenormalMode;
162 /// The float precision limit to use, if non-empty.
163 std::string LimitFloatPrecision;
165 struct BitcodeFileToLink {
166 /// The filename of the bitcode file to link in.
167 std::string Filename;
168 /// If true, we set attributes functions in the bitcode library according to
169 /// our CodeGenOptions, much as we set attrs on functions that we generate
171 bool PropagateAttrs = false;
172 /// If true, we use LLVM module internalizer.
173 bool Internalize = false;
174 /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker.
175 unsigned LinkFlags = 0;
178 /// The files specified here are linked in to the module before optimizations.
179 std::vector<BitcodeFileToLink> LinkBitcodeFiles;
181 /// The user provided name for the "main file", if non-empty. This is useful
182 /// in situations where the input file name does not match the original input
183 /// file, for example with -save-temps.
184 std::string MainFileName;
186 /// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
187 /// attribute in the skeleton CU.
188 std::string SplitDwarfFile;
190 /// Output filename for the split debug info, not used in the skeleton CU.
191 std::string SplitDwarfOutput;
193 /// The name of the relocation model to use.
194 llvm::Reloc::Model RelocationModel;
196 /// The thread model to use
197 std::string ThreadModel;
199 /// If not an empty string, trap intrinsics are lowered to calls to this
200 /// function instead of to trap instructions.
201 std::string TrapFuncName;
203 /// A list of dependent libraries.
204 std::vector<std::string> DependentLibraries;
206 /// A list of linker options to embed in the object file.
207 std::vector<std::string> LinkerOptions;
209 /// Name of the profile file to use as output for -fprofile-instr-generate,
210 /// -fprofile-generate, and -fcs-profile-generate.
211 std::string InstrProfileOutput;
213 /// Name of the profile file to use with -fprofile-sample-use.
214 std::string SampleProfileFile;
216 /// Name of the profile file to use as input for -fprofile-instr-use
217 std::string ProfileInstrumentUsePath;
219 /// Name of the profile remapping file to apply to the profile data supplied
220 /// by -fprofile-sample-use or -fprofile-instr-use.
221 std::string ProfileRemappingFile;
223 /// Name of the function summary index file to use for ThinLTO function
225 std::string ThinLTOIndexFile;
227 /// Name of a file that can optionally be written with minimized bitcode
228 /// to be used as input for the ThinLTO thin link step, which only needs
229 /// the summary and module symbol table (and not, e.g. any debug metadata).
230 std::string ThinLinkBitcodeFile;
232 /// Prefix to use for -save-temps output.
233 std::string SaveTempsFilePrefix;
235 /// Name of file passed with -fcuda-include-gpubinary option to forward to
236 /// CUDA runtime back-end for incorporating them into host-side object file.
237 std::string CudaGpuBinaryFileName;
239 /// The name of the file to which the backend should save YAML optimization
241 std::string OptRecordFile;
243 /// The regex that filters the passes that should be saved to the optimization
245 std::string OptRecordPasses;
247 /// The format used for serializing remarks (default: YAML)
248 std::string OptRecordFormat;
250 /// The name of the partition that symbols are assigned to, specified with
251 /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
252 std::string SymbolPartition;
254 /// Regular expression to select optimizations for which we should enable
255 /// optimization remarks. Transformation passes whose name matches this
256 /// expression (and support this feature), will emit a diagnostic
257 /// whenever they perform a transformation. This is enabled by the
258 /// -Rpass=regexp flag.
259 std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
261 /// Regular expression to select optimizations for which we should enable
262 /// missed optimization remarks. Transformation passes whose name matches this
263 /// expression (and support this feature), will emit a diagnostic
264 /// whenever they tried but failed to perform a transformation. This is
265 /// enabled by the -Rpass-missed=regexp flag.
266 std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
268 /// Regular expression to select optimizations for which we should enable
269 /// optimization analyses. Transformation passes whose name matches this
270 /// expression (and support this feature), will emit a diagnostic
271 /// whenever they want to explain why they decided to apply or not apply
272 /// a given transformation. This is enabled by the -Rpass-analysis=regexp
274 std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
276 /// Set of files defining the rules for the symbol rewriting.
277 std::vector<std::string> RewriteMapFiles;
279 /// Set of sanitizer checks that are non-fatal (i.e. execution should be
280 /// continued when possible).
281 SanitizerSet SanitizeRecover;
283 /// Set of sanitizer checks that trap rather than diagnose.
284 SanitizerSet SanitizeTrap;
286 /// List of backend command-line options for -fembed-bitcode.
287 std::vector<uint8_t> CmdArgs;
289 /// A list of all -fno-builtin-* function names (e.g., memset).
290 std::vector<std::string> NoBuiltinFuncs;
292 std::vector<std::string> Reciprocals;
294 /// The preferred width for auto-vectorization transforms. This is intended to
295 /// override default transforms based on the width of the architected vector
297 std::string PreferVectorWidth;
299 /// Set of XRay instrumentation kinds to emit.
300 XRayInstrSet XRayInstrumentationBundle;
302 std::vector<std::string> DefaultFunctionAttrs;
304 /// List of dynamic shared object files to be loaded as pass plugins.
305 std::vector<std::string> PassPlugins;
308 // Define accessors/mutators for code generation options of enumeration type.
309 #define CODEGENOPT(Name, Bits, Default)
310 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
311 Type get##Name() const { return static_cast<Type>(Name); } \
312 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
313 #include "clang/Basic/CodeGenOptions.def"
317 /// Is this a libc/libm function that is no longer recognized as a
318 /// builtin because a -fno-builtin-* option has been specified?
319 bool isNoBuiltinFunc(const char *Name) const;
321 const std::vector<std::string> &getNoBuiltinFuncs() const {
322 return NoBuiltinFuncs;
325 /// Check if Clang profile instrumenation is on.
326 bool hasProfileClangInstr() const {
327 return getProfileInstr() == ProfileClangInstr;
330 /// Check if IR level profile instrumentation is on.
331 bool hasProfileIRInstr() const {
332 return getProfileInstr() == ProfileIRInstr;
335 /// Check if CS IR level profile instrumentation is on.
336 bool hasProfileCSIRInstr() const {
337 return getProfileInstr() == ProfileCSIRInstr;
340 /// Check if Clang profile use is on.
341 bool hasProfileClangUse() const {
342 return getProfileUse() == ProfileClangInstr;
345 /// Check if IR level profile use is on.
346 bool hasProfileIRUse() const {
347 return getProfileUse() == ProfileIRInstr ||
348 getProfileUse() == ProfileCSIRInstr;
351 /// Check if CSIR profile use is on.
352 bool hasProfileCSIRUse() const { return getProfileUse() == ProfileCSIRInstr; }
355 } // end namespace clang