[llvm] a1383db - [memprof] Add an overload for RawMemProfReader::create.

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 16:05:09 PDT 2023


Author: Snehasish Kumar
Date: 2023-07-11T23:05:04Z
New Revision: a1383db75561fd96d1c196b09655ffd5a705bae7

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

LOG: [memprof] Add an overload for RawMemProfReader::create.

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

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D155021

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/RawMemProfReader.h b/llvm/include/llvm/ProfileData/RawMemProfReader.h
index 63bf819225dc71..4141cfb42e0d96 100644
--- a/llvm/include/llvm/ProfileData/RawMemProfReader.h
+++ b/llvm/include/llvm/ProfileData/RawMemProfReader.h
@@ -51,10 +51,12 @@ class RawMemProfReader {
   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.

diff  --git a/llvm/lib/ProfileData/RawMemProfReader.cpp b/llvm/lib/ProfileData/RawMemProfReader.cpp
index dbfb472f211ed8..d247a0fd6f6911 100644
--- a/llvm/lib/ProfileData/RawMemProfReader.cpp
+++ b/llvm/lib/ProfileData/RawMemProfReader.cpp
@@ -186,8 +186,14 @@ RawMemProfReader::create(const Twine &Path, const StringRef ProfiledBinary,
     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.


        


More information about the llvm-commits mailing list