46 lines · cpp
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-exception6//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_DESC18#include "BPFGenSDNodeInfo.inc"19 20using namespace llvm;21 22#define DEBUG_TYPE "bpf-selectiondag-info"23 24BPFSelectionDAGInfo::BPFSelectionDAGInfo()25 : SelectionDAGGenTargetInfo(BPFGenSDNodeInfo) {}26 27SDValue 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>(Size);33 if (!ConstantSize)34 return SDValue();35 36 unsigned CopyLen = ConstantSize->getZExtValue();37 unsigned StoresNumEstimate = alignTo(CopyLen, Alignment) >> Log2(Alignment);38 // Impose the same copy length limit as MaxStoresPerMemcpy.39 if (StoresNumEstimate > getCommonMaxStoresPerMemFunc())40 return SDValue();41 42 return DAG.getNode(BPFISD::MEMCPY, dl, MVT::Other, Chain, Dst, Src,43 DAG.getConstant(CopyLen, dl, MVT::i64),44 DAG.getConstant(Alignment.value(), dl, MVT::i64));45}46