Skip to content

Commit

Permalink
analysis: fix use counts (again ...)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Nov 29, 2023
1 parent a71aa1c commit f47542d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/ir/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,36 @@ pub fn count_expr_uses(ctx: &Context, sys: &TransitionSystem) -> Vec<u32> {
.iter()
.map(|(e, _)| *e),
);
// ensure that all roots start with count 1
for expr in todo.iter() {
*use_count.get_mut(*expr) = 1;
}

while let Some(expr) = todo.pop() {
// when we process an item for the first time, we set the count to 1
*use_count.get_mut(expr) = 1;
if let Some(state) = states.get(&expr) {
// for states, we also want to mark the initial and the next expression as used
if let Some(init) = state.init {
*use_count.get_mut(init) = 1;
todo.push(init);
let count = use_count.get_mut(init);
if *count == 0 {
*count = 1;
todo.push(init);
}
}
if let Some(next) = state.next {
*use_count.get_mut(next) = 1;
todo.push(next);
let count = use_count.get_mut(next);
if *count == 0 {
*count = 1;
todo.push(next);
}
}
}

ctx.get(expr).for_each_child(|child| {
let count = use_count.get_mut(*child);
let is_first_use = *count == 0;
*count += 1;
if is_first_use {
todo.push(*child);
} else {
*count += 1;
}
});
}
Expand Down

0 comments on commit f47542d

Please sign in to comment.