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§

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.

Computes an expression index for each expression ID, and updates num_expressions to the maximum encountered index plus 1.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

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