xref: /aosp_15_r20/external/llvm/lib/Target/WebAssembly/WebAssemblyInstrFormats.td (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker//=- WebAssemblyInstrFormats.td - WebAssembly Instr. Formats -*- tablegen -*-=//
2*9880d681SAndroid Build Coastguard Worker//
3*9880d681SAndroid Build Coastguard Worker//                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker//
5*9880d681SAndroid Build Coastguard Worker// This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker// License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker//
8*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker///
10*9880d681SAndroid Build Coastguard Worker/// \file
11*9880d681SAndroid Build Coastguard Worker/// \brief WebAssembly instruction format definitions.
12*9880d681SAndroid Build Coastguard Worker///
13*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Worker// WebAssembly Instruction Format.
16*9880d681SAndroid Build Coastguard Workerclass WebAssemblyInst<string asmstr> : Instruction {
17*9880d681SAndroid Build Coastguard Worker  field bits<0> Inst; // Instruction encoding.
18*9880d681SAndroid Build Coastguard Worker  let Namespace   = "WebAssembly";
19*9880d681SAndroid Build Coastguard Worker  let Pattern     = [];
20*9880d681SAndroid Build Coastguard Worker  let AsmString   = asmstr;
21*9880d681SAndroid Build Coastguard Worker}
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Worker// Normal instructions.
24*9880d681SAndroid Build Coastguard Workerclass I<dag oops, dag iops, list<dag> pattern, string asmstr = "">
25*9880d681SAndroid Build Coastguard Worker    : WebAssemblyInst<asmstr> {
26*9880d681SAndroid Build Coastguard Worker  dag OutOperandList = oops;
27*9880d681SAndroid Build Coastguard Worker  dag InOperandList  = iops;
28*9880d681SAndroid Build Coastguard Worker  let Pattern        = pattern;
29*9880d681SAndroid Build Coastguard Worker}
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Worker// Unary and binary instructions, for the local types that WebAssembly supports.
32*9880d681SAndroid Build Coastguard Workermulticlass UnaryInt<SDNode node, string name> {
33*9880d681SAndroid Build Coastguard Worker  def _I32 : I<(outs I32:$dst), (ins I32:$src),
34*9880d681SAndroid Build Coastguard Worker               [(set I32:$dst, (node I32:$src))],
35*9880d681SAndroid Build Coastguard Worker               !strconcat("i32.", !strconcat(name, "\t$dst, $src"))>;
36*9880d681SAndroid Build Coastguard Worker  def _I64 : I<(outs I64:$dst), (ins I64:$src),
37*9880d681SAndroid Build Coastguard Worker               [(set I64:$dst, (node I64:$src))],
38*9880d681SAndroid Build Coastguard Worker               !strconcat("i64.", !strconcat(name, "\t$dst, $src"))>;
39*9880d681SAndroid Build Coastguard Worker}
40*9880d681SAndroid Build Coastguard Workermulticlass BinaryInt<SDNode node, string name> {
41*9880d681SAndroid Build Coastguard Worker  def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs),
42*9880d681SAndroid Build Coastguard Worker               [(set I32:$dst, (node I32:$lhs, I32:$rhs))],
43*9880d681SAndroid Build Coastguard Worker               !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
44*9880d681SAndroid Build Coastguard Worker  def _I64 : I<(outs I64:$dst), (ins I64:$lhs, I64:$rhs),
45*9880d681SAndroid Build Coastguard Worker               [(set I64:$dst, (node I64:$lhs, I64:$rhs))],
46*9880d681SAndroid Build Coastguard Worker               !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
47*9880d681SAndroid Build Coastguard Worker}
48*9880d681SAndroid Build Coastguard Workermulticlass UnaryFP<SDNode node, string name> {
49*9880d681SAndroid Build Coastguard Worker  def _F32 : I<(outs F32:$dst), (ins F32:$src),
50*9880d681SAndroid Build Coastguard Worker               [(set F32:$dst, (node F32:$src))],
51*9880d681SAndroid Build Coastguard Worker               !strconcat("f32.", !strconcat(name, "\t$dst, $src"))>;
52*9880d681SAndroid Build Coastguard Worker  def _F64 : I<(outs F64:$dst), (ins F64:$src),
53*9880d681SAndroid Build Coastguard Worker               [(set F64:$dst, (node F64:$src))],
54*9880d681SAndroid Build Coastguard Worker               !strconcat("f64.", !strconcat(name, "\t$dst, $src"))>;
55*9880d681SAndroid Build Coastguard Worker}
56*9880d681SAndroid Build Coastguard Workermulticlass BinaryFP<SDNode node, string name> {
57*9880d681SAndroid Build Coastguard Worker  def _F32 : I<(outs F32:$dst), (ins F32:$lhs, F32:$rhs),
58*9880d681SAndroid Build Coastguard Worker               [(set F32:$dst, (node F32:$lhs, F32:$rhs))],
59*9880d681SAndroid Build Coastguard Worker               !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
60*9880d681SAndroid Build Coastguard Worker  def _F64 : I<(outs F64:$dst), (ins F64:$lhs, F64:$rhs),
61*9880d681SAndroid Build Coastguard Worker               [(set F64:$dst, (node F64:$lhs, F64:$rhs))],
62*9880d681SAndroid Build Coastguard Worker               !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
63*9880d681SAndroid Build Coastguard Worker}
64*9880d681SAndroid Build Coastguard Workermulticlass ComparisonInt<CondCode cond, string name> {
65*9880d681SAndroid Build Coastguard Worker  def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs),
66*9880d681SAndroid Build Coastguard Worker               [(set I32:$dst, (setcc I32:$lhs, I32:$rhs, cond))],
67*9880d681SAndroid Build Coastguard Worker               !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
68*9880d681SAndroid Build Coastguard Worker  def _I64 : I<(outs I32:$dst), (ins I64:$lhs, I64:$rhs),
69*9880d681SAndroid Build Coastguard Worker               [(set I32:$dst, (setcc I64:$lhs, I64:$rhs, cond))],
70*9880d681SAndroid Build Coastguard Worker               !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
71*9880d681SAndroid Build Coastguard Worker}
72*9880d681SAndroid Build Coastguard Workermulticlass ComparisonFP<CondCode cond, string name> {
73*9880d681SAndroid Build Coastguard Worker  def _F32 : I<(outs I32:$dst), (ins F32:$lhs, F32:$rhs),
74*9880d681SAndroid Build Coastguard Worker               [(set I32:$dst, (setcc F32:$lhs, F32:$rhs, cond))],
75*9880d681SAndroid Build Coastguard Worker               !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
76*9880d681SAndroid Build Coastguard Worker  def _F64 : I<(outs I32:$dst), (ins F64:$lhs, F64:$rhs),
77*9880d681SAndroid Build Coastguard Worker               [(set I32:$dst, (setcc F64:$lhs, F64:$rhs, cond))],
78*9880d681SAndroid Build Coastguard Worker               !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
79*9880d681SAndroid Build Coastguard Worker}
80