Skip to content

Test merge from upstream#103

Closed
akashlevy wants to merge 7 commits intoSilimate:mainfrom
YosysHQ:main
Closed

Test merge from upstream#103
akashlevy wants to merge 7 commits intoSilimate:mainfrom
YosysHQ:main

Conversation

@akashlevy
Copy link

@akashlevy akashlevy commented Feb 4, 2026

If your work is part of a larger effort, please discuss your general plans on Discourse first to align your vision with maintainers.

What are the reasons/motivation for this change?

Explain how this is achieved.

Make sure your change comes with tests. If not possible, share how a reviewer might evaluate it.

These template prompts can be deleted when you're done responding to them.


Important

Add sort command to synthesis scripts and remove redundant sort calls from optimization passes, with updates to signal comparison logic in opt_clean.cc.

  • Behavior:
    • Add sort command to prep.ys, prep.cc, synth_gowin.cc, and synth_xilinx.cc to ensure sorting is done at specific stages.
    • Remove redundant sort calls from opt.cc and opt_clean.cc to streamline optimization passes.
  • Functions:
    • In opt_clean.cc, modify compare_signals() to ensure correct signal comparison by adding a condition to compare offsets when wires are the same.
    • In opt_clean.cc, change rmunused_module_signals() to use the updated compare_signals() logic.
  • Misc:
    • Minor code reordering and cleanup in opt_clean.cc to improve readability and maintainability.

This description was created by Ellipsis for 8bbde80. You can customize this summary. It will automatically update as commits are pushed.

rocallahan and others added 7 commits January 23, 2026 01:14
It's pretty common for `opt_clean` to find no wires to remove. In that case,
there is no point scanning the entire design, which can be significantly
expensive for huge designs.
Currently when `s1` and `s2` are different bits of the same wire,
it is possible for both `compare_signals(s1, s2)` and `compare_signals(s2, s1)` to
return false. This means the calling code will call `assign_map.add()` for
both `s1` and `s2`, which doesn't make much sense --- one of `s1` or `s2`
should be consistently preferred.

So fix that by preferring the `SigBit` with the smaller bit offset.
The negation here is confusing. The intent of the code is "if `s1` is preferred
over `s2` as the canonical `SigBit` for this signal, make `s1` the canonical `SigBit`
in `assign_map`", so write the code that way instead of "if `s2` is not preferred
over `s1` ...".

This doesn't change any behavior now that `compare_signals()` is a total order,
i.e. `s1` is preferred over `s2`, `s2` is preferred over `s1`, or `s1` and `s2` are equal.
Now, when `s1` and `s2` are equal, we don't call `assign_map.add(s1)`, but that's
already a noop in that case.
Remove `Design::sort()` calls from optimization passes
Avoid scanning entire module in `Module::remove()` if there are no wires to remove
Clean up `compare_signals()` in `opt_clean`
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 8bbde80 in 14 seconds. Click for details.
  • Reviewed 113 lines of code in 7 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.

Workflow ID: wflow_Fq3eL7e8TRrFjQuG

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@greptile-apps
Copy link

greptile-apps bot commented Feb 4, 2026

Greptile Overview

Greptile Summary

This PR is a merge from upstream that shifts sorting to be explicit in scripts/passes and tweaks a few internals.

Key changes:

  • Removes implicit Design::sort() calls from the opt and opt_clean/clean passes, and instead adds explicit sort steps in scripts (prep, synth_gowin, synth_xilinx) and the documentation macro example.
  • Adds an early return in RTLIL::Module::remove(const pool<Wire*>&) when the pool is empty.
  • Adjusts representative-selection logic in passes/opt/opt_clean.cc (compare_signals + call-site inversion) to refine canonicalization within connected signal groups.

No must-fix issues were found in the diff: the new compare_signals tie-breaker for bits on the same wire is consistent with the “pick s2 over s1” contract, and the sort relocation keeps determinism while avoiding doing it implicitly in opt/opt_clean.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • Changes are small, localized, and primarily move sorting from implicit pass behavior to explicit script steps; the only functional logic tweak (signal representative selection) remains a deterministic comparison and aligns with existing intent.
  • passes/opt/opt_clean.cc

Important Files Changed

Filename Overview
docs/source/code_examples/macro_commands/prep.ys Adds an explicit sort command to the prep macro example after opt -fast for deterministic ordering.
kernel/rtlil.cc Adds an early return in RTLIL::Module::remove(pool<Wire*>) when the input pool is empty to avoid unnecessary work.
passes/opt/opt.cc Removes design->sort() from the end of the opt pass, relying on callers/scripts to sort explicitly if needed.
passes/opt/opt_clean.cc Adjusts representative-selection logic in rmunused_module_signals and changes compare_signals ordering for bits on the same wire; may change canonicalization behavior and can lead to non-deterministic or unintended representative choice without a strict weak ordering.
techlibs/common/prep.cc Adds run("sort") at the end of the prep script coarse stage to preserve deterministic ordering after fast opt.
techlibs/gowin/synth_gowin.cc Runs sort before the abc/abc9 mapping in map_luts stage to stabilize ordering for mapping.
techlibs/xilinx/synth_xilinx.cc Adds run("sort") at end of prepare stage to make subsequent mapping passes see stable ordering; removes reliance on opt/clean sorting.

Sequence Diagram

sequenceDiagram
    participant User as User/Script
    participant Pass as ScriptPass/Pass
    participant Design as RTLIL::Design
    participant Module as RTLIL::Module

    User->>Pass: "Invoke prep / synth_*"
    Pass->>Design: "optimize()"
    Note over Pass: "PR removes implicit Design::sort() from opt/opt_clean"

    Pass->>Pass: "run('sort') at key stages"
    Pass->>Design: "sort() (explicit)"

    Pass->>Pass: "run('opt_clean')"
    Pass->>Module: "rmunused_module_signals()"
    Module->>Module: "compare_signals() picks representative"
    Module->>Module: "remove(wires)"
    Note over Module: "remove() returns early on empty pools"

    Pass->>Design: "check()"
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@akashlevy akashlevy closed this Feb 4, 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.

3 participants