clang  10.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  MASSV, // IBM MASS vector library.
57  SVML // Intel short vector math library.
58  };
59 
60 
62  Legacy = 0,
63  NonLegacy = 1,
64  Mixed = 2
65  };
66 
67  enum TLSModel {
71  LocalExecTLSModel
72  };
73 
74  /// Clang versions with different platform ABI conformance.
75  enum class ClangABI {
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.
79  Ver3_8,
80 
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.
84  Ver4,
85 
86  /// Conform to the underlying platform's C and C++ ABIs as closely
87  /// as we can.
88  Latest
89  };
90 
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).
95  };
96 
98  ProfileNone, // Profile instrumentation is turned off.
99  ProfileClangInstr, // Clang instrumentation to generate execution counts
100  // to use with PGO.
101  ProfileIRInstr, // IR level PGO instrumentation in LLVM.
102  ProfileCSIRInstr, // IR level PGO context sensitive 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  enum class FramePointerKind {
121  None, // Omit all frame pointers.
122  NonLeaf, // Keep non-leaf frame pointers.
123  All, // Keep all frame pointers.
124  };
125 
126  /// The code model to use (-mcmodel).
127  std::string CodeModel;
128 
129  /// The filename with path we use for coverage data files. The runtime
130  /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
131  /// environment variables.
132  std::string CoverageDataFile;
133 
134  /// The filename with path we use for coverage notes files.
135  std::string CoverageNotesFile;
136 
137  /// Regexes separated by a semi-colon to filter the files to instrument.
138  std::string ProfileFilterFiles;
139 
140  /// Regexes separated by a semi-colon to filter the files to not instrument.
141  std::string ProfileExcludeFiles;
142 
143  /// The version string to put into coverage files.
144  char CoverageVersion[4];
145 
146  /// Enable additional debugging information.
147  std::string DebugPass;
148 
149  /// The string to embed in debug information as the current working directory.
150  std::string DebugCompilationDir;
151 
152  /// The string to embed in the debug information for the compile unit, if
153  /// non-empty.
154  std::string DwarfDebugFlags;
155 
156  /// The string containing the commandline for the llvm.commandline metadata,
157  /// if non-empty.
158  std::string RecordCommandLine;
159 
160  std::map<std::string, std::string> DebugPrefixMap;
161 
162  /// The ABI to use for passing floating point arguments.
163  std::string FloatABI;
164 
165  /// The floating-point denormal mode to use.
166  std::string FPDenormalMode;
167 
168  /// The float precision limit to use, if non-empty.
169  std::string LimitFloatPrecision;
170 
172  /// The filename of the bitcode file to link in.
173  std::string Filename;
174  /// If true, we set attributes functions in the bitcode library according to
175  /// our CodeGenOptions, much as we set attrs on functions that we generate
176  /// ourselves.
177  bool PropagateAttrs = false;
178  /// If true, we use LLVM module internalizer.
179  bool Internalize = false;
180  /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker.
181  unsigned LinkFlags = 0;
182  };
183 
184  /// The files specified here are linked in to the module before optimizations.
185  std::vector<BitcodeFileToLink> LinkBitcodeFiles;
186 
187  /// The user provided name for the "main file", if non-empty. This is useful
188  /// in situations where the input file name does not match the original input
189  /// file, for example with -save-temps.
190  std::string MainFileName;
191 
192  /// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
193  /// attribute in the skeleton CU.
194  std::string SplitDwarfFile;
195 
196  /// Output filename for the split debug info, not used in the skeleton CU.
197  std::string SplitDwarfOutput;
198 
199  /// The name of the relocation model to use.
200  llvm::Reloc::Model RelocationModel;
201 
202  /// The thread model to use
203  std::string ThreadModel;
204 
205  /// If not an empty string, trap intrinsics are lowered to calls to this
206  /// function instead of to trap instructions.
207  std::string TrapFuncName;
208 
209  /// A list of dependent libraries.
210  std::vector<std::string> DependentLibraries;
211 
212  /// A list of linker options to embed in the object file.
213  std::vector<std::string> LinkerOptions;
214 
215  /// Name of the profile file to use as output for -fprofile-instr-generate,
216  /// -fprofile-generate, and -fcs-profile-generate.
217  std::string InstrProfileOutput;
218 
219  /// Name of the profile file to use with -fprofile-sample-use.
220  std::string SampleProfileFile;
221 
222  /// Name of the profile file to use as input for -fprofile-instr-use
224 
225  /// Name of the profile remapping file to apply to the profile data supplied
226  /// by -fprofile-sample-use or -fprofile-instr-use.
227  std::string ProfileRemappingFile;
228 
229  /// Name of the function summary index file to use for ThinLTO function
230  /// importing.
231  std::string ThinLTOIndexFile;
232 
233  /// Name of a file that can optionally be written with minimized bitcode
234  /// to be used as input for the ThinLTO thin link step, which only needs
235  /// the summary and module symbol table (and not, e.g. any debug metadata).
236  std::string ThinLinkBitcodeFile;
237 
238  /// Prefix to use for -save-temps output.
239  std::string SaveTempsFilePrefix;
240 
241  /// Name of file passed with -fcuda-include-gpubinary option to forward to
242  /// CUDA runtime back-end for incorporating them into host-side object file.
244 
245  /// The name of the file to which the backend should save YAML optimization
246  /// records.
247  std::string OptRecordFile;
248 
249  /// The regex that filters the passes that should be saved to the optimization
250  /// records.
251  std::string OptRecordPasses;
252 
253  /// The format used for serializing remarks (default: YAML)
254  std::string OptRecordFormat;
255 
256  /// The name of the partition that symbols are assigned to, specified with
257  /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
258  std::string SymbolPartition;
259 
260  /// Regular expression to select optimizations for which we should enable
261  /// optimization remarks. Transformation passes whose name matches this
262  /// expression (and support this feature), will emit a diagnostic
263  /// whenever they perform a transformation. This is enabled by the
264  /// -Rpass=regexp flag.
265  std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
266 
267  /// Regular expression to select optimizations for which we should enable
268  /// missed optimization remarks. Transformation passes whose name matches this
269  /// expression (and support this feature), will emit a diagnostic
270  /// whenever they tried but failed to perform a transformation. This is
271  /// enabled by the -Rpass-missed=regexp flag.
272  std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
273 
274  /// Regular expression to select optimizations for which we should enable
275  /// optimization analyses. Transformation passes whose name matches this
276  /// expression (and support this feature), will emit a diagnostic
277  /// whenever they want to explain why they decided to apply or not apply
278  /// a given transformation. This is enabled by the -Rpass-analysis=regexp
279  /// flag.
280  std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
281 
282  /// Set of files defining the rules for the symbol rewriting.
283  std::vector<std::string> RewriteMapFiles;
284 
285  /// Set of sanitizer checks that are non-fatal (i.e. execution should be
286  /// continued when possible).
288 
289  /// Set of sanitizer checks that trap rather than diagnose.
291 
292  /// List of backend command-line options for -fembed-bitcode.
293  std::vector<uint8_t> CmdArgs;
294 
295  /// A list of all -fno-builtin-* function names (e.g., memset).
296  std::vector<std::string> NoBuiltinFuncs;
297 
298  std::vector<std::string> Reciprocals;
299 
300  /// The preferred width for auto-vectorization transforms. This is intended to
301  /// override default transforms based on the width of the architected vector
302  /// registers.
303  std::string PreferVectorWidth;
304 
305  /// Set of XRay instrumentation kinds to emit.
307 
308  std::vector<std::string> DefaultFunctionAttrs;
309 
310  /// List of dynamic shared object files to be loaded as pass plugins.
311  std::vector<std::string> PassPlugins;
312 
313 public:
314  // Define accessors/mutators for code generation options of enumeration type.
315 #define CODEGENOPT(Name, Bits, Default)
316 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
317  Type get##Name() const { return static_cast<Type>(Name); } \
318  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
319 #include "clang/Basic/CodeGenOptions.def"
320 
321  CodeGenOptions();
322 
323  /// Is this a libc/libm function that is no longer recognized as a
324  /// builtin because a -fno-builtin-* option has been specified?
325  bool isNoBuiltinFunc(const char *Name) const;
326 
327  const std::vector<std::string> &getNoBuiltinFuncs() const {
328  return NoBuiltinFuncs;
329  }
330 
331  /// Check if Clang profile instrumenation is on.
332  bool hasProfileClangInstr() const {
333  return getProfileInstr() == ProfileClangInstr;
334  }
335 
336  /// Check if IR level profile instrumentation is on.
337  bool hasProfileIRInstr() const {
338  return getProfileInstr() == ProfileIRInstr;
339  }
340 
341  /// Check if CS IR level profile instrumentation is on.
342  bool hasProfileCSIRInstr() const {
343  return getProfileInstr() == ProfileCSIRInstr;
344  }
345 
346  /// Check if Clang profile use is on.
347  bool hasProfileClangUse() const {
348  return getProfileUse() == ProfileClangInstr;
349  }
350 
351  /// Check if IR level profile use is on.
352  bool hasProfileIRUse() const {
353  return getProfileUse() == ProfileIRInstr ||
354  getProfileUse() == ProfileCSIRInstr;
355  }
356 
357  /// Check if CSIR profile use is on.
358  bool hasProfileCSIRUse() const { return getProfileUse() == ProfileCSIRInstr; }
359 };
360 
361 } // end namespace clang
362 
363 #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 OptRecordPasses
The regex that filters the passes that should be saved to the optimization records.
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 used for the DW_AT_[GNU_]dwo_name attribute in the skeleton CU...
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::string SplitDwarfOutput
Output filename for the split debug info, not used in the skeleton CU.
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.
bool hasProfileCSIRUse() const
Check if CSIR profile use is on.
std::vector< std::string > PassPlugins
List of dynamic shared object files to be loaded as pass plugins.
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...
std::string OptRecordFormat
The format used for serializing remarks (default: YAML)
Defines the clang::XRayInstrKind enum.
bool hasProfileCSIRInstr() const
Check if CS IR level profile instrumentation is on.
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 SymbolPartition
The name of the partition that symbols are assigned to, specified with -fsymbol-partition (see https:...
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, -fprofile-generate, and -fcs-profile-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...