Commit Graph

6482 Commits

Author SHA1 Message Date
Geza Lore bcaa110f60
Optimize generated function inlining (#7811)
Previously V3InlineCFuncs inlined call sites but never deleted the now
dead callees. Also missed a lot of opportunities due to evaluation order.

Rewrite using a graph based algorithm, using only a single traversal of
the netlist. This is clearer, more accurate, and faster at compile time.

Also add a clean -fno-inline-cfuncs disable. Setting the limits to 0
still disables inlining, except of empty functions, which can be inlined
with 0 limits (they are no ops). It will also prune unused functions
without -fno-inline-cfuncs.

Pass now also respects `--output-split`
2026-06-21 18:31:56 +01:00
Geza Lore e1f1a50327 Fix assertion when loop unrolling failed (#7810)
Partial fix for #7810
2026-06-21 10:28:23 +01:00
Igor Zaworski e269b914b2
Support NBAs in initial blocks (#7754) 2026-06-20 17:23:05 -04:00
Geza Lore 9a231d254d
Optimize Dfg cycle breaking to do less work (#7210)
When a vertex is made acyclic, conservatively update the SCC map to
propagate and mark connected vertices as acyclic as much as possible.
This way we can stop early if the graph becomes acyclic after some
fixups. This can significantly reduce the number of fixups needing to be
applied, avoiding introducing redundancy.
2026-06-19 22:28:50 +01:00
Geza Lore a37e2ee94b
Optimize wide decoder case statements into decoder expressions (#7804)
Extend the decoder-pattern case optimization to selectors that are too
wide for a full 2^width lookup table. A decoder-pattern case (where
every case item assigns constants to a fixed set of LHSs) is lowered to
a new AstMachMasked expression. AstMachMasked is emitted as a run-time
VL_MATCHMASKEd_* function call. It contains a packed constant pool table,
'matchp', which is a list of '(mask, bits)' pairs. At runtime, the index of the 
first matching entry is returned, and is used to index a value table. This single
(albeit complicated) expression can replace large if-else trees whole, resulting
in much more compact code with fewer static hard to predict branches. It
is worth about 10% speed and 30% code size in some designs.

Example:

```systemverilog
    logic [39:0] sel;
    always_comb
      casez (sel)
        40'b???????????????????????????????????????1: out = 8'h01;
        40'b??????????????????????????????????????1?: out = 8'h02;
        40'b?????????????????????????????????????1??: out = 8'h03;
        default:                                      out = 8'hff;
      endcase
```

is compiled to:

```c++
    out = TABLE_value[VL_MATCHMASKED_Q(sel, CONST_match)];
```

Where 'CONST_match' contains 4 entries, of a 40-bit mask and 40-bit bit
pattern each, and 'TABLE_value' contains 4 entries of the corresponding
8-bit results. (Entries are aligned to word boundaries to avoid runtime
bit swizzling)
2026-06-19 19:46:13 +01:00
Yilou Wang 59fba72cb6
Support method calls on a sub-interface via a virtual interface (#7800) 2026-06-19 08:41:48 -04:00
Yilou Wang 129cfc19c0
Fix cross-hierarchy tristate drivers of interface nets (#7339) (#7801)
Closes #7339.
2026-06-18 19:07:37 -04:00
Yilou Wang a5a16cfbfd
Support unbounded always [m:$] and strong s_always liveness (#7798) 2026-06-18 11:17:09 -04:00
Yilou Wang 22b45f0fd7
Fix randomize() with skipping derived pre/post_randomize (#7799) 2026-06-18 11:04:57 -04:00
Geza Lore 5712f9b614
Optimize decoder case statements into lookup tables (#7795)
Recognize "decoder" case statements (where every case item only assigns
constants to a fixed set of left-hand sides) and replace them with a
single packed constant lookup table indexed by the case expression.
Small tables are materialized inline in the generated code, and are
always optimized. Larger ones are placed in the constant pool and only
optimized if deemed beneficial over branches.

While this slightly conflicts with V3Table, and is not worth that much
on it's own, there will be a follow up patch that converts more cases of
this form which will be much more valuable. This patch does the
necessary analysis and the simple table conversion when possible.

Split -fcase into -fcase-table (this new conversion) and -fcase-tree (the
existing bitwise branch-tree conversion); -fno-case is now an alias for
both.

Default branches, assignments preceding the case (used as default values),
casez wildcards, multiple and partial left-hand sides, and both blocking and
non-blocking assignments are handled. Cases that cannot be safely tabled (e.g.
non-exhaustive with no default, overlapping writes to one variable, or mixed
blocking/non-blocking assignments) fall back to the existing if/else lowering.

Consequently disabled re-inlining of constant pool variables in V3Const,
and rebuild the constant pool hash in V3Dead (previously we didn't
create constant pool entries early enough for this to matter)
2026-06-18 09:30:50 +01:00
Yilou Wang 3a4377d39e
Support clocking event on a sequence declaration body (#7598) (#7793)
Fixes #7598.
2026-06-17 17:57:18 -04:00
Nick Brereton 26c85d4495
Fix `$bits` on unpacked structs (#4521) (#7796)
Fixes #4521.
2026-06-17 17:56:48 -04:00
Tracy Narine 4c5e104825
Internals: Remove bad cmake file reference (#7794) 2026-06-17 12:12:25 -04:00
Geza Lore f11c4084d1 Internals: Minor cleanup of case statement lowering
- Factor out match mask construction
- Rename V3Number method to reflect behaviour
2026-06-17 14:39:06 +01:00
Yilou Wang b581f73843
Support $assertcontrol control_type from lock to kill (#7788) 2026-06-17 07:17:39 -04:00
em2machine a534a1d1bc
Fix parameter pollution when using class parameters (#7711) (#7763)
Fixes #7711.
2026-06-16 14:03:28 -04:00
Ryszard Rozak 792008514b
Fix randomization of dynamic arrs of objects (#7790) 2026-06-16 12:19:00 -04:00
Yilou Wang bec45125bd
Fix `cover property` of an implication counting vacuous matches (#7789) 2026-06-16 11:52:35 -04:00
Jakub Michalski 38fd99b37b
Fix out-of-bounds read value for 2-state types (#7785)
Signed-off-by: Jakub Michalski <jmichalski@antmicro.com>
2026-06-16 09:21:11 +01:00
Nikolai Kumar a5fad9882f
Fix force unpacked bitselect (#7744) (#7745)
Fixes #7744.
2026-06-15 21:57:59 -04:00
Wilson Snyder 0e4a3a92b0 CI: Autoformat markdown files 2026-06-15 17:44:50 -04:00
Artur Bieniek 7061c1f04d
Fix not failing assertion when RHS of a range window rejects once (#7773) 2026-06-15 15:32:11 -04:00
Yilou Wang 709c444df3
Internals: Add AGENTS files to guide AI contributions (#7562) (#7765)
Fixes #7562.
2026-06-15 08:42:34 -04:00
Yilou Wang 077558a9b0
Support cover sequence statement (#7764) 2026-06-15 08:36:21 -04:00
Yilou Wang 969a775ae5
Support assertion control system tasks in classes and interfaces (#7761) 2026-06-15 07:33:55 -04:00
Geza Lore a07a980b73 Internals: Do not overload AstVar::isPrimaryIO() for sampled value vars 2026-06-15 09:17:41 +01:00
Geza Lore 5ab2bf1ec4
Optimize input combinational logic by change detection (#7784)
When a lot of combinational logic is driven from top level inputs,
work can be wasted evaluating that logic if the top level inputs don't
change.

This change adds an optimization by performing a change detect on the
top level inputs, and evaluate 'ico' logic only if the top level input
actually changed. This especially helps with --hierarchical/--lib-create
which runs the 'ico' of each sub-model in the eval settle loop.

This was observed to yield 40%+ run-time speedup on some partitioned
designs.

The added change detection is cheap, so it is emitted even if the 'ico'
region is small, and is on by default.

The optimization is only sound if the model itself does not write to the
top level inputs (otherwise the 'previous value' variables would be out
of sync, which are not updated by internal writes.). If we can detect a
top level input is written within the design, then for that input, we
fall back on always running the relevant logic. With --vpi we cannot
prove safety statically, so --vpi will disable this optimisation unless
explicitly enabled. (In which case it's the user's responsibility to not
write to top level inputs via the VPI.)
2026-06-15 05:42:00 +01:00
Wilson Snyder df78db0e73 Fix $fflush and autoflush with --threads (#7782).
Fixes #7782.
2026-06-14 13:36:49 -04:00
Wilson Snyder 12bcf85d33 Internals: Misc V3Life cleanups. No functional change intended. 2026-06-14 13:36:49 -04:00
Geza Lore 77e6a21224 Internals: Inline AstVar::isToggleCoverable()
Inline into the single call site, remove unnecessary isSc() and
isPrimaryIO() guards (these flags are set only in a later pass).

No functional change.
2026-06-14 16:41:13 +01:00
Geza Lore 9a0cd289e8 Fix memory leak in previous patch 2026-06-14 14:53:40 +01:00
Geza Lore b973b1df5a Fix hang in assertion optimization (#7707 repair) 2026-06-14 13:31:59 +01:00
Geza Lore df1b1577d9
Deprecate isolate_assignments attribute (#7774)
As per discussion. Remove the unsound V3SplitAs pass. The
isolate_assignments attribute/directive is now parsed and ignored in the
frontend for compatibility but otherwise have no effect.

Fixes #7144
2026-06-13 19:40:29 +01:00
Geza Lore 7af22422c7
Optimize table lookups in Dfg (#7772) 2026-06-13 08:45:46 +01:00
Geza Lore ba624d7ce1
Optimize away proven redundant case statement assertions (#7771)
This is still mostly refactoring of V3Case, but with functional changes.
Decouple the exhaustiveness/overlap analysis from the decision to
convert the case using the fast bitwise testing method. This enables
dropping the 'notParallel' assertions for those we can prove exhaustive
and unique, even if we decide to convert them using the generic if/else
ladder scheme.
2026-06-13 08:45:26 +01:00
Nick Brereton 87d2610674
Support unpacked struct stream (#7767) 2026-06-12 17:32:01 -04:00
Matthew Ballance e03fa6c783
Support covergroup runtime model Phase A1 (#7728) 2026-06-12 11:40:48 -04:00
Marco Bartoli 5831cc8d46
Fix timed nested fork block with disable (#6720) (#7743)
Fixes #6720.
2026-06-12 10:42:32 -04:00
Nick Brereton 748e48f881
Fix s_eventually in parameterized interfaces (#7741) 2026-06-12 10:41:56 -04:00
Artur Bieniek dab6889f1e
Support assert property 'default disable iff` (#4848) (#7723) 2026-06-12 10:40:38 -04:00
Geza Lore e0c4c995b9 Fix crash on overlapping priority case 2026-06-12 14:37:05 +01:00
Geza Lore 279b425a57
Internals: Cleanup V3Case (#7769) 2026-06-12 14:15:41 +01:00
Ryszard Rozak e6ee6dd106
Fix bounds checks in expressions with read/write references (#7694) 2026-06-12 06:55:06 -04:00
Geza Lore 60f729639b
Fix 'case (_) inside' with x wildcards (#7766)
Found by inspection, case inside used to threat 'x' as a value, not as a
wildcard. Per the standard it should behave as '==?' which treats both
'x' and 'z' as wildcards.
2026-06-12 07:48:36 +01:00
Geza Lore 4555c8b23c
Internals: Cleanup case condition lifting (#7768)
V3Begin used to lift impure case expressions. With V3LiftExpr, this is
now redundant.
2026-06-12 06:38:21 +01:00
Geza Lore 0ee25038ac
Optimize V3Gate inlining heuristic (#7716)
V3Gate used to inline too many expensive operations. One particularly
bad example is inlining `{<<{wide}}` (bit-reverse of a wide signal),
which is a single input node, but is quite expensive to compute, which
we always used to inline.

Change the heuristic to only inline single input nodes if they are not
wide, or a cheap wide operation, otherwise treat them the same as
multi-input ops and inline them only if they are used no more than once.
2026-06-11 20:59:18 +01:00
Geza Lore c7a262b05d
Optimize bit select removal earlier in Dfg (#7762)
Add a simple Dfg pass that removes redundant bit selects early. This
can significantly cut down on downstream work and remove some temporary
variables introduced during synthesis.
2026-06-11 16:00:30 +01:00
Kornel Uriasz 4c92c035e7
Support reduction XOR/AND operations in constraints (#7753) 2026-06-11 09:43:18 -04:00
Yilou Wang c6caa94fe0
Fix no-scope internal error on virtual interface method calls (#7759) 2026-06-11 09:04:06 -04:00
Adam Kostrzewski 394c9bc9b2
Fix FSM detect unchecked casts and variable redeclaration (#7758) 2026-06-11 08:37:23 -04:00