blob: aea29e6359dea3fdc5f56b6f87a916d82c4d74d9 [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) {
85 TLI.setUnavailable(LibFunc::ldexp);
86 TLI.setUnavailable(LibFunc::ldexpf);
87 TLI.setUnavailable(LibFunc::ldexpl);
Nicolai Haehnle377975f2016-06-14 13:14:53 +000088 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) {
Tom Stellard36a03182014-04-02 19:53:29 +0000100 TLI.setUnavailable(LibFunc::memcpy);
101 TLI.setUnavailable(LibFunc::memset);
102 TLI.setUnavailable(LibFunc::memset_pattern16);
103 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))
Daniel Dunbar9483bb62011-04-19 20:44:08 +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))
113 TLI.setUnavailable(LibFunc::memset_pattern16);
Tim Northover8b403662015-10-28 22:51:16 +0000114 } else if (!T.isWatchOS()) {
Chris Lattner0e125bb2011-02-18 21:50:34 +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)) {
119 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);
Tim Northover103e6482014-02-04 16:28:20 +0000124 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.
134 TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
135 TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
136 }
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) {
Richard Osborne815de532011-03-03 13:17:51 +0000140 TLI.setUnavailable(LibFunc::iprintf);
Richard Osborne2dfb8882011-03-03 14:09:28 +0000141 TLI.setUnavailable(LibFunc::siprintf);
Richard Osborneaf52c522011-03-03 14:20:22 +0000142 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
147 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);
Yi Jiang6ab044e2013-12-16 22:42:40 +0000159 TLI.setUnavailable(LibFunc::fmaxl);
160 TLI.setUnavailable(LibFunc::fminl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000161 TLI.setUnavailable(LibFunc::fmodl);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000162 TLI.setUnavailable(LibFunc::frexpl);
Benjamin Kramer34f460e2014-02-04 20:27:23 +0000163 TLI.setUnavailable(LibFunc::ldexpf);
164 TLI.setUnavailable(LibFunc::ldexpl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000165 TLI.setUnavailable(LibFunc::logl);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000166 TLI.setUnavailable(LibFunc::modfl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000167 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);
173
174 // Win32 only has C89 math
Chad Rosier7fb0cd22012-08-21 23:28:56 +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);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000187 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);
Chad Rosier7fb0cd22012-08-21 23:28:56 +0000199 TLI.setUnavailable(LibFunc::logb);
200 TLI.setUnavailable(LibFunc::logbf);
201 TLI.setUnavailable(LibFunc::logbl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000202 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);
214
215 // Win32 provides some C99 math with mangled names
216 TLI.setAvailableWithName(LibFunc::copysign, "_copysign");
217
218 if (T.getArch() == Triple::x86) {
219 // Win32 on x86 implements single-precision math functions as macros
220 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);
Yi Jiang6ab044e2013-12-16 22:42:40 +0000230 TLI.setUnavailable(LibFunc::fminf);
231 TLI.setUnavailable(LibFunc::fmaxf);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000232 TLI.setUnavailable(LibFunc::fmodf);
233 TLI.setUnavailable(LibFunc::logf);
David Majnemereac58d82016-05-08 08:15:50 +0000234 TLI.setUnavailable(LibFunc::log10f);
235 TLI.setUnavailable(LibFunc::modff);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000236 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);
242 }
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:
246 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);
Meador Inge780a1862012-11-22 15:36:42 +0000255 TLI.setUnavailable(LibFunc::ffs);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000256 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);
Michael Gottesmanf7459c72013-07-03 04:00:51 +0000268 TLI.setUnavailable(LibFunc::gettimeofday);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000269 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:
304 TLI.setUnavailable(LibFunc::atoll);
305 TLI.setUnavailable(LibFunc::frexpf);
Meador Inge780a1862012-11-22 15:36:42 +0000306 TLI.setUnavailable(LibFunc::llabs);
307 }
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.
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000314 TLI.setUnavailable(LibFunc::exp10l);
315 if (T.isMacOSXVersionLT(10, 9)) {
316 TLI.setUnavailable(LibFunc::exp10);
317 TLI.setUnavailable(LibFunc::exp10f);
318 } else {
319 TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
320 TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
321 }
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:
Reid Klecknerf4355ee2013-12-26 19:17:04 +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)))) {
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000331 TLI.setUnavailable(LibFunc::exp10);
332 TLI.setUnavailable(LibFunc::exp10f);
333 } else {
334 TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
335 TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
336 }
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:
347 TLI.setUnavailable(LibFunc::exp10);
348 TLI.setUnavailable(LibFunc::exp10f);
349 TLI.setUnavailable(LibFunc::exp10l);
350 }
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:
367 TLI.setUnavailable(LibFunc::ffsl);
368 }
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:
383 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()) {
391 TLI.setUnavailable(LibFunc::fls);
392 TLI.setUnavailable(LibFunc::flsl);
393 TLI.setUnavailable(LibFunc::flsll);
394 }
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()) {
Meador Ingeb904e6e2013-03-05 21:47:40 +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);
415 }
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 Majnemerae272d72016-03-31 21:29:57 +0000430 TLI.setAvailable(LibFunc::nvvm_reflect);
431 } else {
432 TLI.setUnavailable(LibFunc::nvvm_reflect);
433 }
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,
Ahmed Bougacha220c4012016-04-27 19:04:29 +0000503 LibFunc::Func &F) const {
Mehdi Amini9a72cd72016-10-01 03:10:48 +0000504 StringRef const *Start = &StandardNames[0];
505 StringRef const *End = &StandardNames[LibFunc::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) {
516 F = (LibFunc::Func)(I - Start);
517 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,
523 LibFunc::Func F,
524 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) {
534 case LibFunc::strlen:
535 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
536 FTy.getReturnType()->isIntegerTy());
537
538 case LibFunc::strchr:
539 case LibFunc::strrchr:
540 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
541 FTy.getParamType(0) == FTy.getReturnType() &&
542 FTy.getParamType(1)->isIntegerTy());
543
544 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:
551 return ((NumParams == 2 || NumParams == 3) &&
552 FTy.getParamType(0)->isPointerTy() &&
553 FTy.getParamType(1)->isPointerTy());
554 case LibFunc::strcat:
555 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
556 FTy.getParamType(0) == FTy.getReturnType() &&
557 FTy.getParamType(1) == FTy.getReturnType());
558
559 case LibFunc::strncat:
560 return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
561 FTy.getParamType(0) == FTy.getReturnType() &&
562 FTy.getParamType(1) == FTy.getReturnType() &&
563 FTy.getParamType(2)->isIntegerTy());
564
565 case LibFunc::strcpy_chk:
566 case LibFunc::stpcpy_chk:
567 --NumParams;
568 if (!IsSizeTTy(FTy.getParamType(NumParams)))
569 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000570 LLVM_FALLTHROUGH;
Ahmed Bougachad765a822016-04-27 19:04:35 +0000571 case LibFunc::strcpy:
572 case LibFunc::stpcpy:
573 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
574 FTy.getParamType(0) == FTy.getParamType(1) &&
575 FTy.getParamType(0) == PCharTy);
576
577 case LibFunc::strncpy_chk:
578 case LibFunc::stpncpy_chk:
579 --NumParams;
580 if (!IsSizeTTy(FTy.getParamType(NumParams)))
581 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000582 LLVM_FALLTHROUGH;
Ahmed Bougachad765a822016-04-27 19:04:35 +0000583 case LibFunc::strncpy:
584 case LibFunc::stpncpy:
585 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
590 case LibFunc::strxfrm:
591 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
592 FTy.getParamType(1)->isPointerTy());
593
594 case LibFunc::strcmp:
595 return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
596 FTy.getParamType(0)->isPointerTy() &&
597 FTy.getParamType(0) == FTy.getParamType(1));
598
599 case LibFunc::strncmp:
600 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
605 case LibFunc::strspn:
606 case LibFunc::strcspn:
607 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
608 FTy.getParamType(0) == FTy.getParamType(1) &&
609 FTy.getReturnType()->isIntegerTy());
610
611 case LibFunc::strcoll:
612 case LibFunc::strcasecmp:
613 case LibFunc::strncasecmp:
614 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
615 FTy.getParamType(1)->isPointerTy());
616
617 case LibFunc::strstr:
618 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
619 FTy.getParamType(0)->isPointerTy() &&
620 FTy.getParamType(1)->isPointerTy());
621
622 case LibFunc::strpbrk:
623 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
624 FTy.getReturnType() == FTy.getParamType(0) &&
625 FTy.getParamType(0) == FTy.getParamType(1));
626
627 case LibFunc::strtok:
628 case LibFunc::strtok_r:
629 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
630 case LibFunc::scanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000631 case LibFunc::setbuf:
632 case LibFunc::setvbuf:
633 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
634 case LibFunc::strdup:
635 case LibFunc::strndup:
636 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
637 FTy.getParamType(0)->isPointerTy());
Davide Italiano9cc0bca2016-06-21 04:32:21 +0000638 case LibFunc::sscanf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000639 case LibFunc::stat:
640 case LibFunc::statvfs:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000641 case LibFunc::siprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000642 case LibFunc::sprintf:
643 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
644 FTy.getParamType(1)->isPointerTy());
645 case LibFunc::snprintf:
646 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
647 FTy.getParamType(2)->isPointerTy());
648 case LibFunc::setitimer:
649 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
650 FTy.getParamType(2)->isPointerTy());
651 case LibFunc::system:
652 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
653 case LibFunc::malloc:
654 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
655 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
660 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)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000666 case LibFunc::modf:
667 case LibFunc::modff:
668 case LibFunc::modfl:
669 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
670
671 case LibFunc::memcpy_chk:
672 case LibFunc::memmove_chk:
673 --NumParams;
674 if (!IsSizeTTy(FTy.getParamType(NumParams)))
675 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000676 LLVM_FALLTHROUGH;
Ahmed Bougachad765a822016-04-27 19:04:35 +0000677 case LibFunc::memcpy:
Andrew Kaylorb99d1cc2016-07-29 18:23:18 +0000678 case LibFunc::mempcpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000679 case LibFunc::memmove:
680 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
681 FTy.getParamType(0)->isPointerTy() &&
682 FTy.getParamType(1)->isPointerTy() &&
683 IsSizeTTy(FTy.getParamType(2)));
684
685 case LibFunc::memset_chk:
686 --NumParams;
687 if (!IsSizeTTy(FTy.getParamType(NumParams)))
688 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000689 LLVM_FALLTHROUGH;
Ahmed Bougachad765a822016-04-27 19:04:35 +0000690 case LibFunc::memset:
691 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
692 FTy.getParamType(0)->isPointerTy() &&
693 FTy.getParamType(1)->isIntegerTy() &&
694 IsSizeTTy(FTy.getParamType(2)));
695
696 case LibFunc::memccpy:
697 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
698 case LibFunc::memalign:
699 return (FTy.getReturnType()->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000700 case LibFunc::realloc:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000701 case LibFunc::reallocf:
702 return (NumParams == 2 && FTy.getReturnType() == PCharTy &&
703 FTy.getParamType(0) == FTy.getReturnType() &&
704 IsSizeTTy(FTy.getParamType(1)));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000705 case LibFunc::read:
706 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
707 case LibFunc::rewind:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000708 case LibFunc::rmdir:
709 case LibFunc::remove:
710 case LibFunc::realpath:
711 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
712 case LibFunc::rename:
713 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
714 FTy.getParamType(1)->isPointerTy());
715 case LibFunc::readlink:
716 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
717 FTy.getParamType(1)->isPointerTy());
718 case LibFunc::write:
719 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
720 case LibFunc::bcopy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000721 case LibFunc::bcmp:
722 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
723 FTy.getParamType(1)->isPointerTy());
724 case LibFunc::bzero:
725 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
726 case LibFunc::calloc:
727 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000728
729 case LibFunc::atof:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000730 case LibFunc::atoi:
731 case LibFunc::atol:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000732 case LibFunc::atoll:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000733 case LibFunc::ferror:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000734 case LibFunc::getenv:
735 case LibFunc::getpwnam:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000736 case LibFunc::iprintf:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000737 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
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000747 case LibFunc::access:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000748 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:
Ahmed Bougacha201b97f2016-05-25 21:16:33 +0000761 case LibFunc::fseeko64:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000762 case LibFunc::fseeko:
763 case LibFunc::fsetpos:
764 case LibFunc::ftell:
Ahmed Bougacha201b97f2016-05-25 21:16:33 +0000765 case LibFunc::ftello64:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000766 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:
775 return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
776
Ahmed Bougachad765a822016-04-27 19:04:35 +0000777 case LibFunc::fopen:
778 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
779 FTy.getParamType(0)->isPointerTy() &&
780 FTy.getParamType(1)->isPointerTy());
781 case LibFunc::fdopen:
782 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
783 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000784 case LibFunc::fputc:
785 case LibFunc::fstat:
786 case LibFunc::frexp:
787 case LibFunc::frexpf:
788 case LibFunc::frexpl:
789 case LibFunc::fstatvfs:
790 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
791 case LibFunc::fgets:
792 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
793 FTy.getParamType(2)->isPointerTy());
794 case LibFunc::fread:
795 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
796 FTy.getParamType(3)->isPointerTy());
797 case LibFunc::fwrite:
798 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());
803 case LibFunc::fputs:
804 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
805 FTy.getParamType(1)->isPointerTy());
806 case LibFunc::fscanf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000807 case LibFunc::fiprintf:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000808 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());
812 case LibFunc::fgetpos:
813 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
814 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000815 case LibFunc::getchar:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000816 return (NumParams == 0 && FTy.getReturnType()->isIntegerTy());
817 case LibFunc::gets:
818 return (NumParams == 1 && FTy.getParamType(0) == PCharTy);
Ahmed Bougachad765a822016-04-27 19:04:35 +0000819 case LibFunc::getitimer:
820 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000821 case LibFunc::ungetc:
822 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000823 case LibFunc::utime:
824 case LibFunc::utimes:
825 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
826 FTy.getParamType(1)->isPointerTy());
827 case LibFunc::putc:
828 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000829 case LibFunc::pread:
830 case LibFunc::pwrite:
831 return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000832 case LibFunc::popen:
833 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
834 FTy.getParamType(0)->isPointerTy() &&
835 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000836 case LibFunc::vscanf:
837 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
838 case LibFunc::vsscanf:
839 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
840 FTy.getParamType(2)->isPointerTy());
841 case LibFunc::vfscanf:
842 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
843 FTy.getParamType(2)->isPointerTy());
844 case LibFunc::valloc:
845 return (FTy.getReturnType()->isPointerTy());
846 case LibFunc::vprintf:
847 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
848 case LibFunc::vfprintf:
849 case LibFunc::vsprintf:
850 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
851 FTy.getParamType(1)->isPointerTy());
852 case LibFunc::vsnprintf:
853 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
854 FTy.getParamType(2)->isPointerTy());
855 case LibFunc::open:
856 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
857 case LibFunc::opendir:
858 return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
859 FTy.getParamType(0)->isPointerTy());
860 case LibFunc::tmpfile:
861 return (FTy.getReturnType()->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000862 case LibFunc::htonl:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000863 case LibFunc::ntohl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000864 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
865 FTy.getReturnType() == FTy.getParamType(0));
866 case LibFunc::htons:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000867 case LibFunc::ntohs:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000868 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(16) &&
869 FTy.getReturnType() == FTy.getParamType(0));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000870 case LibFunc::lstat:
871 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
872 FTy.getParamType(1)->isPointerTy());
873 case LibFunc::lchown:
874 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
875 case LibFunc::qsort:
876 return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
877 case LibFunc::dunder_strdup:
878 case LibFunc::dunder_strndup:
879 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
880 FTy.getParamType(0)->isPointerTy());
881 case LibFunc::dunder_strtok_r:
882 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000883 case LibFunc::under_IO_putc:
884 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
885 case LibFunc::dunder_isoc99_scanf:
886 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
887 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());
892 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());
895 case LibFunc::fopen64:
896 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
897 FTy.getParamType(0)->isPointerTy() &&
898 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000899 case LibFunc::tmpfile64:
900 return (FTy.getReturnType()->isPointerTy());
901 case LibFunc::fstat64:
902 case LibFunc::fstatvfs64:
903 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
904 case LibFunc::open64:
905 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
906 case LibFunc::gettimeofday:
907 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
908 FTy.getParamType(1)->isPointerTy());
909
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000910 // new(unsigned int);
911 case LibFunc::Znwj:
912 // new(unsigned long);
913 case LibFunc::Znwm:
914 // new[](unsigned int);
915 case LibFunc::Znaj:
916 // new[](unsigned long);
917 case LibFunc::Znam:
918 // new(unsigned int);
919 case LibFunc::msvc_new_int:
920 // new(unsigned long long);
921 case LibFunc::msvc_new_longlong:
922 // new[](unsigned int);
923 case LibFunc::msvc_new_array_int:
924 // new[](unsigned long long);
925 case LibFunc::msvc_new_array_longlong:
926 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
927
928 // new(unsigned int, nothrow);
929 case LibFunc::ZnwjRKSt9nothrow_t:
930 // new(unsigned long, nothrow);
931 case LibFunc::ZnwmRKSt9nothrow_t:
932 // new[](unsigned int, nothrow);
933 case LibFunc::ZnajRKSt9nothrow_t:
934 // new[](unsigned long, nothrow);
935 case LibFunc::ZnamRKSt9nothrow_t:
936 // new(unsigned int, nothrow);
937 case LibFunc::msvc_new_int_nothrow:
938 // new(unsigned long long, nothrow);
939 case LibFunc::msvc_new_longlong_nothrow:
940 // new[](unsigned int, nothrow);
941 case LibFunc::msvc_new_array_int_nothrow:
942 // new[](unsigned long long, nothrow);
943 case LibFunc::msvc_new_array_longlong_nothrow:
944 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
945
946 // void operator delete[](void*);
947 case LibFunc::ZdaPv:
948 // void operator delete(void*);
949 case LibFunc::ZdlPv:
950 // void operator delete[](void*);
951 case LibFunc::msvc_delete_array_ptr32:
952 // void operator delete[](void*);
953 case LibFunc::msvc_delete_array_ptr64:
954 // void operator delete(void*);
955 case LibFunc::msvc_delete_ptr32:
956 // void operator delete(void*);
957 case LibFunc::msvc_delete_ptr64:
958 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
959
960 // void operator delete[](void*, nothrow);
961 case LibFunc::ZdaPvRKSt9nothrow_t:
962 // void operator delete[](void*, unsigned int);
963 case LibFunc::ZdaPvj:
964 // void operator delete[](void*, unsigned long);
965 case LibFunc::ZdaPvm:
966 // void operator delete(void*, nothrow);
967 case LibFunc::ZdlPvRKSt9nothrow_t:
968 // void operator delete(void*, unsigned int);
969 case LibFunc::ZdlPvj:
970 // void operator delete(void*, unsigned long);
971 case LibFunc::ZdlPvm:
972 // void operator delete[](void*, unsigned int);
973 case LibFunc::msvc_delete_array_ptr32_int:
974 // void operator delete[](void*, nothrow);
975 case LibFunc::msvc_delete_array_ptr32_nothrow:
976 // void operator delete[](void*, unsigned long long);
977 case LibFunc::msvc_delete_array_ptr64_longlong:
978 // void operator delete[](void*, nothrow);
979 case LibFunc::msvc_delete_array_ptr64_nothrow:
980 // void operator delete(void*, unsigned int);
981 case LibFunc::msvc_delete_ptr32_int:
982 // void operator delete(void*, nothrow);
983 case LibFunc::msvc_delete_ptr32_nothrow:
984 // void operator delete(void*, unsigned long long);
985 case LibFunc::msvc_delete_ptr64_longlong:
986 // void operator delete(void*, nothrow);
987 case LibFunc::msvc_delete_ptr64_nothrow:
988 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000989
990 case LibFunc::memset_pattern16:
991 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
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +0000996 case LibFunc::cxa_guard_abort:
997 case LibFunc::cxa_guard_acquire:
998 case LibFunc::cxa_guard_release:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000999 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
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001002 case LibFunc::sincospi_stret:
1003 case LibFunc::sincospif_stret:
1004 return (NumParams == 1 && FTy.getParamType(0)->isFloatingPointTy());
1005
1006 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:
Ahmed Bougachaa65de7e2017-01-17 03:10:00 +00001027 case LibFunc::ceil:
1028 case LibFunc::ceilf:
1029 case LibFunc::ceill:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001030 case LibFunc::cos:
1031 case LibFunc::cosf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001032 case LibFunc::cosh:
1033 case LibFunc::coshf:
1034 case LibFunc::coshl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001035 case LibFunc::cosl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001036 case LibFunc::exp10:
1037 case LibFunc::exp10f:
1038 case LibFunc::exp10l:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001039 case LibFunc::exp2:
1040 case LibFunc::exp2f:
1041 case LibFunc::exp2l:
Ahmed Bougachaa65de7e2017-01-17 03:10:00 +00001042 case LibFunc::exp:
1043 case LibFunc::expf:
1044 case LibFunc::expl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001045 case LibFunc::expm1:
1046 case LibFunc::expm1f:
1047 case LibFunc::expm1l:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001048 case LibFunc::fabs:
1049 case LibFunc::fabsf:
1050 case LibFunc::fabsl:
1051 case LibFunc::floor:
1052 case LibFunc::floorf:
1053 case LibFunc::floorl:
Ahmed Bougachaa65de7e2017-01-17 03:10:00 +00001054 case LibFunc::log10:
1055 case LibFunc::log10f:
1056 case LibFunc::log10l:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001057 case LibFunc::log1p:
1058 case LibFunc::log1pf:
1059 case LibFunc::log1pl:
Ahmed Bougachaa65de7e2017-01-17 03:10:00 +00001060 case LibFunc::log2:
1061 case LibFunc::log2f:
1062 case LibFunc::log2l:
1063 case LibFunc::log:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001064 case LibFunc::logb:
1065 case LibFunc::logbf:
1066 case LibFunc::logbl:
Ahmed Bougachaa65de7e2017-01-17 03:10:00 +00001067 case LibFunc::logf:
1068 case LibFunc::logl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001069 case LibFunc::nearbyint:
1070 case LibFunc::nearbyintf:
1071 case LibFunc::nearbyintl:
Ahmed Bougachaa65de7e2017-01-17 03:10:00 +00001072 case LibFunc::rint:
1073 case LibFunc::rintf:
1074 case LibFunc::rintl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001075 case LibFunc::round:
1076 case LibFunc::roundf:
1077 case LibFunc::roundl:
Ahmed Bougachaa65de7e2017-01-17 03:10:00 +00001078 case LibFunc::sin:
1079 case LibFunc::sinf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001080 case LibFunc::sinh:
1081 case LibFunc::sinhf:
1082 case LibFunc::sinhl:
Ahmed Bougachaa65de7e2017-01-17 03:10:00 +00001083 case LibFunc::sinl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001084 case LibFunc::sqrt:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001085 case LibFunc::sqrt_finite:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001086 case LibFunc::sqrtf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001087 case LibFunc::sqrtf_finite:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001088 case LibFunc::sqrtl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001089 case LibFunc::sqrtl_finite:
Ahmed Bougachaa65de7e2017-01-17 03:10:00 +00001090 case LibFunc::tan:
1091 case LibFunc::tanf:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001092 case LibFunc::tanh:
1093 case LibFunc::tanhf:
1094 case LibFunc::tanhl:
Ahmed Bougachaa65de7e2017-01-17 03:10:00 +00001095 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
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001102 case LibFunc::atan2:
1103 case LibFunc::atan2f:
1104 case LibFunc::atan2l:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001105 case LibFunc::fmin:
1106 case LibFunc::fminf:
1107 case LibFunc::fminl:
1108 case LibFunc::fmax:
1109 case LibFunc::fmaxf:
1110 case LibFunc::fmaxl:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001111 case LibFunc::fmod:
1112 case LibFunc::fmodf:
1113 case LibFunc::fmodl:
Ahmed Bougachad765a822016-04-27 19:04:35 +00001114 case LibFunc::copysign:
1115 case LibFunc::copysignf:
1116 case LibFunc::copysignl:
1117 case LibFunc::pow:
1118 case LibFunc::powf:
1119 case LibFunc::powl:
1120 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1121 FTy.getReturnType() == FTy.getParamType(0) &&
1122 FTy.getReturnType() == FTy.getParamType(1));
1123
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001124 case LibFunc::ldexp:
1125 case LibFunc::ldexpf:
1126 case LibFunc::ldexpl:
1127 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
1128 FTy.getReturnType() == FTy.getParamType(0) &&
1129 FTy.getParamType(1)->isIntegerTy(32));
1130
Ahmed Bougachad765a822016-04-27 19:04:35 +00001131 case LibFunc::ffs:
1132 case LibFunc::ffsl:
1133 case LibFunc::ffsll:
Davide Italiano85ad36b2016-12-15 23:45:11 +00001134 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
Ahmed Bougachad765a822016-04-27 19:04:35 +00001140 case LibFunc::isdigit:
1141 case LibFunc::isascii:
1142 case LibFunc::toascii:
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001143 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
Ahmed Bougachad765a822016-04-27 19:04:35 +00001147 case LibFunc::abs:
1148 case LibFunc::labs:
1149 case LibFunc::llabs:
1150 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1151 FTy.getReturnType() == FTy.getParamType(0));
1152
1153 case LibFunc::cxa_atexit:
1154 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1155 FTy.getParamType(0)->isPointerTy() &&
1156 FTy.getParamType(1)->isPointerTy() &&
1157 FTy.getParamType(2)->isPointerTy());
1158
1159 case LibFunc::sinpi:
1160 case LibFunc::cospi:
1161 return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1162 FTy.getReturnType() == FTy.getParamType(0));
1163
1164 case LibFunc::sinpif:
1165 case LibFunc::cospif:
1166 return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1167 FTy.getReturnType() == FTy.getParamType(0));
1168
Ahmed Bougacha6b9be1d2017-01-17 03:10:02 +00001169 case LibFunc::strnlen:
1170 return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(1) &&
1171 FTy.getParamType(0) == PCharTy &&
1172 FTy.getParamType(1) == SizeTTy);
1173
1174 case LibFunc::posix_memalign:
1175 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,
1187 LibFunc::Func &F) const {
1188 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() {}