LLVM  9.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  i8_func_i8_i8,
55  func_f32_iPTR_iPTR,
56  func_f64_iPTR_iPTR,
57  i16_func_i16_i16,
58  i32_func_f32_f32,
59  i32_func_f64_f64,
60  i32_func_i32_i32,
61  i32_func_i32_i32_iPTR,
62  i64_func_i64_i64,
63  i64_func_i64_i64_iPTR,
64  i64_i64_func_f32,
65  i64_i64_func_f64,
66  i16_i16_func_i16_i16,
67  i32_i32_func_i32_i32,
68  i64_i64_func_i64_i64,
69  i64_i64_func_i64_i64_i64_i64,
70  i64_i64_func_i64_i64_i64_i64_iPTR,
71  i64_i64_i64_i64_func_i64_i64_i64_i64,
72  i64_i64_func_i64_i64_i32,
73  iPTR_func_iPTR_i32_iPTR,
74  iPTR_func_iPTR_iPTR_iPTR,
75  f32_func_f32_f32_f32,
76  f64_func_f64_f64_f64,
77  func_i64_i64_iPTR_iPTR,
78  func_iPTR_f32,
79  func_iPTR_f64,
80  func_iPTR_i32,
81  func_iPTR_i64,
82  func_iPTR_i64_i64,
83  func_iPTR_i64_i64_i64_i64,
84  func_iPTR_i64_i64_i64_i64_i64_i64,
85  i32_func_i64_i64,
86  i32_func_i64_i64_i64_i64,
87  unsupported
88 };
89 
90 struct RuntimeLibcallSignatureTable {
91  std::vector<RuntimeLibcallSignature> Table;
92 
93  // Any newly-added libcalls will be unsupported by default.
94  RuntimeLibcallSignatureTable() : Table(RTLIB::UNKNOWN_LIBCALL, unsupported) {
95  // Integer
96  Table[RTLIB::SHL_I16] = i16_func_i16_i16;
97  Table[RTLIB::SHL_I32] = i32_func_i32_i32;
98  Table[RTLIB::SHL_I64] = i64_func_i64_i64;
99  Table[RTLIB::SHL_I128] = i64_i64_func_i64_i64_i32;
100  Table[RTLIB::SRL_I16] = i16_func_i16_i16;
101  Table[RTLIB::SRL_I32] = i32_func_i32_i32;
102  Table[RTLIB::SRL_I64] = i64_func_i64_i64;
103  Table[RTLIB::SRL_I128] = i64_i64_func_i64_i64_i32;
104  Table[RTLIB::SRA_I16] = i16_func_i16_i16;
105  Table[RTLIB::SRA_I32] = i32_func_i32_i32;
106  Table[RTLIB::SRA_I64] = i64_func_i64_i64;
107  Table[RTLIB::SRA_I128] = i64_i64_func_i64_i64_i32;
108  Table[RTLIB::MUL_I8] = i8_func_i8_i8;
109  Table[RTLIB::MUL_I16] = i16_func_i16_i16;
110  Table[RTLIB::MUL_I32] = i32_func_i32_i32;
111  Table[RTLIB::MUL_I64] = i64_func_i64_i64;
112  Table[RTLIB::MUL_I128] = i64_i64_func_i64_i64_i64_i64;
113  Table[RTLIB::MULO_I32] = i32_func_i32_i32_iPTR;
114  Table[RTLIB::MULO_I64] = i64_func_i64_i64_iPTR;
115  Table[RTLIB::MULO_I128] = i64_i64_func_i64_i64_i64_i64_iPTR;
116  Table[RTLIB::SDIV_I8] = i8_func_i8_i8;
117  Table[RTLIB::SDIV_I16] = i16_func_i16_i16;
118  Table[RTLIB::SDIV_I32] = i32_func_i32_i32;
119  Table[RTLIB::SDIV_I64] = i64_func_i64_i64;
120  Table[RTLIB::SDIV_I128] = i64_i64_func_i64_i64_i64_i64;
121  Table[RTLIB::UDIV_I8] = i8_func_i8_i8;
122  Table[RTLIB::UDIV_I16] = i16_func_i16_i16;
123  Table[RTLIB::UDIV_I32] = i32_func_i32_i32;
124  Table[RTLIB::UDIV_I64] = i64_func_i64_i64;
125  Table[RTLIB::UDIV_I128] = i64_i64_func_i64_i64_i64_i64;
126  Table[RTLIB::SREM_I8] = i8_func_i8_i8;
127  Table[RTLIB::SREM_I16] = i16_func_i16_i16;
128  Table[RTLIB::SREM_I32] = i32_func_i32_i32;
129  Table[RTLIB::SREM_I64] = i64_func_i64_i64;
130  Table[RTLIB::SREM_I128] = i64_i64_func_i64_i64_i64_i64;
131  Table[RTLIB::UREM_I8] = i8_func_i8_i8;
132  Table[RTLIB::UREM_I16] = i16_func_i16_i16;
133  Table[RTLIB::UREM_I32] = i32_func_i32_i32;
134  Table[RTLIB::UREM_I64] = i64_func_i64_i64;
135  Table[RTLIB::UREM_I128] = i64_i64_func_i64_i64_i64_i64;
136  Table[RTLIB::SDIVREM_I8] = i8_func_i8_i8;
137  Table[RTLIB::SDIVREM_I16] = i16_i16_func_i16_i16;
138  Table[RTLIB::SDIVREM_I32] = i32_i32_func_i32_i32;
139  Table[RTLIB::SDIVREM_I64] = i64_func_i64_i64;
140  Table[RTLIB::SDIVREM_I128] = i64_i64_i64_i64_func_i64_i64_i64_i64;
141  Table[RTLIB::UDIVREM_I8] = i8_func_i8_i8;
142  Table[RTLIB::UDIVREM_I16] = i16_i16_func_i16_i16;
143  Table[RTLIB::UDIVREM_I32] = i32_i32_func_i32_i32;
144  Table[RTLIB::UDIVREM_I64] = i64_i64_func_i64_i64;
145  Table[RTLIB::UDIVREM_I128] = i64_i64_i64_i64_func_i64_i64_i64_i64;
146  Table[RTLIB::NEG_I32] = i32_func_i32;
147  Table[RTLIB::NEG_I64] = i64_func_i64;
148 
149  // Floating-point.
150  // All F80 and PPCF128 routines are unsupported.
151  Table[RTLIB::ADD_F32] = f32_func_f32_f32;
152  Table[RTLIB::ADD_F64] = f64_func_f64_f64;
153  Table[RTLIB::ADD_F128] = func_iPTR_i64_i64_i64_i64;
154  Table[RTLIB::SUB_F32] = f32_func_f32_f32;
155  Table[RTLIB::SUB_F64] = f64_func_f64_f64;
156  Table[RTLIB::SUB_F128] = func_iPTR_i64_i64_i64_i64;
157  Table[RTLIB::MUL_F32] = f32_func_f32_f32;
158  Table[RTLIB::MUL_F64] = f64_func_f64_f64;
159  Table[RTLIB::MUL_F128] = func_iPTR_i64_i64_i64_i64;
160  Table[RTLIB::DIV_F32] = f32_func_f32_f32;
161  Table[RTLIB::DIV_F64] = f64_func_f64_f64;
162  Table[RTLIB::DIV_F128] = func_iPTR_i64_i64_i64_i64;
163  Table[RTLIB::REM_F32] = f32_func_f32_f32;
164  Table[RTLIB::REM_F64] = f64_func_f64_f64;
165  Table[RTLIB::REM_F128] = func_iPTR_i64_i64_i64_i64;
166  Table[RTLIB::FMA_F32] = f32_func_f32_f32_f32;
167  Table[RTLIB::FMA_F64] = f64_func_f64_f64_f64;
168  Table[RTLIB::FMA_F128] = func_iPTR_i64_i64_i64_i64_i64_i64;
169  Table[RTLIB::POWI_F32] = f32_func_f32_i32;
170  Table[RTLIB::POWI_F64] = f64_func_f64_i32;
171  Table[RTLIB::POWI_F128] = func_iPTR_i64_i64_i64_i64;
172  Table[RTLIB::SQRT_F32] = f32_func_f32;
173  Table[RTLIB::SQRT_F64] = f64_func_f64;
174  Table[RTLIB::SQRT_F128] = func_iPTR_i64_i64;
175  Table[RTLIB::LOG_F32] = f32_func_f32;
176  Table[RTLIB::LOG_F64] = f64_func_f64;
177  Table[RTLIB::LOG_F128] = func_iPTR_i64_i64;
178  Table[RTLIB::LOG2_F32] = f32_func_f32;
179  Table[RTLIB::LOG2_F64] = f64_func_f64;
180  Table[RTLIB::LOG2_F128] = func_iPTR_i64_i64;
181  Table[RTLIB::LOG10_F32] = f32_func_f32;
182  Table[RTLIB::LOG10_F64] = f64_func_f64;
183  Table[RTLIB::LOG10_F128] = func_iPTR_i64_i64;
184  Table[RTLIB::EXP_F32] = f32_func_f32;
185  Table[RTLIB::EXP_F64] = f64_func_f64;
186  Table[RTLIB::EXP_F128] = func_iPTR_i64_i64;
187  Table[RTLIB::EXP2_F32] = f32_func_f32;
188  Table[RTLIB::EXP2_F64] = f64_func_f64;
189  Table[RTLIB::EXP2_F128] = func_iPTR_i64_i64;
190  Table[RTLIB::SIN_F32] = f32_func_f32;
191  Table[RTLIB::SIN_F64] = f64_func_f64;
192  Table[RTLIB::SIN_F128] = func_iPTR_i64_i64;
193  Table[RTLIB::COS_F32] = f32_func_f32;
194  Table[RTLIB::COS_F64] = f64_func_f64;
195  Table[RTLIB::COS_F128] = func_iPTR_i64_i64;
196  Table[RTLIB::SINCOS_F32] = func_f32_iPTR_iPTR;
197  Table[RTLIB::SINCOS_F64] = func_f64_iPTR_iPTR;
198  Table[RTLIB::SINCOS_F128] = func_i64_i64_iPTR_iPTR;
199  Table[RTLIB::POW_F32] = f32_func_f32_f32;
200  Table[RTLIB::POW_F64] = f64_func_f64_f64;
201  Table[RTLIB::POW_F128] = func_iPTR_i64_i64_i64_i64;
202  Table[RTLIB::CEIL_F32] = f32_func_f32;
203  Table[RTLIB::CEIL_F64] = f64_func_f64;
204  Table[RTLIB::CEIL_F128] = func_iPTR_i64_i64;
205  Table[RTLIB::TRUNC_F32] = f32_func_f32;
206  Table[RTLIB::TRUNC_F64] = f64_func_f64;
207  Table[RTLIB::TRUNC_F128] = func_iPTR_i64_i64;
208  Table[RTLIB::RINT_F32] = f32_func_f32;
209  Table[RTLIB::RINT_F64] = f64_func_f64;
210  Table[RTLIB::RINT_F128] = func_iPTR_i64_i64;
211  Table[RTLIB::NEARBYINT_F32] = f32_func_f32;
212  Table[RTLIB::NEARBYINT_F64] = f64_func_f64;
213  Table[RTLIB::NEARBYINT_F128] = func_iPTR_i64_i64;
214  Table[RTLIB::ROUND_F32] = f32_func_f32;
215  Table[RTLIB::ROUND_F64] = f64_func_f64;
216  Table[RTLIB::ROUND_F128] = func_iPTR_i64_i64;
217  Table[RTLIB::FLOOR_F32] = f32_func_f32;
218  Table[RTLIB::FLOOR_F64] = f64_func_f64;
219  Table[RTLIB::FLOOR_F128] = func_iPTR_i64_i64;
220  Table[RTLIB::COPYSIGN_F32] = f32_func_f32_f32;
221  Table[RTLIB::COPYSIGN_F64] = f64_func_f64_f64;
222  Table[RTLIB::COPYSIGN_F128] = func_iPTR_i64_i64_i64_i64;
223  Table[RTLIB::FMIN_F32] = f32_func_f32_f32;
224  Table[RTLIB::FMIN_F64] = f64_func_f64_f64;
225  Table[RTLIB::FMIN_F128] = func_iPTR_i64_i64_i64_i64;
226  Table[RTLIB::FMAX_F32] = f32_func_f32_f32;
227  Table[RTLIB::FMAX_F64] = f64_func_f64_f64;
228  Table[RTLIB::FMAX_F128] = func_iPTR_i64_i64_i64_i64;
229 
230  // Conversion
231  // All F80 and PPCF128 routines are unspported.
232  Table[RTLIB::FPEXT_F64_F128] = func_iPTR_f64;
233  Table[RTLIB::FPEXT_F32_F128] = func_iPTR_f32;
234  Table[RTLIB::FPEXT_F32_F64] = f64_func_f32;
235  Table[RTLIB::FPEXT_F16_F32] = f32_func_i16;
236  Table[RTLIB::FPROUND_F32_F16] = i16_func_f32;
237  Table[RTLIB::FPROUND_F64_F32] = f32_func_f64;
238  Table[RTLIB::FPROUND_F128_F32] = f32_func_i64_i64;
239  Table[RTLIB::FPROUND_F128_F64] = f64_func_i64_i64;
240  Table[RTLIB::FPTOSINT_F32_I32] = i32_func_f32;
241  Table[RTLIB::FPTOSINT_F32_I64] = i64_func_f32;
242  Table[RTLIB::FPTOSINT_F32_I128] = i64_i64_func_f32;
243  Table[RTLIB::FPTOSINT_F64_I32] = i32_func_f64;
244  Table[RTLIB::FPTOSINT_F64_I64] = i64_func_f64;
245  Table[RTLIB::FPTOSINT_F64_I128] = i64_i64_func_f64;
246  Table[RTLIB::FPTOSINT_F128_I32] = i32_func_i64_i64;
247  Table[RTLIB::FPTOSINT_F128_I64] = i64_func_i64_i64;
248  Table[RTLIB::FPTOSINT_F128_I128] = i64_i64_func_i64_i64;
249  Table[RTLIB::FPTOUINT_F32_I32] = i32_func_f32;
250  Table[RTLIB::FPTOUINT_F32_I64] = i64_func_f32;
251  Table[RTLIB::FPTOUINT_F32_I128] = i64_i64_func_f32;
252  Table[RTLIB::FPTOUINT_F64_I32] = i32_func_f64;
253  Table[RTLIB::FPTOUINT_F64_I64] = i64_func_f64;
254  Table[RTLIB::FPTOUINT_F64_I128] = i64_i64_func_f64;
255  Table[RTLIB::FPTOUINT_F128_I32] = i32_func_i64_i64;
256  Table[RTLIB::FPTOUINT_F128_I64] = i64_func_i64_i64;
257  Table[RTLIB::FPTOUINT_F128_I128] = i64_i64_func_i64_i64;
258  Table[RTLIB::SINTTOFP_I32_F32] = f32_func_i32;
259  Table[RTLIB::SINTTOFP_I32_F64] = f64_func_i32;
260  Table[RTLIB::SINTTOFP_I32_F128] = func_iPTR_i32;
261  Table[RTLIB::SINTTOFP_I64_F32] = f32_func_i64;
262  Table[RTLIB::SINTTOFP_I64_F64] = f64_func_i64;
263  Table[RTLIB::SINTTOFP_I64_F128] = func_iPTR_i64;
264  Table[RTLIB::SINTTOFP_I128_F32] = f32_func_i64_i64;
265  Table[RTLIB::SINTTOFP_I128_F64] = f64_func_i64_i64;
266  Table[RTLIB::SINTTOFP_I128_F128] = func_iPTR_i64_i64;
267  Table[RTLIB::UINTTOFP_I32_F32] = f32_func_i32;
268  Table[RTLIB::UINTTOFP_I32_F64] = f64_func_i64;
269  Table[RTLIB::UINTTOFP_I32_F128] = func_iPTR_i32;
270  Table[RTLIB::UINTTOFP_I64_F32] = f32_func_i64;
271  Table[RTLIB::UINTTOFP_I64_F64] = f64_func_i64;
272  Table[RTLIB::UINTTOFP_I64_F128] = func_iPTR_i64;
273  Table[RTLIB::UINTTOFP_I128_F32] = f32_func_i64_i64;
274  Table[RTLIB::UINTTOFP_I128_F64] = f64_func_i64_i64;
275  Table[RTLIB::UINTTOFP_I128_F128] = func_iPTR_i64_i64;
276 
277  // Comparison
278  // ALl F80 and PPCF128 routines are unsupported.
279  Table[RTLIB::OEQ_F32] = i32_func_f32_f32;
280  Table[RTLIB::OEQ_F64] = i32_func_f64_f64;
281  Table[RTLIB::OEQ_F128] = i32_func_i64_i64_i64_i64;
282  Table[RTLIB::UNE_F32] = i32_func_f32_f32;
283  Table[RTLIB::UNE_F64] = i32_func_f64_f64;
284  Table[RTLIB::UNE_F128] = i32_func_i64_i64_i64_i64;
285  Table[RTLIB::OGE_F32] = i32_func_f32_f32;
286  Table[RTLIB::OGE_F64] = i32_func_f64_f64;
287  Table[RTLIB::OGE_F128] = i32_func_i64_i64_i64_i64;
288  Table[RTLIB::OLT_F32] = i32_func_f32_f32;
289  Table[RTLIB::OLT_F64] = i32_func_f64_f64;
290  Table[RTLIB::OLT_F128] = i32_func_i64_i64_i64_i64;
291  Table[RTLIB::OLE_F32] = i32_func_f32_f32;
292  Table[RTLIB::OLE_F64] = i32_func_f64_f64;
293  Table[RTLIB::OLE_F128] = i32_func_i64_i64_i64_i64;
294  Table[RTLIB::OGT_F32] = i32_func_f32_f32;
295  Table[RTLIB::OGT_F64] = i32_func_f64_f64;
296  Table[RTLIB::OGT_F128] = i32_func_i64_i64_i64_i64;
297  Table[RTLIB::UO_F32] = i32_func_f32_f32;
298  Table[RTLIB::UO_F64] = i32_func_f64_f64;
299  Table[RTLIB::UO_F128] = i32_func_i64_i64_i64_i64;
300  // O_FXX has the weird property that it uses the same libcall name as UO_FXX
301  // This breaks our name-based lookup. Fortunately only the UO family of
302  // libcalls appears to be actually used.
303  Table[RTLIB::O_F32] = unsupported;
304  Table[RTLIB::O_F64] = unsupported;
305  Table[RTLIB::O_F128] = unsupported;
306 
307  // Memory
308  Table[RTLIB::MEMCPY] = iPTR_func_iPTR_iPTR_iPTR;
309  Table[RTLIB::MEMSET] = iPTR_func_iPTR_i32_iPTR;
310  Table[RTLIB::MEMMOVE] = iPTR_func_iPTR_iPTR_iPTR;
311 
312  // Element-wise Atomic memory
313  // TODO: Fix these when we implement atomic support
314  Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_1] = unsupported;
315  Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_2] = unsupported;
316  Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_4] = unsupported;
317  Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_8] = unsupported;
318  Table[RTLIB::MEMCPY_ELEMENT_UNORDERED_ATOMIC_16] = unsupported;
319  Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_1] = unsupported;
320  Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_2] = unsupported;
321  Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_4] = unsupported;
322  Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_8] = unsupported;
323  Table[RTLIB::MEMMOVE_ELEMENT_UNORDERED_ATOMIC_16] = unsupported;
324 
325  Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_1] = unsupported;
326  Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_2] = unsupported;
327  Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_4] = unsupported;
328  Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_8] = unsupported;
329  Table[RTLIB::MEMSET_ELEMENT_UNORDERED_ATOMIC_16] = unsupported;
330 
331  // Atomic '__sync_*' libcalls.
332  // TODO: Fix these when we implement atomic support
333  Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_1] = unsupported;
334  Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_2] = unsupported;
335  Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_4] = unsupported;
336  Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_8] = unsupported;
337  Table[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_16] = unsupported;
338  Table[RTLIB::SYNC_LOCK_TEST_AND_SET_1] = unsupported;
339  Table[RTLIB::SYNC_LOCK_TEST_AND_SET_2] = unsupported;
340  Table[RTLIB::SYNC_LOCK_TEST_AND_SET_4] = unsupported;
341  Table[RTLIB::SYNC_LOCK_TEST_AND_SET_8] = unsupported;
342  Table[RTLIB::SYNC_LOCK_TEST_AND_SET_16] = unsupported;
343  Table[RTLIB::SYNC_FETCH_AND_ADD_1] = unsupported;
344  Table[RTLIB::SYNC_FETCH_AND_ADD_2] = unsupported;
345  Table[RTLIB::SYNC_FETCH_AND_ADD_4] = unsupported;
346  Table[RTLIB::SYNC_FETCH_AND_ADD_8] = unsupported;
347  Table[RTLIB::SYNC_FETCH_AND_ADD_16] = unsupported;
348  Table[RTLIB::SYNC_FETCH_AND_SUB_1] = unsupported;
349  Table[RTLIB::SYNC_FETCH_AND_SUB_2] = unsupported;
350  Table[RTLIB::SYNC_FETCH_AND_SUB_4] = unsupported;
351  Table[RTLIB::SYNC_FETCH_AND_SUB_8] = unsupported;
352  Table[RTLIB::SYNC_FETCH_AND_SUB_16] = unsupported;
353  Table[RTLIB::SYNC_FETCH_AND_AND_1] = unsupported;
354  Table[RTLIB::SYNC_FETCH_AND_AND_2] = unsupported;
355  Table[RTLIB::SYNC_FETCH_AND_AND_4] = unsupported;
356  Table[RTLIB::SYNC_FETCH_AND_AND_8] = unsupported;
357  Table[RTLIB::SYNC_FETCH_AND_AND_16] = unsupported;
358  Table[RTLIB::SYNC_FETCH_AND_OR_1] = unsupported;
359  Table[RTLIB::SYNC_FETCH_AND_OR_2] = unsupported;
360  Table[RTLIB::SYNC_FETCH_AND_OR_4] = unsupported;
361  Table[RTLIB::SYNC_FETCH_AND_OR_8] = unsupported;
362  Table[RTLIB::SYNC_FETCH_AND_OR_16] = unsupported;
363  Table[RTLIB::SYNC_FETCH_AND_XOR_1] = unsupported;
364  Table[RTLIB::SYNC_FETCH_AND_XOR_2] = unsupported;
365  Table[RTLIB::SYNC_FETCH_AND_XOR_4] = unsupported;
366  Table[RTLIB::SYNC_FETCH_AND_XOR_8] = unsupported;
367  Table[RTLIB::SYNC_FETCH_AND_XOR_16] = unsupported;
368  Table[RTLIB::SYNC_FETCH_AND_NAND_1] = unsupported;
369  Table[RTLIB::SYNC_FETCH_AND_NAND_2] = unsupported;
370  Table[RTLIB::SYNC_FETCH_AND_NAND_4] = unsupported;
371  Table[RTLIB::SYNC_FETCH_AND_NAND_8] = unsupported;
372  Table[RTLIB::SYNC_FETCH_AND_NAND_16] = unsupported;
373  Table[RTLIB::SYNC_FETCH_AND_MAX_1] = unsupported;
374  Table[RTLIB::SYNC_FETCH_AND_MAX_2] = unsupported;
375  Table[RTLIB::SYNC_FETCH_AND_MAX_4] = unsupported;
376  Table[RTLIB::SYNC_FETCH_AND_MAX_8] = unsupported;
377  Table[RTLIB::SYNC_FETCH_AND_MAX_16] = unsupported;
378  Table[RTLIB::SYNC_FETCH_AND_UMAX_1] = unsupported;
379  Table[RTLIB::SYNC_FETCH_AND_UMAX_2] = unsupported;
380  Table[RTLIB::SYNC_FETCH_AND_UMAX_4] = unsupported;
381  Table[RTLIB::SYNC_FETCH_AND_UMAX_8] = unsupported;
382  Table[RTLIB::SYNC_FETCH_AND_UMAX_16] = unsupported;
383  Table[RTLIB::SYNC_FETCH_AND_MIN_1] = unsupported;
384  Table[RTLIB::SYNC_FETCH_AND_MIN_2] = unsupported;
385  Table[RTLIB::SYNC_FETCH_AND_MIN_4] = unsupported;
386  Table[RTLIB::SYNC_FETCH_AND_MIN_8] = unsupported;
387  Table[RTLIB::SYNC_FETCH_AND_MIN_16] = unsupported;
388  Table[RTLIB::SYNC_FETCH_AND_UMIN_1] = unsupported;
389  Table[RTLIB::SYNC_FETCH_AND_UMIN_2] = unsupported;
390  Table[RTLIB::SYNC_FETCH_AND_UMIN_4] = unsupported;
391  Table[RTLIB::SYNC_FETCH_AND_UMIN_8] = unsupported;
392  Table[RTLIB::SYNC_FETCH_AND_UMIN_16] = unsupported;
393 
394  // Atomic '__atomic_*' libcalls.
395  // TODO: Fix these when we implement atomic support
396  Table[RTLIB::ATOMIC_LOAD] = unsupported;
397  Table[RTLIB::ATOMIC_LOAD_1] = unsupported;
398  Table[RTLIB::ATOMIC_LOAD_2] = unsupported;
399  Table[RTLIB::ATOMIC_LOAD_4] = unsupported;
400  Table[RTLIB::ATOMIC_LOAD_8] = unsupported;
401  Table[RTLIB::ATOMIC_LOAD_16] = unsupported;
402 
403  Table[RTLIB::ATOMIC_STORE] = unsupported;
404  Table[RTLIB::ATOMIC_STORE_1] = unsupported;
405  Table[RTLIB::ATOMIC_STORE_2] = unsupported;
406  Table[RTLIB::ATOMIC_STORE_4] = unsupported;
407  Table[RTLIB::ATOMIC_STORE_8] = unsupported;
408  Table[RTLIB::ATOMIC_STORE_16] = unsupported;
409 
410  Table[RTLIB::ATOMIC_EXCHANGE] = unsupported;
411  Table[RTLIB::ATOMIC_EXCHANGE_1] = unsupported;
412  Table[RTLIB::ATOMIC_EXCHANGE_2] = unsupported;
413  Table[RTLIB::ATOMIC_EXCHANGE_4] = unsupported;
414  Table[RTLIB::ATOMIC_EXCHANGE_8] = unsupported;
415  Table[RTLIB::ATOMIC_EXCHANGE_16] = unsupported;
416 
417  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE] = unsupported;
418  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_1] = unsupported;
419  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_2] = unsupported;
420  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_4] = unsupported;
421  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_8] = unsupported;
422  Table[RTLIB::ATOMIC_COMPARE_EXCHANGE_16] = unsupported;
423 
424  Table[RTLIB::ATOMIC_FETCH_ADD_1] = unsupported;
425  Table[RTLIB::ATOMIC_FETCH_ADD_2] = unsupported;
426  Table[RTLIB::ATOMIC_FETCH_ADD_4] = unsupported;
427  Table[RTLIB::ATOMIC_FETCH_ADD_8] = unsupported;
428  Table[RTLIB::ATOMIC_FETCH_ADD_16] = unsupported;
429 
430  Table[RTLIB::ATOMIC_FETCH_SUB_1] = unsupported;
431  Table[RTLIB::ATOMIC_FETCH_SUB_2] = unsupported;
432  Table[RTLIB::ATOMIC_FETCH_SUB_4] = unsupported;
433  Table[RTLIB::ATOMIC_FETCH_SUB_8] = unsupported;
434  Table[RTLIB::ATOMIC_FETCH_SUB_16] = unsupported;
435 
436  Table[RTLIB::ATOMIC_FETCH_AND_1] = unsupported;
437  Table[RTLIB::ATOMIC_FETCH_AND_2] = unsupported;
438  Table[RTLIB::ATOMIC_FETCH_AND_4] = unsupported;
439  Table[RTLIB::ATOMIC_FETCH_AND_8] = unsupported;
440  Table[RTLIB::ATOMIC_FETCH_AND_16] = unsupported;
441 
442  Table[RTLIB::ATOMIC_FETCH_OR_1] = unsupported;
443  Table[RTLIB::ATOMIC_FETCH_OR_2] = unsupported;
444  Table[RTLIB::ATOMIC_FETCH_OR_4] = unsupported;
445  Table[RTLIB::ATOMIC_FETCH_OR_8] = unsupported;
446  Table[RTLIB::ATOMIC_FETCH_OR_16] = unsupported;
447 
448  Table[RTLIB::ATOMIC_FETCH_XOR_1] = unsupported;
449  Table[RTLIB::ATOMIC_FETCH_XOR_2] = unsupported;
450  Table[RTLIB::ATOMIC_FETCH_XOR_4] = unsupported;
451  Table[RTLIB::ATOMIC_FETCH_XOR_8] = unsupported;
452  Table[RTLIB::ATOMIC_FETCH_XOR_16] = unsupported;
453 
454  Table[RTLIB::ATOMIC_FETCH_NAND_1] = unsupported;
455  Table[RTLIB::ATOMIC_FETCH_NAND_2] = unsupported;
456  Table[RTLIB::ATOMIC_FETCH_NAND_4] = unsupported;
457  Table[RTLIB::ATOMIC_FETCH_NAND_8] = unsupported;
458  Table[RTLIB::ATOMIC_FETCH_NAND_16] = unsupported;
459  }
460 };
461 
462 ManagedStatic<RuntimeLibcallSignatureTable> RuntimeLibcallSignatures;
463 
464 // Maps libcall names to their RTLIB::Libcall number. Builds the map in a
465 // constructor for use with ManagedStatic
466 struct StaticLibcallNameMap {
468  StaticLibcallNameMap() {
469  static const std::pair<const char *, RTLIB::Libcall> NameLibcalls[] = {
470 #define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code},
471 #include "llvm/IR/RuntimeLibcalls.def"
472 #undef HANDLE_LIBCALL
473  };
474  for (const auto &NameLibcall : NameLibcalls) {
475  if (NameLibcall.first != nullptr &&
476  RuntimeLibcallSignatures->Table[NameLibcall.second] != unsupported) {
477  assert(Map.find(NameLibcall.first) == Map.end() &&
478  "duplicate libcall names in name map");
479  Map[NameLibcall.first] = NameLibcall.second;
480  }
481  }
482  }
483 };
484 
485 } // end anonymous namespace
486 
488  RTLIB::Libcall LC,
491  assert(Rets.empty());
492  assert(Params.empty());
493 
494  wasm::ValType PtrTy =
496 
497  auto &Table = RuntimeLibcallSignatures->Table;
498  switch (Table[LC]) {
499  case func:
500  break;
501  case f32_func_f32:
504  break;
505  case f32_func_f64:
508  break;
509  case f32_func_i32:
512  break;
513  case f32_func_i64:
516  break;
517  case f32_func_i16:
520  break;
521  case f64_func_f32:
524  break;
525  case f64_func_f64:
528  break;
529  case f64_func_i32:
532  break;
533  case f64_func_i64:
536  break;
537  case i32_func_f32:
540  break;
541  case i32_func_f64:
544  break;
545  case i32_func_i32:
548  break;
549  case i64_func_f32:
552  break;
553  case i64_func_f64:
556  break;
557  case i64_func_i64:
560  break;
561  case f32_func_f32_f32:
565  break;
566  case f32_func_f32_i32:
570  break;
571  case f32_func_i64_i64:
575  break;
576  case f64_func_f64_f64:
580  break;
581  case f64_func_f64_i32:
585  break;
586  case f64_func_i64_i64:
590  break;
591  case i16_func_f32:
594  break;
595  case i8_func_i8_i8:
599  break;
600  case func_f32_iPTR_iPTR:
602  Params.push_back(PtrTy);
603  Params.push_back(PtrTy);
604  break;
605  case func_f64_iPTR_iPTR:
607  Params.push_back(PtrTy);
608  Params.push_back(PtrTy);
609  break;
610  case i16_func_i16_i16:
614  break;
615  case i32_func_f32_f32:
619  break;
620  case i32_func_f64_f64:
624  break;
625  case i32_func_i32_i32:
629  break;
630  case i32_func_i32_i32_iPTR:
634  Params.push_back(PtrTy);
635  break;
636  case i64_func_i64_i64:
640  break;
641  case i64_func_i64_i64_iPTR:
645  Params.push_back(PtrTy);
646  break;
647  case i64_i64_func_f32:
648 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
651 #else
652  Params.push_back(PtrTy);
653 #endif
655  break;
656  case i64_i64_func_f64:
657 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
660 #else
661  Params.push_back(PtrTy);
662 #endif
664  break;
665  case i16_i16_func_i16_i16:
666 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
669 #else
670  Params.push_back(PtrTy);
671 #endif
674  break;
675  case i32_i32_func_i32_i32:
676 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
679 #else
680  Params.push_back(PtrTy);
681 #endif
684  break;
685  case i64_i64_func_i64_i64:
686 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
689 #else
690  Params.push_back(PtrTy);
691 #endif
694  break;
695  case i64_i64_func_i64_i64_i64_i64:
696 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
699 #else
700  Params.push_back(PtrTy);
701 #endif
706  break;
707  case i64_i64_func_i64_i64_i64_i64_iPTR:
708 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
711 #else
712  Params.push_back(PtrTy);
713 #endif
718  Params.push_back(PtrTy);
719  break;
720  case i64_i64_i64_i64_func_i64_i64_i64_i64:
721 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
726 #else
727  Params.push_back(PtrTy);
728 #endif
733  break;
734  case i64_i64_func_i64_i64_i32:
735 #if 0 // TODO: Enable this when wasm gets multiple-return-value support.
740 #else
741  Params.push_back(PtrTy);
742 #endif
746  break;
747  case iPTR_func_iPTR_i32_iPTR:
748  Rets.push_back(PtrTy);
749  Params.push_back(PtrTy);
751  Params.push_back(PtrTy);
752  break;
753  case iPTR_func_iPTR_iPTR_iPTR:
754  Rets.push_back(PtrTy);
755  Params.push_back(PtrTy);
756  Params.push_back(PtrTy);
757  Params.push_back(PtrTy);
758  break;
759  case f32_func_f32_f32_f32:
764  break;
765  case f64_func_f64_f64_f64:
770  break;
771  case func_i64_i64_iPTR_iPTR:
774  Params.push_back(PtrTy);
775  Params.push_back(PtrTy);
776  break;
777  case func_iPTR_f32:
778  Params.push_back(PtrTy);
780  break;
781  case func_iPTR_f64:
782  Params.push_back(PtrTy);
784  break;
785  case func_iPTR_i32:
786  Params.push_back(PtrTy);
788  break;
789  case func_iPTR_i64:
790  Params.push_back(PtrTy);
792  break;
793  case func_iPTR_i64_i64:
794  Params.push_back(PtrTy);
797  break;
798  case func_iPTR_i64_i64_i64_i64:
799  Params.push_back(PtrTy);
804  break;
805  case func_iPTR_i64_i64_i64_i64_i64_i64:
806  Params.push_back(PtrTy);
813  break;
814  case i32_func_i64_i64:
818  break;
819  case i32_func_i64_i64_i64_i64:
825  break;
826  case unsupported:
827  llvm_unreachable("unsupported runtime library signature");
828  }
829 }
830 
832 // TODO: If the RTLIB::Libcall-taking flavor of GetSignature remains unsed
833 // other than here, just roll its logic into this version.
835  const char *Name,
838  auto &Map = LibcallNameMap->Map;
839  auto Val = Map.find(Name);
840  assert(Val != Map.end() && "unexpected runtime library name");
841  return getLibcallSignature(Subtarget, Val->second, Rets, Params);
842 }
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:332
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:219
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:60
OUTCHAIN = ATOMIC_STORE(INCHAIN, ptr, val) This corresponds to "store atomic" instruction.
Definition: ISDOpcodes.h:793
Val, OUTCHAIN = ATOMIC_LOAD(INCHAIN, ptr) This corresponds to "load atomic" instruction.
Definition: ISDOpcodes.h:789
iterator end()
Definition: StringMap.h:317