LLVM  14.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"
21 
22 using namespace llvm;
23 
24 #define CGOPT(TY, NAME) \
25  static cl::opt<TY> *NAME##View; \
26  TY codegen::get##NAME() { \
27  assert(NAME##View && "RegisterCodeGenFlags not created."); \
28  return *NAME##View; \
29  }
30 
31 #define CGLIST(TY, NAME) \
32  static cl::list<TY> *NAME##View; \
33  std::vector<TY> codegen::get##NAME() { \
34  assert(NAME##View && "RegisterCodeGenFlags not created."); \
35  return *NAME##View; \
36  }
37 
38 #define CGOPT_EXP(TY, NAME) \
39  CGOPT(TY, NAME) \
40  Optional<TY> codegen::getExplicit##NAME() { \
41  if (NAME##View->getNumOccurrences()) { \
42  TY res = *NAME##View; \
43  return res; \
44  } \
45  return None; \
46  }
47 
48 CGOPT(std::string, MArch)
49 CGOPT(std::string, MCPU)
50 CGLIST(std::string, MAttrs)
51 CGOPT_EXP(Reloc::Model, RelocModel)
52 CGOPT(ThreadModel::Model, ThreadModel)
53 CGOPT_EXP(CodeModel::Model, CodeModel)
54 CGOPT(ExceptionHandling, ExceptionModel)
56 CGOPT(FramePointerKind, FramePointerUsage)
57 CGOPT(bool, EnableUnsafeFPMath)
58 CGOPT(bool, EnableNoInfsFPMath)
59 CGOPT(bool, EnableNoNaNsFPMath)
60 CGOPT(bool, EnableNoSignedZerosFPMath)
61 CGOPT(bool, EnableNoTrappingFPMath)
62 CGOPT(bool, EnableAIXExtendedAltivecABI)
64 CGOPT(DenormalMode::DenormalModeKind, DenormalFP32Math)
65 CGOPT(bool, EnableHonorSignDependentRoundingFPMath)
66 CGOPT(FloatABI::ABIType, FloatABIForCalls)
68 CGOPT(SwiftAsyncFramePointerMode, SwiftAsyncFramePointer)
69 CGOPT(bool, DontPlaceZerosInBSS)
70 CGOPT(bool, EnableGuaranteedTailCallOpt)
71 CGOPT(bool, DisableTailCalls)
72 CGOPT(bool, StackSymbolOrdering)
73 CGOPT(bool, StackRealign)
74 CGOPT(std::string, TrapFuncName)
75 CGOPT(bool, UseCtors)
76 CGOPT(bool, RelaxELFRelocations)
77 CGOPT_EXP(bool, DataSections)
78 CGOPT_EXP(bool, FunctionSections)
79 CGOPT(bool, IgnoreXCOFFVisibility)
80 CGOPT(bool, XCOFFTracebackTable)
81 CGOPT(std::string, BBSections)
82 CGOPT(unsigned, TLSSize)
83 CGOPT(bool, EmulatedTLS)
84 CGOPT(bool, UniqueSectionNames)
85 CGOPT(bool, UniqueBasicBlockSectionNames)
86 CGOPT(EABI, EABIVersion)
87 CGOPT(DebuggerKind, DebuggerTuningOpt)
88 CGOPT(bool, EnableStackSizeSection)
89 CGOPT(bool, EnableAddrsig)
90 CGOPT(bool, EmitCallSiteInfo)
92 CGOPT(bool, EnableDebugEntryValues)
93 CGOPT(bool, ValueTrackingVariableLocations)
94 CGOPT(bool, ForceDwarfFrameSection)
95 CGOPT(bool, XRayOmitFunctionIndex)
96 CGOPT(bool, DebugStrictDwarf)
97 CGOPT(unsigned, AlignLoops)
98 
100 #define CGBINDOPT(NAME) \
101  do { \
102  NAME##View = std::addressof(NAME); \
103  } while (0)
104 
105  static cl::opt<std::string> MArch(
106  "march", cl::desc("Architecture to generate code for (see --version)"));
107  CGBINDOPT(MArch);
108 
109  static cl::opt<std::string> MCPU(
110  "mcpu", cl::desc("Target a specific cpu type (-mcpu=help for details)"),
111  cl::value_desc("cpu-name"), cl::init(""));
112  CGBINDOPT(MCPU);
113 
114  static cl::list<std::string> MAttrs(
115  "mattr", cl::CommaSeparated,
116  cl::desc("Target specific attributes (-mattr=help for details)"),
117  cl::value_desc("a1,+a2,-a3,..."));
118  CGBINDOPT(MAttrs);
119 
120  static cl::opt<Reloc::Model> RelocModel(
121  "relocation-model", cl::desc("Choose relocation model"),
122  cl::values(
123  clEnumValN(Reloc::Static, "static", "Non-relocatable code"),
124  clEnumValN(Reloc::PIC_, "pic",
125  "Fully relocatable, position independent code"),
126  clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
127  "Relocatable external references, non-relocatable code"),
128  clEnumValN(
129  Reloc::ROPI, "ropi",
130  "Code and read-only data relocatable, accessed PC-relative"),
131  clEnumValN(
132  Reloc::RWPI, "rwpi",
133  "Read-write data relocatable, accessed relative to static base"),
134  clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
135  "Combination of ropi and rwpi")));
136  CGBINDOPT(RelocModel);
137 
138  static cl::opt<ThreadModel::Model> ThreadModel(
139  "thread-model", cl::desc("Choose threading model"),
141  cl::values(
142  clEnumValN(ThreadModel::POSIX, "posix", "POSIX thread model"),
143  clEnumValN(ThreadModel::Single, "single", "Single thread model")));
144  CGBINDOPT(ThreadModel);
145 
146  static cl::opt<CodeModel::Model> CodeModel(
147  "code-model", cl::desc("Choose code model"),
148  cl::values(clEnumValN(CodeModel::Tiny, "tiny", "Tiny code model"),
149  clEnumValN(CodeModel::Small, "small", "Small code model"),
150  clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"),
151  clEnumValN(CodeModel::Medium, "medium", "Medium code model"),
152  clEnumValN(CodeModel::Large, "large", "Large code model")));
153  CGBINDOPT(CodeModel);
154 
155  static cl::opt<ExceptionHandling> ExceptionModel(
156  "exception-model", cl::desc("exception model"),
158  cl::values(
160  "default exception handling model"),
162  "DWARF-like CFI based exception handling"),
164  "SjLj exception handling"),
165  clEnumValN(ExceptionHandling::ARM, "arm", "ARM EHABI exceptions"),
167  "Windows exception model"),
169  "WebAssembly exception handling")));
170  CGBINDOPT(ExceptionModel);
171 
173  "filetype", cl::init(CGFT_AssemblyFile),
174  cl::desc(
175  "Choose a file type (not all types are supported by all targets):"),
176  cl::values(
177  clEnumValN(CGFT_AssemblyFile, "asm", "Emit an assembly ('.s') file"),
179  "Emit a native object ('.o') file"),
180  clEnumValN(CGFT_Null, "null",
181  "Emit nothing, for performance testing")));
183 
184  static cl::opt<FramePointerKind> FramePointerUsage(
185  "frame-pointer",
186  cl::desc("Specify frame pointer elimination optimization"),
188  cl::values(
190  "Disable frame pointer elimination"),
192  "Disable frame pointer elimination for non-leaf frame"),
194  "Enable frame pointer elimination")));
195  CGBINDOPT(FramePointerUsage);
196 
197  static cl::opt<bool> EnableUnsafeFPMath(
198  "enable-unsafe-fp-math",
199  cl::desc("Enable optimizations that may decrease FP precision"),
200  cl::init(false));
201  CGBINDOPT(EnableUnsafeFPMath);
202 
203  static cl::opt<bool> EnableNoInfsFPMath(
204  "enable-no-infs-fp-math",
205  cl::desc("Enable FP math optimizations that assume no +-Infs"),
206  cl::init(false));
207  CGBINDOPT(EnableNoInfsFPMath);
208 
209  static cl::opt<bool> EnableNoNaNsFPMath(
210  "enable-no-nans-fp-math",
211  cl::desc("Enable FP math optimizations that assume no NaNs"),
212  cl::init(false));
213  CGBINDOPT(EnableNoNaNsFPMath);
214 
215  static cl::opt<bool> EnableNoSignedZerosFPMath(
216  "enable-no-signed-zeros-fp-math",
217  cl::desc("Enable FP math optimizations that assume "
218  "the sign of 0 is insignificant"),
219  cl::init(false));
220  CGBINDOPT(EnableNoSignedZerosFPMath);
221 
222  static cl::opt<bool> EnableNoTrappingFPMath(
223  "enable-no-trapping-fp-math",
224  cl::desc("Enable setting the FP exceptions build "
225  "attribute not to use exceptions"),
226  cl::init(false));
227  CGBINDOPT(EnableNoTrappingFPMath);
228 
229  static const auto DenormFlagEnumOptions =
231  "IEEE 754 denormal numbers"),
232  clEnumValN(DenormalMode::PreserveSign, "preserve-sign",
233  "the sign of a flushed-to-zero number is preserved "
234  "in the sign of 0"),
235  clEnumValN(DenormalMode::PositiveZero, "positive-zero",
236  "denormals are flushed to positive zero"));
237 
238  // FIXME: Doesn't have way to specify separate input and output modes.
239  static cl::opt<DenormalMode::DenormalModeKind> DenormalFPMath(
240  "denormal-fp-math",
241  cl::desc("Select which denormal numbers the code is permitted to require"),
243  DenormFlagEnumOptions);
244  CGBINDOPT(DenormalFPMath);
245 
246  static cl::opt<DenormalMode::DenormalModeKind> DenormalFP32Math(
247  "denormal-fp-math-f32",
248  cl::desc("Select which denormal numbers the code is permitted to require for float"),
250  DenormFlagEnumOptions);
251  CGBINDOPT(DenormalFP32Math);
252 
253  static cl::opt<bool> EnableHonorSignDependentRoundingFPMath(
254  "enable-sign-dependent-rounding-fp-math", cl::Hidden,
255  cl::desc("Force codegen to assume rounding mode can change dynamically"),
256  cl::init(false));
257  CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
258 
259  static cl::opt<FloatABI::ABIType> FloatABIForCalls(
260  "float-abi", cl::desc("Choose float ABI type"),
263  "Target default float ABI type"),
264  clEnumValN(FloatABI::Soft, "soft",
265  "Soft float ABI (implied by -soft-float)"),
266  clEnumValN(FloatABI::Hard, "hard",
267  "Hard float ABI (uses FP registers)")));
268  CGBINDOPT(FloatABIForCalls);
269 
270  static cl::opt<FPOpFusion::FPOpFusionMode> FuseFPOps(
271  "fp-contract", cl::desc("Enable aggressive formation of fused FP ops"),
273  cl::values(
275  "Fuse FP ops whenever profitable"),
276  clEnumValN(FPOpFusion::Standard, "on", "Only fuse 'blessed' FP ops."),
278  "Only fuse FP ops when the result won't be affected.")));
279  CGBINDOPT(FuseFPOps);
280 
281  static cl::opt<SwiftAsyncFramePointerMode> SwiftAsyncFramePointer(
282  "swift-async-fp",
283  cl::desc("Determine when the Swift async frame pointer should be set"),
286  "Determine based on deployment target"),
288  "Always set the bit"),
290  "Never set the bit")));
291  CGBINDOPT(SwiftAsyncFramePointer);
292 
293  static cl::opt<bool> DontPlaceZerosInBSS(
294  "nozero-initialized-in-bss",
295  cl::desc("Don't place zero-initialized symbols into bss section"),
296  cl::init(false));
297  CGBINDOPT(DontPlaceZerosInBSS);
298 
299  static cl::opt<bool> EnableAIXExtendedAltivecABI(
300  "vec-extabi", cl::desc("Enable the AIX Extended Altivec ABI."),
301  cl::init(false));
302  CGBINDOPT(EnableAIXExtendedAltivecABI);
303 
304  static cl::opt<bool> EnableGuaranteedTailCallOpt(
305  "tailcallopt",
306  cl::desc(
307  "Turn fastcc calls into tail calls by (potentially) changing ABI."),
308  cl::init(false));
309  CGBINDOPT(EnableGuaranteedTailCallOpt);
310 
311  static cl::opt<bool> DisableTailCalls(
312  "disable-tail-calls", cl::desc("Never emit tail calls"), cl::init(false));
313  CGBINDOPT(DisableTailCalls);
314 
315  static cl::opt<bool> StackSymbolOrdering(
316  "stack-symbol-ordering", cl::desc("Order local stack symbols."),
317  cl::init(true));
318  CGBINDOPT(StackSymbolOrdering);
319 
320  static cl::opt<bool> StackRealign(
321  "stackrealign",
322  cl::desc("Force align the stack to the minimum alignment"),
323  cl::init(false));
324  CGBINDOPT(StackRealign);
325 
326  static cl::opt<std::string> TrapFuncName(
327  "trap-func", cl::Hidden,
328  cl::desc("Emit a call to trap function rather than a trap instruction"),
329  cl::init(""));
330  CGBINDOPT(TrapFuncName);
331 
332  static cl::opt<bool> UseCtors("use-ctors",
333  cl::desc("Use .ctors instead of .init_array."),
334  cl::init(false));
335  CGBINDOPT(UseCtors);
336 
337  static cl::opt<bool> RelaxELFRelocations(
338  "relax-elf-relocations",
339  cl::desc(
340  "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
341  cl::init(false));
342  CGBINDOPT(RelaxELFRelocations);
343 
344  static cl::opt<bool> DataSections(
345  "data-sections", cl::desc("Emit data into separate sections"),
346  cl::init(false));
347  CGBINDOPT(DataSections);
348 
349  static cl::opt<bool> FunctionSections(
350  "function-sections", cl::desc("Emit functions into separate sections"),
351  cl::init(false));
352  CGBINDOPT(FunctionSections);
353 
354  static cl::opt<bool> IgnoreXCOFFVisibility(
355  "ignore-xcoff-visibility",
356  cl::desc("Not emit the visibility attribute for asm in AIX OS or give "
357  "all symbols 'unspecified' visibility in XCOFF object file"),
358  cl::init(false));
359  CGBINDOPT(IgnoreXCOFFVisibility);
360 
361  static cl::opt<bool> XCOFFTracebackTable(
362  "xcoff-traceback-table", cl::desc("Emit the XCOFF traceback table"),
363  cl::init(true));
364  CGBINDOPT(XCOFFTracebackTable);
365 
366  static cl::opt<std::string> BBSections(
367  "basic-block-sections",
368  cl::desc("Emit basic blocks into separate sections"),
369  cl::value_desc("all | <function list (file)> | labels | none"),
370  cl::init("none"));
371  CGBINDOPT(BBSections);
372 
373  static cl::opt<unsigned> TLSSize(
374  "tls-size", cl::desc("Bit size of immediate TLS offsets"), cl::init(0));
375  CGBINDOPT(TLSSize);
376 
377  static cl::opt<bool> EmulatedTLS(
378  "emulated-tls", cl::desc("Use emulated TLS model"), cl::init(false));
379  CGBINDOPT(EmulatedTLS);
380 
381  static cl::opt<bool> UniqueSectionNames(
382  "unique-section-names", cl::desc("Give unique names to every section"),
383  cl::init(true));
384  CGBINDOPT(UniqueSectionNames);
385 
386  static cl::opt<bool> UniqueBasicBlockSectionNames(
387  "unique-basic-block-section-names",
388  cl::desc("Give unique names to every basic block section"),
389  cl::init(false));
390  CGBINDOPT(UniqueBasicBlockSectionNames);
391 
392  static cl::opt<EABI> EABIVersion(
393  "meabi", cl::desc("Set EABI type (default depends on triple):"),
395  cl::values(
396  clEnumValN(EABI::Default, "default", "Triple default EABI version"),
397  clEnumValN(EABI::EABI4, "4", "EABI version 4"),
398  clEnumValN(EABI::EABI5, "5", "EABI version 5"),
399  clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
400  CGBINDOPT(EABIVersion);
401 
402  static cl::opt<DebuggerKind> DebuggerTuningOpt(
403  "debugger-tune", cl::desc("Tune debug info for a particular debugger"),
405  cl::values(
406  clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
407  clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
408  clEnumValN(DebuggerKind::DBX, "dbx", "dbx"),
409  clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)")));
410  CGBINDOPT(DebuggerTuningOpt);
411 
412  static cl::opt<bool> EnableStackSizeSection(
413  "stack-size-section",
414  cl::desc("Emit a section containing stack size metadata"),
415  cl::init(false));
416  CGBINDOPT(EnableStackSizeSection);
417 
418  static cl::opt<bool> EnableAddrsig(
419  "addrsig", cl::desc("Emit an address-significance table"),
420  cl::init(false));
421  CGBINDOPT(EnableAddrsig);
422 
423  static cl::opt<bool> EmitCallSiteInfo(
424  "emit-call-site-info",
425  cl::desc(
426  "Emit call site debug information, if debug information is enabled."),
427  cl::init(false));
428  CGBINDOPT(EmitCallSiteInfo);
429 
430  static cl::opt<bool> EnableDebugEntryValues(
431  "debug-entry-values",
432  cl::desc("Enable debug info for the debug entry values."),
433  cl::init(false));
434  CGBINDOPT(EnableDebugEntryValues);
435 
436  static cl::opt<bool> ValueTrackingVariableLocations(
437  "experimental-debug-variable-locations",
438  cl::desc("Use experimental new value-tracking variable locations"),
439  cl::init(false));
440  CGBINDOPT(ValueTrackingVariableLocations);
441 
443  "split-machine-functions",
444  cl::desc("Split out cold basic blocks from machine functions based on "
445  "profile information"),
446  cl::init(false));
448 
449  static cl::opt<bool> ForceDwarfFrameSection(
450  "force-dwarf-frame-section",
451  cl::desc("Always emit a debug frame section."), cl::init(false));
452  CGBINDOPT(ForceDwarfFrameSection);
453 
454  static cl::opt<bool> XRayOmitFunctionIndex(
455  "no-xray-index", cl::desc("Don't emit xray_fn_idx section"),
456  cl::init(false));
457  CGBINDOPT(XRayOmitFunctionIndex);
458 
459  static cl::opt<bool> DebugStrictDwarf(
460  "strict-dwarf", cl::desc("use strict dwarf"), cl::init(false));
461  CGBINDOPT(DebugStrictDwarf);
462 
463  static cl::opt<unsigned> AlignLoops("align-loops",
464  cl::desc("Default alignment for loops"));
465  CGBINDOPT(AlignLoops);
466 
467 #undef CGBINDOPT
468 
470 }
471 
474  if (getBBSections() == "all")
475  return BasicBlockSection::All;
476  else if (getBBSections() == "labels")
478  else if (getBBSections() == "none")
480  else {
483  if (!MBOrErr) {
484  errs() << "Error loading basic block sections function list file: "
485  << MBOrErr.getError().message() << "\n";
486  } else {
487  Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
488  }
490  }
491 }
492 
493 // Common utility function tightly tied to the options listed here. Initializes
494 // a TargetOptions object with CodeGen flags and returns it.
498  Options.AllowFPOpFusion = getFuseFPOps();
499  Options.UnsafeFPMath = getEnableUnsafeFPMath();
500  Options.NoInfsFPMath = getEnableNoInfsFPMath();
501  Options.NoNaNsFPMath = getEnableNoNaNsFPMath();
502  Options.NoSignedZerosFPMath = getEnableNoSignedZerosFPMath();
503  Options.NoTrappingFPMath = getEnableNoTrappingFPMath();
504 
506 
507  // FIXME: Should have separate input and output flags
508  Options.setFPDenormalMode(DenormalMode(DenormKind, DenormKind));
509 
510  Options.HonorSignDependentRoundingFPMathOption =
513  Options.FloatABIType = getFloatABIForCalls();
514  Options.EnableAIXExtendedAltivecABI = getEnableAIXExtendedAltivecABI();
515  Options.NoZerosInBSS = getDontPlaceZerosInBSS();
516  Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt();
517  Options.StackSymbolOrdering = getStackSymbolOrdering();
518  Options.UseInitArray = !getUseCtors();
519  Options.RelaxELFRelocations = getRelaxELFRelocations();
520  Options.DataSections =
522  Options.FunctionSections = getFunctionSections();
523  Options.IgnoreXCOFFVisibility = getIgnoreXCOFFVisibility();
524  Options.XCOFFTracebackTable = getXCOFFTracebackTable();
525  Options.BBSections = getBBSectionsMode(Options);
526  Options.UniqueSectionNames = getUniqueSectionNames();
527  Options.UniqueBasicBlockSectionNames = getUniqueBasicBlockSectionNames();
528  Options.TLSSize = getTLSSize();
529  Options.EmulatedTLS = getEmulatedTLS();
530  Options.ExplicitEmulatedTLS = EmulatedTLSView->getNumOccurrences() > 0;
531  Options.ExceptionModel = getExceptionModel();
532  Options.EmitStackSizeSection = getEnableStackSizeSection();
533  Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter();
534  Options.EmitAddrsig = getEnableAddrsig();
535  Options.EmitCallSiteInfo = getEmitCallSiteInfo();
536  Options.EnableDebugEntryValues = getEnableDebugEntryValues();
537  Options.ValueTrackingVariableLocations = getValueTrackingVariableLocations();
538  Options.ForceDwarfFrameSection = getForceDwarfFrameSection();
539  Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex();
540  Options.DebugStrictDwarf = getDebugStrictDwarf();
541  Options.LoopAlignment = getAlignLoops();
542 
544 
545  Options.ThreadModel = getThreadModel();
546  Options.EABIVersion = getEABIVersion();
547  Options.DebuggerTuning = getDebuggerTuningOpt();
548  Options.SwiftAsyncFramePointer = getSwiftAsyncFramePointer();
549  return Options;
550 }
551 
552 std::string codegen::getCPUStr() {
553  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
554  // this will set the CPU to an empty string which tells the target to
555  // pick a basic default.
556  if (getMCPU() == "native")
557  return std::string(sys::getHostCPUName());
558 
559  return getMCPU();
560 }
561 
562 std::string codegen::getFeaturesStr() {
563  SubtargetFeatures Features;
564 
565  // If user asked for the 'native' CPU, we need to autodetect features.
566  // This is necessary for x86 where the CPU might not support all the
567  // features the autodetected CPU name lists in the target. For example,
568  // not all Sandybridge processors support AVX.
569  if (getMCPU() == "native") {
570  StringMap<bool> HostFeatures;
571  if (sys::getHostCPUFeatures(HostFeatures))
572  for (auto &F : HostFeatures)
573  Features.AddFeature(F.first(), F.second);
574  }
575 
576  for (auto const &MAttr : getMAttrs())
577  Features.AddFeature(MAttr);
578 
579  return Features.getString();
580 }
581 
582 std::vector<std::string> codegen::getFeatureList() {
583  SubtargetFeatures Features;
584 
585  // If user asked for the 'native' CPU, we need to autodetect features.
586  // This is necessary for x86 where the CPU might not support all the
587  // features the autodetected CPU name lists in the target. For example,
588  // not all Sandybridge processors support AVX.
589  if (getMCPU() == "native") {
590  StringMap<bool> HostFeatures;
591  if (sys::getHostCPUFeatures(HostFeatures))
592  for (auto &F : HostFeatures)
593  Features.AddFeature(F.first(), F.second);
594  }
595 
596  for (auto const &MAttr : getMAttrs())
597  Features.AddFeature(MAttr);
598 
599  return Features.getFeatures();
600 }
601 
603  B.addAttribute(Name, Val ? "true" : "false");
604 }
605 
606 #define HANDLE_BOOL_ATTR(CL, AttrName) \
607  do { \
608  if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
609  renderBoolStringAttr(NewAttrs, AttrName, *CL); \
610  } while (0)
611 
612 /// Set function attributes of function \p F based on CPU, Features, and command
613 /// line flags.
615  Function &F) {
616  auto &Ctx = F.getContext();
617  AttributeList Attrs = F.getAttributes();
618  AttrBuilder NewAttrs;
619 
620  if (!CPU.empty() && !F.hasFnAttribute("target-cpu"))
621  NewAttrs.addAttribute("target-cpu", CPU);
622  if (!Features.empty()) {
623  // Append the command line features to any that are already on the function.
624  StringRef OldFeatures =
625  F.getFnAttribute("target-features").getValueAsString();
626  if (OldFeatures.empty())
627  NewAttrs.addAttribute("target-features", Features);
628  else {
629  SmallString<256> Appended(OldFeatures);
630  Appended.push_back(',');
631  Appended.append(Features);
632  NewAttrs.addAttribute("target-features", Appended);
633  }
634  }
635  if (FramePointerUsageView->getNumOccurrences() > 0 &&
636  !F.hasFnAttribute("frame-pointer")) {
638  NewAttrs.addAttribute("frame-pointer", "all");
640  NewAttrs.addAttribute("frame-pointer", "non-leaf");
642  NewAttrs.addAttribute("frame-pointer", "none");
643  }
644  if (DisableTailCallsView->getNumOccurrences() > 0)
645  NewAttrs.addAttribute("disable-tail-calls",
647  if (getStackRealign())
648  NewAttrs.addAttribute("stackrealign");
649 
650  HANDLE_BOOL_ATTR(EnableUnsafeFPMathView, "unsafe-fp-math");
651  HANDLE_BOOL_ATTR(EnableNoInfsFPMathView, "no-infs-fp-math");
652  HANDLE_BOOL_ATTR(EnableNoNaNsFPMathView, "no-nans-fp-math");
653  HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMathView, "no-signed-zeros-fp-math");
654 
655  if (DenormalFPMathView->getNumOccurrences() > 0 &&
656  !F.hasFnAttribute("denormal-fp-math")) {
658 
659  // FIXME: Command line flag should expose separate input/output modes.
660  NewAttrs.addAttribute("denormal-fp-math",
661  DenormalMode(DenormKind, DenormKind).str());
662  }
663 
664  if (DenormalFP32MathView->getNumOccurrences() > 0 &&
665  !F.hasFnAttribute("denormal-fp-math-f32")) {
666  // FIXME: Command line flag should expose separate input/output modes.
668 
669  NewAttrs.addAttribute(
670  "denormal-fp-math-f32",
671  DenormalMode(DenormKind, DenormKind).str());
672  }
673 
674  if (TrapFuncNameView->getNumOccurrences() > 0)
675  for (auto &B : F)
676  for (auto &I : B)
677  if (auto *Call = dyn_cast<CallInst>(&I))
678  if (const auto *F = Call->getCalledFunction())
679  if (F->getIntrinsicID() == Intrinsic::debugtrap ||
680  F->getIntrinsicID() == Intrinsic::trap)
681  Call->addFnAttr(
682  Attribute::get(Ctx, "trap-func-name", getTrapFuncName()));
683 
684  // Let NewAttrs override Attrs.
685  F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
686 }
687 
688 /// Set function attributes of functions in Module M based on CPU,
689 /// Features, and command line flags.
691  Module &M) {
692  for (Function &F : M)
693  setFunctionAttributes(CPU, Features, F);
694 }
llvm::codegen::getDenormalFP32Math
DenormalMode::DenormalModeKind getDenormalFP32Math()
MemoryBuffer.h
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::codegen::getDontPlaceZerosInBSS
bool getDontPlaceZerosInBSS()
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::EABI::GNU
@ GNU
llvm::CGFT_ObjectFile
@ CGFT_ObjectFile
Definition: CodeGen.h:65
llvm::DebuggerKind
DebuggerKind
Identify a debugger for "tuning" the debug info.
Definition: TargetOptions.h:97
llvm::TargetOptions
Definition: TargetOptions.h:124
llvm::ExceptionHandling::SjLj
@ SjLj
setjmp/longjmp based exceptions
llvm::FPOpFusion::Standard
@ Standard
Definition: TargetOptions.h:38
llvm::Function
Definition: Function.h:61
llvm::codegen::getDisableTailCalls
bool getDisableTailCalls()
llvm::SubtargetFeatures::AddFeature
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
Definition: SubtargetFeature.cpp:41
llvm::Attribute::get
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:92
llvm::CodeModel::Medium
@ Medium
Definition: CodeGen.h:28
Host.h
llvm::codegen::getExplicitDataSections
Optional< bool > getExplicitDataSections()
codegen
Since we know that Vector is byte aligned and we know the element offset of we should change the load into a lve *x instead of doing a load store lve *x sequence Implement passing vectors by value into calls and receiving them as arguments GCC apparently tries to codegen
Definition: README_ALTIVEC.txt:46
llvm::codegen::InitTargetOptionsFromCodeGenFlags
TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
Definition: CommandFlags.cpp:496
llvm::cl::CommaSeparated
@ CommaSeparated
Definition: CommandLine.h:169
EnableMachineFunctionSplitter
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.
llvm::codegen::getUseCtors
bool getUseCtors()
llvm::codegen::getEnableNoTrappingFPMath
bool getEnableNoTrappingFPMath()
llvm::codegen::getStackRealign
bool getStackRealign()
llvm::EABI::Default
@ Default
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::CGFT_Null
@ CGFT_Null
Definition: CodeGen.h:66
llvm::ThreadModel::POSIX
@ POSIX
Definition: TargetOptions.h:56
llvm::codegen::getTrapFuncName
std::string getTrapFuncName()
llvm::FloatABI::ABIType
ABIType
Definition: TargetOptions.h:28
llvm::sys::getHostCPUFeatures
bool getHostCPUFeatures(StringMap< bool, MallocAllocator > &Features)
getHostCPUFeatures - Get the LLVM names for the host CPU features.
Module.h
llvm::codegen::getExceptionModel
llvm::ExceptionHandling getExceptionModel()
llvm::AttributeList
Definition: Attributes.h:398
llvm::codegen::getDenormalFPMath
DenormalMode::DenormalModeKind getDenormalFPMath()
llvm::mc::InitMCTargetOptionsFromFlags
MCTargetOptions InitMCTargetOptionsFromFlags()
Definition: MCTargetOptionsCommandFlags.cpp:107
llvm::Reloc::ROPI_RWPI
@ ROPI_RWPI
Definition: CodeGen.h:22
llvm::FPOpFusion::FPOpFusionMode
FPOpFusionMode
Definition: TargetOptions.h:36
llvm::ExceptionHandling::ARM
@ ARM
ARM EHABI.
llvm::FloatABI::Hard
@ Hard
Definition: TargetOptions.h:31
llvm::codegen::getFeaturesStr
std::string getFeaturesStr()
Definition: CommandFlags.cpp:562
llvm::codegen::getEnableMachineFunctionSplitter
bool getEnableMachineFunctionSplitter()
llvm::Triple::hasDefaultDataSections
bool hasDefaultDataSections() const
Tests whether the target uses -data-sections as default.
Definition: Triple.h:825
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:892
llvm::codegen::getMCPU
std::string getMCPU()
llvm::CodeModel::Kernel
@ Kernel
Definition: CodeGen.h:28
llvm::DebuggerKind::GDB
@ GDB
Tune debug info for gdb.
llvm::codegen::getEnableNoSignedZerosFPMath
bool getEnableNoSignedZerosFPMath()
llvm::codegen::getFloatABIForCalls
llvm::FloatABI::ABIType getFloatABIForCalls()
llvm::BasicBlockSection::List
@ List
llvm::BasicBlockSection::None
@ None
llvm::codegen::getEnableAddrsig
bool getEnableAddrsig()
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::DenormalMode::Invalid
@ Invalid
Definition: FloatingPointMode.h:71
llvm::Reloc::Model
Model
Definition: CodeGen.h:22
llvm::SwiftAsyncFramePointerMode::Never
@ Never
Never set the bit.
llvm::codegen::getFunctionSections
bool getFunctionSections()
llvm::codegen::getStackSymbolOrdering
bool getStackSymbolOrdering()
CommandLine.h
llvm::codegen::getAlignLoops
unsigned getAlignLoops()
llvm::codegen::getXRayOmitFunctionIndex
bool getXRayOmitFunctionIndex()
llvm::MemoryBuffer::getFile
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Definition: MemoryBuffer.cpp:246
llvm::codegen::getBBSectionsMode
llvm::BasicBlockSection getBBSectionsMode(llvm::TargetOptions &Options)
Definition: CommandFlags.cpp:473
SubtargetFeature.h
llvm::ExceptionHandling
ExceptionHandling
Definition: MCTargetOptions.h:18
llvm::codegen::getDebuggerTuningOpt
llvm::DebuggerKind getDebuggerTuningOpt()
llvm::codegen::renderBoolStringAttr
void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val)
Definition: CommandFlags.cpp:602
llvm::codegen::getSwiftAsyncFramePointer
SwiftAsyncFramePointerMode getSwiftAsyncFramePointer()
llvm::SubtargetFeatures::getFeatures
const std::vector< std::string > & getFeatures() const
Returns the vector of individual subtarget features.
Definition: SubtargetFeature.h:196
llvm::SubtargetFeatures
Manages the enabling and disabling of subtarget specific features.
Definition: SubtargetFeature.h:183
llvm::codegen::getThreadModel
ThreadModel::Model getThreadModel()
llvm::FloatABI::Default
@ Default
Definition: TargetOptions.h:29
llvm::ErrorOr::getError
std::error_code getError() const
Definition: ErrorOr.h:153
llvm::dwarf::toStringRef
StringRef toStringRef(const Optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
Definition: DWARFFormValue.h:186
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::CodeModel::Small
@ Small
Definition: CodeGen.h:28
llvm::BasicBlockSection::Labels
@ Labels
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
llvm::ExceptionHandling::Wasm
@ Wasm
WebAssembly Exception Handling.
llvm::codegen::getEnableUnsafeFPMath
bool getEnableUnsafeFPMath()
llvm::BasicBlockSection::All
@ All
llvm::codegen::getEnableNoNaNsFPMath
bool getEnableNoNaNsFPMath()
CGLIST
#define CGLIST(TY, NAME)
Definition: CommandFlags.cpp:31
llvm::DenormalMode::DenormalModeKind
DenormalModeKind
Represent handled modes for denormal (aka subnormal) modes in the floating point environment.
Definition: FloatingPointMode.h:70
llvm::EABI::EABI4
@ EABI4
llvm::StringMap< bool >
llvm::SmallString< 256 >
llvm::MachO::FileType
FileType
Defines the file type this file represents.
Definition: InterfaceFile.h:57
llvm::DebuggerKind::DBX
@ DBX
Tune debug info for dbx.
llvm::CodeModel::Model
Model
Definition: CodeGen.h:28
llvm::SmallString::append
void append(StringRef RHS)
Append from a StringRef.
Definition: SmallString.h:67
llvm::SubtargetFeatures::getString
std::string getString() const
Returns features as a string.
Definition: SubtargetFeature.cpp:54
llvm::Optional::getValueOr
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
Definition: Optional.h:297
llvm::cl::opt
Definition: CommandLine.h:1434
llvm::codegen::getEnableGuaranteedTailCallOpt
bool getEnableGuaranteedTailCallOpt()
llvm::cl::values
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:699
llvm::codegen::getIgnoreXCOFFVisibility
bool getIgnoreXCOFFVisibility()
llvm::codegen::getEnableNoInfsFPMath
bool getEnableNoInfsFPMath()
llvm::codegen::getEnableHonorSignDependentRoundingFPMath
bool getEnableHonorSignDependentRoundingFPMath()
llvm::codegen::getEnableStackSizeSection
bool getEnableStackSizeSection()
llvm::codegen::getFeatureList
std::vector< std::string > getFeatureList()
Definition: CommandFlags.cpp:582
llvm::codegen::getEmulatedTLS
bool getEmulatedTLS()
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::codegen::getTLSSize
unsigned getTLSSize()
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::AttrBuilder
Definition: Attributes.h:907
llvm::DenormalMode
Represent subnormal handling kind for floating point instruction inputs and outputs.
Definition: FloatingPointMode.h:67
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::codegen::getCPUStr
std::string getCPUStr()
Definition: CommandFlags.cpp:552
llvm::FramePointerKind::All
@ All
llvm::codegen::getUniqueBasicBlockSectionNames
bool getUniqueBasicBlockSectionNames()
HANDLE_BOOL_ATTR
#define HANDLE_BOOL_ATTR(CL, AttrName)
Definition: CommandFlags.cpp:606
CGOPT_EXP
#define CGOPT_EXP(TY, NAME)
Definition: CommandFlags.cpp:38
llvm::FramePointerKind
FramePointerKind
Definition: CodeGen.h:70
llvm::Reloc::ROPI
@ ROPI
Definition: CodeGen.h:22
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::DenormalMode::IEEE
@ IEEE
IEEE-754 denormal numbers preserved.
Definition: FloatingPointMode.h:74
llvm::Reloc::DynamicNoPIC
@ DynamicNoPIC
Definition: CodeGen.h:22
llvm::codegen::getMAttrs
std::vector< std::string > getMAttrs()
llvm::Reloc::RWPI
@ RWPI
Definition: CodeGen.h:22
llvm::codegen::getEABIVersion
llvm::EABI getEABIVersion()
llvm::Reloc::PIC_
@ PIC_
Definition: CodeGen.h:22
llvm::CodeGenFileType
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition: CodeGen.h:63
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::DebuggerKind::Default
@ Default
No specific tuning requested.
llvm::Reloc::Static
@ Static
Definition: CodeGen.h:22
clEnumValN
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:674
llvm::SwiftAsyncFramePointerMode::DeploymentBased
@ DeploymentBased
Determine whether to set the bit statically or dynamically based on the deployment target.
llvm::DenormalMode::PositiveZero
@ PositiveZero
Denormals are flushed to positive zero.
Definition: FloatingPointMode.h:80
llvm::codegen::getFuseFPOps
llvm::FPOpFusion::FPOpFusionMode getFuseFPOps()
llvm::CodeModel::Tiny
@ Tiny
Definition: CodeGen.h:28
llvm::codegen::setFunctionAttributes
void setFunctionAttributes(StringRef CPU, StringRef Features, Function &F)
Set function attributes of function F based on CPU, Features, and command line flags.
Definition: CommandFlags.cpp:614
llvm::codegen::getDebugStrictDwarf
bool getDebugStrictDwarf()
llvm::EABI::EABI5
@ EABI5
llvm::mc::RegisterMCTargetOptionsFlags
Create this object with static storage to register mc-related command line options.
Definition: MCTargetOptionsCommandFlags.h:49
llvm::codegen::getRelaxELFRelocations
bool getRelaxELFRelocations()
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::codegen::getUniqueSectionNames
bool getUniqueSectionNames()
llvm::FPOpFusion::Strict
@ Strict
Definition: TargetOptions.h:39
llvm::codegen::getValueTrackingVariableLocations
bool getValueTrackingVariableLocations()
CGOPT
#define CGOPT(TY, NAME)
Definition: CommandFlags.cpp:24
llvm::codegen::getEnableDebugEntryValues
bool getEnableDebugEntryValues()
CGBINDOPT
#define CGBINDOPT(NAME)
llvm::ExceptionHandling::WinEH
@ WinEH
Windows Exception Handling.
llvm::FramePointerKind::NonLeaf
@ NonLeaf
llvm::codegen::getEmitCallSiteInfo
bool getEmitCallSiteInfo()
llvm::ThreadModel::Single
@ Single
Definition: TargetOptions.h:57
llvm::cl::value_desc
Definition: CommandLine.h:424
llvm::ExceptionHandling::None
@ None
No exception support.
llvm::FPOpFusion::Fast
@ Fast
Definition: TargetOptions.h:37
llvm::CodeModel::Large
@ Large
Definition: CodeGen.h:28
llvm::AttrBuilder::addAttribute
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
Definition: Attributes.h:933
llvm::BasicBlockSection
BasicBlockSection
Definition: TargetOptions.h:61
llvm::ThreadModel::Model
Model
Definition: TargetOptions.h:55
llvm::codegen::getForceDwarfFrameSection
bool getForceDwarfFrameSection()
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::codegen::getXCOFFTracebackTable
bool getXCOFFTracebackTable()
llvm::sys::getHostCPUName
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
Definition: Host.cpp:1360
llvm::FloatABI::Soft
@ Soft
Definition: TargetOptions.h:30
llvm::codegen::getEnableAIXExtendedAltivecABI
bool getEnableAIXExtendedAltivecABI()
llvm::SwiftAsyncFramePointerMode
SwiftAsyncFramePointerMode
Indicates when and how the Swift async frame pointer bit should be set.
Definition: TargetOptions.h:114
llvm::EABI
EABI
Definition: TargetOptions.h:76
llvm::DenormalMode::PreserveSign
@ PreserveSign
The sign of a flushed-to-zero number is preserved in the sign of 0.
Definition: FloatingPointMode.h:77
llvm::FramePointerKind::None
@ None
llvm::cl::desc
Definition: CommandLine.h:414
llvm::CGFT_AssemblyFile
@ CGFT_AssemblyFile
Definition: CodeGen.h:64
llvm::DebuggerKind::SCE
@ SCE
Tune debug info for SCE targets (e.g. PS4).
llvm::DebuggerKind::LLDB
@ LLDB
Tune debug info for lldb.
CommandFlags.h
llvm::ExceptionHandling::DwarfCFI
@ DwarfCFI
DWARF-like instruction based exceptions.
llvm::codegen::RegisterCodeGenFlags
Create this object with static storage to register codegen-related command line options.
Definition: CommandFlags.h:144
llvm::SwiftAsyncFramePointerMode::Always
@ Always
Always set the bit.
llvm::codegen::getBBSections
std::string getBBSections()
llvm::codegen::getFramePointerUsage
FramePointerKind getFramePointerUsage()
llvm::cl::list
Definition: CommandLine.h:1642