Skip to content

XCore: Declare libcalls used for align 4 memcpy #144976

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/hexagon/add-libcall-definitions-special-memcpy
Choose a base branch
from

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jun 20, 2025

This usage was hidden in XCoreSelectionDAGInfo and bypassed
the usual libcall system, so define these for later use.

This usage was hidden in XCoreSelectionDAGInfo and bypassed
the usual libcall system, so define these for later use.
@llvmbot
Copy link
Member

llvmbot commented Jun 20, 2025

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

This usage was hidden in XCoreSelectionDAGInfo and bypassed
the usual libcall system, so define these for later use.


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

3 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+9)
  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (+3)
  • (modified) llvm/lib/Target/XCore/XCoreSelectionDAGInfo.cpp (+8-5)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 2efe823a760db..57ad6f09e8b57 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -371,6 +371,9 @@ def AEABI_MEMCLR8 : RuntimeLibcall;
 // Hexagon calls
 def HEXAGON_MEMCPY_LIKELY_ALIGNED_MIN32BYTES_MULT8BYTES : RuntimeLibcall;
 
+// XCore calls
+def MEMCPY_ALIGN_4 : RuntimeLibcall;
+
 //--------------------------------------------------------------------
 // Define implementation default libcalls
 //--------------------------------------------------------------------
@@ -1544,6 +1547,12 @@ def _allrem : RuntimeLibcallImpl<SREM_I64>; // CallingConv::X86_StdCall
 def _aullrem : RuntimeLibcallImpl<UREM_I64>; // CallingConv::X86_StdCall
 def _allmul : RuntimeLibcallImpl<MUL_I64>; // CallingConv::X86_StdCall
 
+//===----------------------------------------------------------------------===//
+// XCore Runtime Libcalls
+//===----------------------------------------------------------------------===//
+
+def __memcpy_4 : RuntimeLibcallImpl<MEMCPY_ALIGN_4>;
+
 //===----------------------------------------------------------------------===//
 // ZOS Runtime Libcalls
 //===----------------------------------------------------------------------===//
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 873ee6b509e2d..0f92371f05529 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -627,4 +627,7 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
 
   if (TT.isSystemZ() && TT.isOSzOS())
     setZOSLibCallNameOverrides();
+
+  if (TT.getArch() == Triple::ArchType::xcore)
+    setLibcallImpl(RTLIB::MEMCPY_ALIGN_4, RTLIB::__memcpy_4);
 }
diff --git a/llvm/lib/Target/XCore/XCoreSelectionDAGInfo.cpp b/llvm/lib/Target/XCore/XCoreSelectionDAGInfo.cpp
index bc34ab4319690..1bd92a2b49475 100644
--- a/llvm/lib/Target/XCore/XCoreSelectionDAGInfo.cpp
+++ b/llvm/lib/Target/XCore/XCoreSelectionDAGInfo.cpp
@@ -39,14 +39,17 @@ SDValue XCoreSelectionDAGInfo::EmitTargetCodeForMemcpy(
     Entry.Node = Src; Args.push_back(Entry);
     Entry.Node = Size; Args.push_back(Entry);
 
+    const char *MemcpyAlign4Name = TLI.getLibcallName(RTLIB::MEMCPY_ALIGN_4);
+    CallingConv::ID CC = TLI.getLibcallCallingConv(RTLIB::MEMCPY_ALIGN_4);
+
     TargetLowering::CallLoweringInfo CLI(DAG);
     CLI.setDebugLoc(dl)
         .setChain(Chain)
-        .setLibCallee(TLI.getLibcallCallingConv(RTLIB::MEMCPY),
-                      Type::getVoidTy(*DAG.getContext()),
-                      DAG.getExternalSymbol(
-                          "__memcpy_4", TLI.getPointerTy(DAG.getDataLayout())),
-                      std::move(Args))
+        .setLibCallee(
+            CC, Type::getVoidTy(*DAG.getContext()),
+            DAG.getExternalSymbol(MemcpyAlign4Name,
+                                  TLI.getPointerTy(DAG.getDataLayout())),
+            std::move(Args))
         .setDiscardResult();
 
     std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI);

Copy link
Contributor

@nigelp-xmos nigelp-xmos left a comment

Choose a reason for hiding this comment

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

LGTM

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.

3 participants