https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/210963
>From 606bbb101a017b2e51c2bb52aa5997788cac02f6 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <[email protected]> Date: Tue, 21 Jul 2026 13:57:30 +0200 Subject: [PATCH] Hexagon: Stop excluding some generic compiler-rt functions from libcalls RuntimeLibcalls should indicate any function that exists and is callable. Historically the list of library functions was conflated with the library functions which should be used, so the library definition was complicated by excluding the overridden cases. My reading of the compiler-rt sources is that the generically named functions are built alongside the __hexagon prefixed variants. e.g., __divsi3 and __hexagon_divsi3 both exist. It will simplify future libcall work the fewer special case target exclusions there are, so allow the functions to be defined and apply the selection preference for the __hexagon prefixed versions in LibcallLoweringInfo. I do question why compiler-rt is built this way; why doesn't the hexagon just replace the standard entrypoint names with the target implementations? Co-authored-by: Claude (Claude-Opus-4.8) <[email protected]> --- llvm/include/llvm/IR/RuntimeLibcalls.td | 9 +++--- llvm/lib/Target/Hexagon/HexagonSubtarget.cpp | 29 ++++++++++++++++++++ llvm/lib/Target/Hexagon/HexagonSubtarget.h | 3 ++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index 1af3344023627..6a9585650ae5c 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -2756,12 +2756,13 @@ def hexagon_memcpy_forward_vp4cp4n2 : RuntimeLibcallImpl<HEXAGON_VOLATILE_MEMCPY def isHexagon : RuntimeLibcallAvailability<(all_of IsHexagon)>; +// The generic arithmetic/division helpers (__adddf3, __divsi3, ...) exist in +// Hexagon's compiler-rt alongside the preferred __hexagon_* variants, so both +// are available. Selection of the __hexagon_* variants is handled in +// HexagonSubtarget::initLibcallLoweringInfo. def HexagonSystemLibrary : SystemRuntimeLibrary<isHexagon, - (add (sub DefaultLibcallImpls32, - __adddf3, __divsf3, __udivsi3, __udivdi3, - __umoddi3, __divdf3, __muldf3, __divsi3, __subdf3, sqrtf, - __divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls, + (add DefaultLibcallImpls32, HexagonLibcalls, LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128, exp10f, exp10, exp10l_f128, __stack_chk_fail, __stack_chk_guard, DefaultSafeStackGlobals)>; diff --git a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp index 66c8b0a67169d..91e528f77da31 100644 --- a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp +++ b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp @@ -17,6 +17,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/CodeGen/LibcallLoweringInfo.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineScheduler.h" @@ -165,6 +166,34 @@ HexagonSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) { return *this; } +void HexagonSubtarget::initLibcallLoweringInfo( + LibcallLoweringInfo &Info) const { + // The generic arithmetic/division helper routines (__adddf3, __divsi3, ...) + // exist in Hexagon's compiler-rt alongside the preferred __hexagon_* + // variants, so both are available. The __hexagon_* variant is the one that + // must be used; select it explicitly here. + static const struct { + const RTLIB::Libcall Op; + const RTLIB::LibcallImpl Impl; + } LibraryCalls[] = { + {RTLIB::SDIV_I32, RTLIB::impl___hexagon_divsi3}, + {RTLIB::SDIV_I64, RTLIB::impl___hexagon_divdi3}, + {RTLIB::UDIV_I32, RTLIB::impl___hexagon_udivsi3}, + {RTLIB::UDIV_I64, RTLIB::impl___hexagon_udivdi3}, + {RTLIB::SREM_I32, RTLIB::impl___hexagon_modsi3}, + {RTLIB::SREM_I64, RTLIB::impl___hexagon_moddi3}, + {RTLIB::UREM_I32, RTLIB::impl___hexagon_umodsi3}, + {RTLIB::UREM_I64, RTLIB::impl___hexagon_umoddi3}, + {RTLIB::ADD_F64, RTLIB::impl___hexagon_adddf3}, + {RTLIB::SUB_F64, RTLIB::impl___hexagon_subdf3}, + {RTLIB::MUL_F64, RTLIB::impl___hexagon_muldf3}, + {RTLIB::DIV_F64, RTLIB::impl___hexagon_divdf3}, + {RTLIB::DIV_F32, RTLIB::impl___hexagon_divsf3}, + }; + for (const auto &LC : LibraryCalls) + Info.setLibcallImpl(LC.Op, LC.Impl); +} + bool HexagonSubtarget::isHVXElementType(MVT Ty, bool IncludeBool) const { if (!useHVXOps()) return false; diff --git a/llvm/lib/Target/Hexagon/HexagonSubtarget.h b/llvm/lib/Target/Hexagon/HexagonSubtarget.h index 2019bbf64b365..58fc3710d4412 100644 --- a/llvm/lib/Target/Hexagon/HexagonSubtarget.h +++ b/llvm/lib/Target/Hexagon/HexagonSubtarget.h @@ -35,6 +35,7 @@ namespace llvm { +class LibcallLoweringInfo; class MachineInstr; class SDep; class SUnit; @@ -137,6 +138,8 @@ class HexagonSubtarget : public HexagonGenSubtargetInfo { HexagonSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS); + void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override; + /// ParseSubtargetFeatures - Parses features string setting specified /// subtarget options. Definition of function is auto generated by tblgen. void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS); _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
