https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/146084
>From ca2ae4936767d11d87d9276035c3d740e585b175 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <matthew.arsena...@amd.com> Date: Mon, 23 Jun 2025 23:23:01 +0900 Subject: [PATCH] ARM: Start moving runtime libcalls into tablegen We still need to manually set the calling conventions of some libcalls until the lowering is separated out. --- llvm/include/llvm/IR/RuntimeLibcalls.h | 2 +- llvm/include/llvm/IR/RuntimeLibcalls.td | 48 ++++++++++++ llvm/lib/IR/RuntimeLibcalls.cpp | 73 +------------------ .../RuntimeLibcallEmitter-calling-conv.td | 2 +- llvm/test/TableGen/RuntimeLibcallEmitter.td | 2 +- .../TableGen/Basic/RuntimeLibcallsEmitter.cpp | 2 +- 6 files changed, 53 insertions(+), 76 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index ac83df3a4189e..4ea5ff9c9ade8 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -170,7 +170,7 @@ struct RuntimeLibcallsInfo { void initDefaultLibCallImpls(); /// Generated by tablegen. - void setTargetRuntimeLibcallSets(const Triple &TT); + void setTargetRuntimeLibcallSets(const Triple &TT, FloatABI::ABIType FloatABI); /// Set default libcall names. If a target wants to opt-out of a libcall it /// should be placed here. diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index 513cfdf3be462..e8e96c0bfa7d3 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -17,6 +17,7 @@ class DuplicateLibcallImplWithPrefix<RuntimeLibcallImpl Impl, string prefix> /// Libcall Predicates def isOSDarwin : RuntimeLibcallPredicate<"TT.isOSDarwin()">; +def isOSWindows : RuntimeLibcallPredicate<"TT.isOSWindows()">; def darwinHasSinCosStret : RuntimeLibcallPredicate<"darwinHasSinCosStret(TT)">; def darwinHasExp10 : RuntimeLibcallPredicate<"darwinHasExp10(TT)">; @@ -1266,6 +1267,7 @@ def __aeabi_memclr4 : RuntimeLibcallImpl<AEABI_MEMCLR4>; def __aeabi_memclr8 : RuntimeLibcallImpl<AEABI_MEMCLR8>; // isTargetWindows() +defset list<RuntimeLibcallImpl> WindowsFPIntCastLibcalls = { def __stoi64 : RuntimeLibcallImpl<FPTOSINT_F32_I64>; // CallingConv::ARM_AAPCS_VFP def __dtoi64 : RuntimeLibcallImpl<FPTOSINT_F64_I64>; // CallingConv::ARM_AAPCS_VFP def __stou64 : RuntimeLibcallImpl<FPTOUINT_F32_I64>; // CallingConv::ARM_AAPCS_VFP @@ -1274,6 +1276,7 @@ def __i64tos : RuntimeLibcallImpl<SINTTOFP_I64_F32>; // CallingConv::ARM_AAPCS_V def __i64tod : RuntimeLibcallImpl<SINTTOFP_I64_F64>; // CallingConv::ARM_AAPCS_VFP def __u64tos : RuntimeLibcallImpl<UINTTOFP_I64_F32>; // CallingConv::ARM_AAPCS_VFP def __u64tod : RuntimeLibcallImpl<UINTTOFP_I64_F64>; // CallingConv::ARM_AAPCS_VFP +} def __rt_sdiv : RuntimeLibcallImpl<SDIVREM_I32>; // CallingConv::ARM_AAPCS def __rt_sdiv64 : RuntimeLibcallImpl<SDIVREM_I64>; // CallingConv::ARM_AAPCS @@ -1300,6 +1303,51 @@ def __aeabi_h2f : RuntimeLibcallImpl<FPEXT_F16_F32>; // CallingConv::ARM_AAPCS def __gnu_f2h_ieee : RuntimeLibcallImpl<FPROUND_F32_F16>; def __gnu_h2f_ieee : RuntimeLibcallImpl<FPEXT_F16_F32>; + +def WindowARMDivRemCalls : LibcallImpls< + (add __rt_sdiv, __rt_sdiv64, __rt_udiv, __rt_udiv64), + isOSWindows> { + let CallingConv = ARM_AAPCS; +} + +def WindowARMFPIntCasts : LibcallImpls< + (add WindowsFPIntCastLibcalls), + isOSWindows> { + let CallingConv = ARM_AAPCS_VFP; +} + + +// Register based DivRem for AEABI (RTABI 4.2) +def AEABIDivRemCalls : LibcallImpls< + (add __aeabi_idivmod, __aeabi_ldivmod, + __aeabi_uidivmod, __aeabi_uldivmod), + RuntimeLibcallPredicate<[{TT.isTargetAEABI() || TT.isAndroid() || TT.isTargetGNUAEABI() || + TT.isTargetMuslAEABI()}]>> { + let CallingConv = ARM_AAPCS; +} + +def isARMOrThumb : RuntimeLibcallPredicate<"TT.isARM() || TT.isThumb()">; + +def ARMSystemLibrary + : SystemRuntimeLibrary<isARMOrThumb, + (add DefaultLibcallImpls32, + WindowARMDivRemCalls, + WindowARMFPIntCasts, + AEABIDivRemCalls, + DarwinSinCosStret, DarwinExp10, + + // Use divmod compiler-rt calls for iOS 5.0 and later. + LibcallImpls<(add __divmodsi4, __udivmodsi4), + RuntimeLibcallPredicate<[{TT.isOSBinFormatMachO() && + (!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>)> { + let DefaultLibcallCallingConv = LibcallCallingConv<[{ + (!TT.isOSDarwin() && !TT.isiOS() && !TT.isWatchOS() && !TT.isDriverKit()) ? + (FloatABI == FloatABI::Hard ? CallingConv::ARM_AAPCS_VFP + : CallingConv::ARM_AAPCS) : + CallingConv::C + }]>; +} + //===----------------------------------------------------------------------===// // AVR Runtime Libcalls //===----------------------------------------------------------------------===// diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index c2d0b0684ec39..2d168befd145c 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -25,77 +25,6 @@ static cl::opt<bool> static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT, FloatABI::ABIType FloatABIType, EABI EABIVersion) { - if (!TT.isOSDarwin() && !TT.isiOS() && !TT.isWatchOS() && !TT.isDriverKit()) { - CallingConv::ID DefaultCC = FloatABIType == FloatABI::Hard - ? CallingConv::ARM_AAPCS_VFP - : CallingConv::ARM_AAPCS; - for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls()) - Info.setLibcallImplCallingConv(LC, DefaultCC); - } - - // Register based DivRem for AEABI (RTABI 4.2) - if (TT.isTargetAEABI() || TT.isAndroid() || TT.isTargetGNUAEABI() || - TT.isTargetMuslAEABI() || TT.isOSWindows()) { - if (TT.isOSWindows()) { - const struct { - const RTLIB::Libcall Op; - const RTLIB::LibcallImpl Impl; - const CallingConv::ID CC; - } LibraryCalls[] = { - {RTLIB::SDIVREM_I32, RTLIB::__rt_sdiv, CallingConv::ARM_AAPCS}, - {RTLIB::SDIVREM_I64, RTLIB::__rt_sdiv64, CallingConv::ARM_AAPCS}, - {RTLIB::UDIVREM_I32, RTLIB::__rt_udiv, CallingConv::ARM_AAPCS}, - {RTLIB::UDIVREM_I64, RTLIB::__rt_udiv64, CallingConv::ARM_AAPCS}, - }; - - for (const auto &LC : LibraryCalls) { - Info.setLibcallImpl(LC.Op, LC.Impl); - Info.setLibcallImplCallingConv(LC.Impl, LC.CC); - } - } else { - const struct { - const RTLIB::Libcall Op; - const RTLIB::LibcallImpl Impl; - } LibraryCalls[] = { - {RTLIB::SDIVREM_I32, RTLIB::__aeabi_idivmod}, - {RTLIB::SDIVREM_I64, RTLIB::__aeabi_ldivmod}, - {RTLIB::UDIVREM_I32, RTLIB::__aeabi_uidivmod}, - {RTLIB::UDIVREM_I64, RTLIB::__aeabi_uldivmod}, - }; - - for (const auto &LC : LibraryCalls) - Info.setLibcallImpl(LC.Op, LC.Impl); - } - } - - if (TT.isOSWindows()) { - static const struct { - const RTLIB::Libcall Op; - const RTLIB::LibcallImpl Impl; - const CallingConv::ID CC; - } LibraryCalls[] = { - {RTLIB::FPTOSINT_F32_I64, RTLIB::__stoi64, CallingConv::ARM_AAPCS_VFP}, - {RTLIB::FPTOSINT_F64_I64, RTLIB::__dtoi64, CallingConv::ARM_AAPCS_VFP}, - {RTLIB::FPTOUINT_F32_I64, RTLIB::__stou64, CallingConv::ARM_AAPCS_VFP}, - {RTLIB::FPTOUINT_F64_I64, RTLIB::__dtou64, CallingConv::ARM_AAPCS_VFP}, - {RTLIB::SINTTOFP_I64_F32, RTLIB::__i64tos, CallingConv::ARM_AAPCS_VFP}, - {RTLIB::SINTTOFP_I64_F64, RTLIB::__i64tod, CallingConv::ARM_AAPCS_VFP}, - {RTLIB::UINTTOFP_I64_F32, RTLIB::__u64tos, CallingConv::ARM_AAPCS_VFP}, - {RTLIB::UINTTOFP_I64_F64, RTLIB::__u64tod, CallingConv::ARM_AAPCS_VFP}, - }; - - for (const auto &LC : LibraryCalls) { - Info.setLibcallImpl(LC.Op, LC.Impl); - Info.setLibcallImplCallingConv(LC.Impl, LC.CC); - } - } - - // Use divmod compiler-rt calls for iOS 5.0 and later. - if (TT.isOSBinFormatMachO() && (!TT.isiOS() || !TT.isOSVersionLT(5, 0))) { - Info.setLibcallImpl(RTLIB::SDIVREM_I32, RTLIB::__divmodsi4); - Info.setLibcallImpl(RTLIB::UDIVREM_I32, RTLIB::__udivmodsi4); - } - static const RTLIB::LibcallImpl AAPCS_Libcalls[] = { RTLIB::__aeabi_dadd, RTLIB::__aeabi_ddiv, RTLIB::__aeabi_dmul, RTLIB::__aeabi_dsub, @@ -212,7 +141,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT, ExceptionHandling ExceptionModel, FloatABI::ABIType FloatABI, EABI EABIVersion, StringRef ABIName) { - setTargetRuntimeLibcallSets(TT); + setTargetRuntimeLibcallSets(TT, FloatABI); // Use the f128 variants of math functions on x86 if (TT.isX86() && TT.isGNUEnvironment()) diff --git a/llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td b/llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td index f825ece6cf4bb..49d5ecaa0e5c5 100644 --- a/llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td +++ b/llvm/test/TableGen/RuntimeLibcallEmitter-calling-conv.td @@ -41,7 +41,7 @@ def MSP430LibraryWithCondCC : SystemRuntimeLibrary<isMSP430, >; -// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT) { +// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, FloatABI::ABIType FloatABI) { // CHECK: if (TT.getArch() == Triple::avr && TT.isOSHurd()) { // CHECK-NEXT: const CallingConv::ID DefaultCC = isFoo() ? CallingConv::Fast : CallingConv::GHC; // CHECK-NEXT: for (CallingConv::ID &Entry : LibcallImplCallingConvs) { diff --git a/llvm/test/TableGen/RuntimeLibcallEmitter.td b/llvm/test/TableGen/RuntimeLibcallEmitter.td index 0d7a69165d6f9..a0061afab1db0 100644 --- a/llvm/test/TableGen/RuntimeLibcallEmitter.td +++ b/llvm/test/TableGen/RuntimeLibcallEmitter.td @@ -141,7 +141,7 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, (add calloc, LibraryWithCondi // CHECK-NEXT: }; -// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT) { +// CHECK: void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(const llvm::Triple &TT, FloatABI::ABIType FloatABI) { // CHECK-NEXT: struct LibcallImplPair { // CHECK-NEXT: RTLIB::Libcall Func; // CHECK-NEXT: RTLIB::LibcallImpl Impl; diff --git a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp index 041c404dde9b3..81494f80fb5c9 100644 --- a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp +++ b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp @@ -362,7 +362,7 @@ void RuntimeLibcallEmitter::emitGetInitRuntimeLibcallNames( void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls( raw_ostream &OS) const { OS << "void llvm::RTLIB::RuntimeLibcallsInfo::setTargetRuntimeLibcallSets(" - "const llvm::Triple &TT) {\n" + "const llvm::Triple &TT, FloatABI::ABIType FloatABI) {\n" " struct LibcallImplPair {\n" " RTLIB::Libcall Func;\n" " RTLIB::LibcallImpl Impl;\n" _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits