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