blob: 2a2c79c56d68b967d0cbf51e58cc711bf96c18e6 [file] [log] [blame]
Dan Gohman7f970762015-12-08 03:36:00 +00001//=- WebAssemblyInstrFormats.td - WebAssembly Instr. Formats -*- tablegen -*-=//
Dan Gohman10e730a2015-06-29 23:51:55 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Gohman10e730a2015-06-29 23:51:55 +00006//
7//===----------------------------------------------------------------------===//
JF Bastien5ca0bac2015-07-10 18:23:10 +00008///
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// WebAssembly instruction format definitions.
JF Bastien5ca0bac2015-07-10 18:23:10 +000011///
Dan Gohman10e730a2015-06-29 23:51:55 +000012//===----------------------------------------------------------------------===//
13
JF Bastienaf111db2015-08-24 22:16:48 +000014// WebAssembly Instruction Format.
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000015// We instantiate 2 of these for every actual instruction (register based
16// and stack based), see below.
Thomas Livelyc63b5fc2018-10-22 21:55:26 +000017class 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 Gohman10e730a2015-06-29 23:51:55 +000022 let Namespace = "WebAssembly";
23 let Pattern = [];
Dan Gohmanaf29bd42015-11-05 20:42:30 +000024 let AsmString = asmstr;
Dan Gohman10e730a2015-06-29 23:51:55 +000025}
26
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000027// Normal instructions. Default instantiation of a WebAssemblyInst.
Thomas Livelyc63b5fc2018-10-22 21:55:26 +000028class NI<dag oops, dag iops, list<dag> pattern, string stack,
29 string asmstr = "", bits<32> inst = -1>
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000030 : WebAssemblyInst<inst, asmstr, stack> {
Dan Gohman10e730a2015-06-29 23:51:55 +000031 dag OutOperandList = oops;
32 dag InOperandList = iops;
33 let Pattern = pattern;
Thomas Livelyf04bed82018-10-11 20:21:22 +000034 let Defs = [ARGUMENTS];
Dan Gohman10e730a2015-06-29 23:51:55 +000035}
JF Bastiend9767a32015-07-14 21:13:29 +000036
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000037// Generates both register and stack based versions of one actual instruction.
38// We have 2 sets of operands (oops & iops) for the register and stack
39// based version of this instruction, as well as the corresponding asmstr.
40// The register versions have virtual-register operands which correspond to wasm
41// locals or stack locations. Each use and def of the register corresponds to an
Thomas Lively6a87dda2019-01-08 06:25:55 +000042// implicit local.get / local.set or access of stack operands in wasm. These
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000043// instructions are used for ISel and all MI passes. The stack versions of the
44// instructions do not have register operands (they implicitly operate on the
Thomas Lively6a87dda2019-01-08 06:25:55 +000045// stack), and local.gets and local.sets are explicit. The register instructions
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000046// are converted to their corresponding stack instructions before lowering to
47// MC.
48// Every instruction should want to be based on this multi-class to guarantee
49// there is always an equivalent pair of instructions.
50multiclass I<dag oops_r, dag iops_r, dag oops_s, dag iops_s,
51 list<dag> pattern_r, string asmstr_r = "", string asmstr_s = "",
52 bits<32> inst = -1> {
Wouter van Oortmerssene0403f12018-09-21 20:53:55 +000053 let isCodeGenOnly = 1 in
Thomas Livelyc63b5fc2018-10-22 21:55:26 +000054 def "" : NI<oops_r, iops_r, pattern_r, "false", asmstr_r, inst>;
55 let BaseName = NAME in
56 def _S : NI<oops_s, iops_s, [], "true", asmstr_s, inst>;
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000057}
Derek Schuff39bf39f2016-08-02 23:16:09 +000058
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000059// For instructions that have no register ops, so both sets are the same.
60multiclass NRI<dag oops, dag iops, list<dag> pattern, string asmstr = "",
61 bits<32> inst = -1> {
62 defm "": I<oops, iops, oops, iops, pattern, asmstr, asmstr, inst>;
63}