blob: 8b9f2a27aca3f6de188f33754836da6c2576d92e [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
Chih-Hung Hsieh60d1e792018-01-31 19:12:50 +0000400 // The following functions are available on Linux,
401 // but Android uses bionic instead of glibc.
402 if (!T.isOSLinux() || T.isAndroid()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000403 TLI.setUnavailable(LibFunc_dunder_strdup);
404 TLI.setUnavailable(LibFunc_dunder_strtok_r);
405 TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
406 TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
407 TLI.setUnavailable(LibFunc_under_IO_getc);
408 TLI.setUnavailable(LibFunc_under_IO_putc);
Chih-Hung Hsieh60d1e792018-01-31 19:12:50 +0000409 // But, Android has memalign.
410 if (!T.isAndroid())
411 TLI.setUnavailable(LibFunc_memalign);
David L. Jonesd21529f2017-01-23 23:16:46 +0000412 TLI.setUnavailable(LibFunc_fopen64);
413 TLI.setUnavailable(LibFunc_fseeko64);
414 TLI.setUnavailable(LibFunc_fstat64);
415 TLI.setUnavailable(LibFunc_fstatvfs64);
416 TLI.setUnavailable(LibFunc_ftello64);
417 TLI.setUnavailable(LibFunc_lstat64);
418 TLI.setUnavailable(LibFunc_open64);
419 TLI.setUnavailable(LibFunc_stat64);
420 TLI.setUnavailable(LibFunc_statvfs64);
421 TLI.setUnavailable(LibFunc_tmpfile64);
Sanjay Patel52149f02018-01-08 17:38:09 +0000422
423 // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
424 TLI.setUnavailable(LibFunc_acos_finite);
425 TLI.setUnavailable(LibFunc_acosf_finite);
426 TLI.setUnavailable(LibFunc_acosl_finite);
427 TLI.setUnavailable(LibFunc_acosh_finite);
428 TLI.setUnavailable(LibFunc_acoshf_finite);
429 TLI.setUnavailable(LibFunc_acoshl_finite);
430 TLI.setUnavailable(LibFunc_asin_finite);
431 TLI.setUnavailable(LibFunc_asinf_finite);
432 TLI.setUnavailable(LibFunc_asinl_finite);
433 TLI.setUnavailable(LibFunc_atan2_finite);
434 TLI.setUnavailable(LibFunc_atan2f_finite);
435 TLI.setUnavailable(LibFunc_atan2l_finite);
436 TLI.setUnavailable(LibFunc_atanh_finite);
437 TLI.setUnavailable(LibFunc_atanhf_finite);
438 TLI.setUnavailable(LibFunc_atanhl_finite);
439 TLI.setUnavailable(LibFunc_cosh_finite);
440 TLI.setUnavailable(LibFunc_coshf_finite);
441 TLI.setUnavailable(LibFunc_coshl_finite);
442 TLI.setUnavailable(LibFunc_exp10_finite);
443 TLI.setUnavailable(LibFunc_exp10f_finite);
444 TLI.setUnavailable(LibFunc_exp10l_finite);
445 TLI.setUnavailable(LibFunc_exp2_finite);
446 TLI.setUnavailable(LibFunc_exp2f_finite);
447 TLI.setUnavailable(LibFunc_exp2l_finite);
448 TLI.setUnavailable(LibFunc_exp_finite);
449 TLI.setUnavailable(LibFunc_expf_finite);
450 TLI.setUnavailable(LibFunc_expl_finite);
451 TLI.setUnavailable(LibFunc_log10_finite);
452 TLI.setUnavailable(LibFunc_log10f_finite);
453 TLI.setUnavailable(LibFunc_log10l_finite);
454 TLI.setUnavailable(LibFunc_log2_finite);
455 TLI.setUnavailable(LibFunc_log2f_finite);
456 TLI.setUnavailable(LibFunc_log2l_finite);
457 TLI.setUnavailable(LibFunc_log_finite);
458 TLI.setUnavailable(LibFunc_logf_finite);
459 TLI.setUnavailable(LibFunc_logl_finite);
460 TLI.setUnavailable(LibFunc_pow_finite);
461 TLI.setUnavailable(LibFunc_powf_finite);
462 TLI.setUnavailable(LibFunc_powl_finite);
463 TLI.setUnavailable(LibFunc_sinh_finite);
464 TLI.setUnavailable(LibFunc_sinhf_finite);
465 TLI.setUnavailable(LibFunc_sinhl_finite);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000466 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000467
Justin Lebar51132882016-01-26 23:51:06 +0000468 // As currently implemented in clang, NVPTX code has no standard library to
469 // speak of. Headers provide a standard-ish library implementation, but many
470 // of the signatures are wrong -- for example, many libm functions are not
471 // extern "C".
472 //
473 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
474 // but only used functions are provided to llvm. Moreover, most of the
475 // functions in libdevice don't map precisely to standard library functions.
476 //
477 // FIXME: Having no standard library prevents e.g. many fastmath
478 // optimizations, so this situation should be fixed.
David Majnemerae272d72016-03-31 21:29:57 +0000479 if (T.isNVPTX()) {
Justin Lebar51132882016-01-26 23:51:06 +0000480 TLI.disableAllFunctions();
David L. Jonesd21529f2017-01-23 23:16:46 +0000481 TLI.setAvailable(LibFunc_nvvm_reflect);
David Majnemerae272d72016-03-31 21:29:57 +0000482 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000483 TLI.setUnavailable(LibFunc_nvvm_reflect);
David Majnemerae272d72016-03-31 21:29:57 +0000484 }
Justin Lebar51132882016-01-26 23:51:06 +0000485
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000486 TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000487}
488
Chandler Carruthc0291862015-01-24 02:06:09 +0000489TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000490 // Default to everything being available.
491 memset(AvailableArray, -1, sizeof(AvailableArray));
492
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000493 initialize(*this, Triple(), StandardNames);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000494}
495
Chandler Carruthc0291862015-01-24 02:06:09 +0000496TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000497 // Default to everything being available.
498 memset(AvailableArray, -1, sizeof(AvailableArray));
Chandler Carruthb98f63d2015-01-15 10:41:28 +0000499
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000500 initialize(*this, T, StandardNames);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000501}
Chris Lattner1341df92011-02-18 22:34:03 +0000502
Chandler Carruthc0291862015-01-24 02:06:09 +0000503TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000504 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
505 ShouldExtI32Return(TLI.ShouldExtI32Return),
506 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000507 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
Michael Zolotukhine8f25512015-03-17 19:22:30 +0000508 VectorDescs = TLI.VectorDescs;
509 ScalarDescs = TLI.ScalarDescs;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000510}
511
Chandler Carruthc0291862015-01-24 02:06:09 +0000512TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000513 : CustomNames(std::move(TLI.CustomNames)),
514 ShouldExtI32Param(TLI.ShouldExtI32Param),
515 ShouldExtI32Return(TLI.ShouldExtI32Return),
516 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
Chandler Carruth8ca43222015-01-15 11:39:46 +0000517 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
518 AvailableArray);
Michael Zolotukhine8f25512015-03-17 19:22:30 +0000519 VectorDescs = TLI.VectorDescs;
520 ScalarDescs = TLI.ScalarDescs;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000521}
522
Chandler Carruthc0291862015-01-24 02:06:09 +0000523TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
Eli Friedman489c0ff2011-11-17 01:27:36 +0000524 CustomNames = TLI.CustomNames;
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000525 ShouldExtI32Param = TLI.ShouldExtI32Param;
526 ShouldExtI32Return = TLI.ShouldExtI32Return;
527 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000528 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
529 return *this;
530}
531
Chandler Carruthc0291862015-01-24 02:06:09 +0000532TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
Chandler Carruth8ca43222015-01-15 11:39:46 +0000533 CustomNames = std::move(TLI.CustomNames);
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000534 ShouldExtI32Param = TLI.ShouldExtI32Param;
535 ShouldExtI32Return = TLI.ShouldExtI32Return;
536 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000537 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
538 AvailableArray);
539 return *this;
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000540}
541
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000542static StringRef sanitizeFunctionName(StringRef funcName) {
Benjamin Kramer160f72d2013-03-09 13:48:23 +0000543 // Filter out empty names and names containing null bytes, those can't be in
544 // our table.
545 if (funcName.empty() || funcName.find('\0') != StringRef::npos)
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000546 return StringRef();
Benjamin Kramer160f72d2013-03-09 13:48:23 +0000547
Meador Ingeb904e6e2013-03-05 21:47:40 +0000548 // Check for \01 prefix that is used to mangle __asm declarations and
549 // strip it if present.
Peter Collingbourne6f0ecca2017-05-16 00:39:01 +0000550 return GlobalValue::dropLLVMManglingEscape(funcName);
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000551}
552
553bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
David L. Jonesd21529f2017-01-23 23:16:46 +0000554 LibFunc &F) const {
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000555 StringRef const *Start = &StandardNames[0];
David L. Jonesd21529f2017-01-23 23:16:46 +0000556 StringRef const *End = &StandardNames[NumLibFuncs];
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000557
558 funcName = sanitizeFunctionName(funcName);
559 if (funcName.empty())
560 return false;
561
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000562 StringRef const *I = std::lower_bound(
563 Start, End, funcName, [](StringRef LHS, StringRef RHS) {
564 return LHS < RHS;
Michael Zolotukhind3b76a32015-03-02 20:50:08 +0000565 });
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000566 if (I != End && *I == funcName) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000567 F = (LibFunc)(I - Start);
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000568 return true;
569 }
570 return false;
571}
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000572
Ahmed Bougachad765a822016-04-27 19:04:35 +0000573bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
David L. Jonesd21529f2017-01-23 23:16:46 +0000574 LibFunc F,
Ahmed Bougachad765a822016-04-27 19:04:35 +0000575 const DataLayout *DL) const {
576 LLVMContext &Ctx = FTy.getContext();
577 Type *PCharTy = Type::getInt8PtrTy(Ctx);
578 Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
579 auto IsSizeTTy = [SizeTTy](Type *Ty) {
580 return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
581 };
582 unsigned NumParams = FTy.getNumParams();
583
584 switch (F) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000585 case LibFunc_strlen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000586 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
587 FTy.getReturnType()->isIntegerTy());
588
David L. Jonesd21529f2017-01-23 23:16:46 +0000589 case LibFunc_strchr:
590 case LibFunc_strrchr:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000591 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
592 FTy.getParamType(0) == FTy.getReturnType() &&
593 FTy.getParamType(1)->isIntegerTy());
594
David L. Jonesd21529f2017-01-23 23:16:46 +0000595 case LibFunc_strtol:
596 case LibFunc_strtod:
597 case LibFunc_strtof:
598 case LibFunc_strtoul:
599 case LibFunc_strtoll:
600 case LibFunc_strtold:
601 case LibFunc_strtoull:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000602 return ((NumParams == 2 || NumParams == 3) &&
603 FTy.getParamType(0)->isPointerTy() &&
604 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000605 case LibFunc_strcat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000606 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
607 FTy.getParamType(0) == FTy.getReturnType() &&
608 FTy.getParamType(1) == FTy.getReturnType());
609
David L. Jonesd21529f2017-01-23 23:16:46 +0000610 case LibFunc_strncat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000611 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
612 FTy.getParamType(0) == FTy.getReturnType() &&
613 FTy.getParamType(1) == FTy.getReturnType() &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000614 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000615
David L. Jonesd21529f2017-01-23 23:16:46 +0000616 case LibFunc_strcpy_chk:
617 case LibFunc_stpcpy_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000618 --NumParams;
619 if (!IsSizeTTy(FTy.getParamType(NumParams)))
620 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000621 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000622 case LibFunc_strcpy:
623 case LibFunc_stpcpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000624 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
625 FTy.getParamType(0) == FTy.getParamType(1) &&
626 FTy.getParamType(0) == PCharTy);
627
David L. Jonesd21529f2017-01-23 23:16:46 +0000628 case LibFunc_strncpy_chk:
629 case LibFunc_stpncpy_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000630 --NumParams;
631 if (!IsSizeTTy(FTy.getParamType(NumParams)))
632 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000633 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000634 case LibFunc_strncpy:
635 case LibFunc_stpncpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000636 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
637 FTy.getParamType(0) == FTy.getParamType(1) &&
638 FTy.getParamType(0) == PCharTy &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000639 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000640
David L. Jonesd21529f2017-01-23 23:16:46 +0000641 case LibFunc_strxfrm:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000642 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
643 FTy.getParamType(1)->isPointerTy());
644
David L. Jonesd21529f2017-01-23 23:16:46 +0000645 case LibFunc_strcmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000646 return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
647 FTy.getParamType(0)->isPointerTy() &&
648 FTy.getParamType(0) == FTy.getParamType(1));
649
David L. Jonesd21529f2017-01-23 23:16:46 +0000650 case LibFunc_strncmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000651 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
652 FTy.getParamType(0)->isPointerTy() &&
653 FTy.getParamType(0) == FTy.getParamType(1) &&
Igor Laevsky7bd3fb12017-12-18 10:31:58 +0000654 IsSizeTTy(FTy.getParamType(2)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000655
David L. Jonesd21529f2017-01-23 23:16:46 +0000656 case LibFunc_strspn:
657 case LibFunc_strcspn:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000658 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
659 FTy.getParamType(0) == FTy.getParamType(1) &&
660 FTy.getReturnType()->isIntegerTy());
661
David L. Jonesd21529f2017-01-23 23:16:46 +0000662 case LibFunc_strcoll:
663 case LibFunc_strcasecmp:
664 case LibFunc_strncasecmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000665 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
666 FTy.getParamType(1)->isPointerTy());
667
David L. Jonesd21529f2017-01-23 23:16:46 +0000668 case LibFunc_strstr:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000669 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
670 FTy.getParamType(0)->isPointerTy() &&
671 FTy.getParamType(1)->isPointerTy());
672
David L. Jonesd21529f2017-01-23 23:16:46 +0000673 case LibFunc_strpbrk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000674 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
675 FTy.getReturnType() == FTy.getParamType(0) &&
676 FTy.getParamType(0) == FTy.getParamType(1));
677
David L. Jonesd21529f2017-01-23 23:16:46 +0000678 case LibFunc_strtok:
679 case LibFunc_strtok_r:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000680 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000681 case LibFunc_scanf:
682 case LibFunc_setbuf:
683 case LibFunc_setvbuf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000684 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000685 case LibFunc_strdup:
686 case LibFunc_strndup:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000687 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
688 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000689 case LibFunc_sscanf:
690 case LibFunc_stat:
691 case LibFunc_statvfs:
692 case LibFunc_siprintf:
693 case LibFunc_sprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000694 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
695 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000696 case LibFunc_snprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000697 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
698 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000699 case LibFunc_setitimer:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000700 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
701 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000702 case LibFunc_system:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000703 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000704 case LibFunc_malloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000705 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000706 case LibFunc_memcmp:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000707 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
708 FTy.getParamType(0)->isPointerTy() &&
709 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000710
David L. Jonesd21529f2017-01-23 23:16:46 +0000711 case LibFunc_memchr:
712 case LibFunc_memrchr:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000713 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
714 FTy.getReturnType() == FTy.getParamType(0) &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000715 FTy.getParamType(1)->isIntegerTy(32) &&
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000716 IsSizeTTy(FTy.getParamType(2)));
David L. Jonesd21529f2017-01-23 23:16:46 +0000717 case LibFunc_modf:
718 case LibFunc_modff:
719 case LibFunc_modfl:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000720 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
721
David L. Jonesd21529f2017-01-23 23:16:46 +0000722 case LibFunc_memcpy_chk:
723 case LibFunc_memmove_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000724 --NumParams;
725 if (!IsSizeTTy(FTy.getParamType(NumParams)))
726 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000727 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000728 case LibFunc_memcpy:
729 case LibFunc_mempcpy:
730 case LibFunc_memmove:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000731 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
732 FTy.getParamType(0)->isPointerTy() &&
733 FTy.getParamType(1)->isPointerTy() &&
734 IsSizeTTy(FTy.getParamType(2)));
735
David L. Jonesd21529f2017-01-23 23:16:46 +0000736 case LibFunc_memset_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000737 --NumParams;
738 if (!IsSizeTTy(FTy.getParamType(NumParams)))
739 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000740 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000741 case LibFunc_memset:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000742 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
743 FTy.getParamType(0)->isPointerTy() &&
744 FTy.getParamType(1)->isIntegerTy() &&
745 IsSizeTTy(FTy.getParamType(2)));
746
David L. Jonesd21529f2017-01-23 23:16:46 +0000747 case LibFunc_memccpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000748 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000749 case LibFunc_memalign:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000750 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000751 case LibFunc_realloc:
752 case LibFunc_reallocf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000753 return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
754 FTy.getParamType(0) == FTy.getReturnType() &&
755 IsSizeTTy(FTy.getParamType(1)));
David L. Jonesd21529f2017-01-23 23:16:46 +0000756 case LibFunc_read:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000757 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000758 case LibFunc_rewind:
759 case LibFunc_rmdir:
760 case LibFunc_remove:
761 case LibFunc_realpath:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000762 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000763 case LibFunc_rename:
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_readlink:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000767 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
768 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000769 case LibFunc_write:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000770 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000771 case LibFunc_bcopy:
772 case LibFunc_bcmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000773 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
774 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000775 case LibFunc_bzero:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000776 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000777 case LibFunc_calloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000778 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000779
David L. Jonesd21529f2017-01-23 23:16:46 +0000780 case LibFunc_atof:
781 case LibFunc_atoi:
782 case LibFunc_atol:
783 case LibFunc_atoll:
784 case LibFunc_ferror:
785 case LibFunc_getenv:
786 case LibFunc_getpwnam:
787 case LibFunc_iprintf:
788 case LibFunc_pclose:
789 case LibFunc_perror:
790 case LibFunc_printf:
791 case LibFunc_puts:
792 case LibFunc_uname:
793 case LibFunc_under_IO_getc:
794 case LibFunc_unlink:
795 case LibFunc_unsetenv:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000796 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000797
David L. Jonesd21529f2017-01-23 23:16:46 +0000798 case LibFunc_access:
799 case LibFunc_chmod:
800 case LibFunc_chown:
801 case LibFunc_clearerr:
802 case LibFunc_closedir:
803 case LibFunc_ctermid:
804 case LibFunc_fclose:
805 case LibFunc_feof:
806 case LibFunc_fflush:
807 case LibFunc_fgetc:
808 case LibFunc_fileno:
809 case LibFunc_flockfile:
810 case LibFunc_free:
811 case LibFunc_fseek:
812 case LibFunc_fseeko64:
813 case LibFunc_fseeko:
814 case LibFunc_fsetpos:
815 case LibFunc_ftell:
816 case LibFunc_ftello64:
817 case LibFunc_ftello:
818 case LibFunc_ftrylockfile:
819 case LibFunc_funlockfile:
820 case LibFunc_getc:
821 case LibFunc_getc_unlocked:
822 case LibFunc_getlogin_r:
823 case LibFunc_mkdir:
824 case LibFunc_mktime:
825 case LibFunc_times:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000826 return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
827
David L. Jonesd21529f2017-01-23 23:16:46 +0000828 case LibFunc_fopen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000829 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
830 FTy.getParamType(0)->isPointerTy() &&
831 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000832 case LibFunc_fdopen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000833 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
834 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000835 case LibFunc_fputc:
836 case LibFunc_fstat:
837 case LibFunc_frexp:
838 case LibFunc_frexpf:
839 case LibFunc_frexpl:
840 case LibFunc_fstatvfs:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000841 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000842 case LibFunc_fgets:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000843 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
844 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000845 case LibFunc_fread:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000846 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
847 FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000848 case LibFunc_fwrite:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000849 return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
850 FTy.getParamType(0)->isPointerTy() &&
851 FTy.getParamType(1)->isIntegerTy() &&
852 FTy.getParamType(2)->isIntegerTy() &&
853 FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000854 case LibFunc_fputs:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000855 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
856 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000857 case LibFunc_fscanf:
858 case LibFunc_fiprintf:
859 case LibFunc_fprintf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000860 return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
861 FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000862 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000863 case LibFunc_fgetpos:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000864 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
865 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000866 case LibFunc_getchar:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000867 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000868 case LibFunc_gets:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000869 return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
David L. Jonesd21529f2017-01-23 23:16:46 +0000870 case LibFunc_getitimer:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000871 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000872 case LibFunc_ungetc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000873 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000874 case LibFunc_utime:
875 case LibFunc_utimes:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000876 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
877 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000878 case LibFunc_putc:
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_pread:
881 case LibFunc_pwrite:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000882 return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000883 case LibFunc_popen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000884 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
885 FTy.getParamType(0)->isPointerTy() &&
886 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000887 case LibFunc_vscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000888 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000889 case LibFunc_vsscanf:
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_vfscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000893 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
894 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000895 case LibFunc_valloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000896 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000897 case LibFunc_vprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000898 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000899 case LibFunc_vfprintf:
900 case LibFunc_vsprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000901 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
902 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000903 case LibFunc_vsnprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000904 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
905 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000906 case LibFunc_open:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000907 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000908 case LibFunc_opendir:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000909 return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
910 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000911 case LibFunc_tmpfile:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000912 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000913 case LibFunc_htonl:
914 case LibFunc_ntohl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000915 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
916 FTy.getReturnType() == FTy.getParamType(0));
David L. Jonesd21529f2017-01-23 23:16:46 +0000917 case LibFunc_htons:
918 case LibFunc_ntohs:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000919 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
920 FTy.getReturnType() == FTy.getParamType(0));
David L. Jonesd21529f2017-01-23 23:16:46 +0000921 case LibFunc_lstat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000922 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
923 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000924 case LibFunc_lchown:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000925 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000926 case LibFunc_qsort:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000927 return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000928 case LibFunc_dunder_strdup:
929 case LibFunc_dunder_strndup:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000930 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
931 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000932 case LibFunc_dunder_strtok_r:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000933 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000934 case LibFunc_under_IO_putc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000935 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000936 case LibFunc_dunder_isoc99_scanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000937 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000938 case LibFunc_stat64:
939 case LibFunc_lstat64:
940 case LibFunc_statvfs64:
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_dunder_isoc99_sscanf:
Michael Kuperstein79dcc272016-09-20 23:10:31 +0000944 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000945 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000946 case LibFunc_fopen64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000947 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
948 FTy.getParamType(0)->isPointerTy() &&
949 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000950 case LibFunc_tmpfile64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000951 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000952 case LibFunc_fstat64:
953 case LibFunc_fstatvfs64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000954 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000955 case LibFunc_open64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000956 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000957 case LibFunc_gettimeofday:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000958 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
959 FTy.getParamType(1)->isPointerTy());
960
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000961 // new(unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000962 case LibFunc_Znwj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000963 // new(unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000964 case LibFunc_Znwm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000965 // new[](unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000966 case LibFunc_Znaj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000967 // new[](unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000968 case LibFunc_Znam:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000969 // new(unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000970 case LibFunc_msvc_new_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000971 // new(unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000972 case LibFunc_msvc_new_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000973 // new[](unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000974 case LibFunc_msvc_new_array_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000975 // new[](unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000976 case LibFunc_msvc_new_array_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000977 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
978
979 // new(unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000980 case LibFunc_ZnwjRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000981 // new(unsigned long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000982 case LibFunc_ZnwmRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000983 // new[](unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000984 case LibFunc_ZnajRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000985 // new[](unsigned long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000986 case LibFunc_ZnamRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000987 // new(unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000988 case LibFunc_msvc_new_int_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000989 // new(unsigned long long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000990 case LibFunc_msvc_new_longlong_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000991 // new[](unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000992 case LibFunc_msvc_new_array_int_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000993 // new[](unsigned long long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000994 case LibFunc_msvc_new_array_longlong_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000995 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
996
997 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +0000998 case LibFunc_ZdaPv:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000999 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001000 case LibFunc_ZdlPv:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001001 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001002 case LibFunc_msvc_delete_array_ptr32:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001003 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001004 case LibFunc_msvc_delete_array_ptr64:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001005 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +00001006 case LibFunc_msvc_delete_ptr32:
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_ptr64:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001009 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
1010
1011 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001012 case LibFunc_ZdaPvRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001013 // void operator delete[](void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001014 case LibFunc_ZdaPvj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001015 // void operator delete[](void*, unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001016 case LibFunc_ZdaPvm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001017 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001018 case LibFunc_ZdlPvRKSt9nothrow_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_ZdlPvj:
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_ZdlPvm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001023 // void operator delete[](void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001024 case LibFunc_msvc_delete_array_ptr32_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001025 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001026 case LibFunc_msvc_delete_array_ptr32_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001027 // void operator delete[](void*, unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001028 case LibFunc_msvc_delete_array_ptr64_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001029 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001030 case LibFunc_msvc_delete_array_ptr64_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001031 // void operator delete(void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +00001032 case LibFunc_msvc_delete_ptr32_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001033 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001034 case LibFunc_msvc_delete_ptr32_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001035 // void operator delete(void*, unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +00001036 case LibFunc_msvc_delete_ptr64_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001037 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +00001038 case LibFunc_msvc_delete_ptr64_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001039 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001040
David L. Jonesd21529f2017-01-23 23:16:46 +00001041 case LibFunc_memset_pattern16:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001042 return (!FTy.isVarArg() && NumParams == 3 &&
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001043 FTy.getParamType(0)->isPointerTy() &&
1044 FTy.getParamType(1)->isPointerTy() &&
1045 FTy.getParamType(2)->isIntegerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001046
David L. Jonesd21529f2017-01-23 23:16:46 +00001047 case LibFunc_cxa_guard_abort:
1048 case LibFunc_cxa_guard_acquire:
1049 case LibFunc_cxa_guard_release:
1050 case LibFunc_nvvm_reflect:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001051 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001052
David L. Jonesd21529f2017-01-23 23:16:46 +00001053 case LibFunc_sincospi_stret:
1054 case LibFunc_sincospif_stret:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001055 return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
1056
David L. Jonesd21529f2017-01-23 23:16:46 +00001057 case LibFunc_acos:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001058 case LibFunc_acos_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001059 case LibFunc_acosf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001060 case LibFunc_acosf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001061 case LibFunc_acosh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001062 case LibFunc_acosh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001063 case LibFunc_acoshf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001064 case LibFunc_acoshf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001065 case LibFunc_acoshl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001066 case LibFunc_acoshl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001067 case LibFunc_acosl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001068 case LibFunc_acosl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001069 case LibFunc_asin:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001070 case LibFunc_asin_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001071 case LibFunc_asinf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001072 case LibFunc_asinf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001073 case LibFunc_asinh:
1074 case LibFunc_asinhf:
1075 case LibFunc_asinhl:
1076 case LibFunc_asinl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001077 case LibFunc_asinl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001078 case LibFunc_atan:
1079 case LibFunc_atanf:
1080 case LibFunc_atanh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001081 case LibFunc_atanh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001082 case LibFunc_atanhf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001083 case LibFunc_atanhf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001084 case LibFunc_atanhl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001085 case LibFunc_atanhl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001086 case LibFunc_atanl:
1087 case LibFunc_cbrt:
1088 case LibFunc_cbrtf:
1089 case LibFunc_cbrtl:
1090 case LibFunc_ceil:
1091 case LibFunc_ceilf:
1092 case LibFunc_ceill:
1093 case LibFunc_cos:
1094 case LibFunc_cosf:
1095 case LibFunc_cosh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001096 case LibFunc_cosh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001097 case LibFunc_coshf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001098 case LibFunc_coshf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001099 case LibFunc_coshl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001100 case LibFunc_coshl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001101 case LibFunc_cosl:
1102 case LibFunc_exp10:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001103 case LibFunc_exp10_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001104 case LibFunc_exp10f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001105 case LibFunc_exp10f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001106 case LibFunc_exp10l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001107 case LibFunc_exp10l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001108 case LibFunc_exp2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001109 case LibFunc_exp2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001110 case LibFunc_exp2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001111 case LibFunc_exp2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001112 case LibFunc_exp2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001113 case LibFunc_exp2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001114 case LibFunc_exp:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001115 case LibFunc_exp_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001116 case LibFunc_expf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001117 case LibFunc_expf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001118 case LibFunc_expl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001119 case LibFunc_expl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001120 case LibFunc_expm1:
1121 case LibFunc_expm1f:
1122 case LibFunc_expm1l:
1123 case LibFunc_fabs:
1124 case LibFunc_fabsf:
1125 case LibFunc_fabsl:
1126 case LibFunc_floor:
1127 case LibFunc_floorf:
1128 case LibFunc_floorl:
1129 case LibFunc_log10:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001130 case LibFunc_log10_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001131 case LibFunc_log10f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001132 case LibFunc_log10f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001133 case LibFunc_log10l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001134 case LibFunc_log10l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001135 case LibFunc_log1p:
1136 case LibFunc_log1pf:
1137 case LibFunc_log1pl:
1138 case LibFunc_log2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001139 case LibFunc_log2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001140 case LibFunc_log2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001141 case LibFunc_log2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001142 case LibFunc_log2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001143 case LibFunc_log2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001144 case LibFunc_log:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001145 case LibFunc_log_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001146 case LibFunc_logb:
1147 case LibFunc_logbf:
1148 case LibFunc_logbl:
1149 case LibFunc_logf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001150 case LibFunc_logf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001151 case LibFunc_logl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001152 case LibFunc_logl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001153 case LibFunc_nearbyint:
1154 case LibFunc_nearbyintf:
1155 case LibFunc_nearbyintl:
1156 case LibFunc_rint:
1157 case LibFunc_rintf:
1158 case LibFunc_rintl:
1159 case LibFunc_round:
1160 case LibFunc_roundf:
1161 case LibFunc_roundl:
1162 case LibFunc_sin:
1163 case LibFunc_sinf:
1164 case LibFunc_sinh:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001165 case LibFunc_sinh_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001166 case LibFunc_sinhf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001167 case LibFunc_sinhf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001168 case LibFunc_sinhl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001169 case LibFunc_sinhl_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001170 case LibFunc_sinl:
1171 case LibFunc_sqrt:
1172 case LibFunc_sqrt_finite:
1173 case LibFunc_sqrtf:
1174 case LibFunc_sqrtf_finite:
1175 case LibFunc_sqrtl:
1176 case LibFunc_sqrtl_finite:
1177 case LibFunc_tan:
1178 case LibFunc_tanf:
1179 case LibFunc_tanh:
1180 case LibFunc_tanhf:
1181 case LibFunc_tanhl:
1182 case LibFunc_tanl:
1183 case LibFunc_trunc:
1184 case LibFunc_truncf:
1185 case LibFunc_truncl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001186 return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1187 FTy.getReturnType() == FTy.getParamType(0));
1188
David L. Jonesd21529f2017-01-23 23:16:46 +00001189 case LibFunc_atan2:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001190 case LibFunc_atan2_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001191 case LibFunc_atan2f:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001192 case LibFunc_atan2f_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001193 case LibFunc_atan2l:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001194 case LibFunc_atan2l_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001195 case LibFunc_fmin:
1196 case LibFunc_fminf:
1197 case LibFunc_fminl:
1198 case LibFunc_fmax:
1199 case LibFunc_fmaxf:
1200 case LibFunc_fmaxl:
1201 case LibFunc_fmod:
1202 case LibFunc_fmodf:
1203 case LibFunc_fmodl:
1204 case LibFunc_copysign:
1205 case LibFunc_copysignf:
1206 case LibFunc_copysignl:
1207 case LibFunc_pow:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001208 case LibFunc_pow_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001209 case LibFunc_powf:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001210 case LibFunc_powf_finite:
David L. Jonesd21529f2017-01-23 23:16:46 +00001211 case LibFunc_powl:
Andrew Kaylor3cd8c162017-05-12 22:11:12 +00001212 case LibFunc_powl_finite:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001213 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1214 FTy.getReturnType() == FTy.getParamType(0) &&
1215 FTy.getReturnType() == FTy.getParamType(1));
1216
David L. Jonesd21529f2017-01-23 23:16:46 +00001217 case LibFunc_ldexp:
1218 case LibFunc_ldexpf:
1219 case LibFunc_ldexpl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001220 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1221 FTy.getReturnType() == FTy.getParamType(0) &&
1222 FTy.getParamType(1)->isIntegerTy(32));
1223
David L. Jonesd21529f2017-01-23 23:16:46 +00001224 case LibFunc_ffs:
1225 case LibFunc_ffsl:
1226 case LibFunc_ffsll:
1227 case LibFunc_fls:
1228 case LibFunc_flsl:
1229 case LibFunc_flsll:
Sanjay Patel04949faf2016-09-23 18:44:09 +00001230 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1231 FTy.getParamType(0)->isIntegerTy());
1232
David L. Jonesd21529f2017-01-23 23:16:46 +00001233 case LibFunc_isdigit:
1234 case LibFunc_isascii:
1235 case LibFunc_toascii:
1236 case LibFunc_putchar:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001237 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
Sanjay Patel04949faf2016-09-23 18:44:09 +00001238 FTy.getReturnType() == FTy.getParamType(0));
Ahmed Bougachad765a822016-04-27 19:04:35 +00001239
David L. Jonesd21529f2017-01-23 23:16:46 +00001240 case LibFunc_abs:
1241 case LibFunc_labs:
1242 case LibFunc_llabs:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001243 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1244 FTy.getReturnType() == FTy.getParamType(0));
1245
David L. Jonesd21529f2017-01-23 23:16:46 +00001246 case LibFunc_cxa_atexit:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001247 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1248 FTy.getParamType(0)->isPointerTy() &&
1249 FTy.getParamType(1)->isPointerTy() &&
1250 FTy.getParamType(2)->isPointerTy());
1251
David L. Jonesd21529f2017-01-23 23:16:46 +00001252 case LibFunc_sinpi:
1253 case LibFunc_cospi:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001254 return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1255 FTy.getReturnType() == FTy.getParamType(0));
1256
David L. Jonesd21529f2017-01-23 23:16:46 +00001257 case LibFunc_sinpif:
1258 case LibFunc_cospif:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001259 return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1260 FTy.getReturnType() == FTy.getParamType(0));
1261
David L. Jonesd21529f2017-01-23 23:16:46 +00001262 case LibFunc_strnlen:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001263 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1264 FTy.getParamType(0) == PCharTy &&
1265 FTy.getParamType(1) == SizeTTy);
1266
David L. Jonesd21529f2017-01-23 23:16:46 +00001267 case LibFunc_posix_memalign:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001268 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1269 FTy.getParamType(0)->isPointerTy() &&
1270 FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
1271
Matthias Braun60b40b82017-05-05 20:25:50 +00001272 case LibFunc_wcslen:
1273 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
1274 FTy.getReturnType()->isIntegerTy());
1275
Hal Finkel2ff24732017-12-16 01:26:25 +00001276 case LibFunc_cabs:
1277 case LibFunc_cabsf:
1278 case LibFunc_cabsl: {
1279 Type* RetTy = FTy.getReturnType();
1280 if (!RetTy->isFloatingPointTy())
1281 return false;
1282
1283 // NOTE: These prototypes are target specific and currently support
1284 // "complex" passed as an array or discrete real & imaginary parameters.
1285 // Add other calling conventions to enable libcall optimizations.
1286 if (NumParams == 1)
1287 return (FTy.getParamType(0)->isArrayTy() &&
1288 FTy.getParamType(0)->getArrayNumElements() == 2 &&
1289 FTy.getParamType(0)->getArrayElementType() == RetTy);
1290 else if (NumParams == 2)
1291 return (FTy.getParamType(0) == RetTy && FTy.getParamType(1) == RetTy);
1292 else
1293 return false;
1294 }
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001295 case LibFunc::NumLibFuncs:
Ahmed Bougacha86b680a2017-01-17 19:54:18 +00001296 break;
Ahmed Bougachad765a822016-04-27 19:04:35 +00001297 }
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001298
Ahmed Bougacha86b680a2017-01-17 19:54:18 +00001299 llvm_unreachable("Invalid libfunc");
Ahmed Bougachad765a822016-04-27 19:04:35 +00001300}
1301
1302bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
David L. Jonesd21529f2017-01-23 23:16:46 +00001303 LibFunc &F) const {
Ahmed Bougachad765a822016-04-27 19:04:35 +00001304 const DataLayout *DL =
1305 FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1306 return getLibFunc(FDecl.getName(), F) &&
1307 isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1308}
1309
Chandler Carruthc0291862015-01-24 02:06:09 +00001310void TargetLibraryInfoImpl::disableAllFunctions() {
Chris Lattner1341df92011-02-18 22:34:03 +00001311 memset(AvailableArray, 0, sizeof(AvailableArray));
1312}
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001313
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001314static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001315 return LHS.ScalarFnName < RHS.ScalarFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001316}
1317
1318static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001319 return LHS.VectorFnName < RHS.VectorFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001320}
1321
1322static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001323 return LHS.ScalarFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001324}
1325
1326static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001327 return LHS.VectorFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001328}
1329
1330void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1331 VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
1332 std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
1333
1334 ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
1335 std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
1336}
1337
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001338void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1339 enum VectorLibrary VecLib) {
1340 switch (VecLib) {
1341 case Accelerate: {
1342 const VecDesc VecFuncs[] = {
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001343 // Floating-Point Arithmetic and Auxiliary Functions
1344 {"ceilf", "vceilf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001345 {"fabsf", "vfabsf", 4},
1346 {"llvm.fabs.f32", "vfabsf", 4},
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001347 {"floorf", "vfloorf", 4},
1348 {"sqrtf", "vsqrtf", 4},
1349 {"llvm.sqrt.f32", "vsqrtf", 4},
1350
1351 // Exponential and Logarithmic Functions
1352 {"expf", "vexpf", 4},
1353 {"llvm.exp.f32", "vexpf", 4},
1354 {"expm1f", "vexpm1f", 4},
1355 {"logf", "vlogf", 4},
1356 {"llvm.log.f32", "vlogf", 4},
1357 {"log1pf", "vlog1pf", 4},
1358 {"log10f", "vlog10f", 4},
1359 {"llvm.log10.f32", "vlog10f", 4},
1360 {"logbf", "vlogbf", 4},
1361
1362 // Trigonometric Functions
1363 {"sinf", "vsinf", 4},
1364 {"llvm.sin.f32", "vsinf", 4},
1365 {"cosf", "vcosf", 4},
1366 {"llvm.cos.f32", "vcosf", 4},
1367 {"tanf", "vtanf", 4},
1368 {"asinf", "vasinf", 4},
1369 {"acosf", "vacosf", 4},
1370 {"atanf", "vatanf", 4},
1371
1372 // Hyperbolic Functions
1373 {"sinhf", "vsinhf", 4},
1374 {"coshf", "vcoshf", 4},
1375 {"tanhf", "vtanhf", 4},
1376 {"asinhf", "vasinhf", 4},
1377 {"acoshf", "vacoshf", 4},
1378 {"atanhf", "vatanhf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001379 };
1380 addVectorizableFunctions(VecFuncs);
1381 break;
1382 }
Matt Mastena6669a12016-07-29 16:42:44 +00001383 case SVML: {
1384 const VecDesc VecFuncs[] = {
1385 {"sin", "__svml_sin2", 2},
1386 {"sin", "__svml_sin4", 4},
1387 {"sin", "__svml_sin8", 8},
1388
1389 {"sinf", "__svml_sinf4", 4},
1390 {"sinf", "__svml_sinf8", 8},
1391 {"sinf", "__svml_sinf16", 16},
1392
1393 {"cos", "__svml_cos2", 2},
1394 {"cos", "__svml_cos4", 4},
1395 {"cos", "__svml_cos8", 8},
1396
1397 {"cosf", "__svml_cosf4", 4},
1398 {"cosf", "__svml_cosf8", 8},
1399 {"cosf", "__svml_cosf16", 16},
1400
1401 {"pow", "__svml_pow2", 2},
1402 {"pow", "__svml_pow4", 4},
1403 {"pow", "__svml_pow8", 8},
1404
1405 {"powf", "__svml_powf4", 4},
1406 {"powf", "__svml_powf8", 8},
1407 {"powf", "__svml_powf16", 16},
1408
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001409 { "__pow_finite", "__svml_pow2", 2 },
1410 { "__pow_finite", "__svml_pow4", 4 },
1411 { "__pow_finite", "__svml_pow8", 8 },
1412
1413 { "__powf_finite", "__svml_powf4", 4 },
1414 { "__powf_finite", "__svml_powf8", 8 },
1415 { "__powf_finite", "__svml_powf16", 16 },
1416
Matt Mastena6669a12016-07-29 16:42:44 +00001417 {"llvm.pow.f64", "__svml_pow2", 2},
1418 {"llvm.pow.f64", "__svml_pow4", 4},
1419 {"llvm.pow.f64", "__svml_pow8", 8},
1420
1421 {"llvm.pow.f32", "__svml_powf4", 4},
1422 {"llvm.pow.f32", "__svml_powf8", 8},
1423 {"llvm.pow.f32", "__svml_powf16", 16},
1424
1425 {"exp", "__svml_exp2", 2},
1426 {"exp", "__svml_exp4", 4},
1427 {"exp", "__svml_exp8", 8},
1428
1429 {"expf", "__svml_expf4", 4},
1430 {"expf", "__svml_expf8", 8},
1431 {"expf", "__svml_expf16", 16},
1432
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001433 { "__exp_finite", "__svml_exp2", 2 },
1434 { "__exp_finite", "__svml_exp4", 4 },
1435 { "__exp_finite", "__svml_exp8", 8 },
1436
1437 { "__expf_finite", "__svml_expf4", 4 },
1438 { "__expf_finite", "__svml_expf8", 8 },
1439 { "__expf_finite", "__svml_expf16", 16 },
1440
Matt Mastena6669a12016-07-29 16:42:44 +00001441 {"llvm.exp.f64", "__svml_exp2", 2},
1442 {"llvm.exp.f64", "__svml_exp4", 4},
1443 {"llvm.exp.f64", "__svml_exp8", 8},
1444
1445 {"llvm.exp.f32", "__svml_expf4", 4},
1446 {"llvm.exp.f32", "__svml_expf8", 8},
1447 {"llvm.exp.f32", "__svml_expf16", 16},
1448
1449 {"log", "__svml_log2", 2},
1450 {"log", "__svml_log4", 4},
1451 {"log", "__svml_log8", 8},
1452
1453 {"logf", "__svml_logf4", 4},
1454 {"logf", "__svml_logf8", 8},
1455 {"logf", "__svml_logf16", 16},
1456
Andrew Kaylorb01e94e2017-05-12 22:11:26 +00001457 { "__log_finite", "__svml_log2", 2 },
1458 { "__log_finite", "__svml_log4", 4 },
1459 { "__log_finite", "__svml_log8", 8 },
1460
1461 { "__logf_finite", "__svml_logf4", 4 },
1462 { "__logf_finite", "__svml_logf8", 8 },
1463 { "__logf_finite", "__svml_logf16", 16 },
1464
Matt Mastena6669a12016-07-29 16:42:44 +00001465 {"llvm.log.f64", "__svml_log2", 2},
1466 {"llvm.log.f64", "__svml_log4", 4},
1467 {"llvm.log.f64", "__svml_log8", 8},
1468
1469 {"llvm.log.f32", "__svml_logf4", 4},
1470 {"llvm.log.f32", "__svml_logf8", 8},
1471 {"llvm.log.f32", "__svml_logf16", 16},
1472 };
1473 addVectorizableFunctions(VecFuncs);
1474 break;
1475 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001476 case NoLibrary:
1477 break;
1478 }
1479}
1480
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001481bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1482 funcName = sanitizeFunctionName(funcName);
1483 if (funcName.empty())
1484 return false;
1485
1486 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1487 VectorDescs.begin(), VectorDescs.end(), funcName,
1488 compareWithScalarFnName);
1489 return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1490}
1491
1492StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1493 unsigned VF) const {
1494 F = sanitizeFunctionName(F);
1495 if (F.empty())
1496 return F;
1497 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1498 VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1499 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1500 if (I->VectorizationFactor == VF)
1501 return I->VectorFnName;
1502 ++I;
1503 }
1504 return StringRef();
1505}
1506
1507StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1508 unsigned &VF) const {
1509 F = sanitizeFunctionName(F);
1510 if (F.empty())
1511 return F;
1512
1513 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1514 ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1515 if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1516 return StringRef();
1517 VF = I->VectorizationFactor;
1518 return I->ScalarFnName;
1519}
1520
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001521TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
1522 ModuleAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001523 if (PresetInfoImpl)
1524 return TargetLibraryInfo(*PresetInfoImpl);
1525
1526 return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1527}
1528
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001529TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
1530 FunctionAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001531 if (PresetInfoImpl)
1532 return TargetLibraryInfo(*PresetInfoImpl);
1533
1534 return TargetLibraryInfo(
1535 lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1536}
1537
Benjamin Kramerc321e532016-06-08 19:09:22 +00001538TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001539 std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1540 Impls[T.normalize()];
1541 if (!Impl)
1542 Impl.reset(new TargetLibraryInfoImpl(T));
1543
1544 return *Impl;
1545}
1546
Matthias Braun50ec0b52017-05-19 22:37:09 +00001547unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const {
1548 if (auto *ShortWChar = cast_or_null<ConstantAsMetadata>(
1549 M.getModuleFlag("wchar_size")))
1550 return cast<ConstantInt>(ShortWChar->getValue())->getZExtValue();
Matthias Brauncc603ee2017-09-26 02:36:57 +00001551 return 0;
Matthias Braun50ec0b52017-05-19 22:37:09 +00001552}
Chandler Carruthc0291862015-01-24 02:06:09 +00001553
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001554TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
Chandler Carruthc0291862015-01-24 02:06:09 +00001555 : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001556 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1557}
1558
1559TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
Chandler Carruthc0291862015-01-24 02:06:09 +00001560 : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001561 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1562}
1563
1564TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
Chandler Carruthc0291862015-01-24 02:06:09 +00001565 const TargetLibraryInfoImpl &TLIImpl)
1566 : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001567 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1568}
1569
Chandler Carruthdab4eae2016-11-23 17:53:26 +00001570AnalysisKey TargetLibraryAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +00001571
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001572// Register the basic pass.
1573INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1574 "Target Library Information", false, true)
1575char TargetLibraryInfoWrapperPass::ID = 0;
1576
1577void TargetLibraryInfoWrapperPass::anchor() {}