[llvm] 4aabd19 - [instrprof] Add an overload to accept raw_string_ostream.
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 28 09:37:20 PDT 2023
Author: Snehasish Kumar
Date: 2023-06-28T16:37:15Z
New Revision: 4aabd19c06d353c319d8bbc598305cd254b6b8b8
URL: https://github.com/llvm/llvm-project/commit/4aabd19c06d353c319d8bbc598305cd254b6b8b8
DIFF: https://github.com/llvm/llvm-project/commit/4aabd19c06d353c319d8bbc598305cd254b6b8b8.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/ProfileData/InstrProfWriter.h
llvm/lib/ProfileData/InstrProfWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/InstrProfWriter.h b/llvm/include/llvm/ProfileData/InstrProfWriter.h
index 2be8c78d80edd4..e50705ee053eea 100644
--- a/llvm/include/llvm/ProfileData/InstrProfWriter.h
+++ b/llvm/include/llvm/ProfileData/InstrProfWriter.h
@@ -110,6 +110,9 @@ class InstrProfWriter {
/// 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
index 473fa35bfeec2d..09cd0960b39825 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -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);
More information about the llvm-commits
mailing list