1 | // CodeGen/RuntimeLibcallSignatures.cpp - R.T. Lib. Call Signatures -*- C++ -*-- |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | /// |
9 | /// \file |
10 | /// This file contains signature information for runtime libcalls. |
11 | /// |
12 | /// CodeGen uses external symbols, which it refers to by name. The WebAssembly |
13 | /// target needs type information for all functions. This file contains a big |
14 | /// table providing type signatures for all runtime library functions that LLVM |
15 | /// uses. |
16 | /// |
17 | /// This is currently a fairly heavy-handed solution. |
18 | /// |
19 | //===----------------------------------------------------------------------===// |
20 | |
21 | #include "WebAssemblyRuntimeLibcallSignatures.h" |
22 | #include "WebAssemblySubtarget.h" |
23 | #include "WebAssemblyUtilities.h" |
24 | #include "llvm/CodeGen/RuntimeLibcallUtil.h" |
25 | |
26 | using namespace llvm; |
27 | |
28 | namespace { |
29 | |
30 | enum RuntimeLibcallSignature { |
31 | func, |
32 | f32_func_f32, |
33 | f32_func_f64, |
34 | f32_func_i32, |
35 | f32_func_i64, |
36 | f32_func_i16, |
37 | f64_func_f32, |
38 | f64_func_f64, |
39 | f64_func_i32, |
40 | f64_func_i64, |
41 | i32_func_f32, |
42 | i32_func_f64, |
43 | i32_func_i32, |
44 | i64_func_f32, |
45 | i64_func_f64, |
46 | i64_func_i64, |
47 | f32_func_f32_f32, |
48 | f32_func_f32_i32, |
49 | f32_func_i64_i64, |
50 | f64_func_f64_f64, |
51 | f64_func_f64_i32, |
52 | f64_func_i64_i64, |
53 | i16_func_f32, |
54 | i16_func_f64, |
55 | i16_func_i64_i64, |
56 | i8_func_i8_i8, |
57 | func_f32_iPTR_iPTR, |
58 | func_f64_iPTR_iPTR, |
59 | i16_func_i16_i16, |
60 | i32_func_f32_f32, |
61 | i32_func_f64_f64, |
62 | i32_func_i32_i32, |
63 | i32_func_i32_i32_iPTR, |
64 | i64_func_i64_i64, |
65 | i64_func_i64_i64_iPTR, |
66 | i64_i64_func_i32, |
67 | i64_i64_func_i64, |
68 | i64_i64_func_f32, |
69 | i64_i64_func_f64, |
70 | i16_i16_func_i16_i16, |
71 | i32_i32_func_i32_i32, |
72 | i64_i64_func_i64_i64, |
73 | i64_i64_func_i64_i64_i64_i64, |
74 | i64_i64_func_i64_i64_i64_i64_iPTR, |
75 | i64_i64_i64_i64_func_i64_i64_i64_i64, |
76 | i64_i64_func_i64_i64_i32, |
77 | i64_i64_func_i64_i64_i64_i64_i64_i64, |
78 | iPTR_func_i32, |
79 | iPTR_func_iPTR_i32_iPTR, |
80 | iPTR_func_iPTR_iPTR_iPTR, |
81 | f32_func_f32_f32_f32, |
82 | f64_func_f64_f64_f64, |
83 | func_i64_i64_iPTR_iPTR, |
84 | i32_func_i64_i64, |
85 | i32_func_i64_i64_i64_i64, |
86 | iPTR_func_f32, |
87 | iPTR_func_f64, |
88 | iPTR_func_i64_i64, |
89 | unsupported |
90 | }; |
91 | |
92 | struct RuntimeLibcallSignatureTable { |
93 | std::vector<RuntimeLibcallSignature> Table; |
94 | |
95 | // Any newly-added libcalls will be unsupported by default. |
96 | RuntimeLibcallSignatureTable() : Table(RTLIB::UNKNOWN_LIBCALL, unsupported) { |
97 | // Integer |
98 | Table[RTLIB::SHL_I16] = i16_func_i16_i16; |
99 | Table[RTLIB::SHL_I32] = i32_func_i32_i32; |
100 | Table[RTLIB::SHL_I64] = i64_func_i64_i64; |
101 | Table[RTLIB::SHL_I128] = i64_i64_func_i64_i64_i32; |
102 | Table[RTLIB::SRL_I16] = i16_func_i16_i16; |
103 | Table[RTLIB::SRL_I32] = i32_func_i32_i32; |
104 | Table[RTLIB::SRL_I64] = i64_func_i64_i64; |
105 | Table[RTLIB::SRL_I128] = i64_i64_func_i64_i64_i32; |
106 | Table[RTLIB::SRA_I16] = i16_func_i16_i16; |
107 | Table[RTLIB::SRA_I32] = i32_func_i32_i32; |
108 | Table[RTLIB::SRA_I64] = i64_func_i64_i64; |
109 | Table[RTLIB::SRA_I128] = i64_i64_func_i64_i64_i32; |
110 | Table[RTLIB::MUL_I8] = i8_func_i8_i8; |
111 | Table[RTLIB::MUL_I16] = i16_func_i16_i16; |
112 | Table[RTLIB::MUL_I32] = i32_func_i32_i32; |
113 | Table[RTLIB::MUL_I64] = i64_func_i64_i64; |
114 | Table[RTLIB::MUL_I128] = i64_i64_func_i64_i64_i64_i64; |
115 | Table[RTLIB::MULO_I32] = i32_func_i32_i32_iPTR; |
116 | Table[RTLIB::MULO_I64] = i64_func_i64_i64_iPTR; |
117 | Table[RTLIB::MULO_I128] = i64_i64_func_i64_i64_i64_i64_iPTR; |
118 | Table[RTLIB::SDIV_I8] = i8_func_i8_i8; |
119 | Table[RTLIB::SDIV_I16] = i16_func_i16_i16; |
120 | Table[RTLIB::SDIV_I32] = i32_func_i32_i32; |
121 | Table[RTLIB::SDIV_I64] = i64_func_i64_i64; |
122 | Table[RTLIB::SDIV_I128] = i64_i64_func_i64_i64_i64_i64; |
123 | Table[RTLIB::UDIV_I8] = i8_func_i8_i8; |
124 | Table[RTLIB::UDIV_I16] = i16_func_i16_i16; |
125 | Table[RTLIB::UDIV_I32] = i32_func_i32_i32; |
126 | Table[RTLIB::UDIV_I64] = i64_func_i64_i64; |
127 | Table[RTLIB::UDIV_I128] = i64_i64_func_i64_i64_i64_i64; |
128 | Table[RTLIB::SREM_I8] = i8_func_i8_i8; |
129 | Table[RTLIB::SREM_I16] = i16_func_i16_i16; |
130 | Table[RTLIB::SREM_I32] = i32_func_i32_i32; |
131 | Table[RTLIB::SREM_I64] = i64_func_i64_i64; |
132 | Table[RTLIB::SREM_I128] = i64_i64_func_i64_i64_i64_i64; |
133 | Table[RTLIB::UREM_I8] = i8_func_i8_i8; |
134 | Table[RTLIB::UREM_I16] = i16_func_i16_i16; |
135 | Table[RTLIB::UREM_I32] = i32_func_i32_i32; |
136 | Table[RTLIB::UREM_I64] = i64_func_i64_i64; |
137 | Table[RTLIB::UREM_I128] = i64_i64_func_i64_i64_i64_i64; |
138 | Table[RTLIB::SDIVREM_I8] = i8_func_i8_i8; |
139 | Table[RTLIB::SDIVREM_I16] = i16_i16_func_i16_i16; |
140 | Table[RTLIB::SDIVREM_I32] = i32_i32_func_i32_i32; |
141 | Table[RTLIB::SDIVREM_I64] = i64_func_i64_i64; |
142 | Table[RTLIB::SDIVREM_I128] = i64_i64_i64_i64_func_i64_i64_i64_i64; |
143 | Table[RTLIB::UDIVREM_I8] = i8_func_i8_i8; |
144 | Table[RTLIB::UDIVREM_I16] = i16_i16_func_i16_i16; |
145 | Table[RTLIB::UDIVREM_I32] = i32_i32_func_i32_i32; |
146 | Table[RTLIB::UDIVREM_I64] = i64_i64_func_i64_i64; |
147 | Table[RTLIB::UDIVREM_I128] = i64_i64_i64_i64_func_i64_i64_i64_i64; |
148 | Table[RTLIB::NEG_I32] = i32_func_i32; |
149 | Table[RTLIB::NEG_I64] = i64_func_i64; |
150 | |
151 | // Floating-point. |
152 | // All F80 and PPCF128 routines are unsupported. |
153 | Table[RTLIB::ADD_F32] = f32_func_f32_f32; |
154 | Table[RTLIB::ADD_F64] = f64_func_f64_f64; |
155 | Table[RTLIB::ADD_F128] = i64_i64_func_i64_i64_i64_i64; |
156 | Table[RTLIB::SUB_F32] = f32_func_f32_f32; |
157 | Table[RTLIB::SUB_F64] = f64_func_f64_f64; |
158 | Table[RTLIB::SUB_F128] = i64_i64_func_i64_i64_i64_i64; |
159 | Table[RTLIB::MUL_F32] = f32_func_f32_f32; |
160 | Table[RTLIB::MUL_F64] = f64_func_f64_f64; |
161 | Table[RTLIB::MUL_F128] = i64_i64_func_i64_i64_i64_i64; |
162 | Table[RTLIB::DIV_F32] = f32_func_f32_f32; |
163 | Table[RTLIB::DIV_F64] = f64_func_f64_f64; |
164 | Table[RTLIB::DIV_F128] = i64_i64_func_i64_i64_i64_i64; |
165 | Table[RTLIB::REM_F32] = f32_func_f32_f32; |
166 | Table[RTLIB::REM_F64] = f64_func_f64_f64; |
167 | Table[RTLIB::REM_F128] = i64_i64_func_i64_i64_i64_i64; |
168 | Table[RTLIB::FMA_F32] = f32_func_f32_f32_f32; |
169 | Table[RTLIB::FMA_F64] = f64_func_f64_f64_f64; |
170 | Table[RTLIB::FMA_F128] = i64_i64_func_i64_i64_i64_i64_i64_i64; |
171 | Table[RTLIB::POWI_F32] = f32_func_f32_i32; |
172 | Table[RTLIB::POWI_F64] = f64_func_f64_i32; |
173 | Table[RTLIB::POWI_F128] = i64_i64_func_i64_i64_i32; |
174 | Table[RTLIB::SQRT_F32] = f32_func_f32; |
175 | Table[RTLIB::SQRT_F64] = f64_func_f64; |
176 | Table[RTLIB::SQRT_F128] = i64_i64_func_i64_i64; |
177 | Table[RTLIB::CBRT_F32] = f32_func_f32; |
178 | Table[RTLIB::CBRT_F64] = f64_func_f64; |
179 | Table[RTLIB::CBRT_F128] = i64_i64_func_i64_i64; |
180 | Table[RTLIB::LOG_F32] = f32_func_f32; |
181 | Table[RTLIB::LOG_F64] = f64_func_f64; |
182 | Table[RTLIB::LOG_F128] = i64_i64_func_i64_i64; |
183 | Table[RTLIB::LOG2_F32] = f32_func_f32; |
184 | Table[RTLIB::LOG2_F64] = f64_func_f64; |
185 | Table[RTLIB::LOG2_F128] = i64_i64_func_i64_i64; |
186 | Table[RTLIB::LOG10_F32] = f32_func_f32; |
187 | Table[RTLIB::LOG10_F64] = f64_func_f64; |
188 | Table[RTLIB::LOG10_F128] = i64_i64_func_i64_i64; |
189 | Table[RTLIB::EXP_F32] = f32_func_f32; |
190 | Table[RTLIB::EXP_F64] = f64_func_f64; |
191 | Table[RTLIB::EXP_F128] = i64_i64_func_i64_i64; |
192 | Table[RTLIB::EXP2_F32] = f32_func_f32; |
193 | Table[RTLIB::EXP2_F64] = f64_func_f64; |
194 | Table[RTLIB::EXP2_F128] = i64_i64_func_i64_i64; |
195 | Table[RTLIB::EXP10_F32] = f32_func_f32; |
196 | Table[RTLIB::EXP10_F64] = f64_func_f64; |
197 | Table[RTLIB::EXP10_F128] = i64_i64_func_i64_i64; |
198 | Table[RTLIB::SIN_F32] = f32_func_f32; |
199 | Table[RTLIB::SIN_F64] = f64_func_f64; |
200 | Table[RTLIB::SIN_F128] = i64_i64_func_i64_i64; |
201 | Table[RTLIB::COS_F32] = f32_func_f32; |
202 | Table[RTLIB::COS_F64] = f64_func_f64; |
203 | Table[RTLIB::COS_F128] = i64_i64_func_i64_i64; |
204 | Table[RTLIB::TAN_F32] = f32_func_f32; |
205 | Table[RTLIB::TAN_F64] = f64_func_f64; |
206 | Table[RTLIB::TAN_F128] = i64_i64_func_i64_i64; |
207 | Table[RTLIB::ASIN_F32] = f32_func_f32; |
208 | Table[RTLIB::ASIN_F64] = f64_func_f64; |
209 | Table[RTLIB::ASIN_F128] = i64_i64_func_i64_i64; |
210 | Table[RTLIB::ACOS_F32] = f32_func_f32; |
211 | Table[RTLIB::ACOS_F64] = f64_func_f64; |
212 | Table[RTLIB::ACOS_F128] = i64_i64_func_i64_i64; |
213 | Table[RTLIB::ATAN_F32] = f32_func_f32; |
214 | Table[RTLIB::ATAN_F64] = f64_func_f64; |
215 | Table[RTLIB::ATAN_F128] = i64_i64_func_i64_i64; |
216 | Table[RTLIB::SINH_F32] = f32_func_f32; |
217 | Table[RTLIB::SINH_F64] = f64_func_f64; |
218 | Table[RTLIB::SINH_F128] = i64_i64_func_i64_i64; |
219 | Table[RTLIB::COSH_F32] = f32_func_f32; |
220 | Table[RTLIB::COSH_F64] = f64_func_f64; |
221 | Table[RTLIB::COSH_F128] = i64_i64_func_i64_i64; |
222 | Table[RTLIB::TANH_F32] = f32_func_f32; |
223 | Table[RTLIB::TANH_F64] = f64_func_f64; |
224 | Table[RTLIB::TANH_F128] = i64_i64_func_i64_i64; |
225 | Table[RTLIB::SINCOS_F32] = func_f32_iPTR_iPTR; |
226 | Table[RTLIB::SINCOS_F64] = func_f64_iPTR_iPTR; |
227 | Table[RTLIB::SINCOS_F128] = func_i64_i64_iPTR_iPTR; |
228 | Table[RTLIB::POW_F32] = f32_func_f32_f32; |
229 | Table[RTLIB::POW_F64] = f64_func_f64_f64; |
230 | Table[RTLIB::POW_F128] = i64_i64_func_i64_i64_i64_i64; |
231 | Table[RTLIB::CEIL_F32] = f32_func_f32; |
232 | Table[RTLIB::CEIL_F64] = f64_func_f64; |
233 | Table[RTLIB::CEIL_F128] = i64_i64_func_i64_i64; |
234 | Table[RTLIB::TRUNC_F32] = f32_func_f32; |
235 | Table[RTLIB::TRUNC_F64] = f64_func_f64; |
236 | Table[RTLIB::TRUNC_F128] = i64_i64_func_i64_i64; |
237 | Table[RTLIB::RINT_F32] = f32_func_f32; |
238 | Table[RTLIB::RINT_F64] = f64_func_f64; |
239 | Table[RTLIB::RINT_F128] = i64_i64_func_i64_i64; |
240 | Table[RTLIB::NEARBYINT_F32] = f32_func_f32; |
241 | Table[RTLIB::NEARBYINT_F64] = f64_func_f64; |
242 | Table[RTLIB::NEARBYINT_F128] = i64_i64_func_i64_i64; |
243 | Table[RTLIB::ROUND_F32] = f32_func_f32; |
244 | Table[RTLIB::ROUND_F64] = f64_func_f64; |
245 | Table[RTLIB::ROUND_F128] = i64_i64_func_i64_i64; |
246 | Table[RTLIB::ROUNDEVEN_F32] = f32_func_f32; |
247 | Table[RTLIB::ROUNDEVEN_F64] = f64_func_f64; |
248 | Table[RTLIB::ROUNDEVEN_F128] = i64_i64_func_i64_i64; |
249 | Table[RTLIB::LROUND_F32] = iPTR_func_f32; |
250 | Table[RTLIB::LROUND_F64] = iPTR_func_f64; |
251 | Table[RTLIB::LROUND_F128] = iPTR_func_i64_i64; |
252 | Table[RTLIB::LLROUND_F32] = i64_func_f32; |
253 | Table[RTLIB::LLROUND_F64] = i64_func_f64; |
254 | Table[RTLIB::LLROUND_F128] = i64_func_i64_i64; |
255 | Table[RTLIB::LRINT_F32] = iPTR_func_f32; |
256 | Table[RTLIB::LRINT_F64] = iPTR_func_f64; |
257 | Table[RTLIB::LRINT_F128] = iPTR_func_i64_i64; |
258 | Table[RTLIB::LLRINT_F32] = i64_func_f32; |
259 | Table[RTLIB::LLRINT_F64] = i64_func_f64; |
260 | Table[RTLIB::LLRINT_F128] = i64_func_i64_i64; |
261 | Table[RTLIB::FLOOR_F32] = f32_func_f32; |
262 | Table[RTLIB::FLOOR_F64] = f64_func_f64; |
263 | Table[RTLIB::FLOOR_F128] = i64_i64_func_i64_i64; |
264 | Table[RTLIB::COPYSIGN_F32] = f32_func_f32_f32; |
265 | Table[RTLIB::COPYSIGN_F64] = f64_func_f64_f64; |
266 | Table[RTLIB::COPYSIGN_F128] = i64_i64_func_i64_i64_i64_i64; |
267 | Table[RTLIB::FMIN_F32] = f32_func_f32_f32; |
268 | Table[RTLIB::FMIN_F64] = f64_func_f64_f64; |
269 | Table[RTLIB::FMIN_F128] = i64_i64_func_i64_i64_i64_i64; |
270 | Table[RTLIB::FMAX_F32] = f32_func_f32_f32; |
271 | Table[RTLIB::FMAX_F64] = f64_func_f64_f64; |
272 | Table[RTLIB::FMAX_F128] = i64_i64_func_i64_i64_i64_i64; |
273 | Table[RTLIB::LDEXP_F32] = f32_func_f32_i32; |
274 | Table[RTLIB::LDEXP_F64] = f64_func_f64_i32; |
275 | Table[RTLIB::LDEXP_F128] = i64_i64_func_i64_i64_i32; |
276 | Table[RTLIB::FREXP_F32] = f32_func_f32_i32; |
277 | Table[RTLIB::FREXP_F64] = f64_func_f64_i32; |
278 | Table[RTLIB::FREXP_F128] = i64_i64_func_i64_i64_i32; |
279 | |
280 | // Conversion |
281 | // All F80 and PPCF128 routines are unsupported. |
282 | Table[RTLIB::FPEXT_F64_F128] = i64_i64_func_f64; |
283 | Table[RTLIB::FPEXT_F32_F128] = i64_i64_func_f32; |
284 | Table[RTLIB::FPEXT_F32_F64] = f64_func_f32; |
285 | Table[RTLIB::FPEXT_F16_F32] = f32_func_i16; |
286 | Table[RTLIB::FPROUND_F32_F16] = i16_func_f32; |
287 | Table[RTLIB::FPROUND_F64_F16] = i16_func_f64; |
288 | Table[RTLIB::FPROUND_F64_F32] = f32_func_f64; |
289 | Table[RTLIB::FPROUND_F128_F16] = i16_func_i64_i64; |
290 | Table[RTLIB::FPROUND_F128_F32] = f32_func_i64_i64; |
291 | Table[RTLIB::FPROUND_F128_F64] = f64_func_i64_i64; |
292 | Table[RTLIB::FPTOSINT_F32_I32] = i32_func_f32; |
293 | Table[RTLIB::FPTOSINT_F32_I64] = i64_func_f32; |
294 | Table[RTLIB::FPTOSINT_F32_I128] = i64_i64_func_f32; |
295 | Table[RTLIB::FPTOSINT_F64_I32] = i32_func_f64; |
296 | Table[RTLIB::FPTOSINT_F64_I64] = i64_func_f64; |
297 | Table[RTLIB::FPTOSINT_F64_I128] = i64_i64_func_f64; |
298 | Table[RTLIB::FPTOSINT_F128_I32] = i32_func_i64_i64; |
299 | Table[RTLIB::FPTOSINT_F128_I64] = i64_func_i64_i64; |
300 | Table[RTLIB::FPTOSINT_F128_I128] = i64_i64_func_i64_i64; |
301 | Table[RTLIB::FPTOUINT_F32_I32] = i32_func_f32; |
302 | Table[RTLIB::FPTOUINT_F32_I64] = i64_func_f32; |
303 | Table[RTLIB::FPTOUINT_F32_I128] = i64_i64_func_f32; |
304 | Table[RTLIB::FPTOUINT_F64_I32] = i32_func_f64; |
305 | Table[RTLIB::FPTOUINT_F64_I64] = i64_func_f64; |
306 | Table[RTLIB::FPTOUINT_F64_I128] = i64_i64_func_f64; |
307 | Table[RTLIB::FPTOUINT_F128_I32] = i32_func_i64_i64; |
308 | Table[RTLIB::FPTOUINT_F128_I64] = i64_func_i64_i64; |
309 | Table[RTLIB::FPTOUINT_F128_I128] = i64_i64_func_i64_i64; |
310 | Table[RTLIB::SINTTOFP_I32_F32] = f32_func_i32; |
311 | Table[RTLIB::SINTTOFP_I32_F64] = f64_func_i32; |
312 | Table[RTLIB::SINTTOFP_I32_F128] = i64_i64_func_i32; |
313 | Table[RTLIB::SINTTOFP_I64_F32] = f32_func_i64; |
314 | Table[RTLIB::SINTTOFP_I64_F64] = f64_func_i64; |
315 | Table[RTLIB::SINTTOFP_I64_F128] = i64_i64_func_i64; |
316 | Table[RTLIB::SINTTOFP_I128_F32] = f32_func_i64_i64; |
317 | Table[RTLIB::SINTTOFP_I128_F64] = f64_func_i64_i64; |
318 | Table[RTLIB::SINTTOFP_I128_F128] = i64_i64_func_i64_i64; |
319 | Table[RTLIB::UINTTOFP_I32_F32] = f32_func_i32; |
320 | Table[RTLIB::UINTTOFP_I32_F64] = f64_func_i64; |
321 | Table[RTLIB::UINTTOFP_I32_F128] = i64_i64_func_i32; |
322 | Table[RTLIB::UINTTOFP_I64_F32] = f32_func_i64; |
323 | Table[RTLIB::UINTTOFP_I64_F64] = f64_func_i64; |
324 | Table[RTLIB::UINTTOFP_I64_F128] = i64_i64_func_i64; |
325 | Table[RTLIB::UINTTOFP_I128_F32] = f32_func_i64_i64; |
326 | Table[RTLIB::UINTTOFP_I128_F64] = f64_func_i64_i64; |
327 | Table[RTLIB::UINTTOFP_I128_F128] = i64_i64_func_i64_i64; |
328 | |
329 | // Comparison |
330 | // ALl F80 and PPCF128 routines are unsupported. |
331 | Table[RTLIB::OEQ_F32] = i32_func_f32_f32; |
332 | Table[RTLIB::OEQ_F64] = i32_func_f64_f64; |
333 | Table[RTLIB::OEQ_F128] = i32_func_i64_i64_i64_i64; |
334 | Table[RTLIB::UNE_F32] = i32_func_f32_f32; |
335 | Table[RTLIB::UNE_F64] = i32_func_f64_f64; |
336 | Table[RTLIB::UNE_F128] = i32_func_i64_i64_i64_i64; |
337 | Table[RTLIB::OGE_F32] = i32_func_f32_f32; |
338 | Table[RTLIB::OGE_F64] = i32_func_f64_f64; |
339 | Table[RTLIB::OGE_F128] = i32_func_i64_i64_i64_i64; |
340 | Table[RTLIB::OLT_F32] = i32_func_f32_f32; |
341 | Table[RTLIB::OLT_F64] = i32_func_f64_f64; |
342 | Table[RTLIB::OLT_F128] = i32_func_i64_i64_i64_i64; |
343 | Table[RTLIB::OLE_F32] = i32_func_f32_f32; |
344 | Table[RTLIB::OLE_F64] = i32_func_f64_f64; |
345 | Table[RTLIB::OLE_F128] = i32_func_i64_i64_i64_i64; |
346 | Table[RTLIB::OGT_F32] = i32_func_f32_f32; |
347 | Table[RTLIB::OGT_F64] = i32_func_f64_f64; |
348 | Table[RTLIB::OGT_F128] = i32_func_i64_i64_i64_i64; |
349 | Table[RTLIB::UO_F32] = i32_func_f32_f32; |
350 | Table[RTLIB::UO_F64] = i32_func_f64_f64; |
351 | Table[RTLIB::UO_F128] = i32_func_i64_i64_i64_i64; |
352 | |
353 | // Memory |
354 | Table[RTLIB::MEMCPY] = iPTR_func_iPTR_iPTR_iPTR; |
355 | Table[RTLIB::MEMSET] = iPTR_func_iPTR_i32_iPTR; |
356 | Table[RTLIB::MEMMOVE] = iPTR_func_iPTR_iPTR_iPTR; |
357 | |
358 | // __stack_chk_fail |
359 | Table[RTLIB::STACKPROTECTOR_CHECK_FAIL] = func; |
360 | |
361 | // Return address handling |
362 | Table[RTLIB::RETURN_ADDRESS] = iPTR_func_i32; |
363 | |
364 | // Element-wise Atomic memory |
365 | // TODO: Fix these when we implement atomic support |
366 | Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_1] = unsupported; |
367 | Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_2] = unsupported; |
368 | Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_4] = unsupported; |
369 | Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_8] = unsupported; |
370 | Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_16] = unsupported; |
371 | Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_1] = unsupported; |
372 | Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_2] = unsupported; |
373 | Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_4] = unsupported; |
374 | Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_8] = unsupported; |
375 | Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_16] = unsupported; |
376 | |
377 | Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_1] = unsupported; |
378 | Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_2] = unsupported; |
379 | Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_4] = unsupported; |
380 | Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_8] = unsupported; |
381 | Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_16] = unsupported; |
382 | |
383 | // Atomic '__sync_*' libcalls. |
384 | // TODO: Fix these when we implement atomic support |
385 | Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_1] = unsupported; |
386 | Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_2] = unsupported; |
387 | Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_4] = unsupported; |
388 | Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_8] = unsupported; |
389 | Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_16] = unsupported; |
390 | Table[RTLIB::SYNC_LOCK_TEST_AND_SET_1] = unsupported; |
391 | Table[RTLIB::SYNC_LOCK_TEST_AND_SET_2] = unsupported; |
392 | Table[RTLIB::SYNC_LOCK_TEST_AND_SET_4] = unsupported; |
393 | Table[RTLIB::SYNC_LOCK_TEST_AND_SET_8] = unsupported; |
394 | Table[RTLIB::SYNC_LOCK_TEST_AND_SET_16] = unsupported; |
395 | Table[RTLIB::SYNC_FETCH_AND_ADD_1] = unsupported; |
396 | Table[RTLIB::SYNC_FETCH_AND_ADD_2] = unsupported; |
397 | Table[RTLIB::SYNC_FETCH_AND_ADD_4] = unsupported; |
398 | Table[RTLIB::SYNC_FETCH_AND_ADD_8] = unsupported; |
399 | Table[RTLIB::SYNC_FETCH_AND_ADD_16] = unsupported; |
400 | Table[RTLIB::SYNC_FETCH_AND_SUB_1] = unsupported; |
401 | Table[RTLIB::SYNC_FETCH_AND_SUB_2] = unsupported; |
402 | Table[RTLIB::SYNC_FETCH_AND_SUB_4] = unsupported; |
403 | Table[RTLIB::SYNC_FETCH_AND_SUB_8] = unsupported; |
404 | Table[RTLIB::SYNC_FETCH_AND_SUB_16] = unsupported; |
405 | Table[RTLIB::SYNC_FETCH_AND_AND_1] = unsupported; |
406 | Table[RTLIB::SYNC_FETCH_AND_AND_2] = unsupported; |
407 | Table[RTLIB::SYNC_FETCH_AND_AND_4] = unsupported; |
408 | Table[RTLIB::SYNC_FETCH_AND_AND_8] = unsupported; |
409 | Table[RTLIB::SYNC_FETCH_AND_AND_16] = unsupported; |
410 | Table[RTLIB::SYNC_FETCH_AND_OR_1] = unsupported; |
411 | Table[RTLIB::SYNC_FETCH_AND_OR_2] = unsupported; |
412 | Table[RTLIB::SYNC_FETCH_AND_OR_4] = unsupported; |
413 | Table[RTLIB::SYNC_FETCH_AND_OR_8] = unsupported; |
414 | Table[RTLIB::SYNC_FETCH_AND_OR_16] = unsupported; |
415 | Table[RTLIB::SYNC_FETCH_AND_XOR_1] = unsupported; |
416 | Table[RTLIB::SYNC_FETCH_AND_XOR_2] = unsupported; |
417 | Table[RTLIB::SYNC_FETCH_AND_XOR_4] = unsupported; |
418 | Table[RTLIB::SYNC_FETCH_AND_XOR_8] = unsupported; |
419 | Table[RTLIB::SYNC_FETCH_AND_XOR_16] = unsupported; |
420 | Table[RTLIB::SYNC_FETCH_AND_NAND_1] = unsupported; |
421 | Table[RTLIB::SYNC_FETCH_AND_NAND_2] = unsupported; |
422 | Table[RTLIB::SYNC_FETCH_AND_NAND_4] = unsupported; |
423 | Table[RTLIB::SYNC_FETCH_AND_NAND_8] = unsupported; |
424 | Table[RTLIB::SYNC_FETCH_AND_NAND_16] = unsupported; |
425 | Table[RTLIB::SYNC_FETCH_AND_MAX_1] = unsupported; |
426 | Table[RTLIB::SYNC_FETCH_AND_MAX_2] = unsupported; |
427 | Table[RTLIB::SYNC_FETCH_AND_MAX_4] = unsupported; |
428 | Table[RTLIB::SYNC_FETCH_AND_MAX_8] = unsupported; |
429 | Table[RTLIB::SYNC_FETCH_AND_MAX_16] = unsupported; |
430 | Table[RTLIB::SYNC_FETCH_AND_UMAX_1] = unsupported; |
431 | Table[RTLIB::SYNC_FETCH_AND_UMAX_2] = unsupported; |
432 | Table[RTLIB::SYNC_FETCH_AND_UMAX_4] = unsupported; |
433 | Table[RTLIB::SYNC_FETCH_AND_UMAX_8] = unsupported; |
434 | Table[RTLIB::SYNC_FETCH_AND_UMAX_16] = unsupported; |
435 | Table[RTLIB::SYNC_FETCH_AND_MIN_1] = unsupported; |
436 | Table[RTLIB::SYNC_FETCH_AND_MIN_2] = unsupported; |
437 | Table[RTLIB::SYNC_FETCH_AND_MIN_4] = unsupported; |
438 | Table[RTLIB::SYNC_FETCH_AND_MIN_8] = unsupported; |
439 | Table[RTLIB::SYNC_FETCH_AND_MIN_16] = unsupported; |
440 | Table[RTLIB::SYNC_FETCH_AND_UMIN_1] = unsupported; |
441 | Table[RTLIB::SYNC_FETCH_AND_UMIN_2] = unsupported; |
442 | Table[RTLIB::SYNC_FETCH_AND_UMIN_4] = unsupported; |
443 | Table[RTLIB::SYNC_FETCH_AND_UMIN_8] = unsupported; |
444 | Table[RTLIB::SYNC_FETCH_AND_UMIN_16] = unsupported; |
445 | |
446 | // Atomic '__atomic_*' libcalls. |
447 | // TODO: Fix these when we implement atomic support |
448 | Table[RTLIB::ATOMIC_LOAD] = unsupported; |
449 | Table[RTLIB::ATOMIC_LOAD_1] = unsupported; |
450 | Table[RTLIB::ATOMIC_LOAD_2] = unsupported; |
451 | Table[RTLIB::ATOMIC_LOAD_4] = unsupported; |
452 | Table[RTLIB::ATOMIC_LOAD_8] = unsupported; |
453 | Table[RTLIB::ATOMIC_LOAD_16] = unsupported; |
454 | |
455 | Table[RTLIB::ATOMIC_STORE] = unsupported; |
456 | Table[RTLIB::ATOMIC_STORE_1] = unsupported; |
457 | Table[RTLIB::ATOMIC_STORE_2] = unsupported; |
458 | Table[RTLIB::ATOMIC_STORE_4] = unsupported; |
459 | Table[RTLIB::ATOMIC_STORE_8] = unsupported; |
460 | Table[RTLIB::ATOMIC_STORE_16] = unsupported; |
461 | |
462 | Table[RTLIB::ATOMIC_EXCHANGE] = unsupported; |
463 | Table[RTLIB::ATOMIC_EXCHANGE_1] = unsupported; |
464 | Table[RTLIB::ATOMIC_EXCHANGE_2] = unsupported; |
465 | Table[RTLIB::ATOMIC_EXCHANGE_4] = unsupported; |
466 | Table[RTLIB::ATOMIC_EXCHANGE_8] = unsupported; |
467 | Table[RTLIB::ATOMIC_EXCHANGE_16] = unsupported; |
468 | |
469 | Table[RTLIB::ATOMIC_COMPARE_EXCHANGE] = unsupported; |
470 | Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_1] = unsupported; |
471 | Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_2] = unsupported; |
472 | Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_4] = unsupported; |
473 | Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_8] = unsupported; |
474 | Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_16] = unsupported; |
475 | |
476 | Table[RTLIB::ATOMIC_FETCH_ADD_1] = unsupported; |
477 | Table[RTLIB::ATOMIC_FETCH_ADD_2] = unsupported; |
478 | Table[RTLIB::ATOMIC_FETCH_ADD_4] = unsupported; |
479 | Table[RTLIB::ATOMIC_FETCH_ADD_8] = unsupported; |
480 | Table[RTLIB::ATOMIC_FETCH_ADD_16] = unsupported; |
481 | |
482 | Table[RTLIB::ATOMIC_FETCH_SUB_1] = unsupported; |
483 | Table[RTLIB::ATOMIC_FETCH_SUB_2] = unsupported; |
484 | Table[RTLIB::ATOMIC_FETCH_SUB_4] = unsupported; |
485 | Table[RTLIB::ATOMIC_FETCH_SUB_8] = unsupported; |
486 | Table[RTLIB::ATOMIC_FETCH_SUB_16] = unsupported; |
487 | |
488 | Table[RTLIB::ATOMIC_FETCH_AND_1] = unsupported; |
489 | Table[RTLIB::ATOMIC_FETCH_AND_2] = unsupported; |
490 | Table[RTLIB::ATOMIC_FETCH_AND_4] = unsupported; |
491 | Table[RTLIB::ATOMIC_FETCH_AND_8] = unsupported; |
492 | Table[RTLIB::ATOMIC_FETCH_AND_16] = unsupported; |
493 | |
494 | Table[RTLIB::ATOMIC_FETCH_OR_1] = unsupported; |
495 | Table[RTLIB::ATOMIC_FETCH_OR_2] = unsupported; |
496 | Table[RTLIB::ATOMIC_FETCH_OR_4] = unsupported; |
497 | Table[RTLIB::ATOMIC_FETCH_OR_8] = unsupported; |
498 | Table[RTLIB::ATOMIC_FETCH_OR_16] = unsupported; |
499 | |
500 | Table[RTLIB::ATOMIC_FETCH_XOR_1] = unsupported; |
501 | Table[RTLIB::ATOMIC_FETCH_XOR_2] = unsupported; |
502 | Table[RTLIB::ATOMIC_FETCH_XOR_4] = unsupported; |
503 | Table[RTLIB::ATOMIC_FETCH_XOR_8] = unsupported; |
504 | Table[RTLIB::ATOMIC_FETCH_XOR_16] = unsupported; |
505 | |
506 | Table[RTLIB::ATOMIC_FETCH_NAND_1] = unsupported; |
507 | Table[RTLIB::ATOMIC_FETCH_NAND_2] = unsupported; |
508 | Table[RTLIB::ATOMIC_FETCH_NAND_4] = unsupported; |
509 | Table[RTLIB::ATOMIC_FETCH_NAND_8] = unsupported; |
510 | Table[RTLIB::ATOMIC_FETCH_NAND_16] = unsupported; |
511 | } |
512 | }; |
513 | |
514 | RuntimeLibcallSignatureTable &getRuntimeLibcallSignatures() { |
515 | static RuntimeLibcallSignatureTable RuntimeLibcallSignatures; |
516 | return RuntimeLibcallSignatures; |
517 | } |
518 | |
519 | // Maps libcall names to their RTLIB::Libcall number. Builds the map in a |
520 | // constructor for use with a static variable |
521 | struct StaticLibcallNameMap { |
522 | StringMap<RTLIB::Libcall> Map; |
523 | StaticLibcallNameMap() { |
524 | static const std::pair<const char *, RTLIB::Libcall> NameLibcalls[] = { |
525 | #define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code}, |
526 | #include "llvm/IR/RuntimeLibcalls.def" |
527 | #undef HANDLE_LIBCALL |
528 | }; |
529 | for (const auto &NameLibcall : NameLibcalls) { |
530 | if (NameLibcall.first != nullptr && |
531 | getRuntimeLibcallSignatures().Table[NameLibcall.second] != |
532 | unsupported) { |
533 | assert(!Map.contains(NameLibcall.first) && |
534 | "duplicate libcall names in name map" ); |
535 | Map[NameLibcall.first] = NameLibcall.second; |
536 | } |
537 | } |
538 | // Override the __gnu_f2h_ieee/__gnu_h2f_ieee names so that the f32 name is |
539 | // consistent with the f64 and f128 names. |
540 | Map["__extendhfsf2" ] = RTLIB::FPEXT_F16_F32; |
541 | Map["__truncsfhf2" ] = RTLIB::FPROUND_F32_F16; |
542 | |
543 | Map["emscripten_return_address" ] = RTLIB::RETURN_ADDRESS; |
544 | } |
545 | }; |
546 | |
547 | } // end anonymous namespace |
548 | |
549 | void WebAssembly::getLibcallSignature(const WebAssemblySubtarget &Subtarget, |
550 | RTLIB::Libcall LC, |
551 | SmallVectorImpl<wasm::ValType> &Rets, |
552 | SmallVectorImpl<wasm::ValType> &Params) { |
553 | assert(Rets.empty()); |
554 | assert(Params.empty()); |
555 | |
556 | wasm::ValType PtrTy = |
557 | Subtarget.hasAddr64() ? wasm::ValType::I64 : wasm::ValType::I32; |
558 | |
559 | auto &Table = getRuntimeLibcallSignatures().Table; |
560 | switch (Table[LC]) { |
561 | case func: |
562 | break; |
563 | case f32_func_f32: |
564 | Rets.push_back(Elt: wasm::ValType::F32); |
565 | Params.push_back(Elt: wasm::ValType::F32); |
566 | break; |
567 | case f32_func_f64: |
568 | Rets.push_back(Elt: wasm::ValType::F32); |
569 | Params.push_back(Elt: wasm::ValType::F64); |
570 | break; |
571 | case f32_func_i32: |
572 | Rets.push_back(Elt: wasm::ValType::F32); |
573 | Params.push_back(Elt: wasm::ValType::I32); |
574 | break; |
575 | case f32_func_i64: |
576 | Rets.push_back(Elt: wasm::ValType::F32); |
577 | Params.push_back(Elt: wasm::ValType::I64); |
578 | break; |
579 | case f32_func_i16: |
580 | Rets.push_back(Elt: wasm::ValType::F32); |
581 | Params.push_back(Elt: wasm::ValType::I32); |
582 | break; |
583 | case f64_func_f32: |
584 | Rets.push_back(Elt: wasm::ValType::F64); |
585 | Params.push_back(Elt: wasm::ValType::F32); |
586 | break; |
587 | case f64_func_f64: |
588 | Rets.push_back(Elt: wasm::ValType::F64); |
589 | Params.push_back(Elt: wasm::ValType::F64); |
590 | break; |
591 | case f64_func_i32: |
592 | Rets.push_back(Elt: wasm::ValType::F64); |
593 | Params.push_back(Elt: wasm::ValType::I32); |
594 | break; |
595 | case f64_func_i64: |
596 | Rets.push_back(Elt: wasm::ValType::F64); |
597 | Params.push_back(Elt: wasm::ValType::I64); |
598 | break; |
599 | case i32_func_f32: |
600 | Rets.push_back(Elt: wasm::ValType::I32); |
601 | Params.push_back(Elt: wasm::ValType::F32); |
602 | break; |
603 | case i32_func_f64: |
604 | Rets.push_back(Elt: wasm::ValType::I32); |
605 | Params.push_back(Elt: wasm::ValType::F64); |
606 | break; |
607 | case i32_func_i32: |
608 | Rets.push_back(Elt: wasm::ValType::I32); |
609 | Params.push_back(Elt: wasm::ValType::I32); |
610 | break; |
611 | case i64_func_f32: |
612 | Rets.push_back(Elt: wasm::ValType::I64); |
613 | Params.push_back(Elt: wasm::ValType::F32); |
614 | break; |
615 | case i64_func_f64: |
616 | Rets.push_back(Elt: wasm::ValType::I64); |
617 | Params.push_back(Elt: wasm::ValType::F64); |
618 | break; |
619 | case i64_func_i64: |
620 | Rets.push_back(Elt: wasm::ValType::I64); |
621 | Params.push_back(Elt: wasm::ValType::I64); |
622 | break; |
623 | case f32_func_f32_f32: |
624 | Rets.push_back(Elt: wasm::ValType::F32); |
625 | Params.push_back(Elt: wasm::ValType::F32); |
626 | Params.push_back(Elt: wasm::ValType::F32); |
627 | break; |
628 | case f32_func_f32_i32: |
629 | Rets.push_back(Elt: wasm::ValType::F32); |
630 | Params.push_back(Elt: wasm::ValType::F32); |
631 | Params.push_back(Elt: wasm::ValType::I32); |
632 | break; |
633 | case f32_func_i64_i64: |
634 | Rets.push_back(Elt: wasm::ValType::F32); |
635 | Params.push_back(Elt: wasm::ValType::I64); |
636 | Params.push_back(Elt: wasm::ValType::I64); |
637 | break; |
638 | case f64_func_f64_f64: |
639 | Rets.push_back(Elt: wasm::ValType::F64); |
640 | Params.push_back(Elt: wasm::ValType::F64); |
641 | Params.push_back(Elt: wasm::ValType::F64); |
642 | break; |
643 | case f64_func_f64_i32: |
644 | Rets.push_back(Elt: wasm::ValType::F64); |
645 | Params.push_back(Elt: wasm::ValType::F64); |
646 | Params.push_back(Elt: wasm::ValType::I32); |
647 | break; |
648 | case f64_func_i64_i64: |
649 | Rets.push_back(Elt: wasm::ValType::F64); |
650 | Params.push_back(Elt: wasm::ValType::I64); |
651 | Params.push_back(Elt: wasm::ValType::I64); |
652 | break; |
653 | case i16_func_f32: |
654 | Rets.push_back(Elt: wasm::ValType::I32); |
655 | Params.push_back(Elt: wasm::ValType::F32); |
656 | break; |
657 | case i16_func_f64: |
658 | Rets.push_back(Elt: wasm::ValType::I32); |
659 | Params.push_back(Elt: wasm::ValType::F64); |
660 | break; |
661 | case i16_func_i64_i64: |
662 | Rets.push_back(Elt: wasm::ValType::I32); |
663 | Params.push_back(Elt: wasm::ValType::I64); |
664 | Params.push_back(Elt: wasm::ValType::I64); |
665 | break; |
666 | case i8_func_i8_i8: |
667 | Rets.push_back(Elt: wasm::ValType::I32); |
668 | Params.push_back(Elt: wasm::ValType::I32); |
669 | Params.push_back(Elt: wasm::ValType::I32); |
670 | break; |
671 | case func_f32_iPTR_iPTR: |
672 | Params.push_back(Elt: wasm::ValType::F32); |
673 | Params.push_back(Elt: PtrTy); |
674 | Params.push_back(Elt: PtrTy); |
675 | break; |
676 | case func_f64_iPTR_iPTR: |
677 | Params.push_back(Elt: wasm::ValType::F64); |
678 | Params.push_back(Elt: PtrTy); |
679 | Params.push_back(Elt: PtrTy); |
680 | break; |
681 | case i16_func_i16_i16: |
682 | Rets.push_back(Elt: wasm::ValType::I32); |
683 | Params.push_back(Elt: wasm::ValType::I32); |
684 | Params.push_back(Elt: wasm::ValType::I32); |
685 | break; |
686 | case i32_func_f32_f32: |
687 | Rets.push_back(Elt: wasm::ValType::I32); |
688 | Params.push_back(Elt: wasm::ValType::F32); |
689 | Params.push_back(Elt: wasm::ValType::F32); |
690 | break; |
691 | case i32_func_f64_f64: |
692 | Rets.push_back(Elt: wasm::ValType::I32); |
693 | Params.push_back(Elt: wasm::ValType::F64); |
694 | Params.push_back(Elt: wasm::ValType::F64); |
695 | break; |
696 | case i32_func_i32_i32: |
697 | Rets.push_back(Elt: wasm::ValType::I32); |
698 | Params.push_back(Elt: wasm::ValType::I32); |
699 | Params.push_back(Elt: wasm::ValType::I32); |
700 | break; |
701 | case i32_func_i32_i32_iPTR: |
702 | Rets.push_back(Elt: wasm::ValType::I32); |
703 | Params.push_back(Elt: wasm::ValType::I32); |
704 | Params.push_back(Elt: wasm::ValType::I32); |
705 | Params.push_back(Elt: PtrTy); |
706 | break; |
707 | case i64_func_i64_i64: |
708 | Rets.push_back(Elt: wasm::ValType::I64); |
709 | Params.push_back(Elt: wasm::ValType::I64); |
710 | Params.push_back(Elt: wasm::ValType::I64); |
711 | break; |
712 | case i64_func_i64_i64_iPTR: |
713 | Rets.push_back(Elt: wasm::ValType::I64); |
714 | Params.push_back(Elt: wasm::ValType::I64); |
715 | Params.push_back(Elt: wasm::ValType::I64); |
716 | Params.push_back(Elt: PtrTy); |
717 | break; |
718 | case i64_i64_func_f32: |
719 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
720 | Rets.push_back(Elt: wasm::ValType::I64); |
721 | Rets.push_back(Elt: wasm::ValType::I64); |
722 | } else { |
723 | Params.push_back(Elt: PtrTy); |
724 | } |
725 | Params.push_back(Elt: wasm::ValType::F32); |
726 | break; |
727 | case i64_i64_func_f64: |
728 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
729 | Rets.push_back(Elt: wasm::ValType::I64); |
730 | Rets.push_back(Elt: wasm::ValType::I64); |
731 | } else { |
732 | Params.push_back(Elt: PtrTy); |
733 | } |
734 | Params.push_back(Elt: wasm::ValType::F64); |
735 | break; |
736 | case i16_i16_func_i16_i16: |
737 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
738 | Rets.push_back(Elt: wasm::ValType::I32); |
739 | Rets.push_back(Elt: wasm::ValType::I32); |
740 | } else { |
741 | Params.push_back(Elt: PtrTy); |
742 | } |
743 | Params.push_back(Elt: wasm::ValType::I32); |
744 | Params.push_back(Elt: wasm::ValType::I32); |
745 | break; |
746 | case i32_i32_func_i32_i32: |
747 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
748 | Rets.push_back(Elt: wasm::ValType::I32); |
749 | Rets.push_back(Elt: wasm::ValType::I32); |
750 | } else { |
751 | Params.push_back(Elt: PtrTy); |
752 | } |
753 | Params.push_back(Elt: wasm::ValType::I32); |
754 | Params.push_back(Elt: wasm::ValType::I32); |
755 | break; |
756 | case i64_i64_func_i64_i64: |
757 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
758 | Rets.push_back(Elt: wasm::ValType::I64); |
759 | Rets.push_back(Elt: wasm::ValType::I64); |
760 | } else { |
761 | Params.push_back(Elt: PtrTy); |
762 | } |
763 | Params.push_back(Elt: wasm::ValType::I64); |
764 | Params.push_back(Elt: wasm::ValType::I64); |
765 | break; |
766 | case i64_i64_func_i64_i64_i64_i64: |
767 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
768 | Rets.push_back(Elt: wasm::ValType::I64); |
769 | Rets.push_back(Elt: wasm::ValType::I64); |
770 | } else { |
771 | Params.push_back(Elt: PtrTy); |
772 | } |
773 | Params.push_back(Elt: wasm::ValType::I64); |
774 | Params.push_back(Elt: wasm::ValType::I64); |
775 | Params.push_back(Elt: wasm::ValType::I64); |
776 | Params.push_back(Elt: wasm::ValType::I64); |
777 | break; |
778 | case i64_i64_func_i64_i64_i64_i64_iPTR: |
779 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
780 | Rets.push_back(Elt: wasm::ValType::I64); |
781 | Rets.push_back(Elt: wasm::ValType::I64); |
782 | } else { |
783 | Params.push_back(Elt: PtrTy); |
784 | } |
785 | Params.push_back(Elt: wasm::ValType::I64); |
786 | Params.push_back(Elt: wasm::ValType::I64); |
787 | Params.push_back(Elt: wasm::ValType::I64); |
788 | Params.push_back(Elt: wasm::ValType::I64); |
789 | Params.push_back(Elt: PtrTy); |
790 | break; |
791 | case i64_i64_i64_i64_func_i64_i64_i64_i64: |
792 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
793 | Rets.push_back(Elt: wasm::ValType::I64); |
794 | Rets.push_back(Elt: wasm::ValType::I64); |
795 | Rets.push_back(Elt: wasm::ValType::I64); |
796 | Rets.push_back(Elt: wasm::ValType::I64); |
797 | } else { |
798 | Params.push_back(Elt: PtrTy); |
799 | } |
800 | Params.push_back(Elt: wasm::ValType::I64); |
801 | Params.push_back(Elt: wasm::ValType::I64); |
802 | Params.push_back(Elt: wasm::ValType::I64); |
803 | Params.push_back(Elt: wasm::ValType::I64); |
804 | break; |
805 | case i64_i64_func_i64_i64_i32: |
806 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
807 | Rets.push_back(Elt: wasm::ValType::I64); |
808 | Rets.push_back(Elt: wasm::ValType::I64); |
809 | } else { |
810 | Params.push_back(Elt: PtrTy); |
811 | } |
812 | Params.push_back(Elt: wasm::ValType::I64); |
813 | Params.push_back(Elt: wasm::ValType::I64); |
814 | Params.push_back(Elt: wasm::ValType::I32); |
815 | break; |
816 | case iPTR_func_i32: |
817 | Rets.push_back(Elt: PtrTy); |
818 | Params.push_back(Elt: wasm::ValType::I32); |
819 | break; |
820 | case iPTR_func_iPTR_i32_iPTR: |
821 | Rets.push_back(Elt: PtrTy); |
822 | Params.push_back(Elt: PtrTy); |
823 | Params.push_back(Elt: wasm::ValType::I32); |
824 | Params.push_back(Elt: PtrTy); |
825 | break; |
826 | case iPTR_func_iPTR_iPTR_iPTR: |
827 | Rets.push_back(Elt: PtrTy); |
828 | Params.push_back(Elt: PtrTy); |
829 | Params.push_back(Elt: PtrTy); |
830 | Params.push_back(Elt: PtrTy); |
831 | break; |
832 | case f32_func_f32_f32_f32: |
833 | Rets.push_back(Elt: wasm::ValType::F32); |
834 | Params.push_back(Elt: wasm::ValType::F32); |
835 | Params.push_back(Elt: wasm::ValType::F32); |
836 | Params.push_back(Elt: wasm::ValType::F32); |
837 | break; |
838 | case f64_func_f64_f64_f64: |
839 | Rets.push_back(Elt: wasm::ValType::F64); |
840 | Params.push_back(Elt: wasm::ValType::F64); |
841 | Params.push_back(Elt: wasm::ValType::F64); |
842 | Params.push_back(Elt: wasm::ValType::F64); |
843 | break; |
844 | case func_i64_i64_iPTR_iPTR: |
845 | Params.push_back(Elt: wasm::ValType::I64); |
846 | Params.push_back(Elt: wasm::ValType::I64); |
847 | Params.push_back(Elt: PtrTy); |
848 | Params.push_back(Elt: PtrTy); |
849 | break; |
850 | case i32_func_i64_i64: |
851 | Rets.push_back(Elt: wasm::ValType::I32); |
852 | Params.push_back(Elt: wasm::ValType::I64); |
853 | Params.push_back(Elt: wasm::ValType::I64); |
854 | break; |
855 | case i32_func_i64_i64_i64_i64: |
856 | Rets.push_back(Elt: wasm::ValType::I32); |
857 | Params.push_back(Elt: wasm::ValType::I64); |
858 | Params.push_back(Elt: wasm::ValType::I64); |
859 | Params.push_back(Elt: wasm::ValType::I64); |
860 | Params.push_back(Elt: wasm::ValType::I64); |
861 | break; |
862 | case iPTR_func_f32: |
863 | Rets.push_back(Elt: PtrTy); |
864 | Params.push_back(Elt: wasm::ValType::F32); |
865 | break; |
866 | case iPTR_func_f64: |
867 | Rets.push_back(Elt: PtrTy); |
868 | Params.push_back(Elt: wasm::ValType::F64); |
869 | break; |
870 | case iPTR_func_i64_i64: |
871 | Rets.push_back(Elt: PtrTy); |
872 | Params.push_back(Elt: wasm::ValType::I64); |
873 | Params.push_back(Elt: wasm::ValType::I64); |
874 | break; |
875 | case i64_i64_func_i64_i64_i64_i64_i64_i64: |
876 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
877 | Rets.push_back(Elt: wasm::ValType::I64); |
878 | Rets.push_back(Elt: wasm::ValType::I64); |
879 | } else { |
880 | Params.push_back(Elt: PtrTy); |
881 | } |
882 | Params.push_back(Elt: wasm::ValType::I64); |
883 | Params.push_back(Elt: wasm::ValType::I64); |
884 | Params.push_back(Elt: wasm::ValType::I64); |
885 | Params.push_back(Elt: wasm::ValType::I64); |
886 | Params.push_back(Elt: wasm::ValType::I64); |
887 | Params.push_back(Elt: wasm::ValType::I64); |
888 | break; |
889 | case i64_i64_func_i32: |
890 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
891 | Rets.push_back(Elt: wasm::ValType::I64); |
892 | Rets.push_back(Elt: wasm::ValType::I64); |
893 | } else { |
894 | Params.push_back(Elt: PtrTy); |
895 | } |
896 | Params.push_back(Elt: wasm::ValType::I32); |
897 | break; |
898 | case i64_i64_func_i64: |
899 | if (WebAssembly::canLowerMultivalueReturn(Subtarget: &Subtarget)) { |
900 | Rets.push_back(Elt: wasm::ValType::I64); |
901 | Rets.push_back(Elt: wasm::ValType::I64); |
902 | } else { |
903 | Params.push_back(Elt: PtrTy); |
904 | } |
905 | Params.push_back(Elt: wasm::ValType::I64); |
906 | break; |
907 | case unsupported: |
908 | llvm_unreachable("unsupported runtime library signature" ); |
909 | } |
910 | } |
911 | |
912 | // TODO: If the RTLIB::Libcall-taking flavor of GetSignature remains unused |
913 | // other than here, just roll its logic into this version. |
914 | void WebAssembly::getLibcallSignature(const WebAssemblySubtarget &Subtarget, |
915 | StringRef Name, |
916 | SmallVectorImpl<wasm::ValType> &Rets, |
917 | SmallVectorImpl<wasm::ValType> &Params) { |
918 | static StaticLibcallNameMap LibcallNameMap; |
919 | auto &Map = LibcallNameMap.Map; |
920 | auto Val = Map.find(Key: Name); |
921 | #ifndef NDEBUG |
922 | if (Val == Map.end()) { |
923 | auto Message = |
924 | std::string("unexpected runtime library name: " ) + std::string(Name); |
925 | llvm_unreachable(Message.c_str()); |
926 | } |
927 | #endif |
928 | return getLibcallSignature(Subtarget, LC: Val->second, Rets, Params); |
929 | } |
930 | |