| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef LLVM_PROFILEDATA_INSTRPROFREADER_H |
| 15 |
#define LLVM_PROFILEDATA_INSTRPROFREADER_H |
| 16 |
|
| 17 |
#include "llvm/ADT/ArrayRef.h" |
| 18 |
#include "llvm/ADT/StringRef.h" |
| 19 |
#include "llvm/IR/ProfileSummary.h" |
| 20 |
#include "llvm/ProfileData/InstrProf.h" |
| 21 |
#include "llvm/ProfileData/InstrProfCorrelator.h" |
| 22 |
#include "llvm/Support/Endian.h" |
| 23 |
#include "llvm/Support/Error.h" |
| 24 |
#include "llvm/Support/LineIterator.h" |
| 25 |
#include "llvm/Support/MemoryBuffer.h" |
| 26 |
#include "llvm/Support/OnDiskHashTable.h" |
| 27 |
#include "llvm/Support/SwapByteOrder.h" |
| 28 |
#include <algorithm> |
| 29 |
#include <cassert> |
| 30 |
#include <cstddef> |
| 31 |
#include <cstdint> |
| 32 |
#include <iterator> |
| 33 |
#include <memory> |
| 34 |
#include <utility> |
| 35 |
#include <vector> |
| 36 |
|
| 37 |
namespace llvm { |
| 38 |
|
| 39 |
class InstrProfReader; |
| 40 |
|
| 41 |
|
| 42 |
class InstrProfIterator { |
| 43 |
public: |
| 44 |
using iterator_category = std::input_iterator_tag; |
| 45 |
using value_type = NamedInstrProfRecord; |
| 46 |
using difference_type = std::ptrdiff_t; |
| 47 |
using pointer = value_type *; |
| 48 |
using reference = value_type &; |
| 49 |
|
| 50 |
private: |
| 51 |
InstrProfReader *Reader = nullptr; |
| 52 |
value_type Record; |
| 53 |
|
| 54 |
void Increment(); |
| 55 |
|
| 56 |
public: |
| 57 |
InstrProfIterator() = default; |
| 58 |
InstrProfIterator(InstrProfReader *Reader) : Reader(Reader) { Increment(); } |
| 59 |
|
| 60 |
InstrProfIterator &operator++() { Increment(); return *this; } |
| 61 |
bool operator==(const InstrProfIterator &RHS) const { |
| 62 |
return Reader == RHS.Reader; |
| 63 |
} |
| 64 |
bool operator!=(const InstrProfIterator &RHS) const { |
| 65 |
return Reader != RHS.Reader; |
| 66 |
} |
| 67 |
value_type &operator*() { return Record; } |
| 68 |
value_type *operator->() { return &Record; } |
| 69 |
}; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
class InstrProfReader { |
| 74 |
instrprof_error LastError = instrprof_error::success; |
| 75 |
std::string LastErrorMsg; |
| 76 |
|
| 77 |
public: |
| 78 |
InstrProfReader() = default; |
| 79 |
virtual ~InstrProfReader() = default; |
| 80 |
|
| 81 |
|
| 82 |
virtual Error readHeader() = 0; |
| 83 |
|
| 84 |
|
| 85 |
virtual Error readNextRecord(NamedInstrProfRecord &Record) = 0; |
| 86 |
|
| 87 |
|
| 88 |
virtual Error printBinaryIds(raw_ostream &OS) { return success(); }; |
| 89 |
|
| 90 |
|
| 91 |
InstrProfIterator begin() { return InstrProfIterator(this); } |
| 92 |
InstrProfIterator end() { return InstrProfIterator(); } |
| 93 |
|
| 94 |
virtual bool isIRLevelProfile() const = 0; |
| 95 |
|
| 96 |
virtual bool hasCSIRLevelProfile() const = 0; |
| 97 |
|
| 98 |
virtual bool instrEntryBBEnabled() const = 0; |
| 99 |
|
| 100 |
|
| 101 |
virtual bool useDebugInfoCorrelate() const { return false; } |
| 102 |
|
| 103 |
|
| 104 |
virtual bool hasSingleByteCoverage() const = 0; |
| 105 |
|
| 106 |
|
| 107 |
virtual bool functionEntryOnly() const = 0; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
virtual InstrProfKind getProfileKind() const = 0; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
virtual InstrProfSymtab &getSymtab() = 0; |
| 124 |
|
| 125 |
|
| 126 |
void accumulateCounts(CountSumOrPercent &Sum, bool IsCS); |
| 127 |
|
| 128 |
protected: |
| 129 |
std::unique_ptr<InstrProfSymtab> Symtab; |
| 130 |
|
| 131 |
|
| 132 |
Error error(instrprof_error Err, const std::string &ErrMsg = "") { |
| 133 |
LastError = Err; |
| 134 |
LastErrorMsg = ErrMsg; |
| 135 |
if (Err == instrprof_error::success) |
| 136 |
return Error::success(); |
| 137 |
return make_error<InstrProfError>(Err, ErrMsg); |
| 138 |
} |
| 139 |
|
| 140 |
Error error(Error &&E) { |
| 141 |
handleAllErrors(std::move(E), [&](const InstrProfError &IPE) { |
| 142 |
LastError = IPE.get(); |
| 143 |
LastErrorMsg = IPE.getMessage(); |
| 144 |
}); |
| 145 |
return make_error<InstrProfError>(LastError, LastErrorMsg); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
Error success() { return error(instrprof_error::success); } |
| 150 |
|
| 151 |
public: |
| 152 |
|
| 153 |
bool isEOF() { return LastError == instrprof_error::eof; } |
| 154 |
|
| 155 |
|
| 156 |
bool hasError() { return LastError != instrprof_error::success && !isEOF(); } |
| 157 |
|
| 158 |
|
| 159 |
Error getError() { |
| 160 |
if (hasError()) |
| 161 |
return make_error<InstrProfError>(LastError, LastErrorMsg); |
| 162 |
return Error::success(); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
static Expected<std::unique_ptr<InstrProfReader>> |
| 168 |
create(const Twine &Path, const InstrProfCorrelator *Correlator = nullptr); |
| 169 |
|
| 170 |
static Expected<std::unique_ptr<InstrProfReader>> |
| 171 |
create(std::unique_ptr<MemoryBuffer> Buffer, |
| 172 |
const InstrProfCorrelator *Correlator = nullptr); |
| 173 |
}; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
class TextInstrProfReader : public InstrProfReader { |
| 184 |
private: |
| 185 |
|
| 186 |
std::unique_ptr<MemoryBuffer> DataBuffer; |
| 187 |
|
| 188 |
line_iterator Line; |
| 189 |
|
| 190 |
InstrProfKind ProfileKind = InstrProfKind::Unknown; |
| 191 |
|
| 192 |
Error readValueProfileData(InstrProfRecord &Record); |
| 193 |
|
| 194 |
public: |
| 195 |
TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_) |
| 196 |
: DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {} |
| 197 |
TextInstrProfReader(const TextInstrProfReader &) = delete; |
| 198 |
TextInstrProfReader &operator=(const TextInstrProfReader &) = delete; |
| 199 |
|
| 200 |
|
| 201 |
static bool hasFormat(const MemoryBuffer &Buffer); |
| 202 |
|
| 203 |
bool isIRLevelProfile() const override { |
| 204 |
return static_cast<bool>(ProfileKind & InstrProfKind::IR); |
| 205 |
} |
| 206 |
|
| 207 |
bool hasCSIRLevelProfile() const override { |
| 208 |
return static_cast<bool>(ProfileKind & InstrProfKind::CS); |
| 209 |
} |
| 210 |
|
| 211 |
bool instrEntryBBEnabled() const override { |
| 212 |
return static_cast<bool>(ProfileKind & InstrProfKind::BB); |
| 213 |
} |
| 214 |
|
| 215 |
bool hasSingleByteCoverage() const override { |
| 216 |
return static_cast<bool>(ProfileKind & InstrProfKind::SingleByteCoverage); |
| 217 |
} |
| 218 |
|
| 219 |
bool functionEntryOnly() const override { |
| 220 |
return static_cast<bool>(ProfileKind & InstrProfKind::FunctionEntryOnly); |
| 221 |
} |
| 222 |
|
| 223 |
InstrProfKind getProfileKind() const override { return ProfileKind; } |
| 224 |
|
| 225 |
|
| 226 |
Error readHeader() override; |
| 227 |
|
| 228 |
|
| 229 |
Error readNextRecord(NamedInstrProfRecord &Record) override; |
| 230 |
|
| 231 |
InstrProfSymtab &getSymtab() override { |
| 232 |
assert(Symtab.get()); |
| 233 |
return *Symtab.get(); |
| 234 |
} |
| 235 |
}; |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
template <class IntPtrT> |
| 245 |
class RawInstrProfReader : public InstrProfReader { |
| 246 |
private: |
| 247 |
|
| 248 |
std::unique_ptr<MemoryBuffer> DataBuffer; |
| 249 |
|
| 250 |
|
| 251 |
const InstrProfCorrelatorImpl<IntPtrT> *Correlator; |
| 252 |
bool ShouldSwapBytes; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
uint64_t Version; |
| 257 |
uint64_t CountersDelta; |
| 258 |
uint64_t NamesDelta; |
| 259 |
const RawInstrProf::ProfileData<IntPtrT> *Data; |
| 260 |
const RawInstrProf::ProfileData<IntPtrT> *DataEnd; |
| 261 |
const char *CountersStart; |
| 262 |
const char *CountersEnd; |
| 263 |
const char *NamesStart; |
| 264 |
const char *NamesEnd; |
| 265 |
|
| 266 |
|
| 267 |
const uint8_t *ValueDataStart; |
| 268 |
uint32_t ValueKindLast; |
| 269 |
uint32_t CurValueDataSize; |
| 270 |
|
| 271 |
uint64_t BinaryIdsSize; |
| 272 |
const uint8_t *BinaryIdsStart; |
| 273 |
|
| 274 |
public: |
| 275 |
RawInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer, |
| 276 |
const InstrProfCorrelator *Correlator) |
| 277 |
: DataBuffer(std::move(DataBuffer)), |
| 278 |
Correlator(dyn_cast_or_null<const InstrProfCorrelatorImpl<IntPtrT>>( |
| 279 |
Correlator)) {} |
| 280 |
RawInstrProfReader(const RawInstrProfReader &) = delete; |
| 281 |
RawInstrProfReader &operator=(const RawInstrProfReader &) = delete; |
| 282 |
|
| 283 |
static bool hasFormat(const MemoryBuffer &DataBuffer); |
| 284 |
Error readHeader() override; |
| 285 |
Error readNextRecord(NamedInstrProfRecord &Record) override; |
| 286 |
Error printBinaryIds(raw_ostream &OS) override; |
| 287 |
|
| 288 |
bool isIRLevelProfile() const override { |
| 289 |
return (Version & VARIANT_MASK_IR_PROF) != 0; |
| 290 |
} |
| 291 |
|
| 292 |
bool hasCSIRLevelProfile() const override { |
| 293 |
return (Version & VARIANT_MASK_CSIR_PROF) != 0; |
| 294 |
} |
| 295 |
|
| 296 |
bool instrEntryBBEnabled() const override { |
| 297 |
return (Version & VARIANT_MASK_INSTR_ENTRY) != 0; |
| 298 |
} |
| 299 |
|
| 300 |
bool useDebugInfoCorrelate() const override { |
| 301 |
return (Version & VARIANT_MASK_DBG_CORRELATE) != 0; |
| 302 |
} |
| 303 |
|
| 304 |
bool hasSingleByteCoverage() const override { |
| 305 |
return (Version & VARIANT_MASK_BYTE_COVERAGE) != 0; |
| 306 |
} |
| 307 |
|
| 308 |
bool functionEntryOnly() const override { |
| 309 |
return (Version & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0; |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
InstrProfKind getProfileKind() const override; |
| 314 |
|
| 315 |
InstrProfSymtab &getSymtab() override { |
| 316 |
assert(Symtab.get()); |
| 317 |
return *Symtab.get(); |
| 318 |
} |
| 319 |
|
| 320 |
private: |
| 321 |
Error createSymtab(InstrProfSymtab &Symtab); |
| 322 |
Error readNextHeader(const char *CurrentPos); |
| 323 |
Error readHeader(const RawInstrProf::Header &Header); |
| 324 |
|
| 325 |
template <class IntT> IntT swap(IntT Int) const { |
| 326 |
return ShouldSwapBytes ? sys::getSwappedBytes(Int) : Int; |
| 327 |
} |
| 328 |
|
| 329 |
support::endianness getDataEndianness() const { |
| 330 |
support::endianness HostEndian = getHostEndianness(); |
| 331 |
if (!ShouldSwapBytes) |
| 332 |
return HostEndian; |
| 333 |
if (HostEndian == support::little) |
| 334 |
return support::big; |
| 335 |
else |
| 336 |
return support::little; |
| 337 |
} |
| 338 |
|
| 339 |
inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) { |
| 340 |
return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t)); |
| 341 |
} |
| 342 |
|
| 343 |
Error readName(NamedInstrProfRecord &Record); |
| 344 |
Error readFuncHash(NamedInstrProfRecord &Record); |
| 345 |
Error readRawCounts(InstrProfRecord &Record); |
| 346 |
Error readValueProfilingData(InstrProfRecord &Record); |
| 347 |
bool atEnd() const { return Data == DataEnd; } |
| 348 |
|
| 349 |
void advanceData() { |
| 350 |
|
| 351 |
if (!Correlator) { |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
CountersDelta -= sizeof(*Data); |
| 358 |
} |
| 359 |
Data++; |
| 360 |
ValueDataStart += CurValueDataSize; |
| 361 |
} |
| 362 |
|
| 363 |
const char *getNextHeaderPos() const { |
| 364 |
assert(atEnd()); |
| 365 |
return (const char *)ValueDataStart; |
| 366 |
} |
| 367 |
|
| 368 |
StringRef getName(uint64_t NameRef) const { |
| 369 |
return Symtab->getFuncName(swap(NameRef)); |
| 370 |
} |
| 371 |
|
| 372 |
int getCounterTypeSize() const { |
| 373 |
return hasSingleByteCoverage() ? sizeof(uint8_t) : sizeof(uint64_t); |
| 374 |
} |
| 375 |
}; |
| 376 |
|
| 377 |
using RawInstrProfReader32 = RawInstrProfReader<uint32_t>; |
| 378 |
using RawInstrProfReader64 = RawInstrProfReader<uint64_t>; |
| 379 |
|
| 380 |
namespace IndexedInstrProf { |
| 381 |
|
| 382 |
enum class HashT : uint32_t; |
| 383 |
|
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
class InstrProfLookupTrait { |
| 389 |
std::vector<NamedInstrProfRecord> DataBuffer; |
| 390 |
IndexedInstrProf::HashT HashType; |
| 391 |
unsigned FormatVersion; |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
support::endianness ValueProfDataEndianness = support::little; |
| 396 |
|
| 397 |
public: |
| 398 |
InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion) |
| 399 |
: HashType(HashType), FormatVersion(FormatVersion) {} |
| 400 |
|
| 401 |
using data_type = ArrayRef<NamedInstrProfRecord>; |
| 402 |
|
| 403 |
using internal_key_type = StringRef; |
| 404 |
using external_key_type = StringRef; |
| 405 |
using hash_value_type = uint64_t; |
| 406 |
using offset_type = uint64_t; |
| 407 |
|
| 408 |
static bool EqualKey(StringRef A, StringRef B) { return A == B; } |
| 409 |
static StringRef GetInternalKey(StringRef K) { return K; } |
| 410 |
static StringRef GetExternalKey(StringRef K) { return K; } |
| 411 |
|
| 412 |
hash_value_type ComputeHash(StringRef K); |
| 413 |
|
| 414 |
static std::pair<offset_type, offset_type> |
| 415 |
ReadKeyDataLength(const unsigned char *&D) { |
| 416 |
using namespace support; |
| 417 |
|
| 418 |
offset_type KeyLen = endian::readNext<offset_type, little, unaligned>(D); |
| 419 |
offset_type DataLen = endian::readNext<offset_type, little, unaligned>(D); |
| 420 |
return std::make_pair(KeyLen, DataLen); |
| 421 |
} |
| 422 |
|
| 423 |
StringRef ReadKey(const unsigned char *D, offset_type N) { |
| 424 |
return StringRef((const char *)D, N); |
| 425 |
} |
| 426 |
|
| 427 |
bool readValueProfilingData(const unsigned char *&D, |
| 428 |
const unsigned char *const End); |
| 429 |
data_type ReadData(StringRef K, const unsigned char *D, offset_type N); |
| 430 |
|
| 431 |
|
| 432 |
void setValueProfDataEndianness(support::endianness Endianness) { |
| 433 |
ValueProfDataEndianness = Endianness; |
| 434 |
} |
| 435 |
}; |
| 436 |
|
| 437 |
struct InstrProfReaderIndexBase { |
| 438 |
virtual ~InstrProfReaderIndexBase() = default; |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
virtual Error getRecords(ArrayRef<NamedInstrProfRecord> &Data) = 0; |
| 443 |
|
| 444 |
|
| 445 |
virtual Error getRecords(StringRef FuncName, |
| 446 |
ArrayRef<NamedInstrProfRecord> &Data) = 0; |
| 447 |
virtual void advanceToNextKey() = 0; |
| 448 |
virtual bool atEnd() const = 0; |
| 449 |
virtual void setValueProfDataEndianness(support::endianness Endianness) = 0; |
| 450 |
virtual uint64_t getVersion() const = 0; |
| 451 |
virtual bool isIRLevelProfile() const = 0; |
| 452 |
virtual bool hasCSIRLevelProfile() const = 0; |
| 453 |
virtual bool instrEntryBBEnabled() const = 0; |
| 454 |
virtual bool hasSingleByteCoverage() const = 0; |
| 455 |
virtual bool functionEntryOnly() const = 0; |
| 456 |
virtual InstrProfKind getProfileKind() const = 0; |
| 457 |
virtual Error populateSymtab(InstrProfSymtab &) = 0; |
| 458 |
}; |
| 459 |
|
| 460 |
using OnDiskHashTableImplV3 = |
| 461 |
OnDiskIterableChainedHashTable<InstrProfLookupTrait>; |
| 462 |
|
| 463 |
template <typename HashTableImpl> |
| 464 |
class InstrProfReaderItaniumRemapper; |
| 465 |
|
| 466 |
template <typename HashTableImpl> |
| 467 |
class InstrProfReaderIndex : public InstrProfReaderIndexBase { |
| 468 |
private: |
| 469 |
std::unique_ptr<HashTableImpl> HashTable; |
| 470 |
typename HashTableImpl::data_iterator RecordIterator; |
| 471 |
uint64_t FormatVersion; |
| 472 |
|
| 473 |
friend class InstrProfReaderItaniumRemapper<HashTableImpl>; |
| 474 |
|
| 475 |
public: |
| 476 |
InstrProfReaderIndex(const unsigned char *Buckets, |
| 477 |
const unsigned char *const Payload, |
| 478 |
const unsigned char *const Base, |
| 479 |
IndexedInstrProf::HashT HashType, uint64_t Version); |
| 480 |
~InstrProfReaderIndex() override = default; |
| 481 |
|
| 482 |
Error getRecords(ArrayRef<NamedInstrProfRecord> &Data) override; |
| 483 |
Error getRecords(StringRef FuncName, |
| 484 |
ArrayRef<NamedInstrProfRecord> &Data) override; |
| 485 |
void advanceToNextKey() override { RecordIterator++; } |
| 486 |
|
| 487 |
bool atEnd() const override { |
| 488 |
return RecordIterator == HashTable->data_end(); |
| 489 |
} |
| 490 |
|
| 491 |
void setValueProfDataEndianness(support::endianness Endianness) override { |
| 492 |
HashTable->getInfoObj().setValueProfDataEndianness(Endianness); |
| 493 |
} |
| 494 |
|
| 495 |
uint64_t getVersion() const override { return GET_VERSION(FormatVersion); } |
| 496 |
|
| 497 |
bool isIRLevelProfile() const override { |
| 498 |
return (FormatVersion & VARIANT_MASK_IR_PROF) != 0; |
| 499 |
} |
| 500 |
|
| 501 |
bool hasCSIRLevelProfile() const override { |
| 502 |
return (FormatVersion & VARIANT_MASK_CSIR_PROF) != 0; |
| 503 |
} |
| 504 |
|
| 505 |
bool instrEntryBBEnabled() const override { |
| 506 |
return (FormatVersion & VARIANT_MASK_INSTR_ENTRY) != 0; |
| 507 |
} |
| 508 |
|
| 509 |
bool hasSingleByteCoverage() const override { |
| 510 |
return (FormatVersion & VARIANT_MASK_BYTE_COVERAGE) != 0; |
| 511 |
} |
| 512 |
|
| 513 |
bool functionEntryOnly() const override { |
| 514 |
return (FormatVersion & VARIANT_MASK_FUNCTION_ENTRY_ONLY) != 0; |
| 515 |
} |
| 516 |
|
| 517 |
InstrProfKind getProfileKind() const override; |
| 518 |
|
| 519 |
Error populateSymtab(InstrProfSymtab &Symtab) override { |
| 520 |
return Symtab.create(HashTable->keys()); |
| 521 |
} |
| 522 |
}; |
| 523 |
|
| 524 |
|
| 525 |
class InstrProfReaderRemapper { |
| 526 |
public: |
| 527 |
virtual ~InstrProfReaderRemapper() = default; |
| 528 |
virtual Error populateRemappings() { return Error::success(); } |
| 529 |
virtual Error getRecords(StringRef FuncName, |
| 530 |
ArrayRef<NamedInstrProfRecord> &Data) = 0; |
| 531 |
}; |
| 532 |
|
| 533 |
|
| 534 |
class IndexedInstrProfReader : public InstrProfReader { |
| 535 |
private: |
| 536 |
|
| 537 |
std::unique_ptr<MemoryBuffer> DataBuffer; |
| 538 |
|
| 539 |
std::unique_ptr<MemoryBuffer> RemappingBuffer; |
| 540 |
|
| 541 |
std::unique_ptr<InstrProfReaderIndexBase> Index; |
| 542 |
|
| 543 |
std::unique_ptr<InstrProfReaderRemapper> Remapper; |
| 544 |
|
| 545 |
std::unique_ptr<ProfileSummary> Summary; |
| 546 |
|
| 547 |
std::unique_ptr<ProfileSummary> CS_Summary; |
| 548 |
|
| 549 |
unsigned RecordIndex; |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
const unsigned char *readSummary(IndexedInstrProf::ProfVersion Version, |
| 555 |
const unsigned char *Cur, bool UseCS); |
| 556 |
|
| 557 |
public: |
| 558 |
IndexedInstrProfReader( |
| 559 |
std::unique_ptr<MemoryBuffer> DataBuffer, |
| 560 |
std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr) |
| 561 |
: DataBuffer(std::move(DataBuffer)), |
| 562 |
RemappingBuffer(std::move(RemappingBuffer)), RecordIndex(0) {} |
| 563 |
IndexedInstrProfReader(const IndexedInstrProfReader &) = delete; |
| 564 |
IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete; |
| 565 |
|
| 566 |
|
| 567 |
uint64_t getVersion() const { return Index->getVersion(); } |
| 568 |
bool isIRLevelProfile() const override { return Index->isIRLevelProfile(); } |
| 569 |
bool hasCSIRLevelProfile() const override { |
| 570 |
return Index->hasCSIRLevelProfile(); |
| 571 |
} |
| 572 |
|
| 573 |
bool instrEntryBBEnabled() const override { |
| 574 |
return Index->instrEntryBBEnabled(); |
| 575 |
} |
| 576 |
|
| 577 |
bool hasSingleByteCoverage() const override { |
| 578 |
return Index->hasSingleByteCoverage(); |
| 579 |
} |
| 580 |
|
| 581 |
bool functionEntryOnly() const override { return Index->functionEntryOnly(); } |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
InstrProfKind getProfileKind() const override { |
| 586 |
return Index->getProfileKind(); |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
static bool hasFormat(const MemoryBuffer &DataBuffer); |
| 591 |
|
| 592 |
|
| 593 |
Error readHeader() override; |
| 594 |
|
| 595 |
Error readNextRecord(NamedInstrProfRecord &Record) override; |
| 596 |
|
| 597 |
|
| 598 |
Expected<InstrProfRecord> getInstrProfRecord(StringRef FuncName, |
| 599 |
uint64_t FuncHash); |
| 600 |
|
| 601 |
|
| 602 |
Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash, |
| 603 |
std::vector<uint64_t> &Counts); |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
uint64_t getMaximumFunctionCount(bool UseCS) { |
| 608 |
if (UseCS) { |
| 609 |
assert(CS_Summary && "No context sensitive profile summary"); |
| 610 |
return CS_Summary->getMaxFunctionCount(); |
| 611 |
} else { |
| 612 |
assert(Summary && "No profile summary"); |
| 613 |
return Summary->getMaxFunctionCount(); |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
static Expected<std::unique_ptr<IndexedInstrProfReader>> |
| 619 |
create(const Twine &Path, const Twine &RemappingPath = ""); |
| 620 |
|
| 621 |
static Expected<std::unique_ptr<IndexedInstrProfReader>> |
| 622 |
create(std::unique_ptr<MemoryBuffer> Buffer, |
| 623 |
std::unique_ptr<MemoryBuffer> RemappingBuffer = nullptr); |
| 624 |
|
| 625 |
|
| 626 |
void setValueProfDataEndianness(support::endianness Endianness) { |
| 627 |
Index->setValueProfDataEndianness(Endianness); |
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
InstrProfSymtab &getSymtab() override; |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
ProfileSummary &getSummary(bool UseCS) { |
| 638 |
if (UseCS) { |
| 639 |
assert(CS_Summary && "No context sensitive summary"); |
| 640 |
return *(CS_Summary.get()); |
| 641 |
} else { |
| 642 |
assert(Summary && "No profile summary"); |
| 643 |
return *(Summary.get()); |
| 644 |
} |
| 645 |
} |
| 646 |
}; |
| 647 |
|
| 648 |
} |
| 649 |
|
| 650 |
#endif |