diff --git a/llvm/include/llvm/Analysis/MemoryBuiltins.h b/llvm/include/llvm/Analysis/MemoryBuiltins.h --- a/llvm/include/llvm/Analysis/MemoryBuiltins.h +++ b/llvm/include/llvm/Analysis/MemoryBuiltins.h @@ -52,9 +52,9 @@ /// Tests if a value is a call or invoke to a library function that /// allocates or reallocates memory (either malloc, calloc, realloc, or strdup /// like). -bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI); -bool isAllocationFn(const Value *V, - function_ref GetTLI); +bool isAllocOrReallocLikeFn(const Value *V, const TargetLibraryInfo *TLI); +bool isAllocOrReallocLikeFn( + const Value *V, function_ref GetTLI); /// Tests if a value is a call or invoke to a library function that /// allocates uninitialized memory (such as malloc). diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp --- a/llvm/lib/Analysis/GlobalsModRef.cpp +++ b/llvm/lib/Analysis/GlobalsModRef.cpp @@ -586,7 +586,7 @@ // handled above. if (auto *Call = dyn_cast(&I)) { auto &TLI = GetTLI(*Node->getFunction()); - if (isAllocationFn(Call, &TLI) || isFreeCall(Call, &TLI)) { + if (isAllocOrReallocLikeFn(Call, &TLI) || isFreeCall(Call, &TLI)) { // FIXME: It is completely unclear why this is necessary and not // handled by the above graph code. FI.addModRefInfo(ModRefInfo::ModRef); diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -226,11 +226,13 @@ /// Tests if a value is a call or invoke to a library function that /// allocates or reallocates memory (either malloc, calloc, realloc, or strdup /// like). -bool llvm::isAllocationFn(const Value *V, const TargetLibraryInfo *TLI) { +bool llvm::isAllocOrReallocLikeFn(const Value *V, + const TargetLibraryInfo *TLI) { return getAllocationData(V, AnyAlloc, TLI).hasValue(); } -bool llvm::isAllocationFn( - const Value *V, function_ref GetTLI) { +bool llvm::isAllocOrReallocLikeFn( + const Value *V, + function_ref GetTLI) { return getAllocationData(V, AnyAlloc, GetTLI).hasValue(); } @@ -283,7 +285,7 @@ } bool llvm::isAllocRemovable(const CallBase *CB, const TargetLibraryInfo *TLI) { - assert(isAllocationFn(CB, TLI)); + assert(isAllocOrReallocLikeFn(CB, TLI)); // Note: Removability is highly dependent on the source language. For // example, recent C++ requires direct calls to the global allocation @@ -296,7 +298,7 @@ Value *llvm::getAllocAlignment(const CallBase *V, const TargetLibraryInfo *TLI) { - assert(isAllocationFn(V, TLI)); + assert(isAllocOrReallocLikeFn(V, TLI)); const Optional FnData = getAllocationData(V, AnyAlloc, TLI); if (!FnData.hasValue() || FnData->AlignParam < 0) { @@ -387,7 +389,7 @@ Constant *llvm::getInitialValueOfAllocation(const CallBase *Alloc, const TargetLibraryInfo *TLI, Type *Ty) { - assert(isAllocationFn(Alloc, TLI)); + assert(isAllocOrReallocLikeFn(Alloc, TLI)); // malloc and aligned_alloc are uninitialized (undef) if (isMallocLikeFn(Alloc, TLI) || isAlignedAllocLikeFn(Alloc, TLI)) diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -207,7 +207,7 @@ const TargetLibraryInfo *TLI) { if (isa(Obj)) return UndefValue::get(&Ty); - if (isAllocationFn(&Obj, TLI)) + if (isAllocOrReallocLikeFn(&Obj, TLI)) return getInitialValueOfAllocation(&cast(Obj), TLI, &Ty); auto *GV = dyn_cast(&Obj); if (!GV || !GV->hasLocalLinkage()) diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -5830,7 +5830,7 @@ // To do heap to stack, we need to know that the allocation itself is // removable once uses are rewritten, and that we can initialize the // alloca to the same pattern as the original allocation result. - if (isAllocationFn(CB, TLI) && isAllocRemovable(CB, TLI)) { + if (isAllocOrReallocLikeFn(CB, TLI) && isAllocRemovable(CB, TLI)) { auto *I8Ty = Type::getInt8Ty(CB->getParent()->getContext()); if (nullptr != getInitialValueOfAllocation(CB, TLI, I8Ty)) { AllocationInfo *AI = new (A.Allocator) AllocationInfo{CB}; diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -170,7 +170,7 @@ if (isa(V) || isa(V) || isa(V) || isa(V)) return false; - if (isAllocationFn(V, GetTLI)) + if (isAllocOrReallocLikeFn(V, GetTLI)) return true; Instruction *I = cast(V); @@ -257,7 +257,7 @@ Dead[i].second->eraseFromParent(); Instruction *I = Dead[i].first; do { - if (isAllocationFn(I, GetTLI)) + if (isAllocOrReallocLikeFn(I, GetTLI)) break; Instruction *J = dyn_cast(I->getOperand(0)); if (!J) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2607,7 +2607,7 @@ /// Improvements for call, callbr and invoke instructions. Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) { - if (isAllocationFn(&Call, &TLI)) + if (isAllocOrReallocLikeFn(&Call, &TLI)) annotateAnyAllocSite(Call, &TLI); bool Changed = false; @@ -2761,7 +2761,7 @@ Call, Builder.CreateBitOrPointerCast(ReturnedArg, CallTy)); } - if (isAllocationFn(&Call, &TLI) && + if (isAllocOrReallocLikeFn(&Call, &TLI) && isAllocRemovable(&cast(Call), &TLI)) return visitAllocSite(Call); diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2488,7 +2488,7 @@ // By avoiding such GEPs, phi translation and MemoryDependencyAnalysis have // a better chance to succeed. if (!isa(SrcOp) && GEP.accumulateConstantOffset(DL, Offset) && - !isAllocationFn(SrcOp, &TLI)) { + !isAllocOrReallocLikeFn(SrcOp, &TLI)) { // If this GEP instruction doesn't move the pointer, just replace the GEP // with a bitcast of the real input to the dest type. if (!Offset) { diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -1786,7 +1786,7 @@ if (!isRemovable(DefI)) return false; - if (StoredConstant && isAllocationFn(DefUO, &TLI)) { + if (StoredConstant && isAllocOrReallocLikeFn(DefUO, &TLI)) { auto *CB = cast(DefUO); auto *InitC = getInitialValueOfAllocation(CB, &TLI, StoredConstant->getType()); diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -1111,7 +1111,7 @@ return true; } - if (isAllocationFn(DepInst, TLI)) + if (isAllocOrReallocLikeFn(DepInst, TLI)) if (auto *InitVal = getInitialValueOfAllocation(cast(DepInst), TLI, Load->getType())) { Res = AvailableValue::get(InitVal); diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -1501,7 +1501,7 @@ else if (auto *II = dyn_cast(DepInst)) { if (II->getIntrinsicID() == Intrinsic::lifetime_start) return createConstantExpression(UndefValue::get(LoadType)); - } else if (isAllocationFn(DepInst, TLI)) + } else if (isAllocOrReallocLikeFn(DepInst, TLI)) if (auto *InitVal = getInitialValueOfAllocation(cast(DepInst), TLI, LoadType)) return createConstantExpression(InitVal); diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -492,7 +492,8 @@ } } - if (isAllocationFn(I, TLI) && isAllocRemovable(cast(I), TLI)) + if (isAllocOrReallocLikeFn(I, TLI) && + isAllocRemovable(cast(I), TLI)) return true; if (CallInst *CI = isFreeCall(I, TLI)) diff --git a/llvm/unittests/Analysis/MemoryBuiltinsTest.cpp b/llvm/unittests/Analysis/MemoryBuiltinsTest.cpp --- a/llvm/unittests/Analysis/MemoryBuiltinsTest.cpp +++ b/llvm/unittests/Analysis/MemoryBuiltinsTest.cpp @@ -41,6 +41,6 @@ // FIXME: We might be able to treat allocsize functions as general allocation // functions. - EXPECT_FALSE(isAllocationFn(Caller.get(), TLI)); + EXPECT_FALSE(isAllocOrReallocLikeFn(Caller.get(), TLI)); } }