[llvm] CoverageMappingWriter: Emit `Decision` before `Expansion` (PR #78966)
NAKAMURA Takumi via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 22 04:58:50 PST 2024
https://github.com/chapuni created https://github.com/llvm/llvm-project/pull/78966
Test cases (for llvm) would be required.
https://godbolt.org/z/orE99Y7hT
```
foo:
Expansion,File 0, 4:11 -> 4:12 = #0 (Expanded file = 1)
Decision,File 0, 4:11 -> 4:20 = M:0, C:2
Expansion,File 0, 4:19 -> 4:20 = #1 (Expanded file = 2)
Branch,File 1, 1:14 -> 1:17 = #1, (#0 - #1) [1,2,0]
Branch,File 2, 1:14 -> 1:17 = #2, (#1 - #2) [2,0,0]
```
To relax scanning record, tweak order by `Decision < Expansion`. Relevant to #77871
>From 069bf8eb9250169a703f9afbb392626578f14bfa Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Sun, 21 Jan 2024 18:09:30 +0900
Subject: [PATCH] CoverageMappingWriter: Emit `Decision` before `Expansion`
---
.../ProfileData/Coverage/CoverageMappingWriter.cpp | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
index 1c7d8a8909c488..e8597676003a02 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
@@ -167,7 +167,18 @@ void CoverageMappingWriter::write(raw_ostream &OS) {
return LHS.FileID < RHS.FileID;
if (LHS.startLoc() != RHS.startLoc())
return LHS.startLoc() < RHS.startLoc();
- return LHS.Kind < RHS.Kind;
+
+ // Put `Decision` before `Expansion`.
+ auto getKindKey = [](CounterMappingRegion::RegionKind Kind) {
+ return (Kind == CounterMappingRegion::MCDCDecisionRegion
+ ? 2 * CounterMappingRegion::ExpansionRegion - 1
+ : 2 * Kind);
+ };
+
+ auto LHSKindKey = getKindKey(LHS.Kind);
+ auto RHSKindKey = getKindKey(RHS.Kind);
+
+ return LHSKindKey < RHSKindKey;
});
// Write out the fileid -> filename mapping.
More information about the llvm-commits
mailing list