[llvm] [Coroutines] Conditional elide coroutines based on hot/cold information (PR #145831)
Chuanqi Xu via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 1 19:07:11 PDT 2025
================
@@ -145,6 +191,37 @@ PreservedAnalyses CoroAnnotationElidePass::run(LazyCallGraph::SCC &C,
bool IsCallerPresplitCoroutine = Caller->isPresplitCoroutine();
bool HasAttr = CB->hasFnAttr(llvm::Attribute::CoroElideSafe);
if (IsCallerPresplitCoroutine && HasAttr) {
+
+ llvm::raw_ostream *OS = nullptr;
+ auto _ = getCoroElidedStatsOStream(OS);
+ assert(OS && "At least we should able to get access to standard error");
+
+ auto &BFI = FAM.getResult<BlockFrequencyAnalysis>(*Caller);
+ if (BFI.getBlockFreq(CB->getParent()) <
+ BFI.getEntryFreq()) {
+ static BranchProbability MinBranchProbability(
+ static_cast<int>(CoroElideBranchRatio * MinBlockCounterExecution),
+ MinBlockCounterExecution);
+
+ auto Prob = BranchProbability::getBranchProbability(
+ BFI.getBlockFreq(CB->getParent()).getFrequency(),
+ BFI.getEntryFreq().getFrequency());
+
+ if (Prob < MinBranchProbability) {
+ *OS << "Not eliding " << *CB
+ << " with estimated probability: " << Prob << "\n";
+ continue;
+ }
+
+ *OS << "BB Prob: \t" << Prob << "\n";
+ } else {
+ *OS << "BB Freq: \t"
+ << BFI.getBlockFreq(CB->getParent()).getFrequency() << "\n";
+ *OS << "Entry Freq: \t" << BFI.getEntryFreq().getFrequency() << "\n";
+ }
+
+ *OS << "eliding " << *CB << "\n";
----------------
ChuanqiXu9 wrote:
Agreed. But I am pretty busy right now, (the PR is extracted from downstream project directly), so I want to ask your opinion for landing this:
1. Blocking the current PR until I had sometime to look at this.
2. Land the PR as is, and
a. Others can fix the problem if the want. e.g., if you have time, you can make this
b. Add a FIXME then we can look back at this someday.
Generally, Option 1 is the general option in LLVM community. But given for coroutines, the size of the group of people is much smaller, I guess we can be more flexible? Option 2.a may be best if you'd like to contribute on this.
https://github.com/llvm/llvm-project/pull/145831
More information about the llvm-commits
mailing list