1336809Sdim//===-- BPFSelectionDAGInfo.cpp - BPF SelectionDAG Info -------------------===// 2336809Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6336809Sdim// 7336809Sdim//===----------------------------------------------------------------------===// 8336809Sdim// 9336809Sdim// This file implements the BPFSelectionDAGInfo class. 10336809Sdim// 11336809Sdim//===----------------------------------------------------------------------===// 12336809Sdim 13336809Sdim#include "BPFTargetMachine.h" 14336809Sdim#include "llvm/CodeGen/SelectionDAG.h" 15336809Sdim#include "llvm/IR/DerivedTypes.h" 16336809Sdimusing namespace llvm; 17336809Sdim 18336809Sdim#define DEBUG_TYPE "bpf-selectiondag-info" 19336809Sdim 20336809SdimSDValue BPFSelectionDAGInfo::EmitTargetCodeForMemcpy( 21336809Sdim SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, 22336809Sdim SDValue Size, unsigned Align, bool isVolatile, bool AlwaysInline, 23336809Sdim MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const { 24336809Sdim // Requires the copy size to be a constant. 25336809Sdim ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); 26336809Sdim if (!ConstantSize) 27336809Sdim return SDValue(); 28336809Sdim 29336809Sdim unsigned CopyLen = ConstantSize->getZExtValue(); 30336809Sdim unsigned StoresNumEstimate = alignTo(CopyLen, Align) >> Log2_32(Align); 31336809Sdim // Impose the same copy length limit as MaxStoresPerMemcpy. 32336809Sdim if (StoresNumEstimate > getCommonMaxStoresPerMemFunc()) 33336809Sdim return SDValue(); 34336809Sdim 35336809Sdim SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue); 36336809Sdim 37336809Sdim Dst = DAG.getNode(BPFISD::MEMCPY, dl, VTs, Chain, Dst, Src, 38336809Sdim DAG.getConstant(CopyLen, dl, MVT::i64), 39336809Sdim DAG.getConstant(Align, dl, MVT::i64)); 40336809Sdim 41336809Sdim return Dst.getValue(0); 42336809Sdim} 43