LLVM 20.0.0git
RuntimeLibcalls.cpp
Go to the documentation of this file.
1//===- RuntimeLibcalls.cpp - Interface for runtime libcalls -----*- 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
10
11using namespace llvm;
12using namespace RTLIB;
13
14/// Set default libcall names. If a target wants to opt-out of a libcall it
15/// should be placed here.
16void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
17 std::fill(std::begin(LibcallRoutineNames), std::end(LibcallRoutineNames),
18 nullptr);
19
20#define HANDLE_LIBCALL(code, name) setLibcallName(RTLIB::code, name);
21#include "llvm/IR/RuntimeLibcalls.def"
22#undef HANDLE_LIBCALL
23
24 // Initialize calling conventions to their default.
25 for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC)
27
28 // Use the f128 variants of math functions on x86_64
29 if (TT.getArch() == Triple::ArchType::x86_64 && TT.isGNUEnvironment()) {
30 setLibcallName(RTLIB::REM_F128, "fmodf128");
31 setLibcallName(RTLIB::FMA_F128, "fmaf128");
32 setLibcallName(RTLIB::SQRT_F128, "sqrtf128");
33 setLibcallName(RTLIB::CBRT_F128, "cbrtf128");
34 setLibcallName(RTLIB::LOG_F128, "logf128");
35 setLibcallName(RTLIB::LOG_FINITE_F128, "__logf128_finite");
36 setLibcallName(RTLIB::LOG2_F128, "log2f128");
37 setLibcallName(RTLIB::LOG2_FINITE_F128, "__log2f128_finite");
38 setLibcallName(RTLIB::LOG10_F128, "log10f128");
39 setLibcallName(RTLIB::LOG10_FINITE_F128, "__log10f128_finite");
40 setLibcallName(RTLIB::EXP_F128, "expf128");
41 setLibcallName(RTLIB::EXP_FINITE_F128, "__expf128_finite");
42 setLibcallName(RTLIB::EXP2_F128, "exp2f128");
43 setLibcallName(RTLIB::EXP2_FINITE_F128, "__exp2f128_finite");
44 setLibcallName(RTLIB::EXP10_F128, "exp10f128");
45 setLibcallName(RTLIB::SIN_F128, "sinf128");
46 setLibcallName(RTLIB::COS_F128, "cosf128");
47 setLibcallName(RTLIB::TAN_F128, "tanf128");
48 setLibcallName(RTLIB::SINCOS_F128, "sincosf128");
49 setLibcallName(RTLIB::ASIN_F128, "asinf128");
50 setLibcallName(RTLIB::ACOS_F128, "acosf128");
51 setLibcallName(RTLIB::ATAN_F128, "atanf128");
52 setLibcallName(RTLIB::SINH_F128, "sinhf128");
53 setLibcallName(RTLIB::COSH_F128, "coshf128");
54 setLibcallName(RTLIB::TANH_F128, "tanhf128");
55 setLibcallName(RTLIB::POW_F128, "powf128");
56 setLibcallName(RTLIB::POW_FINITE_F128, "__powf128_finite");
57 setLibcallName(RTLIB::CEIL_F128, "ceilf128");
58 setLibcallName(RTLIB::TRUNC_F128, "truncf128");
59 setLibcallName(RTLIB::RINT_F128, "rintf128");
60 setLibcallName(RTLIB::NEARBYINT_F128, "nearbyintf128");
61 setLibcallName(RTLIB::ROUND_F128, "roundf128");
62 setLibcallName(RTLIB::ROUNDEVEN_F128, "roundevenf128");
63 setLibcallName(RTLIB::FLOOR_F128, "floorf128");
64 setLibcallName(RTLIB::COPYSIGN_F128, "copysignf128");
65 setLibcallName(RTLIB::FMIN_F128, "fminf128");
66 setLibcallName(RTLIB::FMAX_F128, "fmaxf128");
67 setLibcallName(RTLIB::LROUND_F128, "lroundf128");
68 setLibcallName(RTLIB::LLROUND_F128, "llroundf128");
69 setLibcallName(RTLIB::LRINT_F128, "lrintf128");
70 setLibcallName(RTLIB::LLRINT_F128, "llrintf128");
71 setLibcallName(RTLIB::LDEXP_F128, "ldexpf128");
72 setLibcallName(RTLIB::FREXP_F128, "frexpf128");
73 }
74
75 // For IEEE quad-precision libcall names, PPC uses "kf" instead of "tf".
76 if (TT.isPPC()) {
77 setLibcallName(RTLIB::ADD_F128, "__addkf3");
78 setLibcallName(RTLIB::SUB_F128, "__subkf3");
79 setLibcallName(RTLIB::MUL_F128, "__mulkf3");
80 setLibcallName(RTLIB::DIV_F128, "__divkf3");
81 setLibcallName(RTLIB::POWI_F128, "__powikf2");
82 setLibcallName(RTLIB::FPEXT_F32_F128, "__extendsfkf2");
83 setLibcallName(RTLIB::FPEXT_F64_F128, "__extenddfkf2");
84 setLibcallName(RTLIB::FPROUND_F128_F32, "__trunckfsf2");
85 setLibcallName(RTLIB::FPROUND_F128_F64, "__trunckfdf2");
86 setLibcallName(RTLIB::FPTOSINT_F128_I32, "__fixkfsi");
87 setLibcallName(RTLIB::FPTOSINT_F128_I64, "__fixkfdi");
88 setLibcallName(RTLIB::FPTOSINT_F128_I128, "__fixkfti");
89 setLibcallName(RTLIB::FPTOUINT_F128_I32, "__fixunskfsi");
90 setLibcallName(RTLIB::FPTOUINT_F128_I64, "__fixunskfdi");
91 setLibcallName(RTLIB::FPTOUINT_F128_I128, "__fixunskfti");
92 setLibcallName(RTLIB::SINTTOFP_I32_F128, "__floatsikf");
93 setLibcallName(RTLIB::SINTTOFP_I64_F128, "__floatdikf");
94 setLibcallName(RTLIB::SINTTOFP_I128_F128, "__floattikf");
95 setLibcallName(RTLIB::UINTTOFP_I32_F128, "__floatunsikf");
96 setLibcallName(RTLIB::UINTTOFP_I64_F128, "__floatundikf");
97 setLibcallName(RTLIB::UINTTOFP_I128_F128, "__floatuntikf");
98 setLibcallName(RTLIB::OEQ_F128, "__eqkf2");
99 setLibcallName(RTLIB::UNE_F128, "__nekf2");
100 setLibcallName(RTLIB::OGE_F128, "__gekf2");
101 setLibcallName(RTLIB::OLT_F128, "__ltkf2");
102 setLibcallName(RTLIB::OLE_F128, "__lekf2");
103 setLibcallName(RTLIB::OGT_F128, "__gtkf2");
104 setLibcallName(RTLIB::UO_F128, "__unordkf2");
105 }
106
107 // A few names are different on particular architectures or environments.
108 if (TT.isOSDarwin()) {
109 // For f16/f32 conversions, Darwin uses the standard naming scheme,
110 // instead of the gnueabi-style __gnu_*_ieee.
111 // FIXME: What about other targets?
112 setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
113 setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
114
115 // Some darwins have an optimized __bzero/bzero function.
116 switch (TT.getArch()) {
117 case Triple::x86:
118 case Triple::x86_64:
119 if (TT.isMacOSX() && !TT.isMacOSXVersionLT(10, 6))
120 setLibcallName(RTLIB::BZERO, "__bzero");
121 break;
122 case Triple::aarch64:
124 setLibcallName(RTLIB::BZERO, "bzero");
125 break;
126 default:
127 break;
128 }
129
130 if (darwinHasSinCos(TT)) {
131 setLibcallName(RTLIB::SINCOS_STRET_F32, "__sincosf_stret");
132 setLibcallName(RTLIB::SINCOS_STRET_F64, "__sincos_stret");
133 if (TT.isWatchABI()) {
134 setLibcallCallingConv(RTLIB::SINCOS_STRET_F32,
136 setLibcallCallingConv(RTLIB::SINCOS_STRET_F64,
138 }
139 }
140
141 switch (TT.getOS()) {
142 case Triple::MacOSX:
143 if (TT.isMacOSXVersionLT(10, 9)) {
144 setLibcallName(RTLIB::EXP10_F32, nullptr);
145 setLibcallName(RTLIB::EXP10_F64, nullptr);
146 } else {
147 setLibcallName(RTLIB::EXP10_F32, "__exp10f");
148 setLibcallName(RTLIB::EXP10_F64, "__exp10");
149 }
150 break;
151 case Triple::IOS:
152 if (TT.isOSVersionLT(7, 0)) {
153 setLibcallName(RTLIB::EXP10_F32, nullptr);
154 setLibcallName(RTLIB::EXP10_F64, nullptr);
155 break;
156 }
157 [[fallthrough]];
159 case Triple::TvOS:
160 case Triple::WatchOS:
161 case Triple::XROS:
162 setLibcallName(RTLIB::EXP10_F32, "__exp10f");
163 setLibcallName(RTLIB::EXP10_F64, "__exp10");
164 break;
165 default:
166 break;
167 }
168 } else if (TT.getOS() == Triple::BridgeOS) {
169 // TODO: BridgeOS should be included in isOSDarwin.
170 setLibcallName(RTLIB::EXP10_F32, "__exp10f");
171 setLibcallName(RTLIB::EXP10_F64, "__exp10");
172 } else {
173 setLibcallName(RTLIB::FPEXT_F16_F32, "__gnu_h2f_ieee");
174 setLibcallName(RTLIB::FPROUND_F32_F16, "__gnu_f2h_ieee");
175 }
176
177 if (TT.isGNUEnvironment() || TT.isOSFuchsia() ||
178 (TT.isAndroid() && !TT.isAndroidVersionLT(9))) {
179 setLibcallName(RTLIB::SINCOS_F32, "sincosf");
180 setLibcallName(RTLIB::SINCOS_F64, "sincos");
181 setLibcallName(RTLIB::SINCOS_F80, "sincosl");
182 setLibcallName(RTLIB::SINCOS_F128, "sincosl");
183 setLibcallName(RTLIB::SINCOS_PPCF128, "sincosl");
184 }
185
186 if (TT.isPS()) {
187 setLibcallName(RTLIB::SINCOS_F32, "sincosf");
188 setLibcallName(RTLIB::SINCOS_F64, "sincos");
189 }
190
191 if (TT.isOSOpenBSD()) {
192 setLibcallName(RTLIB::STACKPROTECTOR_CHECK_FAIL, nullptr);
193 }
194
195 if (TT.isOSWindows() && !TT.isOSCygMing()) {
196 setLibcallName(RTLIB::LDEXP_F32, nullptr);
197 setLibcallName(RTLIB::LDEXP_F80, nullptr);
198 setLibcallName(RTLIB::LDEXP_F128, nullptr);
199 setLibcallName(RTLIB::LDEXP_PPCF128, nullptr);
200
201 setLibcallName(RTLIB::FREXP_F32, nullptr);
202 setLibcallName(RTLIB::FREXP_F80, nullptr);
203 setLibcallName(RTLIB::FREXP_F128, nullptr);
204 setLibcallName(RTLIB::FREXP_PPCF128, nullptr);
205 }
206
207 if (TT.isAArch64()) {
208 if (TT.isOSMSVCRT()) {
209 // MSVCRT doesn't have powi; fall back to pow
210 setLibcallName(RTLIB::POWI_F32, nullptr);
211 setLibcallName(RTLIB::POWI_F64, nullptr);
212 }
213 }
214
215 // Disable most libcalls on AMDGPU.
216 if (TT.isAMDGPU()) {
217 for (int I = 0; I < RTLIB::UNKNOWN_LIBCALL; ++I) {
218 if (I < RTLIB::ATOMIC_LOAD || I > RTLIB::ATOMIC_FETCH_NAND_16)
219 setLibcallName(static_cast<RTLIB::Libcall>(I), nullptr);
220 }
221 }
222
223 // Disable most libcalls on NVPTX.
224 if (TT.isNVPTX()) {
225 for (int I = 0; I < RTLIB::UNKNOWN_LIBCALL; ++I)
226 if (I < RTLIB::ATOMIC_LOAD || I > RTLIB::ATOMIC_FETCH_NAND_16)
227 setLibcallName(static_cast<RTLIB::Libcall>(I), nullptr);
228 }
229
230 if (TT.isARM() || TT.isThumb()) {
231 // These libcalls are not available in 32-bit.
232 setLibcallName(RTLIB::SHL_I128, nullptr);
233 setLibcallName(RTLIB::SRL_I128, nullptr);
234 setLibcallName(RTLIB::SRA_I128, nullptr);
235 setLibcallName(RTLIB::MUL_I128, nullptr);
236 setLibcallName(RTLIB::MULO_I64, nullptr);
237 setLibcallName(RTLIB::MULO_I128, nullptr);
238
239 if (TT.isOSMSVCRT()) {
240 // MSVCRT doesn't have powi; fall back to pow
241 setLibcallName(RTLIB::POWI_F32, nullptr);
242 setLibcallName(RTLIB::POWI_F64, nullptr);
243 }
244 }
245
246 if (TT.getArch() == Triple::ArchType::avr) {
247 // Division rtlib functions (not supported), use divmod functions instead
248 setLibcallName(RTLIB::SDIV_I8, nullptr);
249 setLibcallName(RTLIB::SDIV_I16, nullptr);
250 setLibcallName(RTLIB::SDIV_I32, nullptr);
251 setLibcallName(RTLIB::UDIV_I8, nullptr);
252 setLibcallName(RTLIB::UDIV_I16, nullptr);
253 setLibcallName(RTLIB::UDIV_I32, nullptr);
254
255 // Modulus rtlib functions (not supported), use divmod functions instead
256 setLibcallName(RTLIB::SREM_I8, nullptr);
257 setLibcallName(RTLIB::SREM_I16, nullptr);
258 setLibcallName(RTLIB::SREM_I32, nullptr);
259 setLibcallName(RTLIB::UREM_I8, nullptr);
260 setLibcallName(RTLIB::UREM_I16, nullptr);
261 setLibcallName(RTLIB::UREM_I32, nullptr);
262 }
263
264 if (TT.getArch() == Triple::ArchType::hexagon) {
265 // These cause problems when the shift amount is non-constant.
266 setLibcallName(RTLIB::SHL_I128, nullptr);
267 setLibcallName(RTLIB::SRL_I128, nullptr);
268 setLibcallName(RTLIB::SRA_I128, nullptr);
269 }
270
271 if (TT.isLoongArch()) {
272 if (!TT.isLoongArch64()) {
273 // Set libcalls.
274 setLibcallName(RTLIB::MUL_I128, nullptr);
275 // The MULO libcall is not part of libgcc, only compiler-rt.
276 setLibcallName(RTLIB::MULO_I64, nullptr);
277 }
278 // The MULO libcall is not part of libgcc, only compiler-rt.
279 setLibcallName(RTLIB::MULO_I128, nullptr);
280 }
281
282 if (TT.isMIPS32()) {
283 // These libcalls are not available in 32-bit.
284 setLibcallName(RTLIB::SHL_I128, nullptr);
285 setLibcallName(RTLIB::SRL_I128, nullptr);
286 setLibcallName(RTLIB::SRA_I128, nullptr);
287 setLibcallName(RTLIB::MUL_I128, nullptr);
288 setLibcallName(RTLIB::MULO_I64, nullptr);
289 setLibcallName(RTLIB::MULO_I128, nullptr);
290 }
291
292 if (TT.isPPC()) {
293 if (!TT.isPPC64()) {
294 // These libcalls are not available in 32-bit.
295 setLibcallName(RTLIB::SHL_I128, nullptr);
296 setLibcallName(RTLIB::SRL_I128, nullptr);
297 setLibcallName(RTLIB::SRA_I128, nullptr);
298 setLibcallName(RTLIB::MUL_I128, nullptr);
299 setLibcallName(RTLIB::MULO_I64, nullptr);
300 }
301 setLibcallName(RTLIB::MULO_I128, nullptr);
302 }
303
304 if (TT.isRISCV32()) {
305 // These libcalls are not available in 32-bit.
306 setLibcallName(RTLIB::SHL_I128, nullptr);
307 setLibcallName(RTLIB::SRL_I128, nullptr);
308 setLibcallName(RTLIB::SRA_I128, nullptr);
309 setLibcallName(RTLIB::MUL_I128, nullptr);
310 setLibcallName(RTLIB::MULO_I64, nullptr);
311 }
312
313 if (TT.isSPARC()) {
314 if (!TT.isSPARC64()) {
315 // These libcalls are not available in 32-bit.
316 setLibcallName(RTLIB::MULO_I64, nullptr);
317 setLibcallName(RTLIB::MUL_I128, nullptr);
318 setLibcallName(RTLIB::SHL_I128, nullptr);
319 setLibcallName(RTLIB::SRL_I128, nullptr);
320 setLibcallName(RTLIB::SRA_I128, nullptr);
321 }
322 setLibcallName(RTLIB::MULO_I128, nullptr);
323 }
324
325 if (TT.isSystemZ()) {
326 setLibcallName(RTLIB::SRL_I128, nullptr);
327 setLibcallName(RTLIB::SHL_I128, nullptr);
328 setLibcallName(RTLIB::SRA_I128, nullptr);
329 }
330
331 if (TT.isX86()) {
332 if (TT.getArch() == Triple::ArchType::x86) {
333 // These libcalls are not available in 32-bit.
334 setLibcallName(RTLIB::SHL_I128, nullptr);
335 setLibcallName(RTLIB::SRL_I128, nullptr);
336 setLibcallName(RTLIB::SRA_I128, nullptr);
337 setLibcallName(RTLIB::MUL_I128, nullptr);
338 // The MULO libcall is not part of libgcc, only compiler-rt.
339 setLibcallName(RTLIB::MULO_I64, nullptr);
340 }
341
342 // The MULO libcall is not part of libgcc, only compiler-rt.
343 setLibcallName(RTLIB::MULO_I128, nullptr);
344
345 if (TT.isOSMSVCRT()) {
346 // MSVCRT doesn't have powi; fall back to pow
347 setLibcallName(RTLIB::POWI_F32, nullptr);
348 setLibcallName(RTLIB::POWI_F64, nullptr);
349 }
350 }
351}
#define I(x, y, z)
Definition: MD5.cpp:58
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
@ aarch64_32
Definition: Triple.h:53
@ ARM_AAPCS_VFP
Same as ARM_AAPCS, but uses hard floating point ABI.
Definition: CallingConv.h:114
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
Libcall
RTLIB::Libcall enum - This enum defines all of the runtime library calls the backend can emit.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void setLibcallName(RTLIB::Libcall Call, const char *Name)
Rename the default libcall routine name for the specified libcall.
void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC)
Set the CallingConv that should be used for the specified libcall.