mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:23:11 +01:00
move a massive amount of code out into its own helper function
to reduce nesting. This needs to be turned into a table. llvm-svn: 126366
This commit is contained in:
parent
72a2ebab6c
commit
d1bb8c0277
@ -1402,6 +1402,7 @@ namespace {
|
||||
void setDoesNotAlias(Function &F, unsigned n);
|
||||
bool doInitialization(Module &M);
|
||||
|
||||
void inferPrototypeAttributes(Function &F);
|
||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
}
|
||||
};
|
||||
@ -1597,27 +1598,16 @@ void SimplifyLibCalls::setDoesNotAlias(Function &F, unsigned n) {
|
||||
}
|
||||
}
|
||||
|
||||
/// doInitialization - Add attributes to well-known functions.
|
||||
///
|
||||
bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
Modified = false;
|
||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
||||
Function &F = *I;
|
||||
if (!F.isDeclaration())
|
||||
continue;
|
||||
|
||||
if (!F.hasName())
|
||||
continue;
|
||||
|
||||
void SimplifyLibCalls::inferPrototypeAttributes(Function &F) {
|
||||
const FunctionType *FTy = F.getFunctionType();
|
||||
|
||||
StringRef Name = F.getName();
|
||||
switch (Name[0]) {
|
||||
case 's':
|
||||
if (Name == "strlen") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setOnlyReadsMemory(F);
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
@ -1626,7 +1616,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isIntegerTy())
|
||||
continue;
|
||||
return;
|
||||
setOnlyReadsMemory(F);
|
||||
setDoesNotThrow(F);
|
||||
} else if (Name == "strcpy" ||
|
||||
@ -1643,14 +1633,14 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
Name == "strtoull") {
|
||||
if (FTy->getNumParams() < 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "strxfrm") {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
@ -1664,40 +1654,36 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() < 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setOnlyReadsMemory(F);
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "strstr" ||
|
||||
Name == "strpbrk") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
setOnlyReadsMemory(F);
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "strtok" ||
|
||||
Name == "strtok_r") {
|
||||
if (FTy->getNumParams() < 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() < 2 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "scanf" ||
|
||||
Name == "setbuf" ||
|
||||
Name == "setvbuf") {
|
||||
if (FTy->getNumParams() < 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() < 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "strdup" ||
|
||||
Name == "strndup") {
|
||||
if (FTy->getNumParams() < 1 ||
|
||||
!FTy->getReturnType()->isPointerTy() ||
|
||||
if (FTy->getNumParams() < 1 || !FTy->getReturnType()->isPointerTy() ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
setDoesNotCapture(F, 1);
|
||||
@ -1708,7 +1694,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() < 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
@ -1716,7 +1702,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(2)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 3);
|
||||
@ -1724,14 +1710,14 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(1)->isPointerTy() ||
|
||||
!FTy->getParamType(2)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
setDoesNotCapture(F, 3);
|
||||
} else if (Name == "system") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
// May throw; "system" is a valid pthread cancellation point.
|
||||
setDoesNotCapture(F, 1);
|
||||
}
|
||||
@ -1740,14 +1726,14 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (Name == "malloc") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getReturnType()->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
} else if (Name == "memcmp") {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setOnlyReadsMemory(F);
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
@ -1755,7 +1741,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
} else if (Name == "memchr" ||
|
||||
Name == "memrchr") {
|
||||
if (FTy->getNumParams() != 3)
|
||||
continue;
|
||||
return;
|
||||
setOnlyReadsMemory(F);
|
||||
setDoesNotThrow(F);
|
||||
} else if (Name == "modf" ||
|
||||
@ -1766,18 +1752,18 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
Name == "memmove") {
|
||||
if (FTy->getNumParams() < 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "memalign") {
|
||||
if (!FTy->getReturnType()->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotAlias(F, 0);
|
||||
} else if (Name == "mkdir" ||
|
||||
Name == "mktime") {
|
||||
if (FTy->getNumParams() == 0 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
}
|
||||
@ -1787,14 +1773,14 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getReturnType()->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "read") {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
// May throw; "read" is a valid pthread cancellation point.
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "rmdir" ||
|
||||
@ -1803,7 +1789,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
Name == "realpath") {
|
||||
if (FTy->getNumParams() < 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "rename" ||
|
||||
@ -1811,7 +1797,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() < 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
@ -1819,9 +1805,8 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
break;
|
||||
case 'w':
|
||||
if (Name == "write") {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 3 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
// May throw; "write" is a valid pthread cancellation point.
|
||||
setDoesNotCapture(F, 2);
|
||||
}
|
||||
@ -1831,7 +1816,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
@ -1839,15 +1824,14 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setOnlyReadsMemory(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "bzero") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
}
|
||||
@ -1856,7 +1840,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (Name == "calloc") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getReturnType()->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
} else if (Name == "chmod" ||
|
||||
@ -1864,9 +1848,8 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
Name == "ctermid" ||
|
||||
Name == "clearerr" ||
|
||||
Name == "closedir") {
|
||||
if (FTy->getNumParams() == 0 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() == 0 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
}
|
||||
@ -1876,16 +1859,14 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
Name == "atol" ||
|
||||
Name == "atof" ||
|
||||
Name == "atoll") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setOnlyReadsMemory(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "access") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
}
|
||||
@ -1896,7 +1877,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
!FTy->getReturnType()->isPointerTy() ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
setDoesNotCapture(F, 1);
|
||||
@ -1905,7 +1886,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getReturnType()->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
setDoesNotCapture(F, 2);
|
||||
@ -1923,15 +1904,13 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
Name == "flockfile" ||
|
||||
Name == "funlockfile" ||
|
||||
Name == "ftrylockfile") {
|
||||
if (FTy->getNumParams() == 0 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() == 0 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "ferror") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setOnlyReadsMemory(F);
|
||||
@ -1941,16 +1920,15 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
Name == "frexpf" ||
|
||||
Name == "frexpl" ||
|
||||
Name == "fstatvfs") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "fgets") {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(2)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 3);
|
||||
} else if (Name == "fread" ||
|
||||
@ -1958,7 +1936,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 4 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(3)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 4);
|
||||
@ -1969,7 +1947,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() < 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
@ -1979,15 +1957,13 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (Name == "getc" ||
|
||||
Name == "getlogin_r" ||
|
||||
Name == "getc_unlocked") {
|
||||
if (FTy->getNumParams() == 0 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() == 0 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "getenv") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setOnlyReadsMemory(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
@ -1995,32 +1971,28 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
Name == "getchar") {
|
||||
setDoesNotThrow(F);
|
||||
} else if (Name == "getitimer") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "getpwnam") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
if (Name == "ungetc") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "uname" ||
|
||||
Name == "unlink" ||
|
||||
Name == "unsetenv") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "utime" ||
|
||||
@ -2028,7 +2000,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
@ -2036,24 +2008,21 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
break;
|
||||
case 'p':
|
||||
if (Name == "putc") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "puts" ||
|
||||
Name == "printf" ||
|
||||
Name == "perror") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "pread" ||
|
||||
Name == "pwrite") {
|
||||
if (FTy->getNumParams() != 4 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 4 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
// May throw; these are valid pthread cancellation points.
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "putchar") {
|
||||
@ -2063,24 +2032,22 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
!FTy->getReturnType()->isPointerTy() ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "pclose") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
if (Name == "vscanf") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "vsscanf" ||
|
||||
@ -2088,19 +2055,18 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(1)->isPointerTy() ||
|
||||
!FTy->getParamType(2)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "valloc") {
|
||||
if (!FTy->getReturnType()->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
} else if (Name == "vprintf") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "vfprintf" ||
|
||||
@ -2108,7 +2074,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
@ -2116,7 +2082,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 4 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(2)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 3);
|
||||
@ -2124,16 +2090,15 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
break;
|
||||
case 'o':
|
||||
if (Name == "open") {
|
||||
if (FTy->getNumParams() < 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() < 2 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
// May throw; "open" is a valid pthread cancellation point.
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "opendir") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getReturnType()->isPointerTy() ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
setDoesNotCapture(F, 1);
|
||||
@ -2142,13 +2107,12 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
case 't':
|
||||
if (Name == "tmpfile") {
|
||||
if (!FTy->getReturnType()->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
} else if (Name == "times") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
}
|
||||
@ -2172,23 +2136,21 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "lchown") {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 3 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
}
|
||||
break;
|
||||
case 'q':
|
||||
if (Name == "qsort") {
|
||||
if (FTy->getNumParams() != 4 ||
|
||||
!FTy->getParamType(3)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 4 || !FTy->getParamType(3)->isPointerTy())
|
||||
return;
|
||||
// May throw; places call through function pointer.
|
||||
setDoesNotCapture(F, 4);
|
||||
}
|
||||
@ -2199,26 +2161,24 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() < 1 ||
|
||||
!FTy->getReturnType()->isPointerTy() ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "__strtok_r") {
|
||||
if (FTy->getNumParams() != 3 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "_IO_getc") {
|
||||
if (FTy->getNumParams() != 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 1 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "_IO_putc") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
}
|
||||
@ -2227,7 +2187,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (Name == "\1__isoc99_scanf") {
|
||||
if (FTy->getNumParams() < 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "\1stat64" ||
|
||||
@ -2237,7 +2197,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
if (FTy->getNumParams() < 1 ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
@ -2246,39 +2206,46 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
!FTy->getReturnType()->isPointerTy() ||
|
||||
!FTy->getParamType(0)->isPointerTy() ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
setDoesNotCapture(F, 1);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "\1fseeko64" ||
|
||||
Name == "\1ftello64") {
|
||||
if (FTy->getNumParams() == 0 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() == 0 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 1);
|
||||
} else if (Name == "\1tmpfile64") {
|
||||
if (!FTy->getReturnType()->isPointerTy())
|
||||
continue;
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotAlias(F, 0);
|
||||
} else if (Name == "\1fstat64" ||
|
||||
Name == "\1fstatvfs64") {
|
||||
if (FTy->getNumParams() != 2 ||
|
||||
!FTy->getParamType(1)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() != 2 || !FTy->getParamType(1)->isPointerTy())
|
||||
return;
|
||||
setDoesNotThrow(F);
|
||||
setDoesNotCapture(F, 2);
|
||||
} else if (Name == "\1open64") {
|
||||
if (FTy->getNumParams() < 2 ||
|
||||
!FTy->getParamType(0)->isPointerTy())
|
||||
continue;
|
||||
if (FTy->getNumParams() < 2 || !FTy->getParamType(0)->isPointerTy())
|
||||
return;
|
||||
// May throw; "open" is a valid pthread cancellation point.
|
||||
setDoesNotCapture(F, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// doInitialization - Add attributes to well-known functions.
|
||||
///
|
||||
bool SimplifyLibCalls::doInitialization(Module &M) {
|
||||
Modified = false;
|
||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
||||
Function &F = *I;
|
||||
if (F.isDeclaration() && F.hasName())
|
||||
inferPrototypeAttributes(F);
|
||||
}
|
||||
return Modified;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user