blob: d18246ac594169d79293079efde248863807e0b2 [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",
Mehdi Amini732afdd2016-10-08 19:41:06 +000028 "Intel SVML library")));
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +000029
Mehdi Amini9a72cd72016-10-01 03:10:48 +000030StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
Jan Wen Voungcd3d25a2015-03-03 23:41:58 +000031#define TLI_DEFINE_STRING
32#include "llvm/Analysis/TargetLibraryInfo.def"
Benjamin Kramer57a3d082015-03-08 16:07:39 +000033};
Eli Friedman489c0ff2011-11-17 01:27:36 +000034
Bob Wilsond8d92d92013-11-03 06:48:38 +000035static bool hasSinCosPiStret(const Triple &T) {
36 // Only Darwin variants have _stret versions of combined trig functions.
Bob Wilson9868d712014-10-09 05:43:30 +000037 if (!T.isOSDarwin())
Bob Wilsond8d92d92013-11-03 06:48:38 +000038 return false;
39
40 // The ABI is rather complicated on x86, so don't do anything special there.
41 if (T.getArch() == Triple::x86)
42 return false;
43
44 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
45 return false;
46
Bob Wilson9868d712014-10-09 05:43:30 +000047 if (T.isiOS() && T.isOSVersionLT(7, 0))
Bob Wilsond8d92d92013-11-03 06:48:38 +000048 return false;
49
50 return true;
51}
52
Sanjay Patel600d24b2017-12-15 18:54:29 +000053/// Initialize the set of available library functions based on the specified
54/// target triple. This should be carefully written so that a missing target
55/// triple gets a sane set of defaults.
Chandler Carruthc0291862015-01-24 02:06:09 +000056static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
Mehdi Amini9a72cd72016-10-01 03:10:48 +000057 ArrayRef<StringRef> StandardNames) {
Bob Wilsonc740e3f2012-08-03 04:06:22 +000058 // Verify that the StandardNames array is in alphabetical order.
Craig Toppere30b8ca2016-01-03 19:43:40 +000059 assert(std::is_sorted(StandardNames.begin(), StandardNames.end(),
Mehdi Amini9a72cd72016-10-01 03:10:48 +000060 [](StringRef LHS, StringRef RHS) {
61 return LHS < RHS;
Craig Toppere30b8ca2016-01-03 19:43:40 +000062 }) &&
63 "TargetLibraryInfoImpl function names must be sorted");
Tom Stellard36a03182014-04-02 19:53:29 +000064
Marcin Koscielnicki6af8e6c2016-11-21 20:20:39 +000065 bool ShouldExtI32Param = false, ShouldExtI32Return = false,
66 ShouldSignExtI32Param = false;
67 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
68 // returns corresponding to C-level ints and unsigned ints.
69 if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le ||
70 T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) {
71 ShouldExtI32Param = true;
72 ShouldExtI32Return = true;
73 }
74 // Mips, on the other hand, needs signext on i32 parameters corresponding
75 // to both signed and unsigned ints.
76 if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
77 T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el) {
78 ShouldSignExtI32Param = true;
79 }
80 TLI.setShouldExtI32Param(ShouldExtI32Param);
81 TLI.setShouldExtI32Return(ShouldExtI32Return);
82 TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
83
Nicolai Hahnle78fd4f02015-12-15 17:24:15 +000084 if (T.getArch() == Triple::r600 ||
85 T.getArch() == Triple::amdgcn) {
David L. Jonesd21529f2017-01-23 23:16:46 +000086 TLI.setUnavailable(LibFunc_ldexp);
87 TLI.setUnavailable(LibFunc_ldexpf);
88 TLI.setUnavailable(LibFunc_ldexpl);
89 TLI.setUnavailable(LibFunc_exp10);
90 TLI.setUnavailable(LibFunc_exp10f);
91 TLI.setUnavailable(LibFunc_exp10l);
92 TLI.setUnavailable(LibFunc_log10);
93 TLI.setUnavailable(LibFunc_log10f);
94 TLI.setUnavailable(LibFunc_log10l);
Nicolai Hahnle78fd4f02015-12-15 17:24:15 +000095 }
96
Tom Stellardd00a9232015-01-07 01:17:37 +000097 // There are no library implementations of mempcy and memset for AMD gpus and
Tom Stellard36a03182014-04-02 19:53:29 +000098 // these can be difficult to lower in the backend.
Tom Stellardd00a9232015-01-07 01:17:37 +000099 if (T.getArch() == Triple::r600 ||
Dan Gohman05532992016-01-19 14:49:23 +0000100 T.getArch() == Triple::amdgcn) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000101 TLI.setUnavailable(LibFunc_memcpy);
102 TLI.setUnavailable(LibFunc_memset);
103 TLI.setUnavailable(LibFunc_memset_pattern16);
Tom Stellard36a03182014-04-02 19:53:29 +0000104 return;
105 }
106
Nico Weberad156922014-03-07 18:08:54 +0000107 // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
Tim Northover8b403662015-10-28 22:51:16 +0000108 // All versions of watchOS support it.
Daniel Dunbarcd01ed52011-04-20 00:14:25 +0000109 if (T.isMacOSX()) {
110 if (T.isMacOSXVersionLT(10, 5))
David L. Jonesd21529f2017-01-23 23:16:46 +0000111 TLI.setUnavailable(LibFunc_memset_pattern16);
Cameron Esfahani943908b2013-08-29 20:23:14 +0000112 } else if (T.isiOS()) {
Daniel Dunbar9483bb62011-04-19 20:44:08 +0000113 if (T.isOSVersionLT(3, 0))
David L. Jonesd21529f2017-01-23 23:16:46 +0000114 TLI.setUnavailable(LibFunc_memset_pattern16);
Tim Northover8b403662015-10-28 22:51:16 +0000115 } else if (!T.isWatchOS()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000116 TLI.setUnavailable(LibFunc_memset_pattern16);
Daniel Dunbar9483bb62011-04-19 20:44:08 +0000117 }
Richard Osborne815de532011-03-03 13:17:51 +0000118
Bob Wilsond8d92d92013-11-03 06:48:38 +0000119 if (!hasSinCosPiStret(T)) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000120 TLI.setUnavailable(LibFunc_sinpi);
121 TLI.setUnavailable(LibFunc_sinpif);
122 TLI.setUnavailable(LibFunc_cospi);
123 TLI.setUnavailable(LibFunc_cospif);
124 TLI.setUnavailable(LibFunc_sincospi_stret);
125 TLI.setUnavailable(LibFunc_sincospif_stret);
Bob Wilsond8d92d92013-11-03 06:48:38 +0000126 }
127
Eli Friedman489c0ff2011-11-17 01:27:36 +0000128 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
129 !T.isMacOSXVersionLT(10, 7)) {
130 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
131 // we don't care about) have two versions; on recent OSX, the one we want
132 // has a $UNIX2003 suffix. The two implementations are identical except
133 // for the return value in some edge cases. However, we don't want to
134 // generate code that depends on the old symbols.
David L. Jonesd21529f2017-01-23 23:16:46 +0000135 TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
136 TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
Eli Friedman489c0ff2011-11-17 01:27:36 +0000137 }
138
Duncan Sandseeb50c82011-06-09 11:11:45 +0000139 // iprintf and friends are only available on XCore and TCE.
140 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000141 TLI.setUnavailable(LibFunc_iprintf);
142 TLI.setUnavailable(LibFunc_siprintf);
143 TLI.setUnavailable(LibFunc_fiprintf);
Richard Osborne2dfb8882011-03-03 14:09:28 +0000144 }
Joe Groffa81bcbb2012-04-17 23:05:54 +0000145
Saleem Abdulrasool8dc8fb12014-07-24 22:09:06 +0000146 if (T.isOSWindows() && !T.isOSCygMing()) {
Joe Groffa81bcbb2012-04-17 23:05:54 +0000147 // Win32 does not support long double
David L. Jonesd21529f2017-01-23 23:16:46 +0000148 TLI.setUnavailable(LibFunc_acosl);
149 TLI.setUnavailable(LibFunc_asinl);
150 TLI.setUnavailable(LibFunc_atanl);
151 TLI.setUnavailable(LibFunc_atan2l);
152 TLI.setUnavailable(LibFunc_ceill);
153 TLI.setUnavailable(LibFunc_copysignl);
154 TLI.setUnavailable(LibFunc_cosl);
155 TLI.setUnavailable(LibFunc_coshl);
156 TLI.setUnavailable(LibFunc_expl);
157 TLI.setUnavailable(LibFunc_fabsf); // Win32 and Win64 both lack fabsf
158 TLI.setUnavailable(LibFunc_fabsl);
159 TLI.setUnavailable(LibFunc_floorl);
160 TLI.setUnavailable(LibFunc_fmaxl);
161 TLI.setUnavailable(LibFunc_fminl);
162 TLI.setUnavailable(LibFunc_fmodl);
163 TLI.setUnavailable(LibFunc_frexpl);
164 TLI.setUnavailable(LibFunc_ldexpf);
165 TLI.setUnavailable(LibFunc_ldexpl);
166 TLI.setUnavailable(LibFunc_logl);
167 TLI.setUnavailable(LibFunc_modfl);
168 TLI.setUnavailable(LibFunc_powl);
169 TLI.setUnavailable(LibFunc_sinl);
170 TLI.setUnavailable(LibFunc_sinhl);
171 TLI.setUnavailable(LibFunc_sqrtl);
172 TLI.setUnavailable(LibFunc_tanl);
173 TLI.setUnavailable(LibFunc_tanhl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000174
175 // Win32 only has C89 math
David L. Jonesd21529f2017-01-23 23:16:46 +0000176 TLI.setUnavailable(LibFunc_acosh);
177 TLI.setUnavailable(LibFunc_acoshf);
178 TLI.setUnavailable(LibFunc_acoshl);
179 TLI.setUnavailable(LibFunc_asinh);
180 TLI.setUnavailable(LibFunc_asinhf);
181 TLI.setUnavailable(LibFunc_asinhl);
182 TLI.setUnavailable(LibFunc_atanh);
183 TLI.setUnavailable(LibFunc_atanhf);
184 TLI.setUnavailable(LibFunc_atanhl);
Hal Finkel2ff24732017-12-16 01:26:25 +0000185 TLI.setUnavailable(LibFunc_cabs);
186 TLI.setUnavailable(LibFunc_cabsf);
187 TLI.setUnavailable(LibFunc_cabsl);
David L. Jonesd21529f2017-01-23 23:16:46 +0000188 TLI.setUnavailable(LibFunc_cbrt);
189 TLI.setUnavailable(LibFunc_cbrtf);
190 TLI.setUnavailable(LibFunc_cbrtl);
191 TLI.setUnavailable(LibFunc_exp2);
192 TLI.setUnavailable(LibFunc_exp2f);
193 TLI.setUnavailable(LibFunc_exp2l);
194 TLI.setUnavailable(LibFunc_expm1);
195 TLI.setUnavailable(LibFunc_expm1f);
196 TLI.setUnavailable(LibFunc_expm1l);
197 TLI.setUnavailable(LibFunc_log2);
198 TLI.setUnavailable(LibFunc_log2f);
199 TLI.setUnavailable(LibFunc_log2l);
200 TLI.setUnavailable(LibFunc_log1p);
201 TLI.setUnavailable(LibFunc_log1pf);
202 TLI.setUnavailable(LibFunc_log1pl);
203 TLI.setUnavailable(LibFunc_logb);
204 TLI.setUnavailable(LibFunc_logbf);
205 TLI.setUnavailable(LibFunc_logbl);
206 TLI.setUnavailable(LibFunc_nearbyint);
207 TLI.setUnavailable(LibFunc_nearbyintf);
208 TLI.setUnavailable(LibFunc_nearbyintl);
209 TLI.setUnavailable(LibFunc_rint);
210 TLI.setUnavailable(LibFunc_rintf);
211 TLI.setUnavailable(LibFunc_rintl);
212 TLI.setUnavailable(LibFunc_round);
213 TLI.setUnavailable(LibFunc_roundf);
214 TLI.setUnavailable(LibFunc_roundl);
215 TLI.setUnavailable(LibFunc_trunc);
216 TLI.setUnavailable(LibFunc_truncf);
217 TLI.setUnavailable(LibFunc_truncl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000218
219 // Win32 provides some C99 math with mangled names
David L. Jonesd21529f2017-01-23 23:16:46 +0000220 TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
Joe Groffa81bcbb2012-04-17 23:05:54 +0000221
222 if (T.getArch() == Triple::x86) {
223 // Win32 on x86 implements single-precision math functions as macros
David L. Jonesd21529f2017-01-23 23:16:46 +0000224 TLI.setUnavailable(LibFunc_acosf);
225 TLI.setUnavailable(LibFunc_asinf);
226 TLI.setUnavailable(LibFunc_atanf);
227 TLI.setUnavailable(LibFunc_atan2f);
228 TLI.setUnavailable(LibFunc_ceilf);
229 TLI.setUnavailable(LibFunc_copysignf);
230 TLI.setUnavailable(LibFunc_cosf);
231 TLI.setUnavailable(LibFunc_coshf);
232 TLI.setUnavailable(LibFunc_expf);
233 TLI.setUnavailable(LibFunc_floorf);
234 TLI.setUnavailable(LibFunc_fminf);
235 TLI.setUnavailable(LibFunc_fmaxf);
236 TLI.setUnavailable(LibFunc_fmodf);
237 TLI.setUnavailable(LibFunc_logf);
238 TLI.setUnavailable(LibFunc_log10f);
239 TLI.setUnavailable(LibFunc_modff);
240 TLI.setUnavailable(LibFunc_powf);
241 TLI.setUnavailable(LibFunc_sinf);
242 TLI.setUnavailable(LibFunc_sinhf);
243 TLI.setUnavailable(LibFunc_sqrtf);
244 TLI.setUnavailable(LibFunc_tanf);
245 TLI.setUnavailable(LibFunc_tanhf);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000246 }
Meador Inge2526a422012-11-10 03:11:06 +0000247
Andrew Kaylor3cd8c162017-05-12 22:11:12 +0000248 // These definitions are due to math-finite.h header on Linux
249 TLI.setUnavailable(LibFunc_acos_finite);
250 TLI.setUnavailable(LibFunc_acosf_finite);
251 TLI.setUnavailable(LibFunc_acosl_finite);
252 TLI.setUnavailable(LibFunc_acosh_finite);
253 TLI.setUnavailable(LibFunc_acoshf_finite);
254 TLI.setUnavailable(LibFunc_acoshl_finite);
255 TLI.setUnavailable(LibFunc_asin_finite);
256 TLI.setUnavailable(LibFunc_asinf_finite);
257 TLI.setUnavailable(LibFunc_asinl_finite);
258 TLI.setUnavailable(LibFunc_atan2_finite);
259 TLI.setUnavailable(LibFunc_atan2f_finite);
260 TLI.setUnavailable(LibFunc_atan2l_finite);
261 TLI.setUnavailable(LibFunc_atanh_finite);
262 TLI.setUnavailable(LibFunc_atanhf_finite);
263 TLI.setUnavailable(LibFunc_atanhl_finite);
264 TLI.setUnavailable(LibFunc_cosh_finite);
265 TLI.setUnavailable(LibFunc_coshf_finite);
266 TLI.setUnavailable(LibFunc_coshl_finite);
267 TLI.setUnavailable(LibFunc_exp10_finite);
268 TLI.setUnavailable(LibFunc_exp10f_finite);
269 TLI.setUnavailable(LibFunc_exp10l_finite);
270 TLI.setUnavailable(LibFunc_exp2_finite);
271 TLI.setUnavailable(LibFunc_exp2f_finite);
272 TLI.setUnavailable(LibFunc_exp2l_finite);
273 TLI.setUnavailable(LibFunc_exp_finite);
274 TLI.setUnavailable(LibFunc_expf_finite);
275 TLI.setUnavailable(LibFunc_expl_finite);
276 TLI.setUnavailable(LibFunc_log10_finite);
277 TLI.setUnavailable(LibFunc_log10f_finite);
278 TLI.setUnavailable(LibFunc_log10l_finite);
279 TLI.setUnavailable(LibFunc_log2_finite);
280 TLI.setUnavailable(LibFunc_log2f_finite);
281 TLI.setUnavailable(LibFunc_log2l_finite);
282 TLI.setUnavailable(LibFunc_log_finite);
283 TLI.setUnavailable(LibFunc_logf_finite);
284 TLI.setUnavailable(LibFunc_logl_finite);
285 TLI.setUnavailable(LibFunc_pow_finite);
286 TLI.setUnavailable(LibFunc_powf_finite);
287 TLI.setUnavailable(LibFunc_powl_finite);
288 TLI.setUnavailable(LibFunc_sinh_finite);
289 TLI.setUnavailable(LibFunc_sinhf_finite);
290 TLI.setUnavailable(LibFunc_sinhl_finite);
291
Meador Ingeb904e6e2013-03-05 21:47:40 +0000292 // Win32 does *not* provide provide these functions, but they are
293 // generally available on POSIX-compliant systems:
David L. Jonesd21529f2017-01-23 23:16:46 +0000294 TLI.setUnavailable(LibFunc_access);
295 TLI.setUnavailable(LibFunc_bcmp);
296 TLI.setUnavailable(LibFunc_bcopy);
297 TLI.setUnavailable(LibFunc_bzero);
298 TLI.setUnavailable(LibFunc_chmod);
299 TLI.setUnavailable(LibFunc_chown);
300 TLI.setUnavailable(LibFunc_closedir);
301 TLI.setUnavailable(LibFunc_ctermid);
302 TLI.setUnavailable(LibFunc_fdopen);
303 TLI.setUnavailable(LibFunc_ffs);
304 TLI.setUnavailable(LibFunc_fileno);
305 TLI.setUnavailable(LibFunc_flockfile);
306 TLI.setUnavailable(LibFunc_fseeko);
307 TLI.setUnavailable(LibFunc_fstat);
308 TLI.setUnavailable(LibFunc_fstatvfs);
309 TLI.setUnavailable(LibFunc_ftello);
310 TLI.setUnavailable(LibFunc_ftrylockfile);
311 TLI.setUnavailable(LibFunc_funlockfile);
312 TLI.setUnavailable(LibFunc_getc_unlocked);
313 TLI.setUnavailable(LibFunc_getitimer);
314 TLI.setUnavailable(LibFunc_getlogin_r);
315 TLI.setUnavailable(LibFunc_getpwnam);
316 TLI.setUnavailable(LibFunc_gettimeofday);
317 TLI.setUnavailable(LibFunc_htonl);
318 TLI.setUnavailable(LibFunc_htons);
319 TLI.setUnavailable(LibFunc_lchown);
320 TLI.setUnavailable(LibFunc_lstat);
321 TLI.setUnavailable(LibFunc_memccpy);
322 TLI.setUnavailable(LibFunc_mkdir);
323 TLI.setUnavailable(LibFunc_ntohl);
324 TLI.setUnavailable(LibFunc_ntohs);
325 TLI.setUnavailable(LibFunc_open);
326 TLI.setUnavailable(LibFunc_opendir);
327 TLI.setUnavailable(LibFunc_pclose);
328 TLI.setUnavailable(LibFunc_popen);
329 TLI.setUnavailable(LibFunc_pread);
330 TLI.setUnavailable(LibFunc_pwrite);
331 TLI.setUnavailable(LibFunc_read);
332 TLI.setUnavailable(LibFunc_readlink);
333 TLI.setUnavailable(LibFunc_realpath);
334 TLI.setUnavailable(LibFunc_rmdir);
335 TLI.setUnavailable(LibFunc_setitimer);
336 TLI.setUnavailable(LibFunc_stat);
337 TLI.setUnavailable(LibFunc_statvfs);
338 TLI.setUnavailable(LibFunc_stpcpy);
339 TLI.setUnavailable(LibFunc_stpncpy);
340 TLI.setUnavailable(LibFunc_strcasecmp);
341 TLI.setUnavailable(LibFunc_strncasecmp);
342 TLI.setUnavailable(LibFunc_times);
343 TLI.setUnavailable(LibFunc_uname);
344 TLI.setUnavailable(LibFunc_unlink);
345 TLI.setUnavailable(LibFunc_unsetenv);
346 TLI.setUnavailable(LibFunc_utime);
347 TLI.setUnavailable(LibFunc_utimes);
348 TLI.setUnavailable(LibFunc_write);
Meador Inge780a1862012-11-22 15:36:42 +0000349
Meador Ingeb904e6e2013-03-05 21:47:40 +0000350 // Win32 does *not* provide provide these functions, but they are
351 // specified by C99:
David L. Jonesd21529f2017-01-23 23:16:46 +0000352 TLI.setUnavailable(LibFunc_atoll);
353 TLI.setUnavailable(LibFunc_frexpf);
354 TLI.setUnavailable(LibFunc_llabs);
Meador Inge780a1862012-11-22 15:36:42 +0000355 }
356
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000357 switch (T.getOS()) {
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000358 case Triple::MacOSX:
Chandler Carruthf5689f82013-12-28 02:40:19 +0000359 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
360 // and their names are __exp10 and __exp10f. exp10l is not available on
361 // OS X or iOS.
David L. Jonesd21529f2017-01-23 23:16:46 +0000362 TLI.setUnavailable(LibFunc_exp10l);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000363 if (T.isMacOSXVersionLT(10, 9)) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000364 TLI.setUnavailable(LibFunc_exp10);
365 TLI.setUnavailable(LibFunc_exp10f);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000366 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000367 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
368 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000369 }
370 break;
371 case Triple::IOS:
Tim Northover89a6eef2015-11-02 18:00:00 +0000372 case Triple::TvOS:
Tim Northover8b403662015-10-28 22:51:16 +0000373 case Triple::WatchOS:
David L. Jonesd21529f2017-01-23 23:16:46 +0000374 TLI.setUnavailable(LibFunc_exp10l);
Tim Northover8b403662015-10-28 22:51:16 +0000375 if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
376 (T.isOSVersionLT(9, 0) &&
377 (T.getArch() == Triple::x86 ||
378 T.getArch() == Triple::x86_64)))) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000379 TLI.setUnavailable(LibFunc_exp10);
380 TLI.setUnavailable(LibFunc_exp10f);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000381 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000382 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
383 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000384 }
385 break;
Chandler Carruthf5689f82013-12-28 02:40:19 +0000386 case Triple::Linux:
387 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
388 // buggy prior to glibc version 2.18. Until this version is widely deployed
389 // or we have a reasonable detection strategy, we cannot use exp10 reliably
390 // on Linux.
391 //
392 // Fall through to disable all of them.
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000393 LLVM_FALLTHROUGH;
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000394 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000395 TLI.setUnavailable(LibFunc_exp10);
396 TLI.setUnavailable(LibFunc_exp10f);
397 TLI.setUnavailable(LibFunc_exp10l);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000398 }
399
Meador Inge780a1862012-11-22 15:36:42 +0000400 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
401 // Linux (GLIBC):
402 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
Davide Italiano83b34812015-11-01 17:00:13 +0000403 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
Meador Inge780a1862012-11-22 15:36:42 +0000404 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
405 switch (T.getOS()) {
406 case Triple::Darwin:
407 case Triple::MacOSX:
408 case Triple::IOS:
Tim Northover89a6eef2015-11-02 18:00:00 +0000409 case Triple::TvOS:
Tim Northover8b403662015-10-28 22:51:16 +0000410 case Triple::WatchOS:
Meador Inge780a1862012-11-22 15:36:42 +0000411 case Triple::FreeBSD:
412 case Triple::Linux:
413 break;
414 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000415 TLI.setUnavailable(LibFunc_ffsl);
Meador Inge780a1862012-11-22 15:36:42 +0000416 }
417
418 // ffsll is available on at least FreeBSD and Linux (GLIBC):
Davide Italiano83b34812015-11-01 17:00:13 +0000419 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
Meador Inge780a1862012-11-22 15:36:42 +0000420 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
421 switch (T.getOS()) {
Tim Northover89a6eef2015-11-02 18:00:00 +0000422 case Triple::Darwin:
423 case Triple::MacOSX:
424 case Triple::IOS:
425 case Triple::TvOS:
426 case Triple::WatchOS:
Meador Inge780a1862012-11-22 15:36:42 +0000427 case Triple::FreeBSD:
428 case Triple::Linux:
429 break;
430 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000431 TLI.setUnavailable(LibFunc_ffsll);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000432 }
Meador Ingeb904e6e2013-03-05 21:47:40 +0000433
Davide Italianobfd30822015-11-09 23:23:20 +0000434 // The following functions are available on at least FreeBSD:
435 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
436 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
437 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
438 if (!T.isOSFreeBSD()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000439 TLI.setUnavailable(LibFunc_fls);
440 TLI.setUnavailable(LibFunc_flsl);
441 TLI.setUnavailable(LibFunc_flsll);
Davide Italianobfd30822015-11-09 23:23:20 +0000442 }
443
Meador Ingeb904e6e2013-03-05 21:47:40 +0000444 // The following functions are available on at least Linux:
Cameron Esfahani943908b2013-08-29 20:23:14 +0000445 if (!T.isOSLinux()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000446 TLI.setUnavailable(LibFunc_dunder_strdup);
447 TLI.setUnavailable(LibFunc_dunder_strtok_r);
448 TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
449 TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
450 TLI.setUnavailable(LibFunc_under_IO_getc);
451 TLI.setUnavailable(LibFunc_under_IO_putc);
452 TLI.setUnavailable(LibFunc_memalign);
453 TLI.setUnavailable(LibFunc_fopen64);
454 TLI.setUnavailable(LibFunc_fseeko64);
455 TLI.setUnavailable(LibFunc_fstat64);
456 TLI.setUnavailable(LibFunc_fstatvfs64);
457 TLI.setUnavailable(LibFunc_ftello64);
458 TLI.setUnavailable(LibFunc_lstat64);
459 TLI.setUnavailable(LibFunc_open64);
460 TLI.setUnavailable(LibFunc_stat64);
461 TLI.setUnavailable(LibFunc_statvfs64);
462 TLI.setUnavailable(LibFunc_tmpfile64);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000463 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000464
Justin Lebar51132882016-01-26 23:51:06 +0000465 // As currently implemented in clang, NVPTX code has no standard library to
466 // speak of. Headers provide a standard-ish library implementation, but many
467 // of the signatures are wrong -- for example, many libm functions are not
468 // extern "C".
469 //
470 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
471 // but only used functions are provided to llvm. Moreover, most of the
472 // functions in libdevice don't map precisely to standard library functions.
473 //
474 // FIXME: Having no standard library prevents e.g. many fastmath
475 // optimizations, so this situation should be fixed.
David Majnemerae272d72016-03-31 21:29:57 +0000476 if (T.isNVPTX()) {
Justin Lebar51132882016-01-26 23:51:06 +0000477 TLI.disableAllFunctions();
David L. Jonesd21529f2017-01-23 23:16:46 +0000478 TLI.setAvailable(LibFunc_nvvm_reflect);
David Majnemerae272d72016-03-31 21:29:57 +0000479 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000480 TLI.setUnavailable(LibFunc_nvvm_reflect);
David Majnemerae272d72016-03-31 21:29:57 +0000481 }
Justin Lebar51132882016-01-26 23:51:06 +0000482
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000483 TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000484}
485
Chandler Carruthc0291862015-01-24 02:06:09 +0000486TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000487 // Default to everything being available.
488 memset(AvailableArray, -1, sizeof(AvailableArray));
489
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000490 initialize(*this, Triple(), StandardNames);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000491}
492
Chandler Carruthc0291862015-01-24 02:06:09 +0000493TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000494 // Default to everything being available.
495 memset(AvailableArray, -1, sizeof(AvailableArray));
Chandler Carruthb98f63d2015-01-15 10:41:28 +0000496
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000497 initialize(*this, T, StandardNames);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000498}
Chris Lattner1341df92011-02-18 22:34:03 +0000499
Chandler Carruthc0291862015-01-24 02:06:09 +0000500TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000501 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
502 ShouldExtI32Return(TLI.ShouldExtI32Return),
503 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000504 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
Michael Zolotukhine8f25512015-03-17 19:22:30 +0000505 VectorDescs = TLI.VectorDescs;
506 ScalarDescs = TLI.ScalarDescs;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000507}
508
Chandler Carruthc0291862015-01-24 02:06:09 +0000509TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000510 : CustomNames(std::move(TLI.CustomNames)),
511 ShouldExtI32Param(TLI.ShouldExtI32Param),
512 ShouldExtI32Return(TLI.ShouldExtI32Return),
513 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
Chandler Carruth8ca43222015-01-15 11:39:46 +0000514 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
515 AvailableArray);
Michael Zolotukhine8f25512015-03-17 19:22:30 +0000516 VectorDescs = TLI.VectorDescs;
517 ScalarDescs = TLI.ScalarDescs;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000518}
519
Chandler Carruthc0291862015-01-24 02:06:09 +0000520TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
Eli Friedman489c0ff2011-11-17 01:27:36 +0000521 CustomNames = TLI.CustomNames;
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000522 ShouldExtI32Param = TLI.ShouldExtI32Param;
523 ShouldExtI32Return = TLI.ShouldExtI32Return;
524 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000525 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
526 return *this;
527}
528
Chandler Carruthc0291862015-01-24 02:06:09 +0000529TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
Chandler Carruth8ca43222015-01-15 11:39:46 +0000530 CustomNames = std::move(TLI.CustomNames);
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000531 ShouldExtI32Param = TLI.ShouldExtI32Param;
532 ShouldExtI32Return = TLI.ShouldExtI32Return;
533 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000534 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
535 AvailableArray);
536 return *this;
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000537}
538
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000539static StringRef sanitizeFunctionName(StringRef funcName) {
Benjamin Kramer160f72d2013-03-09 13:48:23 +0000540 // Filter out empty names and names containing null bytes, those can't be in
541 // our table.
542 if (funcName.empty() || funcName.find('\0') != StringRef::npos)
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000543 return StringRef();
Benjamin Kramer160f72d2013-03-09 13:48:23 +0000544
Meador Ingeb904e6e2013-03-05 21:47:40 +0000545 // Check for \01 prefix that is used to mangle __asm declarations and
546 // strip it if present.
Peter Collingbourne6f0ecca2017-05-16 00:39:01 +0000547 return GlobalValue::dropLLVMManglingEscape(funcName);
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000548}
549
550bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
David L. Jonesd21529f2017-01-23 23:16:46 +0000551 LibFunc &F) const {
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000552 StringRef const *Start = &StandardNames[0];
David L. Jonesd21529f2017-01-23 23:16:46 +0000553 StringRef const *End = &StandardNames[NumLibFuncs];
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000554
555 funcName = sanitizeFunctionName(funcName);
556 if (funcName.empty())
557 return false;
558
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000559 StringRef const *I = std::lower_bound(
560 Start, End, funcName, [](StringRef LHS, StringRef RHS) {
561 return LHS < RHS;
Michael Zolotukhind3b76a32015-03-02 20:50:08 +0000562 });
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000563 if (I != End && *I == funcName) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000564 F = (LibFunc)(I - Start);
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000565 return true;
566 }
567 return false;
568}
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000569
Ahmed Bougachad765a822016-04-27 19:04:35 +0000570bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
David L. Jonesd21529f2017-01-23 23:16:46 +0000571 LibFunc F,
Ahmed Bougachad765a822016-04-27 19:04:35 +0000572 const DataLayout *DL) const {
573 LLVMContext &Ctx = FTy.getContext();
574 Type *PCharTy = Type::getInt8PtrTy(Ctx);
575 Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
576 auto IsSizeTTy = [SizeTTy](Type *Ty) {
577 return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
578 };
579 unsigned NumParams = FTy.getNumParams();
580
581 switch (F) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000582 case LibFunc_strlen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000583 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
584 FTy.getReturnType()->isIntegerTy());
585
David L. Jonesd21529f2017-01-23 23:16:46 +0000586 case LibFunc_strchr:
587 case LibFunc_strrchr:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000588 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
589 FTy.getParamType(0) == FTy.getReturnType() &&
590 FTy.getParamType(1)->isIntegerTy());
591
David L. Jonesd21529f2017-01-23 23:16:46 +0000592 case LibFunc_strtol:
593 case LibFunc_strtod:
594 case LibFunc_strtof:
595 case LibFunc_strtoul:
596 case LibFunc_strtoll:
597 case LibFunc_strtold:
598 case LibFunc_strtoull:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000599 return ((NumParams == 2 || NumParams == 3) &&
600 FTy.getParamType(0)->isPointerTy() &&
601 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000602 case LibFunc_strcat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000603 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
604 FTy.getParamType(0) == FTy.getReturnType() &&
605 FTy.getParamType(1) == FTy.getReturnType());
606
David L. Jonesd21529f2017-01-23 23:16:46 +0000607 case LibFunc_strncat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000608 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
609 FTy.getParamType(0) == FTy.getReturnType() &&
610 FTy.getParamType(1) == FTy.getReturnType() &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000611 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000612
David L. Jonesd21529f2017-01-23 23:16:46 +0000613 case LibFunc_strcpy_chk:
614 case LibFunc_stpcpy_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000615 --NumParams;
616 if (!IsSizeTTy(FTy.getParamType(NumParams)))
617 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000618 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000619 case LibFunc_strcpy:
620 case LibFunc_stpcpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000621 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
622 FTy.getParamType(0) == FTy.getParamType(1) &&
623 FTy.getParamType(0) == PCharTy);
624
David L. Jonesd21529f2017-01-23 23:16:46 +0000625 case LibFunc_strncpy_chk:
626 case LibFunc_stpncpy_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000627 --NumParams;
628 if (!IsSizeTTy(FTy.getParamType(NumParams)))
629 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000630 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000631 case LibFunc_strncpy:
632 case LibFunc_stpncpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000633 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
634 FTy.getParamType(0) == FTy.getParamType(1) &&
635 FTy.getParamType(0) == PCharTy &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000636 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000637
David L. Jonesd21529f2017-01-23 23:16:46 +0000638 case LibFunc_strxfrm:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000639 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
640 FTy.getParamType(1)->isPointerTy());
641
David L. Jonesd21529f2017-01-23 23:16:46 +0000642 case LibFunc_strcmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000643 return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
644 FTy.getParamType(0)->isPointerTy() &&
645 FTy.getParamType(0) == FTy.getParamType(1));
646
David L. Jonesd21529f2017-01-23 23:16:46 +0000647 case LibFunc_strncmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000648 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
649 FTy.getParamType(0)->isPointerTy() &&
650 FTy.getParamType(0) == FTy.getParamType(1) &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000651 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000652
David L. Jonesd21529f2017-01-23 23:16:46 +0000653 case LibFunc_strspn:
654 case LibFunc_strcspn:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000655 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
656 FTy.getParamType(0) == FTy.getParamType(1) &&
657 FTy.getReturnType()->isIntegerTy());
658
David L. Jonesd21529f2017-01-23 23:16:46 +0000659 case LibFunc_strcoll:
660 case LibFunc_strcasecmp:
661 case LibFunc_strncasecmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000662 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
663 FTy.getParamType(1)->isPointerTy());
664
David L. Jonesd21529f2017-01-23 23:16:46 +0000665 case LibFunc_strstr:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000666 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
667 FTy.getParamType(0)->isPointerTy() &&
668 FTy.getParamType(1)->isPointerTy());
669
David L. Jonesd21529f2017-01-23 23:16:46 +0000670 case LibFunc_strpbrk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000671 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
672 FTy.getReturnType() == FTy.getParamType(0) &&
673 FTy.getParamType(0) == FTy.getParamType(1));
674
David L. Jonesd21529f2017-01-23 23:16:46 +0000675 case LibFunc_strtok:
676 case LibFunc_strtok_r:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000677 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000678 case LibFunc_scanf:
679 case LibFunc_setbuf:
680 case LibFunc_setvbuf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000681 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000682 case LibFunc_strdup:
683 case LibFunc_strndup:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000684 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
685 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000686 case LibFunc_sscanf:
687 case LibFunc_stat:
688 case LibFunc_statvfs:
689 case LibFunc_siprintf:
690 case LibFunc_sprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000691 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
692 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000693 case LibFunc_snprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000694 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
695 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000696 case LibFunc_setitimer:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000697 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
698 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000699 case LibFunc_system:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000700 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000701 case LibFunc_malloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000702 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000703 case LibFunc_memcmp:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000704 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
705 FTy.getParamType(0)->isPointerTy() &&
706 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000707
David L. Jonesd21529f2017-01-23 23:16:46 +0000708 case LibFunc_memchr:
709 case LibFunc_memrchr:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000710 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
711 FTy.getReturnType() == FTy.getParamType(0) &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000712 FTy.getParamType(1)->isIntegerTy(32) &&
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000713 IsSizeTTy(FTy.getParamType(2)));
David L. Jonesd21529f2017-01-23 23:16:46 +0000714 case LibFunc_modf:
715 case LibFunc_modff:
716 case LibFunc_modfl:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000717 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
718
David L. Jonesd21529f2017-01-23 23:16:46 +0000719 case LibFunc_memcpy_chk:
720 case LibFunc_memmove_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000721 --NumParams;
722 if (!IsSizeTTy(FTy.getParamType(NumParams)))
723 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000724 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000725 case LibFunc_memcpy:
726 case LibFunc_mempcpy:
727 case LibFunc_memmove:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000728 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
729 FTy.getParamType(0)->isPointerTy() &&
730 FTy.getParamType(1)->isPointerTy() &&
731 IsSizeTTy(FTy.getParamType(2)));
732
David L. Jonesd21529f2017-01-23 23:16:46 +0000733 case LibFunc_memset_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000734 --NumParams;
735 if (!IsSizeTTy(FTy.getParamType(NumParams)))
736 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000737 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000738 case LibFunc_memset:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000739 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
740 FTy.getParamType(0)->isPointerTy() &&
741 FTy.getParamType(1)->isIntegerTy() &&
742 IsSizeTTy(FTy.getParamType(2)));
743
David L. Jonesd21529f2017-01-23 23:16:46 +0000744 case LibFunc_memccpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000745 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000746 case LibFunc_memalign:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000747 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000748 case LibFunc_realloc:
749 case LibFunc_reallocf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000750 return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
751 FTy.getParamType(0) == FTy.getReturnType() &&
752 IsSizeTTy(FTy.getParamType(1)));
David L. Jonesd21529f2017-01-23 23:16:46 +0000753 case LibFunc_read:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000754 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000755 case LibFunc_rewind:
756 case LibFunc_rmdir:
757 case LibFunc_remove:
758 case LibFunc_realpath:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000759 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000760 case LibFunc_rename:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000761 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
762 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000763 case LibFunc_readlink:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000764 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
765 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000766 case LibFunc_write:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000767 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000768 case LibFunc_bcopy:
769 case LibFunc_bcmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000770 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
771 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000772 case LibFunc_bzero:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000773 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000774 case LibFunc_calloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000775 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000776
David L. Jonesd21529f2017-01-23 23:16:46 +0000777 case LibFunc_atof:
778 case LibFunc_atoi:
779 case LibFunc_atol:
780 case LibFunc_atoll:
781 case LibFunc_ferror:
782 case LibFunc_getenv:
783 case LibFunc_getpwnam:
784 case LibFunc_iprintf:
785 case LibFunc_pclose:
786 case LibFunc_perror:
787 case LibFunc_printf:
788 case LibFunc_puts:
789 case LibFunc_uname:
790 case LibFunc_under_IO_getc:
791 case LibFunc_unlink:
792 case LibFunc_unsetenv:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000793 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000794
David L. Jonesd21529f2017-01-23 23:16:46 +0000795 case LibFunc_access:
796 case LibFunc_chmod:
797 case LibFunc_chown:
798 case LibFunc_clearerr:
799 case LibFunc_closedir:
800 case LibFunc_ctermid:
801 case LibFunc_fclose:
802 case LibFunc_feof:
803 case LibFunc_fflush:
804 case LibFunc_fgetc:
805 case LibFunc_fileno:
806 case LibFunc_flockfile:
807 case LibFunc_free:
808 case LibFunc_fseek:
809 case LibFunc_fseeko64:
810 case LibFunc_fseeko:
811 case LibFunc_fsetpos:
812 case LibFunc_ftell:
813 case LibFunc_ftello64:
814 case LibFunc_ftello:
815 case LibFunc_ftrylockfile:
816 case LibFunc_funlockfile:
817 case LibFunc_getc:
818 case LibFunc_getc_unlocked:
819 case LibFunc_getlogin_r:
820 case LibFunc_mkdir:
821 case LibFunc_mktime:
822 case LibFunc_times:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000823 return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
824
David L. Jonesd21529f2017-01-23 23:16:46 +0000825 case LibFunc_fopen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000826 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
827 FTy.getParamType(0)->isPointerTy() &&
828 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000829 case LibFunc_fdopen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000830 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
831 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000832 case LibFunc_fputc:
833 case LibFunc_fstat:
834 case LibFunc_frexp:
835 case LibFunc_frexpf:
836 case LibFunc_frexpl:
837 case LibFunc_fstatvfs:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000838 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000839 case LibFunc_fgets:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000840 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
841 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000842 case LibFunc_fread:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000843 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
844 FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000845 case LibFunc_fwrite:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000846 return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
847 FTy.getParamType(0)->isPointerTy() &&
848 FTy.getParamType(1)->isIntegerTy() &&
849 FTy.getParamType(2)->isIntegerTy() &&
850 FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000851 case LibFunc_fputs:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000852 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
853 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000854 case LibFunc_fscanf:
855 case LibFunc_fiprintf:
856 case LibFunc_fprintf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000857 return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
858 FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000859 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000860 case LibFunc_fgetpos:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000861 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
862 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000863 case LibFunc_getchar:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000864 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000865 case LibFunc_gets:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000866 return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
David L. Jonesd21529f2017-01-23 23:16:46 +0000867 case LibFunc_getitimer:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000868 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000869 case LibFunc_ungetc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000870 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000871 case LibFunc_utime:
872 case LibFunc_utimes:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000873 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
874 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000875 case LibFunc_putc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000876 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000877 case LibFunc_pread:
878 case LibFunc_pwrite:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000879 return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000880 case LibFunc_popen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000881 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
882 FTy.getParamType(0)->isPointerTy() &&
883 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000884 case LibFunc_vscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000885 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000886 case LibFunc_vsscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000887 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
888 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000889 case LibFunc_vfscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000890 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
891 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000892 case LibFunc_valloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000893 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000894 case LibFunc_vprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000895 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000896 case LibFunc_vfprintf:
897 case LibFunc_vsprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000898 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
899 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000900 case LibFunc_vsnprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000901 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
902 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000903 case LibFunc_open:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000904 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000905 case LibFunc_opendir:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000906 return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
907 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000908 case LibFunc_tmpfile:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000909 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000910 case LibFunc_htonl:
911 case LibFunc_ntohl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000912 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
913 FTy.getReturnType() == FTy.getParamType(0));
David L. Jonesd21529f2017-01-23 23:16:46 +0000914 case LibFunc_htons:
915 case LibFunc_ntohs:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000916 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
917 FTy.getReturnType() == FTy.getParamType(0));
David L. Jonesd21529f2017-01-23 23:16:46 +0000918 case LibFunc_lstat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000919 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
920 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000921 case LibFunc_lchown:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000922 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000923 case LibFunc_qsort:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000924 return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000925 case LibFunc_dunder_strdup:
926 case LibFunc_dunder_strndup:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000927 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
928 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000929 case LibFunc_dunder_strtok_r:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000930 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000931 case LibFunc_under_IO_putc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000932 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000933 case LibFunc_dunder_isoc99_scanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000934 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000935 case LibFunc_stat64:
936 case LibFunc_lstat64:
937 case LibFunc_statvfs64:
Michael Kuperstein79dcc272016-09-20 23:10:31 +0000938 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000939 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000940 case LibFunc_dunder_isoc99_sscanf:
Michael Kuperstein79dcc272016-09-20 23:10:31 +0000941 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000942 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000943 case LibFunc_fopen64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000944 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
945 FTy.getParamType(0)->isPointerTy() &&
946 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000947 case LibFunc_tmpfile64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000948 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000949 case LibFunc_fstat64:
950 case LibFunc_fstatvfs64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000951 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000952 case LibFunc_open64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000953 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000954 case LibFunc_gettimeofday:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000955 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
956 FTy.getParamType(1)->isPointerTy());
957
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000958 // new(unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000959 case LibFunc_Znwj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000960 // new(unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000961 case LibFunc_Znwm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000962 // new[](unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000963 case LibFunc_Znaj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000964 // new[](unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000965 case LibFunc_Znam:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000966 // new(unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000967 case LibFunc_msvc_new_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000968 // new(unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000969 case LibFunc_msvc_new_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000970 // new[](unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000971 case LibFunc_msvc_new_array_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000972 // new[](unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000973 case LibFunc_msvc_new_array_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000974 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
975
976 // new(unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000977 case LibFunc_ZnwjRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000978 // new(unsigned long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000979 case LibFunc_ZnwmRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000980 // new[](unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000981 case LibFunc_ZnajRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000982 // new[](unsigned long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000983 case LibFunc_ZnamRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000984 // new(unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000985 case LibFunc_msvc_new_int_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000986 // new(unsigned long long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000987 case LibFunc_msvc_new_longlong_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000988 // new[](unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000989 case LibFunc_msvc_new_array_int_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000990 // new[](unsigned long long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000991 case LibFunc_msvc_new_array_longlong_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000992 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
993
994 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +0000995 case LibFunc_ZdaPv:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000996 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +0000997 case LibFunc_ZdlPv:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000998 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +0000999 case LibFunc_msvc_delete_array_ptr32:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001000 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001001 case LibFunc_msvc_delete_array_ptr64:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001002 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001003 case LibFunc_msvc_delete_ptr32:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001004 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001005 case LibFunc_msvc_delete_ptr64:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001006 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1007
1008 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001009 case LibFunc_ZdaPvRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001010 // void operator delete[](void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001011 case LibFunc_ZdaPvj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001012 // void operator delete[](void*, unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001013 case LibFunc_ZdaPvm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001014 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001015 case LibFunc_ZdlPvRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001016 // void operator delete(void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001017 case LibFunc_ZdlPvj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001018 // void operator delete(void*, unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001019 case LibFunc_ZdlPvm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001020 // void operator delete[](void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001021 case LibFunc_msvc_delete_array_ptr32_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001022 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001023 case LibFunc_msvc_delete_array_ptr32_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001024 // void operator delete[](void*, unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001025 case LibFunc_msvc_delete_array_ptr64_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001026 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001027 case LibFunc_msvc_delete_array_ptr64_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001028 // void operator delete(void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001029 case LibFunc_msvc_delete_ptr32_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001030 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001031 case LibFunc_msvc_delete_ptr32_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001032 // void operator delete(void*, unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001033 case LibFunc_msvc_delete_ptr64_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001034 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001035 case LibFunc_msvc_delete_ptr64_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001036 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001037
David L. Jonesd21529f2017-01-23 23:16:46 +00001038 case LibFunc_memset_pattern16:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001039 return (!FTy.isVarArg() && NumParams == 3 &&
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001040 FTy.getParamType(0)->isPointerTy() &&
1041 FTy.getParamType(1)->isPointerTy() &&
1042 FTy.getParamType(2)->isIntegerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001043
David L. Jonesd21529f2017-01-23 23:16:46 +00001044 case LibFunc_cxa_guard_abort:
1045 case LibFunc_cxa_guard_acquire:
1046 case LibFunc_cxa_guard_release:
1047 case LibFunc_nvvm_reflect:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001048 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001049
David L. Jonesd21529f2017-01-23 23:16:46 +00001050 case LibFunc_sincospi_stret:
1051 case LibFunc_sincospif_stret:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001052 return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
1053
David L. Jonesd21529f2017-01-23 23:16:46 +00001054 case LibFunc_acos:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001055 case LibFunc_acos_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001056 case LibFunc_acosf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001057 case LibFunc_acosf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001058 case LibFunc_acosh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001059 case LibFunc_acosh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001060 case LibFunc_acoshf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001061 case LibFunc_acoshf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001062 case LibFunc_acoshl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001063 case LibFunc_acoshl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001064 case LibFunc_acosl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001065 case LibFunc_acosl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001066 case LibFunc_asin:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001067 case LibFunc_asin_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001068 case LibFunc_asinf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001069 case LibFunc_asinf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001070 case LibFunc_asinh:
1071 case LibFunc_asinhf:
1072 case LibFunc_asinhl:
1073 case LibFunc_asinl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001074 case LibFunc_asinl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001075 case LibFunc_atan:
1076 case LibFunc_atanf:
1077 case LibFunc_atanh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001078 case LibFunc_atanh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001079 case LibFunc_atanhf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001080 case LibFunc_atanhf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001081 case LibFunc_atanhl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001082 case LibFunc_atanhl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001083 case LibFunc_atanl:
1084 case LibFunc_cbrt:
1085 case LibFunc_cbrtf:
1086 case LibFunc_cbrtl:
1087 case LibFunc_ceil:
1088 case LibFunc_ceilf:
1089 case LibFunc_ceill:
1090 case LibFunc_cos:
1091 case LibFunc_cosf:
1092 case LibFunc_cosh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001093 case LibFunc_cosh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001094 case LibFunc_coshf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001095 case LibFunc_coshf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001096 case LibFunc_coshl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001097 case LibFunc_coshl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001098 case LibFunc_cosl:
1099 case LibFunc_exp10:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001100 case LibFunc_exp10_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001101 case LibFunc_exp10f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001102 case LibFunc_exp10f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001103 case LibFunc_exp10l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001104 case LibFunc_exp10l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001105 case LibFunc_exp2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001106 case LibFunc_exp2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001107 case LibFunc_exp2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001108 case LibFunc_exp2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001109 case LibFunc_exp2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001110 case LibFunc_exp2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001111 case LibFunc_exp:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001112 case LibFunc_exp_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001113 case LibFunc_expf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001114 case LibFunc_expf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001115 case LibFunc_expl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001116 case LibFunc_expl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001117 case LibFunc_expm1:
1118 case LibFunc_expm1f:
1119 case LibFunc_expm1l:
1120 case LibFunc_fabs:
1121 case LibFunc_fabsf:
1122 case LibFunc_fabsl:
1123 case LibFunc_floor:
1124 case LibFunc_floorf:
1125 case LibFunc_floorl:
1126 case LibFunc_log10:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001127 case LibFunc_log10_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001128 case LibFunc_log10f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001129 case LibFunc_log10f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001130 case LibFunc_log10l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001131 case LibFunc_log10l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001132 case LibFunc_log1p:
1133 case LibFunc_log1pf:
1134 case LibFunc_log1pl:
1135 case LibFunc_log2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001136 case LibFunc_log2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001137 case LibFunc_log2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001138 case LibFunc_log2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001139 case LibFunc_log2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001140 case LibFunc_log2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001141 case LibFunc_log:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001142 case LibFunc_log_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001143 case LibFunc_logb:
1144 case LibFunc_logbf:
1145 case LibFunc_logbl:
1146 case LibFunc_logf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001147 case LibFunc_logf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001148 case LibFunc_logl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001149 case LibFunc_logl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001150 case LibFunc_nearbyint:
1151 case LibFunc_nearbyintf:
1152 case LibFunc_nearbyintl:
1153 case LibFunc_rint:
1154 case LibFunc_rintf:
1155 case LibFunc_rintl:
1156 case LibFunc_round:
1157 case LibFunc_roundf:
1158 case LibFunc_roundl:
1159 case LibFunc_sin:
1160 case LibFunc_sinf:
1161 case LibFunc_sinh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001162 case LibFunc_sinh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001163 case LibFunc_sinhf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001164 case LibFunc_sinhf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001165 case LibFunc_sinhl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001166 case LibFunc_sinhl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001167 case LibFunc_sinl:
1168 case LibFunc_sqrt:
1169 case LibFunc_sqrt_finite:
1170 case LibFunc_sqrtf:
1171 case LibFunc_sqrtf_finite:
1172 case LibFunc_sqrtl:
1173 case LibFunc_sqrtl_finite:
1174 case LibFunc_tan:
1175 case LibFunc_tanf:
1176 case LibFunc_tanh:
1177 case LibFunc_tanhf:
1178 case LibFunc_tanhl:
1179 case LibFunc_tanl:
1180 case LibFunc_trunc:
1181 case LibFunc_truncf:
1182 case LibFunc_truncl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001183 return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1184 FTy.getReturnType() == FTy.getParamType(0));
1185
David L. Jonesd21529f2017-01-23 23:16:46 +00001186 case LibFunc_atan2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001187 case LibFunc_atan2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001188 case LibFunc_atan2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001189 case LibFunc_atan2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001190 case LibFunc_atan2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001191 case LibFunc_atan2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001192 case LibFunc_fmin:
1193 case LibFunc_fminf:
1194 case LibFunc_fminl:
1195 case LibFunc_fmax:
1196 case LibFunc_fmaxf:
1197 case LibFunc_fmaxl:
1198 case LibFunc_fmod:
1199 case LibFunc_fmodf:
1200 case LibFunc_fmodl:
1201 case LibFunc_copysign:
1202 case LibFunc_copysignf:
1203 case LibFunc_copysignl:
1204 case LibFunc_pow:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001205 case LibFunc_pow_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001206 case LibFunc_powf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001207 case LibFunc_powf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001208 case LibFunc_powl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001209 case LibFunc_powl_finite:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001210 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1211 FTy.getReturnType() == FTy.getParamType(0) &&
1212 FTy.getReturnType() == FTy.getParamType(1));
1213
David L. Jonesd21529f2017-01-23 23:16:46 +00001214 case LibFunc_ldexp:
1215 case LibFunc_ldexpf:
1216 case LibFunc_ldexpl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001217 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1218 FTy.getReturnType() == FTy.getParamType(0) &&
1219 FTy.getParamType(1)->isIntegerTy(32));
1220
David L. Jonesd21529f2017-01-23 23:16:46 +00001221 case LibFunc_ffs:
1222 case LibFunc_ffsl:
1223 case LibFunc_ffsll:
1224 case LibFunc_fls:
1225 case LibFunc_flsl:
1226 case LibFunc_flsll:
Sanjay Patel04949faf2016-09-23 18:44:09 +00001227 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1228 FTy.getParamType(0)->isIntegerTy());
1229
David L. Jonesd21529f2017-01-23 23:16:46 +00001230 case LibFunc_isdigit:
1231 case LibFunc_isascii:
1232 case LibFunc_toascii:
1233 case LibFunc_putchar:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001234 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
Sanjay Patel04949faf2016-09-23 18:44:09 +00001235 FTy.getReturnType() == FTy.getParamType(0));
Ahmed Bougachad765a822016-04-27 19:04:35 +00001236
David L. Jonesd21529f2017-01-23 23:16:46 +00001237 case LibFunc_abs:
1238 case LibFunc_labs:
1239 case LibFunc_llabs:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001240 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1241 FTy.getReturnType() == FTy.getParamType(0));
1242
David L. Jonesd21529f2017-01-23 23:16:46 +00001243 case LibFunc_cxa_atexit:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001244 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1245 FTy.getParamType(0)->isPointerTy() &&
1246 FTy.getParamType(1)->isPointerTy() &&
1247 FTy.getParamType(2)->isPointerTy());
1248
David L. Jonesd21529f2017-01-23 23:16:46 +00001249 case LibFunc_sinpi:
1250 case LibFunc_cospi:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001251 return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1252 FTy.getReturnType() == FTy.getParamType(0));
1253
David L. Jonesd21529f2017-01-23 23:16:46 +00001254 case LibFunc_sinpif:
1255 case LibFunc_cospif:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001256 return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1257 FTy.getReturnType() == FTy.getParamType(0));
1258
David L. Jonesd21529f2017-01-23 23:16:46 +00001259 case LibFunc_strnlen:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001260 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1261 FTy.getParamType(0) == PCharTy &&
1262 FTy.getParamType(1) == SizeTTy);
1263
David L. Jonesd21529f2017-01-23 23:16:46 +00001264 case LibFunc_posix_memalign:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001265 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1266 FTy.getParamType(0)->isPointerTy() &&
1267 FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
1268
Matthias Braun60b40b82017-05-05 20:25:50 +00001269 case LibFunc_wcslen:
1270 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
1271 FTy.getReturnType()->isIntegerTy());
1272
Hal Finkel2ff24732017-12-16 01:26:25 +00001273 case LibFunc_cabs:
1274 case LibFunc_cabsf:
1275 case LibFunc_cabsl: {
1276 Type* RetTy = FTy.getReturnType();
1277 if (!RetTy->isFloatingPointTy())
1278 return false;
1279
1280 // NOTE: These prototypes are target specific and currently support
1281 // "complex" passed as an array or discrete real & imaginary parameters.
1282 // Add other calling conventions to enable libcall optimizations.
1283 if (NumParams == 1)
1284 return (FTy.getParamType(0)->isArrayTy() &&
1285 FTy.getParamType(0)->getArrayNumElements() == 2 &&
1286 FTy.getParamType(0)->getArrayElementType() == RetTy);
1287 else if (NumParams == 2)
1288 return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
1289 else
1290 return false;
1291 }
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001292 case LibFunc::NumLibFuncs:
Ahmed Bougacha86b680a2017-01-17 19:54:18 +00001293 break;
Ahmed Bougachad765a822016-04-27 19:04:35 +00001294 }
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001295
Ahmed Bougacha86b680a2017-01-17 19:54:18 +00001296 llvm_unreachable("Invalid libfunc");
Ahmed Bougachad765a822016-04-27 19:04:35 +00001297}
1298
1299bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
David L. Jonesd21529f2017-01-23 23:16:46 +00001300 LibFunc &F) const {
Ahmed Bougachad765a822016-04-27 19:04:35 +00001301 const DataLayout *DL =
1302 FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1303 return getLibFunc(FDecl.getName(), F) &&
1304 isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1305}
1306
Chandler Carruthc0291862015-01-24 02:06:09 +00001307void TargetLibraryInfoImpl::disableAllFunctions() {
Chris Lattner1341df92011-02-18 22:34:03 +00001308 memset(AvailableArray, 0, sizeof(AvailableArray));
1309}
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001310
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001311static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001312 return LHS.ScalarFnName < RHS.ScalarFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001313}
1314
1315static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001316 return LHS.VectorFnName < RHS.VectorFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001317}
1318
1319static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001320 return LHS.ScalarFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001321}
1322
1323static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001324 return LHS.VectorFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001325}
1326
1327void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1328 VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
1329 std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
1330
1331 ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
1332 std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
1333}
1334
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001335void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1336 enum VectorLibrary VecLib) {
1337 switch (VecLib) {
1338 case Accelerate: {
1339 const VecDesc VecFuncs[] = {
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001340 // Floating-Point Arithmetic and Auxiliary Functions
1341 {"ceilf", "vceilf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001342 {"fabsf", "vfabsf", 4},
1343 {"llvm.fabs.f32", "vfabsf", 4},
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001344 {"floorf", "vfloorf", 4},
1345 {"sqrtf", "vsqrtf", 4},
1346 {"llvm.sqrt.f32", "vsqrtf", 4},
1347
1348 // Exponential and Logarithmic Functions
1349 {"expf", "vexpf", 4},
1350 {"llvm.exp.f32", "vexpf", 4},
1351 {"expm1f", "vexpm1f", 4},
1352 {"logf", "vlogf", 4},
1353 {"llvm.log.f32", "vlogf", 4},
1354 {"log1pf", "vlog1pf", 4},
1355 {"log10f", "vlog10f", 4},
1356 {"llvm.log10.f32", "vlog10f", 4},
1357 {"logbf", "vlogbf", 4},
1358
1359 // Trigonometric Functions
1360 {"sinf", "vsinf", 4},
1361 {"llvm.sin.f32", "vsinf", 4},
1362 {"cosf", "vcosf", 4},
1363 {"llvm.cos.f32", "vcosf", 4},
1364 {"tanf", "vtanf", 4},
1365 {"asinf", "vasinf", 4},
1366 {"acosf", "vacosf", 4},
1367 {"atanf", "vatanf", 4},
1368
1369 // Hyperbolic Functions
1370 {"sinhf", "vsinhf", 4},
1371 {"coshf", "vcoshf", 4},
1372 {"tanhf", "vtanhf", 4},
1373 {"asinhf", "vasinhf", 4},
1374 {"acoshf", "vacoshf", 4},
1375 {"atanhf", "vatanhf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001376 };
1377 addVectorizableFunctions(VecFuncs);
1378 break;
1379 }
Matt Mastena6669a12016-07-29 16:42:44 +00001380 case SVML: {
1381 const VecDesc VecFuncs[] = {
1382 {"sin", "__svml_sin2", 2},
1383 {"sin", "__svml_sin4", 4},
1384 {"sin", "__svml_sin8", 8},
1385
1386 {"sinf", "__svml_sinf4", 4},
1387 {"sinf", "__svml_sinf8", 8},
1388 {"sinf", "__svml_sinf16", 16},
1389
1390 {"cos", "__svml_cos2", 2},
1391 {"cos", "__svml_cos4", 4},
1392 {"cos", "__svml_cos8", 8},
1393
1394 {"cosf", "__svml_cosf4", 4},
1395 {"cosf", "__svml_cosf8", 8},
1396 {"cosf", "__svml_cosf16", 16},
1397
1398 {"pow", "__svml_pow2", 2},
1399 {"pow", "__svml_pow4", 4},
1400 {"pow", "__svml_pow8", 8},
1401
1402 {"powf", "__svml_powf4", 4},
1403 {"powf", "__svml_powf8", 8},
1404 {"powf", "__svml_powf16", 16},
1405
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001406 { "__pow_finite", "__svml_pow2", 2 },
1407 { "__pow_finite", "__svml_pow4", 4 },
1408 { "__pow_finite", "__svml_pow8", 8 },
1409
1410 { "__powf_finite", "__svml_powf4", 4 },
1411 { "__powf_finite", "__svml_powf8", 8 },
1412 { "__powf_finite", "__svml_powf16", 16 },
1413
Matt Mastena6669a12016-07-29 16:42:44 +00001414 {"llvm.pow.f64", "__svml_pow2", 2},
1415 {"llvm.pow.f64", "__svml_pow4", 4},
1416 {"llvm.pow.f64", "__svml_pow8", 8},
1417
1418 {"llvm.pow.f32", "__svml_powf4", 4},
1419 {"llvm.pow.f32", "__svml_powf8", 8},
1420 {"llvm.pow.f32", "__svml_powf16", 16},
1421
1422 {"exp", "__svml_exp2", 2},
1423 {"exp", "__svml_exp4", 4},
1424 {"exp", "__svml_exp8", 8},
1425
1426 {"expf", "__svml_expf4", 4},
1427 {"expf", "__svml_expf8", 8},
1428 {"expf", "__svml_expf16", 16},
1429
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001430 { "__exp_finite", "__svml_exp2", 2 },
1431 { "__exp_finite", "__svml_exp4", 4 },
1432 { "__exp_finite", "__svml_exp8", 8 },
1433
1434 { "__expf_finite", "__svml_expf4", 4 },
1435 { "__expf_finite", "__svml_expf8", 8 },
1436 { "__expf_finite", "__svml_expf16", 16 },
1437
Matt Mastena6669a12016-07-29 16:42:44 +00001438 {"llvm.exp.f64", "__svml_exp2", 2},
1439 {"llvm.exp.f64", "__svml_exp4", 4},
1440 {"llvm.exp.f64", "__svml_exp8", 8},
1441
1442 {"llvm.exp.f32", "__svml_expf4", 4},
1443 {"llvm.exp.f32", "__svml_expf8", 8},
1444 {"llvm.exp.f32", "__svml_expf16", 16},
1445
1446 {"log", "__svml_log2", 2},
1447 {"log", "__svml_log4", 4},
1448 {"log", "__svml_log8", 8},
1449
1450 {"logf", "__svml_logf4", 4},
1451 {"logf", "__svml_logf8", 8},
1452 {"logf", "__svml_logf16", 16},
1453
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001454 { "__log_finite", "__svml_log2", 2 },
1455 { "__log_finite", "__svml_log4", 4 },
1456 { "__log_finite", "__svml_log8", 8 },
1457
1458 { "__logf_finite", "__svml_logf4", 4 },
1459 { "__logf_finite", "__svml_logf8", 8 },
1460 { "__logf_finite", "__svml_logf16", 16 },
1461
Matt Mastena6669a12016-07-29 16:42:44 +00001462 {"llvm.log.f64", "__svml_log2", 2},
1463 {"llvm.log.f64", "__svml_log4", 4},
1464 {"llvm.log.f64", "__svml_log8", 8},
1465
1466 {"llvm.log.f32", "__svml_logf4", 4},
1467 {"llvm.log.f32", "__svml_logf8", 8},
1468 {"llvm.log.f32", "__svml_logf16", 16},
1469 };
1470 addVectorizableFunctions(VecFuncs);
1471 break;
1472 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001473 case NoLibrary:
1474 break;
1475 }
1476}
1477
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001478bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1479 funcName = sanitizeFunctionName(funcName);
1480 if (funcName.empty())
1481 return false;
1482
1483 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1484 VectorDescs.begin(), VectorDescs.end(), funcName,
1485 compareWithScalarFnName);
1486 return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1487}
1488
1489StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1490 unsigned VF) const {
1491 F = sanitizeFunctionName(F);
1492 if (F.empty())
1493 return F;
1494 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1495 VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1496 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1497 if (I->VectorizationFactor == VF)
1498 return I->VectorFnName;
1499 ++I;
1500 }
1501 return StringRef();
1502}
1503
1504StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1505 unsigned &VF) const {
1506 F = sanitizeFunctionName(F);
1507 if (F.empty())
1508 return F;
1509
1510 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1511 ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1512 if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1513 return StringRef();
1514 VF = I->VectorizationFactor;
1515 return I->ScalarFnName;
1516}
1517
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001518TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
1519 ModuleAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001520 if (PresetInfoImpl)
1521 return TargetLibraryInfo(*PresetInfoImpl);
1522
1523 return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1524}
1525
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001526TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
1527 FunctionAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001528 if (PresetInfoImpl)
1529 return TargetLibraryInfo(*PresetInfoImpl);
1530
1531 return TargetLibraryInfo(
1532 lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1533}
1534
Benjamin Kramerc321e532016-06-08 19:09:22 +00001535TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001536 std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1537 Impls[T.normalize()];
1538 if (!Impl)
1539 Impl.reset(new TargetLibraryInfoImpl(T));
1540
1541 return *Impl;
1542}
1543
Matthias Braun50ec0b52017-05-19 22:37:09 +00001544unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
1545 if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1546 M.getModuleFlag("wchar_size")))
1547 return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
Matthias Brauncc603ee2017-09-26 02:36:57 +00001548 return 0;
Matthias Braun50ec0b52017-05-19 22:37:09 +00001549}
Chandler Carruthc0291862015-01-24 02:06:09 +00001550
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001551TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
Chandler Carruthc0291862015-01-24 02:06:09 +00001552 : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001553 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1554}
1555
1556TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
Chandler Carruthc0291862015-01-24 02:06:09 +00001557 : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001558 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1559}
1560
1561TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
Chandler Carruthc0291862015-01-24 02:06:09 +00001562 const TargetLibraryInfoImpl &TLIImpl)
1563 : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001564 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1565}
1566
Chandler Carruthdab4eae2016-11-23 17:53:26 +00001567AnalysisKey TargetLibraryAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +00001568
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001569// Register the basic pass.
1570INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1571 "Target Library Information", false, true)
1572char TargetLibraryInfoWrapperPass::ID = 0;
1573
1574void TargetLibraryInfoWrapperPass::anchor() {}