LLVM  7.0.0
CommandFlags.inc
Go to the documentation of this file.
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 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/IR/Instructions.h"
18 #include "llvm/IR/Intrinsics.h"
19 #include "llvm/IR/Module.h"
22 #include "llvm/Support/CodeGen.h"
24 #include "llvm/Support/Host.h"
27 #include <string>
28 using namespace llvm;
29 
31  MArch("march",
32  cl::desc("Architecture to generate code for (see --version)"));
33 
35  MCPU("mcpu",
36  cl::desc("Target a specific cpu type (-mcpu=help for details)"),
37  cl::value_desc("cpu-name"), cl::init(""));
38 
40  MAttrs("mattr", cl::CommaSeparated,
41  cl::desc("Target specific attributes (-mattr=help for details)"),
42  cl::value_desc("a1,+a2,-a3,..."));
43 
44 static cl::opt<Reloc::Model> RelocModel(
45  "relocation-model", cl::desc("Choose relocation model"),
46  cl::values(
47  clEnumValN(Reloc::Static, "static", "Non-relocatable code"),
48  clEnumValN(Reloc::PIC_, "pic",
49  "Fully relocatable, position independent code"),
50  clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
51  "Relocatable external references, non-relocatable code"),
52  clEnumValN(Reloc::ROPI, "ropi",
53  "Code and read-only data relocatable, accessed PC-relative"),
54  clEnumValN(
55  Reloc::RWPI, "rwpi",
56  "Read-write data relocatable, accessed relative to static base"),
57  clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
58  "Combination of ropi and rwpi")));
59 
61  if (RelocModel.getNumOccurrences()) {
62  Reloc::Model R = RelocModel;
63  return R;
64  }
65  return None;
66 }
67 
68 static cl::opt<ThreadModel::Model> TMModel(
69  "thread-model", cl::desc("Choose threading model"),
71  cl::values(clEnumValN(ThreadModel::POSIX, "posix", "POSIX thread model"),
73  "Single thread model")));
74 
75 static cl::opt<llvm::CodeModel::Model> CMModel(
76  "code-model", cl::desc("Choose code model"),
77  cl::values(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 
83  if (CMModel.getNumOccurrences()) {
84  CodeModel::Model M = CMModel;
85  return M;
86  }
87  return None;
88 }
89 
90 static cl::opt<llvm::ExceptionHandling> ExceptionModel(
91  "exception-model", cl::desc("exception model"),
93  cl::values(
95  "default exception handling model"),
97  "DWARF-like CFI based exception handling"),
98  clEnumValN(ExceptionHandling::SjLj, "sjlj", "SjLj exception handling"),
99  clEnumValN(ExceptionHandling::ARM, "arm", "ARM EHABI exceptions"),
101  "Windows exception model"),
103  "WebAssembly exception handling")));
104 
107  cl::desc(
108  "Choose a file type (not all types are supported by all targets):"),
110  "Emit an assembly ('.s') file"),
112  "Emit a native object ('.o') file"),
114  "Emit nothing, for performance testing")));
115 
116 static cl::opt<bool>
117  DisableFPElim("disable-fp-elim",
118  cl::desc("Disable frame pointer elimination optimization"),
119  cl::init(false));
120 
121 static cl::opt<bool> EnableUnsafeFPMath(
122  "enable-unsafe-fp-math",
123  cl::desc("Enable optimizations that may decrease FP precision"),
124  cl::init(false));
125 
126 static cl::opt<bool> EnableNoInfsFPMath(
127  "enable-no-infs-fp-math",
128  cl::desc("Enable FP math optimizations that assume no +-Infs"),
129  cl::init(false));
130 
131 static cl::opt<bool> EnableNoNaNsFPMath(
132  "enable-no-nans-fp-math",
133  cl::desc("Enable FP math optimizations that assume no NaNs"),
134  cl::init(false));
135 
136 static cl::opt<bool> EnableNoSignedZerosFPMath(
137  "enable-no-signed-zeros-fp-math",
138  cl::desc("Enable FP math optimizations that assume "
139  "the sign of 0 is insignificant"),
140  cl::init(false));
141 
142 static cl::opt<bool>
143  EnableNoTrappingFPMath("enable-no-trapping-fp-math",
144  cl::desc("Enable setting the FP exceptions build "
145  "attribute not to use exceptions"),
146  cl::init(false));
147 
149  "denormal-fp-math",
150  cl::desc("Select which denormal numbers the code is permitted to require"),
153  "IEEE 754 denormal numbers"),
154  clEnumValN(FPDenormal::PreserveSign, "preserve-sign",
155  "the sign of a flushed-to-zero number is preserved "
156  "in the sign of 0"),
157  clEnumValN(FPDenormal::PositiveZero, "positive-zero",
158  "denormals are flushed to positive zero")));
159 
160 static cl::opt<bool> EnableHonorSignDependentRoundingFPMath(
161  "enable-sign-dependent-rounding-fp-math", cl::Hidden,
162  cl::desc("Force codegen to assume rounding mode can change dynamically"),
163  cl::init(false));
164 
165 static cl::opt<llvm::FloatABI::ABIType> FloatABIForCalls(
166  "float-abi", cl::desc("Choose float ABI type"), cl::init(FloatABI::Default),
168  "Target default float ABI type"),
169  clEnumValN(FloatABI::Soft, "soft",
170  "Soft float ABI (implied by -soft-float)"),
171  clEnumValN(FloatABI::Hard, "hard",
172  "Hard float ABI (uses FP registers)")));
173 
175  "fp-contract", cl::desc("Enable aggressive formation of fused FP ops"),
177  cl::values(
178  clEnumValN(FPOpFusion::Fast, "fast", "Fuse FP ops whenever profitable"),
179  clEnumValN(FPOpFusion::Standard, "on", "Only fuse 'blessed' FP ops."),
181  "Only fuse FP ops when the result won't be affected.")));
182 
183 static cl::opt<bool> DontPlaceZerosInBSS(
184  "nozero-initialized-in-bss",
185  cl::desc("Don't place zero-initialized symbols into bss section"),
186  cl::init(false));
187 
188 static cl::opt<bool> EnableGuaranteedTailCallOpt(
189  "tailcallopt",
190  cl::desc(
191  "Turn fastcc calls into tail calls by (potentially) changing ABI."),
192  cl::init(false));
193 
194 static cl::opt<bool> DisableTailCalls("disable-tail-calls",
195  cl::desc("Never emit tail calls"),
196  cl::init(false));
197 
198 static cl::opt<bool> StackSymbolOrdering("stack-symbol-ordering",
199  cl::desc("Order local stack symbols."),
200  cl::init(true));
201 
202 static cl::opt<unsigned>
203  OverrideStackAlignment("stack-alignment",
204  cl::desc("Override default stack alignment"),
205  cl::init(0));
206 
207 static cl::opt<bool>
208  StackRealign("stackrealign",
209  cl::desc("Force align the stack to the minimum alignment"),
210  cl::init(false));
211 
212 static cl::opt<std::string> TrapFuncName(
213  "trap-func", cl::Hidden,
214  cl::desc("Emit a call to trap function rather than a trap instruction"),
215  cl::init(""));
216 
217 static cl::opt<bool> UseCtors("use-ctors",
218  cl::desc("Use .ctors instead of .init_array."),
219  cl::init(false));
220 
221 static cl::opt<bool> RelaxELFRelocations(
222  "relax-elf-relocations",
223  cl::desc("Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
224  cl::init(false));
225 
226 static cl::opt<bool> DataSections("data-sections",
227  cl::desc("Emit data into separate sections"),
228  cl::init(false));
229 
230 static cl::opt<bool>
231  FunctionSections("function-sections",
232  cl::desc("Emit functions into separate sections"),
233  cl::init(false));
234 
235 static cl::opt<bool> EmulatedTLS("emulated-tls",
236  cl::desc("Use emulated TLS model"),
237  cl::init(false));
238 
239 static cl::opt<bool>
240  UniqueSectionNames("unique-section-names",
241  cl::desc("Give unique names to every section"),
242  cl::init(true));
243 
244 static cl::opt<llvm::EABI>
245  EABIVersion("meabi", cl::desc("Set EABI type (default depends on triple):"),
248  "Triple default EABI version"),
249  clEnumValN(EABI::EABI4, "4", "EABI version 4"),
250  clEnumValN(EABI::EABI5, "5", "EABI version 5"),
251  clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
252 
253 static cl::opt<DebuggerKind> DebuggerTuningOpt(
254  "debugger-tune", cl::desc("Tune debug info for a particular debugger"),
256  cl::values(clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
257  clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
258  clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)")));
259 
260 static cl::opt<bool> EnableStackSizeSection(
261  "stack-size-section",
262  cl::desc("Emit a section containing stack size metadata"), cl::init(false));
263 
264 static cl::opt<bool>
265  EnableAddrsig("addrsig", cl::desc("Emit an address-significance table"),
266  cl::init(false));
267 
268 // Common utility function tightly tied to the options listed here. Initializes
269 // a TargetOptions object with CodeGen flags and returns it.
270 static TargetOptions InitTargetOptionsFromCodeGenFlags() {
271  TargetOptions Options;
272  Options.AllowFPOpFusion = FuseFPOps;
273  Options.UnsafeFPMath = EnableUnsafeFPMath;
274  Options.NoInfsFPMath = EnableNoInfsFPMath;
275  Options.NoNaNsFPMath = EnableNoNaNsFPMath;
276  Options.NoSignedZerosFPMath = EnableNoSignedZerosFPMath;
277  Options.NoTrappingFPMath = EnableNoTrappingFPMath;
278  Options.FPDenormalMode = DenormalMode;
280  EnableHonorSignDependentRoundingFPMath;
281  if (FloatABIForCalls != FloatABI::Default)
282  Options.FloatABIType = FloatABIForCalls;
283  Options.NoZerosInBSS = DontPlaceZerosInBSS;
284  Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
285  Options.StackAlignmentOverride = OverrideStackAlignment;
286  Options.StackSymbolOrdering = StackSymbolOrdering;
287  Options.UseInitArray = !UseCtors;
288  Options.RelaxELFRelocations = RelaxELFRelocations;
289  Options.DataSections = DataSections;
290  Options.FunctionSections = FunctionSections;
291  Options.UniqueSectionNames = UniqueSectionNames;
292  Options.EmulatedTLS = EmulatedTLS;
293  Options.ExplicitEmulatedTLS = EmulatedTLS.getNumOccurrences() > 0;
294  Options.ExceptionModel = ExceptionModel;
295  Options.EmitStackSizeSection = EnableStackSizeSection;
296  Options.EmitAddrsig = EnableAddrsig;
297 
298  Options.MCOptions = InitMCTargetOptionsFromFlags();
299 
300  Options.ThreadModel = TMModel;
301  Options.EABIVersion = EABIVersion;
302  Options.DebuggerTuning = DebuggerTuningOpt;
303 
304  return Options;
305 }
306 
307 LLVM_ATTRIBUTE_UNUSED static std::string getCPUStr() {
308  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
309  // this will set the CPU to an empty string which tells the target to
310  // pick a basic default.
311  if (MCPU == "native")
312  return sys::getHostCPUName();
313 
314  return MCPU;
315 }
316 
317 LLVM_ATTRIBUTE_UNUSED static std::string getFeaturesStr() {
319 
320  // If user asked for the 'native' CPU, we need to autodetect features.
321  // This is necessary for x86 where the CPU might not support all the
322  // features the autodetected CPU name lists in the target. For example,
323  // not all Sandybridge processors support AVX.
324  if (MCPU == "native") {
325  StringMap<bool> HostFeatures;
326  if (sys::getHostCPUFeatures(HostFeatures))
327  for (auto &F : HostFeatures)
328  Features.AddFeature(F.first(), F.second);
329  }
330 
331  for (unsigned i = 0; i != MAttrs.size(); ++i)
332  Features.AddFeature(MAttrs[i]);
333 
334  return Features.getString();
335 }
336 
337 LLVM_ATTRIBUTE_UNUSED static std::vector<std::string> getFeatureList() {
339 
340  // If user asked for the 'native' CPU, we need to autodetect features.
341  // This is necessary for x86 where the CPU might not support all the
342  // features the autodetected CPU name lists in the target. For example,
343  // not all Sandybridge processors support AVX.
344  if (MCPU == "native") {
345  StringMap<bool> HostFeatures;
346  if (sys::getHostCPUFeatures(HostFeatures))
347  for (auto &F : HostFeatures)
348  Features.AddFeature(F.first(), F.second);
349  }
350 
351  for (unsigned i = 0; i != MAttrs.size(); ++i)
352  Features.AddFeature(MAttrs[i]);
353 
354  return Features.getFeatures();
355 }
356 
357 /// Set function attributes of functions in Module M based on CPU,
358 /// Features, and command line flags.
359 LLVM_ATTRIBUTE_UNUSED static void
360 setFunctionAttributes(StringRef CPU, StringRef Features, Module &M) {
361  for (auto &F : M) {
362  auto &Ctx = F.getContext();
363  AttributeList Attrs = F.getAttributes();
364  AttrBuilder NewAttrs;
365 
366  if (!CPU.empty())
367  NewAttrs.addAttribute("target-cpu", CPU);
368  if (!Features.empty())
369  NewAttrs.addAttribute("target-features", Features);
370  if (DisableFPElim.getNumOccurrences() > 0)
371  NewAttrs.addAttribute("no-frame-pointer-elim",
372  DisableFPElim ? "true" : "false");
373  if (DisableTailCalls.getNumOccurrences() > 0)
374  NewAttrs.addAttribute("disable-tail-calls",
375  toStringRef(DisableTailCalls));
376  if (StackRealign)
377  NewAttrs.addAttribute("stackrealign");
378 
379  if (TrapFuncName.getNumOccurrences() > 0)
380  for (auto &B : F)
381  for (auto &I : B)
382  if (auto *Call = dyn_cast<CallInst>(&I))
383  if (const auto *F = Call->getCalledFunction())
384  if (F->getIntrinsicID() == Intrinsic::debugtrap ||
385  F->getIntrinsicID() == Intrinsic::trap)
386  Call->addAttribute(
388  Attribute::get(Ctx, "trap-func-name", TrapFuncName));
389 
390  // Let NewAttrs override Attrs.
391  F.setAttributes(
392  Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
393  }
394 }
unsigned StackSymbolOrdering
StackSymbolOrdering - When true, this will allow CodeGen to order the local stack symbols (for code s...
const NoneType None
Definition: None.h:24
unsigned NoTrappingFPMath
NoTrappingFPMath - This flag is enabled when the -enable-no-trapping-fp-math is specified on the comm...
MCTargetOptions MCOptions
Machine level options.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
EABI EABIVersion
EABIVersion - This flag specifies the EABI version.
unsigned DataSections
Emit data into separate sections.
DWARF-like instruction based exceptions.
std::string getString() const
Returns features as a string.
F(f)
setjmp/longjmp based exceptions
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
ThreadModel::Model ThreadModel
ThreadModel - This flag specifies the type of threading model to assume for things like atomics...
ExceptionHandling ExceptionModel
What exception model to use.
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
unsigned NoNaNsFPMath
NoNaNsFPMath - This flag is enabled when the -enable-no-nans-fp-math flag is specified on the command...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
unsigned FunctionSections
Emit functions into separate sections.
unsigned UniqueSectionNames
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
static Reloc::Model getRelocModel(Optional< Reloc::Model > RM)
Windows Exception Handling.
DebuggerKind DebuggerTuning
Which debugger to tune for.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:410
const std::vector< std::string > & getFeatures() const
Returns the vector of individual subtarget features.
unsigned UnsafeFPMath
UnsafeFPMath - This flag is enabled when the -enable-unsafe-fp-math flag is specified on the command ...
FPOpFusion::FPOpFusionMode AllowFPOpFusion
AllowFPOpFusion - This flag is set by the -fuse-fp-ops=xxx option.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned ExplicitEmulatedTLS
Whether -emulated-tls or -no-emulated-tls is set.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:630
unsigned EmitStackSizeSection
Emit section containing metadata on function stack sizes.
unsigned GuaranteedTailCallOpt
GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline...
unsigned NoInfsFPMath
NoInfsFPMath - This flag is enabled when the -enable-no-infs-fp-math flag is specified on the command...
FPDenormal::DenormalMode FPDenormalMode
FPDenormalMode - This flags specificies which denormal numbers the code is permitted to require...
unsigned NoZerosInBSS
NoZerosInBSS - By default some codegens place zero-initialized data to .bss section.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
Definition: StringExtras.h:53
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
Module.h This file contains the declarations for the Module class.
unsigned EmitAddrsig
Emit address-significance table.
unsigned StackAlignmentOverride
StackAlignmentOverride - Override default stack alignment for target.
Manages the enabling and disabling of subtarget specific features.
unsigned EmulatedTLS
EmulatedTLS - This flag enables emulated TLS model, using emutls function in the runtime library...
unsigned RelaxELFRelocations
#define LLVM_ATTRIBUTE_UNUSED
Definition: Compiler.h:147
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:605
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
Definition: Host.cpp:1080
#define I(x, y, z)
Definition: MD5.cpp:58
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:81
AttributeList addAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &B) const
Add attributes to the attribute set at the given index.
unsigned HonorSignDependentRoundingFPMathOption
HonorSignDependentRoundingFPMath - This returns true when the -enable-sign-dependent-rounding-fp-math...
const FeatureBitset Features
unsigned NoSignedZerosFPMath
NoSignedZerosFPMath - This flag is enabled when the -enable-no-signed-zeros-fp-math is specified on t...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool getHostCPUFeatures(StringMap< bool > &Features)
getHostCPUFeatures - Get the LLVM names for the host CPU features.
Definition: Host.cpp:1362
No exception support.
FloatABI::ABIType FloatABIType
FloatABIType - This setting is set by -float-abi=xxx option is specfied on the command line...