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 "BPFTargetMachine.h"
14#include "llvm/CodeGen/SelectionDAG.h"
15#include "llvm/IR/DerivedTypes.h"
16using namespace llvm;
17
18#define DEBUG_TYPE "bpf-selectiondag-info"
19
20SDValue BPFSelectionDAGInfo::EmitTargetCodeForMemcpy(
21 SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
22 SDValue Size, Align Alignment, bool isVolatile, bool AlwaysInline,
23 MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
24 // Requires the copy size to be a constant.
25 ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Val&: Size);
26 if (!ConstantSize)
27 return SDValue();
28
29 unsigned CopyLen = ConstantSize->getZExtValue();
30 unsigned StoresNumEstimate = alignTo(Size: CopyLen, A: Alignment) >> Log2(A: Alignment);
31 // Impose the same copy length limit as MaxStoresPerMemcpy.
32 if (StoresNumEstimate > getCommonMaxStoresPerMemFunc())
33 return SDValue();
34
35 SDVTList VTs = DAG.getVTList(VT1: MVT::Other, VT2: MVT::Glue);
36
37 Dst = DAG.getNode(Opcode: BPFISD::MEMCPY, DL: dl, VTList: VTs, N1: Chain, N2: Dst, N3: Src,
38 N4: DAG.getConstant(Val: CopyLen, DL: dl, VT: MVT::i64),
39 N5: DAG.getConstant(Val: Alignment.value(), DL: dl, VT: MVT::i64));
40
41 return Dst.getValue(R: 0);
42}
43