diff --git a/llvm/include/llvm/ProfileData/InstrProfWriter.h b/llvm/include/llvm/ProfileData/InstrProfWriter.h --- a/llvm/include/llvm/ProfileData/InstrProfWriter.h +++ b/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); diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/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 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);