Skip to content

Hexagon: Move runtime libcall configuration to tablegen #147482

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: users/arsenm/dag/use-fast-variants-math-libcalls
Choose a base branch
from

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jul 8, 2025

No description provided.

Copy link
Contributor Author

arsenm commented Jul 8, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm added backend:Hexagon llvm:SelectionDAG SelectionDAGISel as well labels Jul 8, 2025 — with Graphite App
@arsenm arsenm marked this pull request as ready for review July 8, 2025 08:24
@llvmbot
Copy link
Member

llvmbot commented Jul 8, 2025

@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-backend-hexagon

Author: Matt Arsenault (arsenm)

Changes

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

2 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+11)
  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (-35)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 2099aae877861..e40e71f13af42 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -1414,6 +1414,7 @@ def AVRSystemLibrary
 // Hexagon Runtime Libcalls
 //===----------------------------------------------------------------------===//
 
+defset list<RuntimeLibcallImpl> HexagonLibcalls = {
 def __hexagon_divsi3 : RuntimeLibcallImpl<SDIV_I32>;
 def __hexagon_divdi3 : RuntimeLibcallImpl<SDIV_I64>;
 def __hexagon_udivsi3 : RuntimeLibcallImpl<UDIV_I32>;
@@ -1446,6 +1447,16 @@ def __hexagon_fast2_sqrtdf2 : RuntimeLibcallImpl<FAST_SQRT_F64>;
 
 def __hexagon_memcpy_likely_aligned_min32bytes_mult8bytes
     : RuntimeLibcallImpl<HEXAGON_MEMCPY_LIKELY_ALIGNED_MIN32BYTES_MULT8BYTES>;
+}
+
+def isHexagon : RuntimeLibcallPredicate<"TT.getArch() == Triple::hexagon">;
+
+def HexagonSystemLibrary
+    : SystemRuntimeLibrary<isHexagon,
+    (add (sub DefaultLibcallImpls32,
+    __adddf3, __divsf3, __udivsi3, __udivdi3,
+    __umoddi3, __divdf3, __muldf3, __divsi3, __subdf3, sqrtf,
+    __divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls)>;
 
 //===----------------------------------------------------------------------===//
 // Lanai Runtime Libcalls
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index b60b065c80346..179cc0b1ef58d 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -254,41 +254,6 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
     setLibcallImpl(RTLIB::MULO_I128, RTLIB::Unsupported);
   }
 
-  if (TT.getArch() == Triple::ArchType::hexagon) {
-    setLibcallImpl(RTLIB::SDIV_I32, RTLIB::__hexagon_divsi3);
-    setLibcallImpl(RTLIB::SDIV_I64, RTLIB::__hexagon_divdi3);
-    setLibcallImpl(RTLIB::UDIV_I32, RTLIB::__hexagon_udivsi3);
-    setLibcallImpl(RTLIB::UDIV_I64, RTLIB::__hexagon_udivdi3);
-    setLibcallImpl(RTLIB::SREM_I32, RTLIB::__hexagon_modsi3);
-    setLibcallImpl(RTLIB::SREM_I64, RTLIB::__hexagon_moddi3);
-    setLibcallImpl(RTLIB::UREM_I32, RTLIB::__hexagon_umodsi3);
-    setLibcallImpl(RTLIB::UREM_I64, RTLIB::__hexagon_umoddi3);
-
-    // Prefix is: nothing  for "slow-math",
-    //            "fast2_" for V5+ fast-math double-precision
-    // (actually, keep fast-math and fast-math2 separate for now)
-
-    setLibcallImpl(RTLIB::FAST_ADD_F64, RTLIB::__hexagon_fast_adddf3);
-    setLibcallImpl(RTLIB::FAST_SUB_F64, RTLIB::__hexagon_fast_subdf3);
-    setLibcallImpl(RTLIB::FAST_MUL_F64, RTLIB::__hexagon_fast_muldf3);
-    setLibcallImpl(RTLIB::FAST_DIV_F64, RTLIB::__hexagon_fast_divdf3);
-    setLibcallImpl(RTLIB::FAST_DIV_F32, RTLIB::__hexagon_fast_divsf3);
-    setLibcallImpl(RTLIB::FAST_SQRT_F32, RTLIB::__hexagon_fast2_sqrtf);
-    // This is the only fast library function for sqrtd.
-    setLibcallImpl(RTLIB::FAST_SQRT_F64, RTLIB::__hexagon_fast2_sqrtdf2);
-
-    setLibcallImpl(RTLIB::ADD_F64, RTLIB::__hexagon_adddf3);
-    setLibcallImpl(RTLIB::SUB_F64, RTLIB::__hexagon_subdf3);
-    setLibcallImpl(RTLIB::MUL_F64, RTLIB::__hexagon_muldf3);
-    setLibcallImpl(RTLIB::DIV_F64, RTLIB::__hexagon_divdf3);
-    setLibcallImpl(RTLIB::DIV_F32, RTLIB::__hexagon_divsf3);
-    setLibcallImpl(RTLIB::SQRT_F32, RTLIB::__hexagon_sqrtf);
-
-    setLibcallImpl(
-        RTLIB::HEXAGON_MEMCPY_LIKELY_ALIGNED_MIN32BYTES_MULT8BYTES,
-        RTLIB::__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes);
-  }
-
   if (TT.getArch() == Triple::ArchType::msp430) {
     setLibcallImplCallingConv(RTLIB::__mspabi_mpyll,
                               CallingConv::MSP430_BUILTIN);

@llvmbot llvmbot added the llvm:ir label Jul 8, 2025
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

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

LGTM

@arsenm arsenm force-pushed the users/arsenm/hexagon/move-runtime-libcall-config-tablegen branch from 454e0e4 to ef8813a Compare July 8, 2025 13:05
@arsenm arsenm force-pushed the users/arsenm/dag/use-fast-variants-math-libcalls branch from 920b061 to 24ff719 Compare July 8, 2025 13:05
@arsenm arsenm force-pushed the users/arsenm/hexagon/move-runtime-libcall-config-tablegen branch from 8c552af to 48350d5 Compare July 9, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants