blob: be734fa91425d2653543740a67053eea566eb72e [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"
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +000016#include "llvm/Support/CommandLine.h"
Chris Lattner0e125bb2011-02-18 21:50:34 +000017using namespace llvm;
18
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +000019static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
20 "vector-library", cl::Hidden, cl::desc("Vector functions library"),
21 cl::init(TargetLibraryInfoImpl::NoLibrary),
22 cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
23 "No vector functions library"),
24 clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
25 "Accelerate framework"),
Matt Mastena6669a12016-07-29 16:42:44 +000026 clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
Mehdi Amini732afdd2016-10-08 19:41:06 +000027 "Intel SVML library")));
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +000028
Mehdi Amini9a72cd72016-10-01 03:10:48 +000029StringRef const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
Jan Wen Voungcd3d25a2015-03-03 23:41:58 +000030#define TLI_DEFINE_STRING
31#include "llvm/Analysis/TargetLibraryInfo.def"
Benjamin Kramer57a3d082015-03-08 16:07:39 +000032};
Eli Friedman489c0ff2011-11-17 01:27:36 +000033
Bob Wilsond8d92d92013-11-03 06:48:38 +000034static bool hasSinCosPiStret(const Triple &T) {
35 // Only Darwin variants have _stret versions of combined trig functions.
Bob Wilson9868d712014-10-09 05:43:30 +000036 if (!T.isOSDarwin())
Bob Wilsond8d92d92013-11-03 06:48:38 +000037 return false;
38
39 // The ABI is rather complicated on x86, so don't do anything special there.
40 if (T.getArch() == Triple::x86)
41 return false;
42
43 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
44 return false;
45
Bob Wilson9868d712014-10-09 05:43:30 +000046 if (T.isiOS() && T.isOSVersionLT(7, 0))
Bob Wilsond8d92d92013-11-03 06:48:38 +000047 return false;
48
49 return true;
50}
51
Chris Lattner0e125bb2011-02-18 21:50:34 +000052/// initialize - Initialize the set of available library functions based on the
53/// specified target triple. This should be carefully written so that a missing
54/// target triple gets a sane set of defaults.
Chandler Carruthc0291862015-01-24 02:06:09 +000055static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
Mehdi Amini9a72cd72016-10-01 03:10:48 +000056 ArrayRef<StringRef> StandardNames) {
Bob Wilsonc740e3f2012-08-03 04:06:22 +000057 // Verify that the StandardNames array is in alphabetical order.
Craig Toppere30b8ca2016-01-03 19:43:40 +000058 assert(std::is_sorted(StandardNames.begin(), StandardNames.end(),
Mehdi Amini9a72cd72016-10-01 03:10:48 +000059 [](StringRef LHS, StringRef RHS) {
60 return LHS < RHS;
Craig Toppere30b8ca2016-01-03 19:43:40 +000061 }) &&
62 "TargetLibraryInfoImpl function names must be sorted");
Tom Stellard36a03182014-04-02 19:53:29 +000063
Marcin Koscielnicki6af8e6c2016-11-21 20:20:39 +000064 bool ShouldExtI32Param = false, ShouldExtI32Return = false,
65 ShouldSignExtI32Param = false;
66 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
67 // returns corresponding to C-level ints and unsigned ints.
68 if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le ||
69 T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) {
70 ShouldExtI32Param = true;
71 ShouldExtI32Return = true;
72 }
73 // Mips, on the other hand, needs signext on i32 parameters corresponding
74 // to both signed and unsigned ints.
75 if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
76 T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el) {
77 ShouldSignExtI32Param = true;
78 }
79 TLI.setShouldExtI32Param(ShouldExtI32Param);
80 TLI.setShouldExtI32Return(ShouldExtI32Return);
81 TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
82
Nicolai Hahnle78fd4f02015-12-15 17:24:15 +000083 if (T.getArch() == Triple::r600 ||
84 T.getArch() == Triple::amdgcn) {
David L. Jonesd21529f2017-01-23 23:16:46 +000085 TLI.setUnavailable(LibFunc_ldexp);
86 TLI.setUnavailable(LibFunc_ldexpf);
87 TLI.setUnavailable(LibFunc_ldexpl);
88 TLI.setUnavailable(LibFunc_exp10);
89 TLI.setUnavailable(LibFunc_exp10f);
90 TLI.setUnavailable(LibFunc_exp10l);
91 TLI.setUnavailable(LibFunc_log10);
92 TLI.setUnavailable(LibFunc_log10f);
93 TLI.setUnavailable(LibFunc_log10l);
Nicolai Hahnle78fd4f02015-12-15 17:24:15 +000094 }
95
Tom Stellardd00a9232015-01-07 01:17:37 +000096 // There are no library implementations of mempcy and memset for AMD gpus and
Tom Stellard36a03182014-04-02 19:53:29 +000097 // these can be difficult to lower in the backend.
Tom Stellardd00a9232015-01-07 01:17:37 +000098 if (T.getArch() == Triple::r600 ||
Dan Gohman05532992016-01-19 14:49:23 +000099 T.getArch() == Triple::amdgcn) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000100 TLI.setUnavailable(LibFunc_memcpy);
101 TLI.setUnavailable(LibFunc_memset);
102 TLI.setUnavailable(LibFunc_memset_pattern16);
Tom Stellard36a03182014-04-02 19:53:29 +0000103 return;
104 }
105
Nico Weberad156922014-03-07 18:08:54 +0000106 // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
Tim Northover8b403662015-10-28 22:51:16 +0000107 // All versions of watchOS support it.
Daniel Dunbarcd01ed52011-04-20 00:14:25 +0000108 if (T.isMacOSX()) {
109 if (T.isMacOSXVersionLT(10, 5))
David L. Jonesd21529f2017-01-23 23:16:46 +0000110 TLI.setUnavailable(LibFunc_memset_pattern16);
Cameron Esfahani943908b2013-08-29 20:23:14 +0000111 } else if (T.isiOS()) {
Daniel Dunbar9483bb62011-04-19 20:44:08 +0000112 if (T.isOSVersionLT(3, 0))
David L. Jonesd21529f2017-01-23 23:16:46 +0000113 TLI.setUnavailable(LibFunc_memset_pattern16);
Tim Northover8b403662015-10-28 22:51:16 +0000114 } else if (!T.isWatchOS()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000115 TLI.setUnavailable(LibFunc_memset_pattern16);
Daniel Dunbar9483bb62011-04-19 20:44:08 +0000116 }
Richard Osborne815de532011-03-03 13:17:51 +0000117
Bob Wilsond8d92d92013-11-03 06:48:38 +0000118 if (!hasSinCosPiStret(T)) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000119 TLI.setUnavailable(LibFunc_sinpi);
120 TLI.setUnavailable(LibFunc_sinpif);
121 TLI.setUnavailable(LibFunc_cospi);
122 TLI.setUnavailable(LibFunc_cospif);
123 TLI.setUnavailable(LibFunc_sincospi_stret);
124 TLI.setUnavailable(LibFunc_sincospif_stret);
Bob Wilsond8d92d92013-11-03 06:48:38 +0000125 }
126
Eli Friedman489c0ff2011-11-17 01:27:36 +0000127 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
128 !T.isMacOSXVersionLT(10, 7)) {
129 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
130 // we don't care about) have two versions; on recent OSX, the one we want
131 // has a $UNIX2003 suffix. The two implementations are identical except
132 // for the return value in some edge cases. However, we don't want to
133 // generate code that depends on the old symbols.
David L. Jonesd21529f2017-01-23 23:16:46 +0000134 TLI.setAvailableWithName(LibFunc_fwrite, "fwrite$UNIX2003");
135 TLI.setAvailableWithName(LibFunc_fputs, "fputs$UNIX2003");
Eli Friedman489c0ff2011-11-17 01:27:36 +0000136 }
137
Duncan Sandseeb50c82011-06-09 11:11:45 +0000138 // iprintf and friends are only available on XCore and TCE.
139 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000140 TLI.setUnavailable(LibFunc_iprintf);
141 TLI.setUnavailable(LibFunc_siprintf);
142 TLI.setUnavailable(LibFunc_fiprintf);
Richard Osborne2dfb8882011-03-03 14:09:28 +0000143 }
Joe Groffa81bcbb2012-04-17 23:05:54 +0000144
Saleem Abdulrasool8dc8fb12014-07-24 22:09:06 +0000145 if (T.isOSWindows() && !T.isOSCygMing()) {
Joe Groffa81bcbb2012-04-17 23:05:54 +0000146 // Win32 does not support long double
David L. Jonesd21529f2017-01-23 23:16:46 +0000147 TLI.setUnavailable(LibFunc_acosl);
148 TLI.setUnavailable(LibFunc_asinl);
149 TLI.setUnavailable(LibFunc_atanl);
150 TLI.setUnavailable(LibFunc_atan2l);
151 TLI.setUnavailable(LibFunc_ceill);
152 TLI.setUnavailable(LibFunc_copysignl);
153 TLI.setUnavailable(LibFunc_cosl);
154 TLI.setUnavailable(LibFunc_coshl);
155 TLI.setUnavailable(LibFunc_expl);
156 TLI.setUnavailable(LibFunc_fabsf); // Win32 and Win64 both lack fabsf
157 TLI.setUnavailable(LibFunc_fabsl);
158 TLI.setUnavailable(LibFunc_floorl);
159 TLI.setUnavailable(LibFunc_fmaxl);
160 TLI.setUnavailable(LibFunc_fminl);
161 TLI.setUnavailable(LibFunc_fmodl);
162 TLI.setUnavailable(LibFunc_frexpl);
163 TLI.setUnavailable(LibFunc_ldexpf);
164 TLI.setUnavailable(LibFunc_ldexpl);
165 TLI.setUnavailable(LibFunc_logl);
166 TLI.setUnavailable(LibFunc_modfl);
167 TLI.setUnavailable(LibFunc_powl);
168 TLI.setUnavailable(LibFunc_sinl);
169 TLI.setUnavailable(LibFunc_sinhl);
170 TLI.setUnavailable(LibFunc_sqrtl);
171 TLI.setUnavailable(LibFunc_tanl);
172 TLI.setUnavailable(LibFunc_tanhl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000173
174 // Win32 only has C89 math
David L. Jonesd21529f2017-01-23 23:16:46 +0000175 TLI.setUnavailable(LibFunc_acosh);
176 TLI.setUnavailable(LibFunc_acoshf);
177 TLI.setUnavailable(LibFunc_acoshl);
178 TLI.setUnavailable(LibFunc_asinh);
179 TLI.setUnavailable(LibFunc_asinhf);
180 TLI.setUnavailable(LibFunc_asinhl);
181 TLI.setUnavailable(LibFunc_atanh);
182 TLI.setUnavailable(LibFunc_atanhf);
183 TLI.setUnavailable(LibFunc_atanhl);
184 TLI.setUnavailable(LibFunc_cbrt);
185 TLI.setUnavailable(LibFunc_cbrtf);
186 TLI.setUnavailable(LibFunc_cbrtl);
187 TLI.setUnavailable(LibFunc_exp2);
188 TLI.setUnavailable(LibFunc_exp2f);
189 TLI.setUnavailable(LibFunc_exp2l);
190 TLI.setUnavailable(LibFunc_expm1);
191 TLI.setUnavailable(LibFunc_expm1f);
192 TLI.setUnavailable(LibFunc_expm1l);
193 TLI.setUnavailable(LibFunc_log2);
194 TLI.setUnavailable(LibFunc_log2f);
195 TLI.setUnavailable(LibFunc_log2l);
196 TLI.setUnavailable(LibFunc_log1p);
197 TLI.setUnavailable(LibFunc_log1pf);
198 TLI.setUnavailable(LibFunc_log1pl);
199 TLI.setUnavailable(LibFunc_logb);
200 TLI.setUnavailable(LibFunc_logbf);
201 TLI.setUnavailable(LibFunc_logbl);
202 TLI.setUnavailable(LibFunc_nearbyint);
203 TLI.setUnavailable(LibFunc_nearbyintf);
204 TLI.setUnavailable(LibFunc_nearbyintl);
205 TLI.setUnavailable(LibFunc_rint);
206 TLI.setUnavailable(LibFunc_rintf);
207 TLI.setUnavailable(LibFunc_rintl);
208 TLI.setUnavailable(LibFunc_round);
209 TLI.setUnavailable(LibFunc_roundf);
210 TLI.setUnavailable(LibFunc_roundl);
211 TLI.setUnavailable(LibFunc_trunc);
212 TLI.setUnavailable(LibFunc_truncf);
213 TLI.setUnavailable(LibFunc_truncl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000214
215 // Win32 provides some C99 math with mangled names
David L. Jonesd21529f2017-01-23 23:16:46 +0000216 TLI.setAvailableWithName(LibFunc_copysign, "_copysign");
Joe Groffa81bcbb2012-04-17 23:05:54 +0000217
218 if (T.getArch() == Triple::x86) {
219 // Win32 on x86 implements single-precision math functions as macros
David L. Jonesd21529f2017-01-23 23:16:46 +0000220 TLI.setUnavailable(LibFunc_acosf);
221 TLI.setUnavailable(LibFunc_asinf);
222 TLI.setUnavailable(LibFunc_atanf);
223 TLI.setUnavailable(LibFunc_atan2f);
224 TLI.setUnavailable(LibFunc_ceilf);
225 TLI.setUnavailable(LibFunc_copysignf);
226 TLI.setUnavailable(LibFunc_cosf);
227 TLI.setUnavailable(LibFunc_coshf);
228 TLI.setUnavailable(LibFunc_expf);
229 TLI.setUnavailable(LibFunc_floorf);
230 TLI.setUnavailable(LibFunc_fminf);
231 TLI.setUnavailable(LibFunc_fmaxf);
232 TLI.setUnavailable(LibFunc_fmodf);
233 TLI.setUnavailable(LibFunc_logf);
234 TLI.setUnavailable(LibFunc_log10f);
235 TLI.setUnavailable(LibFunc_modff);
236 TLI.setUnavailable(LibFunc_powf);
237 TLI.setUnavailable(LibFunc_sinf);
238 TLI.setUnavailable(LibFunc_sinhf);
239 TLI.setUnavailable(LibFunc_sqrtf);
240 TLI.setUnavailable(LibFunc_tanf);
241 TLI.setUnavailable(LibFunc_tanhf);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000242 }
Meador Inge2526a422012-11-10 03:11:06 +0000243
Meador Ingeb904e6e2013-03-05 21:47:40 +0000244 // Win32 does *not* provide provide these functions, but they are
245 // generally available on POSIX-compliant systems:
David L. Jonesd21529f2017-01-23 23:16:46 +0000246 TLI.setUnavailable(LibFunc_access);
247 TLI.setUnavailable(LibFunc_bcmp);
248 TLI.setUnavailable(LibFunc_bcopy);
249 TLI.setUnavailable(LibFunc_bzero);
250 TLI.setUnavailable(LibFunc_chmod);
251 TLI.setUnavailable(LibFunc_chown);
252 TLI.setUnavailable(LibFunc_closedir);
253 TLI.setUnavailable(LibFunc_ctermid);
254 TLI.setUnavailable(LibFunc_fdopen);
255 TLI.setUnavailable(LibFunc_ffs);
256 TLI.setUnavailable(LibFunc_fileno);
257 TLI.setUnavailable(LibFunc_flockfile);
258 TLI.setUnavailable(LibFunc_fseeko);
259 TLI.setUnavailable(LibFunc_fstat);
260 TLI.setUnavailable(LibFunc_fstatvfs);
261 TLI.setUnavailable(LibFunc_ftello);
262 TLI.setUnavailable(LibFunc_ftrylockfile);
263 TLI.setUnavailable(LibFunc_funlockfile);
264 TLI.setUnavailable(LibFunc_getc_unlocked);
265 TLI.setUnavailable(LibFunc_getitimer);
266 TLI.setUnavailable(LibFunc_getlogin_r);
267 TLI.setUnavailable(LibFunc_getpwnam);
268 TLI.setUnavailable(LibFunc_gettimeofday);
269 TLI.setUnavailable(LibFunc_htonl);
270 TLI.setUnavailable(LibFunc_htons);
271 TLI.setUnavailable(LibFunc_lchown);
272 TLI.setUnavailable(LibFunc_lstat);
273 TLI.setUnavailable(LibFunc_memccpy);
274 TLI.setUnavailable(LibFunc_mkdir);
275 TLI.setUnavailable(LibFunc_ntohl);
276 TLI.setUnavailable(LibFunc_ntohs);
277 TLI.setUnavailable(LibFunc_open);
278 TLI.setUnavailable(LibFunc_opendir);
279 TLI.setUnavailable(LibFunc_pclose);
280 TLI.setUnavailable(LibFunc_popen);
281 TLI.setUnavailable(LibFunc_pread);
282 TLI.setUnavailable(LibFunc_pwrite);
283 TLI.setUnavailable(LibFunc_read);
284 TLI.setUnavailable(LibFunc_readlink);
285 TLI.setUnavailable(LibFunc_realpath);
286 TLI.setUnavailable(LibFunc_rmdir);
287 TLI.setUnavailable(LibFunc_setitimer);
288 TLI.setUnavailable(LibFunc_stat);
289 TLI.setUnavailable(LibFunc_statvfs);
290 TLI.setUnavailable(LibFunc_stpcpy);
291 TLI.setUnavailable(LibFunc_stpncpy);
292 TLI.setUnavailable(LibFunc_strcasecmp);
293 TLI.setUnavailable(LibFunc_strncasecmp);
294 TLI.setUnavailable(LibFunc_times);
295 TLI.setUnavailable(LibFunc_uname);
296 TLI.setUnavailable(LibFunc_unlink);
297 TLI.setUnavailable(LibFunc_unsetenv);
298 TLI.setUnavailable(LibFunc_utime);
299 TLI.setUnavailable(LibFunc_utimes);
300 TLI.setUnavailable(LibFunc_write);
Meador Inge780a1862012-11-22 15:36:42 +0000301
Meador Ingeb904e6e2013-03-05 21:47:40 +0000302 // Win32 does *not* provide provide these functions, but they are
303 // specified by C99:
David L. Jonesd21529f2017-01-23 23:16:46 +0000304 TLI.setUnavailable(LibFunc_atoll);
305 TLI.setUnavailable(LibFunc_frexpf);
306 TLI.setUnavailable(LibFunc_llabs);
Meador Inge780a1862012-11-22 15:36:42 +0000307 }
308
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000309 switch (T.getOS()) {
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000310 case Triple::MacOSX:
Chandler Carruthf5689f82013-12-28 02:40:19 +0000311 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
312 // and their names are __exp10 and __exp10f. exp10l is not available on
313 // OS X or iOS.
David L. Jonesd21529f2017-01-23 23:16:46 +0000314 TLI.setUnavailable(LibFunc_exp10l);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000315 if (T.isMacOSXVersionLT(10, 9)) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000316 TLI.setUnavailable(LibFunc_exp10);
317 TLI.setUnavailable(LibFunc_exp10f);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000318 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000319 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
320 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000321 }
322 break;
323 case Triple::IOS:
Tim Northover89a6eef2015-11-02 18:00:00 +0000324 case Triple::TvOS:
Tim Northover8b403662015-10-28 22:51:16 +0000325 case Triple::WatchOS:
David L. Jonesd21529f2017-01-23 23:16:46 +0000326 TLI.setUnavailable(LibFunc_exp10l);
Tim Northover8b403662015-10-28 22:51:16 +0000327 if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
328 (T.isOSVersionLT(9, 0) &&
329 (T.getArch() == Triple::x86 ||
330 T.getArch() == Triple::x86_64)))) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000331 TLI.setUnavailable(LibFunc_exp10);
332 TLI.setUnavailable(LibFunc_exp10f);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000333 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000334 TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
335 TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000336 }
337 break;
Chandler Carruthf5689f82013-12-28 02:40:19 +0000338 case Triple::Linux:
339 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
340 // buggy prior to glibc version 2.18. Until this version is widely deployed
341 // or we have a reasonable detection strategy, we cannot use exp10 reliably
342 // on Linux.
343 //
344 // Fall through to disable all of them.
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000345 LLVM_FALLTHROUGH;
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000346 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000347 TLI.setUnavailable(LibFunc_exp10);
348 TLI.setUnavailable(LibFunc_exp10f);
349 TLI.setUnavailable(LibFunc_exp10l);
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000350 }
351
Meador Inge780a1862012-11-22 15:36:42 +0000352 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
353 // Linux (GLIBC):
354 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
Davide Italiano83b34812015-11-01 17:00:13 +0000355 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
Meador Inge780a1862012-11-22 15:36:42 +0000356 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
357 switch (T.getOS()) {
358 case Triple::Darwin:
359 case Triple::MacOSX:
360 case Triple::IOS:
Tim Northover89a6eef2015-11-02 18:00:00 +0000361 case Triple::TvOS:
Tim Northover8b403662015-10-28 22:51:16 +0000362 case Triple::WatchOS:
Meador Inge780a1862012-11-22 15:36:42 +0000363 case Triple::FreeBSD:
364 case Triple::Linux:
365 break;
366 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000367 TLI.setUnavailable(LibFunc_ffsl);
Meador Inge780a1862012-11-22 15:36:42 +0000368 }
369
370 // ffsll is available on at least FreeBSD and Linux (GLIBC):
Davide Italiano83b34812015-11-01 17:00:13 +0000371 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
Meador Inge780a1862012-11-22 15:36:42 +0000372 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
373 switch (T.getOS()) {
Tim Northover89a6eef2015-11-02 18:00:00 +0000374 case Triple::Darwin:
375 case Triple::MacOSX:
376 case Triple::IOS:
377 case Triple::TvOS:
378 case Triple::WatchOS:
Meador Inge780a1862012-11-22 15:36:42 +0000379 case Triple::FreeBSD:
380 case Triple::Linux:
381 break;
382 default:
David L. Jonesd21529f2017-01-23 23:16:46 +0000383 TLI.setUnavailable(LibFunc_ffsll);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000384 }
Meador Ingeb904e6e2013-03-05 21:47:40 +0000385
Davide Italianobfd30822015-11-09 23:23:20 +0000386 // The following functions are available on at least FreeBSD:
387 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
388 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
389 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
390 if (!T.isOSFreeBSD()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000391 TLI.setUnavailable(LibFunc_fls);
392 TLI.setUnavailable(LibFunc_flsl);
393 TLI.setUnavailable(LibFunc_flsll);
Davide Italianobfd30822015-11-09 23:23:20 +0000394 }
395
Meador Ingeb904e6e2013-03-05 21:47:40 +0000396 // The following functions are available on at least Linux:
Cameron Esfahani943908b2013-08-29 20:23:14 +0000397 if (!T.isOSLinux()) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000398 TLI.setUnavailable(LibFunc_dunder_strdup);
399 TLI.setUnavailable(LibFunc_dunder_strtok_r);
400 TLI.setUnavailable(LibFunc_dunder_isoc99_scanf);
401 TLI.setUnavailable(LibFunc_dunder_isoc99_sscanf);
402 TLI.setUnavailable(LibFunc_under_IO_getc);
403 TLI.setUnavailable(LibFunc_under_IO_putc);
404 TLI.setUnavailable(LibFunc_memalign);
405 TLI.setUnavailable(LibFunc_fopen64);
406 TLI.setUnavailable(LibFunc_fseeko64);
407 TLI.setUnavailable(LibFunc_fstat64);
408 TLI.setUnavailable(LibFunc_fstatvfs64);
409 TLI.setUnavailable(LibFunc_ftello64);
410 TLI.setUnavailable(LibFunc_lstat64);
411 TLI.setUnavailable(LibFunc_open64);
412 TLI.setUnavailable(LibFunc_stat64);
413 TLI.setUnavailable(LibFunc_statvfs64);
414 TLI.setUnavailable(LibFunc_tmpfile64);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000415 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000416
Justin Lebar51132882016-01-26 23:51:06 +0000417 // As currently implemented in clang, NVPTX code has no standard library to
418 // speak of. Headers provide a standard-ish library implementation, but many
419 // of the signatures are wrong -- for example, many libm functions are not
420 // extern "C".
421 //
422 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
423 // but only used functions are provided to llvm. Moreover, most of the
424 // functions in libdevice don't map precisely to standard library functions.
425 //
426 // FIXME: Having no standard library prevents e.g. many fastmath
427 // optimizations, so this situation should be fixed.
David Majnemerae272d72016-03-31 21:29:57 +0000428 if (T.isNVPTX()) {
Justin Lebar51132882016-01-26 23:51:06 +0000429 TLI.disableAllFunctions();
David L. Jonesd21529f2017-01-23 23:16:46 +0000430 TLI.setAvailable(LibFunc_nvvm_reflect);
David Majnemerae272d72016-03-31 21:29:57 +0000431 } else {
David L. Jonesd21529f2017-01-23 23:16:46 +0000432 TLI.setUnavailable(LibFunc_nvvm_reflect);
David Majnemerae272d72016-03-31 21:29:57 +0000433 }
Justin Lebar51132882016-01-26 23:51:06 +0000434
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000435 TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000436}
437
Chandler Carruthc0291862015-01-24 02:06:09 +0000438TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000439 // Default to everything being available.
440 memset(AvailableArray, -1, sizeof(AvailableArray));
441
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000442 initialize(*this, Triple(), StandardNames);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000443}
444
Chandler Carruthc0291862015-01-24 02:06:09 +0000445TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
Chris Lattner0e125bb2011-02-18 21:50:34 +0000446 // Default to everything being available.
447 memset(AvailableArray, -1, sizeof(AvailableArray));
Chandler Carruthb98f63d2015-01-15 10:41:28 +0000448
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000449 initialize(*this, T, StandardNames);
Chris Lattner0e125bb2011-02-18 21:50:34 +0000450}
Chris Lattner1341df92011-02-18 22:34:03 +0000451
Chandler Carruthc0291862015-01-24 02:06:09 +0000452TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000453 : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param),
454 ShouldExtI32Return(TLI.ShouldExtI32Return),
455 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000456 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
Michael Zolotukhine8f25512015-03-17 19:22:30 +0000457 VectorDescs = TLI.VectorDescs;
458 ScalarDescs = TLI.ScalarDescs;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000459}
460
Chandler Carruthc0291862015-01-24 02:06:09 +0000461TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000462 : CustomNames(std::move(TLI.CustomNames)),
463 ShouldExtI32Param(TLI.ShouldExtI32Param),
464 ShouldExtI32Return(TLI.ShouldExtI32Return),
465 ShouldSignExtI32Param(TLI.ShouldSignExtI32Param) {
Chandler Carruth8ca43222015-01-15 11:39:46 +0000466 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
467 AvailableArray);
Michael Zolotukhine8f25512015-03-17 19:22:30 +0000468 VectorDescs = TLI.VectorDescs;
469 ScalarDescs = TLI.ScalarDescs;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000470}
471
Chandler Carruthc0291862015-01-24 02:06:09 +0000472TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
Eli Friedman489c0ff2011-11-17 01:27:36 +0000473 CustomNames = TLI.CustomNames;
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000474 ShouldExtI32Param = TLI.ShouldExtI32Param;
475 ShouldExtI32Return = TLI.ShouldExtI32Return;
476 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000477 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
478 return *this;
479}
480
Chandler Carruthc0291862015-01-24 02:06:09 +0000481TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
Chandler Carruth8ca43222015-01-15 11:39:46 +0000482 CustomNames = std::move(TLI.CustomNames);
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000483 ShouldExtI32Param = TLI.ShouldExtI32Param;
484 ShouldExtI32Return = TLI.ShouldExtI32Return;
485 ShouldSignExtI32Param = TLI.ShouldSignExtI32Param;
Chandler Carruth8ca43222015-01-15 11:39:46 +0000486 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
487 AvailableArray);
488 return *this;
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000489}
490
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000491static StringRef sanitizeFunctionName(StringRef funcName) {
Benjamin Kramer160f72d2013-03-09 13:48:23 +0000492 // Filter out empty names and names containing null bytes, those can't be in
493 // our table.
494 if (funcName.empty() || funcName.find('\0') != StringRef::npos)
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000495 return StringRef();
Benjamin Kramer160f72d2013-03-09 13:48:23 +0000496
Meador Ingeb904e6e2013-03-05 21:47:40 +0000497 // Check for \01 prefix that is used to mangle __asm declarations and
498 // strip it if present.
David Majnemercde33032015-03-30 22:58:10 +0000499 return GlobalValue::getRealLinkageName(funcName);
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000500}
501
502bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
David L. Jonesd21529f2017-01-23 23:16:46 +0000503 LibFunc &F) const {
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000504 StringRef const *Start = &StandardNames[0];
David L. Jonesd21529f2017-01-23 23:16:46 +0000505 StringRef const *End = &StandardNames[NumLibFuncs];
Michael Zolotukhin21abdf92015-03-02 23:24:40 +0000506
507 funcName = sanitizeFunctionName(funcName);
508 if (funcName.empty())
509 return false;
510
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000511 StringRef const *I = std::lower_bound(
512 Start, End, funcName, [](StringRef LHS, StringRef RHS) {
513 return LHS < RHS;
Michael Zolotukhind3b76a32015-03-02 20:50:08 +0000514 });
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000515 if (I != End && *I == funcName) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000516 F = (LibFunc)(I - Start);
Bob Wilsonc740e3f2012-08-03 04:06:22 +0000517 return true;
518 }
519 return false;
520}
Chris Lattner4c0d9e22011-05-21 20:09:13 +0000521
Ahmed Bougachad765a822016-04-27 19:04:35 +0000522bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
David L. Jonesd21529f2017-01-23 23:16:46 +0000523 LibFunc F,
Ahmed Bougachad765a822016-04-27 19:04:35 +0000524 const DataLayout *DL) const {
525 LLVMContext &Ctx = FTy.getContext();
526 Type *PCharTy = Type::getInt8PtrTy(Ctx);
527 Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
528 auto IsSizeTTy = [SizeTTy](Type *Ty) {
529 return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
530 };
531 unsigned NumParams = FTy.getNumParams();
532
533 switch (F) {
David L. Jonesd21529f2017-01-23 23:16:46 +0000534 case LibFunc_strlen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000535 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
536 FTy.getReturnType()->isIntegerTy());
537
David L. Jonesd21529f2017-01-23 23:16:46 +0000538 case LibFunc_strchr:
539 case LibFunc_strrchr:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000540 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
541 FTy.getParamType(0) == FTy.getReturnType() &&
542 FTy.getParamType(1)->isIntegerTy());
543
David L. Jonesd21529f2017-01-23 23:16:46 +0000544 case LibFunc_strtol:
545 case LibFunc_strtod:
546 case LibFunc_strtof:
547 case LibFunc_strtoul:
548 case LibFunc_strtoll:
549 case LibFunc_strtold:
550 case LibFunc_strtoull:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000551 return ((NumParams == 2 || NumParams == 3) &&
552 FTy.getParamType(0)->isPointerTy() &&
553 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000554 case LibFunc_strcat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000555 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
556 FTy.getParamType(0) == FTy.getReturnType() &&
557 FTy.getParamType(1) == FTy.getReturnType());
558
David L. Jonesd21529f2017-01-23 23:16:46 +0000559 case LibFunc_strncat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000560 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
561 FTy.getParamType(0) == FTy.getReturnType() &&
562 FTy.getParamType(1) == FTy.getReturnType() &&
563 FTy.getParamType(2)->isIntegerTy());
564
David L. Jonesd21529f2017-01-23 23:16:46 +0000565 case LibFunc_strcpy_chk:
566 case LibFunc_stpcpy_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000567 --NumParams;
568 if (!IsSizeTTy(FTy.getParamType(NumParams)))
569 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000570 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000571 case LibFunc_strcpy:
572 case LibFunc_stpcpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000573 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
574 FTy.getParamType(0) == FTy.getParamType(1) &&
575 FTy.getParamType(0) == PCharTy);
576
David L. Jonesd21529f2017-01-23 23:16:46 +0000577 case LibFunc_strncpy_chk:
578 case LibFunc_stpncpy_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000579 --NumParams;
580 if (!IsSizeTTy(FTy.getParamType(NumParams)))
581 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000582 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000583 case LibFunc_strncpy:
584 case LibFunc_stpncpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000585 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
586 FTy.getParamType(0) == FTy.getParamType(1) &&
587 FTy.getParamType(0) == PCharTy &&
588 FTy.getParamType(2)->isIntegerTy());
589
David L. Jonesd21529f2017-01-23 23:16:46 +0000590 case LibFunc_strxfrm:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000591 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
592 FTy.getParamType(1)->isPointerTy());
593
David L. Jonesd21529f2017-01-23 23:16:46 +0000594 case LibFunc_strcmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000595 return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
596 FTy.getParamType(0)->isPointerTy() &&
597 FTy.getParamType(0) == FTy.getParamType(1));
598
David L. Jonesd21529f2017-01-23 23:16:46 +0000599 case LibFunc_strncmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000600 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
601 FTy.getParamType(0)->isPointerTy() &&
602 FTy.getParamType(0) == FTy.getParamType(1) &&
603 FTy.getParamType(2)->isIntegerTy());
604
David L. Jonesd21529f2017-01-23 23:16:46 +0000605 case LibFunc_strspn:
606 case LibFunc_strcspn:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000607 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
608 FTy.getParamType(0) == FTy.getParamType(1) &&
609 FTy.getReturnType()->isIntegerTy());
610
David L. Jonesd21529f2017-01-23 23:16:46 +0000611 case LibFunc_strcoll:
612 case LibFunc_strcasecmp:
613 case LibFunc_strncasecmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000614 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
615 FTy.getParamType(1)->isPointerTy());
616
David L. Jonesd21529f2017-01-23 23:16:46 +0000617 case LibFunc_strstr:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000618 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
619 FTy.getParamType(0)->isPointerTy() &&
620 FTy.getParamType(1)->isPointerTy());
621
David L. Jonesd21529f2017-01-23 23:16:46 +0000622 case LibFunc_strpbrk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000623 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
624 FTy.getReturnType() == FTy.getParamType(0) &&
625 FTy.getParamType(0) == FTy.getParamType(1));
626
David L. Jonesd21529f2017-01-23 23:16:46 +0000627 case LibFunc_strtok:
628 case LibFunc_strtok_r:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000629 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000630 case LibFunc_scanf:
631 case LibFunc_setbuf:
632 case LibFunc_setvbuf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000633 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000634 case LibFunc_strdup:
635 case LibFunc_strndup:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000636 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
637 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000638 case LibFunc_sscanf:
639 case LibFunc_stat:
640 case LibFunc_statvfs:
641 case LibFunc_siprintf:
642 case LibFunc_sprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000643 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
644 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000645 case LibFunc_snprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000646 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
647 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000648 case LibFunc_setitimer:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000649 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
650 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000651 case LibFunc_system:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000652 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000653 case LibFunc_malloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000654 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000655 case LibFunc_memcmp:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000656 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
657 FTy.getParamType(0)->isPointerTy() &&
658 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000659
David L. Jonesd21529f2017-01-23 23:16:46 +0000660 case LibFunc_memchr:
661 case LibFunc_memrchr:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000662 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
663 FTy.getReturnType() == FTy.getParamType(0) &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000664 FTy.getParamType(1)->isIntegerTy(32) &&
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000665 IsSizeTTy(FTy.getParamType(2)));
David L. Jonesd21529f2017-01-23 23:16:46 +0000666 case LibFunc_modf:
667 case LibFunc_modff:
668 case LibFunc_modfl:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000669 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
670
David L. Jonesd21529f2017-01-23 23:16:46 +0000671 case LibFunc_memcpy_chk:
672 case LibFunc_memmove_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000673 --NumParams;
674 if (!IsSizeTTy(FTy.getParamType(NumParams)))
675 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000676 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000677 case LibFunc_memcpy:
678 case LibFunc_mempcpy:
679 case LibFunc_memmove:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000680 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
681 FTy.getParamType(0)->isPointerTy() &&
682 FTy.getParamType(1)->isPointerTy() &&
683 IsSizeTTy(FTy.getParamType(2)));
684
David L. Jonesd21529f2017-01-23 23:16:46 +0000685 case LibFunc_memset_chk:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000686 --NumParams;
687 if (!IsSizeTTy(FTy.getParamType(NumParams)))
688 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000689 LLVM_FALLTHROUGH;
David L. Jonesd21529f2017-01-23 23:16:46 +0000690 case LibFunc_memset:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000691 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
692 FTy.getParamType(0)->isPointerTy() &&
693 FTy.getParamType(1)->isIntegerTy() &&
694 IsSizeTTy(FTy.getParamType(2)));
695
David L. Jonesd21529f2017-01-23 23:16:46 +0000696 case LibFunc_memccpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000697 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000698 case LibFunc_memalign:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000699 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000700 case LibFunc_realloc:
701 case LibFunc_reallocf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000702 return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
703 FTy.getParamType(0) == FTy.getReturnType() &&
704 IsSizeTTy(FTy.getParamType(1)));
David L. Jonesd21529f2017-01-23 23:16:46 +0000705 case LibFunc_read:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000706 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000707 case LibFunc_rewind:
708 case LibFunc_rmdir:
709 case LibFunc_remove:
710 case LibFunc_realpath:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000711 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000712 case LibFunc_rename:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000713 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
714 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000715 case LibFunc_readlink:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000716 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
717 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000718 case LibFunc_write:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000719 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000720 case LibFunc_bcopy:
721 case LibFunc_bcmp:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000722 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
723 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000724 case LibFunc_bzero:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000725 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000726 case LibFunc_calloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000727 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000728
David L. Jonesd21529f2017-01-23 23:16:46 +0000729 case LibFunc_atof:
730 case LibFunc_atoi:
731 case LibFunc_atol:
732 case LibFunc_atoll:
733 case LibFunc_ferror:
734 case LibFunc_getenv:
735 case LibFunc_getpwnam:
736 case LibFunc_iprintf:
737 case LibFunc_pclose:
738 case LibFunc_perror:
739 case LibFunc_printf:
740 case LibFunc_puts:
741 case LibFunc_uname:
742 case LibFunc_under_IO_getc:
743 case LibFunc_unlink:
744 case LibFunc_unsetenv:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000745 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000746
David L. Jonesd21529f2017-01-23 23:16:46 +0000747 case LibFunc_access:
748 case LibFunc_chmod:
749 case LibFunc_chown:
750 case LibFunc_clearerr:
751 case LibFunc_closedir:
752 case LibFunc_ctermid:
753 case LibFunc_fclose:
754 case LibFunc_feof:
755 case LibFunc_fflush:
756 case LibFunc_fgetc:
757 case LibFunc_fileno:
758 case LibFunc_flockfile:
759 case LibFunc_free:
760 case LibFunc_fseek:
761 case LibFunc_fseeko64:
762 case LibFunc_fseeko:
763 case LibFunc_fsetpos:
764 case LibFunc_ftell:
765 case LibFunc_ftello64:
766 case LibFunc_ftello:
767 case LibFunc_ftrylockfile:
768 case LibFunc_funlockfile:
769 case LibFunc_getc:
770 case LibFunc_getc_unlocked:
771 case LibFunc_getlogin_r:
772 case LibFunc_mkdir:
773 case LibFunc_mktime:
774 case LibFunc_times:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000775 return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
776
David L. Jonesd21529f2017-01-23 23:16:46 +0000777 case LibFunc_fopen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000778 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
779 FTy.getParamType(0)->isPointerTy() &&
780 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000781 case LibFunc_fdopen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000782 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
783 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000784 case LibFunc_fputc:
785 case LibFunc_fstat:
786 case LibFunc_frexp:
787 case LibFunc_frexpf:
788 case LibFunc_frexpl:
789 case LibFunc_fstatvfs:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000790 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000791 case LibFunc_fgets:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000792 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
793 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000794 case LibFunc_fread:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000795 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
796 FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000797 case LibFunc_fwrite:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000798 return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
799 FTy.getParamType(0)->isPointerTy() &&
800 FTy.getParamType(1)->isIntegerTy() &&
801 FTy.getParamType(2)->isIntegerTy() &&
802 FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000803 case LibFunc_fputs:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000804 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
805 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000806 case LibFunc_fscanf:
807 case LibFunc_fiprintf:
808 case LibFunc_fprintf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000809 return (NumParams >= 2 && FTy.getReturnType()->isIntegerTy() &&
810 FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000811 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000812 case LibFunc_fgetpos:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000813 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
814 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000815 case LibFunc_getchar:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000816 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000817 case LibFunc_gets:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000818 return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
David L. Jonesd21529f2017-01-23 23:16:46 +0000819 case LibFunc_getitimer:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000820 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000821 case LibFunc_ungetc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000822 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000823 case LibFunc_utime:
824 case LibFunc_utimes:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000825 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
826 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000827 case LibFunc_putc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000828 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000829 case LibFunc_pread:
830 case LibFunc_pwrite:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000831 return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000832 case LibFunc_popen:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000833 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
834 FTy.getParamType(0)->isPointerTy() &&
835 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000836 case LibFunc_vscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000837 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000838 case LibFunc_vsscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000839 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
840 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000841 case LibFunc_vfscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000842 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
843 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000844 case LibFunc_valloc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000845 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000846 case LibFunc_vprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000847 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000848 case LibFunc_vfprintf:
849 case LibFunc_vsprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000850 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
851 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000852 case LibFunc_vsnprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000853 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
854 FTy.getParamType(2)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000855 case LibFunc_open:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000856 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000857 case LibFunc_opendir:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000858 return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
859 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000860 case LibFunc_tmpfile:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000861 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000862 case LibFunc_htonl:
863 case LibFunc_ntohl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000864 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
865 FTy.getReturnType() == FTy.getParamType(0));
David L. Jonesd21529f2017-01-23 23:16:46 +0000866 case LibFunc_htons:
867 case LibFunc_ntohs:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000868 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
869 FTy.getReturnType() == FTy.getParamType(0));
David L. Jonesd21529f2017-01-23 23:16:46 +0000870 case LibFunc_lstat:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000871 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
872 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000873 case LibFunc_lchown:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000874 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000875 case LibFunc_qsort:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000876 return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000877 case LibFunc_dunder_strdup:
878 case LibFunc_dunder_strndup:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000879 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
880 FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000881 case LibFunc_dunder_strtok_r:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000882 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000883 case LibFunc_under_IO_putc:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000884 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000885 case LibFunc_dunder_isoc99_scanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000886 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000887 case LibFunc_stat64:
888 case LibFunc_lstat64:
889 case LibFunc_statvfs64:
Michael Kuperstein79dcc272016-09-20 23:10:31 +0000890 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000891 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000892 case LibFunc_dunder_isoc99_sscanf:
Michael Kuperstein79dcc272016-09-20 23:10:31 +0000893 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000894 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000895 case LibFunc_fopen64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000896 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
897 FTy.getParamType(0)->isPointerTy() &&
898 FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000899 case LibFunc_tmpfile64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000900 return (FTy.getReturnType()->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000901 case LibFunc_fstat64:
902 case LibFunc_fstatvfs64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000903 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000904 case LibFunc_open64:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000905 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
David L. Jonesd21529f2017-01-23 23:16:46 +0000906 case LibFunc_gettimeofday:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000907 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
908 FTy.getParamType(1)->isPointerTy());
909
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000910 // new(unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000911 case LibFunc_Znwj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000912 // new(unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000913 case LibFunc_Znwm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000914 // new[](unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000915 case LibFunc_Znaj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000916 // new[](unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000917 case LibFunc_Znam:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000918 // new(unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000919 case LibFunc_msvc_new_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000920 // new(unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000921 case LibFunc_msvc_new_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000922 // new[](unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000923 case LibFunc_msvc_new_array_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000924 // new[](unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000925 case LibFunc_msvc_new_array_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000926 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
927
928 // new(unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000929 case LibFunc_ZnwjRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000930 // new(unsigned long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000931 case LibFunc_ZnwmRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000932 // new[](unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000933 case LibFunc_ZnajRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000934 // new[](unsigned long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000935 case LibFunc_ZnamRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000936 // new(unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000937 case LibFunc_msvc_new_int_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000938 // new(unsigned long long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000939 case LibFunc_msvc_new_longlong_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000940 // new[](unsigned int, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000941 case LibFunc_msvc_new_array_int_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000942 // new[](unsigned long long, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000943 case LibFunc_msvc_new_array_longlong_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000944 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
945
946 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +0000947 case LibFunc_ZdaPv:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000948 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +0000949 case LibFunc_ZdlPv:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000950 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +0000951 case LibFunc_msvc_delete_array_ptr32:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000952 // void operator delete[](void*);
David L. Jonesd21529f2017-01-23 23:16:46 +0000953 case LibFunc_msvc_delete_array_ptr64:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000954 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +0000955 case LibFunc_msvc_delete_ptr32:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000956 // void operator delete(void*);
David L. Jonesd21529f2017-01-23 23:16:46 +0000957 case LibFunc_msvc_delete_ptr64:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000958 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
959
960 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000961 case LibFunc_ZdaPvRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000962 // void operator delete[](void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000963 case LibFunc_ZdaPvj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000964 // void operator delete[](void*, unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000965 case LibFunc_ZdaPvm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000966 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000967 case LibFunc_ZdlPvRKSt9nothrow_t:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000968 // void operator delete(void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000969 case LibFunc_ZdlPvj:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000970 // void operator delete(void*, unsigned long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000971 case LibFunc_ZdlPvm:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000972 // void operator delete[](void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000973 case LibFunc_msvc_delete_array_ptr32_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000974 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000975 case LibFunc_msvc_delete_array_ptr32_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000976 // void operator delete[](void*, unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000977 case LibFunc_msvc_delete_array_ptr64_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000978 // void operator delete[](void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000979 case LibFunc_msvc_delete_array_ptr64_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000980 // void operator delete(void*, unsigned int);
David L. Jonesd21529f2017-01-23 23:16:46 +0000981 case LibFunc_msvc_delete_ptr32_int:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000982 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000983 case LibFunc_msvc_delete_ptr32_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000984 // void operator delete(void*, unsigned long long);
David L. Jonesd21529f2017-01-23 23:16:46 +0000985 case LibFunc_msvc_delete_ptr64_longlong:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000986 // void operator delete(void*, nothrow);
David L. Jonesd21529f2017-01-23 23:16:46 +0000987 case LibFunc_msvc_delete_ptr64_nothrow:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000988 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000989
David L. Jonesd21529f2017-01-23 23:16:46 +0000990 case LibFunc_memset_pattern16:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000991 return (!FTy.isVarArg() && NumParams == 3 &&
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000992 FTy.getParamType(0)->isPointerTy() &&
993 FTy.getParamType(1)->isPointerTy() &&
994 FTy.getParamType(2)->isIntegerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000995
David L. Jonesd21529f2017-01-23 23:16:46 +0000996 case LibFunc_cxa_guard_abort:
997 case LibFunc_cxa_guard_acquire:
998 case LibFunc_cxa_guard_release:
999 case LibFunc_nvvm_reflect:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001000 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +00001001
David L. Jonesd21529f2017-01-23 23:16:46 +00001002 case LibFunc_sincospi_stret:
1003 case LibFunc_sincospif_stret:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001004 return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
1005
David L. Jonesd21529f2017-01-23 23:16:46 +00001006 case LibFunc_acos:
1007 case LibFunc_acosf:
1008 case LibFunc_acosh:
1009 case LibFunc_acoshf:
1010 case LibFunc_acoshl:
1011 case LibFunc_acosl:
1012 case LibFunc_asin:
1013 case LibFunc_asinf:
1014 case LibFunc_asinh:
1015 case LibFunc_asinhf:
1016 case LibFunc_asinhl:
1017 case LibFunc_asinl:
1018 case LibFunc_atan:
1019 case LibFunc_atanf:
1020 case LibFunc_atanh:
1021 case LibFunc_atanhf:
1022 case LibFunc_atanhl:
1023 case LibFunc_atanl:
1024 case LibFunc_cbrt:
1025 case LibFunc_cbrtf:
1026 case LibFunc_cbrtl:
1027 case LibFunc_ceil:
1028 case LibFunc_ceilf:
1029 case LibFunc_ceill:
1030 case LibFunc_cos:
1031 case LibFunc_cosf:
1032 case LibFunc_cosh:
1033 case LibFunc_coshf:
1034 case LibFunc_coshl:
1035 case LibFunc_cosl:
1036 case LibFunc_exp10:
1037 case LibFunc_exp10f:
1038 case LibFunc_exp10l:
1039 case LibFunc_exp2:
1040 case LibFunc_exp2f:
1041 case LibFunc_exp2l:
1042 case LibFunc_exp:
1043 case LibFunc_expf:
1044 case LibFunc_expl:
1045 case LibFunc_expm1:
1046 case LibFunc_expm1f:
1047 case LibFunc_expm1l:
1048 case LibFunc_fabs:
1049 case LibFunc_fabsf:
1050 case LibFunc_fabsl:
1051 case LibFunc_floor:
1052 case LibFunc_floorf:
1053 case LibFunc_floorl:
1054 case LibFunc_log10:
1055 case LibFunc_log10f:
1056 case LibFunc_log10l:
1057 case LibFunc_log1p:
1058 case LibFunc_log1pf:
1059 case LibFunc_log1pl:
1060 case LibFunc_log2:
1061 case LibFunc_log2f:
1062 case LibFunc_log2l:
1063 case LibFunc_log:
1064 case LibFunc_logb:
1065 case LibFunc_logbf:
1066 case LibFunc_logbl:
1067 case LibFunc_logf:
1068 case LibFunc_logl:
1069 case LibFunc_nearbyint:
1070 case LibFunc_nearbyintf:
1071 case LibFunc_nearbyintl:
1072 case LibFunc_rint:
1073 case LibFunc_rintf:
1074 case LibFunc_rintl:
1075 case LibFunc_round:
1076 case LibFunc_roundf:
1077 case LibFunc_roundl:
1078 case LibFunc_sin:
1079 case LibFunc_sinf:
1080 case LibFunc_sinh:
1081 case LibFunc_sinhf:
1082 case LibFunc_sinhl:
1083 case LibFunc_sinl:
1084 case LibFunc_sqrt:
1085 case LibFunc_sqrt_finite:
1086 case LibFunc_sqrtf:
1087 case LibFunc_sqrtf_finite:
1088 case LibFunc_sqrtl:
1089 case LibFunc_sqrtl_finite:
1090 case LibFunc_tan:
1091 case LibFunc_tanf:
1092 case LibFunc_tanh:
1093 case LibFunc_tanhf:
1094 case LibFunc_tanhl:
1095 case LibFunc_tanl:
1096 case LibFunc_trunc:
1097 case LibFunc_truncf:
1098 case LibFunc_truncl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001099 return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
1100 FTy.getReturnType() == FTy.getParamType(0));
1101
David L. Jonesd21529f2017-01-23 23:16:46 +00001102 case LibFunc_atan2:
1103 case LibFunc_atan2f:
1104 case LibFunc_atan2l:
1105 case LibFunc_fmin:
1106 case LibFunc_fminf:
1107 case LibFunc_fminl:
1108 case LibFunc_fmax:
1109 case LibFunc_fmaxf:
1110 case LibFunc_fmaxl:
1111 case LibFunc_fmod:
1112 case LibFunc_fmodf:
1113 case LibFunc_fmodl:
1114 case LibFunc_copysign:
1115 case LibFunc_copysignf:
1116 case LibFunc_copysignl:
1117 case LibFunc_pow:
1118 case LibFunc_powf:
1119 case LibFunc_powl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001120 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1121 FTy.getReturnType() == FTy.getParamType(0) &&
1122 FTy.getReturnType() == FTy.getParamType(1));
1123
David L. Jonesd21529f2017-01-23 23:16:46 +00001124 case LibFunc_ldexp:
1125 case LibFunc_ldexpf:
1126 case LibFunc_ldexpl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001127 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1128 FTy.getReturnType() == FTy.getParamType(0) &&
1129 FTy.getParamType(1)->isIntegerTy(32));
1130
David L. Jonesd21529f2017-01-23 23:16:46 +00001131 case LibFunc_ffs:
1132 case LibFunc_ffsl:
1133 case LibFunc_ffsll:
1134 case LibFunc_fls:
1135 case LibFunc_flsl:
1136 case LibFunc_flsll:
Sanjay Patel04949faf2016-09-23 18:44:09 +00001137 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
1138 FTy.getParamType(0)->isIntegerTy());
1139
David L. Jonesd21529f2017-01-23 23:16:46 +00001140 case LibFunc_isdigit:
1141 case LibFunc_isascii:
1142 case LibFunc_toascii:
1143 case LibFunc_putchar:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001144 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
Sanjay Patel04949faf2016-09-23 18:44:09 +00001145 FTy.getReturnType() == FTy.getParamType(0));
Ahmed Bougachad765a822016-04-27 19:04:35 +00001146
David L. Jonesd21529f2017-01-23 23:16:46 +00001147 case LibFunc_abs:
1148 case LibFunc_labs:
1149 case LibFunc_llabs:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001150 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1151 FTy.getReturnType() == FTy.getParamType(0));
1152
David L. Jonesd21529f2017-01-23 23:16:46 +00001153 case LibFunc_cxa_atexit:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001154 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1155 FTy.getParamType(0)->isPointerTy() &&
1156 FTy.getParamType(1)->isPointerTy() &&
1157 FTy.getParamType(2)->isPointerTy());
1158
David L. Jonesd21529f2017-01-23 23:16:46 +00001159 case LibFunc_sinpi:
1160 case LibFunc_cospi:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001161 return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1162 FTy.getReturnType() == FTy.getParamType(0));
1163
David L. Jonesd21529f2017-01-23 23:16:46 +00001164 case LibFunc_sinpif:
1165 case LibFunc_cospif:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001166 return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1167 FTy.getReturnType() == FTy.getParamType(0));
1168
David L. Jonesd21529f2017-01-23 23:16:46 +00001169 case LibFunc_strnlen:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001170 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1171 FTy.getParamType(0) == PCharTy &&
1172 FTy.getParamType(1) == SizeTTy);
1173
David L. Jonesd21529f2017-01-23 23:16:46 +00001174 case LibFunc_posix_memalign:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001175 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
1176 FTy.getParamType(0)->isPointerTy() &&
1177 FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
1178
1179 case LibFunc::NumLibFuncs:
Ahmed Bougacha86b680a2017-01-17 19:54:18 +00001180 break;
Ahmed Bougachad765a822016-04-27 19:04:35 +00001181 }
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001182
Ahmed Bougacha86b680a2017-01-17 19:54:18 +00001183 llvm_unreachable("Invalid libfunc");
Ahmed Bougachad765a822016-04-27 19:04:35 +00001184}
1185
1186bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
David L. Jonesd21529f2017-01-23 23:16:46 +00001187 LibFunc &F) const {
Ahmed Bougachad765a822016-04-27 19:04:35 +00001188 const DataLayout *DL =
1189 FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1190 return getLibFunc(FDecl.getName(), F) &&
1191 isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1192}
1193
Chandler Carruthc0291862015-01-24 02:06:09 +00001194void TargetLibraryInfoImpl::disableAllFunctions() {
Chris Lattner1341df92011-02-18 22:34:03 +00001195 memset(AvailableArray, 0, sizeof(AvailableArray));
1196}
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001197
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001198static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001199 return LHS.ScalarFnName < RHS.ScalarFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001200}
1201
1202static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001203 return LHS.VectorFnName < RHS.VectorFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001204}
1205
1206static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001207 return LHS.ScalarFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001208}
1209
1210static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001211 return LHS.VectorFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001212}
1213
1214void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1215 VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
1216 std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
1217
1218 ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
1219 std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
1220}
1221
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001222void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1223 enum VectorLibrary VecLib) {
1224 switch (VecLib) {
1225 case Accelerate: {
1226 const VecDesc VecFuncs[] = {
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001227 // Floating-Point Arithmetic and Auxiliary Functions
1228 {"ceilf", "vceilf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001229 {"fabsf", "vfabsf", 4},
1230 {"llvm.fabs.f32", "vfabsf", 4},
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001231 {"floorf", "vfloorf", 4},
1232 {"sqrtf", "vsqrtf", 4},
1233 {"llvm.sqrt.f32", "vsqrtf", 4},
1234
1235 // Exponential and Logarithmic Functions
1236 {"expf", "vexpf", 4},
1237 {"llvm.exp.f32", "vexpf", 4},
1238 {"expm1f", "vexpm1f", 4},
1239 {"logf", "vlogf", 4},
1240 {"llvm.log.f32", "vlogf", 4},
1241 {"log1pf", "vlog1pf", 4},
1242 {"log10f", "vlog10f", 4},
1243 {"llvm.log10.f32", "vlog10f", 4},
1244 {"logbf", "vlogbf", 4},
1245
1246 // Trigonometric Functions
1247 {"sinf", "vsinf", 4},
1248 {"llvm.sin.f32", "vsinf", 4},
1249 {"cosf", "vcosf", 4},
1250 {"llvm.cos.f32", "vcosf", 4},
1251 {"tanf", "vtanf", 4},
1252 {"asinf", "vasinf", 4},
1253 {"acosf", "vacosf", 4},
1254 {"atanf", "vatanf", 4},
1255
1256 // Hyperbolic Functions
1257 {"sinhf", "vsinhf", 4},
1258 {"coshf", "vcoshf", 4},
1259 {"tanhf", "vtanhf", 4},
1260 {"asinhf", "vasinhf", 4},
1261 {"acoshf", "vacoshf", 4},
1262 {"atanhf", "vatanhf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001263 };
1264 addVectorizableFunctions(VecFuncs);
1265 break;
1266 }
Matt Mastena6669a12016-07-29 16:42:44 +00001267 case SVML: {
1268 const VecDesc VecFuncs[] = {
1269 {"sin", "__svml_sin2", 2},
1270 {"sin", "__svml_sin4", 4},
1271 {"sin", "__svml_sin8", 8},
1272
1273 {"sinf", "__svml_sinf4", 4},
1274 {"sinf", "__svml_sinf8", 8},
1275 {"sinf", "__svml_sinf16", 16},
1276
1277 {"cos", "__svml_cos2", 2},
1278 {"cos", "__svml_cos4", 4},
1279 {"cos", "__svml_cos8", 8},
1280
1281 {"cosf", "__svml_cosf4", 4},
1282 {"cosf", "__svml_cosf8", 8},
1283 {"cosf", "__svml_cosf16", 16},
1284
1285 {"pow", "__svml_pow2", 2},
1286 {"pow", "__svml_pow4", 4},
1287 {"pow", "__svml_pow8", 8},
1288
1289 {"powf", "__svml_powf4", 4},
1290 {"powf", "__svml_powf8", 8},
1291 {"powf", "__svml_powf16", 16},
1292
1293 {"llvm.pow.f64", "__svml_pow2", 2},
1294 {"llvm.pow.f64", "__svml_pow4", 4},
1295 {"llvm.pow.f64", "__svml_pow8", 8},
1296
1297 {"llvm.pow.f32", "__svml_powf4", 4},
1298 {"llvm.pow.f32", "__svml_powf8", 8},
1299 {"llvm.pow.f32", "__svml_powf16", 16},
1300
1301 {"exp", "__svml_exp2", 2},
1302 {"exp", "__svml_exp4", 4},
1303 {"exp", "__svml_exp8", 8},
1304
1305 {"expf", "__svml_expf4", 4},
1306 {"expf", "__svml_expf8", 8},
1307 {"expf", "__svml_expf16", 16},
1308
1309 {"llvm.exp.f64", "__svml_exp2", 2},
1310 {"llvm.exp.f64", "__svml_exp4", 4},
1311 {"llvm.exp.f64", "__svml_exp8", 8},
1312
1313 {"llvm.exp.f32", "__svml_expf4", 4},
1314 {"llvm.exp.f32", "__svml_expf8", 8},
1315 {"llvm.exp.f32", "__svml_expf16", 16},
1316
1317 {"log", "__svml_log2", 2},
1318 {"log", "__svml_log4", 4},
1319 {"log", "__svml_log8", 8},
1320
1321 {"logf", "__svml_logf4", 4},
1322 {"logf", "__svml_logf8", 8},
1323 {"logf", "__svml_logf16", 16},
1324
1325 {"llvm.log.f64", "__svml_log2", 2},
1326 {"llvm.log.f64", "__svml_log4", 4},
1327 {"llvm.log.f64", "__svml_log8", 8},
1328
1329 {"llvm.log.f32", "__svml_logf4", 4},
1330 {"llvm.log.f32", "__svml_logf8", 8},
1331 {"llvm.log.f32", "__svml_logf16", 16},
1332 };
1333 addVectorizableFunctions(VecFuncs);
1334 break;
1335 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001336 case NoLibrary:
1337 break;
1338 }
1339}
1340
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001341bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1342 funcName = sanitizeFunctionName(funcName);
1343 if (funcName.empty())
1344 return false;
1345
1346 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1347 VectorDescs.begin(), VectorDescs.end(), funcName,
1348 compareWithScalarFnName);
1349 return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1350}
1351
1352StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1353 unsigned VF) const {
1354 F = sanitizeFunctionName(F);
1355 if (F.empty())
1356 return F;
1357 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1358 VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1359 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1360 if (I->VectorizationFactor == VF)
1361 return I->VectorFnName;
1362 ++I;
1363 }
1364 return StringRef();
1365}
1366
1367StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1368 unsigned &VF) const {
1369 F = sanitizeFunctionName(F);
1370 if (F.empty())
1371 return F;
1372
1373 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1374 ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1375 if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1376 return StringRef();
1377 VF = I->VectorizationFactor;
1378 return I->ScalarFnName;
1379}
1380
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001381TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
1382 ModuleAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001383 if (PresetInfoImpl)
1384 return TargetLibraryInfo(*PresetInfoImpl);
1385
1386 return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1387}
1388
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001389TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
1390 FunctionAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001391 if (PresetInfoImpl)
1392 return TargetLibraryInfo(*PresetInfoImpl);
1393
1394 return TargetLibraryInfo(
1395 lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1396}
1397
Benjamin Kramerc321e532016-06-08 19:09:22 +00001398TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001399 std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1400 Impls[T.normalize()];
1401 if (!Impl)
1402 Impl.reset(new TargetLibraryInfoImpl(T));
1403
1404 return *Impl;
1405}
1406
1407
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001408TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
Chandler Carruthc0291862015-01-24 02:06:09 +00001409 : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001410 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1411}
1412
1413TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
Chandler Carruthc0291862015-01-24 02:06:09 +00001414 : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001415 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1416}
1417
1418TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
Chandler Carruthc0291862015-01-24 02:06:09 +00001419 const TargetLibraryInfoImpl &TLIImpl)
1420 : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001421 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1422}
1423
Chandler Carruthdab4eae2016-11-23 17:53:26 +00001424AnalysisKey TargetLibraryAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +00001425
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001426// Register the basic pass.
1427INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1428 "Target Library Information", false, true)
1429char TargetLibraryInfoWrapperPass::ID = 0;
1430
1431void TargetLibraryInfoWrapperPass::anchor() {}