Thomas Lively | d99af23 | 2019-02-05 00:49:55 +0000 | [diff] [blame] | 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 | |
| 14 | // Instruction requiring HasBulkMemory and the bulk memory prefix byte |
| 15 | multiclass BULK_I<dag oops_r, dag iops_r, dag oops_s, dag iops_s, |
| 16 | list<dag> pattern_r, string asmstr_r = "", |
| 17 | string asmstr_s = "", bits<32> simdop = -1> { |
| 18 | defm "" : I<oops_r, iops_r, oops_s, iops_s, pattern_r, asmstr_r, asmstr_s, |
| 19 | !or(0xfc00, !and(0xff, simdop))>, |
| 20 | Requires<[HasBulkMemory]>; |
| 21 | } |
| 22 | |
| 23 | // Bespoke types and nodes for bulk memory ops |
Thomas Lively | de7a0a1 | 2019-02-13 22:11:16 +0000 | [diff] [blame] | 24 | def wasm_memcpy_t : SDTypeProfile<0, 5, |
| 25 | [SDTCisInt<0>, SDTCisInt<1>, SDTCisPtrTy<2>, SDTCisPtrTy<3>, SDTCisInt<4>] |
Thomas Lively | d99af23 | 2019-02-05 00:49:55 +0000 | [diff] [blame] | 26 | >; |
| 27 | def wasm_memcpy : SDNode<"WebAssemblyISD::MEMORY_COPY", wasm_memcpy_t, |
| 28 | [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>; |
| 29 | |
Thomas Lively | bba3f06 | 2019-02-13 22:25:18 +0000 | [diff] [blame] | 30 | def wasm_memset_t : SDTypeProfile<0, 4, |
| 31 | [SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisInt<2>, SDTCisInt<3>] |
| 32 | >; |
| 33 | def wasm_memset : SDNode<"WebAssemblyISD::MEMORY_FILL", wasm_memset_t, |
| 34 | [SDNPHasChain, SDNPMayStore]>; |
Thomas Lively | de7a0a1 | 2019-02-13 22:11:16 +0000 | [diff] [blame] | 35 | |
Thomas Lively | bba3f06 | 2019-02-13 22:25:18 +0000 | [diff] [blame] | 36 | let mayStore = 1, hasSideEffects = 1 in |
Thomas Lively | de7a0a1 | 2019-02-13 22:11:16 +0000 | [diff] [blame] | 37 | defm MEMORY_INIT : |
| 38 | BULK_I<(outs), |
| 39 | (ins i32imm_op:$seg, i32imm_op:$idx, I32:$dest, |
| 40 | I32:$offset, I32:$size), |
| 41 | (outs), (ins i32imm_op:$seg, i32imm_op:$idx), |
Matt Arsenault | 3ecab8e | 2019-09-19 16:26:14 +0000 | [diff] [blame] | 42 | [(int_wasm_memory_init (i32 timm:$seg), (i32 timm:$idx), I32:$dest, |
Thomas Lively | de7a0a1 | 2019-02-13 22:11:16 +0000 | [diff] [blame] | 43 | I32:$offset, I32:$size |
| 44 | )], |
| 45 | "memory.init\t$seg, $idx, $dest, $offset, $size", |
| 46 | "memory.init\t$seg, $idx", 0x08>; |
| 47 | |
Thomas Lively | bba3f06 | 2019-02-13 22:25:18 +0000 | [diff] [blame] | 48 | let hasSideEffects = 1 in |
Thomas Lively | de7a0a1 | 2019-02-13 22:11:16 +0000 | [diff] [blame] | 49 | defm DATA_DROP : |
| 50 | BULK_I<(outs), (ins i32imm_op:$seg), (outs), (ins i32imm_op:$seg), |
Matt Arsenault | 3ecab8e | 2019-09-19 16:26:14 +0000 | [diff] [blame] | 51 | [(int_wasm_data_drop (i32 timm:$seg))], |
Thomas Lively | de7a0a1 | 2019-02-13 22:11:16 +0000 | [diff] [blame] | 52 | "data.drop\t$seg", "data.drop\t$seg", 0x09>; |
| 53 | |
Thomas Lively | d99af23 | 2019-02-05 00:49:55 +0000 | [diff] [blame] | 54 | let mayLoad = 1, mayStore = 1 in |
Thomas Lively | de7a0a1 | 2019-02-13 22:11:16 +0000 | [diff] [blame] | 55 | defm MEMORY_COPY : |
| 56 | BULK_I<(outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx, |
| 57 | I32:$dst, I32:$src, I32:$len), |
| 58 | (outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx), |
| 59 | [(wasm_memcpy (i32 imm:$src_idx), (i32 imm:$dst_idx), |
| 60 | I32:$dst, I32:$src, I32:$len |
| 61 | )], |
| 62 | "memory.copy\t$src_idx, $dst_idx, $dst, $src, $len", |
| 63 | "memory.copy\t$src_idx, $dst_idx", 0x0a>; |
Thomas Lively | bba3f06 | 2019-02-13 22:25:18 +0000 | [diff] [blame] | 64 | |
| 65 | let mayStore = 1 in |
| 66 | defm MEMORY_FILL : |
| 67 | BULK_I<(outs), (ins i32imm_op:$idx, I32:$dst, I32:$value, I32:$size), |
| 68 | (outs), (ins i32imm_op:$idx), |
| 69 | [(wasm_memset (i32 imm:$idx), I32:$dst, I32:$value, I32:$size)], |
| 70 | "memory.fill\t$idx, $dst, $value, $size", |
| 71 | "memory.fill\t$idx", 0x0b>; |