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]:
|
if marks[n]:
|
||||||
yield 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.
|
"""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)
|
queue = deque(origin_nodes)
|
||||||
for n in origin_nodes:
|
yielded = set()
|
||||||
marks[n] = True
|
while len(queue) > 0:
|
||||||
for n in self.topological_order():
|
n = queue.popleft()
|
||||||
if not marks[n]:
|
for line in n.outs.without_nones():
|
||||||
for line in n.ins.without_nones():
|
succ = line.reader
|
||||||
marks[n] |= marks[line.driver]
|
if succ not in yielded and node_filter(succ):
|
||||||
if marks[n]:
|
yielded.add(succ)
|
||||||
yield n
|
queue.append(succ)
|
||||||
|
yield n
|
||||||
|
|
||||||
def fanout_free_regions(self):
|
def fanout_free_regions(self):
|
||||||
for stem in self.reversed_topological_order():
|
for stem in self.reversed_topological_order():
|
||||||
|
|||||||
Reference in new issue
Block a user