[PATCH] D155021: [memprof] Add an overload for RawMemProfReader::create.

Snehasish Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 15:06:45 PDT 2023


snehasish created this revision.
snehasish added a reviewer: tejohnson.
Herald added a subscriber: hiraditya.
Herald added a project: All.
snehasish requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This allows us to pass in a memory buffer directly simplifying usage
downstream.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155021

Files:
  llvm/include/llvm/ProfileData/RawMemProfReader.h
  llvm/lib/ProfileData/RawMemProfReader.cpp


Index: llvm/lib/ProfileData/RawMemProfReader.cpp
===================================================================
--- llvm/lib/ProfileData/RawMemProfReader.cpp
+++ llvm/lib/ProfileData/RawMemProfReader.cpp
@@ -186,8 +186,14 @@
     return report(errorCodeToError(EC), Path.getSingleStringRef());
 
   std::unique_ptr<MemoryBuffer> Buffer(BufferOr.get().release());
+  return create(std::move(Buffer), ProfiledBinary, KeepName);
+}
+
+Expected<std::unique_ptr<RawMemProfReader>>
+RawMemProfReader::create(std::unique_ptr<MemoryBuffer> Buffer,
+                         const StringRef ProfiledBinary, bool KeepName) {
   if (Error E = checkBuffer(*Buffer))
-    return report(std::move(E), Path.getSingleStringRef());
+    return report(std::move(E), Buffer->getBufferIdentifier());
 
   if (ProfiledBinary.empty()) {
     // Peek the build ids to print a helpful error message.
Index: llvm/include/llvm/ProfileData/RawMemProfReader.h
===================================================================
--- llvm/include/llvm/ProfileData/RawMemProfReader.h
+++ llvm/include/llvm/ProfileData/RawMemProfReader.h
@@ -51,10 +51,12 @@
   static bool hasFormat(const StringRef Path);
 
   // Create a RawMemProfReader after sanity checking the contents of the file at
-  // \p Path. The binary from which the profile has been collected is specified
-  // via a path in \p ProfiledBinary.
+  // \p Path or the \p Buffer. The binary from which the profile has been
+  // collected is specified via a path in \p ProfiledBinary.
   static Expected<std::unique_ptr<RawMemProfReader>>
-  create(const Twine &Path, const StringRef ProfiledBinary,
+  create(const Twine &Path, StringRef ProfiledBinary, bool KeepName = false);
+  static Expected<std::unique_ptr<RawMemProfReader>>
+  create(std::unique_ptr<MemoryBuffer> Buffer, StringRef ProfiledBinary,
          bool KeepName = false);
 
   // Returns a list of build ids recorded in the segment information.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155021.539306.patch
Type: text/x-patch
Size: 1949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230711/26ce7db8/attachment.bin>


More information about the llvm-commits mailing list