LLVM  12.0.0git
CommandFlags.cpp
Go to the documentation of this file.
1 //===-- CommandFlags.cpp - 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 
16 #include "llvm/IR/Module.h"
19 #include "llvm/Support/Host.h"
20 
21 using namespace llvm;
22 
23 #define CGOPT(TY, NAME) \
24  static cl::opt<TY> *NAME##View; \
25  TY codegen::get##NAME() { \
26  assert(NAME##View && "RegisterCodeGenFlags not created."); \
27  return *NAME##View; \
28  }
29 
30 #define CGLIST(TY, NAME) \
31  static cl::list<TY> *NAME##View; \
32  std::vector<TY> codegen::get##NAME() { \
33  assert(NAME##View && "RegisterCodeGenFlags not created."); \
34  return *NAME##View; \
35  }
36 
37 #define CGOPT_EXP(TY, NAME) \
38  CGOPT(TY, NAME) \
39  Optional<TY> codegen::getExplicit##NAME() { \
40  if (NAME##View->getNumOccurrences()) { \
41  TY res = *NAME##View; \
42  return res; \
43  } \
44  return None; \
45  }
46 
47 CGOPT(std::string, MArch)
48 CGOPT(std::string, MCPU)
49 CGLIST(std::string, MAttrs)
50 CGOPT_EXP(Reloc::Model, RelocModel)
51 CGOPT(ThreadModel::Model, ThreadModel)
52 CGOPT_EXP(CodeModel::Model, CodeModel)
53 CGOPT(ExceptionHandling, ExceptionModel)
55 CGOPT(FramePointer::FP, FramePointerUsage)
56 CGOPT(bool, EnableUnsafeFPMath)
57 CGOPT(bool, EnableNoInfsFPMath)
58 CGOPT(bool, EnableNoNaNsFPMath)
59 CGOPT(bool, EnableNoSignedZerosFPMath)
60 CGOPT(bool, EnableNoTrappingFPMath)
61 CGOPT(bool, EnableAIXExtendedAltivecABI)
63 CGOPT(DenormalMode::DenormalModeKind, DenormalFP32Math)
64 CGOPT(bool, EnableHonorSignDependentRoundingFPMath)
65 CGOPT(FloatABI::ABIType, FloatABIForCalls)
67 CGOPT(bool, DontPlaceZerosInBSS)
68 CGOPT(bool, EnableGuaranteedTailCallOpt)
69 CGOPT(bool, DisableTailCalls)
70 CGOPT(bool, StackSymbolOrdering)
71 CGOPT(unsigned, OverrideStackAlignment)
72 CGOPT(bool, StackRealign)
73 CGOPT(std::string, TrapFuncName)
74 CGOPT(bool, UseCtors)
75 CGOPT(bool, RelaxELFRelocations)
76 CGOPT_EXP(bool, DataSections)
77 CGOPT_EXP(bool, FunctionSections)
78 CGOPT(bool, IgnoreXCOFFVisibility)
79 CGOPT(bool, XCOFFTracebackTable)
80 CGOPT(std::string, BBSections)
81 CGOPT(std::string, StackProtectorGuard)
82 CGOPT(unsigned, StackProtectorGuardOffset)
83 CGOPT(std::string, StackProtectorGuardReg)
84 CGOPT(unsigned, TLSSize)
85 CGOPT(bool, EmulatedTLS)
86 CGOPT(bool, UniqueSectionNames)
87 CGOPT(bool, UniqueBasicBlockSectionNames)
88 CGOPT(EABI, EABIVersion)
89 CGOPT(DebuggerKind, DebuggerTuningOpt)
90 CGOPT(bool, EnableStackSizeSection)
91 CGOPT(bool, EnableAddrsig)
92 CGOPT(bool, EmitCallSiteInfo)
94 CGOPT(bool, EnableDebugEntryValues)
95 CGOPT(bool, PseudoProbeForProfiling)
96 CGOPT(bool, ValueTrackingVariableLocations)
97 CGOPT(bool, ForceDwarfFrameSection)
98 CGOPT(bool, XRayOmitFunctionIndex)
99 
101 #define CGBINDOPT(NAME) \
102  do { \
103  NAME##View = std::addressof(NAME); \
104  } while (0)
105 
106  static cl::opt<std::string> MArch(
107  "march", cl::desc("Architecture to generate code for (see --version)"));
108  CGBINDOPT(MArch);
109 
110  static cl::opt<std::string> MCPU(
111  "mcpu", cl::desc("Target a specific cpu type (-mcpu=help for details)"),
112  cl::value_desc("cpu-name"), cl::init(""));
113  CGBINDOPT(MCPU);
114 
115  static cl::list<std::string> MAttrs(
116  "mattr", cl::CommaSeparated,
117  cl::desc("Target specific attributes (-mattr=help for details)"),
118  cl::value_desc("a1,+a2,-a3,..."));
119  CGBINDOPT(MAttrs);
120 
121  static cl::opt<Reloc::Model> RelocModel(
122  "relocation-model", cl::desc("Choose relocation model"),
123  cl::values(
124  clEnumValN(Reloc::Static, "static", "Non-relocatable code"),
125  clEnumValN(Reloc::PIC_, "pic",
126  "Fully relocatable, position independent code"),
127  clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
128  "Relocatable external references, non-relocatable code"),
129  clEnumValN(
130  Reloc::ROPI, "ropi",
131  "Code and read-only data relocatable, accessed PC-relative"),
132  clEnumValN(
133  Reloc::RWPI, "rwpi",
134  "Read-write data relocatable, accessed relative to static base"),
135  clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
136  "Combination of ropi and rwpi")));
137  CGBINDOPT(RelocModel);
138 
139  static cl::opt<ThreadModel::Model> ThreadModel(
140  "thread-model", cl::desc("Choose threading model"),
142  cl::values(
143  clEnumValN(ThreadModel::POSIX, "posix", "POSIX thread model"),
144  clEnumValN(ThreadModel::Single, "single", "Single thread model")));
145  CGBINDOPT(ThreadModel);
146 
147  static cl::opt<CodeModel::Model> CodeModel(
148  "code-model", cl::desc("Choose code model"),
149  cl::values(clEnumValN(CodeModel::Tiny, "tiny", "Tiny code model"),
150  clEnumValN(CodeModel::Small, "small", "Small code model"),
151  clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"),
152  clEnumValN(CodeModel::Medium, "medium", "Medium code model"),
153  clEnumValN(CodeModel::Large, "large", "Large code model")));
154  CGBINDOPT(CodeModel);
155 
156  static cl::opt<ExceptionHandling> ExceptionModel(
157  "exception-model", cl::desc("exception model"),
159  cl::values(
161  "default exception handling model"),
163  "DWARF-like CFI based exception handling"),
165  "SjLj exception handling"),
166  clEnumValN(ExceptionHandling::ARM, "arm", "ARM EHABI exceptions"),
168  "Windows exception model"),
170  "WebAssembly exception handling")));
171  CGBINDOPT(ExceptionModel);
172 
174  "filetype", cl::init(CGFT_AssemblyFile),
175  cl::desc(
176  "Choose a file type (not all types are supported by all targets):"),
177  cl::values(
178  clEnumValN(CGFT_AssemblyFile, "asm", "Emit an assembly ('.s') file"),
180  "Emit a native object ('.o') file"),
181  clEnumValN(CGFT_Null, "null",
182  "Emit nothing, for performance testing")));
184 
185  static cl::opt<FramePointer::FP> FramePointerUsage(
186  "frame-pointer",
187  cl::desc("Specify frame pointer elimination optimization"),
189  cl::values(
191  "Disable frame pointer elimination"),
192  clEnumValN(FramePointer::NonLeaf, "non-leaf",
193  "Disable frame pointer elimination for non-leaf frame"),
195  "Enable frame pointer elimination")));
196  CGBINDOPT(FramePointerUsage);
197 
198  static cl::opt<bool> EnableUnsafeFPMath(
199  "enable-unsafe-fp-math",
200  cl::desc("Enable optimizations that may decrease FP precision"),
201  cl::init(false));
202  CGBINDOPT(EnableUnsafeFPMath);
203 
204  static cl::opt<bool> EnableNoInfsFPMath(
205  "enable-no-infs-fp-math",
206  cl::desc("Enable FP math optimizations that assume no +-Infs"),
207  cl::init(false));
208  CGBINDOPT(EnableNoInfsFPMath);
209 
210  static cl::opt<bool> EnableNoNaNsFPMath(
211  "enable-no-nans-fp-math",
212  cl::desc("Enable FP math optimizations that assume no NaNs"),
213  cl::init(false));
214  CGBINDOPT(EnableNoNaNsFPMath);
215 
216  static cl::opt<bool> EnableNoSignedZerosFPMath(
217  "enable-no-signed-zeros-fp-math",
218  cl::desc("Enable FP math optimizations that assume "
219  "the sign of 0 is insignificant"),
220  cl::init(false));
221  CGBINDOPT(EnableNoSignedZerosFPMath);
222 
223  static cl::opt<bool> EnableNoTrappingFPMath(
224  "enable-no-trapping-fp-math",
225  cl::desc("Enable setting the FP exceptions build "
226  "attribute not to use exceptions"),
227  cl::init(false));
228  CGBINDOPT(EnableNoTrappingFPMath);
229 
230  static const auto DenormFlagEnumOptions =
232  "IEEE 754 denormal numbers"),
233  clEnumValN(DenormalMode::PreserveSign, "preserve-sign",
234  "the sign of a flushed-to-zero number is preserved "
235  "in the sign of 0"),
236  clEnumValN(DenormalMode::PositiveZero, "positive-zero",
237  "denormals are flushed to positive zero"));
238 
239  // FIXME: Doesn't have way to specify separate input and output modes.
240  static cl::opt<DenormalMode::DenormalModeKind> DenormalFPMath(
241  "denormal-fp-math",
242  cl::desc("Select which denormal numbers the code is permitted to require"),
244  DenormFlagEnumOptions);
245  CGBINDOPT(DenormalFPMath);
246 
247  static cl::opt<DenormalMode::DenormalModeKind> DenormalFP32Math(
248  "denormal-fp-math-f32",
249  cl::desc("Select which denormal numbers the code is permitted to require for float"),
251  DenormFlagEnumOptions);
252  CGBINDOPT(DenormalFP32Math);
253 
254  static cl::opt<bool> EnableHonorSignDependentRoundingFPMath(
255  "enable-sign-dependent-rounding-fp-math", cl::Hidden,
256  cl::desc("Force codegen to assume rounding mode can change dynamically"),
257  cl::init(false));
258  CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
259 
260  static cl::opt<FloatABI::ABIType> FloatABIForCalls(
261  "float-abi", cl::desc("Choose float ABI type"),
264  "Target default float ABI type"),
265  clEnumValN(FloatABI::Soft, "soft",
266  "Soft float ABI (implied by -soft-float)"),
267  clEnumValN(FloatABI::Hard, "hard",
268  "Hard float ABI (uses FP registers)")));
269  CGBINDOPT(FloatABIForCalls);
270 
271  static cl::opt<FPOpFusion::FPOpFusionMode> FuseFPOps(
272  "fp-contract", cl::desc("Enable aggressive formation of fused FP ops"),
274  cl::values(
276  "Fuse FP ops whenever profitable"),
277  clEnumValN(FPOpFusion::Standard, "on", "Only fuse 'blessed' FP ops."),
279  "Only fuse FP ops when the result won't be affected.")));
280  CGBINDOPT(FuseFPOps);
281 
282  static cl::opt<bool> DontPlaceZerosInBSS(
283  "nozero-initialized-in-bss",
284  cl::desc("Don't place zero-initialized symbols into bss section"),
285  cl::init(false));
286  CGBINDOPT(DontPlaceZerosInBSS);
287 
288  static cl::opt<bool> EnableAIXExtendedAltivecABI(
289  "vec-extabi", cl::desc("Enable the AIX Extended Altivec ABI."),
290  cl::init(false));
291  CGBINDOPT(EnableAIXExtendedAltivecABI);
292 
293  static cl::opt<bool> EnableGuaranteedTailCallOpt(
294  "tailcallopt",
295  cl::desc(
296  "Turn fastcc calls into tail calls by (potentially) changing ABI."),
297  cl::init(false));
298  CGBINDOPT(EnableGuaranteedTailCallOpt);
299 
300  static cl::opt<bool> DisableTailCalls(
301  "disable-tail-calls", cl::desc("Never emit tail calls"), cl::init(false));
302  CGBINDOPT(DisableTailCalls);
303 
304  static cl::opt<bool> StackSymbolOrdering(
305  "stack-symbol-ordering", cl::desc("Order local stack symbols."),
306  cl::init(true));
307  CGBINDOPT(StackSymbolOrdering);
308 
309  static cl::opt<unsigned> OverrideStackAlignment(
310  "stack-alignment", cl::desc("Override default stack alignment"),
311  cl::init(0));
312  CGBINDOPT(OverrideStackAlignment);
313 
314  static cl::opt<bool> StackRealign(
315  "stackrealign",
316  cl::desc("Force align the stack to the minimum alignment"),
317  cl::init(false));
318  CGBINDOPT(StackRealign);
319 
320  static cl::opt<std::string> TrapFuncName(
321  "trap-func", cl::Hidden,
322  cl::desc("Emit a call to trap function rather than a trap instruction"),
323  cl::init(""));
324  CGBINDOPT(TrapFuncName);
325 
326  static cl::opt<bool> UseCtors("use-ctors",
327  cl::desc("Use .ctors instead of .init_array."),
328  cl::init(false));
329  CGBINDOPT(UseCtors);
330 
331  static cl::opt<bool> RelaxELFRelocations(
332  "relax-elf-relocations",
333  cl::desc(
334  "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
335  cl::init(false));
336  CGBINDOPT(RelaxELFRelocations);
337 
338  static cl::opt<bool> DataSections(
339  "data-sections", cl::desc("Emit data into separate sections"),
340  cl::init(false));
341  CGBINDOPT(DataSections);
342 
343  static cl::opt<bool> FunctionSections(
344  "function-sections", cl::desc("Emit functions into separate sections"),
345  cl::init(false));
346  CGBINDOPT(FunctionSections);
347 
348  static cl::opt<bool> IgnoreXCOFFVisibility(
349  "ignore-xcoff-visibility",
350  cl::desc("Not emit the visibility attribute for asm in AIX OS or give "
351  "all symbols 'unspecified' visibility in XCOFF object file"),
352  cl::init(false));
353  CGBINDOPT(IgnoreXCOFFVisibility);
354 
355  static cl::opt<bool> XCOFFTracebackTable(
356  "xcoff-traceback-table", cl::desc("Emit the XCOFF traceback table"),
357  cl::init(true));
358  CGBINDOPT(XCOFFTracebackTable);
359 
360  static cl::opt<std::string> BBSections(
361  "basic-block-sections",
362  cl::desc("Emit basic blocks into separate sections"),
363  cl::value_desc("all | <function list (file)> | labels | none"),
364  cl::init("none"));
365  CGBINDOPT(BBSections);
366 
367  static cl::opt<std::string> StackProtectorGuard(
368  "stack-protector-guard", cl::desc("Stack protector guard mode"),
369  cl::init("none"));
370  CGBINDOPT(StackProtectorGuard);
371 
372  static cl::opt<std::string> StackProtectorGuardReg(
373  "stack-protector-guard-reg", cl::desc("Stack protector guard register"),
374  cl::init("none"));
375  CGBINDOPT(StackProtectorGuardReg);
376 
377  static cl::opt<unsigned> StackProtectorGuardOffset(
378  "stack-protector-guard-offset", cl::desc("Stack protector guard offset"),
379  cl::init((unsigned)-1));
380  CGBINDOPT(StackProtectorGuardOffset);
381 
382  static cl::opt<unsigned> TLSSize(
383  "tls-size", cl::desc("Bit size of immediate TLS offsets"), cl::init(0));
384  CGBINDOPT(TLSSize);
385 
386  static cl::opt<bool> EmulatedTLS(
387  "emulated-tls", cl::desc("Use emulated TLS model"), cl::init(false));
388  CGBINDOPT(EmulatedTLS);
389 
390  static cl::opt<bool> UniqueSectionNames(
391  "unique-section-names", cl::desc("Give unique names to every section"),
392  cl::init(true));
393  CGBINDOPT(UniqueSectionNames);
394 
395  static cl::opt<bool> UniqueBasicBlockSectionNames(
396  "unique-basic-block-section-names",
397  cl::desc("Give unique names to every basic block section"),
398  cl::init(false));
399  CGBINDOPT(UniqueBasicBlockSectionNames);
400 
401  static cl::opt<EABI> EABIVersion(
402  "meabi", cl::desc("Set EABI type (default depends on triple):"),
404  cl::values(
405  clEnumValN(EABI::Default, "default", "Triple default EABI version"),
406  clEnumValN(EABI::EABI4, "4", "EABI version 4"),
407  clEnumValN(EABI::EABI5, "5", "EABI version 5"),
408  clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
409  CGBINDOPT(EABIVersion);
410 
411  static cl::opt<DebuggerKind> DebuggerTuningOpt(
412  "debugger-tune", cl::desc("Tune debug info for a particular debugger"),
414  cl::values(
415  clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
416  clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
417  clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)")));
418  CGBINDOPT(DebuggerTuningOpt);
419 
420  static cl::opt<bool> EnableStackSizeSection(
421  "stack-size-section",
422  cl::desc("Emit a section containing stack size metadata"),
423  cl::init(false));
424  CGBINDOPT(EnableStackSizeSection);
425 
426  static cl::opt<bool> EnableAddrsig(
427  "addrsig", cl::desc("Emit an address-significance table"),
428  cl::init(false));
429  CGBINDOPT(EnableAddrsig);
430 
431  static cl::opt<bool> EmitCallSiteInfo(
432  "emit-call-site-info",
433  cl::desc(
434  "Emit call site debug information, if debug information is enabled."),
435  cl::init(false));
436  CGBINDOPT(EmitCallSiteInfo);
437 
438  static cl::opt<bool> EnableDebugEntryValues(
439  "debug-entry-values",
440  cl::desc("Enable debug info for the debug entry values."),
441  cl::init(false));
442  CGBINDOPT(EnableDebugEntryValues);
443 
444  static cl::opt<bool> PseudoProbeForProfiling(
445  "pseudo-probe-for-profiling", cl::desc("Emit pseudo probes for AutoFDO"),
446  cl::init(false));
447  CGBINDOPT(PseudoProbeForProfiling);
448 
449  static cl::opt<bool> ValueTrackingVariableLocations(
450  "experimental-debug-variable-locations",
451  cl::desc("Use experimental new value-tracking variable locations"),
452  cl::init(false));
453  CGBINDOPT(ValueTrackingVariableLocations);
454 
456  "split-machine-functions",
457  cl::desc("Split out cold basic blocks from machine functions based on "
458  "profile information"),
459  cl::init(false));
461 
462  static cl::opt<bool> ForceDwarfFrameSection(
463  "force-dwarf-frame-section",
464  cl::desc("Always emit a debug frame section."), cl::init(false));
465  CGBINDOPT(ForceDwarfFrameSection);
466 
467  static cl::opt<bool> XRayOmitFunctionIndex(
468  "no-xray-index", cl::desc("Don't emit xray_fn_idx section"),
469  cl::init(false));
470  CGBINDOPT(XRayOmitFunctionIndex);
471 
472 #undef CGBINDOPT
473 
475 }
476 
479  if (getBBSections() == "all")
480  return BasicBlockSection::All;
481  else if (getBBSections() == "labels")
483  else if (getBBSections() == "none")
485  else {
488  if (!MBOrErr) {
489  errs() << "Error loading basic block sections function list file: "
490  << MBOrErr.getError().message() << "\n";
491  } else {
492  Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
493  }
495  }
496 }
497 
500  if (getStackProtectorGuard() == "tls")
502  if (getStackProtectorGuard() == "global")
504  if (getStackProtectorGuard() != "none") {
507  if (!MBOrErr)
508  errs() << "error illegal stack protector guard mode: "
509  << MBOrErr.getError().message() << "\n";
510  else
511  Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
512  }
514 }
515 
516 // Common utility function tightly tied to the options listed here. Initializes
517 // a TargetOptions object with CodeGen flags and returns it.
520  TargetOptions Options;
521  Options.AllowFPOpFusion = getFuseFPOps();
527 
529 
530  // FIXME: Should have separate input and output flags
531  Options.setFPDenormalMode(DenormalMode(DenormKind, DenormKind));
532 
536  Options.FloatABIType = getFloatABIForCalls();
542  Options.UseInitArray = !getUseCtors();
544  Options.DataSections =
549  Options.BBSections = getBBSectionsMode(Options);
555  Options.TLSSize = getTLSSize();
556  Options.EmulatedTLS = getEmulatedTLS();
557  Options.ExplicitEmulatedTLS = EmulatedTLSView->getNumOccurrences() > 0;
558  Options.ExceptionModel = getExceptionModel();
561  Options.EmitAddrsig = getEnableAddrsig();
568 
570 
571  Options.ThreadModel = getThreadModel();
572  Options.EABIVersion = getEABIVersion();
574 
575  return Options;
576 }
577 
578 std::string codegen::getCPUStr() {
579  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
580  // this will set the CPU to an empty string which tells the target to
581  // pick a basic default.
582  if (getMCPU() == "native")
583  return std::string(sys::getHostCPUName());
584 
585  return getMCPU();
586 }
587 
588 std::string codegen::getFeaturesStr() {
589  SubtargetFeatures Features;
590 
591  // If user asked for the 'native' CPU, we need to autodetect features.
592  // This is necessary for x86 where the CPU might not support all the
593  // features the autodetected CPU name lists in the target. For example,
594  // not all Sandybridge processors support AVX.
595  if (getMCPU() == "native") {
596  StringMap<bool> HostFeatures;
597  if (sys::getHostCPUFeatures(HostFeatures))
598  for (auto &F : HostFeatures)
599  Features.AddFeature(F.first(), F.second);
600  }
601 
602  for (auto const &MAttr : getMAttrs())
603  Features.AddFeature(MAttr);
604 
605  return Features.getString();
606 }
607 
608 std::vector<std::string> codegen::getFeatureList() {
609  SubtargetFeatures Features;
610 
611  // If user asked for the 'native' CPU, we need to autodetect features.
612  // This is necessary for x86 where the CPU might not support all the
613  // features the autodetected CPU name lists in the target. For example,
614  // not all Sandybridge processors support AVX.
615  if (getMCPU() == "native") {
616  StringMap<bool> HostFeatures;
617  if (sys::getHostCPUFeatures(HostFeatures))
618  for (auto &F : HostFeatures)
619  Features.AddFeature(F.first(), F.second);
620  }
621 
622  for (auto const &MAttr : getMAttrs())
623  Features.AddFeature(MAttr);
624 
625  return Features.getFeatures();
626 }
627 
629  B.addAttribute(Name, Val ? "true" : "false");
630 }
631 
632 #define HANDLE_BOOL_ATTR(CL, AttrName) \
633  do { \
634  if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
635  renderBoolStringAttr(NewAttrs, AttrName, *CL); \
636  } while (0)
637 
638 /// Set function attributes of function \p F based on CPU, Features, and command
639 /// line flags.
641  Function &F) {
642  auto &Ctx = F.getContext();
643  AttributeList Attrs = F.getAttributes();
644  AttrBuilder NewAttrs;
645 
646  if (!CPU.empty() && !F.hasFnAttribute("target-cpu"))
647  NewAttrs.addAttribute("target-cpu", CPU);
648  if (!Features.empty()) {
649  // Append the command line features to any that are already on the function.
650  StringRef OldFeatures =
651  F.getFnAttribute("target-features").getValueAsString();
652  if (OldFeatures.empty())
653  NewAttrs.addAttribute("target-features", Features);
654  else {
655  SmallString<256> Appended(OldFeatures);
656  Appended.push_back(',');
657  Appended.append(Features);
658  NewAttrs.addAttribute("target-features", Appended);
659  }
660  }
661  if (FramePointerUsageView->getNumOccurrences() > 0 &&
662  !F.hasFnAttribute("frame-pointer")) {
664  NewAttrs.addAttribute("frame-pointer", "all");
666  NewAttrs.addAttribute("frame-pointer", "non-leaf");
668  NewAttrs.addAttribute("frame-pointer", "none");
669  }
670  if (DisableTailCallsView->getNumOccurrences() > 0)
671  NewAttrs.addAttribute("disable-tail-calls",
673  if (getStackRealign())
674  NewAttrs.addAttribute("stackrealign");
675 
676  HANDLE_BOOL_ATTR(EnableUnsafeFPMathView, "unsafe-fp-math");
677  HANDLE_BOOL_ATTR(EnableNoInfsFPMathView, "no-infs-fp-math");
678  HANDLE_BOOL_ATTR(EnableNoNaNsFPMathView, "no-nans-fp-math");
679  HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMathView, "no-signed-zeros-fp-math");
680 
681  if (DenormalFPMathView->getNumOccurrences() > 0 &&
682  !F.hasFnAttribute("denormal-fp-math")) {
684 
685  // FIXME: Command line flag should expose separate input/output modes.
686  NewAttrs.addAttribute("denormal-fp-math",
687  DenormalMode(DenormKind, DenormKind).str());
688  }
689 
690  if (DenormalFP32MathView->getNumOccurrences() > 0 &&
691  !F.hasFnAttribute("denormal-fp-math-f32")) {
692  // FIXME: Command line flag should expose separate input/output modes.
694 
695  NewAttrs.addAttribute(
696  "denormal-fp-math-f32",
697  DenormalMode(DenormKind, DenormKind).str());
698  }
699 
700  if (TrapFuncNameView->getNumOccurrences() > 0)
701  for (auto &B : F)
702  for (auto &I : B)
703  if (auto *Call = dyn_cast<CallInst>(&I))
704  if (const auto *F = Call->getCalledFunction())
705  if (F->getIntrinsicID() == Intrinsic::debugtrap ||
706  F->getIntrinsicID() == Intrinsic::trap)
707  Call->addAttribute(
709  Attribute::get(Ctx, "trap-func-name", getTrapFuncName()));
710 
711  // Let NewAttrs override Attrs.
712  F.setAttributes(
713  Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs));
714 }
715 
716 /// Set function attributes of functions in Module M based on CPU,
717 /// Features, and command line flags.
719  Module &M) {
720  for (Function &F : M)
721  setFunctionAttributes(CPU, Features, F);
722 }
unsigned StackSymbolOrdering
StackSymbolOrdering - When true, this will allow CodeGen to order the local stack symbols (for code s...
ThreadModel::Model getThreadModel()
bool getFunctionSections()
#define CGLIST(TY, NAME)
unsigned NoTrappingFPMath
NoTrappingFPMath - This flag is enabled when the -enable-no-trapping-fp-math is specified on the comm...
Represents either an error or a value T.
Definition: ErrorOr.h:56
bool getPseudoProbeForProfiling()
MCTargetOptions MCOptions
Machine level options.
#define CGOPT(TY, NAME)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
#define CGBINDOPT(NAME)
bool getEmitCallSiteInfo()
unsigned EnableDebugEntryValues
When set to true, the EnableDebugEntryValues option forces production of debug entry values even if t...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
unsigned EmitCallSiteInfo
The flag enables call site info production.
EABI EABIVersion
EABIVersion - This flag specifies the EABI version.
unsigned DataSections
Emit data into separate sections.
void push_back(const T &Elt)
Definition: SmallVector.h:379
setjmp/longjmp based exceptions
llvm::FloatABI::ABIType getFloatABIForCalls()
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Definition: Optional.h:272
llvm::EABI getEABIVersion()
bool getUniqueSectionNames()
bool getForceDwarfFrameSection()
std::string getString() const
Returns features as a string.
F(f)
unsigned EnableAIXExtendedAltivecABI
EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is specified.
Create this object with static storage to register codegen-related command line options.
Definition: CommandFlags.h:142
ThreadModel::Model ThreadModel
ThreadModel - This flag specifies the type of threading model to assume for things like atomics.
unsigned ValueTrackingVariableLocations
std::vector< std::string > getFeatureList()
std::string getCPUStr()
DebuggerKind
Identify a debugger for "tuning" the debug info.
TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
std::string getBBSections()
unsigned getOverrideStackAlignment()
bool getRelaxELFRelocations()
bool getEnableHonorSignDependentRoundingFPMath()
BasicBlockSection
Definition: TargetOptions.h:61
bool getValueTrackingVariableLocations()
ExceptionHandling ExceptionModel
What exception model to use.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:156
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
#define CGOPT_EXP(TY, NAME)
StringRef toStringRef(const Optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
MCTargetOptions InitMCTargetOptionsFromFlags()
unsigned NoNaNsFPMath
NoNaNsFPMath - This flag is enabled when the -enable-no-nans-fp-math flag is specified on the command...
void setFunctionAttributes(StringRef CPU, StringRef Features, Function &F)
Set function attributes of function F based on CPU, Features, and command line flags.
unsigned EnableMachineFunctionSplitter
Enables the MachineFunctionSplitter pass.
bool getDisableTailCalls()
unsigned FunctionSections
Emit functions into separate sections.
unsigned UniqueSectionNames
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned getTLSSize()
unsigned XCOFFTracebackTable
Emit XCOFF traceback table.
bool getXCOFFTracebackTable()
static void codegen(Module *M, llvm::raw_pwrite_stream &OS, function_ref< std::unique_ptr< TargetMachine >()> TMFactory, CodeGenFileType FileType)
Definition: ParallelCG.cpp:27
WebAssembly Exception Handling.
void append(in_iter S, in_iter E)
Append from an iterator pair.
Definition: SmallString.h:86
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition: CodeGen.h:63
DebuggerKind DebuggerTuning
Which debugger to tune for.
unsigned StackProtectorGuardOffset
Stack protector guard offset to use.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:427
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 UniqueBasicBlockSectionNames
Use unique names for basic block sections.
unsigned ExplicitEmulatedTLS
Whether -emulated-tls or -no-emulated-tls is set.
bool getEnableUnsafeFPMath()
unsigned TLSSize
Bit size of immediate TLS offsets (0 == use the default).
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:683
static cl::opt< bool > EnableMachineFunctionSplitter("enable-split-machine-functions", cl::Hidden, cl::desc("Split out cold blocks from machine functions based on profile " "information."))
Enable the machine function splitter pass.
StackProtectorGuards
Definition: TargetOptions.h:76
llvm::StackProtectorGuards getStackProtectorGuardMode(llvm::TargetOptions &Options)
std::error_code getError() const
Definition: ErrorOr.h:153
std::string getMCPU()
unsigned EmitStackSizeSection
Emit section containing metadata on function stack sizes.
IEEE-754 denormal numbers preserved.
unsigned GuaranteedTailCallOpt
GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void setFPDenormalMode(DenormalMode Mode)
unsigned PseudoProbeForProfiling
Emit pseudo probes into the binary for sample profiling.
unsigned NoInfsFPMath
NoInfsFPMath - This flag is enabled when the -enable-no-infs-fp-math flag is specified on the command...
llvm::FPOpFusion::FPOpFusionMode getFuseFPOps()
unsigned NoZerosInBSS
NoZerosInBSS - By default some codegens place zero-initialized data to .bss section.
#define HANDLE_BOOL_ATTR(CL, AttrName)
llvm::FramePointer::FP getFramePointerUsage()
unsigned ForceDwarfFrameSection
Emit DWARF debug frame section.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
bool getEnableAddrsig()
Represent subnormal handling kind for floating point instruction inputs and outputs.
BasicBlockSection BBSections
Emit basic blocks into separate sections.
unsigned getStackProtectorGuardOffset()
void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val)
Optional< bool > getExplicitDataSections()
FileType
Defines the file type this file represents.
Definition: InterfaceFile.h:57
bool getEnableNoInfsFPMath()
bool getStackSymbolOrdering()
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
bool getEnableMachineFunctionSplitter()
bool getEnableNoTrappingFPMath()
bool getUniqueBasicBlockSectionNames()
Module.h This file contains the declarations for the Module class.
llvm::DebuggerKind getDebuggerTuningOpt()
unsigned XRayOmitFunctionIndex
Emit XRay Function Index section.
unsigned EmitAddrsig
Emit address-significance table.
bool getEnableStackSizeSection()
unsigned StackAlignmentOverride
StackAlignmentOverride - Override default stack alignment for target.
bool getUseCtors()
bool getDontPlaceZerosInBSS()
unsigned IgnoreXCOFFVisibility
Do not emit visibility attribute for xcoff.
DenormalModeKind
Represent handled modes for denormal (aka subnormal) modes in the floating point environment.
The sign of a flushed-to-zero number is preserved in the sign of 0.
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.
DenormalMode::DenormalModeKind getDenormalFP32Math()
unsigned RelaxELFRelocations
std::string getStackProtectorGuard()
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:658
std::string StackProtectorGuardReg
Stack protector guard reg to use, e.g. usually fs or gs in X86.
bool getEnableNoSignedZerosFPMath()
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
Definition: Host.cpp:1240
No exception support.
Windows Exception Handling.
#define I(x, y, z)
Definition: MD5.cpp:59
bool getXRayOmitFunctionIndex()
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:81
bool getStackRealign()
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Create this object with static storage to register mc-related command line options.
bool getEnableDebugEntryValues()
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
Definition: Attributes.h:780
std::shared_ptr< MemoryBuffer > BBSectionsFuncListBuf
Memory Buffer that contains information on sampled basic blocks and used to selectively generate basi...
bool getEnableNoNaNsFPMath()
std::vector< std::string > getMAttrs()
unsigned HonorSignDependentRoundingFPMathOption
HonorSignDependentRoundingFPMath - This returns true when the -enable-sign-dependent-rounding-fp-math...
bool getEmulatedTLS()
bool hasDefaultDataSections() const
Tests whether the target uses -data-sections as default.
Definition: Triple.h:812
Denormals are flushed to positive zero.
ExceptionHandling
StackProtectorGuards StackProtectorGuard
Stack protector guard mode to use, e.g. tls, global.
DenormalMode::DenormalModeKind getDenormalFPMath()
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1556
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:57
std::string getTrapFuncName()
llvm::ExceptionHandling getExceptionModel()
std::string getStackProtectorGuardReg()
DWARF-like instruction based exceptions.
bool getEnableGuaranteedTailCallOpt()
llvm::BasicBlockSection getBBSectionsMode(llvm::TargetOptions &Options)
std::string getFeaturesStr()
bool getIgnoreXCOFFVisibility()
bool getEnableAIXExtendedAltivecABI()
FloatABI::ABIType FloatABIType
FloatABIType - This setting is set by -float-abi=xxx option is specfied on the command line.
bool getHostCPUFeatures(StringMap< bool, MallocAllocator > &Features)
getHostCPUFeatures - Get the LLVM names for the host CPU features.