@@ -90,13 +90,7 @@ struct BranchInfo {
9090 }
9191
9292 bool operator <(const BranchInfo &RHS) const {
93- if (From < RHS.From )
94- return true ;
95-
96- if (From == RHS.From )
97- return (To < RHS.To );
98-
99- return false ;
93+ return std::tie (From, To) < std::tie (RHS.From , RHS.To );
10094 }
10195
10296 // / Merges branch and misprediction counts of \p BI with those of this object.
@@ -120,10 +114,8 @@ struct FuncBranchData {
120114
121115 FuncBranchData () {}
122116
123- FuncBranchData (StringRef Name, ContainerTy Data)
124- : Name(Name), Data(std::move(Data)) {}
125-
126- FuncBranchData (StringRef Name, ContainerTy Data, ContainerTy EntryData)
117+ FuncBranchData (StringRef Name, ContainerTy Data = ContainerTy(),
118+ ContainerTy EntryData = ContainerTy())
127119 : Name(Name), Data(std::move(Data)), EntryData(std::move(EntryData)) {}
128120
129121 ErrorOr<const BranchInfo &> getBranch (uint64_t From, uint64_t To) const ;
@@ -211,22 +203,23 @@ struct FuncMemData {
211203
212204 FuncMemData () {}
213205
214- FuncMemData (StringRef Name, ContainerTy Data)
206+ FuncMemData (StringRef Name, ContainerTy Data = ContainerTy() )
215207 : Name(Name), Data(std::move(Data)) {}
216208};
217209
218210// / Similar to BranchInfo, but instead of recording from-to address (an edge),
219211// / it records the address of a perf event and the number of times samples hit
220212// / this address.
221- struct SampleInfo {
213+ struct BasicSampleInfo {
222214 Location Loc;
223215 int64_t Hits;
224216
225- SampleInfo (Location Loc, int64_t Hits) : Loc(std::move(Loc)), Hits(Hits) {}
217+ BasicSampleInfo (Location Loc, int64_t Hits)
218+ : Loc(std::move(Loc)), Hits(Hits) {}
226219
227- bool operator ==(const SampleInfo &RHS) const { return Loc == RHS.Loc ; }
220+ bool operator ==(const BasicSampleInfo &RHS) const { return Loc == RHS.Loc ; }
228221
229- bool operator <(const SampleInfo &RHS) const {
222+ bool operator <(const BasicSampleInfo &RHS) const {
230223 if (Loc < RHS.Loc )
231224 return true ;
232225
@@ -235,23 +228,26 @@ struct SampleInfo {
235228
236229 void print (raw_ostream &OS) const ;
237230
238- void mergeWith (const SampleInfo &SI);
231+ void mergeWith (const BasicSampleInfo &SI);
239232};
240233
241234// / Helper class to store samples recorded in the address space of a given
242235// / function, analogous to FuncBranchData but for samples instead of branches.
243- struct FuncSampleData {
244- typedef std::vector<SampleInfo > ContainerTy;
236+ struct FuncBasicSampleData {
237+ typedef std::vector<BasicSampleInfo > ContainerTy;
245238
246239 StringRef Name;
247240 ContainerTy Data;
248241
249- FuncSampleData (StringRef Name, ContainerTy Data)
242+ FuncBasicSampleData (StringRef Name, ContainerTy Data = ContainerTy() )
250243 : Name(Name), Data(std::move(Data)) {}
251244
252245 // / Get the number of samples recorded in [Start, End)
253246 uint64_t getSamples (uint64_t Start, uint64_t End) const ;
254247
248+ // / Returns the total number of samples recorded in this function.
249+ uint64_t getSamples () const ;
250+
255251 // / Aggregation helper
256252 DenseMap<uint64_t , size_t > Index;
257253
@@ -311,7 +307,7 @@ class DataReader : public ProfileReaderBase {
311307 // / The last step is to infer edge counts based on BB execution count. Note
312308 // / this is the opposite of the LBR way, where we infer BB execution count
313309 // / based on edge counts.
314- void readSampleData (BinaryFunction &BF);
310+ void readBasicSampleData (BinaryFunction &BF);
315311
316312 // / Convert function-level branch data into instruction annotations.
317313 void convertBranchData (BinaryFunction &BF) const ;
@@ -385,7 +381,8 @@ class DataReader : public ProfileReaderBase {
385381 // / Return mem data matching one of the names in \p FuncNames.
386382 FuncMemData *getMemDataForNames (const std::vector<StringRef> &FuncNames);
387383
388- FuncSampleData *getFuncSampleData (const std::vector<StringRef> &FuncNames);
384+ FuncBasicSampleData *
385+ getFuncBasicSampleData (const std::vector<StringRef> &FuncNames);
389386
390387 // / Return a vector of all FuncBranchData matching the list of names.
391388 // / Internally use fuzzy matching to match special names like LTO-generated
@@ -428,7 +425,7 @@ class DataReader : public ProfileReaderBase {
428425 }
429426
430427 using NamesToBranchesMapTy = std::map<StringRef, FuncBranchData>;
431- using NamesToSamplesMapTy = std::map<StringRef, FuncSampleData >;
428+ using NamesToBasicSamplesMapTy = std::map<StringRef, FuncBasicSampleData >;
432429 using NamesToMemEventsMapTy = std::map<StringRef, FuncMemData>;
433430 using FuncsToBranchesMapTy =
434431 std::unordered_map<const BinaryFunction *, FuncBranchData *>;
@@ -477,7 +474,7 @@ class DataReader : public ProfileReaderBase {
477474 return parseLocation (EndChar, EndNl, true );
478475 }
479476 ErrorOr<BranchInfo> parseBranchInfo ();
480- ErrorOr<SampleInfo > parseSampleInfo ();
477+ ErrorOr<BasicSampleInfo > parseSampleInfo ();
481478 ErrorOr<MemInfo> parseMemInfo ();
482479 ErrorOr<bool > maybeParseNoLBRFlag ();
483480 ErrorOr<bool > maybeParseBATFlag ();
@@ -491,7 +488,7 @@ class DataReader : public ProfileReaderBase {
491488 unsigned Line{0 };
492489 unsigned Col{0 };
493490 NamesToBranchesMapTy NamesToBranches;
494- NamesToSamplesMapTy NamesToSamples ;
491+ NamesToBasicSamplesMapTy NamesToBasicSamples ;
495492 NamesToMemEventsMapTy NamesToMemEvents;
496493 FuncsToBranchesMapTy FuncsToBranches;
497494 FuncsToMemDataMapTy FuncsToMemData;
0 commit comments