• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// WebAssemblyInstrInfo.td-Describe the WebAssembly Instructions-*- 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/// \brief WebAssembly Instruction definitions.
12///
13//===----------------------------------------------------------------------===//
14
15//===----------------------------------------------------------------------===//
16// WebAssembly Instruction Predicate Definitions.
17//===----------------------------------------------------------------------===//
18
19def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">;
20def HasAddr64 : Predicate<"Subtarget->hasAddr64()">;
21def HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">,
22                           AssemblerPredicate<"FeatureSIMD128", "simd128">;
23
24//===----------------------------------------------------------------------===//
25// WebAssembly-specific DAG Node Types.
26//===----------------------------------------------------------------------===//
27
28def SDT_WebAssemblyCallSeqStart : SDCallSeqStart<[SDTCisVT<0, iPTR>]>;
29def SDT_WebAssemblyCallSeqEnd :
30    SDCallSeqEnd<[SDTCisVT<0, iPTR>, SDTCisVT<1, iPTR>]>;
31def SDT_WebAssemblyCall0    : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
32def SDT_WebAssemblyCall1    : SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>;
33def SDT_WebAssemblyTableswitch : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
34def SDT_WebAssemblyArgument : SDTypeProfile<1, 1, [SDTCisVT<1, i32>]>;
35def SDT_WebAssemblyReturn   : SDTypeProfile<0, -1, []>;
36def SDT_WebAssemblyWrapper  : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>,
37                                                   SDTCisPtrTy<0>]>;
38
39//===----------------------------------------------------------------------===//
40// WebAssembly-specific DAG Nodes.
41//===----------------------------------------------------------------------===//
42
43def WebAssemblycallseq_start :
44    SDNode<"ISD::CALLSEQ_START", SDT_WebAssemblyCallSeqStart,
45           [SDNPHasChain, SDNPOutGlue]>;
46def WebAssemblycallseq_end :
47    SDNode<"ISD::CALLSEQ_END", SDT_WebAssemblyCallSeqEnd,
48           [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
49def WebAssemblycall0 : SDNode<"WebAssemblyISD::CALL0",
50                              SDT_WebAssemblyCall0,
51                              [SDNPHasChain, SDNPVariadic]>;
52def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1",
53                              SDT_WebAssemblyCall1,
54                              [SDNPHasChain, SDNPVariadic]>;
55def WebAssemblytableswitch : SDNode<"WebAssemblyISD::TABLESWITCH",
56                                    SDT_WebAssemblyTableswitch,
57                                    [SDNPHasChain, SDNPVariadic]>;
58def WebAssemblyargument : SDNode<"WebAssemblyISD::ARGUMENT",
59                                 SDT_WebAssemblyArgument>;
60def WebAssemblyreturn   : SDNode<"WebAssemblyISD::RETURN",
61                                 SDT_WebAssemblyReturn, [SDNPHasChain]>;
62def WebAssemblywrapper  : SDNode<"WebAssemblyISD::Wrapper",
63                                 SDT_WebAssemblyWrapper>;
64
65//===----------------------------------------------------------------------===//
66// WebAssembly-specific Operands.
67//===----------------------------------------------------------------------===//
68
69def bb_op : Operand<OtherVT>;
70
71//===----------------------------------------------------------------------===//
72// WebAssembly Instruction Format Definitions.
73//===----------------------------------------------------------------------===//
74
75include "WebAssemblyInstrFormats.td"
76
77//===----------------------------------------------------------------------===//
78// Additional instructions.
79//===----------------------------------------------------------------------===//
80
81multiclass ARGUMENT<WebAssemblyRegClass vt> {
82  let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
83  def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
84                       [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
85}
86defm : ARGUMENT<I32>;
87defm : ARGUMENT<I64>;
88defm : ARGUMENT<F32>;
89defm : ARGUMENT<F64>;
90
91let Defs = [ARGUMENTS] in {
92
93// get_local and set_local are not generated by instruction selection; they
94// are implied by virtual register uses and defs in most contexts. However,
95// they are explicitly emitted for special purposes.
96multiclass LOCAL<WebAssemblyRegClass vt> {
97  def GET_LOCAL_#vt : I<(outs vt:$res), (ins i32imm:$regno), [],
98                        "get_local\t$res, $regno">;
99  // TODO: set_local returns its operand value
100  def SET_LOCAL_#vt : I<(outs), (ins i32imm:$regno, vt:$src), [],
101                        "set_local\t$regno, $src">;
102
103  // COPY_LOCAL is not an actual instruction in wasm, but since we allow
104  // get_local and set_local to be implicit, we can have a COPY_LOCAL which
105  // is actually a no-op because all the work is done in the implied
106  // get_local and set_local.
107  let isAsCheapAsAMove = 1 in
108  def COPY_LOCAL_#vt : I<(outs vt:$res), (ins vt:$src), [],
109                         "copy_local\t$res, $src">;
110}
111defm : LOCAL<I32>;
112defm : LOCAL<I64>;
113defm : LOCAL<F32>;
114defm : LOCAL<F64>;
115
116let isMoveImm = 1 in {
117def CONST_I32 : I<(outs I32:$res), (ins i32imm:$imm),
118                  [(set I32:$res, imm:$imm)],
119                  "i32.const\t$res, $imm">;
120def CONST_I64 : I<(outs I64:$res), (ins i64imm:$imm),
121                  [(set I64:$res, imm:$imm)],
122                  "i64.const\t$res, $imm">;
123def CONST_F32 : I<(outs F32:$res), (ins f32imm:$imm),
124                  [(set F32:$res, fpimm:$imm)],
125                  "f32.const\t$res, $imm">;
126def CONST_F64 : I<(outs F64:$res), (ins f64imm:$imm),
127                  [(set F64:$res, fpimm:$imm)],
128                  "f64.const\t$res, $imm">;
129} // isMoveImm = 1
130
131} // Defs = [ARGUMENTS]
132
133def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$dst)),
134          (CONST_I32 tglobaladdr:$dst)>;
135def : Pat<(i32 (WebAssemblywrapper texternalsym:$dst)),
136          (CONST_I32 texternalsym:$dst)>;
137def : Pat<(i32 (WebAssemblywrapper tjumptable:$dst)),
138          (CONST_I32 tjumptable:$dst)>;
139
140let Defs = [ARGUMENTS] in {
141
142// Function signature and local variable declaration "instructions".
143def PARAM  : I<(outs), (ins variable_ops), [], ".param  \t">;
144def RESULT : I<(outs), (ins variable_ops), [], ".result \t">;
145def LOCAL  : I<(outs), (ins variable_ops), [], ".local  \t">;
146
147} // Defs = [ARGUMENTS]
148
149//===----------------------------------------------------------------------===//
150// Additional sets of instructions.
151//===----------------------------------------------------------------------===//
152
153include "WebAssemblyInstrMemory.td"
154include "WebAssemblyInstrCall.td"
155include "WebAssemblyInstrControl.td"
156include "WebAssemblyInstrInteger.td"
157include "WebAssemblyInstrConv.td"
158include "WebAssemblyInstrFloat.td"
159include "WebAssemblyInstrAtomics.td"
160include "WebAssemblyInstrSIMD.td"
161