Coverage Report

Created: 2017-10-03 07:32

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