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<ExceptRef, EXCEPT_REF, "except_ref.", [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]>;
143 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
144 (CALL_ExceptRef tglobaladdr:$callee)>,
145 Requires<[HasExceptionHandling]>;
146 def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)),
147 (CALL_VOID tglobaladdr:$callee)>;
148 def : Pat<(WebAssemblyretcall (WebAssemblywrapper tglobaladdr:$callee)),
149 (RET_CALL tglobaladdr:$callee)>, Requires<[HasTailCall]>;
151 // Patterns for matching a direct call to an external symbol.
152 def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
153 (CALL_i32 texternalsym:$callee)>;
154 def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
155 (CALL_i64 texternalsym:$callee)>;
156 def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
157 (CALL_f32 texternalsym:$callee)>;
158 def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
159 (CALL_f64 texternalsym:$callee)>;
160 def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
161 (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>;
162 def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
163 (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>;
164 def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
165 (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
166 def : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
167 (CALL_v2i64 texternalsym:$callee)>, Requires<[HasSIMD128]>;
168 def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
169 (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
170 def : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
171 (CALL_v2f64 texternalsym:$callee)>, Requires<[HasSIMD128]>;
173 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
174 (CALL_ExceptRef texternalsym:$callee)>,
175 Requires<[HasExceptionHandling]>;
176 def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)),
177 (CALL_VOID texternalsym:$callee)>;
178 def : Pat<(WebAssemblyretcall (WebAssemblywrapper texternalsym:$callee)),
179 (RET_CALL texternalsym:$callee)>, Requires<[HasTailCall]>;