Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BOLT][NFCI] Unify branch profile handling in DataAggregator #138181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: users/aaupov/spr/main.boltnfci-simplify-dataaggregator-using-traces
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 15 additions & 36 deletions bolt/include/bolt/Profile/DataAggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,46 +92,33 @@ class DataAggregator : public DataReader {
uint64_t Addr;
};

/// Used for parsing specific pre-aggregated input files.
struct AggregatedLBREntry {
enum Type : char { BRANCH = 0, FT, FT_EXTERNAL_ORIGIN, TRACE };
Location From;
Location To;
uint64_t Count;
uint64_t Mispreds;
Type EntryType;
};

struct Trace {
uint64_t From;
uint64_t To;
Trace(uint64_t From, uint64_t To) : From(From), To(To) {}
bool operator==(const Trace &Other) const {
return From == Other.From && To == Other.To;
uint64_t FallthroughEnd;
bool operator==(const Trace &O) const {
return From == O.From && To == O.To && FallthroughEnd == O.FallthroughEnd;
}
};

struct TraceHash {
size_t operator()(const Trace &L) const {
return std::hash<uint64_t>()(L.From << 32 | L.To);
return llvm::hash_combine(L.From, L.To, L.FallthroughEnd);
}
};

struct FTInfo {
uint64_t InternCount{0};
uint64_t ExternCount{0};
};

struct TakenBranchInfo {
uint64_t TakenCount{0};
uint64_t MispredCount{0};
void operator+=(const TakenBranchInfo &O) {
TakenCount += O.TakenCount;
MispredCount += O.MispredCount;
}
};

/// Intermediate storage for profile data. We save the results of parsing
/// and use them later for processing and assigning profile.
std::unordered_map<Trace, TakenBranchInfo, TraceHash> BranchLBRs;
std::unordered_map<Trace, FTInfo, TraceHash> FallthroughLBRs;
std::vector<AggregatedLBREntry> AggregatedLBRs;
std::unordered_map<Trace, TakenBranchInfo, TraceHash> Traces;
std::unordered_map<uint64_t, uint64_t> BasicSamples;
std::vector<PerfMemSample> MemSamples;

Expand Down Expand Up @@ -204,8 +191,8 @@ class DataAggregator : public DataReader {
/// Return a vector of offsets corresponding to a trace in a function
/// if the trace is valid, std::nullopt otherwise.
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
getFallthroughsInTrace(BinaryFunction &BF, const LBREntry &First,
const LBREntry &Second, uint64_t Count = 1) const;
getFallthroughsInTrace(BinaryFunction &BF, const Trace &Trace,
uint64_t Count) const;

/// Record external entry into the function \p BF.
///
Expand Down Expand Up @@ -272,9 +259,8 @@ class DataAggregator : public DataReader {
/// Register a \p Branch.
bool doBranch(uint64_t From, uint64_t To, uint64_t Count, uint64_t Mispreds);

/// Register a trace between two LBR entries supplied in execution order.
bool doTrace(const LBREntry &First, const LBREntry &Second,
uint64_t Count = 1);
/// Register a \p Trace.
bool doTrace(const Trace &Trace, uint64_t Count);

/// Parser helpers
/// Return false if we exhausted our parser buffer and finished parsing
Expand Down Expand Up @@ -326,7 +312,7 @@ class DataAggregator : public DataReader {
ErrorOr<LBREntry> parseLBREntry();

/// Parse LBR sample.
void parseLBRSample(const PerfBranchSample &Sample, bool NeedsSkylakeFix);
void parseLBRSample(ArrayRef<LBREntry> Samples);

/// Parse and pre-aggregate branch events.
std::error_code parseBranchEvents();
Expand Down Expand Up @@ -416,14 +402,7 @@ class DataAggregator : public DataReader {
/// F 41be90 41be90 4
/// B 4b1942 39b57f0 3 0
/// B 4b196f 4b19e0 2 0
void parsePreAggregated();

/// Parse the full output of pre-aggregated LBR samples generated by
/// an external tool.
std::error_code parsePreAggregatedLBRSamples();

/// Process parsed pre-aggregated data.
void processPreAggregated();
std::error_code parsePreAggregated();

/// If \p Address falls into the binary address space based on memory
/// mapping info \p MMI, then adjust it for further processing by subtracting
Expand Down
Loading
Loading