| 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 | |
| 19 | using namespace llvm; |
| 20 | |
| 21 | #define DEBUG_TYPE "xcore-selectiondag-info" |
| 22 | |
| 23 | XCoreSelectionDAGInfo::XCoreSelectionDAGInfo() |
| 24 | : SelectionDAGGenTargetInfo(XCoreGenSDNodeInfo) {} |
| 25 | |
| 26 | SDValue 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 | TargetLowering::ArgListEntry Entry; |
| 37 | Entry.Ty = DAG.getDataLayout().getIntPtrType(C&: *DAG.getContext()); |
| 38 | Entry.Node = Dst; Args.push_back(x: Entry); |
| 39 | Entry.Node = Src; Args.push_back(x: Entry); |
| 40 | Entry.Node = Size; Args.push_back(x: Entry); |
| 41 | |
| 42 | const char *MemcpyAlign4Name = TLI.getLibcallName(Call: RTLIB::MEMCPY_ALIGN_4); |
| 43 | CallingConv::ID CC = TLI.getLibcallCallingConv(Call: RTLIB::MEMCPY_ALIGN_4); |
| 44 | |
| 45 | TargetLowering::CallLoweringInfo CLI(DAG); |
| 46 | CLI.setDebugLoc(dl) |
| 47 | .setChain(Chain) |
| 48 | .setLibCallee( |
| 49 | CC, ResultType: Type::getVoidTy(C&: *DAG.getContext()), |
| 50 | Target: DAG.getExternalSymbol(Sym: MemcpyAlign4Name, |
| 51 | VT: TLI.getPointerTy(DL: DAG.getDataLayout())), |
| 52 | ArgsList: std::move(Args)) |
| 53 | .setDiscardResult(); |
| 54 | |
| 55 | std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI); |
| 56 | return CallResult.second; |
| 57 | } |
| 58 | |
| 59 | // Otherwise have the target-independent code call memcpy. |
| 60 | return SDValue(); |
| 61 | } |
| 62 | |