• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- XCoreSelectionDAGInfo.cpp - XCore SelectionDAG Info ---------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the XCoreSelectionDAGInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "XCoreTargetMachine.h"
15 using namespace llvm;
16 
17 #define DEBUG_TYPE "xcore-selectiondag-info"
18 
EmitTargetCodeForMemcpy(SelectionDAG & DAG,const SDLoc & dl,SDValue Chain,SDValue Dst,SDValue Src,SDValue Size,unsigned Align,bool isVolatile,bool AlwaysInline,MachinePointerInfo DstPtrInfo,MachinePointerInfo SrcPtrInfo) const19 SDValue XCoreSelectionDAGInfo::EmitTargetCodeForMemcpy(
20     SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
21     SDValue Size, unsigned Align, bool isVolatile, bool AlwaysInline,
22     MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
23   unsigned SizeBitWidth = Size.getValueType().getSizeInBits();
24   // Call __memcpy_4 if the src, dst and size are all 4 byte aligned.
25   if (!AlwaysInline && (Align & 3) == 0 &&
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         .setCallee(TLI.getLibcallCallingConv(RTLIB::MEMCPY),
39                    Type::getVoidTy(*DAG.getContext()),
40                    DAG.getExternalSymbol("__memcpy_4",
41                                          TLI.getPointerTy(DAG.getDataLayout())),
42                    std::move(Args))
43         .setDiscardResult();
44 
45     std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI);
46     return CallResult.second;
47   }
48 
49   // Otherwise have the target-independent code call memcpy.
50   return SDValue();
51 }
52