WebAssemblySelectionDAGInfo.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===-- WebAssemblySelectionDAGInfo.cpp - WebAssembly 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. /// \file
  10. /// This file implements the WebAssemblySelectionDAGInfo class.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #include "WebAssemblyTargetMachine.h"
  14. using namespace llvm;
  15. #define DEBUG_TYPE "wasm-selectiondag-info"
  16. WebAssemblySelectionDAGInfo::~WebAssemblySelectionDAGInfo() = default; // anchor
  17. SDValue WebAssemblySelectionDAGInfo::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. auto &ST = DAG.getMachineFunction().getSubtarget<WebAssemblySubtarget>();
  22. if (!ST.hasBulkMemory())
  23. return SDValue();
  24. SDValue MemIdx = DAG.getConstant(0, DL, MVT::i32);
  25. auto LenMVT = ST.hasAddr64() ? MVT::i64 : MVT::i32;
  26. return DAG.getNode(WebAssemblyISD::MEMORY_COPY, DL, MVT::Other,
  27. {Chain, MemIdx, MemIdx, Dst, Src,
  28. DAG.getZExtOrTrunc(Size, DL, LenMVT)});
  29. }
  30. SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemmove(
  31. SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Op1, SDValue Op2,
  32. SDValue Op3, Align Alignment, bool IsVolatile,
  33. MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
  34. return EmitTargetCodeForMemcpy(DAG, DL, Chain, Op1, Op2, Op3,
  35. Alignment, IsVolatile, false,
  36. DstPtrInfo, SrcPtrInfo);
  37. }
  38. SDValue WebAssemblySelectionDAGInfo::EmitTargetCodeForMemset(
  39. SelectionDAG &DAG, const SDLoc &DL, SDValue Chain, SDValue Dst, SDValue Val,
  40. SDValue Size, Align Alignment, bool IsVolatile, bool AlwaysInline,
  41. MachinePointerInfo DstPtrInfo) const {
  42. auto &ST = DAG.getMachineFunction().getSubtarget<WebAssemblySubtarget>();
  43. if (!ST.hasBulkMemory())
  44. return SDValue();
  45. SDValue MemIdx = DAG.getConstant(0, DL, MVT::i32);
  46. auto LenMVT = ST.hasAddr64() ? MVT::i64 : MVT::i32;
  47. // Only low byte matters for val argument, so anyext the i8
  48. return DAG.getNode(WebAssemblyISD::MEMORY_FILL, DL, MVT::Other, Chain, MemIdx,
  49. Dst, DAG.getAnyExtOrTrunc(Val, DL, MVT::i32),
  50. DAG.getZExtOrTrunc(Size, DL, LenMVT));
  51. }