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 "llvm/Support/Regex.h"
20 #include "llvm/Target/TargetOptions.h"
28 /// \brief Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
29 /// that this large collection of bitfields is a trivial class type.
30 class CodeGenOptionsBase {
32 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
33 #define ENUM_CODEGENOPT(Name, Type, Bits, Default)
34 #include "clang/Frontend/CodeGenOptions.def"
37 #define CODEGENOPT(Name, Bits, Default)
38 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
39 #include "clang/Frontend/CodeGenOptions.def"
42 /// CodeGenOptions - Track various options which control how the code
43 /// is optimized and passed to the backend.
44 class CodeGenOptions : public CodeGenOptionsBase {
47 NormalInlining, // Use the standard function inlining pass.
48 OnlyHintInlining, // Inline only (implicitly) hinted functions.
49 OnlyAlwaysInlining // Only run the always inlining pass.
53 NoLibrary, // Don't use any vector library.
54 Accelerate, // Use the Accelerate framework.
55 SVML // Intel short vector math library.
59 enum ObjCDispatchMethodKind {
66 GeneralDynamicTLSModel,
72 enum FPContractModeKind {
73 FPC_Off, // Form fused FP ops only where result will not be affected.
74 FPC_On, // Form fused FP ops according to FP_CONTRACT rules.
75 FPC_Fast // Aggressively fuse FP ops (E.g. FMA).
78 enum StructReturnConventionKind {
79 SRCK_Default, // No special option was passed.
80 SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return).
81 SRCK_InRegs // Small structs in registers (-freg-struct-return).
84 enum ProfileInstrKind {
85 ProfileNone, // Profile instrumentation is turned off.
86 ProfileClangInstr, // Clang instrumentation to generate execution counts
88 ProfileIRInstr, // IR level PGO instrumentation in LLVM.
91 enum EmbedBitcodeKind {
92 Embed_Off, // No embedded bitcode.
93 Embed_All, // Embed both bitcode and commandline in the output.
94 Embed_Bitcode, // Embed just the bitcode in the output.
95 Embed_Marker // Embed a marker as a placeholder for bitcode.
98 /// The code model to use (-mcmodel).
99 std::string CodeModel;
101 /// The filename with path we use for coverage data files. The runtime
102 /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
103 /// environment variables.
104 std::string CoverageDataFile;
106 /// The filename with path we use for coverage notes files.
107 std::string CoverageNotesFile;
109 /// The version string to put into coverage files.
110 char CoverageVersion[4];
112 /// Enable additional debugging information.
113 std::string DebugPass;
115 /// The string to embed in debug information as the current working directory.
116 std::string DebugCompilationDir;
118 /// The string to embed in the debug information for the compile unit, if
120 std::string DwarfDebugFlags;
122 std::map<std::string, std::string> DebugPrefixMap;
124 /// The ABI to use for passing floating point arguments.
125 std::string FloatABI;
127 /// The floating-point denormal mode to use.
128 std::string FPDenormalMode;
130 /// The float precision limit to use, if non-empty.
131 std::string LimitFloatPrecision;
133 /// The name of the bitcode file to link before optzns.
134 std::vector<std::pair<unsigned, std::string>> LinkBitcodeFiles;
136 /// The user provided name for the "main file", if non-empty. This is useful
137 /// in situations where the input file name does not match the original input
138 /// file, for example with -save-temps.
139 std::string MainFileName;
141 /// The name for the split debug info file that we'll break out. This is used
142 /// in the backend for setting the name in the skeleton cu.
143 std::string SplitDwarfFile;
145 /// The name of the relocation model to use.
146 std::string RelocationModel;
148 /// The thread model to use
149 std::string ThreadModel;
151 /// If not an empty string, trap intrinsics are lowered to calls to this
152 /// function instead of to trap instructions.
153 std::string TrapFuncName;
155 /// A list of command-line options to forward to the LLVM backend.
156 std::vector<std::string> BackendOptions;
158 /// A list of dependent libraries.
159 std::vector<std::string> DependentLibraries;
161 /// A list of linker options to embed in the object file.
162 std::vector<std::string> LinkerOptions;
164 /// Name of the profile file to use as output for -fprofile-instr-generate
165 /// and -fprofile-generate.
166 std::string InstrProfileOutput;
168 /// Name of the profile file to use with -fprofile-sample-use.
169 std::string SampleProfileFile;
171 /// Name of the profile file to use as input for -fprofile-instr-use
172 std::string ProfileInstrumentUsePath;
174 /// Name of the function summary index file to use for ThinLTO function
176 std::string ThinLTOIndexFile;
178 /// A list of file names passed with -fcuda-include-gpubinary options to
179 /// forward to CUDA runtime back-end for incorporating them into host-side
181 std::vector<std::string> CudaGpuBinaryFileNames;
183 /// The name of the file to which the backend should save YAML optimization
185 std::string OptRecordFile;
187 /// Regular expression to select optimizations for which we should enable
188 /// optimization remarks. Transformation passes whose name matches this
189 /// expression (and support this feature), will emit a diagnostic
190 /// whenever they perform a transformation. This is enabled by the
191 /// -Rpass=regexp flag.
192 std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
194 /// Regular expression to select optimizations for which we should enable
195 /// missed optimization remarks. Transformation passes whose name matches this
196 /// expression (and support this feature), will emit a diagnostic
197 /// whenever they tried but failed to perform a transformation. This is
198 /// enabled by the -Rpass-missed=regexp flag.
199 std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
201 /// Regular expression to select optimizations for which we should enable
202 /// optimization analyses. Transformation passes whose name matches this
203 /// expression (and support this feature), will emit a diagnostic
204 /// whenever they want to explain why they decided to apply or not apply
205 /// a given transformation. This is enabled by the -Rpass-analysis=regexp
207 std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
209 /// Set of files definining the rules for the symbol rewriting.
210 std::vector<std::string> RewriteMapFiles;
212 /// Set of sanitizer checks that are non-fatal (i.e. execution should be
213 /// continued when possible).
214 SanitizerSet SanitizeRecover;
216 /// Set of sanitizer checks that trap rather than diagnose.
217 SanitizerSet SanitizeTrap;
219 /// List of backend command-line options for -fembed-bitcode.
220 std::vector<uint8_t> CmdArgs;
222 /// \brief A list of all -fno-builtin-* function names (e.g., memset).
223 std::vector<std::string> NoBuiltinFuncs;
226 // Define accessors/mutators for code generation options of enumeration type.
227 #define CODEGENOPT(Name, Bits, Default)
228 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
229 Type get##Name() const { return static_cast<Type>(Name); } \
230 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
231 #include "clang/Frontend/CodeGenOptions.def"
235 /// \brief Is this a libc/libm function that is no longer recognized as a
236 /// builtin because a -fno-builtin-* option has been specified?
237 bool isNoBuiltinFunc(const char *Name) const;
239 const std::vector<std::string> &getNoBuiltinFuncs() const {
240 return NoBuiltinFuncs;
243 /// \brief Check if Clang profile instrumenation is on.
244 bool hasProfileClangInstr() const {
245 return getProfileInstr() == ProfileClangInstr;
248 /// \brief Check if IR level profile instrumentation is on.
249 bool hasProfileIRInstr() const {
250 return getProfileInstr() == ProfileIRInstr;
253 /// \brief Check if Clang profile use is on.
254 bool hasProfileClangUse() const {
255 return getProfileUse() == ProfileClangInstr;
258 /// \brief Check if IR level profile use is on.
259 bool hasProfileIRUse() const {
260 return getProfileUse() == ProfileIRInstr;
265 } // end namespace clang