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"),
214 clEnumValN(FramePointerKind::Reserved,
"reserved",
215 "Enable frame pointer elimination, but reserve the frame "
218 "Enable frame pointer elimination")));
222 "enable-unsafe-fp-math",
223 cl::desc(
"Enable optimizations that may decrease FP precision"),
228 "enable-no-infs-fp-math",
229 cl::desc(
"Enable FP math optimizations that assume no +-Infs"),
234 "enable-no-nans-fp-math",
235 cl::desc(
"Enable FP math optimizations that assume no NaNs"),
240 "enable-no-signed-zeros-fp-math",
241 cl::desc(
"Enable FP math optimizations that assume "
242 "the sign of 0 is insignificant"),
247 "enable-approx-func-fp-math",
248 cl::desc(
"Enable FP math optimizations that assume approx func"),
253 "enable-no-trapping-fp-math",
254 cl::desc(
"Enable setting the FP exceptions build "
255 "attribute not to use exceptions"),
259 static const auto DenormFlagEnumOptions =
cl::values(
262 "the sign of a flushed-to-zero number is preserved "
265 "denormals are flushed to positive zero"),
267 "denormals have unknown treatment"));
272 cl::desc(
"Select which denormal numbers the code is permitted to require"),
274 DenormFlagEnumOptions);
278 "denormal-fp-math-f32",
279 cl::desc(
"Select which denormal numbers the code is permitted to require for float"),
281 DenormFlagEnumOptions);
285 "enable-sign-dependent-rounding-fp-math",
cl::Hidden,
286 cl::desc(
"Force codegen to assume rounding mode can change dynamically"),
288 CGBINDOPT(EnableHonorSignDependentRoundingFPMath);
291 "float-abi",
cl::desc(
"Choose float ABI type"),
294 "Target default float ABI type"),
296 "Soft float ABI (implied by -soft-float)"),
298 "Hard float ABI (uses FP registers)")));
302 "fp-contract",
cl::desc(
"Enable aggressive formation of fused FP ops"),
306 "Fuse FP ops whenever profitable"),
309 "Only fuse FP ops when the result won't be affected.")));
314 cl::desc(
"Determine when the Swift async frame pointer should be set"),
315 cl::init(SwiftAsyncFramePointerMode::Always),
317 "Determine based on deployment target"),
318 clEnumValN(SwiftAsyncFramePointerMode::Always,
"always",
319 "Always set the bit"),
320 clEnumValN(SwiftAsyncFramePointerMode::Never,
"never",
321 "Never set the bit")));
325 "nozero-initialized-in-bss",
326 cl::desc(
"Don't place zero-initialized symbols into bss section"),
331 "vec-extabi",
cl::desc(
"Enable the AIX Extended Altivec ABI."),
338 "Turn fastcc calls into tail calls by (potentially) changing ABI."),
347 "stack-symbol-ordering",
cl::desc(
"Order local stack symbols."),
353 cl::desc(
"Force align the stack to the minimum alignment"),
359 cl::desc(
"Emit a call to trap function rather than a trap instruction"),
364 cl::desc(
"Use .ctors instead of .init_array."),
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-address-map",
396 "basic-block-sections",
397 cl::desc(
"Emit basic blocks into separate sections"),
411 "enable-tlsdesc",
cl::desc(
"Enable the use of TLS Descriptors"),
416 "unique-section-names",
cl::desc(
"Give unique names to every section"),
421 "unique-basic-block-section-names",
422 cl::desc(
"Give unique names to every basic block section"),
427 "separate-named-sections",
428 cl::desc(
"Use separate unique sections for named sections"),
433 "meabi",
cl::desc(
"Set EABI type (default depends on triple):"),
436 clEnumValN(EABI::Default,
"default",
"Triple default EABI version"),
437 clEnumValN(EABI::EABI4,
"4",
"EABI version 4"),
438 clEnumValN(EABI::EABI5,
"5",
"EABI version 5"),
443 "debugger-tune",
cl::desc(
"Tune debug info for a particular debugger"),
447 clEnumValN(DebuggerKind::LLDB,
"lldb",
"lldb"),
449 clEnumValN(DebuggerKind::SCE,
"sce",
"SCE targets (e.g. PS4)")));
453 "stack-size-section",
454 cl::desc(
"Emit a section containing stack size metadata"),
459 "addrsig",
cl::desc(
"Emit an address-significance table"),
464 "emit-call-site-info",
466 "Emit call site debug information, if debug information is enabled."),
471 "debug-entry-values",
472 cl::desc(
"Enable debug info for the debug entry values."),
477 "split-machine-functions",
478 cl::desc(
"Split out cold basic blocks from machine functions based on "
479 "profile information"),
484 "force-dwarf-frame-section",
488 static cl::opt<bool> XRayFunctionIndex(
"xray-function-index",
489 cl::desc(
"Emit xray_fn_idx section"),
498 cl::desc(
"Default alignment for loops"));
502 "enable-jmc-instrument",
503 cl::desc(
"Instrument functions with a call to __CheckForDebuggerJustMyCode"),
509 cl::desc(
"When set to true, const objects with relocatable address "
510 "values are put into the RO data section."),
515 "no-integrated-as",
cl::desc(
"Disable integrated assembler"),
527 return BasicBlockSection::All;
529 return BasicBlockSection::Labels;
531 return BasicBlockSection::None;
536 errs() <<
"Error loading basic block sections function list file: "
537 << MBOrErr.
getError().message() <<
"\n";
539 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
541 return BasicBlockSection::List;
563 Options.HonorSignDependentRoundingFPMathOption =
655 B.addAttribute(
Name, Val ?
"true" :
"false");
658#define HANDLE_BOOL_ATTR(CL, AttrName) \
660 if (CL->getNumOccurrences() > 0 && !F.hasFnAttribute(AttrName)) \
661 renderBoolStringAttr(NewAttrs, AttrName, *CL); \
668 auto &Ctx =
F.getContext();
672 if (!CPU.
empty() && !
F.hasFnAttribute(
"target-cpu"))
674 if (!Features.
empty()) {
677 F.getFnAttribute(
"target-features").getValueAsString();
678 if (OldFeatures.
empty())
683 Appended.
append(Features);
687 if (FramePointerUsageView->getNumOccurrences() > 0 &&
688 !
F.hasFnAttribute(
"frame-pointer")) {
698 if (DisableTailCallsView->getNumOccurrences() > 0)
710 if (DenormalFPMathView->getNumOccurrences() > 0 &&
711 !
F.hasFnAttribute(
"denormal-fp-math")) {
719 if (DenormalFP32MathView->getNumOccurrences() > 0 &&
720 !
F.hasFnAttribute(
"denormal-fp-math-f32")) {
725 "denormal-fp-math-f32",
729 if (TrapFuncNameView->getNumOccurrences() > 0)
732 if (
auto *Call = dyn_cast<CallInst>(&
I))
733 if (
const auto *
F = Call->getCalledFunction())
734 if (
F->getIntrinsicID() == Intrinsic::debugtrap ||
735 F->getIntrinsicID() == Intrinsic::trap)
740 F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
754 Triple TheTriple(TargetTriple);
756 const auto *TheTarget =
767 Twine(
"could not allocate target machine for ") +
769 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)
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()
const StringMap< bool, MallocAllocator > getHostCPUFeatures()
getHostCPUFeatures - Get the LLVM names for the host CPU features.
StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
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.