@@ -92,46 +92,33 @@ class DataAggregator : public DataReader {
9292 uint64_t Addr;
9393 };
9494
95- // / Used for parsing specific pre-aggregated input files.
96- struct AggregatedLBREntry {
97- enum Type : char { BRANCH = 0 , FT, FT_EXTERNAL_ORIGIN, TRACE };
98- Location From;
99- Location To;
100- uint64_t Count;
101- uint64_t Mispreds;
102- Type EntryType;
103- };
104-
10595 struct Trace {
10696 uint64_t From;
10797 uint64_t To;
108- Trace ( uint64_t From, uint64_t To) : From(From), To(To) {}
109- bool operator ==(const Trace &Other ) const {
110- return From == Other .From && To == Other .To ;
98+ uint64_t FallthroughEnd;
99+ bool operator ==(const Trace &O ) const {
100+ return From == O .From && To == O .To && FallthroughEnd == O. FallthroughEnd ;
111101 }
112102 };
113103
114104 struct TraceHash {
115105 size_t operator ()(const Trace &L) const {
116- return std::hash< uint64_t >()( L.From << 32 | L.To );
106+ return llvm::hash_combine ( L.From , L.To , L. FallthroughEnd );
117107 }
118108 };
119109
120- struct FTInfo {
121- uint64_t InternCount{0 };
122- uint64_t ExternCount{0 };
123- };
124-
125110 struct TakenBranchInfo {
126111 uint64_t TakenCount{0 };
127112 uint64_t MispredCount{0 };
113+ void operator +=(const TakenBranchInfo &O) {
114+ TakenCount += O.TakenCount ;
115+ MispredCount += O.MispredCount ;
116+ }
128117 };
129118
130119 // / Intermediate storage for profile data. We save the results of parsing
131120 // / and use them later for processing and assigning profile.
132- std::unordered_map<Trace, TakenBranchInfo, TraceHash> BranchLBRs;
133- std::unordered_map<Trace, FTInfo, TraceHash> FallthroughLBRs;
134- std::vector<AggregatedLBREntry> AggregatedLBRs;
121+ std::unordered_map<Trace, TakenBranchInfo, TraceHash> Traces;
135122 std::unordered_map<uint64_t , uint64_t > BasicSamples;
136123 std::vector<PerfMemSample> MemSamples;
137124
@@ -197,19 +184,15 @@ class DataAggregator : public DataReader {
197184
198185 BoltAddressTranslation *BAT{nullptr };
199186
200- // / Whether pre-aggregated profile needs to convert branch profile into call
201- // / to continuation fallthrough profile.
202- bool NeedsConvertRetProfileToCallCont{false };
203-
204187 // / Update function execution profile with a recorded trace.
205188 // / A trace is region of code executed between two LBR entries supplied in
206189 // / execution order.
207190 // /
208191 // / Return a vector of offsets corresponding to a trace in a function
209192 // / if the trace is valid, std::nullopt otherwise.
210193 std::optional<SmallVector<std::pair<uint64_t , uint64_t >, 16 >>
211- getFallthroughsInTrace (BinaryFunction &BF, const LBREntry &First ,
212- const LBREntry &Second, uint64_t Count = 1 ) const ;
194+ getFallthroughsInTrace (BinaryFunction &BF, const Trace &Trace ,
195+ uint64_t Count) const ;
213196
214197 // / Record external entry into the function \p BF.
215198 // /
@@ -276,17 +259,16 @@ class DataAggregator : public DataReader {
276259 // / Register a \p Branch.
277260 bool doBranch (uint64_t From, uint64_t To, uint64_t Count, uint64_t Mispreds);
278261
279- // / Register a trace between two LBR entries supplied in execution order.
280- bool doTrace (const LBREntry &First, const LBREntry &Second,
281- uint64_t Count = 1 );
262+ // / Register a \p Trace.
263+ bool doTrace (const Trace &Trace, uint64_t Count);
282264
283265 // / Parser helpers
284266 // / Return false if we exhausted our parser buffer and finished parsing
285267 // / everything
286268 bool hasData () const { return !ParsingBuf.empty (); }
287269
288- // / Print heat map based on LBR samples.
289- std::error_code printLBRHeatMap ();
270+ // / Print heat map based on collected samples.
271+ std::error_code printHeatMap ();
290272
291273 // / Parse a single perf sample containing a PID associated with a sequence of
292274 // / LBR entries. If the PID does not correspond to the binary we are looking
@@ -330,7 +312,7 @@ class DataAggregator : public DataReader {
330312 ErrorOr<LBREntry> parseLBREntry ();
331313
332314 // / Parse LBR sample.
333- void parseLBRSample (const PerfBranchSample &Sample, bool NeedsSkylakeFix );
315+ void parseLBRSample (ArrayRef<LBREntry> Samples );
334316
335317 // / Parse and pre-aggregate branch events.
336318 std::error_code parseBranchEvents ();
@@ -420,14 +402,7 @@ class DataAggregator : public DataReader {
420402 // / F 41be90 41be90 4
421403 // / B 4b1942 39b57f0 3 0
422404 // / B 4b196f 4b19e0 2 0
423- void parsePreAggregated ();
424-
425- // / Parse the full output of pre-aggregated LBR samples generated by
426- // / an external tool.
427- std::error_code parsePreAggregatedLBRSamples ();
428-
429- // / Process parsed pre-aggregated data.
430- void processPreAggregated ();
405+ std::error_code parsePreAggregated ();
431406
432407 // / If \p Address falls into the binary address space based on memory
433408 // / mapping info \p MMI, then adjust it for further processing by subtracting
0 commit comments