coverage: Add CoverageKind::BlockMarker
This commit is contained in:
parent
73475d0d59
commit
c921ab1713
4 changed files with 24 additions and 2 deletions
|
@ -88,7 +88,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
||||||
match coverage.kind {
|
match coverage.kind {
|
||||||
// Marker statements have no effect during codegen,
|
// Marker statements have no effect during codegen,
|
||||||
// so return early and don't create `func_coverage`.
|
// so return early and don't create `func_coverage`.
|
||||||
CoverageKind::SpanMarker => return,
|
CoverageKind::SpanMarker | CoverageKind::BlockMarker { .. } => return,
|
||||||
// Match exhaustively to ensure that newly-added kinds are classified correctly.
|
// Match exhaustively to ensure that newly-added kinds are classified correctly.
|
||||||
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. } => {}
|
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. } => {}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
||||||
|
|
||||||
let Coverage { kind } = coverage;
|
let Coverage { kind } = coverage;
|
||||||
match *kind {
|
match *kind {
|
||||||
CoverageKind::SpanMarker => unreachable!(
|
CoverageKind::SpanMarker | CoverageKind::BlockMarker { .. } => unreachable!(
|
||||||
"unexpected marker statement {kind:?} should have caused an early return"
|
"unexpected marker statement {kind:?} should have caused an early return"
|
||||||
),
|
),
|
||||||
CoverageKind::CounterIncrement { id } => {
|
CoverageKind::CounterIncrement { id } => {
|
||||||
|
|
|
@ -6,6 +6,15 @@ use rustc_span::Symbol;
|
||||||
|
|
||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
|
|
||||||
|
rustc_index::newtype_index! {
|
||||||
|
/// Used by [`CoverageKind::BlockMarker`] to mark blocks during THIR-to-MIR
|
||||||
|
/// lowering, so that those blocks can be identified later.
|
||||||
|
#[derive(HashStable)]
|
||||||
|
#[encodable]
|
||||||
|
#[debug_format = "BlockMarkerId({})"]
|
||||||
|
pub struct BlockMarkerId {}
|
||||||
|
}
|
||||||
|
|
||||||
rustc_index::newtype_index! {
|
rustc_index::newtype_index! {
|
||||||
/// ID of a coverage counter. Values ascend from 0.
|
/// ID of a coverage counter. Values ascend from 0.
|
||||||
///
|
///
|
||||||
|
@ -83,6 +92,12 @@ pub enum CoverageKind {
|
||||||
/// codegen.
|
/// codegen.
|
||||||
SpanMarker,
|
SpanMarker,
|
||||||
|
|
||||||
|
/// Marks its enclosing basic block with an ID that can be referred to by
|
||||||
|
/// other data in the MIR body.
|
||||||
|
///
|
||||||
|
/// Has no effect during codegen.
|
||||||
|
BlockMarker { id: BlockMarkerId },
|
||||||
|
|
||||||
/// Marks the point in MIR control flow represented by a coverage counter.
|
/// Marks the point in MIR control flow represented by a coverage counter.
|
||||||
///
|
///
|
||||||
/// This is eventually lowered to `llvm.instrprof.increment` in LLVM IR.
|
/// This is eventually lowered to `llvm.instrprof.increment` in LLVM IR.
|
||||||
|
@ -107,6 +122,7 @@ impl Debug for CoverageKind {
|
||||||
use CoverageKind::*;
|
use CoverageKind::*;
|
||||||
match self {
|
match self {
|
||||||
SpanMarker => write!(fmt, "SpanMarker"),
|
SpanMarker => write!(fmt, "SpanMarker"),
|
||||||
|
BlockMarker { id } => write!(fmt, "BlockMarker({:?})", id.index()),
|
||||||
CounterIncrement { id } => write!(fmt, "CounterIncrement({:?})", id.index()),
|
CounterIncrement { id } => write!(fmt, "CounterIncrement({:?})", id.index()),
|
||||||
ExpressionUsed { id } => write!(fmt, "ExpressionUsed({:?})", id.index()),
|
ExpressionUsed { id } => write!(fmt, "ExpressionUsed({:?})", id.index()),
|
||||||
}
|
}
|
||||||
|
|
|
@ -405,6 +405,7 @@ TrivialTypeTraversalImpls! {
|
||||||
::rustc_hir::HirId,
|
::rustc_hir::HirId,
|
||||||
::rustc_hir::MatchSource,
|
::rustc_hir::MatchSource,
|
||||||
::rustc_target::asm::InlineAsmRegOrRegClass,
|
::rustc_target::asm::InlineAsmRegOrRegClass,
|
||||||
|
crate::mir::coverage::BlockMarkerId,
|
||||||
crate::mir::coverage::CounterId,
|
crate::mir::coverage::CounterId,
|
||||||
crate::mir::coverage::ExpressionId,
|
crate::mir::coverage::ExpressionId,
|
||||||
crate::mir::Local,
|
crate::mir::Local,
|
||||||
|
|
|
@ -225,6 +225,11 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
|
||||||
Some(statement.source_info.span)
|
Some(statement.source_info.span)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StatementKind::Coverage(box mir::Coverage {
|
||||||
|
// Block markers are used for branch coverage, so ignore them here.
|
||||||
|
kind: CoverageKind::BlockMarker {..}
|
||||||
|
}) => None,
|
||||||
|
|
||||||
StatementKind::Coverage(box mir::Coverage {
|
StatementKind::Coverage(box mir::Coverage {
|
||||||
// These coverage statements should not exist prior to coverage instrumentation.
|
// These coverage statements should not exist prior to coverage instrumentation.
|
||||||
kind: CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. }
|
kind: CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. }
|
||||||
|
|
Loading…
Add table
Reference in a new issue