Repository navigation
memories: run the memory passes on the modules that hold memory cells - #4622
Conversation
`memory -nomap` in extract_memories.tcl walks every module of the design
in each of its passes, and memory_dff builds its per-bit driver and
consumer index (ModWalker::setup, memory_dff.cc:225) for a module before
run() asks whether the module has a memory; opt_mem_priority and
opt_mem_feedback scan every module's cells the same way. On a design that
keeps its memories in small generated modules and its logic in large
ones -- a firtool core has every memory in its own ram_* module -- the
index over the memory-less modules is nearly the whole cost of the step.
Measured on XiangShan's flat XSCore (1870 modules, 407 with memory cells,
read through slang, yosys 0.68), the memory passes alone:
unscoped 721 s memory_dff 462, opt_mem_priority 67,
opt_mem_feedback 52, two opt_clean 99, share 37
scoped 64 s memory_dff 24, opt_mem_priority 27
Both produce the same 407 $mem_v2 cells. The extraction step as a whole
went from about fifteen minutes to under four, and the four remaining
minutes are reading and proc.
memory_bmux2rom still runs first and unscoped, since it is what turns a
module's constant muxes into a memory. The module list comes from the
memory cells' names (the module before the first slash) rather than the
selection's `%m` expansion: `%m` leaves a module partially selected when
its name carries a `$`, as slang's uniquified names do, and every pass
then skips the module with "Ignoring partially selected module" and no
memory is collected. write_json -selected writes the memory modules
only; gen_memories.py's detector reads each module's $mem_v2 cells and
nothing across modules.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
There was a problem hiding this comment.
Code Review
This pull request optimizes the memory extraction process in extract_memories.tcl by scoping the memory -nomap pass only to modules that contain memory cells, which significantly improves performance on designs with large logic modules. Feedback suggests enhancing the robustness of this extraction by supporting older memory cell types and improving the parsing of the select -list output to handle potential whitespace and invalid module names safely.
read_verilog leaves memory reads as $memrd until memory_collect, so the _v2-only list found a memory's module through its write or init cells alone. t:$mem* takes every memory cell type. The module name is the cell path up to its first slash. An escaped name holding a slash is cut short, select warns that it matched nothing, and that module's memories would be skipped without an error. The selection must now hold every memory cell, or the step stops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
🔍 QoR checkMetrics reflect the PR merge build — i.e. what will land on the target branch. Commit 62 design(s) checked — 0 with regression(s), 0 without a comparable baseline. |
|
Codex: Review finding — needs changes. At extract_memories.tcl:56, splitting a cell path at the first |
The module list was cut out of `select -list` lines at the first slash and handed back to `select`. An escaped module name may itself hold a slash, as in `\ram/one`: the cut name matched nothing and the step stopped. A memory's own name may hold one too, so no cut point is right. `t:$mem* %m` selects every module that holds a memory cell, whole, and never goes through a name. Checked with slang on yosys 0.68 against master's unscoped run: slang's uniquified `ram$top.x.a` and the escaped `ram/one$top.z` give the same $mem_v2 cells, and no module is left partially selected. Tested with slang only: yosys's own Verilog frontend is deprecated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
|
Thanks, confirmed: Tested with slang only, as yosys's own Verilog frontend is deprecated: slang's uniquified names ( |
AUTO_MEMORIES' extraction step runs
memory -nomapover the whole design to find memories before synthesis. On a large design almost none of that time goes to the memories.Each pass in
memory -nomapwalks every module.memory_dffbuilds its per-bit index for a module before it asks whether the module has a memory at all (YosysHQ/yosys#6282), andopt_mem_priorityandopt_mem_feedbackscan every module the same way. In a design whose memories sit in small generated modules, a firtool core for instance, indexing the memory-less modules is nearly the whole cost.This PR runs the memory passes only on the modules that hold memory cells.
memory_bmux2romstill runs first over the whole design, because it is what turns constant muxes into memories. The JSON now holds only those modules; the detector reads nothing else.The public ORFS designs are small, so the step costs seconds there. Private designs built with ORFS are much larger, and that is where it costs minutes.
Measured
XiangShan's flat XSCore (1870 modules, 407 with memory cells, read through slang, yosys 0.68), memory passes alone:
memory_dff462,opt_mem_priority67,opt_mem_feedback52, twoopt_clean99,share37memory_dff24,opt_mem_priority27Both runs find the same 407
$mem_v2cells. The whole extraction step went from about fifteen minutes to under four; the remaining four minutes are reading andproc.On a small AUTO_MEMORIES test design (one convertible memory, one inline array that must stay flip-flops),
memories.jsonis byte-identical with and without this change, and the extraction JSON shrinks from 1.99 MB to 9.5 KB.Selecting the modules
t:$mem* %mselects every module that holds a memory cell, whole, without going through its name. An escaped module or memory name may hold a/, a$or a glob character, and none of those survives being cut out of aselect -listline and handed back toselect. Tested with slang only, as yosys's own Verilog frontend is deprecated.tclfmtandtclintare clean.🤖 Generated with Claude Code