[llvm] [NFC][Coverage] Do not use recursion for GCOV propagateCounts. (PR #68455)

Jon Roelofs via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 9 13:59:21 PDT 2023


================
@@ -366,24 +366,80 @@ GCOVBlock &GCOVFunction::getExitBlock() const {
 // outgoing edge counts by Kirchoff's circuit law. If the unmeasured arcs form a
 // spanning tree, the count for each unmeasured arc (GCOV_ARC_ON_TREE) can be
 // uniquely identified.
-uint64_t GCOVFunction::propagateCounts(const GCOVBlock &v, GCOVArc *pred) {
-  // If GCOV_ARC_ON_TREE edges do form a tree, visited is not needed; otherwise
-  // this prevents infinite recursion.
-  if (!visited.insert(&v).second)
-    return 0;
+uint64_t GCOVFunction::propagateCounts(const GCOVBlock &V, GCOVArc *Pred) {
+  struct StackElem {
+    const GCOVBlock &Block;
+    GCOVArc *Pred;
+    size_t PrevStackElemIdx;
----------------
jroelofs wrote:

What do you think about:
```suggestion
    StackElem *Parent;
```

I think that would increase clarity a little over keeping track of the index.

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


More information about the llvm-commits mailing list