1 //===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- tablegen -*-
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// WebAssembly Call operand code-gen constructs.
12 //===----------------------------------------------------------------------===//
14 // TODO: addr64: These currently assume the callee address is 32-bit.
15 // FIXME: add $type to first call_indirect asmstr (and maybe $flags)
17 // Call sequence markers. These have an immediate which represents the amount of
18 // stack space to allocate or free, which is used for varargs lowering.
19 let Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in {
20 defm ADJCALLSTACKDOWN : NRI<(outs), (ins i32imm:$amt, i32imm:$amt2),
21 [(WebAssemblycallseq_start timm:$amt, timm:$amt2)]>;
22 defm ADJCALLSTACKUP : NRI<(outs), (ins i32imm:$amt, i32imm:$amt2),
23 [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>;
24 } // Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1
26 multiclass CALL<ValueType vt, WebAssemblyRegClass rt, string prefix,
27 list<Predicate> preds = []> {
29 I<(outs rt:$dst), (ins function32_op:$callee, variable_ops),
30 (outs), (ins function32_op:$callee),
31 [(set (vt rt:$dst), (WebAssemblycall1 (i32 imm:$callee)))],
32 !strconcat(prefix, "call\t$dst, $callee"),
33 !strconcat(prefix, "call\t$callee"),
37 let isCodeGenOnly = 1 in
38 defm PCALL_INDIRECT_#vt :
39 I<(outs rt:$dst), (ins I32:$callee, variable_ops),
40 (outs), (ins I32:$callee),
41 [(set (vt rt:$dst), (WebAssemblycall1 I32:$callee))],
42 "PSEUDO CALL INDIRECT\t$callee",
43 "PSEUDO CALL INDIRECT\t$callee">,
46 defm CALL_INDIRECT_#vt :
48 (ins TypeIndex:$type, i32imm:$flags, variable_ops),
49 (outs), (ins TypeIndex:$type, i32imm:$flags),
51 !strconcat(prefix, "call_indirect\t$dst"),
52 !strconcat(prefix, "call_indirect\t$type"),
57 let Uses = [SP32, SP64], isCall = 1 in {
58 defm "" : CALL<i32, I32, "i32.">;
59 defm "" : CALL<i64, I64, "i64.">;
60 defm "" : CALL<f32, F32, "f32.">;
61 defm "" : CALL<f64, F64, "f64.">;
62 defm "" : CALL<exnref, EXNREF, "exnref.", [HasExceptionHandling]>;
63 defm "" : CALL<v16i8, V128, "v128.", [HasSIMD128]>;
64 defm "" : CALL<v8i16, V128, "v128.", [HasSIMD128]>;
65 defm "" : CALL<v4i32, V128, "v128.", [HasSIMD128]>;
66 defm "" : CALL<v2i64, V128, "v128.", [HasSIMD128]>;
67 defm "" : CALL<v4f32, V128, "v128.", [HasSIMD128]>;
68 defm "" : CALL<v2f64, V128, "v128.", [HasSIMD128]>;
70 let IsCanonical = 1 in {
72 I<(outs), (ins function32_op:$callee, variable_ops),
73 (outs), (ins function32_op:$callee),
74 [(WebAssemblycall0 (i32 imm:$callee))],
75 "call \t$callee", "call\t$callee", 0x10>;
79 I<(outs), (ins function32_op:$callee, variable_ops),
80 (outs), (ins function32_op:$callee),
81 [(WebAssemblyretcall (i32 imm:$callee))],
82 "return_call \t$callee", "return_call\t$callee", 0x12>,
83 Requires<[HasTailCall]>;
85 let isCodeGenOnly = 1 in
86 defm PCALL_INDIRECT_VOID :
87 I<(outs), (ins I32:$callee, variable_ops),
88 (outs), (ins I32:$callee),
89 [(WebAssemblycall0 I32:$callee)],
90 "PSEUDO CALL INDIRECT\t$callee",
91 "PSEUDO CALL INDIRECT\t$callee">;
93 defm CALL_INDIRECT_VOID :
94 I<(outs), (ins TypeIndex:$type, i32imm:$flags, variable_ops),
95 (outs), (ins TypeIndex:$type, i32imm:$flags),
97 "call_indirect\t", "call_indirect\t$type",
101 defm RET_CALL_INDIRECT :
102 I<(outs), (ins TypeIndex:$type, i32imm:$flags, variable_ops),
103 (outs), (ins TypeIndex:$type, i32imm:$flags),
105 "return_call_indirect\t", "return_call_indirect\t$type",
107 Requires<[HasTailCall]>;
109 let isCodeGenOnly = 1, isReturn = 1 in
110 defm PRET_CALL_INDIRECT:
111 I<(outs), (ins I32:$callee, variable_ops),
112 (outs), (ins I32:$callee),
113 [(WebAssemblyretcall I32:$callee)],
114 "PSEUDO RET_CALL INDIRECT\t$callee",
115 "PSEUDO RET_CALL INDIRECT\t$callee">,
116 Requires<[HasTailCall]>;
119 } // Uses = [SP32,SP64], isCall = 1
121 // Patterns for matching a direct call to a global address.
122 def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
123 (CALL_i32 tglobaladdr:$callee)>;
124 def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
125 (CALL_i64 tglobaladdr:$callee)>;
126 def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
127 (CALL_f32 tglobaladdr:$callee)>;
128 def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
129 (CALL_f64 tglobaladdr:$callee)>;
130 def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
131 (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
132 def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
133 (CALL_v8i16 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
134 def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
135 (CALL_v4i32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
136 def : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
137 (CALL_v2i64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
138 def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
139 (CALL_v4f32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
140 def : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
141 (CALL_v2f64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
142 def : Pat<(exnref (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
143 (CALL_exnref tglobaladdr:$callee)>,
144 Requires<[HasExceptionHandling]>;
145 def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)),
146 (CALL_VOID tglobaladdr:$callee)>;
147 def : Pat<(WebAssemblyretcall (WebAssemblywrapper tglobaladdr:$callee)),
148 (RET_CALL tglobaladdr:$callee)>, Requires<[HasTailCall]>;
150 // Patterns for matching a direct call to an external symbol.
151 def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
152 (CALL_i32 texternalsym:$callee)>;
153 def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
154 (CALL_i64 texternalsym:$callee)>;
155 def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
156 (CALL_f32 texternalsym:$callee)>;
157 def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
158 (CALL_f64 texternalsym:$callee)>;
159 def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
160 (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>;
161 def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
162 (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>;
163 def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
164 (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
165 def : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
166 (CALL_v2i64 texternalsym:$callee)>, Requires<[HasSIMD128]>;
167 def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
168 (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
169 def : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
170 (CALL_v2f64 texternalsym:$callee)>, Requires<[HasSIMD128]>;
171 def : Pat<(exnref (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
172 (CALL_exnref texternalsym:$callee)>,
173 Requires<[HasExceptionHandling]>;
174 def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)),
175 (CALL_VOID texternalsym:$callee)>;
176 def : Pat<(WebAssemblyretcall (WebAssemblywrapper texternalsym:$callee)),
177 (RET_CALL texternalsym:$callee)>, Requires<[HasTailCall]>;