Skip to content

Commit 91fb8a7

Browse files
committed
address comment
1 parent c973526 commit 91fb8a7

File tree

10 files changed

+63
-8
lines changed

10 files changed

+63
-8
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,9 @@ class SelectionDAG {
12531253
/// stack arguments from being clobbered.
12541254
LLVM_ABI SDValue getStackArgumentTokenFactor(SDValue Chain);
12551255

1256+
std::pair<SDValue, SDValue> getMemcmp(SDValue Chain, const SDLoc &dl,
1257+
SDValue Dst, SDValue Src, SDValue Size,
1258+
const CallInst *CI);
12561259
/* \p CI if not null is the memset call being lowered.
12571260
* \p OverrideTailCall is an optional parameter that can be used to override
12581261
* the tail call optimization decision. */

llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
namespace llvm {
2525

2626
class SelectionDAG;
27-
27+
class CallInst;
2828
//===----------------------------------------------------------------------===//
2929
/// Targets can subclass this to parameterize the
3030
/// SelectionDAG lowering and instruction selection process.
@@ -118,8 +118,7 @@ class SelectionDAGTargetInfo {
118118
virtual std::pair<SDValue, SDValue>
119119
EmitTargetCodeForMemcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
120120
SDValue Op1, SDValue Op2, SDValue Op3,
121-
MachinePointerInfo Op1PtrInfo,
122-
MachinePointerInfo Op2PtrInfo) const {
121+
const CallInst *CI) const {
123122
return std::make_pair(SDValue(), SDValue());
124123
}
125124

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ foreach FPTy = ["F32", "F64", "F128", "PPCF128"] in {
241241
}
242242

243243
// Memory
244+
def MEMCMP : RuntimeLibcall;
244245
def MEMCPY : RuntimeLibcall;
245246
def MEMMOVE : RuntimeLibcall;
246247
def MEMSET : RuntimeLibcall;
@@ -1485,11 +1486,13 @@ def __gtkf2 : PPCRuntimeLibcallImpl<OGT_F128>;
14851486
def __unordkf2 : PPCRuntimeLibcallImpl<UO_F128>;
14861487

14871488
// PPC64 && Subtarget.isAIXABI()
1489+
def ___memcmp64 : RuntimeLibcallImpl<MEMCPY>;
14881490
def ___memmove64 : RuntimeLibcallImpl<MEMCPY>;
14891491
def ___memset64 : RuntimeLibcallImpl<MEMSET>;
14901492
def ___bzero64 : RuntimeLibcallImpl<BZERO>;
14911493

14921494
// !PPC64 && Subtarget.isAIXABI()
1495+
def ___memcmp : RuntimeLibcallImpl<MEMCMP>;
14931496
def ___memmove : RuntimeLibcallImpl<MEMMOVE>;
14941497
def ___memset : RuntimeLibcallImpl<MEMSET>;
14951498
def ___bzero : RuntimeLibcallImpl<BZERO>;

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8743,6 +8743,45 @@ static void checkAddrSpaceIsValidForLibcall(const TargetLowering *TLI,
87438743
Twine(AS));
87448744
}
87458745
}
8746+
std::pair<SDValue, SDValue>
8747+
SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
8748+
SDValue Mem1, SDValue Size, const CallInst *CI) {
8749+
8750+
const char *LibCallName = TLI->getLibcallName(RTLIB::MEMCMP);
8751+
if (LibCallName == nullptr)
8752+
return std::make_pair(SDValue(), SDValue());
8753+
// Emit a library call.
8754+
TargetLowering::ArgListTy Args;
8755+
TargetLowering::ArgListEntry Entry;
8756+
Entry.Ty = PointerType::getUnqual(*getContext());
8757+
Entry.Node = Mem0;
8758+
Args.push_back(Entry);
8759+
Entry.Node = Mem1;
8760+
Args.push_back(Entry);
8761+
8762+
Entry.Ty = getDataLayout().getIntPtrType(*getContext());
8763+
Entry.Node = Size;
8764+
Args.push_back(Entry);
8765+
8766+
// FIXME: pass in SDLoc
8767+
TargetLowering::CallLoweringInfo CLI(*this);
8768+
bool IsTailCall = false;
8769+
bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
8770+
IsTailCall = CI && CI->isTailCall() &&
8771+
isInTailCallPosition(*CI, getTarget(), ReturnsFirstArg);
8772+
8773+
CLI.setDebugLoc(dl)
8774+
.setChain(Chain)
8775+
.setLibCallee(
8776+
TLI->getLibcallCallingConv(RTLIB::MEMCMP),
8777+
Type::getInt32Ty(*getContext()),
8778+
getExternalSymbol(LibCallName, TLI->getPointerTy(getDataLayout())),
8779+
std::move(Args))
8780+
.setTailCall(IsTailCall);
8781+
8782+
std::pair<SDValue, SDValue> CallResult = TLI->LowerCallTo(CLI);
8783+
return CallResult;
8784+
}
87468785

