24 class InstrProfRecordTrait {
32 typedef uint64_t hash_value_type;
35 static hash_value_type
ComputeHash(key_type_ref K) {
39 static std::pair<offset_type, offset_type>
40 EmitKeyDataLength(
raw_ostream &Out, key_type_ref K, data_type_ref V) {
41 using namespace llvm::support;
48 for (
const auto &Counts : *V)
49 M += (2 + Counts.second.size()) *
sizeof(uint64_t);
52 return std::make_pair(
N, M);
59 static void EmitData(
raw_ostream &Out, key_type_ref, data_type_ref V,
61 using namespace llvm::support;
64 for (
const auto &Counts : *V) {
65 LE.write<uint64_t>(Counts.first);
66 LE.write<uint64_t>(Counts.second.size());
67 for (uint64_t
I : Counts.second)
68 LE.write<uint64_t>(
I);
76 uint64_t FunctionHash,
85 if (Counters[0] > MaxFunctionCount)
86 MaxFunctionCount = Counters[0];
91 auto &FoundCounters = Where->second;
94 if (FoundCounters.size() != Counters.
size())
97 for (
size_t I = 0, E = Counters.
size();
I < E; ++
I) {
98 if (FoundCounters[
I] + Counters[
I] < FoundCounters[
I])
100 FoundCounters[
I] += Counters[
I];
103 if (FoundCounters[0] > MaxFunctionCount)
104 MaxFunctionCount = FoundCounters[0];
109 std::pair<uint64_t, uint64_t> InstrProfWriter::writeImpl(
raw_ostream &OS) {
113 for (
const auto &
I : FunctionData)
114 Generator.insert(
I.getKey(), &
I.getValue());
116 using namespace llvm::support;
122 LE.write<uint64_t>(MaxFunctionCount);
126 uint64_t HashTableStartLoc = OS.
tell();
127 LE.write<uint64_t>(0);
129 uint64_t HashTableStart = Generator.
Emit(OS);
131 return std::make_pair(HashTableStartLoc, HashTableStart);
136 auto TableStart = writeImpl(OS);
139 using namespace support;
140 OS.
seek(TableStart.first);
148 auto TableStart = writeImpl(OS);
152 using namespace support;
153 uint64_t Bytes = endian::byte_swap<uint64_t, little>(TableStart.second);
154 Data.replace(TableStart.first,
sizeof(uint64_t), (
const char *)&Bytes,
Defines facilities for reading and writing on-disk hash tables.
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
InstrProfLookupTrait::data_type data_type
InstrProfLookupTrait::offset_type offset_type
uint64_t tell() const
tell - Return the current offset with the file.
size_t size() const
size - Get the array size.
raw_ostream & write(unsigned char C)
offset_type Emit(raw_ostream &Out)
Emit the table to Out, which must not be at offset 0.
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it...
Generates an on disk hash table.
Adapter to write values to a stream in a particular byte order.
A raw_ostream that writes to a file descriptor.
static uint64_t ComputeHash(HashT Type, StringRef K)
iterator find(const KeyT &Val)
std::error_code addFunctionCounts(StringRef FunctionName, uint64_t FunctionHash, ArrayRef< uint64_t > Counters)
Add function counts for the given function.
A raw_ostream that writes to an std::string.
void write(raw_fd_ostream &OS)
Write the profile to OS.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
std::unique_ptr< MemoryBuffer > writeBuffer()
Write the profile, returning the raw data. For testing.