blob: 2dbcc9fa6f26291609ef5c1d49d4ad310ae2fffd [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
Meador Ingeb904e6e2013-03-05 21:47:40 +0000248 // Win32 does *not* provide provide these functions, but they are
249 // generally available on POSIX-compliant systems:
David L. Jonesd21529f2017-01-23 23:16:46 +0000250 TLI.setUnavailable(LibFunc_access);
251 TLI.setUnavailable(LibFunc_bcmp);
252 TLI.setUnavailable(LibFunc_bcopy);
253 TLI.setUnavailable(LibFunc_bzero);
254 TLI.setUnavailable(LibFunc_chmod);
255 TLI.setUnavailable(LibFunc_chown);
256 TLI.setUnavailable(LibFunc_closedir);
257 TLI.setUnavailable(LibFunc_ctermid);
258 TLI.setUnavailable(LibFunc_fdopen);
259 TLI.setUnavailable(LibFunc_ffs);
260 TLI.setUnavailable(LibFunc_fileno);
261 TLI.setUnavailable(LibFunc_flockfile);
262 TLI.setUnavailable(LibFunc_fseeko);
263 TLI.setUnavailable(LibFunc_fstat);
264 TLI.setUnavailable(LibFunc_fstatvfs);
265 TLI.setUnavailable(LibFunc_ftello);
266 TLI.setUnavailable(LibFunc_ftrylockfile);
267 TLI.setUnavailable(LibFunc_funlockfile);
268 TLI.setUnavailable(LibFunc_getc_unlocked);
269 TLI.setUnavailable(LibFunc_getitimer);
270 TLI.setUnavailable(LibFunc_getlogin_r);
271 TLI.setUnavailable(LibFunc_getpwnam);
272 TLI.setUnavailable(LibFunc_gettimeofday);
273 TLI.setUnavailable(LibFunc_htonl);
274 TLI.setUnavailable(LibFunc_htons);
275 TLI.setUnavailable(LibFunc_lchown);
276 TLI.setUnavailable(LibFunc_lstat);
277 TLI.setUnavailable(LibFunc_memccpy);
278 TLI.setUnavailable(LibFunc_mkdir);
279 TLI.setUnavailable(LibFunc_ntohl);
280 TLI.setUnavailable(LibFunc_ntohs);
281 TLI.setUnavailable(LibFunc_open);
282 TLI.setUnavailable(LibFunc_opendir);
283 TLI.setUnavailable(LibFunc_pclose);
284 TLI.setUnavailable(LibFunc_popen);
285 TLI.setUnavailable(LibFunc_pread);
286 TLI.setUnavailable(LibFunc_pwrite);
287 TLI.setUnavailable(LibFunc_read);
288 TLI.setUnavailable(LibFunc_readlink);
289 TLI.setUnavailable(LibFunc_realpath);
290 TLI.setUnavailable(LibFunc_rmdir);
291 TLI.setUnavailable(LibFunc_setitimer);
292 TLI.setUnavailable(LibFunc_stat);
293 TLI.setUnavailable(LibFunc_statvfs);
294 TLI.setUnavailable(LibFunc_stpcpy);
295 TLI.setUnavailable(LibFunc_stpncpy);
296 TLI.setUnavailable(LibFunc_strcasecmp);
297 TLI.setUnavailable(LibFunc_strncasecmp);
298 TLI.setUnavailable(LibFunc_times);
299 TLI.setUnavailable(LibFunc_uname);
300 TLI.setUnavailable(LibFunc_unlink);
301 TLI.setUnavailable(LibFunc_unsetenv);
302 TLI.setUnavailable(LibFunc_utime);
303 TLI.setUnavailable(LibFunc_utimes);
304 TLI.setUnavailable(LibFunc_write);
Meador Inge780a1862012-11-22 15:36:42 +0000305
Meador Ingeb904e6e2013-03-05 21:47:40 +0000306 // Win32 does *not* provide provide these functions, but they are
307 // specified by C99:
David L. Jonesd21529f2017-01-23 23:16:46 +0000308 TLI.setUnavailable(LibFunc_atoll);
309 TLI.setUnavailable(LibFunc_frexpf);
310 TLI.setUnavailable(LibFunc_llabs);
Meador Inge780a1862012-11-22 15:36:42 +0000311 }
312
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000313 switch (T.getOS()) {
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000314 case Triple::MacOSX:
Chandler Carruthf5689f82013-12-28 02:40:19 +0000315 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
316 // and their names are __exp10 and __exp10f. exp10l is not available on
317 // OS X or iOS.
David L. Jonesd21529f2017-01-23 23:16:46 +0000318 TLI.setUnavailable(LibFunc_exp10l);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000319 if (T.isMacOSXVersionLT(10, 9)) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000320 TLI.setUnavailable(LibFunc_exp10);
321 TLI.setUnavailable(LibFunc_exp10f);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000322 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000323 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
324 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000325 }
326 break;
327 case Triple::IOS:
Tim Northover89a6eef2015-11-02 18:00:00 +0000328 case Triple::TvOS:
Tim Northover8b403662015-10-28 22:51:16 +0000329 case Triple::WatchOS:
David L. Jonesd21529f2017-01-23 23:16:46 +0000330 TLI.setUnavailable(LibFunc_exp10l);
Tim Northover8b403662015-10-28 22:51:16 +0000331 if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
332 (T.isOSVersionLT(9, 0) &&
333 (T.getArch() == Triple::x86 ||
334 T.getArch() == Triple::x86_64)))) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000335 TLI.setUnavailable(LibFunc_exp10);
336 TLI.setUnavailable(LibFunc_exp10f);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000337 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000338 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
339 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000340 }
341 break;
Chandler Carruthf5689f82013-12-28 02:40:19 +0000342 case Triple::Linux:
343 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
344 // buggy prior to glibc version 2.18. Until this version is widely deployed
345 // or we have a reasonable detection strategy, we cannot use exp10 reliably
346 // on Linux.
347 //
348 // Fall through to disable all of them.
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000349 LLVM_FALLTHROUGH;
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000350 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000351 TLI.setUnavailable(LibFunc_exp10);
352 TLI.setUnavailable(LibFunc_exp10f);
353 TLI.setUnavailable(LibFunc_exp10l);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000354 }
355
Meador Inge780a1862012-11-22 15:36:42 +0000356 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
357 // Linux (GLIBC):
358 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
Davide Italiano83b34812015-11-01 17:00:13 +0000359 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
Meador Inge780a1862012-11-22 15:36:42 +0000360 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
361 switch (T.getOS()) {
362 case Triple::Darwin:
363 case Triple::MacOSX:
364 case Triple::IOS:
Tim Northover89a6eef2015-11-02 18:00:00 +0000365 case Triple::TvOS:
Tim Northover8b403662015-10-28 22:51:16 +0000366 case Triple::WatchOS:
Meador Inge780a1862012-11-22 15:36:42 +0000367 case Triple::FreeBSD:
368 case Triple::Linux:
369 break;
370 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000371 TLI.setUnavailable(LibFunc_ffsl);
Meador Inge780a1862012-11-22 15:36:42 +0000372 }
373
374 // ffsll is available on at least FreeBSD and Linux (GLIBC):
Davide Italiano83b34812015-11-01 17:00:13 +0000375 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
Meador Inge780a1862012-11-22 15:36:42 +0000376 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
377 switch (T.getOS()) {
Tim Northover89a6eef2015-11-02 18:00:00 +0000378 case Triple::Darwin:
379 case Triple::MacOSX:
380 case Triple::IOS:
381 case Triple::TvOS:
382 case Triple::WatchOS:
Meador Inge780a1862012-11-22 15:36:42 +0000383 case Triple::FreeBSD:
384 case Triple::Linux:
385 break;
386 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000387 TLI.setUnavailable(LibFunc_ffsll);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000388 }
Meador Ingeb904e6e2013-03-05 21:47:40 +0000389
Davide Italianobfd30822015-11-09 23:23:20 +0000390 // The following functions are available on at least FreeBSD:
391 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
392 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
393 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
394 if (!T.isOSFreeBSD()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000395 TLI.setUnavailable(LibFunc_fls);
396 TLI.setUnavailable(LibFunc_flsl);
397 TLI.setUnavailable(LibFunc_flsll);
Davide Italianobfd30822015-11-09 23:23:20 +0000398 }
399
MinSeong Kim27f77b42018-01-23 11:11:36 +0000400 // Android uses bionic instead of glibc. So disable some finite
401 // lib calls in glibc for Android. The list of unsupported lib
402 // calls for Android may expand as the need arises.
403 if (T.isAndroid()) {
404 TLI.setUnavailable(LibFunc_exp_finite);
405 TLI.setUnavailable(LibFunc_exp2_finite);
406 TLI.setUnavailable(LibFunc_pow_finite);
407 }
408
Meador Ingeb904e6e2013-03-05 21:47:40 +0000409 // The following functions are available on at least Linux:
Cameron Esfahani943908b2013-08-29 20:23:14 +0000410 if (!T.isOSLinux()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000411 TLI.setUnavailable(LibFunc_dunder_strdup);
412 TLI.setUnavailable(LibFunc_dunder_strtok_r);
413 TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
414 TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
415 TLI.setUnavailable(LibFunc_under_IO_getc);
416 TLI.setUnavailable(LibFunc_under_IO_putc);
417 TLI.setUnavailable(LibFunc_memalign);
418 TLI.setUnavailable(LibFunc_fopen64);
419 TLI.setUnavailable(LibFunc_fseeko64);
420 TLI.setUnavailable(LibFunc_fstat64);
421 TLI.setUnavailable(LibFunc_fstatvfs64);
422 TLI.setUnavailable(LibFunc_ftello64);
423 TLI.setUnavailable(LibFunc_lstat64);
424 TLI.setUnavailable(LibFunc_open64);
425 TLI.setUnavailable(LibFunc_stat64);
426 TLI.setUnavailable(LibFunc_statvfs64);
427 TLI.setUnavailable(LibFunc_tmpfile64);
Sanjay Patel52149f02018-01-08 17:38:09 +0000428
429 // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
430 TLI.setUnavailable(LibFunc_acos_finite);
431 TLI.setUnavailable(LibFunc_acosf_finite);
432 TLI.setUnavailable(LibFunc_acosl_finite);
433 TLI.setUnavailable(LibFunc_acosh_finite);
434 TLI.setUnavailable(LibFunc_acoshf_finite);
435 TLI.setUnavailable(LibFunc_acoshl_finite);
436 TLI.setUnavailable(LibFunc_asin_finite);
437 TLI.setUnavailable(LibFunc_asinf_finite);
438 TLI.setUnavailable(LibFunc_asinl_finite);
439 TLI.setUnavailable(LibFunc_atan2_finite);
440 TLI.setUnavailable(LibFunc_atan2f_finite);
441 TLI.setUnavailable(LibFunc_atan2l_finite);
442 TLI.setUnavailable(LibFunc_atanh_finite);
443 TLI.setUnavailable(LibFunc_atanhf_finite);
444 TLI.setUnavailable(LibFunc_atanhl_finite);
445 TLI.setUnavailable(LibFunc_cosh_finite);
446 TLI.setUnavailable(LibFunc_coshf_finite);
447 TLI.setUnavailable(LibFunc_coshl_finite);
448 TLI.setUnavailable(LibFunc_exp10_finite);
449 TLI.setUnavailable(LibFunc_exp10f_finite);
450 TLI.setUnavailable(LibFunc_exp10l_finite);
451 TLI.setUnavailable(LibFunc_exp2_finite);
452 TLI.setUnavailable(LibFunc_exp2f_finite);
453 TLI.setUnavailable(LibFunc_exp2l_finite);
454 TLI.setUnavailable(LibFunc_exp_finite);
455 TLI.setUnavailable(LibFunc_expf_finite);
456 TLI.setUnavailable(LibFunc_expl_finite);
457 TLI.setUnavailable(LibFunc_log10_finite);
458 TLI.setUnavailable(LibFunc_log10f_finite);
459 TLI.setUnavailable(LibFunc_log10l_finite);
460 TLI.setUnavailable(LibFunc_log2_finite);
461 TLI.setUnavailable(LibFunc_log2f_finite);
462 TLI.setUnavailable(LibFunc_log2l_finite);
463 TLI.setUnavailable(LibFunc_log_finite);
464 TLI.setUnavailable(LibFunc_logf_finite);
465 TLI.setUnavailable(LibFunc_logl_finite);
466 TLI.setUnavailable(LibFunc_pow_finite);
467 TLI.setUnavailable(LibFunc_powf_finite);
468 TLI.setUnavailable(LibFunc_powl_finite);
469 TLI.setUnavailable(LibFunc_sinh_finite);
470 TLI.setUnavailable(LibFunc_sinhf_finite);
471 TLI.setUnavailable(LibFunc_sinhl_finite);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000472 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000473
Justin Lebar51132882016-01-26 23:51:06 +0000474 // As currently implemented in clang, NVPTX code has no standard library to
475 // speak of. Headers provide a standard-ish library implementation, but many
476 // of the signatures are wrong -- for example, many libm functions are not
477 // extern "C".
478 //
479 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
480 // but only used functions are provided to llvm. Moreover, most of the
481 // functions in libdevice don't map precisely to standard library functions.
482 //
483 // FIXME: Having no standard library prevents e.g. many fastmath
484 // optimizations, so this situation should be fixed.
David Majnemerae272d72016-03-31 21:29:57 +0000485 if (T.isNVPTX()) {
Justin Lebar51132882016-01-26 23:51:06 +0000486 TLI.disableAllFunctions();
David L. Jonesd21529f2017-01-23 23:16:46 +0000487 TLI.setAvailable(LibFunc_nvvm_reflect);
David Majnemerae272d72016-03-31 21:29:57 +0000488 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000489 TLI.setUnavailable(LibFunc_nvvm_reflect);
David Majnemerae272d72016-03-31 21:29:57 +0000490 }
Justin Lebar51132882016-01-26 23:51:06 +0000491
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000492 TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000493}
494
Chandler Carruthc0291862015-01-24 02:06:09 +0000495TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000496 // Default to everything being available.
497 memset(AvailableArray, -1, sizeof(AvailableArray));
498
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000499 initialize(*this, Triple(), StandardNames);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000500}
501
Chandler Carruthc0291862015-01-24 02:06:09 +0000502TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000503 // Default to everything being available.
504 memset(AvailableArray, -1, sizeof(AvailableArray));
Chandler Carruthb98f63d2015-01-15 10:41:28 +0000505
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000506 initialize(*this, T, StandardNames);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000507}
Chris Lattner1341df92011-02-18 22:34:03 +0000508
Chandler Carruthc0291862015-01-24 02:06:09 +0000509TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000510 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
511 ShouldExtI32Return(TLI.ShouldExtI32Return),
512 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000513 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
Michael Zolotukhine8f25512015-03-17 19:22:30 +0000514 VectorDescs = TLI.VectorDescs;
515 ScalarDescs = TLI.ScalarDescs;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000516}
517
Chandler Carruthc0291862015-01-24 02:06:09 +0000518TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000519 : CustomNames(std::move(TLI.CustomNames)),
520 ShouldExtI32Param(TLI.ShouldExtI32Param),
521 ShouldExtI32Return(TLI.ShouldExtI32Return),
522 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
Chandler Carruth8ca43222015-01-15 11:39:46 +0000523 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
524 AvailableArray);
Michael Zolotukhine8f25512015-03-17 19:22:30 +0000525 VectorDescs = TLI.VectorDescs;
526 ScalarDescs = TLI.ScalarDescs;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000527}
528
Chandler Carruthc0291862015-01-24 02:06:09 +0000529TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
Eli Friedman489c0ff2011-11-17 01:27:36 +0000530 CustomNames = 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 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
535 return *this;
536}
537
Chandler Carruthc0291862015-01-24 02:06:09 +0000538TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
Chandler Carruth8ca43222015-01-15 11:39:46 +0000539 CustomNames = std::move(TLI.CustomNames);
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000540 ShouldExtI32Param = TLI.ShouldExtI32Param;
541 ShouldExtI32Return = TLI.ShouldExtI32Return;
542 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000543 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
544 AvailableArray);
545 return *this;
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000546}
547
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000548static StringRef sanitizeFunctionName(StringRef funcName) {
Benjamin Kramer160f72d2013-03-09 13:48:23 +0000549 // Filter out empty names and names containing null bytes, those can't be in
550 // our table.
551 if (funcName.empty() || funcName.find('\0') != StringRef::npos)
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000552 return StringRef();
Benjamin Kramer160f72d2013-03-09 13:48:23 +0000553
Meador Ingeb904e6e2013-03-05 21:47:40 +0000554 // Check for \01 prefix that is used to mangle __asm declarations and
555 // strip it if present.
Peter Collingbourne6f0ecca2017-05-16 00:39:01 +0000556 return GlobalValue::dropLLVMManglingEscape(funcName);
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000557}
558
559bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
David L. Jonesd21529f2017-01-23 23:16:46 +0000560 LibFunc &F) const {
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000561 StringRef const *Start = &StandardNames[0];
David L. Jonesd21529f2017-01-23 23:16:46 +0000562 StringRef const *End = &StandardNames[NumLibFuncs];
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000563
564 funcName = sanitizeFunctionName(funcName);
565 if (funcName.empty())
566 return false;
567
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000568 StringRef const *I = std::lower_bound(
569 Start, End, funcName, [](StringRef LHS, StringRef RHS) {
570 return LHS < RHS;
Michael Zolotukhind3b76a32015-03-02 20:50:08 +0000571 });
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000572 if (I != End && *I == funcName) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000573 F = (LibFunc)(I - Start);
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000574 return true;
575 }
576 return false;
577}
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000578
Ahmed Bougachad765a822016-04-27 19:04:35 +0000579bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
David L. Jonesd21529f2017-01-23 23:16:46 +0000580 LibFunc F,
Ahmed Bougachad765a822016-04-27 19:04:35 +0000581 const DataLayout *DL) const {
582 LLVMContext &Ctx = FTy.getContext();
583 Type *PCharTy = Type::getInt8PtrTy(Ctx);
584 Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
585 auto IsSizeTTy = [SizeTTy](Type *Ty) {
586 return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
587 };
588 unsigned NumParams = FTy.getNumParams();
589
590 switch (F) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000591 case LibFunc_strlen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000592 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
593 FTy.getReturnType()->isIntegerTy());
594
David L. Jonesd21529f2017-01-23 23:16:46 +0000595 case LibFunc_strchr:
596 case LibFunc_strrchr:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000597 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
598 FTy.getParamType(0) == FTy.getReturnType() &&
599 FTy.getParamType(1)->isIntegerTy());
600
David L. Jonesd21529f2017-01-23 23:16:46 +0000601 case LibFunc_strtol:
602 case LibFunc_strtod:
603 case LibFunc_strtof:
604 case LibFunc_strtoul:
605 case LibFunc_strtoll:
606 case LibFunc_strtold:
607 case LibFunc_strtoull:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000608 return ((NumParams == 2 || NumParams == 3) &&
609 FTy.getParamType(0)->isPointerTy() &&
610 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000611 case LibFunc_strcat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000612 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
613 FTy.getParamType(0) == FTy.getReturnType() &&
614 FTy.getParamType(1) == FTy.getReturnType());
615
David L. Jonesd21529f2017-01-23 23:16:46 +0000616 case LibFunc_strncat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000617 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
618 FTy.getParamType(0) == FTy.getReturnType() &&
619 FTy.getParamType(1) == FTy.getReturnType() &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000620 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000621
David L. Jonesd21529f2017-01-23 23:16:46 +0000622 case LibFunc_strcpy_chk:
623 case LibFunc_stpcpy_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000624 --NumParams;
625 if (!IsSizeTTy(FTy.getParamType(NumParams)))
626 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000627 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000628 case LibFunc_strcpy:
629 case LibFunc_stpcpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000630 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
631 FTy.getParamType(0) == FTy.getParamType(1) &&
632 FTy.getParamType(0) == PCharTy);
633
David L. Jonesd21529f2017-01-23 23:16:46 +0000634 case LibFunc_strncpy_chk:
635 case LibFunc_stpncpy_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000636 --NumParams;
637 if (!IsSizeTTy(FTy.getParamType(NumParams)))
638 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000639 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000640 case LibFunc_strncpy:
641 case LibFunc_stpncpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000642 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
643 FTy.getParamType(0) == FTy.getParamType(1) &&
644 FTy.getParamType(0) == PCharTy &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000645 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000646
David L. Jonesd21529f2017-01-23 23:16:46 +0000647 case LibFunc_strxfrm:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000648 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
649 FTy.getParamType(1)->isPointerTy());
650
David L. Jonesd21529f2017-01-23 23:16:46 +0000651 case LibFunc_strcmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000652 return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
653 FTy.getParamType(0)->isPointerTy() &&
654 FTy.getParamType(0) == FTy.getParamType(1));
655
David L. Jonesd21529f2017-01-23 23:16:46 +0000656 case LibFunc_strncmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000657 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
658 FTy.getParamType(0)->isPointerTy() &&
659 FTy.getParamType(0) == FTy.getParamType(1) &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000660 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000661
David L. Jonesd21529f2017-01-23 23:16:46 +0000662 case LibFunc_strspn:
663 case LibFunc_strcspn:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000664 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
665 FTy.getParamType(0) == FTy.getParamType(1) &&
666 FTy.getReturnType()->isIntegerTy());
667
David L. Jonesd21529f2017-01-23 23:16:46 +0000668 case LibFunc_strcoll:
669 case LibFunc_strcasecmp:
670 case LibFunc_strncasecmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000671 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
672 FTy.getParamType(1)->isPointerTy());
673
David L. Jonesd21529f2017-01-23 23:16:46 +0000674 case LibFunc_strstr:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000675 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
676 FTy.getParamType(0)->isPointerTy() &&
677 FTy.getParamType(1)->isPointerTy());
678
David L. Jonesd21529f2017-01-23 23:16:46 +0000679 case LibFunc_strpbrk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000680 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
681 FTy.getReturnType() == FTy.getParamType(0) &&
682 FTy.getParamType(0) == FTy.getParamType(1));
683
David L. Jonesd21529f2017-01-23 23:16:46 +0000684 case LibFunc_strtok:
685 case LibFunc_strtok_r:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000686 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000687 case LibFunc_scanf:
688 case LibFunc_setbuf:
689 case LibFunc_setvbuf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000690 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000691 case LibFunc_strdup:
692 case LibFunc_strndup:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000693 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
694 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000695 case LibFunc_sscanf:
696 case LibFunc_stat:
697 case LibFunc_statvfs:
698 case LibFunc_siprintf:
699 case LibFunc_sprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000700 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
701 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000702 case LibFunc_snprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000703 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
704 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000705 case LibFunc_setitimer:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000706 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
707 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000708 case LibFunc_system:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000709 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000710 case LibFunc_malloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000711 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000712 case LibFunc_memcmp:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000713 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
714 FTy.getParamType(0)->isPointerTy() &&
715 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000716
David L. Jonesd21529f2017-01-23 23:16:46 +0000717 case LibFunc_memchr:
718 case LibFunc_memrchr:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000719 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
720 FTy.getReturnType() == FTy.getParamType(0) &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000721 FTy.getParamType(1)->isIntegerTy(32) &&
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000722 IsSizeTTy(FTy.getParamType(2)));
David L. Jonesd21529f2017-01-23 23:16:46 +0000723 case LibFunc_modf:
724 case LibFunc_modff:
725 case LibFunc_modfl:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000726 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
727
David L. Jonesd21529f2017-01-23 23:16:46 +0000728 case LibFunc_memcpy_chk:
729 case LibFunc_memmove_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000730 --NumParams;
731 if (!IsSizeTTy(FTy.getParamType(NumParams)))
732 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000733 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000734 case LibFunc_memcpy:
735 case LibFunc_mempcpy:
736 case LibFunc_memmove:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000737 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
738 FTy.getParamType(0)->isPointerTy() &&
739 FTy.getParamType(1)->isPointerTy() &&
740 IsSizeTTy(FTy.getParamType(2)));
741
David L. Jonesd21529f2017-01-23 23:16:46 +0000742 case LibFunc_memset_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000743 --NumParams;
744 if (!IsSizeTTy(FTy.getParamType(NumParams)))
745 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000746 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000747 case LibFunc_memset:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000748 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
749 FTy.getParamType(0)->isPointerTy() &&
750 FTy.getParamType(1)->isIntegerTy() &&
751 IsSizeTTy(FTy.getParamType(2)));
752
David L. Jonesd21529f2017-01-23 23:16:46 +0000753 case LibFunc_memccpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000754 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000755 case LibFunc_memalign:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000756 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000757 case LibFunc_realloc:
758 case LibFunc_reallocf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000759 return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
760 FTy.getParamType(0) == FTy.getReturnType() &&
761 IsSizeTTy(FTy.getParamType(1)));
David L. Jonesd21529f2017-01-23 23:16:46 +0000762 case LibFunc_read:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000763 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000764 case LibFunc_rewind:
765 case LibFunc_rmdir:
766 case LibFunc_remove:
767 case LibFunc_realpath:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000768 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000769 case LibFunc_rename:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000770 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
771 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000772 case LibFunc_readlink:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000773 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
774 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000775 case LibFunc_write:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000776 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000777 case LibFunc_bcopy:
778 case LibFunc_bcmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000779 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
780 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000781 case LibFunc_bzero:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000782 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000783 case LibFunc_calloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000784 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000785
David L. Jonesd21529f2017-01-23 23:16:46 +0000786 case LibFunc_atof:
787 case LibFunc_atoi:
788 case LibFunc_atol:
789 case LibFunc_atoll:
790 case LibFunc_ferror:
791 case LibFunc_getenv:
792 case LibFunc_getpwnam:
793 case LibFunc_iprintf:
794 case LibFunc_pclose:
795 case LibFunc_perror:
796 case LibFunc_printf:
797 case LibFunc_puts:
798 case LibFunc_uname:
799 case LibFunc_under_IO_getc:
800 case LibFunc_unlink:
801 case LibFunc_unsetenv:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000802 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000803
David L. Jonesd21529f2017-01-23 23:16:46 +0000804 case LibFunc_access:
805 case LibFunc_chmod:
806 case LibFunc_chown:
807 case LibFunc_clearerr:
808 case LibFunc_closedir:
809 case LibFunc_ctermid:
810 case LibFunc_fclose:
811 case LibFunc_feof:
812 case LibFunc_fflush:
813 case LibFunc_fgetc:
814 case LibFunc_fileno:
815 case LibFunc_flockfile:
816 case LibFunc_free:
817 case LibFunc_fseek:
818 case LibFunc_fseeko64:
819 case LibFunc_fseeko:
820 case LibFunc_fsetpos:
821 case LibFunc_ftell:
822 case LibFunc_ftello64:
823 case LibFunc_ftello:
824 case LibFunc_ftrylockfile:
825 case LibFunc_funlockfile:
826 case LibFunc_getc:
827 case LibFunc_getc_unlocked:
828 case LibFunc_getlogin_r:
829 case LibFunc_mkdir:
830 case LibFunc_mktime:
831 case LibFunc_times:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000832 return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
833
David L. Jonesd21529f2017-01-23 23:16:46 +0000834 case LibFunc_fopen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000835 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
836 FTy.getParamType(0)->isPointerTy() &&
837 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000838 case LibFunc_fdopen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000839 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
840 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000841 case LibFunc_fputc:
842 case LibFunc_fstat:
843 case LibFunc_frexp:
844 case LibFunc_frexpf:
845 case LibFunc_frexpl:
846 case LibFunc_fstatvfs:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000847 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000848 case LibFunc_fgets:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000849 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
850 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000851 case LibFunc_fread:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000852 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
853 FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000854 case LibFunc_fwrite:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000855 return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
856 FTy.getParamType(0)->isPointerTy() &&
857 FTy.getParamType(1)->isIntegerTy() &&
858 FTy.getParamType(2)->isIntegerTy() &&
859 FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000860 case LibFunc_fputs:
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_fscanf:
864 case LibFunc_fiprintf:
865 case LibFunc_fprintf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000866 return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
867 FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000868 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000869 case LibFunc_fgetpos:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000870 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
871 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000872 case LibFunc_getchar:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000873 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000874 case LibFunc_gets:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000875 return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
David L. Jonesd21529f2017-01-23 23:16:46 +0000876 case LibFunc_getitimer:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000877 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000878 case LibFunc_ungetc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000879 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000880 case LibFunc_utime:
881 case LibFunc_utimes:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000882 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
883 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000884 case LibFunc_putc:
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_pread:
887 case LibFunc_pwrite:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000888 return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000889 case LibFunc_popen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000890 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
891 FTy.getParamType(0)->isPointerTy() &&
892 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000893 case LibFunc_vscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000894 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000895 case LibFunc_vsscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000896 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
897 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000898 case LibFunc_vfscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000899 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
900 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000901 case LibFunc_valloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000902 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000903 case LibFunc_vprintf:
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_vfprintf:
906 case LibFunc_vsprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000907 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
908 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000909 case LibFunc_vsnprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000910 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
911 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000912 case LibFunc_open:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000913 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000914 case LibFunc_opendir:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000915 return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
916 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000917 case LibFunc_tmpfile:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000918 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000919 case LibFunc_htonl:
920 case LibFunc_ntohl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000921 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
922 FTy.getReturnType() == FTy.getParamType(0));
David L. Jonesd21529f2017-01-23 23:16:46 +0000923 case LibFunc_htons:
924 case LibFunc_ntohs:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000925 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
926 FTy.getReturnType() == FTy.getParamType(0));
David L. Jonesd21529f2017-01-23 23:16:46 +0000927 case LibFunc_lstat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000928 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
929 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000930 case LibFunc_lchown:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000931 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000932 case LibFunc_qsort:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000933 return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000934 case LibFunc_dunder_strdup:
935 case LibFunc_dunder_strndup:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000936 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
937 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000938 case LibFunc_dunder_strtok_r:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000939 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000940 case LibFunc_under_IO_putc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000941 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000942 case LibFunc_dunder_isoc99_scanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000943 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000944 case LibFunc_stat64:
945 case LibFunc_lstat64:
946 case LibFunc_statvfs64:
Michael Kuperstein79dcc272016-09-20 23:10:31 +0000947 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000948 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000949 case LibFunc_dunder_isoc99_sscanf:
Michael Kuperstein79dcc272016-09-20 23:10:31 +0000950 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000951 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000952 case LibFunc_fopen64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000953 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
954 FTy.getParamType(0)->isPointerTy() &&
955 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000956 case LibFunc_tmpfile64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000957 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000958 case LibFunc_fstat64:
959 case LibFunc_fstatvfs64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000960 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000961 case LibFunc_open64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000962 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000963 case LibFunc_gettimeofday:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000964 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
965 FTy.getParamType(1)->isPointerTy());
966
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000967 // new(unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000968 case LibFunc_Znwj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000969 // new(unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000970 case LibFunc_Znwm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000971 // new[](unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000972 case LibFunc_Znaj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000973 // new[](unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000974 case LibFunc_Znam:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000975 // new(unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000976 case LibFunc_msvc_new_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000977 // new(unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000978 case LibFunc_msvc_new_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000979 // new[](unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000980 case LibFunc_msvc_new_array_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000981 // new[](unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000982 case LibFunc_msvc_new_array_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000983 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
984
985 // new(unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000986 case LibFunc_ZnwjRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000987 // new(unsigned long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000988 case LibFunc_ZnwmRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000989 // new[](unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000990 case LibFunc_ZnajRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000991 // new[](unsigned long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000992 case LibFunc_ZnamRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000993 // new(unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000994 case LibFunc_msvc_new_int_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000995 // new(unsigned long long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000996 case LibFunc_msvc_new_longlong_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000997 // new[](unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000998 case LibFunc_msvc_new_array_int_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000999 // new[](unsigned long long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001000 case LibFunc_msvc_new_array_longlong_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001001 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
1002
1003 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001004 case LibFunc_ZdaPv:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001005 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001006 case LibFunc_ZdlPv:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001007 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001008 case LibFunc_msvc_delete_array_ptr32:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001009 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001010 case LibFunc_msvc_delete_array_ptr64:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001011 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001012 case LibFunc_msvc_delete_ptr32:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001013 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001014 case LibFunc_msvc_delete_ptr64:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001015 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1016
1017 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001018 case LibFunc_ZdaPvRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001019 // void operator delete[](void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001020 case LibFunc_ZdaPvj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001021 // void operator delete[](void*, unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001022 case LibFunc_ZdaPvm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001023 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001024 case LibFunc_ZdlPvRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001025 // void operator delete(void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001026 case LibFunc_ZdlPvj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001027 // void operator delete(void*, unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001028 case LibFunc_ZdlPvm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001029 // void operator delete[](void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001030 case LibFunc_msvc_delete_array_ptr32_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001031 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001032 case LibFunc_msvc_delete_array_ptr32_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001033 // void operator delete[](void*, unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001034 case LibFunc_msvc_delete_array_ptr64_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001035 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001036 case LibFunc_msvc_delete_array_ptr64_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001037 // void operator delete(void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001038 case LibFunc_msvc_delete_ptr32_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001039 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001040 case LibFunc_msvc_delete_ptr32_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001041 // void operator delete(void*, unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001042 case LibFunc_msvc_delete_ptr64_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001043 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001044 case LibFunc_msvc_delete_ptr64_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001045 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001046
David L. Jonesd21529f2017-01-23 23:16:46 +00001047 case LibFunc_memset_pattern16:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001048 return (!FTy.isVarArg() && NumParams == 3 &&
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001049 FTy.getParamType(0)->isPointerTy() &&
1050 FTy.getParamType(1)->isPointerTy() &&
1051 FTy.getParamType(2)->isIntegerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001052
David L. Jonesd21529f2017-01-23 23:16:46 +00001053 case LibFunc_cxa_guard_abort:
1054 case LibFunc_cxa_guard_acquire:
1055 case LibFunc_cxa_guard_release:
1056 case LibFunc_nvvm_reflect:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001057 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001058
David L. Jonesd21529f2017-01-23 23:16:46 +00001059 case LibFunc_sincospi_stret:
1060 case LibFunc_sincospif_stret:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001061 return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
1062
David L. Jonesd21529f2017-01-23 23:16:46 +00001063 case LibFunc_acos:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001064 case LibFunc_acos_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001065 case LibFunc_acosf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001066 case LibFunc_acosf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001067 case LibFunc_acosh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001068 case LibFunc_acosh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001069 case LibFunc_acoshf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001070 case LibFunc_acoshf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001071 case LibFunc_acoshl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001072 case LibFunc_acoshl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001073 case LibFunc_acosl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001074 case LibFunc_acosl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001075 case LibFunc_asin:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001076 case LibFunc_asin_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001077 case LibFunc_asinf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001078 case LibFunc_asinf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001079 case LibFunc_asinh:
1080 case LibFunc_asinhf:
1081 case LibFunc_asinhl:
1082 case LibFunc_asinl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001083 case LibFunc_asinl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001084 case LibFunc_atan:
1085 case LibFunc_atanf:
1086 case LibFunc_atanh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001087 case LibFunc_atanh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001088 case LibFunc_atanhf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001089 case LibFunc_atanhf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001090 case LibFunc_atanhl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001091 case LibFunc_atanhl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001092 case LibFunc_atanl:
1093 case LibFunc_cbrt:
1094 case LibFunc_cbrtf:
1095 case LibFunc_cbrtl:
1096 case LibFunc_ceil:
1097 case LibFunc_ceilf:
1098 case LibFunc_ceill:
1099 case LibFunc_cos:
1100 case LibFunc_cosf:
1101 case LibFunc_cosh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001102 case LibFunc_cosh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001103 case LibFunc_coshf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001104 case LibFunc_coshf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001105 case LibFunc_coshl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001106 case LibFunc_coshl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001107 case LibFunc_cosl:
1108 case LibFunc_exp10:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001109 case LibFunc_exp10_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001110 case LibFunc_exp10f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001111 case LibFunc_exp10f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001112 case LibFunc_exp10l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001113 case LibFunc_exp10l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001114 case LibFunc_exp2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001115 case LibFunc_exp2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001116 case LibFunc_exp2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001117 case LibFunc_exp2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001118 case LibFunc_exp2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001119 case LibFunc_exp2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001120 case LibFunc_exp:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001121 case LibFunc_exp_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001122 case LibFunc_expf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001123 case LibFunc_expf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001124 case LibFunc_expl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001125 case LibFunc_expl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001126 case LibFunc_expm1:
1127 case LibFunc_expm1f:
1128 case LibFunc_expm1l:
1129 case LibFunc_fabs:
1130 case LibFunc_fabsf:
1131 case LibFunc_fabsl:
1132 case LibFunc_floor:
1133 case LibFunc_floorf:
1134 case LibFunc_floorl:
1135 case LibFunc_log10:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001136 case LibFunc_log10_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001137 case LibFunc_log10f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001138 case LibFunc_log10f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001139 case LibFunc_log10l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001140 case LibFunc_log10l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001141 case LibFunc_log1p:
1142 case LibFunc_log1pf:
1143 case LibFunc_log1pl:
1144 case LibFunc_log2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001145 case LibFunc_log2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001146 case LibFunc_log2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001147 case LibFunc_log2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001148 case LibFunc_log2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001149 case LibFunc_log2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001150 case LibFunc_log:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001151 case LibFunc_log_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001152 case LibFunc_logb:
1153 case LibFunc_logbf:
1154 case LibFunc_logbl:
1155 case LibFunc_logf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001156 case LibFunc_logf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001157 case LibFunc_logl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001158 case LibFunc_logl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001159 case LibFunc_nearbyint:
1160 case LibFunc_nearbyintf:
1161 case LibFunc_nearbyintl:
1162 case LibFunc_rint:
1163 case LibFunc_rintf:
1164 case LibFunc_rintl:
1165 case LibFunc_round:
1166 case LibFunc_roundf:
1167 case LibFunc_roundl:
1168 case LibFunc_sin:
1169 case LibFunc_sinf:
1170 case LibFunc_sinh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001171 case LibFunc_sinh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001172 case LibFunc_sinhf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001173 case LibFunc_sinhf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001174 case LibFunc_sinhl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001175 case LibFunc_sinhl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001176 case LibFunc_sinl:
1177 case LibFunc_sqrt:
1178 case LibFunc_sqrt_finite:
1179 case LibFunc_sqrtf:
1180 case LibFunc_sqrtf_finite:
1181 case LibFunc_sqrtl:
1182 case LibFunc_sqrtl_finite:
1183 case LibFunc_tan:
1184 case LibFunc_tanf:
1185 case LibFunc_tanh:
1186 case LibFunc_tanhf:
1187 case LibFunc_tanhl:
1188 case LibFunc_tanl:
1189 case LibFunc_trunc:
1190 case LibFunc_truncf:
1191 case LibFunc_truncl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001192 return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1193 FTy.getReturnType() == FTy.getParamType(0));
1194
David L. Jonesd21529f2017-01-23 23:16:46 +00001195 case LibFunc_atan2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001196 case LibFunc_atan2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001197 case LibFunc_atan2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001198 case LibFunc_atan2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001199 case LibFunc_atan2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001200 case LibFunc_atan2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001201 case LibFunc_fmin:
1202 case LibFunc_fminf:
1203 case LibFunc_fminl:
1204 case LibFunc_fmax:
1205 case LibFunc_fmaxf:
1206 case LibFunc_fmaxl:
1207 case LibFunc_fmod:
1208 case LibFunc_fmodf:
1209 case LibFunc_fmodl:
1210 case LibFunc_copysign:
1211 case LibFunc_copysignf:
1212 case LibFunc_copysignl:
1213 case LibFunc_pow:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001214 case LibFunc_pow_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001215 case LibFunc_powf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001216 case LibFunc_powf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001217 case LibFunc_powl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001218 case LibFunc_powl_finite:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001219 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1220 FTy.getReturnType() == FTy.getParamType(0) &&
1221 FTy.getReturnType() == FTy.getParamType(1));
1222
David L. Jonesd21529f2017-01-23 23:16:46 +00001223 case LibFunc_ldexp:
1224 case LibFunc_ldexpf:
1225 case LibFunc_ldexpl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001226 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1227 FTy.getReturnType() == FTy.getParamType(0) &&
1228 FTy.getParamType(1)->isIntegerTy(32));
1229
David L. Jonesd21529f2017-01-23 23:16:46 +00001230 case LibFunc_ffs:
1231 case LibFunc_ffsl:
1232 case LibFunc_ffsll:
1233 case LibFunc_fls:
1234 case LibFunc_flsl:
1235 case LibFunc_flsll:
Sanjay Patel04949faf2016-09-23 18:44:09 +00001236 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1237 FTy.getParamType(0)->isIntegerTy());
1238
David L. Jonesd21529f2017-01-23 23:16:46 +00001239 case LibFunc_isdigit:
1240 case LibFunc_isascii:
1241 case LibFunc_toascii:
1242 case LibFunc_putchar:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001243 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
Sanjay Patel04949faf2016-09-23 18:44:09 +00001244 FTy.getReturnType() == FTy.getParamType(0));
Ahmed Bougachad765a822016-04-27 19:04:35 +00001245
David L. Jonesd21529f2017-01-23 23:16:46 +00001246 case LibFunc_abs:
1247 case LibFunc_labs:
1248 case LibFunc_llabs:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001249 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1250 FTy.getReturnType() == FTy.getParamType(0));
1251
David L. Jonesd21529f2017-01-23 23:16:46 +00001252 case LibFunc_cxa_atexit:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001253 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1254 FTy.getParamType(0)->isPointerTy() &&
1255 FTy.getParamType(1)->isPointerTy() &&
1256 FTy.getParamType(2)->isPointerTy());
1257
David L. Jonesd21529f2017-01-23 23:16:46 +00001258 case LibFunc_sinpi:
1259 case LibFunc_cospi:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001260 return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1261 FTy.getReturnType() == FTy.getParamType(0));
1262
David L. Jonesd21529f2017-01-23 23:16:46 +00001263 case LibFunc_sinpif:
1264 case LibFunc_cospif:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001265 return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1266 FTy.getReturnType() == FTy.getParamType(0));
1267
David L. Jonesd21529f2017-01-23 23:16:46 +00001268 case LibFunc_strnlen:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001269 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1270 FTy.getParamType(0) == PCharTy &&
1271 FTy.getParamType(1) == SizeTTy);
1272
David L. Jonesd21529f2017-01-23 23:16:46 +00001273 case LibFunc_posix_memalign:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001274 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1275 FTy.getParamType(0)->isPointerTy() &&
1276 FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
1277
Matthias Braun60b40b82017-05-05 20:25:50 +00001278 case LibFunc_wcslen:
1279 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
1280 FTy.getReturnType()->isIntegerTy());
1281
Hal Finkel2ff24732017-12-16 01:26:25 +00001282 case LibFunc_cabs:
1283 case LibFunc_cabsf:
1284 case LibFunc_cabsl: {
1285 Type* RetTy = FTy.getReturnType();
1286 if (!RetTy->isFloatingPointTy())
1287 return false;
1288
1289 // NOTE: These prototypes are target specific and currently support
1290 // "complex" passed as an array or discrete real & imaginary parameters.
1291 // Add other calling conventions to enable libcall optimizations.
1292 if (NumParams == 1)
1293 return (FTy.getParamType(0)->isArrayTy() &&
1294 FTy.getParamType(0)->getArrayNumElements() == 2 &&
1295 FTy.getParamType(0)->getArrayElementType() == RetTy);
1296 else if (NumParams == 2)
1297 return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
1298 else
1299 return false;
1300 }
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001301 case LibFunc::NumLibFuncs:
Ahmed Bougacha86b680a2017-01-17 19:54:18 +00001302 break;
Ahmed Bougachad765a822016-04-27 19:04:35 +00001303 }
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001304
Ahmed Bougacha86b680a2017-01-17 19:54:18 +00001305 llvm_unreachable("Invalid libfunc");
Ahmed Bougachad765a822016-04-27 19:04:35 +00001306}
1307
1308bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
David L. Jonesd21529f2017-01-23 23:16:46 +00001309 LibFunc &F) const {
Ahmed Bougachad765a822016-04-27 19:04:35 +00001310 const DataLayout *DL =
1311 FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1312 return getLibFunc(FDecl.getName(), F) &&
1313 isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1314}
1315
Chandler Carruthc0291862015-01-24 02:06:09 +00001316void TargetLibraryInfoImpl::disableAllFunctions() {
Chris Lattner1341df92011-02-18 22:34:03 +00001317 memset(AvailableArray, 0, sizeof(AvailableArray));
1318}
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001319
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001320static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001321 return LHS.ScalarFnName < RHS.ScalarFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001322}
1323
1324static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001325 return LHS.VectorFnName < RHS.VectorFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001326}
1327
1328static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001329 return LHS.ScalarFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001330}
1331
1332static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001333 return LHS.VectorFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001334}
1335
1336void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1337 VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
1338 std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
1339
1340 ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
1341 std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
1342}
1343
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001344void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1345 enum VectorLibrary VecLib) {
1346 switch (VecLib) {
1347 case Accelerate: {
1348 const VecDesc VecFuncs[] = {
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001349 // Floating-Point Arithmetic and Auxiliary Functions
1350 {"ceilf", "vceilf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001351 {"fabsf", "vfabsf", 4},
1352 {"llvm.fabs.f32", "vfabsf", 4},
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001353 {"floorf", "vfloorf", 4},
1354 {"sqrtf", "vsqrtf", 4},
1355 {"llvm.sqrt.f32", "vsqrtf", 4},
1356
1357 // Exponential and Logarithmic Functions
1358 {"expf", "vexpf", 4},
1359 {"llvm.exp.f32", "vexpf", 4},
1360 {"expm1f", "vexpm1f", 4},
1361 {"logf", "vlogf", 4},
1362 {"llvm.log.f32", "vlogf", 4},
1363 {"log1pf", "vlog1pf", 4},
1364 {"log10f", "vlog10f", 4},
1365 {"llvm.log10.f32", "vlog10f", 4},
1366 {"logbf", "vlogbf", 4},
1367
1368 // Trigonometric Functions
1369 {"sinf", "vsinf", 4},
1370 {"llvm.sin.f32", "vsinf", 4},
1371 {"cosf", "vcosf", 4},
1372 {"llvm.cos.f32", "vcosf", 4},
1373 {"tanf", "vtanf", 4},
1374 {"asinf", "vasinf", 4},
1375 {"acosf", "vacosf", 4},
1376 {"atanf", "vatanf", 4},
1377
1378 // Hyperbolic Functions
1379 {"sinhf", "vsinhf", 4},
1380 {"coshf", "vcoshf", 4},
1381 {"tanhf", "vtanhf", 4},
1382 {"asinhf", "vasinhf", 4},
1383 {"acoshf", "vacoshf", 4},
1384 {"atanhf", "vatanhf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001385 };
1386 addVectorizableFunctions(VecFuncs);
1387 break;
1388 }
Matt Mastena6669a12016-07-29 16:42:44 +00001389 case SVML: {
1390 const VecDesc VecFuncs[] = {
1391 {"sin", "__svml_sin2", 2},
1392 {"sin", "__svml_sin4", 4},
1393 {"sin", "__svml_sin8", 8},
1394
1395 {"sinf", "__svml_sinf4", 4},
1396 {"sinf", "__svml_sinf8", 8},
1397 {"sinf", "__svml_sinf16", 16},
1398
1399 {"cos", "__svml_cos2", 2},
1400 {"cos", "__svml_cos4", 4},
1401 {"cos", "__svml_cos8", 8},
1402
1403 {"cosf", "__svml_cosf4", 4},
1404 {"cosf", "__svml_cosf8", 8},
1405 {"cosf", "__svml_cosf16", 16},
1406
1407 {"pow", "__svml_pow2", 2},
1408 {"pow", "__svml_pow4", 4},
1409 {"pow", "__svml_pow8", 8},
1410
1411 {"powf", "__svml_powf4", 4},
1412 {"powf", "__svml_powf8", 8},
1413 {"powf", "__svml_powf16", 16},
1414
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001415 { "__pow_finite", "__svml_pow2", 2 },
1416 { "__pow_finite", "__svml_pow4", 4 },
1417 { "__pow_finite", "__svml_pow8", 8 },
1418
1419 { "__powf_finite", "__svml_powf4", 4 },
1420 { "__powf_finite", "__svml_powf8", 8 },
1421 { "__powf_finite", "__svml_powf16", 16 },
1422
Matt Mastena6669a12016-07-29 16:42:44 +00001423 {"llvm.pow.f64", "__svml_pow2", 2},
1424 {"llvm.pow.f64", "__svml_pow4", 4},
1425 {"llvm.pow.f64", "__svml_pow8", 8},
1426
1427 {"llvm.pow.f32", "__svml_powf4", 4},
1428 {"llvm.pow.f32", "__svml_powf8", 8},
1429 {"llvm.pow.f32", "__svml_powf16", 16},
1430
1431 {"exp", "__svml_exp2", 2},
1432 {"exp", "__svml_exp4", 4},
1433 {"exp", "__svml_exp8", 8},
1434
1435 {"expf", "__svml_expf4", 4},
1436 {"expf", "__svml_expf8", 8},
1437 {"expf", "__svml_expf16", 16},
1438
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001439 { "__exp_finite", "__svml_exp2", 2 },
1440 { "__exp_finite", "__svml_exp4", 4 },
1441 { "__exp_finite", "__svml_exp8", 8 },
1442
1443 { "__expf_finite", "__svml_expf4", 4 },
1444 { "__expf_finite", "__svml_expf8", 8 },
1445 { "__expf_finite", "__svml_expf16", 16 },
1446
Matt Mastena6669a12016-07-29 16:42:44 +00001447 {"llvm.exp.f64", "__svml_exp2", 2},
1448 {"llvm.exp.f64", "__svml_exp4", 4},
1449 {"llvm.exp.f64", "__svml_exp8", 8},
1450
1451 {"llvm.exp.f32", "__svml_expf4", 4},
1452 {"llvm.exp.f32", "__svml_expf8", 8},
1453 {"llvm.exp.f32", "__svml_expf16", 16},
1454
1455 {"log", "__svml_log2", 2},
1456 {"log", "__svml_log4", 4},
1457 {"log", "__svml_log8", 8},
1458
1459 {"logf", "__svml_logf4", 4},
1460 {"logf", "__svml_logf8", 8},
1461 {"logf", "__svml_logf16", 16},
1462
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001463 { "__log_finite", "__svml_log2", 2 },
1464 { "__log_finite", "__svml_log4", 4 },
1465 { "__log_finite", "__svml_log8", 8 },
1466
1467 { "__logf_finite", "__svml_logf4", 4 },
1468 { "__logf_finite", "__svml_logf8", 8 },
1469 { "__logf_finite", "__svml_logf16", 16 },
1470
Matt Mastena6669a12016-07-29 16:42:44 +00001471 {"llvm.log.f64", "__svml_log2", 2},
1472 {"llvm.log.f64", "__svml_log4", 4},
1473 {"llvm.log.f64", "__svml_log8", 8},
1474
1475 {"llvm.log.f32", "__svml_logf4", 4},
1476 {"llvm.log.f32", "__svml_logf8", 8},
1477 {"llvm.log.f32", "__svml_logf16", 16},
1478 };
1479 addVectorizableFunctions(VecFuncs);
1480 break;
1481 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001482 case NoLibrary:
1483 break;
1484 }
1485}
1486
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001487bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1488 funcName = sanitizeFunctionName(funcName);
1489 if (funcName.empty())
1490 return false;
1491
1492 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1493 VectorDescs.begin(), VectorDescs.end(), funcName,
1494 compareWithScalarFnName);
1495 return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1496}
1497
1498StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1499 unsigned VF) const {
1500 F = sanitizeFunctionName(F);
1501 if (F.empty())
1502 return F;
1503 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1504 VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1505 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1506 if (I->VectorizationFactor == VF)
1507 return I->VectorFnName;
1508 ++I;
1509 }
1510 return StringRef();
1511}
1512
1513StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1514 unsigned &VF) const {
1515 F = sanitizeFunctionName(F);
1516 if (F.empty())
1517 return F;
1518
1519 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1520 ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1521 if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1522 return StringRef();
1523 VF = I->VectorizationFactor;
1524 return I->ScalarFnName;
1525}
1526
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001527TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
1528 ModuleAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001529 if (PresetInfoImpl)
1530 return TargetLibraryInfo(*PresetInfoImpl);
1531
1532 return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1533}
1534
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001535TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
1536 FunctionAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001537 if (PresetInfoImpl)
1538 return TargetLibraryInfo(*PresetInfoImpl);
1539
1540 return TargetLibraryInfo(
1541 lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1542}
1543
Benjamin Kramerc321e532016-06-08 19:09:22 +00001544TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001545 std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1546 Impls[T.normalize()];
1547 if (!Impl)
1548 Impl.reset(new TargetLibraryInfoImpl(T));
1549
1550 return *Impl;
1551}
1552
Matthias Braun50ec0b52017-05-19 22:37:09 +00001553unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
1554 if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1555 M.getModuleFlag("wchar_size")))
1556 return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
Matthias Brauncc603ee2017-09-26 02:36:57 +00001557 return 0;
Matthias Braun50ec0b52017-05-19 22:37:09 +00001558}
Chandler Carruthc0291862015-01-24 02:06:09 +00001559
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001560TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
Chandler Carruthc0291862015-01-24 02:06:09 +00001561 : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001562 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1563}
1564
1565TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
Chandler Carruthc0291862015-01-24 02:06:09 +00001566 : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001567 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1568}
1569
1570TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
Chandler Carruthc0291862015-01-24 02:06:09 +00001571 const TargetLibraryInfoImpl &TLIImpl)
1572 : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001573 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1574}
1575
Chandler Carruthdab4eae2016-11-23 17:53:26 +00001576AnalysisKey TargetLibraryAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +00001577
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001578// Register the basic pass.
1579INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1580 "Target Library Information", false, true)
1581char TargetLibraryInfoWrapperPass::ID = 0;
1582
1583void TargetLibraryInfoWrapperPass::anchor() {}