blob: 97583ea0e6ac05cf08b94e83c6ace23a1ef81b38 [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//
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 Bastien5ca0bac2015-07-10 18:23:10 +00009///
10/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000011/// WebAssembly instruction format definitions.
JF Bastien5ca0bac2015-07-10 18:23:10 +000012///
Dan Gohman10e730a2015-06-29 23:51:55 +000013//===----------------------------------------------------------------------===//
14
JF Bastienaf111db2015-08-24 22:16:48 +000015// WebAssembly Instruction Format.
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000016// We instantiate 2 of these for every actual instruction (register based
17// and stack based), see below.
Thomas Livelyc63b5fc2018-10-22 21:55:26 +000018class 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 Gohman10e730a2015-06-29 23:51:55 +000023 let Namespace = "WebAssembly";
24 let Pattern = [];
Dan Gohmanaf29bd42015-11-05 20:42:30 +000025 let AsmString = asmstr;
Dan Gohman10e730a2015-06-29 23:51:55 +000026}
27
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000028// Normal instructions. Default instantiation of a WebAssemblyInst.
Thomas Livelyc63b5fc2018-10-22 21:55:26 +000029class NI<dag oops, dag iops, list<dag> pattern, string stack,
30 string asmstr = "", bits<32> inst = -1>
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000031 : WebAssemblyInst<inst, asmstr, stack> {
Dan Gohman10e730a2015-06-29 23:51:55 +000032 dag OutOperandList = oops;
33 dag InOperandList = iops;
34 let Pattern = pattern;
Thomas Livelyf04bed82018-10-11 20:21:22 +000035 let Defs = [ARGUMENTS];
Dan Gohman10e730a2015-06-29 23:51:55 +000036}
JF Bastiend9767a32015-07-14 21:13:29 +000037
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000038// 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.
51multiclass 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 Oortmerssene0403f12018-09-21 20:53:55 +000054 let isCodeGenOnly = 1 in
Thomas Livelyc63b5fc2018-10-22 21:55:26 +000055 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 Oortmerssen48dac312018-06-18 21:22:44 +000058}
Derek Schuff39bf39f2016-08-02 23:16:09 +000059
Wouter van Oortmerssen48dac312018-06-18 21:22:44 +000060// For instructions that have no register ops, so both sets are the same.
61multiclass 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}