WebAssemblyInstrFormats.td 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //=- WebAssemblyInstrFormats.td - WebAssembly Instr. Formats -*- 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 instruction format definitions.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. // WebAssembly Instruction Format.
  14. // We instantiate 2 of these for every actual instruction (register based
  15. // and stack based), see below.
  16. class WebAssemblyInst<bits<32> inst, string asmstr, bit stack, bit is64>
  17. : StackRel, RegisterRel, Wasm64Rel, Instruction {
  18. bits<32> Inst = inst; // Instruction encoding.
  19. bit StackBased = stack;
  20. string BaseName = NAME;
  21. bit IsWasm64 = is64;
  22. string Wasm32Name = !subst("_A64", "_A32", NAME);
  23. let Namespace = "WebAssembly";
  24. let Pattern = [];
  25. let AsmString = asmstr;
  26. // When there are multiple instructions that map to the same encoding (in
  27. // e.g. the disassembler use case) prefer the one where IsCanonical == 1.
  28. bit IsCanonical = 0;
  29. }
  30. // Normal instructions. Default instantiation of a WebAssemblyInst.
  31. class NI<dag oops, dag iops, list<dag> pattern, bit stack,
  32. string asmstr = "", bits<32> inst = -1, bit is64 = false>
  33. : WebAssemblyInst<inst, asmstr, stack, is64> {
  34. dag OutOperandList = oops;
  35. dag InOperandList = iops;
  36. let Pattern = pattern;
  37. let Defs = [ARGUMENTS];
  38. }
  39. // Generates both register and stack based versions of one actual instruction.
  40. // We have 2 sets of operands (oops & iops) for the register and stack
  41. // based version of this instruction, as well as the corresponding asmstr.
  42. // The register versions have virtual-register operands which correspond to wasm
  43. // locals or stack locations. Each use and def of the register corresponds to an
  44. // implicit local.get / local.set or access of stack operands in wasm. These
  45. // instructions are used for ISel and all MI passes. The stack versions of the
  46. // instructions do not have register operands (they implicitly operate on the
  47. // stack), and local.gets and local.sets are explicit. The register instructions
  48. // are converted to their corresponding stack instructions before lowering to
  49. // MC.
  50. // Every instruction should want to be based on this multi-class to guarantee
  51. // there is always an equivalent pair of instructions.
  52. multiclass I<dag oops_r, dag iops_r, dag oops_s, dag iops_s,
  53. list<dag> pattern_r, string asmstr_r = "", string asmstr_s = "",
  54. bits<32> inst = -1, bit is64 = false> {
  55. let isCodeGenOnly = 1 in
  56. def "" : NI<oops_r, iops_r, pattern_r, false, asmstr_r, inst, is64>;
  57. let BaseName = NAME in
  58. def _S : NI<oops_s, iops_s, [], true, asmstr_s, inst, is64>;
  59. }
  60. // For instructions that have no register ops, so both sets are the same.
  61. multiclass NRI<dag oops, dag iops, list<dag> pattern, string asmstr = "",
  62. bits<32> inst = -1> {
  63. defm "": I<oops, iops, oops, iops, pattern, asmstr, asmstr, inst>;
  64. }