+namespace {
+ struct VISIBILITY_HIDDEN StringCompare {
+ bool operator()(const char *LHS, const char *RHS) {
+ return strcmp(LHS, RHS) < 0;
+ }
+ };
+}
+
+// Note that this list cannot contain libm functions (such as acos and sqrt)
+// that set errno on a domain or other error.
+static const char *DoesntAccessMemoryFns[] = {
+ "abs", "labs", "llabs", "imaxabs", "fabs", "fabsf", "fabsl",
+ "trunc", "truncf", "truncl", "ldexp",
+
+ "atan", "atanf", "atanl", "atan2", "atan2f", "atan2l",
+ "cbrt",
+ "cos", "cosf", "cosl",
+ "exp", "expf", "expl",
+ "hypot",
+ "sin", "sinf", "sinl",
+ "tan", "tanf", "tanl", "tanh", "tanhf", "tanhl",
+
+ "floor", "floorf", "floorl", "ceil", "ceilf", "ceill",
+
+ // ctype.h
+ "isalnum", "isalpha", "iscntrl", "isdigit", "isgraph", "islower", "isprint"
+ "ispunct", "isspace", "isupper", "isxdigit", "tolower", "toupper",
+
+ // wctype.h"
+ "iswalnum", "iswalpha", "iswcntrl", "iswdigit", "iswgraph", "iswlower",
+ "iswprint", "iswpunct", "iswspace", "iswupper", "iswxdigit",
+
+ "iswctype", "towctrans", "towlower", "towupper",
+
+ "btowc", "wctob",
+
+ "isinf", "isnan", "finite",
+
+ // C99 math functions
+ "copysign", "copysignf", "copysignd",
+ "nexttoward", "nexttowardf", "nexttowardd",
+ "nextafter", "nextafterf", "nextafterd",
+
+ // ISO C99:
+ "__signbit", "__signbitf", "__signbitl",
+};
+
+
+static const char *OnlyReadsMemoryFns[] = {
+ "atoi", "atol", "atof", "atoll", "atoq", "a64l",
+ "bcmp", "memcmp", "memchr", "memrchr", "wmemcmp", "wmemchr",
+
+ // Strings
+ "strcmp", "strcasecmp", "strcoll", "strncmp", "strncasecmp",
+ "strchr", "strcspn", "strlen", "strpbrk", "strrchr", "strspn", "strstr",
+ "index", "rindex",
+
+ // Wide char strings
+ "wcschr", "wcscmp", "wcscoll", "wcscspn", "wcslen", "wcsncmp", "wcspbrk",
+ "wcsrchr", "wcsspn", "wcsstr",
+
+ // glibc
+ "alphasort", "alphasort64", "versionsort", "versionsort64",
+
+ // C99
+ "nan", "nanf", "nand",
+
+ // File I/O
+ "feof", "ferror", "fileno",
+ "feof_unlocked", "ferror_unlocked", "fileno_unlocked"
+};
+
+static ManagedStatic<std::vector<const char*> > NoMemoryTable;
+static ManagedStatic<std::vector<const char*> > OnlyReadsMemoryTable;
+
+
+AliasAnalysis::ModRefBehavior
+BasicAliasAnalysis::getModRefBehavior(Function *F, CallSite CS,
+ std::vector<PointerAccessInfo> *Info) {
+ if (!F->isDeclaration()) return UnknownModRefBehavior;
+
+ static bool Initialized = false;
+ if (!Initialized) {
+ NoMemoryTable->insert(NoMemoryTable->end(),
+ DoesntAccessMemoryFns,
+ DoesntAccessMemoryFns+
+ sizeof(DoesntAccessMemoryFns)/sizeof(DoesntAccessMemoryFns[0]));
+
+ OnlyReadsMemoryTable->insert(OnlyReadsMemoryTable->end(),
+ OnlyReadsMemoryFns,
+ OnlyReadsMemoryFns+
+ sizeof(OnlyReadsMemoryFns)/sizeof(OnlyReadsMemoryFns[0]));
+#define GET_MODREF_BEHAVIOR
+#include "llvm/Intrinsics.gen"
+#undef GET_MODREF_BEHAVIOR
+
+ // Sort the table the first time through.
+ std::sort(NoMemoryTable->begin(), NoMemoryTable->end(), StringCompare());
+ std::sort(OnlyReadsMemoryTable->begin(), OnlyReadsMemoryTable->end(),
+ StringCompare());
+ Initialized = true;
+ }
+
+ std::vector<const char*>::iterator Ptr =
+ std::lower_bound(NoMemoryTable->begin(), NoMemoryTable->end(),
+ F->getName().c_str(), StringCompare());
+ if (Ptr != NoMemoryTable->end() && *Ptr == F->getName())
+ return DoesNotAccessMemory;
+
+ Ptr = std::lower_bound(OnlyReadsMemoryTable->begin(),
+ OnlyReadsMemoryTable->end(),
+ F->getName().c_str(), StringCompare());
+ if (Ptr != OnlyReadsMemoryTable->end() && *Ptr == F->getName())
+ return OnlyReadsMemory;
+
+ return UnknownModRefBehavior;
+}
+
+// Make sure that anything that uses AliasAnalysis pulls in this file...
+DEFINING_FILE_FOR(BasicAliasAnalysis)