[llvm] 46e6dd8 - [MemoryBuiltins] Remove isFreeCall() function (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 21 05:46:20 PDT 2022
Author: Nikita Popov
Date: 2022-07-21T14:44:23+02:00
New Revision: 46e6dd84b778dd2e30368183fec265beceecdd0f
URL: https://github.com/llvm/llvm-project/commit/46e6dd84b778dd2e30368183fec265beceecdd0f
DIFF: https://github.com/llvm/llvm-project/commit/46e6dd84b778dd2e30368183fec265beceecdd0f.diff
LOG: [MemoryBuiltins] Remove isFreeCall() function (NFC)
Remove isFreeCall() in favor of getFreedOperand(). Replace the
two remaining uses with a getFreedOperand() != nullptr check, as
they only care that something is getting freed. (The usage in DSE
is correct as such. The allocator-related checks in CFLGraph look
rather questionable in general.)
Added:
Modified:
llvm/include/llvm/Analysis/MemoryBuiltins.h
llvm/lib/Analysis/CFLGraph.h
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/MemoryBuiltins.h b/llvm/include/llvm/Analysis/MemoryBuiltins.h
index 81591e653363..29b0cea66728 100644
--- a/llvm/include/llvm/Analysis/MemoryBuiltins.h
+++ b/llvm/include/llvm/Analysis/MemoryBuiltins.h
@@ -80,9 +80,6 @@ bool isReallocLikeFn(const Function *F, const TargetLibraryInfo *TLI);
/// isLibFreeFunction - Returns true if the function is a builtin free()
bool isLibFreeFunction(const Function *F, const LibFunc TLIFn);
-/// Returns true if the value is a call to a free function.
-bool isFreeCall(const Value *I, const TargetLibraryInfo *TLI);
-
/// If this if a call to a free function, return the freed operand.
Value *getFreedOperand(const CallBase *CB, const TargetLibraryInfo *TLI);
diff --git a/llvm/lib/Analysis/CFLGraph.h b/llvm/lib/Analysis/CFLGraph.h
index 60fc8d18678c..47bb02ac8e8b 100644
--- a/llvm/lib/Analysis/CFLGraph.h
+++ b/llvm/lib/Analysis/CFLGraph.h
@@ -434,7 +434,8 @@ template <typename CFLAA> class CFLGraphBuilder {
// introduce any aliases.
// TODO: address other common library functions such as realloc(),
// strdup(), etc.
- if (isMallocOrCallocLikeFn(&Call, &TLI) || isFreeCall(&Call, &TLI))
+ if (isMallocOrCallocLikeFn(&Call, &TLI) ||
+ getFreedOperand(&Call, &TLI) != nullptr)
return;
// TODO: Add support for noalias args/all the other fun function
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 0ea0b9fe8b1c..b9e73c2b0388 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -531,23 +531,19 @@ bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
return true;
}
-bool llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
+Value *llvm::getFreedOperand(const CallBase *CB, const TargetLibraryInfo *TLI) {
bool IsNoBuiltinCall;
- const Function *Callee = getCalledFunction(I, IsNoBuiltinCall);
+ const Function *Callee = getCalledFunction(CB, IsNoBuiltinCall);
if (Callee == nullptr || IsNoBuiltinCall)
- return false;
+ return nullptr;
LibFunc TLIFn;
- if (!TLI || !TLI->getLibFunc(*Callee, TLIFn) || !TLI->has(TLIFn))
- return false;
-
- return isLibFreeFunction(Callee, TLIFn);
-}
-
-Value *llvm::getFreedOperand(const CallBase *CB, const TargetLibraryInfo *TLI) {
- // All currently supported free functions free the first argument.
- if (isFreeCall(CB, TLI))
+ if (TLI && TLI->getLibFunc(*Callee, TLIFn) && TLI->has(TLIFn) &&
+ isLibFreeFunction(Callee, TLIFn)) {
+ // All currently supported free functions free the first argument.
return CB->getArgOperand(0);
+ }
+
return nullptr;
}
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index c675291688aa..3f0dad7ee769 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1118,9 +1118,9 @@ struct DSEState {
/// Returns true if \p I is a memory terminator instruction like
/// llvm.lifetime.end or free.
bool isMemTerminatorInst(Instruction *I) const {
- IntrinsicInst *II = dyn_cast<IntrinsicInst>(I);
- return (II && II->getIntrinsicID() == Intrinsic::lifetime_end) ||
- isFreeCall(I, &TLI);
+ auto *CB = dyn_cast<CallBase>(I);
+ return CB && (CB->getIntrinsicID() == Intrinsic::lifetime_end ||
+ getFreedOperand(CB, &TLI) != nullptr);
}
/// Returns true if \p MaybeTerm is a memory terminator for \p Loc from
More information about the llvm-commits
mailing list