From 89e79eac508bb69af2ad10a684de1e56b467e3a0 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 7 Nov 2025 17:19:28 -0800 Subject: [PATCH 1/3] RuntimeLibcalls: Add malloc and free entries Calloc was already here, but not the others. Also add manual type information. --- llvm/include/llvm/IR/RuntimeLibcalls.td | 5 ++ llvm/lib/IR/RuntimeLibcalls.cpp | 75 +++++++++++++++++++ .../Util/DeclareRuntimeLibcalls/basic.ll | 9 +++ 3 files changed, 89 insertions(+) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index 11e6127e0741d..5a66b23051b2f 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -382,7 +382,9 @@ def MEMMOVE : RuntimeLibcall; def MEMMOVE_CHK : RuntimeLibcall; def MEMSET : RuntimeLibcall; def MEMSET_CHK : RuntimeLibcall; +def MALLOC : RuntimeLibcall; def CALLOC : RuntimeLibcall; +def FREE : RuntimeLibcall; def BZERO : RuntimeLibcall; def STRLEN : RuntimeLibcall; @@ -1101,8 +1103,11 @@ def __memcpy_chk : RuntimeLibcallImpl; def __memmove_chk : RuntimeLibcallImpl; def __memset_chk : RuntimeLibcallImpl; +def malloc : RuntimeLibcallImpl; + // DSEPass can emit calloc if it finds a pair of malloc/memset def calloc : RuntimeLibcallImpl; +def free : RuntimeLibcallImpl; } // End let IsDefault = true diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index cbe7a7b9f77f4..a5f842a5fb520 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -130,13 +130,23 @@ bool RuntimeLibcallsInfo::darwinHasExp10(const Triple &TT) { } } +/// TODO: There is really no guarantee that sizeof(size_t) is equal to the index +/// size of the default address space. This matches TargetLibraryInfo and should +/// be kept in sync. +static IntegerType *getSizeTType(LLVMContext &Ctx, const DataLayout &DL) { + return DL.getIndexType(Ctx, /*AddressSpace=*/0); +} + std::pair RuntimeLibcallsInfo::getFunctionTy(LLVMContext &Ctx, const Triple &TT, const DataLayout &DL, RTLIB::LibcallImpl LibcallImpl) const { + // TODO: NoCallback probably unsafe in general static constexpr Attribute::AttrKind CommonFnAttrs[] = { Attribute::MustProgress, Attribute::NoCallback, Attribute::NoFree, Attribute::NoSync, Attribute::NoUnwind, Attribute::WillReturn}; + static constexpr Attribute::AttrKind MemoryFnAttrs[] = { + Attribute::MustProgress, Attribute::NoUnwind, Attribute::WillReturn}; static constexpr Attribute::AttrKind CommonPtrArgAttrs[] = { Attribute::NoAlias, Attribute::WriteOnly, Attribute::NonNull}; @@ -182,6 +192,71 @@ RuntimeLibcallsInfo::getFunctionTy(LLVMContext &Ctx, const Triple &TT, return {FunctionType::get(RetTy, {ScalarTy}, false), Attrs}; } + case RTLIB::impl_malloc: + case RTLIB::impl_calloc: { + AttrBuilder FuncAttrBuilder(Ctx); + for (Attribute::AttrKind Attr : MemoryFnAttrs) + FuncAttrBuilder.addAttribute(Attr); + FuncAttrBuilder.addAttribute(Attribute::NoFree); + + AllocFnKind AllocKind = AllocFnKind::Alloc; + if (LibcallImpl == RTLIB::impl_malloc) + AllocKind |= AllocFnKind::Uninitialized; + + // TODO: Set memory attribute + FuncAttrBuilder.addAllocKindAttr(AllocKind); + FuncAttrBuilder.addAttribute("alloc-family", "malloc"); + FuncAttrBuilder.addAllocSizeAttr(0, LibcallImpl == RTLIB::impl_malloc + ? std::nullopt + : std::make_optional(1)); + + AttributeList Attrs; + Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder); + + { + AttrBuilder ArgAttrBuilder(Ctx); + for (Attribute::AttrKind AK : CommonPtrArgAttrs) + ArgAttrBuilder.addAttribute(AK); + + Attrs = Attrs.addRetAttribute(Ctx, Attribute::NoUndef); + Attrs = Attrs.addRetAttribute(Ctx, Attribute::NoAlias); + Attrs = Attrs.addParamAttribute(Ctx, 0, Attribute::NoUndef); + if (LibcallImpl == RTLIB::impl_calloc) + Attrs = Attrs.addParamAttribute(Ctx, 1, Attribute::NoUndef); + } + + IntegerType *SizeT = getSizeTType(Ctx, DL); + PointerType *PtrTy = PointerType::get(Ctx, 0); + SmallVector ArgTys = {SizeT}; + if (LibcallImpl == RTLIB::impl_calloc) + ArgTys.push_back(SizeT); + + return {FunctionType::get(PtrTy, ArgTys, false), Attrs}; + } + case RTLIB::impl_free: { + // TODO: Set memory attribute + AttrBuilder FuncAttrBuilder(Ctx); + for (Attribute::AttrKind Attr : MemoryFnAttrs) + FuncAttrBuilder.addAttribute(Attr); + + FuncAttrBuilder.addAllocKindAttr(AllocFnKind::Free); + FuncAttrBuilder.addAttribute("alloc-family", "malloc"); + + AttributeList Attrs; + Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder); + + { + AttrBuilder ArgAttrBuilder(Ctx); + ArgAttrBuilder.addAttribute(Attribute::NoUndef); + ArgAttrBuilder.addAttribute(Attribute::AllocatedPointer); + ArgAttrBuilder.addCapturesAttr(CaptureInfo::none()); + Attrs = Attrs.addParamAttributes(Ctx, 0, ArgAttrBuilder); + } + + return {FunctionType::get(Type::getVoidTy(Ctx), {PointerType::get(Ctx, 0)}, + false), + Attrs}; + } case RTLIB::impl_sqrtf: case RTLIB::impl_sqrt: { AttrBuilder FuncAttrBuilder(Ctx); diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll index db0cc24c287bc..f1a039dc033ac 100644 --- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll +++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll @@ -20,10 +20,16 @@ define float @sinf(float %x) { ; CHECK: declare void @acosf(...) +; CHECK: declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) [[CALLOC_ATTRS:#[0-9]+]] + ; CHECK: declare void @fdim(...) ; CHECK: declare void @fdimf(...) ; CHECK: declare void @fdiml(...) +; CHECK: declare void @free(ptr allocptr noundef captures(none)) [[FREE_ATTRS:#[0-9]+]] + +; CHECK: declare noalias noundef ptr @malloc(i64 noundef) [[MALLOC_ATTRS:#[0-9]+]] + ; CHECK: declare void @nan(...) ; CHECK: declare void @nanf(...) ; CHECK: declare void @nanl(...) @@ -58,3 +64,6 @@ define float @sinf(float %x) { ; CHECK: declare void @truncl(...) +; CHECK: attributes [[CALLOC_ATTRS]] = { mustprogress nofree nounwind willreturn allockind("alloc") allocsize(0,1) "alloc-family"="malloc" } +; CHECK: attributes [[FREE_ATTRS]] = { mustprogress nounwind willreturn allockind("free") "alloc-family"="malloc" } +; CHECK: attributes [[MALLOC_ATTRS]] = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) "alloc-family"="malloc" } From 12b2b363b8dea9a8eee19753d6eb8680ea23929a Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 7 Nov 2025 18:51:03 -0800 Subject: [PATCH 2/3] RuntimeLibcalls: Add more function entries from TargetLibraryInfo Script scraped dump of most functions in TargetLibraryInfo.def, with existing entries and a few special cases removed. This only adds the definitions, and doesn't add them to any system yet. Adding them in the correct places is the hard part, since it's all written as opt-out with manually written exemptions in TargetLibraryInfo. --- llvm/include/llvm/IR/RuntimeLibcalls.td | 645 ++++++++++++++++++++++++ 1 file changed, 645 insertions(+) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index 5a66b23051b2f..36dea547651c9 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -154,6 +154,8 @@ foreach FPTy = ["F32", "F64", "F80", "F128", "PPCF128"] in { def SINCOS_#FPTy : RuntimeLibcall; def REMQUO_#FPTy : RuntimeLibcall; def FDIM_#FPTy : RuntimeLibcall; + + def CABS_#FPTy : RuntimeLibcall; } foreach FPTy = [ "F32", "F64" ] in { @@ -571,6 +573,302 @@ def OBJC_RETAIN_AUTORELEASE : RuntimeLibcall; def OBJC_SYNC_ENTER : RuntimeLibcall; def OBJC_SYNC_EXIT : RuntimeLibcall; +def ABORT : RuntimeLibcall; +def ABS : RuntimeLibcall; +def ACCESS : RuntimeLibcall; +def ALIGNED_ALLOC : RuntimeLibcall; +def ATEXIT : RuntimeLibcall; +def ATOF : RuntimeLibcall; +def ATOI : RuntimeLibcall; +def ATOL : RuntimeLibcall; +def ATOLL : RuntimeLibcall; +def BCMP : RuntimeLibcall; +def BCOPY : RuntimeLibcall; +def CHMOD : RuntimeLibcall; +def CHOWN : RuntimeLibcall; +def CLEARERR : RuntimeLibcall; +def CLOSEDIR : RuntimeLibcall; +def CTERMID : RuntimeLibcall; +def CXA_ATEXIT : RuntimeLibcall; +def CXA_GUARD_ABORT : RuntimeLibcall; +def CXA_GUARD_ACQUIRE : RuntimeLibcall; +def CXA_GUARD_RELEASE : RuntimeLibcall; +def CXA_THROW : RuntimeLibcall; +def DUNDER_ISOC99_SCANF : RuntimeLibcall; +def DUNDER_ISOC99_SSCANF : RuntimeLibcall; +def DUNDER_STRDUP : RuntimeLibcall; +def DUNDER_STRNDUP : RuntimeLibcall; +def DUNDER_STRTOK_R : RuntimeLibcall; +def ENUM_VARIANT : RuntimeLibcall; +def EXECL : RuntimeLibcall; +def EXECLE : RuntimeLibcall; +def EXECLP : RuntimeLibcall; +def EXECV : RuntimeLibcall; +def EXECVE : RuntimeLibcall; +def EXECVP : RuntimeLibcall; +def EXECVPE : RuntimeLibcall; +def EXIT : RuntimeLibcall; +def FCLOSE : RuntimeLibcall; +def FDOPEN : RuntimeLibcall; +def FEOF : RuntimeLibcall; +def FERROR : RuntimeLibcall; +def FFLUSH : RuntimeLibcall; +def FFS : RuntimeLibcall; +def FFSL : RuntimeLibcall; +def FFSLL : RuntimeLibcall; +def FGETC : RuntimeLibcall; +def FGETC_UNLOCKED : RuntimeLibcall; +def FGETPOS : RuntimeLibcall; +def FGETS : RuntimeLibcall; +def FGETS_UNLOCKED : RuntimeLibcall; +def FILENO : RuntimeLibcall; +def FIPRINTF : RuntimeLibcall; +def FLOCKFILE : RuntimeLibcall; +def FLS : RuntimeLibcall; +def FLSL : RuntimeLibcall; +def FLSLL : RuntimeLibcall; +def FOPEN : RuntimeLibcall; +def FOPEN64 : RuntimeLibcall; +def FORK : RuntimeLibcall; +def FPRINTF : RuntimeLibcall; +def FPUTC : RuntimeLibcall; +def FPUTC_UNLOCKED : RuntimeLibcall; +def FPUTS : RuntimeLibcall; +def FPUTS_UNLOCKED : RuntimeLibcall; +def FREAD : RuntimeLibcall; +def FREAD_UNLOCKED : RuntimeLibcall; +def FSCANF : RuntimeLibcall; +def FSEEK : RuntimeLibcall; +def FSEEKO : RuntimeLibcall; +def FSEEKO64 : RuntimeLibcall; +def FSETPOS : RuntimeLibcall; +def FSTAT : RuntimeLibcall; +def FSTAT64 : RuntimeLibcall; +def FSTATVFS : RuntimeLibcall; +def FSTATVFS64 : RuntimeLibcall; +def FTELL : RuntimeLibcall; +def FTELLO : RuntimeLibcall; +def FTELLO64 : RuntimeLibcall; +def FTRYLOCKFILE : RuntimeLibcall; +def FUNLOCKFILE : RuntimeLibcall; +def FWRITE : RuntimeLibcall; +def FWRITE_UNLOCKED : RuntimeLibcall; +def GETC : RuntimeLibcall; +def GETCHAR : RuntimeLibcall; +def GETCHAR_UNLOCKED : RuntimeLibcall; +def GETC_UNLOCKED : RuntimeLibcall; +def GETENV : RuntimeLibcall; +def GETITIMER : RuntimeLibcall; +def GETLOGIN_R : RuntimeLibcall; +def GETPWNAM : RuntimeLibcall; +def GETS : RuntimeLibcall; +def GETTIMEOFDAY : RuntimeLibcall; +def HTONL : RuntimeLibcall; +def HTONS : RuntimeLibcall; +def IPRINTF : RuntimeLibcall; +def ISASCII : RuntimeLibcall; +def ISDIGIT : RuntimeLibcall; +def LABS : RuntimeLibcall; +def LCHOWN : RuntimeLibcall; +def LLABS : RuntimeLibcall; +def LSTAT : RuntimeLibcall; +def LSTAT64 : RuntimeLibcall; +def MEMALIGN : RuntimeLibcall; +def MEMCCPY : RuntimeLibcall; +def MEMCCPY_CHK : RuntimeLibcall; +def MEMCHR : RuntimeLibcall; +def MEMPCPY : RuntimeLibcall; +def MEMPCPY_CHK : RuntimeLibcall; +def MEMRCHR : RuntimeLibcall; +def MEMSET_PATTERN16 : RuntimeLibcall; +def MEMSET_PATTERN4 : RuntimeLibcall; +def MEMSET_PATTERN8 : RuntimeLibcall; +def MKDIR : RuntimeLibcall; +def MKTIME : RuntimeLibcall; +def MSVC_DELETE_ARRAY_PTR32 : RuntimeLibcall; +def MSVC_DELETE_ARRAY_PTR32_INT : RuntimeLibcall; +def MSVC_DELETE_ARRAY_PTR32_NOTHROW : RuntimeLibcall; +def MSVC_DELETE_ARRAY_PTR64 : RuntimeLibcall; +def MSVC_DELETE_ARRAY_PTR64_LONGLONG : RuntimeLibcall; +def MSVC_DELETE_ARRAY_PTR64_NOTHROW : RuntimeLibcall; +def MSVC_DELETE_PTR32 : RuntimeLibcall; +def MSVC_DELETE_PTR32_INT : RuntimeLibcall; +def MSVC_DELETE_PTR32_NOTHROW : RuntimeLibcall; +def MSVC_DELETE_PTR64 : RuntimeLibcall; +def MSVC_DELETE_PTR64_LONGLONG : RuntimeLibcall; +def MSVC_DELETE_PTR64_NOTHROW : RuntimeLibcall; +def MSVC_NEW_ARRAY_INT : RuntimeLibcall; +def MSVC_NEW_ARRAY_INT_NOTHROW : RuntimeLibcall; +def MSVC_NEW_ARRAY_LONGLONG : RuntimeLibcall; +def MSVC_NEW_ARRAY_LONGLONG_NOTHROW : RuntimeLibcall; +def MSVC_NEW_INT : RuntimeLibcall; +def MSVC_NEW_INT_NOTHROW : RuntimeLibcall; +def MSVC_NEW_LONGLONG : RuntimeLibcall; +def MSVC_NEW_LONGLONG_NOTHROW : RuntimeLibcall; +def NTOHL : RuntimeLibcall; +def NTOHS : RuntimeLibcall; +def OPEN : RuntimeLibcall; +def OPEN64 : RuntimeLibcall; +def OPENDIR : RuntimeLibcall; +def PCLOSE : RuntimeLibcall; +def PERROR : RuntimeLibcall; +def POPEN : RuntimeLibcall; +def POSIX_MEMALIGN : RuntimeLibcall; +def PREAD : RuntimeLibcall; +def PRINTF : RuntimeLibcall; +def PUTC : RuntimeLibcall; +def PUTCHAR : RuntimeLibcall; +def PUTCHAR_UNLOCKED : RuntimeLibcall; +def PUTC_UNLOCKED : RuntimeLibcall; +def PUTS : RuntimeLibcall; +def PVALLOC : RuntimeLibcall; +def PWRITE : RuntimeLibcall; +def QSORT : RuntimeLibcall; +def READ : RuntimeLibcall; +def READLINK : RuntimeLibcall; +def REALLOC : RuntimeLibcall; +def REALLOCARRAY : RuntimeLibcall; +def REALLOCF : RuntimeLibcall; +def REALPATH : RuntimeLibcall; +def REMOVE : RuntimeLibcall; +def RENAME : RuntimeLibcall; +def REWIND : RuntimeLibcall; +def RMDIR : RuntimeLibcall; +def SCANF : RuntimeLibcall; +def SETBUF : RuntimeLibcall; +def SETITIMER : RuntimeLibcall; +def SETVBUF : RuntimeLibcall; +def SIPRINTF : RuntimeLibcall; +def SIZE_RETURNING_NEW : RuntimeLibcall; +def SIZE_RETURNING_NEW_ALIGNED : RuntimeLibcall; +def SIZE_RETURNING_NEW_ALIGNED_HOT_COLD : RuntimeLibcall; +def SIZE_RETURNING_NEW_HOT_COLD : RuntimeLibcall; +def SMALL_FPRINTF : RuntimeLibcall; +def SMALL_PRINTF : RuntimeLibcall; +def SMALL_SPRINTF : RuntimeLibcall; +def SNPRINTF : RuntimeLibcall; +def SNPRINTF_CHK : RuntimeLibcall; +def SPRINTF : RuntimeLibcall; +def SPRINTF_CHK : RuntimeLibcall; +def SSCANF : RuntimeLibcall; +def STAT : RuntimeLibcall; +def STAT64 : RuntimeLibcall; +def STATVFS : RuntimeLibcall; +def STATVFS64 : RuntimeLibcall; +def STPCPY : RuntimeLibcall; +def STPCPY_CHK : RuntimeLibcall; +def STPNCPY : RuntimeLibcall; +def STPNCPY_CHK : RuntimeLibcall; +def STRCASECMP : RuntimeLibcall; +def STRCAT : RuntimeLibcall; +def STRCAT_CHK : RuntimeLibcall; +def STRCHR : RuntimeLibcall; +def STRCMP : RuntimeLibcall; +def STRCOLL : RuntimeLibcall; +def STRCPY : RuntimeLibcall; +def STRCPY_CHK : RuntimeLibcall; +def STRCSPN : RuntimeLibcall; +def STRDUP : RuntimeLibcall; +def STRLCAT : RuntimeLibcall; +def STRLCAT_CHK : RuntimeLibcall; +def STRLCPY : RuntimeLibcall; +def STRLCPY_CHK : RuntimeLibcall; +def STRLEN_CHK : RuntimeLibcall; +def STRNCASECMP : RuntimeLibcall; +def STRNCAT : RuntimeLibcall; +def STRNCAT_CHK : RuntimeLibcall; +def STRNCMP : RuntimeLibcall; +def STRNCPY : RuntimeLibcall; +def STRNCPY_CHK : RuntimeLibcall; +def STRNDUP : RuntimeLibcall; +def STRNLEN : RuntimeLibcall; +def STRPBRK : RuntimeLibcall; +def STRRCHR : RuntimeLibcall; +def STRSPN : RuntimeLibcall; +def STRSTR : RuntimeLibcall; +def STRTOD : RuntimeLibcall; +def STRTOF : RuntimeLibcall; +def STRTOK : RuntimeLibcall; +def STRTOK_R : RuntimeLibcall; +def STRTOL : RuntimeLibcall; +def STRTOLD : RuntimeLibcall; +def STRTOLL : RuntimeLibcall; +def STRTOUL : RuntimeLibcall; +def STRTOULL : RuntimeLibcall; +def STRXFRM : RuntimeLibcall; +def SYSTEM : RuntimeLibcall; +def TERMINATE : RuntimeLibcall; +def TIMES : RuntimeLibcall; +def TMPFILE : RuntimeLibcall; +def TMPFILE64 : RuntimeLibcall; +def TOASCII : RuntimeLibcall; +def UNAME : RuntimeLibcall; +def UNDER_IO_GETC : RuntimeLibcall; +def UNDER_IO_PUTC : RuntimeLibcall; +def UNGETC : RuntimeLibcall; +def UNLINK : RuntimeLibcall; +def UNSETENV : RuntimeLibcall; +def UTIME : RuntimeLibcall; +def UTIMES : RuntimeLibcall; +def VALLOC : RuntimeLibcall; +def VEC_CALLOC : RuntimeLibcall; +def VEC_FREE : RuntimeLibcall; +def VEC_MALLOC : RuntimeLibcall; +def VEC_REALLOC : RuntimeLibcall; +def VFPRINTF : RuntimeLibcall; +def VFSCANF : RuntimeLibcall; +def VPRINTF : RuntimeLibcall; +def VSCANF : RuntimeLibcall; +def VSNPRINTF : RuntimeLibcall; +def VSNPRINTF_CHK : RuntimeLibcall; +def VSPRINTF : RuntimeLibcall; +def VSPRINTF_CHK : RuntimeLibcall; +def VSSCANF : RuntimeLibcall; +def WCSLEN : RuntimeLibcall; +def WRITE : RuntimeLibcall; +def ZDAPV : RuntimeLibcall; +def ZDAPVJ : RuntimeLibcall; +def ZDAPVJST11ALIGN_VAL_T : RuntimeLibcall; +def ZDAPVM : RuntimeLibcall; +def ZDAPVMST11ALIGN_VAL_T : RuntimeLibcall; +def ZDAPVRKST9NOTHROW_T : RuntimeLibcall; +def ZDAPVST11ALIGN_VAL_T : RuntimeLibcall; +def ZDAPVST11ALIGN_VAL_TRKST9NOTHROW_T : RuntimeLibcall; +def ZDLPV : RuntimeLibcall; +def ZDLPVJ : RuntimeLibcall; +def ZDLPVJST11ALIGN_VAL_T : RuntimeLibcall; +def ZDLPVM : RuntimeLibcall; +def ZDLPVMST11ALIGN_VAL_T : RuntimeLibcall; +def ZDLPVRKST9NOTHROW_T : RuntimeLibcall; +def ZDLPVST11ALIGN_VAL_T : RuntimeLibcall; +def ZDLPVST11ALIGN_VAL_TRKST9NOTHROW_T : RuntimeLibcall; +def ZNAJ : RuntimeLibcall; +def ZNAJRKST9NOTHROW_T : RuntimeLibcall; +def ZNAJST11ALIGN_VAL_T : RuntimeLibcall; +def ZNAJST11ALIGN_VAL_TRKST9NOTHROW_T : RuntimeLibcall; +def ZNAM : RuntimeLibcall; +def ZNAM12__HOT_COLD_T : RuntimeLibcall; +def ZNAMRKST9NOTHROW_T : RuntimeLibcall; +def ZNAMRKST9NOTHROW_T12__HOT_COLD_T : RuntimeLibcall; +def ZNAMST11ALIGN_VAL_T : RuntimeLibcall; +def ZNAMST11ALIGN_VAL_T12__HOT_COLD_T : RuntimeLibcall; +def ZNAMST11ALIGN_VAL_TRKST9NOTHROW_T : RuntimeLibcall; +def ZNAMST11ALIGN_VAL_TRKST9NOTHROW_T12__HOT_COLD_T : RuntimeLibcall; +def ZNWJ : RuntimeLibcall; +def ZNWJRKST9NOTHROW_T : RuntimeLibcall; +def ZNWJST11ALIGN_VAL_T : RuntimeLibcall; +def ZNWJST11ALIGN_VAL_TRKST9NOTHROW_T : RuntimeLibcall; +def ZNWM : RuntimeLibcall; +def ZNWM12__HOT_COLD_T : RuntimeLibcall; +def ZNWMRKST9NOTHROW_T : RuntimeLibcall; +def ZNWMRKST9NOTHROW_T12__HOT_COLD_T : RuntimeLibcall; +def ZNWMST11ALIGN_VAL_T : RuntimeLibcall; +def ZNWMST11ALIGN_VAL_T12__HOT_COLD_T : RuntimeLibcall; +def ZNWMST11ALIGN_VAL_TRKST9NOTHROW_T : RuntimeLibcall; +def ZNWMST11ALIGN_VAL_TRKST9NOTHROW_T12__HOT_COLD_T : RuntimeLibcall; +def KMPC_ALLOC_SHARED : RuntimeLibcall; +def KMPC_FREE_SHARED : RuntimeLibcall; + //-------------------------------------------------------------------- // Global variable references //-------------------------------------------------------------------- @@ -1120,6 +1418,353 @@ def exp10l_ppcf128 : RuntimeLibcallImpl; // Stack Protector Fail def __stack_chk_fail : RuntimeLibcallImpl; +//-------------------------------------------------------------------- +// Other functions from TargetLibraryInfo +// +// TODO: These need to be organized by library and added to relevant +// systems. +/// +// -------------------------------------------------------------------- + +def __2_YAPAXI_Z : RuntimeLibcallImpl; +def __2_YAPAXIABUnothrow_t_std___Z + : RuntimeLibcallImpl; +def __2_YAPEAX_K_Z : RuntimeLibcallImpl; +def __2_YAPEAX_KAEBUnothrow_t_std___Z + : RuntimeLibcallImpl; +def __3_YAXPAX_Z : RuntimeLibcallImpl; +def __3_YAXPAXABUnothrow_t_std___Z + : RuntimeLibcallImpl; +def __3_YAXPAXI_Z : RuntimeLibcallImpl; +def __3_YAXPEAX_Z : RuntimeLibcallImpl; +def __3_YAXPEAXAEBUnothrow_t_std___Z + : RuntimeLibcallImpl; +def __3_YAXPEAX_K_Z + : RuntimeLibcallImpl; +def ___U_YAPAXI_Z : RuntimeLibcallImpl; +def ___U_YAPAXIABUnothrow_t_std___Z + : RuntimeLibcallImpl; +def ___U_YAPEAX_K_Z + : RuntimeLibcallImpl; +def ___U_YAPEAX_KAEBUnothrow_t_std___Z + : RuntimeLibcallImpl; +def ___V_YAXPAX_Z + : RuntimeLibcallImpl; +def ___V_YAXPAXABUnothrow_t_std___Z + : RuntimeLibcallImpl; +def ___V_YAXPAXI_Z + : RuntimeLibcallImpl; +def ___V_YAXPEAX_Z + : RuntimeLibcallImpl; +def ___V_YAXPEAXAEBUnothrow_t_std___Z + : RuntimeLibcallImpl; +def ___V_YAXPEAX_K_Z + : RuntimeLibcallImpl; +def _IO_getc : RuntimeLibcallImpl; +def _IO_putc : RuntimeLibcallImpl; +def _ZdaPv : RuntimeLibcallImpl; +def _ZdaPvRKSt9nothrow_t : RuntimeLibcallImpl; +def _ZdaPvSt11align_val_t : RuntimeLibcallImpl; +def _ZdaPvSt11align_val_tRKSt9nothrow_t + : RuntimeLibcallImpl; +def _ZdaPvj : RuntimeLibcallImpl; +def _ZdaPvjSt11align_val_t : RuntimeLibcallImpl; +def _ZdaPvm : RuntimeLibcallImpl; +def _ZdaPvmSt11align_val_t : RuntimeLibcallImpl; +def _ZdlPv : RuntimeLibcallImpl; +def _ZdlPvRKSt9nothrow_t : RuntimeLibcallImpl; +def _ZdlPvSt11align_val_t : RuntimeLibcallImpl; +def _ZdlPvSt11align_val_tRKSt9nothrow_t + : RuntimeLibcallImpl; +def _ZdlPvj : RuntimeLibcallImpl; +def _ZdlPvjSt11align_val_t : RuntimeLibcallImpl; +def _ZdlPvm : RuntimeLibcallImpl; +def _ZdlPvmSt11align_val_t : RuntimeLibcallImpl; +def _Znaj : RuntimeLibcallImpl; +def _ZnajRKSt9nothrow_t : RuntimeLibcallImpl; +def _ZnajSt11align_val_t : RuntimeLibcallImpl; +def _ZnajSt11align_val_tRKSt9nothrow_t + : RuntimeLibcallImpl; +def _Znam : RuntimeLibcallImpl; +def _Znam12__hot_cold_t : RuntimeLibcallImpl; +def _ZnamRKSt9nothrow_t : RuntimeLibcallImpl; +def _ZnamRKSt9nothrow_t12__hot_cold_t + : RuntimeLibcallImpl; +def _ZnamSt11align_val_t : RuntimeLibcallImpl; +def _ZnamSt11align_val_t12__hot_cold_t + : RuntimeLibcallImpl; +def _ZnamSt11align_val_tRKSt9nothrow_t + : RuntimeLibcallImpl; +def _ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t + : RuntimeLibcallImpl; +def _Znwj : RuntimeLibcallImpl; +def _ZnwjRKSt9nothrow_t : RuntimeLibcallImpl; +def _ZnwjSt11align_val_t : RuntimeLibcallImpl; +def _ZnwjSt11align_val_tRKSt9nothrow_t + : RuntimeLibcallImpl; +def _Znwm : RuntimeLibcallImpl; +def _Znwm12__hot_cold_t : RuntimeLibcallImpl; +def _ZnwmRKSt9nothrow_t : RuntimeLibcallImpl; +def _ZnwmRKSt9nothrow_t12__hot_cold_t + : RuntimeLibcallImpl; +def _ZnwmSt11align_val_t : RuntimeLibcallImpl; +def _ZnwmSt11align_val_t12__hot_cold_t + : RuntimeLibcallImpl; +def _ZnwmSt11align_val_tRKSt9nothrow_t + : RuntimeLibcallImpl; +def _ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t + : RuntimeLibcallImpl; +def __size_returning_new : RuntimeLibcallImpl; +def __size_returning_new_hot_cold + : RuntimeLibcallImpl; +def __size_returning_new_aligned + : RuntimeLibcallImpl; +def __size_returning_new_aligned_hot_cold + : RuntimeLibcallImpl; +def __cxa_atexit : RuntimeLibcallImpl; +def atexit : RuntimeLibcallImpl; +def abort : RuntimeLibcallImpl; +def exit : RuntimeLibcallImpl; +def _Exit : RuntimeLibcallImpl; +def _ZSt9terminatev : RuntimeLibcallImpl; +def __cxa_throw : RuntimeLibcallImpl; +def __cxa_guard_abort : RuntimeLibcallImpl; +def __cxa_guard_acquire : RuntimeLibcallImpl; +def __cxa_guard_release : RuntimeLibcallImpl; +def __isoc99_scanf : RuntimeLibcallImpl; +def __isoc99_sscanf : RuntimeLibcallImpl; +def __kmpc_alloc_shared : RuntimeLibcallImpl; +def __kmpc_free_shared : RuntimeLibcallImpl; +def __memccpy_chk : RuntimeLibcallImpl; +def __mempcpy_chk : RuntimeLibcallImpl; +def __small_fprintf : RuntimeLibcallImpl; +def __small_printf : RuntimeLibcallImpl; +def __small_sprintf : RuntimeLibcallImpl; +def __snprintf_chk : RuntimeLibcallImpl; +def __sprintf_chk : RuntimeLibcallImpl; +def __stpcpy_chk : RuntimeLibcallImpl; +def __stpncpy_chk : RuntimeLibcallImpl; +def __strcat_chk : RuntimeLibcallImpl; +def __strcpy_chk : RuntimeLibcallImpl; +def __strdup : RuntimeLibcallImpl; +def __strlcat_chk : RuntimeLibcallImpl; +def __strlcpy_chk : RuntimeLibcallImpl; +def __strlen_chk : RuntimeLibcallImpl; +def __strncat_chk : RuntimeLibcallImpl; +def __strncpy_chk : RuntimeLibcallImpl; +def __strndup : RuntimeLibcallImpl; +def __strtok_r : RuntimeLibcallImpl; +def __vsnprintf_chk : RuntimeLibcallImpl; +def __vsprintf_chk : RuntimeLibcallImpl; +def abs : RuntimeLibcallImpl; +def access : RuntimeLibcallImpl; +def aligned_alloc : RuntimeLibcallImpl; +def atof : RuntimeLibcallImpl; +def atoi : RuntimeLibcallImpl; +def atol : RuntimeLibcallImpl; +def atoll : RuntimeLibcallImpl; +def bcmp : RuntimeLibcallImpl; +def bcopy : RuntimeLibcallImpl; +def cabs : RuntimeLibcallImpl; +def cabsf : RuntimeLibcallImpl; +defm cabsl : LibmLongDoubleLibCall; +def chmod : RuntimeLibcallImpl; +def chown : RuntimeLibcallImpl; +def clearerr : RuntimeLibcallImpl; +def closedir : RuntimeLibcallImpl; +def ctermid : RuntimeLibcallImpl; +def execl : RuntimeLibcallImpl; +def execle : RuntimeLibcallImpl; +def execlp : RuntimeLibcallImpl; +def execv : RuntimeLibcallImpl; +def execvP : RuntimeLibcallImpl; +def execve : RuntimeLibcallImpl; +def execvp : RuntimeLibcallImpl; +def execvpe : RuntimeLibcallImpl; +def fclose : RuntimeLibcallImpl; +def fdopen : RuntimeLibcallImpl; +def feof : RuntimeLibcallImpl; +def ferror : RuntimeLibcallImpl; +def fflush : RuntimeLibcallImpl; +def ffs : RuntimeLibcallImpl; +def ffsl : RuntimeLibcallImpl; +def ffsll : RuntimeLibcallImpl; +def fgetc : RuntimeLibcallImpl; +def fgetc_unlocked : RuntimeLibcallImpl; +def fgetpos : RuntimeLibcallImpl; +def fgets : RuntimeLibcallImpl; +def fgets_unlocked : RuntimeLibcallImpl; +def fileno : RuntimeLibcallImpl; +def fiprintf : RuntimeLibcallImpl; +def flockfile : RuntimeLibcallImpl; +def fls : RuntimeLibcallImpl; +def flsl : RuntimeLibcallImpl; +def flsll : RuntimeLibcallImpl; +def fopen : RuntimeLibcallImpl; +def fopen64 : RuntimeLibcallImpl; +def fork : RuntimeLibcallImpl; +def fprintf : RuntimeLibcallImpl; +def fputc : RuntimeLibcallImpl; +def fputc_unlocked : RuntimeLibcallImpl; +def fputs : RuntimeLibcallImpl; +def fputs_unlocked : RuntimeLibcallImpl; +def fread : RuntimeLibcallImpl; +def fread_unlocked : RuntimeLibcallImpl; +def fscanf : RuntimeLibcallImpl; +def fseek : RuntimeLibcallImpl; +def fseeko : RuntimeLibcallImpl; +def fseeko64 : RuntimeLibcallImpl; +def fsetpos : RuntimeLibcallImpl; +def fstat : RuntimeLibcallImpl; +def fstat64 : RuntimeLibcallImpl; +def fstatvfs : RuntimeLibcallImpl; +def fstatvfs64 : RuntimeLibcallImpl; +def ftell : RuntimeLibcallImpl; +def ftello : RuntimeLibcallImpl; +def ftello64 : RuntimeLibcallImpl; +def ftrylockfile : RuntimeLibcallImpl; +def funlockfile : RuntimeLibcallImpl; +def fwrite : RuntimeLibcallImpl; +def fwrite_unlocked : RuntimeLibcallImpl; +def getc : RuntimeLibcallImpl; +def getc_unlocked : RuntimeLibcallImpl; +def getchar : RuntimeLibcallImpl; +def getchar_unlocked : RuntimeLibcallImpl; +def getenv : RuntimeLibcallImpl; +def getitimer : RuntimeLibcallImpl; +def getlogin_r : RuntimeLibcallImpl; +def getpwnam : RuntimeLibcallImpl; +def gets : RuntimeLibcallImpl; +def gettimeofday : RuntimeLibcallImpl; +def htonl : RuntimeLibcallImpl; +def htons : RuntimeLibcallImpl; +def iprintf : RuntimeLibcallImpl; +def isascii : RuntimeLibcallImpl; +def isdigit : RuntimeLibcallImpl; +def labs : RuntimeLibcallImpl; +def lchown : RuntimeLibcallImpl; +def llabs : RuntimeLibcallImpl; +def lstat : RuntimeLibcallImpl; +def lstat64 : RuntimeLibcallImpl; +def memalign : RuntimeLibcallImpl; +def memccpy : RuntimeLibcallImpl; +def memchr : RuntimeLibcallImpl; +def memcmp : RuntimeLibcallImpl; +def mempcpy : RuntimeLibcallImpl; +def memrchr : RuntimeLibcallImpl; +def memset_pattern16 : RuntimeLibcallImpl; +def memset_pattern4 : RuntimeLibcallImpl; +def memset_pattern8 : RuntimeLibcallImpl; +def mkdir : RuntimeLibcallImpl; +def mktime : RuntimeLibcallImpl; +def ntohl : RuntimeLibcallImpl; +def ntohs : RuntimeLibcallImpl; +def open : RuntimeLibcallImpl; +def open64 : RuntimeLibcallImpl; +def opendir : RuntimeLibcallImpl; +def pclose : RuntimeLibcallImpl; +def perror : RuntimeLibcallImpl; +def popen : RuntimeLibcallImpl; +def posix_memalign : RuntimeLibcallImpl; +def pread : RuntimeLibcallImpl; +def printf : RuntimeLibcallImpl; +def putc : RuntimeLibcallImpl; +def putc_unlocked : RuntimeLibcallImpl; +def putchar : RuntimeLibcallImpl; +def putchar_unlocked : RuntimeLibcallImpl; +def puts : RuntimeLibcallImpl; +def pvalloc : RuntimeLibcallImpl; +def pwrite : RuntimeLibcallImpl; +def qsort : RuntimeLibcallImpl; +def read : RuntimeLibcallImpl; +def readlink : RuntimeLibcallImpl; +def realloc : RuntimeLibcallImpl; +def reallocf : RuntimeLibcallImpl; +def reallocarray : RuntimeLibcallImpl; +def realpath : RuntimeLibcallImpl; +def remove : RuntimeLibcallImpl; +def rename : RuntimeLibcallImpl; +def rewind : RuntimeLibcallImpl; +def rmdir : RuntimeLibcallImpl; +def scanf : RuntimeLibcallImpl; +def setbuf : RuntimeLibcallImpl; +def setitimer : RuntimeLibcallImpl; +def setvbuf : RuntimeLibcallImpl; +def siprintf : RuntimeLibcallImpl; +def snprintf : RuntimeLibcallImpl; +def sprintf : RuntimeLibcallImpl; +def sscanf : RuntimeLibcallImpl; +def stat : RuntimeLibcallImpl; +def stat64 : RuntimeLibcallImpl; +def statvfs : RuntimeLibcallImpl; +def statvfs64 : RuntimeLibcallImpl; +def stpcpy : RuntimeLibcallImpl; +def stpncpy : RuntimeLibcallImpl; +def strcasecmp : RuntimeLibcallImpl; +def strcat : RuntimeLibcallImpl; +def strchr : RuntimeLibcallImpl; +def strcmp : RuntimeLibcallImpl; +def strcoll : RuntimeLibcallImpl; +def strcpy : RuntimeLibcallImpl; +def strcspn : RuntimeLibcallImpl; +def strdup : RuntimeLibcallImpl; +def strlcat : RuntimeLibcallImpl; +def strlcpy : RuntimeLibcallImpl; +def strlen : RuntimeLibcallImpl; +def strncasecmp : RuntimeLibcallImpl; +def strncat : RuntimeLibcallImpl; +def strncmp : RuntimeLibcallImpl; +def strncpy : RuntimeLibcallImpl; +def strndup : RuntimeLibcallImpl; +def strnlen : RuntimeLibcallImpl; +def strpbrk : RuntimeLibcallImpl; +def strrchr : RuntimeLibcallImpl; +def strspn : RuntimeLibcallImpl; +def strstr : RuntimeLibcallImpl; +def strtod : RuntimeLibcallImpl; +def strtof : RuntimeLibcallImpl; +def strtok : RuntimeLibcallImpl; +def strtok_r : RuntimeLibcallImpl; +def strtol : RuntimeLibcallImpl; +def strtold : RuntimeLibcallImpl; +def strtoll : RuntimeLibcallImpl; +def strtoul : RuntimeLibcallImpl; +def strtoull : RuntimeLibcallImpl; +def strxfrm : RuntimeLibcallImpl; +def system : RuntimeLibcallImpl; +def times : RuntimeLibcallImpl; +def tmpfile : RuntimeLibcallImpl; +def tmpfile64 : RuntimeLibcallImpl; +def toascii : RuntimeLibcallImpl; +def uname : RuntimeLibcallImpl; +def ungetc : RuntimeLibcallImpl; +def unlink : RuntimeLibcallImpl; +def unsetenv : RuntimeLibcallImpl; +def utime : RuntimeLibcallImpl; +def utimes : RuntimeLibcallImpl; +def valloc : RuntimeLibcallImpl; +def vec_calloc : RuntimeLibcallImpl; +def vec_free : RuntimeLibcallImpl; +def vec_malloc : RuntimeLibcallImpl; +def vec_realloc : RuntimeLibcallImpl; +def vfprintf : RuntimeLibcallImpl; +def vfscanf : RuntimeLibcallImpl; +def vprintf : RuntimeLibcallImpl; +def vscanf : RuntimeLibcallImpl; +def vsnprintf : RuntimeLibcallImpl; +def vsprintf : RuntimeLibcallImpl; +def vsscanf : RuntimeLibcallImpl; +def wcslen : RuntimeLibcallImpl; +def write : RuntimeLibcallImpl; + //-------------------------------------------------------------------- // compiler-rt/libgcc but 64-bit only, not available by default //-------------------------------------------------------------------- From d668db857de7ced08b1140305fea636fbf28d5a3 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 7 Nov 2025 19:20:05 -0800 Subject: [PATCH 3/3] RuntimeLibcalls: Add memset_pattern* calls to darwin systems This is one of the easier cases to comprehend in TargetLibraryInfo's setup. --- llvm/include/llvm/IR/RuntimeLibcalls.h | 10 +++++++++ llvm/include/llvm/IR/RuntimeLibcalls.td | 12 +++++++--- .../Util/DeclareRuntimeLibcalls/darwin.ll | 22 +++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 llvm/test/Transforms/Util/DeclareRuntimeLibcalls/darwin.ll diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index cf96547063cd0..41fe448382992 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -211,6 +211,16 @@ struct RuntimeLibcallsInfo { return true; } + static bool darwinHasMemsetPattern(const Triple &TT) { + // memset_pattern{4,8,16} is only available on iOS 3.0 and Mac OS X 10.5 and + // later. All versions of watchOS support it. + if (TT.isMacOSX()) + return !TT.isMacOSXVersionLT(10, 5); + if (TT.isiOS()) + return !TT.isOSVersionLT(3, 0); + return TT.isWatchOS(); + } + static bool hasAEABILibcalls(const Triple &TT) { return TT.isTargetAEABI() || TT.isTargetGNUAEABI() || TT.isTargetMuslAEABI() || TT.isOSFuchsia() || TT.isAndroid(); diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index 36dea547651c9..794ab2449bc01 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -50,6 +50,7 @@ def isWindowsMSVCOrItaniumEnvironment : RuntimeLibcallPredicate< def isGNUEnvironment : RuntimeLibcallPredicate<"TT.isGNUEnvironment()">; def darwinHasSinCosStret : RuntimeLibcallPredicate<"darwinHasSinCosStret(TT)">; def darwinHasExp10 : RuntimeLibcallPredicate<"darwinHasExp10(TT)">; +def darwinHasMemsetPattern : RuntimeLibcallPredicate<[{darwinHasMemsetPattern(TT)}]>; def hasExp10 : RuntimeLibcallPredicate<[{!TT.isOSDarwin()}]>; @@ -1976,6 +1977,11 @@ defvar DarwinSinCosStret = LibcallImpls<(add __sincosf_stret, __sincos_stret, darwinHasSinCosStret>; defvar DarwinExp10 = LibcallImpls<(add __exp10f, __exp10), darwinHasExp10>; +defvar DarwinMemsetPattern = LibcallImpls<(add memset_pattern4, + memset_pattern8, + memset_pattern16), + darwinHasMemsetPattern>; + defvar SecurityCheckCookieIfWinMSVC = LibcallImpls<(add __security_check_cookie, __security_cookie), isWindowsMSVCOrItaniumEnvironment>; @@ -2133,7 +2139,7 @@ def AArch64SystemLibrary : SystemRuntimeLibrary< AArch64LibcallImpls, LibcallImpls<(add Int128RTLibcalls), isAArch64_ILP64>, LibcallImpls<(add bzero), isOSDarwin>, - DarwinExp10, DarwinSinCosStret, + DarwinExp10, DarwinSinCosStret, DarwinMemsetPattern, LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128, DefaultLibmExp10, DefaultStackProtector, @@ -2603,7 +2609,7 @@ def ARMSystemLibrary WindowARMFPIntCasts, SecurityCheckCookieIfWinMSVC, AEABIDivRemCalls, - DarwinSinCosStret, DarwinExp10, + DarwinSinCosStret, DarwinExp10, DarwinMemsetPattern, LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128, DefaultLibmExp10, @@ -3288,7 +3294,7 @@ defvar MemChkLibcalls = [__memcpy_chk, __memset_chk, __memmove_chk]; defvar X86CommonLibcalls = (add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides, MemChkLibcalls), - DarwinSinCosStret, DarwinExp10, + DarwinSinCosStret, DarwinExp10, DarwinMemsetPattern, X86_F128_Libcalls, LibmHasSinCosF80, // FIXME: Depends on long double SinCosF32F64Libcalls, diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/darwin.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/darwin.ll new file mode 100644 index 0000000000000..6c63f5902f638 --- /dev/null +++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/darwin.ll @@ -0,0 +1,22 @@ +; REQUIRES: aarch64-registered-target, arm-registered-target, x86-registered-target + +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=i386-apple-macosx10.5 < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=i386-apple-macosx10.4 < %s | FileCheck -check-prefix=NO-MEMSET-PATTERN %s + +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macosx10.5 < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-apple-macosx10.4 < %s | FileCheck -check-prefix=NO-MEMSET-PATTERN %s + +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-ios3 < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=arm64-apple-ios2 < %s | FileCheck -check-prefix=NO-MEMSET-PATTERN %s + +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7-apple-ios3 < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=thumbv7-apple-ios2 < %s | FileCheck -check-prefix=NO-MEMSET-PATTERN %s + +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=arm64_32-apple-watchos < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s +; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=armv7k-apple-watchos < %s | FileCheck -check-prefix=HAS-MEMSET-PATTERN %s + +; HAS-MEMSET-PATTERN: declare void @memset_pattern16(...) +; HAS-MEMSET-PATTERN: declare void @memset_pattern4(...) +; HAS-MEMSET-PATTERN: declare void @memset_pattern8(...) + +; NO-MEMSET-PATTERN-NOT: memset_pattern