[llvm-branch-commits] [llvm] release/22.x: [Coverage] Fix quadratic propagation in RawCoverageMappingReader (#194996) (PR #195300)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri May 1 10:18:23 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
Author: llvmbot
<details>
<summary>Changes</summary>
Backport 0135cf99f3a22f701d9cae06867b885508d894f9
Requested by: @<!-- -->MaskRay
---
Full diff: https://github.com/llvm/llvm-project/pull/195300.diff
1 Files Affected:
- (modified) llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp (+13-6)
``````````diff
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index 8ce0e9f62666c..e89efe09d49e8 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -440,23 +440,30 @@ Error RawCoverageMappingReader::read() {
// Set the counters for the expansion regions.
// i.e. Counter of expansion region = counter of the first region
// from the expanded file.
- // Perform multiple passes to correctly propagate the counters through
- // all the nested expansion regions.
+ // Perform multiple passes to correctly propagate the counters through all the
+ // nested expansion regions. Iterate until no count changes.
SmallVector<CounterMappingRegion *, 8> FileIDExpansionRegionMapping;
FileIDExpansionRegionMapping.resize(VirtualFileMapping.size(), nullptr);
- for (unsigned Pass = 1, S = VirtualFileMapping.size(); Pass < S; ++Pass) {
+ for (;;) {
for (auto &R : MappingRegions) {
if (R.Kind != CounterMappingRegion::ExpansionRegion)
continue;
assert(!FileIDExpansionRegionMapping[R.ExpandedFileID]);
FileIDExpansionRegionMapping[R.ExpandedFileID] = &R;
}
+ bool Changed = false;
for (auto &R : MappingRegions) {
- if (FileIDExpansionRegionMapping[R.FileID]) {
- FileIDExpansionRegionMapping[R.FileID]->Count = R.Count;
- FileIDExpansionRegionMapping[R.FileID] = nullptr;
+ auto *&Slot = FileIDExpansionRegionMapping[R.FileID];
+ if (Slot) {
+ if (Slot->Count != R.Count) {
+ Slot->Count = R.Count;
+ Changed = true;
+ }
+ Slot = nullptr;
}
}
+ if (!Changed)
+ break;
}
return Error::success();
``````````
</details>
https://github.com/llvm/llvm-project/pull/195300
More information about the llvm-branch-commits
mailing list