Struct rustc_mir_transform::coverage::query::CoverageVisitor
source · struct CoverageVisitor {
info: CoverageInfo,
add_missing_operands: bool,
}
Expand description
The num_counters
argument to llvm.instrprof.increment
is the max counter_id + 1, or in
other words, the number of counter value references injected into the MIR (plus 1 for the
reserved ZERO
counter, which uses counter ID 0
when included in an expression). Injected
counters have a counter ID from 1..num_counters-1
.
num_expressions
is the number of counter expressions added to the MIR body.
Both num_counters
and num_expressions
are used to initialize new vectors, during backend
code generate, to lookup counters and expressions by simple u32 indexes.
MIR optimization may split and duplicate some BasicBlock sequences, or optimize out some code
including injected counters. (It is OK if some counters are optimized out, but those counters
are still included in the total num_counters
or num_expressions
.) Simply counting the
calls may not work; but computing the number of counters or expressions by adding 1
to the
highest ID (for a given instrumented function) is valid.
This visitor runs twice, first with add_missing_operands
set to false
, to find the maximum
counter ID and maximum expression ID based on their enum variant id
fields; then, as a
safeguard, with add_missing_operands
set to true
, to find any other counter or expression
IDs referenced by expression operands, if not already seen.
Ideally, each operand ID in a MIR CoverageKind::Expression
will have a separate MIR Coverage
statement for the Counter
or Expression
with the referenced ID. but since current or future
MIR optimizations can theoretically optimize out segments of a MIR, it may not be possible to
guarantee this, so the second pass ensures the CoverageInfo
counts include all referenced IDs.
Fields§
§info: CoverageInfo
§add_missing_operands: bool
Implementations§
source§impl CoverageVisitor
impl CoverageVisitor
sourcefn update_num_counters(&mut self, counter_id: u32)
fn update_num_counters(&mut self, counter_id: u32)
Updates num_counters
to the maximum encountered zero-based counter_id plus 1. Note the
final computed number of counters should be the number of all CoverageKind::Counter
statements in the MIR plus one for the implicit ZERO
counter.
sourcefn update_num_expressions(&mut self, expression_id: u32)
fn update_num_expressions(&mut self, expression_id: u32)
Computes an expression index for each expression ID, and updates num_expressions
to the
maximum encountered index plus 1.
fn update_from_expression_operand(&mut self, operand_id: u32)
fn visit_body(&mut self, body: &Body<'_>)
fn visit_coverage(&mut self, coverage: &Coverage)
Auto Trait Implementations§
impl RefUnwindSafe for CoverageVisitor
impl Send for CoverageVisitor
impl Sync for CoverageVisitor
impl Unpin for CoverageVisitor
impl UnwindSafe for CoverageVisitor
Blanket Implementations§
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 12 bytes