blob: 002e87fb32ce5a7e6cc4e91bb2579c3a058a1e34 [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
Benjamin Kramerbdc49562016-06-12 15:39:02 +000020SDValue HexagonSelectionDAGInfo::EmitTargetCodeForMemcpy(
21 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
22 SDValue Size, unsigned Align, bool isVolatile, bool AlwaysInline,
23 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
Tobias Edler von Kochb51460c2015-12-16 17:29:37 +000024 ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
25 if (AlwaysInline || (Align & 0x3) != 0 || !ConstantSize)
26 return SDValue();
Tony Linthicum1213a7a2011-12-12 21:14:40 +000027
Tobias Edler von Kochb51460c2015-12-16 17:29:37 +000028 uint64_t SizeVal = ConstantSize->getZExtValue();
29 if (SizeVal < 32 || (SizeVal % 8) != 0)
30 return SDValue();
31
32 // Special case aligned memcpys with size >= 32 bytes and a multiple of 8.
33 //
34 const TargetLowering &TLI = *DAG.getSubtarget().getTargetLowering();
35 TargetLowering::ArgListTy Args;
36 TargetLowering::ArgListEntry Entry;
37 Entry.Ty = DAG.getDataLayout().getIntPtrType(*DAG.getContext());
38 Entry.Node = Dst;
39 Args.push_back(Entry);
40 Entry.Node = Src;
41 Args.push_back(Entry);
42 Entry.Node = Size;
43 Args.push_back(Entry);
44
45 const char *SpecialMemcpyName =
46 "__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes";
Krzysztof Parzyszek080bebd2016-07-25 14:42:11 +000047 const MachineFunction &MF = DAG.getMachineFunction();
48 bool LongCalls = MF.getSubtarget<HexagonSubtarget>().useLongCalls();
49 unsigned Flags = LongCalls ? HexagonII::HMOTF_ConstExtended : 0;
Tobias Edler von Kochb51460c2015-12-16 17:29:37 +000050
51 TargetLowering::CallLoweringInfo CLI(DAG);
52 CLI.setDebugLoc(dl)
53 .setChain(Chain)
Nirav Daveac6081c2017-03-18 00:44:07 +000054 .setLibCallee(
Nirav Dave6de2c772017-03-18 00:43:57 +000055 TLI.getLibcallCallingConv(RTLIB::MEMCPY),
56 Type::getVoidTy(*DAG.getContext()),
57 DAG.getTargetExternalSymbol(
58 SpecialMemcpyName, TLI.getPointerTy(DAG.getDataLayout()), Flags),
59 std::move(Args))
Tobias Edler von Kochb51460c2015-12-16 17:29:37 +000060 .setDiscardResult();
61
62 std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI);
63 return CallResult.second;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000064}