Skip to content

ARM: Add runtime libcall definitions for aebi memory functions #144974

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 Jun 20, 2025

Fix bypassing ordinary RuntimeLibcalls APIs for cases handled
in ARMSelectionDAGInfo

@llvmbot
Copy link
Member

llvmbot commented Jun 20, 2025

@llvm/pr-subscribers-backend-arm

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

Fix bypassing ordinary RuntimeLibcalls APIs for cases handled
in ARMSelectionDAGInfo


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

3 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+23)
  • (modified) llvm/lib/Target/ARM/ARMISelLowering.cpp (+17)
  • (modified) llvm/lib/Target/ARM/ARMSelectionDAGInfo.cpp (+10-8)
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<string libcall_basename = !toupper(NAME),
                            !strconcat(rtbasename, "l")>;
 }
 
+// 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<UDIVREM_I32>; //  CallingConv::ARM_AAP
 // Memory operations
 // RTABI chapter 4.3.4
 def __aeabi_memcpy : RuntimeLibcallImpl<MEMCPY>; // CallingConv::ARM_AAPCS
+def __aeabi_memcpy4 : RuntimeLibcallImpl<AEABI_MEMCPY4>;
+def __aeabi_memcpy8 : RuntimeLibcallImpl<AEABI_MEMCPY8>;
+
 def __aeabi_memmove : RuntimeLibcallImpl<MEMMOVE>; // CallingConv::ARM_AAPCS
+def __aeabi_memmove4 : RuntimeLibcallImpl<AEABI_MEMMOVE4>;
+def __aeabi_memmove8 : RuntimeLibcallImpl<AEABI_MEMMOVE8>;
+
 def __aeabi_memset : RuntimeLibcallImpl<MEMSET>; // CallingConv::ARM_AAPCS
+def __aeabi_memset4 : RuntimeLibcallImpl<AEABI_MEMSET4>;
+def __aeabi_memset8 : RuntimeLibcallImpl<AEABI_MEMSET8>;
+
+def __aeabi_memclr : RuntimeLibcallImpl<AEABI_MEMCLR>;
+def __aeabi_memclr4 : RuntimeLibcallImpl<AEABI_MEMCLR4>;
+def __aeabi_memclr8 : RuntimeLibcallImpl<AEABI_MEMCLR8>;
 
 // isTargetWindows()
 def __stoi64 : RuntimeLibcallImpl<FPTOSINT_F32_I64>; // CallingConv::ARM_AAPCS_VFP
diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index 81b535e19bc71..478791699df88 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();

@arsenm arsenm force-pushed the users/arsenm/arm/add-libcall-definitions-eabi-memory-functions branch from bdbc320 to 8fec74a Compare June 23, 2025 13:27
@arsenm arsenm force-pushed the users/arsenm/tablegen/generate-runtime-libcall-impl-enum branch 2 times, most recently from 34ec1d9 to d0d6a5b Compare June 25, 2025 12:42
@arsenm arsenm force-pushed the users/arsenm/arm/add-libcall-definitions-eabi-memory-functions branch 2 times, most recently from 6bfbefe to c18ce19 Compare June 27, 2025 07:31
@arsenm arsenm force-pushed the users/arsenm/tablegen/generate-runtime-libcall-impl-enum branch from d0d6a5b to d5ea33f Compare June 27, 2025 07:31
Copy link
Contributor Author

arsenm commented Jun 27, 2025

Merge activity

  • Jun 27, 8:33 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 27, 8:41 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 27, 8:43 AM UTC: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/tablegen/generate-runtime-libcall-impl-enum branch from d5ea33f to 460bf5d Compare June 27, 2025 08:37
Base automatically changed from users/arsenm/tablegen/generate-runtime-libcall-impl-enum to main June 27, 2025 08:40
Fix bypassing ordinary RuntimeLibcalls APIs for cases handled
in ARMSelectionDAGInfo
@arsenm arsenm force-pushed the users/arsenm/arm/add-libcall-definitions-eabi-memory-functions branch from c18ce19 to 3271772 Compare June 27, 2025 08:40
@arsenm arsenm merged commit 4243e50 into main Jun 27, 2025
5 of 7 checks passed
@arsenm arsenm deleted the users/arsenm/arm/add-libcall-definitions-eabi-memory-functions branch June 27, 2025 08:43
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