Commit Graph

3858 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
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 327def313c [RTG] Use tablegen generated pass registration 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 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
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
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
Kazu Hirata 5e2e73845c
Migrate away from ArrayRef(std::nullopt_t) (#8776)
LLVM has deprecated ArrayRef(std::nullopt_t).  This CL migrates away
from that.
2025-07-24 15:04:17 -07:00
Andrew Young da47d826f6 [FIRRTL] mark some FIRRTLBaseType functions as const
This marks a few more FIRRTLBaseType functions as const, namely
`isConst()` and `getConstType()`.  Probably all functions defined on
this class should be marked const eventually, as none of them should
actually be modifying the object.
2025-07-23 15:52:34 -07:00
Hideto Ueno 754f72d04c
[Support] Add NPN class for Boolean function canonicalization (#8747)
This commit introduces NPNClass and BinaryTruthTable classes to the CIRCT
Support library for Boolean function equivalence checking and canonicalization.

NPNClass computes Negation-Permutation-Negation canonical forms for Boolean
functions, enabling efficient detection of functionally equivalent circuits
under input/output transformations. BinaryTruthTable provides compact
representation using APInt with support for multi-input, multi-output functions.

This infrastructure is essential for technology mapping and Boolean function
optimization in synthesis flows.
2025-07-23 10:27:52 -07:00
Andrew Young 0c5f60cb8f
[FIRRTL] Make enums behave less like aggregates (#8742)
This makes enums behave more like ground types, but doesn't quite take
the jump and make them ground types.  It removes the ability to index
into enum variants using field refs, which was used produce error
messages in InferWidths (and enums no longer support having unknown
widths).  This change adds some helpers to determine the sizes of
enumerations.

This change modifes InferWidths to to take advantage of the fact that
enumerations do not support containing uninferred widths, and removes
some dead code.  In addition to this, field refs no longer index into
the variants of an enum type, so we can handle them in a similar way to
ground types.
2025-07-22 15:20:23 -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
Hideto Ueno f0ec28ac16
[AIG][NFC] Add a module to OutputPort data structure and refactor the name handling (#8759)
This is a preparation commit for subsequent AIG python binding PR. 

 - Modified OutputPort type from pair to tuple to include module reference
 - Added getName() method to Object class for consistent name access
 - Updated JSON serialization to handle the new OutputPort structure
2025-07-21 20:33:45 -07:00
Martin Erhart f1352362d1
[RTG] Add operations to report test result (#8751) 2025-07-21 18:43:42 +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 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
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 0b3976c12e [FIRRTL] TagExtract: make type inference parser friendly
This also changes TagExtract to use the simpler type inference
signatures used by other operations, which will be used when parsing
this operation from fir files.
2025-07-17 15:12:54 -07:00
Andrew Young e5c0e6f20f [FIRRTL] verify no duplicate fields in bundles 2025-07-17 15:10:37 -07: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 5ee54acb05
Bump LLVM to d9190f8141661bd6120dea61d28ae8940fd775d0 (#8715)
Preparing this week's bump to get
* https://github.com/llvm/llvm-project/pull/149087
* https://github.com/llvm/llvm-project/pull/139694

Changes:
* Remove ambiguous builder in SV
2025-07-16 17:54:58 -04: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
Schuyler Eldridge e5603e1437
[ExportVerilog] Use ODS constructor for pre-passes
Convert ExportVerilog pre-passes to use ODS constructors instead of
unnecessarily hand-rolling custom constructors.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-14 21:54:30 -04:00
Schuyler Eldridge ec79b1b617
[hw] Convert HW Passes to use ODS constructors (#8703)
Change all HW passes to use ODS consturctors as opposed to hand-rolling
them.  The hand-rolled constructors aren't necessary and add a bunch of
boilerplate.

Note: a number of these passes do not have users and hence may break out
of tree users.  The out of tree users are likely @teqdruid and @mortbopet.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-14 18:59:07 -04:00
Leon Hielscher 8fa6b23567
[Verif][LEC] Make LECOp result optional to avoid unsafe conversion (#8701)
#8497 introduced a lowering pattern for the LogicEquivalenceCheckingOp which changes behavior depending on whether the result of the operation is used. This is generally not safe and can cause lowerings to erroneously consider the result to be used/unused. The pattern must only depend on the operation itself, not on its def-use context.

By making the result of the operation optional, we should be able to retain the current behavior. In the pattern op.use_empty() is simply replaced by op.getNumResults() == 0. However, we now have to decide at the point of creating the LogicEquivalenceCheckingOp whether the result should be made accessible to the IR.


Co-authored-by: Bea Healy <57840981+TaoBi22@users.noreply.github.com>
2025-07-14 20:30:30 +02:00
Schuyler Eldridge 4a23fec916
[FIRRTL] Cleanup Passes.h after constructors rm'd
Cleanup FIRRTL's Passes.h header now that all the non-ODS pass
constructors have been removed.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:27:11 -04:00
Schuyler Eldridge adc9e43d0f
[FIRRTL] ODS constructor for AssignOutputDirs
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:26:59 -04:00
Schuyler Eldridge a381ba5d83
[FIRRTL] ODS constructor for SpecializeOptions
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:26:47 -04:00
Schuyler Eldridge 5a65f5b221
[FIRRTL] ODS constructor for LinkCircuits
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:26:47 -04:00
Schuyler Eldridge eb1b9adf04
[FIRRTL] ODS constructor for ResolveTraces
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:26:36 -04:00
Schuyler Eldridge 308142bb1d
[FIRRTL] ODS constructor for LowerIntmodules
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:26:24 -04:00
Schuyler Eldridge 98c38c4335
[FIRRTL] ODS constructor for DropName
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:25:51 -04:00
Schuyler Eldridge a7954bb375
[FIRRTL] ODS constructor for MemToRegOfVec
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:25:38 -04:00
Schuyler Eldridge 527f9e89a8
[FIRRTL] ODS constructor for MergeConnections
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:25:26 -04:00
Schuyler Eldridge 2c59ea6472
[FIRRTL] ODS constructor for GrandCentral
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:25:14 -04:00
Schuyler Eldridge abede6aa3f
[FIRRTL] ODS Constructor for BlackBoxReader
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:24:59 -04:00
Schuyler Eldridge 7bfb55eb19
[FIRRTL] ODS constructor for CreateSiFiveMetadata
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:24:41 -04:00
Schuyler Eldridge 0c48ecec9f
[FIRRTL] ODS constructor for RemoveUnusedPorts
This additionally promotes the lone constructor argument to a true pass
option.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:24:24 -04:00
Schuyler Eldridge 7a93fea615
[FIRRTL] ODS Constructor for LowerFIRRTLTypes
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:24:13 -04:00
Schuyler Eldridge 2b98e42337
[FIRRTL] ODS Constructor for LowerFIRRTLAnnotations
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 19:23:44 -04:00