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."); \
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, EnableUnsafeFPMath)
68CGOPT(
bool, EnableNoInfsFPMath)
69CGOPT(
bool, EnableNoNaNsFPMath)
70CGOPT(
bool, EnableNoSignedZerosFPMath)
71CGOPT(
bool, EnableApproxFuncFPMath)
72CGOPT(
bool, EnableNoTrappingFPMath)
73CGOPT(
bool, EnableAIXExtendedAltivecABI)
76CGOPT(
bool, EnableHonorSignDependentRoundingFPMath)
80CGOPT(
bool, DontPlaceZerosInBSS)
81CGOPT(
bool, EnableGuaranteedTailCallOpt)
82CGOPT(
bool, DisableTailCalls)
83CGOPT(
bool, StackSymbolOrdering)
84CGOPT(
bool, StackRealign)
85CGOPT(std::string, TrapFuncName)
87CGOPT(
bool, DisableIntegratedAS)
90CGOPT(
bool, IgnoreXCOFFVisibility)
91CGOPT(
bool, XCOFFTracebackTable)
92CGOPT(
bool, EnableBBAddrMap)
93CGOPT(std::string, BBSections)
94CGOPT(
unsigned, TLSSize)
97CGOPT(
bool, UniqueSectionNames)
98CGOPT(
bool, UniqueBasicBlockSectionNames)
99CGOPT(
bool, SeparateNamedSections)
102CGOPT(
bool, EnableStackSizeSection)
103CGOPT(
bool, EnableAddrsig)
104CGOPT(
bool, EmitCallSiteInfo)
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"),
180 clEnumValN(ExceptionHandling::None,
"default",
181 "default exception handling model"),
182 clEnumValN(ExceptionHandling::DwarfCFI,
"dwarf",
183 "DWARF-like CFI based exception handling"),
185 "SjLj exception handling"),
186 clEnumValN(ExceptionHandling::ARM,
"arm",
"ARM EHABI exceptions"),
188 "Windows exception model"),
190 "WebAssembly exception handling")));
194 "filetype",
cl::init(CodeGenFileType::AssemblyFile),
196 "Choose a file type (not all types are supported by all targets):"),
198 "Emit an assembly ('.s') file"),
199 clEnumValN(CodeGenFileType::ObjectFile,
"obj",
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"),
212 clEnumValN(FramePointerKind::NonLeaf,
"non-leaf",
213 "Disable frame pointer elimination for non-leaf frame"),
215 "Enable frame pointer elimination")));
219 "enable-unsafe-fp-math",
220 cl::desc(
"Enable optimizations that may decrease FP precision"),
225 "enable-no-infs-fp-math",
226 cl::desc(
"Enable FP math optimizations that assume no +-Infs"),
231 "enable-no-nans-fp-math",
232 cl::desc(
"Enable FP math optimizations that assume no NaNs"),
237 "enable-no-signed-zeros-fp-math",
238 cl::desc(
"Enable FP math optimizations that assume "
239 "the sign of 0 is insignificant"),
244 "enable-approx-func-fp-math",
245 cl::desc(
"Enable FP math optimizations that assume approx func"),
250 "enable-no-trapping-fp-math",
251 cl::desc(
"Enable setting the FP exceptions build "
252 "attribute not to use exceptions"),
256 static const auto DenormFlagEnumOptions =
cl::values(
259 "the sign of a flushed-to-zero number is preserved "
262 "denormals are flushed to positive zero"),
264 "denormals have unknown treatment"));
269 cl::desc(
"Select which denormal numbers the code is permitted to require"),
271 DenormFlagEnumOptions);
275 "denormal-fp-math-f32",
276 cl::desc(
"Select which denormal numbers the code is permitted to require for float"),
278 DenormFlagEnumOptions);
282 "enable-sign-dependent-rounding-fp-math",
cl::Hidden,
283 cl::desc(
"Force codegen to assume rounding mode can change dynamically"),
285 CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
288 "float-abi",
cl::desc(
"Choose float ABI type"),
291 "Target default float ABI type"),
293 "Soft float ABI (implied by -soft-float)"),
295 "Hard float ABI (uses FP registers)")));
299 "fp-contract",
cl::desc(
"Enable aggressive formation of fused FP ops"),
303 "Fuse FP ops whenever profitable"),
306 "Only fuse FP ops when the result won't be affected.")));
311 cl::desc(
"Determine when the Swift async frame pointer should be set"),
312 cl::init(SwiftAsyncFramePointerMode::Always),
314 "Determine based on deployment target"),
315 clEnumValN(SwiftAsyncFramePointerMode::Always,
"always",
316 "Always set the bit"),
317 clEnumValN(SwiftAsyncFramePointerMode::Never,
"never",
318 "Never set the bit")));
322 "nozero-initialized-in-bss",
323 cl::desc(
"Don't place zero-initialized symbols into bss section"),
328 "vec-extabi",
cl::desc(
"Enable the AIX Extended Altivec ABI."),
335 "Turn fastcc calls into tail calls by (potentially) changing ABI."),
344 "stack-symbol-ordering",
cl::desc(
"Order local stack symbols."),
350 cl::desc(
"Force align the stack to the minimum alignment"),
356 cl::desc(
"Emit a call to trap function rather than a trap instruction"),
361 cl::desc(
"Use .ctors instead of .init_array."),
366 "data-sections",
cl::desc(
"Emit data into separate sections"),
371 "function-sections",
cl::desc(
"Emit functions into separate sections"),
376 "ignore-xcoff-visibility",
377 cl::desc(
"Not emit the visibility attribute for asm in AIX OS or give "
378 "all symbols 'unspecified' visibility in XCOFF object file"),
383 "xcoff-traceback-table",
cl::desc(
"Emit the XCOFF traceback table"),
388 "basic-block-address-map",
393 "basic-block-sections",
394 cl::desc(
"Emit basic blocks into separate sections"),
408 "enable-tlsdesc",
cl::desc(
"Enable the use of TLS Descriptors"),
413 "unique-section-names",
cl::desc(
"Give unique names to every section"),
418 "unique-basic-block-section-names",
419 cl::desc(
"Give unique names to every basic block section"),
424 "separate-named-sections",
425 cl::desc(
"Use separate unique sections for named sections"),
430 "meabi",
cl::desc(
"Set EABI type (default depends on triple):"),
433 clEnumValN(EABI::Default,
"default",
"Triple default EABI version"),
434 clEnumValN(EABI::EABI4,
"4",
"EABI version 4"),
435 clEnumValN(EABI::EABI5,
"5",
"EABI version 5"),
440 "debugger-tune",
cl::desc(
"Tune debug info for a particular debugger"),
444 clEnumValN(DebuggerKind::LLDB,
"lldb",
"lldb"),
446 clEnumValN(DebuggerKind::SCE,
"sce",
"SCE targets (e.g. PS4)")));
450 "stack-size-section",
451 cl::desc(
"Emit a section containing stack size metadata"),
456 "addrsig",
cl::desc(
"Emit an address-significance table"),
461 "emit-call-site-info",
463 "Emit call site debug information, if debug information is enabled."),
468 "debug-entry-values",
469 cl::desc(
"Enable debug info for the debug entry values."),
474 "split-machine-functions",
475 cl::desc(
"Split out cold basic blocks from machine functions based on "
476 "profile information"),
481 "force-dwarf-frame-section",
485 static cl::opt<bool> XRayFunctionIndex(
"xray-function-index",
486 cl::desc(
"Emit xray_fn_idx section"),
495 cl::desc(
"Default alignment for loops"));
499 "enable-jmc-instrument",
500 cl::desc(
"Instrument functions with a call to __CheckForDebuggerJustMyCode"),
506 cl::desc(
"When set to true, const objects with relocatable address "
507 "values are put into the RO data section."),
512 "no-integrated-as",
cl::desc(
"Disable integrated assembler"),
524 return BasicBlockSection::All;
526 return BasicBlockSection::Labels;
528 return BasicBlockSection::None;
533 errs() <<
"Error loading basic block sections function list file: "
534 << MBOrErr.
getError().message() <<
"\n";
536 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
538 return BasicBlockSection::List;
560 Options.HonorSignDependentRoundingFPMathOption =
627 for (
const auto &[Feature, IsEnabled] : HostFeatures)
647 for (
const auto &[Feature, IsEnabled] : HostFeatures)
658 B.addAttribute(
Name, Val ?
"true" :
"false");
661#define HANDLE_BOOL_ATTR(CL, AttrName) \
663 if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
664 renderBoolStringAttr(NewAttrs, AttrName, *CL); \
671 auto &Ctx =
F.getContext();
675 if (!CPU.
empty() && !
F.hasFnAttribute(
"target-cpu"))
677 if (!Features.
empty()) {
680 F.getFnAttribute(
"target-features").getValueAsString();
681 if (OldFeatures.
empty())
686 Appended.
append(Features);
690 if (FramePointerUsageView->getNumOccurrences() > 0 &&
691 !
F.hasFnAttribute(
"frame-pointer")) {
699 if (DisableTailCallsView->getNumOccurrences() > 0)
711 if (DenormalFPMathView->getNumOccurrences() > 0 &&
712 !
F.hasFnAttribute(
"denormal-fp-math")) {
720 if (DenormalFP32MathView->getNumOccurrences() > 0 &&
721 !
F.hasFnAttribute(
"denormal-fp-math-f32")) {
726 "denormal-fp-math-f32",
730 if (TrapFuncNameView->getNumOccurrences() > 0)
733 if (
auto *Call = dyn_cast<CallInst>(&
I))
734 if (
const auto *
F = Call->getCalledFunction())
735 if (
F->getIntrinsicID() == Intrinsic::debugtrap ||
736 F->getIntrinsicID() == Intrinsic::trap)
741 F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
755 Triple TheTriple(TargetTriple);
757 const auto *TheTarget =
768 Twine(
"could not allocate target machine for ") +
770 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.
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
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)
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.
Target - Wrapper for Target specific information.
TargetMachine * createTargetMachine(StringRef 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 supports both general-dynamic and TLSDESC, and TLSDESC is enabled by default.
bool hasDefaultDataSections() const
Tests whether the target uses -data-sections as default.
const std::string & getTriple() const
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)
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()
std::optional< bool > getExplicitEnableTLSDESC()
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()
std::optional< CodeModel::Model > getExplicitCodeModel()
bool getEnableApproxFuncFPMath()
std::vector< std::string > getFeatureList()
bool getXRayFunctionIndex()
std::string getTrapFuncName()
llvm::ExceptionHandling getExceptionModel()
Expected< std::unique_ptr< TargetMachine > > createTargetMachineForTriple(StringRef TargetTriple, CodeGenOptLevel OptLevel=CodeGenOptLevel::Default)
Creates a TargetMachine instance with the options defined on the command line.
bool getEnableUnsafeFPMath()
bool getSeparateNamedSections()
bool getEnableNoInfsFPMath()
bool getXCOFFReadOnlyPointers()
bool getUniqueBasicBlockSectionNames()
bool getDisableTailCalls()
std::optional< Reloc::Model > getExplicitRelocModel()
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.
bool getEnableBBAddrMap()
llvm::FPOpFusion::FPOpFusionMode getFuseFPOps()
llvm::EABI getEABIVersion()
bool getEnableDebugEntryValues()
bool getDebugStrictDwarf()
bool getFunctionSections()
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.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
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.
CodeGenOptLevel
Code generation optimization level.
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.
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
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.