Remove specializations of ProfileSummary

This removes the subclasses of ProfileSummary, moves the members of the derived classes to the base class.

Differential Revision: http://reviews.llvm.org/D20390

llvm-svn: 270143
This commit is contained in:
Easwaran Raman 2016-05-19 21:53:28 +00:00
parent 476c0afc01
commit 7cefdb81c5
14 changed files with 101 additions and 220 deletions

View File

@ -50,29 +50,23 @@ public:
private: private:
const Kind PSK; const Kind PSK;
static const char *KindStr[2]; static const char *KindStr[2];
protected:
SummaryEntryVector DetailedSummary; SummaryEntryVector DetailedSummary;
uint64_t TotalCount, MaxCount, MaxFunctionCount; uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount;
uint32_t NumCounts, NumFunctions; uint32_t NumCounts, NumFunctions;
ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
uint64_t TotalCount, uint64_t MaxCount,
uint64_t MaxFunctionCount, uint32_t NumCounts,
uint32_t NumFunctions)
: PSK(K), DetailedSummary(DetailedSummary), TotalCount(TotalCount),
MaxCount(MaxCount), MaxFunctionCount(MaxFunctionCount),
NumCounts(NumCounts), NumFunctions(NumFunctions) {}
~ProfileSummary() = default;
/// \brief Return metadata specific to the profile format.
/// Derived classes implement this method to return a vector of Metadata.
virtual std::vector<Metadata *> getFormatSpecificMD(LLVMContext &Context) = 0;
/// \brief Return detailed summary as metadata. /// \brief Return detailed summary as metadata.
Metadata *getDetailedSummaryMD(LLVMContext &Context); Metadata *getDetailedSummaryMD(LLVMContext &Context);
public: public:
static const int Scale = 1000000; static const int Scale = 1000000;
ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
uint64_t TotalCount, uint64_t MaxCount,
uint64_t MaxInternalCount, uint64_t MaxFunctionCount,
uint32_t NumCounts, uint32_t NumFunctions)
: PSK(K), DetailedSummary(DetailedSummary), TotalCount(TotalCount),
MaxCount(MaxCount), MaxInternalCount(MaxInternalCount),
MaxFunctionCount(MaxFunctionCount), NumCounts(NumCounts),
NumFunctions(NumFunctions) {}
Kind getKind() const { return PSK; } Kind getKind() const { return PSK; }
const char *getKindStr() const { return KindStr[PSK]; }
/// \brief Return summary information as metadata. /// \brief Return summary information as metadata.
Metadata *getMD(LLVMContext &Context); Metadata *getMD(LLVMContext &Context);
/// \brief Construct profile summary from metdata. /// \brief Construct profile summary from metdata.
@ -80,49 +74,10 @@ public:
SummaryEntryVector &getDetailedSummary() { return DetailedSummary; } SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
uint32_t getNumFunctions() { return NumFunctions; } uint32_t getNumFunctions() { return NumFunctions; }
uint64_t getMaxFunctionCount() { return MaxFunctionCount; } uint64_t getMaxFunctionCount() { return MaxFunctionCount; }
}; uint32_t getNumCounts() { return NumCounts; }
class InstrProfSummary final : public ProfileSummary {
uint64_t MaxInternalBlockCount;
protected:
std::vector<Metadata *> getFormatSpecificMD(LLVMContext &Context) override;
public:
InstrProfSummary(uint64_t TotalCount, uint64_t MaxBlockCount,
uint64_t MaxInternalBlockCount, uint64_t MaxFunctionCount,
uint32_t NumBlocks, uint32_t NumFunctions,
SummaryEntryVector Summary)
: ProfileSummary(PSK_Instr, Summary, TotalCount, MaxBlockCount,
MaxFunctionCount, NumBlocks, NumFunctions),
MaxInternalBlockCount(MaxInternalBlockCount) {}
static bool classof(const ProfileSummary *PS) {
return PS->getKind() == PSK_Instr;
}
uint32_t getNumBlocks() { return NumCounts; }
uint64_t getTotalCount() { return TotalCount; } uint64_t getTotalCount() { return TotalCount; }
uint64_t getMaxBlockCount() { return MaxCount; } uint64_t getMaxCount() { return MaxCount; }
uint64_t getMaxInternalBlockCount() { return MaxInternalBlockCount; } uint64_t getMaxInternalCount() { return MaxInternalCount; }
};
class SampleProfileSummary final : public ProfileSummary {
protected:
std::vector<Metadata *> getFormatSpecificMD(LLVMContext &Context) override;
public:
uint32_t getNumLinesWithSamples() { return NumCounts; }
uint64_t getTotalSamples() { return TotalCount; }
uint64_t getMaxSamplesPerLine() { return MaxCount; }
SampleProfileSummary(uint64_t TotalSamples, uint64_t MaxSamplesPerLine,
uint64_t MaxFunctionCount, int32_t NumLinesWithSamples,
uint32_t NumFunctions,
SummaryEntryVector DetailedSummary)
: ProfileSummary(PSK_Sample, DetailedSummary, TotalSamples,
MaxSamplesPerLine, MaxFunctionCount, NumLinesWithSamples,
NumFunctions) {}
static bool classof(const ProfileSummary *PS) {
return PS->getKind() == PSK_Sample;
}
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -364,7 +364,7 @@ private:
/// The index into the profile data. /// The index into the profile data.
std::unique_ptr<InstrProfReaderIndexBase> Index; std::unique_ptr<InstrProfReaderIndexBase> Index;
/// Profile summary data. /// Profile summary data.
std::unique_ptr<InstrProfSummary> Summary; std::unique_ptr<ProfileSummary> Summary;
IndexedInstrProfReader(const IndexedInstrProfReader &) = delete; IndexedInstrProfReader(const IndexedInstrProfReader &) = delete;
IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete; IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
@ -417,7 +417,7 @@ public:
// to be used by llvm-profdata (for dumping). Avoid using this when // to be used by llvm-profdata (for dumping). Avoid using this when
// the client is the compiler. // the client is the compiler.
InstrProfSymtab &getSymtab() override; InstrProfSymtab &getSymtab() override;
InstrProfSummary &getSummary() { return *(Summary.get()); } ProfileSummary &getSummary() { return *(Summary.get()); }
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -74,7 +74,7 @@ public:
InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs) InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
: ProfileSummaryBuilder(Cutoffs), MaxInternalBlockCount(0) {} : ProfileSummaryBuilder(Cutoffs), MaxInternalBlockCount(0) {}
void addRecord(const InstrProfRecord &); void addRecord(const InstrProfRecord &);
InstrProfSummary *getSummary(); ProfileSummary *getSummary();
}; };
class SampleProfileSummaryBuilder final : public ProfileSummaryBuilder { class SampleProfileSummaryBuilder final : public ProfileSummaryBuilder {
@ -83,7 +83,7 @@ public:
void addRecord(const sampleprof::FunctionSamples &FS); void addRecord(const sampleprof::FunctionSamples &FS);
SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs) SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
: ProfileSummaryBuilder(Cutoffs) {} : ProfileSummaryBuilder(Cutoffs) {}
SampleProfileSummary *getSummary(); ProfileSummary *getSummary();
}; };
// This is called when a count is seen in the profile. // This is called when a count is seen in the profile.

View File

@ -296,7 +296,7 @@ public:
create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C); create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C);
/// \brief Return the profile summary. /// \brief Return the profile summary.
SampleProfileSummary &getSummary() { return *(Summary.get()); } ProfileSummary &getSummary() { return *(Summary.get()); }
protected: protected:
/// \brief Map every function to its associated profile. /// \brief Map every function to its associated profile.
@ -313,7 +313,7 @@ protected:
std::unique_ptr<MemoryBuffer> Buffer; std::unique_ptr<MemoryBuffer> Buffer;
/// \brief Profile summary information. /// \brief Profile summary information.
std::unique_ptr<SampleProfileSummary> Summary; std::unique_ptr<ProfileSummary> Summary;
/// \brief Compute summary for this profile. /// \brief Compute summary for this profile.
void computeSummary(); void computeSummary();

View File

@ -76,7 +76,7 @@ protected:
std::unique_ptr<raw_ostream> OutputStream; std::unique_ptr<raw_ostream> OutputStream;
/// \brief Profile summary. /// \brief Profile summary.
std::unique_ptr<SampleProfileSummary> Summary; std::unique_ptr<ProfileSummary> Summary;
/// \brief Compute summary for this profile. /// \brief Compute summary for this profile.
void computeSummary(const StringMap<FunctionSamples> &ProfileMap); void computeSummary(const StringMap<FunctionSamples> &ProfileMap);

