Skip to content

Commit b479ed8

Browse files
pamauryandreaskurth
authored andcommitted
[topgen] Precompute memories mapping
Signed-off-by: Amaury Pouly <[email protected]>
1 parent df9c841 commit b479ed8

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

util/topgen/lib.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,11 @@ def __init__(self, top_info: ConfigT, name_to_block: IpBlocksT, enum_type,
927927
self._init_clkmgr_clocks()
928928

929929
self.device_regions = defaultdict(dict)
930+
self.device_memories = defaultdict(dict)
930931
self.subranges = defaultdict(dict)
931932
for addr_space in top_info['addr_spaces']:
932933
self._init_device_regions(addr_space['name'])
934+
self._init_device_memories(addr_space['name'])
933935
self._init_subranges(addr_space['name'])
934936

935937
def _init_device_regions(self, addr_space):
@@ -967,13 +969,16 @@ def all_device_regions(self) -> Dict[str, Dict[str, MemoryRegion]]:
967969
def devices(
968970
self, addr_space
969971
) -> List[Tuple[Tuple[str, Optional[str]], MemoryRegion]]:
970-
'''Return a list of MemoryRegion objects for devices on the bus
972+
'''Return a list of MemoryRegion objects for devices on the bus.
971973
972974
The list returned is pairs (full_if, region) where full_if is itself a
973975
pair (inst_name, if_name). inst_name is the name of some IP block
974976
instantiation. if_name is the name of the interface (may be None).
975977
region is a MemoryRegion object representing the device.
976978
979+
Note that this list only includes register bloks. Use `memories()`
980+
to access the list of memories.
981+
977982
Parameters:
978983
addr_space: The address space representing the bus for generation.
979984
'''
@@ -988,19 +993,13 @@ def devices(
988993

989994
return ret
990995

991-
def memories(self, addr_space) -> List[Tuple[Tuple[str, str], MemoryRegion]]:
992-
'''Return a list of MemoryRegions objects for memories on the bus.
993-
994-
The list returned is pairs (full_if, region) where full_if is itself a
995-
pair (inst_name, if_name). inst_name is the name of some IP block
996-
instantiation. if_name is the name of the interface. region is a
997-
MemoryRegion representing the memory, and its name is set to the full
998-
interface name (<IP instance name>_<interface>).
996+
def _init_device_memories(self, addr_space):
997+
'''Initialize the device_memories dictionary.
999998
1000-
Parameters:
1001-
addr_space: The address space representing the bus for generation.
999+
The dictionary entry maps memories to MemoryRegions for the given
1000+
addr_space.
10021001
'''
1003-
ret = []
1002+
device_memories = defaultdict(dict)
10041003

10051004
for inst in self.top['module']:
10061005
if "memory" in inst:
@@ -1010,13 +1009,33 @@ def memories(self, addr_space) -> List[Tuple[Tuple[str, str], MemoryRegion]]:
10101009
if addr_space not in base:
10111010
continue
10121011

1013-
full_if = (inst['name'], if_name)
10141012
full_if_name = Name.from_snake_case(inst['name']) + \
10151013
Name.from_snake_case(if_name)
10161014
region = MemoryRegion(self._top_name, full_if_name, addr_space,
10171015
base[addr_space], size)
10181016

1019-
ret.append((full_if, region))
1017+
device_memories[inst['name']].update({if_name: region})
1018+
1019+
self.device_memories[addr_space] = device_memories
1020+
1021+
def memories(self, addr_space) -> List[Tuple[Tuple[str, str], MemoryRegion]]:
1022+
'''Return a list of MemoryRegions objects for memories on the bus.
1023+
1024+
The list returned is pairs (full_if, region) where full_if is itself a
1025+
pair (inst_name, if_name). inst_name is the name of some IP block
1026+
instantiation. if_name is the name of the interface. region is a
1027+
MemoryRegion representing the memory, and its name is set to the full
1028+
interface name (<IP instance name>_<interface>).
1029+
1030+
Parameters:
1031+
addr_space: The address space representing the bus for generation.
1032+
'''
1033+
ret = []
1034+
1035+
for (inst, regions) in self.device_memories[addr_space].items():
1036+
for (if_name, region) in regions.items():
1037+
full_if = (inst, if_name)
1038+
ret.append((full_if, region))
10201039

10211040
return ret
10221041

0 commit comments

Comments
 (0)