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