@@ -31,9 +31,12 @@ def optimize(update_working_block=True, block=None, skip_sanity_check=False):
31
31
"""
32
32
Return an optimized version of a synthesized hardware block.
33
33
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)
36
36
: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.
37
40
38
41
Note:
39
42
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):
45
48
with set_working_block (block , no_sanity_check = True ):
46
49
if (not skip_sanity_check ) or _get_debug_mode ():
47
50
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 )
50
53
constant_propagation (block , True )
51
54
_remove_unlistened_nets (block )
52
55
common_subexp_elimination (block )
@@ -73,7 +76,7 @@ def find_producer(self, item):
73
76
return item
74
77
75
78
76
- def _remove_wire_nets (block ):
79
+ def _remove_wire_nets (block , skip_sanity_check = False ):
77
80
""" Remove all wire nodes from the block. """
78
81
79
82
wire_src_dict = _ProducerList ()
@@ -100,10 +103,11 @@ def _remove_wire_nets(block):
100
103
for dead_wirevector in wire_removal_set :
101
104
block .remove_wirevector (dead_wirevector )
102
105
103
- block .sanity_check ()
106
+ if (not skip_sanity_check ) or _get_debug_mode ():
107
+ block .sanity_check ()
104
108
105
109
106
- def _remove_slice_nets (block ):
110
+ def _remove_slice_nets (block , skip_sanity_check = False ):
107
111
""" Remove all unneeded slice nodes from the block.
108
112
109
113
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):
161
165
del block .wirevector_by_name [dead_wirevector .name ]
162
166
block .wirevector_set .remove (dead_wirevector )
163
167
164
- block .sanity_check ()
168
+ if (not skip_sanity_check ) or _get_debug_mode ():
169
+ block .sanity_check ()
165
170
166
171
167
172
def constant_propagation (block , silence_unexpected_net_warnings = False ):
0 commit comments