1//===-- CommandFlags.cpp - Command Line Flags Interface ---------*- C++ -*-===//
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
7//===----------------------------------------------------------------------===//
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
13//===----------------------------------------------------------------------===//
32 #define CGOPT(TY, NAME) \
33 static cl::opt<TY> *NAME##View; \
34 TY codegen::get##NAME() { \
35 assert(NAME##View && "RegisterCodeGenFlags not created."); \
39 #define CGLIST(TY, NAME) \
40 static cl::list<TY> *NAME##View; \
41 std::vector<TY> codegen::get##NAME() { \
42 assert(NAME##View && "RegisterCodeGenFlags not created."); \
46// Temporary macro for incremental transition to std::optional.
47 #define CGOPT_EXP(TY, NAME) \
49 std::optional<TY> codegen::getExplicit##NAME() { \
50 if (NAME##View->getNumOccurrences()) { \
51 TY res = *NAME##View; \
54 return std::nullopt; \
57CGOPT(std::string, MArch)
58CGOPT(std::string, MCPU)
67CGOPT(
bool, EnableNoInfsFPMath)
68CGOPT(
bool, EnableNoNaNsFPMath)
69CGOPT(
bool, EnableNoSignedZerosFPMath)
70CGOPT(
bool, EnableNoTrappingFPMath)
71CGOPT(
bool, EnableAIXExtendedAltivecABI)
74CGOPT(
bool, EnableHonorSignDependentRoundingFPMath)
78CGOPT(
bool, DontPlaceZerosInBSS)
79CGOPT(
bool, EnableGuaranteedTailCallOpt)
80CGOPT(
bool, DisableTailCalls)
81CGOPT(
bool, StackSymbolOrdering)
82CGOPT(
bool, StackRealign)
83CGOPT(std::string, TrapFuncName)
85CGOPT(
bool, DisableIntegratedAS)
88CGOPT(
bool, IgnoreXCOFFVisibility)
89CGOPT(
bool, XCOFFTracebackTable)
90CGOPT(
bool, EnableBBAddrMap)
91CGOPT(std::string, BBSections)
92CGOPT(
unsigned, TLSSize)
95CGOPT(
bool, UniqueSectionNames)
96CGOPT(
bool, UniqueBasicBlockSectionNames)
97CGOPT(
bool, SeparateNamedSections)
100CGOPT(
bool, EnableStackSizeSection)
101CGOPT(
bool, EnableAddrsig)
102CGOPT(
bool, EnableCallGraphSection)
103CGOPT(
bool, EmitCallSiteInfo)
105CGOPT(
bool, EnableStaticDataPartitioning)
106CGOPT(
bool, EnableDebugEntryValues)
107CGOPT(
bool, ForceDwarfFrameSection)
108CGOPT(
bool, XRayFunctionIndex)
109CGOPT(
bool, DebugStrictDwarf)
110CGOPT(
unsigned, AlignLoops)
111CGOPT(
bool, JMCInstrument)
112CGOPT(
bool, XCOFFReadOnlyPointers)
115#define CGBINDOPT(NAME) \
117 NAME##View = std::addressof(NAME); \
121 "march",
cl::desc(
"Architecture to generate code for (see --version)"));
125 "mcpu",
cl::desc(
"Target a specific cpu type (-mcpu=help for details)"),
131 cl::desc(
"Target specific attributes (-mattr=help for details)"),
136 "relocation-model",
cl::desc(
"Choose relocation model"),
140 "Fully relocatable, position independent code"),
142 "Relocatable external references, non-relocatable code"),
145 "Code and read-only data relocatable, accessed PC-relative"),
148 "Read-write data relocatable, accessed relative to static base"),
150 "Combination of ropi and rwpi")));
154 "thread-model",
cl::desc(
"Choose threading model"),
162 "code-model",
cl::desc(
"Choose code model"),
171 "large-data-threshold",
172 cl::desc(
"Choose large data threshold for x86_64 medium code model"),
177 "exception-model",
cl::desc(
"exception model"),
181 "default exception handling model"),
183 "DWARF-like CFI based exception handling"),
185 "SjLj exception handling"),
188 "Windows exception model"),
190 "WebAssembly exception handling")));
196 "Choose a file type (not all types are supported by all targets):"),
198 "Emit an assembly ('.s') file"),
200 "Emit a native object ('.o') file"),
202 "Emit nothing, for performance testing")));
207 cl::desc(
"Specify frame pointer elimination optimization"),
211 "Disable frame pointer elimination"),
213 "Disable frame pointer elimination for non-leaf frame"),
215 "Enable frame pointer elimination, but reserve the frame "
218 "Enable frame pointer elimination")));
222 "enable-no-infs-fp-math",
223 cl::desc(
"Enable FP math optimizations that assume no +-Infs"),
228 "enable-no-nans-fp-math",
229 cl::desc(
"Enable FP math optimizations that assume no NaNs"),
234 "enable-no-signed-zeros-fp-math",
235 cl::desc(
"Enable FP math optimizations that assume "
236 "the sign of 0 is insignificant"),
241 "enable-no-trapping-fp-math",
242 cl::desc(
"Enable setting the FP exceptions build "
243 "attribute not to use exceptions"),
247 static const auto DenormFlagEnumOptions =
cl::values(
250 "the sign of a flushed-to-zero number is preserved "
253 "denormals are flushed to positive zero"),
255 "denormals have unknown treatment"));
257 // FIXME: Doesn't have way to specify separate input and output modes.
260 cl::desc(
"Select which denormal numbers the code is permitted to require"),
262 DenormFlagEnumOptions);
266 "denormal-fp-math-f32",
267 cl::desc(
"Select which denormal numbers the code is permitted to require for float"),
269 DenormFlagEnumOptions);
273 "enable-sign-dependent-rounding-fp-math",
cl::Hidden,
274 cl::desc(
"Force codegen to assume rounding mode can change dynamically"),
276 CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
279 "float-abi",
cl::desc(
"Choose float ABI type"),
282 "Target default float ABI type"),
284 "Soft float ABI (implied by -soft-float)"),
286 "Hard float ABI (uses FP registers)")));
290 "fp-contract",
cl::desc(
"Enable aggressive formation of fused FP ops"),
294 "Fuse FP ops whenever profitable"),
297 "Only fuse FP ops when the result won't be affected.")));
302 cl::desc(
"Determine when the Swift async frame pointer should be set"),
305 "Determine based on deployment target"),
307 "Always set the bit"),
309 "Never set the bit")));
313 "nozero-initialized-in-bss",
314 cl::desc(
"Don't place zero-initialized symbols into bss section"),
319 "vec-extabi",
cl::desc(
"Enable the AIX Extended Altivec ABI."),
326 "Turn fastcc calls into tail calls by (potentially) changing ABI."),
335 "stack-symbol-ordering",
cl::desc(
"Order local stack symbols."),
341 cl::desc(
"Force align the stack to the minimum alignment"),
347 cl::desc(
"Emit a call to trap function rather than a trap instruction"),
352 cl::desc(
"Use .ctors instead of .init_array."),
357 "data-sections",
cl::desc(
"Emit data into separate sections"),
362 "function-sections",
cl::desc(
"Emit functions into separate sections"),
367 "ignore-xcoff-visibility",
368 cl::desc(
"Not emit the visibility attribute for asm in AIX OS or give "
369 "all symbols 'unspecified' visibility in XCOFF object file"),
374 "xcoff-traceback-table",
cl::desc(
"Emit the XCOFF traceback table"),
379 "basic-block-address-map",
384 "basic-block-sections",
385 cl::desc(
"Emit basic blocks into separate sections"),
399 "enable-tlsdesc",
cl::desc(
"Enable the use of TLS Descriptors"),
404 "unique-section-names",
cl::desc(
"Give unique names to every section"),
409 "unique-basic-block-section-names",
410 cl::desc(
"Give unique names to every basic block section"),
415 "separate-named-sections",
416 cl::desc(
"Use separate unique sections for named sections"),
421 "meabi",
cl::desc(
"Set EABI type (default depends on triple):"),
431 "debugger-tune",
cl::desc(
"Tune debug info for a particular debugger"),
441 "stack-size-section",
442 cl::desc(
"Emit a section containing stack size metadata"),
447 "addrsig",
cl::desc(
"Emit an address-significance table"),
452 "call-graph-section",
cl::desc(
"Emit a call graph section"),
457 "emit-call-site-info",
459 "Emit call site debug information, if debug information is enabled."),
464 "debug-entry-values",
465 cl::desc(
"Enable debug info for the debug entry values."),
470 "split-machine-functions",
471 cl::desc(
"Split out cold basic blocks from machine functions based on "
472 "profile information"),
477 "partition-static-data-sections",
478 cl::desc(
"Partition data sections using profile information."),
483 "force-dwarf-frame-section",
487 static cl::opt<bool> XRayFunctionIndex(
"xray-function-index",
488 cl::desc(
"Emit xray_fn_idx section"),
497 cl::desc(
"Default alignment for loops"));
501 "enable-jmc-instrument",
502 cl::desc(
"Instrument functions with a call to __CheckForDebuggerJustMyCode"),
508 cl::desc(
"When set to true, const objects with relocatable address "
509 "values are put into the RO data section."),
514 "no-integrated-as",
cl::desc(
"Disable integrated assembler"),
533 errs() <<
"Error loading basic block sections function list file: "
534 << MBOrErr.
getError().message() <<
"\n";
536 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
542// Common utility function tightly tied to the options listed here. Initializes
543// a TargetOptions object with CodeGen flags and returns it.
555 // FIXME: Should have separate input and output flags
558 Options.HonorSignDependentRoundingFPMathOption =
608 // If user asked for the 'native' CPU, autodetect here. If autodection fails,
609 // this will set the CPU to an empty string which tells the target to
610 // pick a basic default.
620 // If user asked for the 'native' CPU, we need to autodetect features.
621 // This is necessary for x86 where the CPU might not support all the
622 // features the autodetected CPU name lists in the target. For example,
623 // not all Sandybridge processors support AVX.
637 // If user asked for the 'native' CPU, we need to autodetect features.
638 // This is necessary for x86 where the CPU might not support all the
639 // features the autodetected CPU name lists in the target. For example,
640 // not all Sandybridge processors support AVX.
652 B.addAttribute(Name, Val ?
"true" :
"false");
655 #define HANDLE_BOOL_ATTR(CL, AttrName) \
657 if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
658 renderBoolStringAttr(NewAttrs, AttrName, *CL); \
661/// Set function attributes of function \p F based on CPU, Features, and command
665 auto &Ctx =
F.getContext();
666 AttributeList Attrs =
F.getAttributes();
667 AttrBuilder NewAttrs(Ctx);
669 if (!CPU.empty() && !
F.hasFnAttribute(
"target-cpu"))
670 NewAttrs.addAttribute(
"target-cpu", CPU);
671 if (!Features.
empty()) {
672 // Append the command line features to any that are already on the function.
674 F.getFnAttribute(
"target-features").getValueAsString();
675 if (OldFeatures.
empty())
676 NewAttrs.addAttribute(
"target-features", Features);
680 Appended.
append(Features);
681 NewAttrs.addAttribute(
"target-features", Appended);
684 if (FramePointerUsageView->getNumOccurrences() > 0 &&
685 !
F.hasFnAttribute(
"frame-pointer")) {
687 NewAttrs.addAttribute(
"frame-pointer",
"all");
689 NewAttrs.addAttribute(
"frame-pointer",
"non-leaf");
691 NewAttrs.addAttribute(
"frame-pointer",
"reserved");
693 NewAttrs.addAttribute(
"frame-pointer",
"none");
695 if (DisableTailCallsView->getNumOccurrences() > 0)
696 NewAttrs.addAttribute(
"disable-tail-calls",
699 NewAttrs.addAttribute(
"stackrealign");
705 if (DenormalFPMathView->getNumOccurrences() > 0 &&
706 !
F.hasFnAttribute(
"denormal-fp-math")) {
709 // FIXME: Command line flag should expose separate input/output modes.
710 NewAttrs.addAttribute(
"denormal-fp-math",
714 if (DenormalFP32MathView->getNumOccurrences() > 0 &&
715 !
F.hasFnAttribute(
"denormal-fp-math-f32")) {
716 // FIXME: Command line flag should expose separate input/output modes.
719 NewAttrs.addAttribute(
720 "denormal-fp-math-f32",
724 if (TrapFuncNameView->getNumOccurrences() > 0)
728 if (
const auto *
F =
Call->getCalledFunction())
729 if (
F->getIntrinsicID() == Intrinsic::debugtrap ||
730 F->getIntrinsicID() == Intrinsic::trap)
734 // Let NewAttrs override Attrs.
735 F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
738/// Set function attributes of functions in Module M based on CPU,
739/// Features, and command line flags.
749 Triple TheTriple(TargetTriple);
751 const auto *TheTarget =
762 Twine(
"could not allocate target machine for ") +
764 return std::unique_ptr<TargetMachine>(
Target);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define CGOPT_EXP(TY, NAME)
#define HANDLE_BOOL_ATTR(CL, AttrName)
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Module.h This file contains the declarations for the Module class.
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.
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
A Module instance is used to store all the information related to an LLVM module.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Manages the enabling and disabling of subtarget specific features.
const std::vector< std::string > & getFeatures() const
Returns the vector of individual subtarget features.
LLVM_ABI std::string getString() const
Returns features as a string.
LLVM_ABI void AddFeature(StringRef String, bool Enable=true)
Adds Features.
Target - Wrapper for Target specific information.
TargetMachine * createTargetMachine(const Triple &TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOptLevel OL=CodeGenOptLevel::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
Triple - Helper class for working with autoconf configuration names.
bool hasDefaultTLSDESC() const
True if the target uses TLSDESC by default.
bool hasDefaultDataSections() const
Tests whether the target uses -data-sections as default.
bool hasDefaultEmulatedTLS() const
Tests whether the target uses emulated TLS as default.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
LLVM_ABI bool getEnableMachineFunctionSplitter()
LLVM_ABI bool getEnableHonorSignDependentRoundingFPMath()
LLVM_ABI std::string getTrapFuncName()
LLVM_ABI bool getEnableDebugEntryValues()
LLVM_ABI unsigned getTLSSize()
LLVM_ABI bool getEnableGuaranteedTailCallOpt()
LLVM_ABI llvm::FPOpFusion::FPOpFusionMode getFuseFPOps()
LLVM_ABI std::optional< CodeModel::Model > getExplicitCodeModel()
LLVM_ABI bool getFunctionSections()
LLVM_ABI bool getDisableTailCalls()
LLVM_ABI std::string getCPUStr()
LLVM_ABI bool getXCOFFReadOnlyPointers()
LLVM_ABI std::string getFeaturesStr()
LLVM_ABI bool getUniqueSectionNames()
LLVM_ABI DenormalMode::DenormalModeKind getDenormalFPMath()
LLVM_ABI llvm::FloatABI::ABIType getFloatABIForCalls()
LLVM_ABI void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val)
LLVM_ABI bool getDebugStrictDwarf()
LLVM_ABI bool getForceDwarfFrameSection()
LLVM_ABI bool getStackRealign()
LLVM_ABI std::string getMCPU()
LLVM_ABI bool getJMCInstrument()
LLVM_ABI bool getEnableAddrsig()
LLVM_ABI bool getStackSymbolOrdering()
LLVM_ABI SwiftAsyncFramePointerMode getSwiftAsyncFramePointer()
LLVM_ABI bool getEnableBBAddrMap()
LLVM_ABI std::vector< std::string > getFeatureList()
LLVM_ABI bool getEnableStaticDataPartitioning()
LLVM_ABI std::string getMArch()
LLVM_ABI DenormalMode::DenormalModeKind getDenormalFP32Math()
LLVM_ABI bool getEnableNoSignedZerosFPMath()
LLVM_ABI bool getEnableStackSizeSection()
LLVM_ABI llvm::EABI getEABIVersion()
LLVM_ABI bool getEnableCallGraphSection()
LLVM_ABI bool getEnableNoTrappingFPMath()
LLVM_ABI Expected< std::unique_ptr< TargetMachine > > createTargetMachineForTriple(StringRef TargetTriple, CodeGenOptLevel OptLevel=CodeGenOptLevel::Default)
Creates a TargetMachine instance with the options defined on the command line.
LLVM_ABI bool getUniqueBasicBlockSectionNames()
LLVM_ABI FramePointerKind getFramePointerUsage()
LLVM_ABI bool getDontPlaceZerosInBSS()
LLVM_ABI bool getSeparateNamedSections()
LLVM_ABI bool getEnableNoInfsFPMath()
LLVM_ABI bool getEnableNoNaNsFPMath()
LLVM_ABI std::optional< bool > getExplicitDataSections()
LLVM_ABI ThreadModel::Model getThreadModel()
LLVM_ABI bool getXCOFFTracebackTable()
LLVM_ABI bool getIgnoreXCOFFVisibility()
LLVM_ABI bool getDisableIntegratedAS()
LLVM_ABI bool getUseCtors()
LLVM_ABI llvm::DebuggerKind getDebuggerTuningOpt()
LLVM_ABI std::vector< std::string > getMAttrs()
LLVM_ABI void setFunctionAttributes(StringRef CPU, StringRef Features, Function &F)
Set function attributes of function F based on CPU, Features, and command line flags.
LLVM_ABI llvm::BasicBlockSection getBBSectionsMode(llvm::TargetOptions &Options)
LLVM_ABI TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
LLVM_ABI std::string getBBSections()
LLVM_ABI std::optional< bool > getExplicitEnableTLSDESC()
LLVM_ABI unsigned getAlignLoops()
LLVM_ABI std::optional< Reloc::Model > getExplicitRelocModel()
LLVM_ABI bool getEnableAIXExtendedAltivecABI()
LLVM_ABI bool getXRayFunctionIndex()
LLVM_ABI llvm::ExceptionHandling getExceptionModel()
LLVM_ABI bool getEmitCallSiteInfo()
LLVM_ABI std::optional< bool > getExplicitEmulatedTLS()
LLVM_ABI MCTargetOptions InitMCTargetOptionsFromFlags()
LLVM_ABI StringMap< bool, MallocAllocator > getHostCPUFeatures()
getHostCPUFeatures - Get the LLVM names for the host CPU features.
LLVM_ABI StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
@ SjLj
setjmp/longjmp based exceptions
@ None
No exception support.
@ DwarfCFI
DWARF-like instruction based exceptions.
@ WinEH
Windows Exception Handling.
@ Wasm
WebAssembly Exception Handling.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
SwiftAsyncFramePointerMode
Indicates when and how the Swift async frame pointer bit should be set.
@ Always
Always set the bit.
@ Never
Never set the bit.
@ DeploymentBased
Determine whether to set the bit statically or dynamically based on the deployment target.
CodeGenOptLevel
Code generation optimization level.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DebuggerKind
Identify a debugger for "tuning" the debug info.
@ SCE
Tune debug info for SCE targets (e.g. PS4).
@ DBX
Tune debug info for dbx.
@ Default
No specific tuning requested.
@ GDB
Tune debug info for gdb.
@ LLDB
Tune debug info for lldb.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
Represent subnormal handling kind for floating point instruction inputs and outputs.
DenormalModeKind
Represent handled modes for denormal (aka subnormal) modes in the floating point environment.
@ PreserveSign
The sign of a flushed-to-zero number is preserved in the sign of 0.
@ PositiveZero
Denormals are flushed to positive zero.
@ Dynamic
Denormals have unknown treatment.
@ IEEE
IEEE-754 denormal numbers preserved.
static const Target * lookupTarget(StringRef TripleStr, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
LLVM_ABI RegisterCodeGenFlags()
Create this object with static storage to register mc-related command line options.