17#define DEBUG_TYPE "runtime-libcalls-info"
22#define GET_RUNTIME_LIBCALLS_INFO
23#define GET_INIT_RUNTIME_LIBCALL_NAMES
24#define GET_INIT_RUNTIME_LIBCALL_SIGNATURES
25#define GET_RUNTIME_LIBCALL_ATTRIBUTES
26#define GET_RUNTIME_LIBCALL_MASKED_VECTOR_LIBCALL_MAPPING
27#define GET_SET_TARGET_RUNTIME_LIBCALL_SETS
28#define DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
29#define GET_RUNTIME_LIBCALL_INTRINSIC_TO_LIBCALL
30#include "llvm/IR/RuntimeLibcalls.inc"
37 return RuntimeLibrary::accelerate;
39 return RuntimeLibrary::darwin_libsystem_m;
41 return RuntimeLibrary::libmvec;
43 return RuntimeLibrary::massv;
45 return RuntimeLibrary::svml;
47 return RuntimeLibrary::sleefgnuabi;
49 return RuntimeLibrary::armpl;
51 return RuntimeLibrary::amdlibm;
61 : LongDoubleFmt(LDblFormat.value_or(TT.getDefaultLongDoubleFormat())) {
65 ExceptionModel = TT.getDefaultExceptionHandling();
67 initLibcalls(TT, ExceptionModel,
FloatABI, ABIName, LongDoubleFmt);
80 M.getFloatABI(), M.getLongDoubleFormat(), ABIName,
83RTLIB::Libcall RuntimeLibcallsInfo::selectLongDoubleLibcall(
84 RTLIB::Libcall F80, RTLIB::Libcall F128, RTLIB::Libcall PPCF128)
const {
85 switch (LongDoubleFmt) {
97 return RTLIB::UNKNOWN_LIBCALL;
103bool RuntimeLibcallsInfo::isLibraryAvailable(RuntimeLibrary Library)
const {
109void RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(
116 llvm::fill(LibcallImplCallingConvs, DefaultCC);
119 if (isLibraryAvailable(Library))
120 setAvailableLibraryLibcalls(Library, TT, ExceptionModel, FloatABI,
127void RuntimeLibcallsInfo::initLibcalls(
const Triple &TT,
132 setTargetRuntimeLibcallSets(TT, ExceptionModel, FloatABI, ABIName,
137iota_range<RTLIB::LibcallImpl>
138RuntimeLibcallsInfo::libcallImplNameHit(uint16_t NameOffsetEntry,
139 uint16_t StrOffset) {
141 for (uint16_t Entry :
ArrayRef(RuntimeLibcallNameOffsetTable)
142 .drop_front(NameOffsetEntry + 1)) {
143 if (Entry != StrOffset)
148 RTLIB::LibcallImpl ImplStart =
static_cast<RTLIB::LibcallImpl
>(
149 &RuntimeLibcallNameOffsetTable[NameOffsetEntry] -
150 &RuntimeLibcallNameOffsetTable[0]);
152 static_cast<RTLIB::LibcallImpl
>(ImplStart + NumAliases));
155bool RuntimeLibcallsInfo::isAAPCS_ABI(
const Triple &TT, StringRef ABIName) {
170 return T.isLoongArch() ||
T.isMIPS() ||
T.isRISCV64();
176 return T.isLoongArch() ||
T.isRISCV64();
180 bool &ShouldExtI32Return,
181 bool &ShouldSignExtI32Param,
182 bool &ShouldSignExtI32Return,
190 return !
T.isAArch64() && !
T.isOSDarwin();
194 bool &ShouldZExtBoolParam,
bool &ShouldZExtBoolReturn,
const Triple &
T) {
202 return DL.getIndexType(Ctx, 0);
210 if (TT.isOSWindowsOrUEFI() && !TT.isWindowsCygwinEnvironment())
212 return std::max(32u,
DL.getPointerSizeInBits(0));
217 Attribute::NoCallback, Attribute::NoFree, Attribute::NoSync,
218 Attribute::NoUnwind, Attribute::WillReturn};
238 if (TT.isOSWindowsOrUEFI() && TT.isX86_64())
283 if (TT.isAArch64() || TT.isAMDGPU() || TT.isWasm())
308 return DL.getAllocaPtrType(Ctx);
352 for (FuncArgTypeID EltID : EltIDs)
388 const Triple &TT,
bool IsReturn) {
393 if (!
Signed || !Ty->isIntegerTy())
398 unsigned Bits = Ty->getIntegerBitWidth();
402 return *
Signed ? Attribute::SExt : Attribute::ZExt;
403 if (Bits != 32 || IntBits != 32)
406 return *
Signed ? Attribute::SExt : Attribute::ZExt;
408 return Attribute::SExt;
412std::pair<FunctionType *, AttributeList>
415 RTLIB::LibcallImpl LibcallImpl)
const {
416 const FuncArgTypeID *ProtoTypes =
417 &SignatureTable[SignatureOffset[LibcallImpl]];
419 if (ProtoTypes[0] == NoFuncArgType || ProtoTypes[0] == Variable ||
420 ProtoTypes[0] == ThreadLocalVariable)
423 FuncArgTypeID LastID = ProtoTypes[0];
429 if (isInRegStruct(LastID))
430 RetAttrs = RetAttrs.
addAttribute(Ctx, Attribute::InReg);
432 Ctx, getLibcallImplRetAttributes(Ctx, LibcallImpl));
436 bool IsVarArg =
false;
438 for (FuncArgTypeID TyID = ProtoTypes[Idx]; TyID != NoFuncArgType;
439 TyID = ProtoTypes[++Idx]) {
443 assert(ProtoTypes[Idx + 1] == NoFuncArgType);
463 for (
const LibcallArgAttrs &Static :
464 getLibcallImplArgAttributes(LibcallImpl)) {
466 "attributes for nonexistent argument");
467 AttributeSet StaticAttrs = getLibcallArgAttributeSet(Ctx, Static.AttrSetID);
468 if (Static.PointeeType != NoFuncArgType) {
472 Static.AlignToElement ? PointeeTy->
getScalarType() : PointeeTy;
476 if (!
Size.isScalable()) {
489 AttributeList::get(Ctx, getLibcallImplFnAttributes(Ctx, LibcallImpl),
490 RetAttrs, ArgAttrs)};
496 RTLIB::LibcallImpl LibcallImpl)
const {
497 const FuncArgTypeID *ProtoTypes =
498 &SignatureTable[SignatureOffset[LibcallImpl]];
499 if (ProtoTypes[0] != Variable && ProtoTypes[0] != ThreadLocalVariable)
505 Module &M, RTLIB::LibcallImpl LibcallImpl)
const {
509 auto [FuncTy, FuncAttrs] =
523 DL.getProgramAddressSpace(), Name, &M);
524 F->setAttributes(FuncAttrs);
530 Module &M, RTLIB::LibcallImpl LibcallImpl)
const {
538 M.getDataLayout(), LibcallImpl);
546std::pair<FunctionType *, AttributeList>
549 RTLIB::LibcallImpl LibcallImpl)
const {
550 switch (LibcallImpl) {
552 case RTLIB::impl___sincos_stret:
553 case RTLIB::impl___sincosf_stret: {
554 if (!darwinHasSinCosStret(TT))
557 Type *ScalarTy = LibcallImpl == RTLIB::impl___sincosf_stret
561 AttrBuilder FuncAttrBuilder(Ctx);
563 FuncAttrBuilder.addAttribute(Attr);
566 TT.isX86_32() || ((TT.isARM() || TT.isThumb()) &&
573 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
576 AttrBuilder AttrBuilder(Ctx);
578 AttrBuilder.addStructRetAttr(StructTy);
579 AttrBuilder.addAlignmentAttr(
DL.getABITypeAlign(StructTy));
583 return {FuncTy, Attrs.addParamAttributes(Ctx, 0, AttrBuilder)};
587 LibcallImpl == RTLIB::impl___sincosf_stret && TT.isX86_64()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
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 Type * convertToIRType(FuncArgTypeID ID, LLVMContext &Ctx, const Triple &TT, const DataLayout &DL, LongDoubleFormat LdblFormat)
static Type * getLongDoubleType(LLVMContext &Ctx, LongDoubleFormat Format)
static bool shouldZExtBool(const Triple &T)
static IntegerType * getSizeTType(LLVMContext &Ctx, const DataLayout &DL)
TODO: There is really no guarantee that sizeof(size_t) is equal to the index size of the default addr...
static bool shouldExtI32(const Triple &T)
static RuntimeLibrary getVectorRuntimeLibrary(VectorLibrary VecLib)
static Attribute::AttrKind getIntExtAttr(FuncArgTypeID ID, Type *Ty, const Triple &TT, bool IsReturn)
static Type * getInt128Type(LLVMContext &Ctx, const Triple &TT)
static constexpr Attribute::AttrKind CommonFnAttrs[]
static bool shouldSignExtI32Param(const Triple &T)
static unsigned getIntSize(const Triple &TT)
static bool shouldSignExtI32Return(const Triple &T)
static std::optional< bool > isSignedIntArgType(FuncArgTypeID ID)
static unsigned getLongSize(const Triple &TT, const DataLayout &DL)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
Check if the array is empty.
This class holds the attributes for a particular argument, parameter, function, or return value.
LLVM_ABI AttributeSet addAttributes(LLVMContext &C, AttributeSet AS) const
Add attributes to the attribute set.
LLVM_ABI AttributeSet addSortedAttributes(LLVMContext &C, ArrayRef< Attribute > Attrs) const
Add attributes to the attribute set, replacing attributes of the same kind.
static LLVM_ABI AttributeSet get(LLVMContext &C, const AttrBuilder &B)
LLVM_ABI AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add an argument attribute.
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static LLVM_ABI Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
static LLVM_ABI Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
A parsed version of the target data layout string in and methods for querying it.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
@ ExternalLinkage
Externally visible function.
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
This is an important class for using LLVM in a threaded context.
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
static LLVM_ABI ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt128Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
static LLVM_ABI Type * getX86_FP80Ty(LLVMContext &C)
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI LLVM_READONLY ARMABI computeTargetABI(const Triple &TT, StringRef ABIName="")
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
LongDoubleFormat
The floating-point format used for the target's "long double" type.
constexpr auto enum_seq(EnumT Begin, EnumT End)
Iterate over an enum type from Begin up to - but not including - End.
@ Mod
The access may modify the value stored in memory.
@ NoModRef
The access neither references nor modifies the value stored in memory.
ArrayRef(const T &OneElt) -> ArrayRef< T >
@ Default
Not specified; resolve to the target's default model.
VectorLibrary
List of known vector-functions libraries.
LLVM_ABI FunctionCallee getOrInsertLibcallDecl(Module &M, RTLIB::LibcallImpl LibcallImpl) const
static bool isVariable(RTLIB::LibcallImpl LibcallImpl)
static LLVM_ABI ArrayRef< RTLIB::RuntimeLibrary > getDefaultRuntimeLibraries(const Triple &TT)
Return the runtime libraries enabled by default for TT.
LLVM_ABI GlobalValue * getOrInsertImplGlobal(Module &M, RTLIB::LibcallImpl LibcallImpl) const
CallingConv::ID getLibcallImplCallingConv(RTLIB::LibcallImpl Call) const
Get the CallingConv that should be used for the specified libcall.
static unsigned getIntSize(const Triple &TT)
Get size of a C-level int or unsigned int, in bits.
LLVM_ABI Type * getVariableType(LLVMContext &Ctx, const Triple &TT, const DataLayout &DL, RTLIB::LibcallImpl LibcallImpl) const
LLVM_ABI std::pair< FunctionType *, AttributeList > getFunctionTy(LLVMContext &Ctx, const Triple &TT, const DataLayout &DL, RTLIB::LibcallImpl LibcallImpl) const
static LLVM_ABI void initExtensionsForTriple(bool &ShouldExtI32Param, bool &ShouldExtI32Return, bool &ShouldSignExtI32Param, bool &ShouldSignExtI32Return, const Triple &T)
Determine the extension attributes needed for i32 parameters and returns corresponding to C-level int...
static bool isThreadLocalVariable(RTLIB::LibcallImpl LibcallImpl)
static LLVM_ABI void initBoolExtensionsForTriple(bool &ShouldZExtBoolParam, bool &ShouldZExtBoolReturn, const Triple &T)
Determine whether bool parameters and returns need zeroext on T.
RuntimeLibcallsInfo()=default
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl)
Get the libcall routine name for the specified libcall implementation.
LLVM_ABI std::pair< FunctionType *, AttributeList > getDefaultFunctionTy(LLVMContext &Ctx, const Triple &TT, const DataLayout &DL, RTLIB::LibcallImpl LibcallImpl) const
Get the C-type function signature of the Libcall if provided, and convert it to IR FunctionType and A...