30#define CGOPT(TY, NAME) \
31 static cl::opt<TY> *NAME##View; \
32 TY codegen::get##NAME() { \
33 assert(NAME##View && "RegisterCodeGenFlags not created."); \
37#define CGLIST(TY, NAME) \
38 static cl::list<TY> *NAME##View; \
39 std::vector<TY> codegen::get##NAME() { \
40 assert(NAME##View && "RegisterCodeGenFlags not created."); \
45#define CGOPT_EXP(TY, NAME) \
47 std::optional<TY> codegen::getExplicit##NAME() { \
48 if (NAME##View->getNumOccurrences()) { \
49 TY res = *NAME##View; \
52 return std::nullopt; \
55CGOPT(std::string, MArch)
56CGOPT(std::string, MCPU)
65CGOPT(
bool, EnableUnsafeFPMath)
66CGOPT(
bool, EnableNoInfsFPMath)
67CGOPT(
bool, EnableNoNaNsFPMath)
68CGOPT(
bool, EnableNoSignedZerosFPMath)
69CGOPT(
bool, EnableApproxFuncFPMath)
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)
86CGOPT(
bool, RelaxELFRelocations)
89CGOPT(
bool, IgnoreXCOFFVisibility)
90CGOPT(
bool, XCOFFTracebackTable)
91CGOPT(std::string, BBSections)
92CGOPT(
unsigned, TLSSize)
94CGOPT(
bool, UniqueSectionNames)
95CGOPT(
bool, UniqueBasicBlockSectionNames)
98CGOPT(
bool, EnableStackSizeSection)
99CGOPT(
bool, EnableAddrsig)
100CGOPT(
bool, EmitCallSiteInfo)
102CGOPT(
bool, EnableDebugEntryValues)
103CGOPT(
bool, ForceDwarfFrameSection)
104CGOPT(
bool, XRayFunctionIndex)
105CGOPT(
bool, DebugStrictDwarf)
106CGOPT(
unsigned, AlignLoops)
107CGOPT(
bool, JMCInstrument)
108CGOPT(
bool, XCOFFReadOnlyPointers)
111#define CGBINDOPT(NAME) \
113 NAME##View = std::addressof(NAME); \
117 "march",
cl::desc(
"Architecture to generate code for (see --version)"));
121 "mcpu",
cl::desc(
"Target a specific cpu type (-mcpu=help for details)"),
127 cl::desc(
"Target specific attributes (-mattr=help for details)"),
132 "relocation-model",
cl::desc(
"Choose relocation model"),
136 "Fully relocatable, position independent code"),
138 "Relocatable external references, non-relocatable code"),
141 "Code and read-only data relocatable, accessed PC-relative"),
144 "Read-write data relocatable, accessed relative to static base"),
146 "Combination of ropi and rwpi")));
150 "thread-model",
cl::desc(
"Choose threading model"),
158 "code-model",
cl::desc(
"Choose code model"),
167 "large-data-threshold",
168 cl::desc(
"Choose large data threshold for x86_64 medium code model"),
173 "exception-model",
cl::desc(
"exception model"),
176 clEnumValN(ExceptionHandling::None,
"default",
177 "default exception handling model"),
178 clEnumValN(ExceptionHandling::DwarfCFI,
"dwarf",
179 "DWARF-like CFI based exception handling"),
181 "SjLj exception handling"),
182 clEnumValN(ExceptionHandling::ARM,
"arm",
"ARM EHABI exceptions"),
184 "Windows exception model"),
186 "WebAssembly exception handling")));
190 "filetype",
cl::init(CodeGenFileType::AssemblyFile),
192 "Choose a file type (not all types are supported by all targets):"),
194 "Emit an assembly ('.s') file"),
195 clEnumValN(CodeGenFileType::ObjectFile,
"obj",
196 "Emit a native object ('.o') file"),
198 "Emit nothing, for performance testing")));
203 cl::desc(
"Specify frame pointer elimination optimization"),
207 "Disable frame pointer elimination"),
208 clEnumValN(FramePointerKind::NonLeaf,
"non-leaf",
209 "Disable frame pointer elimination for non-leaf frame"),
211 "Enable frame pointer elimination")));
215 "enable-unsafe-fp-math",
216 cl::desc(
"Enable optimizations that may decrease FP precision"),
221 "enable-no-infs-fp-math",
222 cl::desc(
"Enable FP math optimizations that assume no +-Infs"),
227 "enable-no-nans-fp-math",
228 cl::desc(
"Enable FP math optimizations that assume no NaNs"),
233 "enable-no-signed-zeros-fp-math",
234 cl::desc(
"Enable FP math optimizations that assume "
235 "the sign of 0 is insignificant"),
240 "enable-approx-func-fp-math",
241 cl::desc(
"Enable FP math optimizations that assume approx func"),
246 "enable-no-trapping-fp-math",
247 cl::desc(
"Enable setting the FP exceptions build "
248 "attribute not to use exceptions"),
252 static const auto DenormFlagEnumOptions =
cl::values(
255 "the sign of a flushed-to-zero number is preserved "
258 "denormals are flushed to positive zero"),
260 "denormals have unknown treatment"));
265 cl::desc(
"Select which denormal numbers the code is permitted to require"),
267 DenormFlagEnumOptions);
271 "denormal-fp-math-f32",
272 cl::desc(
"Select which denormal numbers the code is permitted to require for float"),
274 DenormFlagEnumOptions);
278 "enable-sign-dependent-rounding-fp-math",
cl::Hidden,
279 cl::desc(
"Force codegen to assume rounding mode can change dynamically"),
281 CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
284 "float-abi",
cl::desc(
"Choose float ABI type"),
287 "Target default float ABI type"),
289 "Soft float ABI (implied by -soft-float)"),
291 "Hard float ABI (uses FP registers)")));
295 "fp-contract",
cl::desc(
"Enable aggressive formation of fused FP ops"),
299 "Fuse FP ops whenever profitable"),
302 "Only fuse FP ops when the result won't be affected.")));
307 cl::desc(
"Determine when the Swift async frame pointer should be set"),
308 cl::init(SwiftAsyncFramePointerMode::Always),
310 "Determine based on deployment target"),
311 clEnumValN(SwiftAsyncFramePointerMode::Always,
"always",
312 "Always set the bit"),
313 clEnumValN(SwiftAsyncFramePointerMode::Never,
"never",
314 "Never set the bit")));
318 "nozero-initialized-in-bss",
319 cl::desc(
"Don't place zero-initialized symbols into bss section"),
324 "vec-extabi",
cl::desc(
"Enable the AIX Extended Altivec ABI."),
331 "Turn fastcc calls into tail calls by (potentially) changing ABI."),
340 "stack-symbol-ordering",
cl::desc(
"Order local stack symbols."),
346 cl::desc(
"Force align the stack to the minimum alignment"),
352 cl::desc(
"Emit a call to trap function rather than a trap instruction"),
357 cl::desc(
"Use .ctors instead of .init_array."),
362 "relax-elf-relocations",
364 "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
369 "data-sections",
cl::desc(
"Emit data into separate sections"),
374 "function-sections",
cl::desc(
"Emit functions into separate sections"),
379 "ignore-xcoff-visibility",
380 cl::desc(
"Not emit the visibility attribute for asm in AIX OS or give "
381 "all symbols 'unspecified' visibility in XCOFF object file"),
386 "xcoff-traceback-table",
cl::desc(
"Emit the XCOFF traceback table"),
391 "basic-block-sections",
392 cl::desc(
"Emit basic blocks into separate sections"),
406 "unique-section-names",
cl::desc(
"Give unique names to every section"),
411 "unique-basic-block-section-names",
412 cl::desc(
"Give unique names to every basic block section"),
417 "meabi",
cl::desc(
"Set EABI type (default depends on triple):"),
420 clEnumValN(EABI::Default,
"default",
"Triple default EABI version"),
421 clEnumValN(EABI::EABI4,
"4",
"EABI version 4"),
422 clEnumValN(EABI::EABI5,
"5",
"EABI version 5"),
427 "debugger-tune",
cl::desc(
"Tune debug info for a particular debugger"),
431 clEnumValN(DebuggerKind::LLDB,
"lldb",
"lldb"),
433 clEnumValN(DebuggerKind::SCE,
"sce",
"SCE targets (e.g. PS4)")));
437 "stack-size-section",
438 cl::desc(
"Emit a section containing stack size metadata"),
443 "addrsig",
cl::desc(
"Emit an address-significance table"),
448 "emit-call-site-info",
450 "Emit call site debug information, if debug information is enabled."),
455 "debug-entry-values",
456 cl::desc(
"Enable debug info for the debug entry values."),
461 "split-machine-functions",
462 cl::desc(
"Split out cold basic blocks from machine functions based on "
463 "profile information"),
468 "force-dwarf-frame-section",
472 static cl::opt<bool> XRayFunctionIndex(
"xray-function-index",
473 cl::desc(
"Emit xray_fn_idx section"),
482 cl::desc(
"Default alignment for loops"));
486 "enable-jmc-instrument",
487 cl::desc(
"Instrument functions with a call to __CheckForDebuggerJustMyCode"),
493 cl::desc(
"When set to true, const objects with relocatable address "
494 "values are put into the RO data section."),
499 "no-integrated-as",
cl::desc(
"Disable integrated assembler"),
511 return BasicBlockSection::All;
513 return BasicBlockSection::Labels;
515 return BasicBlockSection::None;
520 errs() <<
"Error loading basic block sections function list file: "
521 << MBOrErr.
getError().message() <<
"\n";
523 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
525 return BasicBlockSection::List;
547 Options.HonorSignDependentRoundingFPMathOption =
611 for (
const auto &[Feature, IsEnabled] : HostFeatures)
631 for (
const auto &[Feature, IsEnabled] : HostFeatures)
642 B.addAttribute(
Name, Val ?
"true" :
"false");
645#define HANDLE_BOOL_ATTR(CL, AttrName) \
647 if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
648 renderBoolStringAttr(NewAttrs, AttrName, *CL); \
655 auto &Ctx =
F.getContext();
659 if (!CPU.
empty() && !
F.hasFnAttribute(
"target-cpu"))
661 if (!Features.
empty()) {
664 F.getFnAttribute(
"target-features").getValueAsString();
665 if (OldFeatures.
empty())
670 Appended.
append(Features);
674 if (FramePointerUsageView->getNumOccurrences() > 0 &&
675 !
F.hasFnAttribute(
"frame-pointer")) {
683 if (DisableTailCallsView->getNumOccurrences() > 0)
695 if (DenormalFPMathView->getNumOccurrences() > 0 &&
696 !
F.hasFnAttribute(
"denormal-fp-math")) {
704 if (DenormalFP32MathView->getNumOccurrences() > 0 &&
705 !
F.hasFnAttribute(
"denormal-fp-math-f32")) {
710 "denormal-fp-math-f32",
714 if (TrapFuncNameView->getNumOccurrences() > 0)
717 if (
auto *Call = dyn_cast<CallInst>(&
I))
718 if (
const auto *
F = Call->getCalledFunction())
719 if (
F->getIntrinsicID() == Intrinsic::debugtrap ||
720 F->getIntrinsicID() == Intrinsic::trap)
725 F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
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.
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
static 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
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)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
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.
std::string getString() const
Returns features as a string.
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
Triple - Helper class for working with autoconf configuration names.
bool hasDefaultDataSections() const
Tests whether the target uses -data-sections as default.
bool hasDefaultEmulatedTLS() const
Tests whether the target uses emulated TLS as default.
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)
std::string getBBSections()
bool getEnableGuaranteedTailCallOpt()
std::string getFeaturesStr()
std::vector< std::string > getMAttrs()
bool getDisableIntegratedAS()
DenormalMode::DenormalModeKind getDenormalFPMath()
bool getUniqueSectionNames()
FramePointerKind getFramePointerUsage()
bool getEnableNoSignedZerosFPMath()
bool getEnableStackSizeSection()
void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val)
bool getEmitCallSiteInfo()
bool getDontPlaceZerosInBSS()
bool getIgnoreXCOFFVisibility()
std::optional< bool > getExplicitDataSections()
std::optional< bool > getExplicitEmulatedTLS()
bool getEnableMachineFunctionSplitter()
llvm::FloatABI::ABIType getFloatABIForCalls()
bool getEnableApproxFuncFPMath()
std::vector< std::string > getFeatureList()
bool getXRayFunctionIndex()
std::string getTrapFuncName()
llvm::ExceptionHandling getExceptionModel()
bool getEnableUnsafeFPMath()
bool getEnableNoInfsFPMath()
bool getXCOFFReadOnlyPointers()
bool getUniqueBasicBlockSectionNames()
bool getDisableTailCalls()
llvm::DebuggerKind getDebuggerTuningOpt()
bool getForceDwarfFrameSection()
void setFunctionAttributes(StringRef CPU, StringRef Features, Function &F)
Set function attributes of function F based on CPU, Features, and command line flags.
DenormalMode::DenormalModeKind getDenormalFP32Math()
bool getEnableNoTrappingFPMath()
llvm::BasicBlockSection getBBSectionsMode(llvm::TargetOptions &Options)
TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
llvm::FPOpFusion::FPOpFusionMode getFuseFPOps()
llvm::EABI getEABIVersion()
bool getEnableDebugEntryValues()
bool getDebugStrictDwarf()
bool getFunctionSections()
bool getRelaxELFRelocations()
bool getEnableAIXExtendedAltivecABI()
ThreadModel::Model getThreadModel()
bool getStackSymbolOrdering()
bool getEnableHonorSignDependentRoundingFPMath()
bool getEnableNoNaNsFPMath()
SwiftAsyncFramePointerMode getSwiftAsyncFramePointer()
bool getXCOFFTracebackTable()
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
MCTargetOptions InitMCTargetOptionsFromFlags()
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
bool getHostCPUFeatures(StringMap< bool, MallocAllocator > &Features)
getHostCPUFeatures - Get the LLVM names for the host CPU features.
This is an optimization pass for GlobalISel generic memory operations.
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.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DebuggerKind
Identify a debugger for "tuning" the debug info.
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.
Create this object with static storage to register codegen-related command line options.
Create this object with static storage to register mc-related command line options.