Replace ExpressionOperandId
with enum Operand
Because the three kinds of operand are now distinguished explicitly, we no longer need fiddly code to disambiguate counter IDs and expression IDs based on the total number of counters/expressions in a function. This does increase the size of operands from 4 bytes to 8 bytes, but that shouldn't be a big deal since they are mostly stored inside boxed structures, and the current coverage code is not particularly size-optimized anyway.
This commit is contained in:
parent
5a808d40f4
commit
1a014d42f4
11 changed files with 96 additions and 147 deletions
|
@ -65,9 +65,9 @@ impl CoverageCounters {
|
|||
|
||||
fn make_expression<F>(
|
||||
&mut self,
|
||||
lhs: ExpressionOperandId,
|
||||
lhs: Operand,
|
||||
op: Op,
|
||||
rhs: ExpressionOperandId,
|
||||
rhs: Operand,
|
||||
debug_block_label_fn: F,
|
||||
) -> CoverageKind
|
||||
where
|
||||
|
@ -81,13 +81,13 @@ impl CoverageCounters {
|
|||
expression
|
||||
}
|
||||
|
||||
pub fn make_identity_counter(&mut self, counter_operand: ExpressionOperandId) -> CoverageKind {
|
||||
pub fn make_identity_counter(&mut self, counter_operand: Operand) -> CoverageKind {
|
||||
let some_debug_block_label = if self.debug_counters.is_enabled() {
|
||||
self.debug_counters.some_block_label(counter_operand).cloned()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.make_expression(counter_operand, Op::Add, ExpressionOperandId::ZERO, || {
|
||||
self.make_expression(counter_operand, Op::Add, Operand::Zero, || {
|
||||
some_debug_block_label.clone()
|
||||
})
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ impl<'a> BcbCounters<'a> {
|
|||
&mut self,
|
||||
traversal: &mut TraverseCoverageGraphWithLoops,
|
||||
branching_bcb: BasicCoverageBlock,
|
||||
branching_counter_operand: ExpressionOperandId,
|
||||
branching_counter_operand: Operand,
|
||||
collect_intermediate_expressions: &mut Vec<CoverageKind>,
|
||||
) -> Result<(), Error> {
|
||||
let branches = self.bcb_branches(branching_bcb);
|
||||
|
@ -261,7 +261,7 @@ impl<'a> BcbCounters<'a> {
|
|||
" [new intermediate expression: {}]",
|
||||
self.format_counter(&intermediate_expression)
|
||||
);
|
||||
let intermediate_expression_operand = intermediate_expression.as_operand_id();
|
||||
let intermediate_expression_operand = intermediate_expression.as_operand();
|
||||
collect_intermediate_expressions.push(intermediate_expression);
|
||||
some_sumup_counter_operand.replace(intermediate_expression_operand);
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ impl<'a> BcbCounters<'a> {
|
|||
&mut self,
|
||||
bcb: BasicCoverageBlock,
|
||||
collect_intermediate_expressions: &mut Vec<CoverageKind>,
|
||||
) -> Result<ExpressionOperandId, Error> {
|
||||
) -> Result<Operand, Error> {
|
||||
self.recursive_get_or_make_counter_operand(bcb, collect_intermediate_expressions, 1)
|
||||
}
|
||||
|
||||
|
@ -307,7 +307,7 @@ impl<'a> BcbCounters<'a> {
|
|||
bcb: BasicCoverageBlock,
|
||||
collect_intermediate_expressions: &mut Vec<CoverageKind>,
|
||||
debug_indent_level: usize,
|
||||
) -> Result<ExpressionOperandId, Error> {
|
||||
) -> Result<Operand, Error> {
|
||||
// If the BCB already has a counter, return it.
|
||||
if let Some(counter_kind) = self.basic_coverage_blocks[bcb].counter() {
|
||||
debug!(
|
||||
|
@ -316,7 +316,7 @@ impl<'a> BcbCounters<'a> {
|
|||
bcb,
|
||||
self.format_counter(counter_kind),
|
||||
);
|
||||
return Ok(counter_kind.as_operand_id());
|
||||
return Ok(counter_kind.as_operand());
|
||||
}
|
||||
|
||||
// A BCB with only one incoming edge gets a simple `Counter` (via `make_counter()`).
|
||||
|
@ -383,7 +383,7 @@ impl<'a> BcbCounters<'a> {
|
|||
NESTED_INDENT.repeat(debug_indent_level),
|
||||
self.format_counter(&intermediate_expression)
|
||||
);
|
||||
let intermediate_expression_operand = intermediate_expression.as_operand_id();
|
||||
let intermediate_expression_operand = intermediate_expression.as_operand();
|
||||
collect_intermediate_expressions.push(intermediate_expression);
|
||||
some_sumup_edge_counter_operand.replace(intermediate_expression_operand);
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ impl<'a> BcbCounters<'a> {
|
|||
from_bcb: BasicCoverageBlock,
|
||||
to_bcb: BasicCoverageBlock,
|
||||
collect_intermediate_expressions: &mut Vec<CoverageKind>,
|
||||
) -> Result<ExpressionOperandId, Error> {
|
||||
) -> Result<Operand, Error> {
|
||||
self.recursive_get_or_make_edge_counter_operand(
|
||||
from_bcb,
|
||||
to_bcb,
|
||||
|
@ -423,7 +423,7 @@ impl<'a> BcbCounters<'a> {
|
|||
to_bcb: BasicCoverageBlock,
|
||||
collect_intermediate_expressions: &mut Vec<CoverageKind>,
|
||||
debug_indent_level: usize,
|
||||
) -> Result<ExpressionOperandId, Error> {
|
||||
) -> Result<Operand, Error> {
|
||||
// If the source BCB has only one successor (assumed to be the given target), an edge
|
||||
// counter is unnecessary. Just get or make a counter for the source BCB.
|
||||
let successors = self.bcb_successors(from_bcb).iter();
|
||||
|
@ -444,7 +444,7 @@ impl<'a> BcbCounters<'a> {
|
|||
to_bcb,
|
||||
self.format_counter(counter_kind)
|
||||
);
|
||||
return Ok(counter_kind.as_operand_id());
|
||||
return Ok(counter_kind.as_operand());
|
||||
}
|
||||
|
||||
// Make a new counter to count this edge.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue