dc57e0ae9bfc57b408ae1089d7c76c741c76d151
[oota-llvm.git] / lib / Target / XCore / XCoreSelectionDAGInfo.cpp
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
19 XCoreSelectionDAGInfo::XCoreSelectionDAGInfo(const DataLayout &DL)
20     : TargetSelectionDAGInfo(&DL) {}
21
22 XCoreSelectionDAGInfo::~XCoreSelectionDAGInfo() {
23 }
24
25 SDValue XCoreSelectionDAGInfo::
26 EmitTargetCodeForMemcpy(SelectionDAG &DAG, SDLoc dl, SDValue Chain,
27                         SDValue Dst, SDValue Src, SDValue Size, unsigned Align,
28                         bool isVolatile, bool AlwaysInline,
29                         MachinePointerInfo DstPtrInfo,
30                         MachinePointerInfo SrcPtrInfo) const
31 {
32   unsigned SizeBitWidth = Size.getValueType().getSizeInBits();
33   // Call __memcpy_4 if the src, dst and size are all 4 byte aligned.
34   if (!AlwaysInline && (Align & 3) == 0 &&
35       DAG.MaskedValueIsZero(Size, APInt(SizeBitWidth, 3))) {
36     const TargetLowering &TLI = *DAG.getSubtarget().getTargetLowering();
37     TargetLowering::ArgListTy Args;
38     TargetLowering::ArgListEntry Entry;
39     Entry.Ty = TLI.getDataLayout()->getIntPtrType(*DAG.getContext());
40     Entry.Node = Dst; Args.push_back(Entry);
41     Entry.Node = Src; Args.push_back(Entry);
42     Entry.Node = Size; Args.push_back(Entry);
43
44     TargetLowering::CallLoweringInfo CLI(DAG);
45     CLI.setDebugLoc(dl)
46         .setChain(Chain)
47         .setCallee(TLI.getLibcallCallingConv(RTLIB::MEMCPY),
48                    Type::getVoidTy(*DAG.getContext()),
49                    DAG.getExternalSymbol("__memcpy_4",
50                                          TLI.getPointerTy(DAG.getDataLayout())),
51                    std::move(Args), 0)
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 }