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/ADT/FloatingPointMode.h"
20 #include "llvm/Support/CodeGen.h"
21 #include "llvm/Support/Regex.h"
22 #include "llvm/Target/TargetOptions.h"
30 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
31 /// that this large collection of bitfields is a trivial class type.
32 class CodeGenOptionsBase {
34 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
35 #define ENUM_CODEGENOPT(Name, Type, Bits, Default)
36 #include "clang/Basic/CodeGenOptions.def"
39 #define CODEGENOPT(Name, Bits, Default)
40 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
41 #include "clang/Basic/CodeGenOptions.def"
44 /// CodeGenOptions - Track various options which control how the code
45 /// is optimized and passed to the backend.
46 class CodeGenOptions : public CodeGenOptionsBase {
49 NormalInlining, // Use the standard function inlining pass.
50 OnlyHintInlining, // Inline only (implicitly) hinted functions.
51 OnlyAlwaysInlining // Only run the always inlining pass.
55 NoLibrary, // Don't use any vector library.
56 Accelerate, // Use the Accelerate framework.
57 MASSV, // IBM MASS vector library.
58 SVML // Intel short vector math library.
62 enum ObjCDispatchMethodKind {
69 GeneralDynamicTLSModel,
75 /// Clang versions with different platform ABI conformance.
77 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
78 /// (SVN r257626). This causes <1 x long long> to be passed in an
79 /// integer register instead of an SSE register on x64_64.
82 /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
83 /// (SVN r291814). This causes move operations to be ignored when
84 /// determining whether a class type can be passed or returned directly.
87 /// Conform to the underlying platform's C and C++ ABIs as closely
92 enum StructReturnConventionKind {
93 SRCK_Default, // No special option was passed.
94 SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return).
95 SRCK_InRegs // Small structs in registers (-freg-struct-return).
98 enum ProfileInstrKind {
99 ProfileNone, // Profile instrumentation is turned off.
100 ProfileClangInstr, // Clang instrumentation to generate execution counts
102 ProfileIRInstr, // IR level PGO instrumentation in LLVM.
103 ProfileCSIRInstr, // IR level PGO context sensitive instrumentation in LLVM.
106 enum EmbedBitcodeKind {
107 Embed_Off, // No embedded bitcode.
108 Embed_All, // Embed both bitcode and commandline in the output.
109 Embed_Bitcode, // Embed just the bitcode in the output.
110 Embed_Marker // Embed a marker as a placeholder for bitcode.
113 enum class SignReturnAddressScope {
114 None, // No signing for any function
115 NonLeaf, // Sign the return address of functions that spill LR
116 All // Sign the return address of all functions
119 enum class SignReturnAddressKeyValue { AKey, BKey };
121 enum class FramePointerKind {
122 None, // Omit all frame pointers.
123 NonLeaf, // Keep non-leaf frame pointers.
124 All, // Keep all frame pointers.
127 /// The code model to use (-mcmodel).
128 std::string CodeModel;
130 /// The filename with path we use for coverage data files. The runtime
131 /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
132 /// environment variables.
133 std::string CoverageDataFile;
135 /// The filename with path we use for coverage notes files.
136 std::string CoverageNotesFile;
138 /// Regexes separated by a semi-colon to filter the files to instrument.
139 std::string ProfileFilterFiles;
141 /// Regexes separated by a semi-colon to filter the files to not instrument.
142 std::string ProfileExcludeFiles;
144 /// The version string to put into coverage files.
145 char CoverageVersion[4];
147 /// Enable additional debugging information.
148 std::string DebugPass;
150 /// The string to embed in debug information as the current working directory.
151 std::string DebugCompilationDir;
153 /// The string to embed in the debug information for the compile unit, if
155 std::string DwarfDebugFlags;
157 /// The string containing the commandline for the llvm.commandline metadata,
159 std::string RecordCommandLine;
161 std::map<std::string, std::string> DebugPrefixMap;
163 /// The ABI to use for passing floating point arguments.
164 std::string FloatABI;
166 /// The floating-point denormal mode to use.
167 llvm::DenormalMode FPDenormalMode = llvm::DenormalMode::Invalid;
169 /// The float precision limit to use, if non-empty.
170 std::string LimitFloatPrecision;
172 struct BitcodeFileToLink {
173 /// The filename of the bitcode file to link in.
174 std::string Filename;
175 /// If true, we set attributes functions in the bitcode library according to
176 /// our CodeGenOptions, much as we set attrs on functions that we generate
178 bool PropagateAttrs = false;
179 /// If true, we use LLVM module internalizer.
180 bool Internalize = false;
181 /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker.
182 unsigned LinkFlags = 0;
185 /// The files specified here are linked in to the module before optimizations.
186 std::vector<BitcodeFileToLink> LinkBitcodeFiles;
188 /// The user provided name for the "main file", if non-empty. This is useful
189 /// in situations where the input file name does not match the original input
190 /// file, for example with -save-temps.
191 std::string MainFileName;
193 /// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
194 /// attribute in the skeleton CU.
195 std::string SplitDwarfFile;
197 /// Output filename for the split debug info, not used in the skeleton CU.
198 std::string SplitDwarfOutput;
200 /// The name of the relocation model to use.
201 llvm::Reloc::Model RelocationModel;
203 /// The thread model to use
204 std::string ThreadModel;
206 /// If not an empty string, trap intrinsics are lowered to calls to this
207 /// function instead of to trap instructions.
208 std::string TrapFuncName;
210 /// A list of dependent libraries.
211 std::vector<std::string> DependentLibraries;
213 /// A list of linker options to embed in the object file.
214 std::vector<std::string> LinkerOptions;
216 /// Name of the profile file to use as output for -fprofile-instr-generate,
217 /// -fprofile-generate, and -fcs-profile-generate.
218 std::string InstrProfileOutput;
220 /// Name of the profile file to use with -fprofile-sample-use.
221 std::string SampleProfileFile;
223 /// Name of the profile file to use as input for -fprofile-instr-use
224 std::string ProfileInstrumentUsePath;
226 /// Name of the profile remapping file to apply to the profile data supplied
227 /// by -fprofile-sample-use or -fprofile-instr-use.
228 std::string ProfileRemappingFile;
230 /// Name of the function summary index file to use for ThinLTO function
232 std::string ThinLTOIndexFile;
234 /// Name of a file that can optionally be written with minimized bitcode
235 /// to be used as input for the ThinLTO thin link step, which only needs
236 /// the summary and module symbol table (and not, e.g. any debug metadata).
237 std::string ThinLinkBitcodeFile;
239 /// Prefix to use for -save-temps output.
240 std::string SaveTempsFilePrefix;
242 /// Name of file passed with -fcuda-include-gpubinary option to forward to
243 /// CUDA runtime back-end for incorporating them into host-side object file.
244 std::string CudaGpuBinaryFileName;
246 /// The name of the file to which the backend should save YAML optimization
248 std::string OptRecordFile;
250 /// The regex that filters the passes that should be saved to the optimization
252 std::string OptRecordPasses;
254 /// The format used for serializing remarks (default: YAML)
255 std::string OptRecordFormat;
257 /// The name of the partition that symbols are assigned to, specified with
258 /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
259 std::string SymbolPartition;
261 /// Regular expression to select optimizations for which we should enable
262 /// optimization remarks. Transformation passes whose name matches this
263 /// expression (and support this feature), will emit a diagnostic
264 /// whenever they perform a transformation. This is enabled by the
265 /// -Rpass=regexp flag.
266 std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
268 /// Regular expression to select optimizations for which we should enable
269 /// missed optimization remarks. Transformation passes whose name matches this
270 /// expression (and support this feature), will emit a diagnostic
271 /// whenever they tried but failed to perform a transformation. This is
272 /// enabled by the -Rpass-missed=regexp flag.
273 std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
275 /// Regular expression to select optimizations for which we should enable
276 /// optimization analyses. Transformation passes whose name matches this
277 /// expression (and support this feature), will emit a diagnostic
278 /// whenever they want to explain why they decided to apply or not apply
279 /// a given transformation. This is enabled by the -Rpass-analysis=regexp
281 std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
283 /// Set of files defining the rules for the symbol rewriting.
284 std::vector<std::string> RewriteMapFiles;
286 /// Set of sanitizer checks that are non-fatal (i.e. execution should be
287 /// continued when possible).
288 SanitizerSet SanitizeRecover;
290 /// Set of sanitizer checks that trap rather than diagnose.
291 SanitizerSet SanitizeTrap;
293 /// List of backend command-line options for -fembed-bitcode.
294 std::vector<uint8_t> CmdArgs;
296 /// A list of all -fno-builtin-* function names (e.g., memset).
297 std::vector<std::string> NoBuiltinFuncs;
299 std::vector<std::string> Reciprocals;
301 /// The preferred width for auto-vectorization transforms. This is intended to
302 /// override default transforms based on the width of the architected vector
304 std::string PreferVectorWidth;
306 /// Set of XRay instrumentation kinds to emit.
307 XRayInstrSet XRayInstrumentationBundle;
309 std::vector<std::string> DefaultFunctionAttrs;
311 /// List of dynamic shared object files to be loaded as pass plugins.
312 std::vector<std::string> PassPlugins;
315 // Define accessors/mutators for code generation options of enumeration type.
316 #define CODEGENOPT(Name, Bits, Default)
317 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
318 Type get##Name() const { return static_cast<Type>(Name); } \
319 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
320 #include "clang/Basic/CodeGenOptions.def"
324 /// Is this a libc/libm function that is no longer recognized as a
325 /// builtin because a -fno-builtin-* option has been specified?
326 bool isNoBuiltinFunc(const char *Name) const;
328 const std::vector<std::string> &getNoBuiltinFuncs() const {
329 return NoBuiltinFuncs;
332 /// Check if Clang profile instrumenation is on.
333 bool hasProfileClangInstr() const {
334 return getProfileInstr() == ProfileClangInstr;
337 /// Check if IR level profile instrumentation is on.
338 bool hasProfileIRInstr() const {
339 return getProfileInstr() == ProfileIRInstr;
342 /// Check if CS IR level profile instrumentation is on.
343 bool hasProfileCSIRInstr() const {
344 return getProfileInstr() == ProfileCSIRInstr;
347 /// Check if Clang profile use is on.
348 bool hasProfileClangUse() const {
349 return getProfileUse() == ProfileClangInstr;
352 /// Check if IR level profile use is on.
353 bool hasProfileIRUse() const {
354 return getProfileUse() == ProfileIRInstr ||
355 getProfileUse() == ProfileCSIRInstr;
358 /// Check if CSIR profile use is on.
359 bool hasProfileCSIRUse() const { return getProfileUse() == ProfileCSIRInstr; }
361 /// Check if type and variable info should be emitted.
362 bool hasReducedDebugInfo() const {
363 return getDebugInfo() >= codegenoptions::DebugInfoConstructor;
367 } // end namespace clang