/// void *memmove(void *s1, const void *s2, size_t n);
TLI_DEFINE_ENUM_INTERNAL(memmove)
TLI_DEFINE_STRING_INTERNAL("memmove")
-/// void *mempcpy(void *s1, const void *s2, size_t n);
-TLI_DEFINE_ENUM_INTERNAL(mempcpy)
-TLI_DEFINE_STRING_INTERNAL("mempcpy")
// void *memrchr(const void *s, int c, size_t n);
TLI_DEFINE_ENUM_INTERNAL(memrchr)
TLI_DEFINE_STRING_INTERNAL("memrchr")
return false;
}
-///
-/// visitMemPCpyCall -- lower a mempcpy call as a memcpy followed by code to
-/// to adjust the dst pointer by the size of the copied memory.
-bool SelectionDAGBuilder::visitMemPCpyCall(const CallInst &I) {
-
- // Verify argument count: void *mempcpy(void *, const void *, size_t)
- if (I.getNumArgOperands() != 3)
- return false;
-
- SDValue Dst = getValue(I.getArgOperand(0));
- SDValue Src = getValue(I.getArgOperand(1));
- SDValue Size = getValue(I.getArgOperand(2));
-
- unsigned DstAlign = DAG.InferPtrAlignment(Dst);
- unsigned SrcAlign = DAG.InferPtrAlignment(Src);
- unsigned Align = std::min(DstAlign, SrcAlign);
- if (Align == 0) // Alignment of one or both could not be inferred.
- Align = 1; // 0 and 1 both specify no alignment, but 0 is reserved.
-
- bool isVol = false;
- SDLoc sdl = getCurSDLoc();
-
- // In the mempcpy context we need to pass in a false value for isTailCall
- // because the return pointer needs to be adjusted by the size of
- // the copied memory.
- SDValue MC = DAG.getMemcpy(getRoot(), sdl, Dst, Src, Size, Align, isVol,
- false, /*isTailCall=*/false,
- MachinePointerInfo(I.getArgOperand(0)),
- MachinePointerInfo(I.getArgOperand(1)));
- assert(MC.getNode() != nullptr &&
- "** memcpy should not be lowered as TailCall in mempcpy context **");
- DAG.setRoot(MC);
-
- // Check if Size needs to be truncated or extended.
- Size = DAG.getSExtOrTrunc(Size, sdl, Dst.getValueType());
-
- // Adjust return pointer to point just past the last dst byte.
- SDValue DstPlusSize = DAG.getNode(ISD::ADD, sdl, Dst.getValueType(),
- Dst, Size);
- setValue(&I, DstPlusSize);
- return true;
-}
-
/// visitStrCpyCall -- See if we can lower a strcpy or stpcpy call into an
/// optimized form. If so, return true and lower it, otherwise return false
/// and it will be lowered like a normal call.
if (visitMemCmpCall(I))
return;
break;
- case LibFunc::mempcpy:
- if (visitMemPCpyCall(I))
- return;
- break;
case LibFunc::memchr:
if (visitMemChrCall(I))
return;
; CHECK: declare i8* @memcpy(i8*, i8* nocapture readonly, i64) [[G0]]
declare i8* @memcpy(i8*, i8*, i64)
-; CHECK: declare i8* @mempcpy(i8*, i8* nocapture readonly, i64) [[G0]]
-declare i8* @mempcpy(i8*, i8*, i64)
-
; CHECK: declare i8* @memmove(i8*, i8* nocapture readonly, i64) [[G0]]
declare i8* @memmove(i8*, i8*, i64)