Skip to content

Commit aa48664

Browse files
oharboeclaude
andcommitted
synth: remove obsolete make memory report and clean up code
make memory printed the inferred-memory table of the last synthesis from mem.json. Nothing in ORFS documents or calls it, and its mem_hierarchical.json branch has read a file nothing writes since hierarchical synthesis moved to estimates (d07d6d9). What is in use is the SYNTH_MEMORY_MAX_BITS check, which stops a doomed synthesis early. That check needed mem.json, a JSON dump of the whole design written on every synthesis, only so that mem_dump.py could find the memories in it. synth.tcl already loops over the same memories in Tcl for SYNTH_MOCK_LARGE_MEMORIES. The check now runs in that loop, synth_memory_max_bits in flow/scripts/memories/max_bits.tcl, and mem.json, mem_dump.py and make memory go. Every synthesis now logs each inferred memory with its dimensions, a ROM marked as one; the log lines are the ones the mock already wrote. A read/write memory over the limit stops synthesis with an error that names each one, its size and the limit. A ROM is not counted. The design is still sorted where json -o mem.json sorted it: a yosys backend sorts the design by name before it writes, and the passes after it depend on that order. write_json /dev/null keeps the sort without the file; dropping it changes results and would be its own change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent e53f73a commit aa48664

7 files changed

Lines changed: 158 additions & 264 deletions

File tree

‎flow/Makefile‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,6 @@ synth-report: synth
246246
do-synth-report:
247247
$(RUN_CMD) --log $(abspath $(LOG_DIR)/1_2_yosys_metrics.log) --tee -- $(OPENROAD_CMD) $(SCRIPTS_DIR)/synth_metrics.tcl
248248

249-
.PHONY: memory
250-
memory:
251-
if [ -f $(RESULTS_DIR)/mem_hierarchical.json ]; then \
252-
$(PYTHON_EXE) $(SCRIPTS_DIR)/mem_dump.py $(RESULTS_DIR)/mem_hierarchical.json; \
253-
fi
254-
$(PYTHON_EXE) $(SCRIPTS_DIR)/mem_dump.py $(RESULTS_DIR)/mem.json
255-
256249
# ==============================================================================
257250

258251

‎flow/scripts/mem_dump.py‎

Lines changed: 0 additions & 155 deletions
This file was deleted.

‎flow/scripts/memories/max_bits.tcl‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SYNTH_MEMORY_MAX_BITS: a read/write memory larger than max_bits belongs in
2+
# a macro (AUTO_MEMORIES, fakeram) or a mock, and must not go undetected into
3+
# flip-flops. Every inferred memory is logged with its dimensions. With mock
4+
# set (SYNTH_MOCK_LARGE_MEMORIES), each memory over the limit is shrunk to one
5+
# row and kept as a module when keep_mocked is set; otherwise synthesis stops,
6+
# naming every read/write memory over the limit. A ROM, a memory with no
7+
# write port, holds constants that synthesis maps to logic like any other
8+
# logic: it is not counted. Returns the mocked memories as a list of
9+
# {module width size}.
10+
proc synth_memory_max_bits { max_bits mock keep_mocked } {
11+
memory_collect
12+
set mocked {}
13+
set over {}
14+
foreach path [split [string trim [tee -q -s result.string select -list t:\$mem_v2]] "\n"] {
15+
set index [string first "/" $path]
16+
set module [string range $path 0 [expr { $index - 1 }]]
17+
set instance [string range $path [expr { $index + 1 }] end]
18+
19+
set width [rtlil::get_param -uint $module $instance WIDTH]
20+
set size [rtlil::get_param -uint $module $instance SIZE]
21+
set rom [expr { [rtlil::get_param -uint $module $instance WR_PORTS] == 0 }]
22+
set nbits [expr { $width * $size }]
23+
puts "Memory $path has dimensions $size x $width = $nbits[expr { $rom ? ", a ROM" : "" }]"
24+
if { $nbits <= $max_bits } {
25+
continue
26+
}
27+
if { $mock } {
28+
rtlil::set_param -uint $module $instance SIZE 1
29+
puts "Shrunk memory $path from $size rows to 1"
30+
lappend mocked [list $module $width $size]
31+
if { $keep_mocked } {
32+
select -module $module
33+
setattr -mod -set keep_hierarchy 1
34+
select -clear
35+
}
36+
} elseif { !$rom } {
37+
lappend over "$path $size x $width = $nbits"
38+
}
39+
}
40+
if { [llength $over] > 0 } {
41+
error "Memories over SYNTH_MEMORY_MAX_BITS=$max_bits, which would go into\
42+
flip-flops: [join $over {, }]. Put them in macros (AUTO_MEMORIES,\
43+
fakeram), mock them (SYNTH_MOCK_LARGE_MEMORIES=1) or raise the limit."
44+
}
45+
return $mocked
46+
}

