1 //===-- AArch64SelectionDAGInfo.cpp - AArch64 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 AArch64SelectionDAGInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "AArch64TargetMachine.h"
15 using namespace llvm;
16
17 #define DEBUG_TYPE "aarch64-selectiondag-info"
18
AArch64SelectionDAGInfo(const DataLayout * DL)19 AArch64SelectionDAGInfo::AArch64SelectionDAGInfo(const DataLayout *DL)
20 : TargetSelectionDAGInfo(DL) {}
21
~AArch64SelectionDAGInfo()22 AArch64SelectionDAGInfo::~AArch64SelectionDAGInfo() {}
23
EmitTargetCodeForMemset(SelectionDAG & DAG,SDLoc dl,SDValue Chain,SDValue Dst,SDValue Src,SDValue Size,unsigned Align,bool isVolatile,MachinePointerInfo DstPtrInfo) const24 SDValue AArch64SelectionDAGInfo::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 AArch64Subtarget &STI =
32 DAG.getMachineFunction().getSubtarget<AArch64Subtarget>();
33 const char *bzeroEntry =
34 (V && V->isNullValue()) ? STI.getBZeroEntry() : nullptr;
35 // For small size (< 256), it is not beneficial to use bzero
36 // instead of memset.
37 if (bzeroEntry && (!SizeValue || SizeValue->getZExtValue() > 256)) {
38 const AArch64TargetLowering &TLI = *STI.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(DAG);
50 CLI.setDebugLoc(dl).setChain(Chain)
51 .setCallee(CallingConv::C, Type::getVoidTy(*DAG.getContext()),
52 DAG.getExternalSymbol(bzeroEntry, IntPtr), std::move(Args), 0)
53 .setDiscardResult();
54 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
55 return CallResult.second;
56 }
57 return SDValue();
58 }
59