faster fanout generator function
This commit is contained in:
1 parent
0c8a2b7746
commit
1f984c9bd9
1 file changed
+15
-11
+15
-11
@@ -614,20 +614,24 @@ class Circuit:
|
||||
if marks[n]:
|
||||
yield n
|
||||
|
||||
def fanout(self, origin_nodes):
|
||||
def fanout(self, origin_nodes: list[Node], node_filter = lambda n: 'dff' not in n.name.lower()):
|
||||
"""Generator function to iterate over the fan-out cone of a given list of origin nodes.
|
||||
|
||||
Nodes are yielded in topological order.
|
||||
origin_nodes are yielded first, followed by nodes driven by them in a breadth-first manner.
|
||||
The search stops at nodes for which node_filter returns False.
|
||||
Only origin_nodes and nodes for which node_filter returned True are yielded.
|
||||
By default, search stops at flip-flops.
|
||||
"""
|
||||
marks = [False] * len(self.nodes)
|
||||
for n in origin_nodes:
|
||||
marks[n] = True
|
||||
for n in self.topological_order():
|
||||
if not marks[n]:
|
||||
for line in n.ins.without_nones():
|
||||
marks[n] |= marks[line.driver]
|
||||
if marks[n]:
|
||||
yield n
|
||||
queue = deque(origin_nodes)
|
||||
yielded = set()
|
||||
while len(queue) > 0:
|
||||
n = queue.popleft()
|
||||
for line in n.outs.without_nones():
|
||||
succ = line.reader
|
||||
if succ not in yielded and node_filter(succ):
|
||||
yielded.add(succ)
|
||||
queue.append(succ)
|
||||
yield n
|
||||
|
||||
def fanout_free_regions(self):
|
||||
for stem in self.reversed_topological_order():
|
||||
|
||||
Reference in new issue
Block a user