aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/InstrProfWriter.cpp
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2015-10-18 01:02:29 +0000
committerXinliang David Li <davidxl@google.com>2015-10-18 01:02:29 +0000
commitdab183ed40249328531acd424b5c512f86eca77d (patch)
tree06dda7b4eb6d82a69c6bc316acd30d7f28b13a6a /llvm/lib/ProfileData/InstrProfWriter.cpp
parentb8d27aab7d67b214ccfd68d12b8f187adcb103de (diff)
downloadllvm-dab183ed40249328531acd424b5c512f86eca77d.zip
llvm-dab183ed40249328531acd424b5c512f86eca77d.tar.gz
llvm-dab183ed40249328531acd424b5c512f86eca77d.tar.bz2
Minor Instr PGO code restructuring
1. Key constant values (version, magic) and data structures related to raw and indexed profile format are moved into one centralized file: InstrProf.h. 2. Utility function such as MD5Hash computation is also moved to the common header to allow sharing with other components in the future. 3. A header data structure is introduced for Indexed format so that the reader and writer can always be in sync. 4. Added some comments to document different places where multiple definition of the data structure must be kept in sync (reader/writer, runtime, lowering etc). No functional change is intended. Differential Revision: http://reviews.llvm.org/D13758 llvm-svn: 250638
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r--llvm/lib/ProfileData/InstrProfWriter.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 856194d7..e3018a9 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/ProfileData/InstrProfWriter.h"
-#include "InstrProfIndexed.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/EndianStream.h"
#include "llvm/Support/OnDiskHashTable.h"
@@ -197,13 +196,23 @@ std::pair<uint64_t, uint64_t> InstrProfWriter::writeImpl(raw_ostream &OS) {
endian::Writer<little> LE(OS);
// Write the header.
- LE.write<uint64_t>(IndexedInstrProf::Magic);
- LE.write<uint64_t>(IndexedInstrProf::Version);
- LE.write<uint64_t>(MaxFunctionCount);
- LE.write<uint64_t>(static_cast<uint64_t>(IndexedInstrProf::HashType));
+ IndexedInstrProf::Header Header;
+ Header.Magic = IndexedInstrProf::Magic;
+ Header.Version = IndexedInstrProf::Version;
+ Header.MaxFunctionCount = MaxFunctionCount;
+ Header.HashType = static_cast<uint64_t>(IndexedInstrProf::HashType);
+ Header.HashOffset = 0;
+ int N = sizeof(IndexedInstrProf::Header) / sizeof(uint64_t);
+
+ // Only write out all the fields execpt 'HashOffset'. We need
+ // to remember the offset of that field to allow back patching
+ // later.
+ for (int I = 0; I < N - 1; I++)
+ LE.write<uint64_t>(reinterpret_cast<uint64_t *>(&Header)[I]);
// Save a space to write the hash table start location.
uint64_t HashTableStartLoc = OS.tell();
+ // Reserve the space for HashOffset field.
LE.write<uint64_t>(0);
// Write the hash table.
uint64_t HashTableStart = Generator.Emit(OS);
@@ -218,6 +227,7 @@ void InstrProfWriter::write(raw_fd_ostream &OS) {
// Go back and fill in the hash table start.
using namespace support;
OS.seek(TableStart.first);
+ // Now patch the HashOffset field previously reserved.
endian::Writer<little>(OS).write<uint64_t>(TableStart.second);
}