[llvm] [NFC] Refactor the SelectionDAG::getMemcmp etc with a existing helper function getRuntimeCallSDValueHelper (PR #184200)
zhijian lin via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 06:46:53 PST 2026
https://github.com/diggerlin updated https://github.com/llvm/llvm-project/pull/184200
>From c7c9130e38c3966b2a79a6ce8f62d1800e2c4271 Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Fri, 27 Feb 2026 15:39:24 +0000
Subject: [PATCH 1/2] refactor the code using a helper function
---
.../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 61 ++-----------------
1 file changed, 6 insertions(+), 55 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 4a2bd811b5214..f1a36b2bc2497 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -9406,84 +9406,35 @@ std::pair<SDValue, SDValue> SelectionDAG::getMemccpy(SDValue Chain,
std::pair<SDValue, SDValue>
SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
SDValue Mem1, SDValue Size, const CallInst *CI) {
- RTLIB::LibcallImpl MemcmpImpl = Libcalls->getLibcallImpl(RTLIB::MEMCMP);
- if (MemcmpImpl == RTLIB::Unsupported)
- return {};
-
PointerType *PT = PointerType::getUnqual(*getContext());
TargetLowering::ArgListTy Args = {
{Mem0, PT},
{Mem1, PT},
{Size, getDataLayout().getIntPtrType(*getContext())}};
-
- TargetLowering::CallLoweringInfo CLI(*this);
- bool IsTailCall =
- isInTailCallPositionWrapper(CI, this, /*AllowReturnsFirstArg*/ true);
-
- CLI.setDebugLoc(dl)
- .setChain(Chain)
- .setLibCallee(
- Libcalls->getLibcallImplCallingConv(MemcmpImpl),
- Type::getInt32Ty(*getContext()),
- getExternalSymbol(MemcmpImpl, TLI->getPointerTy(getDataLayout())),
- std::move(Args))
- .setTailCall(IsTailCall);
-
- return TLI->LowerCallTo(CLI);
+ return getRuntimeCallSDValueHelper(Chain, dl, std::move(Args), CI,
+ RTLIB::MEMCMP, this, TLI);
}
std::pair<SDValue, SDValue> SelectionDAG::getStrcpy(SDValue Chain,
const SDLoc &dl,
SDValue Dst, SDValue Src,
const CallInst *CI) {
- RTLIB::LibcallImpl LCImpl = Libcalls->getLibcallImpl(RTLIB::STRCPY);
- if (LCImpl == RTLIB::Unsupported)
- return {};
-
PointerType *PT = PointerType::getUnqual(*getContext());
TargetLowering::ArgListTy Args = {{Dst, PT}, {Src, PT}};
-
- TargetLowering::CallLoweringInfo CLI(*this);
- bool IsTailCall =
- isInTailCallPositionWrapper(CI, this, /*AllowReturnsFirstArg=*/true);
-
- CLI.setDebugLoc(dl)
- .setChain(Chain)
- .setLibCallee(
- Libcalls->getLibcallImplCallingConv(LCImpl), CI->getType(),
- getExternalSymbol(LCImpl, TLI->getPointerTy(getDataLayout())),
- std::move(Args))
- .setTailCall(IsTailCall);
-
- return TLI->LowerCallTo(CLI);
+ return getRuntimeCallSDValueHelper(Chain, dl, std::move(Args), CI,
+ RTLIB::STRCPY, this, TLI);
}
std::pair<SDValue, SDValue> SelectionDAG::getStrlen(SDValue Chain,
const SDLoc &dl,
SDValue Src,
const CallInst *CI) {
- RTLIB::LibcallImpl StrlenImpl = Libcalls->getLibcallImpl(RTLIB::STRLEN);
- if (StrlenImpl == RTLIB::Unsupported)
- return {};
-
// Emit a library call.
TargetLowering::ArgListTy Args = {
{Src, PointerType::getUnqual(*getContext())}};
-
+ return getRuntimeCallSDValueHelper(Chain, dl, std::move(Args), CI,
+ RTLIB::STRLEN, this, TLI);
TargetLowering::CallLoweringInfo CLI(*this);
- bool IsTailCall =
- isInTailCallPositionWrapper(CI, this, /*AllowReturnsFirstArg*/ true);
-
- CLI.setDebugLoc(dl)
- .setChain(Chain)
- .setLibCallee(Libcalls->getLibcallImplCallingConv(StrlenImpl),
- CI->getType(),
- getExternalSymbol(
- StrlenImpl, TLI->getProgramPointerTy(getDataLayout())),
- std::move(Args))
- .setTailCall(IsTailCall);
-
- return TLI->LowerCallTo(CLI);
}
SDValue SelectionDAG::getMemcpy(
>From 1c4f51395dc7e29472bfeacd308e5fed7c794df4 Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Tue, 3 Mar 2026 14:58:31 +0000
Subject: [PATCH 2/2] delete dead code
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index f1a36b2bc2497..9eb70cb2d3e9a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -9434,7 +9434,6 @@ std::pair<SDValue, SDValue> SelectionDAG::getStrlen(SDValue Chain,
{Src, PointerType::getUnqual(*getContext())}};
return getRuntimeCallSDValueHelper(Chain, dl, std::move(Args), CI,
RTLIB::STRLEN, this, TLI);
- TargetLowering::CallLoweringInfo CLI(*this);
}
SDValue SelectionDAG::getMemcpy(
More information about the llvm-commits
mailing list