61 lines · cpp
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-exception6//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_DESC17#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(Size, APInt(SizeBitWidth, 3))) {34 const TargetLowering &TLI = *DAG.getSubtarget().getTargetLowering();35 TargetLowering::ArgListTy Args;36 Type *ArgTy = DAG.getDataLayout().getIntPtrType(*DAG.getContext());37 Args.emplace_back(Dst, ArgTy);38 Args.emplace_back(Src, ArgTy);39 Args.emplace_back(Size, ArgTy);40 41 const char *MemcpyAlign4Name = TLI.getLibcallName(RTLIB::MEMCPY_ALIGN_4);42 CallingConv::ID CC = TLI.getLibcallCallingConv(RTLIB::MEMCPY_ALIGN_4);43 44 TargetLowering::CallLoweringInfo CLI(DAG);45 CLI.setDebugLoc(dl)46 .setChain(Chain)47 .setLibCallee(48 CC, Type::getVoidTy(*DAG.getContext()),49 DAG.getExternalSymbol(MemcpyAlign4Name,50 TLI.getPointerTy(DAG.getDataLayout())),51 std::move(Args))52 .setDiscardResult();53 54 std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI);55 return CallResult.second;56 }57 58 // Otherwise have the target-independent code call memcpy.59 return SDValue();60}61