xref: /llvm-project/llvm/lib/Target/BPF/BPFSelectionDAGInfo.cpp (revision ed8019d9fbed2e6a6b08f8f73e9fa54a24f3ed52)
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 using namespace llvm;
16 
17 #define DEBUG_TYPE "bpf-selectiondag-info"
18 
19 SDValue BPFSelectionDAGInfo::EmitTargetCodeForMemcpy(
20     SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
21     SDValue Size, Align Alignment, bool isVolatile, bool AlwaysInline,
22     MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
23   // Requires the copy size to be a constant.
24   ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
25   if (!ConstantSize)
26     return SDValue();
27 
28   unsigned CopyLen = ConstantSize->getZExtValue();
29   unsigned StoresNumEstimate = alignTo(CopyLen, Alignment) >> Log2(Alignment);
30   // Impose the same copy length limit as MaxStoresPerMemcpy.
31   if (StoresNumEstimate > getCommonMaxStoresPerMemFunc())
32     return SDValue();
33 
34   SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue);
35 
36   Dst = DAG.getNode(BPFISD::MEMCPY, dl, VTs, Chain, Dst, Src,
37                     DAG.getConstant(CopyLen, dl, MVT::i64),
38                     DAG.getConstant(Alignment.value(), dl, MVT::i64));
39 
40   return Dst.getValue(0);
41 }
42