Skip to content

Commit 4aabd19

Browse files
committed
[instrprof] Add an overload to accept raw_string_ostream.
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
1 parent e165bc2 commit 4aabd19

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

llvm/include/llvm/ProfileData/InstrProfWriter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ class InstrProfWriter {
110110
/// Write the profile to \c OS
111111
Error write(raw_fd_ostream &OS);
112112

113+
/// Write the profile to a string output stream \c OS
114+
Error write(raw_string_ostream &OS);
115+
113116
/// Write the profile in text format to \c OS
114117
Error writeText(raw_fd_ostream &OS);
115118

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,16 @@ Error InstrProfWriter::write(raw_fd_ostream &OS) {
650650
return writeImpl(POS);
651651
}
652652

653+
Error InstrProfWriter::write(raw_string_ostream &OS) {
654+
ProfOStream POS(OS);
655+
return writeImpl(POS);
656+
}
657+
653658
std::unique_ptr<MemoryBuffer> InstrProfWriter::writeBuffer() {
654659
std::string Data;
655660
raw_string_ostream OS(Data);
656-
ProfOStream POS(OS);
657661
// Write the hash table.
658-
if (Error E = writeImpl(POS))
662+
if (Error E = write(OS))
659663
return nullptr;
660664
// Return this in an aligned memory buffer.
661665
return MemoryBuffer::getMemBufferCopy(Data);

0 commit comments

Comments
 (0)