[llvm] 67a3331 - Inline extractMallocCall to sole use and delete [NFC]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 6 18:16:56 PST 2022


Author: Philip Reames
Date: 2022-01-06T18:02:13-08:00
New Revision: 67a3331e4f6d339a09f07e823b4be8404a59d761

URL: https://github.com/llvm/llvm-project/commit/67a3331e4f6d339a09f07e823b4be8404a59d761
DIFF: https://github.com/llvm/llvm-project/commit/67a3331e4f6d339a09f07e823b4be8404a59d761.diff

LOG: Inline extractMallocCall to sole use and delete [NFC]

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/MemoryBuiltins.h
    llvm/lib/Analysis/MemoryBuiltins.cpp
    llvm/lib/Transforms/IPO/GlobalOpt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/MemoryBuiltins.h b/llvm/include/llvm/Analysis/MemoryBuiltins.h
index 06cc77ffee69e..565c3d097a590 100644
--- a/llvm/include/llvm/Analysis/MemoryBuiltins.h
+++ b/llvm/include/llvm/Analysis/MemoryBuiltins.h
@@ -118,18 +118,6 @@ bool isStrdupLikeFn(const Value *V, const TargetLibraryInfo *TLI,
 //  malloc Call Utility Functions.
 //
 
-/// extractMallocCall - Returns the corresponding CallInst if the instruction
-/// is a malloc call.  Since CallInst::CreateMalloc() only creates calls, we
-/// ignore InvokeInst here.
-const CallInst *
-extractMallocCall(const Value *I,
-                  function_ref<const TargetLibraryInfo &(Function &)> GetTLI);
-inline CallInst *
-extractMallocCall(Value *I,
-                  function_ref<const TargetLibraryInfo &(Function &)> GetTLI) {
-  return const_cast<CallInst *>(extractMallocCall((const Value *)I, GetTLI));
-}
-
 /// getMallocAllocatedType - Returns the Type allocated by malloc call.
 /// The Type depends on the number of bitcast uses of the malloc call:
 ///   0: PointerType is the malloc calls' return type.

diff  --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 437b7c89d5a8c..88cda35960e7c 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -334,15 +334,6 @@ bool llvm::isStrdupLikeFn(const Value *V, const TargetLibraryInfo *TLI,
   return getAllocationData(V, StrDupLike, TLI, LookThroughBitCast).hasValue();
 }
 
-/// extractMallocCall - Returns the corresponding CallInst if the instruction
-/// is a malloc call.  Since CallInst::CreateMalloc() only creates calls, we
-/// ignore InvokeInst here.
-const CallInst *llvm::extractMallocCall(
-    const Value *I,
-    function_ref<const TargetLibraryInfo &(Function &)> GetTLI) {
-  return isMallocLikeFn(I, GetTLI) ? dyn_cast<CallInst>(I) : nullptr;
-}
-
 static Value *computeArraySize(const CallInst *CI, const DataLayout &DL,
                                const TargetLibraryInfo *TLI,
                                bool LookThroughSExt = false) {

diff  --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 896ce8eb52457..7c7e2bc93f008 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1140,7 +1140,8 @@ optimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
       // Optimize away any trapping uses of the loaded value.
       if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC, DL, GetTLI))
         return true;
-    } else if (CallInst *CI = extractMallocCall(StoredOnceVal, GetTLI)) {
+    } else if (isMallocLikeFn(StoredOnceVal, GetTLI)) {
+      auto *CI = cast<CallInst>(StoredOnceVal);
       auto *TLI = &GetTLI(*CI->getFunction());
       Type *MallocType = getMallocAllocatedType(CI, TLI);
       if (MallocType && tryToOptimizeStoreOfMallocToGlobal(GV, CI, MallocType,


        


More information about the llvm-commits mailing list