diff --git a/llvm/include/llvm/ProfileData/RawMemProfReader.h b/llvm/include/llvm/ProfileData/RawMemProfReader.h --- a/llvm/include/llvm/ProfileData/RawMemProfReader.h +++ b/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> - create(const Twine &Path, const StringRef ProfiledBinary, + create(const Twine &Path, StringRef ProfiledBinary, bool KeepName = false); + static Expected> + create(std::unique_ptr 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 --- a/llvm/lib/ProfileData/RawMemProfReader.cpp +++ b/llvm/lib/ProfileData/RawMemProfReader.cpp @@ -186,8 +186,14 @@ return report(errorCodeToError(EC), Path.getSingleStringRef()); std::unique_ptr Buffer(BufferOr.get().release()); + return create(std::move(Buffer), ProfiledBinary, KeepName); +} + +Expected> +RawMemProfReader::create(std::unique_ptr 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.