LLVM  10.0.0svn
WebAssemblyRuntimeLibcallSignatures.cpp
Go to the documentation of this file.
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 
22 #include "WebAssemblySubtarget.h"
25 
26 using namespace llvm;
27 
28 namespace {
29 
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_f32,
67  i64_i64_func_f64,
68  i16_i16_func_i16_i16,
69  i32_i32_func_i32_i32,
70  i64_i64_func_i64_i64,
71  i64_i64_func_i64_i64_i64_i64,
72  i64_i64_func_i64_i64_i64_i64_iPTR,
73  i64_i64_i64_i64_func_i64_i64_i64_i64,
74  i64_i64_func_i64_i64_i32,
75  iPTR_func_iPTR_i32_iPTR,
76  iPTR_func_iPTR_iPTR_iPTR,
77  f32_func_f32_f32_f32,
78  f64_func_f64_f64_f64,
79  func_i64_i64_iPTR_iPTR,
80  func_iPTR_f32,
81  func_iPTR_f64,
82  func_iPTR_i32,
83  func_iPTR_i64,
84  func_iPTR_i64_i64,
85  func_iPTR_i64_i64_i64_i64,
86  func_iPTR_i64_i64_i64_i64_i64_i64,
87  i32_func_i64_i64,
88  i32_func_i64_i64_i64_i64,
89  iPTR_func_f32,
90  iPTR_func_f64,
91  iPTR_func_i64_i64,
92  unsupported
93 };
94 
95 struct RuntimeLibcallSignatureTable {
96  std::vector<RuntimeLibcallSignature> Table;
97 
98  // Any newly-added libcalls will be unsupported by default.
99  RuntimeLibcallSignatureTable() : Table(RTLIB::UNKNOWN_LIBCALL, unsupported) {
100  // Integer
101  Table[RTLIB::SHL_I16] = i16_func_i16_i16;
102  Table[RTLIB::SHL_I32] = i32_func_i32_i32;
103  Table[RTLIB::SHL_I64] = i64_func_i64_i64;
104  Table[RTLIB::SHL_I128] = i64_i64_func_i64_i64_i32;
105  Table[RTLIB::SRL_I16] = i16_func_i16_i16;
106  Table[RTLIB::SRL_I32] = i32_func_i32_i32;
107  Table[RTLIB::SRL_I64] = i64_func_i64_i64;
108  Table[RTLIB::SRL_I128] = i64_i64_func_i64_i64_i32;
109  Table[RTLIB::SRA_I16] = i16_func_i16_i16;
110  Table[RTLIB::SRA_I32] = i32_func_i32_i32;
111  Table[RTLIB::SRA_I64] = i64_func_i64_i64;
112  Table[RTLIB::SRA_I128] = i64_i64_func_i64_i64_i32;
113  Table[RTLIB::MUL_I8] = i8_func_i8_i8;
114  Table[RTLIB::MUL_I16] = i16_func_i16_i16;
115  Table[RTLIB::MUL_I32] = i32_func_i32_i32;
116  Table[RTLIB::MUL_I64] = i64_func_i64_i64;
117  Table[RTLIB::MUL_I128] = i64_i64_func_i64_i64_i64_i64;
118  Table[RTLIB::MULO_I32] = i32_func_i32_i32_iPTR;
119  Table[RTLIB::MULO_I64] = i64_func_i64_i64_iPTR;
120  Table[RTLIB::MULO_I128] = i64_i64_func_i64_i64_i64_i64_iPTR;
121  Table[RTLIB::SDIV_I8] = i8_func_i8_i8;
122  Table[RTLIB::SDIV_I16] = i16_func_i16_i16;
123  Table[RTLIB::SDIV_I32] = i32_func_i32_i32;
124  Table[RTLIB::SDIV_I64] = i64_func_i64_i64;
125  Table[RTLIB::SDIV_I128] = i64_i64_func_i64_i64_i64_i64;
126  Table[RTLIB::UDIV_I8] = i8_func_i8_i8;
127  Table[RTLIB::UDIV_I16] = i16_func_i16_i16;
128  Table[RTLIB::UDIV_I32] = i32_func_i32_i32;
129  Table[RTLIB::UDIV_I64] = i64_func_i64_i64;
130  Table[RTLIB::UDIV_I128] = i64_i64_func_i64_i64_i64_i64;
131  Table[RTLIB::SREM_I8] = i8_func_i8_i8;
132  Table[RTLIB::SREM_I16] = i16_func_i16_i16;
133  Table[RTLIB::SREM_I32] = i32_func_i32_i32;
134  Table[RTLIB::SREM_I64] = i64_func_i64_i64;
135  Table[RTLIB::SREM_I128] = i64_i64_func_i64_i64_i64_i64;
136  Table[RTLIB::UREM_I8] = i8_func_i8_i8;
137  Table[RTLIB::UREM_I16] = i16_func_i16_i16;
138  Table[RTLIB::UREM_I32] = i32_func_i32_i32;
139  Table[RTLIB::UREM_I64] = i64_func_i64_i64;
140  Table[RTLIB::UREM_I128] = i64_i64_func_i64_i64_i64_i64;
141  Table[RTLIB::SDIVREM_I8] = i8_func_i8_i8;
142  Table[RTLIB::SDIVREM_I16] = i16_i16_func_i16_i16;
143  Table[RTLIB::SDIVREM_I32] = i32_i32_func_i32_i32;
144  Table[RTLIB::SDIVREM_I64] = i64_func_i64_i64;
145  Table[RTLIB::SDIVREM_I128] = i64_i64_i64_i64_func_i64_i64_i64_i64;
146  Table[RTLIB::UDIVREM_I8] = i8_func_i8_i8;
147  Table[RTLIB::UDIVREM_I16] = i16_i16_func_i16_i16;
148  Table[RTLIB::UDIVREM_I32] = i32_i32_func_i32_i32;
149  Table[RTLIB::UDIVREM_I64] = i64_i64_func_i64_i64;
150  Table[RTLIB::UDIVREM_I128] = i64_i64_i64_i64_func_i64_i64_i64_i64;
151  Table[RTLIB::NEG_I32] = i32_func_i32;
152  Table[RTLIB::NEG_I64] = i64_func_i64;
153 
154  // Floating-point.
155  // All F80 and PPCF128 routines are unsupported.
156  Table[RTLIB::ADD_F32] = f32_func_f32_f32;
157  Table[RTLIB::ADD_F64] = f64_func_f64_f64;
158  Table[RTLIB::ADD_F128] = func_iPTR_i64_i64_i64_i64;
159  Table[RTLIB::SUB_F32] = f32_func_f32_f32;
160  Table[RTLIB::SUB_F64] = f64_func_f64_f64;
161  Table[RTLIB::SUB_F128] = func_iPTR_i64_i64_i64_i64;
162  Table[RTLIB::MUL_F32] = f32_func_f32_f32;
163  Table[RTLIB::MUL_F64] = f64_func_f64_f64;
164  Table[RTLIB::MUL_F128] = func_iPTR_i64_i64_i64_i64;
165  Table[RTLIB::DIV_F32] = f32_func_f32_f32;
166  Table[RTLIB::DIV_F64] = f64_func_f64_f64;
167  Table[RTLIB::DIV_F128] = func_iPTR_i64_i64_i64_i64;
168  Table[RTLIB::REM_F32] = f32_func_f32_f32;
169  Table[RTLIB::REM_F64] = f64_func_f64_f64;
170  Table[RTLIB::REM_F128] = func_iPTR_i64_i64_i64_i64;
171  Table[RTLIB::FMA_F32] = f32_func_f32_f32_f32;
172  Table[RTLIB::FMA_F64] = f64_func_f64_f64_f64;
173  Table[RTLIB::FMA_F128] = func_iPTR_i64_i64_i64_i64_i64_i64;
174  Table[RTLIB::POWI_F32] = f32_func_f32_i32;
175  Table[RTLIB::POWI_F64] = f64_func_f64_i32;
176  Table[RTLIB::POWI_F128] = func_iPTR_i64_i64_i64_i64;
177  Table[RTLIB::SQRT_F32] = f32_func_f32;
178  Table[RTLIB::SQRT_F64] = f64_func_f64;
179  Table[RTLIB::SQRT_F128] = func_iPTR_i64_i64;
180  Table[RTLIB::LOG_F32] = f32_func_f32;
181  Table[RTLIB::LOG_F64] = f64_func_f64;
182  Table[RTLIB::LOG_F128] = func_iPTR_i64_i64;
183  Table[RTLIB::LOG2_F32] = f32_func_f32;
184  Table[RTLIB::LOG2_F64] = f64_func_f64;
185  Table[RTLIB::LOG2_F128] = func_iPTR_i64_i64;
186  Table[RTLIB::LOG10_F32] = f32_func_f32;
187  Table[RTLIB::LOG10_F64] = f64_func_f64;
188  Table[RTLIB::LOG10_F128] = func_iPTR_i64_i64;
189  Table[RTLIB::EXP_F32] = f32_func_f32;
190  Table[RTLIB::EXP_F64] = f64_func_f64;
191  Table[RTLIB::EXP_F128] = func_iPTR_i64_i64;
192  Table[RTLIB::EXP2_F32] = f32_func_f32;
193  Table[RTLIB::EXP2_F64] = f64_func_f64;
194  Table[RTLIB::EXP2_F128] = func_iPTR_i64_i64;
195  Table[RTLIB::SIN_F32] = f32_func_f32;
196  Table[RTLIB::SIN_F64] = f64_func_f64;
197  Table[RTLIB::SIN_F128] = func_iPTR_i64_i64;
198  Table[RTLIB::COS_F32] = f32_func_f32;
199  Table[RTLIB::COS_F64] = f64_func_f64;
200  Table[RTLIB::COS_F128] = func_iPTR_i64_i64;
201  Table[RTLIB::SINCOS_F32] = func_f32_iPTR_iPTR;
202  Table[RTLIB::SINCOS_F64] = func_f64_iPTR_iPTR;
203  Table[RTLIB::SINCOS_F128] = func_i64_i64_iPTR_iPTR;
204  Table[RTLIB::POW_F32] = f32_func_f32_f32;
205  Table[RTLIB::POW_F64] = f64_func_f64_f64;
206  Table[RTLIB::POW_F128] = func_iPTR_i64_i64_i64_i64;
207  Table[RTLIB::CEIL_F32] = f32_func_f32;
208  Table[RTLIB::CEIL_F64] = f64_func_f64;
209  Table[RTLIB::CEIL_F128] = func_iPTR_i64_i64;
210  Table[RTLIB::TRUNC_F32] = f32_func_f32;
211  Table[RTLIB::TRUNC_F64] = f64_func_f64;
212  Table[RTLIB::TRUNC_F128] = func_iPTR_i64_i64;
213  Table[RTLIB::RINT_F32] = f32_func_f32;
214  Table[RTLIB::RINT_F64] = f64_func_f64;
215  Table[RTLIB::RINT_F128] = func_iPTR_i64_i64;
216  Table[RTLIB::NEARBYINT_F32] = f32_func_f32;
217  Table[RTLIB::NEARBYINT_F64] = f64_func_f64;
218  Table[RTLIB::NEARBYINT_F128] = func_iPTR_i64_i64;
219  Table[RTLIB::ROUND_F32] = f32_func_f32;
220  Table[RTLIB::ROUND_F64] = f64_func_f64;
221  Table[RTLIB::ROUND_F128] = func_iPTR_i64_i64;
222  Table[RTLIB::LROUND_F32] = iPTR_func_f32;
223  Table[RTLIB::LROUND_F64] = iPTR_func_f64;
224  Table[RTLIB::LROUND_F128] = iPTR_func_i64_i64;
225  Table[RTLIB::LLROUND_F32] = i64_func_f32;
226  Table[RTLIB::LLROUND_F64] = i64_func_f64;
227  Table[RTLIB::LLROUND_F128] = i64_func_i64_i64;
228  Table[RTLIB::LRINT_F32] = iPTR_func_f32;
229  Table[RTLIB::LRINT_F64] = iPTR_func_f64;
230  Table[RTLIB::LRINT_F128] = iPTR_func_i64_i64;
231  Table[RTLIB::LLRINT_F32] = i64_func_f32;
232  Table[RTLIB::LLRINT_F64] = i64_func_f64;
233  Table[RTLIB::LLRINT_F128] = i64_func_i64_i64;
234  Table[RTLIB::FLOOR_F32] = f32_func_f32;
235  Table[RTLIB::FLOOR_F64] = f64_func_f64;
236  Table[RTLIB::FLOOR_F128] = func_iPTR_i64_i64;
237  Table[RTLIB::COPYSIGN_F32] = f32_func_f32_f32;
238  Table[RTLIB::COPYSIGN_F64] = f64_func_f64_f64;
239  Table[RTLIB::COPYSIGN_F128] = func_iPTR_i64_i64_i64_i64;
240  Table[RTLIB::FMIN_F32] = f32_func_f32_f32;
241  Table[RTLIB::FMIN_F64] = f64_func_f64_f64;
242  Table[RTLIB::FMIN_F128] = func_iPTR_i64_i64_i64_i64;
243  Table[RTLIB::FMAX_F32] = f32_func_f32_f32;
244  Table[RTLIB::FMAX_F64] = f64_func_f64_f64;
245  Table[RTLIB::FMAX_F128] = func_iPTR_i64_i64_i64_i64;
246 
247  // Conversion
248  // All F80 and PPCF128 routines are unsupported.
249  Table[RTLIB::FPEXT_F64_F128] = func_iPTR_f64;
250  Table[RTLIB::FPEXT_F32_F128] = func_iPTR_f32;
251  Table[RTLIB::FPEXT_F32_F64] = f64_func_f32;
252  Table[RTLIB::FPEXT_F16_F32] = f32_func_i16;
253  Table[RTLIB::FPROUND_F32_F16] = i16_func_f32;
254  Table[RTLIB::FPROUND_F64_F16] = i16_func_f64;
255  Table[RTLIB::FPROUND_F64_F32] = f32_func_f64;
256  Table[RTLIB::FPROUND_F128_F16] = i16_func_i64_i64;
257  Table[RTLIB::FPROUND_F128_F32] = f32_func_i64_i64;
258  Table[RTLIB::FPROUND_F128_F64] = f64_func_i64_i64;
259  Table[RTLIB::FPTOSINT_F32_I32] = i32_func_f32;
260  Table[RTLIB::FPTOSINT_F32_I64] = i64_func_f32;
261  Table[RTLIB::FPTOSINT_F32_I128] = i64_i64_func_f32;
262  Table[RTLIB::FPTOSINT_F64_I32] = i32_func_f64;
263  Table[RTLIB::FPTOSINT_F64_I64] = i64_func_f64;
264  Table[RTLIB::FPTOSINT_F64_I128] = i64_i64_func_f64;
265  Table[RTLIB::FPTOSINT_F128_I32] = i32_func_i64_i64;
266  Table[RTLIB::FPTOSINT_F128_I64] = i64_func_i64_i64;
267  Table[RTLIB::FPTOSINT_F128_I128] = i64_i64_func_i64_i64;
268  Table[RTLIB::FPTOUINT_F32_I32] = i32_func_f32;
269  Table[RTLIB::FPTOUINT_F32_I64] = i64_func_f32;
270  Table[RTLIB::FPTOUINT_F32_I128] = i64_i64_func_f32;
271  Table[RTLIB::FPTOUINT_F64_I32] = i32_func_f64;
272  Table[RTLIB::FPTOUINT_F64_I64] = i64_func_f64;
273  Table[RTLIB::FPTOUINT_F64_I128] = i64_i64_func_f64;
274  Table[RTLIB::FPTOUINT_F128_I32] = i32_func_i64_i64;
275  Table[RTLIB::FPTOUINT_F128_I64] = i64_func_i64_i64;
276  Table[RTLIB::FPTOUINT_F128_I128] = i64_i64_func_i64_i64;
277  Table[RTLIB::SINTTOFP_I32_F32] = f32_func_i32;
278  Table[RTLIB::SINTTOFP_I32_F64] = f64_func_i32;
279  Table[RTLIB::SINTTOFP_I32_F128] = func_iPTR_i32;
280  Table[RTLIB::SINTTOFP_I64_F32] = f32_func_i64;
281  Table[RTLIB::SINTTOFP_I64_F64] = f64_func_i64;
282  Table[RTLIB::SINTTOFP_I64_F128] = func_iPTR_i64;
283  Table[RTLIB::SINTTOFP_I128_F32] = f32_func_i64_i64;
284  Table[RTLIB::SINTTOFP_I128_F64] = f64_func_i64_i64;
285  Table[RTLIB::SINTTOFP_I128_F128] = func_iPTR_i64_i64;
286  Table[RTLIB::UINTTOFP_I32_F32] = f32_func_i32;
287  Table[RTLIB::UINTTOFP_I32_F64] = f64_func_i64;
288  Table[RTLIB::UINTTOFP_I32_F128] = func_iPTR_i32;
289  Table[RTLIB::UINTTOFP_I64_F32] = f32_func_i64;
290  Table[RTLIB::UINTTOFP_I64_F64] = f64_func_i64;
291  Table[RTLIB::UINTTOFP_I64_F128] = func_iPTR_i64;
292  Table[RTLIB::UINTTOFP_I128_F32] = f32_func_i64_i64;
293  Table[RTLIB::UINTTOFP_I128_F64] = f64_func_i64_i64;
294  Table[RTLIB::UINTTOFP_I128_F128] = func_iPTR_i64_i64;
295 
296  // Comparison
297  // ALl F80 and PPCF128 routines are unsupported.
298  Table[RTLIB::OEQ_F32] = i32_func_f32_f32;
299  Table[RTLIB::OEQ_F64] = i32_func_f64_f64;
300  Table[RTLIB::OEQ_F128] = i32_func_i64_i64_i64_i64;
301  Table[RTLIB::UNE_F32] = i32_func_f32_f32;
302  Table[RTLIB::UNE_F64] = i32_func_f64_f64;
303  Table[RTLIB::UNE_F128] = i32_func_i64_i64_i64_i64;
304  Table[RTLIB::OGE_F32] = i32_func_f32_f32;
305  Table[RTLIB::OGE_F64] = i32_func_f64_f64;
306  Table[RTLIB::OGE_F128] = i32_func_i64_i64_i64_i64;
307  Table[RTLIB::OLT_F32] = i32_func_f32_f32;
308  Table[RTLIB::OLT_F64] = i32_func_f64_f64;
309  Table[RTLIB::OLT_F128] = i32_func_i64_i64_i64_i64;
310  Table[RTLIB::OLE_F32] = i32_func_f32_f32;
311  Table[RTLIB::OLE_F64] = i32_func_f64_f64;
312  Table[RTLIB::OLE_F128] = i32_func_i64_i64_i64_i64;
313  Table[RTLIB::OGT_F32] = i32_func_f32_f32;
314  Table[RTLIB::OGT_F64] = i32_func_f64_f64;
315  Table[RTLIB::OGT_F128] = i32_func_i64_i64_i64_i64;
316  Table[RTLIB::UO_F32] = i32_func_f32_f32;
317  Table[RTLIB::UO_F64] = i32_func_f64_f64;
318  Table[RTLIB::UO_F128] = i32_func_i64_i64_i64_i64;
319  // O_FXX has the weird property that it uses the same libcall name as UO_FXX
320  // This breaks our name-based lookup. Fortunately only the UO family of
321  // libcalls appears to be actually used.
322  Table[RTLIB::O_F32] = unsupported;
323  Table[RTLIB::O_F64] = unsupported;
324  Table[RTLIB::O_F128] = unsupported;
325 
326  // Memory
327  Table[RTLIB::MEMCPY] = iPTR_func_iPTR_iPTR_iPTR;
328  Table[RTLIB::MEMSET] = iPTR_func_iPTR_i32_iPTR;
329  Table[RTLIB::MEMMOVE] = iPTR_func_iPTR_iPTR_iPTR;
330 
331  // __stack_chk_fail
332  Table[RTLIB::STACKPROTECTOR_CHECK_FAIL] = func;
333 
334  // Return address handling
335  Table[RTLIB::RETURN_ADDRESS] = i32_func_i32;
336 
337  // Element-wise Atomic memory
338  // TODO: Fix these when we implement atomic support
339  Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_1] = unsupported;
340  Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_2] = unsupported;
341  Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_4] = unsupported;
342  Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_8] = unsupported;
343  Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_16] = unsupported;
344  Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_1] = unsupported;
345  Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_2] = unsupported;
346  Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_4] = unsupported;
347  Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_8] = unsupported;
348  Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_16] = unsupported;
349 
350  Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_1] = unsupported;
351  Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_2] = unsupported;
352  Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_4] = unsupported;
353  Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_8] = unsupported;
354  Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_16] = unsupported;
355 
356  // Atomic '__sync_*' libcalls.
357  // TODO: Fix these when we implement atomic support
358  Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_1] = unsupported;
359  Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_2] = unsupported;
360  Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_4] = unsupported;
361  Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_8] = unsupported;
362  Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_16] = unsupported;
363  Table[RTLIB::SYNC_LOCK_TEST_AND_SET_1] = unsupported;
364  Table[RTLIB::SYNC_LOCK_TEST_AND_SET_2] = unsupported;
365  Table[RTLIB::SYNC_LOCK_TEST_AND_SET_4] = unsupported;
366  Table[RTLIB::SYNC_LOCK_TEST_AND_SET_8] = unsupported;
367  Table[RTLIB::SYNC_LOCK_TEST_AND_SET_16] = unsupported;
368  Table[RTLIB::SYNC_FETCH_AND_ADD_1] = unsupported;
369  Table[RTLIB::SYNC_FETCH_AND_ADD_2] = unsupported;
370  Table[RTLIB::SYNC_FETCH_AND_ADD_4] = unsupported;
371  Table[RTLIB::SYNC_FETCH_AND_ADD_8] = unsupported;
372  Table[RTLIB::SYNC_FETCH_AND_ADD_16] = unsupported;
373  Table[RTLIB::SYNC_FETCH_AND_SUB_1] = unsupported;
374  Table[RTLIB::SYNC_FETCH_AND_SUB_2] = unsupported;
375  Table[RTLIB::SYNC_FETCH_AND_SUB_4] = unsupported;
376  Table[RTLIB::SYNC_FETCH_AND_SUB_8] = unsupported;
377  Table[RTLIB::SYNC_FETCH_AND_SUB_16] = unsupported;
378  Table[RTLIB::SYNC_FETCH_AND_AND_1] = unsupported;
379  Table[RTLIB::SYNC_FETCH_AND_AND_2] = unsupported;
380  Table[RTLIB::SYNC_FETCH_AND_AND_4] = unsupported;
381  Table[RTLIB::SYNC_FETCH_AND_AND_8] = unsupported;
382  Table[RTLIB::SYNC_FETCH_AND_AND_16] = unsupported;
383  Table[RTLIB::SYNC_FETCH_AND_OR_1] = unsupported;
384  Table[RTLIB::SYNC_FETCH_AND_OR_2] = unsupported;
385  Table[RTLIB::SYNC_FETCH_AND_OR_4] = unsupported;
386  Table[RTLIB::SYNC_FETCH_AND_OR_8] = unsupported;
387  Table[RTLIB::SYNC_FETCH_AND_OR_16] = unsupported;
388  Table[RTLIB::SYNC_FETCH_AND_XOR_1] = unsupported;
389  Table[RTLIB::SYNC_FETCH_AND_XOR_2] = unsupported;
390  Table[RTLIB::SYNC_FETCH_AND_XOR_4] = unsupported;
391  Table[RTLIB::SYNC_FETCH_AND_XOR_8] = unsupported;
392  Table[RTLIB::SYNC_FETCH_AND_XOR_16] = unsupported;
393  Table[RTLIB::SYNC_FETCH_AND_NAND_1] = unsupported;
394  Table[RTLIB::SYNC_FETCH_AND_NAND_2] = unsupported;
395  Table[RTLIB::SYNC_FETCH_AND_NAND_4] = unsupported;
396  Table[RTLIB::SYNC_FETCH_AND_NAND_8] = unsupported;
397  Table[RTLIB::SYNC_FETCH_AND_NAND_16] = unsupported;
398  Table[RTLIB::SYNC_FETCH_AND_MAX_1] = unsupported;
399  Table[RTLIB::SYNC_FETCH_AND_MAX_2] = unsupported;
400  Table[RTLIB::SYNC_FETCH_AND_MAX_4] = unsupported;
401  Table[RTLIB::SYNC_FETCH_AND_MAX_8] = unsupported;
402  Table[RTLIB::SYNC_FETCH_AND_MAX_16] = unsupported;
403  Table[RTLIB::SYNC_FETCH_AND_UMAX_1] = unsupported;
404  Table[RTLIB::SYNC_FETCH_AND_UMAX_2] = unsupported;
405  Table[RTLIB::SYNC_FETCH_AND_UMAX_4] = unsupported;
406  Table[RTLIB::SYNC_FETCH_AND_UMAX_8] = unsupported;
407  Table[RTLIB::SYNC_FETCH_AND_UMAX_16] = unsupported;
408  Table[RTLIB::SYNC_FETCH_AND_MIN_1] = unsupported;
409  Table[RTLIB::SYNC_FETCH_AND_MIN_2] = unsupported;
410  Table[RTLIB::SYNC_FETCH_AND_MIN_4] = unsupported;
411  Table[RTLIB::SYNC_FETCH_AND_MIN_8] = unsupported;
412  Table[RTLIB::SYNC_FETCH_AND_MIN_16] = unsupported;
413  Table[RTLIB::SYNC_FETCH_AND_UMIN_1] = unsupported;
414  Table[RTLIB::SYNC_FETCH_AND_UMIN_2] = unsupported;
415  Table[RTLIB::SYNC_FETCH_AND_UMIN_4] = unsupported;
416  Table[RTLIB::SYNC_FETCH_AND_UMIN_8] = unsupported;
417  Table[RTLIB::SYNC_FETCH_AND_UMIN_16] = unsupported;
418 
419  // Atomic '__atomic_*' libcalls.
420  // TODO: Fix these when we implement atomic support
421  Table[RTLIB::ATOMIC_LOAD] = unsupported;
422  Table[RTLIB::ATOMIC_LOAD_1] = unsupported;
423  Table[RTLIB::ATOMIC_LOAD_2] = unsupported;
424  Table[RTLIB::ATOMIC_LOAD_4] = unsupported;
425  Table[RTLIB::ATOMIC_LOAD_8] = unsupported;
426  Table[RTLIB::ATOMIC_LOAD_16] = unsupported;
427 
428  Table[RTLIB::ATOMIC_STORE] = unsupported;
429  Table[RTLIB::ATOMIC_STORE_1] = unsupported;
430  Table[RTLIB::ATOMIC_STORE_2] = unsupported;
431  Table[RTLIB::ATOMIC_STORE_4] = unsupported;
432  Table[RTLIB::ATOMIC_STORE_8] = unsupported;
433  Table[RTLIB::ATOMIC_STORE_16] = unsupported;
434 
435  Table[RTLIB::ATOMIC_EXCHANGE] = unsupported;
436  Table[RTLIB::ATOMIC_EXCHANGE_1] = unsupported;
437  Table[RTLIB::ATOMIC_EXCHANGE_2] = unsupported;
438  Table[RTLIB::ATOMIC_EXCHANGE_4] = unsupported;
439  Table[RTLIB::ATOMIC_EXCHANGE_8] = unsupported;
440  Table[RTLIB::ATOMIC_EXCHANGE_16] = unsupported;
441 
442  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE] = unsupported;
443  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_1] = unsupported;
444  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_2] = unsupported;
445  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_4] = unsupported;
446  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_8] = unsupported;
447  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_16] = unsupported;
448 
449  Table[RTLIB::ATOMIC_FETCH_ADD_1] = unsupported;
450  Table[RTLIB::ATOMIC_FETCH_ADD_2] = unsupported;
451  Table[RTLIB::ATOMIC_FETCH_ADD_4] = unsupported;
452  Table[RTLIB::ATOMIC_FETCH_ADD_8] = unsupported;
453  Table[RTLIB::ATOMIC_FETCH_ADD_16] = unsupported;
454 
455  Table[RTLIB::ATOMIC_FETCH_SUB_1] = unsupported;
456  Table[RTLIB::ATOMIC_FETCH_SUB_2] = unsupported;
457  Table[RTLIB::ATOMIC_FETCH_SUB_4] = unsupported;
458  Table[RTLIB::ATOMIC_FETCH_SUB_8] = unsupported;
459  Table[RTLIB::ATOMIC_FETCH_SUB_16] = unsupported;
460 
461  Table[RTLIB::ATOMIC_FETCH_AND_1] = unsupported;
462  Table[RTLIB::ATOMIC_FETCH_AND_2] = unsupported;
463  Table[RTLIB::ATOMIC_FETCH_AND_4] = unsupported;
464  Table[RTLIB::ATOMIC_FETCH_AND_8] = unsupported;
465  Table[RTLIB::ATOMIC_FETCH_AND_16] = unsupported;
466 
467  Table[RTLIB::ATOMIC_FETCH_OR_1] = unsupported;
468  Table[RTLIB::ATOMIC_FETCH_OR_2] = unsupported;
469  Table[RTLIB::ATOMIC_FETCH_OR_4] = unsupported;
470  Table[RTLIB::ATOMIC_FETCH_OR_8] = unsupported;
471  Table[RTLIB::ATOMIC_FETCH_OR_16] = unsupported;
472 
473  Table[RTLIB::ATOMIC_FETCH_XOR_1] = unsupported;
474  Table[RTLIB::ATOMIC_FETCH_XOR_2] = unsupported;
475  Table[RTLIB::ATOMIC_FETCH_XOR_4] = unsupported;
476  Table[RTLIB::ATOMIC_FETCH_XOR_8] = unsupported;
477  Table[RTLIB::ATOMIC_FETCH_XOR_16] = unsupported;
478 
479  Table[RTLIB::ATOMIC_FETCH_NAND_1] = unsupported;
480  Table[RTLIB::ATOMIC_FETCH_NAND_2] = unsupported;
481  Table[RTLIB::ATOMIC_FETCH_NAND_4] = unsupported;
482  Table[RTLIB::ATOMIC_FETCH_NAND_8] = unsupported;
483  Table[RTLIB::ATOMIC_FETCH_NAND_16] = unsupported;
484  }
485 };
486 
487 ManagedStatic<RuntimeLibcallSignatureTable> RuntimeLibcallSignatures;
488 
489 // Maps libcall names to their RTLIB::Libcall number. Builds the map in a
490 // constructor for use with ManagedStatic
491 struct StaticLibcallNameMap {
493  StaticLibcallNameMap() {
494  static const std::pair<const char *, RTLIB::Libcall> NameLibcalls[] = {
495 #define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code},
496 #include "llvm/IR/RuntimeLibcalls.def"
497 #undef HANDLE_LIBCALL
498  };
499  for (const auto &NameLibcall : NameLibcalls) {
500  if (NameLibcall.first != nullptr &&
501  RuntimeLibcallSignatures->Table[NameLibcall.second] != unsupported) {
502  assert(Map.find(NameLibcall.first) == Map.end() &&
503  "duplicate libcall names in name map");
504  Map[NameLibcall.first] = NameLibcall.second;
505  }
506  }
507  // Override the __gnu_f2h_ieee/__gnu_h2f_ieee names so that the f32 name is
508  // consistent with the f64 and f128 names.
509  Map["__extendhfsf2"] = RTLIB::FPEXT_F16_F32;
510  Map["__truncsfhf2"] = RTLIB::FPROUND_F32_F16;
511 
512  Map["emscripten_return_address"] = RTLIB::RETURN_ADDRESS;
513  }
514 };
515 
516 } // end anonymous namespace
517 
519  RTLIB::Libcall LC,
522  assert(Rets.empty());
523  assert(Params.empty());
524 
525  wasm::ValType PtrTy =
527 
528  auto &Table = RuntimeLibcallSignatures->Table;
529  switch (Table[LC]) {
530  case func:
531  break;
532  case f32_func_f32:
535  break;
536  case f32_func_f64:
539  break;
540  case f32_func_i32:
543  break;
544  case f32_func_i64:
547  break;
548  case f32_func_i16:
551  break;
552  case f64_func_f32:
555  break;
556  case f64_func_f64:
559  break;
560  case f64_func_i32:
563  break;
564  case f64_func_i64:
567  break;
568  case i32_func_f32:
571  break;
572  case i32_func_f64:
575  break;
576  case i32_func_i32:
579  break;
580  case i64_func_f32:
583  break;
584  case i64_func_f64:
587  break;
588  case i64_func_i64:
591  break;
592  case f32_func_f32_f32:
596  break;
597  case f32_func_f32_i32:
601  break;
602  case f32_func_i64_i64:
606  break;
607  case f64_func_f64_f64:
611  break;
612  case f64_func_f64_i32:
616  break;
617  case f64_func_i64_i64:
621  break;
622  case i16_func_f32:
625  break;
626  case i16_func_f64:
629  break;
630  case i16_func_i64_i64:
634  break;
635  case i8_func_i8_i8:
639  break;
640  case func_f32_iPTR_iPTR:
642  Params.push_back(PtrTy);
643  Params.push_back(PtrTy);
644  break;
645  case func_f64_iPTR_iPTR:
647  Params.push_back(PtrTy);
648  Params.push_back(PtrTy);
649  break;
650  case i16_func_i16_i16:
654  break;
655  case i32_func_f32_f32:
659  break;
660  case i32_func_f64_f64:
664  break;
665  case i32_func_i32_i32:
669  break;
670  case i32_func_i32_i32_iPTR:
674  Params.push_back(PtrTy);
675  break;
676  case i64_func_i64_i64:
680  break;
681  case i64_func_i64_i64_iPTR:
685  Params.push_back(PtrTy);
686  break;
687  case i64_i64_func_f32:
688 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
691 #else
692  Params.push_back(PtrTy);
693 #endif
695  break;
696  case i64_i64_func_f64:
697 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
700 #else
701  Params.push_back(PtrTy);
702 #endif
704  break;
705  case i16_i16_func_i16_i16:
706 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
709 #else
710  Params.push_back(PtrTy);
711 #endif
714  break;
715  case i32_i32_func_i32_i32:
716 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
719 #else
720  Params.push_back(PtrTy);
721 #endif
724  break;
725  case i64_i64_func_i64_i64:
726 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
729 #else
730  Params.push_back(PtrTy);
731 #endif
734  break;
735  case i64_i64_func_i64_i64_i64_i64:
736 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
739 #else
740  Params.push_back(PtrTy);
741 #endif
746  break;
747  case i64_i64_func_i64_i64_i64_i64_iPTR:
748 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
751 #else
752  Params.push_back(PtrTy);
753 #endif
758  Params.push_back(PtrTy);
759  break;
760  case i64_i64_i64_i64_func_i64_i64_i64_i64:
761 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
766 #else
767  Params.push_back(PtrTy);
768 #endif
773  break;
774  case i64_i64_func_i64_i64_i32:
775 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
780 #else
781  Params.push_back(PtrTy);
782 #endif
786  break;
787  case iPTR_func_iPTR_i32_iPTR:
788  Rets.push_back(PtrTy);
789  Params.push_back(PtrTy);
791  Params.push_back(PtrTy);
792  break;
793  case iPTR_func_iPTR_iPTR_iPTR:
794  Rets.push_back(PtrTy);
795  Params.push_back(PtrTy);
796  Params.push_back(PtrTy);
797  Params.push_back(PtrTy);
798  break;
799  case f32_func_f32_f32_f32:
804  break;
805  case f64_func_f64_f64_f64:
810  break;
811  case func_i64_i64_iPTR_iPTR:
814  Params.push_back(PtrTy);
815  Params.push_back(PtrTy);
816  break;
817  case func_iPTR_f32:
818  Params.push_back(PtrTy);
820  break;
821  case func_iPTR_f64:
822  Params.push_back(PtrTy);
824  break;
825  case func_iPTR_i32:
826  Params.push_back(PtrTy);
828  break;
829  case func_iPTR_i64:
830  Params.push_back(PtrTy);
832  break;
833  case func_iPTR_i64_i64:
834  Params.push_back(PtrTy);
837  break;
838  case func_iPTR_i64_i64_i64_i64:
839  Params.push_back(PtrTy);
844  break;
845  case func_iPTR_i64_i64_i64_i64_i64_i64:
846  Params.push_back(PtrTy);
853  break;
854  case i32_func_i64_i64:
858  break;
859  case i32_func_i64_i64_i64_i64:
865  break;
866  case iPTR_func_f32:
867  Rets.push_back(PtrTy);
869  break;
870  case iPTR_func_f64:
871  Rets.push_back(PtrTy);
873  break;
874  case iPTR_func_i64_i64:
875  Rets.push_back(PtrTy);
878  break;
879  case unsupported:
880  llvm_unreachable("unsupported runtime library signature");
881  }
882 }
883 
885 // TODO: If the RTLIB::Libcall-taking flavor of GetSignature remains unsed
886 // other than here, just roll its logic into this version.
888  const char *Name,
891  auto &Map = LibcallNameMap->Map;
892  auto Val = Map.find(Name);
893 #ifndef NDEBUG
894  if (Val == Map.end()) {
895  auto message = std::string("unexpected runtime library name: ") + Name;
896  llvm_unreachable(message.c_str());
897  }
898 #endif
899  return getLibcallSignature(Subtarget, Val->second, Rets, Params);
900 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit...
iterator find(StringRef Key)
Definition: StringMap.h:355
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
void getLibcallSignature(const WebAssemblySubtarget &Subtarget, RTLIB::Libcall LC, SmallVectorImpl< wasm::ValType > &Rets, SmallVectorImpl< wasm::ValType > &Params)
This file provides signature information for runtime libcalls.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:242
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
static ManagedStatic< StaticLibcallNameMap > LibcallNameMap
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
OUTCHAIN = ATOMIC_STORE(INCHAIN, ptr, val) This corresponds to "store atomic" instruction.
Definition: ISDOpcodes.h:821
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
Definition: ISDOpcodes.h:817
iterator end()
Definition: StringMap.h:340