Skip to content

synth: extend SYNTH_KEEP_MODULES selection pattern for slang elaboration - #4381

Closed
oharboe wants to merge 2 commits into
The-OpenROAD-Project:masterfrom
oharboe:fix-synth-slang-module-selection
Closed

oharboe wants to merge 2 commits into
The-OpenROAD-Project:masterfrom
oharboe:fix-synth-slang-module-selection

Conversation

@oharboe

@oharboe oharboe commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Extend module selection pattern in flow/scripts/synth.tcl to include $module* alongside $module\$* so kept module preservation (SYNTH_KEEP_MODULES) functions reliably for slang-elaborated modules.

@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 updates the synthesis script flow/scripts/synth.tcl to include a new wildcard pattern "$module*" to match slang-elaborated parameterized instances. Feedback on this change highlights that the wildcard pattern is too broad and acts as a prefix match, which could inadvertently match and keep unrelated modules (e.g., matching "cpu_alu" when "cpu" is specified) and prevent optimization. It is recommended to use a more restrictive pattern to avoid over-matching.

Comment thread flow/scripts/synth.tcl Outdated
# `-module <name>` would error if the module doesn't exist, which
# is why we use bare patterns instead.
select "$module" "$module\\\$*"
select "$module" "$module\\\$*" "$module*"

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.

medium

Using the wildcard pattern "$module*" acts as a prefix match and will match any module whose name starts with the module name. For example, if SYNTH_KEEP_MODULES contains "cpu", this pattern will also match and keep unrelated modules like "cpu_alu" or "cpu_ctrl". This prevents those unrelated modules from being flattened and optimized, which can negatively impact area and timing. If slang-elaborated parameterized modules are named with a specific separator (like an underscore or dollar sign), it is highly recommended to use a more restrictive pattern (such as "${module}_*" or the existing dollar-suffixed pattern) to avoid over-matching.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@povik I'm skeptical of Gemini when it comes to this .tcl Yosys select code.

The symptom here is that the netlist fails in verilator .saif emulation because pins are lost with -hier.

@oharboe oharboe closed this Jul 26, 2026
@oharboe
oharboe requested a review from povik July 26, 2026 19:17
@oharboe oharboe reopened this Jul 26, 2026
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe
oharboe force-pushed the fix-synth-slang-module-selection branch from c068f48 to 4ba7421 Compare July 26, 2026 19:23
@maliberty

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4ba7421085

ℹ️ 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".

Comment thread flow/scripts/synth.tcl Outdated
# `-module <name>` would error if the module doesn't exist, which
# is why we use bare patterns instead.
select "$module" "$module\\\$*"
select "$module" "$module\\\$*" "$module*"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid prefix-matching unrelated modules

When a requested keep name is also a prefix of another module, the new "$module*" pattern selects both and applies keep_hierarchy to the unrelated module. For example, the existing asap7/swerv_wrapper configuration lists exu, exu_alu_ctl, and exu_div_ctl, while its RTL also defines an unlisted exu_mul_ctl; processing exu now preserves exu_mul_ctl as well. This can unexpectedly prevent flattening and change hierarchy and synthesis QoR, so the fallback should distinguish Slang elaboration suffixes rather than accepting every suffix.

Useful? React with 👍 / 👎.

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.

Same concern as Gemini. I asked Claude about it:

Since $* already covers every suffix slang can produce, $module* adds no
slang coverage — it only adds prefix collisions. Whatever is causing the lost
pins under -hier in the verilator SAIF run is a different root cause, and this
pattern change is masking it rather than fixing it.

Sounds like it needs more investigation upstream.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes... I was hoping for insights here from @povik

The wildcard '*' matches any module starting with the base
module's name as a prefix (e.g. 'cpu_alu' when keeping 'cpu').
The pattern '$module\$*' already reliably matches the canonical
parameterized instance names generated by the slang frontend
(e.g., \foo$1), so the broader wildcard is unnecessary and
prevents optimization of unrelated modules sharing the prefix.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@maliberty

Copy link
Copy Markdown
Member

This PR is now a no-op

@oharboe

oharboe commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

I have dropped the overly broad $module* wildcard from the selection pattern. The $module$* pattern already correctly matches the $-suffixed canonical names generated by the slang frontend. This resolves the over-matching issue.

@oharboe oharboe closed this Aug 3, 2026
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