1 //===-- XCoreSelectionDAGInfo.cpp - XCore SelectionDAG Info ---------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the XCoreSelectionDAGInfo class.
11 //===----------------------------------------------------------------------===//
13 #include "XCoreTargetMachine.h"
16 #define DEBUG_TYPE "xcore-selectiondag-info"
18 SDValue
XCoreSelectionDAGInfo::EmitTargetCodeForMemcpy(
19 SelectionDAG
&DAG
, const SDLoc
&dl
, SDValue Chain
, SDValue Dst
, SDValue Src
,
20 SDValue Size
, unsigned Align
, bool isVolatile
, bool AlwaysInline
,
21 MachinePointerInfo DstPtrInfo
, MachinePointerInfo SrcPtrInfo
) const {
22 unsigned SizeBitWidth
= Size
.getValueSizeInBits();
23 // Call __memcpy_4 if the src, dst and size are all 4 byte aligned.
24 if (!AlwaysInline
&& (Align
& 3) == 0 &&
25 DAG
.MaskedValueIsZero(Size
, APInt(SizeBitWidth
, 3))) {
26 const TargetLowering
&TLI
= *DAG
.getSubtarget().getTargetLowering();
27 TargetLowering::ArgListTy Args
;
28 TargetLowering::ArgListEntry Entry
;
29 Entry
.Ty
= DAG
.getDataLayout().getIntPtrType(*DAG
.getContext());
30 Entry
.Node
= Dst
; Args
.push_back(Entry
);
31 Entry
.Node
= Src
; Args
.push_back(Entry
);
32 Entry
.Node
= Size
; Args
.push_back(Entry
);
34 TargetLowering::CallLoweringInfo
CLI(DAG
);
37 .setLibCallee(TLI
.getLibcallCallingConv(RTLIB::MEMCPY
),
38 Type::getVoidTy(*DAG
.getContext()),
39 DAG
.getExternalSymbol(
40 "__memcpy_4", TLI
.getPointerTy(DAG
.getDataLayout())),
44 std::pair
<SDValue
,SDValue
> CallResult
= TLI
.LowerCallTo(CLI
);
45 return CallResult
.second
;
48 // Otherwise have the target-independent code call memcpy.