diff --git a/llvm/include/llvm/IR/ProfileSummary.h b/llvm/include/llvm/IR/ProfileSummary.h index 5da87f3b5fee..ea774631eb42 100644 --- a/llvm/include/llvm/IR/ProfileSummary.h +++ b/llvm/include/llvm/IR/ProfileSummary.h @@ -50,29 +50,23 @@ public: private: const Kind PSK; static const char *KindStr[2]; - -protected: SummaryEntryVector DetailedSummary; - uint64_t TotalCount, MaxCount, MaxFunctionCount; + uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount; 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 getFormatSpecificMD(LLVMContext &Context) = 0; /// \brief Return detailed summary as metadata. Metadata *getDetailedSummaryMD(LLVMContext &Context); public: 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; } - const char *getKindStr() const { return KindStr[PSK]; } /// \brief Return summary information as metadata. Metadata *getMD(LLVMContext &Context); /// \brief Construct profile summary from metdata. @@ -80,49 +74,10 @@ public: SummaryEntryVector &getDetailedSummary() { return DetailedSummary; } uint32_t getNumFunctions() { return NumFunctions; } uint64_t getMaxFunctionCount() { return MaxFunctionCount; } -}; - -class InstrProfSummary final : public ProfileSummary { - uint64_t MaxInternalBlockCount; - -protected: - std::vector 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; } + uint32_t getNumCounts() { return NumCounts; } uint64_t getTotalCount() { return TotalCount; } - uint64_t getMaxBlockCount() { return MaxCount; } - uint64_t getMaxInternalBlockCount() { return MaxInternalBlockCount; } -}; - -class SampleProfileSummary final : public ProfileSummary { -protected: - std::vector 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; - } + uint64_t getMaxCount() { return MaxCount; } + uint64_t getMaxInternalCount() { return MaxInternalCount; } }; } // end namespace llvm diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h b/llvm/include/llvm/ProfileData/InstrProfReader.h index 4e9e618324aa..4c2e5fc913ce 100644 --- a/llvm/include/llvm/ProfileData/InstrProfReader.h +++ b/llvm/include/llvm/ProfileData/InstrProfReader.h @@ -364,7 +364,7 @@ private: /// The index into the profile data. std::unique_ptr Index; /// Profile summary data. - std::unique_ptr Summary; + std::unique_ptr Summary; IndexedInstrProfReader(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 // the client is the compiler. InstrProfSymtab &getSymtab() override; - InstrProfSummary &getSummary() { return *(Summary.get()); } + ProfileSummary &getSummary() { return *(Summary.get()); } }; } // end namespace llvm diff --git a/llvm/include/llvm/ProfileData/ProfileCommon.h b/llvm/include/llvm/ProfileData/ProfileCommon.h index 79eee91c3d70..f5b940554c82 100644 --- a/llvm/include/llvm/ProfileData/ProfileCommon.h +++ b/llvm/include/llvm/ProfileData/ProfileCommon.h @@ -74,7 +74,7 @@ public: InstrProfSummaryBuilder(std::vector Cutoffs) : ProfileSummaryBuilder(Cutoffs), MaxInternalBlockCount(0) {} void addRecord(const InstrProfRecord &); - InstrProfSummary *getSummary(); + ProfileSummary *getSummary(); }; class SampleProfileSummaryBuilder final : public ProfileSummaryBuilder { @@ -83,7 +83,7 @@ public: void addRecord(const sampleprof::FunctionSamples &FS); SampleProfileSummaryBuilder(std::vector Cutoffs) : ProfileSummaryBuilder(Cutoffs) {} - SampleProfileSummary *getSummary(); + ProfileSummary *getSummary(); }; // This is called when a count is seen in the profile. diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h index 716f672fc2d2..dacf6d06c13d 100644 --- a/llvm/include/llvm/ProfileData/SampleProfReader.h +++ b/llvm/include/llvm/ProfileData/SampleProfReader.h @@ -296,7 +296,7 @@ public: create(std::unique_ptr &B, LLVMContext &C); /// \brief Return the profile summary. - SampleProfileSummary &getSummary() { return *(Summary.get()); } + ProfileSummary &getSummary() { return *(Summary.get()); } protected: /// \brief Map every function to its associated profile. @@ -313,7 +313,7 @@ protected: std::unique_ptr Buffer; /// \brief Profile summary information. - std::unique_ptr Summary; + std::unique_ptr Summary; /// \brief Compute summary for this profile. void computeSummary(); diff --git a/llvm/include/llvm/ProfileData/SampleProfWriter.h b/llvm/include/llvm/ProfileData/SampleProfWriter.h index b605d4598902..f6f2e2702e31 100644 --- a/llvm/include/llvm/ProfileData/SampleProfWriter.h +++ b/llvm/include/llvm/ProfileData/SampleProfWriter.h @@ -76,7 +76,7 @@ protected: std::unique_ptr OutputStream; /// \brief Profile summary. - std::unique_ptr Summary; + std::unique_ptr Summary; /// \brief Compute summary for this profile. void computeSummary(const StringMap &ProfileMap); diff --git a/llvm/lib/IR/ProfileSummary.cpp b/llvm/lib/IR/ProfileSummary.cpp index 51bcd1845c7d..c35dfb094403 100644 --- a/llvm/lib/IR/ProfileSummary.cpp +++ b/llvm/lib/IR/ProfileSummary.cpp @@ -70,50 +70,18 @@ Metadata *ProfileSummary::getDetailedSummaryMD(LLVMContext &Context) { // to the kind of profile summary as returned by getFormatSpecificMD. Metadata *ProfileSummary::getMD(LLVMContext &Context) { std::vector Components; - Components.push_back(getKeyValMD(Context, "ProfileFormat", getKindStr())); - std::vector 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 -InstrProfSummary::getFormatSpecificMD(LLVMContext &Context) { - std::vector Components; + Components.push_back(getKeyValMD(Context, "ProfileFormat", KindStr[PSK])); Components.push_back(getKeyValMD(Context, "TotalCount", getTotalCount())); + Components.push_back(getKeyValMD(Context, "MaxCount", getMaxCount())); Components.push_back( - getKeyValMD(Context, "MaxBlockCount", getMaxBlockCount())); - Components.push_back(getKeyValMD(Context, "MaxInternalBlockCount", - getMaxInternalBlockCount())); + getKeyValMD(Context, "MaxInternalCount", getMaxInternalCount())); Components.push_back( 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(getDetailedSummaryMD(Context)); - return Components; -} - -std::vector -SampleProfileSummary::getFormatSpecificMD(LLVMContext &Context) { - std::vector 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; + return MDTuple::get(Context, Components); } // Parse an MDTuple representing (Key, Val) pair. @@ -175,83 +143,47 @@ static bool getSummaryFromMD(MDTuple *MD, SummaryEntryVector &Summary) { 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(Tuple->getOperand(1)), "TotalCount", - TotalCount)) - return nullptr; - if (!getVal(dyn_cast(Tuple->getOperand(2)), "MaxBlockCount", - MaxBlockCount)) - return nullptr; - if (!getVal(dyn_cast(Tuple->getOperand(3)), "MaxInternalBlockCount", - MaxInternalBlockCount)) - return nullptr; - if (!getVal(dyn_cast(Tuple->getOperand(4)), "MaxFunctionCount", - MaxFunctionCount)) - return nullptr; - if (!getVal(dyn_cast(Tuple->getOperand(5)), "NumBlocks", NumBlocks)) - return nullptr; - if (!getVal(dyn_cast(Tuple->getOperand(6)), "NumFunctions", - NumFunctions)) - return nullptr; - if (!getSummaryFromMD(dyn_cast(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(Tuple->getOperand(1)), "TotalSamples", - TotalSamples)) - return nullptr; - if (!getVal(dyn_cast(Tuple->getOperand(2)), "MaxSamplesPerLine", - MaxSamplesPerLine)) - return nullptr; - if (!getVal(dyn_cast(Tuple->getOperand(3)), "MaxFunctionCount", - MaxFunctionCount)) - return nullptr; - if (!getVal(dyn_cast(Tuple->getOperand(4)), "NumLinesWithSamples", - NumLinesWithSamples)) - return nullptr; - if (!getVal(dyn_cast(Tuple->getOperand(5)), "NumFunctions", - NumFunctions)) - return nullptr; - if (!getSummaryFromMD(dyn_cast(Tuple->getOperand(6)), Summary)) - return nullptr; - return new SampleProfileSummary(TotalSamples, MaxSamplesPerLine, - MaxFunctionCount, NumLinesWithSamples, - NumFunctions, Summary); -} - ProfileSummary *ProfileSummary::getFromMD(Metadata *MD) { if (!isa(MD)) return nullptr; MDTuple *Tuple = cast(MD); + if (Tuple->getNumOperands() != 8) + return nullptr; + auto &FormatMD = Tuple->getOperand(0); + ProfileSummary::Kind SummaryKind; if (isKeyValuePair(dyn_cast_or_null(FormatMD), "ProfileFormat", "SampleProfile")) - return getSampleProfileSummaryFromMD(Tuple); + SummaryKind = PSK_Sample; else if (isKeyValuePair(dyn_cast_or_null(FormatMD), "ProfileFormat", "InstrProf")) - return getInstrProfSummaryFromMD(Tuple); + SummaryKind = PSK_Instr; else return nullptr; + + uint64_t NumCounts, TotalCount, NumFunctions, MaxFunctionCount, MaxCount, + MaxInternalCount; + if (!getVal(dyn_cast(Tuple->getOperand(1)), "TotalCount", + TotalCount)) + return nullptr; + if (!getVal(dyn_cast(Tuple->getOperand(2)), "MaxCount", MaxCount)) + return nullptr; + if (!getVal(dyn_cast(Tuple->getOperand(3)), "MaxInternalCount", + MaxInternalCount)) + return nullptr; + if (!getVal(dyn_cast(Tuple->getOperand(4)), "MaxFunctionCount", + MaxFunctionCount)) + return nullptr; + if (!getVal(dyn_cast(Tuple->getOperand(5)), "NumCounts", NumCounts)) + return nullptr; + if (!getVal(dyn_cast(Tuple->getOperand(6)), "NumFunctions", + NumFunctions)) + return nullptr; + + SummaryEntryVector Summary; + if (!getSummaryFromMD(dyn_cast(Tuple->getOperand(7)), Summary)) + return nullptr; + return new ProfileSummary(SummaryKind, Summary, TotalCount, MaxCount, + MaxInternalCount, MaxFunctionCount, NumCounts, + NumFunctions); } diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp index 33535fd8eb64..8ffdc5b80918 100644 --- a/llvm/lib/ProfileData/InstrProfReader.cpp +++ b/llvm/lib/ProfileData/InstrProfReader.cpp @@ -602,13 +602,14 @@ IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version, Ent.NumBlocks); } // initialize InstrProfSummary using the SummaryData from disk. - this->Summary = llvm::make_unique( + this->Summary = llvm::make_unique( + ProfileSummary::PSK_Instr, DetailedSummary, SummaryData->get(Summary::TotalBlockCount), SummaryData->get(Summary::MaxBlockCount), SummaryData->get(Summary::MaxInternalBlockCount), SummaryData->get(Summary::MaxFunctionCount), SummaryData->get(Summary::TotalNumBlocks), - SummaryData->get(Summary::TotalNumFunctions), DetailedSummary); + SummaryData->get(Summary::TotalNumFunctions)); return Cur + SummarySize; } else { // For older version of profile data, we need to compute on the fly: diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index 1036a10ed8a3..e9543ceb91ff 100644 --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -195,17 +195,16 @@ bool InstrProfWriter::shouldEncodeData(const ProfilingData &PD) { } static void setSummary(IndexedInstrProf::Summary *TheSummary, - InstrProfSummary &PS) { + ProfileSummary &PS) { using namespace IndexedInstrProf; std::vector &Res = PS.getDetailedSummary(); TheSummary->NumSummaryFields = Summary::NumKinds; TheSummary->NumCutoffEntries = Res.size(); TheSummary->set(Summary::MaxFunctionCount, PS.getMaxFunctionCount()); - TheSummary->set(Summary::MaxBlockCount, PS.getMaxBlockCount()); - TheSummary->set(Summary::MaxInternalBlockCount, - PS.getMaxInternalBlockCount()); + TheSummary->set(Summary::MaxBlockCount, PS.getMaxCount()); + TheSummary->set(Summary::MaxInternalBlockCount, PS.getMaxInternalCount()); TheSummary->set(Summary::TotalBlockCount, PS.getTotalCount()); - TheSummary->set(Summary::TotalNumBlocks, PS.getNumBlocks()); + TheSummary->set(Summary::TotalNumBlocks, PS.getNumCounts()); TheSummary->set(Summary::TotalNumFunctions, PS.getNumFunctions()); for (unsigned I = 0; I < Res.size(); I++) TheSummary->setEntry(I, Res[I]); @@ -260,8 +259,8 @@ void InstrProfWriter::writeImpl(ProfOStream &OS) { IndexedInstrProf::allocSummary(SummarySize); // Compute the Summary and copy the data to the data // structure to be serialized out (to disk or buffer). - InstrProfSummary *IPS = ISB.getSummary(); - setSummary(TheSummary.get(), *IPS); + ProfileSummary *PS = ISB.getSummary(); + setSummary(TheSummary.get(), *PS); InfoObj->SummaryBuilder = 0; // Now do the final patch: diff --git a/llvm/lib/ProfileData/ProfileSummaryBuilder.cpp b/llvm/lib/ProfileData/ProfileSummaryBuilder.cpp index 3d32722ab633..ee40d68a1a6c 100644 --- a/llvm/lib/ProfileData/ProfileSummaryBuilder.cpp +++ b/llvm/lib/ProfileData/ProfileSummaryBuilder.cpp @@ -86,17 +86,18 @@ void ProfileSummaryBuilder::computeDetailedSummary() { } } -SampleProfileSummary *SampleProfileSummaryBuilder::getSummary() { +ProfileSummary *SampleProfileSummaryBuilder::getSummary() { computeDetailedSummary(); - return new SampleProfileSummary(TotalCount, MaxCount, MaxFunctionCount, - NumCounts, NumFunctions, DetailedSummary); + return new ProfileSummary(ProfileSummary::PSK_Sample, DetailedSummary, + TotalCount, MaxCount, 0, MaxFunctionCount, + NumCounts, NumFunctions); } -InstrProfSummary *InstrProfSummaryBuilder::getSummary() { +ProfileSummary *InstrProfSummaryBuilder::getSummary() { computeDetailedSummary(); - return new InstrProfSummary(TotalCount, MaxCount, MaxInternalBlockCount, - MaxFunctionCount, NumCounts, NumFunctions, - DetailedSummary); + return new ProfileSummary(ProfileSummary::PSK_Instr, DetailedSummary, + TotalCount, MaxCount, MaxInternalBlockCount, + MaxFunctionCount, NumCounts, NumFunctions); } void InstrProfSummaryBuilder::addEntryCount(uint64_t Count) { diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp index 14023bbd509d..bd5aacc96f07 100644 --- a/llvm/lib/ProfileData/SampleProfReader.cpp +++ b/llvm/lib/ProfileData/SampleProfReader.cpp @@ -470,9 +470,9 @@ std::error_code SampleProfileReaderBinary::readSummary() { if (EC != sampleprof_error::success) return EC; } - Summary = llvm::make_unique( - *TotalCount, *MaxBlockCount, *MaxFunctionCount, *NumBlocks, *NumFunctions, - Entries); + Summary = llvm::make_unique( + ProfileSummary::PSK_Sample, Entries, *TotalCount, *MaxBlockCount, 0, + *MaxFunctionCount, *NumBlocks, *NumFunctions); return sampleprof_error::success; } diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp index 56e836c69cd0..9c58f9ed3b44 100644 --- a/llvm/lib/ProfileData/SampleProfWriter.cpp +++ b/llvm/lib/ProfileData/SampleProfWriter.cpp @@ -138,10 +138,10 @@ std::error_code SampleProfileWriterBinary::writeHeader( std::error_code SampleProfileWriterBinary::writeSummary() { auto &OS = *OutputStream; - encodeULEB128(Summary->getTotalSamples(), OS); - encodeULEB128(Summary->getMaxSamplesPerLine(), OS); + encodeULEB128(Summary->getTotalCount(), OS); + encodeULEB128(Summary->getMaxCount(), OS); encodeULEB128(Summary->getMaxFunctionCount(), OS); - encodeULEB128(Summary->getNumLinesWithSamples(), OS); + encodeULEB128(Summary->getNumCounts(), OS); encodeULEB128(Summary->getNumFunctions(), OS); std::vector &Entries = Summary->getDetailedSummary(); encodeULEB128(Entries.size(), OS); diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 1b042be8a3f5..b2e60aa43bc5 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -353,17 +353,16 @@ static int showInstrProfile(std::string Filename, bool ShowCounts, if (ShowCounts && TextFormat) return 0; - std::unique_ptr PS(Builder.getSummary()); + std::unique_ptr PS(Builder.getSummary()); if (ShowAllFunctions || !ShowFunction.empty()) OS << "Functions shown: " << ShownFunctions << "\n"; OS << "Total functions: " << PS->getNumFunctions() << "\n"; OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n"; - OS << "Maximum internal block count: " << PS->getMaxInternalBlockCount() - << "\n"; + OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n"; if (ShowDetailedSummary) { 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"; for (auto Entry : PS->getDetailedSummary()) { OS << Entry.NumCounts << " blocks with count >= " << Entry.MinCount diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp index 9ef3487ba18d..c13f31251de4 100644 --- a/llvm/unittests/ProfileData/InstrProfTest.cpp +++ b/llvm/unittests/ProfileData/InstrProfTest.cpp @@ -156,10 +156,11 @@ TEST_F(InstrProfTest, get_profile_summary) { auto Profile = Writer.writeBuffer(); 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.getMaxBlockCount()); - ASSERT_EQ(10U, IPS.getNumBlocks()); + ASSERT_EQ(2305843009213693952U, IPS.getMaxCount()); + ASSERT_EQ(10U, IPS.getNumCounts()); ASSERT_EQ(4539628424389557499U, IPS.getTotalCount()); std::vector &Details = IPS.getDetailedSummary(); uint32_t Cutoff = 800000; @@ -180,7 +181,7 @@ TEST_F(InstrProfTest, get_profile_summary) { ASSERT_EQ(288230376151711744U, NinetyFivePerc->MinCount); ASSERT_EQ(72057594037927936U, NinetyNinePerc->MinCount); }; - InstrProfSummary &PS = Reader->getSummary(); + ProfileSummary &PS = Reader->getSummary(); VerifySummary(PS); // Test that conversion of summary to and from Metadata works. @@ -189,10 +190,8 @@ TEST_F(InstrProfTest, get_profile_summary) { ASSERT_TRUE(MD); ProfileSummary *PSFromMD = ProfileSummary::getFromMD(MD); ASSERT_TRUE(PSFromMD); - ASSERT_TRUE(isa(PSFromMD)); - InstrProfSummary *IPS = cast(PSFromMD); - VerifySummary(*IPS); - delete IPS; + VerifySummary(*PSFromMD); + delete PSFromMD; // Test that summary can be attached to and read back from module. Module M("my_module", Context); @@ -201,10 +200,8 @@ TEST_F(InstrProfTest, get_profile_summary) { ASSERT_TRUE(MD); PSFromMD = ProfileSummary::getFromMD(MD); ASSERT_TRUE(PSFromMD); - ASSERT_TRUE(isa(PSFromMD)); - IPS = cast(PSFromMD); - VerifySummary(*IPS); - delete IPS; + VerifySummary(*PSFromMD); + delete PSFromMD; } static const char callee1[] = "callee1"; diff --git a/llvm/unittests/ProfileData/SampleProfTest.cpp b/llvm/unittests/ProfileData/SampleProfTest.cpp index 8de090d2293a..175852b93fb2 100644 --- a/llvm/unittests/ProfileData/SampleProfTest.cpp +++ b/llvm/unittests/ProfileData/SampleProfTest.cpp @@ -111,12 +111,13 @@ struct SampleProfTest : ::testing::Test { ASSERT_EQ(20301u, ReadBarSamples.getTotalSamples()); ASSERT_EQ(1437u, ReadBarSamples.getHeadSamples()); - auto VerifySummary = [](SampleProfileSummary &Summary) mutable { - ASSERT_EQ(123603u, Summary.getTotalSamples()); - ASSERT_EQ(6u, Summary.getNumLinesWithSamples()); + auto VerifySummary = [](ProfileSummary &Summary) mutable { + ASSERT_EQ(ProfileSummary::PSK_Sample, Summary.getKind()); + ASSERT_EQ(123603u, Summary.getTotalCount()); + ASSERT_EQ(6u, Summary.getNumCounts()); ASSERT_EQ(2u, Summary.getNumFunctions()); ASSERT_EQ(1437u, Summary.getMaxFunctionCount()); - ASSERT_EQ(60351u, Summary.getMaxSamplesPerLine()); + ASSERT_EQ(60351u, Summary.getMaxCount()); uint32_t Cutoff = 800000; auto Predicate = [&Cutoff](const ProfileSummaryEntry &PE) { @@ -138,7 +139,7 @@ struct SampleProfTest : ::testing::Test { ASSERT_EQ(610u, NinetyNinePerc->MinCount); }; - SampleProfileSummary &Summary = Reader->getSummary(); + ProfileSummary &Summary = Reader->getSummary(); VerifySummary(Summary); // Test that conversion of summary to and from Metadata works. @@ -146,10 +147,8 @@ struct SampleProfTest : ::testing::Test { ASSERT_TRUE(MD); ProfileSummary *PS = ProfileSummary::getFromMD(MD); ASSERT_TRUE(PS); - ASSERT_TRUE(isa(PS)); - SampleProfileSummary *SPS = cast(PS); - VerifySummary(*SPS); - delete SPS; + VerifySummary(*PS); + delete PS; // Test that summary can be attached to and read back from module. Module M("my_module", Context); @@ -158,10 +157,8 @@ struct SampleProfTest : ::testing::Test { ASSERT_TRUE(MD); PS = ProfileSummary::getFromMD(MD); ASSERT_TRUE(PS); - ASSERT_TRUE(isa(PS)); - SPS = cast(PS); - VerifySummary(*SPS); - delete SPS; + VerifySummary(*PS); + delete PS; } };