2014-03-22 01:24:48 +08:00
|
|
|
//=-- InstrProfReader.cpp - Instrumented profiling reader -------------------=//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains support for reading profiling data for clang's
|
|
|
|
// instrumentation based PGO and coverage.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/ProfileData/InstrProfReader.h"
|
2015-03-02 05:28:53 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2014-03-22 01:24:48 +08:00
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-11-03 08:51:45 +08:00
|
|
|
static ErrorOr<std::unique_ptr<MemoryBuffer>>
|
|
|
|
setupMemoryBuffer(std::string Path) {
|
2014-07-07 01:43:13 +08:00
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
|
|
|
|
MemoryBuffer::getFileOrSTDIN(Path);
|
|
|
|
if (std::error_code EC = BufferOrErr.getError())
|
2014-03-22 01:24:48 +08:00
|
|
|
return EC;
|
2015-02-18 09:58:17 +08:00
|
|
|
return std::move(BufferOrErr.get());
|
2014-04-19 05:48:40 +08:00
|
|
|
}
|
|
|
|
|
2014-06-13 10:24:39 +08:00
|
|
|
static std::error_code initializeReader(InstrProfReader &Reader) {
|
2014-04-19 05:48:40 +08:00
|
|
|
return Reader.readHeader();
|
|
|
|
}
|
|
|
|
|
2014-11-03 08:51:45 +08:00
|
|
|
ErrorOr<std::unique_ptr<InstrProfReader>>
|
|
|
|
InstrProfReader::create(std::string Path) {
|
2014-04-19 05:48:40 +08:00
|
|
|
// Set up the buffer to read.
|
2014-11-03 08:51:45 +08:00
|
|
|
auto BufferOrError = setupMemoryBuffer(Path);
|
|
|
|
if (std::error_code EC = BufferOrError.getError())
|
2014-04-19 05:48:40 +08:00
|
|
|
return EC;
|
2015-02-18 09:58:17 +08:00
|
|
|
return InstrProfReader::create(std::move(BufferOrError.get()));
|
|
|
|
}
|
2015-02-17 07:31:07 +08:00
|
|
|
|
2015-02-18 09:58:17 +08:00
|
|
|
ErrorOr<std::unique_ptr<InstrProfReader>>
|
|
|
|
InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
|
|
|
|
// Sanity check the buffer.
|
|
|
|
if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
|
|
|
|
return instrprof_error::too_large;
|
2015-02-17 17:21:43 +08:00
|
|
|
|
2015-02-18 09:58:17 +08:00
|
|
|
std::unique_ptr<InstrProfReader> Result;
|
2014-03-22 04:42:31 +08:00
|
|
|
// Create the reader.
|
2014-04-19 05:48:40 +08:00
|
|
|
if (IndexedInstrProfReader::hasFormat(*Buffer))
|
|
|
|
Result.reset(new IndexedInstrProfReader(std::move(Buffer)));
|
|
|
|
else if (RawInstrProfReader64::hasFormat(*Buffer))
|
2014-03-23 11:38:12 +08:00
|
|
|
Result.reset(new RawInstrProfReader64(std::move(Buffer)));
|
|
|
|
else if (RawInstrProfReader32::hasFormat(*Buffer))
|
|
|
|
Result.reset(new RawInstrProfReader32(std::move(Buffer)));
|
2015-11-13 11:47:58 +08:00
|
|
|
else if (TextInstrProfReader::hasFormat(*Buffer))
|
2015-11-13 02:39:26 +08:00
|
|
|
Result.reset(new TextInstrProfReader(std::move(Buffer)));
|
2015-11-13 11:47:58 +08:00
|
|
|
else
|
|
|
|
return instrprof_error::unrecognized_format;
|
2014-03-22 04:42:31 +08:00
|
|
|
|
2014-04-19 05:48:40 +08:00
|
|
|
// Initialize the reader and return the result.
|
2014-11-03 08:51:45 +08:00
|
|
|
if (std::error_code EC = initializeReader(*Result))
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
return std::move(Result);
|
2014-04-19 05:48:40 +08:00
|
|
|
}
|
|
|
|
|
2015-02-17 05:28:58 +08:00
|
|
|
ErrorOr<std::unique_ptr<IndexedInstrProfReader>>
|
|
|
|
IndexedInstrProfReader::create(std::string Path) {
|
2014-04-19 05:48:40 +08:00
|
|
|
// Set up the buffer to read.
|
2014-11-03 08:51:45 +08:00
|
|
|
auto BufferOrError = setupMemoryBuffer(Path);
|
|
|
|
if (std::error_code EC = BufferOrError.getError())
|
2014-04-19 05:48:40 +08:00
|
|
|
return EC;
|
2015-02-18 09:58:17 +08:00
|
|
|
return IndexedInstrProfReader::create(std::move(BufferOrError.get()));
|
|
|
|
}
|
|
|
|
|
2014-04-19 05:48:40 +08:00
|
|
|
|
2015-02-18 09:58:17 +08:00
|
|
|
ErrorOr<std::unique_ptr<IndexedInstrProfReader>>
|
|
|
|
IndexedInstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
|
|
|
|
// Sanity check the buffer.
|
|
|
|
if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
|
|
|
|
return instrprof_error::too_large;
|
2015-02-17 05:28:58 +08:00
|
|
|
|
2014-04-19 05:48:40 +08:00
|
|
|
// Create the reader.
|
|
|
|
if (!IndexedInstrProfReader::hasFormat(*Buffer))
|
|
|
|
return instrprof_error::bad_magic;
|
2015-02-18 09:58:17 +08:00
|
|
|
auto Result = llvm::make_unique<IndexedInstrProfReader>(std::move(Buffer));
|
2014-04-19 05:48:40 +08:00
|
|
|
|
|
|
|
// Initialize the reader and return the result.
|
2015-02-17 05:28:58 +08:00
|
|
|
if (std::error_code EC = initializeReader(*Result))
|
|
|
|
return EC;
|
|
|
|
|
|
|
|
return std::move(Result);
|
2014-03-22 01:24:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void InstrProfIterator::Increment() {
|
|
|
|
if (Reader->readNextRecord(Record))
|
|
|
|
*this = InstrProfIterator();
|
|
|
|
}
|
|
|
|
|
2015-11-13 11:47:58 +08:00
|
|
|
bool TextInstrProfReader::hasFormat(const MemoryBuffer &Buffer) {
|
|
|
|
// Verify that this really looks like plain ASCII text by checking a
|
|
|
|
// 'reasonable' number of characters (up to profile magic size).
|
|
|
|
size_t count = std::min(Buffer.getBufferSize(), sizeof(uint64_t));
|
|
|
|
StringRef buffer = Buffer.getBufferStart();
|
2015-12-11 08:40:05 +08:00
|
|
|
return count == 0 ||
|
|
|
|
std::all_of(buffer.begin(), buffer.begin() + count,
|
|
|
|
[](char c) { return ::isprint(c) || ::isspace(c); });
|
2015-11-13 11:47:58 +08:00
|
|
|
}
|
|
|
|
|
2016-02-11 01:18:30 +08:00
|
|
|
// Read the profile variant flag from the header: ":FE" means this is a FE
|
|
|
|
// generated profile. ":IR" means this is an IR level profile. Other strings
|
|
|
|
// with a leading ':' will be reported an error format.
|
2015-12-20 14:22:13 +08:00
|
|
|
std::error_code TextInstrProfReader::readHeader() {
|
|
|
|
Symtab.reset(new InstrProfSymtab());
|
2016-02-11 01:18:30 +08:00
|
|
|
bool IsIRInstr = false;
|
|
|
|
if (!Line->startswith(":")) {
|
|
|
|
IsIRLevelProfile = false;
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
StringRef Str = (Line)->substr(1);
|
|
|
|
if (Str.equals_lower("ir"))
|
|
|
|
IsIRInstr = true;
|
|
|
|
else if (Str.equals_lower("fe"))
|
|
|
|
IsIRInstr = false;
|
|
|
|
else
|
|
|
|
return instrprof_error::bad_header;
|
|
|
|
|
|
|
|
++Line;
|
|
|
|
IsIRLevelProfile = IsIRInstr;
|
2015-12-20 14:22:13 +08:00
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2015-12-15 02:44:01 +08:00
|
|
|
std::error_code
|
|
|
|
TextInstrProfReader::readValueProfileData(InstrProfRecord &Record) {
|
|
|
|
|
|
|
|
#define CHECK_LINE_END(Line) \
|
|
|
|
if (Line.is_at_end()) \
|
|
|
|
return error(instrprof_error::truncated);
|
|
|
|
#define READ_NUM(Str, Dst) \
|
|
|
|
if ((Str).getAsInteger(10, (Dst))) \
|
|
|
|
return error(instrprof_error::malformed);
|
|
|
|
#define VP_READ_ADVANCE(Val) \
|
|
|
|
CHECK_LINE_END(Line); \
|
|
|
|
uint32_t Val; \
|
|
|
|
READ_NUM((*Line), (Val)); \
|
|
|
|
Line++;
|
|
|
|
|
|
|
|
if (Line.is_at_end())
|
|
|
|
return success();
|
2015-12-20 14:22:13 +08:00
|
|
|
|
2015-12-15 02:44:01 +08:00
|
|
|
uint32_t NumValueKinds;
|
|
|
|
if (Line->getAsInteger(10, NumValueKinds)) {
|
|
|
|
// No value profile data
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
if (NumValueKinds == 0 || NumValueKinds > IPVK_Last + 1)
|
|
|
|
return error(instrprof_error::malformed);
|
|
|
|
Line++;
|
|
|
|
|
|
|
|
for (uint32_t VK = 0; VK < NumValueKinds; VK++) {
|
|
|
|
VP_READ_ADVANCE(ValueKind);
|
|
|
|
if (ValueKind > IPVK_Last)
|
|
|
|
return error(instrprof_error::malformed);
|
|
|
|
VP_READ_ADVANCE(NumValueSites);
|
|
|
|
if (!NumValueSites)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Record.reserveSites(VK, NumValueSites);
|
|
|
|
for (uint32_t S = 0; S < NumValueSites; S++) {
|
|
|
|
VP_READ_ADVANCE(NumValueData);
|
|
|
|
|
|
|
|
std::vector<InstrProfValueData> CurrentValues;
|
|
|
|
for (uint32_t V = 0; V < NumValueData; V++) {
|
|
|
|
CHECK_LINE_END(Line);
|
|
|
|
std::pair<StringRef, StringRef> VD = Line->split(':');
|
|
|
|
uint64_t TakenCount, Value;
|
2015-12-20 14:22:13 +08:00
|
|
|
if (VK == IPVK_IndirectCallTarget) {
|
|
|
|
Symtab->addFuncName(VD.first);
|
|
|
|
Value = IndexedInstrProf::ComputeHash(VD.first);
|
|
|
|
} else {
|
2015-12-15 02:44:01 +08:00
|
|
|
READ_NUM(VD.first, Value);
|
|
|
|
}
|
2015-12-20 14:22:13 +08:00
|
|
|
READ_NUM(VD.second, TakenCount);
|
2015-12-15 02:44:01 +08:00
|
|
|
CurrentValues.push_back({Value, TakenCount});
|
|
|
|
Line++;
|
|
|
|
}
|
|
|
|
Record.addValueData(VK, S, CurrentValues.data(), NumValueData, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return success();
|
|
|
|
|
|
|
|
#undef CHECK_LINE_END
|
|
|
|
#undef READ_NUM
|
|
|
|
#undef VP_READ_ADVANCE
|
|
|
|
}
|
|
|
|
|
2014-06-13 10:24:39 +08:00
|
|
|
std::error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {
|
2014-07-30 06:29:23 +08:00
|
|
|
// Skip empty lines and comments.
|
|
|
|
while (!Line.is_at_end() && (Line->empty() || Line->startswith("#")))
|
2014-03-22 01:24:48 +08:00
|
|
|
++Line;
|
|
|
|
// If we hit EOF while looking for a name, we're done.
|
2015-12-20 14:22:13 +08:00
|
|
|
if (Line.is_at_end()) {
|
|
|
|
Symtab->finalizeSymtab();
|
2014-03-22 01:24:48 +08:00
|
|
|
return error(instrprof_error::eof);
|
2015-12-20 14:22:13 +08:00
|
|
|
}
|
2014-03-22 01:24:48 +08:00
|
|
|
|
|
|
|
// Read the function name.
|
|
|
|
Record.Name = *Line++;
|
2015-12-20 14:22:13 +08:00
|
|
|
Symtab->addFuncName(Record.Name);
|
2014-03-22 01:24:48 +08:00
|
|
|
|
|
|
|
// Read the function hash.
|
|
|
|
if (Line.is_at_end())
|
|
|
|
return error(instrprof_error::truncated);
|
2015-03-10 02:54:49 +08:00
|
|
|
if ((Line++)->getAsInteger(0, Record.Hash))
|
2014-03-22 01:24:48 +08:00
|
|
|
return error(instrprof_error::malformed);
|
|
|
|
|
|
|
|
// Read the number of counters.
|
|
|
|
uint64_t NumCounters;
|
|
|
|
if (Line.is_at_end())
|
|
|
|
return error(instrprof_error::truncated);
|
|
|
|
if ((Line++)->getAsInteger(10, NumCounters))
|
|
|
|
return error(instrprof_error::malformed);
|
2014-04-25 10:45:33 +08:00
|
|
|
if (NumCounters == 0)
|
|
|
|
return error(instrprof_error::malformed);
|
2014-03-22 01:24:48 +08:00
|
|
|
|
|
|
|
// Read each counter and fill our internal storage with the values.
|
2015-06-23 07:58:05 +08:00
|
|
|
Record.Counts.clear();
|
|
|
|
Record.Counts.reserve(NumCounters);
|
2014-03-22 01:24:48 +08:00
|
|
|
for (uint64_t I = 0; I < NumCounters; ++I) {
|
|
|
|
if (Line.is_at_end())
|
|
|
|
return error(instrprof_error::truncated);
|
|
|
|
uint64_t Count;
|
|
|
|
if ((Line++)->getAsInteger(10, Count))
|
|
|
|
return error(instrprof_error::malformed);
|
2015-06-23 07:58:05 +08:00
|
|
|
Record.Counts.push_back(Count);
|
2014-03-22 01:24:48 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 02:44:01 +08:00
|
|
|
// Check if value profile data exists and read it if so.
|
|
|
|
if (std::error_code EC = readValueProfileData(Record))
|
|
|
|
return EC;
|
|
|
|
|
2015-12-20 14:22:13 +08:00
|
|
|
// This is needed to avoid two pass parsing because llvm-profdata
|
|
|
|
// does dumping while reading.
|
|
|
|
Symtab->finalizeSymtab();
|
2014-03-22 01:24:48 +08:00
|
|
|
return success();
|
|
|
|
}
|
2014-03-22 02:26:05 +08:00
|
|
|
|
2014-03-23 11:38:12 +08:00
|
|
|
template <class IntPtrT>
|
|
|
|
bool RawInstrProfReader<IntPtrT>::hasFormat(const MemoryBuffer &DataBuffer) {
|
2014-03-24 08:47:18 +08:00
|
|
|
if (DataBuffer.getBufferSize() < sizeof(uint64_t))
|
2014-03-22 04:42:31 +08:00
|
|
|
return false;
|
2014-03-24 08:47:18 +08:00
|
|
|
uint64_t Magic =
|
|
|
|
*reinterpret_cast<const uint64_t *>(DataBuffer.getBufferStart());
|
2015-10-18 09:02:29 +08:00
|
|
|
return RawInstrProf::getMagic<IntPtrT>() == Magic ||
|
|
|
|
sys::getSwappedBytes(RawInstrProf::getMagic<IntPtrT>()) == Magic;
|
2014-03-22 04:42:31 +08:00
|
|
|
}
|
|
|
|
|
2014-03-23 11:38:12 +08:00
|
|
|
template <class IntPtrT>
|
2014-06-13 10:24:39 +08:00
|
|
|
std::error_code RawInstrProfReader<IntPtrT>::readHeader() {
|
2014-03-22 04:42:31 +08:00
|
|
|
if (!hasFormat(*DataBuffer))
|
|
|
|
return error(instrprof_error::bad_magic);
|
2015-10-18 09:02:29 +08:00
|
|
|
if (DataBuffer->getBufferSize() < sizeof(RawInstrProf::Header))
|
2014-03-22 04:42:28 +08:00
|
|
|
return error(instrprof_error::bad_header);
|
2015-10-18 09:02:29 +08:00
|
|
|
auto *Header = reinterpret_cast<const RawInstrProf::Header *>(
|
|
|
|
DataBuffer->getBufferStart());
|
|
|
|
ShouldSwapBytes = Header->Magic != RawInstrProf::getMagic<IntPtrT>();
|
2014-03-22 02:26:05 +08:00
|
|
|
return readHeader(*Header);
|
|
|
|
}
|
|
|
|
|
2014-05-16 08:38:00 +08:00
|
|
|
template <class IntPtrT>
|
2014-06-13 10:24:39 +08:00
|
|
|
std::error_code
|
|
|
|
RawInstrProfReader<IntPtrT>::readNextHeader(const char *CurrentPos) {
|
2014-05-16 08:38:00 +08:00
|
|
|
const char *End = DataBuffer->getBufferEnd();
|
|
|
|
// Skip zero padding between profiles.
|
|
|
|
while (CurrentPos != End && *CurrentPos == 0)
|
|
|
|
++CurrentPos;
|
|
|
|
// If there's nothing left, we're done.
|
|
|
|
if (CurrentPos == End)
|
|
|
|
return instrprof_error::eof;
|
|
|
|
// If there isn't enough space for another header, this is probably just
|
|
|
|
// garbage at the end of the file.
|
2015-10-18 09:02:29 +08:00
|
|
|
if (CurrentPos + sizeof(RawInstrProf::Header) > End)
|
2014-05-16 08:38:00 +08:00
|
|
|
return instrprof_error::malformed;
|
2014-09-13 05:22:55 +08:00
|
|
|
// The writer ensures each profile is padded to start at an aligned address.
|
|
|
|
if (reinterpret_cast<size_t>(CurrentPos) % alignOf<uint64_t>())
|
|
|
|
return instrprof_error::malformed;
|
2014-05-16 08:38:00 +08:00
|
|
|
// The magic should have the same byte order as in the previous header.
|
|
|
|
uint64_t Magic = *reinterpret_cast<const uint64_t *>(CurrentPos);
|
2015-10-18 09:02:29 +08:00
|
|
|
if (Magic != swap(RawInstrProf::getMagic<IntPtrT>()))
|
2014-05-16 08:38:00 +08:00
|
|
|
return instrprof_error::bad_magic;
|
|
|
|
|
|
|
|
// There's another profile to read, so we need to process the header.
|
2015-10-18 09:02:29 +08:00
|
|
|
auto *Header = reinterpret_cast<const RawInstrProf::Header *>(CurrentPos);
|
2014-05-16 08:38:00 +08:00
|
|
|
return readHeader(*Header);
|
|
|
|
}
|
|
|
|
|
2014-03-23 11:38:12 +08:00
|
|
|
template <class IntPtrT>
|
2015-12-20 14:22:13 +08:00
|
|
|
void RawInstrProfReader<IntPtrT>::createSymtab(InstrProfSymtab &Symtab) {
|
2016-02-09 02:13:49 +08:00
|
|
|
Symtab.create(StringRef(NamesStart, NamesSize));
|
2015-12-20 14:22:13 +08:00
|
|
|
for (const RawInstrProf::ProfileData<IntPtrT> *I = Data; I != DataEnd; ++I) {
|
|
|
|
const IntPtrT FPtr = swap(I->FunctionPointer);
|
|
|
|
if (!FPtr)
|
|
|
|
continue;
|
2016-02-09 02:13:49 +08:00
|
|
|
Symtab.mapAddress(FPtr, I->NameRef);
|
2015-12-20 14:22:13 +08:00
|
|
|
}
|
|
|
|
Symtab.finalizeSymtab();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class IntPtrT>
|
|
|
|
std::error_code
|
|
|
|
RawInstrProfReader<IntPtrT>::readHeader(const RawInstrProf::Header &Header) {
|
2016-02-11 01:18:30 +08:00
|
|
|
Version = swap(Header.Version);
|
|
|
|
if (GET_VERSION(Version) != RawInstrProf::Version)
|
2014-03-22 02:26:05 +08:00
|
|
|
return error(instrprof_error::unsupported_version);
|
|
|
|
|
|
|
|
CountersDelta = swap(Header.CountersDelta);
|
|
|
|
NamesDelta = swap(Header.NamesDelta);
|
|
|
|
auto DataSize = swap(Header.DataSize);
|
|
|
|
auto CountersSize = swap(Header.CountersSize);
|
2016-02-09 02:13:49 +08:00
|
|
|
NamesSize = swap(Header.NamesSize);
|
2015-11-19 02:14:55 +08:00
|
|
|
auto ValueDataSize = swap(Header.ValueDataSize);
|
|
|
|
ValueKindLast = swap(Header.ValueKindLast);
|
|
|
|
|
|
|
|
auto DataSizeInBytes = DataSize * sizeof(RawInstrProf::ProfileData<IntPtrT>);
|
|
|
|
auto PaddingSize = getNumPaddingBytes(NamesSize);
|
2014-03-22 02:26:05 +08:00
|
|
|
|
2015-10-18 09:02:29 +08:00
|
|
|
ptrdiff_t DataOffset = sizeof(RawInstrProf::Header);
|
2015-11-19 02:14:55 +08:00
|
|
|
ptrdiff_t CountersOffset = DataOffset + DataSizeInBytes;
|
2014-03-22 02:26:05 +08:00
|
|
|
ptrdiff_t NamesOffset = CountersOffset + sizeof(uint64_t) * CountersSize;
|
2015-11-19 02:14:55 +08:00
|
|
|
ptrdiff_t ValueDataOffset = NamesOffset + NamesSize + PaddingSize;
|
|
|
|
size_t ProfileSize = ValueDataOffset + ValueDataSize;
|
2014-03-22 02:26:05 +08:00
|
|
|
|
2014-05-16 08:38:00 +08:00
|
|
|
auto *Start = reinterpret_cast<const char *>(&Header);
|
|
|
|
if (Start + ProfileSize > DataBuffer->getBufferEnd())
|
2014-03-22 04:42:28 +08:00
|
|
|
return error(instrprof_error::bad_header);
|
2014-03-22 02:26:05 +08:00
|
|
|
|
2015-10-18 09:02:29 +08:00
|
|
|
Data = reinterpret_cast<const RawInstrProf::ProfileData<IntPtrT> *>(
|
|
|
|
Start + DataOffset);
|
2014-03-22 02:26:05 +08:00
|
|
|
DataEnd = Data + DataSize;
|
2014-03-24 08:47:18 +08:00
|
|
|
CountersStart = reinterpret_cast<const uint64_t *>(Start + CountersOffset);
|
|
|
|
NamesStart = Start + NamesOffset;
|
2015-12-20 14:22:13 +08:00
|
|
|
ValueDataStart = reinterpret_cast<const uint8_t *>(Start + ValueDataOffset);
|
2014-05-16 08:38:00 +08:00
|
|
|
ProfileEnd = Start + ProfileSize;
|
2014-03-22 02:26:05 +08:00
|
|
|
|
2015-12-20 14:22:13 +08:00
|
|
|
std::unique_ptr<InstrProfSymtab> NewSymtab = make_unique<InstrProfSymtab>();
|
|
|
|
createSymtab(*NewSymtab.get());
|
|
|
|
Symtab = std::move(NewSymtab);
|
2014-03-22 02:26:05 +08:00
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2014-03-23 11:38:12 +08:00
|
|
|
template <class IntPtrT>
|
2015-10-29 03:34:04 +08:00
|
|
|
std::error_code RawInstrProfReader<IntPtrT>::readName(InstrProfRecord &Record) {
|
2016-02-09 02:13:49 +08:00
|
|
|
Record.Name = getName(Data->NameRef);
|
2015-10-29 03:34:04 +08:00
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class IntPtrT>
|
|
|
|
std::error_code RawInstrProfReader<IntPtrT>::readFuncHash(
|
|
|
|
InstrProfRecord &Record) {
|
|
|
|
Record.Hash = swap(Data->FuncHash);
|
|
|
|
return success();
|
|
|
|
}
|
2014-03-22 02:26:05 +08:00
|
|
|
|
2015-10-29 03:34:04 +08:00
|
|
|
template <class IntPtrT>
|
|
|
|
std::error_code RawInstrProfReader<IntPtrT>::readRawCounts(
|
|
|
|
InstrProfRecord &Record) {
|
2014-04-25 10:45:33 +08:00
|
|
|
uint32_t NumCounters = swap(Data->NumCounters);
|
2015-10-29 03:34:04 +08:00
|
|
|
IntPtrT CounterPtr = Data->CounterPtr;
|
2014-04-25 10:45:33 +08:00
|
|
|
if (NumCounters == 0)
|
|
|
|
return error(instrprof_error::malformed);
|
2014-03-22 02:26:05 +08:00
|
|
|
|
2015-10-29 03:34:04 +08:00
|
|
|
auto RawCounts = makeArrayRef(getCounter(CounterPtr), NumCounters);
|
2014-03-24 08:47:18 +08:00
|
|
|
auto *NamesStartAsCounter = reinterpret_cast<const uint64_t *>(NamesStart);
|
2015-10-29 03:34:04 +08:00
|
|
|
|
|
|
|
// Check bounds.
|
|
|
|
if (RawCounts.data() < CountersStart ||
|
2014-03-24 08:47:18 +08:00
|
|
|
RawCounts.data() + RawCounts.size() > NamesStartAsCounter)
|
2014-03-22 02:26:05 +08:00
|
|
|
return error(instrprof_error::malformed);
|
|
|
|
|
|
|
|
if (ShouldSwapBytes) {
|
2015-06-23 07:58:05 +08:00
|
|
|
Record.Counts.clear();
|
|
|
|
Record.Counts.reserve(RawCounts.size());
|
2014-03-22 02:26:05 +08:00
|
|
|
for (uint64_t Count : RawCounts)
|
2015-06-23 07:58:05 +08:00
|
|
|
Record.Counts.push_back(swap(Count));
|
2014-03-22 02:26:05 +08:00
|
|
|
} else
|
|
|
|
Record.Counts = RawCounts;
|
|
|
|
|
2015-10-29 03:34:04 +08:00
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class IntPtrT>
|
2015-12-04 09:02:10 +08:00
|
|
|
std::error_code
|
|
|
|
RawInstrProfReader<IntPtrT>::readValueProfilingData(InstrProfRecord &Record) {
|
2015-11-19 02:14:55 +08:00
|
|
|
|
|
|
|
Record.clearValueData();
|
2015-12-11 14:53:53 +08:00
|
|
|
CurValueDataSize = 0;
|
|
|
|
// Need to match the logic in value profile dumper code in compiler-rt:
|
|
|
|
uint32_t NumValueKinds = 0;
|
|
|
|
for (uint32_t I = 0; I < IPVK_Last + 1; I++)
|
|
|
|
NumValueKinds += (Data->NumValueSites[I] != 0);
|
|
|
|
|
|
|
|
if (!NumValueKinds)
|
2015-11-19 02:14:55 +08:00
|
|
|
return success();
|
|
|
|
|
2015-12-04 09:02:10 +08:00
|
|
|
ErrorOr<std::unique_ptr<ValueProfData>> VDataPtrOrErr =
|
2015-12-11 14:53:53 +08:00
|
|
|
ValueProfData::getValueProfData(ValueDataStart,
|
2015-12-04 09:02:10 +08:00
|
|
|
(const unsigned char *)ProfileEnd,
|
|
|
|
getDataEndianness());
|
2015-11-19 02:14:55 +08:00
|
|
|
|
2015-12-04 09:02:10 +08:00
|
|
|
if (VDataPtrOrErr.getError())
|
|
|
|
return VDataPtrOrErr.getError();
|
2015-11-19 02:14:55 +08:00
|
|
|
|
2015-12-20 14:22:13 +08:00
|
|
|
VDataPtrOrErr.get()->deserializeTo(Record, &Symtab->getAddrHashMap());
|
2015-12-11 14:53:53 +08:00
|
|
|
CurValueDataSize = VDataPtrOrErr.get()->getSize();
|
2015-11-19 02:14:55 +08:00
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class IntPtrT>
|
2015-12-04 09:02:10 +08:00
|
|
|
std::error_code
|
|
|
|
RawInstrProfReader<IntPtrT>::readNextRecord(InstrProfRecord &Record) {
|
2015-10-29 03:34:04 +08:00
|
|
|
if (atEnd())
|
2015-11-12 08:32:17 +08:00
|
|
|
if (std::error_code EC = readNextHeader(ProfileEnd))
|
|
|
|
return EC;
|
2015-10-29 03:34:04 +08:00
|
|
|
|
|
|
|
// Read name ad set it in Record.
|
2015-11-12 08:32:17 +08:00
|
|
|
if (std::error_code EC = readName(Record))
|
|
|
|
return EC;
|
2015-10-29 03:34:04 +08:00
|
|
|
|
|
|
|
// Read FuncHash and set it in Record.
|
2015-11-12 08:32:17 +08:00
|
|
|
if (std::error_code EC = readFuncHash(Record))
|
|
|
|
return EC;
|
2015-10-29 03:34:04 +08:00
|
|
|
|
|
|
|
// Read raw counts and set Record.
|
2015-11-12 08:32:17 +08:00
|
|
|
if (std::error_code EC = readRawCounts(Record))
|
|
|
|
return EC;
|
2015-10-29 03:34:04 +08:00
|
|
|
|
2015-11-19 02:14:55 +08:00
|
|
|
// Read value data and set Record.
|
2015-12-11 07:48:05 +08:00
|
|
|
if (std::error_code EC = readValueProfilingData(Record))
|
|
|
|
return EC;
|
2015-11-19 02:14:55 +08:00
|
|
|
|
2014-03-22 02:26:05 +08:00
|
|
|
// Iterate.
|
2015-10-29 03:34:04 +08:00
|
|
|
advanceData();
|
2014-03-22 02:26:05 +08:00
|
|
|
return success();
|
|
|
|
}
|
2014-03-23 11:38:12 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
template class RawInstrProfReader<uint32_t>;
|
|
|
|
template class RawInstrProfReader<uint64_t>;
|
|
|
|
}
|
2014-04-19 05:48:40 +08:00
|
|
|
|
2014-04-19 06:00:22 +08:00
|
|
|
InstrProfLookupTrait::hash_value_type
|
|
|
|
InstrProfLookupTrait::ComputeHash(StringRef K) {
|
|
|
|
return IndexedInstrProf::ComputeHash(HashType, K);
|
|
|
|
}
|
|
|
|
|
2015-06-23 07:58:05 +08:00
|
|
|
typedef InstrProfLookupTrait::data_type data_type;
|
|
|
|
typedef InstrProfLookupTrait::offset_type offset_type;
|
|
|
|
|
2015-11-28 13:06:00 +08:00
|
|
|
bool InstrProfLookupTrait::readValueProfilingData(
|
2015-09-30 06:13:58 +08:00
|
|
|
const unsigned char *&D, const unsigned char *const End) {
|
2015-11-18 07:00:40 +08:00
|
|
|
ErrorOr<std::unique_ptr<ValueProfData>> VDataPtrOrErr =
|
|
|
|
ValueProfData::getValueProfData(D, End, ValueProfDataEndianness);
|
2015-09-30 06:13:58 +08:00
|
|
|
|
2015-11-10 08:24:45 +08:00
|
|
|
if (VDataPtrOrErr.getError())
|
2015-09-30 06:13:58 +08:00
|
|
|
return false;
|
|
|
|
|
2015-12-20 14:22:13 +08:00
|
|
|
VDataPtrOrErr.get()->deserializeTo(DataBuffer.back(), nullptr);
|
2015-11-10 08:24:45 +08:00
|
|
|
D += VDataPtrOrErr.get()->TotalSize;
|
2015-09-30 06:13:58 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-23 07:58:05 +08:00
|
|
|
data_type InstrProfLookupTrait::ReadData(StringRef K, const unsigned char *D,
|
|
|
|
offset_type N) {
|
|
|
|
// Check if the data is corrupt. If so, don't try to read it.
|
|
|
|
if (N % sizeof(uint64_t))
|
|
|
|
return data_type();
|
|
|
|
|
|
|
|
DataBuffer.clear();
|
|
|
|
std::vector<uint64_t> CounterBuffer;
|
|
|
|
|
2015-09-30 06:13:58 +08:00
|
|
|
using namespace support;
|
|
|
|
const unsigned char *End = D + N;
|
|
|
|
while (D < End) {
|
2015-10-14 00:35:59 +08:00
|
|
|
// Read hash.
|
2015-09-30 06:13:58 +08:00
|
|
|
if (D + sizeof(uint64_t) >= End)
|
2015-06-23 07:58:05 +08:00
|
|
|
return data_type();
|
2015-09-30 06:13:58 +08:00
|
|
|
uint64_t Hash = endian::readNext<uint64_t, little, unaligned>(D);
|
2015-06-23 07:58:05 +08:00
|
|
|
|
2016-02-11 01:18:30 +08:00
|
|
|
// Initialize number of counters for GET_VERSION(FormatVersion) == 1.
|
2015-09-30 06:13:58 +08:00
|
|
|
uint64_t CountsSize = N / sizeof(uint64_t) - 1;
|
2015-10-14 00:35:59 +08:00
|
|
|
// If format version is different then read the number of counters.
|
2016-02-11 01:18:30 +08:00
|
|
|
if (GET_VERSION(FormatVersion) != IndexedInstrProf::ProfVersion::Version1) {
|
2015-09-30 06:13:58 +08:00
|
|
|
if (D + sizeof(uint64_t) > End)
|
|
|
|
return data_type();
|
|
|
|
CountsSize = endian::readNext<uint64_t, little, unaligned>(D);
|
|
|
|
}
|
2015-10-14 00:35:59 +08:00
|
|
|
// Read counter values.
|
2015-09-30 06:13:58 +08:00
|
|
|
if (D + CountsSize * sizeof(uint64_t) > End)
|
2015-06-23 07:58:05 +08:00
|
|
|
return data_type();
|
|
|
|
|
|
|
|
CounterBuffer.clear();
|
2015-09-30 06:13:58 +08:00
|
|
|
CounterBuffer.reserve(CountsSize);
|
|
|
|
for (uint64_t J = 0; J < CountsSize; ++J)
|
2015-06-23 07:58:05 +08:00
|
|
|
CounterBuffer.push_back(endian::readNext<uint64_t, little, unaligned>(D));
|
|
|
|
|
2015-11-02 13:08:23 +08:00
|
|
|
DataBuffer.emplace_back(K, Hash, std::move(CounterBuffer));
|
2015-09-30 06:13:58 +08:00
|
|
|
|
2015-10-14 00:35:59 +08:00
|
|
|
// Read value profiling data.
|
2016-02-11 01:18:30 +08:00
|
|
|
if (GET_VERSION(FormatVersion) > IndexedInstrProf::ProfVersion::Version2 &&
|
2016-01-14 10:47:01 +08:00
|
|
|
!readValueProfilingData(D, End)) {
|
2015-09-30 06:13:58 +08:00
|
|
|
DataBuffer.clear();
|
|
|
|
return data_type();
|
|
|
|
}
|
2015-06-23 07:58:05 +08:00
|
|
|
}
|
|
|
|
return DataBuffer;
|
|
|
|
}
|
|
|
|
|
2015-12-02 04:26:26 +08:00
|
|
|
template <typename HashTableImpl>
|
|
|
|
std::error_code InstrProfReaderIndex<HashTableImpl>::getRecords(
|
|
|
|
StringRef FuncName, ArrayRef<InstrProfRecord> &Data) {
|
|
|
|
auto Iter = HashTable->find(FuncName);
|
|
|
|
if (Iter == HashTable->end())
|
2015-11-12 08:32:17 +08:00
|
|
|
return instrprof_error::unknown_function;
|
2015-10-28 12:20:31 +08:00
|
|
|
|
|
|
|
Data = (*Iter);
|
2015-11-12 08:32:17 +08:00
|
|
|
if (Data.empty())
|
|
|
|
return instrprof_error::malformed;
|
2015-10-28 12:20:31 +08:00
|
|
|
|
|
|
|
return instrprof_error::success;
|
|
|
|
}
|
|
|
|
|
2015-12-02 04:26:26 +08:00
|
|
|
template <typename HashTableImpl>
|
|
|
|
std::error_code InstrProfReaderIndex<HashTableImpl>::getRecords(
|
2015-10-28 12:20:31 +08:00
|
|
|
ArrayRef<InstrProfRecord> &Data) {
|
2015-12-02 04:26:26 +08:00
|
|
|
if (atEnd())
|
|
|
|
return instrprof_error::eof;
|
2015-10-28 12:20:31 +08:00
|
|
|
|
|
|
|
Data = *RecordIterator;
|
|
|
|
|
2015-12-11 07:48:05 +08:00
|
|
|
if (Data.empty())
|
|
|
|
return instrprof_error::malformed;
|
2015-10-28 12:20:31 +08:00
|
|
|
|
|
|
|
return instrprof_error::success;
|
|
|
|
}
|
|
|
|
|
2015-12-02 04:26:26 +08:00
|
|
|
template <typename HashTableImpl>
|
|
|
|
InstrProfReaderIndex<HashTableImpl>::InstrProfReaderIndex(
|
|
|
|
const unsigned char *Buckets, const unsigned char *const Payload,
|
|
|
|
const unsigned char *const Base, IndexedInstrProf::HashT HashType,
|
|
|
|
uint64_t Version) {
|
2015-10-28 12:20:31 +08:00
|
|
|
FormatVersion = Version;
|
2015-12-02 04:26:26 +08:00
|
|
|
HashTable.reset(HashTableImpl::Create(
|
|
|
|
Buckets, Payload, Base,
|
|
|
|
typename HashTableImpl::InfoType(HashType, Version)));
|
|
|
|
RecordIterator = HashTable->data_begin();
|
2015-10-28 12:20:31 +08:00
|
|
|
}
|
|
|
|
|
2014-04-19 05:48:40 +08:00
|
|
|
bool IndexedInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) {
|
2015-11-12 08:32:17 +08:00
|
|
|
if (DataBuffer.getBufferSize() < 8)
|
|
|
|
return false;
|
2014-04-19 05:48:40 +08:00
|
|
|
using namespace support;
|
|
|
|
uint64_t Magic =
|
|
|
|
endian::read<uint64_t, little, aligned>(DataBuffer.getBufferStart());
|
2015-10-14 00:35:59 +08:00
|
|
|
// Verify that it's magical.
|
2014-04-19 05:48:40 +08:00
|
|
|
return Magic == IndexedInstrProf::Magic;
|
|
|
|
}
|
|
|
|
|
2016-02-03 12:08:18 +08:00
|
|
|
const unsigned char *
|
|
|
|
IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version,
|
|
|
|
const unsigned char *Cur) {
|
|
|
|
using namespace support;
|
|
|
|
if (Version >= IndexedInstrProf::Version4) {
|
|
|
|
const IndexedInstrProf::Summary *SummaryInLE =
|
|
|
|
reinterpret_cast<const IndexedInstrProf::Summary *>(Cur);
|
|
|
|
uint64_t NFields =
|
|
|
|
endian::byte_swap<uint64_t, little>(SummaryInLE->NumSummaryFields);
|
|
|
|
uint64_t NEntries =
|
|
|
|
endian::byte_swap<uint64_t, little>(SummaryInLE->NumCutoffEntries);
|
|
|
|
uint32_t SummarySize =
|
|
|
|
IndexedInstrProf::Summary::getSize(NFields, NEntries);
|
|
|
|
std::unique_ptr<IndexedInstrProf::Summary> SummaryData =
|
|
|
|
IndexedInstrProf::allocSummary(SummarySize);
|
|
|
|
|
|
|
|
const uint64_t *Src = reinterpret_cast<const uint64_t *>(SummaryInLE);
|
|
|
|
uint64_t *Dst = reinterpret_cast<uint64_t *>(SummaryData.get());
|
|
|
|
for (unsigned I = 0; I < SummarySize / sizeof(uint64_t); I++)
|
|
|
|
Dst[I] = endian::byte_swap<uint64_t, little>(Src[I]);
|
|
|
|
|
2016-02-18 02:18:47 +08:00
|
|
|
// initialize InstrProfSummary using the SummaryData from disk.
|
|
|
|
this->Summary = llvm::make_unique<InstrProfSummary>(*(SummaryData.get()));
|
2016-02-03 12:08:18 +08:00
|
|
|
return Cur + SummarySize;
|
|
|
|
} else {
|
|
|
|
// For older version of profile data, we need to compute on the fly:
|
|
|
|
using namespace IndexedInstrProf;
|
|
|
|
std::vector<uint32_t> Cutoffs(&SummaryCutoffs[0],
|
|
|
|
&SummaryCutoffs[NumSummaryCutoffs]);
|
2016-02-18 02:18:47 +08:00
|
|
|
this->Summary = llvm::make_unique<InstrProfSummary>(Cutoffs);
|
2016-02-03 12:08:18 +08:00
|
|
|
this->Summary->computeDetailedSummary();
|
|
|
|
return Cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-13 10:24:39 +08:00
|
|
|
std::error_code IndexedInstrProfReader::readHeader() {
|
2014-05-02 01:16:24 +08:00
|
|
|
const unsigned char *Start =
|
|
|
|
(const unsigned char *)DataBuffer->getBufferStart();
|
2014-04-19 05:48:40 +08:00
|
|
|
const unsigned char *Cur = Start;
|
2014-05-02 01:16:24 +08:00
|
|
|
if ((const unsigned char *)DataBuffer->getBufferEnd() - Cur < 24)
|
2014-04-19 05:48:40 +08:00
|
|
|
return error(instrprof_error::truncated);
|
|
|
|
|
|
|
|
using namespace support;
|
|
|
|
|
2015-10-18 09:02:29 +08:00
|
|
|
auto *Header = reinterpret_cast<const IndexedInstrProf::Header *>(Cur);
|
|
|
|
Cur += sizeof(IndexedInstrProf::Header);
|
|
|
|
|
2014-04-19 05:48:40 +08:00
|
|
|
// Check the magic number.
|
2015-10-18 09:02:29 +08:00
|
|
|
uint64_t Magic = endian::byte_swap<uint64_t, little>(Header->Magic);
|
2014-04-19 05:48:40 +08:00
|
|
|
if (Magic != IndexedInstrProf::Magic)
|
|
|
|
return error(instrprof_error::bad_magic);
|
|
|
|
|
|
|
|
// Read the version.
|
2015-10-28 12:20:31 +08:00
|
|
|
uint64_t FormatVersion = endian::byte_swap<uint64_t, little>(Header->Version);
|
2016-02-11 01:18:30 +08:00
|
|
|
if (GET_VERSION(FormatVersion) >
|
|
|
|
IndexedInstrProf::ProfVersion::CurrentVersion)
|
2014-04-19 05:48:40 +08:00
|
|
|
return error(instrprof_error::unsupported_version);
|
|
|
|
|
2016-02-03 12:08:18 +08:00
|
|
|
Cur = readSummary((IndexedInstrProf::ProfVersion)FormatVersion, Cur);
|
2014-04-19 05:48:40 +08:00
|
|
|
|
|
|
|
// Read the hash type and start offset.
|
|
|
|
IndexedInstrProf::HashT HashType = static_cast<IndexedInstrProf::HashT>(
|
2015-10-18 09:02:29 +08:00
|
|
|
endian::byte_swap<uint64_t, little>(Header->HashType));
|
2014-04-19 05:48:40 +08:00
|
|
|
if (HashType > IndexedInstrProf::HashT::Last)
|
|
|
|
return error(instrprof_error::unsupported_hash_type);
|
2015-10-18 09:02:29 +08:00
|
|
|
|
|
|
|
uint64_t HashOffset = endian::byte_swap<uint64_t, little>(Header->HashOffset);
|
2014-04-19 05:48:40 +08:00
|
|
|
|
|
|
|
// The rest of the file is an on disk hash table.
|
2015-12-02 04:26:26 +08:00
|
|
|
InstrProfReaderIndexBase *IndexPtr = nullptr;
|
|
|
|
IndexPtr = new InstrProfReaderIndex<OnDiskHashTableImplV3>(
|
|
|
|
Start + HashOffset, Cur, Start, HashType, FormatVersion);
|
|
|
|
Index.reset(IndexPtr);
|
2014-04-19 05:48:40 +08:00
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2015-12-20 14:22:13 +08:00
|
|
|
InstrProfSymtab &IndexedInstrProfReader::getSymtab() {
|
|
|
|
if (Symtab.get())
|
|
|
|
return *Symtab.get();
|
|
|
|
|
|
|
|
std::unique_ptr<InstrProfSymtab> NewSymtab = make_unique<InstrProfSymtab>();
|
|
|
|
Index->populateSymtab(*NewSymtab.get());
|
|
|
|
|
|
|
|
Symtab = std::move(NewSymtab);
|
|
|
|
return *Symtab.get();
|
|
|
|
}
|
|
|
|
|
2015-11-06 15:54:21 +08:00
|
|
|
ErrorOr<InstrProfRecord>
|
|
|
|
IndexedInstrProfReader::getInstrProfRecord(StringRef FuncName,
|
|
|
|
uint64_t FuncHash) {
|
2015-10-28 12:20:31 +08:00
|
|
|
ArrayRef<InstrProfRecord> Data;
|
2015-12-02 04:26:26 +08:00
|
|
|
std::error_code EC = Index->getRecords(FuncName, Data);
|
2015-11-12 08:32:17 +08:00
|
|
|
if (EC != instrprof_error::success)
|
|
|
|
return EC;
|
2015-10-28 12:20:31 +08:00
|
|
|
// Found it. Look for counters with the right hash.
|
2015-06-23 07:58:05 +08:00
|
|
|
for (unsigned I = 0, E = Data.size(); I < E; ++I) {
|
2014-08-02 06:50:07 +08:00
|
|
|
// Check for a match and fill the vector if there is one.
|
2015-06-23 07:58:05 +08:00
|
|
|
if (Data[I].Hash == FuncHash) {
|
2015-11-02 13:08:23 +08:00
|
|
|
return std::move(Data[I]);
|
2014-08-02 06:50:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return error(instrprof_error::hash_mismatch);
|
2014-04-19 05:48:40 +08:00
|
|
|
}
|
|
|
|
|
2015-11-06 15:54:21 +08:00
|
|
|
std::error_code
|
|
|
|
IndexedInstrProfReader::getFunctionCounts(StringRef FuncName, uint64_t FuncHash,
|
|
|
|
std::vector<uint64_t> &Counts) {
|
2015-11-02 13:08:23 +08:00
|
|
|
ErrorOr<InstrProfRecord> Record = getInstrProfRecord(FuncName, FuncHash);
|
2015-11-06 15:54:21 +08:00
|
|
|
if (std::error_code EC = Record.getError())
|
|
|
|
return EC;
|
2015-11-02 13:08:23 +08:00
|
|
|
|
|
|
|
Counts = Record.get().Counts;
|
|
|
|
return success();
|
|
|
|
}
|
|
|
|
|
2015-10-28 12:20:31 +08:00
|
|
|
std::error_code IndexedInstrProfReader::readNextRecord(
|
|
|
|
InstrProfRecord &Record) {
|
|
|
|
static unsigned RecordIndex = 0;
|
2014-04-19 05:48:40 +08:00
|
|
|
|
2015-10-28 12:20:31 +08:00
|
|
|
ArrayRef<InstrProfRecord> Data;
|
|
|
|
|
2015-12-02 04:26:26 +08:00
|
|
|
std::error_code EC = Index->getRecords(Data);
|
2015-11-12 08:32:17 +08:00
|
|
|
if (EC != instrprof_error::success)
|
|
|
|
return error(EC);
|
2014-08-02 06:50:07 +08:00
|
|
|
|
2015-06-23 07:58:05 +08:00
|
|
|
Record = Data[RecordIndex++];
|
|
|
|
if (RecordIndex >= Data.size()) {
|
2015-12-02 04:26:26 +08:00
|
|
|
Index->advanceToNextKey();
|
2015-06-23 07:58:05 +08:00
|
|
|
RecordIndex = 0;
|
2014-08-02 06:50:07 +08:00
|
|
|
}
|
2014-04-19 05:48:40 +08:00
|
|
|
return success();
|
|
|
|
}
|