clang  9.0.0svn
CodeGenOptions.h
Go to the documentation of this file.
1 //===--- CodeGenOptions.h ---------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the CodeGenOptions interface.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H
14 #define LLVM_CLANG_BASIC_CODEGENOPTIONS_H
15 
17 #include "clang/Basic/Sanitizers.h"
18 #include "clang/Basic/XRayInstr.h"
19 #include "llvm/Support/CodeGen.h"
20 #include "llvm/Support/Regex.h"
21 #include "llvm/Target/TargetOptions.h"
22 #include <map>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 namespace clang {
28 
29 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
30 /// that this large collection of bitfields is a trivial class type.
32 public:
33 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
34 #define ENUM_CODEGENOPT(Name, Type, Bits, Default)
35 #include "clang/Basic/CodeGenOptions.def"
36 
37 protected:
38 #define CODEGENOPT(Name, Bits, Default)
39 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
40 #include "clang/Basic/CodeGenOptions.def"
41 };
42 
43 /// CodeGenOptions - Track various options which control how the code
44 /// is optimized and passed to the backend.
46 public:
48  NormalInlining, // Use the standard function inlining pass.
49  OnlyHintInlining, // Inline only (implicitly) hinted functions.
50  OnlyAlwaysInlining // Only run the always inlining pass.
51  };
52 
54  NoLibrary, // Don't use any vector library.
55  Accelerate, // Use the Accelerate framework.
56  SVML // Intel short vector math library.
57  };
58 
59 
61  Legacy = 0,
62  NonLegacy = 1,
63  Mixed = 2
64  };
65 
66  enum TLSModel {
70  LocalExecTLSModel
71  };
72 
73  enum DwarfFissionKind { NoFission, SplitFileFission, SingleFileFission };
74 
75  /// Clang versions with different platform ABI conformance.
76  enum class ClangABI {
77  /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
78  /// (SVN r257626). This causes <1 x long long> to be passed in an
79  /// integer register instead of an SSE register on x64_64.
80  Ver3_8,
81 
82  /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
83  /// (SVN r291814). This causes move operations to be ignored when
84  /// determining whether a class type can be passed or returned directly.
85  Ver4,
86 
87  /// Conform to the underlying platform's C and C++ ABIs as closely
88  /// as we can.
89  Latest
90  };
91 
93  SRCK_Default, // No special option was passed.
94  SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return).
95  SRCK_InRegs // Small structs in registers (-freg-struct-return).
96  };
97 
99  ProfileNone, // Profile instrumentation is turned off.
100  ProfileClangInstr, // Clang instrumentation to generate execution counts
101  // to use with PGO.
102  ProfileIRInstr, // IR level PGO instrumentation in LLVM.
103  };
104 
106  Embed_Off, // No embedded bitcode.
107  Embed_All, // Embed both bitcode and commandline in the output.
108  Embed_Bitcode, // Embed just the bitcode in the output.
109  Embed_Marker // Embed a marker as a placeholder for bitcode.
110  };
111 
113  None, // No signing for any function
114  NonLeaf, // Sign the return address of functions that spill LR
115  All // Sign the return address of all functions
116  };
117 
118  enum SignReturnAddressKeyValue { AKey, BKey };
119 
120  /// The code model to use (-mcmodel).
121  std::string CodeModel;
122 
123  /// The filename with path we use for coverage data files. The runtime
124  /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
125  /// environment variables.
126  std::string CoverageDataFile;
127 
128  /// The filename with path we use for coverage notes files.
129  std::string CoverageNotesFile;
130 
131  /// Regexes separated by a semi-colon to filter the files to instrument.
132  std::string ProfileFilterFiles;
133 
134  /// Regexes separated by a semi-colon to filter the files to not instrument.
135  std::string ProfileExcludeFiles;
136 
137  /// The version string to put into coverage files.
138  char CoverageVersion[4];
139 
140  /// Enable additional debugging information.
141  std::string DebugPass;
142 
143  /// The string to embed in debug information as the current working directory.
144  std::string DebugCompilationDir;
145 
146  /// The string to embed in the debug information for the compile unit, if
147  /// non-empty.
148  std::string DwarfDebugFlags;
149 
150  /// The string containing the commandline for the llvm.commandline metadata,
151  /// if non-empty.
152  std::string RecordCommandLine;
153 
154  std::map<std::string, std::string> DebugPrefixMap;
155 
156  /// The ABI to use for passing floating point arguments.
157  std::string FloatABI;
158 
159  /// The floating-point denormal mode to use.
160  std::string FPDenormalMode;
161 
162  /// The float precision limit to use, if non-empty.
163  std::string LimitFloatPrecision;
164 
166  /// The filename of the bitcode file to link in.
167  std::string Filename;
168  /// If true, we set attributes functions in the bitcode library according to
169  /// our CodeGenOptions, much as we set attrs on functions that we generate
170  /// ourselves.
171  bool PropagateAttrs = false;
172  /// If true, we use LLVM module internalizer.
173  bool Internalize = false;
174  /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker.
175  unsigned LinkFlags = 0;
176  };
177 
178  /// The files specified here are linked in to the module before optimizations.
179  std::vector<BitcodeFileToLink> LinkBitcodeFiles;
180 
181  /// The user provided name for the "main file", if non-empty. This is useful
182  /// in situations where the input file name does not match the original input
183  /// file, for example with -save-temps.
184  std::string MainFileName;
185 
186  /// The name for the split debug info file that we'll break out. This is used
187  /// in the backend for setting the name in the skeleton cu.
188  std::string SplitDwarfFile;
189 
190  /// The name of the relocation model to use.
191  llvm::Reloc::Model RelocationModel;
192 
193  /// The thread model to use
194  std::string ThreadModel;
195 
196  /// If not an empty string, trap intrinsics are lowered to calls to this
197  /// function instead of to trap instructions.
198  std::string TrapFuncName;
199 
200  /// A list of dependent libraries.
201  std::vector<std::string> DependentLibraries;
202 
203  /// A list of linker options to embed in the object file.
204  std::vector<std::string> LinkerOptions;
205 
206  /// Name of the profile file to use as output for -fprofile-instr-generate
207  /// and -fprofile-generate.
208  std::string InstrProfileOutput;
209 
210  /// Name of the profile file to use with -fprofile-sample-use.
211  std::string SampleProfileFile;
212 
213  /// Name of the profile file to use as input for -fprofile-instr-use
215 
216  /// Name of the profile remapping file to apply to the profile data supplied
217  /// by -fprofile-sample-use or -fprofile-instr-use.
218  std::string ProfileRemappingFile;
219 
220  /// Name of the function summary index file to use for ThinLTO function
221  /// importing.
222  std::string ThinLTOIndexFile;
223 
224  /// Name of a file that can optionally be written with minimized bitcode
225  /// to be used as input for the ThinLTO thin link step, which only needs
226  /// the summary and module symbol table (and not, e.g. any debug metadata).
227  std::string ThinLinkBitcodeFile;
228 
229  /// Prefix to use for -save-temps output.
230  std::string SaveTempsFilePrefix;
231 
232  /// Name of file passed with -fcuda-include-gpubinary option to forward to
233  /// CUDA runtime back-end for incorporating them into host-side object file.
235 
236  /// The name of the file to which the backend should save YAML optimization
237  /// records.
238  std::string OptRecordFile;
239 
240  /// Regular expression to select optimizations for which we should enable
241  /// optimization remarks. Transformation passes whose name matches this
242  /// expression (and support this feature), will emit a diagnostic
243  /// whenever they perform a transformation. This is enabled by the
244  /// -Rpass=regexp flag.
245  std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
246 
247  /// Regular expression to select optimizations for which we should enable
248  /// missed optimization remarks. Transformation passes whose name matches this
249  /// expression (and support this feature), will emit a diagnostic
250  /// whenever they tried but failed to perform a transformation. This is
251  /// enabled by the -Rpass-missed=regexp flag.
252  std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
253 
254  /// Regular expression to select optimizations for which we should enable
255  /// optimization analyses. Transformation passes whose name matches this
256  /// expression (and support this feature), will emit a diagnostic
257  /// whenever they want to explain why they decided to apply or not apply
258  /// a given transformation. This is enabled by the -Rpass-analysis=regexp
259  /// flag.
260  std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
261 
262  /// Set of files defining the rules for the symbol rewriting.
263  std::vector<std::string> RewriteMapFiles;
264 
265  /// Set of sanitizer checks that are non-fatal (i.e. execution should be
266  /// continued when possible).
268 
269  /// Set of sanitizer checks that trap rather than diagnose.
271 
272  /// List of backend command-line options for -fembed-bitcode.
273  std::vector<uint8_t> CmdArgs;
274 
275  /// A list of all -fno-builtin-* function names (e.g., memset).
276  std::vector<std::string> NoBuiltinFuncs;
277 
278  std::vector<std::string> Reciprocals;
279 
280  /// The preferred width for auto-vectorization transforms. This is intended to
281  /// override default transforms based on the width of the architected vector
282  /// registers.
283  std::string PreferVectorWidth;
284 
285  /// Set of XRay instrumentation kinds to emit.
287 
288  std::vector<std::string> DefaultFunctionAttrs;
289 
290 public:
291  // Define accessors/mutators for code generation options of enumeration type.
292 #define CODEGENOPT(Name, Bits, Default)
293 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
294  Type get##Name() const { return static_cast<Type>(Name); } \
295  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
296 #include "clang/Basic/CodeGenOptions.def"
297 
298  CodeGenOptions();
299 
300  /// Is this a libc/libm function that is no longer recognized as a
301  /// builtin because a -fno-builtin-* option has been specified?
302  bool isNoBuiltinFunc(const char *Name) const;
303 
304  const std::vector<std::string> &getNoBuiltinFuncs() const {
305  return NoBuiltinFuncs;
306  }
307 
308  /// Check if Clang profile instrumenation is on.
309  bool hasProfileClangInstr() const {
310  return getProfileInstr() == ProfileClangInstr;
311  }
312 
313  /// Check if IR level profile instrumentation is on.
314  bool hasProfileIRInstr() const {
315  return getProfileInstr() == ProfileIRInstr;
316  }
317 
318  /// Check if Clang profile use is on.
319  bool hasProfileClangUse() const {
320  return getProfileUse() == ProfileClangInstr;
321  }
322 
323  /// Check if IR level profile use is on.
324  bool hasProfileIRUse() const {
325  return getProfileUse() == ProfileIRInstr;
326  }
327 
328 };
329 
330 } // end namespace clang
331 
332 #endif
std::string CoverageNotesFile
The filename with path we use for coverage notes files.
std::string ProfileInstrumentUsePath
Name of the profile file to use as input for -fprofile-instr-use.
std::string DwarfDebugFlags
The string to embed in the debug information for the compile unit, if non-empty.
std::string SaveTempsFilePrefix
Prefix to use for -save-temps output.
std::shared_ptr< llvm::Regex > OptimizationRemarkMissedPattern
Regular expression to select optimizations for which we should enable missed optimization remarks...
std::string FPDenormalMode
The floating-point denormal mode to use.
std::string SampleProfileFile
Name of the profile file to use with -fprofile-sample-use.
std::vector< std::string > Reciprocals
std::vector< std::string > RewriteMapFiles
Set of files defining the rules for the symbol rewriting.
Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure that this large collection of bi...
std::string SplitDwarfFile
The name for the split debug info file that we&#39;ll break out.
std::string DebugPass
Enable additional debugging information.
SanitizerSet SanitizeRecover
Set of sanitizer checks that are non-fatal (i.e.
Defines the clang::SanitizerKind enum.
std::map< std::string, std::string > DebugPrefixMap
std::vector< uint8_t > CmdArgs
List of backend command-line options for -fembed-bitcode.
std::string CodeModel
The code model to use (-mcmodel).
ClangABI
Clang versions with different platform ABI conformance.
std::string FloatABI
The ABI to use for passing floating point arguments.
bool hasProfileClangUse() const
Check if Clang profile use is on.
std::string ThreadModel
The thread model to use.
std::vector< std::string > DependentLibraries
A list of dependent libraries.
std::string ProfileFilterFiles
Regexes separated by a semi-colon to filter the files to instrument.
std::string ProfileRemappingFile
Name of the profile remapping file to apply to the profile data supplied by -fprofile-sample-use or -...
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
std::string LimitFloatPrecision
The float precision limit to use, if non-empty.
std::shared_ptr< llvm::Regex > OptimizationRemarkPattern
Regular expression to select optimizations for which we should enable optimization remarks...
Defines the clang::XRayInstrKind enum.
std::vector< std::string > DefaultFunctionAttrs
SanitizerSet SanitizeTrap
Set of sanitizer checks that trap rather than diagnose.
std::shared_ptr< llvm::Regex > OptimizationRemarkAnalysisPattern
Regular expression to select optimizations for which we should enable optimization analyses...
XRayInstrSet XRayInstrumentationBundle
Set of XRay instrumentation kinds to emit.
std::vector< BitcodeFileToLink > LinkBitcodeFiles
The files specified here are linked in to the module before optimizations.
std::string ThinLTOIndexFile
Name of the function summary index file to use for ThinLTO function importing.
std::string CudaGpuBinaryFileName
Name of file passed with -fcuda-include-gpubinary option to forward to CUDA runtime back-end for inco...
Dataflow Directional Tag Classes.
std::string PreferVectorWidth
The preferred width for auto-vectorization transforms.
llvm::Reloc::Model RelocationModel
The name of the relocation model to use.
bool hasProfileIRUse() const
Check if IR level profile use is on.
std::string DebugCompilationDir
The string to embed in debug information as the current working directory.
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
std::string ProfileExcludeFiles
Regexes separated by a semi-colon to filter the files to not instrument.
std::string CoverageDataFile
The filename with path we use for coverage data files.
std::vector< std::string > LinkerOptions
A list of linker options to embed in the object file.
std::string RecordCommandLine
The string containing the commandline for the llvm.commandline metadata, if non-empty.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
std::string MainFileName
The user provided name for the "main file", if non-empty.
bool hasProfileIRInstr() const
Check if IR level profile instrumentation is on.
const std::vector< std::string > & getNoBuiltinFuncs() const
std::string InstrProfileOutput
Name of the profile file to use as output for -fprofile-instr-generate and -fprofile-generate.
std::string TrapFuncName
If not an empty string, trap intrinsics are lowered to calls to this function instead of to trap inst...
std::string OptRecordFile
The name of the file to which the backend should save YAML optimization records.
std::string ThinLinkBitcodeFile
Name of a file that can optionally be written with minimized bitcode to be used as input for the Thin...