BPFSelectionDAGInfo.cpp 1.6 KB

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