3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-03-02 03:36:56 +00:00
Commit graph

169 commits

Author SHA1 Message Date
Emil J. Tywoniak
ef536c4b1d opt_clean: refactor 2026-02-24 10:39:26 +01:00
Emil J. Tywoniak
17d667eab0 opt_clean: refactor 2026-02-24 10:39:26 +01:00
Emil J. Tywoniak
8dc9c48d4a opt_clean: refactor 2026-02-24 10:39:17 +01:00
Emil J. Tywoniak
97166d5aad opt_clean: refactor 2026-02-24 10:39:13 +01:00
Emil J. Tywoniak
187e91ad65 opt_clean: refactor 2026-02-24 10:39:13 +01:00
Emil J. Tywoniak
17688f053b opt_clean: refactor 2026-02-24 10:39:13 +01:00
Emil J. Tywoniak
090a0fd575 opt_clean: refactor 2026-02-24 10:39:13 +01:00
Emil J. Tywoniak
7d7978a929 opt_clean: more comments 2026-02-24 10:38:59 +01:00
Emil J. Tywoniak
9710be2f84 opt_clean: more comments 2026-02-24 10:38:59 +01:00
Emil J. Tywoniak
a5f554f00a opt_clean: add extra comments 2026-02-24 10:38:59 +01:00
Robert O'Callahan
f2340639e8 Pass the module Subpool to rmunused_module_signals and parallelize that function 2026-02-17 03:24:52 +00:00
Robert O'Callahan
cbb5d8fa12 Pass the module Subpool to rmunused_module_cells and parallelize that function 2026-02-17 03:24:52 +00:00
Robert O'Callahan
e213437095 Pass the module Subpool to rmunused_module_init and parallelize that function 2026-02-17 03:24:51 +00:00
Robert O'Callahan
2659f32616 Pass the toplevel thread pool to rmunused_module, create a Subpool, and parallelize remove_temporary_cells 2026-02-17 03:24:51 +00:00
Robert O'Callahan
0a64402dde Create a toplevel ParallelDispatchThreadPool and parallelize keep_cache_t::scan_module() with it 2026-02-17 03:24:51 +00:00
Robert O'Callahan
20189460bd Introduce RmStats struct to encapsulate removal statistics
Turns out this is not strictly necessary for this PR but it's
still a good thing to do and makes it clearer that the stats
are not modified in a possibly racy way.
2026-02-17 03:24:51 +00:00
Robert O'Callahan
b153fc2d16 Make keep_cache_t process all modules up-front instead of on-demand
We will want to query `keep_cache` from parallel threads. If we compute
the results on-demand, that means we need synchronization for cache
access in those queries, which adds complexity and overhead. Instead, prefill
the cache with the status of all relevant modules. Note that this doesn't
actually do more work --- we always consult `keep_cache` for all cells of
all selected modules, so scanning all those cells and determining the kept
status of all dependency modules is always required.

Later in this PR we're going to parallelize `scan_module` itself, and that's also
much easier to do when no other parallel threads are running.
2026-02-17 03:24:51 +00:00
Emil J
8bbde80e02
Merge pull request #5631 from rocallahan/cleanup-compare-signals
Clean up `compare_signals()` in `opt_clean`
2026-02-04 17:45:05 +01:00
Emil J
992e64342c
Merge pull request #5621 from rocallahan/remove-opt-sort
Remove `Design::sort()` calls from optimization passes
2026-02-04 16:55:56 +01:00
Robert O'Callahan
32e96605d4 Don't update used_signals for retained wires in rmunused_module_signals.
These updates should not be necessary. In fact, if they were necessary, this code
would be buggy, because the results would depend on the order in which wires are traversed:
If wire A is retained, which causes an update to `used_signals`, which then causes wire B
to be retained when it otherwise wouldn't be, then we would get different results depending
on whether A is visited before B.

These updates will also make it difficult to process these wires in parallel.
2026-01-24 03:41:18 +00:00
Robert O'Callahan
7d53d64a47 Make the call to compare_signals() easier to read.
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.
2026-01-24 02:01:05 +00:00
Robert O'Callahan
2468b391bf Make compare_signals produce a total order.
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.
2026-01-24 02:00:33 +00:00
Robert O'Callahan
e87bb65956 Move Design::sort() calls out of opt and opt_clean passes into the synth passes that need them. 2026-01-23 01:14:35 +00:00
Robert O'Callahan
325b27f43a Avoid calling IdString::c_str() in opt_clean 2025-11-12 11:52:04 +01:00
Robert O'Callahan
54bde15329 Implement IdString garbage collection instead of refcounting. 2025-11-12 11:52:04 +01:00
Jannis Harder
cbc1055517 opt_clean: Fix debug output when cleaning up bufnorm cells 2025-09-29 08:21:28 +02:00
Robert O'Callahan
1e5f920dbd Remove .c_str() from parameters to log_debug() 2025-09-23 19:10:33 +12:00
Jannis Harder
5f79a6e868 Clean up $buf with 'z inputs, $input_port and $connect cells
This ensures that entering and leaving bufnorm followed by `opt_clean`
is equivalent to just running `opt_clean`.

