[llvm] r258544 - [PGO] Remove use of static variable. /NFC
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 22 12:25:58 PST 2016
Author: davidxl
Date: Fri Jan 22 14:25:56 2016
New Revision: 258544
URL: http://llvm.org/viewvc/llvm-project?rev=258544&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h
llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
Modified: llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h?rev=258544&r1=258543&r2=258544&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProfWriter.h Fri Jan 22 14:25:56 2016
@@ -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
Modified: llvm/trunk/lib/ProfileData/InstrProfWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfWriter.cpp?rev=258544&r1=258543&r2=258544&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfWriter.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfWriter.cpp Fri Jan 22 14:25:56 2016
@@ -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::addReco
}
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(ProfOStr
// 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}};
More information about the llvm-commits
mailing list