15 #ifndef LLVM_PROFILEDATA_INSTRPROFREADER_H
16 #define LLVM_PROFILEDATA_INSTRPROFREADER_H
30 class InstrProfReader;
53 std::error_code LastError;
69 std::error_code
error(std::error_code EC) {
83 std::error_code
getError() {
return LastError; }
90 create(std::unique_ptr<MemoryBuffer> Buffer);
104 std::unique_ptr<MemoryBuffer> DataBuffer;
112 : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer,
true,
'#') {}
127 template <
class IntPtrT>
131 std::unique_ptr<MemoryBuffer> DataBuffer;
134 const uint32_t NumCounters;
135 const uint64_t FuncHash;
136 const IntPtrT NamePtr;
137 const IntPtrT CounterPtr;
140 const uint64_t
Magic;
142 const uint64_t DataSize;
143 const uint64_t CountersSize;
144 const uint64_t NamesSize;
145 const uint64_t CountersDelta;
146 const uint64_t NamesDelta;
149 bool ShouldSwapBytes;
150 uint64_t CountersDelta;
152 const ProfileData *Data;
153 const ProfileData *DataEnd;
154 const uint64_t *CountersStart;
155 const char *NamesStart;
156 const char *ProfileEnd;
162 : DataBuffer(std::move(DataBuffer)) { }
169 std::error_code readNextHeader(
const char *CurrentPos);
170 std::error_code
readHeader(
const RawHeader &Header);
171 template <
class IntT>
172 IntT swap(IntT
Int)
const {
175 const uint64_t *getCounter(IntPtrT CounterPtr)
const {
176 ptrdiff_t Offset = (swap(CounterPtr) - CountersDelta) /
sizeof(uint64_t);
177 return CountersStart + Offset;
179 const char *getName(IntPtrT NamePtr)
const {
180 ptrdiff_t Offset = (swap(NamePtr) - NamesDelta) /
sizeof(
char);
181 return NamesStart + Offset;
188 namespace IndexedInstrProf {
189 enum class HashT : uint32_t;
195 std::vector<InstrProfRecord> DataBuffer;
197 unsigned FormatVersion;
201 : HashType(HashType), FormatVersion(FormatVersion) {}
215 static std::pair<offset_type, offset_type>
217 using namespace support;
218 offset_type KeyLen = endian::readNext<offset_type, little, unaligned>(D);
219 offset_type DataLen = endian::readNext<offset_type, little, unaligned>(D);
220 return std::make_pair(KeyLen, DataLen);
230 typedef OnDiskIterableChainedHashTable<InstrProfLookupTrait>
237 std::unique_ptr<MemoryBuffer> DataBuffer;
239 std::unique_ptr<InstrProfReaderIndex> Index;
243 uint64_t FormatVersion;
245 uint64_t MaxFunctionCount;
251 : DataBuffer(std::move(DataBuffer)), Index(nullptr) {}
257 std::error_code readHeader()
override;
263 std::vector<uint64_t> &Counts);
269 create(std::string Path);
272 create(std::unique_ptr<MemoryBuffer> Buffer);
std::error_code readNextRecord(InstrProfRecord &Record) override
Read a single record.
Represents either an error or a value T.
std::error_code readHeader() override
Read the header.
virtual std::error_code readHeader()=0
Read the header. Required before reading first record.
Defines facilities for reading and writing on-disk hash tables.
uint64_t getMaximumFunctionCount()
Return the maximum of all known function counts.
A forward iterator which reads text lines from a buffer.
std::error_code success()
Clear the current error code and return a successful one.
InstrProfIterator(InstrProfReader *Reader)
bool operator==(const InstrProfIterator &RHS)
std::error_code readNextRecord(InstrProfRecord &Record) override
Read a single record.
bool operator!=(const InstrProfIterator &RHS)
bool isEOF()
Return true if the reader has finished reading the profile data.
std::error_code error(std::error_code EC)
Set the current std::error_code and return same.
InstrProfLookupTrait::data_type data_type
RawInstrProfReader< uint32_t > RawInstrProfReader32
InstrProfLookupTrait::offset_type offset_type
Iterates over all the entries in the table, returning the data.
RawInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer)
static cl::opt< std::string > FuncName("cppfname", cl::desc("Specify the name of the generated function"), cl::value_desc("function name"))
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static std::pair< offset_type, offset_type > ReadKeyDataLength(const unsigned char *&D)
Reader for the simple text based instrprof format.
static bool hasFormat(const MemoryBuffer &DataBuffer)
StringRef ReadKey(const unsigned char *D, offset_type N)
Base class and interface for reading profiling data of any known instrprof format.
OnDiskIterableChainedHashTable< InstrProfLookupTrait > InstrProfReaderIndex
static const char *const Magic
InstrProfRecord * operator->()
Trait for lookups into the on-disk hash table for the binary instrprof format.
A file format agnostic iterator over profiling data.
Reader for the raw instrprof binary format from runtime.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
static ErrorOr< std::unique_ptr< InstrProfReader > > create(std::string Path)
Factory method to create an appropriately typed reader for the given instrprof file.
std::error_code readHeader() override
Read the header. Required before reading first record.
unsigned char getSwappedBytes(unsigned char C)
RawInstrProfReader< uint64_t > RawInstrProfReader64
TextInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer_)
virtual std::error_code readNextRecord(InstrProfRecord &Record)=0
Read a single record.
std::error_code getError()
Get the current error code.
Profiling information for a single function.
StringRef external_key_type
ArrayRef< InstrProfRecord > data_type
static uint64_t ComputeHash(HashT Type, StringRef K)
InstrProfIterator begin()
Iterator over profile data.
Provides ErrorOr<T> smart pointer.
InstrProfIterator & operator++()
bool hasError()
Return true if the reader encountered an error reading profiling data.
static StringRef GetInternalKey(StringRef K)
InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion)
StringRef internal_key_type
static bool EqualKey(StringRef A, StringRef B)
IndexedInstrProfReader(std::unique_ptr< MemoryBuffer > DataBuffer)
StringRef - Represent a constant reference to a string, i.e.
Reader for the indexed binary instrprof format.
InstrProfRecord & operator*()
virtual ~InstrProfReader()