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)
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, ForceDwarfFrameSection)
94 CGOPT(bool, XRayOmitFunctionIndex)
95 CGOPT(bool, DebugStrictDwarf)
96 CGOPT(unsigned, AlignLoops)
97 
99 #define CGBINDOPT(NAME) \
100  do { \
101  NAME##View = std::addressof(NAME); \
102  } while (0)
103 
104  static cl::opt<std::string> MArch(
105  "march", cl::desc("Architecture to generate code for (see --version)"));
106  CGBINDOPT(MArch);
107 
108  static cl::opt<std::string> MCPU(
109  "mcpu", cl::desc("Target a specific cpu type (-mcpu=help for details)"),
110  cl::value_desc("cpu-name"), cl::init(""));
111  CGBINDOPT(MCPU);
112 
113  static cl::list<std::string> MAttrs(
114  "mattr", cl::CommaSeparated,
115  cl::desc("Target specific attributes (-mattr=help for details)"),
116  cl::value_desc("a1,+a2,-a3,..."));
117  CGBINDOPT(MAttrs);
118 
119  static cl::opt<Reloc::Model> RelocModel(
120  "relocation-model", cl::desc("Choose relocation model"),
121  cl::values(
122  clEnumValN(Reloc::Static, "static", "Non-relocatable code"),
123  clEnumValN(Reloc::PIC_, "pic",
124  "Fully relocatable, position independent code"),
125  clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
126  "Relocatable external references, non-relocatable code"),
127  clEnumValN(
128  Reloc::ROPI, "ropi",
129  "Code and read-only data relocatable, accessed PC-relative"),
130  clEnumValN(
131  Reloc::RWPI, "rwpi",
132  "Read-write data relocatable, accessed relative to static base"),
133  clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
134  "Combination of ropi and rwpi")));
135  CGBINDOPT(RelocModel);
136 
137  static cl::opt<ThreadModel::Model> ThreadModel(
138  "thread-model", cl::desc("Choose threading model"),
140  cl::values(
141  clEnumValN(ThreadModel::POSIX, "posix", "POSIX thread model"),
142  clEnumValN(ThreadModel::Single, "single", "Single thread model")));
143  CGBINDOPT(ThreadModel);
144 
146  "code-model", cl::desc("Choose code model"),
147  cl::values(clEnumValN(CodeModel::Tiny, "tiny", "Tiny code model"),
148  clEnumValN(CodeModel::Small, "small", "Small code model"),
149  clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"),
150  clEnumValN(CodeModel::Medium, "medium", "Medium code model"),
151  clEnumValN(CodeModel::Large, "large", "Large code model")));
153 
154  static cl::opt<ExceptionHandling> ExceptionModel(
155  "exception-model", cl::desc("exception model"),
157  cl::values(
159  "default exception handling model"),
161  "DWARF-like CFI based exception handling"),
163  "SjLj exception handling"),
164  clEnumValN(ExceptionHandling::ARM, "arm", "ARM EHABI exceptions"),
166  "Windows exception model"),
168  "WebAssembly exception handling")));
169  CGBINDOPT(ExceptionModel);
170 
172  "filetype", cl::init(CGFT_AssemblyFile),
173  cl::desc(
174  "Choose a file type (not all types are supported by all targets):"),
175  cl::values(
176  clEnumValN(CGFT_AssemblyFile, "asm", "Emit an assembly ('.s') file"),
178  "Emit a native object ('.o') file"),
179  clEnumValN(CGFT_Null, "null",
180  "Emit nothing, for performance testing")));
182 
183  static cl::opt<FramePointerKind> FramePointerUsage(
184  "frame-pointer",
185  cl::desc("Specify frame pointer elimination optimization"),
187  cl::values(
189  "Disable frame pointer elimination"),
191  "Disable frame pointer elimination for non-leaf frame"),
193  "Enable frame pointer elimination")));
194  CGBINDOPT(FramePointerUsage);
195 
196  static cl::opt<bool> EnableUnsafeFPMath(
197  "enable-unsafe-fp-math",
198  cl::desc("Enable optimizations that may decrease FP precision"),
199  cl::init(false));
200  CGBINDOPT(EnableUnsafeFPMath);
201 
202  static cl::opt<bool> EnableNoInfsFPMath(
203  "enable-no-infs-fp-math",
204  cl::desc("Enable FP math optimizations that assume no +-Infs"),
205  cl::init(false));
206  CGBINDOPT(EnableNoInfsFPMath);
207 
208  static cl::opt<bool> EnableNoNaNsFPMath(
209  "enable-no-nans-fp-math",
210  cl::desc("Enable FP math optimizations that assume no NaNs"),
211  cl::init(false));
212  CGBINDOPT(EnableNoNaNsFPMath);
213 
214  static cl::opt<bool> EnableNoSignedZerosFPMath(
215  "enable-no-signed-zeros-fp-math",
216  cl::desc("Enable FP math optimizations that assume "
217  "the sign of 0 is insignificant"),
218  cl::init(false));
219  CGBINDOPT(EnableNoSignedZerosFPMath);
220 
221  static cl::opt<bool> EnableNoTrappingFPMath(
222  "enable-no-trapping-fp-math",
223  cl::desc("Enable setting the FP exceptions build "
224  "attribute not to use exceptions"),
225  cl::init(false));
226  CGBINDOPT(EnableNoTrappingFPMath);
227 
228  static const auto DenormFlagEnumOptions =
230  "IEEE 754 denormal numbers"),
231  clEnumValN(DenormalMode::PreserveSign, "preserve-sign",
232  "the sign of a flushed-to-zero number is preserved "
233  "in the sign of 0"),
234  clEnumValN(DenormalMode::PositiveZero, "positive-zero",
235  "denormals are flushed to positive zero"));
236 
237  // FIXME: Doesn't have way to specify separate input and output modes.
238  static cl::opt<DenormalMode::DenormalModeKind> DenormalFPMath(
239  "denormal-fp-math",
240  cl::desc("Select which denormal numbers the code is permitted to require"),
242  DenormFlagEnumOptions);
243  CGBINDOPT(DenormalFPMath);
244 
245  static cl::opt<DenormalMode::DenormalModeKind> DenormalFP32Math(
246  "denormal-fp-math-f32",
247  cl::desc("Select which denormal numbers the code is permitted to require for float"),
249  DenormFlagEnumOptions);
250  CGBINDOPT(DenormalFP32Math);
251 
252  static cl::opt<bool> EnableHonorSignDependentRoundingFPMath(
253  "enable-sign-dependent-rounding-fp-math", cl::Hidden,
254  cl::desc("Force codegen to assume rounding mode can change dynamically"),
255  cl::init(false));
256  CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
257 
258  static cl::opt<FloatABI::ABIType> FloatABIForCalls(
259  "float-abi", cl::desc("Choose float ABI type"),
262  "Target default float ABI type"),
263  clEnumValN(FloatABI::Soft, "soft",
264  "Soft float ABI (implied by -soft-float)"),
265  clEnumValN(FloatABI::Hard, "hard",
266  "Hard float ABI (uses FP registers)")));
267  CGBINDOPT(FloatABIForCalls);
268 
269  static cl::opt<FPOpFusion::FPOpFusionMode> FuseFPOps(
270  "fp-contract", cl::desc("Enable aggressive formation of fused FP ops"),
272  cl::values(
274  "Fuse FP ops whenever profitable"),
275  clEnumValN(FPOpFusion::Standard, "on", "Only fuse 'blessed' FP ops."),
277  "Only fuse FP ops when the result won't be affected.")));
278  CGBINDOPT(FuseFPOps);
279 
280  static cl::opt<SwiftAsyncFramePointerMode> SwiftAsyncFramePointer(
281  "swift-async-fp",
282  cl::desc("Determine when the Swift async frame pointer should be set"),
285  "Determine based on deployment target"),
287  "Always set the bit"),
289  "Never set the bit")));
290  CGBINDOPT(SwiftAsyncFramePointer);
291 
292  static cl::opt<bool> DontPlaceZerosInBSS(
293  "nozero-initialized-in-bss",
294  cl::desc("Don't place zero-initialized symbols into bss section"),
295  cl::init(false));
296  CGBINDOPT(DontPlaceZerosInBSS);
297 
298  static cl::opt<bool> EnableAIXExtendedAltivecABI(
299  "vec-extabi", cl::desc("Enable the AIX Extended Altivec ABI."),
300  cl::init(false));
301  CGBINDOPT(EnableAIXExtendedAltivecABI);
302 
303  static cl::opt<bool> EnableGuaranteedTailCallOpt(
304  "tailcallopt",
305  cl::desc(
306  "Turn fastcc calls into tail calls by (potentially) changing ABI."),
307  cl::init(false));
308  CGBINDOPT(EnableGuaranteedTailCallOpt);
309 
310  static cl::opt<bool> DisableTailCalls(
311  "disable-tail-calls", cl::desc("Never emit tail calls"), cl::init(false));
312  CGBINDOPT(DisableTailCalls);
313 
314  static cl::opt<bool> StackSymbolOrdering(
315  "stack-symbol-ordering", cl::desc("Order local stack symbols."),
316  cl::init(true));
317  CGBINDOPT(StackSymbolOrdering);
318 
319  static cl::opt<bool> StackRealign(
320  "stackrealign",
321  cl::desc("Force align the stack to the minimum alignment"),
322  cl::init(false));
323  CGBINDOPT(StackRealign);
324 
325  static cl::opt<std::string> TrapFuncName(
326  "trap-func", cl::Hidden,
327  cl::desc("Emit a call to trap function rather than a trap instruction"),
328  cl::init(""));
329  CGBINDOPT(TrapFuncName);
330 
331  static cl::opt<bool> UseCtors("use-ctors",
332  cl::desc("Use .ctors instead of .init_array."),
333  cl::init(false));
334  CGBINDOPT(UseCtors);
335 
336  static cl::opt<bool> RelaxELFRelocations(
337  "relax-elf-relocations",
338  cl::desc(
339  "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
340  cl::init(false));
341  CGBINDOPT(RelaxELFRelocations);
342 
343  static cl::opt<bool> DataSections(
344  "data-sections", cl::desc("Emit data into separate sections"),
345  cl::init(false));
346  CGBINDOPT(DataSections);
347 
348  static cl::opt<bool> FunctionSections(
349  "function-sections", cl::desc("Emit functions into separate sections"),
350  cl::init(false));
351  CGBINDOPT(FunctionSections);
352 
353  static cl::opt<bool> IgnoreXCOFFVisibility(
354  "ignore-xcoff-visibility",
355  cl::desc("Not emit the visibility attribute for asm in AIX OS or give "
356  "all symbols 'unspecified' visibility in XCOFF object file"),
357  cl::init(false));
358  CGBINDOPT(IgnoreXCOFFVisibility);
359 
360  static cl::opt<bool> XCOFFTracebackTable(
361  "xcoff-traceback-table", cl::desc("Emit the XCOFF traceback table"),
362  cl::init(true));
363  CGBINDOPT(XCOFFTracebackTable);
364 
365  static cl::opt<std::string> BBSections(
366  "basic-block-sections",
367  cl::desc("Emit basic blocks into separate sections"),
368  cl::value_desc("all | <function list (file)> | labels | none"),
369  cl::init("none"));
370  CGBINDOPT(BBSections);
371 
372  static cl::opt<unsigned> TLSSize(
373  "tls-size", cl::desc("Bit size of immediate TLS offsets"), cl::init(0));
374  CGBINDOPT(TLSSize);
375 
376  static cl::opt<bool> EmulatedTLS(
377  "emulated-tls", cl::desc("Use emulated TLS model"), cl::init(false));
378  CGBINDOPT(EmulatedTLS);
379 
380  static cl::opt<bool> UniqueSectionNames(
381  "unique-section-names", cl::desc("Give unique names to every section"),
382  cl::init(true));
383  CGBINDOPT(UniqueSectionNames);
384 
385  static cl::opt<bool> UniqueBasicBlockSectionNames(
386  "unique-basic-block-section-names",
387  cl::desc("Give unique names to every basic block section"),
388  cl::init(false));
389  CGBINDOPT(UniqueBasicBlockSectionNames);
390 
391  static cl::opt<EABI> EABIVersion(
392  "meabi", cl::desc("Set EABI type (default depends on triple):"),
394  cl::values(
395  clEnumValN(EABI::Default, "default", "Triple default EABI version"),
396  clEnumValN(EABI::EABI4, "4", "EABI version 4"),
397  clEnumValN(EABI::EABI5, "5", "EABI version 5"),
398  clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
399  CGBINDOPT(EABIVersion);
400 
401  static cl::opt<DebuggerKind> DebuggerTuningOpt(
402  "debugger-tune", cl::desc("Tune debug info for a particular debugger"),
404  cl::values(
405  clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
406  clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
407  clEnumValN(DebuggerKind::DBX, "dbx", "dbx"),
408  clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)")));
409  CGBINDOPT(DebuggerTuningOpt);
410 
411  static cl::opt<bool> EnableStackSizeSection(
412  "stack-size-section",
413  cl::desc("Emit a section containing stack size metadata"),
414  cl::init(false));
415  CGBINDOPT(EnableStackSizeSection);
416 
417  static cl::opt<bool> EnableAddrsig(
418  "addrsig", cl::desc("Emit an address-significance table"),
419  cl::init(false));
420  CGBINDOPT(EnableAddrsig);
421 
422  static cl::opt<bool> EmitCallSiteInfo(
423  "emit-call-site-info",
424  cl::desc(
425  "Emit call site debug information, if debug information is enabled."),
426  cl::init(false));
427  CGBINDOPT(EmitCallSiteInfo);
428 
429  static cl::opt<bool> EnableDebugEntryValues(
430  "debug-entry-values",
431  cl::desc("Enable debug info for the debug entry values."),
432  cl::init(false));
433  CGBINDOPT(EnableDebugEntryValues);
434 
436  "split-machine-functions",
437  cl::desc("Split out cold basic blocks from machine functions based on "
438  "profile information"),
439  cl::init(false));
441 
442  static cl::opt<bool> ForceDwarfFrameSection(
443  "force-dwarf-frame-section",
444  cl::desc("Always emit a debug frame section."), cl::init(false));
445  CGBINDOPT(ForceDwarfFrameSection);
446 
447  static cl::opt<bool> XRayOmitFunctionIndex(
448  "no-xray-index", cl::desc("Don't emit xray_fn_idx section"),
449  cl::init(false));
450  CGBINDOPT(XRayOmitFunctionIndex);
451 
452  static cl::opt<bool> DebugStrictDwarf(
453  "strict-dwarf", cl::desc("use strict dwarf"), cl::init(false));
454  CGBINDOPT(DebugStrictDwarf);
455 
456  static cl::opt<unsigned> AlignLoops("align-loops",
457  cl::desc("Default alignment for loops"));
458  CGBINDOPT(AlignLoops);
459 
460 #undef CGBINDOPT
461 
463 }
464 
467  if (getBBSections() == "all")
468  return BasicBlockSection::All;
469  else if (getBBSections() == "labels")
471  else if (getBBSections() == "none")
473  else {
476  if (!MBOrErr) {
477  errs() << "Error loading basic block sections function list file: "
478  << MBOrErr.getError().message() << "\n";
479  } else {
480  Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
481  }
483  }
484 }
485 
486 // Common utility function tightly tied to the options listed here. Initializes
487 // a TargetOptions object with CodeGen flags and returns it.
491  Options.AllowFPOpFusion = getFuseFPOps();
492  Options.UnsafeFPMath = getEnableUnsafeFPMath();
493  Options.NoInfsFPMath = getEnableNoInfsFPMath();
494  Options.NoNaNsFPMath = getEnableNoNaNsFPMath();
495  Options.NoSignedZerosFPMath = getEnableNoSignedZerosFPMath();
496  Options.NoTrappingFPMath = getEnableNoTrappingFPMath();
497 
499 
500  // FIXME: Should have separate input and output flags
501  Options.setFPDenormalMode(DenormalMode(DenormKind, DenormKind));
502 
503  Options.HonorSignDependentRoundingFPMathOption =
506  Options.FloatABIType = getFloatABIForCalls();
507  Options.EnableAIXExtendedAltivecABI = getEnableAIXExtendedAltivecABI();
508  Options.NoZerosInBSS = getDontPlaceZerosInBSS();
509  Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt();
510  Options.StackSymbolOrdering = getStackSymbolOrdering();
511  Options.UseInitArray = !getUseCtors();
512  Options.RelaxELFRelocations = getRelaxELFRelocations();
513  Options.DataSections =
515  Options.FunctionSections = getFunctionSections();
516  Options.IgnoreXCOFFVisibility = getIgnoreXCOFFVisibility();
517  Options.XCOFFTracebackTable = getXCOFFTracebackTable();
518  Options.BBSections = getBBSectionsMode(Options);
519  Options.UniqueSectionNames = getUniqueSectionNames();
520  Options.UniqueBasicBlockSectionNames = getUniqueBasicBlockSectionNames();
521  Options.TLSSize = getTLSSize();
522  Options.EmulatedTLS = getEmulatedTLS();
523  Options.ExplicitEmulatedTLS = EmulatedTLSView->getNumOccurrences() > 0;
524  Options.ExceptionModel = getExceptionModel();
525  Options.EmitStackSizeSection = getEnableStackSizeSection();
526  Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter();
527  Options.EmitAddrsig = getEnableAddrsig();
528  Options.EmitCallSiteInfo = getEmitCallSiteInfo();
529  Options.EnableDebugEntryValues = getEnableDebugEntryValues();
530  Options.ForceDwarfFrameSection = getForceDwarfFrameSection();
531  Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex();
532  Options.DebugStrictDwarf = getDebugStrictDwarf();
533  Options.LoopAlignment = getAlignLoops();
534 
536 
537  Options.ThreadModel = getThreadModel();
538  Options.EABIVersion = getEABIVersion();
539  Options.DebuggerTuning = getDebuggerTuningOpt();
540  Options.SwiftAsyncFramePointer = getSwiftAsyncFramePointer();
541  return Options;
542 }
543 
544 std::string codegen::getCPUStr() {
545  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
546  // this will set the CPU to an empty string which tells the target to
547  // pick a basic default.
548  if (getMCPU() == "native")
549  return std::string(sys::getHostCPUName());
550 
551  return getMCPU();
552 }
553 
554 std::string codegen::getFeaturesStr() {
555  SubtargetFeatures Features;
556 
557  // If user asked for the 'native' CPU, we need to autodetect features.
558  // This is necessary for x86 where the CPU might not support all the
559  // features the autodetected CPU name lists in the target. For example,
560  // not all Sandybridge processors support AVX.
561  if (getMCPU() == "native") {
562  StringMap<bool> HostFeatures;
563  if (sys::getHostCPUFeatures(HostFeatures))
564  for (auto &F : HostFeatures)
565  Features.AddFeature(F.first(), F.second);
566  }
567 
568  for (auto const &MAttr : getMAttrs())
569  Features.AddFeature(MAttr);
570 
571  return Features.getString();
572 }
573 
574 std::vector<std::string> codegen::getFeatureList() {
575  SubtargetFeatures Features;
576 
577  // If user asked for the 'native' CPU, we need to autodetect features.
578  // This is necessary for x86 where the CPU might not support all the
579  // features the autodetected CPU name lists in the target. For example,
580  // not all Sandybridge processors support AVX.
581  if (getMCPU() == "native") {
582  StringMap<bool> HostFeatures;
583  if (sys::getHostCPUFeatures(HostFeatures))
584  for (auto &F : HostFeatures)
585  Features.AddFeature(F.first(), F.second);
586  }
587 
588  for (auto const &MAttr : getMAttrs())
589  Features.AddFeature(MAttr);
590 
591  return Features.getFeatures();
592 }
593 
595  B.addAttribute(Name, Val ? "true" : "false");
596 }
597 
598 #define HANDLE_BOOL_ATTR(CL, AttrName) \
599  do { \
600  if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
601  renderBoolStringAttr(NewAttrs, AttrName, *CL); \
602  } while (0)
603 
604 /// Set function attributes of function \p F based on CPU, Features, and command
605 /// line flags.
607  Function &F) {
608  auto &Ctx = F.getContext();
609  AttributeList Attrs = F.getAttributes();
610  AttrBuilder NewAttrs(Ctx);
611 
612  if (!CPU.empty() && !F.hasFnAttribute("target-cpu"))
613  NewAttrs.addAttribute("target-cpu", CPU);
614  if (!Features.empty()) {
615  // Append the command line features to any that are already on the function.
616  StringRef OldFeatures =
617  F.getFnAttribute("target-features").getValueAsString();
618  if (OldFeatures.empty())
619  NewAttrs.addAttribute("target-features", Features);
620  else {
621  SmallString<256> Appended(OldFeatures);
622  Appended.push_back(',');
623  Appended.append(Features);
624  NewAttrs.addAttribute("target-features", Appended);
625  }
626  }
627  if (FramePointerUsageView->getNumOccurrences() > 0 &&
628  !F.hasFnAttribute("frame-pointer")) {
630  NewAttrs.addAttribute("frame-pointer", "all");
632  NewAttrs.addAttribute("frame-pointer", "non-leaf");
634  NewAttrs.addAttribute("frame-pointer", "none");
635  }
636  if (DisableTailCallsView->getNumOccurrences() > 0)
637  NewAttrs.addAttribute("disable-tail-calls",
639  if (getStackRealign())
640  NewAttrs.addAttribute("stackrealign");
641 
642  HANDLE_BOOL_ATTR(EnableUnsafeFPMathView, "unsafe-fp-math");
643  HANDLE_BOOL_ATTR(EnableNoInfsFPMathView, "no-infs-fp-math");
644  HANDLE_BOOL_ATTR(EnableNoNaNsFPMathView, "no-nans-fp-math");
645  HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMathView, "no-signed-zeros-fp-math");
646 
647  if (DenormalFPMathView->getNumOccurrences() > 0 &&
648  !F.hasFnAttribute("denormal-fp-math")) {
650 
651  // FIXME: Command line flag should expose separate input/output modes.
652  NewAttrs.addAttribute("denormal-fp-math",
653  DenormalMode(DenormKind, DenormKind).str());
654  }
655 
656  if (DenormalFP32MathView->getNumOccurrences() > 0 &&
657  !F.hasFnAttribute("denormal-fp-math-f32")) {
658  // FIXME: Command line flag should expose separate input/output modes.
660 
661  NewAttrs.addAttribute(
662  "denormal-fp-math-f32",
663  DenormalMode(DenormKind, DenormKind).str());
664  }
665 
666  if (TrapFuncNameView->getNumOccurrences() > 0)
667  for (auto &B : F)
668  for (auto &I : B)
669  if (auto *Call = dyn_cast<CallInst>(&I))
670  if (const auto *F = Call->getCalledFunction())
671  if (F->getIntrinsicID() == Intrinsic::debugtrap ||
672  F->getIntrinsicID() == Intrinsic::trap)
673  Call->addFnAttr(
674  Attribute::get(Ctx, "trap-func-name", getTrapFuncName()));
675 
676  // Let NewAttrs override Attrs.
677  F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
678 }
679 
680 /// Set function attributes of functions in Module M based on CPU,
681 /// Features, and command line flags.
683  Module &M) {
684  for (Function &F : M)
685  setFunctionAttributes(CPU, Features, F);
686 }
687 
llvm::codegen::getDenormalFP32Math
DenormalMode::DenormalModeKind getDenormalFP32Math()
MemoryBuffer.h
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm
This is an optimization pass for GlobalISel generic memory operations.
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::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:62
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:95
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:489
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:44
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:403
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:554
llvm::codegen::getEnableMachineFunctionSplitter
bool getEnableMachineFunctionSplitter()
llvm::Triple::hasDefaultDataSections
bool hasDefaultDataSections() const
Tests whether the target uses -data-sections as default.
Definition: Triple.h:826
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:893
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:55
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:236
llvm::codegen::getBBSectionsMode
llvm::BasicBlockSection getBBSectionsMode(llvm::TargetOptions &Options)
Definition: CommandFlags.cpp:466
SubtargetFeature.h
llvm::MSP430Attrs::CodeModel
CodeModel
Definition: MSP430Attributes.h:37
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:594
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:191
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::AttrBuilder::addAttribute
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
Definition: Attributes.cpp:1572
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:1432
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:697
llvm::codegen::getIgnoreXCOFFVisibility
bool getIgnoreXCOFFVisibility()
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:152
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:574
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:58
llvm::AttrBuilder
Definition: Attributes.h:997
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:441
llvm::codegen::getCPUStr
std::string getCPUStr()
Definition: CommandFlags.cpp:544
llvm::FramePointerKind::All
@ All
llvm::codegen::getUniqueBasicBlockSectionNames
bool getUniqueBasicBlockSectionNames()
HANDLE_BOOL_ATTR
#define HANDLE_BOOL_ATTR(CL, AttrName)
Definition: CommandFlags.cpp:598
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:65
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:57
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:672
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:606
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:50
llvm::codegen::getUniqueSectionNames
bool getUniqueSectionNames()
llvm::FPOpFusion::Strict
@ Strict
Definition: TargetOptions.h:39
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:422
llvm::ExceptionHandling::None
@ None
No exception support.
llvm::FPOpFusion::Fast
@ Fast
Definition: TargetOptions.h:37
llvm::CodeModel::Large
@ Large
Definition: CodeGen.h:28
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:1371
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:412
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:145
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:1641