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_MASKED_VECTOR_LIBCALL_MAPPING
26#define GET_SET_TARGET_RUNTIME_LIBCALL_SETS
27#define DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
28#define GET_RUNTIME_LIBCALL_INTRINSIC_TO_LIBCALL
29#include "llvm/IR/RuntimeLibcalls.inc"
36 return RuntimeLibrary::accelerate;
38 return RuntimeLibrary::darwin_libsystem_m;
40 return RuntimeLibrary::libmvec;
42 return RuntimeLibrary::massv;
44 return RuntimeLibrary::svml;
46 return RuntimeLibrary::sleefgnuabi;
48 return RuntimeLibrary::armpl;
50 return RuntimeLibrary::amdlibm;
60 : LongDoubleFmt(LDblFormat.value_or(TT.getDefaultLongDoubleFormat())) {
64 ExceptionModel = TT.getDefaultExceptionHandling();
66 initLibcalls(TT, ExceptionModel,
FloatABI, ABIName, LongDoubleFmt);
79 M.getFloatABI(), M.getLongDoubleFormat(), ABIName,
82RTLIB::Libcall RuntimeLibcallsInfo::selectLongDoubleLibcall(
83 RTLIB::Libcall F80, RTLIB::Libcall F128, RTLIB::Libcall PPCF128)
const {
84 switch (LongDoubleFmt) {
96 return RTLIB::UNKNOWN_LIBCALL;
102bool RuntimeLibcallsInfo::isLibraryAvailable(RuntimeLibrary Library)
const {
108void RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(
115 llvm::fill(LibcallImplCallingConvs, DefaultCC);
118 if (isLibraryAvailable(Library))
119 setAvailableLibraryLibcalls(Library, TT, ExceptionModel, FloatABI,
126void RuntimeLibcallsInfo::initLibcalls(
const Triple &TT,
131 setTargetRuntimeLibcallSets(TT, ExceptionModel, FloatABI, ABIName,
136iota_range<RTLIB::LibcallImpl>
137RuntimeLibcallsInfo::libcallImplNameHit(uint16_t NameOffsetEntry,
138 uint16_t StrOffset) {
140 for (uint16_t Entry :
ArrayRef(RuntimeLibcallNameOffsetTable)
141 .drop_front(NameOffsetEntry + 1)) {
142 if (Entry != StrOffset)
147 RTLIB::LibcallImpl ImplStart =
static_cast<RTLIB::LibcallImpl
>(
148 &RuntimeLibcallNameOffsetTable[NameOffsetEntry] -
149 &RuntimeLibcallNameOffsetTable[0]);
151 static_cast<RTLIB::LibcallImpl
>(ImplStart + NumAliases));
154bool RuntimeLibcallsInfo::isAAPCS_ABI(
const Triple &TT, StringRef ABIName) {
160 bool &ShouldExtI32Return,
161 bool &ShouldSignExtI32Param,
162 bool &ShouldSignExtI32Return,
164 ShouldExtI32Param = ShouldExtI32Return =
false;
165 ShouldSignExtI32Param = ShouldSignExtI32Return =
false;
171 ShouldExtI32Param =
true;
172 ShouldExtI32Return =
true;
176 if (
T.isLoongArch() ||
T.isMIPS() ||
T.isRISCV64()) {
177 ShouldSignExtI32Param =
true;
181 if (
T.isLoongArch() ||
T.isRISCV64()) {
182 ShouldSignExtI32Return =
true;
190 return DL.getIndexType(Ctx, 0);
195 Attribute::NoCallback, Attribute::NoFree, Attribute::NoSync,
196 Attribute::NoUnwind, Attribute::WillReturn};
215static std::pair<Type *, Attribute>
306std::pair<FunctionType *, AttributeList>
309 RTLIB::LibcallImpl LibcallImpl)
const {
310 const FuncArgTypeID *ProtoTypes =
311 &SignatureTable[SignatureOffset[LibcallImpl]];
313 if (ProtoTypes[0] == NoFuncArgType)
322 Attrs = Attrs.addRetAttribute(Ctx,
RetAttr);
324 Type *LastTy = RetTy, *ArgTy;
327 bool IsVarArg =
false;
329 for (FuncArgTypeID TyID = ProtoTypes[Idx]; TyID != NoFuncArgType;
330 TyID = ProtoTypes[++Idx]) {
334 assert(ProtoTypes[Idx + 1] == NoFuncArgType);
344 ProtoTypes[Idx], Ctx,
DL, IntBits, LongDoubleFmt);
350 if (ArgAttr.isValid())
351 Attrs = Attrs.addParamAttribute(Ctx, Idx - 1, ArgAttr);
354 if (RetTy->isVectorTy()) {
355 AttrBuilder FuncAttrBuilder(Ctx);
357 FuncAttrBuilder.addAttribute(Attr);
358 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
364std::pair<FunctionType *, AttributeList>
367 RTLIB::LibcallImpl LibcallImpl)
const {
369 Attribute::NoUnwind, Attribute::WillReturn};
371 Attribute::NoAlias, Attribute::WriteOnly, Attribute::NonNull};
373 switch (LibcallImpl) {
375 case RTLIB::impl___sincos_stret:
376 case RTLIB::impl___sincosf_stret: {
377 if (!darwinHasSinCosStret(TT))
380 Type *ScalarTy = LibcallImpl == RTLIB::impl___sincosf_stret
384 AttrBuilder FuncAttrBuilder(Ctx);
386 FuncAttrBuilder.addAttribute(Attr);
389 TT.isX86_32() || ((TT.isARM() || TT.isThumb()) &&
396 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
399 AttrBuilder AttrBuilder(Ctx);
401 AttrBuilder.addStructRetAttr(StructTy);
402 AttrBuilder.addAlignmentAttr(
DL.getABITypeAlign(StructTy));
406 return {FuncTy, Attrs.addParamAttributes(Ctx, 0, AttrBuilder)};
410 LibcallImpl == RTLIB::impl___sincosf_stret && TT.isX86_64()
416 case RTLIB::impl_malloc:
417 case RTLIB::impl_calloc: {
418 AttrBuilder FuncAttrBuilder(Ctx);
420 FuncAttrBuilder.addAttribute(Attr);
421 FuncAttrBuilder.addAttribute(Attribute::NoFree);
424 if (LibcallImpl == RTLIB::impl_malloc)
428 FuncAttrBuilder.addAllocKindAttr(AllocKind);
429 FuncAttrBuilder.addAttribute(
"alloc-family",
"malloc");
430 FuncAttrBuilder.addAllocSizeAttr(0, LibcallImpl == RTLIB::impl_malloc
432 : std::make_optional(1));
435 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
438 AttrBuilder ArgAttrBuilder(Ctx);
440 ArgAttrBuilder.addAttribute(AK);
442 Attrs = Attrs.addRetAttribute(Ctx, Attribute::NoUndef);
443 Attrs = Attrs.addRetAttribute(Ctx, Attribute::NoAlias);
444 Attrs = Attrs.addParamAttribute(Ctx, 0, Attribute::NoUndef);
445 if (LibcallImpl == RTLIB::impl_calloc)
446 Attrs = Attrs.addParamAttribute(Ctx, 1, Attribute::NoUndef);
452 if (LibcallImpl == RTLIB::impl_calloc)
457 case RTLIB::impl_free: {
459 AttrBuilder FuncAttrBuilder(Ctx);
461 FuncAttrBuilder.addAttribute(Attr);
464 FuncAttrBuilder.addAttribute(
"alloc-family",
"malloc");
467 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
470 AttrBuilder ArgAttrBuilder(Ctx);
471 ArgAttrBuilder.addAttribute(Attribute::NoUndef);
472 ArgAttrBuilder.addAttribute(Attribute::AllocatedPointer);
474 Attrs = Attrs.addParamAttributes(Ctx, 0, ArgAttrBuilder);
481 case RTLIB::impl___aeabi_idivmod:
482 case RTLIB::impl___aeabi_uidivmod:
483 case RTLIB::impl___aeabi_ldivmod:
484 case RTLIB::impl___aeabi_uldivmod:
485 case RTLIB::impl___rt_sdiv:
486 case RTLIB::impl___rt_udiv:
487 case RTLIB::impl___rt_sdiv64:
488 case RTLIB::impl___rt_udiv64: {
495 switch (LibcallImpl) {
496 case RTLIB::impl___aeabi_idivmod:
497 case RTLIB::impl___rt_sdiv:
501 case RTLIB::impl___aeabi_uidivmod:
502 case RTLIB::impl___rt_udiv:
506 case RTLIB::impl___aeabi_ldivmod:
507 case RTLIB::impl___rt_sdiv64:
511 case RTLIB::impl___aeabi_uldivmod:
512 case RTLIB::impl___rt_udiv64:
524 AttrBuilder FuncAttrBuilder(Ctx);
526 FuncAttrBuilder.addAttribute(Attr);
530 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
533 Attrs = Attrs.addRetAttribute(Ctx, Attribute::InReg);
534 Attrs = Attrs.addParamAttribute(Ctx, 0, ExtKind);
535 Attrs = Attrs.addParamAttribute(Ctx, 1, ExtKind);
537 return {FuncTy, Attrs};
539 case RTLIB::impl_sqrtf:
540 case RTLIB::impl_sqrt: {
541 AttrBuilder FuncAttrBuilder(Ctx);
544 FuncAttrBuilder.addAttribute(Attr);
548 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
554 Attrs = Attrs.addRetAttribute(
557 return {FuncTy, Attrs};
564 if (!FuncTy || FuncTy->getNumParams() == 0 ||
565 !FuncTy->getParamType(0)->isVectorTy())
566 return {FuncTy, Attrs};
568 Type *VecTy = FuncTy->getParamType(0);
569 AttrBuilder ArgAttrBuilder(Ctx);
571 ArgAttrBuilder.addAttribute(AK);
572 ArgAttrBuilder.addAlignmentAttr(
DL.getABITypeAlign(VecTy));
574 bool HasPtrArg =
false;
575 for (
auto [Idx, ParamTy] :
enumerate(FuncTy->params())) {
576 if (ParamTy->isPointerTy()) {
577 Attrs = Attrs.addParamAttributes(Ctx, Idx, ArgAttrBuilder);
583 AttrBuilder FuncAttrBuilder(Ctx);
585 FuncAttrBuilder.addAttribute(Attr);
587 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
590 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 std::pair< Type *, Attribute > convertToIRTypeAndAttr(FuncArgTypeID ID, LLVMContext &Ctx, const DataLayout &DL, unsigned IntBits, LongDoubleFormat LdblFormat)
static Type * getLongDoubleType(LLVMContext &Ctx, LongDoubleFormat Format)
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 RuntimeLibrary getVectorRuntimeLibrary(VectorLibrary VecLib)
static constexpr Attribute::AttrKind CommonFnAttrs[]
Functions, function parameters, and return types can have attributes to indicate how they should be t...
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static LLVM_ABI Attribute getWithNoFPClass(LLVMContext &Context, FPClassTest Mask)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
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 * 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 * 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)
#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.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
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.
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...
RuntimeLibcallsInfo()=default
unsigned getIntSize(const Triple &TT) const
Get size of a C-level int or unsigned int, in bits.
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...