[llvm] [ctx_prof] Fix checks in `PGOCtxprofFlattening` (PR #108467)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 16 09:54:23 PDT 2024


================
@@ -58,22 +60,28 @@ class ProfileAnnotator final {
 
     // Pass AssumeAllKnown when we try to propagate counts from edges to BBs -
     // because all the edge counters must be known.
-    uint64_t getEdgeSum(const SmallVector<EdgeInfo *> &Edges,
-                        bool AssumeAllKnown) const {
-      uint64_t Sum = 0;
+    // Return std::nullopt if there were no edges to sum. The user can decide
+    // how to interpret that.
+    std::optional<uint64_t> getEdgeSum(const SmallVector<EdgeInfo *> &Edges,
+                                       bool AssumeAllKnown) const {
+      std::optional<uint64_t> Sum;
       for (const auto *E : Edges)
-        if (E)
-          Sum += AssumeAllKnown ? *E->Count : E->Count.value_or(0U);
+        if (E) {
----------------
teresajohnson wrote:

What is the situation where we have an entry in the Edges vector but it is null?

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


More information about the llvm-commits mailing list