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