Also make sure that 'z-$buf cells get techmapped in a compatible way.
2025-09-17 13:56:46 +02:00
Emil J
73e47ac3fe
Merge pull request #5357 from rocallahan/builtin-ff
Instead of using `builtin_ff_cell_types()` directly, go through a method `Cell::is_builtin_ff()`
2025-09-17 11:37:16 +02:00
Robert O'Callahan
d24488d3a5 Instead of using builtin_ff_cell_types() directly, go through a method Cell::is_builtin_ff() 2025-09-17 03:24:19 +00:00
Robert O'Callahan
a7c46f7b4a Remove .c_str() calls from parameters to log_warning()/log_warning_noprefix() 2025-09-16 23:02:16 +00:00
Robert O'Callahan
5600eb2e5b Update passes/opt to avoid bits() 2025-09-16 03:17:23 +00:00
Robert O'Callahan
e0ae7b7af4 Remove .c_str() calls from log()/log_error()
There are some leftovers, but this is an easy regex-based approach that removes most of them.
2025-09-11 20:59:37 +00:00
Krystine Sherwin
cd3b914132
Reinstate #4768
Revert the reversion so that we can fix the bugs that the PR missed.
2025-04-08 11:58:05 +12:00
Miodrag Milanović
d49364d96f
Revert "Refactor full_selection" 2025-04-07 12:11:55 +02:00
Krystine Sherwin
a3968d43f0
Drop deprecation on Design::selected_modules()
Instead, change the default `Design::selected_modules()` to match the behaviour (i.e. `selected_unboxed_modules_warn()`) because it's a lot of files to touch and they don't really _need_ to be updated.
Also change `Design::selected_whole_modules()` users over to `Design::selected_unboxed_whole_modules()`, except `attrmap` because I'm not convinced it should be ignoring boxes.  So instead, leave the deprecation warning for that one use and come back to the pass another time.
2025-03-14 14:08:56 +13:00
Martin Povišer
557047fe1e opt_clean, simplemap: Add $buf handling 2025-03-07 16:08:38 +01:00
Emil J. Tywoniak
785bd44da7 rtlil: represent Const strings as std::string 2024-10-14 06:28:12 +02:00
Martin Povišer
4a8cdfabbb
Merge pull request #4169 from povik/clean-opt_clean-step2
opt_clean: Remove dead assertion
2024-04-13 18:12:40 +02:00
Jannis Harder
8902fc94b6 Suport $scopeinfo in flatten and opt_clean 2024-02-06 17:51:29 +01:00
N. Engelhardt
f96e27ac14
Merge pull request #4123 from povik/clean-opt_clean
opt_clean: Add commentary, remove dead code
2024-02-05 15:08:34 +01:00
Catherine
c7bf0e3b8f Add new $check cell to represent assertions with a message. 2024-02-01 20:10:39 +01:00
Martin Povišer
23c9828d70 opt_clean: Remove dead branch 2024-01-29 11:26:44 +01:00
Martin Povišer
7afc0696e2 opt_clean: Assert an impossible path isn't taken 2024-01-29 11:26:44 +01:00
Martin Povišer
ec065186d3 opt_clean: Add commentary around wire cleaning, NFC 2024-01-29 11:26:44 +01:00
Jannis Harder
62b4df4989 dft_tag: Implement $overwrite_tag and $original_tag
This does not correctly handle an `$overwrite_tag` on a module output,
but since we currently require the user to flatten the design for
cross-module dft, this cannot be observed from within the design, only
by manually inspecting the signals in the design.
2023-09-13 11:32:36 +02:00
whitequark
d51ecde8c2 clean: keep $print cells, since they have unmodelled side effects. 2023-08-11 04:46:52 +02:00
Jannis Harder
e36c71b5b7 Use clk2fflogic attr on cells to track original FF names in witnesses
This makes clk2fflogic add an attr to $ff cells that carry the state of
the emulated async FF. The $ff output doesn't have any async updates
that happened in the current cycle, but the $ff input does, so the $ff
input corresponds to the async FF's output in the original design.

Hence this patch also makes the following changes to passes besides
clk2fflogic (but only for FFs with the clk2fflogic attr set):

  * opt_clean treats the input as a register name (instead of the
    output)

  * rename -witness ensures that the input has a public name

  * the formal backends (smt2, btor, aiger) will use the input's
    name for the initial state of the FF in witness files

  * when sim reads a yw witness that assigns an initial value to the
    input signal, the state update is redirected to the output

This ensures that yosys witness files for clk2fflogic designs have
useful and stable public signal names. It also makes it possible to
simulate a clk2fflogic witness on the original design (with some
limitations when the original design is already using $ff cells).

It might seem like setting the output of a clk2fflogic FF to update the
input's initial value might not work in general, but it works fine for
these reasons:

  * Witnesses for FFs are only present in the initial cycle, so we do
    not care about any later cycles.

  * The logic that clk2fflogic generates loops the output of the
    genreated FF back to the input, with muxes in between to apply any
    edge or level sensitive updates. So when there are no active updates
    in the current gclk cycle, there is a combinational path from the
    output back to the input.

  * The logic clk2fflogic generates makes sure that an edge sensitive
    update cannot be active in the first cycle (i.e. the past initial
    value is assumed to be whatever it needs to be to avoid an edge).

  * When a level sensitive update is active in the first gclk cycle, it
    is actively driving the output for the whole gclk cycle, so ignoring
    any witness initialization is the correct behavior.
2023-05-25 12:48:02 +02:00
Jannis Harder
c0063288d6 Add the $anyinit cell and the formalff pass
These can be used to protect undefined flip-flop initialization values
from optimizations that are not sound for formal verification and can
help mapping all solver-provided values in witness traces for flows that
use different backends simultaneously.
2022-08-16 13:37:30 +02:00
Marcelina Kościelnicka
62d41d4639 opt_clean: Make the init attribute follow the FF's Q.
Previously, opt_clean would reconnect all ports (including FF Q ports)
to a "canonical" SigBit chosen by complex rules, but would leave the
init attribute on the old wire.  This change applies the same
canonicalization rules to the init attributes, ensuring that init moves
to wherever the Q port moved.

Part of another jab at #2920.
2021-08-22 15:38:29 +02:00