Index: llvm/include/llvm/CodeGen/TargetLowering.h =================================================================== --- llvm/include/llvm/CodeGen/TargetLowering.h +++ llvm/include/llvm/CodeGen/TargetLowering.h @@ -1514,7 +1514,7 @@ /// performs validation and error handling, returns the function. Otherwise, /// returns nullptr. Must be previously inserted by insertSSPDeclarations. /// Should be used only when getIRStackGuard returns nullptr. - virtual Value *getSSPStackGuardCheck(const Module &M) const; + virtual Function *getSSPStackGuardCheck(const Module &M) const; protected: Value *getDefaultSafeStackPointerLocation(IRBuilder<> &IRB, Index: llvm/lib/CodeGen/AtomicExpandPass.cpp =================================================================== --- llvm/lib/CodeGen/AtomicExpandPass.cpp +++ llvm/lib/CodeGen/AtomicExpandPass.cpp @@ -1756,7 +1756,7 @@ FunctionType *FnType = FunctionType::get(ResultTy, ArgTys, false); Constant *LibcallFn = M->getOrInsertFunction(TLI->getLibcallName(RTLibType), FnType, Attr); - CallInst *Call = Builder.CreateCall(LibcallFn, Args); + CallInst *Call = Builder.CreateCall(FnType, LibcallFn, Args); Call->setAttributes(Attr); Value *Result = Call; Index: llvm/lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- llvm/lib/CodeGen/CodeGenPrepare.cpp +++ llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -1177,7 +1177,7 @@ #endif Module *M = CI->getModule(); - Value *F = Intrinsic::getDeclaration(M, Intrinsic::uadd_with_overflow, Ty); + Function *F = Intrinsic::getDeclaration(M, Intrinsic::uadd_with_overflow, Ty); auto *InsertPt = AddI->hasOneUse() ? CI : AddI; Index: llvm/lib/CodeGen/DwarfEHPrepare.cpp =================================================================== --- llvm/lib/CodeGen/DwarfEHPrepare.cpp +++ llvm/lib/CodeGen/DwarfEHPrepare.cpp @@ -206,11 +206,11 @@ return true; // We pruned them all. // Find the rewind function if we didn't already. + FunctionType *RewindTy = + FunctionType::get(Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), false); if (!RewindFunction) { - FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), - Type::getInt8PtrTy(Ctx), false); const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME); - RewindFunction = Fn.getParent()->getOrInsertFunction(RewindName, FTy); + RewindFunction = Fn.getParent()->getOrInsertFunction(RewindName, RewindTy); } // Create the basic block where the _Unwind_Resume call will live. @@ -222,7 +222,8 @@ Value *ExnObj = GetExceptionObject(RI); // Call the _Unwind_Resume function. - CallInst *CI = CallInst::Create(RewindFunction, ExnObj, "", UnwindBB); + CallInst *CI = + CallInst::Create(RewindTy, RewindFunction, ExnObj, "", UnwindBB); CI->setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME)); // We never expect _Unwind_Resume to return. @@ -247,7 +248,7 @@ } // Call the function. - CallInst *CI = CallInst::Create(RewindFunction, PN, "", UnwindBB); + CallInst *CI = CallInst::Create(RewindTy, RewindFunction, PN, "", UnwindBB); CI->setCallingConv(TLI->getLibcallCallingConv(RTLIB::UNWIND_RESUME)); // We never expect _Unwind_Resume to return. Index: llvm/lib/CodeGen/IntrinsicLowering.cpp =================================================================== --- llvm/lib/CodeGen/IntrinsicLowering.cpp +++ llvm/lib/CodeGen/IntrinsicLowering.cpp @@ -71,12 +71,12 @@ std::vector ParamTys; for (ArgIt I = ArgBegin; I != ArgEnd; ++I) ParamTys.push_back((*I)->getType()); - Constant* FCache = M->getOrInsertFunction(NewFn, - FunctionType::get(RetTy, ParamTys, false)); + FunctionType *FnTy = FunctionType::get(RetTy, ParamTys, false); + Constant *FCache = M->getOrInsertFunction(NewFn, FnTy); IRBuilder<> Builder(CI->getParent(), CI->getIterator()); SmallVector Args(ArgBegin, ArgEnd); - CallInst *NewCI = Builder.CreateCall(FCache, Args); + CallInst *NewCI = Builder.CreateCall(FnTy, FCache, Args); NewCI->setName(CI->getName()); if (!CI->use_empty()) CI->replaceAllUsesWith(NewCI); @@ -600,7 +600,7 @@ // Okay, we can do this xform, do so now. Module *M = CI->getModule(); - Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty); + Function *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty); Value *Op = CI->getArgOperand(0); Op = CallInst::Create(Int, Op, CI->getName(), CI); Index: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp =================================================================== --- llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp +++ llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp @@ -82,7 +82,7 @@ IRBuilder<> Builder(CI->getParent(), CI->getIterator()); SmallVector Args(CI->arg_begin(), CI->arg_end()); - CallInst *NewCI = Builder.CreateCall(FCache, Args); + CallInst *NewCI = Builder.CreateCall(F.getFunctionType(), FCache, Args); NewCI->setName(CI->getName()); NewCI->setTailCallKind(CI->getTailCallKind()); if (!CI->use_empty()) Index: llvm/lib/CodeGen/SafeStack.cpp =================================================================== --- llvm/lib/CodeGen/SafeStack.cpp +++ llvm/lib/CodeGen/SafeStack.cpp @@ -474,9 +474,10 @@ /* Unreachable */ true, Weights); IRBuilder<> IRBFail(CheckTerm); // FIXME: respect -fsanitize-trap / -ftrap-function here? - Constant *StackChkFail = F.getParent()->getOrInsertFunction( - "__stack_chk_fail", IRB.getVoidTy()); - IRBFail.CreateCall(StackChkFail, {}); + FunctionType *FnTy = FunctionType::get(IRB.getVoidTy(), {}, false); + Constant *StackChkFail = + F.getParent()->getOrInsertFunction("__stack_chk_fail", FnTy); + IRBFail.CreateCall(FnTy, StackChkFail, {}); } /// We explicitly compute and set the unsafe stack layout for all unsafe @@ -782,9 +783,11 @@ if (DISubprogram *SP = F.getSubprogram()) IRB.SetCurrentDebugLocation(DebugLoc::get(SP->getScopeLine(), 0, SP)); if (SafeStackUsePointerAddress) { - Value *Fn = F.getParent()->getOrInsertFunction( - "__safestack_pointer_address", StackPtrTy->getPointerTo(0)); - UnsafeStackPtr = IRB.CreateCall(Fn); + FunctionType *FnTy = + FunctionType::get(StackPtrTy->getPointerTo(0), {}, false); + Value *Fn = + F.getParent()->getOrInsertFunction("__safestack_pointer_address", FnTy); + UnsafeStackPtr = IRB.CreateCall(FnTy, Fn); } else { UnsafeStackPtr = TL.getSafeStackPointerLocation(IRB); } Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -2249,27 +2249,26 @@ GuardVal = TLI.emitStackGuardXorFP(DAG, GuardVal, dl); // Retrieve guard check function, nullptr if instrumentation is inlined. - if (const Value *GuardCheck = TLI.getSSPStackGuardCheck(M)) { + if (const Function *GuardCheckFn = TLI.getSSPStackGuardCheck(M)) { // The target provides a guard check function to validate the guard value. // Generate a call to that function with the content of the guard slot as // argument. - auto *Fn = cast(GuardCheck); - FunctionType *FnTy = Fn->getFunctionType(); + FunctionType *FnTy = GuardCheckFn->getFunctionType(); assert(FnTy->getNumParams() == 1 && "Invalid function signature"); TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; Entry.Node = GuardVal; Entry.Ty = FnTy->getParamType(0); - if (Fn->hasAttribute(1, Attribute::AttrKind::InReg)) + if (GuardCheckFn->hasAttribute(1, Attribute::AttrKind::InReg)) Entry.IsInReg = true; Args.push_back(Entry); TargetLowering::CallLoweringInfo CLI(DAG); CLI.setDebugLoc(getCurSDLoc()) - .setChain(DAG.getEntryNode()) - .setCallee(Fn->getCallingConv(), FnTy->getReturnType(), - getValue(GuardCheck), std::move(Args)); + .setChain(DAG.getEntryNode()) + .setCallee(GuardCheckFn->getCallingConv(), FnTy->getReturnType(), + getValue(GuardCheckFn), std::move(Args)); std::pair Result = TLI.LowerCallTo(CLI); DAG.setRoot(Result.second); Index: llvm/lib/CodeGen/SjLjEHPrepare.cpp =================================================================== --- llvm/lib/CodeGen/SjLjEHPrepare.cpp +++ llvm/lib/CodeGen/SjLjEHPrepare.cpp @@ -39,15 +39,17 @@ Type *doubleUnderDataTy; Type *doubleUnderJBufTy; Type *FunctionContextTy; + FunctionType *RegisterFnTy; + FunctionType *UnregisterFnTy; Constant *RegisterFn; Constant *UnregisterFn; - Constant *BuiltinSetupDispatchFn; - Constant *FrameAddrFn; - Constant *StackAddrFn; - Constant *StackRestoreFn; - Constant *LSDAAddrFn; - Constant *CallSiteFn; - Constant *FuncCtxFn; + Function *BuiltinSetupDispatchFn; + Function *FrameAddrFn; + Function *StackAddrFn; + Function *StackRestoreFn; + Function *LSDAAddrFn; + Function *CallSiteFn; + Function *FuncCtxFn; AllocaInst *FuncCtx; public: @@ -436,8 +438,8 @@ } // Register the function context and make sure it's known to not throw - CallInst *Register = - CallInst::Create(RegisterFn, FuncCtx, "", EntryBB->getTerminator()); + CallInst *Register = CallInst::Create(RegisterFnTy, RegisterFn, FuncCtx, "", + EntryBB->getTerminator()); Register->setDoesNotThrow(); // Following any allocas not in the entry block, update the saved SP in the @@ -462,19 +464,22 @@ // Finally, for any returns from this function, if this function contains an // invoke, add a call to unregister the function context. for (ReturnInst *Return : Returns) - CallInst::Create(UnregisterFn, FuncCtx, "", Return); + CallInst::Create(UnregisterFnTy, UnregisterFn, FuncCtx, "", Return); return true; } bool SjLjEHPrepare::runOnFunction(Function &F) { Module &M = *F.getParent(); - RegisterFn = M.getOrInsertFunction( - "_Unwind_SjLj_Register", Type::getVoidTy(M.getContext()), - PointerType::getUnqual(FunctionContextTy)); - UnregisterFn = M.getOrInsertFunction( - "_Unwind_SjLj_Unregister", Type::getVoidTy(M.getContext()), - PointerType::getUnqual(FunctionContextTy)); + RegisterFnTy = + FunctionType::get(Type::getVoidTy(M.getContext()), + {PointerType::getUnqual(FunctionContextTy)}, false); + RegisterFn = M.getOrInsertFunction("_Unwind_SjLj_Register", RegisterFnTy); + UnregisterFnTy = + FunctionType::get(Type::getVoidTy(M.getContext()), + {PointerType::getUnqual(FunctionContextTy)}, false); + UnregisterFn = + M.getOrInsertFunction("_Unwind_SjLj_Unregister", UnregisterFnTy); FrameAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::frameaddress); StackAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::stacksave); StackRestoreFn = Intrinsic::getDeclaration(&M, Intrinsic::stackrestore); Index: llvm/lib/CodeGen/StackProtector.cpp =================================================================== --- llvm/lib/CodeGen/StackProtector.cpp +++ llvm/lib/CodeGen/StackProtector.cpp @@ -413,15 +413,14 @@ // Generate epilogue instrumentation. The epilogue intrumentation can be // function-based or inlined depending on which mechanism the target is // providing. - if (Value* GuardCheck = TLI->getSSPStackGuardCheck(*M)) { + if (Function *GuardCheck = TLI->getSSPStackGuardCheck(*M)) { // Generate the function-based epilogue instrumentation. // The target provides a guard check function, generate a call to it. IRBuilder<> B(RI); LoadInst *Guard = B.CreateLoad(AI, true, "Guard"); CallInst *Call = B.CreateCall(GuardCheck, {Guard}); - llvm::Function *Function = cast(GuardCheck); - Call->setAttributes(Function->getAttributes()); - Call->setCallingConv(Function->getCallingConv()); + Call->setAttributes(GuardCheck->getAttributes()); + Call->setCallingConv(GuardCheck->getCallingConv()); } else { // Generate the epilogue with inline instrumentation. // If we do not support SelectionDAG based tail calls, generate IR level @@ -499,17 +498,16 @@ IRBuilder<> B(FailBB); B.SetCurrentDebugLocation(DebugLoc::get(0, 0, F->getSubprogram())); if (Trip.isOSOpenBSD()) { + FunctionType *FnTy = FunctionType::get( + Type::getVoidTy(Context), {Type::getInt8PtrTy(Context)}, false); Constant *StackChkFail = - M->getOrInsertFunction("__stack_smash_handler", - Type::getVoidTy(Context), - Type::getInt8PtrTy(Context)); - - B.CreateCall(StackChkFail, B.CreateGlobalStringPtr(F->getName(), "SSH")); + M->getOrInsertFunction("__stack_smash_handler", FnTy); + B.CreateCall(FnTy, StackChkFail, + B.CreateGlobalStringPtr(F->getName(), "SSH")); } else { - Constant *StackChkFail = - M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context)); - - B.CreateCall(StackChkFail, {}); + FunctionType *FnTy = FunctionType::get(Type::getVoidTy(Context), {}, false); + Constant *StackChkFail = M->getOrInsertFunction("__stack_chk_fail", FnTy); + B.CreateCall(FnTy, StackChkFail, {}); } B.CreateUnreachable(); return FailBB; Index: llvm/lib/CodeGen/TargetLoweringBase.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringBase.cpp +++ llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -1587,9 +1587,10 @@ // thread's unsafe stack pointer. Module *M = IRB.GetInsertBlock()->getParent()->getParent(); Type *StackPtrTy = Type::getInt8PtrTy(M->getContext()); - Value *Fn = M->getOrInsertFunction("__safestack_pointer_address", - StackPtrTy->getPointerTo(0)); - return IRB.CreateCall(Fn); + FunctionType *FnTy = + FunctionType::get(StackPtrTy->getPointerTo(0), {}, false); + Value *Fn = M->getOrInsertFunction("__safestack_pointer_address", FnTy); + return IRB.CreateCall(FnTy, Fn); } //===----------------------------------------------------------------------===// @@ -1663,7 +1664,7 @@ return M.getNamedValue("__stack_chk_guard"); } -Value *TargetLoweringBase::getSSPStackGuardCheck(const Module &M) const { +Function *TargetLoweringBase::getSSPStackGuardCheck(const Module &M) const { return nullptr; } Index: llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp =================================================================== --- llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -235,13 +235,14 @@ assert(F.isDeclaration() && "Can't turn a definition into a stub."); assert(F.getParent() && "Function isn't in a module."); Module &M = *F.getParent(); + FunctionType *FTy = F.getFunctionType(); BasicBlock *EntryBlock = BasicBlock::Create(M.getContext(), "entry", &F); IRBuilder<> Builder(EntryBlock); LoadInst *ImplAddr = Builder.CreateLoad(&ImplPointer); std::vector CallArgs; for (auto &A : F.args()) CallArgs.push_back(&A); - CallInst *Call = Builder.CreateCall(ImplAddr, CallArgs); + CallInst *Call = Builder.CreateCall(FTy, ImplAddr, CallArgs); Call->setTailCall(); Call->setAttributes(F.getAttributes()); if (F.getReturnType()->isVoidTy()) Index: llvm/lib/IR/IRBuilder.cpp =================================================================== --- llvm/lib/IR/IRBuilder.cpp +++ llvm/lib/IR/IRBuilder.cpp @@ -71,7 +71,7 @@ return BCI; } -static CallInst *createCallHelper(Value *Callee, ArrayRef Ops, +static CallInst *createCallHelper(Function *Callee, ArrayRef Ops, IRBuilderBase *Builder, const Twine &Name = "", Instruction *FMFSource = nullptr) { @@ -104,7 +104,7 @@ Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)}; Type *Tys[] = { Ptr->getType(), Size->getType() }; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys); + Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys); CallInst *CI = createCallHelper(TheFn, Ops, this); @@ -134,7 +134,7 @@ Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)}; Type *Tys[] = {Ptr->getType(), Size->getType()}; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration( + Function *TheFn = Intrinsic::getDeclaration( M, Intrinsic::memset_element_unordered_atomic, Tys); CallInst *CI = createCallHelper(TheFn, Ops, this); @@ -166,7 +166,7 @@ Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)}; Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys); + Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys); CallInst *CI = createCallHelper(TheFn, Ops, this); @@ -207,7 +207,7 @@ Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)}; Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()}; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration( + Function *TheFn = Intrinsic::getDeclaration( M, Intrinsic::memcpy_element_unordered_atomic, Tys); CallInst *CI = createCallHelper(TheFn, Ops, this); @@ -246,7 +246,7 @@ Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)}; Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys); + Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys); CallInst *CI = createCallHelper(TheFn, Ops, this); @@ -283,7 +283,7 @@ Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)}; Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()}; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration( + Function *TheFn = Intrinsic::getDeclaration( M, Intrinsic::memmove_element_unordered_atomic, Tys); CallInst *CI = createCallHelper(TheFn, Ops, this); @@ -408,8 +408,8 @@ "lifetime.start requires the size to be an i64"); Value *Ops[] = { Size, Ptr }; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_start, - { Ptr->getType() }); + Function *TheFn = + Intrinsic::getDeclaration(M, Intrinsic::lifetime_start, {Ptr->getType()}); return createCallHelper(TheFn, Ops, this); } @@ -424,8 +424,8 @@ "lifetime.end requires the size to be an i64"); Value *Ops[] = { Size, Ptr }; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end, - { Ptr->getType() }); + Function *TheFn = + Intrinsic::getDeclaration(M, Intrinsic::lifetime_end, {Ptr->getType()}); return createCallHelper(TheFn, Ops, this); } @@ -444,7 +444,7 @@ // Fill in the single overloaded type: memory object type. Type *ObjectPtr[1] = {Ptr->getType()}; Module *M = BB->getParent()->getParent(); - Value *TheFn = + Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::invariant_start, ObjectPtr); return createCallHelper(TheFn, Ops, this); } @@ -455,7 +455,7 @@ Value *Ops[] = { Cond }; Module *M = BB->getParent()->getParent(); - Value *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume); + Function *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume); return createCallHelper(FnAssume, Ops, this); } @@ -507,7 +507,7 @@ ArrayRef OverloadedTypes, const Twine &Name) { Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration(M, Id, OverloadedTypes); + Function *TheFn = Intrinsic::getDeclaration(M, Id, OverloadedTypes); return createCallHelper(TheFn, Ops, this, Name); } @@ -708,7 +708,7 @@ Intrinsic::ID ID = Intrinsic::experimental_gc_result; Module *M = BB->getParent()->getParent(); Type *Types[] = {ResultType}; - Value *FnGCResult = Intrinsic::getDeclaration(M, ID, Types); + Function *FnGCResult = Intrinsic::getDeclaration(M, ID, Types); Value *Args[] = {Statepoint}; return createCallHelper(FnGCResult, Args, this, Name); @@ -721,8 +721,8 @@ const Twine &Name) { Module *M = BB->getParent()->getParent(); Type *Types[] = {ResultType}; - Value *FnGCRelocate = - Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types); + Function *FnGCRelocate = + Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types); Value *Args[] = {Statepoint, getInt32(BaseOffset), Index: llvm/lib/IR/Instructions.cpp =================================================================== --- llvm/lib/IR/Instructions.cpp +++ llvm/lib/IR/Instructions.cpp @@ -428,8 +428,8 @@ Instruction *InsertPt) { std::vector Args(CI->arg_begin(), CI->arg_end()); - auto *NewCI = CallInst::Create(CI->getCalledValue(), Args, OpB, CI->getName(), - InsertPt); + auto *NewCI = CallInst::Create(CI->getFunctionType(), CI->getCalledValue(), + Args, OpB, CI->getName(), InsertPt); NewCI->setTailCallKind(CI->getTailCallKind()); NewCI->setCallingConv(CI->getCallingConv()); NewCI->SubclassOptionalData = CI->SubclassOptionalData; @@ -502,22 +502,29 @@ BasicBlock *BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd; Module *M = BB->getParent()->getParent(); Type *BPTy = Type::getInt8PtrTy(BB->getContext()); - Value *MallocFunc = MallocF; - if (!MallocFunc) + Constant *MallocFunc; + FunctionType *MallocFnTy; + if (MallocF) { + MallocFnTy = MallocF->getFunctionType(); + MallocFunc = MallocF; + } else { // prototype malloc as "void *malloc(size_t)" - MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy); + MallocFnTy = FunctionType::get(BPTy, {IntPtrTy}, false); + MallocFunc = M->getOrInsertFunction("malloc", MallocFnTy); + } PointerType *AllocPtrType = PointerType::getUnqual(AllocTy); CallInst *MCall = nullptr; Instruction *Result = nullptr; if (InsertBefore) { - MCall = CallInst::Create(MallocFunc, AllocSize, OpB, "malloccall", - InsertBefore); + MCall = CallInst::Create(MallocFnTy, MallocFunc, AllocSize, OpB, + "malloccall", InsertBefore); Result = MCall; if (Result->getType() != AllocPtrType) // Create a cast instruction to convert to the right type... Result = new BitCastInst(MCall, AllocPtrType, Name, InsertBefore); } else { - MCall = CallInst::Create(MallocFunc, AllocSize, OpB, "malloccall"); + MCall = + CallInst::Create(MallocFnTy, MallocFunc, AllocSize, OpB, "malloccall"); Result = MCall; if (Result->getType() != AllocPtrType) { InsertAtEnd->getInstList().push_back(MCall); @@ -599,17 +606,19 @@ Type *VoidTy = Type::getVoidTy(M->getContext()); Type *IntPtrTy = Type::getInt8PtrTy(M->getContext()); // prototype free as "void free(void*)" - Value *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy); + FunctionType *FreeTy = FunctionType::get(VoidTy, {IntPtrTy}, false); + Value *FreeFunc = M->getOrInsertFunction("free", FreeTy); CallInst *Result = nullptr; Value *PtrCast = Source; if (InsertBefore) { if (Source->getType() != IntPtrTy) PtrCast = new BitCastInst(Source, IntPtrTy, "", InsertBefore); - Result = CallInst::Create(FreeFunc, PtrCast, Bundles, "", InsertBefore); + Result = + CallInst::Create(FreeTy, FreeFunc, PtrCast, Bundles, "", InsertBefore); } else { if (Source->getType() != IntPtrTy) PtrCast = new BitCastInst(Source, IntPtrTy, "", InsertAtEnd); - Result = CallInst::Create(FreeFunc, PtrCast, Bundles, ""); + Result = CallInst::Create(FreeTy, FreeFunc, PtrCast, Bundles, ""); } Result->setTailCall(); if (Function *F = dyn_cast(FreeFunc)) Index: llvm/lib/Target/AArch64/AArch64ISelLowering.h =================================================================== --- llvm/lib/Target/AArch64/AArch64ISelLowering.h +++ llvm/lib/Target/AArch64/AArch64ISelLowering.h @@ -408,7 +408,7 @@ void insertSSPDeclarations(Module &M) const override; Value *getSDagStackGuard(const Module &M) const override; - Value *getSSPStackGuardCheck(const Module &M) const override; + Function *getSSPStackGuardCheck(const Module &M) const override; /// If the target has a standard location for the unsafe stack pointer, /// returns the address of that location. Otherwise, returns nullptr. Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -11768,7 +11768,7 @@ return TargetLowering::getSDagStackGuard(M); } -Value *AArch64TargetLowering::getSSPStackGuardCheck(const Module &M) const { +Function *AArch64TargetLowering::getSSPStackGuardCheck(const Module &M) const { // MSVC CRT has a function to validate security cookie. if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment()) return M.getFunction("__security_check_cookie"); Index: llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp +++ llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp @@ -72,7 +72,7 @@ // Return a pointer (pointer expr) to the function if function defintion with // "FuncName" exists. It may create a new function prototype in pre-link mode. - Constant *getFunction(Module *M, const FuncInfo& fInfo); + Function *getFunction(Module *M, const FuncInfo &fInfo); // Replace a normal function with its native version. bool replaceWithNative(CallInst *CI, const FuncInfo &FInfo); @@ -139,7 +139,7 @@ // Insert an Alloc instruction. AllocaInst* insertAlloca(CallInst * UI, IRBuilder<> &B, const char *prefix); // Get a scalar native builtin signle argument FP function - Constant* getNativeFunction(Module* M, const FuncInfo &FInfo); + Function *getNativeFunction(Module *M, const FuncInfo &FInfo); protected: CallInst *CI; @@ -216,20 +216,18 @@ false, false) template -static CallInst *CreateCallEx(IRB &B, Value *Callee, Value *Arg, +static CallInst *CreateCallEx(IRB &B, Function *Callee, Value *Arg, const Twine &Name = "") { CallInst *R = B.CreateCall(Callee, Arg, Name); - if (Function* F = dyn_cast(Callee)) - R->setCallingConv(F->getCallingConv()); + R->setCallingConv(Callee->getCallingConv()); return R; } template -static CallInst *CreateCallEx2(IRB &B, Value *Callee, Value *Arg1, Value *Arg2, - const Twine &Name = "") { +static CallInst *CreateCallEx2(IRB &B, Function *Callee, Value *Arg1, + Value *Arg2, const Twine &Name = "") { CallInst *R = B.CreateCall(Callee, {Arg1, Arg2}, Name); - if (Function* F = dyn_cast(Callee)) - R->setCallingConv(F->getCallingConv()); + R->setCallingConv(Callee->getCallingConv()); return R; } @@ -471,7 +469,7 @@ return (AMDGPULibFunc::EType)FInfo.getLeads()[0].ArgType; } -Constant *AMDGPULibCalls::getFunction(Module *M, const FuncInfo& fInfo) { +Function *AMDGPULibCalls::getFunction(Module *M, const FuncInfo &fInfo) { // If we are doing PreLinkOpt, the function is external. So it is safe to // use getOrInsertFunction() at this stage. @@ -518,11 +516,11 @@ nf.setPrefix(AMDGPULibFunc::NATIVE); nf.setId(AMDGPULibFunc::EI_SIN); - Constant *sinExpr = getFunction(M, nf); + Function *sinExpr = getFunction(M, nf); nf.setPrefix(AMDGPULibFunc::NATIVE); nf.setId(AMDGPULibFunc::EI_COS); - Constant *cosExpr = getFunction(M, nf); + Function *cosExpr = getFunction(M, nf); if (sinExpr && cosExpr) { Value *sinval = CallInst::Create(sinExpr, opr0, "splitsin", aCI); Value *cosval = CallInst::Create(cosExpr, opr0, "splitcos", aCI); @@ -933,13 +931,14 @@ if (CF && (CF->isExactlyValue(0.5) || CF->isExactlyValue(-0.5))) { // pow[r](x, [-]0.5) = sqrt(x) bool issqrt = CF->isExactlyValue(0.5); - if (Constant *FPExpr = getFunction(M, - AMDGPULibFunc(issqrt ? AMDGPULibFunc::EI_SQRT - : AMDGPULibFunc::EI_RSQRT, FInfo))) { + if (Function *FPExpr = + getFunction(M, AMDGPULibFunc(issqrt ? AMDGPULibFunc::EI_SQRT + : AMDGPULibFunc::EI_RSQRT, + FInfo))) { LLVM_DEBUG(errs() << "AMDIC: " << *CI << " ---> " << FInfo.getName().c_str() << "(" << *opr0 << ")\n"); - Value *nval = CreateCallEx(B,FPExpr, opr0, issqrt ? "__pow2sqrt" - : "__pow2rsqrt"); + Value *nval = + CreateCallEx(B, FPExpr, opr0, issqrt ? "__pow2sqrt" : "__pow2rsqrt"); replaceCall(nval); return true; } @@ -1002,8 +1001,8 @@ // powr ---> exp2(y * log2(x)) // pown/pow ---> powr(fabs(x), y) | (x & ((int)y << 31)) - Constant *ExpExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_EXP2, - FInfo)); + Function *ExpExpr = + getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_EXP2, FInfo)); if (!ExpExpr) return false; @@ -1089,8 +1088,8 @@ Value *nval; if (needabs) { - Constant *AbsExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_FABS, - FInfo)); + Function *AbsExpr = + getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_FABS, FInfo)); if (!AbsExpr) return false; nval = CreateCallEx(B, AbsExpr, opr0, "__fabs"); @@ -1098,11 +1097,11 @@ nval = cnval ? cnval : opr0; } if (needlog) { - Constant *LogExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_LOG2, - FInfo)); + Function *LogExpr = + getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_LOG2, FInfo)); if (!LogExpr) return false; - nval = CreateCallEx(B,LogExpr, nval, "__log2"); + nval = CreateCallEx(B, LogExpr, nval, "__log2"); } if (FInfo.getId() == AMDGPULibFunc::EI_POWN) { @@ -1110,7 +1109,7 @@ opr1 = B.CreateSIToFP(opr1, nval->getType(), "pownI2F"); } nval = B.CreateFMul(opr1, nval, "__ylogx"); - nval = CreateCallEx(B,ExpExpr, nval, "__exp2"); + nval = CreateCallEx(B, ExpExpr, nval, "__exp2"); if (needcopysign) { Value *opr_n; @@ -1158,19 +1157,19 @@ std::vector ParamsTys; ParamsTys.push_back(opr0->getType()); Module *M = CI->getModule(); - if (Constant *FPExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_SQRT, - FInfo))) { + if (Function *FPExpr = + getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_SQRT, FInfo))) { LLVM_DEBUG(errs() << "AMDIC: " << *CI << " ---> sqrt(" << *opr0 << ")\n"); - Value *nval = CreateCallEx(B,FPExpr, opr0, "__rootn2sqrt"); + Value *nval = CreateCallEx(B, FPExpr, opr0, "__rootn2sqrt"); replaceCall(nval); return true; } } else if (ci_opr1 == 3) { // rootn(x, 3) = cbrt(x) Module *M = CI->getModule(); - if (Constant *FPExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_CBRT, - FInfo))) { + if (Function *FPExpr = + getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_CBRT, FInfo))) { LLVM_DEBUG(errs() << "AMDIC: " << *CI << " ---> cbrt(" << *opr0 << ")\n"); - Value *nval = CreateCallEx(B,FPExpr, opr0, "__rootn2cbrt"); + Value *nval = CreateCallEx(B, FPExpr, opr0, "__rootn2cbrt"); replaceCall(nval); return true; } @@ -1185,11 +1184,11 @@ std::vector ParamsTys; ParamsTys.push_back(opr0->getType()); Module *M = CI->getModule(); - if (Constant *FPExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_RSQRT, - FInfo))) { + if (Function *FPExpr = + getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_RSQRT, FInfo))) { LLVM_DEBUG(errs() << "AMDIC: " << *CI << " ---> rsqrt(" << *opr0 << ")\n"); - Value *nval = CreateCallEx(B,FPExpr, opr0, "__rootn2rsqrt"); + Value *nval = CreateCallEx(B, FPExpr, opr0, "__rootn2rsqrt"); replaceCall(nval); return true; } @@ -1242,7 +1241,7 @@ } // Get a scalar native builtin signle argument FP function -Constant* AMDGPULibCalls::getNativeFunction(Module* M, const FuncInfo& FInfo) { +Function *AMDGPULibCalls::getNativeFunction(Module *M, const FuncInfo &FInfo) { if (getArgType(FInfo) == AMDGPULibFunc::F64 || !HasNative(FInfo.getId())) return nullptr; FuncInfo nf = FInfo; @@ -1255,12 +1254,12 @@ const FuncInfo &FInfo) { if (getArgType(FInfo) == AMDGPULibFunc::F32 && (getVecSize(FInfo) == 1) && (FInfo.getPrefix() != AMDGPULibFunc::NATIVE)) { - if (Constant *FPExpr = getNativeFunction( - CI->getModule(), AMDGPULibFunc(AMDGPULibFunc::EI_SQRT, FInfo))) { + if (Function *FPExpr = getNativeFunction( + CI->getModule(), AMDGPULibFunc(AMDGPULibFunc::EI_SQRT, FInfo))) { Value *opr0 = CI->getArgOperand(0); LLVM_DEBUG(errs() << "AMDIC: " << *CI << " ---> " << "sqrt(" << *opr0 << ")\n"); - Value *nval = CreateCallEx(B,FPExpr, opr0, "__sqrt"); + Value *nval = CreateCallEx(B, FPExpr, opr0, "__sqrt"); replaceCall(nval); return true; } Index: llvm/lib/Target/Hexagon/HexagonGenExtract.cpp =================================================================== --- llvm/lib/Target/Hexagon/HexagonGenExtract.cpp +++ llvm/lib/Target/Hexagon/HexagonGenExtract.cpp @@ -210,7 +210,7 @@ Intrinsic::ID IntId = (BW == 32) ? Intrinsic::hexagon_S2_extractu : Intrinsic::hexagon_S2_extractup; Module *Mod = BB->getParent()->getParent(); - Value *ExtF = Intrinsic::getDeclaration(Mod, IntId); + Function *ExtF = Intrinsic::getDeclaration(Mod, IntId); Value *NewIn = IRB.CreateCall(ExtF, {BF, IRB.getInt32(W), IRB.getInt32(SR)}); if (SL != 0) NewIn = IRB.CreateShl(NewIn, SL, CSL->getName()); Index: llvm/lib/Target/Hexagon/HexagonISelLowering.cpp =================================================================== --- llvm/lib/Target/Hexagon/HexagonISelLowering.cpp +++ llvm/lib/Target/Hexagon/HexagonISelLowering.cpp @@ -3116,12 +3116,12 @@ assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic loads supported"); Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_L2_loadw_locked : Intrinsic::hexagon_L4_loadd_locked; + Function *Fn = Intrinsic::getDeclaration(M, IntID); PointerType *NewPtrTy = Builder.getIntNTy(SZ)->getPointerTo(PT->getAddressSpace()); Addr = Builder.CreateBitCast(Addr, NewPtrTy); - Value *Fn = Intrinsic::getDeclaration(M, IntID); Value *Call = Builder.CreateCall(Fn, Addr, "larx"); return Builder.CreateBitCast(Call, Ty); @@ -3140,7 +3140,7 @@ assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic stores supported"); Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_S2_storew_locked : Intrinsic::hexagon_S4_stored_locked; - Value *Fn = Intrinsic::getDeclaration(M, IntID); + Function *Fn = Intrinsic::getDeclaration(M, IntID); unsigned AS = Addr->getType()->getPointerAddressSpace(); Addr = Builder.CreateBitCast(Addr, CastTy->getPointerTo(AS)); Index: llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp =================================================================== --- llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp +++ llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp @@ -1523,7 +1523,7 @@ ParsedValues &PV) { IRBuilder<> B(&*At); Module *M = At->getParent()->getParent()->getParent(); - Value *PMF = Intrinsic::getDeclaration(M, Intrinsic::hexagon_M4_pmpyw); + Function *PMF = Intrinsic::getDeclaration(M, Intrinsic::hexagon_M4_pmpyw); Value *P = PV.P, *Q = PV.Q, *P0 = P; unsigned IC = PV.IterCount; Index: llvm/lib/Target/Mips/Mips16HardFloat.cpp =================================================================== --- llvm/lib/Target/Mips/Mips16HardFloat.cpp +++ llvm/lib/Target/Mips/Mips16HardFloat.cpp @@ -51,7 +51,7 @@ FunctionType::get(Type::getVoidTy(C), AsmArgTypes, false); InlineAsm *IA = InlineAsm::get(AsmFTy, AsmText, "", true, /* IsAlignStack */ false, InlineAsm::AD_ATT); - CallInst::Create(IA, AsmArgs, "", BB); + CallInst::Create(AsmFTy, IA, AsmArgs, "", BB); } char Mips16HardFloat::ID = 0; @@ -414,8 +414,9 @@ Attribute::ReadNone); A = A.addAttribute(C, AttributeList::FunctionIndex, Attribute::NoInline); - Value *F = (M->getOrInsertFunction(Name, A, MyVoid, T)); - CallInst::Create(F, Params, "", &I); + FunctionType *FTy = FunctionType::get(MyVoid, {T}, false); + Value *F = (M->getOrInsertFunction(Name, FTy, A)); + CallInst::Create(FTy, F, Params, "", &I); } else if (const CallInst *CI = dyn_cast(&I)) { FunctionType *FT = CI->getFunctionType(); Function *F_ = CI->getCalledFunction(); Index: llvm/lib/Target/PowerPC/PPCCTRLoops.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCCTRLoops.cpp +++ llvm/lib/Target/PowerPC/PPCCTRLoops.cpp @@ -660,13 +660,13 @@ IRBuilder<> CountBuilder(Preheader->getTerminator()); Module *M = Preheader->getParent()->getParent(); - Value *MTCTRFunc = Intrinsic::getDeclaration(M, Intrinsic::ppc_mtctr, - CountType); + Function *MTCTRFunc = + Intrinsic::getDeclaration(M, Intrinsic::ppc_mtctr, CountType); CountBuilder.CreateCall(MTCTRFunc, ECValue); IRBuilder<> CondBuilder(CountedExitBranch); - Value *DecFunc = - Intrinsic::getDeclaration(M, Intrinsic::ppc_is_decremented_ctr_nonzero); + Function *DecFunc = + Intrinsic::getDeclaration(M, Intrinsic::ppc_is_decremented_ctr_nonzero); Value *NewCond = CondBuilder.CreateCall(DecFunc, {}); Value *OldCond = CountedExitBranch->getCondition(); CountedExitBranch->setCondition(NewCond); Index: llvm/lib/Target/SystemZ/SystemZTDC.cpp =================================================================== --- llvm/lib/Target/SystemZ/SystemZTDC.cpp +++ llvm/lib/Target/SystemZ/SystemZTDC.cpp @@ -355,8 +355,8 @@ if (!Worthy) continue; // Call the intrinsic, compare result with 0. - Value *TDCFunc = Intrinsic::getDeclaration(&M, Intrinsic::s390_tdc, - V->getType()); + Function *TDCFunc = + Intrinsic::getDeclaration(&M, Intrinsic::s390_tdc, V->getType()); IRBuilder<> IRB(I); Value *MaskVal = ConstantInt::get(Type::getInt64Ty(Ctx), Mask); Instruction *TDC = IRB.CreateCall(TDCFunc, {V, MaskVal}); Index: llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp =================================================================== --- llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp +++ llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp @@ -256,7 +256,7 @@ UndefValue::get(MainArgTys[1])}; Value *Casted = ConstantExpr::getBitCast(Main, PointerType::get(MainTy, 0)); - CallMain = CallInst::Create(Casted, Args, "call_main"); + CallMain = CallInst::Create(MainTy, Casted, Args, "call_main"); Use *UseMain = &CallMain->getOperandUse(2); Uses.push_back(std::make_pair(UseMain, &F)); } Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp =================================================================== --- llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp @@ -768,7 +768,8 @@ // This can't throw, and we don't need this invoke, just replace it with a // call+branch SmallVector Args(II->arg_begin(), II->arg_end()); - CallInst *NewCall = IRB.CreateCall(II->getCalledValue(), Args); + CallInst *NewCall = + IRB.CreateCall(II->getFunctionType(), II->getCalledValue(), Args); NewCall->takeName(II); NewCall->setCallingConv(II->getCallingConv()); NewCall->setDebugLoc(II->getDebugLoc()); Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp =================================================================== --- llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp +++ llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp @@ -142,13 +142,13 @@ : Twine()), &M); BasicBlock *BB = BasicBlock::Create(C, "body", CallDtors); + FunctionType *VoidVoid = FunctionType::get(Type::getVoidTy(C), + /*isVarArg=*/false); for (auto Dtor : AssociatedAndMore.second) - CallInst::Create(Dtor, "", BB); + CallInst::Create(VoidVoid, Dtor, "", BB); ReturnInst::Create(C, BB); - FunctionType *VoidVoid = FunctionType::get(Type::getVoidTy(C), - /*isVarArg=*/false); Function *RegisterCallDtors = Function::Create( VoidVoid, Function::PrivateLinkage, "register_call_dtors" + @@ -163,7 +163,7 @@ Value *Null = ConstantPointerNull::get(VoidStar); Value *Args[] = {CallDtors, Null, DsoHandle}; - Value *Res = CallInst::Create(AtExit, Args, "call", EntryBB); + Value *Res = CallInst::Create(AtExitTy, AtExit, Args, "call", EntryBB); Value *Cmp = new ICmpInst(*EntryBB, ICmpInst::ICMP_NE, Res, Constant::getNullValue(Res->getType())); BranchInst::Create(FailBB, RetBB, Cmp, EntryBB); Index: llvm/lib/Target/X86/X86ISelLowering.h =================================================================== --- llvm/lib/Target/X86/X86ISelLowering.h +++ llvm/lib/Target/X86/X86ISelLowering.h @@ -1104,7 +1104,7 @@ bool useStackGuardXorFP() const override; void insertSSPDeclarations(Module &M) const override; Value *getSDagStackGuard(const Module &M) const override; - Value *getSSPStackGuardCheck(const Module &M) const override; + Function *getSSPStackGuardCheck(const Module &M) const override; SDValue emitStackGuardXorFP(SelectionDAG &DAG, SDValue Val, const SDLoc &DL) const override; Index: llvm/lib/Target/X86/X86ISelLowering.cpp =================================================================== --- llvm/lib/Target/X86/X86ISelLowering.cpp +++ llvm/lib/Target/X86/X86ISelLowering.cpp @@ -2303,7 +2303,7 @@ return TargetLowering::getSDagStackGuard(M); } -Value *X86TargetLowering::getSSPStackGuardCheck(const Module &M) const { +Function *X86TargetLowering::getSSPStackGuardCheck(const Module &M) const { // MSVC CRT has a function to validate security cookie. if (Subtarget.getTargetTriple().isWindowsMSVCEnvironment() || Subtarget.getTargetTriple().isWindowsItaniumEnvironment()) { Index: llvm/lib/Target/X86/X86WinEHState.cpp =================================================================== --- llvm/lib/Target/X86/X86WinEHState.cpp +++ llvm/lib/Target/X86/X86WinEHState.cpp @@ -86,6 +86,7 @@ StructType *EHLinkRegistrationTy = nullptr; StructType *CXXEHRegistrationTy = nullptr; StructType *SEHRegistrationTy = nullptr; + FunctionType *SetJmp3Ty = nullptr; Constant *SetJmp3 = nullptr; Constant *CxxLongjmpUnwind = nullptr; @@ -130,6 +131,7 @@ EHLinkRegistrationTy = nullptr; CXXEHRegistrationTy = nullptr; SEHRegistrationTy = nullptr; + SetJmp3Ty = nullptr; SetJmp3 = nullptr; CxxLongjmpUnwind = nullptr; SehLongjmpUnwind = nullptr; @@ -174,11 +176,11 @@ return false; Type *Int8PtrType = Type::getInt8PtrTy(TheModule->getContext()); - SetJmp3 = TheModule->getOrInsertFunction( - "_setjmp3", FunctionType::get( - Type::getInt32Ty(TheModule->getContext()), - {Int8PtrType, Type::getInt32Ty(TheModule->getContext())}, - /*isVarArg=*/true)); + SetJmp3Ty = FunctionType::get( + Type::getInt32Ty(TheModule->getContext()), + {Int8PtrType, Type::getInt32Ty(TheModule->getContext())}, + /*isVarArg=*/true); + SetJmp3 = TheModule->getOrInsertFunction("_setjmp3", SetJmp3Ty); // Disable frame pointer elimination in this function. // FIXME: Do the nested handlers need to keep the parent ebp in ebp, or can we @@ -411,7 +413,7 @@ Builder.CreateBitCast(PersonalityFn, TargetFuncTy->getPointerTo()); auto AI = Trampoline->arg_begin(); Value *Args[5] = {LSDA, &*AI++, &*AI++, &*AI++, &*AI++}; - CallInst *Call = Builder.CreateCall(CastPersonality, Args); + CallInst *Call = Builder.CreateCall(TargetFuncTy, CastPersonality, Args); // Can't use musttail due to prototype mismatch, but we can use tail. Call->setTailCall(true); // Set inreg so we pass it in EAX. @@ -492,7 +494,7 @@ CallSite NewCS; if (CS.isCall()) { auto *CI = cast(Inst); - CallInst *NewCI = Builder.CreateCall(SetJmp3, Args, OpBundles); + CallInst *NewCI = Builder.CreateCall(SetJmp3Ty, SetJmp3, Args, OpBundles); NewCI->setTailCallKind(CI->getTailCallKind()); NewCS = NewCI; } else { Index: llvm/lib/Transforms/Coroutines/CoroSplit.cpp =================================================================== --- llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -827,6 +827,7 @@ // split. static void prepareForSplit(Function &F, CallGraph &CG) { Module &M = *F.getParent(); + LLVMContext &Context = F.getContext(); #ifndef NDEBUG Function *DevirtFn = M.getFunction(CORO_DEVIRT_TRIGGER_FN); assert(DevirtFn && "coro.devirt.trigger function not found"); @@ -841,10 +842,12 @@ // call void %1(i8* null) coro::LowererBase Lowerer(M); Instruction *InsertPt = F.getEntryBlock().getTerminator(); - auto *Null = ConstantPointerNull::get(Type::getInt8PtrTy(F.getContext())); + auto *Null = ConstantPointerNull::get(Type::getInt8PtrTy(Context)); auto *DevirtFnAddr = Lowerer.makeSubFnCall(Null, CoroSubFnInst::RestartTrigger, InsertPt); - auto *IndirectCall = CallInst::Create(DevirtFnAddr, Null, "", InsertPt); + FunctionType *FnTy = FunctionType::get(Type::getVoidTy(Context), + {Type::getInt8PtrTy(Context)}, false); + auto *IndirectCall = CallInst::Create(FnTy, DevirtFnAddr, Null, "", InsertPt); // Update CG graph with an indirect call we just added. CG[&F]->addCalledFunction(IndirectCall, CG.getCallsExternalNode()); Index: llvm/lib/Transforms/IPO/ArgumentPromotion.cpp =================================================================== --- llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -325,7 +325,8 @@ NewCS = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(), Args, OpBundles, "", Call); } else { - auto *NewCall = CallInst::Create(NF, Args, OpBundles, "", Call); + auto *NewCall = CallInst::Create(NF->getFunctionType(), NF, Args, + OpBundles, "", Call); NewCall->setTailCallKind(cast(Call)->getTailCallKind()); NewCS = NewCall; } Index: llvm/lib/Transforms/IPO/CrossDSOCFI.cpp =================================================================== --- llvm/lib/Transforms/IPO/CrossDSOCFI.cpp +++ llvm/lib/Transforms/IPO/CrossDSOCFI.cpp @@ -132,10 +132,13 @@ BasicBlock *TrapBB = BasicBlock::Create(Ctx, "fail", F); IRBuilder<> IRBFail(TrapBB); - Constant *CFICheckFailFn = M.getOrInsertFunction( - "__cfi_check_fail", Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), - Type::getInt8PtrTy(Ctx)); - IRBFail.CreateCall(CFICheckFailFn, {&CFICheckFailData, &Addr}); + FunctionType *CFICheckFailFnTy = FunctionType::get( + Type::getVoidTy(Ctx), {Type::getInt8PtrTy(Ctx), Type::getInt8PtrTy(Ctx)}, + false); + Constant *CFICheckFailFn = + M.getOrInsertFunction("__cfi_check_fail", CFICheckFailFnTy); + IRBFail.CreateCall(CFICheckFailFnTy, CFICheckFailFn, + {&CFICheckFailData, &Addr}); IRBFail.CreateBr(ExitBB); IRBuilder<> IRBExit(ExitBB); Index: llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp =================================================================== --- llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -200,7 +200,8 @@ NewCS = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(), Args, OpBundles, "", Call); } else { - NewCS = CallInst::Create(NF, Args, OpBundles, "", Call); + NewCS = CallInst::Create(NF->getFunctionType(), NF, Args, OpBundles, "", + Call); cast(NewCS.getInstruction()) ->setTailCallKind(cast(Call)->getTailCallKind()); } @@ -938,7 +939,7 @@ NewCS = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(), Args, OpBundles, "", Call->getParent()); } else { - NewCS = CallInst::Create(NF, Args, OpBundles, "", Call); + NewCS = CallInst::Create(NFTy, NF, Args, OpBundles, "", Call); cast(NewCS.getInstruction()) ->setTailCallKind(cast(Call)->getTailCallKind()); } Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp =================================================================== --- llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -1333,7 +1333,7 @@ AsmOS.str(), ConstraintOS.str(), /*hasSideEffects=*/true); - IRB.CreateCall(JumpTableAsm, AsmArgs); + IRB.CreateCall(JumpTableAsm->getFunctionType(), JumpTableAsm, AsmArgs); IRB.CreateUnreachable(); } Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp =================================================================== --- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp +++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp @@ -881,7 +881,7 @@ } BasicBlock *BB = BasicBlock::Create(M.getContext(), "", JT, nullptr); - Constant *Intr = + Function *Intr = Intrinsic::getDeclaration(&M, llvm::Intrinsic::icall_branch_funnel, {}); auto *CI = CallInst::Create(Intr, JTArgs, "", BB); @@ -920,9 +920,10 @@ NewArgs.push_back(Int8PtrTy); for (Type *T : CS.getFunctionType()->params()) NewArgs.push_back(T); - PointerType *NewFT = PointerType::getUnqual( + FunctionType *NewFT = FunctionType::get(CS.getFunctionType()->getReturnType(), NewArgs, - CS.getFunctionType()->isVarArg())); + CS.getFunctionType()->isVarArg()); + PointerType *NewFTPtr = PointerType::getUnqual(NewFT); IRBuilder<> IRB(CS.getInstruction()); std::vector Args; @@ -932,10 +933,10 @@ CallSite NewCS; if (CS.isCall()) - NewCS = IRB.CreateCall(IRB.CreateBitCast(JT, NewFT), Args); + NewCS = IRB.CreateCall(NewFT, IRB.CreateBitCast(JT, NewFTPtr), Args); else NewCS = IRB.CreateInvoke( - IRB.CreateBitCast(JT, NewFT), + IRB.CreateBitCast(JT, NewFTPtr), cast(CS.getInstruction())->getNormalDest(), cast(CS.getInstruction())->getUnwindDest(), Args); NewCS.setCallingConv(CS.getCallingConv()); Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -891,7 +891,7 @@ if (II.getIntrinsicID() == Intrinsic::x86_sse4a_extrq) { Value *Args[] = {Op0, CILength, CIIndex}; Module *M = II.getModule(); - Value *F = Intrinsic::getDeclaration(M, Intrinsic::x86_sse4a_extrqi); + Function *F = Intrinsic::getDeclaration(M, Intrinsic::x86_sse4a_extrqi); return Builder.CreateCall(F, Args); } } @@ -992,7 +992,7 @@ Value *Args[] = {Op0, Op1, CILength, CIIndex}; Module *M = II.getModule(); - Value *F = Intrinsic::getDeclaration(M, Intrinsic::x86_sse4a_insertqi); + Function *F = Intrinsic::getDeclaration(M, Intrinsic::x86_sse4a_insertqi); return Builder.CreateCall(F, Args); } @@ -3653,7 +3653,7 @@ // register (which contains the bitmask of live threads). So a // comparison that always returns true is the same as a read of the // EXEC register. - Value *NewF = Intrinsic::getDeclaration( + Function *NewF = Intrinsic::getDeclaration( II->getModule(), Intrinsic::read_register, II->getType()); Metadata *MDArgs[] = {MDString::get(II->getContext(), "exec")}; MDNode *MD = MDNode::get(II->getContext(), MDArgs); @@ -3748,8 +3748,8 @@ } else if (!Ty->isFloatTy() && !Ty->isDoubleTy() && !Ty->isHalfTy()) break; - Value *NewF = Intrinsic::getDeclaration(II->getModule(), NewIID, - SrcLHS->getType()); + Function *NewF = + Intrinsic::getDeclaration(II->getModule(), NewIID, SrcLHS->getType()); Value *Args[] = { SrcLHS, SrcRHS, ConstantInt::get(CC->getType(), SrcPred) }; CallInst *NewCall = Builder.CreateCall(NewF, Args); @@ -3864,16 +3864,20 @@ // Canonicalize assume(a && b) -> assume(a); assume(b); // Note: New assumption intrinsics created here are registered by // the InstCombineIRInserter object. - Value *AssumeIntrinsic = II->getCalledValue(), *A, *B; + FunctionType *AssumeIntrinsicTy = II->getFunctionType(); + Value *AssumeIntrinsic = II->getCalledValue(); + Value *A, *B; if (match(IIOperand, m_And(m_Value(A), m_Value(B)))) { - Builder.CreateCall(AssumeIntrinsic, A, II->getName()); - Builder.CreateCall(AssumeIntrinsic, B, II->getName()); + Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic, A, II->getName()); + Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic, B, II->getName()); return eraseInstFromFunction(*II); } // assume(!(a || b)) -> assume(!a); assume(!b); if (match(IIOperand, m_Not(m_Or(m_Value(A), m_Value(B))))) { - Builder.CreateCall(AssumeIntrinsic, Builder.CreateNot(A), II->getName()); - Builder.CreateCall(AssumeIntrinsic, Builder.CreateNot(B), II->getName()); + Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic, + Builder.CreateNot(A), II->getName()); + Builder.CreateCall(AssumeIntrinsicTy, AssumeIntrinsic, + Builder.CreateNot(B), II->getName()); return eraseInstFromFunction(*II); } @@ -4653,13 +4657,12 @@ Instruction *NewCaller; if (InvokeInst *II = dyn_cast(Caller)) { - NewCaller = InvokeInst::Create(NewCallee, - II->getNormalDest(), II->getUnwindDest(), - NewArgs, OpBundles); + NewCaller = InvokeInst::Create(NewFTy, NewCallee, II->getNormalDest(), + II->getUnwindDest(), NewArgs, OpBundles); cast(NewCaller)->setCallingConv(II->getCallingConv()); cast(NewCaller)->setAttributes(NewPAL); } else { - NewCaller = CallInst::Create(NewCallee, NewArgs, OpBundles); + NewCaller = CallInst::Create(NewFTy, NewCallee, NewArgs, OpBundles); cast(NewCaller)->setTailCallKind( cast(Caller)->getTailCallKind()); cast(NewCaller)->setCallingConv( Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1656,8 +1656,9 @@ II->getIntrinsicID(), Ty); SmallVector OpBundles; II->getOperandBundlesAsDefs(OpBundles); - CallInst *NewCI = CallInst::Create(Overload, { InnerTrunc }, OpBundles, - II->getName()); + CallInst *NewCI = + CallInst::Create(Overload->getFunctionType(), Overload, {InnerTrunc}, + OpBundles, II->getName()); NewCI->copyFastMathFlags(II); return NewCI; } Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1291,8 +1291,8 @@ // use the sadd_with_overflow intrinsic to efficiently compute both the // result and the overflow bit. Type *NewType = IntegerType::get(OrigAdd->getContext(), NewWidth); - Value *F = Intrinsic::getDeclaration(I.getModule(), - Intrinsic::sadd_with_overflow, NewType); + Function *F = Intrinsic::getDeclaration( + I.getModule(), Intrinsic::sadd_with_overflow, NewType); InstCombiner::BuilderTy &Builder = IC.Builder; @@ -4139,8 +4139,8 @@ MulA = Builder.CreateZExt(A, MulType); if (WidthB < MulWidth) MulB = Builder.CreateZExt(B, MulType); - Value *F = Intrinsic::getDeclaration(I.getModule(), - Intrinsic::umul_with_overflow, MulType); + Function *F = Intrinsic::getDeclaration( + I.getModule(), Intrinsic::umul_with_overflow, MulType); CallInst *Call = Builder.CreateCall(F, {MulA, MulB}, "umul"); IC.Worklist.Add(MulInstr); Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -875,15 +875,12 @@ std::unique_ptr EmptyInlineAsm; FunctionStackPoisoner(Function &F, AddressSanitizer &ASan) - : F(F), - ASan(ASan), - DIB(*F.getParent(), /*AllowUnresolved*/ false), - C(ASan.C), - IntptrTy(ASan.IntptrTy), - IntptrPtrTy(PointerType::get(IntptrTy, 0)), - Mapping(ASan.Mapping), + : F(F), ASan(ASan), DIB(*F.getParent(), /*AllowUnresolved*/ false), + C(ASan.C), IntptrTy(ASan.IntptrTy), + IntptrPtrTy(PointerType::get(IntptrTy, 0)), Mapping(ASan.Mapping), StackAlignment(1 << Mapping.Scale), - EmptyInlineAsm(CallInst::Create(ASan.EmptyAsm)) {} + EmptyInlineAsm(CallInst::Create(ASan.EmptyAsm->getFunctionType(), + ASan.EmptyAsm)) {} bool runOnFunction() { if (!ClStack) return false; @@ -1485,7 +1482,7 @@ // We don't do Call->setDoesNotReturn() because the BB already has // UnreachableInst at the end. // This EmptyAsm is required to avoid callback merge. - IRB.CreateCall(EmptyAsm, {}); + IRB.CreateCall(EmptyAsm->getFunctionType(), EmptyAsm, {}); return Call; } @@ -1624,7 +1621,8 @@ // Add calls to unpoison all globals before each return instruction. for (auto &BB : GlobalInit.getBasicBlockList()) if (ReturnInst *RI = dyn_cast(BB.getTerminator())) - CallInst::Create(AsanUnpoisonGlobals, "", RI); + CallInst::Create(AsanUnpoisonGlobals->getFunctionType(), + AsanUnpoisonGlobals, "", RI); } void AddressSanitizerModule::createInitializerPoisonCalls( @@ -2450,8 +2448,8 @@ FunctionType::get(IntptrTy, {AsanShadowGlobal->getType()}, false), StringRef(""), StringRef("=r,0"), /*hasSideEffects=*/false); - LocalDynamicShadow = - IRB.CreateCall(Asm, {AsanShadowGlobal}, ".asan.shadow"); + LocalDynamicShadow = IRB.CreateCall(Asm->getFunctionType(), Asm, + {AsanShadowGlobal}, ".asan.shadow"); } else { LocalDynamicShadow = IRB.CreatePointerCast(AsanShadowGlobal, IntptrTy, ".asan.shadow"); Index: llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -332,6 +332,8 @@ Constant *RetvalTLS; void *(*GetArgTLSPtr)(); void *(*GetRetvalTLSPtr)(); + FunctionType *GetArgTLSTy; + FunctionType *GetRetvalTLSTy; Constant *GetArgTLS; Constant *GetRetvalTLS; Constant *ExternalShadowMask; @@ -580,17 +582,17 @@ if (GetArgTLSPtr) { Type *ArgTLSTy = ArrayType::get(ShadowTy, 64); ArgTLS = nullptr; + GetArgTLSTy = FunctionType::get(PointerType::getUnqual(ArgTLSTy), false); GetArgTLS = ConstantExpr::getIntToPtr( ConstantInt::get(IntptrTy, uintptr_t(GetArgTLSPtr)), - PointerType::getUnqual( - FunctionType::get(PointerType::getUnqual(ArgTLSTy), false))); + PointerType::getUnqual(GetArgTLSTy)); } if (GetRetvalTLSPtr) { RetvalTLS = nullptr; + GetRetvalTLSTy = FunctionType::get(PointerType::getUnqual(ShadowTy), false); GetRetvalTLS = ConstantExpr::getIntToPtr( ConstantInt::get(IntptrTy, uintptr_t(GetRetvalTLSPtr)), - PointerType::getUnqual( - FunctionType::get(PointerType::getUnqual(ShadowTy), false))); + PointerType::getUnqual(GetRetvalTLSTy)); } ColdCallWeights = MDBuilder(*Ctx).createBranchWeights(1, 1000); @@ -655,7 +657,7 @@ if (F->isVarArg()) { NewF->removeAttributes(AttributeList::FunctionIndex, AttrBuilder().addAttribute("split-stack")); - CallInst::Create(DFSanVarargWrapperFn, + CallInst::Create(DFSanVarargWrapperFnTy, DFSanVarargWrapperFn, IRBuilder<>(BB).CreateGlobalStringPtr(F->getName()), "", BB); new UnreachableInst(*Ctx, BB); @@ -686,7 +688,7 @@ Function::arg_iterator AI = F->arg_begin(); ++AI; for (unsigned N = FT->getNumParams(); N != 0; ++AI, --N) Args.push_back(&*AI); - CallInst *CI = CallInst::Create(&*F->arg_begin(), Args, "", BB); + CallInst *CI = CallInst::Create(FT, &*F->arg_begin(), Args, "", BB); ReturnInst *RI; if (FT->getReturnType()->isVoidTy()) RI = ReturnInst::Create(*Ctx, BB); @@ -966,7 +968,8 @@ BranchInst *BI = cast(SplitBlockAndInsertIfThen( Ne, Pos, /*Unreachable=*/false, ColdCallWeights)); IRBuilder<> ThenIRB(BI); - ThenIRB.CreateCall(DFSF.DFS.DFSanNonzeroLabelFn, {}); + ThenIRB.CreateCall(DFSF.DFS.DFSanNonzeroLabelFnTy, + DFSF.DFS.DFSanNonzeroLabelFn, {}); } } } @@ -981,7 +984,7 @@ return ArgTLSPtr = DFS.ArgTLS; IRBuilder<> IRB(&F->getEntryBlock().front()); - return ArgTLSPtr = IRB.CreateCall(DFS.GetArgTLS, {}); + return ArgTLSPtr = IRB.CreateCall(DFS.GetArgTLSTy, DFS.GetArgTLS, {}); } Value *DFSanFunction::getRetvalTLS() { @@ -991,7 +994,8 @@ return RetvalTLSPtr = DFS.RetvalTLS; IRBuilder<> IRB(&F->getEntryBlock().front()); - return RetvalTLSPtr = IRB.CreateCall(DFS.GetRetvalTLS, {}); + return RetvalTLSPtr = + IRB.CreateCall(DFS.GetRetvalTLSTy, DFS.GetRetvalTLS, {}); } Value *DFSanFunction::getArgTLS(unsigned Idx, Instruction *Pos) { @@ -1094,7 +1098,8 @@ IRBuilder<> IRB(Pos); if (AvoidNewBlocks) { - CallInst *Call = IRB.CreateCall(DFS.DFSanCheckedUnionFn, {V1, V2}); + CallInst *Call = + IRB.CreateCall(DFS.DFSanUnionFnTy, DFS.DFSanCheckedUnionFn, {V1, V2}); Call->addAttribute(AttributeList::ReturnIndex, Attribute::ZExt); Call->addParamAttr(0, Attribute::ZExt); Call->addParamAttr(1, Attribute::ZExt); @@ -1107,7 +1112,8 @@ BranchInst *BI = cast(SplitBlockAndInsertIfThen( Ne, Pos, /*Unreachable=*/false, DFS.ColdCallWeights, &DT)); IRBuilder<> ThenIRB(BI); - CallInst *Call = ThenIRB.CreateCall(DFS.DFSanUnionFn, {V1, V2}); + CallInst *Call = + ThenIRB.CreateCall(DFS.DFSanUnionFnTy, DFS.DFSanUnionFn, {V1, V2}); Call->addAttribute(AttributeList::ReturnIndex, Attribute::ZExt); Call->addParamAttr(0, Attribute::ZExt); Call->addParamAttr(1, Attribute::ZExt); @@ -1208,7 +1214,7 @@ BasicBlock *FallbackBB = BasicBlock::Create(*DFS.Ctx, "", F); IRBuilder<> FallbackIRB(FallbackBB); CallInst *FallbackCall = FallbackIRB.CreateCall( - DFS.DFSanUnionLoadFn, + DFS.DFSanUnionLoadFnTy, DFS.DFSanUnionLoadFn, {ShadowAddr, ConstantInt::get(DFS.IntptrTy, Size)}); FallbackCall->addAttribute(AttributeList::ReturnIndex, Attribute::ZExt); @@ -1265,8 +1271,9 @@ } IRBuilder<> IRB(Pos); - CallInst *FallbackCall = IRB.CreateCall( - DFS.DFSanUnionLoadFn, {ShadowAddr, ConstantInt::get(DFS.IntptrTy, Size)}); + CallInst *FallbackCall = + IRB.CreateCall(DFS.DFSanUnionLoadFnTy, DFS.DFSanUnionLoadFn, + {ShadowAddr, ConstantInt::get(DFS.IntptrTy, Size)}); FallbackCall->addAttribute(AttributeList::ReturnIndex, Attribute::ZExt); return FallbackCall; } @@ -1452,10 +1459,11 @@ void DFSanVisitor::visitMemSetInst(MemSetInst &I) { IRBuilder<> IRB(&I); Value *ValShadow = DFSF.getShadow(I.getValue()); - IRB.CreateCall(DFSF.DFS.DFSanSetLabelFn, - {ValShadow, IRB.CreateBitCast(I.getDest(), Type::getInt8PtrTy( - *DFSF.DFS.Ctx)), - IRB.CreateZExtOrTrunc(I.getLength(), DFSF.DFS.IntptrTy)}); + IRB.CreateCall( + DFSF.DFS.DFSanSetLabelFnTy, DFSF.DFS.DFSanSetLabelFn, + {ValShadow, + IRB.CreateBitCast(I.getDest(), Type::getInt8PtrTy(*DFSF.DFS.Ctx)), + IRB.CreateZExtOrTrunc(I.getLength(), DFSF.DFS.IntptrTy)}); } void DFSanVisitor::visitMemTransferInst(MemTransferInst &I) { @@ -1469,7 +1477,7 @@ DestShadow = IRB.CreateBitCast(DestShadow, Int8Ptr); SrcShadow = IRB.CreateBitCast(SrcShadow, Int8Ptr); auto *MTI = cast( - IRB.CreateCall(I.getCalledValue(), + IRB.CreateCall(I.getFunctionType(), I.getCalledValue(), {DestShadow, SrcShadow, LenShadow, I.getVolatileCst()})); if (ClPreserveAlignment) { MTI->setDestAlignment(I.getDestAlignment() * (DFSF.DFS.ShadowWidth / 8)); @@ -1524,7 +1532,8 @@ switch (DFSF.DFS.getWrapperKind(F)) { case DataFlowSanitizer::WK_Warning: CS.setCalledFunction(F); - IRB.CreateCall(DFSF.DFS.DFSanUnimplementedFn, + IRB.CreateCall(DFSF.DFS.DFSanUnimplementedFnTy, + DFSF.DFS.DFSanUnimplementedFn, IRB.CreateGlobalStringPtr(F->getName())); DFSF.setShadow(CS.getInstruction(), DFSF.DFS.ZeroShadow); return; @@ -1612,7 +1621,8 @@ for (i = CS.arg_begin() + FT->getNumParams(); i != CS.arg_end(); ++i) Args.push_back(*i); - CallInst *CustomCI = IRB.CreateCall(CustomF, Args); + CallInst *CustomCI = + IRB.CreateCall(CustomFn.TransformedType, CustomF, Args); CustomCI->setCallingConv(CI->getCallingConv()); CustomCI->setAttributes(TransformFunctionAttributes(CustomFn, CI->getContext(), CI->getAttributes())); @@ -1708,7 +1718,7 @@ NewCS = IRB.CreateInvoke(Func, II->getNormalDest(), II->getUnwindDest(), Args); } else { - NewCS = IRB.CreateCall(Func, Args); + NewCS = IRB.CreateCall(NewFT, Func, Args); } NewCS.setCallingConv(CS.getCallingConv()); NewCS.setAttributes(CS.getAttributes().removeAttributes( Index: llvm/lib/Transforms/Instrumentation/EfficiencySanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/EfficiencySanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/EfficiencySanitizer.cpp @@ -669,7 +669,7 @@ Type *OrigTy = cast(Addr->getType())->getElementType(); const uint32_t TypeSizeBytes = DL.getTypeStoreSizeInBits(OrigTy) / 8; - Value *OnAccessFunc = nullptr; + Function *OnAccessFunc = nullptr; // Convert 0 to the default alignment. if (Alignment == 0) Index: llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -102,11 +102,11 @@ std::vector &Regexes); // Get pointers to the functions in the runtime library. - Constant *getStartFileFunc(); - Constant *getEmitFunctionFunc(); - Constant *getEmitArcsFunc(); - Constant *getSummaryInfoFunc(); - Constant *getEndFileFunc(); + Constant *getStartFileFunc(FunctionType *&FTy); + Constant *getEmitFunctionFunc(FunctionType *&FTy); + Constant *getEmitArcsFunc(FunctionType *&FTy); + Constant *getSummaryInfoFunc(FunctionType *&FTy); + Constant *getEndFileFunc(FunctionType *&FTy); // Add the function to write out all our counters to the global destructor // list. @@ -648,7 +648,7 @@ IRBuilder<> Builder(I); FunctionType *FTy = FunctionType::get(Builder.getVoidTy(), {}, false); Constant *GCOVFlush = M->getOrInsertFunction("__gcov_flush", FTy); - Builder.CreateCall(GCOVFlush); + Builder.CreateCall(FTy, GCOVFlush); I->getParent()->splitBasicBlock(I); } } @@ -864,7 +864,7 @@ // Initialize the environment and register the local writeout and flush // functions. Constant *GCOVInit = M->getOrInsertFunction("llvm_gcov_init", FTy); - Builder.CreateCall(GCOVInit, {WriteoutF, FlushF}); + Builder.CreateCall(FTy, GCOVInit, {WriteoutF, FlushF}); Builder.CreateRetVoid(); appendToGlobalCtors(*M, F, 0); @@ -873,22 +873,21 @@ return Result; } -Constant *GCOVProfiler::getStartFileFunc() { +Constant *GCOVProfiler::getStartFileFunc(FunctionType *&FTy) { Type *Args[] = { Type::getInt8PtrTy(*Ctx), // const char *orig_filename Type::getInt8PtrTy(*Ctx), // const char version[4] Type::getInt32Ty(*Ctx), // uint32_t checksum }; - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); + FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); auto *Res = M->getOrInsertFunction("llvm_gcda_start_file", FTy); if (Function *FunRes = dyn_cast(Res)) if (auto AK = TLI->getExtAttrForI32Param(false)) FunRes->addParamAttr(2, AK); return Res; - } -Constant *GCOVProfiler::getEmitFunctionFunc() { +Constant *GCOVProfiler::getEmitFunctionFunc(FunctionType *&FTy) { Type *Args[] = { Type::getInt32Ty(*Ctx), // uint32_t ident Type::getInt8PtrTy(*Ctx), // const char *function_name @@ -896,7 +895,7 @@ Type::getInt8Ty(*Ctx), // uint8_t use_extra_checksum Type::getInt32Ty(*Ctx), // uint32_t cfg_checksum }; - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); + FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); auto *Res = M->getOrInsertFunction("llvm_gcda_emit_function", FTy); if (Function *FunRes = dyn_cast(Res)) if (auto AK = TLI->getExtAttrForI32Param(false)) { @@ -908,12 +907,12 @@ return Res; } -Constant *GCOVProfiler::getEmitArcsFunc() { +Constant *GCOVProfiler::getEmitArcsFunc(FunctionType *&FTy) { Type *Args[] = { Type::getInt32Ty(*Ctx), // uint32_t num_counters Type::getInt64PtrTy(*Ctx), // uint64_t *counters }; - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); + FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); auto *Res = M->getOrInsertFunction("llvm_gcda_emit_arcs", FTy); if (Function *FunRes = dyn_cast(Res)) if (auto AK = TLI->getExtAttrForI32Param(false)) @@ -921,13 +920,13 @@ return Res; } -Constant *GCOVProfiler::getSummaryInfoFunc() { - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); +Constant *GCOVProfiler::getSummaryInfoFunc(FunctionType *&FTy) { + FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); return M->getOrInsertFunction("llvm_gcda_summary_info", FTy); } -Constant *GCOVProfiler::getEndFileFunc() { - FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); +Constant *GCOVProfiler::getEndFileFunc(FunctionType *&FTy) { + FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); return M->getOrInsertFunction("llvm_gcda_end_file", FTy); } @@ -946,11 +945,13 @@ BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", WriteoutF); IRBuilder<> Builder(BB); - Constant *StartFile = getStartFileFunc(); - Constant *EmitFunction = getEmitFunctionFunc(); - Constant *EmitArcs = getEmitArcsFunc(); - Constant *SummaryInfo = getSummaryInfoFunc(); - Constant *EndFile = getEndFileFunc(); + FunctionType *StartFileFTy, *EmitFunctionFTy, *EmitArcsFTy, *SummaryInfoFTy, + *EndFileFTy; + Constant *StartFile = getStartFileFunc(StartFileFTy); + Constant *EmitFunction = getEmitFunctionFunc(EmitFunctionFTy); + Constant *EmitArcs = getEmitArcsFunc(EmitArcsFTy); + Constant *SummaryInfo = getSummaryInfoFunc(SummaryInfoFTy); + Constant *EndFile = getEndFileFunc(EndFileFTy); NamedMDNode *CUNodes = M->getNamedMetadata("llvm.dbg.cu"); if (!CUNodes) { @@ -1091,7 +1092,7 @@ Builder.CreateInBoundsGEP(FileInfoArrayGV, {Builder.getInt32(0), IV}); auto *StartFileCallArgsPtr = Builder.CreateStructGEP(FileInfoPtr, 0); auto *StartFileCall = Builder.CreateCall( - StartFile, + StartFileFTy, StartFile, {Builder.CreateLoad(Builder.CreateStructGEP(StartFileCallArgsPtr, 0)), Builder.CreateLoad(Builder.CreateStructGEP(StartFileCallArgsPtr, 1)), Builder.CreateLoad(Builder.CreateStructGEP(StartFileCallArgsPtr, 2))}); @@ -1113,7 +1114,7 @@ auto *EmitFunctionCallArgsPtr = Builder.CreateInBoundsGEP(EmitFunctionCallArgsArray, {JV}); auto *EmitFunctionCall = Builder.CreateCall( - EmitFunction, + EmitFunctionFTy, EmitFunction, {Builder.CreateLoad(Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 0)), Builder.CreateLoad(Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 1)), Builder.CreateLoad(Builder.CreateStructGEP(EmitFunctionCallArgsPtr, 2)), @@ -1129,7 +1130,7 @@ auto *EmitArcsCallArgsPtr = Builder.CreateInBoundsGEP(EmitArcsCallArgsArray, {JV}); auto *EmitArcsCall = Builder.CreateCall( - EmitArcs, + EmitArcsFTy, EmitArcs, {Builder.CreateLoad(Builder.CreateStructGEP(EmitArcsCallArgsPtr, 0)), Builder.CreateLoad(Builder.CreateStructGEP(EmitArcsCallArgsPtr, 1))}); if (auto AK = TLI->getExtAttrForI32Param(false)) @@ -1140,8 +1141,8 @@ JV->addIncoming(NextJV, CounterLoopHeader); Builder.SetInsertPoint(FileLoopLatch); - Builder.CreateCall(SummaryInfo, {}); - Builder.CreateCall(EndFile, {}); + Builder.CreateCall(SummaryInfoFTy, SummaryInfo, {}); + Builder.CreateCall(EndFileFTy, EndFile, {}); auto *NextIV = Builder.CreateAdd(IV, Builder.getInt32(1)); auto *FileLoopCond = Builder.CreateICmpSLT(NextIV, Builder.getInt32(FileInfos.size())); @@ -1171,7 +1172,7 @@ BasicBlock *Entry = BasicBlock::Create(*Ctx, "entry", FlushF); // Write out the current counters. - Constant *WriteoutF = M->getFunction("__llvm_gcov_writeout"); + Function *WriteoutF = M->getFunction("__llvm_gcov_writeout"); assert(WriteoutF && "Need to create the writeout function first!"); IRBuilder<> Builder(Entry); Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -415,7 +415,7 @@ FunctionType::get(Int8PtrTy, {ShadowGlobal->getType()}, false), StringRef(""), StringRef("=r,0"), /*hasSideEffects=*/false); - return IRB.CreateCall(Asm, {ShadowGlobal}, ".hwasan.shadow"); + return IRB.CreateCall(Asm->getFunctionType(), Asm, {ShadowGlobal}, ".hwasan.shadow"); } Value *HWAddressSanitizer::getDynamicShadowNonTls(IRBuilder<> &IRB) { @@ -596,7 +596,7 @@ default: report_fatal_error("unsupported architecture"); } - IRB.CreateCall(Asm, PtrLong); + IRB.CreateCall(Asm->getFunctionType(), Asm, PtrLong); } void HWAddressSanitizer::instrumentMemIntrinsic(MemIntrinsic *MI) { Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -508,22 +508,16 @@ return true; } -static Constant *getOrInsertValueProfilingCall(Module &M, - const TargetLibraryInfo &TLI, - bool IsRange = false) { +static FunctionType *getValueProfilingFType(Module &M, bool IsRange) { LLVMContext &Ctx = M.getContext(); auto *ReturnTy = Type::getVoidTy(M.getContext()); - Constant *Res; if (!IsRange) { Type *ParamTypes[] = { #define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType) ParamLLVMType #include "llvm/ProfileData/InstrProfData.inc" }; - auto *ValueProfilingCallTy = - FunctionType::get(ReturnTy, makeArrayRef(ParamTypes), false); - Res = M.getOrInsertFunction(getInstrProfValueProfFuncName(), - ValueProfilingCallTy); + return FunctionType::get(ReturnTy, makeArrayRef(ParamTypes), false); } else { Type *RangeParamTypes[] = { #define VALUE_RANGE_PROF 1 @@ -531,17 +525,8 @@ #include "llvm/ProfileData/InstrProfData.inc" #undef VALUE_RANGE_PROF }; - auto *ValueRangeProfilingCallTy = - FunctionType::get(ReturnTy, makeArrayRef(RangeParamTypes), false); - Res = M.getOrInsertFunction(getInstrProfValueRangeProfFuncName(), - ValueRangeProfilingCallTy); + return FunctionType::get(ReturnTy, makeArrayRef(RangeParamTypes), false); } - - if (Function *FunRes = dyn_cast(Res)) { - if (auto AK = TLI.getExtAttrForI32Param(false)) - FunRes->addParamAttr(2, AK); - } - return Res; } void InstrProfiling::computeNumValueSiteCounts(InstrProfValueProfileInst *Ind) { @@ -572,12 +557,23 @@ IRBuilder<> Builder(Ind); bool IsRange = (Ind->getValueKind()->getZExtValue() == llvm::InstrProfValueKind::IPVK_MemOPSize); + + FunctionType *FTy = getValueProfilingFType(*M, IsRange); + Value *F = + M->getOrInsertFunction(IsRange ? getInstrProfValueRangeProfFuncName() + : getInstrProfValueProfFuncName(), + FTy); + if (Function *FunRes = dyn_cast(F)) { + if (auto AK = TLI->getExtAttrForI32Param(false)) + FunRes->addParamAttr(2, AK); + } + CallInst *Call = nullptr; if (!IsRange) { Value *Args[3] = {Ind->getTargetValue(), Builder.CreateBitCast(DataVar, Builder.getInt8PtrTy()), Builder.getInt32(Index)}; - Call = Builder.CreateCall(getOrInsertValueProfilingCall(*M, *TLI), Args); + Call = Builder.CreateCall(FTy, F, Args); } else { Value *Args[6] = { Ind->getTargetValue(), @@ -586,8 +582,7 @@ Builder.getInt64(MemOPSizeRangeStart), Builder.getInt64(MemOPSizeRangeLast), Builder.getInt64(MemOPSizeLarge == 0 ? INT64_MIN : MemOPSizeLarge)}; - Call = - Builder.CreateCall(getOrInsertValueProfilingCall(*M, *TLI, true), Args); + Call = Builder.CreateCall(FTy, F, Args); } if (auto AK = TLI->getExtAttrForI32Param(false)) Call->addParamAttr(2, AK); @@ -983,7 +978,7 @@ } } - Constant *RegisterF = M->getFunction(getInstrProfRegFuncsName()); + Function *RegisterF = M->getFunction(getInstrProfRegFuncsName()); if (!RegisterF) return; @@ -999,8 +994,7 @@ // Add the basic block and the necessary calls. IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", F)); - if (RegisterF) - IRB.CreateCall(RegisterF, {}); + IRB.CreateCall(RegisterF, {}); IRB.CreateRetVoid(); appendToGlobalCtors(*M, F, 0); Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -539,34 +539,46 @@ Value *WarningFn; // These arrays are indexed by log2(AccessSize). + FunctionType *MaybeWarningFnTy[kNumberOfAccessSizes]; Value *MaybeWarningFn[kNumberOfAccessSizes]; + FunctionType *MaybeStoreOriginFnTy[kNumberOfAccessSizes]; Value *MaybeStoreOriginFn[kNumberOfAccessSizes]; /// Run-time helper that generates a new origin value for a stack /// allocation. + FunctionType *MsanSetAllocaOrigin4FnTy; Value *MsanSetAllocaOrigin4Fn; /// Run-time helper that poisons stack on function entry. + FunctionType *MsanPoisonStackFnTy; Value *MsanPoisonStackFn; /// Run-time helper that records a store (or any event) of an /// uninitialized value and returns an updated origin id encoding this info. + FunctionType *MsanChainOriginFnTy; Value *MsanChainOriginFn; /// MSan runtime replacements for memmove, memcpy and memset. + FunctionType *MemmoveFnTy, *MemcpyFnTy, *MemsetFnTy; Value *MemmoveFn, *MemcpyFn, *MemsetFn; /// KMSAN callback for task-local function argument shadow. + FunctionType *MsanGetContextStateFnTy; Value *MsanGetContextStateFn; /// Functions for poisoning/unpoisoning local variables + FunctionType *MsanPoisonAllocaFnTy, *MsanUnpoisonAllocaFnTy; Value *MsanPoisonAllocaFn, *MsanUnpoisonAllocaFn; /// Each of the MsanMetadataPtrXxx functions returns a pair of shadow/origin /// pointers. + FunctionType *MsanMetadataPtrGetterFnTy; Value *MsanMetadataPtrForLoadN, *MsanMetadataPtrForStoreN; + FunctionType *MsanMetadataPtrGetterFixedSizeFnTy; Value *MsanMetadataPtrForLoad_1_8[4]; Value *MsanMetadataPtrForStore_1_8[4]; + + FunctionType *MsanInstrumentAsmStoreFnTy; Value *MsanInstrumentAsmStoreFn; /// Helper to choose between different MsanMetadataPtrXxx(). @@ -677,8 +689,7 @@ IRB.getInt32Ty()); // Requests the per-task context state (kmsan_context_state*) from the // runtime library. - MsanGetContextStateFn = M.getOrInsertFunction( - "__msan_get_context_state", + MsanGetContextStateFnTy = FunctionType::get( PointerType::get( StructType::get(ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8), ArrayType::get(IRB.getInt64Ty(), kRetvalTLSSize / 8), @@ -688,35 +699,45 @@ IRB.getInt64Ty(), ArrayType::get(OriginTy, kParamTLSSize / 4), OriginTy, OriginTy), - 0)); + 0), + {}, false); + MsanGetContextStateFn = M.getOrInsertFunction("__msan_get_context_state", + MsanGetContextStateFnTy); Type *RetTy = StructType::get(PointerType::get(IRB.getInt8Ty(), 0), PointerType::get(IRB.getInt32Ty(), 0)); + MsanMetadataPtrGetterFixedSizeFnTy = + FunctionType::get(RetTy, {PointerType::get(IRB.getInt8Ty(), 0)}, false); + for (int ind = 0, size = 1; ind < 4; ind++, size <<= 1) { std::string name_load = "__msan_metadata_ptr_for_load_" + std::to_string(size); std::string name_store = "__msan_metadata_ptr_for_store_" + std::to_string(size); - MsanMetadataPtrForLoad_1_8[ind] = M.getOrInsertFunction( - name_load, RetTy, PointerType::get(IRB.getInt8Ty(), 0)); - MsanMetadataPtrForStore_1_8[ind] = M.getOrInsertFunction( - name_store, RetTy, PointerType::get(IRB.getInt8Ty(), 0)); + MsanMetadataPtrForLoad_1_8[ind] = + M.getOrInsertFunction(name_load, MsanMetadataPtrGetterFixedSizeFnTy); + MsanMetadataPtrForStore_1_8[ind] = + M.getOrInsertFunction(name_store, MsanMetadataPtrGetterFixedSizeFnTy); } + MsanMetadataPtrGetterFnTy = FunctionType::get( + RetTy, {PointerType::get(IRB.getInt8Ty(), 0), IRB.getInt64Ty()}, false); MsanMetadataPtrForLoadN = M.getOrInsertFunction( - "__msan_metadata_ptr_for_load_n", RetTy, - PointerType::get(IRB.getInt8Ty(), 0), IRB.getInt64Ty()); + "__msan_metadata_ptr_for_load_n", MsanMetadataPtrGetterFnTy); MsanMetadataPtrForStoreN = M.getOrInsertFunction( - "__msan_metadata_ptr_for_store_n", RetTy, - PointerType::get(IRB.getInt8Ty(), 0), IRB.getInt64Ty()); + "__msan_metadata_ptr_for_store_n", MsanMetadataPtrGetterFnTy); // Functions for poisoning and unpoisoning memory. + MsanPoisonAllocaFnTy = FunctionType::get( + IRB.getVoidTy(), {IRB.getInt8PtrTy(), IntptrTy, IRB.getInt8PtrTy()}, + false); MsanPoisonAllocaFn = - M.getOrInsertFunction("__msan_poison_alloca", IRB.getVoidTy(), - IRB.getInt8PtrTy(), IntptrTy, IRB.getInt8PtrTy()); - MsanUnpoisonAllocaFn = M.getOrInsertFunction( - "__msan_unpoison_alloca", IRB.getVoidTy(), IRB.getInt8PtrTy(), IntptrTy); + M.getOrInsertFunction("__msan_poison_alloca", MsanPoisonAllocaFnTy); + MsanUnpoisonAllocaFnTy = + FunctionType::get(IRB.getVoidTy(), {IRB.getInt8PtrTy(), IntptrTy}, false); + MsanUnpoisonAllocaFn = + M.getOrInsertFunction("__msan_unpoison_alloca", MsanUnpoisonAllocaFnTy); } static Constant *getOrInsertGlobal(Module &M, StringRef Name, Type *Ty) { @@ -768,22 +789,30 @@ AccessSizeIndex++) { unsigned AccessSize = 1 << AccessSizeIndex; std::string FunctionName = "__msan_maybe_warning_" + itostr(AccessSize); - MaybeWarningFn[AccessSizeIndex] = M.getOrInsertFunction( - FunctionName, IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8), - IRB.getInt32Ty()); + MaybeWarningFnTy[AccessSizeIndex] = FunctionType::get( + IRB.getVoidTy(), {IRB.getIntNTy(AccessSize * 8), IRB.getInt32Ty()}, + false); + MaybeWarningFn[AccessSizeIndex] = + M.getOrInsertFunction(FunctionName, MaybeWarningFnTy[AccessSizeIndex]); FunctionName = "__msan_maybe_store_origin_" + itostr(AccessSize); + MaybeStoreOriginFnTy[AccessSizeIndex] = FunctionType::get( + IRB.getVoidTy(), + {IRB.getIntNTy(AccessSize * 8), IRB.getInt8PtrTy(), IRB.getInt32Ty()}, + false); MaybeStoreOriginFn[AccessSizeIndex] = M.getOrInsertFunction( - FunctionName, IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8), - IRB.getInt8PtrTy(), IRB.getInt32Ty()); + FunctionName, MaybeStoreOriginFnTy[AccessSizeIndex]); } - MsanSetAllocaOrigin4Fn = M.getOrInsertFunction( - "__msan_set_alloca_origin4", IRB.getVoidTy(), IRB.getInt8PtrTy(), IntptrTy, - IRB.getInt8PtrTy(), IntptrTy); + MsanSetAllocaOrigin4FnTy = FunctionType::get( + IRB.getVoidTy(), + {IRB.getInt8PtrTy(), IntptrTy, IRB.getInt8PtrTy(), IntptrTy}, false); + MsanSetAllocaOrigin4Fn = M.getOrInsertFunction("__msan_set_alloca_origin4", + MsanSetAllocaOrigin4FnTy); + MsanPoisonStackFnTy = + FunctionType::get(IRB.getVoidTy(), {IRB.getInt8PtrTy(), IntptrTy}, false); MsanPoisonStackFn = - M.getOrInsertFunction("__msan_poison_stack", IRB.getVoidTy(), - IRB.getInt8PtrTy(), IntptrTy); + M.getOrInsertFunction("__msan_poison_stack", MsanPoisonStackFnTy); } /// Insert extern declaration of runtime-provided functions and globals. @@ -795,25 +824,31 @@ IRBuilder<> IRB(*C); // Initialize callbacks that are common for kernel and userspace // instrumentation. - MsanChainOriginFn = M.getOrInsertFunction( - "__msan_chain_origin", IRB.getInt32Ty(), IRB.getInt32Ty()); - MemmoveFn = M.getOrInsertFunction( - "__msan_memmove", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), - IRB.getInt8PtrTy(), IntptrTy); - MemcpyFn = M.getOrInsertFunction( - "__msan_memcpy", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), - IntptrTy); - MemsetFn = M.getOrInsertFunction( - "__msan_memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt32Ty(), - IntptrTy); + MsanChainOriginFnTy = + FunctionType::get(IRB.getInt32Ty(), {IRB.getInt32Ty()}, false); + MsanChainOriginFn = + M.getOrInsertFunction("__msan_chain_origin", MsanChainOriginFnTy); + MemmoveFnTy = FunctionType::get( + IRB.getInt8PtrTy(), {IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy}, + false); + MemmoveFn = M.getOrInsertFunction("__msan_memmove", MemmoveFnTy); + MemcpyFnTy = FunctionType::get( + IRB.getInt8PtrTy(), {IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy}, + false); + MemcpyFn = M.getOrInsertFunction("__msan_memcpy", MemcpyFnTy); + MemsetFnTy = FunctionType::get( + IRB.getInt8PtrTy(), {IRB.getInt8PtrTy(), IRB.getInt32Ty(), IntptrTy}, + false); + MemsetFn = M.getOrInsertFunction("__msan_memset", MemsetFnTy); // We insert an empty inline asm after __msan_report* to avoid callback merge. EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), StringRef(""), StringRef(""), /*hasSideEffects=*/true); - MsanInstrumentAsmStoreFn = - M.getOrInsertFunction("__msan_instrument_asm_store", IRB.getVoidTy(), - PointerType::get(IRB.getInt8Ty(), 0), IntptrTy); + MsanInstrumentAsmStoreFnTy = FunctionType::get( + IRB.getVoidTy(), {PointerType::get(IRB.getInt8Ty(), 0), IntptrTy}, false); + MsanInstrumentAsmStoreFn = M.getOrInsertFunction( + "__msan_instrument_asm_store", MsanInstrumentAsmStoreFnTy); if (CompileKernel) { createKernelApi(M); @@ -1057,7 +1092,7 @@ Value *updateOrigin(Value *V, IRBuilder<> &IRB) { if (MS.TrackOrigins <= 1) return V; - return IRB.CreateCall(MS.MsanChainOriginFn, V); + return IRB.CreateCall(MS.MsanChainOriginFnTy, MS.MsanChainOriginFn, V); } Value *originToIntptr(IRBuilder<> &IRB, Value *Origin) { @@ -1123,12 +1158,14 @@ DL.getTypeSizeInBits(ConvertedShadow->getType()); unsigned SizeIndex = TypeSizeToSizeIndex(TypeSizeInBits); if (AsCall && SizeIndex < kNumberOfAccessSizes && !MS.CompileKernel) { + FunctionType *FnTy = MS.MaybeStoreOriginFnTy[SizeIndex]; Value *Fn = MS.MaybeStoreOriginFn[SizeIndex]; Value *ConvertedShadow2 = IRB.CreateZExt( ConvertedShadow, IRB.getIntNTy(8 * (1 << SizeIndex))); - IRB.CreateCall(Fn, {ConvertedShadow2, - IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy()), - Origin}); + IRB.CreateCall(FnTy, Fn, + {ConvertedShadow2, + IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy()), + Origin}); } else { Value *Cmp = IRB.CreateICmpNE( ConvertedShadow, getCleanShadow(ConvertedShadow), "_mscmp"); @@ -1172,14 +1209,17 @@ if (!Origin) Origin = (Value *)IRB.getInt32(0); if (MS.CompileKernel) { - IRB.CreateCall(MS.WarningFn, Origin); + IRB.CreateCall( + FunctionType::get(IRB.getVoidTy(), {IRB.getInt32Ty()}, false), + MS.WarningFn, Origin); } else { if (MS.TrackOrigins) { IRB.CreateStore(Origin, MS.OriginTLS); } - IRB.CreateCall(MS.WarningFn, {}); + IRB.CreateCall(FunctionType::get(IRB.getVoidTy(), false), MS.WarningFn, + {}); } - IRB.CreateCall(MS.EmptyAsm, {}); + IRB.CreateCall(MS.EmptyAsm->getFunctionType(), MS.EmptyAsm, {}); // FIXME: Insert UnreachableInst if !MS.Recover? // This may invalidate some of the following checks and needs to be done // at the very end. @@ -1205,12 +1245,14 @@ unsigned TypeSizeInBits = DL.getTypeSizeInBits(ConvertedShadow->getType()); unsigned SizeIndex = TypeSizeToSizeIndex(TypeSizeInBits); if (AsCall && SizeIndex < kNumberOfAccessSizes && !MS.CompileKernel) { + FunctionType *FnTy = MS.MaybeWarningFnTy[SizeIndex]; Value *Fn = MS.MaybeWarningFn[SizeIndex]; Value *ConvertedShadow2 = IRB.CreateZExt(ConvertedShadow, IRB.getIntNTy(8 * (1 << SizeIndex))); - IRB.CreateCall(Fn, {ConvertedShadow2, MS.TrackOrigins && Origin - ? Origin - : (Value *)IRB.getInt32(0)}); + IRB.CreateCall(FnTy, Fn, + {ConvertedShadow2, MS.TrackOrigins && Origin + ? Origin + : (Value *)IRB.getInt32(0)}); } else { Value *Cmp = IRB.CreateICmpNE(ConvertedShadow, getCleanShadow(ConvertedShadow), "_mscmp"); @@ -1238,7 +1280,8 @@ BasicBlock *ret = SplitBlock(&F.getEntryBlock(), F.getEntryBlock().getFirstNonPHI()); IRBuilder<> IRB(F.getEntryBlock().getFirstNonPHI()); - Value *ContextState = IRB.CreateCall(MS.MsanGetContextStateFn, {}); + Value *ContextState = IRB.CreateCall(MS.MsanGetContextStateFnTy, + MS.MsanGetContextStateFn, {}); Constant *Zero = IRB.getInt32(0); MS.ParamTLS = IRB.CreateGEP(ContextState, {Zero, IRB.getInt32(0)}, "param_shadow"); @@ -1416,10 +1459,12 @@ Value *AddrCast = IRB.CreatePointerCast(Addr, PointerType::get(IRB.getInt8Ty(), 0)); if (Getter) { - ShadowOriginPtrs = IRB.CreateCall(Getter, AddrCast); + ShadowOriginPtrs = IRB.CreateCall(MS.MsanMetadataPtrGetterFixedSizeFnTy, + Getter, AddrCast); } else { Value *SizeVal = ConstantInt::get(MS.IntptrTy, Size); - ShadowOriginPtrs = IRB.CreateCall(isStore ? MS.MsanMetadataPtrForStoreN + ShadowOriginPtrs = IRB.CreateCall(MS.MsanMetadataPtrGetterFnTy, + isStore ? MS.MsanMetadataPtrForStoreN : MS.MsanMetadataPtrForLoadN, {AddrCast, SizeVal}); } @@ -2371,7 +2416,7 @@ void visitMemMoveInst(MemMoveInst &I) { IRBuilder<> IRB(&I); IRB.CreateCall( - MS.MemmoveFn, + MS.MemmoveFnTy, MS.MemmoveFn, {IRB.CreatePointerCast(I.getArgOperand(0), IRB.getInt8PtrTy()), IRB.CreatePointerCast(I.getArgOperand(1), IRB.getInt8PtrTy()), IRB.CreateIntCast(I.getArgOperand(2), MS.IntptrTy, false)}); @@ -2385,7 +2430,7 @@ void visitMemCpyInst(MemCpyInst &I) { IRBuilder<> IRB(&I); IRB.CreateCall( - MS.MemcpyFn, + MS.MemcpyFnTy, MS.MemcpyFn, {IRB.CreatePointerCast(I.getArgOperand(0), IRB.getInt8PtrTy()), IRB.CreatePointerCast(I.getArgOperand(1), IRB.getInt8PtrTy()), IRB.CreateIntCast(I.getArgOperand(2), MS.IntptrTy, false)}); @@ -2396,7 +2441,7 @@ void visitMemSetInst(MemSetInst &I) { IRBuilder<> IRB(&I); IRB.CreateCall( - MS.MemsetFn, + MS.MemsetFnTy, MS.MemsetFn, {IRB.CreatePointerCast(I.getArgOperand(0), IRB.getInt8PtrTy()), IRB.CreateIntCast(I.getArgOperand(1), IRB.getInt32Ty(), false), IRB.CreateIntCast(I.getArgOperand(2), MS.IntptrTy, false)}); @@ -2669,7 +2714,7 @@ : Lower64ShadowExtend(IRB, S2, getShadowTy(&I)); Value *V1 = I.getOperand(0); Value *V2 = I.getOperand(1); - Value *Shift = IRB.CreateCall(I.getCalledValue(), + Value *Shift = IRB.CreateCall(I.getFunctionType(), I.getCalledValue(), {IRB.CreateBitCast(S1, V1->getType()), V2}); Shift = IRB.CreateBitCast(Shift, getShadowTy(&I)); setShadow(&I, IRB.CreateOr(Shift, S2Conv)); @@ -3351,7 +3396,7 @@ void instrumentAllocaUserspace(AllocaInst &I, IRBuilder<> &IRB, Value *Len) { if (PoisonStack && ClPoisonStackWithCall) { - IRB.CreateCall(MS.MsanPoisonStackFn, + IRB.CreateCall(MS.MsanPoisonStackFnTy, MS.MsanPoisonStackFn, {IRB.CreatePointerCast(&I, IRB.getInt8PtrTy()), Len}); } else { Value *ShadowBase, *OriginBase; @@ -3364,7 +3409,7 @@ if (PoisonStack && MS.TrackOrigins) { Value *Descr = getLocalVarDescription(I); - IRB.CreateCall(MS.MsanSetAllocaOrigin4Fn, + IRB.CreateCall(MS.MsanSetAllocaOrigin4FnTy, MS.MsanSetAllocaOrigin4Fn, {IRB.CreatePointerCast(&I, IRB.getInt8PtrTy()), Len, IRB.CreatePointerCast(Descr, IRB.getInt8PtrTy()), IRB.CreatePointerCast(&F, MS.IntptrTy)}); @@ -3374,11 +3419,11 @@ void instrumentAllocaKmsan(AllocaInst &I, IRBuilder<> &IRB, Value *Len) { Value *Descr = getLocalVarDescription(I); if (PoisonStack) { - IRB.CreateCall(MS.MsanPoisonAllocaFn, + IRB.CreateCall(MS.MsanPoisonAllocaFnTy, MS.MsanPoisonAllocaFn, {IRB.CreatePointerCast(&I, IRB.getInt8PtrTy()), Len, IRB.CreatePointerCast(Descr, IRB.getInt8PtrTy())}); } else { - IRB.CreateCall(MS.MsanUnpoisonAllocaFn, + IRB.CreateCall(MS.MsanUnpoisonAllocaFnTy, MS.MsanUnpoisonAllocaFn, {IRB.CreatePointerCast(&I, IRB.getInt8PtrTy()), Len}); } } @@ -3540,7 +3585,8 @@ int Size = DL.getTypeStoreSize(ElType); Value *Ptr = IRB.CreatePointerCast(Operand, IRB.getInt8PtrTy()); Value *SizeVal = ConstantInt::get(MS.IntptrTy, Size); - IRB.CreateCall(MS.MsanInstrumentAsmStoreFn, {Ptr, SizeVal}); + IRB.CreateCall(MS.MsanInstrumentAsmStoreFnTy, MS.MsanInstrumentAsmStoreFn, + {Ptr, SizeVal}); } /// Get the number of output arguments returned by pointers. Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -784,7 +784,8 @@ IRB.SetCurrentDebugLocation(EntryLoc); if (Options.TracePC) { IRB.CreateCall(SanCovTracePC); // gets the PC using GET_CALLER_PC. - IRB.CreateCall(EmptyAsm, {}); // Avoids callback merge. + IRB.CreateCall(EmptyAsm->getFunctionType(), EmptyAsm, + {}); // Avoids callback merge. } if (Options.TracePCGuard) { auto GuardPtr = IRB.CreateIntToPtr( @@ -792,7 +793,8 @@ ConstantInt::get(IntptrTy, Idx * 4)), Int32PtrTy); IRB.CreateCall(SanCovTracePCGuard, GuardPtr); - IRB.CreateCall(EmptyAsm, {}); // Avoids callback merge. + IRB.CreateCall(EmptyAsm->getFunctionType(), EmptyAsm, + {}); // Avoids callback merge. } if (Options.Inline8bitCounters) { auto CounterPtr = IRB.CreateGEP( Index: llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp @@ -558,7 +558,7 @@ : cast(I)->getAlignment(); Type *OrigTy = cast(Addr->getType())->getElementType(); const uint32_t TypeSize = DL.getTypeStoreSizeInBits(OrigTy); - Value *OnAccessFunc = nullptr; + Function *OnAccessFunc = nullptr; if (Alignment == 0 || Alignment >= 8 || (Alignment % (TypeSize / 8)) == 0) OnAccessFunc = IsWrite ? TsanWrite[Idx] : TsanRead[Idx]; else Index: llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h =================================================================== --- llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h +++ llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h @@ -33,7 +33,7 @@ namespace llvm { -class Constant; +class Function; class LLVMContext; namespace objcarc { @@ -69,7 +69,7 @@ RetainAutoreleaseRV = nullptr; } - Constant *get(ARCRuntimeEntryPointKind kind) { + Function *get(ARCRuntimeEntryPointKind kind) { assert(TheModule != nullptr && "Not initialized."); switch (kind) { @@ -105,33 +105,33 @@ Module *TheModule = nullptr; /// Declaration for ObjC runtime function objc_autoreleaseReturnValue. - Constant *AutoreleaseRV = nullptr; + Function *AutoreleaseRV = nullptr; /// Declaration for ObjC runtime function objc_release. - Constant *Release = nullptr; + Function *Release = nullptr; /// Declaration for ObjC runtime function objc_retain. - Constant *Retain = nullptr; + Function *Retain = nullptr; /// Declaration for ObjC runtime function objc_retainBlock. - Constant *RetainBlock = nullptr; + Function *RetainBlock = nullptr; /// Declaration for ObjC runtime function objc_autorelease. - Constant *Autorelease = nullptr; + Function *Autorelease = nullptr; /// Declaration for objc_storeStrong(). - Constant *StoreStrong = nullptr; + Function *StoreStrong = nullptr; /// Declaration for objc_retainAutoreleasedReturnValue(). - Constant *RetainRV = nullptr; + Function *RetainRV = nullptr; /// Declaration for objc_retainAutorelease(). - Constant *RetainAutorelease = nullptr; + Function *RetainAutorelease = nullptr; /// Declaration for objc_retainAutoreleaseReturnValue(). - Constant *RetainAutoreleaseRV = nullptr; + Function *RetainAutoreleaseRV = nullptr; - Constant *getIntrinsicEntryPoint(Constant *&Decl, Intrinsic::ID IntID) { + Function *getIntrinsicEntryPoint(Function *&Decl, Intrinsic::ID IntID) { if (Decl) return Decl; Index: llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp =================================================================== --- llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp +++ llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp @@ -313,8 +313,8 @@ /// Create a call instruction with the correct funclet token. Should be used /// instead of calling CallInst::Create directly. static CallInst * -createCallInst(Value *Func, ArrayRef Args, const Twine &NameStr, - Instruction *InsertBefore, +createCallInst(FunctionType *FTy, Value *Func, ArrayRef Args, + const Twine &NameStr, Instruction *InsertBefore, const DenseMap &BlockColors) { SmallVector OpBundles; if (!BlockColors.empty()) { @@ -325,7 +325,15 @@ OpBundles.emplace_back("funclet", EHPad); } - return CallInst::Create(Func, Args, OpBundles, NameStr, InsertBefore); + return CallInst::Create(FTy, Func, Args, OpBundles, NameStr, InsertBefore); +} + +static CallInst * +createCallInst(Function *Func, ArrayRef Args, const Twine &NameStr, + Instruction *InsertBefore, + const DenseMap &BlockColors) { + return createCallInst(Func->getFunctionType(), Func, Args, NameStr, + InsertBefore, BlockColors); } /// Attempt to merge an objc_release with a store, load, and objc_retain to form @@ -408,7 +416,7 @@ Args[0] = new BitCastInst(Args[0], I8XX, "", Store); if (Args[1]->getType() != I8X) Args[1] = new BitCastInst(Args[1], I8X, "", Store); - Constant *Decl = EP.get(ARCRuntimeEntryPointKind::StoreStrong); + Function *Decl = EP.get(ARCRuntimeEntryPointKind::StoreStrong); CallInst *StoreStrong = createCallInst(Decl, Args, "", Store, BlockColors); StoreStrong->setDoesNotThrow(); StoreStrong->setDebugLoc(Store->getDebugLoc()); @@ -486,7 +494,7 @@ RVInstMarker->getString(), /*Constraints=*/"", /*hasSideEffects=*/true); - createCallInst(IA, None, "", Inst, BlockColors); + createCallInst(IA->getFunctionType(), IA, None, "", Inst, BlockColors); } decline_rv_optimization: return false; Index: llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp =================================================================== --- llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -829,7 +829,7 @@ // Create the declaration lazily. LLVMContext &C = Inst->getContext(); - Constant *Decl = EP.get(ARCRuntimeEntryPointKind::Release); + Function *Decl = EP.get(ARCRuntimeEntryPointKind::Release); CallInst *NewCall = CallInst::Create(Decl, Call->getArgOperand(0), "", Call); NewCall->setMetadata(MDKindCache.get(ARCMDKindID::ImpreciseRelease), @@ -1527,7 +1527,7 @@ for (Instruction *InsertPt : ReleasesToMove.ReverseInsertPts) { Value *MyArg = ArgTy == ParamTy ? Arg : new BitCastInst(Arg, ParamTy, "", InsertPt); - Constant *Decl = EP.get(ARCRuntimeEntryPointKind::Retain); + Function *Decl = EP.get(ARCRuntimeEntryPointKind::Retain); CallInst *Call = CallInst::Create(Decl, MyArg, "", InsertPt); Call->setDoesNotThrow(); Call->setTailCall(); @@ -1540,7 +1540,7 @@ for (Instruction *InsertPt : RetainsToMove.ReverseInsertPts) { Value *MyArg = ArgTy == ParamTy ? Arg : new BitCastInst(Arg, ParamTy, "", InsertPt); - Constant *Decl = EP.get(ARCRuntimeEntryPointKind::Release); + Function *Decl = EP.get(ARCRuntimeEntryPointKind::Release); CallInst *Call = CallInst::Create(Decl, MyArg, "", InsertPt); // Attach a clang.imprecise_release metadata tag, if appropriate. if (MDNode *M = ReleasesToMove.ReleaseMetadata) @@ -1876,7 +1876,7 @@ Changed = true; // If the load has a builtin retain, insert a plain retain for it. if (Class == ARCInstKind::LoadWeakRetained) { - Constant *Decl = EP.get(ARCRuntimeEntryPointKind::Retain); + Function *Decl = EP.get(ARCRuntimeEntryPointKind::Retain); CallInst *CI = CallInst::Create(Decl, EarlierCall, "", Call); CI->setTailCall(); } @@ -1905,7 +1905,7 @@ Changed = true; // If the load has a builtin retain, insert a plain retain for it. if (Class == ARCInstKind::LoadWeakRetained) { - Constant *Decl = EP.get(ARCRuntimeEntryPointKind::Retain); + Function *Decl = EP.get(ARCRuntimeEntryPointKind::Retain); CallInst *CI = CallInst::Create(Decl, EarlierCall, "", Call); CI->setTailCall(); } Index: llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp +++ llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp @@ -312,7 +312,8 @@ IRBuilder<> Builder(MemI); Module *M = BB->getParent()->getParent(); Type *I32 = Type::getInt32Ty(BB->getContext()); - Value *PrefetchFunc = Intrinsic::getDeclaration(M, Intrinsic::prefetch); + Function *PrefetchFunc = + Intrinsic::getDeclaration(M, Intrinsic::prefetch); Builder.CreateCall( PrefetchFunc, {PrefPtrValue, @@ -332,4 +333,3 @@ return MadeChange; } - Index: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -930,9 +930,9 @@ Module *M = TheStore->getModule(); StringRef FuncName = "memset_pattern16"; - Value *MSP = - M->getOrInsertFunction(FuncName, Builder.getVoidTy(), - Int8PtrTy, Int8PtrTy, IntPtr); + FunctionType *MSPTy = FunctionType::get( + Builder.getVoidTy(), {Int8PtrTy, Int8PtrTy, IntPtr}, false); + Value *MSP = M->getOrInsertFunction(FuncName, MSPTy); inferLibFuncAttributes(M, FuncName, *TLI); // Otherwise we should form a memset_pattern16. PatternValue is known to be @@ -943,7 +943,7 @@ GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); // Ok to merge these. GV->setAlignment(16); Value *PatternPtr = ConstantExpr::getBitCast(GV, Int8PtrTy); - NewCall = Builder.CreateCall(MSP, {BasePtr, PatternPtr, NumBytes}); + NewCall = Builder.CreateCall(MSPTy, MSP, {BasePtr, PatternPtr, NumBytes}); } LLVM_DEBUG(dbgs() << " Formed memset: " << *NewCall << "\n" @@ -1528,7 +1528,7 @@ Type *Tys[] = {Val->getType()}; Module *M = IRBuilder.GetInsertBlock()->getParent()->getParent(); - Value *Func = Intrinsic::getDeclaration(M, Intrinsic::ctpop, Tys); + Function *Func = Intrinsic::getDeclaration(M, Intrinsic::ctpop, Tys); CallInst *CI = IRBuilder.CreateCall(Func, Ops); CI->setDebugLoc(DL); @@ -1542,7 +1542,7 @@ Type *Tys[] = {Val->getType()}; Module *M = IRBuilder.GetInsertBlock()->getParent()->getParent(); - Value *Func = Intrinsic::getDeclaration(M, IID, Tys); + Function *Func = Intrinsic::getDeclaration(M, IID, Tys); CallInst *CI = IRBuilder.CreateCall(Func, Ops); CI->setDebugLoc(DL); Index: llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp =================================================================== --- llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -1306,7 +1306,7 @@ // Lazily populated map from input types to the canonicalized form mentioned // in the comment above. This should probably be cached somewhere more // broadly. - DenseMap TypeToDeclMap; + DenseMap TypeToDeclMap; for (unsigned i = 0; i < LiveVariables.size(); i++) { // Generate the gc.relocate call and save the result @@ -1317,7 +1317,7 @@ Type *Ty = LiveVariables[i]->getType(); if (!TypeToDeclMap.count(Ty)) TypeToDeclMap[Ty] = getGCRelocateDecl(Ty); - Value *GCRelocateDecl = TypeToDeclMap[Ty]; + Function *GCRelocateDecl = TypeToDeclMap[Ty]; // only specify a debug name if we can give a useful one CallInst *Reloc = Builder.CreateCall( Index: llvm/lib/Transforms/Utils/BuildLibCalls.cpp =================================================================== --- llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -797,10 +797,11 @@ 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()); + FunctionType *StrLenTy = + FunctionType::get(DL.getIntPtrType(Context), {B.getInt8PtrTy()}, false); + Constant *StrLen = M->getOrInsertFunction(StrlenName, StrLenTy); inferLibFuncAttributes(M, StrlenName, *TLI); - CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), StrlenName); + CallInst *CI = B.CreateCall(StrLenTy, StrLen, castToCStr(Ptr, B), StrlenName); if (const Function *F = dyn_cast(StrLen->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); @@ -816,11 +817,12 @@ StringRef StrChrName = TLI->getName(LibFunc_strchr); Type *I8Ptr = B.getInt8PtrTy(); Type *I32Ty = B.getInt32Ty(); - Constant *StrChr = - M->getOrInsertFunction(StrChrName, I8Ptr, I8Ptr, I32Ty); + FunctionType *StrChrTy = FunctionType::get(I8Ptr, {I8Ptr, I32Ty}, false); + Constant *StrChr = M->getOrInsertFunction(StrChrName, StrChrTy); inferLibFuncAttributes(M, StrChrName, *TLI); - CallInst *CI = B.CreateCall( - StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, StrChrName); + CallInst *CI = B.CreateCall(StrChrTy, StrChr, + {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, + StrChrName); if (const Function *F = dyn_cast(StrChr->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -834,12 +836,14 @@ 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)); + FunctionType *StrNCmpTy = FunctionType::get( + B.getInt32Ty(), + {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)}, false); + Value *StrNCmp = M->getOrInsertFunction(StrNCmpName, StrNCmpTy); inferLibFuncAttributes(M, StrNCmpName, *TLI); - CallInst *CI = B.CreateCall( - StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, StrNCmpName); + CallInst *CI = B.CreateCall(StrNCmpTy, StrNCmp, + {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, + StrNCmpName); if (const Function *F = dyn_cast(StrNCmp->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); @@ -854,10 +858,11 @@ Module *M = B.GetInsertBlock()->getModule(); Type *I8Ptr = B.getInt8PtrTy(); - Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr); + FunctionType *StrCpyTy = FunctionType::get(I8Ptr, {I8Ptr, I8Ptr}, false); + Value *StrCpy = M->getOrInsertFunction(Name, StrCpyTy); inferLibFuncAttributes(M, Name, *TLI); - CallInst *CI = - B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name); + CallInst *CI = B.CreateCall(StrCpyTy, StrCpy, + {castToCStr(Dst, B), castToCStr(Src, B)}, Name); if (const Function *F = dyn_cast(StrCpy->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -870,11 +875,12 @@ Module *M = B.GetInsertBlock()->getModule(); Type *I8Ptr = B.getInt8PtrTy(); - Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr, - Len->getType()); + FunctionType *StrNCpyTy = + FunctionType::get(I8Ptr, {I8Ptr, I8Ptr, Len->getType()}, false); + Value *StrNCpy = M->getOrInsertFunction(Name, StrNCpyTy); inferLibFuncAttributes(M, Name, *TLI); CallInst *CI = B.CreateCall( - StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, Name); + StrNCpyTy, StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, Name); if (const Function *F = dyn_cast(StrNCpy->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -891,13 +897,16 @@ AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex, Attribute::NoUnwind); LLVMContext &Context = B.GetInsertBlock()->getContext(); + FunctionType *MemCpyTy = + FunctionType::get(B.getInt8PtrTy(), + {B.getInt8PtrTy(), B.getInt8PtrTy(), + DL.getIntPtrType(Context), DL.getIntPtrType(Context)}, + false); Value *MemCpy = M->getOrInsertFunction( - "__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(), - B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context), - DL.getIntPtrType(Context)); + "__memcpy_chk", MemCpyTy, AttributeList::get(M->getContext(), AS)); Dst = castToCStr(Dst, B); Src = castToCStr(Src, B); - CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize}); + CallInst *CI = B.CreateCall(MemCpyTy, MemCpy, {Dst, Src, Len, ObjSize}); if (const Function *F = dyn_cast(MemCpy->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -911,11 +920,13 @@ 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)); + FunctionType *MemChrTy = FunctionType::get( + B.getInt8PtrTy(), + {B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context)}, false); + Value *MemChr = M->getOrInsertFunction(MemChrName, MemChrTy); inferLibFuncAttributes(M, MemChrName, *TLI); - CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, MemChrName); + CallInst *CI = B.CreateCall(MemChrTy, MemChr, {castToCStr(Ptr, B), Val, Len}, + MemChrName); if (const Function *F = dyn_cast(MemChr->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); @@ -931,12 +942,15 @@ 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)); + + FunctionType *MemCmpTy = FunctionType::get( + B.getInt32Ty(), + {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)}, false); + Value *MemCmp = M->getOrInsertFunction(MemCmpName, MemCmpTy); inferLibFuncAttributes(M, MemCmpName, *TLI); - CallInst *CI = B.CreateCall( - MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, MemCmpName); + CallInst *CI = + B.CreateCall(MemCmpTy, MemCmp, + {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, MemCmpName); if (const Function *F = dyn_cast(MemCmp->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); @@ -965,9 +979,9 @@ assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall"); Module *M = B.GetInsertBlock()->getModule(); - Value *Callee = M->getOrInsertFunction(Name, Op->getType(), - Op->getType()); - CallInst *CI = B.CreateCall(Callee, Op, Name); + FunctionType *FnTy = FunctionType::get(Op->getType(), {Op->getType()}, false); + Value *Callee = M->getOrInsertFunction(Name, FnTy); + CallInst *CI = B.CreateCall(FnTy, Callee, Op, Name); // The incoming attribute set may have come from a speculatable intrinsic, but // is being replaced with a library call which is not allowed to be @@ -1008,9 +1022,10 @@ appendTypeSuffix(Op1, Name, NameBuffer); Module *M = B.GetInsertBlock()->getModule(); - Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), Op1->getType(), - Op2->getType()); - CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name); + FunctionType *FnTy = FunctionType::get( + Op1->getType(), {Op1->getType(), Op2->getType()}, false); + Value *Callee = M->getOrInsertFunction(Name, FnTy); + CallInst *CI = B.CreateCall(FnTy, Callee, {Op1, Op2}, Name); CI->setAttributes(Attrs); if (const Function *F = dyn_cast(Callee->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); @@ -1025,14 +1040,14 @@ Module *M = B.GetInsertBlock()->getModule(); StringRef PutCharName = TLI->getName(LibFunc_putchar); - Value *PutChar = M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty()); + FunctionType *PutCharTy = + FunctionType::get(B.getInt32Ty(), {B.getInt32Ty()}, false); + Value *PutChar = M->getOrInsertFunction(PutCharName, PutCharTy); inferLibFuncAttributes(M, PutCharName, *TLI); - CallInst *CI = B.CreateCall(PutChar, - B.CreateIntCast(Char, - B.getInt32Ty(), - /*isSigned*/true, - "chari"), - PutCharName); + CallInst *CI = B.CreateCall( + PutCharTy, PutChar, + B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/ true, "chari"), + PutCharName); if (const Function *F = dyn_cast(PutChar->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); @@ -1046,10 +1061,11 @@ Module *M = B.GetInsertBlock()->getModule(); StringRef PutsName = TLI->getName(LibFunc_puts); - Value *PutS = - M->getOrInsertFunction(PutsName, B.getInt32Ty(), B.getInt8PtrTy()); + FunctionType *PutSTy = + FunctionType::get(B.getInt32Ty(), {B.getInt8PtrTy()}, false); + Value *PutS = M->getOrInsertFunction(PutsName, PutSTy); inferLibFuncAttributes(M, PutsName, *TLI); - CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), PutsName); + CallInst *CI = B.CreateCall(PutSTy, PutS, castToCStr(Str, B), PutsName); if (const Function *F = dyn_cast(PutS->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -1062,15 +1078,16 @@ Module *M = B.GetInsertBlock()->getModule(); StringRef FPutcName = TLI->getName(LibFunc_fputc); - Constant *F = M->getOrInsertFunction(FPutcName, B.getInt32Ty(), B.getInt32Ty(), - File->getType()); + FunctionType *FPutcTy = FunctionType::get( + B.getInt32Ty(), {B.getInt32Ty(), File->getType()}, false); + Constant *FPutc = M->getOrInsertFunction(FPutcName, FPutcTy); 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); + CallInst *CI = B.CreateCall(FPutcTy, FPutc, {Char, File}, FPutcName); - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) + if (const Function *Fn = dyn_cast(FPutc->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1082,14 +1099,18 @@ Module *M = B.GetInsertBlock()->getModule(); StringRef FPutcUnlockedName = TLI->getName(LibFunc_fputc_unlocked); - Constant *F = M->getOrInsertFunction(FPutcUnlockedName, B.getInt32Ty(), - B.getInt32Ty(), File->getType()); + FunctionType *FPutcUnlockedTy = FunctionType::get( + B.getInt32Ty(), {B.getInt32Ty(), File->getType()}, false); + Constant *FPutcUnlocked = + M->getOrInsertFunction(FPutcUnlockedName, FPutcUnlockedTy); 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); + CallInst *CI = B.CreateCall(FPutcUnlockedTy, FPutcUnlocked, {Char, File}, + FPutcUnlockedName); - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast(FPutcUnlocked->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1101,13 +1122,15 @@ Module *M = B.GetInsertBlock()->getModule(); StringRef FPutsName = TLI->getName(LibFunc_fputs); - Constant *F = M->getOrInsertFunction( - FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType()); + FunctionType *FPutsTy = FunctionType::get( + B.getInt32Ty(), {B.getInt8PtrTy(), File->getType()}, false); + Constant *FPuts = M->getOrInsertFunction(FPutsName, FPutsTy); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FPutsName, *TLI); - CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsName); + CallInst *CI = + B.CreateCall(FPutsTy, FPuts, {castToCStr(Str, B), File}, FPutsName); - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) + if (const Function *Fn = dyn_cast(FPuts->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1119,13 +1142,17 @@ Module *M = B.GetInsertBlock()->getModule(); StringRef FPutsUnlockedName = TLI->getName(LibFunc_fputs_unlocked); - Constant *F = M->getOrInsertFunction(FPutsUnlockedName, B.getInt32Ty(), - B.getInt8PtrTy(), File->getType()); + FunctionType *FPutsUnlockedTy = FunctionType::get( + B.getInt32Ty(), {B.getInt8PtrTy(), File->getType()}, false); + Constant *FPutsUnlocked = + M->getOrInsertFunction(FPutsUnlockedName, FPutsUnlockedTy); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FPutsUnlockedName, *TLI); - CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsUnlockedName); + CallInst *CI = B.CreateCall(FPutsUnlockedTy, FPutsUnlocked, + {castToCStr(Str, B), File}, FPutsUnlockedName); - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast(FPutsUnlocked->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1138,17 +1165,21 @@ Module *M = B.GetInsertBlock()->getModule(); LLVMContext &Context = B.GetInsertBlock()->getContext(); StringRef FWriteName = TLI->getName(LibFunc_fwrite); - Constant *F = M->getOrInsertFunction( - FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(), - DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType()); + FunctionType *FWriteTy = + FunctionType::get(DL.getIntPtrType(Context), + {B.getInt8PtrTy(), DL.getIntPtrType(Context), + DL.getIntPtrType(Context), File->getType()}, + false); + Constant *FWrite = M->getOrInsertFunction(FWriteName, FWriteTy); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FWriteName, *TLI); CallInst *CI = - B.CreateCall(F, {castToCStr(Ptr, B), Size, - ConstantInt::get(DL.getIntPtrType(Context), 1), File}); + B.CreateCall(FWriteTy, FWrite, + {castToCStr(Ptr, B), Size, + ConstantInt::get(DL.getIntPtrType(Context), 1), File}); - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) + if (const Function *Fn = dyn_cast(FWrite->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1159,12 +1190,13 @@ return nullptr; 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)); + StringRef MallocName = TLI->getName(LibFunc_malloc); + FunctionType *MallocTy = + FunctionType::get(B.getInt8PtrTy(), {DL.getIntPtrType(Context)}, false); + Value *Malloc = M->getOrInsertFunction(MallocName, MallocTy); inferLibFuncAttributes(M, MallocName, *TLI); - CallInst *CI = B.CreateCall(Malloc, Num, MallocName); + CallInst *CI = B.CreateCall(MallocTy, Malloc, Num, MallocName); if (const Function *F = dyn_cast(Malloc->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); @@ -1181,10 +1213,11 @@ 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); + FunctionType *CallocTy = + FunctionType::get(B.getInt8PtrTy(), {PtrType, PtrType}, false); + Value *Calloc = M->getOrInsertFunction(CallocName, CallocTy, Attrs); inferLibFuncAttributes(M, CallocName, TLI); - CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName); + CallInst *CI = B.CreateCall(CallocTy, Calloc, {Num, Size}, CallocName); if (const auto *F = dyn_cast(Calloc->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); @@ -1201,15 +1234,21 @@ Module *M = B.GetInsertBlock()->getModule(); LLVMContext &Context = B.GetInsertBlock()->getContext(); StringRef FWriteUnlockedName = TLI->getName(LibFunc_fwrite_unlocked); - Constant *F = M->getOrInsertFunction( - FWriteUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(), - DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType()); + FunctionType *FWriteUnlockedTy = + FunctionType::get(DL.getIntPtrType(Context), + {B.getInt8PtrTy(), DL.getIntPtrType(Context), + DL.getIntPtrType(Context), File->getType()}, + false); + Constant *FWriteUnlocked = + M->getOrInsertFunction(FWriteUnlockedName, FWriteUnlockedTy); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FWriteUnlockedName, *TLI); - CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File}); + CallInst *CI = B.CreateCall(FWriteUnlockedTy, FWriteUnlocked, + {castToCStr(Ptr, B), Size, N, File}); - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast(FWriteUnlocked->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1221,13 +1260,17 @@ Module *M = B.GetInsertBlock()->getModule(); StringRef FGetCUnlockedName = TLI->getName(LibFunc_fgetc_unlocked); - Constant *F = - M->getOrInsertFunction(FGetCUnlockedName, B.getInt32Ty(), File->getType()); + FunctionType *FGetCUnlockedTy = + FunctionType::get(B.getInt32Ty(), {File->getType()}, false); + Constant *FGetCUnlocked = + M->getOrInsertFunction(FGetCUnlockedName, FGetCUnlockedTy); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FGetCUnlockedName, *TLI); - CallInst *CI = B.CreateCall(F, File, FGetCUnlockedName); + CallInst *CI = + B.CreateCall(FGetCUnlockedTy, FGetCUnlocked, File, FGetCUnlockedName); - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast(FGetCUnlocked->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1239,14 +1282,18 @@ Module *M = B.GetInsertBlock()->getModule(); StringRef FGetSUnlockedName = TLI->getName(LibFunc_fgets_unlocked); - Constant *F = - M->getOrInsertFunction(FGetSUnlockedName, B.getInt8PtrTy(), - B.getInt8PtrTy(), B.getInt32Ty(), File->getType()); + FunctionType *FGetSUnlockedTy = FunctionType::get( + B.getInt8PtrTy(), {B.getInt8PtrTy(), B.getInt32Ty(), File->getType()}, + false); + Constant *FGetSUnlocked = + M->getOrInsertFunction(FGetSUnlockedName, FGetSUnlockedTy); inferLibFuncAttributes(M, FGetSUnlockedName, *TLI); CallInst *CI = - B.CreateCall(F, {castToCStr(Str, B), Size, File}, FGetSUnlockedName); + B.CreateCall(FGetSUnlockedTy, FGetSUnlocked, + {castToCStr(Str, B), Size, File}, FGetSUnlockedName); - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast(FGetSUnlocked->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1260,15 +1307,21 @@ Module *M = B.GetInsertBlock()->getModule(); LLVMContext &Context = B.GetInsertBlock()->getContext(); StringRef FReadUnlockedName = TLI->getName(LibFunc_fread_unlocked); - Constant *F = M->getOrInsertFunction( - FReadUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(), - DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType()); + FunctionType *FReadUnlockedTy = + FunctionType::get(DL.getIntPtrType(Context), + {B.getInt8PtrTy(), DL.getIntPtrType(Context), + DL.getIntPtrType(Context), File->getType()}, + false); + Constant *FReadUnlocked = + M->getOrInsertFunction(FReadUnlockedName, FReadUnlockedTy); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FReadUnlockedName, *TLI); - CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File}); + CallInst *CI = B.CreateCall(FReadUnlockedTy, FReadUnlocked, + {castToCStr(Ptr, B), Size, N, File}); - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast(FReadUnlocked->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } Index: llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp =================================================================== --- llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp +++ llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp @@ -30,8 +30,9 @@ Func == "__mcount" || Func == "_mcount" || Func == "__cyg_profile_func_enter_bare") { - Constant *Fn = M.getOrInsertFunction(Func, Type::getVoidTy(C)); - CallInst *Call = CallInst::Create(Fn, "", InsertionPt); + FunctionType *FnTy = FunctionType::get(Type::getVoidTy(C), {}, false); + Constant *Fn = M.getOrInsertFunction(Func, FnTy); + CallInst *Call = CallInst::Create(FnTy, Fn, "", InsertionPt); Call->setDebugLoc(DL); return; } @@ -39,8 +40,8 @@ if (Func == "__cyg_profile_func_enter" || Func == "__cyg_profile_func_exit") { Type *ArgTypes[] = {Type::getInt8PtrTy(C), Type::getInt8PtrTy(C)}; - Constant *Fn = M.getOrInsertFunction( - Func, FunctionType::get(Type::getVoidTy(C), ArgTypes, false)); + FunctionType *FnTy = FunctionType::get(Type::getVoidTy(C), ArgTypes, false); + Constant *Fn = M.getOrInsertFunction(Func, FnTy); Instruction *RetAddr = CallInst::Create( Intrinsic::getDeclaration(&M, Intrinsic::returnaddress), @@ -52,7 +53,7 @@ RetAddr}; CallInst *Call = - CallInst::Create(Fn, ArrayRef(Args), "", InsertionPt); + CallInst::Create(FnTy, Fn, ArrayRef(Args), "", InsertionPt); Call->setDebugLoc(DL); return; } Index: llvm/lib/Transforms/Utils/InlineFunction.cpp =================================================================== --- llvm/lib/Transforms/Utils/InlineFunction.cpp +++ llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1864,10 +1864,8 @@ // Add VarArgs to existing parameters. SmallVector Params(CI->arg_operands()); Params.append(VarArgsToForward.begin(), VarArgsToForward.end()); - CallInst *NewCI = - CallInst::Create(CI->getCalledFunction() ? CI->getCalledFunction() - : CI->getCalledValue(), - Params, "", CI); + CallInst *NewCI = CallInst::Create( + CI->getFunctionType(), CI->getCalledOperand(), Params, "", CI); NewCI->setDebugLoc(CI->getDebugLoc()); NewCI->setAttributes(Attrs); NewCI->setCallingConv(CI->getCallingConv()); Index: llvm/lib/Transforms/Utils/Local.cpp =================================================================== --- llvm/lib/Transforms/Utils/Local.cpp +++ llvm/lib/Transforms/Utils/Local.cpp @@ -1936,8 +1936,8 @@ SmallVector Args(II->arg_begin(), II->arg_end()); SmallVector OpBundles; II->getOperandBundlesAsDefs(OpBundles); - CallInst *NewCall = CallInst::Create(II->getCalledValue(), Args, OpBundles, - "", II); + CallInst *NewCall = CallInst::Create( + II->getFunctionType(), II->getCalledValue(), Args, OpBundles, "", II); NewCall->takeName(II); NewCall->setCallingConv(II->getCallingConv()); NewCall->setAttributes(II->getAttributes()); Index: llvm/lib/Transforms/Utils/LowerInvoke.cpp =================================================================== --- llvm/lib/Transforms/Utils/LowerInvoke.cpp +++ llvm/lib/Transforms/Utils/LowerInvoke.cpp @@ -52,7 +52,8 @@ II->getOperandBundlesAsDefs(OpBundles); // Insert a normal call instruction... CallInst *NewCall = - CallInst::Create(II->getCalledValue(), CallArgs, OpBundles, "", II); + CallInst::Create(II->getFunctionType(), II->getCalledValue(), + CallArgs, OpBundles, "", II); NewCall->takeName(II); NewCall->setCallingConv(II->getCallingConv()); NewCall->setAttributes(II->getAttributes()); Index: llvm/lib/Transforms/Utils/SanitizerStats.cpp =================================================================== --- llvm/lib/Transforms/Utils/SanitizerStats.cpp +++ llvm/lib/Transforms/Utils/SanitizerStats.cpp @@ -65,7 +65,8 @@ ConstantInt::get(IntPtrTy, 0), ConstantInt::get(B.getInt32Ty(), 2), ConstantInt::get(IntPtrTy, Inits.size() - 1), }); - B.CreateCall(StatReport, ConstantExpr::getBitCast(InitAddr, Int8PtrTy)); + B.CreateCall(StatReportTy, StatReport, + ConstantExpr::getBitCast(InitAddr, Int8PtrTy)); } void SanitizerStatReport::finish() { @@ -100,7 +101,8 @@ Constant *StatInit = M->getOrInsertFunction( "__sanitizer_stat_init", StatInitTy); - B.CreateCall(StatInit, ConstantExpr::getBitCast(NewModuleStatsGV, Int8PtrTy)); + B.CreateCall(StatInitTy, StatInit, + ConstantExpr::getBitCast(NewModuleStatsGV, Int8PtrTy)); B.CreateRetVoid(); appendToGlobalCtors(*M, F, 0); Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp =================================================================== --- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1503,10 +1503,10 @@ One = ConstantExpr::getFPExtend(One, Op->getType()); Module *M = CI->getModule(); - Value *NewCallee = - M->getOrInsertFunction(TLI->getName(LdExp), Op->getType(), - Op->getType(), B.getInt32Ty()); - CallInst *CI = B.CreateCall(NewCallee, {One, LdExpArg}); + FunctionType *NewFnTy = FunctionType::get( + Op->getType(), {Op->getType(), B.getInt32Ty()}, false); + Value *NewCallee = M->getOrInsertFunction(TLI->getName(LdExp), NewFnTy); + CallInst *CI = B.CreateCall(NewFnTy, NewCallee, {One, LdExpArg}); if (const Function *F = dyn_cast(Callee->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); @@ -1653,13 +1653,13 @@ // replace it with the fabs of that factor. Module *M = Callee->getParent(); Type *ArgType = I->getType(); - Value *Fabs = Intrinsic::getDeclaration(M, Intrinsic::fabs, ArgType); + Function *Fabs = Intrinsic::getDeclaration(M, Intrinsic::fabs, ArgType); Value *FabsCall = B.CreateCall(Fabs, RepeatOp, "fabs"); if (OtherOp) { // If we found a non-repeated factor, we still need to get its square // root. We then multiply that by the value that was simplified out // of the square root calculation. - Value *Sqrt = Intrinsic::getDeclaration(M, Intrinsic::sqrt, ArgType); + Function *Sqrt = Intrinsic::getDeclaration(M, Intrinsic::sqrt, ArgType); Value *SqrtCall = B.CreateCall(Sqrt, OtherOp, "sqrt"); return B.CreateFMul(FabsCall, SqrtCall); } @@ -1727,8 +1727,9 @@ } Module *M = OrigCallee->getParent(); - Value *Callee = M->getOrInsertFunction(Name, OrigCallee->getAttributes(), - ResTy, ArgTy); + FunctionType *CalleeFnTy = FunctionType::get(ResTy, {ArgTy}, false); + Value *Callee = + M->getOrInsertFunction(Name, CalleeFnTy, OrigCallee->getAttributes()); if (Instruction *ArgInst = dyn_cast(Arg)) { // If the argument is an instruction, it must dominate all uses so put our @@ -1741,7 +1742,7 @@ B.SetInsertPoint(&EntryBB, EntryBB.begin()); } - SinCos = B.CreateCall(Callee, Arg, "sincospi"); + SinCos = B.CreateCall(CalleeFnTy, Callee, Arg, "sincospi"); if (SinCos->getType()->isStructTy()) { Sin = B.CreateExtractValue(SinCos, 0, "sinpi"); @@ -1839,8 +1840,8 @@ // ffs(x) -> x != 0 ? (i32)llvm.cttz(x)+1 : 0 Value *Op = CI->getArgOperand(0); Type *ArgType = Op->getType(); - Value *F = Intrinsic::getDeclaration(CI->getCalledFunction()->getParent(), - Intrinsic::cttz, ArgType); + Function *F = Intrinsic::getDeclaration(CI->getCalledFunction()->getParent(), + Intrinsic::cttz, ArgType); Value *V = B.CreateCall(F, {Op, B.getTrue()}, "cttz"); V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1)); V = B.CreateIntCast(V, B.getInt32Ty(), false); @@ -1853,8 +1854,8 @@ // fls(x) -> (i32)(sizeInBits(x) - llvm.ctlz(x, false)) Value *Op = CI->getArgOperand(0); Type *ArgType = Op->getType(); - Value *F = Intrinsic::getDeclaration(CI->getCalledFunction()->getParent(), - Intrinsic::ctlz, ArgType); + Function *F = Intrinsic::getDeclaration(CI->getCalledFunction()->getParent(), + Intrinsic::ctlz, ArgType); Value *V = B.CreateCall(F, {Op, B.getFalse()}, "ctlz"); V = B.CreateSub(ConstantInt::get(V->getType(), ArgType->getIntegerBitWidth()), V); Index: llvm/tools/bugpoint/Miscompilation.cpp =================================================================== --- llvm/tools/bugpoint/Miscompilation.cpp +++ llvm/tools/bugpoint/Miscompilation.cpp @@ -826,9 +826,11 @@ // Add the resolver to the Safe module. // Prototype: void *getPointerToNamedFunction(const char* Name) - Constant *resolverFunc = Safe->getOrInsertFunction( - "getPointerToNamedFunction", Type::getInt8PtrTy(Safe->getContext()), - Type::getInt8PtrTy(Safe->getContext())); + FunctionType *resolverFuncTy = + FunctionType::get(Type::getInt8PtrTy(Safe->getContext()), + {Type::getInt8PtrTy(Safe->getContext())}, false); + Constant *resolverFunc = + Safe->getOrInsertFunction("getPointerToNamedFunction", resolverFuncTy); // Use the function we just added to get addresses of functions we need. for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) { @@ -886,8 +888,8 @@ // Resolve the call to function F via the JIT API: // // call resolver(GetElementPtr...) - CallInst *Resolver = CallInst::Create(resolverFunc, ResolverArgs, - "resolver", LookupBB); + CallInst *Resolver = CallInst::Create( + resolverFuncTy, resolverFunc, ResolverArgs, "resolver", LookupBB); // Cast the result from the resolver to correctly-typed function. CastInst *CastedResolver = new BitCastInst( @@ -910,11 +912,11 @@ // Pass on the arguments to the real function, return its result if (F->getReturnType()->isVoidTy()) { - CallInst::Create(FuncPtr, Args, "", DoCallBB); + CallInst::Create(FuncTy, FuncPtr, Args, "", DoCallBB); ReturnInst::Create(F->getContext(), DoCallBB); } else { CallInst *Call = - CallInst::Create(FuncPtr, Args, "retval", DoCallBB); + CallInst::Create(FuncTy, FuncPtr, Args, "retval", DoCallBB); ReturnInst::Create(F->getContext(), Call, DoCallBB); } Index: llvm/unittests/IR/BasicBlockTest.cpp =================================================================== --- llvm/unittests/IR/BasicBlockTest.cpp +++ llvm/unittests/IR/BasicBlockTest.cpp @@ -100,10 +100,9 @@ Argument *V = new Argument(Type::getInt32Ty(Ctx)); Function *F = Function::Create(FT, Function::ExternalLinkage, "", M); - Value *DbgAddr = Intrinsic::getDeclaration(M, Intrinsic::dbg_addr); - Value *DbgDeclare = - Intrinsic::getDeclaration(M, Intrinsic::dbg_declare); - Value *DbgValue = Intrinsic::getDeclaration(M, Intrinsic::dbg_value); + Function *DbgAddr = Intrinsic::getDeclaration(M, Intrinsic::dbg_addr); + Function *DbgDeclare = Intrinsic::getDeclaration(M, Intrinsic::dbg_declare); + Function *DbgValue = Intrinsic::getDeclaration(M, Intrinsic::dbg_value); Value *DIV = MetadataAsValue::get(Ctx, (Metadata *)nullptr); SmallVector Args = {DIV, DIV, DIV}; Index: llvm/unittests/IR/IRBuilderTest.cpp =================================================================== --- llvm/unittests/IR/IRBuilderTest.cpp +++ llvm/unittests/IR/IRBuilderTest.cpp @@ -353,7 +353,7 @@ FCall = Builder.CreateCall(Callee, None); EXPECT_FALSE(FCall->hasNoNaNs()); - Value *V = + Function *V = Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get()); FCall = Builder.CreateCall(V, None); EXPECT_FALSE(FCall->hasNoNaNs()); Index: llvm/unittests/IR/InstructionsTest.cpp =================================================================== --- llvm/unittests/IR/InstructionsTest.cpp +++ llvm/unittests/IR/InstructionsTest.cpp @@ -504,14 +504,15 @@ LLVMContext C; Type *Int32Ty = Type::getInt32Ty(C); Type *ArgTys[] = {Int32Ty, Int32Ty, Int32Ty}; - Type *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false); + FunctionType *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false); Value *Callee = Constant::getNullValue(FnTy->getPointerTo()); Value *Args[] = { ConstantInt::get(Int32Ty, 1), ConstantInt::get(Int32Ty, 2), ConstantInt::get(Int32Ty, 3) }; - std::unique_ptr Call(CallInst::Create(Callee, Args, "result")); + std::unique_ptr Call( + CallInst::Create(FnTy, Callee, Args, "result")); // Test cloning the tail call kind. CallInst::TailCallKind Kinds[] = {CallInst::TCK_None, CallInst::TCK_Tail, @@ -537,12 +538,12 @@ TEST(InstructionsTest, AlterCallBundles) { LLVMContext C; Type *Int32Ty = Type::getInt32Ty(C); - Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false); + FunctionType *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false); Value *Callee = Constant::getNullValue(FnTy->getPointerTo()); Value *Args[] = {ConstantInt::get(Int32Ty, 42)}; OperandBundleDef OldBundle("before", UndefValue::get(Int32Ty)); std::unique_ptr Call( - CallInst::Create(Callee, Args, OldBundle, "result")); + CallInst::Create(FnTy, Callee, Args, OldBundle, "result")); Call->setTailCallKind(CallInst::TailCallKind::TCK_NoTail); AttrBuilder AB; AB.addAttribute(Attribute::Cold);