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, PseudoProbeForProfiling)
94 CGOPT(bool, ValueTrackingVariableLocations)
95 CGOPT(bool, ForceDwarfFrameSection)
96 CGOPT(bool, XRayOmitFunctionIndex)
97 CGOPT(bool, DebugStrictDwarf)
98 CGOPT(unsigned, AlignLoops)
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<FramePointerKind> FramePointerUsage(
186  "frame-pointer",
187  cl::desc("Specify frame pointer elimination optimization"),
189  cl::values(
191  "Disable frame pointer elimination"),
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<SwiftAsyncFramePointerMode> SwiftAsyncFramePointer(
283  "swift-async-fp",
284  cl::desc("Determine when the Swift async frame pointer should be set"),
287  "Determine based on deployment target"),
289  "Always set the bit"),
291  "Never set the bit")));
292  CGBINDOPT(SwiftAsyncFramePointer);
293 
294  static cl::opt<bool> DontPlaceZerosInBSS(
295  "nozero-initialized-in-bss",
296  cl::desc("Don't place zero-initialized symbols into bss section"),
297  cl::init(false));
298  CGBINDOPT(DontPlaceZerosInBSS);
299 
300  static cl::opt<bool> EnableAIXExtendedAltivecABI(
301  "vec-extabi", cl::desc("Enable the AIX Extended Altivec ABI."),
302  cl::init(false));
303  CGBINDOPT(EnableAIXExtendedAltivecABI);
304 
305  static cl::opt<bool> EnableGuaranteedTailCallOpt(
306  "tailcallopt",
307  cl::desc(
308  "Turn fastcc calls into tail calls by (potentially) changing ABI."),
309  cl::init(false));
310  CGBINDOPT(EnableGuaranteedTailCallOpt);
311 
312  static cl::opt<bool> DisableTailCalls(
313  "disable-tail-calls", cl::desc("Never emit tail calls"), cl::init(false));
314  CGBINDOPT(DisableTailCalls);
315 
316  static cl::opt<bool> StackSymbolOrdering(
317  "stack-symbol-ordering", cl::desc("Order local stack symbols."),
318  cl::init(true));
319  CGBINDOPT(StackSymbolOrdering);
320 
321  static cl::opt<bool> StackRealign(
322  "stackrealign",
323  cl::desc("Force align the stack to the minimum alignment"),
324  cl::init(false));
325  CGBINDOPT(StackRealign);
326 
327  static cl::opt<std::string> TrapFuncName(
328  "trap-func", cl::Hidden,
329  cl::desc("Emit a call to trap function rather than a trap instruction"),
330  cl::init(""));
331  CGBINDOPT(TrapFuncName);
332 
333  static cl::opt<bool> UseCtors("use-ctors",
334  cl::desc("Use .ctors instead of .init_array."),
335  cl::init(false));
336  CGBINDOPT(UseCtors);
337 
338  static cl::opt<bool> RelaxELFRelocations(
339  "relax-elf-relocations",
340  cl::desc(
341  "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
342  cl::init(false));
343  CGBINDOPT(RelaxELFRelocations);
344 
345  static cl::opt<bool> DataSections(
346  "data-sections", cl::desc("Emit data into separate sections"),
347  cl::init(false));
348  CGBINDOPT(DataSections);
349 
350  static cl::opt<bool> FunctionSections(
351  "function-sections", cl::desc("Emit functions into separate sections"),
352  cl::init(false));
353  CGBINDOPT(FunctionSections);
354 
355  static cl::opt<bool> IgnoreXCOFFVisibility(
356  "ignore-xcoff-visibility",
357  cl::desc("Not emit the visibility attribute for asm in AIX OS or give "
358  "all symbols 'unspecified' visibility in XCOFF object file"),
359  cl::init(false));
360  CGBINDOPT(IgnoreXCOFFVisibility);
361 
362  static cl::opt<bool> XCOFFTracebackTable(
363  "xcoff-traceback-table", cl::desc("Emit the XCOFF traceback table"),
364  cl::init(true));
365  CGBINDOPT(XCOFFTracebackTable);
366 
367  static cl::opt<std::string> BBSections(
368  "basic-block-sections",
369  cl::desc("Emit basic blocks into separate sections"),
370  cl::value_desc("all | <function list (file)> | labels | none"),
371  cl::init("none"));
372  CGBINDOPT(BBSections);
373 
374  static cl::opt<unsigned> TLSSize(
375  "tls-size", cl::desc("Bit size of immediate TLS offsets"), cl::init(0));
376  CGBINDOPT(TLSSize);
377 
378  static cl::opt<bool> EmulatedTLS(
379  "emulated-tls", cl::desc("Use emulated TLS model"), cl::init(false));
380  CGBINDOPT(EmulatedTLS);
381 
382  static cl::opt<bool> UniqueSectionNames(
383  "unique-section-names", cl::desc("Give unique names to every section"),
384  cl::init(true));
385  CGBINDOPT(UniqueSectionNames);
386 
387  static cl::opt<bool> UniqueBasicBlockSectionNames(
388  "unique-basic-block-section-names",
389  cl::desc("Give unique names to every basic block section"),
390  cl::init(false));
391  CGBINDOPT(UniqueBasicBlockSectionNames);
392 
393  static cl::opt<EABI> EABIVersion(
394  "meabi", cl::desc("Set EABI type (default depends on triple):"),
396  cl::values(
397  clEnumValN(EABI::Default, "default", "Triple default EABI version"),
398  clEnumValN(EABI::EABI4, "4", "EABI version 4"),
399  clEnumValN(EABI::EABI5, "5", "EABI version 5"),
400  clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
401  CGBINDOPT(EABIVersion);
402 
403  static cl::opt<DebuggerKind> DebuggerTuningOpt(
404  "debugger-tune", cl::desc("Tune debug info for a particular debugger"),
406  cl::values(
407  clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
408  clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
409  clEnumValN(DebuggerKind::DBX, "dbx", "dbx"),
410  clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)")));
411  CGBINDOPT(DebuggerTuningOpt);
412 
413  static cl::opt<bool> EnableStackSizeSection(
414  "stack-size-section",
415  cl::desc("Emit a section containing stack size metadata"),
416  cl::init(false));
417  CGBINDOPT(EnableStackSizeSection);
418 
419  static cl::opt<bool> EnableAddrsig(
420  "addrsig", cl::desc("Emit an address-significance table"),
421  cl::init(false));
422  CGBINDOPT(EnableAddrsig);
423 
424  static cl::opt<bool> EmitCallSiteInfo(
425  "emit-call-site-info",
426  cl::desc(
427  "Emit call site debug information, if debug information is enabled."),
428  cl::init(false));
429  CGBINDOPT(EmitCallSiteInfo);
430 
431  static cl::opt<bool> EnableDebugEntryValues(
432  "debug-entry-values",
433  cl::desc("Enable debug info for the debug entry values."),
434  cl::init(false));
435  CGBINDOPT(EnableDebugEntryValues);
436 
437  static cl::opt<bool> PseudoProbeForProfiling(
438  "pseudo-probe-for-profiling", cl::desc("Emit pseudo probes for AutoFDO"),
439  cl::init(false));
440  CGBINDOPT(PseudoProbeForProfiling);
441 
442  static cl::opt<bool> ValueTrackingVariableLocations(
443  "experimental-debug-variable-locations",
444  cl::desc("Use experimental new value-tracking variable locations"),
445  cl::init(false));
446  CGBINDOPT(ValueTrackingVariableLocations);
447 
449  "split-machine-functions",
450  cl::desc("Split out cold basic blocks from machine functions based on "
451  "profile information"),
452  cl::init(false));
454 
455  static cl::opt<bool> ForceDwarfFrameSection(
456  "force-dwarf-frame-section",
457  cl::desc("Always emit a debug frame section."), cl::init(false));
458  CGBINDOPT(ForceDwarfFrameSection);
459 
460  static cl::opt<bool> XRayOmitFunctionIndex(
461  "no-xray-index", cl::desc("Don't emit xray_fn_idx section"),
462  cl::init(false));
463  CGBINDOPT(XRayOmitFunctionIndex);
464 
465  static cl::opt<bool> DebugStrictDwarf(
466  "strict-dwarf", cl::desc("use strict dwarf"), cl::init(false));
467  CGBINDOPT(DebugStrictDwarf);
468 
469  static cl::opt<unsigned> AlignLoops("align-loops",
470  cl::desc("Default alignment for loops"));
471  CGBINDOPT(AlignLoops);
472 
473 #undef CGBINDOPT
474 
476 }
477 
480  if (getBBSections() == "all")
481  return BasicBlockSection::All;
482  else if (getBBSections() == "labels")
484  else if (getBBSections() == "none")
486  else {
489  if (!MBOrErr) {
490  errs() << "Error loading basic block sections function list file: "
491  << MBOrErr.getError().message() << "\n";
492  } else {
493  Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
494  }
496  }
497 }
498 
499 // Common utility function tightly tied to the options listed here. Initializes
500 // a TargetOptions object with CodeGen flags and returns it.
504  Options.AllowFPOpFusion = getFuseFPOps();
505  Options.UnsafeFPMath = getEnableUnsafeFPMath();
506  Options.NoInfsFPMath = getEnableNoInfsFPMath();
507  Options.NoNaNsFPMath = getEnableNoNaNsFPMath();
508  Options.NoSignedZerosFPMath = getEnableNoSignedZerosFPMath();
509  Options.NoTrappingFPMath = getEnableNoTrappingFPMath();
510 
512 
513  // FIXME: Should have separate input and output flags
514  Options.setFPDenormalMode(DenormalMode(DenormKind, DenormKind));
515 
516  Options.HonorSignDependentRoundingFPMathOption =
519  Options.FloatABIType = getFloatABIForCalls();
520  Options.EnableAIXExtendedAltivecABI = getEnableAIXExtendedAltivecABI();
521  Options.NoZerosInBSS = getDontPlaceZerosInBSS();
522  Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt();
523  Options.StackSymbolOrdering = getStackSymbolOrdering();
524  Options.UseInitArray = !getUseCtors();
525  Options.RelaxELFRelocations = getRelaxELFRelocations();
526  Options.DataSections =
528  Options.FunctionSections = getFunctionSections();
529  Options.IgnoreXCOFFVisibility = getIgnoreXCOFFVisibility();
530  Options.XCOFFTracebackTable = getXCOFFTracebackTable();
531  Options.BBSections = getBBSectionsMode(Options);
532  Options.UniqueSectionNames = getUniqueSectionNames();
533  Options.UniqueBasicBlockSectionNames = getUniqueBasicBlockSectionNames();
534  Options.TLSSize = getTLSSize();
535  Options.EmulatedTLS = getEmulatedTLS();
536  Options.ExplicitEmulatedTLS = EmulatedTLSView->getNumOccurrences() > 0;
537  Options.ExceptionModel = getExceptionModel();
538  Options.EmitStackSizeSection = getEnableStackSizeSection();
539  Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter();
540  Options.EmitAddrsig = getEnableAddrsig();
541  Options.EmitCallSiteInfo = getEmitCallSiteInfo();
542  Options.EnableDebugEntryValues = getEnableDebugEntryValues();
543  Options.PseudoProbeForProfiling = getPseudoProbeForProfiling();
544  Options.ValueTrackingVariableLocations = getValueTrackingVariableLocations();
545  Options.ForceDwarfFrameSection = getForceDwarfFrameSection();
546  Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex();
547  Options.DebugStrictDwarf = getDebugStrictDwarf();
548  Options.LoopAlignment = getAlignLoops();
549 
551 
552  Options.ThreadModel = getThreadModel();
553  Options.EABIVersion = getEABIVersion();
554  Options.DebuggerTuning = getDebuggerTuningOpt();
555  Options.SwiftAsyncFramePointer = getSwiftAsyncFramePointer();
556  return Options;
557 }
558 
559 std::string codegen::getCPUStr() {
560  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
561  // this will set the CPU to an empty string which tells the target to
562  // pick a basic default.
563  if (getMCPU() == "native")
564  return std::string(sys::getHostCPUName());
565 
566  return getMCPU();
567 }
568 
569 std::string codegen::getFeaturesStr() {
570  SubtargetFeatures Features;
571 
572  // If user asked for the 'native' CPU, we need to autodetect features.
573  // This is necessary for x86 where the CPU might not support all the
574  // features the autodetected CPU name lists in the target. For example,
575  // not all Sandybridge processors support AVX.
576  if (getMCPU() == "native") {
577  StringMap<bool> HostFeatures;
578  if (sys::getHostCPUFeatures(HostFeatures))
579  for (auto &F : HostFeatures)
580  Features.AddFeature(F.first(), F.second);
581  }
582 
583  for (auto const &MAttr : getMAttrs())
584  Features.AddFeature(MAttr);
585 
586  return Features.getString();
587 }
588 
589 std::vector<std::string> codegen::getFeatureList() {
590  SubtargetFeatures Features;
591 
592  // If user asked for the 'native' CPU, we need to autodetect features.
593  // This is necessary for x86 where the CPU might not support all the
594  // features the autodetected CPU name lists in the target. For example,
595  // not all Sandybridge processors support AVX.
596  if (getMCPU() == "native") {
597  StringMap<bool> HostFeatures;
598  if (sys::getHostCPUFeatures(HostFeatures))
599  for (auto &F : HostFeatures)
600  Features.AddFeature(F.first(), F.second);
601  }
602 
603  for (auto const &MAttr : getMAttrs())
604  Features.AddFeature(MAttr);
605 
606  return Features.getFeatures();
607 }
608 
610  B.addAttribute(Name, Val ? "true" : "false");
611 }
612 
613 #define HANDLE_BOOL_ATTR(CL, AttrName) \
614  do { \
615  if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
616  renderBoolStringAttr(NewAttrs, AttrName, *CL); \
617  } while (0)
618 
619 /// Set function attributes of function \p F based on CPU, Features, and command
620 /// line flags.
622  Function &F) {
623  auto &Ctx = F.getContext();
624  AttributeList Attrs = F.getAttributes();
625  AttrBuilder NewAttrs;
626 
627  if (!CPU.empty() && !F.hasFnAttribute("target-cpu"))
628  NewAttrs.addAttribute("target-cpu", CPU);
629  if (!Features.empty()) {
630  // Append the command line features to any that are already on the function.
631  StringRef OldFeatures =
632  F.getFnAttribute("target-features").getValueAsString();
633  if (OldFeatures.empty())
634  NewAttrs.addAttribute("target-features", Features);
635  else {
636  SmallString<256> Appended(OldFeatures);
637  Appended.push_back(',');
638  Appended.append(Features);
639  NewAttrs.addAttribute("target-features", Appended);
640  }
641  }
642  if (FramePointerUsageView->getNumOccurrences() > 0 &&
643  !F.hasFnAttribute("frame-pointer")) {
645  NewAttrs.addAttribute("frame-pointer", "all");
647  NewAttrs.addAttribute("frame-pointer", "non-leaf");
649  NewAttrs.addAttribute("frame-pointer", "none");
650  }
651  if (DisableTailCallsView->getNumOccurrences() > 0)
652  NewAttrs.addAttribute("disable-tail-calls",
654  if (getStackRealign())
655  NewAttrs.addAttribute("stackrealign");
656 
657  HANDLE_BOOL_ATTR(EnableUnsafeFPMathView, "unsafe-fp-math");
658  HANDLE_BOOL_ATTR(EnableNoInfsFPMathView, "no-infs-fp-math");
659  HANDLE_BOOL_ATTR(EnableNoNaNsFPMathView, "no-nans-fp-math");
660  HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMathView, "no-signed-zeros-fp-math");
661 
662  if (DenormalFPMathView->getNumOccurrences() > 0 &&
663  !F.hasFnAttribute("denormal-fp-math")) {
665 
666  // FIXME: Command line flag should expose separate input/output modes.
667  NewAttrs.addAttribute("denormal-fp-math",
668  DenormalMode(DenormKind, DenormKind).str());
669  }
670 
671  if (DenormalFP32MathView->getNumOccurrences() > 0 &&
672  !F.hasFnAttribute("denormal-fp-math-f32")) {
673  // FIXME: Command line flag should expose separate input/output modes.
675 
676  NewAttrs.addAttribute(
677  "denormal-fp-math-f32",
678  DenormalMode(DenormKind, DenormKind).str());
679  }
680 
681  if (TrapFuncNameView->getNumOccurrences() > 0)
682  for (auto &B : F)
683  for (auto &I : B)
684  if (auto *Call = dyn_cast<CallInst>(&I))
685  if (const auto *F = Call->getCalledFunction())
686  if (F->getIntrinsicID() == Intrinsic::debugtrap ||
687  F->getIntrinsicID() == Intrinsic::trap)
688  Call->addFnAttr(
689  Attribute::get(Ctx, "trap-func-name", getTrapFuncName()));
690 
691  // Let NewAttrs override Attrs.
692  F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
693 }
694 
695 /// Set function attributes of functions in Module M based on CPU,
696 /// Features, and command line flags.
698  Module &M) {
699  for (Function &F : M)
700  setFunctionAttributes(CPU, Features, F);
701 }
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:502
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:569
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:479
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:609
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:589
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:559
llvm::FramePointerKind::All
@ All
llvm::codegen::getUniqueBasicBlockSectionNames
bool getUniqueBasicBlockSectionNames()
HANDLE_BOOL_ATTR
#define HANDLE_BOOL_ATTR(CL, AttrName)
Definition: CommandFlags.cpp:613
llvm::codegen::getPseudoProbeForProfiling
bool getPseudoProbeForProfiling()
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:621
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:147
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