From 5265ac72c6686d73edcf5de37b019b64c814d00c Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Mon, 10 Jan 2022 09:50:01 -0800 Subject: [MemoryBuiltin] Add an API for checking if an unused allocation can be removed [NFC] Not all allocation functions are removable if unused. An example of a non-removable allocation would be a direct call to the replaceable global allocation function in C++. An example of a removable one - at least according to historical practice - would be malloc. --- llvm/lib/Analysis/MemoryBuiltins.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp') diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index 213fdc5a..48c01fb 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -298,6 +298,17 @@ bool llvm::isStrdupLikeFn(const Value *V, const TargetLibraryInfo *TLI) { return getAllocationData(V, StrDupLike, TLI).hasValue(); } +bool llvm::isAllocRemovable(const CallBase *CB, const TargetLibraryInfo *TLI) { + assert(isAllocationFn(CB, TLI)); + + // Note: Removability is highly dependent on the source language. For + // example, recent C++ requires direct calls to the global allocation + // [basic.stc.dynamic.allocation] to be observable unless part of a new + // expression [expr.new paragraph 13]. + + // Historically we've treated the C family allocation routines as removable + return isAllocLikeFn(CB, TLI); +} Value *llvm::getAllocAlignment(const CallBase *V, const TargetLibraryInfo *TLI) { -- cgit v1.1