1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 12:12:47 +01:00

[PGO] Remove use of static variable. /NFC

Make the variable a member of  the writer trait object owned
now by the writer. Also use a different generator interface
to pass the infoObject from the writer. 

llvm-svn: 258544
This commit is contained in:
Xinliang David Li 2016-01-22 20:25:56 +00:00
parent 8af301da92
commit 42a10f05d4
2 changed files with 21 additions and 12 deletions

View File

@ -25,6 +25,8 @@ namespace llvm {
/// Writer for instrumentation based profile data.
class ProfOStream;
class InstrProfRecordWriterTrait;
class InstrProfWriter {
public:
typedef SmallDenseMap<uint64_t, InstrProfRecord, 1> ProfilingData;
@ -32,9 +34,12 @@ public:
private:
StringMap<ProfilingData> FunctionData;
uint64_t MaxFunctionCount;
// Use raw pointer here for the incomplete type object.
InstrProfRecordWriterTrait *InfoObj;
public:
InstrProfWriter() : MaxFunctionCount(0) {}
InstrProfWriter();
~InstrProfWriter();
/// Add function counts for the given function. If there are already counts
/// for this function and the hash and number of counts match, each counter is

View File

@ -71,12 +71,8 @@ public:
raw_ostream &OS;
support::endian::Writer<support::little> LE;
};
}
namespace {
static support::endianness ValueProfDataEndianness = support::little;
class InstrProfRecordTrait {
class InstrProfRecordWriterTrait {
public:
typedef StringRef key_type;
typedef StringRef key_type_ref;
@ -87,6 +83,9 @@ public:
typedef uint64_t hash_value_type;
typedef uint64_t offset_type;
support::endianness ValueProfDataEndianness;
InstrProfRecordWriterTrait() : ValueProfDataEndianness(support::little) {}
static hash_value_type ComputeHash(key_type_ref K) {
return IndexedInstrProf::ComputeHash(K);
}
@ -114,12 +113,11 @@ public:
return std::make_pair(N, M);
}
static void EmitKey(raw_ostream &Out, key_type_ref K, offset_type N){
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type N) {
Out.write(K.data(), N);
}
static void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V,
offset_type) {
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type) {
using namespace llvm::support;
endian::Writer<little> LE(Out);
for (const auto &ProfileData : *V) {
@ -141,10 +139,16 @@ public:
};
}
InstrProfWriter::InstrProfWriter()
: FunctionData(), MaxFunctionCount(0),
InfoObj(new InstrProfRecordWriterTrait()) {}
InstrProfWriter::~InstrProfWriter() { delete InfoObj; }
// Internal interface for testing purpose only.
void InstrProfWriter::setValueProfDataEndianness(
support::endianness Endianness) {
ValueProfDataEndianness = Endianness;
InfoObj->ValueProfDataEndianness = Endianness;
}
std::error_code InstrProfWriter::addRecord(InstrProfRecord &&I,
@ -181,7 +185,7 @@ std::error_code InstrProfWriter::addRecord(InstrProfRecord &&I,
}
void InstrProfWriter::writeImpl(ProfOStream &OS) {
OnDiskChainedHashTableGenerator<InstrProfRecordTrait> Generator;
OnDiskChainedHashTableGenerator<InstrProfRecordWriterTrait> Generator;
// Populate the hash table generator.
for (const auto &I : FunctionData)
Generator.insert(I.getKey(), &I.getValue());
@ -205,7 +209,7 @@ void InstrProfWriter::writeImpl(ProfOStream &OS) {
// Reserve the space for HashOffset field.
OS.write(0);
// Write the hash table.
uint64_t HashTableStart = Generator.Emit(OS.OS);
uint64_t HashTableStart = Generator.Emit(OS.OS, *InfoObj);
// Now do the final patch:
PatchItem PatchItems[1] = {{HashTableStartLoc, &HashTableStart, 1}};