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,
82bool RuntimeLibcallsInfo::isLibraryAvailable(RuntimeLibrary Library)
const {
90void RuntimeLibcallsInfo::initLibcalls(
const Triple &TT,
95 setTargetRuntimeLibcallSets(TT, ExceptionModel,
FloatABI, ABIName,
101RuntimeLibcallsInfo::libcallImplNameHit(
uint16_t NameOffsetEntry,
105 .drop_front(NameOffsetEntry + 1)) {
106 if (Entry != StrOffset)
111 RTLIB::LibcallImpl ImplStart =
static_cast<RTLIB::LibcallImpl
>(
112 &RuntimeLibcallNameOffsetTable[NameOffsetEntry] -
113 &RuntimeLibcallNameOffsetTable[0]);
115 static_cast<RTLIB::LibcallImpl
>(ImplStart + NumAliases));
118bool RuntimeLibcallsInfo::isAAPCS_ABI(
const Triple &TT, StringRef ABIName) {
127 return DL.getIndexType(Ctx, 0);
132 Attribute::NoCallback, Attribute::NoFree, Attribute::NoSync,
133 Attribute::NoUnwind, Attribute::WillReturn};
152static std::pair<Type *, Attribute>
154 unsigned IntBits,
Type *LongDoubleTy) {
233std::pair<FunctionType *, AttributeList>
236 RTLIB::LibcallImpl LibcallImpl)
const {
238 const FuncArgTypeID *ProtoTypes = &SignatureTable[SignatureOffset[LC]];
240 if (ProtoTypes[0] == NoFuncArgType)
250 Attrs = Attrs.addRetAttribute(Ctx,
RetAttr);
252 Type *LastTy = RetTy, *ArgTy;
255 bool IsVarArg =
false;
257 for (FuncArgTypeID TyID = ProtoTypes[Idx]; TyID != NoFuncArgType;
258 TyID = ProtoTypes[++Idx]) {
262 assert(ProtoTypes[Idx + 1] == NoFuncArgType);
272 ProtoTypes[Idx], Ctx,
DL, IntBits, LongDoubleTy);
278 if (ArgAttr.isValid())
279 Attrs = Attrs.addParamAttribute(Ctx, Idx - 1, ArgAttr);
282 if (RetTy->isVectorTy()) {
283 AttrBuilder FuncAttrBuilder(Ctx);
285 FuncAttrBuilder.addAttribute(Attr);
286 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
292std::pair<FunctionType *, AttributeList>
295 RTLIB::LibcallImpl LibcallImpl)
const {
297 Attribute::NoUnwind, Attribute::WillReturn};
299 Attribute::NoAlias, Attribute::WriteOnly, Attribute::NonNull};
301 switch (LibcallImpl) {
302 case RTLIB::impl___sincos_stret:
303 case RTLIB::impl___sincosf_stret: {
304 if (!darwinHasSinCosStret(TT))
307 Type *ScalarTy = LibcallImpl == RTLIB::impl___sincosf_stret
311 AttrBuilder FuncAttrBuilder(Ctx);
313 FuncAttrBuilder.addAttribute(Attr);
316 TT.isX86_32() || ((TT.isARM() || TT.isThumb()) &&
323 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
326 AttrBuilder AttrBuilder(Ctx);
328 AttrBuilder.addStructRetAttr(StructTy);
329 AttrBuilder.addAlignmentAttr(
DL.getABITypeAlign(StructTy));
333 return {FuncTy, Attrs.addParamAttributes(Ctx, 0, AttrBuilder)};
337 LibcallImpl == RTLIB::impl___sincosf_stret && TT.isX86_64()
343 case RTLIB::impl_malloc:
344 case RTLIB::impl_calloc: {
345 AttrBuilder FuncAttrBuilder(Ctx);
347 FuncAttrBuilder.addAttribute(Attr);
348 FuncAttrBuilder.addAttribute(Attribute::NoFree);
351 if (LibcallImpl == RTLIB::impl_malloc)
355 FuncAttrBuilder.addAllocKindAttr(AllocKind);
356 FuncAttrBuilder.addAttribute(
"alloc-family",
"malloc");
357 FuncAttrBuilder.addAllocSizeAttr(0, LibcallImpl == RTLIB::impl_malloc
359 : std::make_optional(1));
362 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
365 AttrBuilder ArgAttrBuilder(Ctx);
367 ArgAttrBuilder.addAttribute(AK);
369 Attrs = Attrs.addRetAttribute(Ctx, Attribute::NoUndef);
370 Attrs = Attrs.addRetAttribute(Ctx, Attribute::NoAlias);
371 Attrs = Attrs.addParamAttribute(Ctx, 0, Attribute::NoUndef);
372 if (LibcallImpl == RTLIB::impl_calloc)
373 Attrs = Attrs.addParamAttribute(Ctx, 1, Attribute::NoUndef);
379 if (LibcallImpl == RTLIB::impl_calloc)
384 case RTLIB::impl_free: {
386 AttrBuilder FuncAttrBuilder(Ctx);
388 FuncAttrBuilder.addAttribute(Attr);
391 FuncAttrBuilder.addAttribute(
"alloc-family",
"malloc");
394 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
397 AttrBuilder ArgAttrBuilder(Ctx);
398 ArgAttrBuilder.addAttribute(Attribute::NoUndef);
399 ArgAttrBuilder.addAttribute(Attribute::AllocatedPointer);
401 Attrs = Attrs.addParamAttributes(Ctx, 0, ArgAttrBuilder);
408 case RTLIB::impl___aeabi_idivmod:
409 case RTLIB::impl___aeabi_uidivmod:
410 case RTLIB::impl___aeabi_ldivmod:
411 case RTLIB::impl___aeabi_uldivmod:
412 case RTLIB::impl___rt_sdiv:
413 case RTLIB::impl___rt_udiv:
414 case RTLIB::impl___rt_sdiv64:
415 case RTLIB::impl___rt_udiv64: {
422 switch (LibcallImpl) {
423 case RTLIB::impl___aeabi_idivmod:
424 case RTLIB::impl___rt_sdiv:
428 case RTLIB::impl___aeabi_uidivmod:
429 case RTLIB::impl___rt_udiv:
433 case RTLIB::impl___aeabi_ldivmod:
434 case RTLIB::impl___rt_sdiv64:
438 case RTLIB::impl___aeabi_uldivmod:
439 case RTLIB::impl___rt_udiv64:
451 AttrBuilder FuncAttrBuilder(Ctx);
453 FuncAttrBuilder.addAttribute(Attr);
457 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
460 Attrs = Attrs.addRetAttribute(Ctx, Attribute::InReg);
461 Attrs = Attrs.addParamAttribute(Ctx, 0, ExtKind);
462 Attrs = Attrs.addParamAttribute(Ctx, 1, ExtKind);
464 return {FuncTy, Attrs};
466 case RTLIB::impl_sqrtf:
467 case RTLIB::impl_sqrt: {
468 AttrBuilder FuncAttrBuilder(Ctx);
471 FuncAttrBuilder.addAttribute(Attr);
475 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
481 Attrs = Attrs.addRetAttribute(
484 return {FuncTy, Attrs};
491 if (!FuncTy || FuncTy->getNumParams() == 0 ||
492 !FuncTy->getParamType(0)->isVectorTy())
493 return {FuncTy, Attrs};
495 Type *VecTy = FuncTy->getParamType(0);
496 AttrBuilder ArgAttrBuilder(Ctx);
498 ArgAttrBuilder.addAttribute(AK);
499 ArgAttrBuilder.addAlignmentAttr(
DL.getABITypeAlign(VecTy));
501 bool HasPtrArg =
false;
502 for (
auto [Idx, ParamTy] :
enumerate(FuncTy->params())) {
503 if (ParamTy->isPointerTy()) {
504 Attrs = Attrs.addParamAttributes(Ctx, Idx, ArgAttrBuilder);
510 AttrBuilder FuncAttrBuilder(Ctx);
512 FuncAttrBuilder.addAttribute(Attr);
514 Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
517 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 * 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 std::pair< Type *, Attribute > convertToIRTypeAndAttr(FuncArgTypeID ID, LLVMContext &Ctx, const DataLayout &DL, unsigned IntBits, Type *LongDoubleTy)
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 argumentOrErrnoMemOnly(ModRefInfo ArgMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=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="")
This is an optimization pass for GlobalISel generic memory operations.
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.
LLVM_ABI std::pair< FunctionType *, AttributeList > getFunctionTy(LLVMContext &Ctx, const Triple &TT, const DataLayout &DL, RTLIB::LibcallImpl LibcallImpl) const
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...
static RTLIB::Libcall getLibcallFromImpl(RTLIB::LibcallImpl Impl)
Return the libcall provided by Impl.