2011-02-18 22:50:34 +01:00
|
|
|
//===-- TargetLibraryInfo.cpp - Runtime library information ----------------==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the TargetLibraryInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-01-15 03:16:27 +01:00
|
|
|
#include "llvm/Analysis/TargetLibraryInfo.h"
|
2011-02-18 22:50:34 +01:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2015-03-17 20:50:55 +01:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2011-02-18 22:50:34 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2015-03-17 20:50:55 +01:00
|
|
|
static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
|
|
|
|
"vector-library", cl::Hidden, cl::desc("Vector functions library"),
|
|
|
|
cl::init(TargetLibraryInfoImpl::NoLibrary),
|
|
|
|
cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
|
|
|
|
"No vector functions library"),
|
|
|
|
clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
|
|
|
|
"Accelerate framework"),
|
|
|
|
clEnumValEnd));
|
|
|
|
|
2015-03-08 17:07:39 +01:00
|
|
|
const char *const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] = {
|
2015-03-04 00:41:58 +01:00
|
|
|
#define TLI_DEFINE_STRING
|
|
|
|
#include "llvm/Analysis/TargetLibraryInfo.def"
|
2015-03-08 17:07:39 +01:00
|
|
|
};
|
2011-11-17 02:27:36 +01:00
|
|
|
|
2013-11-03 07:48:38 +01:00
|
|
|
static bool hasSinCosPiStret(const Triple &T) {
|
|
|
|
// Only Darwin variants have _stret versions of combined trig functions.
|
2014-10-09 07:43:30 +02:00
|
|
|
if (!T.isOSDarwin())
|
2013-11-03 07:48:38 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// The ABI is rather complicated on x86, so don't do anything special there.
|
|
|
|
if (T.getArch() == Triple::x86)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (T.isMacOSX() && T.isMacOSXVersionLT(10, 9))
|
|
|
|
return false;
|
|
|
|
|
2014-10-09 07:43:30 +02:00
|
|
|
if (T.isiOS() && T.isOSVersionLT(7, 0))
|
2013-11-03 07:48:38 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-18 22:50:34 +01:00
|
|
|
/// initialize - Initialize the set of available library functions based on the
|
|
|
|
/// specified target triple. This should be carefully written so that a missing
|
|
|
|
/// target triple gets a sane set of defaults.
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
|
2016-01-03 20:43:40 +01:00
|
|
|
ArrayRef<const char *> StandardNames) {
|
2012-08-03 06:06:22 +02:00
|
|
|
// Verify that the StandardNames array is in alphabetical order.
|
2016-01-03 20:43:40 +01:00
|
|
|
assert(std::is_sorted(StandardNames.begin(), StandardNames.end(),
|
|
|
|
[](const char *LHS, const char *RHS) {
|
|
|
|
return strcmp(LHS, RHS) < 0;
|
|
|
|
}) &&
|
|
|
|
"TargetLibraryInfoImpl function names must be sorted");
|
2014-04-02 21:53:29 +02:00
|
|
|
|
2015-12-15 18:24:15 +01:00
|
|
|
if (T.getArch() == Triple::r600 ||
|
|
|
|
T.getArch() == Triple::amdgcn) {
|
|
|
|
TLI.setUnavailable(LibFunc::ldexp);
|
|
|
|
TLI.setUnavailable(LibFunc::ldexpf);
|
|
|
|
TLI.setUnavailable(LibFunc::ldexpl);
|
|
|
|
}
|
|
|
|
|
2015-01-07 02:17:37 +01:00
|
|
|
// There are no library implementations of mempcy and memset for AMD gpus and
|
2014-04-02 21:53:29 +02:00
|
|
|
// these can be difficult to lower in the backend.
|
2015-01-07 02:17:37 +01:00
|
|
|
if (T.getArch() == Triple::r600 ||
|
2016-01-19 15:49:23 +01:00
|
|
|
T.getArch() == Triple::amdgcn) {
|
2014-04-02 21:53:29 +02:00
|
|
|
TLI.setUnavailable(LibFunc::memcpy);
|
|
|
|
TLI.setUnavailable(LibFunc::memset);
|
|
|
|
TLI.setUnavailable(LibFunc::memset_pattern16);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-07 19:08:54 +01:00
|
|
|
// memset_pattern16 is only available on iOS 3.0 and Mac OS X 10.5 and later.
|
2015-10-28 23:51:16 +01:00
|
|
|
// All versions of watchOS support it.
|
2011-04-20 02:14:25 +02:00
|
|
|
if (T.isMacOSX()) {
|
|
|
|
if (T.isMacOSXVersionLT(10, 5))
|
2011-04-19 22:44:08 +02:00
|
|
|
TLI.setUnavailable(LibFunc::memset_pattern16);
|
2013-08-29 22:23:14 +02:00
|
|
|
} else if (T.isiOS()) {
|
2011-04-19 22:44:08 +02:00
|
|
|
if (T.isOSVersionLT(3, 0))
|
|
|
|
TLI.setUnavailable(LibFunc::memset_pattern16);
|
2015-10-28 23:51:16 +01:00
|
|
|
} else if (!T.isWatchOS()) {
|
2011-02-18 22:50:34 +01:00
|
|
|
TLI.setUnavailable(LibFunc::memset_pattern16);
|
2011-04-19 22:44:08 +02:00
|
|
|
}
|
2011-03-03 14:17:51 +01:00
|
|
|
|
2013-11-03 07:48:38 +01:00
|
|
|
if (!hasSinCosPiStret(T)) {
|
|
|
|
TLI.setUnavailable(LibFunc::sinpi);
|
|
|
|
TLI.setUnavailable(LibFunc::sinpif);
|
|
|
|
TLI.setUnavailable(LibFunc::cospi);
|
|
|
|
TLI.setUnavailable(LibFunc::cospif);
|
|
|
|
TLI.setUnavailable(LibFunc::sincospi_stret);
|
2014-02-04 17:28:20 +01:00
|
|
|
TLI.setUnavailable(LibFunc::sincospif_stret);
|
2013-11-03 07:48:38 +01:00
|
|
|
}
|
|
|
|
|
2011-11-17 02:27:36 +01:00
|
|
|
if (T.isMacOSX() && T.getArch() == Triple::x86 &&
|
|
|
|
!T.isMacOSXVersionLT(10, 7)) {
|
|
|
|
// x86-32 OSX has a scheme where fwrite and fputs (and some other functions
|
|
|
|
// we don't care about) have two versions; on recent OSX, the one we want
|
|
|
|
// has a $UNIX2003 suffix. The two implementations are identical except
|
|
|
|
// for the return value in some edge cases. However, we don't want to
|
|
|
|
// generate code that depends on the old symbols.
|
|
|
|
TLI.setAvailableWithName(LibFunc::fwrite, "fwrite$UNIX2003");
|
|
|
|
TLI.setAvailableWithName(LibFunc::fputs, "fputs$UNIX2003");
|
|
|
|
}
|
|
|
|
|
2011-06-09 13:11:45 +02:00
|
|
|
// iprintf and friends are only available on XCore and TCE.
|
|
|
|
if (T.getArch() != Triple::xcore && T.getArch() != Triple::tce) {
|
2011-03-03 14:17:51 +01:00
|
|
|
TLI.setUnavailable(LibFunc::iprintf);
|
2011-03-03 15:09:28 +01:00
|
|
|
TLI.setUnavailable(LibFunc::siprintf);
|
2011-03-03 15:20:22 +01:00
|
|
|
TLI.setUnavailable(LibFunc::fiprintf);
|
2011-03-03 15:09:28 +01:00
|
|
|
}
|
2012-04-18 01:05:54 +02:00
|
|
|
|
2014-07-25 00:09:06 +02:00
|
|
|
if (T.isOSWindows() && !T.isOSCygMing()) {
|
2012-04-18 01:05:54 +02:00
|
|
|
// Win32 does not support long double
|
|
|
|
TLI.setUnavailable(LibFunc::acosl);
|
|
|
|
TLI.setUnavailable(LibFunc::asinl);
|
|
|
|
TLI.setUnavailable(LibFunc::atanl);
|
|
|
|
TLI.setUnavailable(LibFunc::atan2l);
|
|
|
|
TLI.setUnavailable(LibFunc::ceill);
|
|
|
|
TLI.setUnavailable(LibFunc::copysignl);
|
|
|
|
TLI.setUnavailable(LibFunc::cosl);
|
|
|
|
TLI.setUnavailable(LibFunc::coshl);
|
|
|
|
TLI.setUnavailable(LibFunc::expl);
|
|
|
|
TLI.setUnavailable(LibFunc::fabsf); // Win32 and Win64 both lack fabsf
|
|
|
|
TLI.setUnavailable(LibFunc::fabsl);
|
|
|
|
TLI.setUnavailable(LibFunc::floorl);
|
2013-12-16 23:42:40 +01:00
|
|
|
TLI.setUnavailable(LibFunc::fmaxl);
|
|
|
|
TLI.setUnavailable(LibFunc::fminl);
|
2012-04-18 01:05:54 +02:00
|
|
|
TLI.setUnavailable(LibFunc::fmodl);
|
2013-03-05 22:47:40 +01:00
|
|
|
TLI.setUnavailable(LibFunc::frexpl);
|
2014-02-04 21:27:23 +01:00
|
|
|
TLI.setUnavailable(LibFunc::ldexpf);
|
|
|
|
TLI.setUnavailable(LibFunc::ldexpl);
|
2012-04-18 01:05:54 +02:00
|
|
|
TLI.setUnavailable(LibFunc::logl);
|
2013-03-05 22:47:40 +01:00
|
|
|
TLI.setUnavailable(LibFunc::modfl);
|
2012-04-18 01:05:54 +02:00
|
|
|
TLI.setUnavailable(LibFunc::powl);
|
|
|
|
TLI.setUnavailable(LibFunc::sinl);
|
|
|
|
TLI.setUnavailable(LibFunc::sinhl);
|
|
|
|
TLI.setUnavailable(LibFunc::sqrtl);
|
|
|
|
TLI.setUnavailable(LibFunc::tanl);
|
|
|
|
TLI.setUnavailable(LibFunc::tanhl);
|
|
|
|
|
|
|
|
// Win32 only has C89 math
|
2012-08-22 01:28:56 +02:00
|
|
|
TLI.setUnavailable(LibFunc::acosh);
|
|
|
|
TLI.setUnavailable(LibFunc::acoshf);
|
|
|
|
TLI.setUnavailable(LibFunc::acoshl);
|
|
|
|
TLI.setUnavailable(LibFunc::asinh);
|
|
|
|
TLI.setUnavailable(LibFunc::asinhf);
|
|
|
|
TLI.setUnavailable(LibFunc::asinhl);
|
|
|
|
TLI.setUnavailable(LibFunc::atanh);
|
|
|
|
TLI.setUnavailable(LibFunc::atanhf);
|
|
|
|
TLI.setUnavailable(LibFunc::atanhl);
|
|
|
|
TLI.setUnavailable(LibFunc::cbrt);
|
|
|
|
TLI.setUnavailable(LibFunc::cbrtf);
|
|
|
|
TLI.setUnavailable(LibFunc::cbrtl);
|
2012-04-18 01:05:54 +02:00
|
|
|
TLI.setUnavailable(LibFunc::exp2);
|
|
|
|
TLI.setUnavailable(LibFunc::exp2f);
|
|
|
|
TLI.setUnavailable(LibFunc::exp2l);
|
|
|
|
TLI.setUnavailable(LibFunc::expm1);
|
|
|
|
TLI.setUnavailable(LibFunc::expm1f);
|
|
|
|
TLI.setUnavailable(LibFunc::expm1l);
|
|
|
|
TLI.setUnavailable(LibFunc::log2);
|
|
|
|
TLI.setUnavailable(LibFunc::log2f);
|
|
|
|
TLI.setUnavailable(LibFunc::log2l);
|
|
|
|
TLI.setUnavailable(LibFunc::log1p);
|
|
|
|
TLI.setUnavailable(LibFunc::log1pf);
|
|
|
|
TLI.setUnavailable(LibFunc::log1pl);
|
2012-08-22 01:28:56 +02:00
|
|
|
TLI.setUnavailable(LibFunc::logb);
|
|
|
|
TLI.setUnavailable(LibFunc::logbf);
|
|
|
|
TLI.setUnavailable(LibFunc::logbl);
|
2012-04-18 01:05:54 +02:00
|
|
|
TLI.setUnavailable(LibFunc::nearbyint);
|
|
|
|
TLI.setUnavailable(LibFunc::nearbyintf);
|
|
|
|
TLI.setUnavailable(LibFunc::nearbyintl);
|
|
|
|
TLI.setUnavailable(LibFunc::rint);
|
|
|
|
TLI.setUnavailable(LibFunc::rintf);
|
|
|
|
TLI.setUnavailable(LibFunc::rintl);
|
|
|
|
TLI.setUnavailable(LibFunc::round);
|
|
|
|
TLI.setUnavailable(LibFunc::roundf);
|
|
|
|
TLI.setUnavailable(LibFunc::roundl);
|
|
|
|
TLI.setUnavailable(LibFunc::trunc);
|
|
|
|
TLI.setUnavailable(LibFunc::truncf);
|
|
|
|
TLI.setUnavailable(LibFunc::truncl);
|
|
|
|
|
|
|
|
// Win32 provides some C99 math with mangled names
|
|
|
|
TLI.setAvailableWithName(LibFunc::copysign, "_copysign");
|
|
|
|
|
|
|
|
if (T.getArch() == Triple::x86) {
|
|
|
|
// Win32 on x86 implements single-precision math functions as macros
|
|
|
|
TLI.setUnavailable(LibFunc::acosf);
|
|
|
|
TLI.setUnavailable(LibFunc::asinf);
|
|
|
|
TLI.setUnavailable(LibFunc::atanf);
|
|
|
|
TLI.setUnavailable(LibFunc::atan2f);
|
|
|
|
TLI.setUnavailable(LibFunc::ceilf);
|
|
|
|
TLI.setUnavailable(LibFunc::copysignf);
|
|
|
|
TLI.setUnavailable(LibFunc::cosf);
|
|
|
|
TLI.setUnavailable(LibFunc::coshf);
|
|
|
|
TLI.setUnavailable(LibFunc::expf);
|
|
|
|
TLI.setUnavailable(LibFunc::floorf);
|
2013-12-16 23:42:40 +01:00
|
|
|
TLI.setUnavailable(LibFunc::fminf);
|
|
|
|
TLI.setUnavailable(LibFunc::fmaxf);
|
2012-04-18 01:05:54 +02:00
|
|
|
TLI.setUnavailable(LibFunc::fmodf);
|
|
|
|
TLI.setUnavailable(LibFunc::logf);
|
2016-05-08 10:15:50 +02:00
|
|
|
TLI.setUnavailable(LibFunc::log10f);
|
|
|
|
TLI.setUnavailable(LibFunc::modff);
|
2012-04-18 01:05:54 +02:00
|
|
|
TLI.setUnavailable(LibFunc::powf);
|
|
|
|
TLI.setUnavailable(LibFunc::sinf);
|
|
|
|
TLI.setUnavailable(LibFunc::sinhf);
|
|
|
|
TLI.setUnavailable(LibFunc::sqrtf);
|
|
|
|
TLI.setUnavailable(LibFunc::tanf);
|
|
|
|
TLI.setUnavailable(LibFunc::tanhf);
|
|
|
|
}
|
2012-11-10 04:11:06 +01:00
|
|
|
|
2013-03-05 22:47:40 +01:00
|
|
|
// Win32 does *not* provide provide these functions, but they are
|
|
|
|
// generally available on POSIX-compliant systems:
|
|
|
|
TLI.setUnavailable(LibFunc::access);
|
|
|
|
TLI.setUnavailable(LibFunc::bcmp);
|
|
|
|
TLI.setUnavailable(LibFunc::bcopy);
|
|
|
|
TLI.setUnavailable(LibFunc::bzero);
|
|
|
|
TLI.setUnavailable(LibFunc::chmod);
|
|
|
|
TLI.setUnavailable(LibFunc::chown);
|
|
|
|
TLI.setUnavailable(LibFunc::closedir);
|
|
|
|
TLI.setUnavailable(LibFunc::ctermid);
|
|
|
|
TLI.setUnavailable(LibFunc::fdopen);
|
2012-11-22 16:36:42 +01:00
|
|
|
TLI.setUnavailable(LibFunc::ffs);
|
2013-03-05 22:47:40 +01:00
|
|
|
TLI.setUnavailable(LibFunc::fileno);
|
|
|
|
TLI.setUnavailable(LibFunc::flockfile);
|
|
|
|
TLI.setUnavailable(LibFunc::fseeko);
|
|
|
|
TLI.setUnavailable(LibFunc::fstat);
|
|
|
|
TLI.setUnavailable(LibFunc::fstatvfs);
|
|
|
|
TLI.setUnavailable(LibFunc::ftello);
|
|
|
|
TLI.setUnavailable(LibFunc::ftrylockfile);
|
|
|
|
TLI.setUnavailable(LibFunc::funlockfile);
|
|
|
|
TLI.setUnavailable(LibFunc::getc_unlocked);
|
|
|
|
TLI.setUnavailable(LibFunc::getitimer);
|
|
|
|
TLI.setUnavailable(LibFunc::getlogin_r);
|
|
|
|
TLI.setUnavailable(LibFunc::getpwnam);
|
2013-07-03 06:00:51 +02:00
|
|
|
TLI.setUnavailable(LibFunc::gettimeofday);
|
2013-03-05 22:47:40 +01:00
|
|
|
TLI.setUnavailable(LibFunc::htonl);
|
|
|
|
TLI.setUnavailable(LibFunc::htons);
|
|
|
|
TLI.setUnavailable(LibFunc::lchown);
|
|
|
|
TLI.setUnavailable(LibFunc::lstat);
|
|
|
|
TLI.setUnavailable(LibFunc::memccpy);
|
|
|
|
TLI.setUnavailable(LibFunc::mkdir);
|
|
|
|
TLI.setUnavailable(LibFunc::ntohl);
|
|
|
|
TLI.setUnavailable(LibFunc::ntohs);
|
|
|
|
TLI.setUnavailable(LibFunc::open);
|
|
|
|
TLI.setUnavailable(LibFunc::opendir);
|
|
|
|
TLI.setUnavailable(LibFunc::pclose);
|
|
|
|
TLI.setUnavailable(LibFunc::popen);
|
|
|
|
TLI.setUnavailable(LibFunc::pread);
|
|
|
|
TLI.setUnavailable(LibFunc::pwrite);
|
|
|
|
TLI.setUnavailable(LibFunc::read);
|
|
|
|
TLI.setUnavailable(LibFunc::readlink);
|
|
|
|
TLI.setUnavailable(LibFunc::realpath);
|
|
|
|
TLI.setUnavailable(LibFunc::rmdir);
|
|
|
|
TLI.setUnavailable(LibFunc::setitimer);
|
|
|
|
TLI.setUnavailable(LibFunc::stat);
|
|
|
|
TLI.setUnavailable(LibFunc::statvfs);
|
|
|
|
TLI.setUnavailable(LibFunc::stpcpy);
|
|
|
|
TLI.setUnavailable(LibFunc::stpncpy);
|
|
|
|
TLI.setUnavailable(LibFunc::strcasecmp);
|
|
|
|
TLI.setUnavailable(LibFunc::strncasecmp);
|
|
|
|
TLI.setUnavailable(LibFunc::times);
|
|
|
|
TLI.setUnavailable(LibFunc::uname);
|
|
|
|
TLI.setUnavailable(LibFunc::unlink);
|
|
|
|
TLI.setUnavailable(LibFunc::unsetenv);
|
|
|
|
TLI.setUnavailable(LibFunc::utime);
|
|
|
|
TLI.setUnavailable(LibFunc::utimes);
|
|
|
|
TLI.setUnavailable(LibFunc::write);
|
2012-11-22 16:36:42 +01:00
|
|
|
|
2013-03-05 22:47:40 +01:00
|
|
|
// Win32 does *not* provide provide these functions, but they are
|
|
|
|
// specified by C99:
|
|
|
|
TLI.setUnavailable(LibFunc::atoll);
|
|
|
|
TLI.setUnavailable(LibFunc::frexpf);
|
2012-11-22 16:36:42 +01:00
|
|
|
TLI.setUnavailable(LibFunc::llabs);
|
2013-12-26 20:17:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (T.getOS()) {
|
|
|
|
case Triple::MacOSX:
|
2013-12-28 03:40:19 +01:00
|
|
|
// exp10 and exp10f are not available on OS X until 10.9 and iOS until 7.0
|
|
|
|
// and their names are __exp10 and __exp10f. exp10l is not available on
|
|
|
|
// OS X or iOS.
|
2013-12-26 20:17:04 +01:00
|
|
|
TLI.setUnavailable(LibFunc::exp10l);
|
|
|
|
if (T.isMacOSXVersionLT(10, 9)) {
|
|
|
|
TLI.setUnavailable(LibFunc::exp10);
|
|
|
|
TLI.setUnavailable(LibFunc::exp10f);
|
|
|
|
} else {
|
|
|
|
TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
|
|
|
|
TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Triple::IOS:
|
2015-11-02 19:00:00 +01:00
|
|
|
case Triple::TvOS:
|
2015-10-28 23:51:16 +01:00
|
|
|
case Triple::WatchOS:
|
2013-12-26 20:17:04 +01:00
|
|
|
TLI.setUnavailable(LibFunc::exp10l);
|
2015-10-28 23:51:16 +01:00
|
|
|
if (!T.isWatchOS() && (T.isOSVersionLT(7, 0) ||
|
|
|
|
(T.isOSVersionLT(9, 0) &&
|
|
|
|
(T.getArch() == Triple::x86 ||
|
|
|
|
T.getArch() == Triple::x86_64)))) {
|
2013-12-26 20:17:04 +01:00
|
|
|
TLI.setUnavailable(LibFunc::exp10);
|
|
|
|
TLI.setUnavailable(LibFunc::exp10f);
|
|
|
|
} else {
|
|
|
|
TLI.setAvailableWithName(LibFunc::exp10, "__exp10");
|
|
|
|
TLI.setAvailableWithName(LibFunc::exp10f, "__exp10f");
|
|
|
|
}
|
|
|
|
break;
|
2013-12-28 03:40:19 +01:00
|
|
|
case Triple::Linux:
|
|
|
|
// exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
|
|
|
|
// buggy prior to glibc version 2.18. Until this version is widely deployed
|
|
|
|
// or we have a reasonable detection strategy, we cannot use exp10 reliably
|
|
|
|
// on Linux.
|
|
|
|
//
|
|
|
|
// Fall through to disable all of them.
|
2013-12-26 20:17:04 +01:00
|
|
|
default:
|
|
|
|
TLI.setUnavailable(LibFunc::exp10);
|
|
|
|
TLI.setUnavailable(LibFunc::exp10f);
|
|
|
|
TLI.setUnavailable(LibFunc::exp10l);
|
2012-11-22 16:36:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
|
|
|
|
// Linux (GLIBC):
|
|
|
|
// http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/ffsl.3.html
|
2015-11-01 18:00:13 +01:00
|
|
|
// http://svn.freebsd.org/base/head/lib/libc/string/ffsl.c
|
2012-11-22 16:36:42 +01:00
|
|
|
// http://www.gnu.org/software/gnulib/manual/html_node/ffsl.html
|
|
|
|
switch (T.getOS()) {
|
|
|
|
case Triple::Darwin:
|
|
|
|
case Triple::MacOSX:
|
|
|
|
case Triple::IOS:
|
2015-11-02 19:00:00 +01:00
|
|
|
case Triple::TvOS:
|
2015-10-28 23:51:16 +01:00
|
|
|
case Triple::WatchOS:
|
2012-11-22 16:36:42 +01:00
|
|
|
case Triple::FreeBSD:
|
|
|
|
case Triple::Linux:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
TLI.setUnavailable(LibFunc::ffsl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ffsll is available on at least FreeBSD and Linux (GLIBC):
|
2015-11-01 18:00:13 +01:00
|
|
|
// http://svn.freebsd.org/base/head/lib/libc/string/ffsll.c
|
2012-11-22 16:36:42 +01:00
|
|
|
// http://www.gnu.org/software/gnulib/manual/html_node/ffsll.html
|
|
|
|
switch (T.getOS()) {
|
2015-11-02 19:00:00 +01:00
|
|
|
case Triple::Darwin:
|
|
|
|
case Triple::MacOSX:
|
|
|
|
case Triple::IOS:
|
|
|
|
case Triple::TvOS:
|
|
|
|
case Triple::WatchOS:
|
2012-11-22 16:36:42 +01:00
|
|
|
case Triple::FreeBSD:
|
|
|
|
case Triple::Linux:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
TLI.setUnavailable(LibFunc::ffsll);
|
2012-04-18 01:05:54 +02:00
|
|
|
}
|
2013-03-05 22:47:40 +01:00
|
|
|
|
2015-11-10 00:23:20 +01:00
|
|
|
// The following functions are available on at least FreeBSD:
|
|
|
|
// http://svn.freebsd.org/base/head/lib/libc/string/fls.c
|
|
|
|
// http://svn.freebsd.org/base/head/lib/libc/string/flsl.c
|
|
|
|
// http://svn.freebsd.org/base/head/lib/libc/string/flsll.c
|
|
|
|
if (!T.isOSFreeBSD()) {
|
|
|
|
TLI.setUnavailable(LibFunc::fls);
|
|
|
|
TLI.setUnavailable(LibFunc::flsl);
|
|
|
|
TLI.setUnavailable(LibFunc::flsll);
|
|
|
|
}
|
|
|
|
|
2013-03-05 22:47:40 +01:00
|
|
|
// The following functions are available on at least Linux:
|
2013-08-29 22:23:14 +02:00
|
|
|
if (!T.isOSLinux()) {
|
2013-03-05 22:47:40 +01:00
|
|
|
TLI.setUnavailable(LibFunc::dunder_strdup);
|
|
|
|
TLI.setUnavailable(LibFunc::dunder_strtok_r);
|
|
|
|
TLI.setUnavailable(LibFunc::dunder_isoc99_scanf);
|
|
|
|
TLI.setUnavailable(LibFunc::dunder_isoc99_sscanf);
|
|
|
|
TLI.setUnavailable(LibFunc::under_IO_getc);
|
|
|
|
TLI.setUnavailable(LibFunc::under_IO_putc);
|
|
|
|
TLI.setUnavailable(LibFunc::memalign);
|
|
|
|
TLI.setUnavailable(LibFunc::fopen64);
|
|
|
|
TLI.setUnavailable(LibFunc::fseeko64);
|
|
|
|
TLI.setUnavailable(LibFunc::fstat64);
|
|
|
|
TLI.setUnavailable(LibFunc::fstatvfs64);
|
|
|
|
TLI.setUnavailable(LibFunc::ftello64);
|
|
|
|
TLI.setUnavailable(LibFunc::lstat64);
|
|
|
|
TLI.setUnavailable(LibFunc::open64);
|
|
|
|
TLI.setUnavailable(LibFunc::stat64);
|
|
|
|
TLI.setUnavailable(LibFunc::statvfs64);
|
|
|
|
TLI.setUnavailable(LibFunc::tmpfile64);
|
|
|
|
}
|
2015-03-17 20:50:55 +01:00
|
|
|
|
2016-01-27 00:51:06 +01:00
|
|
|
// As currently implemented in clang, NVPTX code has no standard library to
|
|
|
|
// speak of. Headers provide a standard-ish library implementation, but many
|
|
|
|
// of the signatures are wrong -- for example, many libm functions are not
|
|
|
|
// extern "C".
|
|
|
|
//
|
|
|
|
// libdevice, an IR library provided by nvidia, is linked in by the front-end,
|
|
|
|
// but only used functions are provided to llvm. Moreover, most of the
|
|
|
|
// functions in libdevice don't map precisely to standard library functions.
|
|
|
|
//
|
|
|
|
// FIXME: Having no standard library prevents e.g. many fastmath
|
|
|
|
// optimizations, so this situation should be fixed.
|
2016-03-31 23:29:57 +02:00
|
|
|
if (T.isNVPTX()) {
|
2016-01-27 00:51:06 +01:00
|
|
|
TLI.disableAllFunctions();
|
2016-03-31 23:29:57 +02:00
|
|
|
TLI.setAvailable(LibFunc::nvvm_reflect);
|
|
|
|
} else {
|
|
|
|
TLI.setUnavailable(LibFunc::nvvm_reflect);
|
|
|
|
}
|
2016-01-27 00:51:06 +01:00
|
|
|
|
2015-03-17 20:50:55 +01:00
|
|
|
TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
|
2011-02-18 22:50:34 +01:00
|
|
|
}
|
|
|
|
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
TargetLibraryInfoImpl::TargetLibraryInfoImpl() {
|
2011-02-18 22:50:34 +01:00
|
|
|
// Default to everything being available.
|
|
|
|
memset(AvailableArray, -1, sizeof(AvailableArray));
|
|
|
|
|
2012-08-03 06:06:22 +02:00
|
|
|
initialize(*this, Triple(), StandardNames);
|
2011-02-18 22:50:34 +01:00
|
|
|
}
|
|
|
|
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
|
2011-02-18 22:50:34 +01:00
|
|
|
// Default to everything being available.
|
|
|
|
memset(AvailableArray, -1, sizeof(AvailableArray));
|
2015-01-15 11:41:28 +01:00
|
|
|
|
2012-08-03 06:06:22 +02:00
|
|
|
initialize(*this, T, StandardNames);
|
2011-02-18 22:50:34 +01:00
|
|
|
}
|
2011-02-18 23:34:03 +01:00
|
|
|
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
|
2015-01-15 12:39:46 +01:00
|
|
|
: CustomNames(TLI.CustomNames) {
|
2011-05-21 22:09:13 +02:00
|
|
|
memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
|
2015-03-17 20:22:30 +01:00
|
|
|
VectorDescs = TLI.VectorDescs;
|
|
|
|
ScalarDescs = TLI.ScalarDescs;
|
2015-01-15 12:39:46 +01:00
|
|
|
}
|
|
|
|
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
|
2015-01-15 12:39:46 +01:00
|
|
|
: CustomNames(std::move(TLI.CustomNames)) {
|
|
|
|
std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
|
|
|
|
AvailableArray);
|
2015-03-17 20:22:30 +01:00
|
|
|
VectorDescs = TLI.VectorDescs;
|
|
|
|
ScalarDescs = TLI.ScalarDescs;
|
2015-01-15 12:39:46 +01:00
|
|
|
}
|
|
|
|
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
|
2011-11-17 02:27:36 +01:00
|
|
|
CustomNames = TLI.CustomNames;
|
2015-01-15 12:39:46 +01:00
|
|
|
memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) {
|
2015-01-15 12:39:46 +01:00
|
|
|
CustomNames = std::move(TLI.CustomNames);
|
|
|
|
std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
|
|
|
|
AvailableArray);
|
|
|
|
return *this;
|
2011-05-21 22:09:13 +02:00
|
|
|
}
|
|
|
|
|
2015-03-03 00:24:40 +01:00
|
|
|
static StringRef sanitizeFunctionName(StringRef funcName) {
|
2013-03-09 14:48:23 +01:00
|
|
|
// Filter out empty names and names containing null bytes, those can't be in
|
|
|
|
// our table.
|
|
|
|
if (funcName.empty() || funcName.find('\0') != StringRef::npos)
|
2015-03-03 00:24:40 +01:00
|
|
|
return StringRef();
|
2013-03-09 14:48:23 +01:00
|
|
|
|
2013-03-05 22:47:40 +01:00
|
|
|
// Check for \01 prefix that is used to mangle __asm declarations and
|
|
|
|
// strip it if present.
|
2015-03-31 00:58:10 +02:00
|
|
|
return GlobalValue::getRealLinkageName(funcName);
|
2015-03-03 00:24:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TargetLibraryInfoImpl::getLibFunc(StringRef funcName,
|
2016-04-27 21:04:29 +02:00
|
|
|
LibFunc::Func &F) const {
|
2015-03-08 17:07:39 +01:00
|
|
|
const char *const *Start = &StandardNames[0];
|
|
|
|
const char *const *End = &StandardNames[LibFunc::NumLibFuncs];
|
2015-03-03 00:24:40 +01:00
|
|
|
|
|
|
|
funcName = sanitizeFunctionName(funcName);
|
|
|
|
if (funcName.empty())
|
|
|
|
return false;
|
|
|
|
|
2015-03-08 17:07:39 +01:00
|
|
|
const char *const *I = std::lower_bound(
|
2015-03-02 21:50:08 +01:00
|
|
|
Start, End, funcName, [](const char *LHS, StringRef RHS) {
|
|
|
|
return std::strncmp(LHS, RHS.data(), RHS.size()) < 0;
|
|
|
|
});
|
2012-08-03 06:06:22 +02:00
|
|
|
if (I != End && *I == funcName) {
|
|
|
|
F = (LibFunc::Func)(I - Start);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-21 22:09:13 +02:00
|
|
|
|
2016-04-27 21:04:35 +02:00
|
|
|
bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
|
|
|
|
LibFunc::Func F,
|
|
|
|
const DataLayout *DL) const {
|
|
|
|
LLVMContext &Ctx = FTy.getContext();
|
|
|
|
Type *PCharTy = Type::getInt8PtrTy(Ctx);
|
|
|
|
Type *SizeTTy = DL ? DL->getIntPtrType(Ctx, /*AS=*/0) : nullptr;
|
|
|
|
auto IsSizeTTy = [SizeTTy](Type *Ty) {
|
|
|
|
return SizeTTy ? Ty == SizeTTy : Ty->isIntegerTy();
|
|
|
|
};
|
|
|
|
unsigned NumParams = FTy.getNumParams();
|
|
|
|
|
|
|
|
switch (F) {
|
|
|
|
case LibFunc::strlen:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getReturnType()->isIntegerTy());
|
|
|
|
|
|
|
|
case LibFunc::strchr:
|
|
|
|
case LibFunc::strrchr:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(0) == FTy.getReturnType() &&
|
|
|
|
FTy.getParamType(1)->isIntegerTy());
|
|
|
|
|
|
|
|
case LibFunc::strtol:
|
|
|
|
case LibFunc::strtod:
|
|
|
|
case LibFunc::strtof:
|
|
|
|
case LibFunc::strtoul:
|
|
|
|
case LibFunc::strtoll:
|
|
|
|
case LibFunc::strtold:
|
|
|
|
case LibFunc::strtoull:
|
|
|
|
return ((NumParams == 2 || NumParams == 3) &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::strcat:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(0) == FTy.getReturnType() &&
|
|
|
|
FTy.getParamType(1) == FTy.getReturnType());
|
|
|
|
|
|
|
|
case LibFunc::strncat:
|
|
|
|
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(0) == FTy.getReturnType() &&
|
|
|
|
FTy.getParamType(1) == FTy.getReturnType() &&
|
|
|
|
FTy.getParamType(2)->isIntegerTy());
|
|
|
|
|
|
|
|
case LibFunc::strcpy_chk:
|
|
|
|
case LibFunc::stpcpy_chk:
|
|
|
|
--NumParams;
|
|
|
|
if (!IsSizeTTy(FTy.getParamType(NumParams)))
|
|
|
|
return false;
|
|
|
|
// fallthrough
|
|
|
|
case LibFunc::strcpy:
|
|
|
|
case LibFunc::stpcpy:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType() == FTy.getParamType(0) &&
|
|
|
|
FTy.getParamType(0) == FTy.getParamType(1) &&
|
|
|
|
FTy.getParamType(0) == PCharTy);
|
|
|
|
|
|
|
|
case LibFunc::strncpy_chk:
|
|
|
|
case LibFunc::stpncpy_chk:
|
|
|
|
--NumParams;
|
|
|
|
if (!IsSizeTTy(FTy.getParamType(NumParams)))
|
|
|
|
return false;
|
|
|
|
// fallthrough
|
|
|
|
case LibFunc::strncpy:
|
|
|
|
case LibFunc::stpncpy:
|
|
|
|
return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
|
|
|
|
FTy.getParamType(0) == FTy.getParamType(1) &&
|
|
|
|
FTy.getParamType(0) == PCharTy &&
|
|
|
|
FTy.getParamType(2)->isIntegerTy());
|
|
|
|
|
|
|
|
case LibFunc::strxfrm:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
|
|
|
|
case LibFunc::strcmp:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType()->isIntegerTy(32) &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(0) == FTy.getParamType(1));
|
|
|
|
|
|
|
|
case LibFunc::strncmp:
|
|
|
|
return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(0) == FTy.getParamType(1) &&
|
|
|
|
FTy.getParamType(2)->isIntegerTy());
|
|
|
|
|
|
|
|
case LibFunc::strspn:
|
|
|
|
case LibFunc::strcspn:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(0) == FTy.getParamType(1) &&
|
|
|
|
FTy.getReturnType()->isIntegerTy());
|
|
|
|
|
|
|
|
case LibFunc::strcoll:
|
|
|
|
case LibFunc::strcasecmp:
|
|
|
|
case LibFunc::strncasecmp:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
|
|
|
|
case LibFunc::strstr:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
|
|
|
|
case LibFunc::strpbrk:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getReturnType() == FTy.getParamType(0) &&
|
|
|
|
FTy.getParamType(0) == FTy.getParamType(1));
|
|
|
|
|
|
|
|
case LibFunc::strtok:
|
|
|
|
case LibFunc::strtok_r:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::scanf:
|
|
|
|
return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::setbuf:
|
|
|
|
case LibFunc::setvbuf:
|
|
|
|
return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::strdup:
|
|
|
|
case LibFunc::strndup:
|
|
|
|
return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::stat:
|
|
|
|
case LibFunc::statvfs:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::sscanf:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::sprintf:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::snprintf:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(2)->isPointerTy());
|
|
|
|
case LibFunc::setitimer:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
|
|
|
|
FTy.getParamType(2)->isPointerTy());
|
|
|
|
case LibFunc::system:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::malloc:
|
|
|
|
return (NumParams == 1 && FTy.getReturnType()->isPointerTy());
|
|
|
|
case LibFunc::memcmp:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy() &&
|
|
|
|
FTy.getReturnType()->isIntegerTy(32));
|
|
|
|
|
|
|
|
case LibFunc::memchr:
|
|
|
|
case LibFunc::memrchr:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isIntegerTy(32) &&
|
|
|
|
FTy.getParamType(2)->isIntegerTy() &&
|
|
|
|
FTy.getReturnType()->isPointerTy());
|
|
|
|
case LibFunc::modf:
|
|
|
|
case LibFunc::modff:
|
|
|
|
case LibFunc::modfl:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
|
|
|
|
case LibFunc::memcpy_chk:
|
|
|
|
case LibFunc::memmove_chk:
|
|
|
|
--NumParams;
|
|
|
|
if (!IsSizeTTy(FTy.getParamType(NumParams)))
|
|
|
|
return false;
|
|
|
|
// fallthrough
|
|
|
|
case LibFunc::memcpy:
|
|
|
|
case LibFunc::memmove:
|
|
|
|
return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy() &&
|
|
|
|
IsSizeTTy(FTy.getParamType(2)));
|
|
|
|
|
|
|
|
case LibFunc::memset_chk:
|
|
|
|
--NumParams;
|
|
|
|
if (!IsSizeTTy(FTy.getParamType(NumParams)))
|
|
|
|
return false;
|
|
|
|
// fallthrough
|
|
|
|
case LibFunc::memset:
|
|
|
|
return (NumParams == 3 && FTy.getReturnType() == FTy.getParamType(0) &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isIntegerTy() &&
|
|
|
|
IsSizeTTy(FTy.getParamType(2)));
|
|
|
|
|
|
|
|
case LibFunc::memccpy:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::memalign:
|
|
|
|
return (FTy.getReturnType()->isPointerTy());
|
|
|
|
case LibFunc::mkdir:
|
|
|
|
return (NumParams == 0 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::mktime:
|
|
|
|
return (NumParams == 0 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::realloc:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getReturnType()->isPointerTy());
|
|
|
|
case LibFunc::read:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::rewind:
|
|
|
|
return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::rmdir:
|
|
|
|
case LibFunc::remove:
|
|
|
|
case LibFunc::realpath:
|
|
|
|
return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::rename:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::readlink:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::write:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::bcopy:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::bcmp:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::bzero:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::calloc:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType()->isPointerTy());
|
|
|
|
case LibFunc::chmod:
|
|
|
|
case LibFunc::chown:
|
|
|
|
return (NumParams == 0 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::ctermid:
|
|
|
|
case LibFunc::clearerr:
|
|
|
|
case LibFunc::closedir:
|
|
|
|
return (NumParams == 0 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::atoi:
|
|
|
|
case LibFunc::atol:
|
|
|
|
case LibFunc::atof:
|
|
|
|
case LibFunc::atoll:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::access:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::fopen:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::fdopen:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::feof:
|
|
|
|
case LibFunc::free:
|
|
|
|
case LibFunc::fseek:
|
|
|
|
case LibFunc::ftell:
|
|
|
|
case LibFunc::fgetc:
|
|
|
|
case LibFunc::fseeko:
|
|
|
|
case LibFunc::ftello:
|
|
|
|
case LibFunc::fileno:
|
|
|
|
case LibFunc::fflush:
|
|
|
|
case LibFunc::fclose:
|
|
|
|
case LibFunc::fsetpos:
|
|
|
|
case LibFunc::flockfile:
|
|
|
|
case LibFunc::funlockfile:
|
|
|
|
case LibFunc::ftrylockfile:
|
|
|
|
return (NumParams == 0 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::ferror:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::fputc:
|
|
|
|
case LibFunc::fstat:
|
|
|
|
case LibFunc::frexp:
|
|
|
|
case LibFunc::frexpf:
|
|
|
|
case LibFunc::frexpl:
|
|
|
|
case LibFunc::fstatvfs:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::fgets:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(2)->isPointerTy());
|
|
|
|
case LibFunc::fread:
|
|
|
|
return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(3)->isPointerTy());
|
|
|
|
case LibFunc::fwrite:
|
|
|
|
return (NumParams == 4 && FTy.getReturnType()->isIntegerTy() &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isIntegerTy() &&
|
|
|
|
FTy.getParamType(2)->isIntegerTy() &&
|
|
|
|
FTy.getParamType(3)->isPointerTy());
|
|
|
|
case LibFunc::fputs:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::fscanf:
|
|
|
|
case LibFunc::fprintf:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::fgetpos:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::getc:
|
|
|
|
case LibFunc::getlogin_r:
|
|
|
|
case LibFunc::getc_unlocked:
|
|
|
|
return (NumParams == 0 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::getenv:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::gets:
|
|
|
|
case LibFunc::getchar:
|
|
|
|
case LibFunc::getitimer:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::getpwnam:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::ungetc:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::uname:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::unlink:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::unsetenv:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::utime:
|
|
|
|
case LibFunc::utimes:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::putc:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::puts:
|
|
|
|
case LibFunc::printf:
|
|
|
|
case LibFunc::perror:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::pread:
|
|
|
|
case LibFunc::pwrite:
|
|
|
|
return (NumParams == 4 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::putchar:
|
|
|
|
case LibFunc::popen:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::pclose:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::vscanf:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::vsscanf:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
|
|
|
|
FTy.getParamType(2)->isPointerTy());
|
|
|
|
case LibFunc::vfscanf:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(1)->isPointerTy() &&
|
|
|
|
FTy.getParamType(2)->isPointerTy());
|
|
|
|
case LibFunc::valloc:
|
|
|
|
return (FTy.getReturnType()->isPointerTy());
|
|
|
|
case LibFunc::vprintf:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::vfprintf:
|
|
|
|
case LibFunc::vsprintf:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::vsnprintf:
|
|
|
|
return (NumParams == 4 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(2)->isPointerTy());
|
|
|
|
case LibFunc::open:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::opendir:
|
|
|
|
return (NumParams == 1 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::tmpfile:
|
|
|
|
return (FTy.getReturnType()->isPointerTy());
|
|
|
|
case LibFunc::times:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::htonl:
|
|
|
|
case LibFunc::htons:
|
|
|
|
case LibFunc::ntohl:
|
|
|
|
case LibFunc::ntohs:
|
|
|
|
case LibFunc::lstat:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::lchown:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::qsort:
|
|
|
|
return (NumParams == 4 && FTy.getParamType(3)->isPointerTy());
|
|
|
|
case LibFunc::dunder_strdup:
|
|
|
|
case LibFunc::dunder_strndup:
|
|
|
|
return (NumParams >= 1 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::dunder_strtok_r:
|
|
|
|
return (NumParams == 3 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::under_IO_getc:
|
|
|
|
return (NumParams == 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::under_IO_putc:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::dunder_isoc99_scanf:
|
|
|
|
return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::stat64:
|
|
|
|
case LibFunc::lstat64:
|
|
|
|
case LibFunc::statvfs64:
|
|
|
|
return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::dunder_isoc99_sscanf:
|
|
|
|
return (NumParams >= 1 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::fopen64:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::fseeko64:
|
|
|
|
case LibFunc::ftello64:
|
|
|
|
return (NumParams == 0 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::tmpfile64:
|
|
|
|
return (FTy.getReturnType()->isPointerTy());
|
|
|
|
case LibFunc::fstat64:
|
|
|
|
case LibFunc::fstatvfs64:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(1)->isPointerTy());
|
|
|
|
case LibFunc::open64:
|
|
|
|
return (NumParams >= 2 && FTy.getParamType(0)->isPointerTy());
|
|
|
|
case LibFunc::gettimeofday:
|
|
|
|
return (NumParams == 2 && FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy());
|
|
|
|
|
|
|
|
case LibFunc::Znwj: // new(unsigned int);
|
|
|
|
case LibFunc::Znwm: // new(unsigned long);
|
|
|
|
case LibFunc::Znaj: // new[](unsigned int);
|
|
|
|
case LibFunc::Znam: // new[](unsigned long);
|
|
|
|
case LibFunc::msvc_new_int: // new(unsigned int);
|
|
|
|
case LibFunc::msvc_new_longlong: // new(unsigned long long);
|
|
|
|
case LibFunc::msvc_new_array_int: // new[](unsigned int);
|
|
|
|
case LibFunc::msvc_new_array_longlong: // new[](unsigned long long);
|
|
|
|
return (NumParams == 1);
|
|
|
|
|
|
|
|
case LibFunc::memset_pattern16:
|
|
|
|
return (!FTy.isVarArg() && NumParams == 3 &&
|
|
|
|
isa<PointerType>(FTy.getParamType(0)) &&
|
|
|
|
isa<PointerType>(FTy.getParamType(1)) &&
|
|
|
|
isa<IntegerType>(FTy.getParamType(2)));
|
|
|
|
|
|
|
|
// int __nvvm_reflect(const char *);
|
|
|
|
case LibFunc::nvvm_reflect:
|
|
|
|
return (NumParams == 1 && isa<PointerType>(FTy.getParamType(0)));
|
|
|
|
|
|
|
|
case LibFunc::sin:
|
|
|
|
case LibFunc::sinf:
|
|
|
|
case LibFunc::sinl:
|
|
|
|
case LibFunc::cos:
|
|
|
|
case LibFunc::cosf:
|
|
|
|
case LibFunc::cosl:
|
|
|
|
case LibFunc::exp:
|
|
|
|
case LibFunc::expf:
|
|
|
|
case LibFunc::expl:
|
|
|
|
case LibFunc::exp2:
|
|
|
|
case LibFunc::exp2f:
|
|
|
|
case LibFunc::exp2l:
|
|
|
|
case LibFunc::log:
|
|
|
|
case LibFunc::logf:
|
|
|
|
case LibFunc::logl:
|
|
|
|
case LibFunc::log10:
|
|
|
|
case LibFunc::log10f:
|
|
|
|
case LibFunc::log10l:
|
|
|
|
case LibFunc::log2:
|
|
|
|
case LibFunc::log2f:
|
|
|
|
case LibFunc::log2l:
|
|
|
|
case LibFunc::fabs:
|
|
|
|
case LibFunc::fabsf:
|
|
|
|
case LibFunc::fabsl:
|
|
|
|
case LibFunc::floor:
|
|
|
|
case LibFunc::floorf:
|
|
|
|
case LibFunc::floorl:
|
|
|
|
case LibFunc::ceil:
|
|
|
|
case LibFunc::ceilf:
|
|
|
|
case LibFunc::ceill:
|
|
|
|
case LibFunc::trunc:
|
|
|
|
case LibFunc::truncf:
|
|
|
|
case LibFunc::truncl:
|
|
|
|
case LibFunc::rint:
|
|
|
|
case LibFunc::rintf:
|
|
|
|
case LibFunc::rintl:
|
|
|
|
case LibFunc::nearbyint:
|
|
|
|
case LibFunc::nearbyintf:
|
|
|
|
case LibFunc::nearbyintl:
|
|
|
|
case LibFunc::round:
|
|
|
|
case LibFunc::roundf:
|
|
|
|
case LibFunc::roundl:
|
|
|
|
case LibFunc::sqrt:
|
|
|
|
case LibFunc::sqrtf:
|
|
|
|
case LibFunc::sqrtl:
|
|
|
|
return (NumParams == 1 && FTy.getReturnType()->isFloatingPointTy() &&
|
|
|
|
FTy.getReturnType() == FTy.getParamType(0));
|
|
|
|
|
|
|
|
case LibFunc::fmin:
|
|
|
|
case LibFunc::fminf:
|
|
|
|
case LibFunc::fminl:
|
|
|
|
case LibFunc::fmax:
|
|
|
|
case LibFunc::fmaxf:
|
|
|
|
case LibFunc::fmaxl:
|
|
|
|
case LibFunc::copysign:
|
|
|
|
case LibFunc::copysignf:
|
|
|
|
case LibFunc::copysignl:
|
|
|
|
case LibFunc::pow:
|
|
|
|
case LibFunc::powf:
|
|
|
|
case LibFunc::powl:
|
|
|
|
return (NumParams == 2 && FTy.getReturnType()->isFloatingPointTy() &&
|
|
|
|
FTy.getReturnType() == FTy.getParamType(0) &&
|
|
|
|
FTy.getReturnType() == FTy.getParamType(1));
|
|
|
|
|
|
|
|
case LibFunc::ffs:
|
|
|
|
case LibFunc::ffsl:
|
|
|
|
case LibFunc::ffsll:
|
|
|
|
case LibFunc::isdigit:
|
|
|
|
case LibFunc::isascii:
|
|
|
|
case LibFunc::toascii:
|
|
|
|
return (NumParams == 1 && FTy.getReturnType()->isIntegerTy(32) &&
|
|
|
|
FTy.getParamType(0)->isIntegerTy());
|
|
|
|
|
|
|
|
case LibFunc::fls:
|
|
|
|
case LibFunc::flsl:
|
|
|
|
case LibFunc::flsll:
|
|
|
|
case LibFunc::abs:
|
|
|
|
case LibFunc::labs:
|
|
|
|
case LibFunc::llabs:
|
|
|
|
return (NumParams == 1 && FTy.getReturnType()->isIntegerTy() &&
|
|
|
|
FTy.getReturnType() == FTy.getParamType(0));
|
|
|
|
|
|
|
|
case LibFunc::cxa_atexit:
|
|
|
|
return (NumParams == 3 && FTy.getReturnType()->isIntegerTy() &&
|
|
|
|
FTy.getParamType(0)->isPointerTy() &&
|
|
|
|
FTy.getParamType(1)->isPointerTy() &&
|
|
|
|
FTy.getParamType(2)->isPointerTy());
|
|
|
|
|
|
|
|
case LibFunc::sinpi:
|
|
|
|
case LibFunc::cospi:
|
|
|
|
return (NumParams == 1 && FTy.getReturnType()->isDoubleTy() &&
|
|
|
|
FTy.getReturnType() == FTy.getParamType(0));
|
|
|
|
|
|
|
|
case LibFunc::sinpif:
|
|
|
|
case LibFunc::cospif:
|
|
|
|
return (NumParams == 1 && FTy.getReturnType()->isFloatTy() &&
|
|
|
|
FTy.getReturnType() == FTy.getParamType(0));
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Assume the other functions are correct.
|
|
|
|
// FIXME: It'd be really nice to cover them all.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
|
|
|
|
LibFunc::Func &F) const {
|
|
|
|
const DataLayout *DL =
|
|
|
|
FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
|
|
|
|
return getLibFunc(FDecl.getName(), F) &&
|
|
|
|
isValidProtoForLibFunc(*FDecl.getFunctionType(), F, DL);
|
|
|
|
}
|
|
|
|
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
void TargetLibraryInfoImpl::disableAllFunctions() {
|
2011-02-18 23:34:03 +01:00
|
|
|
memset(AvailableArray, 0, sizeof(AvailableArray));
|
|
|
|
}
|
2015-01-15 11:41:28 +01:00
|
|
|
|
2015-03-17 20:22:30 +01:00
|
|
|
static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
|
|
|
|
return std::strncmp(LHS.ScalarFnName, RHS.ScalarFnName,
|
|
|
|
std::strlen(RHS.ScalarFnName)) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
|
|
|
|
return std::strncmp(LHS.VectorFnName, RHS.VectorFnName,
|
|
|
|
std::strlen(RHS.VectorFnName)) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
|
|
|
|
return std::strncmp(LHS.ScalarFnName, S.data(), S.size()) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool compareWithVectorFnName(const VecDesc &LHS, StringRef S) {
|
|
|
|
return std::strncmp(LHS.VectorFnName, S.data(), S.size()) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
|
|
|
|
VectorDescs.insert(VectorDescs.end(), Fns.begin(), Fns.end());
|
|
|
|
std::sort(VectorDescs.begin(), VectorDescs.end(), compareByScalarFnName);
|
|
|
|
|
|
|
|
ScalarDescs.insert(ScalarDescs.end(), Fns.begin(), Fns.end());
|
|
|
|
std::sort(ScalarDescs.begin(), ScalarDescs.end(), compareByVectorFnName);
|
|
|
|
}
|
|
|
|
|
2015-03-17 20:50:55 +01:00
|
|
|
void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
|
|
|
|
enum VectorLibrary VecLib) {
|
|
|
|
switch (VecLib) {
|
|
|
|
case Accelerate: {
|
|
|
|
const VecDesc VecFuncs[] = {
|
2015-05-07 19:11:51 +02:00
|
|
|
// Floating-Point Arithmetic and Auxiliary Functions
|
|
|
|
{"ceilf", "vceilf", 4},
|
|
|
|
{"fabsf", "vfabsf", 4},
|
|
|
|
{"llvm.fabs.f32", "vfabsf", 4},
|
|
|
|
{"floorf", "vfloorf", 4},
|
|
|
|
{"sqrtf", "vsqrtf", 4},
|
|
|
|
{"llvm.sqrt.f32", "vsqrtf", 4},
|
|
|
|
|
|
|
|
// Exponential and Logarithmic Functions
|
2015-03-17 20:50:55 +01:00
|
|
|
{"expf", "vexpf", 4},
|
|
|
|
{"llvm.exp.f32", "vexpf", 4},
|
2015-05-07 19:11:51 +02:00
|
|
|
{"expm1f", "vexpm1f", 4},
|
2015-03-17 20:50:55 +01:00
|
|
|
{"logf", "vlogf", 4},
|
|
|
|
{"llvm.log.f32", "vlogf", 4},
|
2015-05-07 19:11:51 +02:00
|
|
|
{"log1pf", "vlog1pf", 4},
|
|
|
|
{"log10f", "vlog10f", 4},
|
|
|
|
{"llvm.log10.f32", "vlog10f", 4},
|
|
|
|
{"logbf", "vlogbf", 4},
|
|
|
|
|
|
|
|
// Trigonometric Functions
|
|
|
|
{"sinf", "vsinf", 4},
|
|
|
|
{"llvm.sin.f32", "vsinf", 4},
|
|
|
|
{"cosf", "vcosf", 4},
|
|
|
|
{"llvm.cos.f32", "vcosf", 4},
|
|
|
|
{"tanf", "vtanf", 4},
|
|
|
|
{"asinf", "vasinf", 4},
|
|
|
|
{"acosf", "vacosf", 4},
|
|
|
|
{"atanf", "vatanf", 4},
|
|
|
|
|
|
|
|
// Hyperbolic Functions
|
|
|
|
{"sinhf", "vsinhf", 4},
|
|
|
|
{"coshf", "vcoshf", 4},
|
|
|
|
{"tanhf", "vtanhf", 4},
|
|
|
|
{"asinhf", "vasinhf", 4},
|
|
|
|
{"acoshf", "vacoshf", 4},
|
|
|
|
{"atanhf", "vatanhf", 4},
|
2015-03-17 20:50:55 +01:00
|
|
|
};
|
|
|
|
addVectorizableFunctions(VecFuncs);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NoLibrary:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 20:22:30 +01:00
|
|
|
bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
|
|
|
|
funcName = sanitizeFunctionName(funcName);
|
|
|
|
if (funcName.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<VecDesc>::const_iterator I = std::lower_bound(
|
|
|
|
VectorDescs.begin(), VectorDescs.end(), funcName,
|
|
|
|
compareWithScalarFnName);
|
|
|
|
return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
|
|
|
|
unsigned VF) const {
|
|
|
|
F = sanitizeFunctionName(F);
|
|
|
|
if (F.empty())
|
|
|
|
return F;
|
|
|
|
std::vector<VecDesc>::const_iterator I = std::lower_bound(
|
|
|
|
VectorDescs.begin(), VectorDescs.end(), F, compareWithScalarFnName);
|
|
|
|
while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
|
|
|
|
if (I->VectorizationFactor == VF)
|
|
|
|
return I->VectorFnName;
|
|
|
|
++I;
|
|
|
|
}
|
|
|
|
return StringRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef TargetLibraryInfoImpl::getScalarizedFunction(StringRef F,
|
|
|
|
unsigned &VF) const {
|
|
|
|
F = sanitizeFunctionName(F);
|
|
|
|
if (F.empty())
|
|
|
|
return F;
|
|
|
|
|
|
|
|
std::vector<VecDesc>::const_iterator I = std::lower_bound(
|
|
|
|
ScalarDescs.begin(), ScalarDescs.end(), F, compareWithVectorFnName);
|
|
|
|
if (I == VectorDescs.end() || StringRef(I->VectorFnName) != F)
|
|
|
|
return StringRef();
|
|
|
|
VF = I->VectorizationFactor;
|
|
|
|
return I->ScalarFnName;
|
|
|
|
}
|
|
|
|
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
TargetLibraryInfo TargetLibraryAnalysis::run(Module &M) {
|
|
|
|
if (PresetInfoImpl)
|
|
|
|
return TargetLibraryInfo(*PresetInfoImpl);
|
|
|
|
|
|
|
|
return TargetLibraryInfo(lookupInfoImpl(Triple(M.getTargetTriple())));
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetLibraryInfo TargetLibraryAnalysis::run(Function &F) {
|
|
|
|
if (PresetInfoImpl)
|
|
|
|
return TargetLibraryInfo(*PresetInfoImpl);
|
|
|
|
|
|
|
|
return TargetLibraryInfo(
|
|
|
|
lookupInfoImpl(Triple(F.getParent()->getTargetTriple())));
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetLibraryInfoImpl &TargetLibraryAnalysis::lookupInfoImpl(Triple T) {
|
|
|
|
std::unique_ptr<TargetLibraryInfoImpl> &Impl =
|
|
|
|
Impls[T.normalize()];
|
|
|
|
if (!Impl)
|
|
|
|
Impl.reset(new TargetLibraryInfoImpl(T));
|
|
|
|
|
|
|
|
return *Impl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-15 11:41:28 +01:00
|
|
|
TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
: ImmutablePass(ID), TLIImpl(), TLI(TLIImpl) {
|
2015-01-15 11:41:28 +01:00
|
|
|
initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(const Triple &T)
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
: ImmutablePass(ID), TLIImpl(T), TLI(TLIImpl) {
|
2015-01-15 11:41:28 +01:00
|
|
|
initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass(
|
[PM] Rework how the TargetLibraryInfo pass integrates with the new pass
manager to support the actual uses of it. =]
When I ported instcombine to the new pass manager I discover that it
didn't work because TLI wasn't available in the right places. This is
a somewhat surprising and/or subtle aspect of the new pass manager
design that came up before but I think is useful to be reminded of:
While the new pass manager *allows* a function pass to query a module
analysis, it requires that the module analysis is already run and cached
prior to the function pass manager starting up, possibly with
a 'require<foo>' style utility in the pass pipeline. This is an
intentional hurdle because using a module analysis from a function pass
*requires* that the module analysis is run prior to entering the
function pass manager. Otherwise the other functions in the module could
be in who-knows-what state, etc.
A somewhat surprising consequence of this design decision (at least to
me) is that you have to design a function pass that leverages
a module analysis to do so as an optional feature. Even if that means
your function pass does no work in the absence of the module analysis,
you have to handle that possibility and remain conservatively correct.
This is a natural consequence of things being able to invalidate the
module analysis and us being unable to re-run it. And it's a generally
good thing because it lets us reorder passes arbitrarily without
breaking correctness, etc.
This ends up causing problems in one case. What if we have a module
analysis that is *definitionally* impossible to invalidate. In the
places this might come up, the analysis is usually also definitionally
trivial to run even while other transformation passes run on the module,
regardless of the state of anything. And so, it follows that it is
natural to have a hard requirement on such analyses from a function
pass.
It turns out, that TargetLibraryInfo is just such an analysis, and
InstCombine has a hard requirement on it.
The approach I've taken here is to produce an analysis that models this
flexibility by making it both a module and a function analysis. This
exposes the fact that it is in fact safe to compute at any point. We can
even make it a valid CGSCC analysis at some point if that is useful.
However, we don't want to have a copy of the actual target library info
state for each function! This state is specific to the triple. The
somewhat direct and blunt approach here is to turn TLI into a pimpl,
with the state and mutators in the implementation class and the query
routines primarily in the wrapper. Then the analysis can lazily
construct and cache the implementations, keyed on the triple, and
on-demand produce wrappers of them for each function.
One minor annoyance is that we will end up with a wrapper for each
function in the module. While this is a bit wasteful (one pointer per
function) it seems tolerable. And it has the advantage of ensuring that
we pay the absolute minimum synchronization cost to access this
information should we end up with a nice parallel function pass manager
in the future. We could look into trying to mark when analysis results
are especially cheap to recompute and more eagerly GC-ing the cached
results, or we could look at supporting a variant of analyses whose
results are specifically *not* cached and expected to just be used and
discarded by the consumer. Either way, these seem like incremental
enhancements that should happen when we start profiling the memory and
CPU usage of the new pass manager and not before.
The other minor annoyance is that if we end up using the TLI in both
a module pass and a function pass, those will be produced by two
separate analyses, and thus will point to separate copies of the
implementation state. While a minor issue, I dislike this and would like
to find a way to cleanly allow a single analysis instance to be used
across multiple IR unit managers. But I don't have a good solution to
this today, and I don't want to hold up all of the work waiting to come
up with one. This too seems like a reasonable thing to incrementally
improve later.
llvm-svn: 226981
2015-01-24 03:06:09 +01:00
|
|
|
const TargetLibraryInfoImpl &TLIImpl)
|
|
|
|
: ImmutablePass(ID), TLIImpl(TLIImpl), TLI(this->TLIImpl) {
|
2015-01-15 11:41:28 +01:00
|
|
|
initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
2016-03-11 11:22:49 +01:00
|
|
|
char TargetLibraryAnalysis::PassID;
|
2016-02-28 18:17:00 +01:00
|
|
|
|
2015-01-15 11:41:28 +01:00
|
|
|
// Register the basic pass.
|
|
|
|
INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
|
|
|
|
"Target Library Information", false, true)
|
|
|
|
char TargetLibraryInfoWrapperPass::ID = 0;
|
|
|
|
|
|
|
|
void TargetLibraryInfoWrapperPass::anchor() {}
|