1//===-- XCoreSelectionDAGInfo.cpp - XCore SelectionDAG Info ---------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the XCoreSelectionDAGInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "XCoreSelectionDAGInfo.h"
14#include "XCoreTargetMachine.h"
15
16#define GET_SDNODE_DESC
17#include "XCoreGenSDNodeInfo.inc"
18
19using namespace llvm;
20
21#define DEBUG_TYPE "xcore-selectiondag-info"
22
23XCoreSelectionDAGInfo::XCoreSelectionDAGInfo()
24 : SelectionDAGGenTargetInfo(XCoreGenSDNodeInfo) {}
25
26SDValue XCoreSelectionDAGInfo::EmitTargetCodeForMemcpy(
27 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
28 SDValue Size, Align DstAlign, Align SrcAlign, bool isVolatile,
29 bool AlwaysInline, MachinePointerInfo DstPtrInfo,
30 MachinePointerInfo SrcPtrInfo) const {
31 unsigned SizeBitWidth = Size.getValueSizeInBits();
32 // Call __memcpy_4 if the src, dst and size are all 4 byte aligned.
33 if (!AlwaysInline && SrcAlign >= Align(4) && DstAlign >= Align(4) &&
34 DAG.MaskedValueIsZero(Op: Size, Mask: APInt(SizeBitWidth, 3))) {
35 const TargetLowering &TLI = *DAG.getSubtarget().getTargetLowering();
36 TargetLowering::ArgListTy Args;
37 Type *ArgTy = DAG.getDataLayout().getIntPtrType(C&: *DAG.getContext());
38 Args.emplace_back(args&: Dst, args&: ArgTy);
39 Args.emplace_back(args&: Src, args&: ArgTy);
40 Args.emplace_back(args&: Size, args&: ArgTy);
41
42 RTLIB::LibcallImpl MemcpyAlign4Impl =
43 DAG.getLibcalls().getLibcallImpl(Call: RTLIB::MEMCPY_ALIGN_4);
44 if (MemcpyAlign4Impl == RTLIB::Unsupported)
45 return SDValue();
46
47 CallingConv::ID CC =
48 DAG.getLibcalls().getLibcallImplCallingConv(Call: MemcpyAlign4Impl);
49
50 TargetLowering::CallLoweringInfo CLI(DAG);
51 CLI.setDebugLoc(dl)
52 .setChain(Chain)
53 .setLibCallee(
54 CC, ResultType: Type::getVoidTy(C&: *DAG.getContext()),
55 Target: DAG.getExternalSymbol(LCImpl: MemcpyAlign4Impl,
56 VT: TLI.getPointerTy(DL: DAG.getDataLayout())),
57 ArgsList: std::move(Args))
58 .setDiscardResult();
59
60 std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI);
61 return CallResult.second;
62 }
63
64 // Otherwise have the target-independent code call memcpy.
65 return SDValue();
66}
67