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 30bba3f06dSThomas Livelydef wasm_memset_t : SDTypeProfile<0, 4, 31bba3f06dSThomas Lively [SDTCisInt<0>, SDTCisPtrTy<1>, SDTCisInt<2>, SDTCisInt<3>] 32bba3f06dSThomas Lively>; 33bba3f06dSThomas Livelydef wasm_memset : SDNode<"WebAssemblyISD::MEMORY_FILL", wasm_memset_t, 34bba3f06dSThomas Lively [SDNPHasChain, SDNPMayStore]>; 35de7a0a15SThomas Lively 36*16d83c39SWouter van Oortmerssenmulticlass BulkMemoryOps<WebAssemblyRegClass rc, string B> { 37*16d83c39SWouter van Oortmerssen 38bba3f06dSThomas Livelylet mayStore = 1, hasSideEffects = 1 in 39*16d83c39SWouter van Oortmerssendefm MEMORY_INIT_A#B : 40de7a0a15SThomas Lively BULK_I<(outs), 41*16d83c39SWouter van Oortmerssen (ins i32imm_op:$seg, i32imm_op:$idx, rc:$dest, 42*16d83c39SWouter van Oortmerssen rc:$offset, rc:$size), 43de7a0a15SThomas Lively (outs), (ins i32imm_op:$seg, i32imm_op:$idx), 44*16d83c39SWouter van Oortmerssen [], 45de7a0a15SThomas Lively "memory.init\t$seg, $idx, $dest, $offset, $size", 46de7a0a15SThomas Lively "memory.init\t$seg, $idx", 0x08>; 47de7a0a15SThomas Lively 48bba3f06dSThomas Livelylet hasSideEffects = 1 in 49de7a0a15SThomas Livelydefm DATA_DROP : 50de7a0a15SThomas Lively BULK_I<(outs), (ins i32imm_op:$seg), (outs), (ins i32imm_op:$seg), 51*16d83c39SWouter van Oortmerssen [], 52de7a0a15SThomas Lively "data.drop\t$seg", "data.drop\t$seg", 0x09>; 53de7a0a15SThomas Lively 54d99af237SThomas Livelylet mayLoad = 1, mayStore = 1 in 55*16d83c39SWouter van Oortmerssendefm MEMORY_COPY_A#B : 56de7a0a15SThomas Lively BULK_I<(outs), (ins i32imm_op:$src_idx, i32imm_op:$dst_idx, 57*16d83c39SWouter van Oortmerssen rc:$dst, rc:$src, rc:$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), 60*16d83c39SWouter van Oortmerssen rc:$dst, rc:$src, rc:$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>; 64bba3f06dSThomas Lively 65bba3f06dSThomas Livelylet mayStore = 1 in 66*16d83c39SWouter van Oortmerssendefm MEMORY_FILL_A#B : 67*16d83c39SWouter van Oortmerssen BULK_I<(outs), (ins i32imm_op:$idx, rc:$dst, I32:$value, rc:$size), 68bba3f06dSThomas Lively (outs), (ins i32imm_op:$idx), 69*16d83c39SWouter van Oortmerssen [(wasm_memset (i32 imm:$idx), rc:$dst, I32:$value, rc:$size)], 70bba3f06dSThomas Lively "memory.fill\t$idx, $dst, $value, $size", 71bba3f06dSThomas Lively "memory.fill\t$idx", 0x0b>; 72*16d83c39SWouter van Oortmerssen} 73*16d83c39SWouter van Oortmerssen 74*16d83c39SWouter van Oortmerssendefm : BulkMemoryOps<I32, "32">; 75*16d83c39SWouter van Oortmerssendefm : BulkMemoryOps<I64, "64">; 76