diff options
author | Justin Bogner <mail@justinbogner.com> | 2015-02-16 23:27:48 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2015-02-16 23:27:48 +0000 |
commit | f83e895fa79af04035916597204209112c8178c6 (patch) | |
tree | 8dc2f5f54e49f80a1d7c8eb8e3d4b23594cc7c93 /llvm/lib/ProfileData/InstrProfWriter.cpp | |
parent | f25731a4b45bf9813afc7fd65cf2b220cc2a7227 (diff) | |
download | bcm5719-llvm-f83e895fa79af04035916597204209112c8178c6.tar.gz bcm5719-llvm-f83e895fa79af04035916597204209112c8178c6.zip |
InstrProf: Add unit tests for the profile reader and writer
This required some minor API to be added to these types to avoid
needing temp files.
Also, I've used initializer lists in the tests, as MSVC 2013 claims to
support them. I'll redo this without them if the bots complain.
llvm-svn: 229455
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r-- | llvm/lib/ProfileData/InstrProfWriter.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index d4cde2e195d..2c72efe3faa 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,31 @@ 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::string InstrProfWriter::writeString() { + std::string Result; + llvm::raw_string_ostream OS(Result); + // 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); + Result.replace(TableStart.first, sizeof(uint64_t), (const char *)&Bytes, + sizeof(uint64_t)); + + return Result; } |