blob: 66145b0bb2526dbf4da0367e397639ff6eca522b [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
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
Derek Schuff39bf39f2016-08-02 23:16:09 +000031class SIMD_I<dag oops, dag iops, list<dag> pattern, string asmstr = "">
32 : I<oops, iops, pattern, asmstr>, Requires<[HasSIMD128]>;
33
JF Bastiend9767a32015-07-14 21:13:29 +000034// Unary and binary instructions, for the local types that WebAssembly supports.
Dan Gohmanaf29bd42015-11-05 20:42:30 +000035multiclass UnaryInt<SDNode node, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000036 def _I32 : I<(outs I32:$dst), (ins I32:$src),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000037 [(set I32:$dst, (node I32:$src))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000038 !strconcat("i32.", !strconcat(name, "\t$dst, $src"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000039 def _I64 : I<(outs I64:$dst), (ins I64:$src),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000040 [(set I64:$dst, (node I64:$src))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000041 !strconcat("i64.", !strconcat(name, "\t$dst, $src"))>;
JF Bastiend9767a32015-07-14 21:13:29 +000042}
Dan Gohmanaf29bd42015-11-05 20:42:30 +000043multiclass BinaryInt<SDNode node, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000044 def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000045 [(set I32:$dst, (node I32:$lhs, I32:$rhs))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000046 !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000047 def _I64 : I<(outs I64:$dst), (ins I64:$lhs, I64:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000048 [(set I64:$dst, (node I64:$lhs, I64:$rhs))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000049 !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
JF Bastiend9767a32015-07-14 21:13:29 +000050}
Dan Gohmanaf29bd42015-11-05 20:42:30 +000051multiclass UnaryFP<SDNode node, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000052 def _F32 : I<(outs F32:$dst), (ins F32:$src),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000053 [(set F32:$dst, (node F32:$src))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000054 !strconcat("f32.", !strconcat(name, "\t$dst, $src"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000055 def _F64 : I<(outs F64:$dst), (ins F64:$src),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000056 [(set F64:$dst, (node F64:$src))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000057 !strconcat("f64.", !strconcat(name, "\t$dst, $src"))>;
JF Bastiend9767a32015-07-14 21:13:29 +000058}
Dan Gohmanaf29bd42015-11-05 20:42:30 +000059multiclass BinaryFP<SDNode node, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000060 def _F32 : I<(outs F32:$dst), (ins F32:$lhs, F32:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000061 [(set F32:$dst, (node F32:$lhs, F32:$rhs))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000062 !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000063 def _F64 : I<(outs F64:$dst), (ins F64:$lhs, F64:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000064 [(set F64:$dst, (node F64:$lhs, F64:$rhs))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000065 !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
JF Bastiend9767a32015-07-14 21:13:29 +000066}
Derek Schuff39bf39f2016-08-02 23:16:09 +000067multiclass SIMDBinary<SDNode node, SDNode fnode, string name> {
68 def _I8x16 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs),
69 [(set (v16i8 V128:$dst), (node V128:$lhs, V128:$rhs))],
70 !strconcat("i8x16.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
71 def _I16x8 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs),
72 [(set (v8i16 V128:$dst), (node V128:$lhs, V128:$rhs))],
73 !strconcat("i16x8.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
74 def _I32x4 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs),
75 [(set (v4i32 V128:$dst), (node V128:$lhs, V128:$rhs))],
76 !strconcat("i32x4.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
77 def _F32x4 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs),
78 [(set (v4f32 V128:$dst), (fnode V128:$lhs, V128:$rhs))],
79 !strconcat("f32x4.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
80
81}
Dan Gohmanaf29bd42015-11-05 20:42:30 +000082multiclass ComparisonInt<CondCode cond, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000083 def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000084 [(set I32:$dst, (setcc I32:$lhs, I32:$rhs, cond))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000085 !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000086 def _I64 : I<(outs I32:$dst), (ins I64:$lhs, I64:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000087 [(set I32:$dst, (setcc I64:$lhs, I64:$rhs, cond))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000088 !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
JF Bastienda06bce2015-08-11 21:02:46 +000089}
Dan Gohmanaf29bd42015-11-05 20:42:30 +000090multiclass ComparisonFP<CondCode cond, string name> {
Dan Gohmand0bf9812015-09-26 01:09:44 +000091 def _F32 : I<(outs I32:$dst), (ins F32:$lhs, F32:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000092 [(set I32:$dst, (setcc F32:$lhs, F32:$rhs, cond))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000093 !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
Dan Gohmand0bf9812015-09-26 01:09:44 +000094 def _F64 : I<(outs I32:$dst), (ins F64:$lhs, F64:$rhs),
Dan Gohmanaf29bd42015-11-05 20:42:30 +000095 [(set I32:$dst, (setcc F64:$lhs, F64:$rhs, cond))],
Dan Gohman1031d4a2015-11-15 15:34:19 +000096 !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
JF Bastienda06bce2015-08-11 21:02:46 +000097}