llvm.org GIT mirror llvm / 30c760d
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270143 91177308-0d34-0410-b5e6-96231b3b80d8 Easwaran Raman 3 years ago
14 changed file(s) with 95 addition(s) and 214 deletion(s). Raw diff Collapse all Expand all
4949 private:
5050 const Kind PSK;
5151 static const char *KindStr[2];
52
53 protected:
5452 SummaryEntryVector DetailedSummary;
55 uint64_t TotalCount, MaxCount, MaxFunctionCount;
53 uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount;
5654 uint32_t NumCounts, NumFunctions;
57 ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
58 uint64_t TotalCount, uint64_t MaxCount,
59 uint64_t MaxFunctionCount, uint32_t NumCounts,
60 uint32_t NumFunctions)
61 : PSK(K), DetailedSummary(DetailedSummary), TotalCount(TotalCount),
62 MaxCount(MaxCount), MaxFunctionCount(MaxFunctionCount),
63 NumCounts(NumCounts), NumFunctions(NumFunctions) {}
64 ~ProfileSummary() = default;
65 /// \brief Return metadata specific to the profile format.
66 /// Derived classes implement this method to return a vector of Metadata.
67 virtual std::vector getFormatSpecificMD(LLVMContext &Context) = 0;
6855 /// \brief Return detailed summary as metadata.
6956 Metadata *getDetailedSummaryMD(LLVMContext &Context);
7057
7158 public:
7259 static const int Scale = 1000000;
60 ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
61 uint64_t TotalCount, uint64_t MaxCount,
62 uint64_t MaxInternalCount, uint64_t MaxFunctionCount,
63 uint32_t NumCounts, uint32_t NumFunctions)
64 : PSK(K), DetailedSummary(DetailedSummary), TotalCount(TotalCount),
65 MaxCount(MaxCount), MaxInternalCount(MaxInternalCount),
66 MaxFunctionCount(MaxFunctionCount), NumCounts(NumCounts),
67 NumFunctions(NumFunctions) {}
7368 Kind getKind() const { return PSK; }
74 const char *getKindStr() const { return KindStr[PSK]; }
7569 /// \brief Return summary information as metadata.
7670 Metadata *getMD(LLVMContext &Context);
7771 /// \brief Construct profile summary from metdata.
7973 SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
8074 uint32_t getNumFunctions() { return NumFunctions; }
8175 uint64_t getMaxFunctionCount() { return MaxFunctionCount; }
82 };
83
84 class InstrProfSummary final : public ProfileSummary {
85 uint64_t MaxInternalBlockCount;
86
87 protected:
88 std::vector getFormatSpecificMD(LLVMContext &Context) override;
89
90 public:
91 InstrProfSummary(uint64_t TotalCount, uint64_t MaxBlockCount,
92 uint64_t MaxInternalBlockCount, uint64_t MaxFunctionCount,
93 uint32_t NumBlocks, uint32_t NumFunctions,
94 SummaryEntryVector Summary)
95 : ProfileSummary(PSK_Instr, Summary, TotalCount, MaxBlockCount,
96 MaxFunctionCount, NumBlocks, NumFunctions),
97 MaxInternalBlockCount(MaxInternalBlockCount) {}
98 static bool classof(const ProfileSummary *PS) {
99 return PS->getKind() == PSK_Instr;
100 }
101 uint32_t getNumBlocks() { return NumCounts; }
76 uint32_t getNumCounts() { return NumCounts; }
10277 uint64_t getTotalCount() { return TotalCount; }
103 uint64_t getMaxBlockCount() { return MaxCount; }
104 uint64_t getMaxInternalBlockCount() { return MaxInternalBlockCount; }
105 };
106
107 class SampleProfileSummary final : public ProfileSummary {
108 protected:
109 std::vector getFormatSpecificMD(LLVMContext &Context) override;
110
111 public:
112 uint32_t getNumLinesWithSamples() { return NumCounts; }
113 uint64_t getTotalSamples() { return TotalCount; }
114 uint64_t getMaxSamplesPerLine() { return MaxCount; }
115 SampleProfileSummary(uint64_t TotalSamples, uint64_t MaxSamplesPerLine,
116 uint64_t MaxFunctionCount, int32_t NumLinesWithSamples,
117 uint32_t NumFunctions,
118 SummaryEntryVector DetailedSummary)
119 : ProfileSummary(PSK_Sample, DetailedSummary, TotalSamples,
120 MaxSamplesPerLine, MaxFunctionCount, NumLinesWithSamples,
121 NumFunctions) {}
122 static bool classof(const ProfileSummary *PS) {
123 return PS->getKind() == PSK_Sample;
124 }
78 uint64_t getMaxCount() { return MaxCount; }
79 uint64_t getMaxInternalCount() { return MaxInternalCount; }
12580 };
12681
12782 } // end namespace llvm
363363 /// The index into the profile data.
364364 std::unique_ptr Index;
365365 /// Profile summary data.
366 std::unique_ptr<InstrProfSummary> Summary;
366 std::unique_ptr<ProfileSummary> Summary;
367367
368368 IndexedInstrProfReader(const IndexedInstrProfReader &) = delete;
369369 IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
416416 // to be used by llvm-profdata (for dumping). Avoid using this when
417417 // the client is the compiler.
418418 InstrProfSymtab &getSymtab() override;
419 InstrProfSummary &getSummary() { return *(Summary.get()); }
419 ProfileSummary &getSummary() { return *(Summary.get()); }
420420 };
421421
422422 } // end namespace llvm
7373 InstrProfSummaryBuilder(std::vector Cutoffs)
7474 : ProfileSummaryBuilder(Cutoffs), MaxInternalBlockCount(0) {}
7575 void addRecord(const InstrProfRecord &);
76 InstrProfSummary *getSummary();
76 ProfileSummary *getSummary();
7777 };
7878
7979 class SampleProfileSummaryBuilder final : public ProfileSummaryBuilder {
8282 void addRecord(const sampleprof::FunctionSamples &FS);
8383 SampleProfileSummaryBuilder(std::vector Cutoffs)
8484 : ProfileSummaryBuilder(Cutoffs) {}
85 SampleProfileSummary *getSummary();
85 ProfileSummary *getSummary();
8686 };
8787
8888 // This is called when a count is seen in the profile.
295295 create(std::unique_ptr &B, LLVMContext &C);
296296
297297 /// \brief Return the profile summary.
298 SampleProfileSummary &getSummary() { return *(Summary.get()); }
298 ProfileSummary &getSummary() { return *(Summary.get()); }
299299
300300 protected:
301301 /// \brief Map every function to its associated profile.
312312 std::unique_ptr Buffer;
313313
314314 /// \brief Profile summary information.
315 std::unique_ptr<SampleProfileSummary> Summary;
315 std::unique_ptr<ProfileSummary> Summary;
316316
317317 /// \brief Compute summary for this profile.
318318 void computeSummary();
7575 std::unique_ptr OutputStream;
7676
7777 /// \brief Profile summary.
78 std::unique_ptr<SampleProfileSummary> Summary;
78 std::unique_ptr<ProfileSummary> Summary;
7979
8080 /// \brief Compute summary for this profile.
8181 void computeSummary(const StringMap &ProfileMap);
6969 // to the kind of profile summary as returned by getFormatSpecificMD.
7070 Metadata *ProfileSummary::getMD(LLVMContext &Context) {
7171 std::vector Components;
72 Components.push_back(getKeyValMD(Context, "ProfileFormat", getKindStr()));
73 std::vector Res = getFormatSpecificMD(Context);
74 Components.insert(Components.end(), Res.begin(), Res.end());
75 return MDTuple::get(Context, Components);
76 }
77
78 // Returns a vector of MDTuples specific to InstrProfSummary. The first six
79 // elements of this vector are (Key, Val) pairs of the six scalar fields of
80 // InstrProfSummary (TotalCount, MaxBlockCount, MaxInternalBlockCount,
81 // MaxFunctionCount, NumBlocks, NumFunctions). The last element of this vector
82 // is an MDTuple returned by getDetailedSummaryMD.
83 std::vector
84 InstrProfSummary::getFormatSpecificMD(LLVMContext &Context) {
85 std::vector Components;
72 Components.push_back(getKeyValMD(Context, "ProfileFormat", KindStr[PSK]));
8673
8774 Components.push_back(getKeyValMD(Context, "TotalCount", getTotalCount()));
75 Components.push_back(getKeyValMD(Context, "MaxCount", getMaxCount()));
8876 Components.push_back(
89 getKeyValMD(Context, "MaxBlockCount", getMaxBlockCount()));
90 Components.push_back(getKeyValMD(Context, "MaxInternalBlockCount",
91 getMaxInternalBlockCount()));
77 getKeyValMD(Context, "MaxInternalCount", getMaxInternalCount()));
9278 Components.push_back(
9379 getKeyValMD(Context, "MaxFunctionCount", getMaxFunctionCount()));
94 Components.push_back(getKeyValMD(Context, "NumBlocks", getNumBlocks()));
80 Components.push_back(getKeyValMD(Context, "NumCounts", getNumCounts()));
9581 Components.push_back(getKeyValMD(Context, "NumFunctions", getNumFunctions()));
96
9782 Components.push_back(getDetailedSummaryMD(Context));
98 return Components;
99 }
100
101 std::vector
102 SampleProfileSummary::getFormatSpecificMD(LLVMContext &Context) {
103 std::vector Components;
104
105 Components.push_back(getKeyValMD(Context, "TotalSamples", getTotalSamples()));
106 Components.push_back(
107 getKeyValMD(Context, "MaxSamplesPerLine", getMaxSamplesPerLine()));
108 Components.push_back(
109 getKeyValMD(Context, "MaxFunctionCount", getMaxFunctionCount()));
110 Components.push_back(
111 getKeyValMD(Context, "NumLinesWithSamples", getNumLinesWithSamples()));
112 Components.push_back(getKeyValMD(Context, "NumFunctions", NumFunctions));
113
114 Components.push_back(getDetailedSummaryMD(Context));
115 return Components;
83 return MDTuple::get(Context, Components);
11684 }
11785
11886 // Parse an MDTuple representing (Key, Val) pair.
174142 return true;
175143 }
176144
177 // Parse an MDTuple representing an InstrProfSummary object.
178 static ProfileSummary *getInstrProfSummaryFromMD(MDTuple *Tuple) {
179 uint64_t NumBlocks, TotalCount, NumFunctions, MaxFunctionCount, MaxBlockCount,
180 MaxInternalBlockCount;
181 SummaryEntryVector Summary;
182
145 ProfileSummary *ProfileSummary::getFromMD(Metadata *MD) {
146 if (!isa(MD))
147 return nullptr;
148 MDTuple *Tuple = cast(MD);
183149 if (Tuple->getNumOperands() != 8)
184150 return nullptr;
185151
186 // Skip operand 0 which has been already parsed in the caller
152 auto &FormatMD = Tuple->getOperand(0);
153 ProfileSummary::Kind SummaryKind;
154 if (isKeyValuePair(dyn_cast_or_null(FormatMD), "ProfileFormat",
155 "SampleProfile"))
156 SummaryKind = PSK_Sample;
157 else if (isKeyValuePair(dyn_cast_or_null(FormatMD), "ProfileFormat",
158 "InstrProf"))
159 SummaryKind = PSK_Instr;
160 else
161 return nullptr;
162
163 uint64_t NumCounts, TotalCount, NumFunctions, MaxFunctionCount, MaxCount,
164 MaxInternalCount;
187165 if (!getVal(dyn_cast(Tuple->getOperand(1)), "TotalCount",
188166 TotalCount))
189167 return nullptr;
190 if (!getVal(dyn_cast(Tuple->getOperand(2)), "MaxBlockCount",
191 MaxBlockCount))
168 if (!getVal(dyn_cast(Tuple->getOperand(2)), "MaxCount", MaxCount))
192169 return nullptr;
193 if (!getVal(dyn_cast(Tuple->getOperand(3)), "MaxInternalBlockCount",
194 MaxInternalBlockCount))
170 if (!getVal(dyn_cast(Tuple->getOperand(3)), "MaxInternalCount",
171 MaxInternalCount))
195172 return nullptr;
196173 if (!getVal(dyn_cast(Tuple->getOperand(4)), "MaxFunctionCount",
197174 MaxFunctionCount))
198175 return nullptr;
199 if (!getVal(dyn_cast(Tuple->getOperand(5)), "NumBlocks", NumBlocks))
176 if (!getVal(dyn_cast(Tuple->getOperand(5)), "NumCounts", NumCounts))
200177 return nullptr;
201178 if (!getVal(dyn_cast(Tuple->getOperand(6)), "NumFunctions",
202179 NumFunctions))
203180 return nullptr;
181
182 SummaryEntryVector Summary;
204183 if (!getSummaryFromMD(dyn_cast(Tuple->getOperand(7)), Summary))
205184 return nullptr;
206 return new InstrProfSummary(TotalCount, MaxBlockCount, MaxInternalBlockCount,
207 MaxFunctionCount, NumBlocks, NumFunctions,
208 Summary);
185 return new ProfileSummary(SummaryKind, Summary, TotalCount, MaxCount,
186 MaxInternalCount, MaxFunctionCount, NumCounts,
187 NumFunctions);
209188 }
210
211 // Parse an MDTuple representing a SampleProfileSummary object.
212 static ProfileSummary *getSampleProfileSummaryFromMD(MDTuple *Tuple) {
213 uint64_t TotalSamples, MaxSamplesPerLine, MaxFunctionCount,
214 NumLinesWithSamples, NumFunctions;
215 SummaryEntryVector Summary;
216
217 if (Tuple->getNumOperands() != 7)
218 return nullptr;
219
220 // Skip operand 0 which has been already parsed in the caller
221 if (!getVal(dyn_cast(Tuple->getOperand(1)), "TotalSamples",
222 TotalSamples))
223 return nullptr;
224 if (!getVal(dyn_cast(Tuple->getOperand(2)), "MaxSamplesPerLine",
225 MaxSamplesPerLine))
226 return nullptr;
227 if (!getVal(dyn_cast(Tuple->getOperand(3)), "MaxFunctionCount",
228 MaxFunctionCount))
229 return nullptr;
230 if (!getVal(dyn_cast(Tuple->getOperand(4)), "NumLinesWithSamples",
231 NumLinesWithSamples))
232 return nullptr;
233 if (!getVal(dyn_cast(Tuple->getOperand(5)), "NumFunctions",
234 NumFunctions))
235 return nullptr;
236 if (!getSummaryFromMD(dyn_cast(Tuple->getOperand(6)), Summary))
237 return nullptr;
238 return new SampleProfileSummary(TotalSamples, MaxSamplesPerLine,
239 MaxFunctionCount, NumLinesWithSamples,
240 NumFunctions, Summary);
241 }
242
243 ProfileSummary *ProfileSummary::getFromMD(Metadata *MD) {
244 if (!isa(MD))
245 return nullptr;
246 MDTuple *Tuple = cast(MD);
247 auto &FormatMD = Tuple->getOperand(0);
248 if (isKeyValuePair(dyn_cast_or_null(FormatMD), "ProfileFormat",
249 "SampleProfile"))
250 return getSampleProfileSummaryFromMD(Tuple);
251 else if (isKeyValuePair(dyn_cast_or_null(FormatMD), "ProfileFormat",
252 "InstrProf"))
253 return getInstrProfSummaryFromMD(Tuple);
254 else
255 return nullptr;
256 }
601601 Ent.NumBlocks);
602602 }
603603 // initialize InstrProfSummary using the SummaryData from disk.
604 this->Summary = llvm::make_unique<InstrProfSummary>(
604 this->Summary = llvm::make_unique<ProfileSummary>(
605 ProfileSummary::PSK_Instr, DetailedSummary,
605606 SummaryData->get(Summary::TotalBlockCount),
606607 SummaryData->get(Summary::MaxBlockCount),
607608 SummaryData->get(Summary::MaxInternalBlockCount),
608609 SummaryData->get(Summary::MaxFunctionCount),
609610 SummaryData->get(Summary::TotalNumBlocks),
610 SummaryData->get(Summary::TotalNumFunctions), DetailedSummary);
611 SummaryData->get(Summary::TotalNumFunctions));
611612 return Cur + SummarySize;
612613 } else {
613614 // For older version of profile data, we need to compute on the fly:
194194 }
195195
196196 static void setSummary(IndexedInstrProf::Summary *TheSummary,
197 InstrProfSummary &PS) {
197 ProfileSummary &PS) {
198198 using namespace IndexedInstrProf;
199199 std::vector &Res = PS.getDetailedSummary();
200200 TheSummary->NumSummaryFields = Summary::NumKinds;
201201 TheSummary->NumCutoffEntries = Res.size();
202202 TheSummary->set(Summary::MaxFunctionCount, PS.getMaxFunctionCount());
203 TheSummary->set(Summary::MaxBlockCount, PS.getMaxBlockCount());
204 TheSummary->set(Summary::MaxInternalBlockCount,
205 PS.getMaxInternalBlockCount());
203 TheSummary->set(Summary::MaxBlockCount, PS.getMaxCount());
204 TheSummary->set(Summary::MaxInternalBlockCount, PS.getMaxInternalCount());
206205 TheSummary->set(Summary::TotalBlockCount, PS.getTotalCount());
207 TheSummary->set(Summary::TotalNumBlocks, PS.getNumBlocks());
206 TheSummary->set(Summary::TotalNumBlocks, PS.getNumCounts());
208207 TheSummary->set(Summary::TotalNumFunctions, PS.getNumFunctions());
209208 for (unsigned I = 0; I < Res.size(); I++)
210209 TheSummary->setEntry(I, Res[I]);
259258 IndexedInstrProf::allocSummary(SummarySize);
260259 // Compute the Summary and copy the data to the data
261260 // structure to be serialized out (to disk or buffer).
262 InstrProfSummary *IPS = ISB.getSummary();
263 setSummary(TheSummary.get(), *IPS);
261 ProfileSummary *PS = ISB.getSummary();
262 setSummary(TheSummary.get(), *PS);
264263 InfoObj->SummaryBuilder = 0;
265264
266265 // Now do the final patch:
8585 }
8686 }
8787
88 SampleProfileSummary *SampleProfileSummaryBuilder::getSummary() {
88 ProfileSummary *SampleProfileSummaryBuilder::getSummary() {
8989 computeDetailedSummary();
90 return new SampleProfileSummary(TotalCount, MaxCount, MaxFunctionCount,
91 NumCounts, NumFunctions, DetailedSummary);
90 return new ProfileSummary(ProfileSummary::PSK_Sample, DetailedSummary,
91 TotalCount, MaxCount, 0, MaxFunctionCount,
92 NumCounts, NumFunctions);
9293 }
9394
94 InstrProfSummary *InstrProfSummaryBuilder::getSummary() {
95 ProfileSummary *InstrProfSummaryBuilder::getSummary() {
9596 computeDetailedSummary();
96 return new InstrProfSummary(TotalCount, MaxCount, MaxInternalBlockCount,
97 MaxFunctionCount, NumCounts, NumFunctions,
98 DetailedSummary);
97 return new ProfileSummary(ProfileSummary::PSK_Instr, DetailedSummary,
98 TotalCount, MaxCount, MaxInternalBlockCount,
99 MaxFunctionCount, NumCounts, NumFunctions);
99100 }
100101
101102 void InstrProfSummaryBuilder::addEntryCount(uint64_t Count) {
469469 if (EC != sampleprof_error::success)
470470 return EC;
471471 }
472 Summary = llvm::make_unique(
473 *TotalCount, *MaxBlockCount, *MaxFunctionCount, *NumBlocks, *NumFunctions,
474 Entries);
472 Summary = llvm::make_unique(
473 ProfileSummary::PSK_Sample, Entries, *TotalCount, *MaxBlockCount, 0,
474 *MaxFunctionCount, *NumBlocks, *NumFunctions);
475475
476476 return sampleprof_error::success;
477477 }
137137
138138 std::error_code SampleProfileWriterBinary::writeSummary() {
139139 auto &OS = *OutputStream;
140 encodeULEB128(Summary->getTotalSamples(), OS);
141 encodeULEB128(Summary->getMaxSamplesPerLine(), OS);
140 encodeULEB128(Summary->getTotalCount(), OS);
141 encodeULEB128(Summary->getMaxCount(), OS);
142142 encodeULEB128(Summary->getMaxFunctionCount(), OS);
143 encodeULEB128(Summary->getNumLinesWithSamples(), OS);
143 encodeULEB128(Summary->getNumCounts(), OS);
144144 encodeULEB128(Summary->getNumFunctions(), OS);
145145 std::vector &Entries = Summary->getDetailedSummary();
146146 encodeULEB128(Entries.size(), OS);
352352
353353 if (ShowCounts && TextFormat)
354354 return 0;
355 std::unique_ptr<InstrProfSummary> PS(Builder.getSummary());
355 std::unique_ptr<ProfileSummary> PS(Builder.getSummary());
356356 if (ShowAllFunctions || !ShowFunction.empty())
357357 OS << "Functions shown: " << ShownFunctions << "\n";
358358 OS << "Total functions: " << PS->getNumFunctions() << "\n";
359359 OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n";
360 OS << "Maximum internal block count: " << PS->getMaxInternalBlockCount()
361 << "\n";
360 OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n";
362361
363362 if (ShowDetailedSummary) {
364363 OS << "Detailed summary:\n";
365 OS << "Total number of blocks: " << PS->getNumBlocks() << "\n";
364 OS << "Total number of blocks: " << PS->getNumCounts() << "\n";
366365 OS << "Total count: " << PS->getTotalCount() << "\n";
367366 for (auto Entry : PS->getDetailedSummary()) {
368367 OS << Entry.NumCounts << " blocks with count >= " << Entry.MinCount
155155 auto Profile = Writer.writeBuffer();
156156 readProfile(std::move(Profile));
157157
158 auto VerifySummary = [](InstrProfSummary &IPS) mutable {
158 auto VerifySummary = [](ProfileSummary &IPS) mutable {
159 ASSERT_EQ(ProfileSummary::PSK_Instr, IPS.getKind());
159160 ASSERT_EQ(2305843009213693952U, IPS.getMaxFunctionCount());
160 ASSERT_EQ(2305843009213693952U, IPS.getMaxBlockCount());
161 ASSERT_EQ(10U, IPS.getNumBlocks());
161 ASSERT_EQ(2305843009213693952U, IPS.getMaxCount());
162 ASSERT_EQ(10U, IPS.getNumCounts());
162163 ASSERT_EQ(4539628424389557499U, IPS.getTotalCount());
163164 std::vector &Details = IPS.getDetailedSummary();
164165 uint32_t Cutoff = 800000;
179180 ASSERT_EQ(288230376151711744U, NinetyFivePerc->MinCount);
180181 ASSERT_EQ(72057594037927936U, NinetyNinePerc->MinCount);
181182 };
182 InstrProfSummary &PS = Reader->getSummary();
183 ProfileSummary &PS = Reader->getSummary();
183184 VerifySummary(PS);
184185
185186 // Test that conversion of summary to and from Metadata works.
188189 ASSERT_TRUE(MD);
189190 ProfileSummary *PSFromMD = ProfileSummary::getFromMD(MD);
190191 ASSERT_TRUE(PSFromMD);
191 ASSERT_TRUE(isa(PSFromMD));
192 InstrProfSummary *IPS = cast(PSFromMD);
193 VerifySummary(*IPS);
194 delete IPS;
192 VerifySummary(*PSFromMD);
193 delete PSFromMD;
195194
196195 // Test that summary can be attached to and read back from module.
197196 Module M("my_module", Context);
200199 ASSERT_TRUE(MD);
201200 PSFromMD = ProfileSummary::getFromMD(MD);
202201 ASSERT_TRUE(PSFromMD);
203 ASSERT_TRUE(isa(PSFromMD));
204 IPS = cast(PSFromMD);
205 VerifySummary(*IPS);
206 delete IPS;
202 VerifySummary(*PSFromMD);
203 delete PSFromMD;
207204 }
208205
209206 static const char callee1[] = "callee1";
110110 ASSERT_EQ(20301u, ReadBarSamples.getTotalSamples());
111111 ASSERT_EQ(1437u, ReadBarSamples.getHeadSamples());
112112
113 auto VerifySummary = [](SampleProfileSummary &Summary) mutable {
114 ASSERT_EQ(123603u, Summary.getTotalSamples());
115 ASSERT_EQ(6u, Summary.getNumLinesWithSamples());
113 auto VerifySummary = [](ProfileSummary &Summary) mutable {
114 ASSERT_EQ(ProfileSummary::PSK_Sample, Summary.getKind());
115 ASSERT_EQ(123603u, Summary.getTotalCount());
116 ASSERT_EQ(6u, Summary.getNumCounts());
116117 ASSERT_EQ(2u, Summary.getNumFunctions());
117118 ASSERT_EQ(1437u, Summary.getMaxFunctionCount());
118 ASSERT_EQ(60351u, Summary.getMaxSamplesPerLine());
119 ASSERT_EQ(60351u, Summary.getMaxCount());
119120
120121 uint32_t Cutoff = 800000;
121122 auto Predicate = [&Cutoff](const ProfileSummaryEntry &PE) {
137138 ASSERT_EQ(610u, NinetyNinePerc->MinCount);
138139 };
139140
140 SampleProfileSummary &Summary = Reader->getSummary();
141 ProfileSummary &Summary = Reader->getSummary();
141142 VerifySummary(Summary);
142143
143144 // Test that conversion of summary to and from Metadata works.
145146 ASSERT_TRUE(MD);
146147 ProfileSummary *PS = ProfileSummary::getFromMD(MD);
147148 ASSERT_TRUE(PS);
148 ASSERT_TRUE(isa(PS));
149 SampleProfileSummary *SPS = cast(PS);
150 VerifySummary(*SPS);
151 delete SPS;
149 VerifySummary(*PS);
150 delete PS;
152151
153152 // Test that summary can be attached to and read back from module.
154153 Module M("my_module", Context);
157156 ASSERT_TRUE(MD);
158157 PS = ProfileSummary::getFromMD(MD);
159158 ASSERT_TRUE(PS);
160 ASSERT_TRUE(isa(PS));
161 SPS = cast(PS);
162 VerifySummary(*SPS);
163 delete SPS;
159 VerifySummary(*PS);
160 delete PS;
164161 }
165162 };
166163