blob: ae449f023a4b37f4a447e7101454743a5816d7b7 [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
Nicolai Hahnle78fd4f02015-12-15 17:24:15 +000064 if (T.getArch() == Triple::r600 ||
65 T.getArch() == Triple::amdgcn) {
66 TLI.setUnavailable(LibFunc::ldexp);
67 TLI.setUnavailable(LibFunc::ldexpf);
68 TLI.setUnavailable(LibFunc::ldexpl);
Nicolai Haehnle377975f2016-06-14 13:14:53 +000069 TLI.setUnavailable(LibFunc::exp10);
70 TLI.setUnavailable(LibFunc::exp10f);
71 TLI.setUnavailable(LibFunc::exp10l);
72 TLI.setUnavailable(LibFunc::log10);
73 TLI.setUnavailable(LibFunc::log10f);
74 TLI.setUnavailable(LibFunc::log10l);
Nicolai Hahnle78fd4f02015-12-15 17:24:15 +000075 }
76
Tom Stellardd00a9232015-01-07 01:17:37 +000077 // There are no library implementations of mempcy and memset for AMD gpus and
Tom Stellard36a03182014-04-02 19:53:29 +000078 // these can be difficult to lower in the backend.
Tom Stellardd00a9232015-01-07 01:17:37 +000079 if (T.getArch() == Triple::r600 ||
Dan Gohman05532992016-01-19 14:49:23 +000080 T.getArch() == Triple::amdgcn) {
Tom Stellard36a03182014-04-02 19:53:29 +000081 TLI.setUnavailable(LibFunc::memcpy);
82 TLI.setUnavailable(LibFunc::memset);
83 TLI.setUnavailable(LibFunc::memset_pattern16);
84 return;
85 }
86
Nico Weberad156922014-03-07 18:08:54 +000087 // memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
Tim Northover8b403662015-10-28 22:51:16 +000088 // All versions of watchOS support it.
Daniel Dunbarcd01ed52011-04-20 00:14:25 +000089 if (T.isMacOSX()) {
90 if (T.isMacOSXVersionLT(10, 5))
Daniel Dunbar9483bb62011-04-19 20:44:08 +000091 TLI.setUnavailable(LibFunc::memset_pattern16);
Cameron Esfahani943908b2013-08-29 20:23:14 +000092 } else if (T.isiOS()) {
Daniel Dunbar9483bb62011-04-19 20:44:08 +000093 if (T.isOSVersionLT(3, 0))
94 TLI.setUnavailable(LibFunc::memset_pattern16);
Tim Northover8b403662015-10-28 22:51:16 +000095 } else if (!T.isWatchOS()) {
Chris Lattner0e125bb2011-02-18 21:50:34 +000096 TLI.setUnavailable(LibFunc::memset_pattern16);
Daniel Dunbar9483bb62011-04-19 20:44:08 +000097 }
Richard Osborne815de532011-03-03 13:17:51 +000098
Bob Wilsond8d92d92013-11-03 06:48:38 +000099 if (!hasSinCosPiStret(T)) {
100 TLI.setUnavailable(LibFunc::sinpi);
101 TLI.setUnavailable(LibFunc::sinpif);
102 TLI.setUnavailable(LibFunc::cospi);
103 TLI.setUnavailable(LibFunc::cospif);
104 TLI.setUnavailable(LibFunc::sincospi_stret);
Tim Northover103e6482014-02-04 16:28:20 +0000105 TLI.setUnavailable(LibFunc::sincospif_stret);
Bob Wilsond8d92d92013-11-03 06:48:38 +0000106 }
107
Eli Friedman489c0ff2011-11-17 01:27:36 +0000108 if (T.isMacOSX() && T.getArch() == Triple::x86 &&
109 !T.isMacOSXVersionLT(10, 7)) {
110 // x86-32 OSX has a scheme where fwrite and fputs (and some other functions
111 // we don't care about) have two versions; on recent OSX, the one we want
112 // has a $UNIX2003 suffix. The two implementations are identical except
113 // for the return value in some edge cases. However, we don't want to
114 // generate code that depends on the old symbols.
115 TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
116 TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
117 }
118
Duncan Sandseeb50c82011-06-09 11:11:45 +0000119 // iprintf and friends are only available on XCore and TCE.
120 if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
Richard Osborne815de532011-03-03 13:17:51 +0000121 TLI.setUnavailable(LibFunc::iprintf);
Richard Osborne2dfb8882011-03-03 14:09:28 +0000122 TLI.setUnavailable(LibFunc::siprintf);
Richard Osborneaf52c522011-03-03 14:20:22 +0000123 TLI.setUnavailable(LibFunc::fiprintf);
Richard Osborne2dfb8882011-03-03 14:09:28 +0000124 }
Joe Groffa81bcbb2012-04-17 23:05:54 +0000125
Saleem Abdulrasool8dc8fb12014-07-24 22:09:06 +0000126 if (T.isOSWindows() && !T.isOSCygMing()) {
Joe Groffa81bcbb2012-04-17 23:05:54 +0000127 // Win32 does not support long double
128 TLI.setUnavailable(LibFunc::acosl);
129 TLI.setUnavailable(LibFunc::asinl);
130 TLI.setUnavailable(LibFunc::atanl);
131 TLI.setUnavailable(LibFunc::atan2l);
132 TLI.setUnavailable(LibFunc::ceill);
133 TLI.setUnavailable(LibFunc::copysignl);
134 TLI.setUnavailable(LibFunc::cosl);
135 TLI.setUnavailable(LibFunc::coshl);
136 TLI.setUnavailable(LibFunc::expl);
137 TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf
138 TLI.setUnavailable(LibFunc::fabsl);
139 TLI.setUnavailable(LibFunc::floorl);
Yi Jiang6ab044e2013-12-16 22:42:40 +0000140 TLI.setUnavailable(LibFunc::fmaxl);
141 TLI.setUnavailable(LibFunc::fminl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000142 TLI.setUnavailable(LibFunc::fmodl);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000143 TLI.setUnavailable(LibFunc::frexpl);
Benjamin Kramer34f460e2014-02-04 20:27:23 +0000144 TLI.setUnavailable(LibFunc::ldexpf);
145 TLI.setUnavailable(LibFunc::ldexpl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000146 TLI.setUnavailable(LibFunc::logl);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000147 TLI.setUnavailable(LibFunc::modfl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000148 TLI.setUnavailable(LibFunc::powl);
149 TLI.setUnavailable(LibFunc::sinl);
150 TLI.setUnavailable(LibFunc::sinhl);
151 TLI.setUnavailable(LibFunc::sqrtl);
152 TLI.setUnavailable(LibFunc::tanl);
153 TLI.setUnavailable(LibFunc::tanhl);
154
155 // Win32 only has C89 math
Chad Rosier7fb0cd22012-08-21 23:28:56 +0000156 TLI.setUnavailable(LibFunc::acosh);
157 TLI.setUnavailable(LibFunc::acoshf);
158 TLI.setUnavailable(LibFunc::acoshl);
159 TLI.setUnavailable(LibFunc::asinh);
160 TLI.setUnavailable(LibFunc::asinhf);
161 TLI.setUnavailable(LibFunc::asinhl);
162 TLI.setUnavailable(LibFunc::atanh);
163 TLI.setUnavailable(LibFunc::atanhf);
164 TLI.setUnavailable(LibFunc::atanhl);
165 TLI.setUnavailable(LibFunc::cbrt);
166 TLI.setUnavailable(LibFunc::cbrtf);
167 TLI.setUnavailable(LibFunc::cbrtl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000168 TLI.setUnavailable(LibFunc::exp2);
169 TLI.setUnavailable(LibFunc::exp2f);
170 TLI.setUnavailable(LibFunc::exp2l);
171 TLI.setUnavailable(LibFunc::expm1);
172 TLI.setUnavailable(LibFunc::expm1f);
173 TLI.setUnavailable(LibFunc::expm1l);
174 TLI.setUnavailable(LibFunc::log2);
175 TLI.setUnavailable(LibFunc::log2f);
176 TLI.setUnavailable(LibFunc::log2l);
177 TLI.setUnavailable(LibFunc::log1p);
178 TLI.setUnavailable(LibFunc::log1pf);
179 TLI.setUnavailable(LibFunc::log1pl);
Chad Rosier7fb0cd22012-08-21 23:28:56 +0000180 TLI.setUnavailable(LibFunc::logb);
181 TLI.setUnavailable(LibFunc::logbf);
182 TLI.setUnavailable(LibFunc::logbl);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000183 TLI.setUnavailable(LibFunc::nearbyint);
184 TLI.setUnavailable(LibFunc::nearbyintf);
185 TLI.setUnavailable(LibFunc::nearbyintl);
186 TLI.setUnavailable(LibFunc::rint);
187 TLI.setUnavailable(LibFunc::rintf);
188 TLI.setUnavailable(LibFunc::rintl);
189 TLI.setUnavailable(LibFunc::round);
190 TLI.setUnavailable(LibFunc::roundf);
191 TLI.setUnavailable(LibFunc::roundl);
192 TLI.setUnavailable(LibFunc::trunc);
193 TLI.setUnavailable(LibFunc::truncf);
194 TLI.setUnavailable(LibFunc::truncl);
195
196 // Win32 provides some C99 math with mangled names
197 TLI.setAvailableWithName(LibFunc::copysign, "_copysign");
198
199 if (T.getArch() == Triple::x86) {
200 // Win32 on x86 implements single-precision math functions as macros
201 TLI.setUnavailable(LibFunc::acosf);
202 TLI.setUnavailable(LibFunc::asinf);
203 TLI.setUnavailable(LibFunc::atanf);
204 TLI.setUnavailable(LibFunc::atan2f);
205 TLI.setUnavailable(LibFunc::ceilf);
206 TLI.setUnavailable(LibFunc::copysignf);
207 TLI.setUnavailable(LibFunc::cosf);
208 TLI.setUnavailable(LibFunc::coshf);
209 TLI.setUnavailable(LibFunc::expf);
210 TLI.setUnavailable(LibFunc::floorf);
Yi Jiang6ab044e2013-12-16 22:42:40 +0000211 TLI.setUnavailable(LibFunc::fminf);
212 TLI.setUnavailable(LibFunc::fmaxf);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000213 TLI.setUnavailable(LibFunc::fmodf);
214 TLI.setUnavailable(LibFunc::logf);
David Majnemereac58d82016-05-08 08:15:50 +0000215 TLI.setUnavailable(LibFunc::log10f);
216 TLI.setUnavailable(LibFunc::modff);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000217 TLI.setUnavailable(LibFunc::powf);
218 TLI.setUnavailable(LibFunc::sinf);
219 TLI.setUnavailable(LibFunc::sinhf);
220 TLI.setUnavailable(LibFunc::sqrtf);
221 TLI.setUnavailable(LibFunc::tanf);
222 TLI.setUnavailable(LibFunc::tanhf);
223 }
Meador Inge2526a422012-11-10 03:11:06 +0000224
Meador Ingeb904e6e2013-03-05 21:47:40 +0000225 // Win32 does *not* provide provide these functions, but they are
226 // generally available on POSIX-compliant systems:
227 TLI.setUnavailable(LibFunc::access);
228 TLI.setUnavailable(LibFunc::bcmp);
229 TLI.setUnavailable(LibFunc::bcopy);
230 TLI.setUnavailable(LibFunc::bzero);
231 TLI.setUnavailable(LibFunc::chmod);
232 TLI.setUnavailable(LibFunc::chown);
233 TLI.setUnavailable(LibFunc::closedir);
234 TLI.setUnavailable(LibFunc::ctermid);
235 TLI.setUnavailable(LibFunc::fdopen);
Meador Inge780a1862012-11-22 15:36:42 +0000236 TLI.setUnavailable(LibFunc::ffs);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000237 TLI.setUnavailable(LibFunc::fileno);
238 TLI.setUnavailable(LibFunc::flockfile);
239 TLI.setUnavailable(LibFunc::fseeko);
240 TLI.setUnavailable(LibFunc::fstat);
241 TLI.setUnavailable(LibFunc::fstatvfs);
242 TLI.setUnavailable(LibFunc::ftello);
243 TLI.setUnavailable(LibFunc::ftrylockfile);
244 TLI.setUnavailable(LibFunc::funlockfile);
245 TLI.setUnavailable(LibFunc::getc_unlocked);
246 TLI.setUnavailable(LibFunc::getitimer);
247 TLI.setUnavailable(LibFunc::getlogin_r);
248 TLI.setUnavailable(LibFunc::getpwnam);
Michael Gottesmanf7459c72013-07-03 04:00:51 +0000249 TLI.setUnavailable(LibFunc::gettimeofday);
Meador Ingeb904e6e2013-03-05 21:47:40 +0000250 TLI.setUnavailable(LibFunc::htonl);
251 TLI.setUnavailable(LibFunc::htons);
252 TLI.setUnavailable(LibFunc::lchown);
253 TLI.setUnavailable(LibFunc::lstat);
254 TLI.setUnavailable(LibFunc::memccpy);
255 TLI.setUnavailable(LibFunc::mkdir);
256 TLI.setUnavailable(LibFunc::ntohl);
257 TLI.setUnavailable(LibFunc::ntohs);
258 TLI.setUnavailable(LibFunc::open);
259 TLI.setUnavailable(LibFunc::opendir);
260 TLI.setUnavailable(LibFunc::pclose);
261 TLI.setUnavailable(LibFunc::popen);
262 TLI.setUnavailable(LibFunc::pread);
263 TLI.setUnavailable(LibFunc::pwrite);
264 TLI.setUnavailable(LibFunc::read);
265 TLI.setUnavailable(LibFunc::readlink);
266 TLI.setUnavailable(LibFunc::realpath);
267 TLI.setUnavailable(LibFunc::rmdir);
268 TLI.setUnavailable(LibFunc::setitimer);
269 TLI.setUnavailable(LibFunc::stat);
270 TLI.setUnavailable(LibFunc::statvfs);
271 TLI.setUnavailable(LibFunc::stpcpy);
272 TLI.setUnavailable(LibFunc::stpncpy);
273 TLI.setUnavailable(LibFunc::strcasecmp);
274 TLI.setUnavailable(LibFunc::strncasecmp);
275 TLI.setUnavailable(LibFunc::times);
276 TLI.setUnavailable(LibFunc::uname);
277 TLI.setUnavailable(LibFunc::unlink);
278 TLI.setUnavailable(LibFunc::unsetenv);
279 TLI.setUnavailable(LibFunc::utime);
280 TLI.setUnavailable(LibFunc::utimes);
281 TLI.setUnavailable(LibFunc::write);
Meador Inge780a1862012-11-22 15:36:42 +0000282
Meador Ingeb904e6e2013-03-05 21:47:40 +0000283 // Win32 does *not* provide provide these functions, but they are
284 // specified by C99:
285 TLI.setUnavailable(LibFunc::atoll);
286 TLI.setUnavailable(LibFunc::frexpf);
Meador Inge780a1862012-11-22 15:36:42 +0000287 TLI.setUnavailable(LibFunc::llabs);
288 }
289
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000290 switch (T.getOS()) {
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000291 case Triple::MacOSX:
Chandler Carruthf5689f82013-12-28 02:40:19 +0000292 // exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
293 // and their names are __exp10 and __exp10f. exp10l is not available on
294 // OS X or iOS.
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000295 TLI.setUnavailable(LibFunc::exp10l);
296 if (T.isMacOSXVersionLT(10, 9)) {
297 TLI.setUnavailable(LibFunc::exp10);
298 TLI.setUnavailable(LibFunc::exp10f);
299 } else {
300 TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
301 TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
302 }
303 break;
304 case Triple::IOS:
Tim Northover89a6eef2015-11-02 18:00:00 +0000305 case Triple::TvOS:
Tim Northover8b403662015-10-28 22:51:16 +0000306 case Triple::WatchOS:
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000307 TLI.setUnavailable(LibFunc::exp10l);
Tim Northover8b403662015-10-28 22:51:16 +0000308 if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
309 (T.isOSVersionLT(9, 0) &&
310 (T.getArch() == Triple::x86 ||
311 T.getArch() == Triple::x86_64)))) {
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000312 TLI.setUnavailable(LibFunc::exp10);
313 TLI.setUnavailable(LibFunc::exp10f);
314 } else {
315 TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
316 TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
317 }
318 break;
Chandler Carruthf5689f82013-12-28 02:40:19 +0000319 case Triple::Linux:
320 // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
321 // buggy prior to glibc version 2.18. Until this version is widely deployed
322 // or we have a reasonable detection strategy, we cannot use exp10 reliably
323 // on Linux.
324 //
325 // Fall through to disable all of them.
Justin Bognercd1d5aa2016-08-17 20:30:52 +0000326 LLVM_FALLTHROUGH;
Reid Klecknerf4355ee2013-12-26 19:17:04 +0000327 default:
328 TLI.setUnavailable(LibFunc::exp10);
329 TLI.setUnavailable(LibFunc::exp10f);
330 TLI.setUnavailable(LibFunc::exp10l);
331 }
332
Meador Inge780a1862012-11-22 15:36:42 +0000333 // ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
334 // Linux (GLIBC):
335 // http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
Davide Italiano83b34812015-11-01 17:00:13 +0000336 // http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
Meador Inge780a1862012-11-22 15:36:42 +0000337 // http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
338 switch (T.getOS()) {
339 case Triple::Darwin:
340 case Triple::MacOSX:
341 case Triple::IOS:
Tim Northover89a6eef2015-11-02 18:00:00 +0000342 case Triple::TvOS:
Tim Northover8b403662015-10-28 22:51:16 +0000343 case Triple::WatchOS:
Meador Inge780a1862012-11-22 15:36:42 +0000344 case Triple::FreeBSD:
345 case Triple::Linux:
346 break;
347 default:
348 TLI.setUnavailable(LibFunc::ffsl);
349 }
350
351 // ffsll is available on at least FreeBSD and Linux (GLIBC):
Davide Italiano83b34812015-11-01 17:00:13 +0000352 // http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
Meador Inge780a1862012-11-22 15:36:42 +0000353 // http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
354 switch (T.getOS()) {
Tim Northover89a6eef2015-11-02 18:00:00 +0000355 case Triple::Darwin:
356 case Triple::MacOSX:
357 case Triple::IOS:
358 case Triple::TvOS:
359 case Triple::WatchOS:
Meador Inge780a1862012-11-22 15:36:42 +0000360 case Triple::FreeBSD:
361 case Triple::Linux:
362 break;
363 default:
364 TLI.setUnavailable(LibFunc::ffsll);
Joe Groffa81bcbb2012-04-17 23:05:54 +0000365 }
Meador Ingeb904e6e2013-03-05 21:47:40 +0000366
Davide Italianobfd30822015-11-09 23:23:20 +0000367 // The following functions are available on at least FreeBSD:
368 // http://svn.freebsd.org/base/head/lib/libc/string/fls.c
369 // http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
370 // http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
371 if (!T.isOSFreeBSD()) {
372 TLI.setUnavailable(LibFunc::fls);
373 TLI.setUnavailable(LibFunc::flsl);
374 TLI.setUnavailable(LibFunc::flsll);
375 }
376
Meador Ingeb904e6e2013-03-05 21:47:40 +0000377 // The following functions are available on at least Linux:
Cameron Esfahani943908b2013-08-29 20:23:14 +0000378 if (!T.isOSLinux()) {
Meador Ingeb904e6e2013-03-05 21:47:40 +0000379 TLI.setUnavailable(LibFunc::dunder_strdup);
380 TLI.setUnavailable(LibFunc::dunder_strtok_r);
381 TLI.setUnavailable(LibFunc::dunder_isoc99_scanf);
382 TLI.setUnavailable(LibFunc::dunder_isoc99_sscanf);
383 TLI.setUnavailable(LibFunc::under_IO_getc);
384 TLI.setUnavailable(LibFunc::under_IO_putc);
385 TLI.setUnavailable(LibFunc::memalign);
386 TLI.setUnavailable(LibFunc::fopen64);
387 TLI.setUnavailable(LibFunc::fseeko64);
388 TLI.setUnavailable(LibFunc::fstat64);
389 TLI.setUnavailable(LibFunc::fstatvfs64);
390 TLI.setUnavailable(LibFunc::ftello64);
391 TLI.setUnavailable(LibFunc::lstat64);
392 TLI.setUnavailable(LibFunc::open64);
393 TLI.setUnavailable(LibFunc::stat64);
394 TLI.setUnavailable(LibFunc::statvfs64);
395 TLI.setUnavailable(LibFunc::tmpfile64);
396 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000397
Justin Lebar51132882016-01-26 23:51:06 +0000398 // As currently implemented in clang, NVPTX code has no standard library to
399 // speak of. Headers provide a standard-ish library implementation, but many
400 // of the signatures are wrong -- for example, many libm functions are not
401 // extern "C".
402 //
403 // libdevice, an IR library provided by nvidia, is linked in by the front-end,
404 // but only used functions are provided to llvm. Moreover, most of the
405 // functions in libdevice don't map precisely to standard library functions.
406 //
407 // FIXME: Having no standard library prevents e.g. many fastmath
408 // optimizations, so this situation should be fixed.
David Majnemerae272d72016-03-31 21:29:57 +0000409 if (T.isNVPTX()) {
Justin Lebar51132882016-01-26 23:51:06 +0000410 TLI.disableAllFunctions();
David Majnemerae272d72016-03-31 21:29:57 +0000411 TLI.setAvailable(LibFunc::nvvm_reflect);
412 } else {
413 TLI.setUnavailable(LibFunc::nvvm_reflect);
414 }
Justin Lebar51132882016-01-26 23:51:06 +0000415
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +0000416 TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
Marcin Koscielnicki5ae2c522016-11-21 11:57:11 +0000417
418 bool ShouldExtI32Param = false, ShouldExtI32Return = false,
419 ShouldSignExtI32Param = false;
420 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
421 // returns corresponding to C-level ints and unsigned ints.
422 if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le ||
423 T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) {
424 ShouldExtI32Param = true;
425 ShouldExtI32Return = true;
426 }
427 // Mips, on the other hand, needs signext on i32 parameters corresponding
428 // to both signed and unsigned ints.
429 if (T.getArch() == Triple::mips || T.getArch() == Triple::mipsel ||
430 T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el) {
431 ShouldSignExtI32Param = true;
432 }
433 TLI.setShouldExtI32Param(ShouldExtI32Param);
434 TLI.setShouldExtI32Return(ShouldExtI32Return);
435 TLI.setShouldSignExtI32Param(ShouldSignExtI32Param);
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 Bougachad765a822016-04-27 19:04:35 +0000641 case LibFunc::sprintf:
642 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
643 FTy.getParamType(1)->isPointerTy());
644 case LibFunc::snprintf:
645 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
646 FTy.getParamType(2)->isPointerTy());
647 case LibFunc::setitimer:
648 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
649 FTy.getParamType(2)->isPointerTy());
650 case LibFunc::system:
651 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
652 case LibFunc::malloc:
653 return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
654 case LibFunc::memcmp:
655 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
656 FTy.getParamType(1)->isPointerTy() &&
657 FTy.getReturnType()->isIntegerTy(32));
658
659 case LibFunc::memchr:
660 case LibFunc::memrchr:
661 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
662 FTy.getParamType(1)->isIntegerTy(32) &&
663 FTy.getParamType(2)->isIntegerTy() &&
664 FTy.getReturnType()->isPointerTy());
665 case LibFunc::modf:
666 case LibFunc::modff:
667 case LibFunc::modfl:
668 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
669
670 case LibFunc::memcpy_chk:
671 case LibFunc::memmove_chk:
672 --NumParams;
673 if (!IsSizeTTy(FTy.getParamType(NumParams)))
674 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000675 LLVM_FALLTHROUGH;
Ahmed Bougachad765a822016-04-27 19:04:35 +0000676 case LibFunc::memcpy:
Andrew Kaylorb99d1cc2016-07-29 18:23:18 +0000677 case LibFunc::mempcpy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000678 case LibFunc::memmove:
679 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
680 FTy.getParamType(0)->isPointerTy() &&
681 FTy.getParamType(1)->isPointerTy() &&
682 IsSizeTTy(FTy.getParamType(2)));
683
684 case LibFunc::memset_chk:
685 --NumParams;
686 if (!IsSizeTTy(FTy.getParamType(NumParams)))
687 return false;
Justin Bognerb03fd122016-08-17 05:10:15 +0000688 LLVM_FALLTHROUGH;
Ahmed Bougachad765a822016-04-27 19:04:35 +0000689 case LibFunc::memset:
690 return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
691 FTy.getParamType(0)->isPointerTy() &&
692 FTy.getParamType(1)->isIntegerTy() &&
693 IsSizeTTy(FTy.getParamType(2)));
694
695 case LibFunc::memccpy:
696 return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
697 case LibFunc::memalign:
698 return (FTy.getReturnType()->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000699 case LibFunc::realloc:
700 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
701 FTy.getReturnType()->isPointerTy());
702 case LibFunc::read:
703 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
704 case LibFunc::rewind:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000705 case LibFunc::rmdir:
706 case LibFunc::remove:
707 case LibFunc::realpath:
708 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
709 case LibFunc::rename:
710 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
711 FTy.getParamType(1)->isPointerTy());
712 case LibFunc::readlink:
713 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
714 FTy.getParamType(1)->isPointerTy());
715 case LibFunc::write:
716 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
717 case LibFunc::bcopy:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000718 case LibFunc::bcmp:
719 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
720 FTy.getParamType(1)->isPointerTy());
721 case LibFunc::bzero:
722 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
723 case LibFunc::calloc:
724 return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000725
726 case LibFunc::atof:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000727 case LibFunc::atoi:
728 case LibFunc::atol:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000729 case LibFunc::atoll:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000730 case LibFunc::ferror:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000731 case LibFunc::getenv:
732 case LibFunc::getpwnam:
733 case LibFunc::pclose:
734 case LibFunc::perror:
735 case LibFunc::printf:
736 case LibFunc::puts:
737 case LibFunc::uname:
738 case LibFunc::under_IO_getc:
739 case LibFunc::unlink:
740 case LibFunc::unsetenv:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000741 return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000742
743 case LibFunc::chmod:
744 case LibFunc::chown:
745 case LibFunc::clearerr:
746 case LibFunc::closedir:
747 case LibFunc::ctermid:
748 case LibFunc::fclose:
749 case LibFunc::feof:
750 case LibFunc::fflush:
751 case LibFunc::fgetc:
752 case LibFunc::fileno:
753 case LibFunc::flockfile:
754 case LibFunc::free:
755 case LibFunc::fseek:
Ahmed Bougacha201b97f2016-05-25 21:16:33 +0000756 case LibFunc::fseeko64:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000757 case LibFunc::fseeko:
758 case LibFunc::fsetpos:
759 case LibFunc::ftell:
Ahmed Bougacha201b97f2016-05-25 21:16:33 +0000760 case LibFunc::ftello64:
Ahmed Bougacha1fe3f1c2016-05-25 20:22:45 +0000761 case LibFunc::ftello:
762 case LibFunc::ftrylockfile:
763 case LibFunc::funlockfile:
764 case LibFunc::getc:
765 case LibFunc::getc_unlocked:
766 case LibFunc::getlogin_r:
767 case LibFunc::mkdir:
768 case LibFunc::mktime:
769 case LibFunc::times:
770 return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
771
Ahmed Bougachad765a822016-04-27 19:04:35 +0000772 case LibFunc::access:
773 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
774 case LibFunc::fopen:
775 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
776 FTy.getParamType(0)->isPointerTy() &&
777 FTy.getParamType(1)->isPointerTy());
778 case LibFunc::fdopen:
779 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
780 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000781 case LibFunc::fputc:
782 case LibFunc::fstat:
783 case LibFunc::frexp:
784 case LibFunc::frexpf:
785 case LibFunc::frexpl:
786 case LibFunc::fstatvfs:
787 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
788 case LibFunc::fgets:
789 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
790 FTy.getParamType(2)->isPointerTy());
791 case LibFunc::fread:
792 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
793 FTy.getParamType(3)->isPointerTy());
794 case LibFunc::fwrite:
795 return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
796 FTy.getParamType(0)->isPointerTy() &&
797 FTy.getParamType(1)->isIntegerTy() &&
798 FTy.getParamType(2)->isIntegerTy() &&
799 FTy.getParamType(3)->isPointerTy());
800 case LibFunc::fputs:
801 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
802 FTy.getParamType(1)->isPointerTy());
803 case LibFunc::fscanf:
804 case LibFunc::fprintf:
805 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
806 FTy.getParamType(1)->isPointerTy());
807 case LibFunc::fgetpos:
808 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
809 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000810 case LibFunc::gets:
811 case LibFunc::getchar:
812 case LibFunc::getitimer:
813 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000814 case LibFunc::ungetc:
815 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000816 case LibFunc::utime:
817 case LibFunc::utimes:
818 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
819 FTy.getParamType(1)->isPointerTy());
820 case LibFunc::putc:
821 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000822 case LibFunc::pread:
823 case LibFunc::pwrite:
824 return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000825 case LibFunc::popen:
826 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
827 FTy.getParamType(0)->isPointerTy() &&
828 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000829 case LibFunc::vscanf:
830 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
831 case LibFunc::vsscanf:
832 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
833 FTy.getParamType(2)->isPointerTy());
834 case LibFunc::vfscanf:
835 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
836 FTy.getParamType(2)->isPointerTy());
837 case LibFunc::valloc:
838 return (FTy.getReturnType()->isPointerTy());
839 case LibFunc::vprintf:
840 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
841 case LibFunc::vfprintf:
842 case LibFunc::vsprintf:
843 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
844 FTy.getParamType(1)->isPointerTy());
845 case LibFunc::vsnprintf:
846 return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
847 FTy.getParamType(2)->isPointerTy());
848 case LibFunc::open:
849 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
850 case LibFunc::opendir:
851 return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
852 FTy.getParamType(0)->isPointerTy());
853 case LibFunc::tmpfile:
854 return (FTy.getReturnType()->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000855 case LibFunc::htonl:
856 case LibFunc::htons:
857 case LibFunc::ntohl:
858 case LibFunc::ntohs:
859 case LibFunc::lstat:
860 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
861 FTy.getParamType(1)->isPointerTy());
862 case LibFunc::lchown:
863 return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
864 case LibFunc::qsort:
865 return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
866 case LibFunc::dunder_strdup:
867 case LibFunc::dunder_strndup:
868 return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
869 FTy.getParamType(0)->isPointerTy());
870 case LibFunc::dunder_strtok_r:
871 return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000872 case LibFunc::under_IO_putc:
873 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
874 case LibFunc::dunder_isoc99_scanf:
875 return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
876 case LibFunc::stat64:
877 case LibFunc::lstat64:
878 case LibFunc::statvfs64:
Michael Kuperstein79dcc272016-09-20 23:10:31 +0000879 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000880 FTy.getParamType(1)->isPointerTy());
881 case LibFunc::dunder_isoc99_sscanf:
Michael Kuperstein79dcc272016-09-20 23:10:31 +0000882 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
Ahmed Bougachad765a822016-04-27 19:04:35 +0000883 FTy.getParamType(1)->isPointerTy());
884 case LibFunc::fopen64:
885 return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
886 FTy.getParamType(0)->isPointerTy() &&
887 FTy.getParamType(1)->isPointerTy());
Ahmed Bougachad765a822016-04-27 19:04:35 +0000888 case LibFunc::tmpfile64:
889 return (FTy.getReturnType()->isPointerTy());
890 case LibFunc::fstat64:
891 case LibFunc::fstatvfs64:
892 return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
893 case LibFunc::open64:
894 return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
895 case LibFunc::gettimeofday:
896 return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
897 FTy.getParamType(1)->isPointerTy());
898
899 case LibFunc::Znwj: // new(unsigned int);
900 case LibFunc::Znwm: // new(unsigned long);
901 case LibFunc::Znaj: // new[](unsigned int);
902 case LibFunc::Znam: // new[](unsigned long);
903 case LibFunc::msvc_new_int: // new(unsigned int);
904 case LibFunc::msvc_new_longlong: // new(unsigned long long);
905 case LibFunc::msvc_new_array_int: // new[](unsigned int);
906 case LibFunc::msvc_new_array_longlong: // new[](unsigned long long);
907 return (NumParams == 1);
908
909 case LibFunc::memset_pattern16:
910 return (!FTy.isVarArg() && NumParams == 3 &&
911 isa<PointerType>(FTy.getParamType(0)) &&
912 isa<PointerType>(FTy.getParamType(1)) &&
913 isa<IntegerType>(FTy.getParamType(2)));
914
915 // int __nvvm_reflect(const char *);
916 case LibFunc::nvvm_reflect:
917 return (NumParams == 1 && isa<PointerType>(FTy.getParamType(0)));
918
919 case LibFunc::sin:
920 case LibFunc::sinf:
921 case LibFunc::sinl:
922 case LibFunc::cos:
923 case LibFunc::cosf:
924 case LibFunc::cosl:
David Majnemerb62692e2016-06-15 16:47:23 +0000925 case LibFunc::tan:
926 case LibFunc::tanf:
927 case LibFunc::tanl:
Ahmed Bougachad765a822016-04-27 19:04:35 +0000928 case LibFunc::exp:
929 case LibFunc::expf:
930 case LibFunc::expl:
931 case LibFunc::exp2:
932 case LibFunc::exp2f:
933 case LibFunc::exp2l:
934 case LibFunc::log:
935 case LibFunc::logf:
936 case LibFunc::logl:
937 case LibFunc::log10:
938 case LibFunc::log10f:
939 case LibFunc::log10l:
940 case LibFunc::log2:
941 case LibFunc::log2f:
942 case LibFunc::log2l:
943 case LibFunc::fabs:
944 case LibFunc::fabsf:
945 case LibFunc::fabsl:
946 case LibFunc::floor:
947 case LibFunc::floorf:
948 case LibFunc::floorl:
949 case LibFunc::ceil:
950 case LibFunc::ceilf:
951 case LibFunc::ceill:
952 case LibFunc::trunc:
953 case LibFunc::truncf:
954 case LibFunc::truncl:
955 case LibFunc::rint:
956 case LibFunc::rintf:
957 case LibFunc::rintl:
958 case LibFunc::nearbyint:
959 case LibFunc::nearbyintf:
960 case LibFunc::nearbyintl:
961 case LibFunc::round:
962 case LibFunc::roundf:
963 case LibFunc::roundl:
964 case LibFunc::sqrt:
965 case LibFunc::sqrtf:
966 case LibFunc::sqrtl:
967 return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
968 FTy.getReturnType() == FTy.getParamType(0));
969
970 case LibFunc::fmin:
971 case LibFunc::fminf:
972 case LibFunc::fminl:
973 case LibFunc::fmax:
974 case LibFunc::fmaxf:
975 case LibFunc::fmaxl:
976 case LibFunc::copysign:
977 case LibFunc::copysignf:
978 case LibFunc::copysignl:
979 case LibFunc::pow:
980 case LibFunc::powf:
981 case LibFunc::powl:
982 return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
983 FTy.getReturnType() == FTy.getParamType(0) &&
984 FTy.getReturnType() == FTy.getParamType(1));
985
986 case LibFunc::ffs:
987 case LibFunc::ffsl:
988 case LibFunc::ffsll:
Sanjay Patel04949faf2016-09-23 18:44:09 +0000989 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
990 FTy.getParamType(0)->isIntegerTy());
991
Ahmed Bougachad765a822016-04-27 19:04:35 +0000992 case LibFunc::isdigit:
993 case LibFunc::isascii:
994 case LibFunc::toascii:
995 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
Sanjay Patel04949faf2016-09-23 18:44:09 +0000996 FTy.getReturnType() == FTy.getParamType(0));
Ahmed Bougachad765a822016-04-27 19:04:35 +0000997
998 case LibFunc::fls:
999 case LibFunc::flsl:
1000 case LibFunc::flsll:
1001 case LibFunc::abs:
1002 case LibFunc::labs:
1003 case LibFunc::llabs:
1004 return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
1005 FTy.getReturnType() == FTy.getParamType(0));
1006
1007 case LibFunc::cxa_atexit:
1008 return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
1009 FTy.getParamType(0)->isPointerTy() &&
1010 FTy.getParamType(1)->isPointerTy() &&
1011 FTy.getParamType(2)->isPointerTy());
1012
1013 case LibFunc::sinpi:
1014 case LibFunc::cospi:
1015 return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
1016 FTy.getReturnType() == FTy.getParamType(0));
1017
1018 case LibFunc::sinpif:
1019 case LibFunc::cospif:
1020 return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
1021 FTy.getReturnType() == FTy.getParamType(0));
1022
1023 default:
1024 // Assume the other functions are correct.
1025 // FIXME: It'd be really nice to cover them all.
1026 return true;
1027 }
1028}
1029
1030bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
1031 LibFunc::Func &F) const {
1032 const DataLayout *DL =
1033 FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
1034 return getLibFunc(FDecl.getName(), F) &&
1035 isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
1036}
1037
Chandler Carruthc0291862015-01-24 02:06:09 +00001038void TargetLibraryInfoImpl::disableAllFunctions() {
Chris Lattner1341df92011-02-18 22:34:03 +00001039 memset(AvailableArray, 0, sizeof(AvailableArray));
1040}
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001041
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001042static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001043 return LHS.ScalarFnName < RHS.ScalarFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001044}
1045
1046static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001047 return LHS.VectorFnName < RHS.VectorFnName;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001048}
1049
1050static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001051 return LHS.ScalarFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001052}
1053
1054static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
Mehdi Amini9a72cd72016-10-01 03:10:48 +00001055 return LHS.VectorFnName < S;
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001056}
1057
1058void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
1059 VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
1060 std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
1061
1062 ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
1063 std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
1064}
1065
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001066void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1067 enum VectorLibrary VecLib) {
1068 switch (VecLib) {
1069 case Accelerate: {
1070 const VecDesc VecFuncs[] = {
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001071 // Floating-Point Arithmetic and Auxiliary Functions
1072 {"ceilf", "vceilf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001073 {"fabsf", "vfabsf", 4},
1074 {"llvm.fabs.f32", "vfabsf", 4},
Michael Zolotukhinde63aac2015-05-07 17:11:51 +00001075 {"floorf", "vfloorf", 4},
1076 {"sqrtf", "vsqrtf", 4},
1077 {"llvm.sqrt.f32", "vsqrtf", 4},
1078
1079 // Exponential and Logarithmic Functions
1080 {"expf", "vexpf", 4},
1081 {"llvm.exp.f32", "vexpf", 4},
1082 {"expm1f", "vexpm1f", 4},
1083 {"logf", "vlogf", 4},
1084 {"llvm.log.f32", "vlogf", 4},
1085 {"log1pf", "vlog1pf", 4},
1086 {"log10f", "vlog10f", 4},
1087 {"llvm.log10.f32", "vlog10f", 4},
1088 {"logbf", "vlogbf", 4},
1089
1090 // Trigonometric Functions
1091 {"sinf", "vsinf", 4},
1092 {"llvm.sin.f32", "vsinf", 4},
1093 {"cosf", "vcosf", 4},
1094 {"llvm.cos.f32", "vcosf", 4},
1095 {"tanf", "vtanf", 4},
1096 {"asinf", "vasinf", 4},
1097 {"acosf", "vacosf", 4},
1098 {"atanf", "vatanf", 4},
1099
1100 // Hyperbolic Functions
1101 {"sinhf", "vsinhf", 4},
1102 {"coshf", "vcoshf", 4},
1103 {"tanhf", "vtanhf", 4},
1104 {"asinhf", "vasinhf", 4},
1105 {"acoshf", "vacoshf", 4},
1106 {"atanhf", "vatanhf", 4},
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001107 };
1108 addVectorizableFunctions(VecFuncs);
1109 break;
1110 }
Matt Mastena6669a12016-07-29 16:42:44 +00001111 case SVML: {
1112 const VecDesc VecFuncs[] = {
1113 {"sin", "__svml_sin2", 2},
1114 {"sin", "__svml_sin4", 4},
1115 {"sin", "__svml_sin8", 8},
1116
1117 {"sinf", "__svml_sinf4", 4},
1118 {"sinf", "__svml_sinf8", 8},
1119 {"sinf", "__svml_sinf16", 16},
1120
1121 {"cos", "__svml_cos2", 2},
1122 {"cos", "__svml_cos4", 4},
1123 {"cos", "__svml_cos8", 8},
1124
1125 {"cosf", "__svml_cosf4", 4},
1126 {"cosf", "__svml_cosf8", 8},
1127 {"cosf", "__svml_cosf16", 16},
1128
1129 {"pow", "__svml_pow2", 2},
1130 {"pow", "__svml_pow4", 4},
1131 {"pow", "__svml_pow8", 8},
1132
1133 {"powf", "__svml_powf4", 4},
1134 {"powf", "__svml_powf8", 8},
1135 {"powf", "__svml_powf16", 16},
1136
1137 {"llvm.pow.f64", "__svml_pow2", 2},
1138 {"llvm.pow.f64", "__svml_pow4", 4},
1139 {"llvm.pow.f64", "__svml_pow8", 8},
1140
1141 {"llvm.pow.f32", "__svml_powf4", 4},
1142 {"llvm.pow.f32", "__svml_powf8", 8},
1143 {"llvm.pow.f32", "__svml_powf16", 16},
1144
1145 {"exp", "__svml_exp2", 2},
1146 {"exp", "__svml_exp4", 4},
1147 {"exp", "__svml_exp8", 8},
1148
1149 {"expf", "__svml_expf4", 4},
1150 {"expf", "__svml_expf8", 8},
1151 {"expf", "__svml_expf16", 16},
1152
1153 {"llvm.exp.f64", "__svml_exp2", 2},
1154 {"llvm.exp.f64", "__svml_exp4", 4},
1155 {"llvm.exp.f64", "__svml_exp8", 8},
1156
1157 {"llvm.exp.f32", "__svml_expf4", 4},
1158 {"llvm.exp.f32", "__svml_expf8", 8},
1159 {"llvm.exp.f32", "__svml_expf16", 16},
1160
1161 {"log", "__svml_log2", 2},
1162 {"log", "__svml_log4", 4},
1163 {"log", "__svml_log8", 8},
1164
1165 {"logf", "__svml_logf4", 4},
1166 {"logf", "__svml_logf8", 8},
1167 {"logf", "__svml_logf16", 16},
1168
1169 {"llvm.log.f64", "__svml_log2", 2},
1170 {"llvm.log.f64", "__svml_log4", 4},
1171 {"llvm.log.f64", "__svml_log8", 8},
1172
1173 {"llvm.log.f32", "__svml_logf4", 4},
1174 {"llvm.log.f32", "__svml_logf8", 8},
1175 {"llvm.log.f32", "__svml_logf16", 16},
1176 };
1177 addVectorizableFunctions(VecFuncs);
1178 break;
1179 }
Michael Zolotukhin6d8a2aa2015-03-17 19:50:55 +00001180 case NoLibrary:
1181 break;
1182 }
1183}
1184
Michael Zolotukhine8f25512015-03-17 19:22:30 +00001185bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1186 funcName = sanitizeFunctionName(funcName);
1187 if (funcName.empty())
1188 return false;
1189
1190 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1191 VectorDescs.begin(), VectorDescs.end(), funcName,
1192 compareWithScalarFnName);
1193 return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1194}
1195
1196StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1197 unsigned VF) const {
1198 F = sanitizeFunctionName(F);
1199 if (F.empty())
1200 return F;
1201 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1202 VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
1203 while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1204 if (I->VectorizationFactor == VF)
1205 return I->VectorFnName;
1206 ++I;
1207 }
1208 return StringRef();
1209}
1210
1211StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
1212 unsigned &VF) const {
1213 F = sanitizeFunctionName(F);
1214 if (F.empty())
1215 return F;
1216
1217 std::vector<VecDesc>::const_iterator I = std::lower_bound(
1218 ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
1219 if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
1220 return StringRef();
1221 VF = I->VectorizationFactor;
1222 return I->ScalarFnName;
1223}
1224
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001225TargetLibraryInfo TargetLibraryAnalysis::run(Module &M,
1226 ModuleAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001227 if (PresetInfoImpl)
1228 return TargetLibraryInfo(*PresetInfoImpl);
1229
1230 return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
1231}
1232
Chandler Carruth164a2aa62016-06-17 00:11:01 +00001233TargetLibraryInfo TargetLibraryAnalysis::run(Function &F,
1234 FunctionAnalysisManager &) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001235 if (PresetInfoImpl)
1236 return TargetLibraryInfo(*PresetInfoImpl);
1237
1238 return TargetLibraryInfo(
1239 lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
1240}
1241
Benjamin Kramerc321e532016-06-08 19:09:22 +00001242TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(const Triple &T) {
Chandler Carruthc0291862015-01-24 02:06:09 +00001243 std::unique_ptr<TargetLibraryInfoImpl> &Impl =
1244 Impls[T.normalize()];
1245 if (!Impl)
1246 Impl.reset(new TargetLibraryInfoImpl(T));
1247
1248 return *Impl;
1249}
1250
1251
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001252TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
Chandler Carruthc0291862015-01-24 02:06:09 +00001253 : ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001254 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1255}
1256
1257TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
Chandler Carruthc0291862015-01-24 02:06:09 +00001258 : ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001259 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1260}
1261
1262TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
Chandler Carruthc0291862015-01-24 02:06:09 +00001263 const TargetLibraryInfoImpl &TLIImpl)
1264 : ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001265 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
1266}
1267
Chandler Carruthb4faf132016-03-11 10:22:49 +00001268char TargetLibraryAnalysis::PassID;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +00001269
Chandler Carruthb98f63d2015-01-15 10:41:28 +00001270// Register the basic pass.
1271INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
1272 "Target Library Information", false, true)
1273char TargetLibraryInfoWrapperPass::ID = 0;
1274
1275void TargetLibraryInfoWrapperPass::anchor() {}