clang  10.0.0git
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/ADT/FloatingPointMode.h"
20 #include "llvm/Support/CodeGen.h"
21 #include "llvm/Support/Regex.h"
22 #include "llvm/Target/TargetOptions.h"
23 #include <map>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 namespace clang {
29 
30 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
31 /// that this large collection of bitfields is a trivial class type.
33 public:
34 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
35 #define ENUM_CODEGENOPT(Name, Type, Bits, Default)
36 #include "clang/Basic/CodeGenOptions.def"
37 
38 protected:
39 #define CODEGENOPT(Name, Bits, Default)
40 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
41 #include "clang/Basic/CodeGenOptions.def"
42 };
43 
44 /// CodeGenOptions - Track various options which control how the code
45 /// is optimized and passed to the backend.
47 public:
49  NormalInlining, // Use the standard function inlining pass.
50  OnlyHintInlining, // Inline only (implicitly) hinted functions.
51  OnlyAlwaysInlining // Only run the always inlining pass.
52  };
53 
55  NoLibrary, // Don't use any vector library.
56  Accelerate, // Use the Accelerate framework.
57  MASSV, // IBM MASS vector library.
58  SVML // Intel short vector math library.
59  };
60 
61 
63  Legacy = 0,
64  NonLegacy = 1,
65  Mixed = 2
66  };
67 
68  enum TLSModel {
72  LocalExecTLSModel
73  };
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  ProfileCSIRInstr, // IR level PGO context sensitive instrumentation in LLVM.
104  };
105 
107  Embed_Off, // No embedded bitcode.
108  Embed_All, // Embed both bitcode and commandline in the output.
109  Embed_Bitcode, // Embed just the bitcode in the output.
110  Embed_Marker // Embed a marker as a placeholder for bitcode.
111  };
112 
114  None, // No signing for any function
115  NonLeaf, // Sign the return address of functions that spill LR
116  All // Sign the return address of all functions
117  };
118 
119  enum class SignReturnAddressKeyValue { AKey, BKey };
120 
121  enum class FramePointerKind {
122  None, // Omit all frame pointers.
123  NonLeaf, // Keep non-leaf frame pointers.
124  All, // Keep all frame pointers.
125  };
126 
127  /// The code model to use (-mcmodel).
128  std::string CodeModel;
129 
130  /// The filename with path we use for coverage data files. The runtime
131  /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
132  /// environment variables.
133  std::string CoverageDataFile;
134 
135  /// The filename with path we use for coverage notes files.
136  std::string CoverageNotesFile;
137 
138  /// Regexes separated by a semi-colon to filter the files to instrument.
139  std::string ProfileFilterFiles;
140 
141  /// Regexes separated by a semi-colon to filter the files to not instrument.
142  std::string ProfileExcludeFiles;
143 
144  /// The version string to put into coverage files.
145  char CoverageVersion[4];
146 
147  /// Enable additional debugging information.
148  std::string DebugPass;
149 
150  /// The string to embed in debug information as the current working directory.
151  std::string DebugCompilationDir;
152 
153  /// The string to embed in the debug information for the compile unit, if
154  /// non-empty.
155  std::string DwarfDebugFlags;
156 
157  /// The string containing the commandline for the llvm.commandline metadata,
158  /// if non-empty.
159  std::string RecordCommandLine;
160 
161  std::map<std::string, std::string> DebugPrefixMap;
162 
163  /// The ABI to use for passing floating point arguments.
164  std::string FloatABI;
165 
166  /// The floating-point denormal mode to use.
167  llvm::DenormalMode FPDenormalMode = llvm::DenormalMode::Invalid;
168 
169  /// The float precision limit to use, if non-empty.
170  std::string LimitFloatPrecision;
171 
173  /// The filename of the bitcode file to link in.
174  std::string Filename;
175  /// If true, we set attributes functions in the bitcode library according to
176  /// our CodeGenOptions, much as we set attrs on functions that we generate
177  /// ourselves.
178  bool PropagateAttrs = false;
179  /// If true, we use LLVM module internalizer.
180  bool Internalize = false;
181  /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker.
182  unsigned LinkFlags = 0;
183  };
184 
185  /// The files specified here are linked in to the module before optimizations.
186  std::vector<BitcodeFileToLink> LinkBitcodeFiles;
187 
188  /// The user provided name for the "main file", if non-empty. This is useful
189  /// in situations where the input file name does not match the original input
190  /// file, for example with -save-temps.
191  std::string MainFileName;
192 
193  /// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
194  /// attribute in the skeleton CU.
195  std::string SplitDwarfFile;
196 
197  /// Output filename for the split debug info, not used in the skeleton CU.
198  std::string SplitDwarfOutput;
199 
200  /// The name of the relocation model to use.
201  llvm::Reloc::Model RelocationModel;
202 
203  /// The thread model to use
204  std::string ThreadModel;
205 
206  /// If not an empty string, trap intrinsics are lowered to calls to this
207  /// function instead of to trap instructions.
208  std::string TrapFuncName;
209 
210  /// A list of dependent libraries.
211  std::vector<std::string> DependentLibraries;
212 
213  /// A list of linker options to embed in the object file.
214  std::vector<std::string> LinkerOptions;
215 
216  /// Name of the profile file to use as output for -fprofile-instr-generate,
217  /// -fprofile-generate, and -fcs-profile-generate.
218  std::string InstrProfileOutput;
219 
220  /// Name of the profile file to use with -fprofile-sample-use.
221  std::string SampleProfileFile;
222 
223  /// Name of the profile file to use as input for -fprofile-instr-use
225 
226  /// Name of the profile remapping file to apply to the profile data supplied
227  /// by -fprofile-sample-use or -fprofile-instr-use.
228  std::string ProfileRemappingFile;
229 
230  /// Name of the function summary index file to use for ThinLTO function
231  /// importing.
232  std::string ThinLTOIndexFile;
233 
234  /// Name of a file that can optionally be written with minimized bitcode
235  /// to be used as input for the ThinLTO thin link step, which only needs
236  /// the summary and module symbol table (and not, e.g. any debug metadata).
237  std::string ThinLinkBitcodeFile;
238 
239  /// Prefix to use for -save-temps output.
240  std::string SaveTempsFilePrefix;
241 
242  /// Name of file passed with -fcuda-include-gpubinary option to forward to
243  /// CUDA runtime back-end for incorporating them into host-side object file.
245 
246  /// The name of the file to which the backend should save YAML optimization
247  /// records.
248  std::string OptRecordFile;
249 
250  /// The regex that filters the passes that should be saved to the optimization
251  /// records.
252  std::string OptRecordPasses;
253 
254  /// The format used for serializing remarks (default: YAML)
255  std::string OptRecordFormat;
256 
257  /// The name of the partition that symbols are assigned to, specified with
258  /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
259  std::string SymbolPartition;
260 
261  /// Regular expression to select optimizations for which we should enable
262  /// optimization remarks. Transformation passes whose name matches this
263  /// expression (and support this feature), will emit a diagnostic
264  /// whenever they perform a transformation. This is enabled by the
265  /// -Rpass=regexp flag.
266  std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
267 
268  /// Regular expression to select optimizations for which we should enable
269  /// missed optimization remarks. Transformation passes whose name matches this
270  /// expression (and support this feature), will emit a diagnostic
271  /// whenever they tried but failed to perform a transformation. This is
272  /// enabled by the -Rpass-missed=regexp flag.
273  std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
274 
275  /// Regular expression to select optimizations for which we should enable
276  /// optimization analyses. Transformation passes whose name matches this
277  /// expression (and support this feature), will emit a diagnostic
278  /// whenever they want to explain why they decided to apply or not apply
279  /// a given transformation. This is enabled by the -Rpass-analysis=regexp
280  /// flag.
281  std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
282 
283  /// Set of files defining the rules for the symbol rewriting.
284  std::vector<std::string> RewriteMapFiles;
285 
286  /// Set of sanitizer checks that are non-fatal (i.e. execution should be
287  /// continued when possible).
289 
290  /// Set of sanitizer checks that trap rather than diagnose.
292 
293  /// List of backend command-line options for -fembed-bitcode.
294  std::vector<uint8_t> CmdArgs;
295 
296  /// A list of all -fno-builtin-* function names (e.g., memset).
297  std::vector<std::string> NoBuiltinFuncs;
298 
299  std::vector<std::string> Reciprocals;
300 
301  /// The preferred width for auto-vectorization transforms. This is intended to
302  /// override default transforms based on the width of the architected vector
303  /// registers.
304  std::string PreferVectorWidth;
305 
306  /// Set of XRay instrumentation kinds to emit.
308 
309  std::vector<std::string> DefaultFunctionAttrs;
310 
311  /// List of dynamic shared object files to be loaded as pass plugins.
312  std::vector<std::string> PassPlugins;
313 
314 public:
315  // Define accessors/mutators for code generation options of enumeration type.
316 #define CODEGENOPT(Name, Bits, Default)
317 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
318  Type get##Name() const { return static_cast<Type>(Name); } \
319  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
320 #include "clang/Basic/CodeGenOptions.def"
321 
322  CodeGenOptions();
323 
324  /// Is this a libc/libm function that is no longer recognized as a
325  /// builtin because a -fno-builtin-* option has been specified?
326  bool isNoBuiltinFunc(const char *Name) const;
327 
328  const std::vector<std::string> &getNoBuiltinFuncs() const {
329  return NoBuiltinFuncs;
330  }
331 
332  /// Check if Clang profile instrumenation is on.
333  bool hasProfileClangInstr() const {
334  return getProfileInstr() == ProfileClangInstr;
335  }
336 
337  /// Check if IR level profile instrumentation is on.
338  bool hasProfileIRInstr() const {
339  return getProfileInstr() == ProfileIRInstr;
340  }
341 
342  /// Check if CS IR level profile instrumentation is on.
343  bool hasProfileCSIRInstr() const {
344  return getProfileInstr() == ProfileCSIRInstr;
345  }
346 
347  /// Check if Clang profile use is on.
348  bool hasProfileClangUse() const {
349  return getProfileUse() == ProfileClangInstr;
350  }
351 
352  /// Check if IR level profile use is on.
353  bool hasProfileIRUse() const {
354  return getProfileUse() == ProfileIRInstr ||
355  getProfileUse() == ProfileCSIRInstr;
356  }
357 
358  /// Check if CSIR profile use is on.
359  bool hasProfileCSIRUse() const { return getProfileUse() == ProfileCSIRInstr; }
360 
361  /// Check if type and variable info should be emitted.
362  bool hasReducedDebugInfo() const {
363  return getDebugInfo() >= codegenoptions::DebugInfoConstructor;
364  }
365 };
366 
367 } // end namespace clang
368 
369 #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 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.
Limit generated debug info for classes to reduce size.
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...
bool hasReducedDebugInfo() const
Check if type and variable info should be emitted.
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...