aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/WebAssembly/WebAssemblyInstrFormats.td
blob: 8008dd32353aea16d72433a858418a740d66ba66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//=- WebAssemblyInstrFormats.td - WebAssembly Instr. Formats -*- tablegen -*-=//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief WebAssembly instruction format definitions.
///
//===----------------------------------------------------------------------===//

// WebAssembly Instruction Format.
class WebAssemblyInst<string asmstr> : Instruction {
  field bits<0> Inst; // Instruction encoding.
  let Namespace   = "WebAssembly";
  let Pattern     = [];
  let AsmString   = asmstr;
}

// Normal instructions.
class I<dag oops, dag iops, list<dag> pattern, string asmstr = "">
    : WebAssemblyInst<asmstr> {
  dag OutOperandList = oops;
  dag InOperandList  = iops;
  let Pattern        = pattern;
}

// Unary and binary instructions, for the local types that WebAssembly supports.
multiclass UnaryInt<SDNode node, string name> {
  def _I32 : I<(outs I32:$dst), (ins I32:$src),
               [(set I32:$dst, (node I32:$src))],
               !strconcat("i32.", !strconcat(name, "\t$dst, $src"))>;
  def _I64 : I<(outs I64:$dst), (ins I64:$src),
               [(set I64:$dst, (node I64:$src))],
               !strconcat("i64.", !strconcat(name, "\t$dst, $src"))>;
}
multiclass BinaryInt<SDNode node, string name> {
  def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs),
               [(set I32:$dst, (node I32:$lhs, I32:$rhs))],
               !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
  def _I64 : I<(outs I64:$dst), (ins I64:$lhs, I64:$rhs),
               [(set I64:$dst, (node I64:$lhs, I64:$rhs))],
               !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
}
multiclass UnaryFP<SDNode node, string name> {
  def _F32 : I<(outs F32:$dst), (ins F32:$src),
               [(set F32:$dst, (node F32:$src))],
               !strconcat("f32.", !strconcat(name, "\t$dst, $src"))>;
  def _F64 : I<(outs F64:$dst), (ins F64:$src),
               [(set F64:$dst, (node F64:$src))],
               !strconcat("f64.", !strconcat(name, "\t$dst, $src"))>;
}
multiclass BinaryFP<SDNode node, string name> {
  def _F32 : I<(outs F32:$dst), (ins F32:$lhs, F32:$rhs),
               [(set F32:$dst, (node F32:$lhs, F32:$rhs))],
               !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
  def _F64 : I<(outs F64:$dst), (ins F64:$lhs, F64:$rhs),
               [(set F64:$dst, (node F64:$lhs, F64:$rhs))],
               !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
}
multiclass ComparisonInt<CondCode cond, string name> {
  def _I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs),
               [(set I32:$dst, (setcc I32:$lhs, I32:$rhs, cond))],
               !strconcat("i32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
  def _I64 : I<(outs I32:$dst), (ins I64:$lhs, I64:$rhs),
               [(set I32:$dst, (setcc I64:$lhs, I64:$rhs, cond))],
               !strconcat("i64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
}
multiclass ComparisonFP<CondCode cond, string name> {
  def _F32 : I<(outs I32:$dst), (ins F32:$lhs, F32:$rhs),
               [(set I32:$dst, (setcc F32:$lhs, F32:$rhs, cond))],
               !strconcat("f32.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
  def _F64 : I<(outs I32:$dst), (ins F64:$lhs, F64:$rhs),
               [(set I32:$dst, (setcc F64:$lhs, F64:$rhs, cond))],
               !strconcat("f64.", !strconcat(name, "\t$dst, $lhs, $rhs"))>;
}