[PATCH] D153904: [instrprof] Add an overload for raw_fd_ostream.

Snehasish Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 27 11:37:54 PDT 2023


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

Add an overload for InstrProfWriter::write so that users can emit the
buffer to a string. Also use this new overload for existing unit test
usecases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153904

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


Index: llvm/lib/ProfileData/InstrProfWriter.cpp
===================================================================
--- llvm/lib/ProfileData/InstrProfWriter.cpp
+++ llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -650,12 +650,16 @@
   return writeImpl(POS);
 }
 
+Error InstrProfWriter::write(raw_string_ostream &OS) {
+  ProfOStream POS(OS);
+  return writeImpl(POS);
+}
+
 std::unique_ptr<MemoryBuffer> InstrProfWriter::writeBuffer() {
   std::string Data;
   raw_string_ostream OS(Data);
-  ProfOStream POS(OS);
   // Write the hash table.
-  if (Error E = writeImpl(POS))
+  if (Error E = write(OS))
     return nullptr;
   // Return this in an aligned memory buffer.
   return MemoryBuffer::getMemBufferCopy(Data);
Index: llvm/include/llvm/ProfileData/InstrProfWriter.h
===================================================================
--- llvm/include/llvm/ProfileData/InstrProfWriter.h
+++ llvm/include/llvm/ProfileData/InstrProfWriter.h
@@ -110,6 +110,9 @@
   /// Write the profile to \c OS
   Error write(raw_fd_ostream &OS);
 
+  /// WRite the profile to a string output stream \c OS
+  Error write(raw_string_ostream &OS);
+
   /// Write the profile in text format to \c OS
   Error writeText(raw_fd_ostream &OS);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153904.535081.patch
Type: text/x-patch
Size: 1225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230627/5ee4ecca/attachment.bin>


More information about the llvm-commits mailing list