1//=- WebAssemblyInstrFormats.td - WebAssembly Instr. Formats -*- tablegen -*-=// 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//===----------------------------------------------------------------------===// 9/// 10/// \file 11/// WebAssembly instruction format definitions. 12/// 13//===----------------------------------------------------------------------===// 14 15// WebAssembly Instruction Format. 16class WebAssemblyInst<bits<32> inst, string asmstr> : Instruction { 17 field bits<32> Inst = inst; // Instruction encoding. 18 let Namespace = "WebAssembly"; 19 let Pattern = []; 20 let AsmString = asmstr; 21} 22 23// Normal instructions. 24class I<dag oops, dag iops, list<dag> pattern, string asmstr = "", bits<32> inst = -1> 25 : WebAssemblyInst<inst, asmstr> { 26 dag OutOperandList = oops; 27 dag InOperandList = iops; 28 let Pattern = pattern; 29} 30 31class 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]>; 34 35class 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 39// Unary and binary instructions, for the local types that WebAssembly supports. 40multiclass UnaryInt<SDNode node, string name, bits<32> i32Inst, bits<32> i64Inst> { 41 def _I32 : I<(outs I32:$dst), (ins I32:$src), 42 [(set I32:$dst, (node I32:$src))], 43 !strconcat("i32.", !strconcat(name, "\t$dst, $src")), i32Inst>; 44 def _I64 : I<(outs I64:$dst), (ins I64:$src), 45 [(set I64:$dst, (node I64:$src))], 46 !strconcat("i64.", !strconcat(name, "\t$dst, $src")), i64Inst>; 47} 48multiclass BinaryInt<SDNode node, string name, bits<32> i32Inst, bits<32> i64Inst> { 49 def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs), 50 [(set I32:$dst, (node I32:$lhs, I32:$rhs))], 51 !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs")), i32Inst>; 52 def _I64 : I<(outs I64:$dst), (ins I64:$lhs, I64:$rhs), 53 [(set I64:$dst, (node I64:$lhs, I64:$rhs))], 54 !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs")), i64Inst>; 55} 56multiclass UnaryFP<SDNode node, string name, bits<32> f32Inst, bits<32> f64Inst> { 57 def _F32 : I<(outs F32:$dst), (ins F32:$src), 58 [(set F32:$dst, (node F32:$src))], 59 !strconcat("f32.", !strconcat(name, "\t$dst, $src")), f32Inst>; 60 def _F64 : I<(outs F64:$dst), (ins F64:$src), 61 [(set F64:$dst, (node F64:$src))], 62 !strconcat("f64.", !strconcat(name, "\t$dst, $src")), f64Inst>; 63} 64multiclass BinaryFP<SDNode node, string name, bits<32> f32Inst, bits<32> f64Inst> { 65 def _F32 : I<(outs F32:$dst), (ins F32:$lhs, F32:$rhs), 66 [(set F32:$dst, (node F32:$lhs, F32:$rhs))], 67 !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs")), f32Inst>; 68 def _F64 : I<(outs F64:$dst), (ins F64:$lhs, F64:$rhs), 69 [(set F64:$dst, (node F64:$lhs, F64:$rhs))], 70 !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs")), f64Inst>; 71} 72multiclass 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} 87multiclass ComparisonInt<CondCode cond, string name, bits<32> i32Inst, bits<32> i64Inst> { 88 def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs), 89 [(set I32:$dst, (setcc I32:$lhs, I32:$rhs, cond))], 90 !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs")), 91 i32Inst>; 92 def _I64 : I<(outs I32:$dst), (ins I64:$lhs, I64:$rhs), 93 [(set I32:$dst, (setcc I64:$lhs, I64:$rhs, cond))], 94 !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs")), 95 i64Inst>; 96} 97multiclass ComparisonFP<CondCode cond, string name, bits<32> f32Inst, bits<32> f64Inst> { 98 def _F32 : I<(outs I32:$dst), (ins F32:$lhs, F32:$rhs), 99 [(set I32:$dst, (setcc F32:$lhs, F32:$rhs, cond))], 100 !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs")), 101 f32Inst>; 102 def _F64 : I<(outs I32:$dst), (ins F64:$lhs, F64:$rhs), 103 [(set I32:$dst, (setcc F64:$lhs, F64:$rhs, cond))], 104 !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs")), 105 f64Inst>; 106} 107