blob: 239dbda8f27b6c90c339f14e1c1b2b3b97f1edb7 [file] [log] [blame]
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001//===-- HexagonSelectionDAGInfo.cpp - Hexagon 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 HexagonSelectionDAGInfo class.
11//
12//===----------------------------------------------------------------------===//
13
Tony Linthicum1213a7a2011-12-12 21:14:40 +000014#include "HexagonTargetMachine.h"
Tobias Edler von Kochb51460c2015-12-16 17:29:37 +000015#include "llvm/CodeGen/SelectionDAG.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000016using namespace llvm;
17
Chandler Carruth84e68b22014-04-22 02:41:26 +000018#define DEBUG_TYPE "hexagon-selectiondag-info"
19
Tony Linthicum1213a7a2011-12-12 21:14:40 +000020SDValue
21HexagonSelectionDAGInfo::
Andrew Trickef9de2a2013-05-25 02:42:55 +000022EmitTargetCodeForMemcpy(SelectionDAG &DAG, SDLoc dl, SDValue Chain,
Tony Linthicum1213a7a2011-12-12 21:14:40 +000023 SDValue Dst, SDValue Src, SDValue Size, unsigned Align,
24 bool isVolatile, bool AlwaysInline,
25 MachinePointerInfo DstPtrInfo,
26 MachinePointerInfo SrcPtrInfo) const {
Tobias Edler von Kochb51460c2015-12-16 17:29:37 +000027 ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
28 if (AlwaysInline || (Align & 0x3) != 0 || !ConstantSize)
29 return SDValue();
Tony Linthicum1213a7a2011-12-12 21:14:40 +000030
Tobias Edler von Kochb51460c2015-12-16 17:29:37 +000031 uint64_t SizeVal = ConstantSize->getZExtValue();
32 if (SizeVal < 32 || (SizeVal % 8) != 0)
33 return SDValue();
34
35 // Special case aligned memcpys with size >= 32 bytes and a multiple of 8.
36 //
37 const TargetLowering &TLI = *DAG.getSubtarget().getTargetLowering();
38 TargetLowering::ArgListTy Args;
39 TargetLowering::ArgListEntry Entry;
40 Entry.Ty = DAG.getDataLayout().getIntPtrType(*DAG.getContext());
41 Entry.Node = Dst;
42 Args.push_back(Entry);
43 Entry.Node = Src;
44 Args.push_back(Entry);
45 Entry.Node = Size;
46 Args.push_back(Entry);
47
48 const char *SpecialMemcpyName =
49 "__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes";
50
51 TargetLowering::CallLoweringInfo CLI(DAG);
52 CLI.setDebugLoc(dl)
53 .setChain(Chain)
54 .setCallee(TLI.getLibcallCallingConv(RTLIB::MEMCPY),
55 Type::getVoidTy(*DAG.getContext()),
56 DAG.getTargetExternalSymbol(
57 SpecialMemcpyName, TLI.getPointerTy(DAG.getDataLayout())),
58 std::move(Args), 0)
59 .setDiscardResult();
60
61 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
62 return CallResult.second;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000063}