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 StructReturnConventionKind {
73 SRCK_Default, // No special option was passed.
74 SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return).
75 SRCK_InRegs // Small structs in registers (-freg-struct-return).
78 enum ProfileInstrKind {
79 ProfileNone, // Profile instrumentation is turned off.
80 ProfileClangInstr, // Clang instrumentation to generate execution counts
82 ProfileIRInstr, // IR level PGO instrumentation in LLVM.
85 enum EmbedBitcodeKind {
86 Embed_Off, // No embedded bitcode.
87 Embed_All, // Embed both bitcode and commandline in the output.
88 Embed_Bitcode, // Embed just the bitcode in the output.
89 Embed_Marker // Embed a marker as a placeholder for bitcode.
92 /// The code model to use (-mcmodel).
93 std::string CodeModel;
95 /// The filename with path we use for coverage data files. The runtime
96 /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
97 /// environment variables.
98 std::string CoverageDataFile;
100 /// The filename with path we use for coverage notes files.
101 std::string CoverageNotesFile;
103 /// The version string to put into coverage files.
104 char CoverageVersion[4];
106 /// Enable additional debugging information.
107 std::string DebugPass;
109 /// The string to embed in debug information as the current working directory.
110 std::string DebugCompilationDir;
112 /// The string to embed in the debug information for the compile unit, if
114 std::string DwarfDebugFlags;
116 std::map<std::string, std::string> DebugPrefixMap;
118 /// The ABI to use for passing floating point arguments.
119 std::string FloatABI;
121 /// The floating-point denormal mode to use.
122 std::string FPDenormalMode;
124 /// The float precision limit to use, if non-empty.
125 std::string LimitFloatPrecision;
127 struct BitcodeFileToLink {
128 /// The filename of the bitcode file to link in.
129 std::string Filename;
130 /// If true, we set attributes functions in the bitcode library according to
131 /// our CodeGenOptions, much as we set attrs on functions that we generate
133 bool PropagateAttrs = false;
134 /// If true, we use LLVM module internalizer.
135 bool Internalize = false;
136 /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker.
137 unsigned LinkFlags = 0;
140 /// The files specified here are linked in to the module before optimizations.
141 std::vector<BitcodeFileToLink> LinkBitcodeFiles;
143 /// The user provided name for the "main file", if non-empty. This is useful
144 /// in situations where the input file name does not match the original input
145 /// file, for example with -save-temps.
146 std::string MainFileName;
148 /// The name for the split debug info file that we'll break out. This is used
149 /// in the backend for setting the name in the skeleton cu.
150 std::string SplitDwarfFile;
152 /// The name of the relocation model to use.
153 std::string RelocationModel;
155 /// The thread model to use
156 std::string ThreadModel;
158 /// If not an empty string, trap intrinsics are lowered to calls to this
159 /// function instead of to trap instructions.
160 std::string TrapFuncName;
162 /// A list of command-line options to forward to the LLVM backend.
163 std::vector<std::string> BackendOptions;
165 /// A list of dependent libraries.
166 std::vector<std::string> DependentLibraries;
168 /// A list of linker options to embed in the object file.
169 std::vector<std::string> LinkerOptions;
171 /// Name of the profile file to use as output for -fprofile-instr-generate
172 /// and -fprofile-generate.
173 std::string InstrProfileOutput;
175 /// Name of the profile file to use with -fprofile-sample-use.
176 std::string SampleProfileFile;
178 /// Name of the profile file to use as input for -fprofile-instr-use
179 std::string ProfileInstrumentUsePath;
181 /// Name of the function summary index file to use for ThinLTO function
183 std::string ThinLTOIndexFile;
185 /// Name of a file that can optionally be written with minimized bitcode
186 /// to be used as input for the ThinLTO thin link step, which only needs
187 /// the summary and module symbol table (and not, e.g. any debug metadata).
188 std::string ThinLinkBitcodeFile;
190 /// A list of file names passed with -fcuda-include-gpubinary options to
191 /// forward to CUDA runtime back-end for incorporating them into host-side
193 std::vector<std::string> CudaGpuBinaryFileNames;
195 /// The name of the file to which the backend should save YAML optimization
197 std::string OptRecordFile;
199 /// Regular expression to select optimizations for which we should enable
200 /// optimization remarks. Transformation passes whose name matches this
201 /// expression (and support this feature), will emit a diagnostic
202 /// whenever they perform a transformation. This is enabled by the
203 /// -Rpass=regexp flag.
204 std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
206 /// Regular expression to select optimizations for which we should enable
207 /// missed optimization remarks. Transformation passes whose name matches this
208 /// expression (and support this feature), will emit a diagnostic
209 /// whenever they tried but failed to perform a transformation. This is
210 /// enabled by the -Rpass-missed=regexp flag.
211 std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
213 /// Regular expression to select optimizations for which we should enable
214 /// optimization analyses. Transformation passes whose name matches this
215 /// expression (and support this feature), will emit a diagnostic
216 /// whenever they want to explain why they decided to apply or not apply
217 /// a given transformation. This is enabled by the -Rpass-analysis=regexp
219 std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
221 /// Set of files defining the rules for the symbol rewriting.
222 std::vector<std::string> RewriteMapFiles;
224 /// Set of sanitizer checks that are non-fatal (i.e. execution should be
225 /// continued when possible).
226 SanitizerSet SanitizeRecover;
228 /// Set of sanitizer checks that trap rather than diagnose.
229 SanitizerSet SanitizeTrap;
231 /// List of backend command-line options for -fembed-bitcode.
232 std::vector<uint8_t> CmdArgs;
234 /// \brief A list of all -fno-builtin-* function names (e.g., memset).
235 std::vector<std::string> NoBuiltinFuncs;
238 // Define accessors/mutators for code generation options of enumeration type.
239 #define CODEGENOPT(Name, Bits, Default)
240 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
241 Type get##Name() const { return static_cast<Type>(Name); } \
242 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
243 #include "clang/Frontend/CodeGenOptions.def"
247 /// \brief Is this a libc/libm function that is no longer recognized as a
248 /// builtin because a -fno-builtin-* option has been specified?
249 bool isNoBuiltinFunc(const char *Name) const;
251 const std::vector<std::string> &getNoBuiltinFuncs() const {
252 return NoBuiltinFuncs;
255 /// \brief Check if Clang profile instrumenation is on.
256 bool hasProfileClangInstr() const {
257 return getProfileInstr() == ProfileClangInstr;
260 /// \brief Check if IR level profile instrumentation is on.
261 bool hasProfileIRInstr() const {
262 return getProfileInstr() == ProfileIRInstr;
265 /// \brief Check if Clang profile use is on.
266 bool hasProfileClangUse() const {
267 return getProfileUse() == ProfileClangInstr;
270 /// \brief Check if IR level profile use is on.
271 bool hasProfileIRUse() const {
272 return getProfileUse() == ProfileIRInstr;
277 } // end namespace clang