diff options
author | Justin Bogner <mail@justinbogner.com> | 2015-02-18 01:58:17 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2015-02-18 01:58:17 +0000 |
commit | 2b6c537bdc59836f5cab71d3d01e9a061f88edbe (patch) | |
tree | 978172d89c5f58c8ae453a67e85b6d6f487bc6f2 /llvm/lib/ProfileData/InstrProfWriter.cpp | |
parent | 11042c8523ecc3f4762829af81463cd28f132f07 (diff) | |
download | bcm5719-llvm-2b6c537bdc59836f5cab71d3d01e9a061f88edbe.tar.gz bcm5719-llvm-2b6c537bdc59836f5cab71d3d01e9a061f88edbe.zip |
Re-apply "InstrProf: Add unit tests for the profile reader and writer"
Have the InstrProfWriter return a MemoryBuffer instead of a
std::string. This fixes the alignment issues the reader would hit, and
it's a more appropriate type for this anyway.
I've also removed an ugly helper function that's not needed since
we're allowing initializer lists now, and updated some error code
checks based on MSVC's issues with r229473.
This reverts r229483, reapplying r229478.
llvm-svn: 229602
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r-- | llvm/lib/ProfileData/InstrProfWriter.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index d4cde2e195d..2188543ed61 100644 --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -106,7 +106,7 @@ InstrProfWriter::addFunctionCounts(StringRef FunctionName, return instrprof_error::success; } -void InstrProfWriter::write(raw_fd_ostream &OS) { +std::pair<uint64_t, uint64_t> InstrProfWriter::writeImpl(raw_ostream &OS) { OnDiskChainedHashTableGenerator<InstrProfRecordTrait> Generator; // Populate the hash table generator. @@ -128,7 +128,32 @@ void InstrProfWriter::write(raw_fd_ostream &OS) { // Write the hash table. uint64_t HashTableStart = Generator.Emit(OS); + return std::make_pair(HashTableStartLoc, HashTableStart); +} + +void InstrProfWriter::write(raw_fd_ostream &OS) { + // Write the hash table. + auto TableStart = writeImpl(OS); + // Go back and fill in the hash table start. - OS.seek(HashTableStartLoc); - LE.write<uint64_t>(HashTableStart); + using namespace support; + OS.seek(TableStart.first); + endian::Writer<little>(OS).write<uint64_t>(TableStart.second); +} + +std::unique_ptr<MemoryBuffer> InstrProfWriter::writeBuffer() { + std::string Data; + llvm::raw_string_ostream OS(Data); + // Write the hash table. + auto TableStart = writeImpl(OS); + OS.flush(); + + // Go back and fill in the hash table start. + using namespace support; + uint64_t Bytes = endian::byte_swap<uint64_t, little>(TableStart.second); + Data.replace(TableStart.first, sizeof(uint64_t), (const char *)&Bytes, + sizeof(uint64_t)); + + // Return this in an aligned memory buffer. + return MemoryBuffer::getMemBufferCopy(Data); } |