Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1 | //===-- HexagonSelectionDAGInfo.cpp - Hexagon SelectionDAG Info -----------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the HexagonSelectionDAGInfo class. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 13 | #include "HexagonTargetMachine.h" |
Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/SelectionDAG.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 15 | using namespace llvm; |
| 16 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 17 | #define DEBUG_TYPE "hexagon-selectiondag-info" |
| 18 | |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 19 | SDValue HexagonSelectionDAGInfo::EmitTargetCodeForMemcpy( |
| 20 | SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, |
| 21 | SDValue Size, unsigned Align, bool isVolatile, bool AlwaysInline, |
| 22 | MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const { |
Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame] | 23 | ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); |
| 24 | if (AlwaysInline || (Align & 0x3) != 0 || !ConstantSize) |
| 25 | return SDValue(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 26 | |
Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame] | 27 | uint64_t SizeVal = ConstantSize->getZExtValue(); |
| 28 | if (SizeVal < 32 || (SizeVal % 8) != 0) |
| 29 | return SDValue(); |
| 30 | |
| 31 | // Special case aligned memcpys with size >= 32 bytes and a multiple of 8. |
| 32 | // |
| 33 | const TargetLowering &TLI = *DAG.getSubtarget().getTargetLowering(); |
| 34 | TargetLowering::ArgListTy Args; |
| 35 | TargetLowering::ArgListEntry Entry; |
| 36 | Entry.Ty = DAG.getDataLayout().getIntPtrType(*DAG.getContext()); |
| 37 | Entry.Node = Dst; |
| 38 | Args.push_back(Entry); |
| 39 | Entry.Node = Src; |
| 40 | Args.push_back(Entry); |
| 41 | Entry.Node = Size; |
| 42 | Args.push_back(Entry); |
| 43 | |
| 44 | const char *SpecialMemcpyName = |
| 45 | "__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes"; |
Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 46 | const MachineFunction &MF = DAG.getMachineFunction(); |
| 47 | bool LongCalls = MF.getSubtarget<HexagonSubtarget>().useLongCalls(); |
| 48 | unsigned Flags = LongCalls ? HexagonII::HMOTF_ConstExtended : 0; |
Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame] | 49 | |
| 50 | TargetLowering::CallLoweringInfo CLI(DAG); |
| 51 | CLI.setDebugLoc(dl) |
| 52 | .setChain(Chain) |
Nirav Dave | ac6081c | 2017-03-18 00:44:07 +0000 | [diff] [blame] | 53 | .setLibCallee( |
Nirav Dave | 6de2c77 | 2017-03-18 00:43:57 +0000 | [diff] [blame] | 54 | TLI.getLibcallCallingConv(RTLIB::MEMCPY), |
| 55 | Type::getVoidTy(*DAG.getContext()), |
| 56 | DAG.getTargetExternalSymbol( |
| 57 | SpecialMemcpyName, TLI.getPointerTy(DAG.getDataLayout()), Flags), |
| 58 | std::move(Args)) |
Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame] | 59 | .setDiscardResult(); |
| 60 | |
| 61 | std::pair<SDValue, SDValue> CallResult = TLI.LowerCallTo(CLI); |
| 62 | return CallResult.second; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 63 | } |