Commit Graph

3495 Commits

Author SHA1 Message Date
Martin Erhart c56d5659d5 [RTG] Use FlatSymbolRefAttr for SymbolDCE to pick it up as SymbolUse 2025-07-30 12:59:26 +01:00
Martin Erhart a11a834d96
[RTG] Simplify EmitISAEmission pass (#8798) 2025-07-29 21:16:48 +01:00
Martin Erhart 01a53d4552
[RTG] Sequences are always private (#8792) 2025-07-29 17:45:52 +01:00
Martin Erhart 964cc8be4f
[RTG] Don't hardcode the root op of passes where not necessary (#8791) 2025-07-29 17:45:08 +01:00
Martin Erhart 1ef47b3cdb
[RTG] Add InsertTestToFileMappingPass (#8795)
Add a pass to group tests to output files. Currently, this matches what the emission pass does but can be extended to group tests according to certain requirements demanded from the execution environment. Also add a simple pass that inlines the tests without any gluecode (matching what the emission pass currently does). The emission pass will be simplified in a future PR to only iterate over the file operations and print what's inside
2025-07-29 17:09:29 +01:00
Hideto Ueno 7f9e66f5f5
[FIRRTL] Type check in Cat operatnds in FIR parser (#8793)
Fix a parser crashe when cat is constructed with invalid type operands.
2025-07-28 18:26:56 -07:00
Hideto Ueno 108965f1e5
[HW][HWAggregateToComb] Add support for hw.array_inject operation in HWAggregateToComb pass (#8788)
This patch implements lowering of hw.array_inject operations to combinational
logic in the HWAggregateToComb transformation pass.

The implementation creates a 2D array where each row represents the result
of injecting the new value at a specific index. A multiplexer then selects
the appropriate row based on the injection index.
2025-07-28 11:34:15 -07:00
Maria Fernanda Guimarães 2f0ca3c18e
[Comb] Add comb.reverse operation (#8758)
This commit introduces a new operation to the Comb dialect:
`comb.reverse`, which performs bitwise reversal (mirroring) of an 
integer value.

It also adds Verilog export support for this operation using 
SystemVerilog’s streaming operator `{<<{}}`.

Bit reversal is a common operation in hardware design, especially in 
signal processing and communication protocols. Previously, reversing 
bits required generating many explicit `assign` statements. This new 
operation makes the IR cleaner and enables direct export to compact 
Verilog syntax.
2025-07-28 11:28:22 -07:00
Hideto Ueno 896e80ec9a
[AIG] Remove aig.cut (#8784)
Technology mapping/Cut rewriting requires enumerating multiple cuts to find best cuts, so representing a single cut as an operation doesn't make sense in general. When the AIG dialect was originally introduced, the cut operation was not well-thought-out and not used anywhere so clean up before implementing tech mapping.

Close https://github.com/llvm/circt/issues/8761
2025-07-25 21:59:14 -07:00
Bea Healy 82a8af4acf
[Comb] Fix more recursive mux folders (#8756)
Co-authored-by: Fabian Schuiki <fabian@schuiki.ch>
2025-07-25 15:57:07 +01:00
Andrew Young dafbb02738
[FIRRTL] FRT: support creating 0-valued enums (#8772)
This adds the ability to the FullResetTransform to create enumeration
values which are 0.  When the enumeration has a valid variant that is
encoded as a 0, we create this value using the FEnumCreateOp.  If there
is no valid variant with the value 0, we create a constant 0 and bitcast
it to the enumeration type.
2025-07-23 15:52:56 -07:00
Andrew Young 57a2a9aedb [FIRRTL] make mux type inference support enumeration types 2025-07-23 15:52:34 -07:00
Andrew Young 237f744475
[FIRRTL] Fix TagExtractOp's type inference (#8766)
TagExtractOp's type inference predates adding user-defined encodings for
enums in FIRRTL. This fixes the issue by using the bitwidth helpers
defined on the enumeration type.
2025-07-23 15:29:56 -07:00
Andrew Young b4da671b10 [FIRRTL] FlattenMemories: handle memories with enums
This adds support to flatten memories with enumeration in them.
Enumerations are treated as non-aggregate types, and so they get a
single bit mask to control the whole value.
2025-07-22 21:16:25 -07:00
Prithayan Barua 4ce45d581f
[Seq] Add a pass to convert an array seq.firreg to seq.firmem (#8716)
This commit introduces a new transformation pass `RegOfVecToMem` that converts
register arrays following memory access patterns into `seq.firmem` operations.

When a valid pattern is detected, the pass replaces the register array with a
`seq.firmem` operation and corresponding read/write ports.

This is required for the `circt-verilog` tool, to identify memories, such that
other `circt` transformations/analysis can be run in the `seq` dialect on the
`mlir` parsed from verilog.
2025-07-22 14:17:34 -07:00
Martin Erhart f1352362d1
[RTG] Add operations to report test result (#8751) 2025-07-21 18:43:42 +01:00
Martin Erhart a8600777dc
[RTG] Support immediate slice/concat after validate (#8744) 2025-07-20 09:15:27 +01:00
Hideto Ueno dc524e9ea0
[AIG][LongestPathAnalysis] Fix a bug in deduplicatePathsImpl (#8746)
This commit fixes a bug in deduplicatePathsImpl within the AIG LongestPathAnalysis.

Close https://github.com/llvm/circt/issues/8745
2025-07-19 20:51:17 -07:00
Martin Erhart 24bd19e3cc
[RTG] Fix ValidateOp elaboration (#8743) 2025-07-19 11:10:36 +01:00
Martin Erhart 418459fd0d
[RTG] Add concat_immediate and slice_immediate folders (#8738) 2025-07-19 09:23:48 +01:00
Martin Erhart fb0b3dae45
[RTG] Add immediate concat and slice operations (#8735) 2025-07-19 09:22:02 +01:00
Andrew Young 9c54fa5619
[FIRRTL] Do not allow uninferred widths or resets in enums (#8740)
This adds verifiers to the FIRRTL parser and to the FEnumType to prevent
having uninferred widths and resets inside enumerations.  It seems like
the trickiness to implement these features would be hard to take
advantage of in practice, making it not worth it.  This also fixes the
error messages produced by the type verifier that had extraneous quotes
around the field name, and rearranges some tests to be co-located in the
test file.
2025-07-18 15:32:34 -07:00
Andrew Young 20fd9f4ae8 [FIRRTL] FIRParser: parse tagExtract operations 2025-07-18 12:04:46 -07:00
Andrew Young 6ece8a3005
[FIRRTL] Enums: Add user-defined constructor encodings (#8724)
This adds the ability to specify the constants used to encode
enumeration variants in the tag. For example,
``` firrtl
wire a : {| A = 10, B = 5 |}
```

The values can be unspecified, in which case it defaults to one higher
than the previous value, or zero if it is the first value. For example,
these two enumerations are the same:
``` firrtl
{| A = 0, B = 1 |} == {| A, B |}
```

In FIRRTL, Two enumeration types are considered equal if they have the
same variants with the same values and data, without regard to variant
order.  Internally in FIRRTL dialect IR, enumerations types must have
the variants sorted from low to high. For example the following two
enumeration types are equivalent:
``` firrtl
{| B = 1, A = 0 |} == {| A, B |}
```

The mlir syntax has been updated to ellide the the tag values and data
types if they are implicit.  For example, the first type would be
roundtripped to the second type:
``` mlir
!firrtl.enum<a = 0 : uint<0>> => !firrtl.enum<a>
```

Enumerations are no longer lowered to SystemVerilog enumerations, but to
regular integer types.  This is for a variety of reasons, but mainly
because enumerations in SV are nominal and it was not a good fit for our
structural enumerations.

In LowerToHW, the `firrtl.istag` operation lowers to a comparison to a
constant value created with  a localparam, which can show up in the
output depending on how the module is optimized. The  FIRRTL code below,

``` firrtl
FIRRTL version 4.0.0
circuit Enums:
  public module Enums:
    input in : {|A = 8 : UInt<8>, B = 16 |}
    output out : UInt<8>
    match in:
      A(data):
        connect out, data
      B:
        connect out, UInt<8>(16)
```
produces:
``` verilog
module Enums(
  input  struct packed {logic [4:0] tag; union packed {logic [7:0] A;/*B: Zero Width;*/ } body; } in,
  output [7:0]                                                                                    out
);

  localparam [4:0] A = 8;
  assign out = in.tag == A ? in.body.A : 8'h10;
endmodule
```
2025-07-18 11:26:31 -07:00
Leon Hielscher 71dec45d65
[Verif] Add RefinementCheckingOp (#8713)
This PR adds the RefinementCheckingOp to the verif dialect. The motivation behind this operation is to be able to automatically check whether a 'target' circuit is a refinement of a 'source' circuit. This should be a small step towards performing translation validation comparable to Alive2. The operation is structurally identical to the LogicEquivalenceCheckingOp, so I factored out most of the ODS into a common CircuitRelationCheckOp. If there is no non-determinism present in the circuits, the operation is also functionally identical to LogicEquivalenceCheckingOp.

Co-authored-by: Bea Healy <57840981+TaoBi22@users.noreply.github.com>
2025-07-18 19:36:58 +02:00
Martin Erhart f741e83f0f
[RTG] Add a pass to print a list of tests (#8734)
This pass prints the names of the tests in the IR. Since tests can be duplicated and elaborated differently during compilation, it prints both the newly uniqued name and the original name as specified by the user in the frontend.
2025-07-18 18:08:19 +01:00
Andrew Young cfe267e907
[FIRRTL] LowerSigs: Add enum support (#8731)
This adds support for enumerations to LowerSigs so that the pass no
longer fails when it encounters an enum, and just passes them through
unchanged.

Fixes #7106
2025-07-18 08:58:52 -07:00
John Demme 3e42dbce12
[ESI] Fix wrap op canonicalizers (#8730)
Fixes the canonicalizers for wrap operations in the ESI dialect by replacing problematic attribute-based folding with proper operation creation and improving pattern matching logic.

- Updates `WrapValidReadyOp` and `WrapFIFOOp` fold methods to create `NullSourceOp` operations instead of using attributes
- Improves the `WrapFIFOOp` canonicalize method with better error handling and more robust user checking
- Delegates constant materialization to the HW dialect for better consistency
2025-07-17 15:50:53 -07:00
Andrew Young e5c0e6f20f [FIRRTL] verify no duplicate fields in bundles 2025-07-17 15:10:37 -07:00
Andrew Young f9ef4cd72a [FIRRTL] FIRParser: check the bundle field names are unique 2025-07-17 15:10:37 -07:00
Andrew Young dc0940687a
[FIRRTL] FIRParser: support caching constants in match statements (#8723)
This fixes a long standing bug when parsing match statements which
contain numeric constants.

The FIRParser has a contant cache so that we can reuse any constant
operation created as we parse, by inserting them into the top-level body
of the module.  To find the top level block, we were searching upwards
from the current insertion point.

In general, when creating any operation, we are required to know how
many regions the operation has; it is impossible to add more regions
after creating the operation. Due to this, when parsing the arms of a
match statement, the expressions are inserted into a region which is not
attached to any operation.  This means we can not search upwards from
the insertion point to find the top level block. When operations do not
have this problem as they always have space 2 regions.

This change passes in the top level block when creating the
FIRModuleContext.  If it turns out that the region we are inserting into
is not underneath the module, then we can insert the constant at the end
of the module's block.

This change also makes the cache itself a private member, and removes a
bit of code which was unnecessarily directly accessing the cache.
2025-07-17 11:45:25 -07:00
Andrew Young ad3d990f9b
[FIRRTL] SFCCompat: properly lower invalidated enums (#8722)
Enum types were not handled by this pass, and so it would hit an
unreachable assert.  This handles enum types using the aggregate
codepath, which creates a 0 value and bitcasts it to the aggregate type.
2025-07-17 11:45:15 -07:00
Robert Young 194a788319
[FIRRTL] Remove circuit from macro used by inline layers (#8714)
We want to use the same macro for an inline layer across all compilation units
(circuits) in a design.  Remove the circuit name from the macro name.
2025-07-17 14:24:10 -04:00
Martin Erhart 1e70370de2
[RTG] Enable conditional value forwarding for ValidateOp (#8712) 2025-07-17 08:59:04 +01:00
Martin Erhart 916ff355ee
[RTG] Add custom tuple type to support empty tuples (#8711)
The builtin tuple type does not allow empty tuples, but they can avoid special casing in the frontend and can also be used as indicators (something like a none type could otherwise be used for but which we don't have in RTG).
2025-07-17 08:13:28 +01:00
Martin Erhart 0ee3284927
[RTG] Redefine RandomNumberInRangeOp upper bound to be inclusive (#8710)
When we want to be able to get all possible numbers that fit in a 64 bit register, we would need a 65 bit number as the upper bound. However, an iindex typed attribute uses an APInt with 64 bits and would thus make this complicated.
2025-07-16 19:41:55 +01:00
Prithayan Barua 2beb8e783f
[OM] Deprecate the OM Map and Tuple (#8606)
Remove the support for OM Map and Tuple. 
All the dependence on them have been removed.
---------

Co-authored-by: Mike Urbach <mikeurbach@gmail.com>
2025-07-14 19:57:59 -07:00
Hideto Ueno bb8e97b88a
[AIG] Add canonicalization to simplify inversion (#8697)
Add a canonicalization pattern for AndInverterOp that flattens nested
inversions by detecting when an and_inv operation takes as input another
and_inv operation with a single inverted operand.

This eliminates redundant double inversions and simplifies the AIG
representation by reducing the depth of inversion chains.
2025-07-11 18:40:43 -07:00
Fabian Schuiki 7df789c3ba
[Comb] Fix excessive const shifts causing crashes and invalid IR (#8696)
The folders and canonicalizers for `comb.shl`, `comb.shru`, and
`comb.shrs` perform unchecked `getZExtValue()` calls which can crash
if the shift amount does not fit into 64 bits. The shift amount is also
not clamped to the width of the result, which causes the shift to be
replaced with ops that have a different type.

Found with [VlogHammer], which turns out to be a very handy tool!

Fixes #8694.
Fixes #8695.

[VlogHammer]: https://github.com/YosysHQ/VlogHammer
2025-07-11 17:30:48 -07:00
Bea Healy 0b4b514cb7
[NFC] Change comb folds check comment to double slash 2025-07-11 16:49:57 +01:00
Bea Healy 89a571a420
[Comb] Avoid some non-terminating MuxOp fold cases (#8691) 2025-07-11 16:48:21 +01:00
Fabian Schuiki c43ec9809f
[Deseq] Add bin flag to enable mux (#8686)
Set the `bin` flag on the `comb.mux` that we insert for enable
flip-flops in LLHD's Deseq pass. This allows circt-verilog to preserve
the difference between `if (en) q <= d` and `q <= en ? d : q` enables.

In the future we'll probably want to have more explicit ops to describe
these differences. But adding the `bin` flag causes the pipeline to
preserve the property we're interested in for now.
2025-07-11 08:11:00 -07:00
Robert Young 752ccb5218
[FIRRTL] Add "knownlayers" specifications to ExtModules (#8623)
* [FIRRTL] Add "knownlayers" specifications to ExtModules

In a circuit, we only know about the layers which have been declared. If we
have an extmodule, it may have been defined under a different set of layers
than what is in the current circuit. In particular, if there is a layer which
we know about, but the extmodule does not, then the extmodule will not have a
bind file for us to include.

This commit adds a "knownlayer" declaration to extmodules, which is an explicit
specification of the layers which an extmodule was defined with.  For each
bound-in layer that an extmodule knows about, we can assume that there will be
a bindfile to include.

Changes:

FExtModule: Add a knownLayers property. Update the verifier so that, if a layer
is mentioned by an enablelayer specification or port type, then that layer must
be known by the exmodule. Bonus: implement verifySymbolUses for extmodules.

FIRParser: add parsing for knownlayer declarations on extmodules.

LowerLayersPass: Use the known-layers of extmodules while building the
bindfiles for modules in the current circuit. If a module in the current
circuit instantiates an extmodule, then that module's bindfiles will include
the bindfiles for the known-layers of the extmodule.

SpecializeLayers: Clean up known-layers when a layer is specialized away.

FirEmitter: Emit knownlayer declarations.

* Apply suggestions from code review

Co-authored-by: Schuyler Eldridge <schuyler.eldridge@gmail.com>

* Address comments

* Fix typo

* Clean up layer verification messages

* Use nextFIRVersion for guarding knownlayer

---------

Co-authored-by: Schuyler Eldridge <schuyler.eldridge@gmail.com>
2025-07-11 09:10:59 -04:00
John Demme 2d75698c63 [HW] Add materialization support for type aliases
Would have been working but the check was using `isa` rather than
`type_isa`, the custom version which looks through type aliases.
2025-07-11 05:03:59 +00:00
John Demme 05c06ad134
[ESI] Add a transaction snoop operation (#8684)
Adds a new transaction‐level snoop operation (`snoop.xact`) to the ESI dialect, lowers it to hardware, and wires it through the Python front end.

- Introduce `SnoopTransactionOp` in ESIChannels.td with `verify` and `inferReturnTypes` in ESIOps.cpp  
- Extend the HW lowering pass to remove `snoop.xact` via `RemoveSnoopTransactionOp`  
- Update MLIR tests and the PyCDE API (`snoop_xact`) to exercise the new operation
2025-07-10 21:14:35 -07:00
Robert Young 323a112db1
[FIRRTL][firtool] Enable advanced layer sink by default (#8683)
Advanced layer sink is now the only "layer sinking" pass that can run, it is no
longer possible to run the original layer sink pass. This commit also disables
layer sinking when optimizations are disabled.

Remove the LayerSink pass and rename advanced-layer-sink to layer-sink.
2025-07-10 22:01:25 -04:00
Fabian Schuiki 9dc7a6a0d0
[Comb] Replace mux cond uses in true/false operand with constant (#8685)
Implement the following canonicalizations which essentially assume the
value of a mux condition to be a constant in the op that supplies the
true or false value of the mux:

```
mux(cond, op(cond), x) -> mux(cond, op(1), x)
mux(cond, x, op(cond)) -> mux(cond, x, op(0))
```

This only works if the true or false value only have a single use.
2025-07-10 18:46:38 -07:00
Robert Young fffcf2ece6
[FIRRTL] Lower registers under ifdefs (#8605)
* [CIRCT] Move parallelTransformReduce to common util header

* [FIRRTL] Lower registers under ifdefs

In seq-to-sv, we transform seq FirRegOps to sv RegOps. This is done using a
helper called FirRegLowering. This PR changes FirRegLowering to correctly lower
registers under ifdef blocks.

The initialization of registers is placed in an initial block at the footer of
the enclosing HWModuleOp. In order to initialize registers buried under ifdefs,
we have to refer to these registers by a local XMR, because the buried
registers will not dominate the initial block. We build these in a prepass over
the MLIR module, returning a "PathTable" sending buried FirRegOps to their
HierPathOps.

The main FirRegLowering procedure operates in parallel on each HWModuleOp. Each
invocation is now handed a const reference to the path table, which allows us
to produce an XMRRefOp as needed while emitting the register initialization
code at the footer of the HWModule.

The initialization code for a register has to be guarded under the same ifdef
conditions as the register itself. To do this, while lowering registers, we
record the conditions under which the register is defined, and recreate them to
guard the initialization code.

When we lower a register, we attempt to transform any input mux tree into an SV
if-else tree of connects. This PR modifies the if-else generation to co-locate
the if-else with the register. So if a register is guarded under an ifdef, then
the if-else structure driving it will also be under the same ifdef.
2025-07-10 15:42:50 -04:00
Jacques Pienaar 945019b09f
Insert probes at least post def. (#8674)
Handle failure case where the probe was being inserted before def.
2025-07-10 11:14:22 -07:00
Martin Erhart 56625bf811
[RTG] Add Randomization Pipeline (#8675) 2025-07-10 14:14:24 +01:00