blob: 7a2e0b02ac9bf179ff78fd257e2f57930c2cdcf8 [file] [log] [blame]
Chris Lattner0e125bb2011-02-18 21:50:34 +00001//===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the TargetLibraryInfo class.
11//
12//===----------------------------------------------------------------------===//
13
Chandler Carruth62d42152015-01-15 02:16:27 +000014#include "llvm/Analysis/TargetLibraryInfo.h"
Chris Lattner0e125bb2011-02-18 21:50:34 +000015#include "llvm/ADT/Triple.h"
Matthias Braun50ec0b52017-05-19 22:37:09 +000016#include "llvm/IR/Constants.h"
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +000017#include "llvm/Support/CommandLine.h"
Chris Lattner0e125bb2011-02-18 21:50:34 +000018using namespace llvm;
19
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +000020static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
21 "vector-library", cl::Hidden, cl::desc("Vector functions library"),
22 cl::init(TargetLibraryInfoImpl::NoLibrary),
23 cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
24 "No vector functions library"),
25 clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
26 "Accelerate framework"),
Matt Mastena6669a12016-07-29 16:42:44 +000027 clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
Joel Jones5f533c52018-11-24 06:41:39 +000028 "Intel SVML library"),
29 clEnumValN(TargetLibraryInfoImpl::SLEEFGNUABI, "sleefgnuabi",
30 "SIMD Library for Evaluating Elementary Functions")));
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +000031
Mehdi Amini9a72cd72016-10-01 03:10:48 +000032StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
Jan Wen Voungcd3d25a2015-03-03 23:41:58 +000033#define TLI_DEFINE_STRING
34#include "llvm/Analysis/TargetLibraryInfo.def"
Benjamin Kramer57a3d082015-03-08 16:07:39 +000035};
Eli Friedman489c0ff2011-11-17 01:27:36 +000036
Bob Wilsond8d92d92013-11-03 06:48:38 +000037static bool hasSinCosPiStret(const Triple &T) {
38 // Only Darwin variants have _stret versions of combined trig functions.
Bob Wilson9868d712014-10-09 05:43:30 +000039 if (!T.isOSDarwin())
Bob Wilsond8d92d92013-11-03 06:48:38 +000040 return false;
41
42 // The ABI is rather complicated on x86, so don't do anything special there.
43 if (T.getArch() == Triple::x86)
44 return false;
45
46 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
47 return false;
48
Bob Wilson9868d712014-10-09 05:43:30 +000049 if (T.isiOS() && T.isOSVersionLT(7, 0))
Bob Wilsond8d92d92013-11-03 06:48:38 +000050 return false;
51
52 return true;
53}
54
Sanjay Patel600d24b2017-12-15 18:54:29 +000055/// Initialize the set of available library functions based on the specified
56/// target triple. This should be carefully written so that a missing target
57/// triple gets a sane set of defaults.
Chandler Carruthc0291862015-01-24 02:06:09 +000058static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
Mehdi Amini9a72cd72016-10-01 03:10:48 +000059 ArrayRef<StringRef> StandardNames) {
Bob Wilsonc740e3f2012-08-03 04:06:22 +000060 // Verify that the StandardNames array is in alphabetical order.
Craig Toppere30b8ca2016-01-03 19:43:40 +000061 assert(std::is_sorted(StandardNames.begin(), StandardNames.end(),
Mehdi Amini9a72cd72016-10-01 03:10:48 +000062 [](StringRef LHS, StringRef RHS) {
63 return LHS < RHS;
Craig Toppere30b8ca2016-01-03 19:43:40 +000064 }) &&
65 "TargetLibraryInfoImpl function names must be sorted");
Tom Stellard36a03182014-04-02 19:53:29 +000066
David Bolvanskyca22d422018-05-16 11:39:52 +000067 // Set IO unlocked variants as unavailable
68 // Set them as available per system below
69 TLI.setUnavailable(LibFunc_getchar_unlocked);
70 TLI.setUnavailable(LibFunc_putc_unlocked);
71 TLI.setUnavailable(LibFunc_putchar_unlocked);
72 TLI.setUnavailable(LibFunc_fputc_unlocked);
73 TLI.setUnavailable(LibFunc_fgetc_unlocked);
74 TLI.setUnavailable(LibFunc_fread_unlocked);
75 TLI.setUnavailable(LibFunc_fwrite_unlocked);
76 TLI.setUnavailable(LibFunc_fputs_unlocked);
77 TLI.setUnavailable(LibFunc_fgets_unlocked);
78
Marcin Koscielnicki6af8e6c2016-11-21 20:20:39 +000079 bool ShouldExtI32Param = false, ShouldExtI32Return = false,
80 ShouldSignExtI32Param = false;
81 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
82 // returns corresponding to C-level ints and unsigned ints.
83 if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le ||
84 T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) {
85 ShouldExtI32Param = true;
86 ShouldExtI32Return = true;
87 }
88 // Mips, on the other hand, needs signext on i32 parameters corresponding
89 // to both signed and unsigned ints.
Alexander Richardson85e200e2018-06-25 16:49:20 +000090 if (T.isMIPS()) {
Marcin Koscielnicki6af8e6c2016-11-21 20:20:39 +000091 ShouldSignExtI32Param = true;
92 }
93 TLI.setShouldExtI32Param(ShouldExtI32Param);
94 TLI.setShouldExtI32Return(ShouldExtI32Return);
95 TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
96
Nicolai Hahnle78fd4f02015-12-15 17:24:15 +000097 if (T.getArch() == Triple::r600 ||
98 T.getArch() == Triple::amdgcn) {
David L. Jonesd21529f2017-01-23 23:16:46 +000099 TLI.setUnavailable(LibFunc_ldexp);
100 TLI.setUnavailable(LibFunc_ldexpf);
101 TLI.setUnavailable(LibFunc_ldexpl);
102 TLI.setUnavailable(LibFunc_exp10);
103 TLI.setUnavailable(LibFunc_exp10f);
104 TLI.setUnavailable(LibFunc_exp10l);
105 TLI.setUnavailable(LibFunc_log10);
106 TLI.setUnavailable(LibFunc_log10f);
107 TLI.setUnavailable(LibFunc_log10l);
Nicolai Hahnle78fd4f02015-12-15 17:24:15 +0000108 }
109
Tom Stellardd00a9232015-01-07 01:17:37 +0000110 // There are no library implementations of mempcy and memset for AMD gpus and
Tom Stellard36a03182014-04-02 19:53:29 +0000111 // these can be difficult to lower in the backend.
Tom Stellardd00a9232015-01-07 01:17:37 +0000112 if (T.getArch() == Triple::r600 ||
Dan Gohman05532992016-01-19 14:49:23 +0000113 T.getArch() == Triple::amdgcn) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000114 TLI.setUnavailable(LibFunc_memcpy);
115 TLI.setUnavailable(LibFunc_memset);
116 TLI.setUnavailable(LibFunc_memset_pattern16);
Tom Stellard36a03182014-04-02 19:53:29 +0000117 return;
118 }
119
Nico Weberad156922014-03-07 18:08:54 +0000120 // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
Tim Northover8b403662015-10-28 22:51:16 +0000121 // All versions of watchOS support it.
Daniel Dunbarcd01ed52011-04-20 00:14:25 +0000122 if (T.isMacOSX()) {
David Bolvanskyca22d422018-05-16 11:39:52 +0000123 // available IO unlocked variants on Mac OS X
124 TLI.setAvailable(LibFunc_getc_unlocked);
125 TLI.setAvailable(LibFunc_getchar_unlocked);
126 TLI.setAvailable(LibFunc_putc_unlocked);
127 TLI.setAvailable(LibFunc_putchar_unlocked);
128
Daniel Dunbarcd01ed52011-04-20 00:14:25 +0000129 if (T.isMacOSXVersionLT(10, 5))
David L. Jonesd21529f2017-01-23 23:16:46 +0000130 TLI.setUnavailable(LibFunc_memset_pattern16);
Cameron Esfahani943908b2013-08-29 20:23:14 +0000131 } else if (T.isiOS()) {
Daniel Dunbar9483bb62011-04-19 20:44:08 +0000132 if (T.isOSVersionLT(3, 0))
David L. Jonesd21529f2017-01-23 23:16:46 +0000133 TLI.setUnavailable(LibFunc_memset_pattern16);
Tim Northover8b403662015-10-28 22:51:16 +0000134 } else if (!T.isWatchOS()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000135 TLI.setUnavailable(LibFunc_memset_pattern16);
Daniel Dunbar9483bb62011-04-19 20:44:08 +0000136 }
Richard Osborne815de532011-03-03 13:17:51 +0000137
Bob Wilsond8d92d92013-11-03 06:48:38 +0000138 if (!hasSinCosPiStret(T)) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000139 TLI.setUnavailable(LibFunc_sinpi);
140 TLI.setUnavailable(LibFunc_sinpif);
141 TLI.setUnavailable(LibFunc_cospi);
142 TLI.setUnavailable(LibFunc_cospif);
143 TLI.setUnavailable(LibFunc_sincospi_stret);
144 TLI.setUnavailable(LibFunc_sincospif_stret);
Bob Wilsond8d92d92013-11-03 06:48:38 +0000145 }
146
Eli Friedman489c0ff2011-11-17 01:27:36 +0000147 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
148 !T.isMacOSXVersionLT(10, 7)) {
149 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
150 // we don't care about) have two versions; on recent OSX, the one we want
151 // has a $UNIX2003 suffix. The two implementations are identical except
152 // for the return value in some edge cases. However, we don't want to
153 // generate code that depends on the old symbols.
David L. Jonesd21529f2017-01-23 23:16:46 +0000154 TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
155 TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
Eli Friedman489c0ff2011-11-17 01:27:36 +0000156 }
157
Duncan Sandseeb50c82011-06-09 11:11:45 +0000158 // iprintf and friends are only available on XCore and TCE.
159 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000160 TLI.setUnavailable(LibFunc_iprintf);
161 TLI.setUnavailable(LibFunc_siprintf);
162 TLI.setUnavailable(LibFunc_fiprintf);
Richard Osborne2dfb8882011-03-03 14:09:28 +0000163 }
Joe Groffa81bcbb2012-04-17 23:05:54 +0000164
Saleem Abdulrasool8dc8fb12014-07-24 22:09:06 +0000165 if (T.isOSWindows() && !T.isOSCygMing()) {
Joe Groffa81bcbb2012-04-17 23:05:54 +0000166 // Win32 does not support long double
David L. Jonesd21529f2017-01-23 23:16:46 +0000167 TLI.setUnavailable(LibFunc_acosl);
168 TLI.setUnavailable(LibFunc_asinl);
169 TLI.setUnavailable(LibFunc_atanl);
170 TLI.setUnavailable(LibFunc_atan2l);
171 TLI.setUnavailable(LibFunc_ceill);
172 TLI.setUnavailable(LibFunc_copysignl);
173 TLI.setUnavailable(LibFunc_cosl);
174 TLI.setUnavailable(LibFunc_coshl);
175 TLI.setUnavailable(LibFunc_expl);
176 TLI.setUnavailable(LibFunc_fabsf); // Win32 and Win64 both lack fabsf
177 TLI.setUnavailable(LibFunc_fabsl);
178 TLI.setUnavailable(LibFunc_floorl);
179 TLI.setUnavailable(LibFunc_fmaxl);
180 TLI.setUnavailable(LibFunc_fminl);
181 TLI.setUnavailable(LibFunc_fmodl);
182 TLI.setUnavailable(LibFunc_frexpl);
183 TLI.setUnavailable(LibFunc_ldexpf);
184 TLI.setUnavailable(LibFunc_ldexpl);
185 TLI.setUnavailable(LibFunc_logl);
186 TLI.setUnavailable(LibFunc_modfl);
187 TLI.setUnavailable(LibFunc_powl);
188 TLI.setUnavailable(LibFunc_sinl);
189 TLI.setUnavailable(LibFunc_sinhl);
190 TLI.setUnavailable(LibFunc_sqrtl);
191 TLI.setUnavailable(LibFunc_tanl);
192 TLI.setUnavailable(LibFunc_tanhl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000193
194 // Win32 only has C89 math
David L. Jonesd21529f2017-01-23 23:16:46 +0000195 TLI.setUnavailable(LibFunc_acosh);
196 TLI.setUnavailable(LibFunc_acoshf);
197 TLI.setUnavailable(LibFunc_acoshl);
198 TLI.setUnavailable(LibFunc_asinh);
199 TLI.setUnavailable(LibFunc_asinhf);
200 TLI.setUnavailable(LibFunc_asinhl);
201 TLI.setUnavailable(LibFunc_atanh);
202 TLI.setUnavailable(LibFunc_atanhf);
203 TLI.setUnavailable(LibFunc_atanhl);
Hal Finkel2ff24732017-12-16 01:26:25 +0000204 TLI.setUnavailable(LibFunc_cabs);
205 TLI.setUnavailable(LibFunc_cabsf);
206 TLI.setUnavailable(LibFunc_cabsl);
David L. Jonesd21529f2017-01-23 23:16:46 +0000207 TLI.setUnavailable(LibFunc_cbrt);
208 TLI.setUnavailable(LibFunc_cbrtf);
209 TLI.setUnavailable(LibFunc_cbrtl);
210 TLI.setUnavailable(LibFunc_exp2);
211 TLI.setUnavailable(LibFunc_exp2f);
212 TLI.setUnavailable(LibFunc_exp2l);
213 TLI.setUnavailable(LibFunc_expm1);
214 TLI.setUnavailable(LibFunc_expm1f);
215 TLI.setUnavailable(LibFunc_expm1l);
216 TLI.setUnavailable(LibFunc_log2);
217 TLI.setUnavailable(LibFunc_log2f);
218 TLI.setUnavailable(LibFunc_log2l);
219 TLI.setUnavailable(LibFunc_log1p);
220 TLI.setUnavailable(LibFunc_log1pf);
221 TLI.setUnavailable(LibFunc_log1pl);
222 TLI.setUnavailable(LibFunc_logb);
223 TLI.setUnavailable(LibFunc_logbf);
224 TLI.setUnavailable(LibFunc_logbl);
225 TLI.setUnavailable(LibFunc_nearbyint);
226 TLI.setUnavailable(LibFunc_nearbyintf);
227 TLI.setUnavailable(LibFunc_nearbyintl);
228 TLI.setUnavailable(LibFunc_rint);
229 TLI.setUnavailable(LibFunc_rintf);
230 TLI.setUnavailable(LibFunc_rintl);
231 TLI.setUnavailable(LibFunc_round);
232 TLI.setUnavailable(LibFunc_roundf);
233 TLI.setUnavailable(LibFunc_roundl);
234 TLI.setUnavailable(LibFunc_trunc);
235 TLI.setUnavailable(LibFunc_truncf);
236 TLI.setUnavailable(LibFunc_truncl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000237
238 // Win32 provides some C99 math with mangled names
David L. Jonesd21529f2017-01-23 23:16:46 +0000239 TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
Joe Groffa81bcbb2012-04-17 23:05:54 +0000240
241 if (T.getArch() == Triple::x86) {
242 // Win32 on x86 implements single-precision math functions as macros
David L. Jonesd21529f2017-01-23 23:16:46 +0000243 TLI.setUnavailable(LibFunc_acosf);
244 TLI.setUnavailable(LibFunc_asinf);
245 TLI.setUnavailable(LibFunc_atanf);
246 TLI.setUnavailable(LibFunc_atan2f);
247 TLI.setUnavailable(LibFunc_ceilf);
248 TLI.setUnavailable(LibFunc_copysignf);
249 TLI.setUnavailable(LibFunc_cosf);
250 TLI.setUnavailable(LibFunc_coshf);
251 TLI.setUnavailable(LibFunc_expf);
252 TLI.setUnavailable(LibFunc_floorf);
253 TLI.setUnavailable(LibFunc_fminf);
254 TLI.setUnavailable(LibFunc_fmaxf);
255 TLI.setUnavailable(LibFunc_fmodf);
256 TLI.setUnavailable(LibFunc_logf);
257 TLI.setUnavailable(LibFunc_log10f);
258 TLI.setUnavailable(LibFunc_modff);
259 TLI.setUnavailable(LibFunc_powf);
260 TLI.setUnavailable(LibFunc_sinf);
261 TLI.setUnavailable(LibFunc_sinhf);
262 TLI.setUnavailable(LibFunc_sqrtf);
263 TLI.setUnavailable(LibFunc_tanf);
264 TLI.setUnavailable(LibFunc_tanhf);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000265 }
Meador Inge2526a422012-11-10 03:11:06 +0000266
Fangrui Song956ee792018-03-30 22:22:31 +0000267 // Win32 does *not* provide these functions, but they are
Meador Ingeb904e6e2013-03-05 21:47:40 +0000268 // generally available on POSIX-compliant systems:
David L. Jonesd21529f2017-01-23 23:16:46 +0000269 TLI.setUnavailable(LibFunc_access);
270 TLI.setUnavailable(LibFunc_bcmp);
271 TLI.setUnavailable(LibFunc_bcopy);
272 TLI.setUnavailable(LibFunc_bzero);
273 TLI.setUnavailable(LibFunc_chmod);
274 TLI.setUnavailable(LibFunc_chown);
275 TLI.setUnavailable(LibFunc_closedir);
276 TLI.setUnavailable(LibFunc_ctermid);
277 TLI.setUnavailable(LibFunc_fdopen);
278 TLI.setUnavailable(LibFunc_ffs);
279 TLI.setUnavailable(LibFunc_fileno);
280 TLI.setUnavailable(LibFunc_flockfile);
281 TLI.setUnavailable(LibFunc_fseeko);
282 TLI.setUnavailable(LibFunc_fstat);
283 TLI.setUnavailable(LibFunc_fstatvfs);
284 TLI.setUnavailable(LibFunc_ftello);
285 TLI.setUnavailable(LibFunc_ftrylockfile);
286 TLI.setUnavailable(LibFunc_funlockfile);
David L. Jonesd21529f2017-01-23 23:16:46 +0000287 TLI.setUnavailable(LibFunc_getitimer);
288 TLI.setUnavailable(LibFunc_getlogin_r);
289 TLI.setUnavailable(LibFunc_getpwnam);
290 TLI.setUnavailable(LibFunc_gettimeofday);
291 TLI.setUnavailable(LibFunc_htonl);
292 TLI.setUnavailable(LibFunc_htons);
293 TLI.setUnavailable(LibFunc_lchown);
294 TLI.setUnavailable(LibFunc_lstat);
295 TLI.setUnavailable(LibFunc_memccpy);
296 TLI.setUnavailable(LibFunc_mkdir);
297 TLI.setUnavailable(LibFunc_ntohl);
298 TLI.setUnavailable(LibFunc_ntohs);
299 TLI.setUnavailable(LibFunc_open);
300 TLI.setUnavailable(LibFunc_opendir);
301 TLI.setUnavailable(LibFunc_pclose);
302 TLI.setUnavailable(LibFunc_popen);
303 TLI.setUnavailable(LibFunc_pread);
304 TLI.setUnavailable(LibFunc_pwrite);
305 TLI.setUnavailable(LibFunc_read);
306 TLI.setUnavailable(LibFunc_readlink);
307 TLI.setUnavailable(LibFunc_realpath);
308 TLI.setUnavailable(LibFunc_rmdir);
309 TLI.setUnavailable(LibFunc_setitimer);
310 TLI.setUnavailable(LibFunc_stat);
311 TLI.setUnavailable(LibFunc_statvfs);
312 TLI.setUnavailable(LibFunc_stpcpy);
313 TLI.setUnavailable(LibFunc_stpncpy);
314 TLI.setUnavailable(LibFunc_strcasecmp);
315 TLI.setUnavailable(LibFunc_strncasecmp);
316 TLI.setUnavailable(LibFunc_times);
317 TLI.setUnavailable(LibFunc_uname);
318 TLI.setUnavailable(LibFunc_unlink);
319 TLI.setUnavailable(LibFunc_unsetenv);
320 TLI.setUnavailable(LibFunc_utime);
321 TLI.setUnavailable(LibFunc_utimes);
322 TLI.setUnavailable(LibFunc_write);
Meador Inge780a1862012-11-22 15:36:42 +0000323
Meador Ingeb904e6e2013-03-05 21:47:40 +0000324 // Win32 does *not* provide provide these functions, but they are
325 // specified by C99:
David L. Jonesd21529f2017-01-23 23:16:46 +0000326 TLI.setUnavailable(LibFunc_atoll);
327 TLI.setUnavailable(LibFunc_frexpf);
328 TLI.setUnavailable(LibFunc_llabs);
Meador Inge780a1862012-11-22 15:36:42 +0000329 }
330
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000331 switch (T.getOS()) {
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000332 case Triple::MacOSX:
Chandler Carruthf5689f82013-12-28 02:40:19 +0000333 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
334 // and their names are __exp10 and __exp10f. exp10l is not available on
335 // OS X or iOS.
David L. Jonesd21529f2017-01-23 23:16:46 +0000336 TLI.setUnavailable(LibFunc_exp10l);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000337 if (T.isMacOSXVersionLT(10, 9)) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000338 TLI.setUnavailable(LibFunc_exp10);
339 TLI.setUnavailable(LibFunc_exp10f);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000340 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000341 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
342 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000343 }
344 break;
345 case Triple::IOS:
Tim Northover89a6eef2015-11-02 18:00:00 +0000346 case Triple::TvOS:
Tim Northover8b403662015-10-28 22:51:16 +0000347 case Triple::WatchOS:
David L. Jonesd21529f2017-01-23 23:16:46 +0000348 TLI.setUnavailable(LibFunc_exp10l);
Tim Northover8b403662015-10-28 22:51:16 +0000349 if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
350 (T.isOSVersionLT(9, 0) &&
351 (T.getArch() == Triple::x86 ||
352 T.getArch() == Triple::x86_64)))) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000353 TLI.setUnavailable(LibFunc_exp10);
354 TLI.setUnavailable(LibFunc_exp10f);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000355 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000356 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
357 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000358 }
359 break;
Chandler Carruthf5689f82013-12-28 02:40:19 +0000360 case Triple::Linux:
361 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
362 // buggy prior to glibc version 2.18. Until this version is widely deployed
363 // or we have a reasonable detection strategy, we cannot use exp10 reliably
364 // on Linux.
365 //
366 // Fall through to disable all of them.
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000367 LLVM_FALLTHROUGH;
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000368 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000369 TLI.setUnavailable(LibFunc_exp10);
370 TLI.setUnavailable(LibFunc_exp10f);
371 TLI.setUnavailable(LibFunc_exp10l);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000372 }
373
Meador Inge780a1862012-11-22 15:36:42 +0000374 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
375 // Linux (GLIBC):
376 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
Davide Italiano83b34812015-11-01 17:00:13 +0000377 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
Meador Inge780a1862012-11-22 15:36:42 +0000378 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
379 switch (T.getOS()) {
380 case Triple::Darwin:
381 case Triple::MacOSX:
382 case Triple::IOS:
Tim Northover89a6eef2015-11-02 18:00:00 +0000383 case Triple::TvOS:
Tim Northover8b403662015-10-28 22:51:16 +0000384 case Triple::WatchOS:
Meador Inge780a1862012-11-22 15:36:42 +0000385 case Triple::FreeBSD:
386 case Triple::Linux:
387 break;
388 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000389 TLI.setUnavailable(LibFunc_ffsl);
Meador Inge780a1862012-11-22 15:36:42 +0000390 }
391
392 // ffsll is available on at least FreeBSD and Linux (GLIBC):
Davide Italiano83b34812015-11-01 17:00:13 +0000393 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
Meador Inge780a1862012-11-22 15:36:42 +0000394 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
395 switch (T.getOS()) {
Tim Northover89a6eef2015-11-02 18:00:00 +0000396 case Triple::Darwin:
397 case Triple::MacOSX:
398 case Triple::IOS:
399 case Triple::TvOS:
400 case Triple::WatchOS:
Meador Inge780a1862012-11-22 15:36:42 +0000401 case Triple::FreeBSD:
402 case Triple::Linux:
403 break;
404 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000405 TLI.setUnavailable(LibFunc_ffsll);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000406 }
Meador Ingeb904e6e2013-03-05 21:47:40 +0000407
Davide Italianobfd30822015-11-09 23:23:20 +0000408 // The following functions are available on at least FreeBSD:
409 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
410 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
411 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
412 if (!T.isOSFreeBSD()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000413 TLI.setUnavailable(LibFunc_fls);
414 TLI.setUnavailable(LibFunc_flsl);
415 TLI.setUnavailable(LibFunc_flsll);
Davide Italianobfd30822015-11-09 23:23:20 +0000416 }
417
Eli Friedmane3a5fc62018-11-06 18:23:32 +0000418 // The following functions are only available on GNU/Linux (using glibc).
419 // Linux variants without glibc (eg: bionic, musl) may have some subset.
420 if (!T.isOSLinux() || !T.isGNUEnvironment()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000421 TLI.setUnavailable(LibFunc_dunder_strdup);
422 TLI.setUnavailable(LibFunc_dunder_strtok_r);
423 TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
424 TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
425 TLI.setUnavailable(LibFunc_under_IO_getc);
426 TLI.setUnavailable(LibFunc_under_IO_putc);
Eli Friedmane3a5fc62018-11-06 18:23:32 +0000427 // But, Android and musl have memalign.
428 if (!T.isAndroid() && !T.isMusl())
Chih-Hung Hsieh60d1e792018-01-31 19:12:50 +0000429 TLI.setUnavailable(LibFunc_memalign);
David L. Jonesd21529f2017-01-23 23:16:46 +0000430 TLI.setUnavailable(LibFunc_fopen64);
431 TLI.setUnavailable(LibFunc_fseeko64);
432 TLI.setUnavailable(LibFunc_fstat64);
433 TLI.setUnavailable(LibFunc_fstatvfs64);
434 TLI.setUnavailable(LibFunc_ftello64);
435 TLI.setUnavailable(LibFunc_lstat64);
436 TLI.setUnavailable(LibFunc_open64);
437 TLI.setUnavailable(LibFunc_stat64);
438 TLI.setUnavailable(LibFunc_statvfs64);
439 TLI.setUnavailable(LibFunc_tmpfile64);
Sanjay Patel52149f02018-01-08 17:38:09 +0000440
441 // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
442 TLI.setUnavailable(LibFunc_acos_finite);
443 TLI.setUnavailable(LibFunc_acosf_finite);
444 TLI.setUnavailable(LibFunc_acosl_finite);
445 TLI.setUnavailable(LibFunc_acosh_finite);
446 TLI.setUnavailable(LibFunc_acoshf_finite);
447 TLI.setUnavailable(LibFunc_acoshl_finite);
448 TLI.setUnavailable(LibFunc_asin_finite);
449 TLI.setUnavailable(LibFunc_asinf_finite);
450 TLI.setUnavailable(LibFunc_asinl_finite);
451 TLI.setUnavailable(LibFunc_atan2_finite);
452 TLI.setUnavailable(LibFunc_atan2f_finite);
453 TLI.setUnavailable(LibFunc_atan2l_finite);
454 TLI.setUnavailable(LibFunc_atanh_finite);
455 TLI.setUnavailable(LibFunc_atanhf_finite);
456 TLI.setUnavailable(LibFunc_atanhl_finite);
457 TLI.setUnavailable(LibFunc_cosh_finite);
458 TLI.setUnavailable(LibFunc_coshf_finite);
459 TLI.setUnavailable(LibFunc_coshl_finite);
460 TLI.setUnavailable(LibFunc_exp10_finite);
461 TLI.setUnavailable(LibFunc_exp10f_finite);
462 TLI.setUnavailable(LibFunc_exp10l_finite);
463 TLI.setUnavailable(LibFunc_exp2_finite);
464 TLI.setUnavailable(LibFunc_exp2f_finite);
465 TLI.setUnavailable(LibFunc_exp2l_finite);
466 TLI.setUnavailable(LibFunc_exp_finite);
467 TLI.setUnavailable(LibFunc_expf_finite);
468 TLI.setUnavailable(LibFunc_expl_finite);
469 TLI.setUnavailable(LibFunc_log10_finite);
470 TLI.setUnavailable(LibFunc_log10f_finite);
471 TLI.setUnavailable(LibFunc_log10l_finite);
472 TLI.setUnavailable(LibFunc_log2_finite);
473 TLI.setUnavailable(LibFunc_log2f_finite);
474 TLI.setUnavailable(LibFunc_log2l_finite);
475 TLI.setUnavailable(LibFunc_log_finite);
476 TLI.setUnavailable(LibFunc_logf_finite);
477 TLI.setUnavailable(LibFunc_logl_finite);
478 TLI.setUnavailable(LibFunc_pow_finite);
479 TLI.setUnavailable(LibFunc_powf_finite);
480 TLI.setUnavailable(LibFunc_powl_finite);
481 TLI.setUnavailable(LibFunc_sinh_finite);
482 TLI.setUnavailable(LibFunc_sinhf_finite);
483 TLI.setUnavailable(LibFunc_sinhl_finite);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000484 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000485
Martin Storsjoc1078872018-05-17 08:16:08 +0000486 if ((T.isOSLinux() && T.isGNUEnvironment()) ||
487 (T.isAndroid() && !T.isAndroidVersionLT(28))) {
David Bolvanskyca22d422018-05-16 11:39:52 +0000488 // available IO unlocked variants on GNU/Linux and Android P or later
489 TLI.setAvailable(LibFunc_getc_unlocked);
490 TLI.setAvailable(LibFunc_getchar_unlocked);
491 TLI.setAvailable(LibFunc_putc_unlocked);
492 TLI.setAvailable(LibFunc_putchar_unlocked);
493 TLI.setAvailable(LibFunc_fputc_unlocked);
494 TLI.setAvailable(LibFunc_fgetc_unlocked);
495 TLI.setAvailable(LibFunc_fread_unlocked);
496 TLI.setAvailable(LibFunc_fwrite_unlocked);
497 TLI.setAvailable(LibFunc_fputs_unlocked);
498 TLI.setAvailable(LibFunc_fgets_unlocked);
499 }
500
Justin Lebar51132882016-01-26 23:51:06 +0000501 // As currently implemented in clang, NVPTX code has no standard library to
502 // speak of. Headers provide a standard-ish library implementation, but many
503 // of the signatures are wrong -- for example, many libm functions are not
504 // extern "C".
505 //
506 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
507 // but only used functions are provided to llvm. Moreover, most of the
508 // functions in libdevice don't map precisely to standard library functions.
509 //
510 // FIXME: Having no standard library prevents e.g. many fastmath
511 // optimizations, so this situation should be fixed.
David Majnemerae272d72016-03-31 21:29:57 +0000512 if (T.isNVPTX()) {
Justin Lebar51132882016-01-26 23:51:06 +0000513 TLI.disableAllFunctions();
David L. Jonesd21529f2017-01-23 23:16:46 +0000514 TLI.setAvailable(LibFunc_nvvm_reflect);
David Majnemerae272d72016-03-31 21:29:57 +0000515 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000516 TLI.setUnavailable(LibFunc_nvvm_reflect);
David Majnemerae272d72016-03-31 21:29:57 +0000517 }
Justin Lebar51132882016-01-26 23:51:06 +0000518
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000519 TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000520}
521
Chandler Carruthc0291862015-01-24 02:06:09 +0000522TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000523 // Default to everything being available.
524 memset(AvailableArray, -1, sizeof(AvailableArray));
525
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000526 initialize(*this, Triple(), StandardNames);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000527}
528
Joel Jones5f533c52018-11-24 06:41:39 +0000529TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T)
530 : TT(T) {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000531 // Default to everything being available.
532 memset(AvailableArray, -1, sizeof(AvailableArray));
Chandler Carruthb98f63d2015-01-15 10:41:28 +0000533
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000534 initialize(*this, T, StandardNames);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000535}
Chris Lattner1341df92011-02-18 22:34:03 +0000536
Chandler Carruthc0291862015-01-24 02:06:09 +0000537TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
Joel Jones5f533c52018-11-24 06:41:39 +0000538 : TT(TLI.TT), CustomNames(TLI.CustomNames),
539 ShouldExtI32Param(TLI.ShouldExtI32Param),
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000540 ShouldExtI32Return(TLI.ShouldExtI32Return),
541 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000542 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
Michael Zolotukhine8f25512015-03-17 19:22:30 +0000543 VectorDescs = TLI.VectorDescs;
544 ScalarDescs = TLI.ScalarDescs;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000545}
546
Chandler Carruthc0291862015-01-24 02:06:09 +0000547TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
Joel Jones5f533c52018-11-24 06:41:39 +0000548 : TT(std::move(TLI.TT)), CustomNames(std::move(TLI.CustomNames)),
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000549 ShouldExtI32Param(TLI.ShouldExtI32Param),
550 ShouldExtI32Return(TLI.ShouldExtI32Return),
551 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
Chandler Carruth8ca43222015-01-15 11:39:46 +0000552 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
553 AvailableArray);
Michael Zolotukhine8f25512015-03-17 19:22:30 +0000554 VectorDescs = TLI.VectorDescs;
555 ScalarDescs = TLI.ScalarDescs;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000556}
557
Chandler Carruthc0291862015-01-24 02:06:09 +0000558TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
Joel Jones5f533c52018-11-24 06:41:39 +0000559 TT = TLI.TT;
Eli Friedman489c0ff2011-11-17 01:27:36 +0000560 CustomNames = TLI.CustomNames;
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000561 ShouldExtI32Param = TLI.ShouldExtI32Param;
562 ShouldExtI32Return = TLI.ShouldExtI32Return;
563 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000564 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
565 return *this;
566}
567
Chandler Carruthc0291862015-01-24 02:06:09 +0000568TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
Joel Jones5f533c52018-11-24 06:41:39 +0000569 TT = std::move(TLI.TT);
Chandler Carruth8ca43222015-01-15 11:39:46 +0000570 CustomNames = std::move(TLI.CustomNames);
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000571 ShouldExtI32Param = TLI.ShouldExtI32Param;
572 ShouldExtI32Return = TLI.ShouldExtI32Return;
573 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000574 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
575 AvailableArray);
576 return *this;
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000577}
578
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000579static StringRef sanitizeFunctionName(StringRef funcName) {
Benjamin Kramer160f72d2013-03-09 13:48:23 +0000580 // Filter out empty names and names containing null bytes, those can't be in
581 // our table.
582 if (funcName.empty() || funcName.find('\0') != StringRef::npos)
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000583 return StringRef();
Benjamin Kramer160f72d2013-03-09 13:48:23 +0000584
Meador Ingeb904e6e2013-03-05 21:47:40 +0000585 // Check for \01 prefix that is used to mangle __asm declarations and
586 // strip it if present.
Peter Collingbourne6f0ecca2017-05-16 00:39:01 +0000587 return GlobalValue::dropLLVMManglingEscape(funcName);
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000588}
589
590bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
David L. Jonesd21529f2017-01-23 23:16:46 +0000591 LibFunc &F) const {
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000592 StringRef const *Start = &StandardNames[0];
David L. Jonesd21529f2017-01-23 23:16:46 +0000593 StringRef const *End = &StandardNames[NumLibFuncs];
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000594
595 funcName = sanitizeFunctionName(funcName);
596 if (funcName.empty())
597 return false;
598
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000599 StringRef const *I = std::lower_bound(
600 Start, End, funcName, [](StringRef LHS, StringRef RHS) {
601 return LHS < RHS;
Michael Zolotukhind3b76a32015-03-02 20:50:08 +0000602 });
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000603 if (I != End && *I == funcName) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000604 F = (LibFunc)(I - Start);
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000605 return true;
606 }
607 return false;
608}
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000609
Ahmed Bougachad765a822016-04-27 19:04:35 +0000610bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
David L. Jonesd21529f2017-01-23 23:16:46 +0000611 LibFunc F,
Ahmed Bougachad765a822016-04-27 19:04:35 +0000612 const DataLayout *DL) const {
613 LLVMContext &Ctx = FTy.getContext();
614 Type *PCharTy = Type::getInt8PtrTy(Ctx);
615 Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
616 auto IsSizeTTy = [SizeTTy](Type *Ty) {
617 return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
618 };
619 unsigned NumParams = FTy.getNumParams();
620
621 switch (F) {
Calixte Denizetc3bed1e2018-11-07 13:49:17 +0000622 case LibFunc_execl:
623 case LibFunc_execlp:
Calixte Denizet8f07efc2018-11-07 14:46:26 +0000624 case LibFunc_execle:
Calixte Denizetc3bed1e2018-11-07 13:49:17 +0000625 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
626 FTy.getParamType(1)->isPointerTy() &&
627 FTy.getReturnType()->isIntegerTy(32));
Calixte Denizetc3bed1e2018-11-07 13:49:17 +0000628 case LibFunc_execv:
629 case LibFunc_execvp:
630 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
631 FTy.getParamType(1)->isPointerTy() &&
632 FTy.getReturnType()->isIntegerTy(32));
633 case LibFunc_execvP:
634 case LibFunc_execvpe:
635 case LibFunc_execve:
636 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
637 FTy.getParamType(1)->isPointerTy() &&
638 FTy.getParamType(2)->isPointerTy() &&
639 FTy.getReturnType()->isIntegerTy(32));
David L. Jonesd21529f2017-01-23 23:16:46 +0000640 case LibFunc_strlen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000641 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
642 FTy.getReturnType()->isIntegerTy());
643
David L. Jonesd21529f2017-01-23 23:16:46 +0000644 case LibFunc_strchr:
645 case LibFunc_strrchr:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000646 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
647 FTy.getParamType(0) == FTy.getReturnType() &&
648 FTy.getParamType(1)->isIntegerTy());
649
David L. Jonesd21529f2017-01-23 23:16:46 +0000650 case LibFunc_strtol:
651 case LibFunc_strtod:
652 case LibFunc_strtof:
653 case LibFunc_strtoul:
654 case LibFunc_strtoll:
655 case LibFunc_strtold:
656 case LibFunc_strtoull:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000657 return ((NumParams == 2 || NumParams == 3) &&
658 FTy.getParamType(0)->isPointerTy() &&
659 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000660 case LibFunc_strcat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000661 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
662 FTy.getParamType(0) == FTy.getReturnType() &&
663 FTy.getParamType(1) == FTy.getReturnType());
664
David L. Jonesd21529f2017-01-23 23:16:46 +0000665 case LibFunc_strncat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000666 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
667 FTy.getParamType(0) == FTy.getReturnType() &&
668 FTy.getParamType(1) == FTy.getReturnType() &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000669 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000670
David L. Jonesd21529f2017-01-23 23:16:46 +0000671 case LibFunc_strcpy_chk:
672 case LibFunc_stpcpy_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000673 --NumParams;
674 if (!IsSizeTTy(FTy.getParamType(NumParams)))
675 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000676 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000677 case LibFunc_strcpy:
678 case LibFunc_stpcpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000679 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
680 FTy.getParamType(0) == FTy.getParamType(1) &&
681 FTy.getParamType(0) == PCharTy);
682
David L. Jonesd21529f2017-01-23 23:16:46 +0000683 case LibFunc_strncpy_chk:
684 case LibFunc_stpncpy_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000685 --NumParams;
686 if (!IsSizeTTy(FTy.getParamType(NumParams)))
687 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000688 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000689 case LibFunc_strncpy:
690 case LibFunc_stpncpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000691 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
692 FTy.getParamType(0) == FTy.getParamType(1) &&
693 FTy.getParamType(0) == PCharTy &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000694 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000695
David L. Jonesd21529f2017-01-23 23:16:46 +0000696 case LibFunc_strxfrm:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000697 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
698 FTy.getParamType(1)->isPointerTy());
699
David L. Jonesd21529f2017-01-23 23:16:46 +0000700 case LibFunc_strcmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000701 return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
702 FTy.getParamType(0)->isPointerTy() &&
703 FTy.getParamType(0) == FTy.getParamType(1));
704
David L. Jonesd21529f2017-01-23 23:16:46 +0000705 case LibFunc_strncmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000706 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
707 FTy.getParamType(0)->isPointerTy() &&
708 FTy.getParamType(0) == FTy.getParamType(1) &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000709 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000710
David L. Jonesd21529f2017-01-23 23:16:46 +0000711 case LibFunc_strspn:
712 case LibFunc_strcspn:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000713 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
714 FTy.getParamType(0) == FTy.getParamType(1) &&
715 FTy.getReturnType()->isIntegerTy());
716
David L. Jonesd21529f2017-01-23 23:16:46 +0000717 case LibFunc_strcoll:
718 case LibFunc_strcasecmp:
719 case LibFunc_strncasecmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000720 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
721 FTy.getParamType(1)->isPointerTy());
722
David L. Jonesd21529f2017-01-23 23:16:46 +0000723 case LibFunc_strstr:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000724 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
725 FTy.getParamType(0)->isPointerTy() &&
726 FTy.getParamType(1)->isPointerTy());
727
David L. Jonesd21529f2017-01-23 23:16:46 +0000728 case LibFunc_strpbrk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000729 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
730 FTy.getReturnType() == FTy.getParamType(0) &&
731 FTy.getParamType(0) == FTy.getParamType(1));
732
David L. Jonesd21529f2017-01-23 23:16:46 +0000733 case LibFunc_strtok:
734 case LibFunc_strtok_r:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000735 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000736 case LibFunc_scanf:
737 case LibFunc_setbuf:
738 case LibFunc_setvbuf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000739 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000740 case LibFunc_strdup:
741 case LibFunc_strndup:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000742 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
743 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000744 case LibFunc_sscanf:
745 case LibFunc_stat:
746 case LibFunc_statvfs:
747 case LibFunc_siprintf:
748 case LibFunc_sprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000749 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
Martin Storsjo0d7c3772018-05-11 16:53:56 +0000750 FTy.getParamType(1)->isPointerTy() &&
751 FTy.getReturnType()->isIntegerTy(32));
David L. Jonesd21529f2017-01-23 23:16:46 +0000752 case LibFunc_snprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000753 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
Martin Storsjo0d7c3772018-05-11 16:53:56 +0000754 FTy.getParamType(2)->isPointerTy() &&
755 FTy.getReturnType()->isIntegerTy(32));
David L. Jonesd21529f2017-01-23 23:16:46 +0000756 case LibFunc_setitimer:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000757 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
758 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000759 case LibFunc_system:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000760 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000761 case LibFunc_malloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000762 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000763 case LibFunc_memcmp:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000764 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
765 FTy.getParamType(0)->isPointerTy() &&
766 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000767
David L. Jonesd21529f2017-01-23 23:16:46 +0000768 case LibFunc_memchr:
769 case LibFunc_memrchr:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000770 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
771 FTy.getReturnType() == FTy.getParamType(0) &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000772 FTy.getParamType(1)->isIntegerTy(32) &&
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000773 IsSizeTTy(FTy.getParamType(2)));
David L. Jonesd21529f2017-01-23 23:16:46 +0000774 case LibFunc_modf:
775 case LibFunc_modff:
776 case LibFunc_modfl:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000777 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
778
David L. Jonesd21529f2017-01-23 23:16:46 +0000779 case LibFunc_memcpy_chk:
780 case LibFunc_memmove_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000781 --NumParams;
782 if (!IsSizeTTy(FTy.getParamType(NumParams)))
783 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000784 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000785 case LibFunc_memcpy:
786 case LibFunc_mempcpy:
787 case LibFunc_memmove:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000788 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
789 FTy.getParamType(0)->isPointerTy() &&
790 FTy.getParamType(1)->isPointerTy() &&
791 IsSizeTTy(FTy.getParamType(2)));
792
David L. Jonesd21529f2017-01-23 23:16:46 +0000793 case LibFunc_memset_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000794 --NumParams;
795 if (!IsSizeTTy(FTy.getParamType(NumParams)))
796 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000797 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000798 case LibFunc_memset:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000799 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
800 FTy.getParamType(0)->isPointerTy() &&
801 FTy.getParamType(1)->isIntegerTy() &&
802 IsSizeTTy(FTy.getParamType(2)));
803
David L. Jonesd21529f2017-01-23 23:16:46 +0000804 case LibFunc_memccpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000805 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000806 case LibFunc_memalign:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000807 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000808 case LibFunc_realloc:
809 case LibFunc_reallocf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000810 return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
811 FTy.getParamType(0) == FTy.getReturnType() &&
812 IsSizeTTy(FTy.getParamType(1)));
David L. Jonesd21529f2017-01-23 23:16:46 +0000813 case LibFunc_read:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000814 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000815 case LibFunc_rewind:
816 case LibFunc_rmdir:
817 case LibFunc_remove:
818 case LibFunc_realpath:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000819 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000820 case LibFunc_rename:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000821 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
822 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000823 case LibFunc_readlink:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000824 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
825 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000826 case LibFunc_write:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000827 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000828 case LibFunc_bcopy:
829 case LibFunc_bcmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000830 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
831 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000832 case LibFunc_bzero:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000833 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000834 case LibFunc_calloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000835 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000836
David L. Jonesd21529f2017-01-23 23:16:46 +0000837 case LibFunc_atof:
838 case LibFunc_atoi:
839 case LibFunc_atol:
840 case LibFunc_atoll:
841 case LibFunc_ferror:
842 case LibFunc_getenv:
843 case LibFunc_getpwnam:
844 case LibFunc_iprintf:
845 case LibFunc_pclose:
846 case LibFunc_perror:
847 case LibFunc_printf:
848 case LibFunc_puts:
849 case LibFunc_uname:
850 case LibFunc_under_IO_getc:
851 case LibFunc_unlink:
852 case LibFunc_unsetenv:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000853 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000854
David L. Jonesd21529f2017-01-23 23:16:46 +0000855 case LibFunc_access:
856 case LibFunc_chmod:
857 case LibFunc_chown:
858 case LibFunc_clearerr:
859 case LibFunc_closedir:
860 case LibFunc_ctermid:
861 case LibFunc_fclose:
862 case LibFunc_feof:
863 case LibFunc_fflush:
864 case LibFunc_fgetc:
David Bolvanskyca22d422018-05-16 11:39:52 +0000865 case LibFunc_fgetc_unlocked:
David L. Jonesd21529f2017-01-23 23:16:46 +0000866 case LibFunc_fileno:
867 case LibFunc_flockfile:
868 case LibFunc_free:
869 case LibFunc_fseek:
870 case LibFunc_fseeko64:
871 case LibFunc_fseeko:
872 case LibFunc_fsetpos:
873 case LibFunc_ftell:
874 case LibFunc_ftello64:
875 case LibFunc_ftello:
876 case LibFunc_ftrylockfile:
877 case LibFunc_funlockfile:
878 case LibFunc_getc:
879 case LibFunc_getc_unlocked:
880 case LibFunc_getlogin_r:
881 case LibFunc_mkdir:
882 case LibFunc_mktime:
883 case LibFunc_times:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000884 return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
885
David L. Jonesd21529f2017-01-23 23:16:46 +0000886 case LibFunc_fopen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000887 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
888 FTy.getParamType(0)->isPointerTy() &&
889 FTy.getParamType(1)->isPointerTy());
Calixte Denizetc3bed1e2018-11-07 13:49:17 +0000890 case LibFunc_fork:
891 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy(32));
David L. Jonesd21529f2017-01-23 23:16:46 +0000892 case LibFunc_fdopen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000893 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
894 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000895 case LibFunc_fputc:
David Bolvanskyca22d422018-05-16 11:39:52 +0000896 case LibFunc_fputc_unlocked:
David L. Jonesd21529f2017-01-23 23:16:46 +0000897 case LibFunc_fstat:
898 case LibFunc_frexp:
899 case LibFunc_frexpf:
900 case LibFunc_frexpl:
901 case LibFunc_fstatvfs:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000902 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000903 case LibFunc_fgets:
David Bolvanskyca22d422018-05-16 11:39:52 +0000904 case LibFunc_fgets_unlocked:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000905 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
906 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000907 case LibFunc_fread:
David Bolvanskyca22d422018-05-16 11:39:52 +0000908 case LibFunc_fread_unlocked:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000909 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
910 FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000911 case LibFunc_fwrite:
David Bolvanskyca22d422018-05-16 11:39:52 +0000912 case LibFunc_fwrite_unlocked:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000913 return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
914 FTy.getParamType(0)->isPointerTy() &&
915 FTy.getParamType(1)->isIntegerTy() &&
916 FTy.getParamType(2)->isIntegerTy() &&
917 FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000918 case LibFunc_fputs:
David Bolvanskyca22d422018-05-16 11:39:52 +0000919 case LibFunc_fputs_unlocked:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000920 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
921 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000922 case LibFunc_fscanf:
923 case LibFunc_fiprintf:
924 case LibFunc_fprintf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000925 return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
926 FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000927 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000928 case LibFunc_fgetpos:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000929 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
930 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000931 case LibFunc_getchar:
David Bolvanskyca22d422018-05-16 11:39:52 +0000932 case LibFunc_getchar_unlocked:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000933 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000934 case LibFunc_gets:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000935 return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
David L. Jonesd21529f2017-01-23 23:16:46 +0000936 case LibFunc_getitimer:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000937 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000938 case LibFunc_ungetc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000939 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000940 case LibFunc_utime:
941 case LibFunc_utimes:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000942 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
943 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000944 case LibFunc_putc:
David Bolvanskyca22d422018-05-16 11:39:52 +0000945 case LibFunc_putc_unlocked:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000946 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000947 case LibFunc_pread:
948 case LibFunc_pwrite:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000949 return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000950 case LibFunc_popen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000951 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
952 FTy.getParamType(0)->isPointerTy() &&
953 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000954 case LibFunc_vscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000955 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000956 case LibFunc_vsscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000957 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
958 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000959 case LibFunc_vfscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000960 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
961 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000962 case LibFunc_valloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000963 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000964 case LibFunc_vprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000965 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000966 case LibFunc_vfprintf:
967 case LibFunc_vsprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000968 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
969 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000970 case LibFunc_vsnprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000971 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
972 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000973 case LibFunc_open:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000974 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000975 case LibFunc_opendir:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000976 return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
977 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000978 case LibFunc_tmpfile:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000979 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000980 case LibFunc_htonl:
981 case LibFunc_ntohl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000982 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
983 FTy.getReturnType() == FTy.getParamType(0));
David L. Jonesd21529f2017-01-23 23:16:46 +0000984 case LibFunc_htons:
985 case LibFunc_ntohs:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000986 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
987 FTy.getReturnType() == FTy.getParamType(0));
David L. Jonesd21529f2017-01-23 23:16:46 +0000988 case LibFunc_lstat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000989 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
990 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000991 case LibFunc_lchown:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000992 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000993 case LibFunc_qsort:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000994 return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000995 case LibFunc_dunder_strdup:
996 case LibFunc_dunder_strndup:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000997 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
998 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000999 case LibFunc_dunder_strtok_r:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001000 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +00001001 case LibFunc_under_IO_putc:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001002 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +00001003 case LibFunc_dunder_isoc99_scanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001004 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +00001005 case LibFunc_stat64:
1006 case LibFunc_lstat64:
1007 case LibFunc_statvfs64:
Michael Kuperstein79dcc272016-09-20 23:10:31 +00001008 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +00001009 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +00001010 case LibFunc_dunder_isoc99_sscanf:
Michael Kuperstein79dcc272016-09-20 23:10:31 +00001011 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +00001012 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +00001013 case LibFunc_fopen64:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001014 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1015 FTy.getParamType(0)->isPointerTy() &&
1016 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +00001017 case LibFunc_tmpfile64:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001018 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +00001019 case LibFunc_fstat64:
1020 case LibFunc_fstatvfs64:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001021 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +00001022 case LibFunc_open64:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001023 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +00001024 case LibFunc_gettimeofday:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001025 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
1026 FTy.getParamType(1)->isPointerTy());
1027
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001028 // new(unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001029 case LibFunc_Znwj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001030 // new(unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001031 case LibFunc_Znwm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001032 // new[](unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001033 case LibFunc_Znaj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001034 // new[](unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001035 case LibFunc_Znam:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001036 // new(unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001037 case LibFunc_msvc_new_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001038 // new(unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001039 case LibFunc_msvc_new_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001040 // new[](unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001041 case LibFunc_msvc_new_array_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001042 // new[](unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001043 case LibFunc_msvc_new_array_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001044 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
1045
1046 // new(unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001047 case LibFunc_ZnwjRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001048 // new(unsigned long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001049 case LibFunc_ZnwmRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001050 // new[](unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001051 case LibFunc_ZnajRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001052 // new[](unsigned long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001053 case LibFunc_ZnamRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001054 // new(unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001055 case LibFunc_msvc_new_int_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001056 // new(unsigned long long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001057 case LibFunc_msvc_new_longlong_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001058 // new[](unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001059 case LibFunc_msvc_new_array_int_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001060 // new[](unsigned long long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001061 case LibFunc_msvc_new_array_longlong_nothrow:
Eric Fiselier96bbec72018-04-04 19:01:51 +00001062 // new(unsigned int, align_val_t)
1063 case LibFunc_ZnwjSt11align_val_t:
1064 // new(unsigned long, align_val_t)
1065 case LibFunc_ZnwmSt11align_val_t:
1066 // new[](unsigned int, align_val_t)
1067 case LibFunc_ZnajSt11align_val_t:
1068 // new[](unsigned long, align_val_t)
1069 case LibFunc_ZnamSt11align_val_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001070 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
1071
Eric Fiselier96bbec72018-04-04 19:01:51 +00001072 // new(unsigned int, align_val_t, nothrow)
1073 case LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t:
1074 // new(unsigned long, align_val_t, nothrow)
1075 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t:
1076 // new[](unsigned int, align_val_t, nothrow)
1077 case LibFunc_ZnajSt11align_val_tRKSt9nothrow_t:
1078 // new[](unsigned long, align_val_t, nothrow)
1079 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t:
1080 return (NumParams == 3 && FTy.getReturnType()->isPointerTy());
1081
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001082 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001083 case LibFunc_ZdaPv:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001084 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001085 case LibFunc_ZdlPv:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001086 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001087 case LibFunc_msvc_delete_array_ptr32:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001088 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001089 case LibFunc_msvc_delete_array_ptr64:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001090 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001091 case LibFunc_msvc_delete_ptr32:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001092 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001093 case LibFunc_msvc_delete_ptr64:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001094 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1095
1096 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001097 case LibFunc_ZdaPvRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001098 // void operator delete[](void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001099 case LibFunc_ZdaPvj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001100 // void operator delete[](void*, unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001101 case LibFunc_ZdaPvm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001102 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001103 case LibFunc_ZdlPvRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001104 // void operator delete(void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001105 case LibFunc_ZdlPvj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001106 // void operator delete(void*, unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001107 case LibFunc_ZdlPvm:
Eric Fiselier96bbec72018-04-04 19:01:51 +00001108 // void operator delete(void*, align_val_t)
1109 case LibFunc_ZdlPvSt11align_val_t:
1110 // void operator delete[](void*, align_val_t)
1111 case LibFunc_ZdaPvSt11align_val_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001112 // void operator delete[](void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001113 case LibFunc_msvc_delete_array_ptr32_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001114 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001115 case LibFunc_msvc_delete_array_ptr32_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001116 // void operator delete[](void*, unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001117 case LibFunc_msvc_delete_array_ptr64_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001118 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001119 case LibFunc_msvc_delete_array_ptr64_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001120 // void operator delete(void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001121 case LibFunc_msvc_delete_ptr32_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001122 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001123 case LibFunc_msvc_delete_ptr32_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001124 // void operator delete(void*, unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001125 case LibFunc_msvc_delete_ptr64_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001126 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001127 case LibFunc_msvc_delete_ptr64_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001128 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001129
Eric Fiselier96bbec72018-04-04 19:01:51 +00001130 // void operator delete(void*, align_val_t, nothrow)
1131 case LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t:
1132 // void operator delete[](void*, align_val_t, nothrow)
1133 case LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t:
1134 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
1135
David L. Jonesd21529f2017-01-23 23:16:46 +00001136 case LibFunc_memset_pattern16:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001137 return (!FTy.isVarArg() && NumParams == 3 &&
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001138 FTy.getParamType(0)->isPointerTy() &&
1139 FTy.getParamType(1)->isPointerTy() &&
1140 FTy.getParamType(2)->isIntegerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001141
David L. Jonesd21529f2017-01-23 23:16:46 +00001142 case LibFunc_cxa_guard_abort:
1143 case LibFunc_cxa_guard_acquire:
1144 case LibFunc_cxa_guard_release:
1145 case LibFunc_nvvm_reflect:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001146 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001147
David L. Jonesd21529f2017-01-23 23:16:46 +00001148 case LibFunc_sincospi_stret:
1149 case LibFunc_sincospif_stret:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001150 return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
1151
David L. Jonesd21529f2017-01-23 23:16:46 +00001152 case LibFunc_acos:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001153 case LibFunc_acos_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001154 case LibFunc_acosf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001155 case LibFunc_acosf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001156 case LibFunc_acosh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001157 case LibFunc_acosh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001158 case LibFunc_acoshf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001159 case LibFunc_acoshf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001160 case LibFunc_acoshl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001161 case LibFunc_acoshl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001162 case LibFunc_acosl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001163 case LibFunc_acosl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001164 case LibFunc_asin:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001165 case LibFunc_asin_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001166 case LibFunc_asinf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001167 case LibFunc_asinf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001168 case LibFunc_asinh:
1169 case LibFunc_asinhf:
1170 case LibFunc_asinhl:
1171 case LibFunc_asinl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001172 case LibFunc_asinl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001173 case LibFunc_atan:
1174 case LibFunc_atanf:
1175 case LibFunc_atanh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001176 case LibFunc_atanh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001177 case LibFunc_atanhf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001178 case LibFunc_atanhf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001179 case LibFunc_atanhl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001180 case LibFunc_atanhl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001181 case LibFunc_atanl:
1182 case LibFunc_cbrt:
1183 case LibFunc_cbrtf:
1184 case LibFunc_cbrtl:
1185 case LibFunc_ceil:
1186 case LibFunc_ceilf:
1187 case LibFunc_ceill:
1188 case LibFunc_cos:
1189 case LibFunc_cosf:
1190 case LibFunc_cosh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001191 case LibFunc_cosh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001192 case LibFunc_coshf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001193 case LibFunc_coshf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001194 case LibFunc_coshl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001195 case LibFunc_coshl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001196 case LibFunc_cosl:
1197 case LibFunc_exp10:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001198 case LibFunc_exp10_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001199 case LibFunc_exp10f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001200 case LibFunc_exp10f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001201 case LibFunc_exp10l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001202 case LibFunc_exp10l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001203 case LibFunc_exp2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001204 case LibFunc_exp2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001205 case LibFunc_exp2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001206 case LibFunc_exp2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001207 case LibFunc_exp2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001208 case LibFunc_exp2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001209 case LibFunc_exp:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001210 case LibFunc_exp_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001211 case LibFunc_expf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001212 case LibFunc_expf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001213 case LibFunc_expl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001214 case LibFunc_expl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001215 case LibFunc_expm1:
1216 case LibFunc_expm1f:
1217 case LibFunc_expm1l:
1218 case LibFunc_fabs:
1219 case LibFunc_fabsf:
1220 case LibFunc_fabsl:
1221 case LibFunc_floor:
1222 case LibFunc_floorf:
1223 case LibFunc_floorl:
1224 case LibFunc_log10:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001225 case LibFunc_log10_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001226 case LibFunc_log10f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001227 case LibFunc_log10f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001228 case LibFunc_log10l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001229 case LibFunc_log10l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001230 case LibFunc_log1p:
1231 case LibFunc_log1pf:
1232 case LibFunc_log1pl:
1233 case LibFunc_log2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001234 case LibFunc_log2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001235 case LibFunc_log2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001236 case LibFunc_log2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001237 case LibFunc_log2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001238 case LibFunc_log2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001239 case LibFunc_log:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001240 case LibFunc_log_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001241 case LibFunc_logb:
1242 case LibFunc_logbf:
1243 case LibFunc_logbl:
1244 case LibFunc_logf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001245 case LibFunc_logf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001246 case LibFunc_logl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001247 case LibFunc_logl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001248 case LibFunc_nearbyint:
1249 case LibFunc_nearbyintf:
1250 case LibFunc_nearbyintl:
1251 case LibFunc_rint:
1252 case LibFunc_rintf:
1253 case LibFunc_rintl:
1254 case LibFunc_round:
1255 case LibFunc_roundf:
1256 case LibFunc_roundl:
1257 case LibFunc_sin:
1258 case LibFunc_sinf:
1259 case LibFunc_sinh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001260 case LibFunc_sinh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001261 case LibFunc_sinhf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001262 case LibFunc_sinhf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001263 case LibFunc_sinhl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001264 case LibFunc_sinhl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001265 case LibFunc_sinl:
1266 case LibFunc_sqrt:
1267 case LibFunc_sqrt_finite:
1268 case LibFunc_sqrtf:
1269 case LibFunc_sqrtf_finite:
1270 case LibFunc_sqrtl:
1271 case LibFunc_sqrtl_finite:
1272 case LibFunc_tan:
1273 case LibFunc_tanf:
1274 case LibFunc_tanh:
1275 case LibFunc_tanhf:
1276 case LibFunc_tanhl:
1277 case LibFunc_tanl:
1278 case LibFunc_trunc:
1279 case LibFunc_truncf:
1280 case LibFunc_truncl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001281 return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1282 FTy.getReturnType() == FTy.getParamType(0));
1283
David L. Jonesd21529f2017-01-23 23:16:46 +00001284 case LibFunc_atan2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001285 case LibFunc_atan2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001286 case LibFunc_atan2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001287 case LibFunc_atan2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001288 case LibFunc_atan2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001289 case LibFunc_atan2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001290 case LibFunc_fmin:
1291 case LibFunc_fminf:
1292 case LibFunc_fminl:
1293 case LibFunc_fmax:
1294 case LibFunc_fmaxf:
1295 case LibFunc_fmaxl:
1296 case LibFunc_fmod:
1297 case LibFunc_fmodf:
1298 case LibFunc_fmodl:
1299 case LibFunc_copysign:
1300 case LibFunc_copysignf:
1301 case LibFunc_copysignl:
1302 case LibFunc_pow:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001303 case LibFunc_pow_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001304 case LibFunc_powf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001305 case LibFunc_powf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001306 case LibFunc_powl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001307 case LibFunc_powl_finite:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001308 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1309 FTy.getReturnType() == FTy.getParamType(0) &&
1310 FTy.getReturnType() == FTy.getParamType(1));
1311
David L. Jonesd21529f2017-01-23 23:16:46 +00001312 case LibFunc_ldexp:
1313 case LibFunc_ldexpf:
1314 case LibFunc_ldexpl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001315 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1316 FTy.getReturnType() == FTy.getParamType(0) &&
1317 FTy.getParamType(1)->isIntegerTy(32));
1318
David L. Jonesd21529f2017-01-23 23:16:46 +00001319 case LibFunc_ffs:
1320 case LibFunc_ffsl:
1321 case LibFunc_ffsll:
1322 case LibFunc_fls:
1323 case LibFunc_flsl:
1324 case LibFunc_flsll:
Sanjay Patel04949faf2016-09-23 18:44:09 +00001325 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1326 FTy.getParamType(0)->isIntegerTy());
1327
David L. Jonesd21529f2017-01-23 23:16:46 +00001328 case LibFunc_isdigit:
1329 case LibFunc_isascii:
1330 case LibFunc_toascii:
1331 case LibFunc_putchar:
David Bolvanskyca22d422018-05-16 11:39:52 +00001332 case LibFunc_putchar_unlocked:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001333 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
Sanjay Patel04949faf2016-09-23 18:44:09 +00001334 FTy.getReturnType() == FTy.getParamType(0));
Ahmed Bougachad765a822016-04-27 19:04:35 +00001335
David L. Jonesd21529f2017-01-23 23:16:46 +00001336 case LibFunc_abs:
1337 case LibFunc_labs:
1338 case LibFunc_llabs:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001339 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1340 FTy.getReturnType() == FTy.getParamType(0));
1341
David L. Jonesd21529f2017-01-23 23:16:46 +00001342 case LibFunc_cxa_atexit:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001343 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1344 FTy.getParamType(0)->isPointerTy() &&
1345 FTy.getParamType(1)->isPointerTy() &&
1346 FTy.getParamType(2)->isPointerTy());
1347
David L. Jonesd21529f2017-01-23 23:16:46 +00001348 case LibFunc_sinpi:
1349 case LibFunc_cospi:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001350 return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1351 FTy.getReturnType() == FTy.getParamType(0));
1352
David L. Jonesd21529f2017-01-23 23:16:46 +00001353 case LibFunc_sinpif:
1354 case LibFunc_cospif:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001355 return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1356 FTy.getReturnType() == FTy.getParamType(0));
1357
David L. Jonesd21529f2017-01-23 23:16:46 +00001358 case LibFunc_strnlen:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001359 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1360 FTy.getParamType(0) == PCharTy &&
1361 FTy.getParamType(1) == SizeTTy);
1362
David L. Jonesd21529f2017-01-23 23:16:46 +00001363 case LibFunc_posix_memalign:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001364 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1365 FTy.getParamType(0)->isPointerTy() &&
1366 FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
1367
Matthias Braun60b40b82017-05-05 20:25:50 +00001368 case LibFunc_wcslen:
1369 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
1370 FTy.getReturnType()->isIntegerTy());
1371
Hal Finkel2ff24732017-12-16 01:26:25 +00001372 case LibFunc_cabs:
1373 case LibFunc_cabsf:
1374 case LibFunc_cabsl: {
1375 Type* RetTy = FTy.getReturnType();
1376 if (!RetTy->isFloatingPointTy())
1377 return false;
1378
1379 // NOTE: These prototypes are target specific and currently support
1380 // "complex" passed as an array or discrete real & imaginary parameters.
1381 // Add other calling conventions to enable libcall optimizations.
1382 if (NumParams == 1)
1383 return (FTy.getParamType(0)->isArrayTy() &&
1384 FTy.getParamType(0)->getArrayNumElements() == 2 &&
1385 FTy.getParamType(0)->getArrayElementType() == RetTy);
1386 else if (NumParams == 2)
1387 return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
1388 else
1389 return false;
1390 }
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001391 case LibFunc::NumLibFuncs:
Ahmed Bougacha86b680a2017-01-17 19:54:18 +00001392 break;
Ahmed Bougachad765a822016-04-27 19:04:35 +00001393 }
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001394
Ahmed Bougacha86b680a2017-01-17 19:54:18 +00001395 llvm_unreachable("Invalid libfunc");
Ahmed Bougachad765a822016-04-27 19:04:35 +00001396}
1397
1398bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
David L. Jonesd21529f2017-01-23 23:16:46 +00001399 LibFunc &F) const {
Ahmed Bougachad765a822016-04-27 19:04:35 +00001400 const DataLayout *DL =
1401 FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1402 return getLibFunc(FDecl.getName(), F) &&
1403 isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1404}
1405
Chandler Carruthc0291862015-01-24 02:06:09 +00001406void TargetLibraryInfoImpl::disableAllFunctions() {
Chris Lattner1341df92011-02-18 22:34:03 +00001407 memset(AvailableArray, 0, sizeof(AvailableArray));
1408}
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001409
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001410static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001411 return LHS.ScalarFnName < RHS.ScalarFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001412}
1413
1414static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001415 return LHS.VectorFnName < RHS.VectorFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001416}
1417
1418static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001419 return LHS.ScalarFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001420}
1421
1422static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001423 return LHS.VectorFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001424}
1425
1426void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1427 VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
Fangrui Song0cac7262018-09-27 02:13:45 +00001428 llvm::sort(VectorDescs, compareByScalarFnName);
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001429
1430 ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
Fangrui Song0cac7262018-09-27 02:13:45 +00001431 llvm::sort(ScalarDescs, compareByVectorFnName);
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001432}
1433
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001434void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1435 enum VectorLibrary VecLib) {
1436 switch (VecLib) {
1437 case Accelerate: {
1438 const VecDesc VecFuncs[] = {
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001439 // Floating-Point Arithmetic and Auxiliary Functions
1440 {"ceilf", "vceilf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001441 {"fabsf", "vfabsf", 4},
1442 {"llvm.fabs.f32", "vfabsf", 4},
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001443 {"floorf", "vfloorf", 4},
1444 {"sqrtf", "vsqrtf", 4},
1445 {"llvm.sqrt.f32", "vsqrtf", 4},
1446
1447 // Exponential and Logarithmic Functions
1448 {"expf", "vexpf", 4},
1449 {"llvm.exp.f32", "vexpf", 4},
1450 {"expm1f", "vexpm1f", 4},
1451 {"logf", "vlogf", 4},
1452 {"llvm.log.f32", "vlogf", 4},
1453 {"log1pf", "vlog1pf", 4},
1454 {"log10f", "vlog10f", 4},
1455 {"llvm.log10.f32", "vlog10f", 4},
1456 {"logbf", "vlogbf", 4},
1457
1458 // Trigonometric Functions
1459 {"sinf", "vsinf", 4},
1460 {"llvm.sin.f32", "vsinf", 4},
1461 {"cosf", "vcosf", 4},
1462 {"llvm.cos.f32", "vcosf", 4},
1463 {"tanf", "vtanf", 4},
1464 {"asinf", "vasinf", 4},
1465 {"acosf", "vacosf", 4},
1466 {"atanf", "vatanf", 4},
1467
1468 // Hyperbolic Functions
1469 {"sinhf", "vsinhf", 4},
1470 {"coshf", "vcoshf", 4},
1471 {"tanhf", "vtanhf", 4},
1472 {"asinhf", "vasinhf", 4},
1473 {"acoshf", "vacoshf", 4},
1474 {"atanhf", "vatanhf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001475 };
1476 addVectorizableFunctions(VecFuncs);
1477 break;
1478 }
Matt Mastena6669a12016-07-29 16:42:44 +00001479 case SVML: {
1480 const VecDesc VecFuncs[] = {
1481 {"sin", "__svml_sin2", 2},
1482 {"sin", "__svml_sin4", 4},
1483 {"sin", "__svml_sin8", 8},
1484
1485 {"sinf", "__svml_sinf4", 4},
1486 {"sinf", "__svml_sinf8", 8},
1487 {"sinf", "__svml_sinf16", 16},
1488
Sanjay Patel4b1205b2018-06-07 18:21:24 +00001489 {"llvm.sin.f64", "__svml_sin2", 2},
1490 {"llvm.sin.f64", "__svml_sin4", 4},
1491 {"llvm.sin.f64", "__svml_sin8", 8},
1492
1493 {"llvm.sin.f32", "__svml_sinf4", 4},
1494 {"llvm.sin.f32", "__svml_sinf8", 8},
1495 {"llvm.sin.f32", "__svml_sinf16", 16},
1496
Matt Mastena6669a12016-07-29 16:42:44 +00001497 {"cos", "__svml_cos2", 2},
1498 {"cos", "__svml_cos4", 4},
1499 {"cos", "__svml_cos8", 8},
1500
1501 {"cosf", "__svml_cosf4", 4},
1502 {"cosf", "__svml_cosf8", 8},
1503 {"cosf", "__svml_cosf16", 16},
1504
Sanjay Patel4b1205b2018-06-07 18:21:24 +00001505 {"llvm.cos.f64", "__svml_cos2", 2},
1506 {"llvm.cos.f64", "__svml_cos4", 4},
1507 {"llvm.cos.f64", "__svml_cos8", 8},
1508
1509 {"llvm.cos.f32", "__svml_cosf4", 4},
1510 {"llvm.cos.f32", "__svml_cosf8", 8},
1511 {"llvm.cos.f32", "__svml_cosf16", 16},
1512
Matt Mastena6669a12016-07-29 16:42:44 +00001513 {"pow", "__svml_pow2", 2},
1514 {"pow", "__svml_pow4", 4},
1515 {"pow", "__svml_pow8", 8},
1516
1517 {"powf", "__svml_powf4", 4},
1518 {"powf", "__svml_powf8", 8},
1519 {"powf", "__svml_powf16", 16},
1520
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001521 { "__pow_finite", "__svml_pow2", 2 },
1522 { "__pow_finite", "__svml_pow4", 4 },
1523 { "__pow_finite", "__svml_pow8", 8 },
1524
1525 { "__powf_finite", "__svml_powf4", 4 },
1526 { "__powf_finite", "__svml_powf8", 8 },
1527 { "__powf_finite", "__svml_powf16", 16 },
1528
Matt Mastena6669a12016-07-29 16:42:44 +00001529 {"llvm.pow.f64", "__svml_pow2", 2},
1530 {"llvm.pow.f64", "__svml_pow4", 4},
1531 {"llvm.pow.f64", "__svml_pow8", 8},
1532
1533 {"llvm.pow.f32", "__svml_powf4", 4},
1534 {"llvm.pow.f32", "__svml_powf8", 8},
1535 {"llvm.pow.f32", "__svml_powf16", 16},
1536
1537 {"exp", "__svml_exp2", 2},
1538 {"exp", "__svml_exp4", 4},
1539 {"exp", "__svml_exp8", 8},
1540
1541 {"expf", "__svml_expf4", 4},
1542 {"expf", "__svml_expf8", 8},
1543 {"expf", "__svml_expf16", 16},
1544
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001545 { "__exp_finite", "__svml_exp2", 2 },
1546 { "__exp_finite", "__svml_exp4", 4 },
1547 { "__exp_finite", "__svml_exp8", 8 },
1548
1549 { "__expf_finite", "__svml_expf4", 4 },
1550 { "__expf_finite", "__svml_expf8", 8 },
1551 { "__expf_finite", "__svml_expf16", 16 },
1552
Matt Mastena6669a12016-07-29 16:42:44 +00001553 {"llvm.exp.f64", "__svml_exp2", 2},
1554 {"llvm.exp.f64", "__svml_exp4", 4},
1555 {"llvm.exp.f64", "__svml_exp8", 8},
1556
1557 {"llvm.exp.f32", "__svml_expf4", 4},
1558 {"llvm.exp.f32", "__svml_expf8", 8},
1559 {"llvm.exp.f32", "__svml_expf16", 16},
1560
1561 {"log", "__svml_log2", 2},
1562 {"log", "__svml_log4", 4},
1563 {"log", "__svml_log8", 8},
1564
1565 {"logf", "__svml_logf4", 4},
1566 {"logf", "__svml_logf8", 8},
1567 {"logf", "__svml_logf16", 16},
1568
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001569 { "__log_finite", "__svml_log2", 2 },
1570 { "__log_finite", "__svml_log4", 4 },
1571 { "__log_finite", "__svml_log8", 8 },
1572
1573 { "__logf_finite", "__svml_logf4", 4 },
1574 { "__logf_finite", "__svml_logf8", 8 },
1575 { "__logf_finite", "__svml_logf16", 16 },
1576
Matt Mastena6669a12016-07-29 16:42:44 +00001577 {"llvm.log.f64", "__svml_log2", 2},
1578 {"llvm.log.f64", "__svml_log4", 4},
1579 {"llvm.log.f64", "__svml_log8", 8},
1580
1581 {"llvm.log.f32", "__svml_logf4", 4},
1582 {"llvm.log.f32", "__svml_logf8", 8},
1583 {"llvm.log.f32", "__svml_logf16", 16},
1584 };
1585 addVectorizableFunctions(VecFuncs);
1586 break;
1587 }
Joel Jones5f533c52018-11-24 06:41:39 +00001588 case SLEEFGNUABI: {
1589 if (TT.getArch() == llvm::Triple::aarch64 ||
1590 TT.getArch() == llvm::Triple::aarch64_be) {
1591 const VecDesc AArch64TwoAndFourLaneVecFuncs[] = {
1592 { "acos", "_ZGVnN2v_acos", 2 },
1593 { "acos", "_ZGVnN4v_acosf", 4 },
1594 { "acosf", "_ZGVnN4v_acosf", 4 },
1595 { "llvm.acos.f64", "_ZGVnN2v_acos", 2 },
1596 { "llvm.acos.f32", "_ZGVnN4v_acosf", 4 },
1597
1598 { "asin", "_ZGVnN2v_asin", 2 },
1599 { "asin", "_ZGVnN4v_asinf", 4 },
1600 { "asinf", "_ZGVnN4v_asinf", 4 },
1601 { "llvm.asin.f64", "_ZGVnN2v_asin", 2 },
1602 { "llvm.asin.f32", "_ZGVnN4v_asinf", 4 },
1603
1604 { "atan", "_ZGVnN2v_atan", 2 },
1605 { "atan", "_ZGVnN4v_atanf", 4 },
1606 { "atanf", "_ZGVnN4v_atanf", 4 },
1607 { "llvm.atan.f64", "_ZGVnN2v_atan", 2 },
1608 { "llvm.atan.f32", "_ZGVnN4v_atanf", 4 },
1609
1610 { "atan2", "_ZGVnN2vv_atan2", 2 },
1611 { "atan2", "_ZGVnN4vv_atan2f", 4 },
1612 { "atan2f", "_ZGVnN4vv_atan2f", 4 },
1613 { "llvm.atan2.f64", "_ZGVnN2vv_atan2", 2 },
1614 { "llvm.atan2.f32", "_ZGVnN4vv_atan2f", 4 },
1615 { "llvm.atan2.v2f64", "_ZGVnN2vv_atan2", 2 },
1616 { "llvm.atan2.v4f32", "_ZGVnN4vv_atan2f", 4 },
1617
1618 { "atanh", "_ZGVnN2v_atanh", 2 },
1619 { "atanh", "_ZGVnN4v_atanhf", 4 },
1620 { "atanhf", "_ZGVnN4v_atanhf", 4 },
1621 { "llvm.atanh.f64", "_ZGVnN2v_atanh", 2 },
1622 { "llvm.atanh.f32", "_ZGVnN4v_atanhf", 4 },
1623
1624 { "cos", "_ZGVnN2v_cos", 2 },
1625 { "cos", "_ZGVnN4v_cosf", 4 },
1626 { "cosf", "_ZGVnN4v_cosf", 4 },
1627 { "llvm.cos.f64", "_ZGVnN2v_cos", 2 },
1628 { "llvm.cos.f32", "_ZGVnN4v_cosf", 4 },
1629
1630 { "cosh", "_ZGVnN2v_cosh", 2 },
1631 { "cosh", "_ZGVnN4v_coshf", 4 },
1632 { "coshf", "_ZGVnN4v_coshf", 4 },
1633 { "llvm.cosh.f64", "_ZGVnN2v_cosh", 2 },
1634 { "llvm.cosh.f32", "_ZGVnN4v_coshf", 4 },
1635
1636 { "exp", "_ZGVnN2v_exp", 2 },
1637 { "exp", "_ZGVnN4v_expf", 4 },
1638 { "expf", "_ZGVnN4v_expf", 4 },
1639 { "llvm.exp.f64", "_ZGVnN2v_exp", 2 },
1640 { "llvm.exp.f32", "_ZGVnN4v_expf", 4 },
1641 { "llvm.exp.v2f64", "_ZGVnN2v_exp", 2 },
1642 { "llvm.exp.v4f32", "_ZGVnN4v_expf", 4 },
1643
1644 { "exp2", "_ZGVnN2v_exp2", 2 },
1645 { "exp2", "_ZGVnN4v_exp2f", 4 },
1646 { "exp2f", "_ZGVnN4v_exp2f", 4 },
1647 { "llvm.exp2.f64", "_ZGVnN2v_exp2", 2 },
1648 { "llvm.exp2.f32", "_ZGVnN4v_exp2f", 4 },
1649 { "llvm.exp2.v2f64", "_ZGVnN2v_exp2", 2 },
1650 { "llvm.exp2.v4f32", "_ZGVnN4v_exp2f", 4 },
1651
1652 { "exp10", "_ZGVnN2v_exp10", 2 },
1653 { "exp10", "_ZGVnN4v_exp10f", 4 },
1654 { "exp10f", "_ZGVnN4v_exp10f", 4 },
1655 { "llvm.exp10.f64", "_ZGVnN2v_exp10", 2 },
1656 { "llvm.exp10.f32", "_ZGVnN4v_exp10f", 4 },
1657 { "llvm.exp10.v2f64", "_ZGVnN2v_exp10", 2 },
1658 { "llvm.exp10.v4f32", "_ZGVnN4v_exp10f", 4 },
1659
1660 { "lgamma", "_ZGVnN2v_lgamma", 2 },
1661 { "lgamma", "_ZGVnN4v_lgammaf", 4 },
1662 { "lgammaf", "_ZGVnN4v_lgammaf", 4 },
1663 { "llvm.lgamma.f64", "_ZGVnN2v_lgamma", 2 },
1664 { "llvm.lgamma.f32", "_ZGVnN4v_lgammaf", 4 },
1665
1666 { "log", "_ZGVnN2v_log", 2 },
1667 { "log", "_ZGVnN4v_logf", 4 },
1668 { "logf", "_ZGVnN4v_logf", 4 },
1669 { "llvm.log.f64", "_ZGVnN2v_log", 2 },
1670 { "llvm.log.f32", "_ZGVnN4v_logf", 4 },
1671
1672 { "log2", "_ZGVnN2v_log2", 2 },
1673 { "log2", "_ZGVnN4v_log2f", 4 },
1674 { "log2f", "_ZGVnN4v_log2f", 4 },
1675 { "llvm.log2.f64", "_ZGVnN2v_log2", 2 },
1676 { "llvm.log2.f32", "_ZGVnN4v_log2f", 4 },
1677
1678 { "log10", "_ZGVnN2v_log10", 2 },
1679 { "log10", "_ZGVnN4v_log10f", 4 },
1680 { "log10f", "_ZGVnN4v_log10f", 4 },
1681 { "llvm.log10.f64", "_ZGVnN2v_log10", 2 },
1682 { "llvm.log10.f32", "_ZGVnN4v_log10f", 4 },
1683
1684 { "pow", "_ZGVnN2vv_pow", 2 },
1685 { "pow", "_ZGVnN4vv_powf", 4 },
1686 { "powf", "_ZGVnN4vv_powf", 4 },
1687 { "llvm.pow.f64", "_ZGVnN2vv_pow", 2 },
1688 { "llvm.pow.f32", "_ZGVnN4vv_powf", 4 },
1689 { "llvm.pow.v2f64", "_ZGVnN2vv_pow", 2 },
1690 { "llvm.pow.v4f32", "_ZGVnN4vv_powf", 4 },
1691
1692 { "sin", "_ZGVnN2v_sin", 2 },
1693 { "sin", "_ZGVnN4v_sinf", 4 },
1694 { "sinf", "_ZGVnN4v_sinf", 4 },
1695 { "llvm.sin.f64", "_ZGVnN2v_sin", 2 },
1696 { "llvm.sin.f32", "_ZGVnN4v_sinf", 4 },
1697
1698 { "sinh", "_ZGVnN2v_sinh", 2 },
1699 { "sinh", "_ZGVnN4v_sinhf", 4 },
1700 { "sinhf", "_ZGVnN4v_sinhf", 4 },
1701 { "llvm.sinh.f64", "_ZGVnN2v_sinh", 2 },
1702 { "llvm.sinh.f32", "_ZGVnN4v_sinhf", 4 },
1703
1704 { "sqrt", "_ZGVnN2v_sqrt", 2 },
1705 { "sqrt", "_ZGVnN4v_sqrtf", 4 },
1706 { "sqrtf", "_ZGVnN4v_sqrtf", 4 },
1707 { "llvm.sqrt.f64", "_ZGVnN2v_sqrt", 2 },
1708 { "llvm.sqrt.f32", "_ZGVnN4v_sqrtf", 4 },
1709
1710 { "tan", "_ZGVnN2v_tan", 2 },
1711 { "tan", "_ZGVnN4v_tanf", 4 },
1712 { "tanf", "_ZGVnN4v_tanf", 4 },
1713 { "llvm.tan.f64", "_ZGVnN2v_tan", 2 },
1714 { "llvm.tan.f32", "_ZGVnN4v_tanf", 4 },
1715
1716 { "tanh", "_ZGVnN2v_tanh", 2 },
1717 { "tanh", "_ZGVnN4v_tanhf", 4 },
1718 { "tanhf", "_ZGVnN4v_tanhf", 4 },
1719 { "llvm.tanh.f64", "_ZGVnN2v_tanh", 2 },
1720 { "llvm.tanh.f32", "_ZGVnN4v_tanhf", 4 },
1721
1722 { "tgamma", "_ZGVnN2v_tgamma", 2 },
1723 { "tgamma", "_ZGVnN4v_tgammaf", 4 },
1724 { "tgammaf", "_ZGVnN4v_tgammaf", 4 },
1725 { "llvm.tgamma.f64", "_ZGVnN2v_tgamma", 2 },
1726 { "llvm.tgamma.f32", "_ZGVnN4v_tgammaf", 4 },
1727 };
1728 addVectorizableFunctions(AArch64TwoAndFourLaneVecFuncs);
1729 }
1730 break;
1731 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001732 case NoLibrary:
1733 break;
1734 }
1735}
1736
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001737bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1738 funcName = sanitizeFunctionName(funcName);
1739 if (funcName.empty())
1740 return false;
1741
1742 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1743 VectorDescs.begin(), VectorDescs.end(), funcName,
1744 compareWithScalarFnName);
1745 return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1746}
1747
1748StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1749 unsigned VF) const {
1750 F = sanitizeFunctionName(F);
1751 if (F.empty())
1752 return F;
1753 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1754 VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1755 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1756 if (I->VectorizationFactor == VF)
1757 return I->VectorFnName;
1758 ++I;
1759 }
1760 return StringRef();
1761}
1762
1763StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1764 unsigned &VF) const {
1765 F = sanitizeFunctionName(F);
1766 if (F.empty())
1767 return F;
1768
1769 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1770 ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1771 if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1772 return StringRef();
1773 VF = I->VectorizationFactor;
1774 return I->ScalarFnName;
1775}
1776
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001777TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
1778 ModuleAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001779 if (PresetInfoImpl)
1780 return TargetLibraryInfo(*PresetInfoImpl);
1781
1782 return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1783}
1784
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001785TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
1786 FunctionAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001787 if (PresetInfoImpl)
1788 return TargetLibraryInfo(*PresetInfoImpl);
1789
1790 return TargetLibraryInfo(
1791 lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1792}
1793
Benjamin Kramerc321e532016-06-08 19:09:22 +00001794TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001795 std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1796 Impls[T.normalize()];
1797 if (!Impl)
1798 Impl.reset(new TargetLibraryInfoImpl(T));
1799
1800 return *Impl;
1801}
1802
Matthias Braun50ec0b52017-05-19 22:37:09 +00001803unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
1804 if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1805 M.getModuleFlag("wchar_size")))
1806 return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
Matthias Brauncc603ee2017-09-26 02:36:57 +00001807 return 0;
Matthias Braun50ec0b52017-05-19 22:37:09 +00001808}
Chandler Carruthc0291862015-01-24 02:06:09 +00001809
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001810TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
Chandler Carruthc0291862015-01-24 02:06:09 +00001811 : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001812 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1813}
1814
1815TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
Chandler Carruthc0291862015-01-24 02:06:09 +00001816 : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001817 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1818}
1819
1820TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
Chandler Carruthc0291862015-01-24 02:06:09 +00001821 const TargetLibraryInfoImpl &TLIImpl)
1822 : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001823 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1824}
1825
Chandler Carruthdab4eae2016-11-23 17:53:26 +00001826AnalysisKey TargetLibraryAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +00001827
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001828// Register the basic pass.
1829INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1830 "Target Library Information", false, true)
1831char TargetLibraryInfoWrapperPass::ID = 0;
1832
1833void TargetLibraryInfoWrapperPass::anchor() {}