Skip to content

Commit aacb50d

Browse files
committed
[Coverage] Make SingleByteCoverage work consistent to merging
- Round `Counts` as 1/0 - Confirm both `ExecutionCount` and `AltExecutionCount` are in range.
1 parent 178b57c commit aacb50d

File tree

6 files changed

+11
-4
lines changed

6 files changed

+11
-4
lines changed

compiler-rt/test/profile/instrprof-block-coverage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ int main(int argc, char *argv[]) {
4949

5050
// CHECK-ERROR-NOT: warning: {{.*}}: Found inconsistent block coverage
5151

52-
// COUNTS: Maximum function count: 4
52+
// COUNTS: Maximum function count: 1

compiler-rt/test/profile/instrprof-entry-coverage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ int main(int argc, char *argv[]) {
3636
// CHECK-DAG: foo
3737
// CHECK-DAG: bar
3838

39-
// COUNTS: Maximum function count: 2
39+
// COUNTS: Maximum function count: 1

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ struct InstrProfValueSiteRecord {
830830
/// Profiling information for a single function.
831831
struct InstrProfRecord {
832832
std::vector<uint64_t> Counts;
833+
bool SingleByteCoverage = false;
833834
std::vector<uint8_t> BitmapBytes;
834835

835836
InstrProfRecord() = default;
@@ -839,13 +840,15 @@ struct InstrProfRecord {
839840
: Counts(std::move(Counts)), BitmapBytes(std::move(BitmapBytes)) {}
840841
InstrProfRecord(InstrProfRecord &&) = default;
841842
InstrProfRecord(const InstrProfRecord &RHS)
842-
: Counts(RHS.Counts), BitmapBytes(RHS.BitmapBytes),
843+
: Counts(RHS.Counts), SingleByteCoverage(RHS.SingleByteCoverage),
844+
BitmapBytes(RHS.BitmapBytes),
843845
ValueData(RHS.ValueData
844846
? std::make_unique<ValueProfData>(*RHS.ValueData)
845847
: nullptr) {}
846848
InstrProfRecord &operator=(InstrProfRecord &&) = default;
847849
InstrProfRecord &operator=(const InstrProfRecord &RHS) {
848850
Counts = RHS.Counts;
851+
SingleByteCoverage = RHS.SingleByteCoverage;
849852
BitmapBytes = RHS.BitmapBytes;
850853
if (!RHS.ValueData) {
851854
ValueData = nullptr;

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,9 @@ Error CoverageMapping::loadFunctionRecord(
874874
consumeError(std::move(E));
875875
return Error::success();
876876
}
877+
assert(!SingleByteCoverage ||
878+
(0 <= *ExecutionCount && *ExecutionCount <= 1 &&
879+
0 <= *AltExecutionCount && *AltExecutionCount <= 1));
877880
Function.pushRegion(Region, *ExecutionCount, *AltExecutionCount);
878881

879882
// Record ExpansionRegion.

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ void InstrProfRecord::merge(InstrProfRecord &Other, uint64_t Weight,
952952
Value = getInstrMaxCountValue();
953953
Overflowed = true;
954954
}
955-
Counts[I] = Value;
955+
Counts[I] = (SingleByteCoverage && Value != 0 ? 1 : Value);
956956
if (Overflowed)
957957
Warn(instrprof_error::counter_overflow);
958958
}

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ Error RawInstrProfReader<IntPtrT>::readRawCounts(
743743

744744
Record.Counts.clear();
745745
Record.Counts.reserve(NumCounters);
746+
Record.SingleByteCoverage = hasSingleByteCoverage();
746747
for (uint32_t I = 0; I < NumCounters; I++) {
747748
const char *Ptr =
748749
CountersStart + CounterBaseOffset + I * getCounterTypeSize();

0 commit comments

Comments
 (0)