Skip to content

Commit

Permalink
Fix bug where multiple invokes of the same cg-cell pair were counted …
Browse files Browse the repository at this point in the history
…distinctly
  • Loading branch information
ayakayorihiro committed Mar 9, 2025
1 parent 7199858 commit 3b0ec8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions calyx/opt/src/passes/simplify_invoke_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,22 @@ impl Visitor for SimplifyInvokeWith {
) -> VisResult {
if let Some(cg) = &s.comb_group {
let cg_name = cg.borrow().name();
if let std::collections::hash_map::Entry::Vacant(_) =
self.comb_groups_to_modify.entry(cg_name)
{
// no invokes have used this comb group so far
self.comb_groups_to_modify
.insert(cg_name, s.comp.borrow().name());
} else {
// there is a different invoke that is using the same comb group
self.comb_groups_used_elsewhere.insert(cg_name);
let cell_name = s.comp.borrow().name();
let entry = self.comb_groups_to_modify.entry(cg_name);
match entry {
std::collections::hash_map::Entry::Occupied(occupied_entry) => {
// if the two invokes involve the same cell and comb group, then ignore
if !(*occupied_entry.key() == cg_name
&& *occupied_entry.get() == cell_name)
{
// there is a different invoke that is using the same comb group
self.comb_groups_used_elsewhere.insert(cg_name);
}
}
std::collections::hash_map::Entry::Vacant(_) => {
// no invokes have used this comb group so far
self.comb_groups_to_modify.insert(cg_name, cell_name);
}
}
}
Ok(Action::Continue)
Expand Down
2 changes: 1 addition & 1 deletion tests/passes/simplify-invoke-with/two_dup_invokes.expect
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ component main(@go go: 1, @clk clk: 1, @reset reset: 1) -> (@done done: 1) {
}
wires {
comb group comb_invoke {
mul_active.in = !mul.done ? 1'd1;
mul_active.in = !1'd0 ? 1'd1;
}
comb group comb_invoke1 {
mul2_active.in = !1'd0 ? 1'd1;
Expand Down

0 comments on commit 3b0ec8a

Please # to comment.