diff options
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r-- | llvm/lib/Transforms/Utils/BuildLibCalls.cpp | 150 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/EscapeEnumerator.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/ModuleUtils.cpp | 47 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/PredicateInfo.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/SanitizerStats.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 15 |
7 files changed, 125 insertions, 111 deletions
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp index 348d5b0df67..568850876a2 100644 --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -797,11 +797,12 @@ 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(); - Constant *StrLen = M->getOrInsertFunction(StrlenName, DL.getIntPtrType(Context), - B.getInt8PtrTy()); + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(StrLen.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -816,12 +817,13 @@ Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilder<> &B, StringRef StrChrName = TLI->getName(LibFunc_strchr); Type *I8Ptr = B.getInt8PtrTy(); Type *I32Ty = B.getInt32Ty(); - Constant *StrChr = + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(StrChr.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -834,14 +836,15 @@ 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(); - Value *StrNCmp = M->getOrInsertFunction(StrNCmpName, B.getInt32Ty(), - B.getInt8PtrTy(), B.getInt8PtrTy(), - DL.getIntPtrType(Context)); + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(StrNCmp.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -854,11 +857,12 @@ Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); Type *I8Ptr = B.getInt8PtrTy(); - Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr); + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(StrCpy.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -870,12 +874,13 @@ Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); Type *I8Ptr = B.getInt8PtrTy(); - Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr, - Len->getType()); + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(StrNCpy.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -891,14 +896,15 @@ 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(); - Value *MemCpy = M->getOrInsertFunction( + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -911,13 +917,14 @@ 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(); - Value *MemChr = M->getOrInsertFunction(MemChrName, B.getInt8PtrTy(), - B.getInt8PtrTy(), B.getInt32Ty(), - DL.getIntPtrType(Context)); + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(MemChr.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -931,14 +938,15 @@ 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(); - Value *MemCmp = M->getOrInsertFunction(MemCmpName, B.getInt32Ty(), - B.getInt8PtrTy(), B.getInt8PtrTy(), - DL.getIntPtrType(Context)); + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(MemCmp.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -965,8 +973,8 @@ static Value *emitUnaryFloatFnCallHelper(Value *Op, StringRef Name, assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall"); Module *M = B.GetInsertBlock()->getModule(); - Value *Callee = M->getOrInsertFunction(Name, Op->getType(), - Op->getType()); + FunctionCallee 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 @@ -975,7 +983,8 @@ 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(Callee.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -1008,11 +1017,12 @@ Value *llvm::emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, appendTypeSuffix(Op1, Name, NameBuffer); Module *M = B.GetInsertBlock()->getModule(); - Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), Op1->getType(), - Op2->getType()); + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(Callee.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -1025,7 +1035,8 @@ Value *llvm::emitPutChar(Value *Char, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef PutCharName = TLI->getName(LibFunc_putchar); - Value *PutChar = M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty()); + FunctionCallee PutChar = + M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty()); inferLibFuncAttributes(M, PutCharName, *TLI); CallInst *CI = B.CreateCall(PutChar, B.CreateIntCast(Char, @@ -1034,7 +1045,8 @@ Value *llvm::emitPutChar(Value *Char, IRBuilder<> &B, "chari"), PutCharName); - if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(PutChar.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -1046,11 +1058,12 @@ Value *llvm::emitPutS(Value *Str, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef PutsName = TLI->getName(LibFunc_puts); - Value *PutS = + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(PutS.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -1062,15 +1075,16 @@ Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef FPutcName = TLI->getName(LibFunc_fputc); - Constant *F = M->getOrInsertFunction(FPutcName, B.getInt32Ty(), B.getInt32Ty(), - File->getType()); + FunctionCallee 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->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1082,14 +1096,15 @@ Value *llvm::emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef FPutcUnlockedName = TLI->getName(LibFunc_fputc_unlocked); - Constant *F = M->getOrInsertFunction(FPutcUnlockedName, B.getInt32Ty(), - B.getInt32Ty(), File->getType()); + FunctionCallee 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->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1101,13 +1116,14 @@ Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef FPutsName = TLI->getName(LibFunc_fputs); - Constant *F = M->getOrInsertFunction( - FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType()); + FunctionCallee 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->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1119,13 +1135,14 @@ Value *llvm::emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef FPutsUnlockedName = TLI->getName(LibFunc_fputs_unlocked); - Constant *F = M->getOrInsertFunction(FPutsUnlockedName, B.getInt32Ty(), - B.getInt8PtrTy(), File->getType()); + FunctionCallee 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->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1138,7 +1155,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); - Constant *F = M->getOrInsertFunction( + FunctionCallee F = M->getOrInsertFunction( FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(), DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType()); @@ -1148,7 +1165,8 @@ 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->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1161,12 +1179,13 @@ 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(); - Value *Malloc = M->getOrInsertFunction(MallocName, B.getInt8PtrTy(), - DL.getIntPtrType(Context)); + FunctionCallee 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->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -1181,12 +1200,13 @@ 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())); - Value *Calloc = M->getOrInsertFunction(CallocName, Attrs, B.getInt8PtrTy(), - PtrType, PtrType); + FunctionCallee 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->stripPointerCasts())) + if (const auto *F = + dyn_cast<Function>(Calloc.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -1201,7 +1221,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); - Constant *F = M->getOrInsertFunction( + FunctionCallee F = M->getOrInsertFunction( FWriteUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(), DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType()); @@ -1209,7 +1229,8 @@ 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->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1221,13 +1242,14 @@ Value *llvm::emitFGetCUnlocked(Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef FGetCUnlockedName = TLI->getName(LibFunc_fgetc_unlocked); - Constant *F = - M->getOrInsertFunction(FGetCUnlockedName, B.getInt32Ty(), File->getType()); + FunctionCallee 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->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1239,14 +1261,15 @@ Value *llvm::emitFGetSUnlocked(Value *Str, Value *Size, Value *File, Module *M = B.GetInsertBlock()->getModule(); StringRef FGetSUnlockedName = TLI->getName(LibFunc_fgets_unlocked); - Constant *F = + FunctionCallee 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->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1260,7 +1283,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); - Constant *F = M->getOrInsertFunction( + FunctionCallee F = M->getOrInsertFunction( FReadUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(), DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType()); @@ -1268,7 +1291,8 @@ 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->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp index e63155a3409..4aa40eeadda 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") { - Constant *Fn = M.getOrInsertFunction(Func, Type::getVoidTy(C)); + FunctionCallee 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)}; - Constant *Fn = M.getOrInsertFunction( + FunctionCallee 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 92c0c0bcc39..914babeb682 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 Constant *getDefaultPersonalityFn(Module *M) { +static FunctionCallee 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()) { - Constant *PersFn = getDefaultPersonalityFn(F.getParent()); - F.setPersonalityFn(PersFn); + FunctionCallee PersFn = getDefaultPersonalityFn(F.getParent()); + F.setPersonalityFn(cast<Constant>(PersFn.getCallee())); } if (isScopedEHPersonality(classifyEHPersonality(F.getPersonalityFn()))) { diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index fa6eed52ba3..b076e7503c6 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -126,36 +126,24 @@ void llvm::appendToCompilerUsed(Module &M, ArrayRef<GlobalValue *> Values) { appendToUsedList(M, "llvm.compiler.used", Values); } -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) { +FunctionCallee +llvm::declareSanitizerInitFunction(Module &M, StringRef InitName, + ArrayRef<Type *> InitArgTypes) { assert(!InitName.empty() && "Expected init function name"); - Function *F = checkSanitizerInterfaceFunction(M.getOrInsertFunction( + return M.getOrInsertFunction( InitName, FunctionType::get(Type::getVoidTy(M.getContext()), InitArgTypes, false), - AttributeList())); - F->setLinkage(Function::ExternalLinkage); - return F; + AttributeList()); } -std::pair<Function *, Function *> llvm::createSanitizerCtorAndInitFunctions( +std::pair<Function *, FunctionCallee> 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"); - Function *InitFunction = + FunctionCallee InitFunction = declareSanitizerInitFunction(M, InitName, InitArgTypes); Function *Ctor = Function::Create( FunctionType::get(Type::getVoidTy(M.getContext()), false), @@ -164,20 +152,19 @@ std::pair<Function *, Function *> llvm::createSanitizerCtorAndInitFunctions( IRBuilder<> IRB(ReturnInst::Create(M.getContext(), CtorBB)); IRB.CreateCall(InitFunction, InitArgs); if (!VersionCheckName.empty()) { - Function *VersionCheckFunction = - checkSanitizerInterfaceFunction(M.getOrInsertFunction( - VersionCheckName, FunctionType::get(IRB.getVoidTy(), {}, false), - AttributeList())); + FunctionCallee VersionCheckFunction = M.getOrInsertFunction( + VersionCheckName, FunctionType::get(IRB.getVoidTy(), {}, false), + AttributeList()); IRB.CreateCall(VersionCheckFunction, {}); } return std::make_pair(Ctor, InitFunction); } -std::pair<Function *, Function *> +std::pair<Function *, FunctionCallee> llvm::getOrCreateSanitizerCtorAndInitFunctions( Module &M, StringRef CtorName, StringRef InitName, ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs, - function_ref<void(Function *, Function *)> FunctionsCreatedCallback, + function_ref<void(Function *, FunctionCallee)> FunctionsCreatedCallback, StringRef VersionCheckName) { assert(!CtorName.empty() && "Expected ctor function name"); @@ -188,7 +175,8 @@ llvm::getOrCreateSanitizerCtorAndInitFunctions( Ctor->getReturnType() == Type::getVoidTy(M.getContext())) return {Ctor, declareSanitizerInitFunction(M, InitName, InitArgTypes)}; - Function *Ctor, *InitFunction; + Function *Ctor; + FunctionCallee InitFunction; std::tie(Ctor, InitFunction) = llvm::createSanitizerCtorAndInitFunctions( M, CtorName, InitName, InitArgTypes, InitArgs, VersionCheckName); FunctionsCreatedCallback(Ctor, InitFunction); @@ -207,9 +195,10 @@ Function *llvm::getOrCreateInitFunction(Module &M, StringRef Name) { } return F; } - Function *F = checkSanitizerInterfaceFunction(M.getOrInsertFunction( - Name, AttributeList(), Type::getVoidTy(M.getContext()))); - F->setLinkage(Function::ExternalLinkage); + Function *F = + cast<Function>(M.getOrInsertFunction(Name, AttributeList(), + Type::getVoidTy(M.getContext())) + .getCallee()); appendToGlobalCtors(M, F, 0); diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp index 85fb321e207..f1c0792da78 100644 --- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp +++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp @@ -488,8 +488,10 @@ 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))); + return cast<Function>( + M->getOrInsertFunction(Name, + getType(M->getContext(), Intrinsic::ssa_copy, Ty)) + .getCallee()); } // 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 631b2384be0..a1313c77ed7 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); - Constant *StatReport = M->getOrInsertFunction( - "__sanitizer_stat_report", StatReportTy); + FunctionCallee 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); - Constant *StatInit = M->getOrInsertFunction( - "__sanitizer_stat_init", StatInitTy); + FunctionCallee 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 c0957c11719..de4ec621da6 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1503,9 +1503,8 @@ Value *LibCallSimplifier::optimizeExp2(CallInst *CI, IRBuilder<> &B) { One = ConstantExpr::getFPExtend(One, Op->getType()); Module *M = CI->getModule(); - Value *NewCallee = - M->getOrInsertFunction(TLI->getName(LdExp), Op->getType(), - Op->getType(), B.getInt32Ty()); + FunctionCallee 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()); @@ -1727,8 +1726,8 @@ static void insertSinCosCall(IRBuilder<> &B, Function *OrigCallee, Value *Arg, } Module *M = OrigCallee->getParent(); - Value *Callee = M->getOrInsertFunction(Name, OrigCallee->getAttributes(), - ResTy, ArgTy); + FunctionCallee 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 @@ -2025,7 +2024,7 @@ Value *LibCallSimplifier::optimizePrintF(CallInst *CI, IRBuilder<> &B) { // arguments. if (TLI->has(LibFunc_iprintf) && !callHasFloatingPointArgument(CI)) { Module *M = B.GetInsertBlock()->getParent()->getParent(); - Constant *IPrintFFn = + FunctionCallee IPrintFFn = M->getOrInsertFunction("iprintf", FT, Callee->getAttributes()); CallInst *New = cast<CallInst>(CI->clone()); New->setCalledFunction(IPrintFFn); @@ -2104,7 +2103,7 @@ Value *LibCallSimplifier::optimizeSPrintF(CallInst *CI, IRBuilder<> &B) { // point arguments. if (TLI->has(LibFunc_siprintf) && !callHasFloatingPointArgument(CI)) { Module *M = B.GetInsertBlock()->getParent()->getParent(); - Constant *SIPrintFFn = + FunctionCallee SIPrintFFn = M->getOrInsertFunction("siprintf", FT, Callee->getAttributes()); CallInst *New = cast<CallInst>(CI->clone()); New->setCalledFunction(SIPrintFFn); @@ -2261,7 +2260,7 @@ Value *LibCallSimplifier::optimizeFPrintF(CallInst *CI, IRBuilder<> &B) { // floating point arguments. if (TLI->has(LibFunc_fiprintf) && !callHasFloatingPointArgument(CI)) { Module *M = B.GetInsertBlock()->getParent()->getParent(); - Constant *FIPrintFFn = + FunctionCallee FIPrintFFn = M->getOrInsertFunction("fiprintf", FT, Callee->getAttributes()); CallInst *New = cast<CallInst>(CI->clone()); New->setCalledFunction(FIPrintFFn); |