Dan Gohman | 7f97076 | 2015-12-08 03:36:00 +0000 | [diff] [blame] | 1 | //=- WebAssemblyInstrFormats.td - WebAssembly Instr. Formats -*- tablegen -*-=// |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 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 Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
| 11 | /// \brief WebAssembly instruction format definitions. |
| 12 | /// |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 15 | // WebAssembly Instruction Format. |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 16 | class WebAssemblyInst<bits<32> inst, string asmstr> : Instruction { |
| 17 | field bits<32> Inst = inst; // Instruction encoding. |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 18 | let Namespace = "WebAssembly"; |
| 19 | let Pattern = []; |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 20 | let AsmString = asmstr; |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 21 | } |
| 22 | |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 23 | // Normal instructions. |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 24 | class I<dag oops, dag iops, list<dag> pattern, string asmstr = "", bits<32> inst = -1> |
| 25 | : WebAssemblyInst<inst, asmstr> { |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 26 | dag OutOperandList = oops; |
| 27 | dag InOperandList = iops; |
| 28 | let Pattern = pattern; |
| 29 | } |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 30 | |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 31 | class 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 Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 34 | |
Derek Schuff | 18ba192 | 2017-08-30 18:07:45 +0000 | [diff] [blame] | 35 | class ATOMIC_I<dag oops, dag iops, list<dag> pattern, |
| 36 | string asmstr = "", bits<32> inst = -1> |
| 37 | : I<oops, iops, pattern, asmstr, inst>, Requires<[HasAtomics]>; |
| 38 | |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 39 | // Unary and binary instructions, for the local types that WebAssembly supports. |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 40 | multiclass UnaryInt<SDNode node, string name, bits<32> i32Inst, bits<32> i64Inst> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 41 | def _I32 : I<(outs I32:$dst), (ins I32:$src), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 42 | [(set I32:$dst, (node I32:$src))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 43 | !strconcat("i32.", !strconcat(name, "\t$dst, $src")), i32Inst>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 44 | def _I64 : I<(outs I64:$dst), (ins I64:$src), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 45 | [(set I64:$dst, (node I64:$src))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 46 | !strconcat("i64.", !strconcat(name, "\t$dst, $src")), i64Inst>; |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 47 | } |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 48 | multiclass BinaryInt<SDNode node, string name, bits<32> i32Inst, bits<32> i64Inst> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 49 | def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 50 | [(set I32:$dst, (node I32:$lhs, I32:$rhs))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 51 | !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs")), i32Inst>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 52 | def _I64 : I<(outs I64:$dst), (ins I64:$lhs, I64:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 53 | [(set I64:$dst, (node I64:$lhs, I64:$rhs))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 54 | !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs")), i64Inst>; |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 55 | } |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 56 | multiclass UnaryFP<SDNode node, string name, bits<32> f32Inst, bits<32> f64Inst> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 57 | def _F32 : I<(outs F32:$dst), (ins F32:$src), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 58 | [(set F32:$dst, (node F32:$src))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 59 | !strconcat("f32.", !strconcat(name, "\t$dst, $src")), f32Inst>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 60 | def _F64 : I<(outs F64:$dst), (ins F64:$src), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 61 | [(set F64:$dst, (node F64:$src))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 62 | !strconcat("f64.", !strconcat(name, "\t$dst, $src")), f64Inst>; |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 63 | } |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 64 | multiclass BinaryFP<SDNode node, string name, bits<32> f32Inst, bits<32> f64Inst> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 65 | def _F32 : I<(outs F32:$dst), (ins F32:$lhs, F32:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 66 | [(set F32:$dst, (node F32:$lhs, F32:$rhs))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 67 | !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs")), f32Inst>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 68 | def _F64 : I<(outs F64:$dst), (ins F64:$lhs, F64:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 69 | [(set F64:$dst, (node F64:$lhs, F64:$rhs))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 70 | !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs")), f64Inst>; |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 71 | } |
Derek Schuff | 39bf39f | 2016-08-02 23:16:09 +0000 | [diff] [blame] | 72 | multiclass SIMDBinary<SDNode node, SDNode fnode, string name> { |
| 73 | def _I8x16 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), |
| 74 | [(set (v16i8 V128:$dst), (node V128:$lhs, V128:$rhs))], |
| 75 | !strconcat("i8x16.", !strconcat(name, "\t$dst, $lhs, $rhs"))>; |
| 76 | def _I16x8 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), |
| 77 | [(set (v8i16 V128:$dst), (node V128:$lhs, V128:$rhs))], |
| 78 | !strconcat("i16x8.", !strconcat(name, "\t$dst, $lhs, $rhs"))>; |
| 79 | def _I32x4 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), |
| 80 | [(set (v4i32 V128:$dst), (node V128:$lhs, V128:$rhs))], |
| 81 | !strconcat("i32x4.", !strconcat(name, "\t$dst, $lhs, $rhs"))>; |
| 82 | def _F32x4 : SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), |
| 83 | [(set (v4f32 V128:$dst), (fnode V128:$lhs, V128:$rhs))], |
| 84 | !strconcat("f32x4.", !strconcat(name, "\t$dst, $lhs, $rhs"))>; |
| 85 | |
| 86 | } |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 87 | multiclass ComparisonInt<CondCode cond, string name, bits<32> i32Inst, bits<32> i64Inst> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 88 | def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 89 | [(set I32:$dst, (setcc I32:$lhs, I32:$rhs, cond))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 90 | !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs")), |
| 91 | i32Inst>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 92 | def _I64 : I<(outs I32:$dst), (ins I64:$lhs, I64:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 93 | [(set I32:$dst, (setcc I64:$lhs, I64:$rhs, cond))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 94 | !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs")), |
| 95 | i64Inst>; |
JF Bastien | da06bce | 2015-08-11 21:02:46 +0000 | [diff] [blame] | 96 | } |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 97 | multiclass ComparisonFP<CondCode cond, string name, bits<32> f32Inst, bits<32> f64Inst> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 98 | def _F32 : I<(outs I32:$dst), (ins F32:$lhs, F32:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 99 | [(set I32:$dst, (setcc F32:$lhs, F32:$rhs, cond))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 100 | !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs")), |
| 101 | f32Inst>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 102 | def _F64 : I<(outs I32:$dst), (ins F64:$lhs, F64:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 103 | [(set I32:$dst, (setcc F64:$lhs, F64:$rhs, cond))], |
Dan Gohman | 5a68ec7 | 2016-10-05 21:24:08 +0000 | [diff] [blame] | 104 | !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs")), |
| 105 | f64Inst>; |
JF Bastien | da06bce | 2015-08-11 21:02:46 +0000 | [diff] [blame] | 106 | } |