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  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  /// 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 used for the DW_AT_[GNU_]dwo_name
187  /// attribute in the skeleton CU.
188  std::string SplitDwarfFile;
189 
190  /// Output filename for the split debug info, not used in the skeleton CU.
191  std::string SplitDwarfOutput;
192 
193  /// The name of the relocation model to use.
194  llvm::Reloc::Model RelocationModel;
195 
196  /// The thread model to use
197  std::string ThreadModel;
198 
199  /// If not an empty string, trap intrinsics are lowered to calls to this
200  /// function instead of to trap instructions.
201  std::string TrapFuncName;
202 
203  /// A list of dependent libraries.
204  std::vector<std::string> DependentLibraries;
205 
206  /// A list of linker options to embed in the object file.
207  std::vector<std::string> LinkerOptions;
208 
209  /// Name of the profile file to use as output for -fprofile-instr-generate,
210  /// -fprofile-generate, and -fcs-profile-generate.
211  std::string InstrProfileOutput;
212 
213  /// Name of the profile file to use with -fprofile-sample-use.
214  std::string SampleProfileFile;
215 
216  /// Name of the profile file to use as input for -fprofile-instr-use
218 
219  /// Name of the profile remapping file to apply to the profile data supplied
220  /// by -fprofile-sample-use or -fprofile-instr-use.
221  std::string ProfileRemappingFile;
222 
223  /// Name of the function summary index file to use for ThinLTO function
224  /// importing.
225  std::string ThinLTOIndexFile;
226 
227  /// Name of a file that can optionally be written with minimized bitcode
228  /// to be used as input for the ThinLTO thin link step, which only needs
229  /// the summary and module symbol table (and not, e.g. any debug metadata).
230  std::string ThinLinkBitcodeFile;
231 
232  /// Prefix to use for -save-temps output.
233  std::string SaveTempsFilePrefix;
234 
235  /// Name of file passed with -fcuda-include-gpubinary option to forward to
236  /// CUDA runtime back-end for incorporating them into host-side object file.
238 
239  /// The name of the file to which the backend should save YAML optimization
240  /// records.
241  std::string OptRecordFile;
242 
243  /// The regex that filters the passes that should be saved to the optimization
244  /// records.
245  std::string OptRecordPasses;
246 
247  /// The format used for serializing remarks (default: YAML)
248  std::string OptRecordFormat;
249 
250  /// The name of the partition that symbols are assigned to, specified with
251  /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
252  std::string SymbolPartition;
253 
254  /// Regular expression to select optimizations for which we should enable
255  /// optimization remarks. Transformation passes whose name matches this
256  /// expression (and support this feature), will emit a diagnostic
257  /// whenever they perform a transformation. This is enabled by the
258  /// -Rpass=regexp flag.
259  std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
260 
261  /// Regular expression to select optimizations for which we should enable
262  /// missed optimization remarks. Transformation passes whose name matches this
263  /// expression (and support this feature), will emit a diagnostic
264  /// whenever they tried but failed to perform a transformation. This is
265  /// enabled by the -Rpass-missed=regexp flag.
266  std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
267 
268  /// Regular expression to select optimizations for which we should enable
269  /// optimization analyses. Transformation passes whose name matches this
270  /// expression (and support this feature), will emit a diagnostic
271  /// whenever they want to explain why they decided to apply or not apply
272  /// a given transformation. This is enabled by the -Rpass-analysis=regexp
273  /// flag.
274  std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
275 
276  /// Set of files defining the rules for the symbol rewriting.
277  std::vector<std::string> RewriteMapFiles;
278 
279  /// Set of sanitizer checks that are non-fatal (i.e. execution should be
280  /// continued when possible).
282 
283  /// Set of sanitizer checks that trap rather than diagnose.
285 
286  /// List of backend command-line options for -fembed-bitcode.
287  std::vector<uint8_t> CmdArgs;
288 
289  /// A list of all -fno-builtin-* function names (e.g., memset).
290  std::vector<std::string> NoBuiltinFuncs;
291 
292  std::vector<std::string> Reciprocals;
293 
294  /// The preferred width for auto-vectorization transforms. This is intended to
295  /// override default transforms based on the width of the architected vector
296  /// registers.
297  std::string PreferVectorWidth;
298 
299  /// Set of XRay instrumentation kinds to emit.
301 
302  std::vector<std::string> DefaultFunctionAttrs;
303 
304  /// List of dynamic shared object files to be loaded as pass plugins.
305  std::vector<std::string> PassPlugins;
306 
307 public:
308  // Define accessors/mutators for code generation options of enumeration type.
309 #define CODEGENOPT(Name, Bits, Default)
310 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
311  Type get##Name() const { return static_cast<Type>(Name); } \
312  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
313 #include "clang/Basic/CodeGenOptions.def"
314 
315  CodeGenOptions();
316 
317  /// Is this a libc/libm function that is no longer recognized as a
318  /// builtin because a -fno-builtin-* option has been specified?
319  bool isNoBuiltinFunc(const char *Name) const;
320 
321  const std::vector<std::string> &getNoBuiltinFuncs() const {
322  return NoBuiltinFuncs;
323  }
324 
325  /// Check if Clang profile instrumenation is on.
326  bool hasProfileClangInstr() const {
327  return getProfileInstr() == ProfileClangInstr;
328  }
329 
330  /// Check if IR level profile instrumentation is on.
331  bool hasProfileIRInstr() const {
332  return getProfileInstr() == ProfileIRInstr;
333  }
334 
335  /// Check if CS IR level profile instrumentation is on.
336  bool hasProfileCSIRInstr() const {
337  return getProfileInstr() == ProfileCSIRInstr;
338  }
339 
340  /// Check if Clang profile use is on.
341  bool hasProfileClangUse() const {
342  return getProfileUse() == ProfileClangInstr;
343  }
344 
345  /// Check if IR level profile use is on.
346  bool hasProfileIRUse() const {
347  return getProfileUse() == ProfileIRInstr ||
348  getProfileUse() == ProfileCSIRInstr;
349  }
350 
351  /// Check if CSIR profile use is on.
352  bool hasProfileCSIRUse() const { return getProfileUse() == ProfileCSIRInstr; }
353 };
354 
355 } // end namespace clang
356 
357 #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...