1 //===--- CodeGenOptions.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the CodeGenOptions interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H
15 #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H
17 #include "clang/Basic/DebugInfoOptions.h"
18 #include "clang/Basic/Sanitizers.h"
19 #include "clang/Basic/XRayInstr.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 SVML // Intel short vector math library.
61 enum ObjCDispatchMethodKind {
68 GeneralDynamicTLSModel,
74 enum DwarfFissionKind { NoFission, SplitFileFission, SingleFileFission };
76 /// Clang versions with different platform ABI conformance.
78 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
79 /// (SVN r257626). This causes <1 x long long> to be passed in an
80 /// integer register instead of an SSE register on x64_64.
83 /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
84 /// (SVN r291814). This causes move operations to be ignored when
85 /// determining whether a class type can be passed or returned directly.
88 /// Conform to the underlying platform's C and C++ ABIs as closely
93 enum StructReturnConventionKind {
94 SRCK_Default, // No special option was passed.
95 SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return).
96 SRCK_InRegs // Small structs in registers (-freg-struct-return).
99 enum ProfileInstrKind {
100 ProfileNone, // Profile instrumentation is turned off.
101 ProfileClangInstr, // Clang instrumentation to generate execution counts
103 ProfileIRInstr, // IR level PGO 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 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 SignReturnAddressKeyValue { AKey, BKey };
121 /// The code model to use (-mcmodel).
122 std::string CodeModel;
124 /// The filename with path we use for coverage data files. The runtime
125 /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
126 /// environment variables.
127 std::string CoverageDataFile;
129 /// The filename with path we use for coverage notes files.
130 std::string CoverageNotesFile;
132 /// Regexes separated by a semi-colon to filter the files to instrument.
133 std::string ProfileFilterFiles;
135 /// Regexes separated by a semi-colon to filter the files to not instrument.
136 std::string ProfileExcludeFiles;
138 /// The version string to put into coverage files.
139 char CoverageVersion[4];
141 /// Enable additional debugging information.
142 std::string DebugPass;
144 /// The string to embed in debug information as the current working directory.
145 std::string DebugCompilationDir;
147 /// The string to embed in the debug information for the compile unit, if
149 std::string DwarfDebugFlags;
151 /// The string containing the commandline for the llvm.commandline metadata,
153 std::string RecordCommandLine;
155 std::map<std::string, std::string> DebugPrefixMap;
157 /// The ABI to use for passing floating point arguments.
158 std::string FloatABI;
160 /// The floating-point denormal mode to use.
161 std::string FPDenormalMode;
163 /// The float precision limit to use, if non-empty.
164 std::string LimitFloatPrecision;
166 struct BitcodeFileToLink {
167 /// The filename of the bitcode file to link in.
168 std::string Filename;
169 /// If true, we set attributes functions in the bitcode library according to
170 /// our CodeGenOptions, much as we set attrs on functions that we generate
172 bool PropagateAttrs = false;
173 /// If true, we use LLVM module internalizer.
174 bool Internalize = false;
175 /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker.
176 unsigned LinkFlags = 0;
179 /// The files specified here are linked in to the module before optimizations.
180 std::vector<BitcodeFileToLink> LinkBitcodeFiles;
182 /// The user provided name for the "main file", if non-empty. This is useful
183 /// in situations where the input file name does not match the original input
184 /// file, for example with -save-temps.
185 std::string MainFileName;
187 /// The name for the split debug info file that we'll break out. This is used
188 /// in the backend for setting the name in the skeleton cu.
189 std::string SplitDwarfFile;
191 /// The name of the relocation model to use.
192 llvm::Reloc::Model RelocationModel;
194 /// The thread model to use
195 std::string ThreadModel;
197 /// If not an empty string, trap intrinsics are lowered to calls to this
198 /// function instead of to trap instructions.
199 std::string TrapFuncName;
201 /// A list of dependent libraries.
202 std::vector<std::string> DependentLibraries;
204 /// A list of linker options to embed in the object file.
205 std::vector<std::string> LinkerOptions;
207 /// Name of the profile file to use as output for -fprofile-instr-generate
208 /// and -fprofile-generate.
209 std::string InstrProfileOutput;
211 /// Name of the profile file to use with -fprofile-sample-use.
212 std::string SampleProfileFile;
214 /// Name of the profile file to use as input for -fprofile-instr-use
215 std::string ProfileInstrumentUsePath;
217 /// Name of the profile remapping file to apply to the profile data supplied
218 /// by -fprofile-sample-use or -fprofile-instr-use.
219 std::string ProfileRemappingFile;
221 /// Name of the function summary index file to use for ThinLTO function
223 std::string ThinLTOIndexFile;
225 /// Name of a file that can optionally be written with minimized bitcode
226 /// to be used as input for the ThinLTO thin link step, which only needs
227 /// the summary and module symbol table (and not, e.g. any debug metadata).
228 std::string ThinLinkBitcodeFile;
230 /// Prefix to use for -save-temps output.
231 std::string SaveTempsFilePrefix;
233 /// Name of file passed with -fcuda-include-gpubinary option to forward to
234 /// CUDA runtime back-end for incorporating them into host-side object file.
235 std::string CudaGpuBinaryFileName;
237 /// The name of the file to which the backend should save YAML optimization
239 std::string OptRecordFile;
241 /// Regular expression to select optimizations for which we should enable
242 /// optimization remarks. Transformation passes whose name matches this
243 /// expression (and support this feature), will emit a diagnostic
244 /// whenever they perform a transformation. This is enabled by the
245 /// -Rpass=regexp flag.
246 std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
248 /// Regular expression to select optimizations for which we should enable
249 /// missed optimization remarks. Transformation passes whose name matches this
250 /// expression (and support this feature), will emit a diagnostic
251 /// whenever they tried but failed to perform a transformation. This is
252 /// enabled by the -Rpass-missed=regexp flag.
253 std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
255 /// Regular expression to select optimizations for which we should enable
256 /// optimization analyses. Transformation passes whose name matches this
257 /// expression (and support this feature), will emit a diagnostic
258 /// whenever they want to explain why they decided to apply or not apply
259 /// a given transformation. This is enabled by the -Rpass-analysis=regexp
261 std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
263 /// Set of files defining the rules for the symbol rewriting.
264 std::vector<std::string> RewriteMapFiles;
266 /// Set of sanitizer checks that are non-fatal (i.e. execution should be
267 /// continued when possible).
268 SanitizerSet SanitizeRecover;
270 /// Set of sanitizer checks that trap rather than diagnose.
271 SanitizerSet SanitizeTrap;
273 /// List of backend command-line options for -fembed-bitcode.
274 std::vector<uint8_t> CmdArgs;
276 /// A list of all -fno-builtin-* function names (e.g., memset).
277 std::vector<std::string> NoBuiltinFuncs;
279 std::vector<std::string> Reciprocals;
281 /// The preferred width for auto-vectorization transforms. This is intended to
282 /// override default transforms based on the width of the architected vector
284 std::string PreferVectorWidth;
286 /// Set of XRay instrumentation kinds to emit.
287 XRayInstrSet XRayInstrumentationBundle;
289 std::vector<std::string> DefaultFunctionAttrs;
292 // Define accessors/mutators for code generation options of enumeration type.
293 #define CODEGENOPT(Name, Bits, Default)
294 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
295 Type get##Name() const { return static_cast<Type>(Name); } \
296 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
297 #include "clang/Basic/CodeGenOptions.def"
301 /// Is this a libc/libm function that is no longer recognized as a
302 /// builtin because a -fno-builtin-* option has been specified?
303 bool isNoBuiltinFunc(const char *Name) const;
305 const std::vector<std::string> &getNoBuiltinFuncs() const {
306 return NoBuiltinFuncs;
309 /// Check if Clang profile instrumenation is on.
310 bool hasProfileClangInstr() const {
311 return getProfileInstr() == ProfileClangInstr;
314 /// Check if IR level profile instrumentation is on.
315 bool hasProfileIRInstr() const {
316 return getProfileInstr() == ProfileIRInstr;
319 /// Check if Clang profile use is on.
320 bool hasProfileClangUse() const {
321 return getProfileUse() == ProfileClangInstr;
324 /// Check if IR level profile use is on.
325 bool hasProfileIRUse() const {
326 return getProfileUse() == ProfileIRInstr;
331 } // end namespace clang