Dan Gohman | 7f97076 | 2015-12-08 03:36:00 +0000 | [diff] [blame] | 1 | //=- WebAssemblyInstrFormats.td - WebAssembly Instr. Formats -*- tablegen -*-=// |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 11 | /// WebAssembly instruction format definitions. |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 12 | /// |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 15 | // WebAssembly Instruction Format. |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 16 | // We instantiate 2 of these for every actual instruction (register based |
| 17 | // and stack based), see below. |
Thomas Lively | c63b5fc | 2018-10-22 21:55:26 +0000 | [diff] [blame] | 18 | class WebAssemblyInst<bits<32> inst, string asmstr, string stack> : StackRel, |
| 19 | Instruction { |
| 20 | bits<32> Inst = inst; // Instruction encoding. |
| 21 | string StackBased = stack; |
| 22 | string BaseName = NAME; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 23 | let Namespace = "WebAssembly"; |
| 24 | let Pattern = []; |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 25 | let AsmString = asmstr; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 28 | // Normal instructions. Default instantiation of a WebAssemblyInst. |
Thomas Lively | c63b5fc | 2018-10-22 21:55:26 +0000 | [diff] [blame] | 29 | class NI<dag oops, dag iops, list<dag> pattern, string stack, |
| 30 | string asmstr = "", bits<32> inst = -1> |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 31 | : WebAssemblyInst<inst, asmstr, stack> { |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 32 | dag OutOperandList = oops; |
| 33 | dag InOperandList = iops; |
| 34 | let Pattern = pattern; |
Thomas Lively | f04bed8 | 2018-10-11 20:21:22 +0000 | [diff] [blame] | 35 | let Defs = [ARGUMENTS]; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 36 | } |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 37 | |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 38 | // Generates both register and stack based versions of one actual instruction. |
| 39 | // We have 2 sets of operands (oops & iops) for the register and stack |
| 40 | // based version of this instruction, as well as the corresponding asmstr. |
| 41 | // The register versions have virtual-register operands which correspond to wasm |
| 42 | // locals or stack locations. Each use and def of the register corresponds to an |
| 43 | // implicit get_local / set_local or access of stack operands in wasm. These |
| 44 | // instructions are used for ISel and all MI passes. The stack versions of the |
| 45 | // instructions do not have register operands (they implicitly operate on the |
| 46 | // stack), and get_locals and set_locals are explicit. The register instructions |
| 47 | // are converted to their corresponding stack instructions before lowering to |
| 48 | // MC. |
| 49 | // Every instruction should want to be based on this multi-class to guarantee |
| 50 | // there is always an equivalent pair of instructions. |
| 51 | multiclass I<dag oops_r, dag iops_r, dag oops_s, dag iops_s, |
| 52 | list<dag> pattern_r, string asmstr_r = "", string asmstr_s = "", |
| 53 | bits<32> inst = -1> { |
Wouter van Oortmerssen | e0403f1 | 2018-09-21 20:53:55 +0000 | [diff] [blame] | 54 | let isCodeGenOnly = 1 in |
Thomas Lively | c63b5fc | 2018-10-22 21:55:26 +0000 | [diff] [blame] | 55 | def "" : NI<oops_r, iops_r, pattern_r, "false", asmstr_r, inst>; |
| 56 | let BaseName = NAME in |
| 57 | def _S : NI<oops_s, iops_s, [], "true", asmstr_s, inst>; |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 58 | } |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 59 | |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 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 | } |