Commit Graph

5282 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
Michael dcb2d92b98
[HWToLLVM] Add lowering support for 'hw.array_inject' op (#8774) 2025-07-30 10:31:23 +02:00
Hideto Ueno 9e27c4ddae
[HWToSMT] Return an unbound value for OOB hw.array_inject (#8794)
This is a follow up to 186dcc8b0e to fix OOB behavior.

h/t @fzi-hielscher for pointing out the issue
2025-07-29 17:00:06 -07:00
Martin Erhart a11a834d96
[RTG] Simplify EmitISAEmission pass (#8798) 2025-07-29 21:16:48 +01:00
Martin Erhart 175e30d32f [RTG] Rely on textual pass pipeline in Python and CAPI
The textual pass pipeline has a bit more overhead due to the string parsing, but it reduces the required maintenance as we don't have to write CAPI and Python bindings for all the pass options.
2025-07-29 17:48:13 +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 1a7fc25c63
Bump LLVM to 76bebb5be9daf9ca035777b17fa63d4ce13e79b9 (#8796) 2025-07-29 17:16:26 +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
Samuel Coward 30a4a38fca
[Datapath] Create Datapath to Comb Pass (#8736)
* Initiate datapath to comb pass

* Add tests and tidy datapath to compress implementation

* Improve comments

* Formatting and test corrections

* Correct CAPI

* Move wallace tree reduction and full-adder to comb ops

* Adding integration tests using circt-lec and correcting review comments

* Fix bug in Booth code for final sign correction row and add testing using lec. Add a forceBooth option largely for testing purposes

* Minor fix

* Formatting

* Removing populate patterns function

* Formatting
2025-07-25 14:13:24 +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
Fabian Schuiki dbbc952d89
[circt-verilog] Add register-to-memory pass to pipeline (#8773)
Add the new RegOfVecToMem pass to the circt-verilog pipeline. This will
detect memories described as `always` blocks and map them from the
current `seq.firreg` representation to the correpsonding `seq.firmem`.
This allows later parts of the pipeline to reason about memories more
easily and transform them if needed.
2025-07-23 15:24:37 -07:00
Fabian Schuiki 5c3780f58b
[MooreToCore] Preserve module port order (#8768)
Preserve the order of module ports when converting from `moore.module`
to `hw.module`. The current implementation populates separate input and
output vectors, which makes all inputs appear before all outputs. The
updated version just populates a single array of ports, which preserves
order. This makes it easier to round-trip Verilog through circt-verilog,
and makes the output of circt-verilog more predictable.
2025-07-23 10:39:09 -07:00
Leon Hielscher ab7a0a6c85
[VerifToSMT] Lower `verif.refines` to SMT (#8749)
Implement a conversion pattern for the `verif.refines` operation to the SMT dialect.
2025-07-23 11:42:19 +02:00
Hideto Ueno 186dcc8b0e
[HWToSMT] Add ArrayInject lowering to HWToSMT (#8765)
This commit implements the lowering of hw.array_inject operations to SMT
expressions using smt.array.store operations. The lowering creates a new
array with the specified element injected at the given index, with proper
bounds checking to handle out-of-bounds accesses gracefully.

The implementation includes bounds checking that compares the index against
the maximum valid index (numElements - 1) and uses smt.ite to return either
the updated array (if in bounds) or the original array (if out of bounds).
2025-07-23 01:21:59 -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
Hideto Ueno 640daf0c92
[HW][AIG] Add InstancePath CAPI and use native structures for AIG longest path analysis (#8760)
This commit refactors the AIG longest path analysis C API to use native C structures instead of JSON strings, providing better performance and type safety.

The API changes replace `aigLongestPathCollectionGetPath` returning JSON with `aigLongestPathCollectionGetDataflowPath` returning native objects. New opaque handle types are added including `AIGLongestPathObject`, `AIGLongestPathHistory`, and `AIGLongestPathDataflowPath`. Comprehensive APIs are provided for accessing path data, history, and object properties. 

InstancePath C API support is introduced in `circt-c/Support/InstanceGraph.h`. Currently `InstancePathCache` itself is not provided, as the use of LongestPathAnalysis is read-only and there is no need to mutate/construct InstancePath. Unfortunately due to that testing of CAPI of InstancePath got a bit tricky. For now AIGLongestPathAnalysis is used to produce InstancePath in CAPI.

The Python binding updates refactor Object, DataflowPath, and LongestPathHistory classes to use the native C API. JSON parsing dependencies and from_json_string() methods are removed. Proper property accessors using the new C API are added while maintaining backward compatibility for existing Python interfaces. So the existing integration tests cover most of the APIs. 

Testing updates include comprehensive coverage in the existing C API tests in `test/CAPI/aig.c`. A new `test/CAPI/support.c` is added for InstancePath API testing. Python integration tests are updated to work with the new API.

This change improves performance by eliminating JSON serialization/deserialization overhead and provides a more robust, type-safe interface for accessing longest path analysis results.
2025-07-22 11:30:43 -07:00
Michael 9088c29f4b
[ImportVerilog] Add full_case attribute support (#8762)
This patch adds support of `(* full_case *)` attribute in case 
statements [1], which says that all possible case items have been 
covered and no default clause is needed.

[1]: http://www1.pldworld.com/@xilinx/html/technote/TOOL/MANUAL/21i_doc/data/fndtn/ver/ver7_4.htm
2025-07-22 10:46:16 -07:00
Leon Hielscher e80a67d30d
[VerifToSMT] Fix lowering of no output, no result LEC op (#8763) 2025-07-22 18:16:17 +02:00
Martin Erhart f1352362d1
[RTG] Add operations to report test result (#8751) 2025-07-21 18:43:42 +01:00
Yicheng Liu 331820d6d0
[circt-bmc] Support `seq.firreg` with sync reset (#8698)
This adds support for seq.firreg with synchronous reset in ExternalizeRegistersPass.
2025-07-21 17:34:37 +01:00
Atticus Kuhn 888e6787e4
[FSMToSV] Fix bug of operations not being cloned in transition region (#8753)
Co-authored-by: Atticus Kuhn <atticusmkuhn@gmail.com>
2025-07-21 17:27:07 +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
Schuyler Eldridge 47cf87cdcd
[firtool] Fix argument passing to LowerAnnotations
Fix a bug introduced in [[1]] where two parameters passed to the
LowerAnnotations pass were swapped.  Swap these back and add a test of
this behavior.

[1]: 2b98e4233

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-18 16:39:05 -04:00
Andrew Young 0671e9d440
[FIRRTL] LowerToHW: handle TagExtractOp (#8726)
This updates LowerToHW to handle the TagExtractOp.  This reflects on the
lowered input value's type to determine how the enum was lowered.  If it
was lowered to a struct, we extract the tag field. If it was lowered to
a integer, we can return the integer directly.
2025-07-18 12:05:20 -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
Martin Erhart 277d3ec03c
[CombToSMT] Force conversion from bool to bv<1> after icmp (#8737) 2025-07-18 14:02:13 +01:00
Hideto Ueno ba24efca88
[circt-synth] Add an option to disable WordsToBits, remove verification code from design (#8733)
This modifies circt-synth to make it more practical.
* Remove verification code from synthesis parts. ExtarctTestCode is currently used, but eventually it must be replaced with something cleaner. 
* Add an option to disable wordsToBits.
2025-07-18 01:51:51 -07:00
Andrew Young 62a6582687 [ExportVerilog] localparam should always print bitwidths
We are currently printing 1-bit localparams without a size, which causes
verilator to complain that it does not have a known bitwidth when used
in some expressions.  This changes ExportVerilog to always print the
bitwidth of localparams, which is something we already do for
parameters.
2025-07-17 17:30:05 -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