Skip to content

AUTO_MEMORIES cleanup: read the files blackboxes.txt names, no globs or existence checks - #4810

Merged
maliberty merged 1 commit into
The-OpenROAD-Project:masterfrom
oharboe:auto-memories-explicit
Nov 11, 2026
Merged

maliberty merged 1 commit into
The-OpenROAD-Project:masterfrom
oharboe:auto-memories-explicit

Conversation

@oharboe

@oharboe oharboe commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

This is the cleanup of AUTO_MEMORIES file handling. #4389 merged AUTO_MEMORIES as an experimental baseline, to be cleaned up once we knew what it needed. One gap from then: every step after synthesis globbed $(RESULTS_DIR)/memories for views, "because the file names are only known at run time". They were already known, though, because blackboxes.txt, written in that same PR, names every macro do-auto-memories generates, each with its .lib and .lef beside it.

The steps now read what the lists name, through one set of helpers. The flow has fewer code paths and fails loudly where it used to read the wrong thing quietly.

Less code

  • Globs and wildcards: three gone (load.tcl, read_liberty.tcl, the Makefile's klayout LEF list), along with the _pre_layout.lib filter the glob needed.
  • Existence checks: five file exists guards on files the flow guarantees are gone, per the Tcl Contract ("A script never guards a read the flow guarantees").
  • List readers: auto_memories_inline and auto_memories_regfile_cores were near-identical, so they merge into one auto_memories_names <list>. auto_memories_areas moves to util.tcl, so OpenROAD and yosys share one reader.
  • Line count: the flow's Tcl is 26 lines shorter, +76/−102 across six files. The Makefile's $(wildcard ...) becomes a --blackboxes argument to generate_klayout_tech.py (Makefile +2/−2, Python +25/−1), so the logic is in Python rather than untested Make.
  • Tests: 29 new lines of unit tests in flow/test/test_generate_klayout_tech.py, for logic that had none.

More robust

Situation Before Now
A view left from an earlier run that no list names read with the current ones not read
A missing list (regfiles.txt, inline.txt, regfile_cores.txt) skipped the step stops at the read, with the tool's own message
A missing view skipped the step stops at the read, with the tool's own message

No new file or variable is needed.

Changes

  • util.tcl: auto_memories_areas (moved from synth_preamble.tcl), auto_memories_names <list>, and auto_memories_views <ext>, which gives the views of the macros blackboxes.txt lists.
  • load.tcl, read_liberty.tcl: read auto_memories_views .lef / .lib instead of globbing.
  • macro_place.tcl, regfile_dissolve.tcl, synth_preamble.tcl: read the lists through auto_memories_names.
  • generate_klayout_tech.py --blackboxes: the klayout tech's LEF list comes from blackboxes.txt, in Python with unit tests, not $(shell ...) in the Makefile (Makefile Contract).
  • docs/user/AutoMemories.md: says a file no list names is not read.

extract_memories.tcl runs before the lists exist and already sets AUTO_MEMORIES=0 for its own process, so it is unaffected.

Testing

  • tclfmt/tclint 0.7.0 and black 26.10.1 are clean. flow/test/test_generate_klayout_tech.py passes, with new tests for the listed LEFs, a stray LEF that is ignored and a missing list.
  • An AUTO_MEMORIES design on the hierarchical synthesis path (bazel-orfs test/auto_memories:am_top, one FakeRAM macro) was built through CTS with and without this change. 4_cts.odb and 4_cts.sdc are byte-identical.
  • In a deployed tree of the same design:
    • A stray, unparseable junk.lib and junk.lef in memories/: floorplan reads only am_ram_2048x32.lib and passes. As a control, with junk added to blackboxes.txt it stops at [ERROR STA-0164] .../memories/junk.lib line 1, syntax error.
    • With am_ram_2048x32.lef removed, do-1_synth stops at [ERROR ORD-0001] .../memories/am_ram_2048x32.lef does not exist.; restored, it passes.
    • With blackboxes.txt removed, do-1_synth stops at couldn't open ".../memories/blackboxes.txt": no such file or directory.

Not covered by a run:

  • The klayout tech: am_top stops at CTS; tinyRocket, tage_update and cva6 take that path in CI.
  • A non-empty regfiles.txt/inline.txt/regfile_cores.txt: every AUTO_MEMORIES design reads them empty, and no CI design lists a register file.

🤖 Generated with Claude Code

Before, every stage after synthesis globbed $(RESULTS_DIR)/memories for
*.lef and *.lib, the klayout tech took $(wildcard memories/*.lef), and
macro placement, regfile dissolve and synthesis read regfiles.txt,
inline.txt and regfile_cores.txt only if they existed. In a tree that
kept files from an earlier run, a .lib or .lef no longer generated was
read with the current ones, and a missing list was skipped.

Now each step reads the <m>.lib/<m>.lef of every module blackboxes.txt
lists, and the lists themselves without an existence check: a file no
list names is not read, and a missing list stops the step at the read.
The readers move from synth_preamble.tcl to util.tcl so OpenROAD and
yosys share them, and generate_klayout_tech.py takes --blackboxes.

On a clean tree the files read, and the results, are the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the AUTO_MEMORIES flow to use explicit file lists (such as blackboxes.txt, inline.txt, regfile_cores.txt, and regfiles.txt) instead of globbing files in the memories directory. It introduces centralized helper functions in flow/scripts/util.tcl (auto_memories_areas, auto_memories_names, and auto_memories_views) to handle these lists consistently across synthesis, placement, and layout generation. Additionally, generate_klayout_tech.py is updated to accept a --blackboxes argument to parse the exact LEF files needed, accompanied by new unit tests. I have no feedback to provide.

@oharboe oharboe changed the title AUTO_MEMORIES: read the views the lists name, not what memories/ holds AUTO_MEMORIES cleanup: read the files blackboxes.txt names, no globs or existence checks Nov 9, 2026
@oharboe
oharboe requested a review from maliberty November 9, 2026 14:56
@openroad-ci

Copy link
Copy Markdown
Member

🔍 QoR check

Metrics reflect the PR merge build — i.e. what will land on the target branch.

Commit 54581a5 · Jenkins build #1 · Baseline: build · View build on dashboard

62 design(s) checked — 0 with regression(s), 0 without a comparable baseline.

@oharboe

oharboe commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@maliberty This blocks another PR for me...

@maliberty maliberty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits (none blocking):

  1. Less helpful error. The old "do-auto-memories must run before synthesis" hint becomes Tcl's plain "couldn't open …" error. The Tcl contract allows this, but the old message was more useful when AUTO_MEMORIES is switched on in an existing run directory.
  2. Two parsers for one file. blackbox_lefs in Python reads blackboxes.txt without the Tcl reader's format check or de-duplication. A malformed or repeated line would quietly give a wrong or duplicated LEF list for klayout.
  3. One helper left behind. auto_memories_blackboxes stays in synth_preamble.tcl while its siblings moved to util.tcl. It's a one-liner and could move with them.
  4. Outdated comment. In read_liberty.tcl, the _pre_layout sentence now describes files the code never touches. It could be trimmed to "named by blackboxes.txt".

@maliberty
maliberty merged commit a47d4fd into The-OpenROAD-Project:master Nov 11, 2026
13 checks passed
@oharboe

oharboe commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the careful read! Follow-up in #4825:

  1. Not taken. Tcl can only tell "missing" from "couldn't check" by catching open's error and reading its error code, which is code no test covers. A file exists guard first would hide the cases where the check itself fails (an unreadable directory, a broken mount), which is exactly when the real error matters. open's own error names the file, and that's enough for whoever, human or agent, debugs it from the source.
  2. Taken, at the root. blackboxes.txt had two writers (FakeRAM, then gen_memories.py appending register files) and a check in one of three readers. Now gen_memories.py resolves the listed register files before FakeRAM runs and writes the file once from the final inventory, so a malformed or repeated line can't be written. All three readers just split the lines: the Python ones take the first field, the Tcl one the <module> <area> pairs as a dict, no checks.
  3. Taken. auto_memories_blackboxes moved to util.tcl with its siblings.
  4. Taken. The read_liberty.tcl comment is now just "named by blackboxes.txt".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants