Coverage Report

Created: 2019-02-21 13:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/CommandFlags.inc
Line
Count
Source (jump to first uncovered line)
1
//===-- CommandFlags.h - Command Line Flags Interface -----------*- 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 contains codegen-specific flags that are shared between different
10
// command line tools. The tools "llc" and "opt" both use this file to prevent
11
// flag duplication.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#include "llvm/ADT/StringExtras.h"
16
#include "llvm/IR/Instructions.h"
17
#include "llvm/IR/Intrinsics.h"
18
#include "llvm/IR/Module.h"
19
#include "llvm/MC/MCTargetOptionsCommandFlags.inc"
20
#include "llvm/MC/SubtargetFeature.h"
21
#include "llvm/Support/CodeGen.h"
22
#include "llvm/Support/CommandLine.h"
23
#include "llvm/Support/Host.h"
24
#include "llvm/Target/TargetMachine.h"
25
#include "llvm/Target/TargetOptions.h"
26
#include <string>
27
using namespace llvm;
28
29
static cl::opt<std::string>
30
    MArch("march",
31
          cl::desc("Architecture to generate code for (see --version)"));
32
33
static cl::opt<std::string>
34
    MCPU("mcpu",
35
         cl::desc("Target a specific cpu type (-mcpu=help for details)"),
36
         cl::value_desc("cpu-name"), cl::init(""));
37
38
static cl::list<std::string>
39
    MAttrs("mattr", cl::CommaSeparated,
40
           cl::desc("Target specific attributes (-mattr=help for details)"),
41
           cl::value_desc("a1,+a2,-a3,..."));
42
43
static cl::opt<Reloc::Model> RelocModel(
44
    "relocation-model", cl::desc("Choose relocation model"),
45
    cl::values(
46
        clEnumValN(Reloc::Static, "static", "Non-relocatable code"),
47
        clEnumValN(Reloc::PIC_, "pic",
48
                   "Fully relocatable, position independent code"),
49
        clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
50
                   "Relocatable external references, non-relocatable code"),
51
        clEnumValN(Reloc::ROPI, "ropi",
52
                   "Code and read-only data relocatable, accessed PC-relative"),
53
        clEnumValN(
54
            Reloc::RWPI, "rwpi",
55
            "Read-write data relocatable, accessed relative to static base"),
56
        clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
57
                   "Combination of ropi and rwpi")));
58
59
26.8k
LLVM_ATTRIBUTE_UNUSED static Optional<Reloc::Model> getRelocModel() {
60
26.8k
  if (RelocModel.getNumOccurrences()) {
61
1.92k
    Reloc::Model R = RelocModel;
62
1.92k
    return R;
63
1.92k
  }
64
24.9k
  return None;
65
24.9k
}
opt.cpp:getRelocModel()
Line
Count
Source
59
4.32k
LLVM_ATTRIBUTE_UNUSED static Optional<Reloc::Model> getRelocModel() {
60
4.32k
  if (RelocModel.getNumOccurrences()) {
61
6
    Reloc::Model R = RelocModel;
62
6
    return R;
63
6
  }
64
4.32k
  return None;
65
4.32k
}
llc.cpp:getRelocModel()
Line
Count
Source
59
22.5k
LLVM_ATTRIBUTE_UNUSED static Optional<Reloc::Model> getRelocModel() {
60
22.5k
  if (RelocModel.getNumOccurrences()) {
61
1.91k
    Reloc::Model R = RelocModel;
62
1.91k
    return R;
63
1.91k
  }
64
20.6k
  return None;
65
20.6k
}
66
67
static cl::opt<ThreadModel::Model> TMModel(
68
    "thread-model", cl::desc("Choose threading model"),
69
    cl::init(ThreadModel::POSIX),
70
    cl::values(clEnumValN(ThreadModel::POSIX, "posix", "POSIX thread model"),
71
               clEnumValN(ThreadModel::Single, "single",
72
                          "Single thread model")));
73
74
static cl::opt<llvm::CodeModel::Model> CMModel(
75
    "code-model", cl::desc("Choose code model"),
76
    cl::values(clEnumValN(CodeModel::Tiny, "tiny", "Tiny code model"),
77
               clEnumValN(CodeModel::Small, "small", "Small code model"),
78
               clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"),
79
               clEnumValN(CodeModel::Medium, "medium", "Medium code model"),
80
               clEnumValN(CodeModel::Large, "large", "Large code model")));
81
82
26.8k
LLVM_ATTRIBUTE_UNUSED static Optional<CodeModel::Model> getCodeModel() {
83
26.8k
  if (CMModel.getNumOccurrences()) {
84
207
    CodeModel::Model M = CMModel;
85
207
    return M;
86
207
  }
87
26.6k
  return None;
88
26.6k
}
opt.cpp:getCodeModel()
Line
Count
Source
82
4.32k
LLVM_ATTRIBUTE_UNUSED static Optional<CodeModel::Model> getCodeModel() {
83
4.32k
  if (CMModel.getNumOccurrences()) {
84
0
    CodeModel::Model M = CMModel;
85
0
    return M;
86
0
  }
87
4.32k
  return None;
88
4.32k
}
llc.cpp:getCodeModel()
Line
Count
Source
82
22.5k
LLVM_ATTRIBUTE_UNUSED static Optional<CodeModel::Model> getCodeModel() {
83
22.5k
  if (CMModel.getNumOccurrences()) {
84
207
    CodeModel::Model M = CMModel;
85
207
    return M;
86
207
  }
87
22.3k
  return None;
88
22.3k
}
89
90
static cl::opt<llvm::ExceptionHandling> ExceptionModel(
91
    "exception-model", cl::desc("exception model"),
92
    cl::init(ExceptionHandling::None),
93
    cl::values(
94
        clEnumValN(ExceptionHandling::None, "default",
95
                   "default exception handling model"),
96
        clEnumValN(ExceptionHandling::DwarfCFI, "dwarf",
97
                   "DWARF-like CFI based exception handling"),
98
        clEnumValN(ExceptionHandling::SjLj, "sjlj", "SjLj exception handling"),
99
        clEnumValN(ExceptionHandling::ARM, "arm", "ARM EHABI exceptions"),
100
        clEnumValN(ExceptionHandling::WinEH, "wineh",
101
                   "Windows exception model"),
102
        clEnumValN(ExceptionHandling::Wasm, "wasm",
103
                   "WebAssembly exception handling")));
104
105
static cl::opt<TargetMachine::CodeGenFileType> FileType(
106
    "filetype", cl::init(TargetMachine::CGFT_AssemblyFile),
107
    cl::desc(
108
        "Choose a file type (not all types are supported by all targets):"),
109
    cl::values(clEnumValN(TargetMachine::CGFT_AssemblyFile, "asm",
110
                          "Emit an assembly ('.s') file"),
111
               clEnumValN(TargetMachine::CGFT_ObjectFile, "obj",
112
                          "Emit a native object ('.o') file"),
113
               clEnumValN(TargetMachine::CGFT_Null, "null",
114
                          "Emit nothing, for performance testing")));
115
116
static cl::opt<llvm::FramePointer::FP> FramePointerUsage(
117
    "frame-pointer", cl::desc("Specify frame pointer elimination optimization"),
118
    cl::init(llvm::FramePointer::None),
119
    cl::values(
120
        clEnumValN(llvm::FramePointer::All, "all",
121
                   "Disable frame pointer elimination"),
122
        clEnumValN(llvm::FramePointer::NonLeaf, "non-leaf",
123
                   "Disable frame pointer elimination for non-leaf frame"),
124
        clEnumValN(llvm::FramePointer::None, "none",
125
                   "Enable frame pointer elimination")));
126
127
static cl::opt<bool> EnableUnsafeFPMath(
128
    "enable-unsafe-fp-math",
129
    cl::desc("Enable optimizations that may decrease FP precision"),
130
    cl::init(false));
131
132
static cl::opt<bool> EnableNoInfsFPMath(
133
    "enable-no-infs-fp-math",
134
    cl::desc("Enable FP math optimizations that assume no +-Infs"),
135
    cl::init(false));
136
137
static cl::opt<bool> EnableNoNaNsFPMath(
138
    "enable-no-nans-fp-math",
139
    cl::desc("Enable FP math optimizations that assume no NaNs"),
140
    cl::init(false));
141
142
static cl::opt<bool> EnableNoSignedZerosFPMath(
143
    "enable-no-signed-zeros-fp-math",
144
    cl::desc("Enable FP math optimizations that assume "
145
             "the sign of 0 is insignificant"),
146
    cl::init(false));
147
148
static cl::opt<bool>
149
    EnableNoTrappingFPMath("enable-no-trapping-fp-math",
150
                           cl::desc("Enable setting the FP exceptions build "
151
                                    "attribute not to use exceptions"),
152
                           cl::init(false));
153
154
static cl::opt<llvm::FPDenormal::DenormalMode> DenormalMode(
155
    "denormal-fp-math",
156
    cl::desc("Select which denormal numbers the code is permitted to require"),
157
    cl::init(FPDenormal::IEEE),
158
    cl::values(clEnumValN(FPDenormal::IEEE, "ieee",
159
                          "IEEE 754 denormal numbers"),
160
               clEnumValN(FPDenormal::PreserveSign, "preserve-sign",
161
                          "the sign of a  flushed-to-zero number is preserved "
162
                          "in the sign of 0"),
163
               clEnumValN(FPDenormal::PositiveZero, "positive-zero",
164
                          "denormals are flushed to positive zero")));
165
166
static cl::opt<bool> EnableHonorSignDependentRoundingFPMath(
167
    "enable-sign-dependent-rounding-fp-math", cl::Hidden,
168
    cl::desc("Force codegen to assume rounding mode can change dynamically"),
169
    cl::init(false));
170
171
static cl::opt<llvm::FloatABI::ABIType> FloatABIForCalls(
172
    "float-abi", cl::desc("Choose float ABI type"), cl::init(FloatABI::Default),
173
    cl::values(clEnumValN(FloatABI::Default, "default",
174
                          "Target default float ABI type"),
175
               clEnumValN(FloatABI::Soft, "soft",
176
                          "Soft float ABI (implied by -soft-float)"),
177
               clEnumValN(FloatABI::Hard, "hard",
178
                          "Hard float ABI (uses FP registers)")));
179
180
static cl::opt<llvm::FPOpFusion::FPOpFusionMode> FuseFPOps(
181
    "fp-contract", cl::desc("Enable aggressive formation of fused FP ops"),
182
    cl::init(FPOpFusion::Standard),
183
    cl::values(
184
        clEnumValN(FPOpFusion::Fast, "fast", "Fuse FP ops whenever profitable"),
185
        clEnumValN(FPOpFusion::Standard, "on", "Only fuse 'blessed' FP ops."),
186
        clEnumValN(FPOpFusion::Strict, "off",
187
                   "Only fuse FP ops when the result won't be affected.")));
188
189
static cl::opt<bool> DontPlaceZerosInBSS(
190
    "nozero-initialized-in-bss",
191
    cl::desc("Don't place zero-initialized symbols into bss section"),
192
    cl::init(false));
193
194
static cl::opt<bool> EnableGuaranteedTailCallOpt(
195
    "tailcallopt",
196
    cl::desc(
197
        "Turn fastcc calls into tail calls by (potentially) changing ABI."),
198
    cl::init(false));
199
200
static cl::opt<bool> DisableTailCalls("disable-tail-calls",
201
                                      cl::desc("Never emit tail calls"),
202
                                      cl::init(false));
203
204
static cl::opt<bool> StackSymbolOrdering("stack-symbol-ordering",
205
                                         cl::desc("Order local stack symbols."),
206
                                         cl::init(true));
207
208
static cl::opt<unsigned>
209
    OverrideStackAlignment("stack-alignment",
210
                           cl::desc("Override default stack alignment"),
211
                           cl::init(0));
212
213
static cl::opt<bool>
214
    StackRealign("stackrealign",
215
                 cl::desc("Force align the stack to the minimum alignment"),
216
                 cl::init(false));
217
218
static cl::opt<std::string> TrapFuncName(
219
    "trap-func", cl::Hidden,
220
    cl::desc("Emit a call to trap function rather than a trap instruction"),
221
    cl::init(""));
222
223
static cl::opt<bool> UseCtors("use-ctors",
224
                              cl::desc("Use .ctors instead of .init_array."),
225
                              cl::init(false));
