-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coverage: Clean up marker statements that aren't needed later
Some of the marker statements used by coverage are added during MIR building for use by the InstrumentCoverage pass (during analysis), and are not needed afterwards.
Showing
6 changed files
with
148 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/mir-opt/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
- // MIR for `main` before CleanupPostBorrowck | ||
+ // MIR for `main` after CleanupPostBorrowck | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let mut _1: bool; | ||
|
||
coverage branch { true: BlockMarkerId(0), false: BlockMarkerId(1) } => /the/src/instrument_coverage_cleanup.rs:17:8: 17:36 (#0) | ||
|
||
coverage ExpressionId(0) => Expression { lhs: Counter(0), op: Subtract, rhs: Counter(1) }; | ||
coverage ExpressionId(1) => Expression { lhs: Counter(1), op: Add, rhs: Expression(0) }; | ||
coverage Code(Counter(0)) => /the/src/instrument_coverage_cleanup.rs:16:1 - 17:36; | ||
coverage Code(Expression(0)) => /the/src/instrument_coverage_cleanup.rs:17:37 - 17:39; | ||
coverage Code(Counter(1)) => /the/src/instrument_coverage_cleanup.rs:17:39 - 17:40; | ||
coverage Code(Expression(1)) => /the/src/instrument_coverage_cleanup.rs:18:1 - 18:2; | ||
coverage Branch { true_term: Expression(0), false_term: Counter(1) } => /the/src/instrument_coverage_cleanup.rs:17:8 - 17:36; | ||
|
||
bb0: { | ||
Coverage::CounterIncrement(0); | ||
- Coverage::SpanMarker; | ||
+ nop; | ||
StorageLive(_1); | ||
_1 = std::hint::black_box::<bool>(const true) -> [return: bb1, unwind: bb5]; | ||
} | ||
|
||
bb1: { | ||
switchInt(move _1) -> [0: bb3, otherwise: bb2]; | ||
} | ||
|
||
bb2: { | ||
Coverage::CounterIncrement(1); | ||
- Coverage::BlockMarker(1); | ||
+ nop; | ||
_0 = const (); | ||
goto -> bb4; | ||
} | ||
|
||
bb3: { | ||
Coverage::ExpressionUsed(0); | ||
- Coverage::BlockMarker(0); | ||
+ nop; | ||
_0 = const (); | ||
goto -> bb4; | ||
} | ||
|
||
bb4: { | ||
Coverage::ExpressionUsed(1); | ||
StorageDead(_1); | ||
return; | ||
} | ||
|
||
bb5 (cleanup): { | ||
resume; | ||
} | ||
} | ||
|
53 changes: 53 additions & 0 deletions
53
tests/mir-opt/instrument_coverage_cleanup.main.InstrumentCoverage.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
- // MIR for `main` before InstrumentCoverage | ||
+ // MIR for `main` after InstrumentCoverage | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let mut _1: bool; | ||
|
||
coverage branch { true: BlockMarkerId(0), false: BlockMarkerId(1) } => /the/src/instrument_coverage_cleanup.rs:17:8: 17:36 (#0) | ||
|
||
+ coverage ExpressionId(0) => Expression { lhs: Counter(0), op: Subtract, rhs: Counter(1) }; | ||
+ coverage ExpressionId(1) => Expression { lhs: Counter(1), op: Add, rhs: Expression(0) }; | ||
+ coverage Code(Counter(0)) => /the/src/instrument_coverage_cleanup.rs:16:1 - 17:36; | ||
+ coverage Code(Expression(0)) => /the/src/instrument_coverage_cleanup.rs:17:37 - 17:39; | ||
+ coverage Code(Counter(1)) => /the/src/instrument_coverage_cleanup.rs:17:39 - 17:40; | ||
+ coverage Code(Expression(1)) => /the/src/instrument_coverage_cleanup.rs:18:1 - 18:2; | ||
+ coverage Branch { true_term: Expression(0), false_term: Counter(1) } => /the/src/instrument_coverage_cleanup.rs:17:8 - 17:36; | ||
+ | ||
bb0: { | ||
+ Coverage::CounterIncrement(0); | ||
Coverage::SpanMarker; | ||
StorageLive(_1); | ||
_1 = std::hint::black_box::<bool>(const true) -> [return: bb1, unwind: bb5]; | ||
} | ||
|
||
bb1: { | ||
switchInt(move _1) -> [0: bb3, otherwise: bb2]; | ||
} | ||
|
||
bb2: { | ||
+ Coverage::CounterIncrement(1); | ||
Coverage::BlockMarker(1); | ||
_0 = const (); | ||
goto -> bb4; | ||
} | ||
|
||
bb3: { | ||
+ Coverage::ExpressionUsed(0); | ||
Coverage::BlockMarker(0); | ||
_0 = const (); | ||
goto -> bb4; | ||
} | ||
|
||
bb4: { | ||
+ Coverage::ExpressionUsed(1); | ||
StorageDead(_1); | ||
return; | ||
} | ||
|
||
bb5 (cleanup): { | ||
resume; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Test that CleanupPostBorrowck cleans up the marker statements that are | ||
// inserted during MIR building (after InstrumentCoverage is done with them), | ||
// but leaves the statements that were added by InstrumentCoverage. | ||
// | ||
// Removed statement kinds: BlockMarker, SpanMarker | ||
// Retained statement kinds: CounterIncrement, ExpressionUsed | ||
|
||
//@ unit-test: InstrumentCoverage | ||
//@ needs-profiler-support | ||
//@ ignore-windows (see ./instrument_coverage.rs) | ||
//@ compile-flags: -Cinstrument-coverage -Zcoverage-options=branch | ||
//@ compile-flags: --remap-path-prefix={{src-base}}=/the/src | ||
|
||
// EMIT_MIR instrument_coverage_cleanup.main.InstrumentCoverage.diff | ||
// EMIT_MIR instrument_coverage_cleanup.main.CleanupPostBorrowck.diff | ||
fn main() { | ||
if !core::hint::black_box(true) {} | ||
} | ||
|
||
// CHECK-NOT: Coverage::BlockMarker | ||
// CHECK-NOT: Coverage::SpanMarker | ||
// CHECK: Coverage::CounterIncrement | ||
// CHECK-NOT: Coverage::BlockMarker | ||
// CHECK-NOT: Coverage::SpanMarker |