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 NoInlining, // Perform no inlining whatsoever.
48 NormalInlining, // Use the standard function inlining pass.
49 OnlyHintInlining, // Inline only (implicitly) hinted functions.
50 OnlyAlwaysInlining // Only run the always inlining pass.
54 NoLibrary, // Don't use any vector library.
55 Accelerate // Use the Accelerate framework.
58 enum ObjCDispatchMethodKind {
65 GeneralDynamicTLSModel,
71 enum FPContractModeKind {
72 FPC_Off, // Form fused FP ops only where result will not be affected.
73 FPC_On, // Form fused FP ops according to FP_CONTRACT rules.
74 FPC_Fast // Aggressively fuse FP ops (E.g. FMA).
77 enum StructReturnConventionKind {
78 SRCK_Default, // No special option was passed.
79 SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return).
80 SRCK_InRegs // Small structs in registers (-freg-struct-return).
83 enum ProfileInstrKind {
84 ProfileNone, // Profile instrumentation is turned off.
85 ProfileClangInstr, // Clang instrumentation to generate execution counts
87 ProfileIRInstr, // IR level PGO instrumentation in LLVM.
90 enum EmbedBitcodeKind {
91 Embed_Off, // No embedded bitcode.
92 Embed_All, // Embed both bitcode and commandline in the output.
93 Embed_Bitcode, // Embed just the bitcode in the output.
94 Embed_Marker // Embed a marker as a placeholder for bitcode.
97 /// The code model to use (-mcmodel).
98 std::string CodeModel;
100 /// The filename with path we use for coverage files. The extension will be
102 std::string CoverageFile;
104 /// The version string to put into coverage files.
105 char CoverageVersion[4];
107 /// Enable additional debugging information.
108 std::string DebugPass;
110 /// The string to embed in debug information as the current working directory.
111 std::string DebugCompilationDir;
113 /// The string to embed in the debug information for the compile unit, if
115 std::string DwarfDebugFlags;
117 std::map<std::string, std::string> DebugPrefixMap;
119 /// The ABI to use for passing floating point arguments.
120 std::string FloatABI;
122 /// The float precision limit to use, if non-empty.
123 std::string LimitFloatPrecision;
125 /// The name of the bitcode file to link before optzns.
126 std::vector<std::pair<unsigned, std::string>> LinkBitcodeFiles;
128 /// The user provided name for the "main file", if non-empty. This is useful
129 /// in situations where the input file name does not match the original input
130 /// file, for example with -save-temps.
131 std::string MainFileName;
133 /// The name for the split debug info file that we'll break out. This is used
134 /// in the backend for setting the name in the skeleton cu.
135 std::string SplitDwarfFile;
137 /// The name of the relocation model to use.
138 std::string RelocationModel;
140 /// The thread model to use
141 std::string ThreadModel;
143 /// If not an empty string, trap intrinsics are lowered to calls to this
144 /// function instead of to trap instructions.
145 std::string TrapFuncName;
147 /// A list of command-line options to forward to the LLVM backend.
148 std::vector<std::string> BackendOptions;
150 /// A list of dependent libraries.
151 std::vector<std::string> DependentLibraries;
153 /// A list of linker options to embed in the object file.
154 std::vector<std::string> LinkerOptions;
156 /// Name of the profile file to use as output for -fprofile-instr-generate
157 /// and -fprofile-generate.
158 std::string InstrProfileOutput;
160 /// Name of the profile file to use with -fprofile-sample-use.
161 std::string SampleProfileFile;
163 /// Name of the profile file to use as input for -fprofile-instr-use
164 std::string ProfileInstrumentUsePath;
166 /// Name of the function summary index file to use for ThinLTO function
168 std::string ThinLTOIndexFile;
170 /// A list of file names passed with -fcuda-include-gpubinary options to
171 /// forward to CUDA runtime back-end for incorporating them into host-side
173 std::vector<std::string> CudaGpuBinaryFileNames;
175 /// Regular expression to select optimizations for which we should enable
176 /// optimization remarks. Transformation passes whose name matches this
177 /// expression (and support this feature), will emit a diagnostic
178 /// whenever they perform a transformation. This is enabled by the
179 /// -Rpass=regexp flag.
180 std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
182 /// Regular expression to select optimizations for which we should enable
183 /// missed optimization remarks. Transformation passes whose name matches this
184 /// expression (and support this feature), will emit a diagnostic
185 /// whenever they tried but failed to perform a transformation. This is
186 /// enabled by the -Rpass-missed=regexp flag.
187 std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
189 /// Regular expression to select optimizations for which we should enable
190 /// optimization analyses. Transformation passes whose name matches this
191 /// expression (and support this feature), will emit a diagnostic
192 /// whenever they want to explain why they decided to apply or not apply
193 /// a given transformation. This is enabled by the -Rpass-analysis=regexp
195 std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
197 /// Set of files definining the rules for the symbol rewriting.
198 std::vector<std::string> RewriteMapFiles;
200 /// Set of sanitizer checks that are non-fatal (i.e. execution should be
201 /// continued when possible).
202 SanitizerSet SanitizeRecover;
204 /// Set of sanitizer checks that trap rather than diagnose.
205 SanitizerSet SanitizeTrap;
207 /// List of backend command-line options for -fembed-bitcode.
208 std::vector<uint8_t> CmdArgs;
210 /// \brief A list of all -fno-builtin-* function names (e.g., memset).
211 std::vector<std::string> NoBuiltinFuncs;
214 // Define accessors/mutators for code generation options of enumeration type.
215 #define CODEGENOPT(Name, Bits, Default)
216 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
217 Type get##Name() const { return static_cast<Type>(Name); } \
218 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
219 #include "clang/Frontend/CodeGenOptions.def"
223 /// \brief Is this a libc/libm function that is no longer recognized as a
224 /// builtin because a -fno-builtin-* option has been specified?
225 bool isNoBuiltinFunc(const char *Name) const;
227 const std::vector<std::string> &getNoBuiltinFuncs() const {
228 return NoBuiltinFuncs;
231 /// \brief Check if Clang profile instrumenation is on.
232 bool hasProfileClangInstr() const {
233 return getProfileInstr() == ProfileClangInstr;
236 /// \brief Check if IR level profile instrumentation is on.
237 bool hasProfileIRInstr() const {
238 return getProfileInstr() == ProfileIRInstr;
241 /// \brief Check if Clang profile use is on.
242 bool hasProfileClangUse() const {
243 return getProfileUse() == ProfileClangInstr;
246 /// \brief Check if IR level profile use is on.
247 bool hasProfileIRUse() const {
248 return getProfileUse() == ProfileIRInstr;
253 } // end namespace clang