87478786
SDValue SelectionDAG::getMemcpy(
87488787
SDValue Chain, const SDLoc &dl, SDValue Dst, SDValue Src, SDValue Size,

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9056,7 +9056,7 @@ bool SelectionDAGBuilder::visitMemCmpBCmpCall(const CallInst &I) {
90569056
const SelectionDAGTargetInfo &TSI = DAG.getSelectionDAGInfo();
90579057
std::pair<SDValue, SDValue> Res = TSI.EmitTargetCodeForMemcmp(
90589058
DAG, getCurSDLoc(), DAG.getRoot(), getValue(LHS), getValue(RHS),
9059-
getValue(Size), MachinePointerInfo(LHS), MachinePointerInfo(RHS));
9059+
getValue(Size), &I);
90609060
if (Res.first.getNode()) {
90619061
processIntegerCallValue(I, Res.first, true);
90629062
PendingLoads.push_back(Res.second);

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,13 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
376376
// TODO: Tablegen predicate support
377377
if (TT.isOSAIX()) {
378378
if (TT.isPPC64()) {
379+
setLibcallImpl(RTLIB::MEMCMP, RTLIB::___memcmp64);
379380
setLibcallImpl(RTLIB::MEMCPY, RTLIB::Unsupported);
380381
setLibcallImpl(RTLIB::MEMMOVE, RTLIB::___memmove64);
381382
setLibcallImpl(RTLIB::MEMSET, RTLIB::___memset64);
382383
setLibcallImpl(RTLIB::BZERO, RTLIB::___bzero64);
383384
} else {
385+
setLibcallImpl(RTLIB::MEMCMP, RTLIB::___memcmp);
384386
setLibcallImpl(RTLIB::MEMCPY, RTLIB::Unsupported);
385387
setLibcallImpl(RTLIB::MEMMOVE, RTLIB::___memmove);
386388
setLibcallImpl(RTLIB::MEMSET, RTLIB::___memset);

llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ bool PPCSelectionDAGInfo::isTargetStrictFPOpcode(unsigned Opcode) const {
2222
return Opcode >= PPCISD::FIRST_STRICTFP_OPCODE &&
2323
Opcode <= PPCISD::LAST_STRICTFP_OPCODE;
2424
}
25+
26+
std::pair<SDValue, SDValue> PPCSelectionDAGInfo::EmitTargetCodeForMemcmp(
27+
SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Op1, SDValue Op2,
28+
SDValue Op3, const CallInst *CI) const {
29+
return DAG.getMemcmp(Chain, dl, Op1, Op2, Op3, CI);
30+
}

llvm/lib/Target/PowerPC/PPCSelectionDAGInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class PPCSelectionDAGInfo : public SelectionDAGTargetInfo {
2020
bool isTargetMemoryOpcode(unsigned Opcode) const override;
2121

2222
bool isTargetStrictFPOpcode(unsigned Opcode) const override;
23+
24+
std::pair<SDValue, SDValue>
25+
EmitTargetCodeForMemcmp(SelectionDAG &DAG, const SDLoc &dl, SDValue Chain,
26+
SDValue Op1, SDValue Op2, SDValue Op3,
27+
const CallInst *CI) const;
2328
};
2429

2530
} // namespace llvm

llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ static SDValue addIPMSequence(const SDLoc &DL, SDValue CCReg,
181181

182182
std::pair<SDValue, SDValue> SystemZSelectionDAGInfo::EmitTargetCodeForMemcmp(
183183
SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Src1,
184-
SDValue Src2, SDValue Size, MachinePointerInfo Op1PtrInfo,
185-
MachinePointerInfo Op2PtrInfo) const {
184+
SDValue Src2, SDValue Size, const CallInst *CI) const {
186185
SDValue CCReg;
187186
// Swap operands to invert CC == 1 vs. CC == 2 cases.
188187
if (auto *CSize = dyn_cast<ConstantSDNode>(Size)) {

llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ class SystemZSelectionDAGInfo : public SelectionDAGTargetInfo {
4141
std::pair<SDValue, SDValue>
4242
EmitTargetCodeForMemcmp(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,
4343
SDValue Src1, SDValue Src2, SDValue Size,
44-
MachinePointerInfo Op1PtrInfo,
45-
MachinePointerInfo Op2PtrInfo) const override;
44+
const CallInst *CI) const override;
4645

4746
std::pair<SDValue, SDValue>
4847
EmitTargetCodeForMemchr(SelectionDAG &DAG, const SDLoc &DL, SDValue Chain,

0 commit comments

Comments
 (0)