LLVM  16.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/ADT/StringExtras.h"
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/IR/Instructions.h"
19 #include "llvm/IR/Intrinsics.h"
20 #include "llvm/IR/Module.h"
24 #include "llvm/Support/Host.h"
26 
27 using namespace llvm;
28 
29 #define CGOPT(TY, NAME) \
30  static cl::opt<TY> *NAME##View; \
31  TY codegen::get##NAME() { \
32  assert(NAME##View && "RegisterCodeGenFlags not created."); \
33  return *NAME##View; \
34  }
35 
36 #define CGLIST(TY, NAME) \
37  static cl::list<TY> *NAME##View; \
38  std::vector<TY> codegen::get##NAME() { \
39  assert(NAME##View && "RegisterCodeGenFlags not created."); \
40  return *NAME##View; \
41  }
42 
43 #define CGOPT_EXP(TY, NAME) \
44  CGOPT(TY, NAME) \
45  Optional<TY> codegen::getExplicit##NAME() { \
46  if (NAME##View->getNumOccurrences()) { \
47  TY res = *NAME##View; \
48  return res; \
49  } \
50  return None; \
51  }
52 
53 CGOPT(std::string, MArch)
54 CGOPT(std::string, MCPU)
55 CGLIST(std::string, MAttrs)
56 CGOPT_EXP(Reloc::Model, RelocModel)
57 CGOPT(ThreadModel::Model, ThreadModel)
59 CGOPT(ExceptionHandling, ExceptionModel)
61 CGOPT(FramePointerKind, FramePointerUsage)
62 CGOPT(bool, EnableUnsafeFPMath)
63 CGOPT(bool, EnableNoInfsFPMath)
64 CGOPT(bool, EnableNoNaNsFPMath)
65 CGOPT(bool, EnableNoSignedZerosFPMath)
66 CGOPT(bool, EnableApproxFuncFPMath)
67 CGOPT(bool, EnableNoTrappingFPMath)
68 CGOPT(bool, EnableAIXExtendedAltivecABI)
70 CGOPT(DenormalMode::DenormalModeKind, DenormalFP32Math)
71 CGOPT(bool, EnableHonorSignDependentRoundingFPMath)
72 CGOPT(FloatABI::ABIType, FloatABIForCalls)
74 CGOPT(SwiftAsyncFramePointerMode, SwiftAsyncFramePointer)
75 CGOPT(bool, DontPlaceZerosInBSS)
76 CGOPT(bool, EnableGuaranteedTailCallOpt)
77 CGOPT(bool, DisableTailCalls)
78 CGOPT(bool, StackSymbolOrdering)
79 CGOPT(bool, StackRealign)
80 CGOPT(std::string, TrapFuncName)
81 CGOPT(bool, UseCtors)
82 CGOPT(bool, LowerGlobalDtorsViaCxaAtExit)
83 CGOPT(bool, RelaxELFRelocations)
84 CGOPT_EXP(bool, DataSections)
85 CGOPT_EXP(bool, FunctionSections)
86 CGOPT(bool, IgnoreXCOFFVisibility)
87 CGOPT(bool, XCOFFTracebackTable)
88 CGOPT(std::string, BBSections)
89 CGOPT(unsigned, TLSSize)
90 CGOPT(bool, EmulatedTLS)
91 CGOPT(bool, UniqueSectionNames)
92 CGOPT(bool, UniqueBasicBlockSectionNames)
93 CGOPT(EABI, EABIVersion)
94 CGOPT(DebuggerKind, DebuggerTuningOpt)
95 CGOPT(bool, EnableStackSizeSection)
96 CGOPT(bool, EnableAddrsig)
97 CGOPT(bool, EmitCallSiteInfo)
99 CGOPT(bool, EnableDebugEntryValues)
100 CGOPT(bool, ForceDwarfFrameSection)
101 CGOPT(bool, XRayOmitFunctionIndex)
102 CGOPT(bool, DebugStrictDwarf)
103 CGOPT(unsigned, AlignLoops)
104 CGOPT(bool, JMCInstrument)
105 
107 #define CGBINDOPT(NAME) \
108  do { \
109  NAME##View = std::addressof(NAME); \
110  } while (0)
111 
112  static cl::opt<std::string> MArch(
113  "march", cl::desc("Architecture to generate code for (see --version)"));
114  CGBINDOPT(MArch);
115 
116  static cl::opt<std::string> MCPU(
117  "mcpu", cl::desc("Target a specific cpu type (-mcpu=help for details)"),
118  cl::value_desc("cpu-name"), cl::init(""));
119  CGBINDOPT(MCPU);
120 
121  static cl::list<std::string> MAttrs(
122  "mattr", cl::CommaSeparated,
123  cl::desc("Target specific attributes (-mattr=help for details)"),
124  cl::value_desc("a1,+a2,-a3,..."));
125  CGBINDOPT(MAttrs);
126 
127  static cl::opt<Reloc::Model> RelocModel(
128  "relocation-model", cl::desc("Choose relocation model"),
129  cl::values(
130  clEnumValN(Reloc::Static, "static", "Non-relocatable code"),
131  clEnumValN(Reloc::PIC_, "pic",
132  "Fully relocatable, position independent code"),
133  clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
134  "Relocatable external references, non-relocatable code"),
135  clEnumValN(
136  Reloc::ROPI, "ropi",
137  "Code and read-only data relocatable, accessed PC-relative"),
138  clEnumValN(
139  Reloc::RWPI, "rwpi",
140  "Read-write data relocatable, accessed relative to static base"),
141  clEnumValN(Reloc::ROPI_RWPI, "ropi-rwpi",
142  "Combination of ropi and rwpi")));
143  CGBINDOPT(RelocModel);
144 
145  static cl::opt<ThreadModel::Model> ThreadModel(
146  "thread-model", cl::desc("Choose threading model"),
148  cl::values(
149  clEnumValN(ThreadModel::POSIX, "posix", "POSIX thread model"),
150  clEnumValN(ThreadModel::Single, "single", "Single thread model")));
151  CGBINDOPT(ThreadModel);
152 
154  "code-model", cl::desc("Choose code model"),
155  cl::values(clEnumValN(CodeModel::Tiny, "tiny", "Tiny code model"),
156  clEnumValN(CodeModel::Small, "small", "Small code model"),
157  clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"),
158  clEnumValN(CodeModel::Medium, "medium", "Medium code model"),
159  clEnumValN(CodeModel::Large, "large", "Large code model")));
161 
162  static cl::opt<ExceptionHandling> ExceptionModel(
163  "exception-model", cl::desc("exception model"),
165  cl::values(
167  "default exception handling model"),
169  "DWARF-like CFI based exception handling"),
171  "SjLj exception handling"),
172  clEnumValN(ExceptionHandling::ARM, "arm", "ARM EHABI exceptions"),
174  "Windows exception model"),
176  "WebAssembly exception handling")));
177  CGBINDOPT(ExceptionModel);
178 
180  "filetype", cl::init(CGFT_AssemblyFile),
181  cl::desc(
182  "Choose a file type (not all types are supported by all targets):"),
183  cl::values(
184  clEnumValN(CGFT_AssemblyFile, "asm", "Emit an assembly ('.s') file"),
186  "Emit a native object ('.o') file"),
187  clEnumValN(CGFT_Null, "null",
188  "Emit nothing, for performance testing")));
190 
191  static cl::opt<FramePointerKind> FramePointerUsage(
192  "frame-pointer",
193  cl::desc("Specify frame pointer elimination optimization"),
195  cl::values(
197  "Disable frame pointer elimination"),
199  "Disable frame pointer elimination for non-leaf frame"),
201  "Enable frame pointer elimination")));
202  CGBINDOPT(FramePointerUsage);
203 
204  static cl::opt<bool> EnableUnsafeFPMath(
205  "enable-unsafe-fp-math",
206  cl::desc("Enable optimizations that may decrease FP precision"),
207  cl::init(false));
208  CGBINDOPT(EnableUnsafeFPMath);
209 
210  static cl::opt<bool> EnableNoInfsFPMath(
211  "enable-no-infs-fp-math",
212  cl::desc("Enable FP math optimizations that assume no +-Infs"),
213  cl::init(false));
214  CGBINDOPT(EnableNoInfsFPMath);
215 
216  static cl::opt<bool> EnableNoNaNsFPMath(
217  "enable-no-nans-fp-math",
218  cl::desc("Enable FP math optimizations that assume no NaNs"),
219  cl::init(false));
220  CGBINDOPT(EnableNoNaNsFPMath);
221 
222  static cl::opt<bool> EnableNoSignedZerosFPMath(
223  "enable-no-signed-zeros-fp-math",
224  cl::desc("Enable FP math optimizations that assume "
225  "the sign of 0 is insignificant"),
226  cl::init(false));
227  CGBINDOPT(EnableNoSignedZerosFPMath);
228 
229  static cl::opt<bool> EnableApproxFuncFPMath(
230  "enable-approx-func-fp-math",
231  cl::desc("Enable FP math optimizations that assume approx func"),
232  cl::init(false));
233  CGBINDOPT(EnableApproxFuncFPMath);
234 
235  static cl::opt<bool> EnableNoTrappingFPMath(
236  "enable-no-trapping-fp-math",
237  cl::desc("Enable setting the FP exceptions build "
238  "attribute not to use exceptions"),
239  cl::init(false));
240  CGBINDOPT(EnableNoTrappingFPMath);
241 
242  static const auto DenormFlagEnumOptions =
244  "IEEE 754 denormal numbers"),
245  clEnumValN(DenormalMode::PreserveSign, "preserve-sign",
246  "the sign of a flushed-to-zero number is preserved "
247  "in the sign of 0"),
248  clEnumValN(DenormalMode::PositiveZero, "positive-zero",
249  "denormals are flushed to positive zero"));
250 
251  // FIXME: Doesn't have way to specify separate input and output modes.
252  static cl::opt<DenormalMode::DenormalModeKind> DenormalFPMath(
253  "denormal-fp-math",
254  cl::desc("Select which denormal numbers the code is permitted to require"),
256  DenormFlagEnumOptions);
257  CGBINDOPT(DenormalFPMath);
258 
259  static cl::opt<DenormalMode::DenormalModeKind> DenormalFP32Math(
260  "denormal-fp-math-f32",
261  cl::desc("Select which denormal numbers the code is permitted to require for float"),
263  DenormFlagEnumOptions);
264  CGBINDOPT(DenormalFP32Math);
265 
266  static cl::opt<bool> EnableHonorSignDependentRoundingFPMath(
267  "enable-sign-dependent-rounding-fp-math", cl::Hidden,
268  cl::desc("Force codegen to assume rounding mode can change dynamically"),
269  cl::init(false));
270  CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
271 
272  static cl::opt<FloatABI::ABIType> FloatABIForCalls(
273  "float-abi", cl::desc("Choose float ABI type"),
276  "Target default float ABI type"),
277  clEnumValN(FloatABI::Soft, "soft",
278  "Soft float ABI (implied by -soft-float)"),
279  clEnumValN(FloatABI::Hard, "hard",
280  "Hard float ABI (uses FP registers)")));
281  CGBINDOPT(FloatABIForCalls);
282 
283  static cl::opt<FPOpFusion::FPOpFusionMode> FuseFPOps(
284  "fp-contract", cl::desc("Enable aggressive formation of fused FP ops"),
286  cl::values(
288  "Fuse FP ops whenever profitable"),
289  clEnumValN(FPOpFusion::Standard, "on", "Only fuse 'blessed' FP ops."),
291  "Only fuse FP ops when the result won't be affected.")));
292  CGBINDOPT(FuseFPOps);
293 
294  static cl::opt<SwiftAsyncFramePointerMode> SwiftAsyncFramePointer(
295  "swift-async-fp",
296  cl::desc("Determine when the Swift async frame pointer should be set"),
299  "Determine based on deployment target"),
301  "Always set the bit"),
303  "Never set the bit")));
304  CGBINDOPT(SwiftAsyncFramePointer);
305 
306  static cl::opt<bool> DontPlaceZerosInBSS(
307  "nozero-initialized-in-bss",
308  cl::desc("Don't place zero-initialized symbols into bss section"),
309  cl::init(false));
310  CGBINDOPT(DontPlaceZerosInBSS);
311 
312  static cl::opt<bool> EnableAIXExtendedAltivecABI(
313  "vec-extabi", cl::desc("Enable the AIX Extended Altivec ABI."),
314  cl::init(false));
315  CGBINDOPT(EnableAIXExtendedAltivecABI);
316 
317  static cl::opt<bool> EnableGuaranteedTailCallOpt(
318  "tailcallopt",
319  cl::desc(
320  "Turn fastcc calls into tail calls by (potentially) changing ABI."),
321  cl::init(false));
322  CGBINDOPT(EnableGuaranteedTailCallOpt);
323 
324  static cl::opt<bool> DisableTailCalls(
325  "disable-tail-calls", cl::desc("Never emit tail calls"), cl::init(false));
326  CGBINDOPT(DisableTailCalls);
327 
328  static cl::opt<bool> StackSymbolOrdering(
329  "stack-symbol-ordering", cl::desc("Order local stack symbols."),
330  cl::init(true));
331  CGBINDOPT(StackSymbolOrdering);
332 
333  static cl::opt<bool> StackRealign(
334  "stackrealign",
335  cl::desc("Force align the stack to the minimum alignment"),
336  cl::init(false));
337  CGBINDOPT(StackRealign);
338 
339  static cl::opt<std::string> TrapFuncName(
340  "trap-func", cl::Hidden,
341  cl::desc("Emit a call to trap function rather than a trap instruction"),
342  cl::init(""));
343  CGBINDOPT(TrapFuncName);
344 
345  static cl::opt<bool> UseCtors("use-ctors",
346  cl::desc("Use .ctors instead of .init_array."),
347  cl::init(false));
348  CGBINDOPT(UseCtors);
349 
350  static cl::opt<bool> LowerGlobalDtorsViaCxaAtExit(
351  "lower-global-dtors-via-cxa-atexit",
352  cl::desc("Lower llvm.global_dtors (global destructors) via __cxa_atexit"),
353  cl::init(true));
354  CGBINDOPT(LowerGlobalDtorsViaCxaAtExit);
355 
356  static cl::opt<bool> RelaxELFRelocations(
357  "relax-elf-relocations",
358  cl::desc(
359  "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
360  cl::init(false));
361  CGBINDOPT(RelaxELFRelocations);
362 
363  static cl::opt<bool> DataSections(
364  "data-sections", cl::desc("Emit data into separate sections"),
365  cl::init(false));
366  CGBINDOPT(DataSections);
367 
368  static cl::opt<bool> FunctionSections(
369  "function-sections", cl::desc("Emit functions into separate sections"),
370  cl::init(false));
371  CGBINDOPT(FunctionSections);
372 
373  static cl::opt<bool> IgnoreXCOFFVisibility(
374  "ignore-xcoff-visibility",
375  cl::desc("Not emit the visibility attribute for asm in AIX OS or give "
376  "all symbols 'unspecified' visibility in XCOFF object file"),
377  cl::init(false));
378  CGBINDOPT(IgnoreXCOFFVisibility);
379 
380  static cl::opt<bool> XCOFFTracebackTable(
381  "xcoff-traceback-table", cl::desc("Emit the XCOFF traceback table"),
382  cl::init(true));
383  CGBINDOPT(XCOFFTracebackTable);
384 
385  static cl::opt<std::string> BBSections(
386  "basic-block-sections",
387  cl::desc("Emit basic blocks into separate sections"),
388  cl::value_desc("all | <function list (file)> | labels | none"),
389  cl::init("none"));
390  CGBINDOPT(BBSections);
391 
392  static cl::opt<unsigned> TLSSize(
393  "tls-size", cl::desc("Bit size of immediate TLS offsets"), cl::init(0));
394  CGBINDOPT(TLSSize);
395 
396  static cl::opt<bool> EmulatedTLS(
397  "emulated-tls", cl::desc("Use emulated TLS model"), cl::init(false));
398  CGBINDOPT(EmulatedTLS);
399 
400  static cl::opt<bool> UniqueSectionNames(
401  "unique-section-names", cl::desc("Give unique names to every section"),
402  cl::init(true));
403  CGBINDOPT(UniqueSectionNames);
404 
405  static cl::opt<bool> UniqueBasicBlockSectionNames(
406  "unique-basic-block-section-names",
407  cl::desc("Give unique names to every basic block section"),
408  cl::init(false));
409  CGBINDOPT(UniqueBasicBlockSectionNames);
410 
411  static cl::opt<EABI> EABIVersion(
412  "meabi", cl::desc("Set EABI type (default depends on triple):"),
414  cl::values(
415  clEnumValN(EABI::Default, "default", "Triple default EABI version"),
416  clEnumValN(EABI::EABI4, "4", "EABI version 4"),
417  clEnumValN(EABI::EABI5, "5", "EABI version 5"),
418  clEnumValN(EABI::GNU, "gnu", "EABI GNU")));
419  CGBINDOPT(EABIVersion);
420 
421  static cl::opt<DebuggerKind> DebuggerTuningOpt(
422  "debugger-tune", cl::desc("Tune debug info for a particular debugger"),
424  cl::values(
425  clEnumValN(DebuggerKind::GDB, "gdb", "gdb"),
426  clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"),
427  clEnumValN(DebuggerKind::DBX, "dbx", "dbx"),
428  clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)")));
429  CGBINDOPT(DebuggerTuningOpt);
430 
431  static cl::opt<bool> EnableStackSizeSection(
432  "stack-size-section",
433  cl::desc("Emit a section containing stack size metadata"),
434  cl::init(false));
435  CGBINDOPT(EnableStackSizeSection);
436 
437  static cl::opt<bool> EnableAddrsig(
438  "addrsig", cl::desc("Emit an address-significance table"),
439  cl::init(false));
440  CGBINDOPT(EnableAddrsig);
441 
442  static cl::opt<bool> EmitCallSiteInfo(
443  "emit-call-site-info",
444  cl::desc(
445  "Emit call site debug information, if debug information is enabled."),
446  cl::init(false));
447  CGBINDOPT(EmitCallSiteInfo);
448 
449  static cl::opt<bool> EnableDebugEntryValues(
450  "debug-entry-values",
451  cl::desc("Enable debug info for the debug entry values."),
452  cl::init(false));
453  CGBINDOPT(EnableDebugEntryValues);
454 
456  "split-machine-functions",
457  cl::desc("Split out cold basic blocks from machine functions based on "
458  "profile information"),
459  cl::init(false));
461 
462  static cl::opt<bool> ForceDwarfFrameSection(
463  "force-dwarf-frame-section",
464  cl::desc("Always emit a debug frame section."), cl::init(false));
465  CGBINDOPT(ForceDwarfFrameSection);
466 
467  static cl::opt<bool> XRayOmitFunctionIndex(
468  "no-xray-index", cl::desc("Don't emit xray_fn_idx section"),
469  cl::init(false));
470  CGBINDOPT(XRayOmitFunctionIndex);
471 
472  static cl::opt<bool> DebugStrictDwarf(
473  "strict-dwarf", cl::desc("use strict dwarf"), cl::init(false));
474  CGBINDOPT(DebugStrictDwarf);
475 
476  static cl::opt<unsigned> AlignLoops("align-loops",
477  cl::desc("Default alignment for loops"));
478  CGBINDOPT(AlignLoops);
479 
480  static cl::opt<bool> JMCInstrument(
481  "enable-jmc-instrument",
482  cl::desc("Instrument functions with a call to __CheckForDebuggerJustMyCode"),
483  cl::init(false));
484  CGBINDOPT(JMCInstrument);
485 
486 #undef CGBINDOPT
487 
489 }
490 
493  if (getBBSections() == "all")
494  return BasicBlockSection::All;
495  else if (getBBSections() == "labels")
497  else if (getBBSections() == "none")
499  else {
502  if (!MBOrErr) {
503  errs() << "Error loading basic block sections function list file: "
504  << MBOrErr.getError().message() << "\n";
505  } else {
506  Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
507  }
509  }
510 }
511 
512 // Common utility function tightly tied to the options listed here. Initializes
513 // a TargetOptions object with CodeGen flags and returns it.
517  Options.AllowFPOpFusion = getFuseFPOps();
518  Options.UnsafeFPMath = getEnableUnsafeFPMath();
519  Options.NoInfsFPMath = getEnableNoInfsFPMath();
520  Options.NoNaNsFPMath = getEnableNoNaNsFPMath();
521  Options.NoSignedZerosFPMath = getEnableNoSignedZerosFPMath();
522  Options.ApproxFuncFPMath = getEnableApproxFuncFPMath();
523  Options.NoTrappingFPMath = getEnableNoTrappingFPMath();
524 
526 
527  // FIXME: Should have separate input and output flags
528  Options.setFPDenormalMode(DenormalMode(DenormKind, DenormKind));
529 
530  Options.HonorSignDependentRoundingFPMathOption =
533  Options.FloatABIType = getFloatABIForCalls();
534  Options.EnableAIXExtendedAltivecABI = getEnableAIXExtendedAltivecABI();
535  Options.NoZerosInBSS = getDontPlaceZerosInBSS();
536  Options.GuaranteedTailCallOpt = getEnableGuaranteedTailCallOpt();
537  Options.StackSymbolOrdering = getStackSymbolOrdering();
538  Options.UseInitArray = !getUseCtors();
539  Options.LowerGlobalDtorsViaCxaAtExit = getLowerGlobalDtorsViaCxaAtExit();
540  Options.RelaxELFRelocations = getRelaxELFRelocations();
541  Options.DataSections =
543  Options.FunctionSections = getFunctionSections();
544  Options.IgnoreXCOFFVisibility = getIgnoreXCOFFVisibility();
545  Options.XCOFFTracebackTable = getXCOFFTracebackTable();
546  Options.BBSections = getBBSectionsMode(Options);
547  Options.UniqueSectionNames = getUniqueSectionNames();
548  Options.UniqueBasicBlockSectionNames = getUniqueBasicBlockSectionNames();
549  Options.TLSSize = getTLSSize();
550  Options.EmulatedTLS = getEmulatedTLS();
551  Options.ExplicitEmulatedTLS = EmulatedTLSView->getNumOccurrences() > 0;
552  Options.ExceptionModel = getExceptionModel();
553  Options.EmitStackSizeSection = getEnableStackSizeSection();
554  Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter();
555  Options.EmitAddrsig = getEnableAddrsig();
556  Options.EmitCallSiteInfo = getEmitCallSiteInfo();
557  Options.EnableDebugEntryValues = getEnableDebugEntryValues();
558  Options.ForceDwarfFrameSection = getForceDwarfFrameSection();
559  Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex();
560  Options.DebugStrictDwarf = getDebugStrictDwarf();
561  Options.LoopAlignment = getAlignLoops();
562  Options.JMCInstrument = getJMCInstrument();
563 
565 
566  Options.ThreadModel = getThreadModel();
567  Options.EABIVersion = getEABIVersion();
568  Options.DebuggerTuning = getDebuggerTuningOpt();
569  Options.SwiftAsyncFramePointer = getSwiftAsyncFramePointer();
570  return Options;
571 }
572 
573 std::string codegen::getCPUStr() {
574  // If user asked for the 'native' CPU, autodetect here. If autodection fails,
575  // this will set the CPU to an empty string which tells the target to
576  // pick a basic default.
577  if (getMCPU() == "native")
578  return std::string(sys::getHostCPUName());
579 
580  return getMCPU();
581 }
582 
583 std::string codegen::getFeaturesStr() {
584  SubtargetFeatures Features;
585 
586  // If user asked for the 'native' CPU, we need to autodetect features.
587  // This is necessary for x86 where the CPU might not support all the
588  // features the autodetected CPU name lists in the target. For example,
589  // not all Sandybridge processors support AVX.
590  if (getMCPU() == "native") {
591  StringMap<bool> HostFeatures;
592  if (sys::getHostCPUFeatures(HostFeatures))
593  for (auto &F : HostFeatures)
594  Features.AddFeature(F.first(), F.second);
595  }
596 
597  for (auto const &MAttr : getMAttrs())
598  Features.AddFeature(MAttr);
599 
600  return Features.getString();
601 }
602 
603 std::vector<std::string> codegen::getFeatureList() {
604  SubtargetFeatures Features;
605 
606  // If user asked for the 'native' CPU, we need to autodetect features.
607  // This is necessary for x86 where the CPU might not support all the
608  // features the autodetected CPU name lists in the target. For example,
609  // not all Sandybridge processors support AVX.
610  if (getMCPU() == "native") {
611  StringMap<bool> HostFeatures;
612  if (sys::getHostCPUFeatures(HostFeatures))
613  for (auto &F : HostFeatures)
614  Features.AddFeature(F.first(), F.second);
615  }
616 
617  for (auto const &MAttr : getMAttrs())
618  Features.AddFeature(MAttr);
619 
620  return Features.getFeatures();
621 }
622 
624  B.addAttribute(Name, Val ? "true" : "false");
625 }
626 
627 #define HANDLE_BOOL_ATTR(CL, AttrName) \
628  do { \
629  if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
630  renderBoolStringAttr(NewAttrs, AttrName, *CL); \
631  } while (0)
632 
633 /// Set function attributes of function \p F based on CPU, Features, and command
634 /// line flags.
636  Function &F) {
637  auto &Ctx = F.getContext();
638  AttributeList Attrs = F.getAttributes();
639  AttrBuilder NewAttrs(Ctx);
640 
641  if (!CPU.empty() && !F.hasFnAttribute("target-cpu"))
642  NewAttrs.addAttribute("target-cpu", CPU);
643  if (!Features.empty()) {
644  // Append the command line features to any that are already on the function.
645  StringRef OldFeatures =
646  F.getFnAttribute("target-features").getValueAsString();
647  if (OldFeatures.empty())
648  NewAttrs.addAttribute("target-features", Features);
649  else {
650  SmallString<256> Appended(OldFeatures);
651  Appended.push_back(',');
652  Appended.append(Features);
653  NewAttrs.addAttribute("target-features", Appended);
654  }
655  }
656  if (FramePointerUsageView->getNumOccurrences() > 0 &&
657  !F.hasFnAttribute("frame-pointer")) {
659  NewAttrs.addAttribute("frame-pointer", "all");
661  NewAttrs.addAttribute("frame-pointer", "non-leaf");
663  NewAttrs.addAttribute("frame-pointer", "none");
664  }
665  if (DisableTailCallsView->getNumOccurrences() > 0)
666  NewAttrs.addAttribute("disable-tail-calls",
668  if (getStackRealign())
669  NewAttrs.addAttribute("stackrealign");
670 
671  HANDLE_BOOL_ATTR(EnableUnsafeFPMathView, "unsafe-fp-math");
672  HANDLE_BOOL_ATTR(EnableNoInfsFPMathView, "no-infs-fp-math");
673  HANDLE_BOOL_ATTR(EnableNoNaNsFPMathView, "no-nans-fp-math");
674  HANDLE_BOOL_ATTR(EnableNoSignedZerosFPMathView, "no-signed-zeros-fp-math");
675  HANDLE_BOOL_ATTR(EnableApproxFuncFPMathView, "approx-func-fp-math");
676 
677  if (DenormalFPMathView->getNumOccurrences() > 0 &&
678  !F.hasFnAttribute("denormal-fp-math")) {
680 
681  // FIXME: Command line flag should expose separate input/output modes.
682  NewAttrs.addAttribute("denormal-fp-math",
683  DenormalMode(DenormKind, DenormKind).str());
684  }
685 
686  if (DenormalFP32MathView->getNumOccurrences() > 0 &&
687  !F.hasFnAttribute("denormal-fp-math-f32")) {
688  // FIXME: Command line flag should expose separate input/output modes.
690 
691  NewAttrs.addAttribute(
692  "denormal-fp-math-f32",
693  DenormalMode(DenormKind, DenormKind).str());
694  }
695 
696  if (TrapFuncNameView->getNumOccurrences() > 0)
697  for (auto &B : F)
698  for (auto &I : B)
699  if (auto *Call = dyn_cast<CallInst>(&I))
700  if (const auto *F = Call->getCalledFunction())
701  if (F->getIntrinsicID() == Intrinsic::debugtrap ||
702  F->getIntrinsicID() == Intrinsic::trap)
703  Call->addFnAttr(
704  Attribute::get(Ctx, "trap-func-name", getTrapFuncName()));
705 
706  // Let NewAttrs override Attrs.
707  F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
708 }
709 
710 /// Set function attributes of functions in Module M based on CPU,
711 /// Features, and command line flags.
713  Module &M) {
714  for (Function &F : M)
715  setFunctionAttributes(CPU, Features, F);
716 }
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: AddressRanges.h:18
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:60
llvm::codegen::getDisableTailCalls
bool getDisableTailCalls()
llvm::SubtargetFeatures::AddFeature
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
Definition: SubtargetFeature.cpp:37
llvm::Attribute::get
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:91
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:515
llvm::cl::CommaSeparated
@ CommaSeparated
Definition: CommandLine.h:166
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
MCTargetOptionsCommandFlags.h
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:140
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:430
llvm::codegen::getDenormalFPMath
DenormalMode::DenormalModeKind getDenormalFPMath()
llvm::mc::InitMCTargetOptionsFromFlags
MCTargetOptions InitMCTargetOptionsFromFlags()
Definition: MCTargetOptionsCommandFlags.cpp:125
llvm::Reloc::ROPI_RWPI
@ ROPI_RWPI
Definition: CodeGen.h:22
llvm::FPOpFusion::FPOpFusionMode
FPOpFusionMode
Definition: TargetOptions.h:36
llvm::codegen::getEnableApproxFuncFPMath
bool getEnableApproxFuncFPMath()
llvm::ExceptionHandling::ARM
@ ARM
ARM EHABI.
llvm::codegen::getLowerGlobalDtorsViaCxaAtExit
bool getLowerGlobalDtorsViaCxaAtExit()
llvm::FloatABI::Hard
@ Hard
Definition: TargetOptions.h:31
llvm::codegen::getFeaturesStr
std::string getFeaturesStr()
Definition: CommandFlags.cpp:583
llvm::codegen::getEnableMachineFunctionSplitter
bool getEnableMachineFunctionSplitter()
llvm::Triple::hasDefaultDataSections
bool hasDefaultDataSections() const
Tests whether the target uses -data-sections as default.
Definition: Triple.h:953
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:891
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()
llvm::MemoryBuffer::getFile
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, Optional< Align > Alignment=None)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Definition: MemoryBuffer.cpp:244
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::DenormalMode::Invalid
@ Invalid
Definition: FloatingPointMode.h:73
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::codegen::getBBSectionsMode
llvm::BasicBlockSection getBBSectionsMode(llvm::TargetOptions &Options)
Definition: CommandFlags.cpp:492
SubtargetFeature.h
llvm::MSP430Attrs::CodeModel
CodeModel
Definition: MSP430Attributes.h:37
llvm::ExceptionHandling
ExceptionHandling
Definition: MCTargetOptions.h:19
Intrinsics.h
llvm::codegen::getDebuggerTuningOpt
llvm::DebuggerKind getDebuggerTuningOpt()
llvm::codegen::renderBoolStringAttr
void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val)
Definition: CommandFlags.cpp:623
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:193
llvm::SubtargetFeatures
Manages the enabling and disabling of subtarget specific features.
Definition: SubtargetFeature.h:180
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:193
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:36
llvm::DenormalMode::DenormalModeKind
DenormalModeKind
Represent handled modes for denormal (aka subnormal) modes in the floating point environment.
Definition: FloatingPointMode.h:72
llvm::EABI::EABI4
@ EABI4
llvm::StringMap< bool >
llvm::SmallString< 256 >
llvm::MachO::FileType
FileType
Defines the file type this file represents.
Definition: InterfaceFile.h:53
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:1702
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
llvm::SmallString::append
void append(StringRef RHS)
Append from a StringRef.
Definition: SmallString.h:68
llvm::SubtargetFeatures::getString
std::string getString() const
Returns features as a string.
Definition: SubtargetFeature.cpp:50
llvm::cl::opt
Definition: CommandLine.h:1412
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:705
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:603
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:1038
StringExtras.h
llvm::DenormalMode
Represent subnormal handling kind for floating point instruction inputs and outputs.
Definition: FloatingPointMode.h:69
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:447
llvm::codegen::getCPUStr
std::string getCPUStr()
Definition: CommandFlags.cpp:573
llvm::FramePointerKind::All
@ All
llvm::codegen::getUniqueBasicBlockSectionNames
bool getUniqueBasicBlockSectionNames()
HANDLE_BOOL_ATTR
#define HANDLE_BOOL_ATTR(CL, AttrName)
Definition: CommandFlags.cpp:627
CGOPT_EXP
#define CGOPT_EXP(TY, NAME)
Definition: CommandFlags.cpp:43
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:76
llvm::Reloc::DynamicNoPIC
@ DynamicNoPIC
Definition: CodeGen.h:22
Triple.h
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:50
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:680
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:82
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:635
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:54
llvm::codegen::getRelaxELFRelocations
bool getRelaxELFRelocations()
llvm::codegen::getUniqueSectionNames
bool getUniqueSectionNames()
llvm::FPOpFusion::Strict
@ Strict
Definition: TargetOptions.h:39
CGOPT
#define CGOPT(TY, NAME)
Definition: CommandFlags.cpp:29
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
Instructions.h
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:1563
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:79
llvm::FramePointerKind::None
@ None
llvm::cl::desc
Definition: CommandLine.h:413
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.
llvm::Optional::value_or
constexpr T value_or(U &&alt) const &
Definition: Optional.h:291
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:149
llvm::SwiftAsyncFramePointerMode::Always
@ Always
Always set the bit.
llvm::codegen::getBBSections
std::string getBBSections()
llvm::codegen::getFramePointerUsage
FramePointerKind getFramePointerUsage()
llvm::codegen::getJMCInstrument
bool getJMCInstrument()
llvm::cl::list
Definition: CommandLine.h:1648