| 1 | //===-- BPFSelectionDAGInfo.cpp - BPF SelectionDAG Info -------------------===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the BPFSelectionDAGInfo class. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "BPFSelectionDAGInfo.h" |
| 14 | #include "BPFTargetMachine.h" |
| 15 | #include "llvm/CodeGen/SelectionDAG.h" |
| 16 | |
| 17 | #define GET_SDNODE_DESC |
| 18 | #include "BPFGenSDNodeInfo.inc" |
| 19 | |
| 20 | using namespace llvm; |
| 21 | |
| 22 | #define DEBUG_TYPE "bpf-selectiondag-info" |
| 23 | |
| 24 | BPFSelectionDAGInfo::BPFSelectionDAGInfo() |
| 25 | : SelectionDAGGenTargetInfo(BPFGenSDNodeInfo) {} |
| 26 | |
| 27 | SDValue BPFSelectionDAGInfo::EmitTargetCodeForMemcpy( |
| 28 | SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, |
| 29 | SDValue Size, Align Alignment, bool isVolatile, bool AlwaysInline, |
| 30 | MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const { |
| 31 | // Requires the copy size to be a constant. |
| 32 | ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Val&: Size); |
| 33 | if (!ConstantSize) |
| 34 | return SDValue(); |
| 35 | |
| 36 | unsigned CopyLen = ConstantSize->getZExtValue(); |
| 37 | unsigned StoresNumEstimate = alignTo(Size: CopyLen, A: Alignment) >> Log2(A: Alignment); |
| 38 | // Impose the same copy length limit as MaxStoresPerMemcpy. |
| 39 | if (StoresNumEstimate > getCommonMaxStoresPerMemFunc()) |
| 40 | return SDValue(); |
| 41 | |
| 42 | return DAG.getNode(Opcode: BPFISD::MEMCPY, DL: dl, VT: MVT::Other, N1: Chain, N2: Dst, N3: Src, |
| 43 | N4: DAG.getConstant(Val: CopyLen, DL: dl, VT: MVT::i64), |
| 44 | N5: DAG.getConstant(Val: Alignment.value(), DL: dl, VT: MVT::i64)); |
| 45 | } |
| 46 | |