View File

@ -70,50 +70,18 @@ Metadata *ProfileSummary::getDetailedSummaryMD(LLVMContext &Context) {
// to the kind of profile summary as returned by getFormatSpecificMD. // to the kind of profile summary as returned by getFormatSpecificMD.
Metadata *ProfileSummary::getMD(LLVMContext &Context) { Metadata *ProfileSummary::getMD(LLVMContext &Context) {
std::vector<Metadata *> Components; std::vector<Metadata *> Components;
Components.push_back(getKeyValMD(Context, "ProfileFormat", getKindStr())); Components.push_back(getKeyValMD(Context, "ProfileFormat", KindStr[PSK]));
std::vector<Metadata *> Res = getFormatSpecificMD(Context);
Components.insert(Components.end(), Res.begin(), Res.end());
return MDTuple::get(Context, Components);
}
// Returns a vector of MDTuples specific to InstrProfSummary. The first six
// elements of this vector are (Key, Val) pairs of the six scalar fields of
// InstrProfSummary (TotalCount, MaxBlockCount, MaxInternalBlockCount,
// MaxFunctionCount, NumBlocks, NumFunctions). The last element of this vector
// is an MDTuple returned by getDetailedSummaryMD.
std::vector<Metadata *>
InstrProfSummary::getFormatSpecificMD(LLVMContext &Context) {
std::vector<Metadata *> Components;
Components.push_back(getKeyValMD(Context, "TotalCount", getTotalCount())); Components.push_back(getKeyValMD(Context, "TotalCount", getTotalCount()));
Components.push_back(getKeyValMD(Context, "MaxCount", getMaxCount()));
Components.push_back( Components.push_back(
getKeyValMD(Context, "MaxBlockCount", getMaxBlockCount())); getKeyValMD(Context, "MaxInternalCount", getMaxInternalCount()));
Components.push_back(getKeyValMD(Context, "MaxInternalBlockCount",
getMaxInternalBlockCount()));
Components.push_back( Components.push_back(
getKeyValMD(Context, "MaxFunctionCount", getMaxFunctionCount())); getKeyValMD(Context, "MaxFunctionCount", getMaxFunctionCount()));
Components.push_back(getKeyValMD(Context, "NumBlocks", getNumBlocks())); Components.push_back(getKeyValMD(Context, "NumCounts", getNumCounts()));
Components.push_back(getKeyValMD(Context, "NumFunctions", getNumFunctions())); Components.push_back(getKeyValMD(Context, "NumFunctions", getNumFunctions()));
Components.push_back(getDetailedSummaryMD(Context)); Components.push_back(getDetailedSummaryMD(Context));
return Components; return MDTuple::get(Context, Components);
}
std::vector<Metadata *>
SampleProfileSummary::getFormatSpecificMD(LLVMContext &Context) {
std::vector<Metadata *> Components;
Components.push_back(getKeyValMD(Context, "TotalSamples", getTotalSamples()));
Components.push_back(
getKeyValMD(Context, "MaxSamplesPerLine", getMaxSamplesPerLine()));
Components.push_back(
getKeyValMD(Context, "MaxFunctionCount", getMaxFunctionCount()));
Components.push_back(
getKeyValMD(Context, "NumLinesWithSamples", getNumLinesWithSamples()));
Components.push_back(getKeyValMD(Context, "NumFunctions", NumFunctions));
Components.push_back(getDetailedSummaryMD(Context));
return Components;
} }
// Parse an MDTuple representing (Key, Val) pair. // Parse an MDTuple representing (Key, Val) pair.
@ -175,83 +143,47 @@ static bool getSummaryFromMD(MDTuple *MD, SummaryEntryVector &Summary) {
return true; return true;
} }
// Parse an MDTuple representing an InstrProfSummary object.
static ProfileSummary *getInstrProfSummaryFromMD(MDTuple *Tuple) {
uint64_t NumBlocks, TotalCount, NumFunctions, MaxFunctionCount, MaxBlockCount,
MaxInternalBlockCount;
SummaryEntryVector Summary;
if (Tuple->getNumOperands() != 8)
return nullptr;
// Skip operand 0 which has been already parsed in the caller
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(1)), "TotalCount",
TotalCount))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(2)), "MaxBlockCount",
MaxBlockCount))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(3)), "MaxInternalBlockCount",
MaxInternalBlockCount))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(4)), "MaxFunctionCount",
MaxFunctionCount))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(5)), "NumBlocks", NumBlocks))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(6)), "NumFunctions",
NumFunctions))
return nullptr;
if (!getSummaryFromMD(dyn_cast<MDTuple>(Tuple->getOperand(7)), Summary))
return nullptr;
return new InstrProfSummary(TotalCount, MaxBlockCount, MaxInternalBlockCount,
MaxFunctionCount, NumBlocks, NumFunctions,
Summary);
}
// Parse an MDTuple representing a SampleProfileSummary object.
static ProfileSummary *getSampleProfileSummaryFromMD(MDTuple *Tuple) {
uint64_t TotalSamples, MaxSamplesPerLine, MaxFunctionCount,
NumLinesWithSamples, NumFunctions;
SummaryEntryVector Summary;
if (Tuple->getNumOperands() != 7)
return nullptr;
// Skip operand 0 which has been already parsed in the caller
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(1)), "TotalSamples",
TotalSamples))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(2)), "MaxSamplesPerLine",
MaxSamplesPerLine))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(3)), "MaxFunctionCount",
MaxFunctionCount))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(4)), "NumLinesWithSamples",
NumLinesWithSamples))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(5)), "NumFunctions",
NumFunctions))
return nullptr;
if (!getSummaryFromMD(dyn_cast<MDTuple>(Tuple->getOperand(6)), Summary))
return nullptr;
return new SampleProfileSummary(TotalSamples, MaxSamplesPerLine,
MaxFunctionCount, NumLinesWithSamples,
NumFunctions, Summary);
}
ProfileSummary *ProfileSummary::getFromMD(Metadata *MD) { ProfileSummary *ProfileSummary::getFromMD(Metadata *MD) {
if (!isa<MDTuple>(MD)) if (!isa<MDTuple>(MD))
return nullptr; return nullptr;
MDTuple *Tuple = cast<MDTuple>(MD); MDTuple *Tuple = cast<MDTuple>(MD);
if (Tuple->getNumOperands() != 8)
return nullptr;
auto &FormatMD = Tuple->getOperand(0); auto &FormatMD = Tuple->getOperand(0);
ProfileSummary::Kind SummaryKind;
if (isKeyValuePair(dyn_cast_or_null<MDTuple>(FormatMD), "ProfileFormat", if (isKeyValuePair(dyn_cast_or_null<MDTuple>(FormatMD), "ProfileFormat",
"SampleProfile")) "SampleProfile"))
return getSampleProfileSummaryFromMD(Tuple); SummaryKind = PSK_Sample;
else if (isKeyValuePair(dyn_cast_or_null<MDTuple>(FormatMD), "ProfileFormat", else if (isKeyValuePair(dyn_cast_or_null<MDTuple>(FormatMD), "ProfileFormat",
"InstrProf")) "InstrProf"))
return getInstrProfSummaryFromMD(Tuple); SummaryKind = PSK_Instr;
else else
return nullptr; return nullptr;
uint64_t NumCounts, TotalCount, NumFunctions, MaxFunctionCount, MaxCount,
MaxInternalCount;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(1)), "TotalCount",
TotalCount))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(2)), "MaxCount", MaxCount))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(3)), "MaxInternalCount",
MaxInternalCount))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(4)), "MaxFunctionCount",
MaxFunctionCount))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(5)), "NumCounts", NumCounts))
return nullptr;
if (!getVal(dyn_cast<MDTuple>(Tuple->getOperand(6)), "NumFunctions",
NumFunctions))
return nullptr;
SummaryEntryVector Summary;
if (!getSummaryFromMD(dyn_cast<MDTuple>(Tuple->getOperand(7)), Summary))
return nullptr;
return new ProfileSummary(SummaryKind, Summary, TotalCount, MaxCount,
MaxInternalCount, MaxFunctionCount, NumCounts,
NumFunctions);
} }

