xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/BPF/BPFSelectionDAGInfo.cpp (revision e25152834cdf3b353892835a4f3b157e066a8ed4)
10b57cec5SDimitry Andric //===-- BPFSelectionDAGInfo.cpp - BPF SelectionDAG Info -------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements the BPFSelectionDAGInfo class.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "BPFTargetMachine.h"
140b57cec5SDimitry Andric #include "llvm/CodeGen/SelectionDAG.h"
150b57cec5SDimitry Andric #include "llvm/IR/DerivedTypes.h"
160b57cec5SDimitry Andric using namespace llvm;
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #define DEBUG_TYPE "bpf-selectiondag-info"
190b57cec5SDimitry Andric 
EmitTargetCodeForMemcpy(SelectionDAG & DAG,const SDLoc & dl,SDValue Chain,SDValue Dst,SDValue Src,SDValue Size,Align Alignment,bool isVolatile,bool AlwaysInline,MachinePointerInfo DstPtrInfo,MachinePointerInfo SrcPtrInfo) const200b57cec5SDimitry Andric SDValue BPFSelectionDAGInfo::EmitTargetCodeForMemcpy(
210b57cec5SDimitry Andric     SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
22*5ffd83dbSDimitry Andric     SDValue Size, Align Alignment, bool isVolatile, bool AlwaysInline,
230b57cec5SDimitry Andric     MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
240b57cec5SDimitry Andric   // Requires the copy size to be a constant.
250b57cec5SDimitry Andric   ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
260b57cec5SDimitry Andric   if (!ConstantSize)
270b57cec5SDimitry Andric     return SDValue();
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric   unsigned CopyLen = ConstantSize->getZExtValue();
30*5ffd83dbSDimitry Andric   unsigned StoresNumEstimate = alignTo(CopyLen, Alignment) >> Log2(Alignment);
310b57cec5SDimitry Andric   // Impose the same copy length limit as MaxStoresPerMemcpy.
320b57cec5SDimitry Andric   if (StoresNumEstimate > getCommonMaxStoresPerMemFunc())
330b57cec5SDimitry Andric     return SDValue();
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric   SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue);
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric   Dst = DAG.getNode(BPFISD::MEMCPY, dl, VTs, Chain, Dst, Src,
380b57cec5SDimitry Andric                     DAG.getConstant(CopyLen, dl, MVT::i64),
39*5ffd83dbSDimitry Andric                     DAG.getConstant(Alignment.value(), dl, MVT::i64));
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric   return Dst.getValue(0);
420b57cec5SDimitry Andric }
43