Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1 | //===-- 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 Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 14 | #include "HexagonTargetMachine.h" |
Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame^] | 15 | #include "llvm/CodeGen/SelectionDAG.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 16 | using namespace llvm; |
| 17 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 18 | #define DEBUG_TYPE "hexagon-selectiondag-info" |
| 19 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 20 | SDValue |
| 21 | HexagonSelectionDAGInfo:: |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 22 | EmitTargetCodeForMemcpy(SelectionDAG &DAG, SDLoc dl, SDValue Chain, |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 23 | SDValue Dst, SDValue Src, SDValue Size, unsigned Align, |
| 24 | bool isVolatile, bool AlwaysInline, |
| 25 | MachinePointerInfo DstPtrInfo, |
| 26 | MachinePointerInfo SrcPtrInfo) const { |
Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame^] | 27 | ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); |
| 28 | if (AlwaysInline || (Align & 0x3) != 0 || !ConstantSize) |
| 29 | return SDValue(); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 30 | |
Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame^] | 31 | 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 Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 63 | } |