1e8d8bef9SDimitry Andric// WebAssemblyInstrTable.td - WebAssembly Table codegen support -*- tablegen -*- 2e8d8bef9SDimitry Andric// 3e8d8bef9SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e8d8bef9SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 5e8d8bef9SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e8d8bef9SDimitry Andric// 7e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 8e8d8bef9SDimitry Andric/// 9e8d8bef9SDimitry Andric/// \file 10e8d8bef9SDimitry Andric/// WebAssembly Table operand code-gen constructs. 11e8d8bef9SDimitry Andric/// Instructions that handle tables 12e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===// 13e8d8bef9SDimitry Andric 14349cc55cSDimitry Andricdef WebAssemblyTableSet_t : SDTypeProfile<0, 3, [SDTCisPtrTy<1>]>; 15349cc55cSDimitry Andricdef WebAssemblyTableSet : SDNode<"WebAssemblyISD::TABLE_SET", WebAssemblyTableSet_t, 16349cc55cSDimitry Andric [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>; 17349cc55cSDimitry Andric 18349cc55cSDimitry Andricdef WebAssemblyTableGet_t : SDTypeProfile<1, 2, [SDTCisPtrTy<1>]>; 19349cc55cSDimitry Andricdef WebAssemblyTableGet : SDNode<"WebAssemblyISD::TABLE_GET", WebAssemblyTableGet_t, 20349cc55cSDimitry Andric [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>; 21349cc55cSDimitry Andric 22349cc55cSDimitry Andric 230eae32dcSDimitry Andricmulticlass TABLE<WebAssemblyRegClass rc, string suffix> { 24fe6060f1SDimitry Andric let mayLoad = 1 in 25349cc55cSDimitry Andric defm TABLE_GET_#rc : I<(outs rc:$res), (ins table32_op:$table, I32:$i), 26e8d8bef9SDimitry Andric (outs), (ins table32_op:$table), 27bdd1243dSDimitry Andric [(set rc:$res, (!cast<Intrinsic>("int_wasm_table_get_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i))], 28fe6060f1SDimitry Andric "table.get\t$res, $table, $i", 29e8d8bef9SDimitry Andric "table.get\t$table", 30e8d8bef9SDimitry Andric 0x25>; 31e8d8bef9SDimitry Andric 32fe6060f1SDimitry Andric let mayStore = 1 in 33349cc55cSDimitry Andric defm TABLE_SET_#rc : I<(outs), (ins table32_op:$table, I32:$i, rc:$val), 34e8d8bef9SDimitry Andric (outs), (ins table32_op:$table), 35bdd1243dSDimitry Andric [(!cast<Intrinsic>("int_wasm_table_set_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i, rc:$val)], 36fe6060f1SDimitry Andric "table.set\t$table, $i, $val", 37e8d8bef9SDimitry Andric "table.set\t$table", 38e8d8bef9SDimitry Andric 0x26>; 39e8d8bef9SDimitry Andric 40349cc55cSDimitry Andric defm TABLE_GROW_#rc : I<(outs I32:$sz), (ins table32_op:$table, rc:$val, I32:$n), 41e8d8bef9SDimitry Andric (outs), (ins table32_op:$table), 420eae32dcSDimitry Andric [(set I32:$sz, (!cast<Intrinsic>("int_wasm_table_grow_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), rc:$val, I32:$n))], 43fe6060f1SDimitry Andric "table.grow\t$sz, $table, $val, $n", 44e8d8bef9SDimitry Andric "table.grow\t$table", 45e8d8bef9SDimitry Andric 0xfc0f>; 46e8d8bef9SDimitry Andric 47349cc55cSDimitry Andric defm TABLE_FILL_#rc : I<(outs), (ins table32_op:$table, I32:$i, rc:$val, I32:$n), 48e8d8bef9SDimitry Andric (outs), (ins table32_op:$table), 490eae32dcSDimitry Andric [(!cast<Intrinsic>("int_wasm_table_fill_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i, rc:$val, I32:$n)], 50fe6060f1SDimitry Andric "table.fill\t$table, $i, $val, $n", 51e8d8bef9SDimitry Andric "table.fill\t$table", 52e8d8bef9SDimitry Andric 0xfc11>; 53e8d8bef9SDimitry Andric 54349cc55cSDimitry Andric foreach vt = rc.RegTypes in { 55349cc55cSDimitry Andric def : Pat<(vt (WebAssemblyTableGet (WebAssemblyWrapper tglobaladdr:$table), i32:$idx)), 56349cc55cSDimitry Andric (!cast<NI>("TABLE_GET_" # rc) tglobaladdr:$table, i32:$idx)>; 57349cc55cSDimitry Andric def : Pat<(WebAssemblyTableSet 58349cc55cSDimitry Andric (WebAssemblyWrapper tglobaladdr:$table), 59349cc55cSDimitry Andric i32:$idx, 60349cc55cSDimitry Andric vt:$src), 61349cc55cSDimitry Andric (!cast<NI>("TABLE_SET_" # rc) tglobaladdr:$table, i32:$idx, vt:$src)>; 62349cc55cSDimitry Andric } 63e8d8bef9SDimitry Andric} 64e8d8bef9SDimitry Andric 650eae32dcSDimitry Andricdefm "" : TABLE<FUNCREF, "funcref">, Requires<[HasReferenceTypes]>; 660eae32dcSDimitry Andricdefm "" : TABLE<EXTERNREF, "externref">, Requires<[HasReferenceTypes]>; 67*0fca6ea1SDimitry Andricdefm "" : TABLE<EXNREF, "exnref">, 68*0fca6ea1SDimitry Andric Requires<[HasReferenceTypes, HasExceptionHandling]>; 69e8d8bef9SDimitry Andric 70349cc55cSDimitry Andricdef : Pat<(WebAssemblyTableSet mcsym:$table, i32:$idx, funcref:$r), 71349cc55cSDimitry Andric (TABLE_SET_FUNCREF mcsym:$table, i32:$idx, funcref:$r)>, 72fe6060f1SDimitry Andric Requires<[HasReferenceTypes]>; 73fe6060f1SDimitry Andric 74e8d8bef9SDimitry Andricdefm TABLE_SIZE : I<(outs I32:$sz), (ins table32_op:$table), 75e8d8bef9SDimitry Andric (outs), (ins table32_op:$table), 760eae32dcSDimitry Andric [(set I32:$sz, (int_wasm_table_size (WebAssemblyWrapper tglobaladdr:$table)))], 77e8d8bef9SDimitry Andric "table.size\t$sz, $table", 78e8d8bef9SDimitry Andric "table.size\t$table", 79e8d8bef9SDimitry Andric 0xfc10>, 80e8d8bef9SDimitry Andric Requires<[HasReferenceTypes]>; 81e8d8bef9SDimitry Andric 82e8d8bef9SDimitry Andric 83fe6060f1SDimitry Andricdefm TABLE_COPY : I<(outs), (ins table32_op:$table1, table32_op:$table2, I32:$d, I32:$s, I32:$n), 84e8d8bef9SDimitry Andric (outs), (ins table32_op:$table1, table32_op:$table2), 850eae32dcSDimitry Andric [(int_wasm_table_copy (WebAssemblyWrapper tglobaladdr:$table1), 860eae32dcSDimitry Andric (WebAssemblyWrapper tglobaladdr:$table2), 870eae32dcSDimitry Andric I32:$d, I32:$s, I32:$n)], 88fe6060f1SDimitry Andric "table.copy\t$table1, $table2, $d, $s, $n", 89e8d8bef9SDimitry Andric "table.copy\t$table1, $table2", 90e8d8bef9SDimitry Andric 0xfc0e>, 91e8d8bef9SDimitry Andric Requires<[HasReferenceTypes]>; 92