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 "XCoreTargetMachine.h"
14 using namespace llvm;
15
16 #define DEBUG_TYPE "xcore-selectiondag-info"
17
EmitTargetCodeForMemcpy(SelectionDAG & DAG,const SDLoc & dl,SDValue Chain,SDValue Dst,SDValue Src,SDValue Size,Align Alignment,bool isVolatile,bool AlwaysInline,bool MustPreserveCheriCapabilities,MachinePointerInfo DstPtrInfo,MachinePointerInfo SrcPtrInfo) const18 SDValue XCoreSelectionDAGInfo::EmitTargetCodeForMemcpy(
19 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
20 SDValue Size, Align Alignment, bool isVolatile, bool AlwaysInline,
21 bool MustPreserveCheriCapabilities, MachinePointerInfo DstPtrInfo,
22 MachinePointerInfo SrcPtrInfo) const {
23 unsigned SizeBitWidth = Size.getValueSizeInBits();
24 // Call __memcpy_4 if the src, dst and size are all 4 byte aligned.
25 if (!AlwaysInline && Alignment >= Align(4) &&
26 DAG.MaskedValueIsZero(Size, APInt(SizeBitWidth, 3))) {
27 const TargetLowering &TLI = *DAG.getSubtarget().getTargetLowering();
28 TargetLowering::ArgListTy Args;
29 TargetLowering::ArgListEntry Entry;
30 Entry.Ty = DAG.getDataLayout().getIntPtrType(*DAG.getContext());
31 Entry.Node = Dst; Args.push_back(Entry);
32 Entry.Node = Src; Args.push_back(Entry);
33 Entry.Node = Size; Args.push_back(Entry);
34
35 TargetLowering::CallLoweringInfo CLI(DAG);
36 CLI.setDebugLoc(dl)
37 .setChain(Chain)
38 .setLibCallee(TLI.getLibcallCallingConv(RTLIB::MEMCPY),
39 Type::getVoidTy(*DAG.getContext()),
40 DAG.getExternalFunctionSymbol("__memcpy_4"),
41 std::move(Args))
42 .setDiscardResult();
43
44 std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI);
45 return CallResult.second;
46 }
47
48 // Otherwise have the target-independent code call memcpy.
49 return SDValue();
50 }
51