1 // WebAssemblyInstrInfo.td-Describe the WebAssembly Instructions-*- tablegen -*-
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief WebAssembly Instruction definitions.
13 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
16 // WebAssembly Instruction Predicate Definitions.
17 //===----------------------------------------------------------------------===//
19 def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">;
20 def HasAddr64 : Predicate<"Subtarget->hasAddr64()">;
21 def HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">,
22 AssemblerPredicate<"FeatureSIMD128", "simd128">;
24 //===----------------------------------------------------------------------===//
25 // WebAssembly-specific DAG Node Types.
26 //===----------------------------------------------------------------------===//
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>,
39 //===----------------------------------------------------------------------===//
40 // WebAssembly-specific DAG Nodes.
41 //===----------------------------------------------------------------------===//
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",
51 [SDNPHasChain, SDNPVariadic]>;
52 def WebAssemblycall1 : SDNode<"WebAssemblyISD::CALL1",
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>;
65 //===----------------------------------------------------------------------===//
66 // WebAssembly-specific Operands.
67 //===----------------------------------------------------------------------===//
69 let OperandNamespace = "WebAssembly" in {
71 let OperandType = "OPERAND_BASIC_BLOCK" in
72 def bb_op : Operand<OtherVT>;
74 let OperandType = "OPERAND_FPIMM" in {
75 def f32imm_op : Operand<f32>;
76 def f64imm_op : Operand<f64>;
77 } // OperandType = "OPERAND_FPIMM"
79 } // OperandNamespace = "WebAssembly"
81 //===----------------------------------------------------------------------===//
82 // WebAssembly Instruction Format Definitions.
83 //===----------------------------------------------------------------------===//
85 include "WebAssemblyInstrFormats.td"
87 //===----------------------------------------------------------------------===//
88 // Additional instructions.
89 //===----------------------------------------------------------------------===//
91 multiclass ARGUMENT<WebAssemblyRegClass vt> {
92 let hasSideEffects = 1, Uses = [ARGUMENTS], isCodeGenOnly = 1 in
93 def ARGUMENT_#vt : I<(outs vt:$res), (ins i32imm:$argno),
94 [(set vt:$res, (WebAssemblyargument timm:$argno))]>;
101 let Defs = [ARGUMENTS] in {
103 // get_local and set_local are not generated by instruction selection; they
104 // are implied by virtual register uses and defs in most contexts. However,
105 // they are explicitly emitted for special purposes.
106 multiclass LOCAL<WebAssemblyRegClass vt> {
107 def GET_LOCAL_#vt : I<(outs vt:$res), (ins i32imm:$regno), [],
108 "get_local\t$res, $regno">;
109 // TODO: set_local returns its operand value
110 def SET_LOCAL_#vt : I<(outs), (ins i32imm:$regno, vt:$src), [],
111 "set_local\t$regno, $src">;
113 // COPY_LOCAL is not an actual instruction in wasm, but since we allow
114 // get_local and set_local to be implicit, we can have a COPY_LOCAL which
115 // is actually a no-op because all the work is done in the implied
116 // get_local and set_local.
117 let isAsCheapAsAMove = 1 in
118 def COPY_LOCAL_#vt : I<(outs vt:$res), (ins vt:$src), [],
119 "copy_local\t$res, $src">;
126 let isMoveImm = 1 in {
127 def CONST_I32 : I<(outs I32:$res), (ins i32imm:$imm),
128 [(set I32:$res, imm:$imm)],
129 "i32.const\t$res, $imm">;
130 def CONST_I64 : I<(outs I64:$res), (ins i64imm:$imm),
131 [(set I64:$res, imm:$imm)],
132 "i64.const\t$res, $imm">;
133 def CONST_F32 : I<(outs F32:$res), (ins f32imm_op:$imm),
134 [(set F32:$res, fpimm:$imm)],
135 "f32.const\t$res, $imm">;
136 def CONST_F64 : I<(outs F64:$res), (ins f64imm_op:$imm),
137 [(set F64:$res, fpimm:$imm)],
138 "f64.const\t$res, $imm">;
141 } // Defs = [ARGUMENTS]
143 def : Pat<(i32 (WebAssemblywrapper tglobaladdr:$addr)),
144 (CONST_I32 tglobaladdr:$addr)>;
145 def : Pat<(i32 (WebAssemblywrapper texternalsym:$addr)),
146 (CONST_I32 texternalsym:$addr)>;
148 //===----------------------------------------------------------------------===//
149 // Additional sets of instructions.
150 //===----------------------------------------------------------------------===//
152 include "WebAssemblyInstrMemory.td"
153 include "WebAssemblyInstrCall.td"
154 include "WebAssemblyInstrControl.td"
155 include "WebAssemblyInstrInteger.td"
156 include "WebAssemblyInstrConv.td"
157 include "WebAssemblyInstrFloat.td"
158 include "WebAssemblyInstrAtomics.td"
159 include "WebAssemblyInstrSIMD.td"