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