[llvm] [BPI] Cache LoopExitBlocks to improve compile time (PR #93451)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon May 27 11:59:52 PDT 2024


================
@@ -828,12 +828,13 @@ void BranchProbabilityInfo::computeEestimateBlockWeight(
   do {
     while (!LoopWorkList.empty()) {
       const LoopBlock LoopBB = LoopWorkList.pop_back_val();
-
-      if (EstimatedLoopWeight.count(LoopBB.getLoopData()))
+      const LoopData LD = LoopBB.getLoopData();
+      if (EstimatedLoopWeight.count(LD))
         continue;
 
-      SmallVector<BasicBlock *, 4> Exits;
-      getLoopExitBlocks(LoopBB, Exits);
+      if (!LoopExitBlocks.count(LD))
----------------
nikic wrote:

I meant using find() to avoid doing both the count() and then below another lookup using LoopExitBlocks[LD].

Your suggestion of using try_emplace also covers the insertion path, so I guess that's even better.

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


More information about the llvm-commits mailing list