diff options
| author | bors <bors@rust-lang.org> | 2023-10-03 18:36:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-03 18:36:21 +0000 |
| commit | 36aab8df0ab8a76f1c4f95ce8becefdd8a6fe526 (patch) | |
| tree | a3e01fc97d6ef483471e82a089ee2cd9a2c30185 /compiler/rustc_mir_transform/src/coverage/query.rs | |
| parent | 268d6250299b4f08f8e669a2889fdf71388d1f39 (diff) | |
| parent | 053c4f94a098be5fbb80ca881b01cc8e9c64a8a5 (diff) | |
| download | rust-36aab8df0ab8a76f1c4f95ce8becefdd8a6fe526.tar.gz rust-36aab8df0ab8a76f1c4f95ce8becefdd8a6fe526.zip | |
Auto merge of #115301 - Zalathar:regions-vec, r=davidtwco
coverage: Allow each coverage statement to have multiple code regions The original implementation of coverage instrumentation was built around the assumption that a coverage counter/expression would be associated with *up to one* code region. When it was discovered that *multiple* regions would sometimes need to share a counter, a workaround was found: for the remaining regions, the instrumentor would create a fresh expression that adds zero to the existing counter/expression. That got the job done, but resulted in some awkward code, and produces unnecessarily complicated coverage maps in the final binary. --- This PR removes that tension by changing `StatementKind::Coverage`'s code region field from `Option<CodeRegion>` to `Vec<CodeRegion>`. The changes on the codegen side are fairly straightforward. As long as each `CoverageKind::Counter` only injects one `llvm.instrprof.increment`, the rest of coverage codegen is happy to handle multiple regions mapped to the same counter/expression, with only minor option-to-vec adjustments. On the instrumentor/mir-transform side, we can get rid of the code that creates extra (x + 0) expressions. Instead we gather all of the code regions associated with a single BCB, and inject them all into one coverage statement. --- There are several patches here but they can be divided in to three phases: - Preparatory work - Actually switching over to multiple regions per coverage statement - Cleaning up So viewing the patches individually may be easier.
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/query.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/query.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/query.rs b/compiler/rustc_mir_transform/src/coverage/query.rs index 56365c5d474..2c0164e765c 100644 --- a/compiler/rustc_mir_transform/src/coverage/query.rs +++ b/compiler/rustc_mir_transform/src/coverage/query.rs @@ -93,8 +93,8 @@ fn coverageinfo<'tcx>(tcx: TyCtxt<'tcx>, instance_def: ty::InstanceDef<'tcx>) -> fn covered_code_regions(tcx: TyCtxt<'_>, def_id: DefId) -> Vec<&CodeRegion> { let body = mir_body(tcx, def_id); all_coverage_in_mir_body(body) - // Not all coverage statements have an attached code region. - .filter_map(|coverage| coverage.code_region.as_ref()) + // Coverage statements have a list of code regions (possibly empty). + .flat_map(|coverage| coverage.code_regions.as_slice()) .collect() } |
