Skip to content

Commit 3feaab5

Browse files
committed
[coverage] Allow llvm not to change mappings order
1 parent 6f1013a commit 3feaab5

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

llvm/include/llvm/ProfileData/Coverage/CoverageMappingWriter.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ class CoverageMappingWriter {
4242
ArrayRef<unsigned> VirtualFileMapping;
4343
ArrayRef<CounterExpression> Expressions;
4444
MutableArrayRef<CounterMappingRegion> MappingRegions;
45+
bool KeepMappingOrder;
4546

4647
public:
4748
CoverageMappingWriter(ArrayRef<unsigned> VirtualFileMapping,
4849
ArrayRef<CounterExpression> Expressions,
49-
MutableArrayRef<CounterMappingRegion> MappingRegions)
50+
MutableArrayRef<CounterMappingRegion> MappingRegions,
51+
bool KeepMappingOrder = false)
5052
: VirtualFileMapping(VirtualFileMapping), Expressions(Expressions),
51-
MappingRegions(MappingRegions) {}
53+
MappingRegions(MappingRegions), KeepMappingOrder(KeepMappingOrder) {}
5254

5355
/// Write encoded coverage mapping data to the given output stream.
5456
void write(raw_ostream &OS);

llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp

+19-16
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,25 @@ void CoverageMappingWriter::write(raw_ostream &OS) {
161161

162162
// Sort the regions in an ascending order by the file id and the starting
163163
// location. Sort by region kinds to ensure stable order for tests.
164-
llvm::stable_sort(MappingRegions, [](const CounterMappingRegion &LHS,
165-
const CounterMappingRegion &RHS) {
166-
if (LHS.FileID != RHS.FileID)
167-
return LHS.FileID < RHS.FileID;
168-
if (LHS.startLoc() != RHS.startLoc())
169-
return LHS.startLoc() < RHS.startLoc();
170-
171-
// Put `Decision` before `Expansion`.
172-
auto getKindKey = [](CounterMappingRegion::RegionKind Kind) {
173-
return (Kind == CounterMappingRegion::MCDCDecisionRegion
174-
? 2 * CounterMappingRegion::ExpansionRegion - 1
175-
: 2 * Kind);
176-
};
177-
178-
return getKindKey(LHS.Kind) < getKindKey(RHS.Kind);
179-
});
164+
if (!KeepMappingOrder) {
165+
llvm::stable_sort(MappingRegions, [](const CounterMappingRegion &LHS,
166+
const CounterMappingRegion &RHS) {
167+
if (LHS.FileID != RHS.FileID)
168+
return LHS.FileID < RHS.FileID;
169+
170+
if (LHS.startLoc() != RHS.startLoc())
171+
return LHS.startLoc() < RHS.startLoc();
172+
173+
// Put `Decision` before `Expansion`.
174+
auto getKindKey = [](CounterMappingRegion::RegionKind Kind) {
175+
return (Kind == CounterMappingRegion::MCDCDecisionRegion
176+
? 2 * CounterMappingRegion::ExpansionRegion - 1
177+
: 2 * Kind);
178+
};
179+
180+
return getKindKey(LHS.Kind) < getKindKey(RHS.Kind);
181+
});
182+
}
180183

181184
// Write out the fileid -> filename mapping.
182185
encodeULEB128(VirtualFileMapping.size(), OS);

0 commit comments

Comments
 (0)