blob: dd7a01713c15610c4f9e03af7e04e4ee55e8ee6a [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001// WebAssemblyInstrFormats.td - WebAssembly Instruction Formats -*- tblgen -*-//
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 Bastien5ca0bac2015-07-10 18:23:10 +00009///
10/// \file
11/// \brief WebAssembly instruction format definitions.
12///
Dan Gohman10e730a2015-06-29 23:51:55 +000013//===----------------------------------------------------------------------===//
14
JF Bastienaf111db2015-08-24 22:16:48 +000015// WebAssembly Instruction Format.
Dan Gohman10e730a2015-06-29 23:51:55 +000016class WebAssemblyInst<string cstr> : Instruction {
17 field bits<0> Inst; // Instruction encoding.
18 let Namespace = "WebAssembly";
19 let Pattern = [];
20 let Constraints = cstr;
21}
22
JF Bastienaf111db2015-08-24 22:16:48 +000023// Normal instructions.
Dan Gohman10e730a2015-06-29 23:51:55 +000024class I<dag oops, dag iops, list<dag> pattern, string cstr = "">
25 : WebAssemblyInst<cstr> {
26 dag OutOperandList = oops;
27 dag InOperandList = iops;
28 let Pattern = pattern;
29}
JF Bastiend9767a32015-07-14 21:13:29 +000030
31// Unary and binary instructions, for the local types that WebAssembly supports.
32multiclass UnaryInt<SDNode node> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000033 def _I32 : I<(outs I32:$dst), (ins I32:$src),
34 [(set I32:$dst, (node I32:$src))]>;
35 def _I64 : I<(outs I64:$dst), (ins I64:$src),
36 [(set I64:$dst, (node I64:$src))]>;
JF Bastiend9767a32015-07-14 21:13:29 +000037}
38multiclass BinaryInt<SDNode node> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000039 def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs),
40 [(set I32:$dst, (node I32:$lhs, I32:$rhs))]>;
41 def _I64 : I<(outs I64:$dst), (ins I64:$lhs, I64:$rhs),
42 [(set I64:$dst, (node I64:$lhs, I64:$rhs))]>;
JF Bastiend9767a32015-07-14 21:13:29 +000043}
44multiclass UnaryFP<SDNode node> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000045 def _F32 : I<(outs F32:$dst), (ins F32:$src),
46 [(set F32:$dst, (node F32:$src))]>;
47 def _F64 : I<(outs F64:$dst), (ins F64:$src),
48 [(set F64:$dst, (node F64:$src))]>;
JF Bastiend9767a32015-07-14 21:13:29 +000049}
50multiclass BinaryFP<SDNode node> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000051 def _F32 : I<(outs F32:$dst), (ins F32:$lhs, F32:$rhs),
52 [(set F32:$dst, (node F32:$lhs, F32:$rhs))]>;
53 def _F64 : I<(outs F64:$dst), (ins F64:$lhs, F64:$rhs),
54 [(set F64:$dst, (node F64:$lhs, F64:$rhs))]>;
JF Bastiend9767a32015-07-14 21:13:29 +000055}
JF Bastienda06bce2015-08-11 21:02:46 +000056multiclass ComparisonInt<CondCode cond> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000057 def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs),
58 [(set I32:$dst, (setcc I32:$lhs, I32:$rhs, cond))]>;
59 def _I64 : I<(outs I32:$dst), (ins I64:$lhs, I64:$rhs),
60 [(set I32:$dst, (setcc I64:$lhs, I64:$rhs, cond))]>;
JF Bastienda06bce2015-08-11 21:02:46 +000061}
62multiclass ComparisonFP<CondCode cond> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000063 def _F32 : I<(outs I32:$dst), (ins F32:$lhs, F32:$rhs),
64 [(set I32:$dst, (setcc F32:$lhs, F32:$rhs, cond))]>;
65 def _F64 : I<(outs I32:$dst), (ins F64:$lhs, F64:$rhs),
66 [(set I32:$dst, (setcc F64:$lhs, F64:$rhs, cond))]>;
JF Bastienda06bce2015-08-11 21:02:46 +000067}