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 Alignment, bool isVolatile, bool AlwaysInline,
29 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
30 unsigned SizeBitWidth = Size.getValueSizeInBits();
31 // Call __memcpy_4 if the src, dst and size are all 4 byte aligned.
32 if (!AlwaysInline && Alignment >= Align(4) &&
33 DAG.MaskedValueIsZero(Op: Size, Mask: APInt(SizeBitWidth, 3))) {
34 const TargetLowering &TLI = *DAG.getSubtarget().getTargetLowering();
35 TargetLowering::ArgListTy Args;
36 Type *ArgTy = DAG.getDataLayout().getIntPtrType(C&: *DAG.getContext());
37 Args.emplace_back(args&: Dst, args&: ArgTy);
38 Args.emplace_back(args&: Src, args&: ArgTy);
39 Args.emplace_back(args&: Size, args&: ArgTy);
40
41 RTLIB::LibcallImpl MemcpyAlign4Impl =
42 DAG.getLibcalls().getLibcallImpl(Call: RTLIB::MEMCPY_ALIGN_4);
43 if (MemcpyAlign4Impl == RTLIB::Unsupported)
44 return SDValue();
45
46 CallingConv::ID CC =
47 DAG.getLibcalls().getLibcallImplCallingConv(Call: MemcpyAlign4Impl);
48
49 TargetLowering::CallLoweringInfo CLI(DAG);
50 CLI.setDebugLoc(dl)
51 .setChain(Chain)
52 .setLibCallee(
53 CC, ResultType: Type::getVoidTy(C&: *DAG.getContext()),
54 Target: DAG.getExternalSymbol(LCImpl: MemcpyAlign4Impl,
55 VT: TLI.getPointerTy(DL: DAG.getDataLayout())),
56 ArgsList: std::move(Args))
57 .setDiscardResult();
58
59 std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI);
60 return CallResult.second;
61 }
62
63 // Otherwise have the target-independent code call memcpy.
64 return SDValue();
65}
66