[PATCH] D117624: [NFC] MemoryBuiltins: tease out a getFreeFunctionDataForFunction helper

Augie Fackler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 1 07:00:32 PST 2022


durin42 updated this revision to Diff 404916.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117624/new/

https://reviews.llvm.org/D117624

Files:
  llvm/lib/Analysis/MemoryBuiltins.cpp


Index: llvm/lib/Analysis/MemoryBuiltins.cpp
===================================================================
--- llvm/lib/Analysis/MemoryBuiltins.cpp
+++ llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -43,6 +43,7 @@
 #include <cassert>
 #include <cstdint>
 #include <iterator>
+#include <type_traits>
 #include <utility>
 
 using namespace llvm;
@@ -434,16 +435,22 @@
 };
 // clang-format on
 
-/// isLibFreeFunction - Returns true if the function is a builtin free()
-bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
+Optional<FreeFnsTy> getFreeFunctionDataForFunction(const Function *Callee,
+                                                   const LibFunc TLIFn) {
   const auto *Iter =
       find_if(FreeFnData, [TLIFn](const std::pair<LibFunc, FreeFnsTy> &P) {
         return P.first == TLIFn;
       });
-  if (Iter == std::end(FreeFnData)) {
+  if (Iter == std::end(FreeFnData))
+    return None;
+  return Iter->second;
+}
+
+/// isLibFreeFunction - Returns true if the function is a builtin free()
+bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
+  Optional<FreeFnsTy> FnData = getFreeFunctionDataForFunction(F, TLIFn);
+  if (!FnData.hasValue())
     return false;
-  }
-  const FreeFnsTy *FnData = &Iter->second;
 
   // Check free prototype.
   // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117624.404916.patch
Type: text/x-patch
Size: 1374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220201/f26f47a4/attachment.bin>


More information about the llvm-commits mailing list