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)
64CGOPT(
bool, EnableUnsafeFPMath)
65CGOPT(
bool, EnableNoInfsFPMath)
66CGOPT(
bool, EnableNoNaNsFPMath)
67CGOPT(
bool, EnableNoSignedZerosFPMath)
68CGOPT(
bool, EnableApproxFuncFPMath)
69CGOPT(
bool, EnableNoTrappingFPMath)
70CGOPT(
bool, EnableAIXExtendedAltivecABI)
73CGOPT(
bool, EnableHonorSignDependentRoundingFPMath)
77CGOPT(
bool, DontPlaceZerosInBSS)
78CGOPT(
bool, EnableGuaranteedTailCallOpt)
79CGOPT(
bool, DisableTailCalls)
80CGOPT(
bool, StackSymbolOrdering)
81CGOPT(
bool, StackRealign)
82CGOPT(std::string, TrapFuncName)
84CGOPT(
bool, RelaxELFRelocations)
87CGOPT(
bool, IgnoreXCOFFVisibility)
88CGOPT(
bool, XCOFFTracebackTable)
89CGOPT(std::string, BBSections)
90CGOPT(
unsigned, TLSSize)
91CGOPT(
bool, EmulatedTLS)
92CGOPT(
bool, UniqueSectionNames)
93CGOPT(
bool, UniqueBasicBlockSectionNames)
96CGOPT(
bool, EnableStackSizeSection)
97CGOPT(
bool, EnableAddrsig)
98CGOPT(
bool, EmitCallSiteInfo)
100CGOPT(
bool, EnableDebugEntryValues)
101CGOPT(
bool, ForceDwarfFrameSection)
102CGOPT(
bool, XRayOmitFunctionIndex)
103CGOPT(
bool, DebugStrictDwarf)
104CGOPT(
unsigned, AlignLoops)
105CGOPT(
bool, JMCInstrument)
106CGOPT(
bool, XCOFFReadOnlyPointers)
109#define CGBINDOPT(NAME) \
111 NAME##View = std::addressof(NAME); \
115 "march",
cl::desc(
"Architecture to generate code for (see --version)"));
119 "mcpu",
cl::desc(
"Target a specific cpu type (-mcpu=help for details)"),
125 cl::desc(
"Target specific attributes (-mattr=help for details)"),
130 "relocation-model",
cl::desc(
"Choose relocation model"),
134 "Fully relocatable, position independent code"),
136 "Relocatable external references, non-relocatable code"),
139 "Code and read-only data relocatable, accessed PC-relative"),
142 "Read-write data relocatable, accessed relative to static base"),
144 "Combination of ropi and rwpi")));
148 "thread-model",
cl::desc(
"Choose threading model"),
156 "code-model",
cl::desc(
"Choose code model"),
165 "exception-model",
cl::desc(
"exception model"),
168 clEnumValN(ExceptionHandling::None,
"default",
169 "default exception handling model"),
170 clEnumValN(ExceptionHandling::DwarfCFI,
"dwarf",
171 "DWARF-like CFI based exception handling"),
173 "SjLj exception handling"),
174 clEnumValN(ExceptionHandling::ARM,
"arm",
"ARM EHABI exceptions"),
176 "Windows exception model"),
178 "WebAssembly exception handling")));
184 "Choose a file type (not all types are supported by all targets):"),
188 "Emit a native object ('.o') file"),
190 "Emit nothing, for performance testing")));
195 cl::desc(
"Specify frame pointer elimination optimization"),
199 "Disable frame pointer elimination"),
200 clEnumValN(FramePointerKind::NonLeaf,
"non-leaf",
201 "Disable frame pointer elimination for non-leaf frame"),
203 "Enable frame pointer elimination")));
207 "enable-unsafe-fp-math",
208 cl::desc(
"Enable optimizations that may decrease FP precision"),
213 "enable-no-infs-fp-math",
214 cl::desc(
"Enable FP math optimizations that assume no +-Infs"),
219 "enable-no-nans-fp-math",
220 cl::desc(
"Enable FP math optimizations that assume no NaNs"),
225 "enable-no-signed-zeros-fp-math",
226 cl::desc(
"Enable FP math optimizations that assume "
227 "the sign of 0 is insignificant"),
232 "enable-approx-func-fp-math",
233 cl::desc(
"Enable FP math optimizations that assume approx func"),
238 "enable-no-trapping-fp-math",
239 cl::desc(
"Enable setting the FP exceptions build "
240 "attribute not to use exceptions"),
244 static const auto DenormFlagEnumOptions =
246 "IEEE 754 denormal numbers"),
248 "the sign of a flushed-to-zero number is preserved "
251 "denormals are flushed to positive zero"));
256 cl::desc(
"Select which denormal numbers the code is permitted to require"),
258 DenormFlagEnumOptions);
262 "denormal-fp-math-f32",
263 cl::desc(
"Select which denormal numbers the code is permitted to require for float"),
265 DenormFlagEnumOptions);
269 "enable-sign-dependent-rounding-fp-math",
cl::Hidden,
270 cl::desc(
"Force codegen to assume rounding mode can change dynamically"),
272 CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
275 "float-abi",
cl::desc(
"Choose float ABI type"),
278 "Target default float ABI type"),
280 "Soft float ABI (implied by -soft-float)"),
282 "Hard float ABI (uses FP registers)")));
286 "fp-contract",
cl::desc(
"Enable aggressive formation of fused FP ops"),
290 "Fuse FP ops whenever profitable"),
293 "Only fuse FP ops when the result won't be affected.")));
298 cl::desc(
"Determine when the Swift async frame pointer should be set"),
299 cl::init(SwiftAsyncFramePointerMode::Always),
301 "Determine based on deployment target"),
302 clEnumValN(SwiftAsyncFramePointerMode::Always,
"always",
303 "Always set the bit"),
304 clEnumValN(SwiftAsyncFramePointerMode::Never,
"never",
305 "Never set the bit")));
309 "nozero-initialized-in-bss",
310 cl::desc(
"Don't place zero-initialized symbols into bss section"),
315 "vec-extabi",
cl::desc(
"Enable the AIX Extended Altivec ABI."),
322 "Turn fastcc calls into tail calls by (potentially) changing ABI."),
331 "stack-symbol-ordering",
cl::desc(
"Order local stack symbols."),
337 cl::desc(
"Force align the stack to the minimum alignment"),
343 cl::desc(
"Emit a call to trap function rather than a trap instruction"),
348 cl::desc(
"Use .ctors instead of .init_array."),
353 "relax-elf-relocations",
355 "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
360 "data-sections",
cl::desc(
"Emit data into separate sections"),
365 "function-sections",
cl::desc(
"Emit functions into separate sections"),
370 "ignore-xcoff-visibility",
371 cl::desc(
"Not emit the visibility attribute for asm in AIX OS or give "
372 "all symbols 'unspecified' visibility in XCOFF object file"),
377 "xcoff-traceback-table",
cl::desc(
"Emit the XCOFF traceback table"),
382 "basic-block-sections",
383 cl::desc(
"Emit basic blocks into separate sections"),
397 "unique-section-names",
cl::desc(
"Give unique names to every section"),
402 "unique-basic-block-section-names",
403 cl::desc(
"Give unique names to every basic block section"),
408 "meabi",
cl::desc(
"Set EABI type (default depends on triple):"),
411 clEnumValN(EABI::Default,
"default",
"Triple default EABI version"),
412 clEnumValN(EABI::EABI4,
"4",
"EABI version 4"),
413 clEnumValN(EABI::EABI5,
"5",
"EABI version 5"),
418 "debugger-tune",
cl::desc(
"Tune debug info for a particular debugger"),
422 clEnumValN(DebuggerKind::LLDB,
"lldb",
"lldb"),
424 clEnumValN(DebuggerKind::SCE,
"sce",
"SCE targets (e.g. PS4)")));
428 "stack-size-section",
429 cl::desc(
"Emit a section containing stack size metadata"),
434 "addrsig",
cl::desc(
"Emit an address-significance table"),
439 "emit-call-site-info",
441 "Emit call site debug information, if debug information is enabled."),
446 "debug-entry-values",
447 cl::desc(
"Enable debug info for the debug entry values."),
452 "split-machine-functions",
453 cl::desc(
"Split out cold basic blocks from machine functions based on "
454 "profile information"),
459 "force-dwarf-frame-section",
464 "no-xray-index",
cl::desc(
"Don't emit xray_fn_idx section"),
473 cl::desc(
"Default alignment for loops"));
477 "enable-jmc-instrument",
478 cl::desc(
"Instrument functions with a call to __CheckForDebuggerJustMyCode"),
484 cl::desc(
"When set to true, const objects with relocatable address "
485 "values are put into the RO data section."),
497 return BasicBlockSection::All;
499 return BasicBlockSection::Labels;
501 return BasicBlockSection::None;
506 errs() <<
"Error loading basic block sections function list file: "
507 << MBOrErr.
getError().message() <<
"\n";
509 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
511 return BasicBlockSection::List;
533 Options.HonorSignDependentRoundingFPMathOption =
553 Options.ExplicitEmulatedTLS = EmulatedTLSView->getNumOccurrences() > 0;
596 for (
const auto &[Feature, IsEnabled] : HostFeatures)
616 for (
const auto &[Feature, IsEnabled] : HostFeatures)
627 B.addAttribute(
Name, Val ?
"true" :
"false");
630#define HANDLE_BOOL_ATTR(CL, AttrName) \
632 if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
633 renderBoolStringAttr(NewAttrs, AttrName, *CL); \
640 auto &Ctx =
F.getContext();
644 if (!CPU.
empty() && !
F.hasFnAttribute(
"target-cpu"))
646 if (!Features.
empty()) {
649 F.getFnAttribute(
"target-features").getValueAsString();
650 if (OldFeatures.
empty())
655 Appended.
append(Features);
659 if (FramePointerUsageView->getNumOccurrences() > 0 &&
660 !
F.hasFnAttribute(
"frame-pointer")) {
668 if (DisableTailCallsView->getNumOccurrences() > 0)
680 if (DenormalFPMathView->getNumOccurrences() > 0 &&
681 !
F.hasFnAttribute(
"denormal-fp-math")) {
689 if (DenormalFP32MathView->getNumOccurrences() > 0 &&
690 !
F.hasFnAttribute(
"denormal-fp-math-f32")) {
695 "denormal-fp-math-f32",
699 if (TrapFuncNameView->getNumOccurrences() > 0)
702 if (
auto *Call = dyn_cast<CallInst>(&
I))
703 if (
const auto *
F = Call->getCalledFunction())
704 if (
F->getIntrinsicID() == Intrinsic::debugtrap ||
705 F->getIntrinsicID() == Intrinsic::trap)
710 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.
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()
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()
bool getEnableMachineFunctionSplitter()
llvm::FloatABI::ABIType getFloatABIForCalls()
bool getXRayOmitFunctionIndex()
bool getEnableApproxFuncFPMath()
std::vector< std::string > getFeatureList()
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.
@ 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.