From 8fec74a8e1d393ce11ee4a9b5a0b0d6c6572f190 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 16 Jun 2025 15:50:24 +0900 Subject: [PATCH] ARM: Add runtime libcall definitions for eabi memory functions Fix bypassing ordinary RuntimeLibcalls APIs for cases handled in ARMSelectionDAGInfo --- llvm/include/llvm/IR/RuntimeLibcalls.td | 23 +++++++++++++++++++++ llvm/lib/Target/ARM/ARMISelLowering.cpp | 17 +++++++++++++++ llvm/lib/Target/ARM/ARMSelectionDAGInfo.cpp | 18 +++++++++------- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td index c910fce2edd80..71efecdf082af 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.td +++ b/llvm/include/llvm/IR/RuntimeLibcalls.td @@ -357,6 +357,17 @@ multiclass LibmLongDoubleLibCall; } +// ARM EABI calls +def AEABI_MEMCPY4 : RuntimeLibcall; // Align 4 +def AEABI_MEMCPY8 : RuntimeLibcall; // Align 8 +def AEABI_MEMMOVE4 : RuntimeLibcall; +def AEABI_MEMMOVE8 : RuntimeLibcall; +def AEABI_MEMSET4 : RuntimeLibcall; +def AEABI_MEMSET8 : RuntimeLibcall; +def AEABI_MEMCLR : RuntimeLibcall; +def AEABI_MEMCLR4 : RuntimeLibcall; +def AEABI_MEMCLR8 : RuntimeLibcall; + //-------------------------------------------------------------------- // Define implementation default libcalls //-------------------------------------------------------------------- @@ -1134,8 +1145,20 @@ def __aeabi_uidivmod : RuntimeLibcallImpl; // CallingConv::ARM_AAP // Memory operations // RTABI chapter 4.3.4 def __aeabi_memcpy : RuntimeLibcallImpl; // CallingConv::ARM_AAPCS +def __aeabi_memcpy4 : RuntimeLibcallImpl; +def __aeabi_memcpy8 : RuntimeLibcallImpl; + def __aeabi_memmove : RuntimeLibcallImpl; // CallingConv::ARM_AAPCS +def __aeabi_memmove4 : RuntimeLibcallImpl; +def __aeabi_memmove8 : RuntimeLibcallImpl; + def __aeabi_memset : RuntimeLibcallImpl; // CallingConv::ARM_AAPCS +def __aeabi_memset4 : RuntimeLibcallImpl; +def __aeabi_memset8 : RuntimeLibcallImpl; + +def __aeabi_memclr : RuntimeLibcallImpl; +def __aeabi_memclr4 : RuntimeLibcallImpl; +def __aeabi_memclr8 : RuntimeLibcallImpl; // isTargetWindows() def __stoi64 : RuntimeLibcallImpl; // CallingConv::ARM_AAPCS_VFP diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index 809e15dbb56b0..b4c2ad55d1b33 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -704,6 +704,23 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_, {RTLIB::MEMCPY, RTLIB::__aeabi_memcpy, CallingConv::ARM_AAPCS}, {RTLIB::MEMMOVE, RTLIB::__aeabi_memmove, CallingConv::ARM_AAPCS}, {RTLIB::MEMSET, RTLIB::__aeabi_memset, CallingConv::ARM_AAPCS}, + {RTLIB::AEABI_MEMCPY4, RTLIB::__aeabi_memcpy4, + CallingConv::ARM_AAPCS}, + {RTLIB::AEABI_MEMCPY8, RTLIB::__aeabi_memcpy8, + CallingConv::ARM_AAPCS}, + {RTLIB::AEABI_MEMMOVE4, RTLIB::__aeabi_memmove4, + CallingConv::ARM_AAPCS}, + {RTLIB::AEABI_MEMMOVE8, RTLIB::__aeabi_memmove8, + CallingConv::ARM_AAPCS}, + {RTLIB::AEABI_MEMSET4, RTLIB::__aeabi_memset4, + CallingConv::ARM_AAPCS}, + {RTLIB::AEABI_MEMSET8, RTLIB::__aeabi_memset8, + CallingConv::ARM_AAPCS}, + {RTLIB::AEABI_MEMCLR, RTLIB::__aeabi_memclr, CallingConv::ARM_AAPCS}, + {RTLIB::AEABI_MEMCLR4, RTLIB::__aeabi_memclr4, + CallingConv::ARM_AAPCS}, + {RTLIB::AEABI_MEMCLR8, RTLIB::__aeabi_memclr8, + CallingConv::ARM_AAPCS}, }; for (const auto &LC : MemOpsLibraryCalls) { diff --git a/llvm/lib/Target/ARM/ARMSelectionDAGInfo.cpp b/llvm/lib/Target/ARM/ARMSelectionDAGInfo.cpp index 77f4782699c96..b4677a8bfb035 100644 --- a/llvm/lib/Target/ARM/ARMSelectionDAGInfo.cpp +++ b/llvm/lib/Target/ARM/ARMSelectionDAGInfo.cpp @@ -121,18 +121,20 @@ SDValue ARMSelectionDAGInfo::EmitSpecializedLibcall( Args.push_back(Entry); } - char const *FunctionNames[4][3] = { - { "__aeabi_memcpy", "__aeabi_memcpy4", "__aeabi_memcpy8" }, - { "__aeabi_memmove", "__aeabi_memmove4", "__aeabi_memmove8" }, - { "__aeabi_memset", "__aeabi_memset4", "__aeabi_memset8" }, - { "__aeabi_memclr", "__aeabi_memclr4", "__aeabi_memclr8" } - }; + static const RTLIB::Libcall FunctionImpls[4][3] = { + {RTLIB::MEMCPY, RTLIB::AEABI_MEMCPY4, RTLIB::AEABI_MEMCPY8}, + {RTLIB::MEMMOVE, RTLIB::AEABI_MEMMOVE4, RTLIB::AEABI_MEMMOVE8}, + {RTLIB::MEMSET, RTLIB::AEABI_MEMSET4, RTLIB::AEABI_MEMSET8}, + {RTLIB::AEABI_MEMCLR, RTLIB::AEABI_MEMCLR4, RTLIB::AEABI_MEMCLR8}}; + + RTLIB::Libcall NewLC = FunctionImpls[AEABILibcall][AlignVariant]; + TargetLowering::CallLoweringInfo CLI(DAG); CLI.setDebugLoc(dl) .setChain(Chain) .setLibCallee( - TLI->getLibcallCallingConv(LC), Type::getVoidTy(*DAG.getContext()), - DAG.getExternalSymbol(FunctionNames[AEABILibcall][AlignVariant], + TLI->getLibcallCallingConv(NewLC), Type::getVoidTy(*DAG.getContext()), + DAG.getExternalSymbol(TLI->getLibcallName(NewLC), TLI->getPointerTy(DAG.getDataLayout())), std::move(Args)) .setDiscardResult();