Skip to content

ARM: Move calling conv config to RuntimeLibcalls #152065

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Aug 5, 2025

Consolidate module level ABI into RuntimeLibcalls

@arsenm arsenm added the backend:ARM label Aug 5, 2025 — with Graphite App
Copy link
Contributor Author

arsenm commented Aug 5, 2025

@llvmbot
Copy link
Member

llvmbot commented Aug 5, 2025

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-backend-arm

Author: Matt Arsenault (arsenm)

Changes

Consolidate module level ABI into RuntimeLibcalls


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

2 Files Affected:

  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (+35-3)
  • (modified) llvm/lib/Target/ARM/ARMISelLowering.cpp (-19)
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index b6e2cac5f7b04..0eb7ed4c3e619 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -9,6 +9,7 @@
 #include "llvm/IR/RuntimeLibcalls.h"
 #include "llvm/ADT/StringTable.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/TargetParser/ARMTargetParser.h"
 
 #define DEBUG_TYPE "runtime-libcalls-info"
 
@@ -22,8 +23,39 @@ using namespace RTLIB;
 #undef GET_SET_TARGET_RUNTIME_LIBCALL_SETS
 
 static void setARMLibcallNames(RuntimeLibcallsInfo &Info, const Triple &TT,
-                               FloatABI::ABIType FloatABIType,
-                               EABI EABIVersion) {
+                               FloatABI::ABIType FloatABIType, EABI EABIVersion,
+                               StringRef ABIName) {
+  // The half <-> float conversion functions are always soft-float on
+  // non-watchos platforms, but are needed for some targets which use a
+  // hard-float calling convention by default.
+  if (!TT.isWatchABI()) {
+    ARM::ARMABI TargetABI = ARM::computeTargetABI(TT, ABIName);
+
+    if (TargetABI == ARM::ARM_ABI_AAPCS || TargetABI == ARM::ARM_ABI_AAPCS16) {
+      Info.setLibcallImplCallingConv(RTLIB::__truncsfhf2,
+                                     CallingConv::ARM_AAPCS);
+      Info.setLibcallImplCallingConv(RTLIB::__truncdfhf2,
+                                     CallingConv::ARM_AAPCS);
+      Info.setLibcallImplCallingConv(RTLIB::__extendhfsf2,
+                                     CallingConv::ARM_AAPCS);
+      Info.setLibcallImplCallingConv(RTLIB::__gnu_h2f_ieee,
+                                     CallingConv::ARM_AAPCS);
+      Info.setLibcallImplCallingConv(RTLIB::__gnu_f2h_ieee,
+                                     CallingConv::ARM_AAPCS);
+    } else {
+      Info.setLibcallImplCallingConv(RTLIB::__truncsfhf2,
+                                     CallingConv::ARM_APCS);
+      Info.setLibcallImplCallingConv(RTLIB::__truncdfhf2,
+                                     CallingConv::ARM_APCS);
+      Info.setLibcallImplCallingConv(RTLIB::__extendhfsf2,
+                                     CallingConv::ARM_APCS);
+      Info.setLibcallImplCallingConv(RTLIB::__gnu_h2f_ieee,
+                                     CallingConv::ARM_APCS);
+      Info.setLibcallImplCallingConv(RTLIB::__gnu_f2h_ieee,
+                                     CallingConv::ARM_APCS);
+    }
+  }
+
   static const RTLIB::LibcallImpl AAPCS_Libcalls[] = {
       RTLIB::__aeabi_dadd,        RTLIB::__aeabi_ddiv,
       RTLIB::__aeabi_dmul,        RTLIB::__aeabi_dsub,
@@ -77,7 +109,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
     setLibcallImpl(RTLIB::UNWIND_RESUME, RTLIB::_Unwind_SjLj_Resume);
 
   if (TT.isARM() || TT.isThumb()) {
-    setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
+    setARMLibcallNames(*this, TT, FloatABI, EABIVersion, ABIName);
     return;
   }
 
diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index 936625606e315..183e64e1c88d9 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -711,25 +711,6 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
     }
   }
 
-  // The half <-> float conversion functions are always soft-float on
-  // non-watchos platforms, but are needed for some targets which use a
-  // hard-float calling convention by default.
-  if (!TT.isWatchABI()) {
-    if (TM.isAAPCS_ABI()) {
-      setLibcallImplCallingConv(RTLIB::__truncsfhf2, CallingConv::ARM_AAPCS);
-      setLibcallImplCallingConv(RTLIB::__truncdfhf2, CallingConv::ARM_AAPCS);
-      setLibcallImplCallingConv(RTLIB::__extendhfsf2, CallingConv::ARM_AAPCS);
-      setLibcallImplCallingConv(RTLIB::__gnu_h2f_ieee, CallingConv::ARM_AAPCS);
-      setLibcallImplCallingConv(RTLIB::__gnu_f2h_ieee, CallingConv::ARM_AAPCS);
-    } else {
-      setLibcallImplCallingConv(RTLIB::__truncsfhf2, CallingConv::ARM_APCS);
-      setLibcallImplCallingConv(RTLIB::__truncdfhf2, CallingConv::ARM_APCS);
-      setLibcallImplCallingConv(RTLIB::__extendhfsf2, CallingConv::ARM_APCS);
-      setLibcallImplCallingConv(RTLIB::__gnu_h2f_ieee, CallingConv::ARM_APCS);
-      setLibcallImplCallingConv(RTLIB::__gnu_f2h_ieee, CallingConv::ARM_APCS);
-    }
-  }
-
   // In EABI, these functions have an __aeabi_ prefix, but in GNUEABI they have
   // a __gnu_ prefix (which is the default).
   if (TT.isTargetAEABI()) {

@arsenm arsenm marked this pull request as ready for review August 5, 2025 01:43
@llvmbot llvmbot added the llvm:ir label Aug 5, 2025
@arsenm arsenm force-pushed the users/arsenm/arm/move-calling-conv-config-runtime-libcalls branch 2 times, most recently from f012e8f to ea3013e Compare August 5, 2025 10:07
@arsenm arsenm force-pushed the users/arsenm/arm/move-calling-conv-config-runtime-libcalls branch from ea3013e to 2af18c4 Compare August 5, 2025 14:17
Consolidate module level ABI into RuntimeLibcalls
@arsenm arsenm force-pushed the users/arsenm/arm/move-calling-conv-config-runtime-libcalls branch from 2af18c4 to c644888 Compare August 6, 2025 03:10
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.

2 participants