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::ATAN2_F128, "atan2f128");
53 setLibcallName(RTLIB::SINH_F128, "sinhf128");
54 setLibcallName(RTLIB::COSH_F128, "coshf128");
55 setLibcallName(RTLIB::TANH_F128, "tanhf128");
56 setLibcallName(RTLIB::POW_F128, "powf128");
57 setLibcallName(RTLIB::POW_FINITE_F128, "__powf128_finite");
58 setLibcallName(RTLIB::CEIL_F128, "ceilf128");
59 setLibcallName(RTLIB::TRUNC_F128, "truncf128");
60 setLibcallName(RTLIB::RINT_F128, "rintf128");
61 setLibcallName(RTLIB::NEARBYINT_F128, "nearbyintf128");
62 setLibcallName(RTLIB::ROUND_F128, "roundf128");
63 setLibcallName(RTLIB::ROUNDEVEN_F128, "roundevenf128");
64 setLibcallName(RTLIB::FLOOR_F128, "floorf128");
65 setLibcallName(RTLIB::COPYSIGN_F128, "copysignf128");
66 setLibcallName(RTLIB::FMIN_F128, "fminf128");
67 setLibcallName(RTLIB::FMAX_F128, "fmaxf128");
68 setLibcallName(RTLIB::LROUND_F128, "lroundf128");
69 setLibcallName(RTLIB::LLROUND_F128, "llroundf128");
70 setLibcallName(RTLIB::LRINT_F128, "lrintf128");
71 setLibcallName(RTLIB::LLRINT_F128, "llrintf128");
72 setLibcallName(RTLIB::LDEXP_F128, "ldexpf128");
73 setLibcallName(RTLIB::FREXP_F128, "frexpf128");
74 }
75
76 // For IEEE quad-precision libcall names, PPC uses "kf" instead of "tf".
77 if (TT.isPPC()) {
78 setLibcallName(RTLIB::ADD_F128, "__addkf3");
79 setLibcallName(RTLIB::SUB_F128, "__subkf3");
80 setLibcallName(RTLIB::MUL_F128, "__mulkf3");
81 setLibcallName(RTLIB::DIV_F128, "__divkf3");
82 setLibcallName(RTLIB::POWI_F128, "__powikf2");
83 setLibcallName(RTLIB::FPEXT_F32_F128, "__extendsfkf2");
84 setLibcallName(RTLIB::FPEXT_F64_F128, "__extenddfkf2");
85 setLibcallName(RTLIB::FPROUND_F128_F32, "__trunckfsf2");
86 setLibcallName(RTLIB::FPROUND_F128_F64, "__trunckfdf2");
87 setLibcallName(RTLIB::FPTOSINT_F128_I32, "__fixkfsi");
88 setLibcallName(RTLIB::FPTOSINT_F128_I64, "__fixkfdi");
89 setLibcallName(RTLIB::FPTOSINT_F128_I128, "__fixkfti");
90 setLibcallName(RTLIB::FPTOUINT_F128_I32, "__fixunskfsi");
91 setLibcallName(RTLIB::FPTOUINT_F128_I64, "__fixunskfdi");
92 setLibcallName(RTLIB::FPTOUINT_F128_I128, "__fixunskfti");
93 setLibcallName(RTLIB::SINTTOFP_I32_F128, "__floatsikf");
94 setLibcallName(RTLIB::SINTTOFP_I64_F128, "__floatdikf");
95 setLibcallName(RTLIB::SINTTOFP_I128_F128, "__floattikf");
96 setLibcallName(RTLIB::UINTTOFP_I32_F128, "__floatunsikf");
97 setLibcallName(RTLIB::UINTTOFP_I64_F128, "__floatundikf");
98 setLibcallName(RTLIB::UINTTOFP_I128_F128, "__floatuntikf");
99 setLibcallName(RTLIB::OEQ_F128, "__eqkf2");
100 setLibcallName(RTLIB::UNE_F128, "__nekf2");
101 setLibcallName(RTLIB::OGE_F128, "__gekf2");
102 setLibcallName(RTLIB::OLT_F128, "__ltkf2");
103 setLibcallName(RTLIB::OLE_F128, "__lekf2");
104 setLibcallName(RTLIB::OGT_F128, "__gtkf2");
105 setLibcallName(RTLIB::UO_F128, "__unordkf2");
106 }
107
108 // A few names are different on particular architectures or environments.
109 if (TT.isOSDarwin()) {
110 // For f16/f32 conversions, Darwin uses the standard naming scheme,
111 // instead of the gnueabi-style __gnu_*_ieee.
112 // FIXME: What about other targets?
113 setLibcallName(RTLIB::FPEXT_F16_F32, "__extendhfsf2");
114 setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");
115
116 // Some darwins have an optimized __bzero/bzero function.
117 switch (TT.getArch()) {
118 case Triple::x86:
119 case Triple::x86_64:
120 if (TT.isMacOSX() && !TT.isMacOSXVersionLT(10, 6))
121 setLibcallName(RTLIB::BZERO, "__bzero");
122 break;
123 case Triple::aarch64:
125 setLibcallName(RTLIB::BZERO, "bzero");
126 break;
127 default:
128 break;
129 }
130
131 if (darwinHasSinCos(TT)) {
132 setLibcallName(RTLIB::SINCOS_STRET_F32, "__sincosf_stret");
133 setLibcallName(RTLIB::SINCOS_STRET_F64, "__sincos_stret");
134 if (TT.isWatchABI()) {
135 setLibcallCallingConv(RTLIB::SINCOS_STRET_F32,
137 setLibcallCallingConv(RTLIB::SINCOS_STRET_F64,
139 }
140 }
141
142 switch (TT.getOS()) {
143 case Triple::MacOSX:
144 if (TT.isMacOSXVersionLT(10, 9)) {
145 setLibcallName(RTLIB::EXP10_F32, nullptr);
146 setLibcallName(RTLIB::EXP10_F64, nullptr);
147 } else {
148 setLibcallName(RTLIB::EXP10_F32, "__exp10f");
149 setLibcallName(RTLIB::EXP10_F64, "__exp10");
150 }
151 break;
152 case Triple::IOS:
153 if (TT.isOSVersionLT(7, 0)) {
154 setLibcallName(RTLIB::EXP10_F32, nullptr);
155 setLibcallName(RTLIB::EXP10_F64, nullptr);
156 break;
157 }
158 [[fallthrough]];
160 case Triple::TvOS:
161 case Triple::WatchOS:
162 case Triple::XROS:
163 setLibcallName(RTLIB::EXP10_F32, "__exp10f");
164 setLibcallName(RTLIB::EXP10_F64, "__exp10");
165 break;
166 default:
167 break;
168 }
169 } else if (TT.getOS() == Triple::BridgeOS) {
170 // TODO: BridgeOS should be included in isOSDarwin.
171 setLibcallName(RTLIB::EXP10_F32, "__exp10f");
172 setLibcallName(RTLIB::EXP10_F64, "__exp10");
173 } else {
174 setLibcallName(RTLIB::FPEXT_F16_F32, "__gnu_h2f_ieee");
175 setLibcallName(RTLIB::FPROUND_F32_F16, "__gnu_f2h_ieee");
176 }
177
178 if (TT.isGNUEnvironment() || TT.isOSFuchsia() ||
179 (TT.isAndroid() && !TT.isAndroidVersionLT(9))) {
180 setLibcallName(RTLIB::SINCOS_F32, "sincosf");
181 setLibcallName(RTLIB::SINCOS_F64, "sincos");
182 setLibcallName(RTLIB::SINCOS_F80, "sincosl");
183 setLibcallName(RTLIB::SINCOS_F128, "sincosl");
184 setLibcallName(RTLIB::SINCOS_PPCF128, "sincosl");
185 }
186
187 if (TT.isPS()) {
188 setLibcallName(RTLIB::SINCOS_F32, "sincosf");
189 setLibcallName(RTLIB::SINCOS_F64, "sincos");
190 }
191
192 if (TT.isOSOpenBSD()) {
193 setLibcallName(RTLIB::STACKPROTECTOR_CHECK_FAIL, nullptr);
194 }
195
196 if (TT.isOSWindows() && !TT.isOSCygMing()) {
197 setLibcallName(RTLIB::LDEXP_F32, nullptr);
198 setLibcallName(RTLIB::LDEXP_F80, nullptr);
199 setLibcallName(RTLIB::LDEXP_F128, nullptr);
200 setLibcallName(RTLIB::LDEXP_PPCF128, nullptr);
201
202 setLibcallName(RTLIB::FREXP_F32, nullptr);
203 setLibcallName(RTLIB::FREXP_F80, nullptr);
204 setLibcallName(RTLIB::FREXP_F128, nullptr);
205 setLibcallName(RTLIB::FREXP_PPCF128, nullptr);
206 }
207
208 // Disable most libcalls on AMDGPU.
209 if (TT.isAMDGPU()) {
210 for (int I = 0; I < RTLIB::UNKNOWN_LIBCALL; ++I) {
211 if (I < RTLIB::ATOMIC_LOAD || I > RTLIB::ATOMIC_FETCH_NAND_16)
212 setLibcallName(static_cast<RTLIB::Libcall>(I), nullptr);
213 }
214 }
215
216 // Disable most libcalls on NVPTX.
217 if (TT.isNVPTX()) {
218 for (int I = 0; I < RTLIB::UNKNOWN_LIBCALL; ++I)
219 if (I < RTLIB::ATOMIC_LOAD || I > RTLIB::ATOMIC_FETCH_NAND_16)
220 setLibcallName(static_cast<RTLIB::Libcall>(I), nullptr);
221 }
222
223 if (TT.isOSMSVCRT()) {
224 // MSVCRT doesn't have powi; fall back to pow
225 setLibcallName(RTLIB::POWI_F32, nullptr);
226 setLibcallName(RTLIB::POWI_F64, nullptr);
227 }
228
229 if (TT.getArch() == Triple::ArchType::avr) {
230 // Division rtlib functions (not supported), use divmod functions instead
231 setLibcallName(RTLIB::SDIV_I8, nullptr);
232 setLibcallName(RTLIB::SDIV_I16, nullptr);
233 setLibcallName(RTLIB::SDIV_I32, nullptr);
234 setLibcallName(RTLIB::UDIV_I8, nullptr);
235 setLibcallName(RTLIB::UDIV_I16, nullptr);
236 setLibcallName(RTLIB::UDIV_I32, nullptr);
237
238 // Modulus rtlib functions (not supported), use divmod functions instead
239 setLibcallName(RTLIB::SREM_I8, nullptr);
240 setLibcallName(RTLIB::SREM_I16, nullptr);
241 setLibcallName(RTLIB::SREM_I32, nullptr);
242 setLibcallName(RTLIB::UREM_I8, nullptr);
243 setLibcallName(RTLIB::UREM_I16, nullptr);
244 setLibcallName(RTLIB::UREM_I32, nullptr);
245 }
246
247 if (!TT.isWasm()) {
248 // These libcalls are only available in compiler-rt, not libgcc.
249 if (TT.isArch32Bit()) {
250 setLibcallName(RTLIB::SHL_I128, nullptr);
251 setLibcallName(RTLIB::SRL_I128, nullptr);
252 setLibcallName(RTLIB::SRA_I128, nullptr);
253 setLibcallName(RTLIB::MUL_I128, nullptr);
254 setLibcallName(RTLIB::MULO_I64, nullptr);
255 }
256 setLibcallName(RTLIB::MULO_I128, nullptr);
257 }
258}
#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.