Skip to content

Commit

Permalink
Fixed wires used in submodules being marked as unused
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Jan 5, 2024
1 parent a3bde49 commit 5988d3f
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/flattening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ pub struct SubModuleInstance {
pub outputs_start : usize,
pub local_wires : Box<[FlatID]>
}
impl SubModuleInstance {
pub fn inputs(&self) -> &[FlatID] {
&self.local_wires[..self.outputs_start]
}
pub fn outputs(&self) -> &[FlatID] {
&self.local_wires[self.outputs_start..]
}
}

#[derive(Debug)]
pub enum Instantiation {
Expand Down Expand Up @@ -654,14 +662,23 @@ impl FlattenedModule {
/* Additional Warnings */
pub fn find_unused_variables(&self) {
// Setup Wire Fanouts List for faster processing
let mut connection_fanin : FlatAlloc<Vec<FlatID>, FlatIDMarker> = self.instantiations.iter().map(|_| Vec::new()).collect();
let mut gathered_connection_fanin : FlatAlloc<Vec<FlatID>, FlatIDMarker> = self.instantiations.iter().map(|_| Vec::new()).collect();

for (_id, conn) in &self.instantiations {
if let Instantiation::Connection(conn) = conn {
connection_fanin[conn.to.root].push(conn.from);
if let Some(cond) = conn.condition {
connection_fanin[conn.to.root].push(cond);
for (inst_id, inst) in &self.instantiations {
match inst {
Instantiation::Connection(conn) => {
gathered_connection_fanin[conn.to.root].push(conn.from);
if let Some(cond) = conn.condition {
gathered_connection_fanin[conn.to.root].push(cond);
}
}
Instantiation::SubModule(sm) => {
for w in sm.outputs() {
gathered_connection_fanin[*w].push(inst_id);
}
}
Instantiation::WireDeclaration(_) => {} // Handle these outside
Instantiation::Wire(_) => {}
}
}

Expand All @@ -674,39 +691,29 @@ impl FlattenedModule {
wire_to_explore_queue.push(port.wire_id);
}

println!("Pre Explore");
println!("{:?}", connection_fanin);
println!("{:?}", is_instance_used_map);
println!("{:?}", wire_to_explore_queue);

while let Some(item) = wire_to_explore_queue.pop() {
let mut func = |from| {
let mut mark_not_unused = |from| {
if !is_instance_used_map[from] {
is_instance_used_map[from] = true;
wire_to_explore_queue.push(from);
}
};
match &self.instantiations[item] {
Instantiation::WireDeclaration(decl) => {
decl.typ.for_each_generative_input(&mut func);
decl.typ.for_each_generative_input(&mut mark_not_unused);
}
Instantiation::Wire(wire) => {
wire.source.for_each_input_wire(&mut func);
wire.source.for_each_input_wire(&mut mark_not_unused);
}
Instantiation::SubModule(submodule) => {
for (port_id, port) in submodule.local_wires.iter().enumerate() {
if port_id < submodule.outputs_start {
func(*port);
}
for port in submodule.inputs() {
mark_not_unused(*port);
}
}
Instantiation::Connection(_) => {unreachable!()}
}
for from in &connection_fanin[item] {
if !is_instance_used_map[*from] {
is_instance_used_map[*from] = true;
wire_to_explore_queue.push(*from);
}
for from in &gathered_connection_fanin[item] {
mark_not_unused(*from);
}
}

Expand Down

0 comments on commit 5988d3f

Please sign in to comment.