summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r--llvm/lib/Transforms/Utils/BuildLibCalls.cpp150
-rw-r--r--llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp4
-rw-r--r--llvm/lib/Transforms/Utils/EscapeEnumerator.cpp6
-rw-r--r--llvm/lib/Transforms/Utils/ModuleUtils.cpp47
-rw-r--r--llvm/lib/Transforms/Utils/PredicateInfo.cpp6
-rw-r--r--llvm/lib/Transforms/Utils/SanitizerStats.cpp8
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp15
7 files changed, 111 insertions, 125 deletions
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index 568850876a2..348d5b0df67 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -797,12 +797,11 @@ Value *llvm::emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL,
Module *M = B.GetInsertBlock()->getModule();
StringRef StrlenName = TLI->getName(LibFunc_strlen);
LLVMContext &Context = B.GetInsertBlock()->getContext();
- FunctionCallee StrLen = M->getOrInsertFunction(
- StrlenName, DL.getIntPtrType(Context), B.getInt8PtrTy());
+ Constant *StrLen = M->getOrInsertFunction(StrlenName, DL.getIntPtrType(Context),
+ B.getInt8PtrTy());
inferLibFuncAttributes(M, StrlenName, *TLI);
CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), StrlenName);
- if (const Function *F =
- dyn_cast<Function>(StrLen.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
@@ -817,13 +816,12 @@ Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilder<> &B,
StringRef StrChrName = TLI->getName(LibFunc_strchr);
Type *I8Ptr = B.getInt8PtrTy();
Type *I32Ty = B.getInt32Ty();
- FunctionCallee StrChr =
+ Constant *StrChr =
M->getOrInsertFunction(StrChrName, I8Ptr, I8Ptr, I32Ty);
inferLibFuncAttributes(M, StrChrName, *TLI);
CallInst *CI = B.CreateCall(
StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, StrChrName);
- if (const Function *F =
- dyn_cast<Function>(StrChr.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
}
@@ -836,15 +834,14 @@ Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
StringRef StrNCmpName = TLI->getName(LibFunc_strncmp);
LLVMContext &Context = B.GetInsertBlock()->getContext();
- FunctionCallee StrNCmp =
- M->getOrInsertFunction(StrNCmpName, B.getInt32Ty(), B.getInt8PtrTy(),
- B.getInt8PtrTy(), DL.getIntPtrType(Context));
+ Value *StrNCmp = M->getOrInsertFunction(StrNCmpName, B.getInt32Ty(),
+ B.getInt8PtrTy(), B.getInt8PtrTy(),
+ DL.getIntPtrType(Context));
inferLibFuncAttributes(M, StrNCmpName, *TLI);
CallInst *CI = B.CreateCall(
StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, StrNCmpName);
- if (const Function *F =
- dyn_cast<Function>(StrNCmp.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
@@ -857,12 +854,11 @@ Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
Type *I8Ptr = B.getInt8PtrTy();
- FunctionCallee StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr);
+ Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr);
inferLibFuncAttributes(M, Name, *TLI);
CallInst *CI =
B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name);
- if (const Function *F =
- dyn_cast<Function>(StrCpy.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
}
@@ -874,13 +870,12 @@ Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
Type *I8Ptr = B.getInt8PtrTy();
- FunctionCallee StrNCpy =
- M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr, Len->getType());
+ Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr,
+ Len->getType());
inferLibFuncAttributes(M, Name, *TLI);
CallInst *CI = B.CreateCall(
StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, Name);
- if (const Function *F =
- dyn_cast<Function>(StrNCpy.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
}
@@ -896,15 +891,14 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
Attribute::NoUnwind);
LLVMContext &Context = B.GetInsertBlock()->getContext();
- FunctionCallee MemCpy = M->getOrInsertFunction(
+ Value *MemCpy = M->getOrInsertFunction(
"__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(),
B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
DL.getIntPtrType(Context));
Dst = castToCStr(Dst, B);
Src = castToCStr(Src, B);
CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
- if (const Function *F =
- dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
}
@@ -917,14 +911,13 @@ Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
StringRef MemChrName = TLI->getName(LibFunc_memchr);
LLVMContext &Context = B.GetInsertBlock()->getContext();
- FunctionCallee MemChr =
- M->getOrInsertFunction(MemChrName, B.getInt8PtrTy(), B.getInt8PtrTy(),
- B.getInt32Ty(), DL.getIntPtrType(Context));
+ Value *MemChr = M->getOrInsertFunction(MemChrName, B.getInt8PtrTy(),
+ B.getInt8PtrTy(), B.getInt32Ty(),
+ DL.getIntPtrType(Context));
inferLibFuncAttributes(M, MemChrName, *TLI);
CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, MemChrName);
- if (const Function *F =
- dyn_cast<Function>(MemChr.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
@@ -938,15 +931,14 @@ Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
StringRef MemCmpName = TLI->getName(LibFunc_memcmp);
LLVMContext &Context = B.GetInsertBlock()->getContext();
- FunctionCallee MemCmp =
- M->getOrInsertFunction(MemCmpName, B.getInt32Ty(), B.getInt8PtrTy(),
- B.getInt8PtrTy(), DL.getIntPtrType(Context));
+ Value *MemCmp = M->getOrInsertFunction(MemCmpName, B.getInt32Ty(),
+ B.getInt8PtrTy(), B.getInt8PtrTy(),
+ DL.getIntPtrType(Context));
inferLibFuncAttributes(M, MemCmpName, *TLI);
CallInst *CI = B.CreateCall(
MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, MemCmpName);
- if (const Function *F =
- dyn_cast<Function>(MemCmp.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
@@ -973,8 +965,8 @@ static Value *emitUnaryFloatFnCallHelper(Value *Op, StringRef Name,
assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
Module *M = B.GetInsertBlock()->getModule();
- FunctionCallee Callee =
- M->getOrInsertFunction(Name, Op->getType(), Op->getType());
+ Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
+ Op->getType());
CallInst *CI = B.CreateCall(Callee, Op, Name);
// The incoming attribute set may have come from a speculatable intrinsic, but
@@ -983,8 +975,7 @@ static Value *emitUnaryFloatFnCallHelper(Value *Op, StringRef Name,
CI->setAttributes(Attrs.removeAttribute(B.getContext(),
AttributeList::FunctionIndex,
Attribute::Speculatable));
- if (const Function *F =
- dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
@@ -1017,12 +1008,11 @@ Value *llvm::emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
appendTypeSuffix(Op1, Name, NameBuffer);
Module *M = B.GetInsertBlock()->getModule();
- FunctionCallee Callee = M->getOrInsertFunction(
- Name, Op1->getType(), Op1->getType(), Op2->getType());
+ Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), Op1->getType(),
+ Op2->getType());
CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name);
CI->setAttributes(Attrs);
- if (const Function *F =
- dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
@@ -1035,8 +1025,7 @@ Value *llvm::emitPutChar(Value *Char, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
StringRef PutCharName = TLI->getName(LibFunc_putchar);
- FunctionCallee PutChar =
- M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty());
+ Value *PutChar = M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty());
inferLibFuncAttributes(M, PutCharName, *TLI);
CallInst *CI = B.CreateCall(PutChar,
B.CreateIntCast(Char,
@@ -1045,8 +1034,7 @@ Value *llvm::emitPutChar(Value *Char, IRBuilder<> &B,
"chari"),
PutCharName);
- if (const Function *F =
- dyn_cast<Function>(PutChar.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
}
@@ -1058,12 +1046,11 @@ Value *llvm::emitPutS(Value *Str, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
StringRef PutsName = TLI->getName(LibFunc_puts);
- FunctionCallee PutS =
+ Value *PutS =
M->getOrInsertFunction(PutsName, B.getInt32Ty(), B.getInt8PtrTy());
inferLibFuncAttributes(M, PutsName, *TLI);
CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), PutsName);
- if (const Function *F =
- dyn_cast<Function>(PutS.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
}
@@ -1075,16 +1062,15 @@ Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
StringRef FPutcName = TLI->getName(LibFunc_fputc);
- FunctionCallee F = M->getOrInsertFunction(FPutcName, B.getInt32Ty(),
- B.getInt32Ty(), File->getType());
+ Constant *F = M->getOrInsertFunction(FPutcName, B.getInt32Ty(), B.getInt32Ty(),
+ File->getType());
if (File->getType()->isPointerTy())
inferLibFuncAttributes(M, FPutcName, *TLI);
Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
"chari");
CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
- if (const Function *Fn =
- dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
+ if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
CI->setCallingConv(Fn->getCallingConv());
return CI;
}
@@ -1096,15 +1082,14 @@ Value *llvm::emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
StringRef FPutcUnlockedName = TLI->getName(LibFunc_fputc_unlocked);
- FunctionCallee F = M->getOrInsertFunction(FPutcUnlockedName, B.getInt32Ty(),
- B.getInt32Ty(), File->getType());
+ Constant *F = M->getOrInsertFunction(FPutcUnlockedName, B.getInt32Ty(),
+ B.getInt32Ty(), File->getType());
if (File->getType()->isPointerTy())
inferLibFuncAttributes(M, FPutcUnlockedName, *TLI);
Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/ true, "chari");
CallInst *CI = B.CreateCall(F, {Char, File}, FPutcUnlockedName);
- if (const Function *Fn =
- dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
+ if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
CI->setCallingConv(Fn->getCallingConv());
return CI;
}
@@ -1116,14 +1101,13 @@ Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
StringRef FPutsName = TLI->getName(LibFunc_fputs);
- FunctionCallee F = M->getOrInsertFunction(FPutsName, B.getInt32Ty(),
- B.getInt8PtrTy(), File->getType());
+ Constant *F = M->getOrInsertFunction(
+ FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType());
if (File->getType()->isPointerTy())
inferLibFuncAttributes(M, FPutsName, *TLI);
CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsName);
- if (const Function *Fn =
- dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
+ if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
CI->setCallingConv(Fn->getCallingConv());
return CI;
}
@@ -1135,14 +1119,13 @@ Value *llvm::emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
StringRef FPutsUnlockedName = TLI->getName(LibFunc_fputs_unlocked);
- FunctionCallee F = M->getOrInsertFunction(FPutsUnlockedName, B.getInt32Ty(),
- B.getInt8PtrTy(), File->getType());
+ Constant *F = M->getOrInsertFunction(FPutsUnlockedName, B.getInt32Ty(),
+ B.getInt8PtrTy(), File->getType());
if (File->getType()->isPointerTy())
inferLibFuncAttributes(M, FPutsUnlockedName, *TLI);
CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsUnlockedName);
- if (const Function *Fn =
- dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
+ if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
CI->setCallingConv(Fn->getCallingConv());
return CI;
}
@@ -1155,7 +1138,7 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
LLVMContext &Context = B.GetInsertBlock()->getContext();
StringRef FWriteName = TLI->getName(LibFunc_fwrite);
- FunctionCallee F = M->getOrInsertFunction(
+ Constant *F = M->getOrInsertFunction(
FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
@@ -1165,8 +1148,7 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
B.CreateCall(F, {castToCStr(Ptr, B), Size,
ConstantInt::get(DL.getIntPtrType(Context), 1), File});
- if (const Function *Fn =
- dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
+ if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
CI->setCallingConv(Fn->getCallingConv());
return CI;
}
@@ -1179,13 +1161,12 @@ Value *llvm::emitMalloc(Value *Num, IRBuilder<> &B, const DataLayout &DL,
Module *M = B.GetInsertBlock()->getModule();
StringRef MallocName = TLI->getName(LibFunc_malloc);
LLVMContext &Context = B.GetInsertBlock()->getContext();
- FunctionCallee Malloc = M->getOrInsertFunction(MallocName, B.getInt8PtrTy(),
- DL.getIntPtrType(Context));
+ Value *Malloc = M->getOrInsertFunction(MallocName, B.getInt8PtrTy(),
+ DL.getIntPtrType(Context));
inferLibFuncAttributes(M, MallocName, *TLI);
CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
- if (const Function *F =
- dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
+ if (const Function *F = dyn_cast<Function>(Malloc->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
@@ -1200,13 +1181,12 @@ Value *llvm::emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs,
StringRef CallocName = TLI.getName(LibFunc_calloc);
const DataLayout &DL = M->getDataLayout();
IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext()));
- FunctionCallee Calloc = M->getOrInsertFunction(
- CallocName, Attrs, B.getInt8PtrTy(), PtrType, PtrType);
+ Value *Calloc = M->getOrInsertFunction(CallocName, Attrs, B.getInt8PtrTy(),
+ PtrType, PtrType);
inferLibFuncAttributes(M, CallocName, TLI);
CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
- if (const auto *F =
- dyn_cast<Function>(Calloc.getCallee()->stripPointerCasts()))
+ if (const auto *F = dyn_cast<Function>(Calloc->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
return CI;
@@ -1221,7 +1201,7 @@ Value *llvm::emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,
Module *M = B.GetInsertBlock()->getModule();
LLVMContext &Context = B.GetInsertBlock()->getContext();
StringRef FWriteUnlockedName = TLI->getName(LibFunc_fwrite_unlocked);
- FunctionCallee F = M->getOrInsertFunction(
+ Constant *F = M->getOrInsertFunction(
FWriteUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
@@ -1229,8 +1209,7 @@ Value *llvm::emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,
inferLibFuncAttributes(M, FWriteUnlockedName, *TLI);
CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File});
- if (const Function *Fn =
- dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
+ if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
CI->setCallingConv(Fn->getCallingConv());
return CI;
}
@@ -1242,14 +1221,13 @@ Value *llvm::emitFGetCUnlocked(Value *File, IRBuilder<> &B,
Module *M = B.GetInsertBlock()->getModule();
StringRef FGetCUnlockedName = TLI->getName(LibFunc_fgetc_unlocked);
- FunctionCallee F = M->getOrInsertFunction(FGetCUnlockedName, B.getInt32Ty(),
- File->getType());
+ Constant *F =
+ M->getOrInsertFunction(FGetCUnlockedName, B.getInt32Ty(), File->getType());
if (File->getType()->isPointerTy())
inferLibFuncAttributes(M, FGetCUnlockedName, *TLI);
CallInst *CI = B.CreateCall(F, File, FGetCUnlockedName);
- if (const Function *Fn =
- dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
+ if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
CI->setCallingConv(Fn->getCallingConv());
return CI;
}
@@ -1261,15 +1239,14 @@ Value *llvm::emitFGetSUnlocked(Value *Str, Value *Size, Value *File,
Module *M = B.GetInsertBlock()->getModule();
StringRef FGetSUnlockedName = TLI->getName(LibFunc_fgets_unlocked);
- FunctionCallee F =
+ Constant *F =
M->getOrInsertFunction(FGetSUnlockedName, B.getInt8PtrTy(),
B.getInt8PtrTy(), B.getInt32Ty(), File->getType());
inferLibFuncAttributes(M, FGetSUnlockedName, *TLI);
CallInst *CI =
B.CreateCall(F, {castToCStr(Str, B), Size, File}, FGetSUnlockedName);
- if (const Function *Fn =
- dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
+ if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
CI->setCallingConv(Fn->getCallingConv());
return CI;
}
@@ -1283,7 +1260,7 @@ Value *llvm::emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,
Module *M = B.GetInsertBlock()->getModule();
LLVMContext &Context = B.GetInsertBlock()->getContext();
StringRef FReadUnlockedName = TLI->getName(LibFunc_fread_unlocked);
- FunctionCallee F = M->getOrInsertFunction(
+ Constant *F = M->getOrInsertFunction(
FReadUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
@@ -1291,8 +1268,7 @@ Value *llvm::emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,
inferLibFuncAttributes(M, FReadUnlockedName, *TLI);
CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File});
- if (const Function *Fn =
- dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
+ if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
CI->setCallingConv(Fn->getCallingConv());
return CI;
}
diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
index 4aa40eeadda..e63155a3409 100644
--- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
+++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
@@ -30,7 +30,7 @@ static void insertCall(Function &CurFn, StringRef Func,
Func == "__mcount" ||
Func == "_mcount" ||
Func == "__cyg_profile_func_enter_bare") {
- FunctionCallee Fn = M.getOrInsertFunction(Func, Type::getVoidTy(C));
+ Constant *Fn = M.getOrInsertFunction(Func, Type::getVoidTy(C));
CallInst *Call = CallInst::Create(Fn, "", InsertionPt);
Call->setDebugLoc(DL);
return;
@@ -39,7 +39,7 @@ static void insertCall(Function &CurFn, StringRef Func,
if (Func == "__cyg_profile_func_enter" || Func == "__cyg_profile_func_exit") {
Type *ArgTypes[] = {Type::getInt8PtrTy(C), Type::getInt8PtrTy(C)};
- FunctionCallee Fn = M.getOrInsertFunction(
+ Constant *Fn = M.getOrInsertFunction(
Func, FunctionType::get(Type::getVoidTy(C), ArgTypes, false));
Instruction *RetAddr = CallInst::Create(
diff --git a/llvm/lib/Transforms/Utils/EscapeEnumerator.cpp b/llvm/lib/Transforms/Utils/EscapeEnumerator.cpp
index 914babeb682..92c0c0bcc39 100644
--- a/llvm/lib/Transforms/Utils/EscapeEnumerator.cpp
+++ b/llvm/lib/Transforms/Utils/EscapeEnumerator.cpp
@@ -18,7 +18,7 @@
#include "llvm/IR/Module.h"
using namespace llvm;
-static FunctionCallee getDefaultPersonalityFn(Module *M) {
+static Constant *getDefaultPersonalityFn(Module *M) {
LLVMContext &C = M->getContext();
Triple T(M->getTargetTriple());
EHPersonality Pers = getDefaultEHPersonality(T);
@@ -68,8 +68,8 @@ IRBuilder<> *EscapeEnumerator::Next() {
BasicBlock *CleanupBB = BasicBlock::Create(C, CleanupBBName, &F);
Type *ExnTy = StructType::get(Type::getInt8PtrTy(C), Type::getInt32Ty(C));
if (!F.hasPersonalityFn()) {
- FunctionCallee PersFn = getDefaultPersonalityFn(F.getParent());
- F.setPersonalityFn(cast<Constant>(PersFn.getCallee()));
+ Constant *PersFn = getDefaultPersonalityFn(F.getParent());
+ F.setPersonalityFn(PersFn);
}
if (isScopedEHPersonality(classifyEHPersonality(F.getPersonalityFn()))) {
diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
index b076e7503c6..fa6eed52ba3 100644
--- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -126,24 +126,36 @@ void llvm::appendToCompilerUsed(Module &M, ArrayRef<GlobalValue *> Values) {
appendToUsedList(M, "llvm.compiler.used", Values);
}
-FunctionCallee
-llvm::declareSanitizerInitFunction(Module &M, StringRef InitName,
- ArrayRef<Type *> InitArgTypes) {
+Function *llvm::checkSanitizerInterfaceFunction(Constant *FuncOrBitcast) {
+ if (isa<Function>(FuncOrBitcast))
+ return cast<Function>(FuncOrBitcast);
+ FuncOrBitcast->print(errs());
+ errs() << '\n';
+ std::string Err;
+ raw_string_ostream Stream(Err);
+ Stream << "Sanitizer interface function redefined: " << *FuncOrBitcast;
+ report_fatal_error(Err);
+}
+
+Function *llvm::declareSanitizerInitFunction(Module &M, StringRef InitName,
+ ArrayRef<Type *> InitArgTypes) {
assert(!InitName.empty() && "Expected init function name");
- return M.getOrInsertFunction(
+ Function *F = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
InitName,
FunctionType::get(Type::getVoidTy(M.getContext()), InitArgTypes, false),
- AttributeList());
+ AttributeList()));
+ F->setLinkage(Function::ExternalLinkage);
+ return F;
}
-std::pair<Function *, FunctionCallee> llvm::createSanitizerCtorAndInitFunctions(
+std::pair<Function *, Function *> llvm::createSanitizerCtorAndInitFunctions(
Module &M, StringRef CtorName, StringRef InitName,
ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
StringRef VersionCheckName) {
assert(!InitName.empty() && "Expected init function name");
assert(InitArgs.size() == InitArgTypes.size() &&
"Sanitizer's init function expects different number of arguments");
- FunctionCallee InitFunction =
+ Function *InitFunction =
declareSanitizerInitFunction(M, InitName, InitArgTypes);
Function *Ctor = Function::Create(
FunctionType::get(Type::getVoidTy(M.getContext()), false),
@@ -152,19 +164,20 @@ std::pair<Function *, FunctionCallee> llvm::createSanitizerCtorAndInitFunctions(
IRBuilder<> IRB(ReturnInst::Create(M.getContext(), CtorBB));
IRB.CreateCall(InitFunction, InitArgs);
if (!VersionCheckName.empty()) {
- FunctionCallee VersionCheckFunction = M.getOrInsertFunction(
- VersionCheckName, FunctionType::get(IRB.getVoidTy(), {}, false),
- AttributeList());
+ Function *VersionCheckFunction =
+ checkSanitizerInterfaceFunction(M.getOrInsertFunction(
+ VersionCheckName, FunctionType::get(IRB.getVoidTy(), {}, false),
+ AttributeList()));
IRB.CreateCall(VersionCheckFunction, {});
}
return std::make_pair(Ctor, InitFunction);
}
-std::pair<Function *, FunctionCallee>
+std::pair<Function *, Function *>
llvm::getOrCreateSanitizerCtorAndInitFunctions(
Module &M, StringRef CtorName, StringRef InitName,
ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
- function_ref<void(Function *, FunctionCallee)> FunctionsCreatedCallback,
+ function_ref<void(Function *, Function *)> FunctionsCreatedCallback,
StringRef VersionCheckName) {
assert(!CtorName.empty() && "Expected ctor function name");
@@ -175,8 +188,7 @@ llvm::getOrCreateSanitizerCtorAndInitFunctions(
Ctor->getReturnType() == Type::getVoidTy(M.getContext()))
return {Ctor, declareSanitizerInitFunction(M, InitName, InitArgTypes)};
- Function *Ctor;
- FunctionCallee InitFunction;
+ Function *Ctor, *InitFunction;
std::tie(Ctor, InitFunction) = llvm::createSanitizerCtorAndInitFunctions(
M, CtorName, InitName, InitArgTypes, InitArgs, VersionCheckName);
FunctionsCreatedCallback(Ctor, InitFunction);
@@ -195,10 +207,9 @@ Function *llvm::getOrCreateInitFunction(Module &M, StringRef Name) {
}
return F;
}
- Function *F =
- cast<Function>(M.getOrInsertFunction(Name, AttributeList(),
- Type::getVoidTy(M.getContext()))
- .getCallee());
+ Function *F = checkSanitizerInterfaceFunction(M.getOrInsertFunction(
+ Name, AttributeList(), Type::getVoidTy(M.getContext())));
+ F->setLinkage(Function::ExternalLinkage);
appendToGlobalCtors(M, F, 0);
diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
index f1c0792da78..85fb321e207 100644
--- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp
+++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
@@ -488,10 +488,8 @@ void PredicateInfo::buildPredicateInfo() {
// tricky (FIXME).
static Function *getCopyDeclaration(Module *M, Type *Ty) {
std::string Name = "llvm.ssa.copy." + utostr((uintptr_t) Ty);
- return cast<Function>(
- M->getOrInsertFunction(Name,
- getType(M->getContext(), Intrinsic::ssa_copy, Ty))
- .getCallee());
+ return cast<Function>(M->getOrInsertFunction(
+ Name, getType(M->getContext(), Intrinsic::ssa_copy, Ty)));
}
// Given the renaming stack, make all the operands currently on the stack real
diff --git a/llvm/lib/Transforms/Utils/SanitizerStats.cpp b/llvm/lib/Transforms/Utils/SanitizerStats.cpp
index a1313c77ed7..631b2384be0 100644
--- a/llvm/lib/Transforms/Utils/SanitizerStats.cpp
+++ b/llvm/lib/Transforms/Utils/SanitizerStats.cpp
@@ -56,8 +56,8 @@ void SanitizerStatReport::create(IRBuilder<> &B, SanitizerStatKind SK) {
FunctionType *StatReportTy =
FunctionType::get(B.getVoidTy(), Int8PtrTy, false);
- FunctionCallee StatReport =
- M->getOrInsertFunction("__sanitizer_stat_report", StatReportTy);
+ Constant *StatReport = M->getOrInsertFunction(
+ "__sanitizer_stat_report", StatReportTy);
auto InitAddr = ConstantExpr::getGetElementPtr(
EmptyModuleStatsTy, ModuleStatsGV,
@@ -97,8 +97,8 @@ void SanitizerStatReport::finish() {
IRBuilder<> B(BB);
FunctionType *StatInitTy = FunctionType::get(VoidTy, Int8PtrTy, false);
- FunctionCallee StatInit =
- M->getOrInsertFunction("__sanitizer_stat_init", StatInitTy);
+ Constant *StatInit = M->getOrInsertFunction(
+ "__sanitizer_stat_init", StatInitTy);
B.CreateCall(StatInit, ConstantExpr::getBitCast(NewModuleStatsGV, Int8PtrTy));
B.CreateRetVoid();
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index de4ec621da6..c0957c11719 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1503,8 +1503,9 @@ Value *LibCallSimplifier::optimizeExp2(CallInst *CI, IRBuilder<> &B) {
One = ConstantExpr::getFPExtend(One, Op->getType());
Module *M = CI->getModule();
- FunctionCallee NewCallee = M->getOrInsertFunction(
- TLI->getName(LdExp), Op->getType(), Op->getType(), B.getInt32Ty());
+ Value *NewCallee =
+ M->getOrInsertFunction(TLI->getName(LdExp), Op->getType(),
+ Op->getType(), B.getInt32Ty());
CallInst *CI = B.CreateCall(NewCallee, {One, LdExpArg});
if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
CI->setCallingConv(F->getCallingConv());
@@ -1726,8 +1727,8 @@ static void insertSinCosCall(IRBuilder<> &B, Function *OrigCallee, Value *Arg,
}
Module *M = OrigCallee->getParent();
- FunctionCallee Callee =
- M->getOrInsertFunction(Name, OrigCallee->getAttributes(), ResTy, ArgTy);
+ Value *Callee = M->getOrInsertFunction(Name, OrigCallee->getAttributes(),
+ ResTy, ArgTy);
if (Instruction *ArgInst = dyn_cast<Instruction>(Arg)) {
// If the argument is an instruction, it must dominate all uses so put our
@@ -2024,7 +2025,7 @@ Value *LibCallSimplifier::optimizePrintF(CallInst *CI, IRBuilder<> &B) {
// arguments.
if (TLI->has(LibFunc_iprintf) && !callHasFloatingPointArgument(CI)) {
Module *M = B.GetInsertBlock()->getParent()->getParent();
- FunctionCallee IPrintFFn =
+ Constant *IPrintFFn =
M->getOrInsertFunction("iprintf", FT, Callee->getAttributes());
CallInst *New = cast<CallInst>(CI->clone());
New->setCalledFunction(IPrintFFn);
@@ -2103,7 +2104,7 @@ Value *LibCallSimplifier::optimizeSPrintF(CallInst *CI, IRBuilder<> &B) {
// point arguments.
if (TLI->has(LibFunc_siprintf) && !callHasFloatingPointArgument(CI)) {
Module *M = B.GetInsertBlock()->getParent()->getParent();
- FunctionCallee SIPrintFFn =
+ Constant *SIPrintFFn =
M->getOrInsertFunction("siprintf", FT, Callee->getAttributes());
CallInst *New = cast<CallInst>(CI->clone());
New->setCalledFunction(SIPrintFFn);
@@ -2260,7 +2261,7 @@ Value *LibCallSimplifier::optimizeFPrintF(CallInst *CI, IRBuilder<> &B) {
// floating point arguments.
if (TLI->has(LibFunc_fiprintf) && !callHasFloatingPointArgument(CI)) {
Module *M = B.GetInsertBlock()->getParent()->getParent();
- FunctionCallee FIPrintFFn =
+ Constant *FIPrintFFn =
M->getOrInsertFunction("fiprintf", FT, Callee->getAttributes());
CallInst *New = cast<CallInst>(CI->clone());
New->setCalledFunction(FIPrintFFn);
OpenPOWER on IntegriCloud