WebAssemblyInstrBulkMemory.td 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // WebAssemblyInstrBulkMemory.td - bulk memory codegen support --*- tablegen -*-
  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. /// WebAssembly bulk memory codegen constructs.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. // Instruction requiring HasBulkMemory and the bulk memory prefix byte
  14. multiclass BULK_I<dag oops_r, dag iops_r, dag oops_s, dag iops_s,
  15. list<dag> pattern_r, string asmstr_r = "",
  16. string asmstr_s = "", bits<32> simdop = -1> {
  17. defm "" : I<oops_r, iops_r, oops_s, iops_s, pattern_r, asmstr_r, asmstr_s,
  18. !or(0xfc00, !and(0xff, simdop))>,
  19. Requires<[HasBulkMemory]>;
  20. }
  21. // Bespoke types and nodes for bulk memory ops
  22. def wasm_memcpy_t : SDTypeProfile<0, 5,
  23. [SDTCisInt<0>, SDTCisInt<1>, SDTCisPtrTy<2>, SDTCisPtrTy<3>, SDTCisInt<4>]
  24. >;
  25. def wasm_memcpy : SDNode<"WebAssemblyISD::MEMORY_COPY", wasm_memcpy_t,
  26. [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
  27. def wasm_memset_t : SDTypeProfile<0, 4,
  28. [SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisInt<2>, SDTCisInt<3>]
  29. >;
  30. def wasm_memset : SDNode<"WebAssemblyISD::MEMORY_FILL", wasm_memset_t,
  31. [SDNPHasChain, SDNPMayStore]>;
  32. multiclass BulkMemoryOps<WebAssemblyRegClass rc, string B> {
  33. let mayStore = 1, hasSideEffects = 1 in
  34. defm MEMORY_INIT_A#B :
  35. BULK_I<(outs),
  36. (ins i32imm_op:$seg, i32imm_op:$idx, rc:$dest,
  37. I32:$offset, I32:$size),
  38. (outs), (ins i32imm_op:$seg, i32imm_op:$idx),
  39. [],
  40. "memory.init\t$seg, $idx, $dest, $offset, $size",
  41. "memory.init\t$seg, $idx", 0x08>;
  42. let hasSideEffects = 1 in
  43. defm DATA_DROP :
  44. BULK_I<(outs), (ins i32imm_op:$seg), (outs), (ins i32imm_op:$seg),
  45. [],
  46. "data.drop\t$seg", "data.drop\t$seg", 0x09>;
  47. let mayLoad = 1, mayStore = 1 in
  48. defm MEMORY_COPY_A#B :
  49. BULK_I<(outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx,
  50. rc:$dst, rc:$src, rc:$len),
  51. (outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx),
  52. [(wasm_memcpy (i32 imm:$src_idx), (i32 imm:$dst_idx),
  53. rc:$dst, rc:$src, rc:$len
  54. )],
  55. "memory.copy\t$src_idx, $dst_idx, $dst, $src, $len",
  56. "memory.copy\t$src_idx, $dst_idx", 0x0a>;
  57. let mayStore = 1 in
  58. defm MEMORY_FILL_A#B :
  59. BULK_I<(outs), (ins i32imm_op:$idx, rc:$dst, I32:$value, rc:$size),
  60. (outs), (ins i32imm_op:$idx),
  61. [(wasm_memset (i32 imm:$idx), rc:$dst, I32:$value, rc:$size)],
  62. "memory.fill\t$idx, $dst, $value, $size",
  63. "memory.fill\t$idx", 0x0b>;
  64. }
  65. defm : BulkMemoryOps<I32, "32">;
  66. defm : BulkMemoryOps<I64, "64">;