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
24*de7a0a15SThomas Livelydef wasm_memcpy_t : SDTypeProfile<0, 5,
25*de7a0a15SThomas 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
30d99af237SThomas Lively//===----------------------------------------------------------------------===//
31*de7a0a15SThomas Lively// memory.init
32*de7a0a15SThomas Lively//===----------------------------------------------------------------------===//
33*de7a0a15SThomas Lively
34*de7a0a15SThomas Livelylet mayStore = 1 in
35*de7a0a15SThomas Livelydefm MEMORY_INIT :
36*de7a0a15SThomas Lively  BULK_I<(outs),
37*de7a0a15SThomas Lively         (ins i32imm_op:$seg, i32imm_op:$idx, I32:$dest,
38*de7a0a15SThomas Lively              I32:$offset, I32:$size),
39*de7a0a15SThomas Lively         (outs), (ins i32imm_op:$seg, i32imm_op:$idx),
40*de7a0a15SThomas Lively         [(int_wasm_memory_init (i32 imm:$seg), (i32 imm:$idx), I32:$dest,
41*de7a0a15SThomas Lively            I32:$offset, I32:$size
42*de7a0a15SThomas Lively          )],
43*de7a0a15SThomas Lively         "memory.init\t$seg, $idx, $dest, $offset, $size",
44*de7a0a15SThomas Lively         "memory.init\t$seg, $idx", 0x08>;
45*de7a0a15SThomas Lively
46*de7a0a15SThomas Lively//===----------------------------------------------------------------------===//
47*de7a0a15SThomas Lively// data.drop
48*de7a0a15SThomas Lively//===----------------------------------------------------------------------===//
49*de7a0a15SThomas Lively
50*de7a0a15SThomas Livelydefm DATA_DROP :
51*de7a0a15SThomas Lively  BULK_I<(outs), (ins i32imm_op:$seg), (outs), (ins i32imm_op:$seg),
52*de7a0a15SThomas Lively         [(int_wasm_data_drop (i32 imm:$seg))],
53*de7a0a15SThomas Lively         "data.drop\t$seg", "data.drop\t$seg", 0x09>;
54*de7a0a15SThomas Lively
55*de7a0a15SThomas Lively//===----------------------------------------------------------------------===//
56d99af237SThomas Lively// memory.copy
57d99af237SThomas Lively//===----------------------------------------------------------------------===//
58d99af237SThomas Lively
59d99af237SThomas Livelylet mayLoad = 1, mayStore = 1 in
60*de7a0a15SThomas Livelydefm MEMORY_COPY :
61*de7a0a15SThomas Lively  BULK_I<(outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx,
62*de7a0a15SThomas Lively                      I32:$dst, I32:$src, I32:$len),
63*de7a0a15SThomas Lively         (outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx),
64*de7a0a15SThomas Lively         [(wasm_memcpy (i32 imm:$src_idx), (i32 imm:$dst_idx),
65*de7a0a15SThomas Lively           I32:$dst, I32:$src, I32:$len
66*de7a0a15SThomas Lively         )],
67*de7a0a15SThomas Lively         "memory.copy\t$src_idx, $dst_idx, $dst, $src, $len",
68*de7a0a15SThomas Lively         "memory.copy\t$src_idx, $dst_idx", 0x0a>;
69