//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_PROFILEDATA_INSTRPROF_READER_H_
-#define LLVM_PROFILEDATA_INSTRPROF_READER_H_
+#ifndef LLVM_PROFILEDATA_INSTRPROFREADER_H
+#define LLVM_PROFILEDATA_INSTRPROFREADER_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/EndianStream.h"
+#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/EndianStream.h"
#include "llvm/Support/OnDiskHashTable.h"
-
#include <iterator>
namespace llvm {
class InstrProfReader;
-/// Profiling information for a single function.
-struct InstrProfRecord {
- InstrProfRecord() {}
- InstrProfRecord(StringRef Name, uint64_t Hash, ArrayRef<uint64_t> Counts)
- : Name(Name), Hash(Hash), Counts(Counts) {}
- StringRef Name;
- uint64_t Hash;
- ArrayRef<uint64_t> Counts;
-};
-
/// A file format agnostic iterator over profiling data.
class InstrProfIterator : public std::iterator<std::input_iterator_tag,
InstrProfRecord> {
/// Factory method to create an appropriately typed reader for the given
/// instrprof file.
- static std::error_code create(std::string Path,
- std::unique_ptr<InstrProfReader> &Result);
+ static ErrorOr<std::unique_ptr<InstrProfReader>> create(std::string Path);
+
+ static ErrorOr<std::unique_ptr<InstrProfReader>>
+ create(std::unique_ptr<MemoryBuffer> Buffer);
};
/// Reader for the simple text based instrprof format.
std::unique_ptr<MemoryBuffer> DataBuffer;
/// Iterator over the profile data.
line_iterator Line;
- /// The current set of counter values.
- std::vector<uint64_t> Counts;
- TextInstrProfReader(const TextInstrProfReader &) LLVM_DELETED_FUNCTION;
- TextInstrProfReader &operator=(const TextInstrProfReader &)
- LLVM_DELETED_FUNCTION;
+ TextInstrProfReader(const TextInstrProfReader &) = delete;
+ TextInstrProfReader &operator=(const TextInstrProfReader &) = delete;
public:
TextInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer_)
- : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, '#') {}
+ : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {}
/// Read the header.
std::error_code readHeader() override { return success(); }
private:
/// The profile data file contents.
std::unique_ptr<MemoryBuffer> DataBuffer;
- /// The current set of counter values.
- std::vector<uint64_t> Counts;
struct ProfileData {
const uint32_t NameSize;
const uint32_t NumCounters;
const char *NamesStart;
const char *ProfileEnd;
- RawInstrProfReader(const RawInstrProfReader &) LLVM_DELETED_FUNCTION;
- RawInstrProfReader &operator=(const RawInstrProfReader &)
- LLVM_DELETED_FUNCTION;
+ RawInstrProfReader(const RawInstrProfReader &) = delete;
+ RawInstrProfReader &operator=(const RawInstrProfReader &) = delete;
public:
RawInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer)
: DataBuffer(std::move(DataBuffer)) { }
/// Trait for lookups into the on-disk hash table for the binary instrprof
/// format.
class InstrProfLookupTrait {
- std::vector<uint64_t> CountBuffer;
+ std::vector<InstrProfRecord> DataBuffer;
IndexedInstrProf::HashT HashType;
+ unsigned FormatVersion;
+
public:
- InstrProfLookupTrait(IndexedInstrProf::HashT HashType) : HashType(HashType) {}
+ InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion)
+ : HashType(HashType), FormatVersion(FormatVersion) {}
+
+ typedef ArrayRef<InstrProfRecord> data_type;
- typedef InstrProfRecord data_type;
typedef StringRef internal_key_type;
typedef StringRef external_key_type;
typedef uint64_t hash_value_type;
return StringRef((const char *)D, N);
}
- InstrProfRecord ReadData(StringRef K, const unsigned char *D, offset_type N) {
- if (N < 2 * sizeof(uint64_t) || N % sizeof(uint64_t)) {
- // The data is corrupt, don't try to read it.
- CountBuffer.clear();
- return InstrProfRecord("", 0, CountBuffer);
- }
-
- using namespace support;
-
- // The first stored value is the hash.
- uint64_t Hash = endian::readNext<uint64_t, little, unaligned>(D);
- // Each counter follows.
- unsigned NumCounters = N / sizeof(uint64_t) - 1;
- CountBuffer.clear();
- CountBuffer.reserve(NumCounters - 1);
- for (unsigned I = 0; I < NumCounters; ++I)
- CountBuffer.push_back(endian::readNext<uint64_t, little, unaligned>(D));
-
- return InstrProfRecord(K, Hash, CountBuffer);
- }
+ data_type ReadData(StringRef K, const unsigned char *D, offset_type N);
};
+
typedef OnDiskIterableChainedHashTable<InstrProfLookupTrait>
InstrProfReaderIndex;
std::unique_ptr<InstrProfReaderIndex> Index;
/// Iterator over the profile data.
InstrProfReaderIndex::data_iterator RecordIterator;
- /// The maximal execution count among all fucntions.
+ /// The file format version of the profile data.
+ uint64_t FormatVersion;
+ /// The maximal execution count among all functions.
uint64_t MaxFunctionCount;
- IndexedInstrProfReader(const IndexedInstrProfReader &) LLVM_DELETED_FUNCTION;
- IndexedInstrProfReader &operator=(const IndexedInstrProfReader &)
- LLVM_DELETED_FUNCTION;
+ IndexedInstrProfReader(const IndexedInstrProfReader &) = delete;
+ IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
public:
IndexedInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer)
: DataBuffer(std::move(DataBuffer)), Index(nullptr) {}
std::error_code readNextRecord(InstrProfRecord &Record) override;
/// Fill Counts with the profile data for the given function name.
- std::error_code getFunctionCounts(StringRef FuncName, uint64_t &FuncHash,
+ std::error_code getFunctionCounts(StringRef FuncName, uint64_t FuncHash,
std::vector<uint64_t> &Counts);
/// Return the maximum of all known function counts.
uint64_t getMaximumFunctionCount() { return MaxFunctionCount; }
/// Factory method to create an indexed reader.
- static std::error_code
- create(std::string Path, std::unique_ptr<IndexedInstrProfReader> &Result);
+ static ErrorOr<std::unique_ptr<IndexedInstrProfReader>>
+ create(std::string Path);
+
+ static ErrorOr<std::unique_ptr<IndexedInstrProfReader>>
+ create(std::unique_ptr<MemoryBuffer> Buffer);
};
} // end namespace llvm
-#endif // LLVM_PROFILEDATA_INSTRPROF_READER_H_
+#endif