ARM64: initial backend import
[oota-llvm.git] / lib / Target / ARM64 / ARM64SelectionDAGInfo.cpp
1 //===-- ARM64SelectionDAGInfo.cpp - ARM64 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 ARM64SelectionDAGInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #define DEBUG_TYPE "arm64-selectiondag-info"
15 #include "ARM64TargetMachine.h"
16 using namespace llvm;
17
18 ARM64SelectionDAGInfo::ARM64SelectionDAGInfo(const TargetMachine &TM)
19     : TargetSelectionDAGInfo(TM),
20       Subtarget(&TM.getSubtarget<ARM64Subtarget>()) {}
21
22 ARM64SelectionDAGInfo::~ARM64SelectionDAGInfo() {}
23
24 SDValue ARM64SelectionDAGInfo::EmitTargetCodeForMemset(
25     SelectionDAG &DAG, SDLoc dl, SDValue Chain, SDValue Dst, SDValue Src,
26     SDValue Size, unsigned Align, bool isVolatile,
27     MachinePointerInfo DstPtrInfo) const {
28   // Check to see if there is a specialized entry-point for memory zeroing.
29   ConstantSDNode *V = dyn_cast<ConstantSDNode>(Src);
30   ConstantSDNode *SizeValue = dyn_cast<ConstantSDNode>(Size);
31   const char *bzeroEntry =
32       (V && V->isNullValue()) ? Subtarget->getBZeroEntry() : 0;
33   // For small size (< 256), it is not beneficial to use bzero
34   // instead of memset.
35   if (bzeroEntry && (!SizeValue || SizeValue->getZExtValue() > 256)) {
36     const ARM64TargetLowering &TLI = *static_cast<const ARM64TargetLowering *>(
37                                           DAG.getTarget().getTargetLowering());
38
39     EVT IntPtr = TLI.getPointerTy();
40     Type *IntPtrTy = getDataLayout()->getIntPtrType(*DAG.getContext());
41     TargetLowering::ArgListTy Args;
42     TargetLowering::ArgListEntry Entry;
43     Entry.Node = Dst;
44     Entry.Ty = IntPtrTy;
45     Args.push_back(Entry);
46     Entry.Node = Size;
47     Args.push_back(Entry);
48     TargetLowering::CallLoweringInfo CLI(
49         Chain, Type::getVoidTy(*DAG.getContext()), false, false, false, false,
50         0, CallingConv::C, /*isTailCall=*/false,
51         /*doesNotRet=*/false, /*isReturnValueUsed=*/false,
52         DAG.getExternalSymbol(bzeroEntry, IntPtr), Args, DAG, dl);
53     std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
54     return CallResult.second;
55   }
56   return SDValue();
57 }