View File

@ -602,13 +602,14 @@ IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version,
Ent.NumBlocks); Ent.NumBlocks);
} }
// initialize InstrProfSummary using the SummaryData from disk. // initialize InstrProfSummary using the SummaryData from disk.
this->Summary = llvm::make_unique<InstrProfSummary>( this->Summary = llvm::make_unique<ProfileSummary>(
ProfileSummary::PSK_Instr, DetailedSummary,
SummaryData->get(Summary::TotalBlockCount), SummaryData->get(Summary::TotalBlockCount),
SummaryData->get(Summary::MaxBlockCount), SummaryData->get(Summary::MaxBlockCount),
SummaryData->get(Summary::MaxInternalBlockCount), SummaryData->get(Summary::MaxInternalBlockCount),
SummaryData->get(Summary::MaxFunctionCount), SummaryData->get(Summary::MaxFunctionCount),
SummaryData->get(Summary::TotalNumBlocks), SummaryData->get(Summary::TotalNumBlocks),
SummaryData->get(Summary::TotalNumFunctions), DetailedSummary); SummaryData->get(Summary::TotalNumFunctions));
return Cur + SummarySize; return Cur + SummarySize;
} else { } else {
// For older version of profile data, we need to compute on the fly: // For older version of profile data, we need to compute on the fly:

View File

@ -195,17 +195,16 @@ bool InstrProfWriter::shouldEncodeData(const ProfilingData &PD) {
} }
static void setSummary(IndexedInstrProf::Summary *TheSummary, static void setSummary(IndexedInstrProf::Summary *TheSummary,
InstrProfSummary &PS) { ProfileSummary &PS) {
using namespace IndexedInstrProf; using namespace IndexedInstrProf;
std::vector<ProfileSummaryEntry> &Res = PS.getDetailedSummary(); std::vector<ProfileSummaryEntry> &Res = PS.getDetailedSummary();
TheSummary->NumSummaryFields = Summary::NumKinds; TheSummary->NumSummaryFields = Summary::NumKinds;
TheSummary->NumCutoffEntries = Res.size(); TheSummary->NumCutoffEntries = Res.size();
TheSummary->set(Summary::MaxFunctionCount, PS.getMaxFunctionCount()); TheSummary->set(Summary::MaxFunctionCount, PS.getMaxFunctionCount());
TheSummary->set(Summary::MaxBlockCount, PS.getMaxBlockCount()); TheSummary->set(Summary::MaxBlockCount, PS.getMaxCount());
TheSummary->set(Summary::MaxInternalBlockCount, TheSummary->set(Summary::MaxInternalBlockCount, PS.getMaxInternalCount());
PS.getMaxInternalBlockCount());
TheSummary->set(Summary::TotalBlockCount, PS.getTotalCount()); TheSummary->set(Summary::TotalBlockCount, PS.getTotalCount());
TheSummary->set(Summary::TotalNumBlocks, PS.getNumBlocks()); TheSummary->set(Summary::TotalNumBlocks, PS.getNumCounts());
TheSummary->set(Summary::TotalNumFunctions, PS.getNumFunctions()); TheSummary->set(Summary::TotalNumFunctions, PS.getNumFunctions());
for (unsigned I = 0; I < Res.size(); I++) for (unsigned I = 0; I < Res.size(); I++)
TheSummary->setEntry(I, Res[I]); TheSummary->setEntry(I, Res[I]);
@ -260,8 +259,8 @@ void InstrProfWriter::writeImpl(ProfOStream &OS) {
IndexedInstrProf::allocSummary(SummarySize); IndexedInstrProf::allocSummary(SummarySize);
// Compute the Summary and copy the data to the data // Compute the Summary and copy the data to the data
// structure to be serialized out (to disk or buffer). // structure to be serialized out (to disk or buffer).
InstrProfSummary *IPS = ISB.getSummary(); ProfileSummary *PS = ISB.getSummary();
setSummary(TheSummary.get(), *IPS); setSummary(TheSummary.get(), *PS);
InfoObj->SummaryBuilder = 0; InfoObj->SummaryBuilder = 0;
// Now do the final patch: // Now do the final patch:

View File

@ -86,17 +86,18 @@ void ProfileSummaryBuilder::computeDetailedSummary() {
} }
} }
SampleProfileSummary *SampleProfileSummaryBuilder::getSummary() { ProfileSummary *SampleProfileSummaryBuilder::getSummary() {
computeDetailedSummary(); computeDetailedSummary();
return new SampleProfileSummary(TotalCount, MaxCount, MaxFunctionCount, return new ProfileSummary(ProfileSummary::PSK_Sample, DetailedSummary,
NumCounts, NumFunctions, DetailedSummary); TotalCount, MaxCount, 0, MaxFunctionCount,
NumCounts, NumFunctions);
} }
InstrProfSummary *InstrProfSummaryBuilder::getSummary() { ProfileSummary *InstrProfSummaryBuilder::getSummary() {
computeDetailedSummary(); computeDetailedSummary();
return new InstrProfSummary(TotalCount, MaxCount, MaxInternalBlockCount, return new ProfileSummary(ProfileSummary::PSK_Instr, DetailedSummary,
MaxFunctionCount, NumCounts, NumFunctions, TotalCount, MaxCount, MaxInternalBlockCount,
DetailedSummary); MaxFunctionCount, NumCounts, NumFunctions);
} }
void InstrProfSummaryBuilder::addEntryCount(uint64_t Count) { void InstrProfSummaryBuilder::addEntryCount(uint64_t Count) {

View File

@ -470,9 +470,9 @@ std::error_code SampleProfileReaderBinary::readSummary() {
if (EC != sampleprof_error::success) if (EC != sampleprof_error::success)
return EC; return EC;
} }
Summary = llvm::make_unique<SampleProfileSummary>( Summary = llvm::make_unique<ProfileSummary>(
*TotalCount, *MaxBlockCount, *MaxFunctionCount, *NumBlocks, *NumFunctions, ProfileSummary::PSK_Sample, Entries, *TotalCount, *MaxBlockCount, 0,
Entries); *MaxFunctionCount, *NumBlocks, *NumFunctions);
return sampleprof_error::success; return sampleprof_error::success;
} }

