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)
101CGOPT(
bool, EnableStackSizeSection)
102CGOPT(
bool, EnableAddrsig)
103CGOPT(
bool, EmitCallSiteInfo)
105CGOPT(
bool, EnableDebugEntryValues)
106CGOPT(
bool, ForceDwarfFrameSection)
107CGOPT(
bool, XRayFunctionIndex)
108CGOPT(
bool, DebugStrictDwarf)
109CGOPT(
unsigned, AlignLoops)
110CGOPT(
bool, JMCInstrument)
111CGOPT(
bool, XCOFFReadOnlyPointers)
114#define CGBINDOPT(NAME) \
116 NAME##View = std::addressof(NAME); \
120 "march",
cl::desc(
"Architecture to generate code for (see --version)"));
124 "mcpu",
cl::desc(
"Target a specific cpu type (-mcpu=help for details)"),
130 cl::desc(
"Target specific attributes (-mattr=help for details)"),
135 "relocation-model",
cl::desc(
"Choose relocation model"),
139 "Fully relocatable, position independent code"),
141 "Relocatable external references, non-relocatable code"),
144 "Code and read-only data relocatable, accessed PC-relative"),
147 "Read-write data relocatable, accessed relative to static base"),
149 "Combination of ropi and rwpi")));
153 "thread-model",
cl::desc(
"Choose threading model"),
161 "code-model",
cl::desc(
"Choose code model"),
170 "large-data-threshold",
171 cl::desc(
"Choose large data threshold for x86_64 medium code model"),
176 "exception-model",
cl::desc(
"exception model"),
179 clEnumValN(ExceptionHandling::None,
"default",
180 "default exception handling model"),
181 clEnumValN(ExceptionHandling::DwarfCFI,
"dwarf",
182 "DWARF-like CFI based exception handling"),
184 "SjLj exception handling"),
185 clEnumValN(ExceptionHandling::ARM,
"arm",
"ARM EHABI exceptions"),
187 "Windows exception model"),
189 "WebAssembly exception handling")));
193 "filetype",
cl::init(CodeGenFileType::AssemblyFile),
195 "Choose a file type (not all types are supported by all targets):"),
197 "Emit an assembly ('.s') file"),
198 clEnumValN(CodeGenFileType::ObjectFile,
"obj",
199 "Emit a native object ('.o') file"),
201 "Emit nothing, for performance testing")));
206 cl::desc(
"Specify frame pointer elimination optimization"),
210 "Disable frame pointer elimination"),
211 clEnumValN(FramePointerKind::NonLeaf,
"non-leaf",
212 "Disable frame pointer elimination for non-leaf frame"),
214 "Enable frame pointer elimination")));
218 "enable-unsafe-fp-math",
219 cl::desc(
"Enable optimizations that may decrease FP precision"),
224 "enable-no-infs-fp-math",
225 cl::desc(
"Enable FP math optimizations that assume no +-Infs"),
230 "enable-no-nans-fp-math",
231 cl::desc(
"Enable FP math optimizations that assume no NaNs"),
236 "enable-no-signed-zeros-fp-math",
237 cl::desc(
"Enable FP math optimizations that assume "
238 "the sign of 0 is insignificant"),
243 "enable-approx-func-fp-math",
244 cl::desc(
"Enable FP math optimizations that assume approx func"),
249 "enable-no-trapping-fp-math",
250 cl::desc(
"Enable setting the FP exceptions build "
251 "attribute not to use exceptions"),
255 static const auto DenormFlagEnumOptions =
cl::values(
258 "the sign of a flushed-to-zero number is preserved "
261 "denormals are flushed to positive zero"),
263 "denormals have unknown treatment"));
268 cl::desc(
"Select which denormal numbers the code is permitted to require"),
270 DenormFlagEnumOptions);
274 "denormal-fp-math-f32",
275 cl::desc(
"Select which denormal numbers the code is permitted to require for float"),
277 DenormFlagEnumOptions);
281 "enable-sign-dependent-rounding-fp-math",
cl::Hidden,
282 cl::desc(
"Force codegen to assume rounding mode can change dynamically"),
284 CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
287 "float-abi",
cl::desc(
"Choose float ABI type"),
290 "Target default float ABI type"),
292 "Soft float ABI (implied by -soft-float)"),
294 "Hard float ABI (uses FP registers)")));
298 "fp-contract",
cl::desc(
"Enable aggressive formation of fused FP ops"),
302 "Fuse FP ops whenever profitable"),
305 "Only fuse FP ops when the result won't be affected.")));
310 cl::desc(
"Determine when the Swift async frame pointer should be set"),
311 cl::init(SwiftAsyncFramePointerMode::Always),
313 "Determine based on deployment target"),
314 clEnumValN(SwiftAsyncFramePointerMode::Always,
"always",
315 "Always set the bit"),
316 clEnumValN(SwiftAsyncFramePointerMode::Never,
"never",
317 "Never set the bit")));
321 "nozero-initialized-in-bss",
322 cl::desc(
"Don't place zero-initialized symbols into bss section"),
327 "vec-extabi",
cl::desc(
"Enable the AIX Extended Altivec ABI."),
334 "Turn fastcc calls into tail calls by (potentially) changing ABI."),
343 "stack-symbol-ordering",
cl::desc(
"Order local stack symbols."),
349 cl::desc(
"Force align the stack to the minimum alignment"),
355 cl::desc(
"Emit a call to trap function rather than a trap instruction"),
360 cl::desc(
"Use .ctors instead of .init_array."),
365 "data-sections",
cl::desc(
"Emit data into separate sections"),
370 "function-sections",
cl::desc(
"Emit functions into separate sections"),
375 "ignore-xcoff-visibility",
376 cl::desc(
"Not emit the visibility attribute for asm in AIX OS or give "
377 "all symbols 'unspecified' visibility in XCOFF object file"),
382 "xcoff-traceback-table",
cl::desc(
"Emit the XCOFF traceback table"),
387 "basic-block-address-map",
392 "basic-block-sections",
393 cl::desc(
"Emit basic blocks into separate sections"),
407 "enable-tlsdesc",
cl::desc(
"Enable the use of TLS Descriptors"),
412 "unique-section-names",
cl::desc(
"Give unique names to every section"),
417 "unique-basic-block-section-names",
418 cl::desc(
"Give unique names to every basic block section"),
423 "meabi",
cl::desc(
"Set EABI type (default depends on triple):"),
426 clEnumValN(EABI::Default,
"default",
"Triple default EABI version"),
427 clEnumValN(EABI::EABI4,
"4",
"EABI version 4"),
428 clEnumValN(EABI::EABI5,
"5",
"EABI version 5"),
433 "debugger-tune",
cl::desc(
"Tune debug info for a particular debugger"),
437 clEnumValN(DebuggerKind::LLDB,
"lldb",
"lldb"),
439 clEnumValN(DebuggerKind::SCE,
"sce",
"SCE targets (e.g. PS4)")));
443 "stack-size-section",
444 cl::desc(
"Emit a section containing stack size metadata"),
449 "addrsig",
cl::desc(
"Emit an address-significance table"),
454 "emit-call-site-info",
456 "Emit call site debug information, if debug information is enabled."),
461 "debug-entry-values",
462 cl::desc(
"Enable debug info for the debug entry values."),
467 "split-machine-functions",
468 cl::desc(
"Split out cold basic blocks from machine functions based on "
469 "profile information"),
474 "force-dwarf-frame-section",
478 static cl::opt<bool> XRayFunctionIndex(
"xray-function-index",
479 cl::desc(
"Emit xray_fn_idx section"),
488 cl::desc(
"Default alignment for loops"));
492 "enable-jmc-instrument",
493 cl::desc(
"Instrument functions with a call to __CheckForDebuggerJustMyCode"),
499 cl::desc(
"When set to true, const objects with relocatable address "
500 "values are put into the RO data section."),
505 "no-integrated-as",
cl::desc(
"Disable integrated assembler"),
517 return BasicBlockSection::All;
519 return BasicBlockSection::Labels;
521 return BasicBlockSection::None;
526 errs() <<
"Error loading basic block sections function list file: "
527 << MBOrErr.
getError().message() <<
"\n";
529 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
531 return BasicBlockSection::List;
553 Options.HonorSignDependentRoundingFPMathOption =
619 for (
const auto &[Feature, IsEnabled] : HostFeatures)
639 for (
const auto &[Feature, IsEnabled] : HostFeatures)
650 B.addAttribute(
Name, Val ?
"true" :
"false");
653#define HANDLE_BOOL_ATTR(CL, AttrName) \
655 if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
656 renderBoolStringAttr(NewAttrs, AttrName, *CL); \
663 auto &Ctx =
F.getContext();
667 if (!CPU.
empty() && !
F.hasFnAttribute(
"target-cpu"))
669 if (!Features.
empty()) {
672 F.getFnAttribute(
"target-features").getValueAsString();
673 if (OldFeatures.
empty())
678 Appended.
append(Features);
682 if (FramePointerUsageView->getNumOccurrences() > 0 &&
683 !
F.hasFnAttribute(
"frame-pointer")) {
691 if (DisableTailCallsView->getNumOccurrences() > 0)
703 if (DenormalFPMathView->getNumOccurrences() > 0 &&
704 !
F.hasFnAttribute(
"denormal-fp-math")) {
712 if (DenormalFP32MathView->getNumOccurrences() > 0 &&
713 !
F.hasFnAttribute(
"denormal-fp-math-f32")) {
718 "denormal-fp-math-f32",
722 if (TrapFuncNameView->getNumOccurrences() > 0)
725 if (
auto *Call = dyn_cast<CallInst>(&
I))
726 if (
const auto *
F = Call->getCalledFunction())
727 if (
F->getIntrinsicID() == Intrinsic::debugtrap ||
728 F->getIntrinsicID() == Intrinsic::trap)
733 F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
747 Triple TheTriple(TargetTriple);
749 const auto *TheTarget =
760 Twine(
"could not allocate target machine for ") +
762 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 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.