‎flow/scripts/synth.tcl‎

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,37 +149,22 @@ if { [env_var_equals SYNTH_HDL_FRONTEND slang] } {
149149
opt_clean
150150
}
151151

152+
# Fail early if this synthesis run is doomed
153+
set mocked [synth_memory_max_bits $::env(SYNTH_MEMORY_MAX_BITS) \
154+
$::env(SYNTH_MOCK_LARGE_MEMORIES) $::env(SYNTH_KEEP_MOCKED_MEMORIES)]
152155
if { $::env(SYNTH_MOCK_LARGE_MEMORIES) } {
153-
memory_collect
154-
set select [tee -q -s result.string select -list t:\$mem_v2]
155156
set report_file [open $::env(REPORTS_DIR)/synth_mocked_memories.txt "w"]
156-
foreach path [split [string trim $select] "\n"] {
157-
set index [string first "/" $path]
158-
set module [string range $path 0 [expr { $index - 1 }]]
159-
set instance [string range $path [expr { $index + 1 }] end]
160-
161-
set width [rtlil::get_param -uint $module $instance WIDTH]
162-
set size [rtlil::get_param -uint $module $instance SIZE]
163-
set nbits [expr $width * $size]
164-
puts "Memory $path has dimensions $size x $width = $nbits"
165-
if { $nbits > $::env(SYNTH_MEMORY_MAX_BITS) } {
166-
rtlil::set_param -uint $module $instance SIZE 1
167-
puts "Shrunk memory $path from $size rows to 1"
168-
puts -nonewline $report_file "$module:\n width: $width\n size: $size\n"
169-
if { $::env(SYNTH_KEEP_MOCKED_MEMORIES) } {
170-
select -module $module
171-
setattr -mod -set keep_hierarchy 1
172-
select -clear
173-
}
174-
}
157+
foreach memory $mocked {
158+
lassign $memory module width size
159+
puts -nonewline $report_file "$module:\n width: $width\n size: $size\n"
175160
}
176161
close $report_file
177162
}
178163

179-
json -o $::env(RESULTS_DIR)/mem.json
180-
# Run report and check here so as to fail early if this synthesis run is doomed
181-
exec -- $::env(PYTHON_EXE) $::env(SCRIPTS_DIR)/mem_dump.py \
182-
--max-bits $::env(SYNTH_MEMORY_MAX_BITS) $::env(RESULTS_DIR)/mem.json
164+
# A yosys backend sorts the design by name before it writes, and the passes
165+
# below depend on that order; json -o mem.json did it here. The sort stays,
166+
# the file goes: dropping the sort changes results and is its own change.
167+
write_json /dev/null
183168

184169
if { [env_var_exists_and_non_empty SYNTH_RETIME_MODULES] } {
185170
select {*}$::env(SYNTH_RETIME_MODULES)

‎flow/scripts/synth_preamble.tcl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ proc read_checkpoint { file } {
4949
# canonicalization, one `<module> <area>` per line; see
5050
# docs/user/AutoMemories.md.
5151
source $::env(SCRIPTS_DIR)/memories/check_blackboxed.tcl
52+
source $::env(SCRIPTS_DIR)/memories/max_bits.tcl
5253

5354
proc auto_memories_areas { } {
5455
if { ![env_var_equals AUTO_MEMORIES 1] } {

‎flow/test/test_mem_dump.py‎

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)