WebAssemblyInstrTable.td 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. def WebAssemblyTableSet_t : SDTypeProfile<0, 3, [SDTCisPtrTy<1>]>;
  14. def WebAssemblyTableSet : SDNode<"WebAssemblyISD::TABLE_SET", WebAssemblyTableSet_t,
  15. [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
  16. def WebAssemblyTableGet_t : SDTypeProfile<1, 2, [SDTCisPtrTy<1>]>;
  17. def WebAssemblyTableGet : SDNode<"WebAssemblyISD::TABLE_GET", WebAssemblyTableGet_t,
  18. [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
  19. multiclass TABLE<WebAssemblyRegClass rc, string suffix> {
  20. let mayLoad = 1 in
  21. defm TABLE_GET_#rc : I<(outs rc:$res), (ins table32_op:$table, I32:$i),
  22. (outs), (ins table32_op:$table),
  23. [(set rc:$res, (!cast<Intrinsic>("int_wasm_table_get_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i))],
  24. "table.get\t$res, $table, $i",
  25. "table.get\t$table",
  26. 0x25>;
  27. let mayStore = 1 in
  28. defm TABLE_SET_#rc : I<(outs), (ins table32_op:$table, I32:$i, rc:$val),
  29. (outs), (ins table32_op:$table),
  30. [(!cast<Intrinsic>("int_wasm_table_set_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i, rc:$val)],
  31. "table.set\t$table, $i, $val",
  32. "table.set\t$table",
  33. 0x26>;
  34. defm TABLE_GROW_#rc : I<(outs I32:$sz), (ins table32_op:$table, rc:$val, I32:$n),
  35. (outs), (ins table32_op:$table),
  36. [(set I32:$sz, (!cast<Intrinsic>("int_wasm_table_grow_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), rc:$val, I32:$n))],
  37. "table.grow\t$sz, $table, $val, $n",
  38. "table.grow\t$table",
  39. 0xfc0f>;
  40. defm TABLE_FILL_#rc : I<(outs), (ins table32_op:$table, I32:$i, rc:$val, I32:$n),
  41. (outs), (ins table32_op:$table),
  42. [(!cast<Intrinsic>("int_wasm_table_fill_" # suffix) (WebAssemblyWrapper tglobaladdr:$table), I32:$i, rc:$val, I32:$n)],
  43. "table.fill\t$table, $i, $val, $n",
  44. "table.fill\t$table",
  45. 0xfc11>;
  46. foreach vt = rc.RegTypes in {
  47. def : Pat<(vt (WebAssemblyTableGet (WebAssemblyWrapper tglobaladdr:$table), i32:$idx)),
  48. (!cast<NI>("TABLE_GET_" # rc) tglobaladdr:$table, i32:$idx)>;
  49. def : Pat<(WebAssemblyTableSet
  50. (WebAssemblyWrapper tglobaladdr:$table),
  51. i32:$idx,
  52. vt:$src),
  53. (!cast<NI>("TABLE_SET_" # rc) tglobaladdr:$table, i32:$idx, vt:$src)>;
  54. }
  55. }
  56. defm "" : TABLE<FUNCREF, "funcref">, Requires<[HasReferenceTypes]>;
  57. defm "" : TABLE<EXTERNREF, "externref">, Requires<[HasReferenceTypes]>;
  58. def : Pat<(WebAssemblyTableSet mcsym:$table, i32:$idx, funcref:$r),
  59. (TABLE_SET_FUNCREF mcsym:$table, i32:$idx, funcref:$r)>,
  60. Requires<[HasReferenceTypes]>;
  61. defm TABLE_SIZE : I<(outs I32:$sz), (ins table32_op:$table),
  62. (outs), (ins table32_op:$table),
  63. [(set I32:$sz, (int_wasm_table_size (WebAssemblyWrapper tglobaladdr:$table)))],
  64. "table.size\t$sz, $table",
  65. "table.size\t$table",
  66. 0xfc10>,
  67. Requires<[HasReferenceTypes]>;
  68. defm TABLE_COPY : I<(outs), (ins table32_op:$table1, table32_op:$table2, I32:$d, I32:$s, I32:$n),
  69. (outs), (ins table32_op:$table1, table32_op:$table2),
  70. [(int_wasm_table_copy (WebAssemblyWrapper tglobaladdr:$table1),
  71. (WebAssemblyWrapper tglobaladdr:$table2),
  72. I32:$d, I32:$s, I32:$n)],
  73. "table.copy\t$table1, $table2, $d, $s, $n",
  74. "table.copy\t$table1, $table2",
  75. 0xfc0e>,
  76. Requires<[HasReferenceTypes]>;