summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/ProfileData/InstrProfWriter.h7
-rw-r--r--llvm/lib/ProfileData/InstrProfWriter.cpp26
2 files changed, 21 insertions, 12 deletions
diff --git a/llvm/include/llvm/ProfileData/InstrProfWriter.h b/llvm/include/llvm/ProfileData/InstrProfWriter.h
index 7e4f6011a39..5c21bd12d10 100644
--- a/llvm/include/llvm/ProfileData/InstrProfWriter.h
+++ b/llvm/include/llvm/ProfileData/InstrProfWriter.h
@@ -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
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 4c7f5de26aa..8557d8083e2 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -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}};
OpenPOWER on IntegriCloud