Skip to content

RuntimeLibcalls: Mostly move x86 configuration into tablegen #148575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jul 14, 2025

This is getting pretty ugly, but seems to be the worst of the
cases. Opting out of the base set of calls for the various windows
cases is really ugly. We need to apply that to the arm cases as well.

It also may make sense to go back to transposing the architecture
and operating system (i.e. make isOSWindows the SystemLibrary
and then modify based on architecture).

@llvmbot
Copy link
Member

llvmbot commented Jul 14, 2025

@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

This is getting pretty ugly, but seems to be the worst of the
cases. Opting out of the base set of calls for the various windows
cases is really ugly. We need to apply that to the arm cases as well.

It also may make sense to go back to transposing the architecture
and operating system (i.e. make isOSWindows the SystemLibrary
and then modify based on architecture).


Full diff: https://github.com/llvm/llvm-project/pull/148575.diff

3 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.h (+4)
  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+83-7)
  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (+18-136)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index 97a6389844439..c63c7cd64ec4d 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -174,6 +174,10 @@ struct RuntimeLibcallsInfo {
            (TT.isAndroid() && !TT.isAndroidVersionLT(9));
   }
 
+  static bool hasSinCos_f32_f64(const Triple &TT) {
+    return hasSinCos(TT) || TT.isPS();
+  }
+
   LLVM_ABI void initDefaultLibCallImpls();
 
   /// Generated by tablegen.
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index b0651a8ac9920..be2558a8b1c8a 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -17,12 +17,23 @@ class DuplicateLibcallImplWithPrefix<RuntimeLibcallImpl Impl, string prefix>
 
 /// Libcall Predicates
 def isOSDarwin : RuntimeLibcallPredicate<"TT.isOSDarwin()">;
+def isOSOpenBSD : RuntimeLibcallPredicate<"TT.isOSOpenBSD()">;
 def isOSWindows : RuntimeLibcallPredicate<"TT.isOSWindows()">;
+def isNotOSWindows : RuntimeLibcallPredicate<"!TT.isOSWindows()">;
+def isNotOSMSVCRT : RuntimeLibcallPredicate<"!TT.isOSMSVCRT()">;
+def isPS : RuntimeLibcallPredicate<"TT.isPS()">;
+def isNotOSWindowsOrIsCygwinMinGW
+  : RuntimeLibcallPredicate<"!TT.isOSWindows() || TT.isOSCygMing()">;
 
+
+def isGNUEnvironment : RuntimeLibcallPredicate<"TT.isGNUEnvironment()">;
 def darwinHasSinCosStret : RuntimeLibcallPredicate<"darwinHasSinCosStret(TT)">;
 def darwinHasExp10 : RuntimeLibcallPredicate<"darwinHasExp10(TT)">;
 def hasSinCos : RuntimeLibcallPredicate<"hasSinCos(TT)">;
 
+// FIXME: Way to combine predicates
+def hasSinCos_f32_f64 : RuntimeLibcallPredicate<"hasSinCos_f32_f64(TT)">;
+
 //--------------------------------------------------------------------
 // Declare all kinds of used libcalls
 //--------------------------------------------------------------------
@@ -514,11 +525,13 @@ def __divxf3 : RuntimeLibcallImpl<DIV_F80>;
 def __divtf3 : RuntimeLibcallImpl<DIV_F128>;
 def __gcc_qdiv : RuntimeLibcallImpl<DIV_PPCF128>;
 
+defset list<RuntimeLibcallImpl> PowiLibcallImpls = {
 def __powisf2 : RuntimeLibcallImpl<POWI_F32>;
 def __powidf2 : RuntimeLibcallImpl<POWI_F64>;
 def __powixf2 : RuntimeLibcallImpl<POWI_F80>;
 def __powitf2_f128 : RuntimeLibcallImpl<POWI_F128, "__powitf2">;
 def __powitf2_ppc128 : RuntimeLibcallImpl<POWI_PPCF128, "__powitf2">;
+}
 
 // Conversion
 def __extendbfsf2 : RuntimeLibcallImpl<FPEXT_BF16_F32>;
@@ -1087,6 +1100,29 @@ defvar LibmHasSinCosF80 = LibcallImpls<(add sincos_f80), hasSinCos>;
 defvar LibmHasSinCosF128 = LibcallImpls<(add sincos_f128), hasSinCos>;
 defvar LibmHasSinCosPPCF128 = LibcallImpls<(add sincos_ppcf128), hasSinCos>;
 
+defvar WindowsMathRemovals = [
+  ldexpf, ldexp_f80, ldexp_f128, ldexp_ppcf128,
+  frexpf, frexp_f80, frexp_f128, frexp_ppcf128
+];
+
+defvar MostPowI = !listremove(PowiLibcallImpls, [__powitf2_f128]);
+defvar WindowsExclusions = !listconcat(WindowsMathRemovals, MostPowI);
+
+// Targets which support windows should start with these as a base and
+// add in calls for other OSes
+defvar Win32DefaultLibcallImpls = !listremove(DefaultLibcallImpls32, WindowsExclusions);
+defvar Win64DefaultLibcallImpls = !listremove(DefaultLibcallImpls64, WindowsExclusions);
+
+defvar LibmHasFrexpF32 = LibcallImpls<(add frexpf), isNotOSWindowsOrIsCygwinMinGW>;
+defvar LibmHasLdexpF32 = LibcallImpls<(add ldexpf), isNotOSWindowsOrIsCygwinMinGW>;
+
+defvar LibmHasFrexpF80 = LibcallImpls<(add frexp_f80), isNotOSWindowsOrIsCygwinMinGW>;
+defvar LibmHasLdexpF80 = LibcallImpls<(add ldexp_f80), isNotOSWindowsOrIsCygwinMinGW>;
+
+defvar LibmHasFrexpF128 = LibcallImpls<(add frexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
+defvar LibmHasLdexpF128 = LibcallImpls<(add ldexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
+
+
 //===----------------------------------------------------------------------===//
 // Objective-C Runtime Libcalls
 //===----------------------------------------------------------------------===//
@@ -1154,7 +1190,10 @@ def isAArch64_ILP64  : RuntimeLibcallPredicate<"TT.isAArch64(64)">;
 
 def AArch64SystemLibrary : SystemRuntimeLibrary<
   isAArch64_ExceptArm64EC,
-  (add DefaultRuntimeLibcallImpls,
+  (add Win64DefaultLibcallImpls,
+       LibcallImpls<(add __powisf2, __powidf2), isNotOSMSVCRT>,
+       LibmHasFrexpF32, LibmHasLdexpF32,
+       LibmHasFrexpF128, LibmHasLdexpF128,
        AArch64LibcallImpls,
        LibcallImpls<(add Int128RTLibcalls), isAArch64_ILP64>,
        LibcallImpls<(add bzero), isOSDarwin>,
@@ -1164,7 +1203,7 @@ def AArch64SystemLibrary : SystemRuntimeLibrary<
 
 // Prepend a # to every name
 defset list<RuntimeLibcallImpl> WinArm64ECDefaultRuntimeLibcallImpls = {
-  foreach libcall = DefaultLibcallImpls64 in {
+  foreach libcall = Win64DefaultLibcallImpls in {
     def arm64ec_#libcall : DuplicateLibcallImplWithPrefix<libcall, "#">;
   }
 
@@ -1421,11 +1460,15 @@ def isARMOrThumb : RuntimeLibcallPredicate<"TT.isARM() || TT.isThumb()">;
 
 def ARMSystemLibrary
     : SystemRuntimeLibrary<isARMOrThumb,
-      (add DefaultLibcallImpls32,
+      (add Win32DefaultLibcallImpls,
+           LibcallImpls<(add __powisf2, __powidf2), isNotOSMSVCRT>,
+           LibmHasFrexpF32, LibmHasLdexpF32,
+           LibmHasFrexpF128, LibmHasLdexpF128,
            WindowARMDivRemCalls,
            WindowARMFPIntCasts,
            AEABIDivRemCalls,
            DarwinSinCosStret, DarwinExp10,
+           LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
 
            // Use divmod compiler-rt calls for iOS 5.0 and later.
            LibcallImpls<(add __divmodsi4, __udivmodsi4),
@@ -1919,6 +1962,8 @@ def PPCSystemLibrary
            __extendkftf2, __trunctfkf2,
            DefaultRuntimeLibcallImpls_ppcf128,
            LibmF128Libcalls, AIX32Calls, AIX64Calls,
+           LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
+           LibmHasSinCosPPCF128,
            AvailableIf<memcpy, isNotAIX>,
            LibcallImpls<(add Int128RTLibcalls), isPPC64>)>;
 
@@ -1989,13 +2034,13 @@ def _Q_ulltoq : RuntimeLibcallImpl<UINTTOFP_I64_F128>;
 // Windows Runtime Libcalls
 //===----------------------------------------------------------------------===//
 
-// TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment()
-
+defset list<RuntimeLibcallImpl> WindowsDivRemMulLibcalls = {
 def _alldiv : RuntimeLibcallImpl<SDIV_I64>;
 def _aulldiv : RuntimeLibcallImpl<UDIV_I64>;
 def _allrem : RuntimeLibcallImpl<SREM_I64>;
 def _aullrem : RuntimeLibcallImpl<UREM_I64>;
 def _allmul : RuntimeLibcallImpl<MUL_I64>;
+}
 
 //===----------------------------------------------------------------------===//
 // X86 Runtime Libcalls
@@ -2003,14 +2048,45 @@ def _allmul : RuntimeLibcallImpl<MUL_I64>;
 
 def isX86_32 : RuntimeLibcallPredicate<"TT.getArch() == Triple::x86">;
 def isX86_64 : RuntimeLibcallPredicate<"TT.getArch() == Triple::x86_64">;
+def isX86 : RuntimeLibcallPredicate<"TT.isX86()">;
+
+// Some darwins have an optimized __bzero/bzero function.
+def darwinHas__bzero : RuntimeLibcallPredicate<"TT.isMacOSX() && !TT.isMacOSXVersionLT(10, 6)">;
+
+// Use the f128 variants of math functions on x86
+defvar X86_F128_Libcalls = LibcallImpls<(add LibmF128Libcalls, LibmF128FiniteLibcalls), isGNUEnvironment>;
+
+defvar SinCosF32F64Libcalls = LibcallImpls<(add sincosf, sincos), hasSinCos_f32_f64>;
+
+defvar X86CommonLibcalls =
+  (add DarwinSinCosStret, DarwinExp10,
+       X86_F128_Libcalls,
+       sincos_f80,
+       LibmHasSinCosF80, // FIXME: Depends on long double
+       SinCosF32F64Libcalls,
+       LibcallImpls<(add __bzero), darwinHas__bzero>,
+       LibmHasFrexpF32, LibmHasLdexpF32,
+       LibmHasFrexpF80, LibmHasLdexpF80,
+       DefaultRuntimeLibcallImpls_f80,
+       // MSVCRT doesn't have powi
+       // FIXME: It's almost certainly correct that MSVCRT has
+       // __powitf2_f128, but at least one test is relying on it.
+       __powitf2_f128,
+       LibcallImpls<(add MostPowI), isNotOSMSVCRT>
+);
+
+defvar Windows32DivRemMulCalls =
+  LibcallImpls<(add WindowsDivRemMulLibcalls),
+  RuntimeLibcallPredicate<"TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment()">>;
 
 def X86_32SystemLibrary
     : SystemRuntimeLibrary<isX86_32,
-      (add DefaultLibcallImpls32, DefaultRuntimeLibcallImpls_f80)>;
+      (add X86CommonLibcalls,
+           Windows32DivRemMulCalls, Win32DefaultLibcallImpls)>;
 
 def X86_64SystemLibrary
     : SystemRuntimeLibrary<isX86_64,
-      (add DefaultLibcallImpls64, DefaultRuntimeLibcallImpls_f80)>;
+      (add X86CommonLibcalls, Win64DefaultLibcallImpls, Int128RTLibcalls)>;
 
 //===----------------------------------------------------------------------===//
 // XCore Runtime Libcalls
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 74cde5e9cee92..60da0047291a9 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -62,69 +62,6 @@ static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
     Info.setLibcallImplCallingConv(Impl, CallingConv::ARM_AAPCS);
 }
 
-static void setLongDoubleIsF128Libm(RuntimeLibcallsInfo &Info,
-                                    bool FiniteOnlyFuncs = false) {
-  Info.setLibcallImpl(RTLIB::REM_F128, RTLIB::fmodf128);
-  Info.setLibcallImpl(RTLIB::FMA_F128, RTLIB::fmaf128);
-  Info.setLibcallImpl(RTLIB::SQRT_F128, RTLIB::sqrtf128);
-  Info.setLibcallImpl(RTLIB::CBRT_F128, RTLIB::cbrtf128);
-  Info.setLibcallImpl(RTLIB::LOG_F128, RTLIB::logf128);
-  Info.setLibcallImpl(RTLIB::LOG2_F128, RTLIB::log2f128);
-  Info.setLibcallImpl(RTLIB::LOG10_F128, RTLIB::log10f128);
-  Info.setLibcallImpl(RTLIB::EXP_F128, RTLIB::expf128);
-  Info.setLibcallImpl(RTLIB::EXP2_F128, RTLIB::exp2f128);
-  Info.setLibcallImpl(RTLIB::EXP10_F128, RTLIB::exp10f128);
-  Info.setLibcallImpl(RTLIB::SIN_F128, RTLIB::sinf128);
-  Info.setLibcallImpl(RTLIB::COS_F128, RTLIB::cosf128);
-  Info.setLibcallImpl(RTLIB::TAN_F128, RTLIB::tanf128);
-  Info.setLibcallImpl(RTLIB::SINCOS_F128, RTLIB::sincosf128);
-  Info.setLibcallImpl(RTLIB::ASIN_F128, RTLIB::asinf128);
-  Info.setLibcallImpl(RTLIB::ACOS_F128, RTLIB::acosf128);
-  Info.setLibcallImpl(RTLIB::ATAN_F128, RTLIB::atanf128);
-  Info.setLibcallImpl(RTLIB::ATAN2_F128, RTLIB::atan2f128);
-  Info.setLibcallImpl(RTLIB::SINH_F128, RTLIB::sinhf128);
-  Info.setLibcallImpl(RTLIB::COSH_F128, RTLIB::coshf128);
-  Info.setLibcallImpl(RTLIB::TANH_F128, RTLIB::tanhf128);
-  Info.setLibcallImpl(RTLIB::POW_F128, RTLIB::powf128);
-  Info.setLibcallImpl(RTLIB::CEIL_F128, RTLIB::ceilf128);
-  Info.setLibcallImpl(RTLIB::TRUNC_F128, RTLIB::truncf128);
-  Info.setLibcallImpl(RTLIB::RINT_F128, RTLIB::rintf128);
-  Info.setLibcallImpl(RTLIB::NEARBYINT_F128, RTLIB::nearbyintf128);
-  Info.setLibcallImpl(RTLIB::ROUND_F128, RTLIB::roundf128);
-  Info.setLibcallImpl(RTLIB::ROUNDEVEN_F128, RTLIB::roundevenf128);
-  Info.setLibcallImpl(RTLIB::FLOOR_F128, RTLIB::floorf128);
-  Info.setLibcallImpl(RTLIB::COPYSIGN_F128, RTLIB::copysignf128);
-  Info.setLibcallImpl(RTLIB::FMIN_F128, RTLIB::fminf128);
-  Info.setLibcallImpl(RTLIB::FMAX_F128, RTLIB::fmaxf128);
-  Info.setLibcallImpl(RTLIB::FMINIMUM_F128, RTLIB::fminimumf128);
-  Info.setLibcallImpl(RTLIB::FMAXIMUM_F128, RTLIB::fmaximumf128);
-  Info.setLibcallImpl(RTLIB::FMINIMUM_NUM_F128, RTLIB::fminimum_numf128);
-  Info.setLibcallImpl(RTLIB::FMAXIMUM_NUM_F128, RTLIB::fmaximum_numf128);
-  Info.setLibcallImpl(RTLIB::LROUND_F128, RTLIB::lroundf128);
-  Info.setLibcallImpl(RTLIB::LLROUND_F128, RTLIB::llroundf128);
-  Info.setLibcallImpl(RTLIB::LRINT_F128, RTLIB::lrintf128);
-  Info.setLibcallImpl(RTLIB::LLRINT_F128, RTLIB::llrintf128);
-  Info.setLibcallImpl(RTLIB::LDEXP_F128, RTLIB::ldexpf128);
-  Info.setLibcallImpl(RTLIB::FREXP_F128, RTLIB::frexpf128);
-  Info.setLibcallImpl(RTLIB::MODF_F128, RTLIB::modff128);
-
-  if (FiniteOnlyFuncs) {
-    Info.setLibcallImpl(RTLIB::LOG_FINITE_F128, RTLIB::__logf128_finite);
-    Info.setLibcallImpl(RTLIB::LOG2_FINITE_F128, RTLIB::__log2f128_finite);
-    Info.setLibcallImpl(RTLIB::LOG10_FINITE_F128, RTLIB::__log10f128_finite);
-    Info.setLibcallImpl(RTLIB::EXP_FINITE_F128, RTLIB::__expf128_finite);
-    Info.setLibcallImpl(RTLIB::EXP2_FINITE_F128, RTLIB::__exp2f128_finite);
-    Info.setLibcallImpl(RTLIB::POW_FINITE_F128, RTLIB::__powf128_finite);
-  } else {
-    Info.setLibcallImpl(RTLIB::LOG_FINITE_F128, RTLIB::Unsupported);
-    Info.setLibcallImpl(RTLIB::LOG2_FINITE_F128, RTLIB::Unsupported);
-    Info.setLibcallImpl(RTLIB::LOG10_FINITE_F128, RTLIB::Unsupported);
-    Info.setLibcallImpl(RTLIB::EXP_FINITE_F128, RTLIB::Unsupported);
-    Info.setLibcallImpl(RTLIB::EXP2_FINITE_F128, RTLIB::Unsupported);
-    Info.setLibcallImpl(RTLIB::POW_FINITE_F128, RTLIB::Unsupported);
-  }
-}
-
 void RTLIB::RuntimeLibcallsInfo::initDefaultLibCallImpls() {
   std::memcpy(LibcallImpls, DefaultLibcallImpls, sizeof(LibcallImpls));
   static_assert(sizeof(LibcallImpls) == sizeof(DefaultLibcallImpls),
@@ -143,10 +80,6 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
   if (TT.isAMDGPU() || TT.isNVPTX() || TT.isWasm())
     return;
 
-  // Use the f128 variants of math functions on x86
-  if (TT.isX86() && TT.isGNUEnvironment())
-    setLongDoubleIsF128Libm(*this, /*FiniteOnlyFuncs=*/true);
-
   if (TT.isX86() || TT.isVE() || TT.isARM() || TT.isThumb()) {
     if (ExceptionModel == ExceptionHandling::SjLj)
       setLibcallImpl(RTLIB::UNWIND_RESUME, RTLIB::_Unwind_SjLj_Resume);
@@ -160,91 +93,40 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
     setLibcallImpl(RTLIB::FPEXT_F16_F32, RTLIB::__extendhfsf2);
     setLibcallImpl(RTLIB::FPROUND_F32_F16, RTLIB::__truncsfhf2);
 
-    // Some darwins have an optimized __bzero/bzero function.
-    if (TT.isX86()) {
-      if (TT.isMacOSX() && !TT.isMacOSXVersionLT(10, 6))
-        setLibcallImpl(RTLIB::BZERO, RTLIB::__bzero);
-    }
-
-    if (darwinHasSinCosStret(TT)) {
-      setLibcallImpl(RTLIB::SINCOS_STRET_F32, RTLIB::__sincosf_stret);
-      setLibcallImpl(RTLIB::SINCOS_STRET_F64, RTLIB::__sincos_stret);
-      if (TT.isWatchABI()) {
-        setLibcallImplCallingConv(RTLIB::__sincosf_stret,
-                                  CallingConv::ARM_AAPCS_VFP);
-        setLibcallImplCallingConv(RTLIB::__sincos_stret,
-                                  CallingConv::ARM_AAPCS_VFP);
-      }
+    if (TT.isWatchABI()) {
+      setLibcallImplCallingConv(RTLIB::__sincosf_stret,
+                                CallingConv::ARM_AAPCS_VFP);
+      setLibcallImplCallingConv(RTLIB::__sincos_stret,
+                                CallingConv::ARM_AAPCS_VFP);
     }
 
-    if (darwinHasExp10(TT)) {
-      setLibcallImpl(RTLIB::EXP10_F32, RTLIB::__exp10f);
-      setLibcallImpl(RTLIB::EXP10_F64, RTLIB::__exp10);
-    } else {
+    if (!darwinHasExp10(TT)) {
+      // FIXME: Remove exp10 from default set
       setLibcallImpl(RTLIB::EXP10_F32, RTLIB::Unsupported);
       setLibcallImpl(RTLIB::EXP10_F64, RTLIB::Unsupported);
     }
   }
 
-  if (hasSinCos(TT)) {
-    setLibcallImpl(RTLIB::SINCOS_F32, RTLIB::sincosf);
-    setLibcallImpl(RTLIB::SINCOS_F64, RTLIB::sincos);
-    setLibcallImpl(RTLIB::SINCOS_F80, RTLIB::sincos_f80);
-    setLibcallImpl(RTLIB::SINCOS_F128, RTLIB::sincos_f128);
-    setLibcallImpl(RTLIB::SINCOS_PPCF128, RTLIB::sincos_ppcf128);
-  }
-
-  if (TT.isPS()) {
-    setLibcallImpl(RTLIB::SINCOS_F32, RTLIB::sincosf);
-    setLibcallImpl(RTLIB::SINCOS_F64, RTLIB::sincos);
-  }
-
   if (TT.isOSOpenBSD()) {
     setLibcallImpl(RTLIB::STACKPROTECTOR_CHECK_FAIL, RTLIB::Unsupported);
   }
 
-  if (TT.isOSWindows() && !TT.isOSCygMing()) {
-    setLibcallImpl(RTLIB::LDEXP_F32, RTLIB::Unsupported);
-    setLibcallImpl(RTLIB::LDEXP_F80, RTLIB::Unsupported);
-    setLibcallImpl(RTLIB::LDEXP_F128, RTLIB::Unsupported);
-    setLibcallImpl(RTLIB::LDEXP_PPCF128, RTLIB::Unsupported);
-
-    setLibcallImpl(RTLIB::FREXP_F32, RTLIB::Unsupported);
-    setLibcallImpl(RTLIB::FREXP_F80, RTLIB::Unsupported);
-    setLibcallImpl(RTLIB::FREXP_F128, RTLIB::Unsupported);
-    setLibcallImpl(RTLIB::FREXP_PPCF128, RTLIB::Unsupported);
-  }
+  // Skip default manual processing for targets that have been fully ported to
+  // tablegen for now. Eventually the rest of this should be deleted.
+  if (TT.isX86() || TT.isAArch64() || TT.isWasm())
+    return;
 
-  if (TT.isOSMSVCRT()) {
-    // MSVCRT doesn't have powi; fall back to pow
-    setLibcallImpl(RTLIB::POWI_F32, RTLIB::Unsupported);
-    setLibcallImpl(RTLIB::POWI_F64, RTLIB::Unsupported);
+  if (TT.isARM() || TT.isThumb()) {
+    setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
+    return;
   }
 
-  // Setup Windows compiler runtime calls.
-  if (TT.getArch() == Triple::x86 &&
-      (TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment())) {
-    static const struct {
-      const RTLIB::Libcall Op;
-      const RTLIB::LibcallImpl Impl;
-      const CallingConv::ID CC;
-    } LibraryCalls[] = {
-        {RTLIB::SDIV_I64, RTLIB::_alldiv, CallingConv::X86_StdCall},
-        {RTLIB::UDIV_I64, RTLIB::_aulldiv, CallingConv::X86_StdCall},
-        {RTLIB::SREM_I64, RTLIB::_allrem, CallingConv::X86_StdCall},
-        {RTLIB::UREM_I64, RTLIB::_aullrem, CallingConv::X86_StdCall},
-        {RTLIB::MUL_I64, RTLIB::_allmul, CallingConv::X86_StdCall},
-    };
-
-    for (const auto &LC : LibraryCalls) {
-      setLibcallImpl(LC.Op, LC.Impl);
-      setLibcallImplCallingConv(LC.Impl, LC.CC);
-    }
+  if (hasSinCos(TT)) {
+    setLibcallImpl(RTLIB::SINCOS_F32, RTLIB::sincosf);
+    setLibcallImpl(RTLIB::SINCOS_F64, RTLIB::sincos);
+    setLibcallImpl(RTLIB::SINCOS_F128, RTLIB::sincos_f128);
   }
 
-  if (TT.isARM() || TT.isThumb())
-    setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
-
   // These libcalls are only available in compiler-rt, not libgcc.
   if (TT.isArch64Bit()) {
     setLibcallImpl(RTLIB::SHL_I128, RTLIB::__ashlti3);

@arsenm arsenm marked this pull request as ready for review July 14, 2025 07:18
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/x86-mostly-move-libcalls-tablegen branch from bbd359e to 1a5ee21 Compare July 14, 2025 10:15
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/switch-compiler-rt-64-libcalls-opt-in branch from 2f195de to e933483 Compare July 14, 2025 10:15
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/switch-compiler-rt-64-libcalls-opt-in branch from e933483 to b1cc318 Compare July 14, 2025 15:56
Base automatically changed from users/arsenm/runtime-libcalls/switch-compiler-rt-64-libcalls-opt-in to main July 14, 2025 15:59
Copy link
Contributor

@dpaoliello dpaoliello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor clarification, otherwise LGTM

LibmHasFrexpF80, LibmHasLdexpF80,
DefaultRuntimeLibcallImpls_f80,
// MSVCRT doesn't have powi
// FIXME: It's almost certainly correct that MSVCRT has
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is confusing: does MSVC NOT have __powitf2_f128 but there's a test relying on it, or does MSVC have __powitf2_f128 and there's a test relying on it NOT having it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't have it, I assume (none of this stuff is documented but it would be weird if it had the f128 version and not the f32/f64). There's a test that tests all the types for the constrained powi intrinsic that happens to use an mcvc run line which currently compiles, this is avoiding turning that into an error

arsenm added 5 commits July 15, 2025 15:04
This is getting pretty ugly, but seems to be the worst of the
cases. Opting out of the base set of calls for the various windows
cases is really ugly. We need to apply that to the arm cases as well.

It also may make sense to go back to transposing the architecture
and operating system (i.e. make isOSWindows the SystemLibrary
and then modify based on architecture).
Comment on lines 1188 to 1194
def AArch64SystemLibrary : SystemRuntimeLibrary<
isAArch64_ExceptArm64EC,
(add DefaultRuntimeLibcallImpls,
(add Win64DefaultLibcallImpls,
LibcallImpls<(add __powisf2, __powidf2), isNotOSMSVCRT>,
LibmHasFrexpF32, LibmHasLdexpF32,
LibmHasFrexpF128, LibmHasLdexpF128,
AArch64LibcallImpls,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be missing something here, but it doesn't look like AArch64SystemLibrary is only for Windows. Why did it change to Win64DefaultLibcallImpls rather than DefaultRuntimeLibcallImpls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Win64DefaultLibcallImpls is the subset supported by windows. Everything else is additive for different not windows

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Just surprising that the libcalls on most other targets tends to be a proper superset of Windows libcalls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, there are some isOSWindows in there.

This whole thing is also messier than it should be, it should improve once the list of calls is fully separated from the lowering decision

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/x86-mostly-move-libcalls-tablegen branch from 5915e12 to 27fd017 Compare July 15, 2025 06:19
Copy link
Contributor Author

arsenm commented Jul 15, 2025

Merge activity

  • Jul 15, 7:17 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 15, 7:18 AM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm merged commit 0991435 into main Jul 15, 2025
9 checks passed
@arsenm arsenm deleted the users/arsenm/runtime-libcalls/x86-mostly-move-libcalls-tablegen branch July 15, 2025 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants