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 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 8 | /// |
| 9 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 10 | /// WebAssembly instruction format definitions. |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 11 | /// |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 14 | // WebAssembly Instruction Format. |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 15 | // We instantiate 2 of these for every actual instruction (register based |
| 16 | // and stack based), see below. |
Thomas Lively | c63b5fc | 2018-10-22 21:55:26 +0000 | [diff] [blame] | 17 | class WebAssemblyInst<bits<32> inst, string asmstr, string stack> : StackRel, |
| 18 | Instruction { |
| 19 | bits<32> Inst = inst; // Instruction encoding. |
| 20 | string StackBased = stack; |
| 21 | string BaseName = NAME; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 22 | let Namespace = "WebAssembly"; |
| 23 | let Pattern = []; |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 24 | let AsmString = asmstr; |
Wouter van Oortmerssen | 1a91cb0 | 2019-02-05 01:19:45 +0000 | [diff] [blame] | 25 | // When there are multiple instructions that map to the same encoding (in |
| 26 | // e.g. the disassembler use case) prefer the one where IsCanonical == 1. |
| 27 | bit IsCanonical = 0; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 30 | // Normal instructions. Default instantiation of a WebAssemblyInst. |
Thomas Lively | c63b5fc | 2018-10-22 21:55:26 +0000 | [diff] [blame] | 31 | class NI<dag oops, dag iops, list<dag> pattern, string stack, |
| 32 | string asmstr = "", bits<32> inst = -1> |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 33 | : WebAssemblyInst<inst, asmstr, stack> { |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 34 | dag OutOperandList = oops; |
| 35 | dag InOperandList = iops; |
| 36 | let Pattern = pattern; |
Thomas Lively | f04bed8 | 2018-10-11 20:21:22 +0000 | [diff] [blame] | 37 | let Defs = [ARGUMENTS]; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 38 | } |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 39 | |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 40 | // Generates both register and stack based versions of one actual instruction. |
| 41 | // We have 2 sets of operands (oops & iops) for the register and stack |
| 42 | // based version of this instruction, as well as the corresponding asmstr. |
| 43 | // The register versions have virtual-register operands which correspond to wasm |
| 44 | // locals or stack locations. Each use and def of the register corresponds to an |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 45 | // implicit local.get / local.set or access of stack operands in wasm. These |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 46 | // instructions are used for ISel and all MI passes. The stack versions of the |
| 47 | // instructions do not have register operands (they implicitly operate on the |
Thomas Lively | 6a87dda | 2019-01-08 06:25:55 +0000 | [diff] [blame] | 48 | // stack), and local.gets and local.sets are explicit. The register instructions |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 49 | // are converted to their corresponding stack instructions before lowering to |
| 50 | // MC. |
| 51 | // Every instruction should want to be based on this multi-class to guarantee |
| 52 | // there is always an equivalent pair of instructions. |
| 53 | multiclass I<dag oops_r, dag iops_r, dag oops_s, dag iops_s, |
| 54 | list<dag> pattern_r, string asmstr_r = "", string asmstr_s = "", |
| 55 | bits<32> inst = -1> { |
Wouter van Oortmerssen | e0403f1 | 2018-09-21 20:53:55 +0000 | [diff] [blame] | 56 | let isCodeGenOnly = 1 in |
Thomas Lively | c63b5fc | 2018-10-22 21:55:26 +0000 | [diff] [blame] | 57 | def "" : NI<oops_r, iops_r, pattern_r, "false", asmstr_r, inst>; |
| 58 | let BaseName = NAME in |
| 59 | def _S : NI<oops_s, iops_s, [], "true", asmstr_s, inst>; |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 60 | } |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 61 | |
Wouter van Oortmerssen | 48dac31 | 2018-06-18 21:22:44 +0000 | [diff] [blame] | 62 | // For instructions that have no register ops, so both sets are the same. |
| 63 | multiclass NRI<dag oops, dag iops, list<dag> pattern, string asmstr = "", |
| 64 | bits<32> inst = -1> { |
| 65 | defm "": I<oops, iops, oops, iops, pattern, asmstr, asmstr, inst>; |
| 66 | } |