1d99af237SThomas Lively// WebAssemblyInstrBulkMemory.td - bulk memory codegen support --*- tablegen -*-
2d99af237SThomas Lively//
3d99af237SThomas Lively// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4d99af237SThomas Lively// See https://llvm.org/LICENSE.txt for license information.
5d99af237SThomas Lively// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6d99af237SThomas Lively//
7d99af237SThomas Lively//===----------------------------------------------------------------------===//
8d99af237SThomas Lively///
9d99af237SThomas Lively/// \file
10d99af237SThomas Lively/// WebAssembly bulk memory codegen constructs.
11d99af237SThomas Lively///
12d99af237SThomas Lively//===----------------------------------------------------------------------===//
13d99af237SThomas Lively
14d99af237SThomas Lively// Instruction requiring HasBulkMemory and the bulk memory prefix byte
15d99af237SThomas Livelymulticlass BULK_I<dag oops_r, dag iops_r, dag oops_s, dag iops_s,
16d99af237SThomas Lively                  list<dag> pattern_r, string asmstr_r = "",
17d99af237SThomas Lively                  string asmstr_s = "", bits<32> simdop = -1> {
18d99af237SThomas Lively  defm "" : I<oops_r, iops_r, oops_s, iops_s, pattern_r, asmstr_r, asmstr_s,
19d99af237SThomas Lively              !or(0xfc00, !and(0xff, simdop))>,
20d99af237SThomas Lively            Requires<[HasBulkMemory]>;
21d99af237SThomas Lively}
22d99af237SThomas Lively
23d99af237SThomas Lively// Bespoke types and nodes for bulk memory ops
24de7a0a15SThomas Livelydef wasm_memcpy_t : SDTypeProfile<0, 5,
25de7a0a15SThomas Lively  [SDTCisInt<0>, SDTCisInt<1>, SDTCisPtrTy<2>, SDTCisPtrTy<3>, SDTCisInt<4>]
26d99af237SThomas Lively>;
27d99af237SThomas Livelydef wasm_memcpy : SDNode<"WebAssemblyISD::MEMORY_COPY", wasm_memcpy_t,
28d99af237SThomas Lively                         [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
29d99af237SThomas Lively
30*bba3f06dSThomas Livelydef wasm_memset_t : SDTypeProfile<0, 4,
31*bba3f06dSThomas Lively  [SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisInt<2>, SDTCisInt<3>]
32*bba3f06dSThomas Lively>;
33*bba3f06dSThomas Livelydef wasm_memset : SDNode<"WebAssemblyISD::MEMORY_FILL", wasm_memset_t,
34*bba3f06dSThomas Lively                         [SDNPHasChain, SDNPMayStore]>;
35de7a0a15SThomas Lively
36*bba3f06dSThomas Livelylet mayStore = 1, hasSideEffects = 1 in
37de7a0a15SThomas Livelydefm MEMORY_INIT :
38de7a0a15SThomas Lively  BULK_I<(outs),
39de7a0a15SThomas Lively         (ins i32imm_op:$seg, i32imm_op:$idx, I32:$dest,
40de7a0a15SThomas Lively              I32:$offset, I32:$size),
41de7a0a15SThomas Lively         (outs), (ins i32imm_op:$seg, i32imm_op:$idx),
42de7a0a15SThomas Lively         [(int_wasm_memory_init (i32 imm:$seg), (i32 imm:$idx), I32:$dest,
43de7a0a15SThomas Lively            I32:$offset, I32:$size
44de7a0a15SThomas Lively          )],
45de7a0a15SThomas Lively         "memory.init\t$seg, $idx, $dest, $offset, $size",
46de7a0a15SThomas Lively         "memory.init\t$seg, $idx", 0x08>;
47de7a0a15SThomas Lively
48*bba3f06dSThomas Livelylet hasSideEffects = 1 in
49de7a0a15SThomas Livelydefm DATA_DROP :
50de7a0a15SThomas Lively  BULK_I<(outs), (ins i32imm_op:$seg), (outs), (ins i32imm_op:$seg),
51de7a0a15SThomas Lively         [(int_wasm_data_drop (i32 imm:$seg))],
52de7a0a15SThomas Lively         "data.drop\t$seg", "data.drop\t$seg", 0x09>;
53de7a0a15SThomas Lively
54d99af237SThomas Livelylet mayLoad = 1, mayStore = 1 in
55de7a0a15SThomas Livelydefm MEMORY_COPY :
56de7a0a15SThomas Lively  BULK_I<(outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx,
57de7a0a15SThomas Lively                      I32:$dst, I32:$src, I32:$len),
58de7a0a15SThomas Lively         (outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx),
59de7a0a15SThomas Lively         [(wasm_memcpy (i32 imm:$src_idx), (i32 imm:$dst_idx),
60de7a0a15SThomas Lively           I32:$dst, I32:$src, I32:$len
61de7a0a15SThomas Lively         )],
62de7a0a15SThomas Lively         "memory.copy\t$src_idx, $dst_idx, $dst, $src, $len",
63de7a0a15SThomas Lively         "memory.copy\t$src_idx, $dst_idx", 0x0a>;
64*bba3f06dSThomas Lively
65*bba3f06dSThomas Livelylet mayStore = 1 in
66*bba3f06dSThomas Livelydefm MEMORY_FILL :
67*bba3f06dSThomas Lively  BULK_I<(outs), (ins i32imm_op:$idx, I32:$dst, I32:$value, I32:$size),
68*bba3f06dSThomas Lively         (outs), (ins i32imm_op:$idx),
69*bba3f06dSThomas Lively         [(wasm_memset (i32 imm:$idx), I32:$dst, I32:$value, I32:$size)],
70*bba3f06dSThomas Lively         "memory.fill\t$idx, $dst, $value, $size",
71*bba3f06dSThomas Lively         "memory.fill\t$idx", 0x0b>;
72