-
Notifications
You must be signed in to change notification settings - Fork 49
[opt] net reader compaction
Shunning Jiang edited this page Oct 6, 2017
·
1 revision
def compact_net_readers( nets ):
ret = []
all_reads = set()
# First add normal update block reads
for read in s._all_read_upblks:
obj = s._id_obj[ read ]
while obj:
all_reads.add( id(obj) )
obj = obj._nested
# Then add net writers and top level output ports in the net!
for writer, readers in nets:
obj = writer
while obj:
all_reads.add( id(obj) )
obj = obj._nested
for reader in readers:
if isinstance( reader, OutVPort ) and reader._host == s:
obj = reader
while obj:
all_reads.add( id(obj) )
obj = obj._nested
# Now figure out if a reader can be safely removed from the net
# Check if the reader itself, its ancestors, or sibling slices are
# read somewhere else. If not, the reader can be moved from the net.
for writer, readers in nets:
new_readers = []
for x in readers:
flag = False
obj = x
while obj:
if id(obj) in all_reads:
flag = True
break
obj = obj._nested
if x._slice:
for obj in x._nested._slices.values(): # Check sibling slices
if x != obj and _overlap(obj._slice, x._slice) and \
id(obj) in all_reads:
flag = True
break
if flag: new_readers.append( x ) # is read somewhere else
ret.append( (writer, new_readers) )
return ret