Coverage Report

Created: 2021-01-23 06:44

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Basic/CodeGenOptions.h
Line
Count
Source (jump to first uncovered line)
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
16
#include "clang/Basic/DebugInfoOptions.h"
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.
32
class CodeGenOptionsBase {
33
  friend class CompilerInvocation;
34
35
public:
36
#define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
37
#define ENUM_CODEGENOPT(Name, Type, Bits, Default)
38
#include "clang/Basic/CodeGenOptions.def"
39
40
protected:
41
#define CODEGENOPT(Name, Bits, Default)
42
#define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
43
#include "clang/Basic/CodeGenOptions.def"
44
};
45
46
/// CodeGenOptions - Track various options which control how the code
47
/// is optimized and passed to the backend.
48
class CodeGenOptions : public CodeGenOptionsBase {
49
public:
50
  enum InliningMethod {
51
    NormalInlining,     // Use the standard function inlining pass.
52
    OnlyHintInlining,   // Inline only (implicitly) hinted functions.
53
    OnlyAlwaysInlining  // Only run the always inlining pass.
54
  };
55
56
  enum VectorLibrary {
57
    NoLibrary,  // Don't use any vector library.
58
    Accelerate, // Use the Accelerate framework.
59
    LIBMVEC,    // GLIBC vector math library.
60
    MASSV,      // IBM MASS vector library.
61
    SVML        // Intel short vector math library.
62
  };
63
64
  enum ObjCDispatchMethodKind {
65
    Legacy = 0,
66
    NonLegacy = 1,
67
    Mixed = 2
68
  };
69
70
  enum TLSModel {
71
    GeneralDynamicTLSModel,
72
    LocalDynamicTLSModel,
73
    InitialExecTLSModel,
74
    LocalExecTLSModel
75
  };
76
77
  /// Clang versions with different platform ABI conformance.
78
  enum class ClangABI {
79
    /// Attempt to be ABI-compatible with code generated by Clang 3.8.x
80
    /// (SVN r257626). This causes <1 x long long> to be passed in an
81
    /// integer register instead of an SSE register on x64_64.
82
    Ver3_8,
83
84
    /// Attempt to be ABI-compatible with code generated by Clang 4.0.x
85
    /// (SVN r291814). This causes move operations to be ignored when
86
    /// determining whether a class type can be passed or returned directly.
87
    Ver4,
88
89
    /// Conform to the underlying platform's C and C++ ABIs as closely
90
    /// as we can.
91
    Latest
92
  };
93
94
  enum StructReturnConventionKind {
95
    SRCK_Default,  // No special option was passed.
96
    SRCK_OnStack,  // Small structs on the stack (-fpcc-struct-return).
97
    SRCK_InRegs    // Small structs in registers (-freg-struct-return).
98
  };
99
100
  enum ProfileInstrKind {
101
    ProfileNone,       // Profile instrumentation is turned off.
102
    ProfileClangInstr, // Clang instrumentation to generate execution counts
103
                       // to use with PGO.
104
    ProfileIRInstr,    // IR level PGO instrumentation in LLVM.
105
    ProfileCSIRInstr, // IR level PGO context sensitive instrumentation in LLVM.
106
  };
107
108
  enum EmbedBitcodeKind {
109
    Embed_Off,      // No embedded bitcode.
110
    Embed_All,      // Embed both bitcode and commandline in the output.
111
    Embed_Bitcode,  // Embed just the bitcode in the output.
112
    Embed_Marker    // Embed a marker as a placeholder for bitcode.
113
  };
114
115
  // This field stores one of the allowed values for the option
116
  // -fbasic-block-sections=.  The allowed values with this option are:
117
  // {"labels", "all", "list=<file>", "none"}.
118
  //
119
  // "labels":      Only generate basic block symbols (labels) for all basic
120
  //                blocks, do not generate unique sections for basic blocks.
121
  //                Use the machine basic block id in the symbol name to
122
  //                associate profile info from virtual address to machine
123
  //                basic block.
124
  // "all" :        Generate basic block sections for all basic blocks.
125
  // "list=<file>": Generate basic block sections for a subset of basic blocks.
126
  //                The functions and the machine basic block ids are specified
127
  //                in the file.
128
  // "none":        Disable sections/labels for basic blocks.
129
  std::string BBSections;
130
131
  enum class FramePointerKind {
132
    None,        // Omit all frame pointers.
133
    NonLeaf,     // Keep non-leaf frame pointers.
134
    All,         // Keep all frame pointers.
135
  };
136
137
  /// The code model to use (-mcmodel).
138
  std::string CodeModel;
139
140
  /// The filename with path we use for coverage data files. The runtime
141
  /// allows further manipulation with the GCOV_PREFIX and GCOV_PREFIX_STRIP
142
  /// environment variables.
143
  std::string CoverageDataFile;
144
145
  /// The filename with path we use for coverage notes files.
146
  std::string CoverageNotesFile;
147
148
  /// Regexes separated by a semi-colon to filter the files to instrument.
149
  std::string ProfileFilterFiles;
150
151
  /// Regexes separated by a semi-colon to filter the files to not instrument.
152
  std::string ProfileExcludeFiles;
153
154
  /// The version string to put into coverage files.
155
  char CoverageVersion[4];
156
157
  /// Enable additional debugging information.
158
  std::string DebugPass;
159
160
  /// The string to embed in debug information as the current working directory.
161
  std::string DebugCompilationDir;
162
163
  /// The string to embed in the debug information for the compile unit, if
164
  /// non-empty.
165
  std::string DwarfDebugFlags;
166
167
  /// The string containing the commandline for the llvm.commandline metadata,
168
  /// if non-empty.
169
  std::string RecordCommandLine;
170
171
  std::map<std::string, std::string> DebugPrefixMap;
172
173
  /// The ABI to use for passing floating point arguments.
174
  std::string FloatABI;
175
176
  /// The floating-point denormal mode to use.
177
  llvm::DenormalMode FPDenormalMode = llvm::DenormalMode::getIEEE();
178
179
  /// The floating-point denormal mode to use, for float.
180
  llvm::DenormalMode FP32DenormalMode = llvm::DenormalMode::getIEEE();
181
182
  /// The float precision limit to use, if non-empty.
183
  std::string LimitFloatPrecision;
184
185
  struct BitcodeFileToLink {
186
    /// The filename of the bitcode file to link in.
187
    std::string Filename;
188
    /// If true, we set attributes functions in the bitcode library according to
189
    /// our CodeGenOptions, much as we set attrs on functions that we generate
190
    /// ourselves.
191
    bool PropagateAttrs = false;
192
    /// If true, we use LLVM module internalizer.
193
    bool Internalize = false;
194
    /// Bitwise combination of llvm::Linker::Flags, passed to the LLVM linker.
195
    unsigned LinkFlags = 0;
196
  };
197
198
  /// The files specified here are linked in to the module before optimizations.
199
  std::vector<BitcodeFileToLink> LinkBitcodeFiles;
200
201
  /// The user provided name for the "main file", if non-empty. This is useful
202
  /// in situations where the input file name does not match the original input
203
  /// file, for example with -save-temps.
204
  std::string MainFileName;
205
206
  /// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
207
  /// attribute in the skeleton CU.
208
  std::string SplitDwarfFile;
209
210
  /// Output filename for the split debug info, not used in the skeleton CU.
211
  std::string SplitDwarfOutput;
212
213
  /// The name of the relocation model to use.
214
  llvm::Reloc::Model RelocationModel;
215
216
  /// If not an empty string, trap intrinsics are lowered to calls to this
217
  /// function instead of to trap instructions.
218
  std::string TrapFuncName;
219
220
  /// A list of dependent libraries.
221
  std::vector<std::string> DependentLibraries;
222
223
  /// A list of linker options to embed in the object file.
224
  std::vector<std::string> LinkerOptions;
225
226
  /// Name of the profile file to use as output for -fprofile-instr-generate,
227
  /// -fprofile-generate, and -fcs-profile-generate.
228
  std::string InstrProfileOutput;
229
230
  /// Name of the profile file to use with -fprofile-sample-use.
231
  std::string SampleProfileFile;
232
233
  /// Name of the profile file to use as output for with -fmemory-profile.
234
  std::string MemoryProfileOutput;
235
236
  /// Name of the profile file to use as input for -fprofile-instr-use
237
  std::string ProfileInstrumentUsePath;
238
239
  /// Name of the profile remapping file to apply to the profile data supplied
240
  /// by -fprofile-sample-use or -fprofile-instr-use.
241
  std::string ProfileRemappingFile;
242
243
  /// Name of the function summary index file to use for ThinLTO function
244
  /// importing.
245
  std::string ThinLTOIndexFile;
246
247
  /// Name of a file that can optionally be written with minimized bitcode
248
  /// to be used as input for the ThinLTO thin link step, which only needs
249
  /// the summary and module symbol table (and not, e.g. any debug metadata).
250
  std::string ThinLinkBitcodeFile;
251
252
  /// Prefix to use for -save-temps output.
253
  std::string SaveTempsFilePrefix;
254
255
  /// Name of file passed with -fcuda-include-gpubinary option to forward to
256
  /// CUDA runtime back-end for incorporating them into host-side object file.
257
  std::string CudaGpuBinaryFileName;
258
259
  /// The name of the file to which the backend should save YAML optimization
260
  /// records.
261
  std::string OptRecordFile;
262
263
  /// The regex that filters the passes that should be saved to the optimization
264
  /// records.
265
  std::string OptRecordPasses;
266
267
  /// The format used for serializing remarks (default: YAML)
268
  std::string OptRecordFormat;
269
270
  /// The name of the partition that symbols are assigned to, specified with
271
  /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
272
  std::string SymbolPartition;
273
274
  /// Regular expression to select optimizations for which we should enable
275
  /// optimization remarks. Transformation passes whose name matches this
276
  /// expression (and support this feature), will emit a diagnostic
277
  /// whenever they perform a transformation. This is enabled by the
278
  /// -Rpass=regexp flag.
279
  std::shared_ptr<llvm::Regex> OptimizationRemarkPattern;
280
281
  /// Regular expression to select optimizations for which we should enable
282
  /// missed optimization remarks. Transformation passes whose name matches this
283
  /// expression (and support this feature), will emit a diagnostic
284
  /// whenever they tried but failed to perform a transformation. This is
285
  /// enabled by the -Rpass-missed=regexp flag.
286
  std::shared_ptr<llvm::Regex> OptimizationRemarkMissedPattern;
287
288
  /// Regular expression to select optimizations for which we should enable
289
  /// optimization analyses. Transformation passes whose name matches this
290
  /// expression (and support this feature), will emit a diagnostic
291
  /// whenever they want to explain why they decided to apply or not apply
292
  /// a given transformation. This is enabled by the -Rpass-analysis=regexp
293
  /// flag.
294
  std::shared_ptr<llvm::Regex> OptimizationRemarkAnalysisPattern;
295
296
  /// Set of files defining the rules for the symbol rewriting.
297
  std::vector<std::string> RewriteMapFiles;
298
299
  /// Set of sanitizer checks that are non-fatal (i.e. execution should be
300
  /// continued when possible).
301
  SanitizerSet SanitizeRecover;
302
303
  /// Set of sanitizer checks that trap rather than diagnose.
304
  SanitizerSet SanitizeTrap;
305
306
  /// List of backend command-line options for -fembed-bitcode.
307
  std::vector<uint8_t> CmdArgs;
308
309
  /// A list of all -fno-builtin-* function names (e.g., memset).
310
  std::vector<std::string> NoBuiltinFuncs;
311
312
  std::vector<std::string> Reciprocals;
313
314
  /// The preferred width for auto-vectorization transforms. This is intended to
315
  /// override default transforms based on the width of the architected vector
316
  /// registers.
317
  std::string PreferVectorWidth;
318
319
  /// Set of XRay instrumentation kinds to emit.
320
  XRayInstrSet XRayInstrumentationBundle;
321
322
  std::vector<std::string> DefaultFunctionAttrs;
323
324
  /// List of dynamic shared object files to be loaded as pass plugins.
325
  std::vector<std::string> PassPlugins;
326
327
  /// Path to allowlist file specifying which objects
328
  /// (files, functions) should exclusively be instrumented
329
  /// by sanitizer coverage pass.
330
  std::vector<std::string> SanitizeCoverageAllowlistFiles;
331
332
  /// The guard style used for stack protector to get a initial value, this
333
  /// value usually be gotten from TLS or get from __stack_chk_guard, or some
334
  /// other styles we may implement in the future.
335
  std::string StackProtectorGuard;
336
337
  /// The TLS base register when StackProtectorGuard is "tls".
338
  /// On x86 this can be "fs" or "gs".
339
  std::string StackProtectorGuardReg;
340
341
  /// Path to blocklist file specifying which objects
342
  /// (files, functions) listed for instrumentation by sanitizer
343
  /// coverage pass should actually not be instrumented.
344
  std::vector<std::string> SanitizeCoverageBlocklistFiles;
345
346
  /// Executable and command-line used to create a given CompilerInvocation.
347
  /// Most of the time this will be the full -cc1 command.
348
  const char *Argv0 = nullptr;
349
  ArrayRef<const char *> CommandLineArgs;
350
351
  /// The minimum hotness value a diagnostic needs in order to be included in
352
  /// optimization diagnostics.
353
  ///
354
  /// The threshold is an Optional value, which maps to one of the 3 states:
355
  /// 1. 0            => threshold disabled. All remarks will be printed.
356
  /// 2. positive int => manual threshold by user. Remarks with hotness exceed
357
  ///                    threshold will be printed.
358
  /// 3. None         => 'auto' threshold by user. The actual value is not
359
  ///                    available at command line, but will be synced with
360
  ///                    hotness threshold from profile summary during
361
  ///                    compilation.
362
  ///
363
  /// If threshold option is not specified, it is disabled by default.
364
  Optional<uint64_t> DiagnosticsHotnessThreshold = 0;
365
366
public:
367
  // Define accessors/mutators for code generation options of enumeration type.
368
#define CODEGENOPT(Name, Bits, Default)
369
#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
370
5.77M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getDebugInfo() const
Line
Count
Source
370
4.37M
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getProfileUse() const
Line
Count
Source
370
131k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getCompressDebugSections() const
Line
Count
Source
370
17.9k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getFramePointer() const
Line
Count
Source
370
325k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getEmbedBitcode() const
Line
Count
Source
370
17.8k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getObjCDispatchMethod() const
Line
Count
Source
370
12.0k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getProfileInstr() const
Line
Count
Source
370
696k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getStructReturnConvention() const
Line
Count
Source
370
3.04k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getDebuggerTuning() const
Line
Count
Source
370
93.1k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getInlining() const
Line
Count
Source
370
80.0k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getVecLib() const
Line
Count
Source
370
21.6k
  Type get##Name() const { return static_cast<Type>(Name); } \
clang::CodeGenOptions::getDefaultTLSModel() const
Line
Count
Source
370
583
  Type get##Name() const { return static_cast<Type>(Name); } \
371
1.40M
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setCompressDebugSections(llvm::DebugCompressionType)
Line
Count
Source
371
109k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setFramePointer(clang::CodeGenOptions::FramePointerKind)
Line
Count
Source
371
122k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setEmbedBitcode(clang::CodeGenOptions::EmbedBitcodeKind)
Line
Count
Source
371
109k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setObjCDispatchMethod(clang::CodeGenOptions::ObjCDispatchMethodKind)
Line
Count
Source
371
109k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setProfileInstr(clang::CodeGenOptions::ProfileInstrKind)
Line
Count
Source
371
109k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setProfileUse(clang::CodeGenOptions::ProfileInstrKind)
Line
Count
Source
371
109k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setStructReturnConvention(clang::CodeGenOptions::StructReturnConventionKind)
Line
Count
Source
371
109k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setDebugInfo(clang::codegenoptions::DebugInfoKind)
Line
Count
Source
371
123k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setDebuggerTuning(llvm::DebuggerKind)
Line
Count
Source
371
109k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setInlining(clang::CodeGenOptions::InliningMethod)
Line
Count
Source
371
174k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setVecLib(clang::CodeGenOptions::VectorLibrary)
Line
Count
Source
371
109k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
clang::CodeGenOptions::setDefaultTLSModel(clang::CodeGenOptions::TLSModel)
Line
Count
Source
371
109k
  void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
372
#include "clang/Basic/CodeGenOptions.def"
373
374
  CodeGenOptions();
375
376
  /// Is this a libc/libm function that is no longer recognized as a
377
  /// builtin because a -fno-builtin-* option has been specified?
378
  bool isNoBuiltinFunc(const char *Name) const;
379
380
0
  const std::vector<std::string> &getNoBuiltinFuncs() const {
381
0
    return NoBuiltinFuncs;
382
0
  }
383
384
  /// Check if Clang profile instrumenation is on.
385
661k
  bool hasProfileClangInstr() const {
386
661k
    return getProfileInstr() == ProfileClangInstr;
387
661k
  }
388
389
  /// Check if IR level profile instrumentation is on.
390
17.5k
  bool hasProfileIRInstr() const {
391
17.5k
    return getProfileInstr() == ProfileIRInstr;
392
17.5k
  }
393
394
  /// Check if CS IR level profile instrumentation is on.
395
17.5k
  bool hasProfileCSIRInstr() const {
396
17.5k
    return getProfileInstr() == ProfileCSIRInstr;
397
17.5k
  }
398
399
  /// Check if Clang profile use is on.
400
31.4k
  bool hasProfileClangUse() const {
401
31.4k
    return getProfileUse() == ProfileClangInstr;
402
31.4k
  }
403
404
  /// Check if IR level profile use is on.
405
17.5k
  bool hasProfileIRUse() const {
406
17.5k
    return getProfileUse() == ProfileIRInstr ||
407
17.5k
           getProfileUse() == ProfileCSIRInstr;
408
17.5k
  }
409
410
  /// Check if CSIR profile use is on.
411
88
  bool hasProfileCSIRUse() const { return getProfileUse() == ProfileCSIRInstr; }
412
413
  /// Check if type and variable info should be emitted.
414
1.63M
  bool hasReducedDebugInfo() const {
415
1.63M
    return getDebugInfo() >= codegenoptions::DebugInfoConstructor;
416
1.63M
  }
417
418
  /// Check if maybe unused type info should be emitted.
419
2.60M
  bool hasMaybeUnusedDebugInfo() const {
420
2.60M
    return getDebugInfo() >= codegenoptions::UnusedTypeInfo;
421
2.60M
  }
422
};
423
424
}  // end namespace clang
425
426
#endif