[instrprof] Add an overload to accept raw_string_ostream.
authorSnehasish Kumar <snehasishk@google.com>
Tue, 27 Jun 2023 18:26:57 +0000 (18:26 +0000)
committerSnehasish Kumar <snehasishk@google.com>
Wed, 28 Jun 2023 16:37:15 +0000 (16:37 +0000)
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.

Reviewed By: tejohnson

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

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

index 2be8c78..e50705e 100644 (file)
@@ -110,6 +110,9 @@ public:
   /// 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);
 
index 473fa35..09cd096 100644 (file)
@@ -650,12 +650,16 @@ Error InstrProfWriter::write(raw_fd_ostream &OS) {
   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);