Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | // 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 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 | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 16 | class WebAssemblyInst<string asmstr> : Instruction { |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 17 | field bits<0> Inst; // Instruction encoding. |
| 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 | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 24 | class I<dag oops, dag iops, list<dag> pattern, string asmstr = ""> |
| 25 | : WebAssemblyInst<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 | |
| 31 | // Unary and binary instructions, for the local types that WebAssembly supports. |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 32 | multiclass UnaryInt<SDNode node, string name> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 33 | def _I32 : I<(outs I32:$dst), (ins I32:$src), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 34 | [(set I32:$dst, (node I32:$src))], |
| 35 | !strconcat("i32.", !strconcat(name, " $dst, $src"))>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 36 | def _I64 : I<(outs I64:$dst), (ins I64:$src), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 37 | [(set I64:$dst, (node I64:$src))], |
| 38 | !strconcat("i64.", !strconcat(name, " $dst, $src"))>; |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 39 | } |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 40 | multiclass BinaryInt<SDNode node, string name> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 41 | def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 42 | [(set I32:$dst, (node I32:$lhs, I32:$rhs))], |
| 43 | !strconcat("i32.", !strconcat(name, " $dst, $lhs, $rhs"))>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 44 | def _I64 : I<(outs I64:$dst), (ins I64:$lhs, I64:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 45 | [(set I64:$dst, (node I64:$lhs, I64:$rhs))], |
| 46 | !strconcat("i64.", !strconcat(name, " $dst, $lhs, $rhs"))>; |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 47 | } |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 48 | multiclass UnaryFP<SDNode node, string name> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 49 | def _F32 : I<(outs F32:$dst), (ins F32:$src), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 50 | [(set F32:$dst, (node F32:$src))], |
| 51 | !strconcat("f32.", !strconcat(name, " $dst, $src"))>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 52 | def _F64 : I<(outs F64:$dst), (ins F64:$src), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 53 | [(set F64:$dst, (node F64:$src))], |
| 54 | !strconcat("f64.", !strconcat(name, " $dst, $src"))>; |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 55 | } |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 56 | multiclass BinaryFP<SDNode node, string name> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 57 | def _F32 : I<(outs F32:$dst), (ins F32:$lhs, F32:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 58 | [(set F32:$dst, (node F32:$lhs, F32:$rhs))], |
| 59 | !strconcat("f32.", !strconcat(name, " $dst, $lhs, $rhs"))>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 60 | def _F64 : I<(outs F64:$dst), (ins F64:$lhs, F64:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 61 | [(set F64:$dst, (node F64:$lhs, F64:$rhs))], |
| 62 | !strconcat("f64.", !strconcat(name, " $dst, $lhs, $rhs"))>; |
JF Bastien | d9767a3 | 2015-07-14 21:13:29 +0000 | [diff] [blame] | 63 | } |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 64 | multiclass ComparisonInt<CondCode cond, string name> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 65 | def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 66 | [(set I32:$dst, (setcc I32:$lhs, I32:$rhs, cond))], |
| 67 | !strconcat("i32.", !strconcat(name, " $dst, $lhs, $rhs"))>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 68 | def _I64 : I<(outs I32:$dst), (ins I64:$lhs, I64:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 69 | [(set I32:$dst, (setcc I64:$lhs, I64:$rhs, cond))], |
| 70 | !strconcat("i64.", !strconcat(name, " $dst, $lhs, $rhs"))>; |
JF Bastien | da06bce | 2015-08-11 21:02:46 +0000 | [diff] [blame] | 71 | } |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 72 | multiclass ComparisonFP<CondCode cond, string name> { |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 73 | def _F32 : I<(outs I32:$dst), (ins F32:$lhs, F32:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 74 | [(set I32:$dst, (setcc F32:$lhs, F32:$rhs, cond))], |
| 75 | !strconcat("f32.", !strconcat(name, " $dst, $lhs, $rhs"))>; |
Dan Gohman | d0bf981 | 2015-09-26 01:09:44 +0000 | [diff] [blame] | 76 | def _F64 : I<(outs I32:$dst), (ins F64:$lhs, F64:$rhs), |
Dan Gohman | af29bd4 | 2015-11-05 20:42:30 +0000 | [diff] [blame] | 77 | [(set I32:$dst, (setcc F64:$lhs, F64:$rhs, cond))], |
| 78 | !strconcat("f64.", !strconcat(name, " $dst, $lhs, $rhs"))>; |
JF Bastien | da06bce | 2015-08-11 21:02:46 +0000 | [diff] [blame] | 79 | } |