diff options
author | Amir Ayupov <aaupov@fb.com> | 2025-02-12 18:13:31 -0800 |
---|---|---|
committer | Amir Ayupov <aaupov@fb.com> | 2025-02-12 18:13:31 -0800 |
commit | e06744dc99f7370eac8491a091743a7146213bea (patch) | |
tree | 755fc5f975bd0cb531b73de7de016f8ee68bc266 | |
parent | 1c207f1b6e8bba69dfbbcbd72704b4d720e363d0 (diff) | |
download | llvm-users/aaupov/spr/main.boltnfc-simplify-parseaggregatedlbrentry.zip llvm-users/aaupov/spr/main.boltnfc-simplify-parseaggregatedlbrentry.tar.gz llvm-users/aaupov/spr/main.boltnfc-simplify-parseaggregatedlbrentry.tar.bz2 |
[𝘀𝗽𝗿] changes to main this commit is based onusers/aaupov/spr/main.boltnfc-simplify-parseaggregatedlbrentry
Created using spr 1.3.4
[skip ci]
-rw-r--r-- | bolt/include/bolt/Profile/DataAggregator.h | 7 | ||||
-rw-r--r-- | bolt/lib/Profile/DataAggregator.cpp | 15 |
2 files changed, 15 insertions, 7 deletions
diff --git a/bolt/include/bolt/Profile/DataAggregator.h b/bolt/include/bolt/Profile/DataAggregator.h index aa83d7f..dc8b7d2 100644 --- a/bolt/include/bolt/Profile/DataAggregator.h +++ b/bolt/include/bolt/Profile/DataAggregator.h @@ -197,6 +197,10 @@ private: BoltAddressTranslation *BAT{nullptr}; + /// Whether pre-aggregated profile needs to convert branch profile into call + /// to continuation fallthrough profile. + bool NeedsConvertRetProfileToCallCont{false}; + /// Update function execution profile with a recorded trace. /// A trace is region of code executed between two LBR entries supplied in /// execution order. @@ -268,8 +272,7 @@ private: uint64_t Mispreds); /// Register a \p Branch. - bool doBranch(uint64_t From, uint64_t To, uint64_t Count, uint64_t Mispreds, - bool IsPreagg); + 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, diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp index de9ec6c..704c884 100644 --- a/bolt/lib/Profile/DataAggregator.cpp +++ b/bolt/lib/Profile/DataAggregator.cpp @@ -711,7 +711,7 @@ bool DataAggregator::doInterBranch(BinaryFunction *FromFunc, } bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count, - uint64_t Mispreds, bool IsPreagg) { + uint64_t Mispreds) { // Returns whether \p Offset in \p Func contains a return instruction. auto checkReturn = [&](const BinaryFunction &Func, const uint64_t Offset) { auto isReturn = [&](auto MI) { return MI && BC->MIB->isReturn(*MI); }; @@ -772,7 +772,8 @@ bool DataAggregator::doBranch(uint64_t From, uint64_t To, uint64_t Count, return false; // Record call to continuation trace. - if (IsPreagg && FromFunc != ToFunc && (IsReturn || IsCallCont)) { + if (NeedsConvertRetProfileToCallCont && FromFunc != ToFunc && + (IsReturn || IsCallCont)) { LBREntry First{ToOrig - 1, ToOrig - 1, false}; LBREntry Second{ToOrig, ToOrig, false}; return doTrace(First, Second, Count); @@ -1224,12 +1225,17 @@ DataAggregator::parseAggregatedLBREntry() { ErrorOr<StringRef> TypeOrErr = parseString(FieldSeparator); if (std::error_code EC = TypeOrErr.getError()) return EC; + // Pre-aggregated profile with branches and fallthroughs needs to convert + // return profile into call to continuation fall-through. auto Type = AggregatedLBREntry::BRANCH; if (TypeOrErr.get() == "B") { + NeedsConvertRetProfileToCallCont = true; Type = AggregatedLBREntry::BRANCH; } else if (TypeOrErr.get() == "F") { + NeedsConvertRetProfileToCallCont = true; Type = AggregatedLBREntry::FT; } else if (TypeOrErr.get() == "f") { + NeedsConvertRetProfileToCallCont = true; Type = AggregatedLBREntry::FT_EXTERNAL_ORIGIN; } else { reportError("expected B, F or f"); @@ -1585,8 +1591,7 @@ void DataAggregator::processBranchEvents() { for (const auto &AggrLBR : BranchLBRs) { const Trace &Loc = AggrLBR.first; const TakenBranchInfo &Info = AggrLBR.second; - doBranch(Loc.From, Loc.To, Info.TakenCount, Info.MispredCount, - /*IsPreagg*/ false); + doBranch(Loc.From, Loc.To, Info.TakenCount, Info.MispredCount); } } @@ -1747,7 +1752,7 @@ void DataAggregator::processPreAggregated() { switch (AggrEntry.EntryType) { case AggregatedLBREntry::BRANCH: doBranch(AggrEntry.From.Offset, AggrEntry.To.Offset, AggrEntry.Count, - AggrEntry.Mispreds, /*IsPreagg*/ true); + AggrEntry.Mispreds); break; case AggregatedLBREntry::FT: case AggregatedLBREntry::FT_EXTERNAL_ORIGIN: { |