coverage: Store the number of counters/expressions in function coverage info
Coverage codegen can now allocate arrays based on the number of counters/expressions originally used by the instrumentor. The existing query that inspects coverage statements is still used for determining the number of counters passed to `llvm.instrprof.increment`. If some high-numbered counters were removed by MIR optimizations, the instrumented binary can potentially use less memory and disk space at runtime.
This commit is contained in:
@@ -140,4 +140,6 @@ impl Op {
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
pub struct FunctionCoverageInfo {
|
||||
pub function_source_hash: u64,
|
||||
pub num_counters: usize,
|
||||
pub num_expressions: usize,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Values computed by queries that use MIR.
|
||||
|
||||
use crate::mir;
|
||||
use crate::ty::{self, OpaqueHiddenType, Ty, TyCtxt};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::unord::UnordSet;
|
||||
@@ -445,14 +446,19 @@ pub struct DestructuredConstant<'tcx> {
|
||||
pub fields: &'tcx [(ConstValue<'tcx>, Ty<'tcx>)],
|
||||
}
|
||||
|
||||
/// Coverage information summarized from a MIR if instrumented for source code coverage (see
|
||||
/// compiler option `-Cinstrument-coverage`). This information is generated by the
|
||||
/// `InstrumentCoverage` MIR pass and can be retrieved via the `coverageinfo` query.
|
||||
/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
|
||||
/// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
|
||||
/// have had a chance to potentially remove some of them.
|
||||
///
|
||||
/// Used by the `coverage_ids_info` query.
|
||||
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable)]
|
||||
pub struct CoverageInfo {
|
||||
/// The total number of coverage region counters added to the MIR `Body`.
|
||||
pub num_counters: u32,
|
||||
|
||||
/// The total number of coverage region counter expressions added to the MIR `Body`.
|
||||
pub num_expressions: u32,
|
||||
pub struct CoverageIdsInfo {
|
||||
/// Coverage codegen needs to know the highest counter ID that is ever
|
||||
/// incremented within a function, so that it can set the `num-counters`
|
||||
/// argument of the `llvm.instrprof.increment` intrinsic.
|
||||
///
|
||||
/// This may be less than the highest counter ID emitted by the
|
||||
/// InstrumentCoverage MIR pass, if the highest-numbered counter increments
|
||||
/// were removed by MIR optimizations.
|
||||
pub max_counter_id: mir::coverage::CounterId,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user