1// WebAssemblyInstrTable.td - WebAssembly Table 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 Table operand code-gen constructs. 11/// Instructions that handle tables 12//===----------------------------------------------------------------------===// 13 14multiclass TABLE<WebAssemblyRegClass rt> { 15 let mayLoad = 1 in 16 defm TABLE_GET_#rt : I<(outs rt:$res), (ins table32_op:$table, I32:$i), 17 (outs), (ins table32_op:$table), 18 [], 19 "table.get\t$res, $table, $i", 20 "table.get\t$table", 21 0x25>; 22 23 let mayStore = 1 in 24 defm TABLE_SET_#rt : I<(outs), (ins table32_op:$table, I32:$i, rt:$val), 25 (outs), (ins table32_op:$table), 26 [], 27 "table.set\t$table, $i, $val", 28 "table.set\t$table", 29 0x26>; 30 31 defm TABLE_GROW_#rt : I<(outs I32:$sz), (ins table32_op:$table, rt:$val, I32:$n), 32 (outs), (ins table32_op:$table), 33 [], 34 "table.grow\t$sz, $table, $val, $n", 35 "table.grow\t$table", 36 0xfc0f>; 37 38 defm TABLE_FILL_#rt : I<(outs), (ins table32_op:$table, I32:$i, rt:$val, I32:$n), 39 (outs), (ins table32_op:$table), 40 [], 41 "table.fill\t$table, $i, $val, $n", 42 "table.fill\t$table", 43 0xfc11>; 44 45} 46 47defm "" : TABLE<FUNCREF>, Requires<[HasReferenceTypes]>; 48defm "" : TABLE<EXTERNREF>, Requires<[HasReferenceTypes]>; 49 50def wasm_table_set_t : SDTypeProfile<0, 3, []>; 51def wasm_table_set : SDNode<"WebAssemblyISD::TABLE_SET", wasm_table_set_t, 52 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; 53 54def : Pat<(wasm_table_set i32:$table, i32:$idx, funcref:$r), 55 (TABLE_SET_FUNCREF i32:$table, i32:$idx, funcref:$r)>, 56 Requires<[HasReferenceTypes]>; 57def : Pat<(wasm_table_set i32:$table, i32:$idx, externref:$r), 58 (TABLE_SET_EXTERNREF i32:$table, i32:$idx, externref:$r)>, 59 Requires<[HasReferenceTypes]>; 60 61defm TABLE_SIZE : I<(outs I32:$sz), (ins table32_op:$table), 62 (outs), (ins table32_op:$table), 63 [], 64 "table.size\t$sz, $table", 65 "table.size\t$table", 66 0xfc10>, 67 Requires<[HasReferenceTypes]>; 68 69 70defm TABLE_COPY : I<(outs), (ins table32_op:$table1, table32_op:$table2, I32:$d, I32:$s, I32:$n), 71 (outs), (ins table32_op:$table1, table32_op:$table2), 72 [], 73 "table.copy\t$table1, $table2, $d, $s, $n", 74 "table.copy\t$table1, $table2", 75 0xfc0e>, 76 Requires<[HasReferenceTypes]>; 77