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);
434 bool IsVarArg =
false;
436 for (FuncArgTypeID TyID = ProtoTypes[Idx]; TyID != NoFuncArgType;
437 TyID = ProtoTypes[++Idx]) {
441 assert(ProtoTypes[Idx + 1] == NoFuncArgType);
461 for (
const LibcallArgAttrs &Static :
462 getLibcallImplArgAttributes(LibcallImpl)) {
464 "attributes for nonexistent argument");
465 AttributeSet StaticAttrs = getLibcallArgAttributeSet(Ctx, Static.AttrSetID);
466 if (Static.PointeeType != NoFuncArgType) {
470 Static.AlignToElement ? PointeeTy->
getScalarType() : PointeeTy;
474 if (!
Size.isScalable()) {
487 AttributeList::get(Ctx, getLibcallImplFnAttributes(Ctx, LibcallImpl),
488 RetAttrs, ArgAttrs)};
494 RTLIB::LibcallImpl LibcallImpl)
const {
495 const FuncArgTypeID *ProtoTypes =
496 &SignatureTable[SignatureOffset[LibcallImpl]];
497 if (ProtoTypes[0] != Variable && ProtoTypes[0] != ThreadLocalVariable)
502std::pair<FunctionType *, AttributeList>
505 RTLIB::LibcallImpl LibcallImpl)
const {
507 Attribute::NoUnwind, Attribute::WillReturn};
509 Attribute::NoAlias, Attribute::WriteOnly, Attribute::NonNull};
511 switch (LibcallImpl) {
513 case RTLIB::impl___sincos_stret:
514 case RTLIB::impl___sincosf_stret: {
515 if (!darwinHasSinCosStret(TT))
518 Type *ScalarTy = LibcallImpl == RTLIB::impl___sincosf_stret
522 AttrBuilder FuncAttrBuilder(Ctx);
524 FuncAttrBuilder.addAttribute(Attr);
527 TT.isX86_32() || ((TT.isARM() || TT.isThumb()) &&
534 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
537 AttrBuilder AttrBuilder(Ctx);
539 AttrBuilder.addStructRetAttr(StructTy);
540 AttrBuilder.addAlignmentAttr(
DL.getABITypeAlign(StructTy));
544 return {FuncTy, Attrs.addParamAttributes(Ctx, 0, AttrBuilder)};
548 LibcallImpl == RTLIB::impl___sincosf_stret && TT.isX86_64()
554 case RTLIB::impl_malloc:
555 case RTLIB::impl_calloc: {
556 AttrBuilder FuncAttrBuilder(Ctx);
558 FuncAttrBuilder.addAttribute(Attr);
559 FuncAttrBuilder.addAttribute(Attribute::NoFree);
562 if (LibcallImpl == RTLIB::impl_malloc)
566 FuncAttrBuilder.addAllocKindAttr(AllocKind);
567 FuncAttrBuilder.addAttribute(
"alloc-family",
"malloc");
568 FuncAttrBuilder.addAllocSizeAttr(0, LibcallImpl == RTLIB::impl_malloc
570 : std::make_optional(1));
573 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
576 AttrBuilder ArgAttrBuilder(Ctx);
578 ArgAttrBuilder.addAttribute(AK);
580 Attrs = Attrs.addRetAttribute(Ctx, Attribute::NoUndef);
581 Attrs = Attrs.addRetAttribute(Ctx, Attribute::NoAlias);
582 Attrs = Attrs.addParamAttribute(Ctx, 0, Attribute::NoUndef);
583 if (LibcallImpl == RTLIB::impl_calloc)
584 Attrs = Attrs.addParamAttribute(Ctx, 1, Attribute::NoUndef);
590 if (LibcallImpl == RTLIB::impl_calloc)
595 case RTLIB::impl_free: {
597 AttrBuilder FuncAttrBuilder(Ctx);
599 FuncAttrBuilder.addAttribute(Attr);
602 FuncAttrBuilder.addAttribute(
"alloc-family",
"malloc");
605 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
608 AttrBuilder ArgAttrBuilder(Ctx);
609 ArgAttrBuilder.addAttribute(Attribute::NoUndef);
610 ArgAttrBuilder.addAttribute(Attribute::AllocatedPointer);
612 Attrs = Attrs.addParamAttributes(Ctx, 0, ArgAttrBuilder);
619 case RTLIB::impl___aeabi_idivmod:
620 case RTLIB::impl___aeabi_uidivmod:
621 case RTLIB::impl___aeabi_ldivmod:
622 case RTLIB::impl___aeabi_uldivmod:
623 case RTLIB::impl___rt_sdiv:
624 case RTLIB::impl___rt_udiv:
625 case RTLIB::impl___rt_sdiv64:
626 case RTLIB::impl___rt_udiv64:
627 case RTLIB::impl___divmodqi4:
628 case RTLIB::impl___udivmodqi4:
629 case RTLIB::impl___divmodhi4:
630 case RTLIB::impl___udivmodhi4:
631 case RTLIB::impl_avr___divmodsi4:
632 case RTLIB::impl_avr___udivmodsi4: {
634 AttrBuilder FuncAttrBuilder(Ctx);
636 FuncAttrBuilder.addAttribute(Attr);
638 return {FuncTy, Attrs.addFnAttributes(Ctx, FuncAttrBuilder)};
640 case RTLIB::impl_sqrtf:
641 case RTLIB::impl_sqrt: {
642 AttrBuilder FuncAttrBuilder(Ctx);
645 FuncAttrBuilder.addAttribute(Attr);
649 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
655 Attrs = Attrs.addRetAttribute(
658 return {FuncTy, Attrs};
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)
static LLVM_ABI Attribute getWithNoFPClass(LLVMContext &Context, FPClassTest Mask)
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.
static CaptureInfo none()
Create CaptureInfo that does not capture any components of the pointer.
A parsed version of the target data layout string in and methods for querying it.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
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.
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)
static MemoryEffectsBase errnoMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
static MemoryEffectsBase none()
A Module instance is used to store all the information related to an LLVM module.
Class to represent pointers.
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.
static LLVM_ABI ArrayRef< RTLIB::RuntimeLibrary > getDefaultRuntimeLibraries(const Triple &TT)
Return the runtime libraries enabled by default for TT.
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 LLVM_ABI void initBoolExtensionsForTriple(bool &ShouldZExtBoolParam, bool &ShouldZExtBoolReturn, const Triple &T)
Determine whether bool parameters and returns need zeroext on T.
RuntimeLibcallsInfo()=default
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...