coverage: Eliminate more counters by giving them to unreachable nodes
When preparing a function's coverage counters and metadata during codegen, any part of the original coverage graph that was removed by MIR optimizations can be treated as having an execution count of zero. Somewhat counter-intuitively, if we give those unreachable nodes a _higher_ priority for receiving physical counters (instead of counter expressions), that ends up reducing the total number of physical counters needed. This works because if a node is unreachable, we don't actually create a physical counter for it. Instead that node gets a fixed zero counter, and any other node that would have relied on that physical counter in its counter expression can just ignore that term completely.
This commit is contained in:
@@ -114,12 +114,8 @@ pub(crate) fn transcribe_counters(
|
||||
let mut new_counters_for_sites = |sites: Vec<BasicCoverageBlock>| {
|
||||
sites.into_iter().map(|node| new.ensure_phys_counter(node)).collect::<Vec<_>>()
|
||||
};
|
||||
let mut pos = new_counters_for_sites(pos);
|
||||
let mut neg = new_counters_for_sites(neg);
|
||||
|
||||
// These sorts are also not strictly necessary; see above.
|
||||
pos.sort();
|
||||
neg.sort();
|
||||
let pos = new_counters_for_sites(pos);
|
||||
let neg = new_counters_for_sites(neg);
|
||||
|
||||
let pos_counter = new.make_sum(&pos).unwrap_or(CovTerm::Zero);
|
||||
let new_counter = new.make_subtracted_sum(pos_counter, &neg);
|
||||
|
||||
Reference in New Issue
Block a user