mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-29 13:18:23 +00:00
Revert "InstrProf: When reading, copy the data instead of taking a reference. NFC"
Seems like MSVC doesn't like this: InstrProf.h(49) : error C2614: 'llvm::InstrProfRecord' : illegal member initialization: 'Hash' is not a base or member This reverts r240206. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240208 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -16,9 +16,7 @@
|
|||||||
#ifndef LLVM_PROFILEDATA_INSTRPROF_H_
|
#ifndef LLVM_PROFILEDATA_INSTRPROF_H_
|
||||||
#define LLVM_PROFILEDATA_INSTRPROF_H_
|
#define LLVM_PROFILEDATA_INSTRPROF_H_
|
||||||
|
|
||||||
#include "llvm/ADT/StringRef.h"
|
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
const std::error_category &instrprof_category();
|
const std::error_category &instrprof_category();
|
||||||
@@ -43,16 +41,6 @@ inline std::error_code make_error_code(instrprof_error E) {
|
|||||||
return std::error_code(static_cast<int>(E), instrprof_category());
|
return std::error_code(static_cast<int>(E), instrprof_category());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Profiling information for a single function.
|
|
||||||
struct InstrProfRecord {
|
|
||||||
InstrProfRecord() {}
|
|
||||||
InstrProfRecord(StringRef Name, uint64_t Hash, std::vector<uint64_t> &Counts)
|
|
||||||
: Name(Name), Hash(Hash), Counts(std::move(Counts)) {}
|
|
||||||
StringRef Name;
|
|
||||||
uint64_t Hash;
|
|
||||||
std::vector<uint64_t> Counts;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|||||||
@@ -29,6 +29,16 @@ namespace llvm {
|
|||||||
|
|
||||||
class InstrProfReader;
|
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.
|
/// A file format agnostic iterator over profiling data.
|
||||||
class InstrProfIterator : public std::iterator<std::input_iterator_tag,
|
class InstrProfIterator : public std::iterator<std::input_iterator_tag,
|
||||||
InstrProfRecord> {
|
InstrProfRecord> {
|
||||||
@@ -104,6 +114,8 @@ private:
|
|||||||
std::unique_ptr<MemoryBuffer> DataBuffer;
|
std::unique_ptr<MemoryBuffer> DataBuffer;
|
||||||
/// Iterator over the profile data.
|
/// Iterator over the profile data.
|
||||||
line_iterator Line;
|
line_iterator Line;
|
||||||
|
/// The current set of counter values.
|
||||||
|
std::vector<uint64_t> Counts;
|
||||||
|
|
||||||
TextInstrProfReader(const TextInstrProfReader &) = delete;
|
TextInstrProfReader(const TextInstrProfReader &) = delete;
|
||||||
TextInstrProfReader &operator=(const TextInstrProfReader &) = delete;
|
TextInstrProfReader &operator=(const TextInstrProfReader &) = delete;
|
||||||
@@ -129,6 +141,8 @@ class RawInstrProfReader : public InstrProfReader {
|
|||||||
private:
|
private:
|
||||||
/// The profile data file contents.
|
/// The profile data file contents.
|
||||||
std::unique_ptr<MemoryBuffer> DataBuffer;
|
std::unique_ptr<MemoryBuffer> DataBuffer;
|
||||||
|
/// The current set of counter values.
|
||||||
|
std::vector<uint64_t> Counts;
|
||||||
struct ProfileData {
|
struct ProfileData {
|
||||||
const uint32_t NameSize;
|
const uint32_t NameSize;
|
||||||
const uint32_t NumCounters;
|
const uint32_t NumCounters;
|
||||||
@@ -192,16 +206,17 @@ enum class HashT : uint32_t;
|
|||||||
/// Trait for lookups into the on-disk hash table for the binary instrprof
|
/// Trait for lookups into the on-disk hash table for the binary instrprof
|
||||||
/// format.
|
/// format.
|
||||||
class InstrProfLookupTrait {
|
class InstrProfLookupTrait {
|
||||||
std::vector<InstrProfRecord> DataBuffer;
|
std::vector<uint64_t> DataBuffer;
|
||||||
IndexedInstrProf::HashT HashType;
|
IndexedInstrProf::HashT HashType;
|
||||||
unsigned FormatVersion;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion)
|
InstrProfLookupTrait(IndexedInstrProf::HashT HashType) : HashType(HashType) {}
|
||||||
: HashType(HashType), FormatVersion(FormatVersion) {}
|
|
||||||
|
|
||||||
typedef ArrayRef<InstrProfRecord> data_type;
|
|
||||||
|
|
||||||
|
struct data_type {
|
||||||
|
data_type(StringRef Name, ArrayRef<uint64_t> Data)
|
||||||
|
: Name(Name), Data(Data) {}
|
||||||
|
StringRef Name;
|
||||||
|
ArrayRef<uint64_t> Data;
|
||||||
|
};
|
||||||
typedef StringRef internal_key_type;
|
typedef StringRef internal_key_type;
|
||||||
typedef StringRef external_key_type;
|
typedef StringRef external_key_type;
|
||||||
typedef uint64_t hash_value_type;
|
typedef uint64_t hash_value_type;
|
||||||
@@ -224,9 +239,22 @@ public:
|
|||||||
return StringRef((const char *)D, N);
|
return StringRef((const char *)D, N);
|
||||||
}
|
}
|
||||||
|
|
||||||
data_type ReadData(StringRef K, const unsigned char *D, offset_type N);
|
data_type ReadData(StringRef K, const unsigned char *D, offset_type N) {
|
||||||
};
|
DataBuffer.clear();
|
||||||
|
if (N % sizeof(uint64_t))
|
||||||
|
// The data is corrupt, don't try to read it.
|
||||||
|
return data_type("", DataBuffer);
|
||||||
|
|
||||||
|
using namespace support;
|
||||||
|
// We just treat the data as opaque here. It's simpler to handle in
|
||||||
|
// IndexedInstrProfReader.
|
||||||
|
unsigned NumEntries = N / sizeof(uint64_t);
|
||||||
|
DataBuffer.reserve(NumEntries);
|
||||||
|
for (unsigned I = 0; I < NumEntries; ++I)
|
||||||
|
DataBuffer.push_back(endian::readNext<uint64_t, little, unaligned>(D));
|
||||||
|
return data_type(K, DataBuffer);
|
||||||
|
}
|
||||||
|
};
|
||||||
typedef OnDiskIterableChainedHashTable<InstrProfLookupTrait>
|
typedef OnDiskIterableChainedHashTable<InstrProfLookupTrait>
|
||||||
InstrProfReaderIndex;
|
InstrProfReaderIndex;
|
||||||
|
|
||||||
@@ -239,6 +267,8 @@ private:
|
|||||||
std::unique_ptr<InstrProfReaderIndex> Index;
|
std::unique_ptr<InstrProfReaderIndex> Index;
|
||||||
/// Iterator over the profile data.
|
/// Iterator over the profile data.
|
||||||
InstrProfReaderIndex::data_iterator RecordIterator;
|
InstrProfReaderIndex::data_iterator RecordIterator;
|
||||||
|
/// Offset into our current data set.
|
||||||
|
size_t CurrentOffset;
|
||||||
/// The file format version of the profile data.
|
/// The file format version of the profile data.
|
||||||
uint64_t FormatVersion;
|
uint64_t FormatVersion;
|
||||||
/// The maximal execution count among all functions.
|
/// The maximal execution count among all functions.
|
||||||
@@ -248,7 +278,7 @@ private:
|
|||||||
IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
|
IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
|
||||||
public:
|
public:
|
||||||
IndexedInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer)
|
IndexedInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer)
|
||||||
: DataBuffer(std::move(DataBuffer)), Index(nullptr) {}
|
: DataBuffer(std::move(DataBuffer)), Index(nullptr), CurrentOffset(0) {}
|
||||||
|
|
||||||
/// Return true if the given buffer is in an indexed instrprof format.
|
/// Return true if the given buffer is in an indexed instrprof format.
|
||||||
static bool hasFormat(const MemoryBuffer &DataBuffer);
|
static bool hasFormat(const MemoryBuffer &DataBuffer);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "llvm/ProfileData/InstrProfReader.h"
|
#include "llvm/ProfileData/InstrProfReader.h"
|
||||||
#include "InstrProfIndexed.h"
|
#include "InstrProfIndexed.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
|
#include "llvm/ProfileData/InstrProf.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@@ -125,16 +126,18 @@ std::error_code TextInstrProfReader::readNextRecord(InstrProfRecord &Record) {
|
|||||||
return error(instrprof_error::malformed);
|
return error(instrprof_error::malformed);
|
||||||
|
|
||||||
// Read each counter and fill our internal storage with the values.
|
// Read each counter and fill our internal storage with the values.
|
||||||
Record.Counts.clear();
|
Counts.clear();
|
||||||
Record.Counts.reserve(NumCounters);
|
Counts.reserve(NumCounters);
|
||||||
for (uint64_t I = 0; I < NumCounters; ++I) {
|
for (uint64_t I = 0; I < NumCounters; ++I) {
|
||||||
if (Line.is_at_end())
|
if (Line.is_at_end())
|
||||||
return error(instrprof_error::truncated);
|
return error(instrprof_error::truncated);
|
||||||
uint64_t Count;
|
uint64_t Count;
|
||||||
if ((Line++)->getAsInteger(10, Count))
|
if ((Line++)->getAsInteger(10, Count))
|
||||||
return error(instrprof_error::malformed);
|
return error(instrprof_error::malformed);
|
||||||
Record.Counts.push_back(Count);
|
Counts.push_back(Count);
|
||||||
}
|
}
|
||||||
|
// Give the record a reference to our internal counter storage.
|
||||||
|
Record.Counts = Counts;
|
||||||
|
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
@@ -277,10 +280,11 @@ RawInstrProfReader<IntPtrT>::readNextRecord(InstrProfRecord &Record) {
|
|||||||
Record.Hash = swap(Data->FuncHash);
|
Record.Hash = swap(Data->FuncHash);
|
||||||
Record.Name = RawName;
|
Record.Name = RawName;
|
||||||
if (ShouldSwapBytes) {
|
if (ShouldSwapBytes) {
|
||||||
Record.Counts.clear();
|
Counts.clear();
|
||||||
Record.Counts.reserve(RawCounts.size());
|
Counts.reserve(RawCounts.size());
|
||||||
for (uint64_t Count : RawCounts)
|
for (uint64_t Count : RawCounts)
|
||||||
Record.Counts.push_back(swap(Count));
|
Counts.push_back(swap(Count));
|
||||||
|
Record.Counts = Counts;
|
||||||
} else
|
} else
|
||||||
Record.Counts = RawCounts;
|
Record.Counts = RawCounts;
|
||||||
|
|
||||||
@@ -299,49 +303,6 @@ InstrProfLookupTrait::ComputeHash(StringRef K) {
|
|||||||
return IndexedInstrProf::ComputeHash(HashType, K);
|
return IndexedInstrProf::ComputeHash(HashType, K);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef InstrProfLookupTrait::data_type data_type;
|
|
||||||
typedef InstrProfLookupTrait::offset_type offset_type;
|
|
||||||
|
|
||||||
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();
|
|
||||||
uint64_t NumCounts;
|
|
||||||
uint64_t NumEntries = N / sizeof(uint64_t);
|
|
||||||
std::vector<uint64_t> CounterBuffer;
|
|
||||||
for (uint64_t I = 0; I < NumEntries; I += NumCounts) {
|
|
||||||
using namespace support;
|
|
||||||
// The function hash comes first.
|
|
||||||
uint64_t Hash = endian::readNext<uint64_t, little, unaligned>(D);
|
|
||||||
|
|
||||||
if (++I >= NumEntries)
|
|
||||||
return data_type();
|
|
||||||
|
|
||||||
// In v1, we have at least one count.
|
|
||||||
// Later, we have the number of counts.
|
|
||||||
NumCounts = (1 == FormatVersion)
|
|
||||||
? NumEntries - I
|
|
||||||
: endian::readNext<uint64_t, little, unaligned>(D);
|
|
||||||
if (1 != FormatVersion)
|
|
||||||
++I;
|
|
||||||
|
|
||||||
// If we have more counts than data, this is bogus.
|
|
||||||
if (I + NumCounts > NumEntries)
|
|
||||||
return data_type();
|
|
||||||
|
|
||||||
CounterBuffer.clear();
|
|
||||||
for (unsigned J = 0; J < NumCounts; ++J)
|
|
||||||
CounterBuffer.push_back(endian::readNext<uint64_t, little, unaligned>(D));
|
|
||||||
|
|
||||||
DataBuffer.push_back(InstrProfRecord(K, Hash, CounterBuffer));
|
|
||||||
}
|
|
||||||
return DataBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IndexedInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) {
|
bool IndexedInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) {
|
||||||
if (DataBuffer.getBufferSize() < 8)
|
if (DataBuffer.getBufferSize() < 8)
|
||||||
return false;
|
return false;
|
||||||
@@ -381,9 +342,8 @@ std::error_code IndexedInstrProfReader::readHeader() {
|
|||||||
uint64_t HashOffset = endian::readNext<uint64_t, little, unaligned>(Cur);
|
uint64_t HashOffset = endian::readNext<uint64_t, little, unaligned>(Cur);
|
||||||
|
|
||||||
// The rest of the file is an on disk hash table.
|
// The rest of the file is an on disk hash table.
|
||||||
Index.reset(InstrProfReaderIndex::Create(
|
Index.reset(InstrProfReaderIndex::Create(Start + HashOffset, Cur, Start,
|
||||||
Start + HashOffset, Cur, Start,
|
InstrProfLookupTrait(HashType)));
|
||||||
InstrProfLookupTrait(HashType, FormatVersion)));
|
|
||||||
// Set up our iterator for readNextRecord.
|
// Set up our iterator for readNextRecord.
|
||||||
RecordIterator = Index->data_begin();
|
RecordIterator = Index->data_begin();
|
||||||
|
|
||||||
@@ -397,14 +357,21 @@ std::error_code IndexedInstrProfReader::getFunctionCounts(
|
|||||||
return error(instrprof_error::unknown_function);
|
return error(instrprof_error::unknown_function);
|
||||||
|
|
||||||
// Found it. Look for counters with the right hash.
|
// Found it. Look for counters with the right hash.
|
||||||
ArrayRef<InstrProfRecord> Data = (*Iter);
|
ArrayRef<uint64_t> Data = (*Iter).Data;
|
||||||
if (Data.empty())
|
uint64_t NumCounts;
|
||||||
|
for (uint64_t I = 0, E = Data.size(); I != E; I += NumCounts) {
|
||||||
|
// The function hash comes first.
|
||||||
|
uint64_t FoundHash = Data[I++];
|
||||||
|
// In v1, we have at least one count. Later, we have the number of counts.
|
||||||
|
if (I == E)
|
||||||
|
return error(instrprof_error::malformed);
|
||||||
|
NumCounts = FormatVersion == 1 ? E - I : Data[I++];
|
||||||
|
// If we have more counts than data, this is bogus.
|
||||||
|
if (I + NumCounts > E)
|
||||||
return error(instrprof_error::malformed);
|
return error(instrprof_error::malformed);
|
||||||
|
|
||||||
for (unsigned I = 0, E = Data.size(); I < E; ++I) {
|
|
||||||
// Check for a match and fill the vector if there is one.
|
// Check for a match and fill the vector if there is one.
|
||||||
if (Data[I].Hash == FuncHash) {
|
if (FoundHash == FuncHash) {
|
||||||
Counts = Data[I].Counts;
|
Counts = Data.slice(I, NumCounts);
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -417,15 +384,30 @@ IndexedInstrProfReader::readNextRecord(InstrProfRecord &Record) {
|
|||||||
if (RecordIterator == Index->data_end())
|
if (RecordIterator == Index->data_end())
|
||||||
return error(instrprof_error::eof);
|
return error(instrprof_error::eof);
|
||||||
|
|
||||||
if ((*RecordIterator).empty())
|
// Record the current function name.
|
||||||
return error(instrprof_error::malformed);
|
Record.Name = (*RecordIterator).Name;
|
||||||
|
|
||||||
static unsigned RecordIndex = 0;
|
ArrayRef<uint64_t> Data = (*RecordIterator).Data;
|
||||||
ArrayRef<InstrProfRecord> Data = (*RecordIterator);
|
// Valid data starts with a hash and either a count or the number of counts.
|
||||||
Record = Data[RecordIndex++];
|
if (CurrentOffset + 1 > Data.size())
|
||||||
if (RecordIndex >= Data.size()) {
|
return error(instrprof_error::malformed);
|
||||||
|
// First we have a function hash.
|
||||||
|
Record.Hash = Data[CurrentOffset++];
|
||||||
|
// In version 1 we knew the number of counters implicitly, but in newer
|
||||||
|
// versions we store the number of counters next.
|
||||||
|
uint64_t NumCounts =
|
||||||
|
FormatVersion == 1 ? Data.size() - CurrentOffset : Data[CurrentOffset++];
|
||||||
|
if (CurrentOffset + NumCounts > Data.size())
|
||||||
|
return error(instrprof_error::malformed);
|
||||||
|
// And finally the counts themselves.
|
||||||
|
Record.Counts = Data.slice(CurrentOffset, NumCounts);
|
||||||
|
|
||||||
|
// If we've exhausted this function's data, increment the record.
|
||||||
|
CurrentOffset += NumCounts;
|
||||||
|
if (CurrentOffset == Data.size()) {
|
||||||
++RecordIterator;
|
++RecordIterator;
|
||||||
RecordIndex = 0;
|
CurrentOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user