blob: 62a108c0d400b587557ee887c49e9a608d6b86f2 [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 Gohmanaf29bd42015-11-05 20:42:30 +000016class WebAssemblyInst<string asmstr> : Instruction {
Dan Gohman10e730a2015-06-29 23:51:55 +000017 field bits<0> Inst; // Instruction encoding.
18 let Namespace = "WebAssembly";
19 let Pattern = [];
Dan Gohmanaf29bd42015-11-05 20:42:30 +000020 let AsmString = asmstr;
Dan Gohman10e730a2015-06-29 23:51:55 +000021}
22
JF Bastienaf111db2015-08-24 22:16:48 +000023// Normal instructions.
Dan Gohmanaf29bd42015-11-05 20:42:30 +000024class I<dag oops, dag iops, list<dag> pattern, string asmstr = "">
25 : WebAssemblyInst<asmstr> {
Dan Gohman10e730a2015-06-29 23:51:55 +000026 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.
Dan Gohmanaf29bd42015-11-05 20:42:30 +000032multiclass UnaryInt<SDNode node, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000033 def _I32 : I<(outs I32:$dst), (ins I32:$src),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000034 [(set I32:$dst, (node I32:$src))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000035 !strconcat("i32.", !strconcat(name, "\t$dst, $src"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000036 def _I64 : I<(outs I64:$dst), (ins I64:$src),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000037 [(set I64:$dst, (node I64:$src))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000038 !strconcat("i64.", !strconcat(name, "\t$dst, $src"))>;
JF Bastiend9767a32015-07-14 21:13:29 +000039}
Dan Gohmanaf29bd42015-11-05 20:42:30 +000040multiclass BinaryInt<SDNode node, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000041 def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000042 [(set I32:$dst, (node I32:$lhs, I32:$rhs))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000043 !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000044 def _I64 : I<(outs I64:$dst), (ins I64:$lhs, I64:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000045 [(set I64:$dst, (node I64:$lhs, I64:$rhs))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000046 !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
JF Bastiend9767a32015-07-14 21:13:29 +000047}
Dan Gohmanaf29bd42015-11-05 20:42:30 +000048multiclass UnaryFP<SDNode node, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000049 def _F32 : I<(outs F32:$dst), (ins F32:$src),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000050 [(set F32:$dst, (node F32:$src))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000051 !strconcat("f32.", !strconcat(name, "\t$dst, $src"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000052 def _F64 : I<(outs F64:$dst), (ins F64:$src),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000053 [(set F64:$dst, (node F64:$src))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000054 !strconcat("f64.", !strconcat(name, "\t$dst, $src"))>;
JF Bastiend9767a32015-07-14 21:13:29 +000055}
Dan Gohmanaf29bd42015-11-05 20:42:30 +000056multiclass BinaryFP<SDNode node, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000057 def _F32 : I<(outs F32:$dst), (ins F32:$lhs, F32:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000058 [(set F32:$dst, (node F32:$lhs, F32:$rhs))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000059 !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000060 def _F64 : I<(outs F64:$dst), (ins F64:$lhs, F64:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000061 [(set F64:$dst, (node F64:$lhs, F64:$rhs))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000062 !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
JF Bastiend9767a32015-07-14 21:13:29 +000063}
Dan Gohmanaf29bd42015-11-05 20:42:30 +000064multiclass ComparisonInt<CondCode cond, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000065 def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000066 [(set I32:$dst, (setcc I32:$lhs, I32:$rhs, cond))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000067 !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000068 def _I64 : I<(outs I32:$dst), (ins I64:$lhs, I64:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000069 [(set I32:$dst, (setcc I64:$lhs, I64:$rhs, cond))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000070 !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
JF Bastienda06bce2015-08-11 21:02:46 +000071}
Dan Gohmanaf29bd42015-11-05 20:42:30 +000072multiclass ComparisonFP<CondCode cond, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000073 def _F32 : I<(outs I32:$dst), (ins F32:$lhs, F32:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000074 [(set I32:$dst, (setcc F32:$lhs, F32:$rhs, cond))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000075 !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000076 def _F64 : I<(outs I32:$dst), (ins F64:$lhs, F64:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000077 [(set I32:$dst, (setcc F64:$lhs, F64:$rhs, cond))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000078 !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
JF Bastienda06bce2015-08-11 21:02:46 +000079}