1 //===- WebAssemblyInstrCall.td-WebAssembly Call codegen support -*- 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 /// WebAssembly Call operand code-gen constructs.
13 //===----------------------------------------------------------------------===//
15 // TODO: addr64: These currently assume the callee address is 32-bit.
16 // FIXME: add $type to first call_indirect asmstr (and maybe $flags)
18 // Call sequence markers. These have an immediate which represents the amount of
19 // stack space to allocate or free, which is used for varargs lowering.
20 let Uses = [SP32, SP64], Defs = [SP32, SP64], isCodeGenOnly = 1 in {
21 defm ADJCALLSTACKDOWN : NRI<(outs), (ins i32imm:$amt, i32imm:$amt2),
22 [(WebAssemblycallseq_start timm:$amt, timm:$amt2)]>;
23 defm ADJCALLSTACKUP : NRI<(outs), (ins i32imm:$amt, i32imm:$amt2),
24 [(WebAssemblycallseq_end timm:$amt, timm:$amt2)]>;
25 } // isCodeGenOnly = 1
27 multiclass CALL<WebAssemblyRegClass vt, string prefix> {
28 defm CALL_#vt : I<(outs vt:$dst), (ins function32_op:$callee, variable_ops),
29 (outs), (ins function32_op:$callee),
30 [(set vt:$dst, (WebAssemblycall1 (i32 imm:$callee)))],
31 !strconcat(prefix, "call\t$dst, $callee"),
32 !strconcat(prefix, "call\t$callee"),
35 let isCodeGenOnly = 1 in {
36 defm PCALL_INDIRECT_#vt : I<(outs vt:$dst), (ins I32:$callee, variable_ops),
37 (outs), (ins I32:$callee),
38 [(set vt:$dst, (WebAssemblycall1 I32:$callee))],
39 "PSEUDO CALL INDIRECT\t$callee",
40 "PSEUDO CALL INDIRECT\t$callee">;
41 } // isCodeGenOnly = 1
43 defm CALL_INDIRECT_#vt : I<(outs vt:$dst),
44 (ins TypeIndex:$type, i32imm:$flags, variable_ops),
45 (outs), (ins TypeIndex:$type, i32imm:$flags),
47 !strconcat(prefix, "call_indirect\t$dst"),
48 !strconcat(prefix, "call_indirect\t$type"),
52 multiclass SIMD_CALL<ValueType vt, string prefix> {
54 defm CALL_#vt : I<(outs V128:$dst), (ins function32_op:$callee, variable_ops),
55 (outs), (ins function32_op:$callee),
57 (WebAssemblycall1 (i32 imm:$callee)))],
58 !strconcat(prefix, "call\t$dst, $callee"),
59 !strconcat(prefix, "call\t$callee"),
61 Requires<[HasSIMD128]>;
63 let isCodeGenOnly = 1 in {
64 defm PCALL_INDIRECT_#vt : I<(outs V128:$dst),
65 (ins I32:$callee, variable_ops),
66 (outs), (ins I32:$callee),
68 (WebAssemblycall1 I32:$callee))],
69 "PSEUDO CALL INDIRECT\t$callee",
70 "PSEUDO CALL INDIRECT\t$callee">,
71 Requires<[HasSIMD128]>;
72 } // isCodeGenOnly = 1
74 defm CALL_INDIRECT_#vt : I<(outs V128:$dst),
75 (ins TypeIndex:$type, i32imm:$flags, variable_ops),
76 (outs), (ins TypeIndex:$type, i32imm:$flags),
78 !strconcat(prefix, "call_indirect\t$dst"),
79 !strconcat(prefix, "call_indirect\t$type"),
81 Requires<[HasSIMD128]>;
84 let Uses = [SP32, SP64], isCall = 1 in {
85 defm "" : CALL<I32, "i32.">;
86 defm "" : CALL<I64, "i64.">;
87 defm "" : CALL<F32, "f32.">;
88 defm "" : CALL<F64, "f64.">;
89 defm "" : CALL<EXCEPT_REF, "except_ref.">;
90 defm "" : SIMD_CALL<v16i8, "v128.">;
91 defm "" : SIMD_CALL<v8i16, "v128.">;
92 defm "" : SIMD_CALL<v4i32, "v128.">;
93 defm "" : SIMD_CALL<v2i64, "v128.">;
94 defm "" : SIMD_CALL<v4f32, "v128.">;
95 defm "" : SIMD_CALL<v2f64, "v128.">;
97 defm CALL_VOID : I<(outs), (ins function32_op:$callee, variable_ops),
98 (outs), (ins function32_op:$callee),
99 [(WebAssemblycall0 (i32 imm:$callee))],
100 "call \t$callee", "call\t$callee", 0x10>;
102 let isCodeGenOnly = 1 in {
103 defm PCALL_INDIRECT_VOID : I<(outs), (ins I32:$callee, variable_ops),
104 (outs), (ins I32:$callee),
105 [(WebAssemblycall0 I32:$callee)],
106 "PSEUDO CALL INDIRECT\t$callee",
107 "PSEUDO CALL INDIRECT\t$callee">;
108 } // isCodeGenOnly = 1
110 defm CALL_INDIRECT_VOID : I<(outs),
111 (ins TypeIndex:$type, i32imm:$flags,
113 (outs), (ins TypeIndex:$type, i32imm:$flags),
115 "call_indirect\t", "call_indirect\t$type",
117 } // Uses = [SP32,SP64], isCall = 1
119 // Patterns for matching a direct call to a global address.
120 def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
121 (CALL_I32 tglobaladdr:$callee)>;
122 def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
123 (CALL_I64 tglobaladdr:$callee)>;
124 def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
125 (CALL_F32 tglobaladdr:$callee)>;
126 def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
127 (CALL_F64 tglobaladdr:$callee)>;
128 def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
129 (CALL_v16i8 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
130 def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
131 (CALL_v8i16 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
132 def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
133 (CALL_v4i32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
134 def : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
135 (CALL_v2i64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
136 def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
137 (CALL_v4f32 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
138 def : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
139 (CALL_v2f64 tglobaladdr:$callee)>, Requires<[HasSIMD128]>;
141 (WebAssemblycall1 (WebAssemblywrapper tglobaladdr:$callee))),
142 (CALL_EXCEPT_REF tglobaladdr:$callee)>;
143 def : Pat<(WebAssemblycall0 (WebAssemblywrapper tglobaladdr:$callee)),
144 (CALL_VOID tglobaladdr:$callee)>;
146 // Patterns for matching a direct call to an external symbol.
147 def : Pat<(i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
148 (CALL_I32 texternalsym:$callee)>;
149 def : Pat<(i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
150 (CALL_I64 texternalsym:$callee)>;
151 def : Pat<(f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
152 (CALL_F32 texternalsym:$callee)>;
153 def : Pat<(f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
154 (CALL_F64 texternalsym:$callee)>;
155 def : Pat<(v16i8 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
156 (CALL_v16i8 texternalsym:$callee)>, Requires<[HasSIMD128]>;
157 def : Pat<(v8i16 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
158 (CALL_v8i16 texternalsym:$callee)>, Requires<[HasSIMD128]>;
159 def : Pat<(v4i32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
160 (CALL_v4i32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
161 def : Pat<(v2i64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
162 (CALL_v2i64 texternalsym:$callee)>, Requires<[HasSIMD128]>;
163 def : Pat<(v4f32 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
164 (CALL_v4f32 texternalsym:$callee)>, Requires<[HasSIMD128]>;
165 def : Pat<(v2f64 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
166 (CALL_v2f64 texternalsym:$callee)>, Requires<[HasSIMD128]>;
168 (WebAssemblycall1 (WebAssemblywrapper texternalsym:$callee))),
169 (CALL_EXCEPT_REF texternalsym:$callee)>;
170 def : Pat<(WebAssemblycall0 (WebAssemblywrapper texternalsym:$callee)),
171 (CALL_VOID texternalsym:$callee)>;