Skip to content

synth: match slang \$-suffixed module names in SYNTH_KEEP_MODULES#4175

Merged
maliberty merged 4 commits intoThe-OpenROAD-Project:masterfrom
oharboe:orfs-synth-keep-slang-select
Apr 26, 2026
Merged

synth: match slang \$-suffixed module names in SYNTH_KEEP_MODULES#4175
maliberty merged 4 commits intoThe-OpenROAD-Project:masterfrom
oharboe:orfs-synth-keep-slang-select

Conversation

@oharboe
Copy link
Copy Markdown
Collaborator

@oharboe oharboe commented Apr 22, 2026

The slang HDL frontend produces \$-suffixed canonical RTLIL names for parameterized module instantiations, so select -module <name> misses them and keep_hierarchy silently doesn't get applied.

Replace with a two-pattern select that matches both the bare name and <name>\$*. The second pattern matches nothing when no \$-suffix names exist, so the builtin and verific frontends are unchanged.

Copy link
Copy Markdown

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

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 updates the synthesis script to ensure parameterized modules are preserved during hierarchy optimization by expanding the selection pattern to include $-suffixed canonical names. A technical issue was identified where the new selection pattern might fail to match RTLIL canonical names because Yosys does not automatically prepend backslashes when wildcards are present; a more robust selection command using the -module flag and a leading wildcard was suggested.

Comment thread flow/scripts/synth.tcl
The slang HDL frontend produces `\$`-suffixed canonical RTLIL names
for parameterized module instantiations, so `select -module <name>`
misses them and `keep_hierarchy` silently doesn't get applied.

Replace with a two-pattern `select` that matches both the bare name
and `<name>\$*`. The second pattern matches nothing when no `\$`-suffix
names exist, so the builtin and verific frontends are unchanged.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe oharboe force-pushed the orfs-synth-keep-slang-select branch from 8718306 to 3355586 Compare April 22, 2026 10:26
@maliberty
Copy link
Copy Markdown
Member

@codex review

@maliberty
Copy link
Copy Markdown
Member

/gemini review

Copy link
Copy Markdown

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

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 updates the module selection logic in synth.tcl to support parameterized instances generated by the slang frontend. However, the current implementation of the select command incorrectly handles multiple patterns on the Yosys stack, which can lead to the base module being ignored or an empty selection. It is recommended to use the union operator %u and retain the -module flag to ensure correct behavior across different frontends.

Comment thread flow/scripts/synth.tcl
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

oharboe added 2 commits April 24, 2026 07:01
Gemini flagged that `select A B` might not union the two patterns,
which would regress the non-slang case where only the bare name
exists. It does union them -- yosys/passes/cmds/select.cc:1494 runs
`while (work_stack.size() > 1) select_op_union(...)` at the end of
select -- but make the intent obvious by explicitly stacking `%u`, and
expand the comment so future readers don't have to trace select.cc to
convince themselves the non-slang case still works.

No behavior change; verified with yosys 0.63 against a design carrying
both a renamed `\bar$2` (slang-style canonical) and a plain `\top`:
both receive `keep_hierarchy` under the two-pattern select whether or
not `%u` is present.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
The previous commit added a cosmetic `%u` to quiet a review concern
about `select A B` not unioning its patterns. It does union them, and
the `%u` is redundant. Drop the `%u` and instead document the two
yosys behaviors that make the construct correct, citing the source
file and function names so future readers don't have to rediscover
them:

  * match_ids retries the pattern against the id with a leading `\`
    stripped, so the wildcard pattern matches canonical names like
    `\foo$1` without needing a `\`-prefix in the Tcl string.
  * The select command auto-unions remaining patterns on the work
    stack when it finishes parsing, so a pattern that matches nothing
    only produces a warning -- the other pattern still applies.

Also note why we don't use `-module <name>`: it errors out when the
module doesn't exist, which is exactly the case this change is trying
to handle.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe
Copy link
Copy Markdown
Collaborator Author

oharboe commented Apr 24, 2026

@maliberty I don't know what to do about the security check:

Running pre-commit security hook....

ERROR: File flow/scripts/synth.tcl contains blocked content on line 48 :
      #  - `$module` matches the bare name produced by verilog/verific.


To request an exception please file an issue on GitHub

@oharboe oharboe requested a review from maliberty April 24, 2026 15:19
@maliberty
Copy link
Copy Markdown
Member

We look for the word verific to catch any accidental inclusion of their proprietary code. I could make an exception for this file but in this case it seems easier to just change verilog/verific to verilog.

@oharboe
Copy link
Copy Markdown
Collaborator Author

oharboe commented Apr 25, 2026

We look for the word verific to catch any accidental inclusion of their proprietary code. I could make an exception for this file but in this case it seems easier to just change verilog/verific to verilog.

Should I do something?

Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
@maliberty maliberty enabled auto-merge April 26, 2026 00:40
@maliberty maliberty merged commit 172bd23 into The-OpenROAD-Project:master Apr 26, 2026
8 checks passed
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.

2 participants