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_FRONTEND_CODEGENOPTIONS_H
15 #define LLVM_CLANG_FRONTEND_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/Frontend/CodeGenOptions.def"
39 #define CODEGENOPT(Name, Bits, Default)
40 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
41 #include "clang/Frontend/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 /// 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.
104 enum EmbedBitcodeKind {
105 Embed_Off, // No embedded bitcode.
106 Embed_All, // Embed both bitcode and commandline in the output.
107 Embed_Bitcode, // Embed just the bitcode in the output.
108 Embed_Marker // Embed a marker as a placeholder for bitcode.
111 /// The code model to use (-mcmodel).
112 std::string CodeModel;
114 /// The filename with path we use for coverage data files. The runtime
115 /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
116 /// environment variables.
117 std::string CoverageDataFile;
119 /// The filename with path we use for coverage notes files.
120 std::string CoverageNotesFile;
122 /// The version string to put into coverage files.
123 char CoverageVersion[4];
125 /// Enable additional debugging information.
126 std::string DebugPass;
128 /// The string to embed in debug information as the current working directory.
129 std::string DebugCompilationDir;
131 /// The string to embed in the debug information for the compile unit, if
133 std::string DwarfDebugFlags;
135 std::map<std::string, std::string> DebugPrefixMap;
137 /// The ABI to use for passing floating point arguments.
138 std::string FloatABI;
140 /// The floating-point denormal mode to use.
141 std::string FPDenormalMode;
143 /// The float precision limit to use, if non-empty.
144 std::string LimitFloatPrecision;
146 struct BitcodeFileToLink {
147 /// The filename of the bitcode file to link in.
148 std::string Filename;
149 /// If true, we set attributes functions in the bitcode library according to
150 /// our CodeGenOptions, much as we set attrs on functions that we generate
152 bool PropagateAttrs = false;
153 /// If true, we use LLVM module internalizer.
154 bool Internalize = false;
155 /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker.
156 unsigned LinkFlags = 0;
159 /// The files specified here are linked in to the module before optimizations.
160 std::vector<BitcodeFileToLink> LinkBitcodeFiles;
162 /// The user provided name for the "main file", if non-empty. This is useful
163 /// in situations where the input file name does not match the original input
164 /// file, for example with -save-temps.
165 std::string MainFileName;
167 /// The name for the split debug info file that we'll break out. This is used
168 /// in the backend for setting the name in the skeleton cu.
169 std::string SplitDwarfFile;
171 /// The name of the relocation model to use.
172 llvm::Reloc::Model RelocationModel;
174 /// The thread model to use
175 std::string ThreadModel;
177 /// If not an empty string, trap intrinsics are lowered to calls to this
178 /// function instead of to trap instructions.
179 std::string TrapFuncName;
181 /// A list of dependent libraries.
182 std::vector<std::string> DependentLibraries;
184 /// A list of linker options to embed in the object file.
185 std::vector<std::string> LinkerOptions;
187 /// Name of the profile file to use as output for -fprofile-instr-generate
188 /// and -fprofile-generate.
189 std::string InstrProfileOutput;
191 /// Name of the profile file to use with -fprofile-sample-use.
192 std::string SampleProfileFile;
194 /// Name of the profile file to use as input for -fprofile-instr-use
195 std::string ProfileInstrumentUsePath;
197 /// Name of the function summary index file to use for ThinLTO function
199 std::string ThinLTOIndexFile;
201 /// Name of a file that can optionally be written with minimized bitcode
202 /// to be used as input for the ThinLTO thin link step, which only needs
203 /// the summary and module symbol table (and not, e.g. any debug metadata).
204 std::string ThinLinkBitcodeFile;
206 /// Prefix to use for -save-temps output.
207 std::string SaveTempsFilePrefix;
209 /// Name of file passed with -fcuda-include-gpubinary option to forward to
210 /// CUDA runtime back-end for incorporating them into host-side object file.
211 std::string CudaGpuBinaryFileName;
213 /// The name of the file to which the backend should save YAML optimization
215 std::string OptRecordFile;
217 /// Regular expression to select optimizations for which we should enable
218 /// optimization remarks. Transformation passes whose name matches this
219 /// expression (and support this feature), will emit a diagnostic
220 /// whenever they perform a transformation. This is enabled by the
221 /// -Rpass=regexp flag.
222 std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
224 /// Regular expression to select optimizations for which we should enable
225 /// missed optimization remarks. Transformation passes whose name matches this
226 /// expression (and support this feature), will emit a diagnostic
227 /// whenever they tried but failed to perform a transformation. This is
228 /// enabled by the -Rpass-missed=regexp flag.
229 std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
231 /// Regular expression to select optimizations for which we should enable
232 /// optimization analyses. Transformation passes whose name matches this
233 /// expression (and support this feature), will emit a diagnostic
234 /// whenever they want to explain why they decided to apply or not apply
235 /// a given transformation. This is enabled by the -Rpass-analysis=regexp
237 std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
239 /// Set of files defining the rules for the symbol rewriting.
240 std::vector<std::string> RewriteMapFiles;
242 /// Set of sanitizer checks that are non-fatal (i.e. execution should be
243 /// continued when possible).
244 SanitizerSet SanitizeRecover;
246 /// Set of sanitizer checks that trap rather than diagnose.
247 SanitizerSet SanitizeTrap;
249 /// List of backend command-line options for -fembed-bitcode.
250 std::vector<uint8_t> CmdArgs;
252 /// A list of all -fno-builtin-* function names (e.g., memset).
253 std::vector<std::string> NoBuiltinFuncs;
255 std::vector<std::string> Reciprocals;
257 /// The preferred width for auto-vectorization transforms. This is intended to
258 /// override default transforms based on the width of the architected vector
260 std::string PreferVectorWidth;
262 /// Set of XRay instrumentation kinds to emit.
263 XRayInstrSet XRayInstrumentationBundle;
266 // Define accessors/mutators for code generation options of enumeration type.
267 #define CODEGENOPT(Name, Bits, Default)
268 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
269 Type get##Name() const { return static_cast<Type>(Name); } \
270 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
271 #include "clang/Frontend/CodeGenOptions.def"
275 /// Is this a libc/libm function that is no longer recognized as a
276 /// builtin because a -fno-builtin-* option has been specified?
277 bool isNoBuiltinFunc(const char *Name) const;
279 const std::vector<std::string> &getNoBuiltinFuncs() const {
280 return NoBuiltinFuncs;
283 /// Check if Clang profile instrumenation is on.
284 bool hasProfileClangInstr() const {
285 return getProfileInstr() == ProfileClangInstr;
288 /// Check if IR level profile instrumentation is on.
289 bool hasProfileIRInstr() const {
290 return getProfileInstr() == ProfileIRInstr;
293 /// Check if Clang profile use is on.
294 bool hasProfileClangUse() const {
295 return getProfileUse() == ProfileClangInstr;
298 /// Check if IR level profile use is on.
299 bool hasProfileIRUse() const {
300 return getProfileUse() == ProfileIRInstr;
305 } // end namespace clang