41#include <system_error>
45#define OPTIONS_STRUCT_DECL
46#include "CodeGenToolOptions.inc"
48#define OPTIONS_STRUCT_DEFS
49#include "CodeGenToolOptions.inc"
52 return C.getLibraryOptions().get<CodeGenToolOptions>();
56 return C.get<CodeGenToolOptions>().march.str();
60 return C.get<CodeGenToolOptions>().mcpu.str();
63std::vector<std::string>
66 return std::vector<std::string>(MAttrs.
begin(), MAttrs.
end());
69std::optional<Reloc::Model>
71 return C.get<CodeGenToolOptions>().relocation_model;
74std::optional<CodeModel::Model>
76 return C.get<CodeGenToolOptions>().code_model;
79std::optional<uint64_t>
81 return C.get<CodeGenToolOptions>().large_data_threshold;
84std::optional<CodeGenFileType>
86 return C.get<CodeGenToolOptions>().filetype;
95 return C.get<CodeGenToolOptions>().float_abi;
100 return toOptional(
C.get<CodeGenToolOptions>().data_sections);
105 return toOptional(
C.get<CodeGenToolOptions>().function_sections);
110 return toOptional(
C.get<CodeGenToolOptions>().emulated_tls);
114 return C.get<CodeGenToolOptions>().mtune.str();
119 return C.get<CodeGenToolOptions>().save_stats;
124 std::in_place_type<CodeGenToolOptions>);
133 if (Opts.basic_block_sections ==
"all")
135 else if (Opts.basic_block_sections ==
"none")
141 errs() <<
"Error loading basic block sections function list file: "
142 << MBOrErr.
getError().message() <<
"\n";
144 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
154 const Triple &TheTriple) {
155 const CodeGenToolOptions &Opts = LibraryOptions.
get<CodeGenToolOptions>();
157 Options.NoZerosInBSS = Opts.nozero_initialized_in_bss;
158 Options.GuaranteedTailCallOpt = Opts.tailcallopt;
159 Options.StackSymbolOrdering = Opts.stack_symbol_ordering;
160 Options.UseInitArray = !Opts.use_ctors;
163 Options.FunctionSections =
valueOr(Opts.function_sections,
false);
164 Options.IgnoreXCOFFVisibility = Opts.ignore_xcoff_visibility;
165 Options.XCOFFTracebackTable = Opts.xcoff_traceback_table;
166 Options.BBAddrMap = Opts.basic_block_address_map;
168 Options.UniqueSectionNames = Opts.unique_section_names;
169 Options.UniqueBasicBlockSectionNames = Opts.unique_basic_block_section_names;
170 Options.SeparateNamedSections = Opts.separate_named_sections;
171 Options.TLSSize = Opts.tls_size;
176 Options.VecLib = Opts.vector_library;
177 Options.EmitStackSizeSection = Opts.stack_size_section;
178 Options.EnableStaticDataPartitioning = Opts.partition_static_data_sections;
179 Options.EmitAddrsig = Opts.addrsig;
180 Options.EmitCallGraphSection = Opts.call_graph_section;
181 Options.EmitCallSiteInfo = Opts.emit_call_site_info;
182 Options.EnableDebugEntryValues = Opts.debug_entry_values;
183 Options.ForceDwarfFrameSection = Opts.force_dwarf_frame_section;
184 Options.XRayFunctionIndex = Opts.xray_function_index;
185 Options.DebugStrictDwarf = Opts.strict_dwarf;
186 Options.LoopAlignment = Opts.align_loops;
187 Options.JMCInstrument = Opts.enable_jmc_instrument;
188 Options.XCOFFReadOnlyPointers = Opts.mxcoff_roptr;
192 Options.SwiftAsyncFramePointer = Opts.swift_async_fp;
202 if (MCPU ==
"native")
214 if (TuneCPU ==
"native")
237std::vector<std::string>
256 B.addAttribute(Name, Val ?
"true" :
"false");
261 auto &Ctx =
F.getContext();
264 AttrBuilder NewAttrs(Ctx);
266 if (!CPU.empty() && !
F.hasFnAttribute(
"target-cpu"))
267 NewAttrs.addAttribute(
"target-cpu", CPU);
268 if (!TuneCPU.
empty() && !
F.hasFnAttribute(
"tune-cpu"))
269 NewAttrs.addAttribute(
"tune-cpu", TuneCPU);
270 if (!Features.
empty()) {
273 F.getFnAttribute(
"target-features").getValueAsString();
274 if (OldFeatures.
empty())
275 NewAttrs.addAttribute(
"target-features", Features);
279 Appended.
append(Features);
280 NewAttrs.addAttribute(
"target-features", Appended);
283 if (Opts.frame_pointer && !
F.hasFnAttribute(
"frame-pointer")) {
285 NewAttrs.addAttribute(
"frame-pointer",
"all");
287 NewAttrs.addAttribute(
"frame-pointer",
"non-leaf");
289 NewAttrs.addAttribute(
"frame-pointer",
"non-leaf-no-reserve");
291 NewAttrs.addAttribute(
"frame-pointer",
"reserved");
293 NewAttrs.addAttribute(
"frame-pointer",
"none");
296 NewAttrs.addAttribute(
"disable-tail-calls",
298 if (Opts.stackrealign)
299 NewAttrs.addAttribute(
"stackrealign");
301 if ((Opts.denormal_fp_math || Opts.denormal_fp_math_f32) &&
302 !
F.hasFnAttribute(Attribute::DenormalFPEnv)) {
311 NewAttrs.addDenormalFPEnvAttr(FPEnv);
318 if (
const auto *
F =
Call->getCalledFunction())
319 if (
F->getIntrinsicID() == Intrinsic::debugtrap ||
320 F->getIntrinsicID() == Intrinsic::trap)
325 F.setAttributes(Attrs.addFnAttributes(Ctx, NewAttrs));
341 " conflicts with the \"float-abi\" module flag \"" +
342 Existing->getString() +
"\"");
361 " conflicts with the \"exception-model\" module flag \"" +
362 Existing->getString() +
"\"");
375 if (!ABIName.
empty() && !M.getModuleFlag(
"target-abi")) {
388 Triple TheTriple(TargetTriple);
402 Twine(
"could not allocate target machine for ") +
404 return std::unique_ptr<TargetMachine>(
Target);
426 "Should have been a valid --save-stats value");
436 std::make_unique<llvm::raw_fd_ostream>(StatsFilename, EC, FileFlags);
439 <<
"Unable to open statistics file: " << EC.message() <<
"\n";
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static BasicBlockSection getBBSectionsMode(const CodeGenToolOptions &Opts, TargetOptions &Options)
static const CodeGenToolOptions & getCodeGenToolOptions(const LLVMContext &C)
Utilities for dealing with flags related to floating point properties and mode controls.
Module.h This file contains the declarations for the Module class.
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
This file defines the SmallString class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
Represent a constant reference to an array (0 or more elements consecutively in memory),...
static LLVM_ABI 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.
This is an important class for using LLVM in a threaded context.
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
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.
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
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)
Represent a constant reference to a string, i.e.
constexpr bool empty() const
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.
LLVM_ABI std::string getString() const
Returns features as a string.
LLVM_ABI void AddFeature(StringRef String, bool Enable=true)
Adds Features.
Target - Wrapper for Target specific information.
TargetMachine * createTargetMachine(const Triple &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 uses TLSDESC by default.
bool hasDefaultDataSections() const
Tests whether the target uses -data-sections as default.
const std::string & str() 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...
static LLVM_ABI raw_ostream & error()
Convenience method for printing "error: " to stderr.
The options of a library that declares them in TableGen rather than as cl::opt (see llvm/Option/Libra...
Connects options struct T to cl::parseCommandLineOptions and cl::LibraryOptionsContext.
StringRef getABITypeName(ABIType ABI)
Returns the string spelling used by the "float-abi" IR module flag for a Soft or Hard ABIType.
LLVM_ABI std::string getMArch(const cl::LibraryOptionsContext &C)
LLVM_ABI SaveStatsMode getSaveStats(const cl::LibraryOptionsContext &C)
LLVM_ABI std::string getMTune(const cl::LibraryOptionsContext &C)
LLVM_ABI void renderBoolStringAttr(AttrBuilder &B, StringRef Name, bool Val)
LLVM_ABI std::vector< std::string > getMAttrs(const cl::LibraryOptionsContext &C)
LLVM_ABI Expected< std::unique_ptr< TargetMachine > > createTargetMachineForTriple(const cl::LibraryOptionsContext &LibraryOptions, const Triple &TargetTriple, CodeGenOptLevel OptLevel=CodeGenOptLevel::Default)
Creates a TargetMachine instance with the options defined on the command line.
LLVM_ABI std::optional< Reloc::Model > getExplicitRelocModel(const cl::LibraryOptionsContext &C)
LLVM_ABI void setFunctionAttributes(Function &F, StringRef CPU, StringRef Features, StringRef TuneCPU="")
Set function attributes of function F based on CPU, TuneCPU, Features, and command line flags.
LLVM_ABI ArrayRef< const cl::LibraryOptions * > getToolOptions()
The options that a tool reading getTargetOptions passes to cl::parseCommandLineOptions.
LLVM_ABI TargetOptions getTargetOptions(const cl::LibraryOptionsContext &LibraryOptions, const llvm::Triple &TheTriple)
Common utility function tightly tied to the options listed here.
LLVM_ABI std::string getFeaturesStr(const cl::LibraryOptionsContext &C)
LLVM_ABI std::optional< bool > getExplicitFunctionSections(const cl::LibraryOptionsContext &C)
LLVM_ABI std::vector< std::string > getFeatureList(const cl::LibraryOptionsContext &C)
LLVM_ABI CodeGenFileType getFileType(const cl::LibraryOptionsContext &C)
LLVM_ABI std::string getCPUStr(const cl::LibraryOptionsContext &C)
LLVM_ABI std::optional< CodeModel::Model > getExplicitCodeModel(const cl::LibraryOptionsContext &C)
LLVM_ABI std::optional< bool > getExplicitDataSections(const cl::LibraryOptionsContext &C)
LLVM_ABI int maybeSaveStatistics(const cl::LibraryOptionsContext &C, StringRef OutputFilename, StringRef ToolName)
Conditionally saves the collected LLVM statistics to the received output file, based on the value of ...
LLVM_ABI std::optional< CodeGenFileType > getExplicitFileType(const cl::LibraryOptionsContext &C)
LLVM_ABI std::optional< uint64_t > getExplicitLargeDataThreshold(const cl::LibraryOptionsContext &C)
LLVM_ABI std::string getTuneCPUStr(const cl::LibraryOptionsContext &C)
LLVM_ABI std::optional< bool > getExplicitEmulatedTLS(const cl::LibraryOptionsContext &C)
LLVM_ABI llvm::FloatABI::ABIType getFloatABIForCalls(const cl::LibraryOptionsContext &C)
LLVM_ABI void maybeEnableStatistics(const cl::LibraryOptionsContext &C)
Conditionally enables the collection of LLVM statistics during the tool run, based on the value of th...
LLVM_ABI std::string getMCPU(const cl::LibraryOptionsContext &C)
LLVM_ABI MCTargetOptions getMCTargetOptions(const cl::LibraryOptionsContext &C)
LLVM_ABI ArrayRef< const cl::LibraryOptions * > getToolOptions()
The options that a tool reading getMCTargetOptions passes to cl::parseCommandLineOptions.
LLVM_ABI StringRef getABIName(const cl::LibraryOptionsContext &C)
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
LLVM_ABI void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
LLVM_ABI void replace_extension(SmallVectorImpl< char > &path, const Twine &extension, Style style=Style::native)
Replace the file extension of path with extension.
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
LLVM_ABI StringMap< bool, MallocAllocator > getHostCPUFeatures()
getHostCPUFeatures - Get the LLVM names for the host CPU features.
LLVM_ABI StringRef getHostCPUName()
getHostCPUName - Get the LLVM name for the host CPU.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI 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.
StringRef getExceptionModelName(ExceptionHandling EH)
Returns the "exception-model" module flag spelling for an ExceptionHandling value.
auto dyn_cast_or_null(const Y &Val)
LLVM_ABI void EnableStatistics(bool DoPrintOnExit=true)
Enable the collection and printing of statistics.
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
CodeGenOptLevel
Code generation optimization level.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
constexpr std::optional< bool > toOptional(BoolOrDefault X)
@ Default
Not specified; resolve to the target's default model.
constexpr bool valueOr(BoolOrDefault X, bool Default)
LLVM_ABI void PrintStatisticsJSON(raw_ostream &OS)
Print statistics in JSON format.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Represents the full denormal controls for a function, including the default mode and the f32 specific...
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.
@ IEEE
IEEE-754 denormal numbers preserved.
static LLVM_ABI const Target * lookupTarget(const Triple &TheTriple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.