[llvm] [Coroutines] Conditional elide coroutines based on hot/cold information (PR #145831)

Adrian Vogelsgesang via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 11:45:50 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";
----------------
vogelsgesang wrote:

I think your PR might actually become simpler if you integrate with optimization remarks right away. You might be able to remove the debug settings and the custom logic to determine the output stream

https://github.com/llvm/llvm-project/pull/145831


More information about the llvm-commits mailing list