- };
-}
-
-// 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 *DoesntAccessMemoryTable[] = {
- // LLVM intrinsics:
- "llvm.frameaddress", "llvm.returnaddress", "llvm.readport", "llvm.isunordered",
-
- "abs", "labs", "llabs", "imaxabs", "fabs", "fabsf", "fabsl",
- "trunc", "truncf", "truncl", "ldexp",
-
- "atan", "atanf", "atanl", "atan2", "atan2f", "atan2l",
- "cbrt",
- "cos", "cosf", "cosl", "cosh", "coshf", "coshl",
- "exp", "expf", "expl",
- "hypot",
- "sin", "sinf", "sinl", "sinh", "sinhf", "sinhl",
- "tan", "tanf", "tanl", "tanh", "tanhf", "tanhl",
-
- // 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",
-
- // glibc functions:
- "__fpclassify", "__fpclassifyf", "__fpclassifyl",
- "__signbit", "__signbitf", "__signbitl",
-};
-
-static const unsigned DAMTableSize =
- sizeof(DoesntAccessMemoryTable)/sizeof(DoesntAccessMemoryTable[0]);
-
-/// doesNotAccessMemory - Return true if we know that the function does not
-/// access memory at all. Since basicaa does no analysis, we can only do simple
-/// things here. In particular, if we have an external function with the name
-/// of a standard C library function, we are allowed to assume it will be
-/// resolved by libc, so we can hardcode some entries in here.
-bool BasicAliasAnalysis::doesNotAccessMemory(Function *F) {
- if (!F->isExternal()) return false;
-
- static bool Initialized = false;
- if (!Initialized) {
- // Sort the table the first time through.
- std::sort(DoesntAccessMemoryTable, DoesntAccessMemoryTable+DAMTableSize,
- StringCompare());
- Initialized = true;
- }
-
- const char **Ptr = std::lower_bound(DoesntAccessMemoryTable,
- DoesntAccessMemoryTable+DAMTableSize,
- F->getName().c_str(), StringCompare());
- return Ptr != DoesntAccessMemoryTable+DAMTableSize && *Ptr == F->getName();
-}
-
-
-static const char *OnlyReadsMemoryTable[] = {
- "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 const unsigned ORMTableSize =
- sizeof(OnlyReadsMemoryTable)/sizeof(OnlyReadsMemoryTable[0]);
-
-bool BasicAliasAnalysis::onlyReadsMemory(Function *F) {
- if (doesNotAccessMemory(F)) return true;
- if (!F->isExternal()) return false;
-
- static bool Initialized = false;
- if (!Initialized) {
- // Sort the table the first time through.
- std::sort(OnlyReadsMemoryTable, OnlyReadsMemoryTable+ORMTableSize,
- StringCompare());
- Initialized = true;