[llvm] [VPlan] Use BlockFrequencyInfo in getPredBlockCostDivisor (PR #158690)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 8 05:02:00 PST 2025


================
@@ -1729,6 +1722,17 @@ class LoopVectorizationCostModel {
   /// Interface to emit optimization remarks.
   OptimizationRemarkEmitter *ORE;
 
+  /// A function to lazily fetch BlockFrequencyInfo. This avoids computing it
+  /// unless necessary, e.g. when the loop isn't legal to vectorize or when
+  /// there is no predication.
+  std::function<BlockFrequencyInfo &()> GetBFI;
+  BlockFrequencyInfo *BFI = nullptr;
+  BlockFrequencyInfo &getBFI() {
+    if (!BFI)
+      BFI = &GetBFI();
+    return *BFI;
+  }
----------------
fhahn wrote:

Would be good to briefly document, perhpas something like below

```suggestion
  
  /// Cached BlockFrequencyInfo, managed by getBFI.
  BlockFrequencyInfo *BFI = nullptr;
  
  /// Return the BlockFrequencyInfo for the function. If not cached already, fetch it via GetBFI.
  BlockFrequencyInfo &getBFI() {
    if (!BFI)
      BFI = &GetBFI();
    return *BFI;
  }
```


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


More information about the llvm-commits mailing list