226
227
static cl::opt<bool> RelaxELFRelocations(
228
    "relax-elf-relocations",
229
    cl::desc("Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
230
    cl::init(false));
231
232
static cl::opt<bool> DataSections("data-sections",
233
                                  cl::desc("Emit data into separate sections"),
234
                                  cl::init(false));
235
236
static cl::opt<bool>
237
    FunctionSections("function-sections",
238
                     cl::desc("Emit functions into separate sections"),
239
                     cl::init(false));
240
241
static cl::opt<bool> EmulatedTLS("emulated-tls",
242
                                 cl::desc("Use emulated TLS model"),
243
                                 cl::init(false));
244
245
static cl::opt<bool>
246
    UniqueSectionNames("unique-section-names",
247
                       cl::desc("Give unique names to every section"),
248
                       cl::init(true));
249
250
static cl::opt<llvm::EABI>
251
    EABIVersion("meabi", cl::desc("Set EABI type (default depends on triple):"),
252
                cl::init(EABI::Default),
253
                cl::values(clEnumValN(EABI::Default, "default",
254
                                      "Triple default EABI version"),
255
                           clEnumValN(EABI::EABI4, "4", "EABI version 4"),
256
                           clEnumValN(EABI::EABI5, "5", "EABI version 5"),
257
                           clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
258
259
static cl::opt<DebuggerKind> DebuggerTuningOpt(
260
    "debugger-tune", cl::desc("Tune debug info for a particular debugger"),
261
    cl::init(DebuggerKind::Default),
262
    cl::values(clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
263
               clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
264
               clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)")));
265
266
static cl::opt<bool> EnableStackSizeSection(
267
    "stack-size-section",
268
    cl::desc("Emit a section containing stack size metadata"), cl::init(false));
269
270
static cl::opt<bool>
271
    EnableAddrsig("addrsig", cl::desc("Emit an address-significance table"),
272
                  cl::init(false));
273
274
// Common utility function tightly tied to the options listed here. Initializes
275
// a TargetOptions object with CodeGen flags and returns it.
276
32.9k
static TargetOptions InitTargetOptionsFromCodeGenFlags() {
277
32.9k
  TargetOptions Options;
278
32.9k
  Options.AllowFPOpFusion = FuseFPOps;
279
32.9k
  Options.UnsafeFPMath = EnableUnsafeFPMath;
280
32.9k
  Options.NoInfsFPMath = EnableNoInfsFPMath;
281
32.9k
  Options.NoNaNsFPMath = EnableNoNaNsFPMath;
282
32.9k
  Options.NoSignedZerosFPMath = EnableNoSignedZerosFPMath;
283
32.9k
  Options.NoTrappingFPMath = EnableNoTrappingFPMath;
284
32.9k
  Options.FPDenormalMode = DenormalMode;
285
32.9k
  Options.HonorSignDependentRoundingFPMathOption =
286
32.9k
      EnableHonorSignDependentRoundingFPMath;
287
32.9k
  if (FloatABIForCalls != FloatABI::Default)
288
111
    Options.FloatABIType = FloatABIForCalls;
289
32.9k
  Options.NoZerosInBSS = DontPlaceZerosInBSS;
290
32.9k
  Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
291
32.9k
  Options.StackAlignmentOverride = OverrideStackAlignment;
292
32.9k
  Options.StackSymbolOrdering = StackSymbolOrdering;
293
32.9k
  Options.UseInitArray = !UseCtors;
294
32.9k
  Options.RelaxELFRelocations = RelaxELFRelocations;
295
32.9k
  Options.DataSections = DataSections;
296
32.9k
  Options.FunctionSections = FunctionSections;
297
32.9k
  Options.UniqueSectionNames = UniqueSectionNames;
298
32.9k
  Options.EmulatedTLS = EmulatedTLS;
299
32.9k
  Options.ExplicitEmulatedTLS = EmulatedTLS.getNumOccurrences() > 0;
300
32.9k
  Options.ExceptionModel = ExceptionModel;
301
32.9k
  Options.EmitStackSizeSection = EnableStackSizeSection;
302
32.9k
  Options.EmitAddrsig = EnableAddrsig;
303
32.9k
304
32.9k
  Options.MCOptions = InitMCTargetOptionsFromFlags();
305
32.9k
306
32.9k
  Options.ThreadModel = TMModel;
307
32.9k
  Options.EABIVersion = EABIVersion;
308
32.9k
  Options.DebuggerTuning = DebuggerTuningOpt;
309
32.9k
310
32.9k
  return Options;
311
32.9k
}
opt.cpp:InitTargetOptionsFromCodeGenFlags()
Line
Count
Source
276
10.4k
static TargetOptions InitTargetOptionsFromCodeGenFlags() {
277
10.4k
  TargetOptions Options;
278
10.4k
  Options.AllowFPOpFusion = FuseFPOps;
279
10.4k
  Options.UnsafeFPMath = EnableUnsafeFPMath;
280
10.4k
  Options.NoInfsFPMath = EnableNoInfsFPMath;
281
10.4k
  Options.NoNaNsFPMath = EnableNoNaNsFPMath;
282
10.4k
  Options.NoSignedZerosFPMath = EnableNoSignedZerosFPMath;
283
10.4k
  Options.NoTrappingFPMath = EnableNoTrappingFPMath;
284
10.4k
  Options.FPDenormalMode = DenormalMode;
285
10.4k
  Options.HonorSignDependentRoundingFPMathOption =
286
10.4k
      EnableHonorSignDependentRoundingFPMath;
287
10.4k
  if (FloatABIForCalls != FloatABI::Default)
288
0
    Options.FloatABIType = FloatABIForCalls;
289
10.4k
  Options.NoZerosInBSS = DontPlaceZerosInBSS;
290
10.4k
  Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
291
10.4k
  Options.StackAlignmentOverride = OverrideStackAlignment;
292
10.4k
  Options.StackSymbolOrdering = StackSymbolOrdering;
293
10.4k
  Options.UseInitArray = !UseCtors;
294
10.4k
  Options.RelaxELFRelocations = RelaxELFRelocations;
295
10.4k
  Options.DataSections = DataSections;
296
10.4k
  Options.FunctionSections = FunctionSections;
297
10.4k
  Options.UniqueSectionNames = UniqueSectionNames;
298
10.4k
  Options.EmulatedTLS = EmulatedTLS;
299
10.4k
  Options.ExplicitEmulatedTLS = EmulatedTLS.getNumOccurrences() > 0;
300
10.4k
  Options.ExceptionModel = ExceptionModel;
301
10.4k
  Options.EmitStackSizeSection = EnableStackSizeSection;
302
10.4k
  Options.EmitAddrsig = EnableAddrsig;
303
10.4k
304
10.4k
  Options.MCOptions = InitMCTargetOptionsFromFlags();
305
10.4k
306
10.4k
  Options.ThreadModel = TMModel;
307
10.4k
  Options.EABIVersion = EABIVersion;
308
10.4k
  Options.DebuggerTuning = DebuggerTuningOpt;
309
10.4k
310
10.4k
  return Options;
311
10.4k
}
llc.cpp:InitTargetOptionsFromCodeGenFlags()
Line
Count
Source
276
22.5k
static TargetOptions InitTargetOptionsFromCodeGenFlags() {
277
22.5k
  TargetOptions Options;
278
22.5k
  Options.AllowFPOpFusion = FuseFPOps;
279
22.5k
  Options.UnsafeFPMath = EnableUnsafeFPMath;
280
22.5k
  Options.NoInfsFPMath = EnableNoInfsFPMath;
281
22.5k
  Options.NoNaNsFPMath = EnableNoNaNsFPMath;
282
22.5k
  Options.NoSignedZerosFPMath = EnableNoSignedZerosFPMath;
283
22.5k
  Options.NoTrappingFPMath = EnableNoTrappingFPMath;
284
22.5k
  Options.FPDenormalMode = DenormalMode;
285
22.5k
  Options.HonorSignDependentRoundingFPMathOption =
286
22.5k
      EnableHonorSignDependentRoundingFPMath;
287
22.5k
  if (FloatABIForCalls != FloatABI::Default)
288
111
    Options.FloatABIType = FloatABIForCalls;
289
22.5k
  Options.NoZerosInBSS = DontPlaceZerosInBSS;
290
22.5k
  Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
291
22.5k
  Options.StackAlignmentOverride = OverrideStackAlignment;
292
22.5k
  Options.StackSymbolOrdering = StackSymbolOrdering;
293
22.5k
  Options.UseInitArray = !UseCtors;
294
22.5k
  Options.RelaxELFRelocations = RelaxELFRelocations;
295
22.5k
  Options.DataSections = DataSections;
296
22.5k
  Options.FunctionSections = FunctionSections;
297
22.5k
  Options.UniqueSectionNames = UniqueSectionNames;
298
22.5k
  Options.EmulatedTLS = EmulatedTLS;
299
22.5k
  Options.ExplicitEmulatedTLS = EmulatedTLS.getNumOccurrences() > 0;
300
22.5k
  Options.ExceptionModel = ExceptionModel;
301
22.5k
  Options.EmitStackSizeSection = EnableStackSizeSection;
302
22.5k
  Options.EmitAddrsig = EnableAddrsig;
303
22.5k
304
22.5k
  Options.MCOptions = InitMCTargetOptionsFromFlags();
305
22.5k
306
22.5k
  Options.ThreadModel = TMModel;
307
22.5k
  Options.EABIVersion = EABIVersion;
308
22.5k
  Options.DebuggerTuning = DebuggerTuningOpt;
309
22.5k
310
22.5k
  return Options;
311
22.5k
}
312
313
26.8k
LLVM_ATTRIBUTE_UNUSED static std::string getCPUStr() {
314
26.8k
  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
315
26.8k
  // this will set the CPU to an empty string which tells the target to
316
26.8k
  // pick a basic default.
317
26.8k
  if (MCPU == "native")
318
0
    return sys::getHostCPUName();
319
26.8k
320
26.8k
  return MCPU;
321
26.8k
}
opt.cpp:getCPUStr()
Line
Count
Source
313
4.33k
LLVM_ATTRIBUTE_UNUSED static std::string getCPUStr() {
314
4.33k
  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
315
4.33k
  // this will set the CPU to an empty string which tells the target to
316
4.33k
  // pick a basic default.
317
4.33k
  if (MCPU == "native")
318
0
    return sys::getHostCPUName();
319
4.33k
320
4.33k
  return MCPU;
321
4.33k
}
llc.cpp:getCPUStr()
Line
Count
Source
313
22.5k
LLVM_ATTRIBUTE_UNUSED static std::string getCPUStr() {
314
22.5k
  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
315
22.5k
  // this will set the CPU to an empty string which tells the target to
316
22.5k
  // pick a basic default.
317
22.5k
  if (MCPU == "native")
318
0
    return sys::getHostCPUName();
319
22.5k
320
22.5k
  return MCPU;
321
22.5k
}
322
323
26.8k
LLVM_ATTRIBUTE_UNUSED static std::string getFeaturesStr() {
324
26.8k
  SubtargetFeatures Features;
325
26.8k
326
26.8k
  // If user asked for the 'native' CPU, we need to autodetect features.
327
26.8k
  // This is necessary for x86 where the CPU might not support all the
328
26.8k
  // features the autodetected CPU name lists in the target. For example,
329
26.8k
  // not all Sandybridge processors support AVX.
330
26.8k
  if (MCPU == "native") {
331
0
    StringMap<bool> HostFeatures;
332
0
    if (sys::getHostCPUFeatures(HostFeatures))
333
0
      for (auto &F : HostFeatures)
334
0
        Features.AddFeature(F.first(), F.second);
335
0
  }
336
26.8k
337
36.5k
  for (unsigned i = 0; i != MAttrs.size(); 
++i9.67k
)
338
9.67k
    Features.AddFeature(MAttrs[i]);
339
26.8k
340
26.8k
  return Features.getString();
341
26.8k
}
opt.cpp:getFeaturesStr()
Line
Count
Source
323
4.33k
LLVM_ATTRIBUTE_UNUSED static std::string getFeaturesStr() {
324
4.33k
  SubtargetFeatures Features;
325
4.33k
326
4.33k
  // If user asked for the 'native' CPU, we need to autodetect features.
327
4.33k
  // This is necessary for x86 where the CPU might not support all the
328
4.33k
  // features the autodetected CPU name lists in the target. For example,
329
4.33k
  // not all Sandybridge processors support AVX.
330
4.33k
  if (MCPU == "native") {
331
0
    StringMap<bool> HostFeatures;
332
0
    if (sys::getHostCPUFeatures(HostFeatures))
333
0
      for (auto &F : HostFeatures)
334
0
        Features.AddFeature(F.first(), F.second);
335
0
  }
336
4.33k
337
5.18k
  for (unsigned i = 0; i != MAttrs.size(); 
++i846
)
338
846
    Features.AddFeature(MAttrs[i]);
339
4.33k
340
4.33k
  return Features.getString();
341
4.33k
}
llc.cpp:getFeaturesStr()
Line
Count
Source
323
22.5k
LLVM_ATTRIBUTE_UNUSED static std::string getFeaturesStr() {
324
22.5k
  SubtargetFeatures Features;
325
22.5k
326
22.5k
  // If user asked for the 'native' CPU, we need to autodetect features.
327
22.5k
  // This is necessary for x86 where the CPU might not support all the
328
22.5k
  // features the autodetected CPU name lists in the target. For example,
329
22.5k
  // not all Sandybridge processors support AVX.
330
22.5k
  if (MCPU == "native") {
331
0
    StringMap<bool> HostFeatures;
332
0
    if (sys::getHostCPUFeatures(HostFeatures))
333
0
      for (auto &F : HostFeatures)
334
0
        Features.AddFeature(F.first(), F.second);
335
0
  }
336
22.5k
337
31.3k
  for (unsigned i = 0; i != MAttrs.size(); 
++i8.82k
)
338
8.82k
    Features.AddFeature(MAttrs[i]);
339
22.5k
340
22.5k
  return Features.getString();
341
22.5k
}
342
343
0
LLVM_ATTRIBUTE_UNUSED static std::vector<std::string> getFeatureList() {
344
0
  SubtargetFeatures Features;
345
0
346
0
  // If user asked for the 'native' CPU, we need to autodetect features.
347
0
  // This is necessary for x86 where the CPU might not support all the
348
0
  // features the autodetected CPU name lists in the target. For example,
349
0
  // not all Sandybridge processors support AVX.
350
0
  if (MCPU == "native") {
351
0
    StringMap<bool> HostFeatures;
352
0
    if (sys::getHostCPUFeatures(HostFeatures))
353
0
      for (auto &F : HostFeatures)
354
0
        Features.AddFeature(F.first(), F.second);
355
0
  }
356
0
357
0
  for (unsigned i = 0; i != MAttrs.size(); ++i)
358
0
    Features.AddFeature(MAttrs[i]);
359
0
360
0
  return Features.getFeatures();
361
0
}
Unexecuted instantiation: opt.cpp:getFeatureList()
Unexecuted instantiation: llc.cpp:getFeatureList()
362
363
/// Set function attributes of functions in Module M based on CPU,
364
/// Features, and command line flags.
365
LLVM_ATTRIBUTE_UNUSED static void
366
32.9k
setFunctionAttributes(StringRef CPU, StringRef Features, Module &M) {
367
333k
  for (auto &F : M) {
368
333k
    auto &Ctx = F.getContext();
369
333k
    AttributeList Attrs = F.getAttributes();
370
333k
    AttrBuilder NewAttrs;
371
333k
372
333k
    if (!CPU.empty())
373
76.5k
      NewAttrs.addAttribute("target-cpu", CPU);
374
333k
    if (!Features.empty())
375
149k
      NewAttrs.addAttribute("target-features", Features);
376
333k
    if (FramePointerUsage.getNumOccurrences() > 0) {
377
2.26k
      if (FramePointerUsage == llvm::FramePointer::All)
378
2.24k
        NewAttrs.addAttribute("frame-pointer", "all");
379
21
      else if (FramePointerUsage == llvm::FramePointer::NonLeaf)
380
0
        NewAttrs.addAttribute("frame-pointer", "non-leaf");
381
21
      else if (FramePointerUsage == llvm::FramePointer::None)
382
21
        NewAttrs.addAttribute("frame-pointer", "none");
383
2.26k
    }
384
333k
    if (DisableTailCalls.getNumOccurrences() > 0)
385
36
      NewAttrs.addAttribute("disable-tail-calls",
386
36
                            toStringRef(DisableTailCalls));
387
333k
    if (StackRealign)
388
84
      NewAttrs.addAttribute("stackrealign");
389
333k
390
333k
    if (TrapFuncName.getNumOccurrences() > 0)
391
12
      for (auto &B : F)
392
7
        for (auto &I : B)
393
14
          if (auto *Call = dyn_cast<CallInst>(&I))
394
7
            if (const auto *F = Call->getCalledFunction())
395
7
              if (F->getIntrinsicID() == Intrinsic::debugtrap ||
396
7
                  
F->getIntrinsicID() == Intrinsic::trap5
)
397
7
                Call->addAttribute(
398
7
                    llvm::AttributeList::FunctionIndex,
399
7
                    Attribute::get(Ctx, "trap-func-name", TrapFuncName));
400
333k
401
333k
    // Let NewAttrs override Attrs.
402
333k
    F.setAttributes(
403
333k
        Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
404
333k
  }
405
32.9k
}
opt.cpp:setFunctionAttributes(llvm::StringRef, llvm::StringRef, llvm::Module&)
Line
Count
Source
366
10.4k
setFunctionAttributes(StringRef CPU, StringRef Features, Module &M) {
367
81.9k
  for (auto &F : M) {
368
81.9k
    auto &Ctx = F.getContext();
369
81.9k
    AttributeList Attrs = F.getAttributes();
370
81.9k
    AttrBuilder NewAttrs;
371
81.9k
372
81.9k
    if (!CPU.empty())
373
7.54k
      NewAttrs.addAttribute("target-cpu", CPU);
374
81.9k
    if (!Features.empty())
375
13.9k
      NewAttrs.addAttribute("target-features", Features);
376
81.9k
    if (FramePointerUsage.getNumOccurrences() > 0) {
377
0
      if (FramePointerUsage == llvm::FramePointer::All)
378
0
        NewAttrs.addAttribute("frame-pointer", "all");
379
0
      else if (FramePointerUsage == llvm::FramePointer::NonLeaf)
380
0
        NewAttrs.addAttribute("frame-pointer", "non-leaf");
381
0
      else if (FramePointerUsage == llvm::FramePointer::None)
382
0
        NewAttrs.addAttribute("frame-pointer", "none");
383
0
    }
384
81.9k
    if (DisableTailCalls.getNumOccurrences() > 0)
385
0
      NewAttrs.addAttribute("disable-tail-calls",
386
0
                            toStringRef(DisableTailCalls));
387
81.9k
    if (StackRealign)
388
0
      NewAttrs.addAttribute("stackrealign");
389
81.9k
390
81.9k
    if (TrapFuncName.getNumOccurrences() > 0)
391
0
      for (auto &B : F)
392
0
        for (auto &I : B)
393
0
          if (auto *Call = dyn_cast<CallInst>(&I))
394
0
            if (const auto *F = Call->getCalledFunction())
395
0
              if (F->getIntrinsicID() == Intrinsic::debugtrap ||
396
0
                  F->getIntrinsicID() == Intrinsic::trap)
397
0
                Call->addAttribute(
398
0
                    llvm::AttributeList::FunctionIndex,
399
0
                    Attribute::get(Ctx, "trap-func-name", TrapFuncName));
400
81.9k
401
81.9k
    // Let NewAttrs override Attrs.
402
81.9k
    F.setAttributes(
403
81.9k
        Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
404
81.9k
  }
405
10.4k
}
llc.cpp:setFunctionAttributes(llvm::StringRef, llvm::StringRef, llvm::Module&)
Line
Count
Source
366
22.5k
setFunctionAttributes(StringRef CPU, StringRef Features, Module &M) {
367
251k
  for (auto &F : M) {
368
251k
    auto &Ctx = F.getContext();
369
251k
    AttributeList Attrs = F.getAttributes();
370
251k
    AttrBuilder NewAttrs;
371
251k
372
251k
    if (!CPU.empty())
373
68.9k
      NewAttrs.addAttribute("target-cpu", CPU);
374
251k
    if (!Features.empty())
375
135k
      NewAttrs.addAttribute("target-features", Features);
376
251k
    if (FramePointerUsage.getNumOccurrences() > 0) {
377
2.26k
      if (FramePointerUsage == llvm::FramePointer::All)
378
2.24k
        NewAttrs.addAttribute("frame-pointer", "all");
379
21
      else if (FramePointerUsage == llvm::FramePointer::NonLeaf)
380
0
        NewAttrs.addAttribute("frame-pointer", "non-leaf");
381
21
      else if (FramePointerUsage == llvm::FramePointer::None)
382
21
        NewAttrs.addAttribute("frame-pointer", "none");
383
2.26k
    }
384
251k
    if (DisableTailCalls.getNumOccurrences() > 0)
385
36
      NewAttrs.addAttribute("disable-tail-calls",
386
36
                            toStringRef(DisableTailCalls));
387
251k
    if (StackRealign)
388
84
      NewAttrs.addAttribute("stackrealign");
389
251k
390
251k
    if (TrapFuncName.getNumOccurrences() > 0)
391
12
      for (auto &B : F)
392
7
        for (auto &I : B)
393
14
          if (auto *Call = dyn_cast<CallInst>(&I))
394
7
            if (const auto *F = Call->getCalledFunction())
395
7
              if (F->getIntrinsicID() == Intrinsic::debugtrap ||
396
7
                  
F->getIntrinsicID() == Intrinsic::trap5
)
397
7
                Call->addAttribute(
398
7
                    llvm::AttributeList::FunctionIndex,
399
7
                    Attribute::get(Ctx, "trap-func-name", TrapFuncName));
400
251k
401
251k
    // Let NewAttrs override Attrs.
402
251k
    F.setAttributes(
403
251k
        Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
404
251k
  }
405
22.5k
}