Skip to content

Commit f3f7c20

Browse files
committed
coverage: Move CoverageIdsInfo into mir::coverage
1 parent 728f2da commit f3f7c20

File tree

5 files changed

+34
-35
lines changed

5 files changed

+34
-35
lines changed

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use rustc_data_structures::captures::Captures;
22
use rustc_data_structures::fx::FxIndexSet;
33
use rustc_index::bit_set::BitSet;
4-
use rustc_middle::mir::CoverageIdsInfo;
54
use rustc_middle::mir::coverage::{
6-
CounterId, CovTerm, Expression, ExpressionId, FunctionCoverageInfo, Mapping, MappingKind, Op,
7-
SourceRegion,
5+
CounterId, CovTerm, CoverageIdsInfo, Expression, ExpressionId, FunctionCoverageInfo, Mapping,
6+
MappingKind, Op, SourceRegion,
87
};
98
use rustc_middle::ty::Instance;
109
use tracing::debug;

Diff for: compiler/rustc_middle/src/mir/coverage.rs

+28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::fmt::{self, Debug, Formatter};
44

55
use rustc_index::IndexVec;
6+
use rustc_index::bit_set::BitSet;
67
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
78
use rustc_span::Span;
89

@@ -310,3 +311,30 @@ pub struct MCDCDecisionSpan {
310311
pub decision_depth: u16,
311312
pub num_conditions: usize,
312313
}
314+
315+
/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
316+
/// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
317+
/// have had a chance to potentially remove some of them.
318+
///
319+
/// Used by the `coverage_ids_info` query.
320+
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable)]
321+
pub struct CoverageIdsInfo {
322+
pub counters_seen: BitSet<CounterId>,
323+
pub expressions_seen: BitSet<ExpressionId>,
324+
}
325+
326+
impl CoverageIdsInfo {
327+
/// Coverage codegen needs to know how many coverage counters are ever
328+
/// incremented within a function, so that it can set the `num-counters`
329+
/// argument of the `llvm.instrprof.increment` intrinsic.
330+
///
331+
/// This may be less than the highest counter ID emitted by the
332+
/// InstrumentCoverage MIR pass, if the highest-numbered counter increments
333+
/// were removed by MIR optimizations.
334+
pub fn num_counters_after_mir_opts(&self) -> u32 {
335+
// FIXME(Zalathar): Currently this treats an unused counter as "used"
336+
// if its ID is less than that of the highest counter that really is
337+
// used. Fixing this would require adding a renumbering step somewhere.
338+
self.counters_seen.last_set_in(..).map_or(0, |max| max.as_u32() + 1)
339+
}
340+
}

Diff for: compiler/rustc_middle/src/mir/query.rs

+1-29
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ use rustc_abi::{FieldIdx, VariantIdx};
88
use rustc_data_structures::fx::FxIndexMap;
99
use rustc_errors::ErrorGuaranteed;
1010
use rustc_hir::def_id::LocalDefId;
11-
use rustc_index::bit_set::{BitMatrix, BitSet};
11+
use rustc_index::bit_set::BitMatrix;
1212
use rustc_index::{Idx, IndexVec};
1313
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
1414
use rustc_span::Span;
1515
use rustc_span::symbol::Symbol;
1616
use smallvec::SmallVec;
1717

1818
use super::{ConstValue, SourceInfo};
19-
use crate::mir;
2019
use crate::ty::fold::fold_regions;
2120
use crate::ty::{self, CoroutineArgsExt, OpaqueHiddenType, Ty, TyCtxt};
2221

@@ -351,30 +350,3 @@ pub struct DestructuredConstant<'tcx> {
351350
pub variant: Option<VariantIdx>,
352351
pub fields: &'tcx [(ConstValue<'tcx>, Ty<'tcx>)],
353352
}
354-
355-
/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
356-
/// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
357-
/// have had a chance to potentially remove some of them.
358-
///
359-
/// Used by the `coverage_ids_info` query.
360-
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable)]
361-
pub struct CoverageIdsInfo {
362-
pub counters_seen: BitSet<mir::coverage::CounterId>,
363-
pub expressions_seen: BitSet<mir::coverage::ExpressionId>,
364-
}
365-
366-
impl CoverageIdsInfo {
367-
/// Coverage codegen needs to know how many coverage counters are ever
368-
/// incremented within a function, so that it can set the `num-counters`
369-
/// argument of the `llvm.instrprof.increment` intrinsic.
370-
///
371-
/// This may be less than the highest counter ID emitted by the
372-
/// InstrumentCoverage MIR pass, if the highest-numbered counter increments
373-
/// were removed by MIR optimizations.
374-
pub fn num_counters_after_mir_opts(&self) -> u32 {
375-
// FIXME(Zalathar): Currently this treats an unused counter as "used"
376-
// if its ID is less than that of the highest counter that really is
377-
// used. Fixing this would require adding a renumbering step somewhere.
378-
self.counters_seen.last_set_in(..).map_or(0, |max| max.as_u32() + 1)
379-
}
380-
}

Diff for: compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ rustc_queries! {
581581
/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
582582
/// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
583583
/// have had a chance to potentially remove some of them.
584-
query coverage_ids_info(key: ty::InstanceKind<'tcx>) -> &'tcx mir::CoverageIdsInfo {
584+
query coverage_ids_info(key: ty::InstanceKind<'tcx>) -> &'tcx mir::coverage::CoverageIdsInfo {
585585
desc { |tcx| "retrieving coverage IDs info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
586586
arena_cache
587587
}

Diff for: compiler/rustc_mir_transform/src/coverage/query.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc_data_structures::captures::Captures;
22
use rustc_index::bit_set::BitSet;
33
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
4-
use rustc_middle::mir::coverage::{CovTerm, CoverageKind, MappingKind};
5-
use rustc_middle::mir::{Body, CoverageIdsInfo, Statement, StatementKind};
4+
use rustc_middle::mir::coverage::{CovTerm, CoverageIdsInfo, CoverageKind, MappingKind};
5+
use rustc_middle::mir::{Body, Statement, StatementKind};
66
use rustc_middle::query::TyCtxtAt;
77
use rustc_middle::ty::{self, TyCtxt};
88
use rustc_middle::util::Providers;

0 commit comments

Comments
 (0)