View File

@ -138,10 +138,10 @@ std::error_code SampleProfileWriterBinary::writeHeader(
std::error_code SampleProfileWriterBinary::writeSummary() { std::error_code SampleProfileWriterBinary::writeSummary() {
auto &OS = *OutputStream; auto &OS = *OutputStream;
encodeULEB128(Summary->getTotalSamples(), OS); encodeULEB128(Summary->getTotalCount(), OS);
encodeULEB128(Summary->getMaxSamplesPerLine(), OS); encodeULEB128(Summary->getMaxCount(), OS);
encodeULEB128(Summary->getMaxFunctionCount(), OS); encodeULEB128(Summary->getMaxFunctionCount(), OS);
encodeULEB128(Summary->getNumLinesWithSamples(), OS); encodeULEB128(Summary->getNumCounts(), OS);
encodeULEB128(Summary->getNumFunctions(), OS); encodeULEB128(Summary->getNumFunctions(), OS);
std::vector<ProfileSummaryEntry> &Entries = Summary->getDetailedSummary(); std::vector<ProfileSummaryEntry> &Entries = Summary->getDetailedSummary();
encodeULEB128(Entries.size(), OS); encodeULEB128(Entries.size(), OS);

View File

@ -353,17 +353,16 @@ static int showInstrProfile(std::string Filename, bool ShowCounts,
if (ShowCounts && TextFormat) if (ShowCounts && TextFormat)
return 0; return 0;
std::unique_ptr<InstrProfSummary> PS(Builder.getSummary()); std::unique_ptr<ProfileSummary> PS(Builder.getSummary());
if (ShowAllFunctions || !ShowFunction.empty()) if (ShowAllFunctions || !ShowFunction.empty())
OS << "Functions shown: " << ShownFunctions << "\n"; OS << "Functions shown: " << ShownFunctions << "\n";
OS << "Total functions: " << PS->getNumFunctions() << "\n"; OS << "Total functions: " << PS->getNumFunctions() << "\n";
OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n"; OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n";
OS << "Maximum internal block count: " << PS->getMaxInternalBlockCount() OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n";
<< "\n";
if (ShowDetailedSummary) { if (ShowDetailedSummary) {
OS << "Detailed summary:\n"; OS << "Detailed summary:\n";
OS << "Total number of blocks: " << PS->getNumBlocks() << "\n"; OS << "Total number of blocks: " << PS->getNumCounts() << "\n";
OS << "Total count: " << PS->getTotalCount() << "\n"; OS << "Total count: " << PS->getTotalCount() << "\n";
for (auto Entry : PS->getDetailedSummary()) { for (auto Entry : PS->getDetailedSummary()) {
OS << Entry.NumCounts << " blocks with count >= " << Entry.MinCount OS << Entry.NumCounts << " blocks with count >= " << Entry.MinCount

View File

@ -156,10 +156,11 @@ TEST_F(InstrProfTest, get_profile_summary) {
auto Profile = Writer.writeBuffer(); auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile)); readProfile(std::move(Profile));
auto VerifySummary = [](InstrProfSummary &IPS) mutable { auto VerifySummary = [](ProfileSummary &IPS) mutable {
ASSERT_EQ(ProfileSummary::PSK_Instr, IPS.getKind());
ASSERT_EQ(2305843009213693952U, IPS.getMaxFunctionCount()); ASSERT_EQ(2305843009213693952U, IPS.getMaxFunctionCount());
ASSERT_EQ(2305843009213693952U, IPS.getMaxBlockCount()); ASSERT_EQ(2305843009213693952U, IPS.getMaxCount());
ASSERT_EQ(10U, IPS.getNumBlocks()); ASSERT_EQ(10U, IPS.getNumCounts());
ASSERT_EQ(4539628424389557499U, IPS.getTotalCount()); ASSERT_EQ(4539628424389557499U, IPS.getTotalCount());
std::vector<ProfileSummaryEntry> &Details = IPS.getDetailedSummary(); std::vector<ProfileSummaryEntry> &Details = IPS.getDetailedSummary();
uint32_t Cutoff = 800000; uint32_t Cutoff = 800000;
@ -180,7 +181,7 @@ TEST_F(InstrProfTest, get_profile_summary) {
ASSERT_EQ(288230376151711744U, NinetyFivePerc->MinCount); ASSERT_EQ(288230376151711744U, NinetyFivePerc->MinCount);
ASSERT_EQ(72057594037927936U, NinetyNinePerc->MinCount); ASSERT_EQ(72057594037927936U, NinetyNinePerc->MinCount);
}; };
InstrProfSummary &PS = Reader->getSummary(); ProfileSummary &PS = Reader->getSummary();
VerifySummary(PS); VerifySummary(PS);
// Test that conversion of summary to and from Metadata works. // Test that conversion of summary to and from Metadata works.
@ -189,10 +190,8 @@ TEST_F(InstrProfTest, get_profile_summary) {
ASSERT_TRUE(MD); ASSERT_TRUE(MD);
ProfileSummary *PSFromMD = ProfileSummary::getFromMD(MD); ProfileSummary *PSFromMD = ProfileSummary::getFromMD(MD);
ASSERT_TRUE(PSFromMD); ASSERT_TRUE(PSFromMD);
ASSERT_TRUE(isa<InstrProfSummary>(PSFromMD)); VerifySummary(*PSFromMD);
InstrProfSummary *IPS = cast<InstrProfSummary>(PSFromMD); delete PSFromMD;
VerifySummary(*IPS);
delete IPS;
// Test that summary can be attached to and read back from module. // Test that summary can be attached to and read back from module.
Module M("my_module", Context); Module M("my_module", Context);
@ -201,10 +200,8 @@ TEST_F(InstrProfTest, get_profile_summary) {
ASSERT_TRUE(MD); ASSERT_TRUE(MD);
PSFromMD = ProfileSummary::getFromMD(MD); PSFromMD = ProfileSummary::getFromMD(MD);
ASSERT_TRUE(PSFromMD); ASSERT_TRUE(PSFromMD);
ASSERT_TRUE(isa<InstrProfSummary>(PSFromMD)); VerifySummary(*PSFromMD);
IPS = cast<InstrProfSummary>(PSFromMD); delete PSFromMD;
VerifySummary(*IPS);
delete IPS;
} }
static const char callee1[] = "callee1"; static const char callee1[] = "callee1";

View File

@ -111,12 +111,13 @@ struct SampleProfTest : ::testing::Test {
ASSERT_EQ(20301u, ReadBarSamples.getTotalSamples()); ASSERT_EQ(20301u, ReadBarSamples.getTotalSamples());
ASSERT_EQ(1437u, ReadBarSamples.getHeadSamples()); ASSERT_EQ(1437u, ReadBarSamples.getHeadSamples());
auto VerifySummary = [](SampleProfileSummary &Summary) mutable { auto VerifySummary = [](ProfileSummary &Summary) mutable {
ASSERT_EQ(123603u, Summary.getTotalSamples()); ASSERT_EQ(ProfileSummary::PSK_Sample, Summary.getKind());
ASSERT_EQ(6u, Summary.getNumLinesWithSamples()); ASSERT_EQ(123603u, Summary.getTotalCount());
ASSERT_EQ(6u, Summary.getNumCounts());
ASSERT_EQ(2u, Summary.getNumFunctions()); ASSERT_EQ(2u, Summary.getNumFunctions());
ASSERT_EQ(1437u, Summary.getMaxFunctionCount()); ASSERT_EQ(1437u, Summary.getMaxFunctionCount());
ASSERT_EQ(60351u, Summary.getMaxSamplesPerLine()); ASSERT_EQ(60351u, Summary.getMaxCount());
uint32_t Cutoff = 800000; uint32_t Cutoff = 800000;
auto Predicate = [&Cutoff](const ProfileSummaryEntry &PE) { auto Predicate = [&Cutoff](const ProfileSummaryEntry &PE) {
@ -138,7 +139,7 @@ struct SampleProfTest : ::testing::Test {
ASSERT_EQ(610u, NinetyNinePerc->MinCount); ASSERT_EQ(610u, NinetyNinePerc->MinCount);
}; };
SampleProfileSummary &Summary = Reader->getSummary(); ProfileSummary &Summary = Reader->getSummary();
VerifySummary(Summary); VerifySummary(Summary);
// Test that conversion of summary to and from Metadata works. // Test that conversion of summary to and from Metadata works.
@ -146,10 +147,8 @@ struct SampleProfTest : ::testing::Test {
ASSERT_TRUE(MD); ASSERT_TRUE(MD);
ProfileSummary *PS = ProfileSummary::getFromMD(MD); ProfileSummary *PS = ProfileSummary::getFromMD(MD);
ASSERT_TRUE(PS); ASSERT_TRUE(PS);
ASSERT_TRUE(isa<SampleProfileSummary>(PS)); VerifySummary(*PS);
SampleProfileSummary *SPS = cast<SampleProfileSummary>(PS); delete PS;
VerifySummary(*SPS);
delete SPS;
// Test that summary can be attached to and read back from module. // Test that summary can be attached to and read back from module.
Module M("my_module", Context); Module M("my_module", Context);
@ -158,10 +157,8 @@ struct SampleProfTest : ::testing::Test {
ASSERT_TRUE(MD); ASSERT_TRUE(MD);
PS = ProfileSummary::getFromMD(MD); PS = ProfileSummary::getFromMD(MD);
ASSERT_TRUE(PS); ASSERT_TRUE(PS);
ASSERT_TRUE(isa<SampleProfileSummary>(PS)); VerifySummary(*PS);
SPS = cast<SampleProfileSummary>(PS); delete PS;
VerifySummary(*SPS);
delete SPS;
} }
}; };