Skip to content

Commit 6a86dc4

Browse files
authored
Merge pull request #389 from pllab/passes-update
Feed sanity check flag during optimization to subpasses
2 parents bf391f6 + c168040 commit 6a86dc4

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

pyrtl/passes.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ def optimize(update_working_block=True, block=None, skip_sanity_check=False):
3131
"""
3232
Return an optimized version of a synthesized hardware block.
3333
34-
:param Boolean update_working_block: Don't copy the block and optimize the
35-
new block
34+
:param bool update_working_block: Don't copy the block and optimize the
35+
new block (defaults to True)
3636
:param Block block: the block to optimize (defaults to working block)
37+
:param bool skip_sanity_check: Don't perform sanity checks on the block
38+
before/during/after the optimization passes (defaults to False).
39+
Sanity checks will always be performed if in debug mode.
3740
3841
Note:
3942
optimize works on all hardware designs, both synthesized and non synthesized
@@ -45,8 +48,8 @@ def optimize(update_working_block=True, block=None, skip_sanity_check=False):
4548
with set_working_block(block, no_sanity_check=True):
4649
if (not skip_sanity_check) or _get_debug_mode():
4750
block.sanity_check()
48-
_remove_wire_nets(block)
49-
_remove_slice_nets(block)
51+
_remove_wire_nets(block, skip_sanity_check)
52+
_remove_slice_nets(block, skip_sanity_check)
5053
constant_propagation(block, True)
5154
_remove_unlistened_nets(block)
5255
common_subexp_elimination(block)
@@ -73,7 +76,7 @@ def find_producer(self, item):
7376
return item
7477

7578

76-
def _remove_wire_nets(block):
79+
def _remove_wire_nets(block, skip_sanity_check=False):
7780
""" Remove all wire nodes from the block. """
7881

7982
wire_src_dict = _ProducerList()
@@ -100,10 +103,11 @@ def _remove_wire_nets(block):
100103
for dead_wirevector in wire_removal_set:
101104
block.remove_wirevector(dead_wirevector)
102105

103-
block.sanity_check()
106+
if (not skip_sanity_check) or _get_debug_mode():
107+
block.sanity_check()
104108

105109

106-
def _remove_slice_nets(block):
110+
def _remove_slice_nets(block, skip_sanity_check=False):
107111
""" Remove all unneeded slice nodes from the block.
108112
109113
Unneeded here means that the source and destination wires of a slice net are exactly
@@ -161,7 +165,8 @@ def is_net_slicing_entire_wire(net):
161165
del block.wirevector_by_name[dead_wirevector.name]
162166
block.wirevector_set.remove(dead_wirevector)
163167

164-
block.sanity_check()
168+
if (not skip_sanity_check) or _get_debug_mode():
169+
block.sanity_check()
165170

166171

167172
def constant_propagation(block, silence_unexpected_net_warnings=False):

0 commit comments

Comments
 (0)