Commit Graph

10108 Commits

Author SHA1 Message Date
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
Schuyler Eldridge 26d875ca88
[FIRRTL] ODS constructors for option-less passes
Convert the remaining option-less FIRRTL passes to use ODS constructors
instead of rolling our own.  There's no actual benefit in using the custom
ones other than making things more complex (and adding confusing
boilerplate that developers think they need to copy).

h/t @eunoku for the suggestion to do this.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-11 15:45:45 -04: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
Samuel Coward 097604cfa1
[Datapath] Add Datapath to SMT conversion pass (#8682)
To verify correctness of transformations involving datapath operations,
include a lowering from datapath to SMT. Will later be integrated into
circt-lec to enable verification of these operators. Each operator
satisfied a contract, rather than providing a precise semantics for
every operator. This is because the datapath operators return values in
redundant number representations, meaning there are many valid
implementations.

For example:
```mlir
%0:2 = datapath.compress %a, %b, %c : i8 [3 -> 2]
```
Will be verified by introducing free variables for each return value 
`(%0#0, %0#1)` then asserting that the sum of the associated free 
variables is equal to the sum of the inputs:
`assert(%0#0 + %0#1 == %a + %b + %c)`.

Whilst this is encoded as an assert it really represents an assumption
that must be satisfied by a valid implementation of datapath.compress.
2025-07-11 08:13:11 -07: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
Leon Hielscher ece9412ddf
[VerifToSMT] Fix lowering of initial integer values for BMC (#8689)
Fixes a problem during VerifToSMT lowering when creating the smt::BVConstantOps for initial integer values of registers in the BMC operation. The current implementation calls getSExtValue() on the APInt provided by the initial value attribute. This causes a crash in either of the following situations:
- The initial value type is lager than 64 bits
- The initial value type is smaller than 64 bits and the MSB of the value is set. By sign-extending to 64 bits, the resulting integer value exceeds the width of the created BitVector.

This is fixed by passing the APInt directly to the builder of smt::BVConstantOp and adding a check beforehand ensuring that the types of the initial attribute and the initialized register match.


Co-authored-by: Martin Erhart <maerhart@outlook.com>
2025-07-11 13:52:59 +02:00
John Demme b9004ca0d6
[HW] MaterializeConstant: check for null block (#8687)
Builders don't always specify the block. If it doesn't, this function
segfaults. Fix this bug and add a unit test.
2025-07-10 23:24:35 -07: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
Schuyler Eldridge cf6ca8e53b
[FIRRTL] Switch some passes to ODS constructor
Change from using custom pass constructors to using the ODS-generated pass
constructors.  This both saves on line count and also generates nicer,
more consistent constructors for passes which have options.

This migrates some passes that do not use options.  More passes need to be
migrated.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-10 23:02:46 -04: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
Schuyler Eldridge 2d679b93c2
[firtool] Default -lint-xmrs-in-design to false
Change the default value for `-lint-xmrs-in-design` to `false`.  This
provides at least one version where this linting is available, but
opt-in (which is backwards compatible) as opposed to opt-out (which is
not).  Additionally, for flows that are using `-enable-layers` and
`-sv-extract-test-code`, defaulting this to `true` creates issues where
you _need_ to turn it off because linting happens after layers are
inlined, but before they are extracted.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-10 21:57:09 -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
Fabian Schuiki c26c060dbd
[Comb] Add HW as dependent dialect
The canonicalizers in the Comb dialect generate `hw.constant`
operations. If the input does not contain any HW ops that would trigger
the HW dialect to load, the canonicalizers would crash when trying to
create a constant.

Marking HW as a dependent dialect causes it to be loaded.
2025-07-10 17:19:39 -07:00
Hideto Ueno 1fb38a58ea
[circt-synth] [Synthesis] Add synthesis pipeline and refactor the lib structure (#8681)
This commit introduces a standardized synthesis pipeline and restructures the codebase:

* Creates a new SynthesisPipeline class to define the default synthesis pipeline. This pipeline serves both circt-synth and is exposed through the C API for Python bindings.
* Added a dedicated Synthesis directory under `lib/` to house synthesis-related code. This architectural change is aimed to promote synthesis capabilities to a first-class component within CIRCT rather than limiting it to the circt-synth tool.
2025-07-10 16:16:11 -07:00
Liam Jay dd7b402d96
[MooreToCore] Lower moore.powu to math.ipowi (#8654)
Change PowUOpConversion to call into the MLIR math dialect for unsigned 
integer exponentiation.
2025-07-10 14:50:42 -07:00
Schuyler Eldridge 96b54ebc67
[FIRRTL] Fix Lint.cpp compile error
The `transformReduce` utility was moved out of FIRRTL and into a CIRCT
support library.  Update a user of this in the `Lint` pass.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-10 15:59:23 -04: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
Fabian Schuiki 436ed621bd
[ImportVerilog] Incorporate block names to variable/instance names (#8680)
Use the names of surrounding generate blocks as a prefix for variable
and instance names. This makes the names match up more closely with how
existing EDA tools would label variables and instances embededded in
generate blocks.

Consider the following Verilog input:

```systemverilog
module Top;
  int x;
  begin : foo
    int y;
    for (genvar i = 2; i < 6; ++i) begin : bar
      int z;
    end
  end
endmodule
```

The ImportVerilog conversion pass will now produce the following
variables:

```mlir
%x = moore.variable : <i32>            // before: %x
%foo.y = moore.variable : <i32>        // before: %y
%foo.bar_2.z = moore.variable : <i32>  // before: %z
%foo.bar_3.z = moore.variable : <i32>  // before: %z_0
%foo.bar_4.z = moore.variable : <i32>  // before: %z_1
%foo.bar_5.z = moore.variable : <i32>  // before: %z_2
```

This closely matches names like `foo.bar[2].z` or `foo_bar_2_z` that
would be generated by common EDA tools. Ideally we would be able to use
a name like `foo.bar[2].z` directly, but ExportVerilog currently does
not support escaped identifiers, causing the name to be sanitized to
something like `foo_bar5B25D_z`.

By incorporating for-generate loop indices and block names into the
variable name, logical equivalence checking should become easier and the
signal names in Arcilator waveforms will match user expectations more
closely.

Fixes #8679.
2025-07-09 17:20:31 -07:00
Schuyler Eldridge dfa0fe98e9
[FIRRTL] Fix inject-dut-hier deleting new top (#8678)
Fix an issue with the `moveDut=true` behavior of the `InjectDUTHierarchy`
pass that would occur if the design-under-test (DUT) was the main module
in a circuit.  If this happens, this would create a new wrapper module
above the DUT, mark it private, and keep the main module of the circuit
pointing at the wrapper.  This would then cause the new DUT to be deleted
as it was a private module.

This is not FIRRTL ABI compatible as it will create a new public module
and cause things like additional ref files to be created.

CC: @azidar

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-09 18:30:42 -04:00
Schuyler Eldridge 77afe72378
[FIRRTL] Remove unused variable, NFC
Remove an unused variable in the `CreateSiFiveMetadata` pass.  This fixes
a compilation warning.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-09 15:01:43 -04:00
Schuyler Eldridge 5c6371fa83
[FIRRTL] Fix test circuit name, NFC
Fix an incorrect test circuit name.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-09 14:42:04 -04:00
Trevor McKay bffff7d9a2
Add SitestBlackBoxLibrariesAnnotation; process in CreateSiFiveMetadataPass (#8670) 2025-07-09 12:04:44 -06:00
Samuel Coward 713a91ddff
[Datapath] Conversion Pass Comb to Datapath (#8664)
Add support for lowering variadic adders and two-input multipliers to datapath operations. Now automiatng 
```
%0 = comb.mul %a, %b : i4
%1 = comb.add %0, %c : i4
```

Resulting from comb-to-datapath and canonicalize:
```
%0:4 = datapath.partial_product %a, %b : (i4, i4) -> (i4, i4, i4, i4)
%1:2 = datapath.compress %0#0, %0#1, %0#2, %0#3, %c : i4 [5 -> 2]
%2 = comb.add %1#0, %1#1 : i4
```
2025-07-09 08:54:55 -07:00
Tobias Wölfel f91e77c509
[ImportVerilog] Add support for SVA declarations (#8656)
Support `sequence` and `property` declarations. Slang already handles 
the references and variable ports. Make visiting of `AssertionInstance` 
legal. Those are part of `Expressions` of the `Simple` case. Adapt this 
visitor to handle the varied return types.
2025-07-09 08:40:25 -07:00
Fabian Schuiki 3df813fd7e
[ImportVerilog] Fix range selects, unify lvalue/rvalue code paths
Fix a few issues in the conversion of indexed ranges selects like
`[a+:b]` and `[a-:b]`. These would not properly convert from the bit
indices to the bit offsets of the underlying storage. The `+:` and `-:`
directions and ascending/descending range specifications make for
strange combinations that need to be handled.

Also pull the code that is almost identical between lvalue and rvalue
lowering into a new common `ExprVisitor` base class. This class has an
`isLvalue` boolean member that can be consulted by the conversion to
either build lvalue ops such as `moore.extract_ref`, or rvalue ops such
as `moore.extract`. This allows us to have a single implementation for
bit and range selects, as well as member accesses.

Add tests for all flavors of range selects, for both ascending and
descending ranges, and rvalues and lvalues.

Fixes #8671.
2025-07-08 21:28:42 -07:00
Schuyler Eldridge 09ea9da012
[FIRRTL] Refactor lint to use ODS constructor
Refactor FIRRTL's Lint pass to use the ODS-generated constructor as
opposed to hand-rolling one.  This avoids weirdness where the command-line
options have different defaults from what they are specified as in ODS and
avoids the need for a "Config" struct inside the linter's namespace (as
the ODS-generated one can be used).

h/t @uenoku for the suggestion.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-08 22:19:37 -04:00
Schuyler Eldridge 96177f5d8b
[firtool] Add -lint-xmrs-in-design firtool option
Add an option to the `firtool` command line that allows for
disabling/enabling the linting of XMRs that exist in the "design".  While
there is now a general policy of exposing each lint option in firtool, I
am particularly nervous about this option as it has a high likelihood of
causing problems (false positives).

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-08 22:19:18 -04:00
Schuyler Eldridge b99b7c3186
[FIRRTL] Add lint-xmrs-in-design option to Linter
Add an option to FIRRTL's linter that allows for disabling/enabling
linting of XMRs that exist in the "design".

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-08 22:18:58 -04:00
Schuyler Eldridge 5d61b452ef
[FIRRTL] Add linting of XMRs in the design
Extend the FIRRTL linter to check that there are no XMRs that will be
located in the "design".  This intentionally only checks for problems in
the "design" and NOT the "effective design".  This errs on the side of
having more false negatives without introducing the possibility of false
positives for separate compilation flows.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-08 22:18:39 -04:00
Schuyler Eldridge b39b6c6be5
[firtool] Expose -lint-static-asserts option
Expose an option to turn off/on the linting of trivially false assertions.
This option defaults to "on" because this was the behavior originally.
Also, I am intending to follow this going forward where lint checks are
always on and have to be turned off.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-08 22:18:18 -04:00
Schuyler Eldridge 9edab3eb93
[FIRRTL] Add lint-static-asserts option to linter
Make the linting of static assertions an option to the linter.  While this
appears unnecessary now, I am intending to add additional lint checks to
the linter and I want to be able to turn each of them off if they become
problematic.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-08 22:17:57 -04:00
Schuyler Eldridge e7c47930f7
[FIRRTL] Make Lint Circuit Pass w/ parallelism
Convert the FIRRTL linting pass to be a `CircuitOp` pass with internally
handled parallelism.  This is done in preparation to add XMR linting which
requires an `InstanceInfo` analysis which needs to be on the `CircuitOp`.
There are two ways of doing this:

  1. Make the pass operate on the `CircuitOp` as this patch does.

  2. Use a cached parent analysis which requires a dedicated pass to
     compute the `InstanceInfo` analysis and then careful pass pipeline
     structuring.

(2): is used in one place in IREE and nowhere else.  Additionally, (1) was
suggested by multiple people in "Hallway Usabilty Testing"-type
discussions.  (Many people thought (2) was odd.)

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-08 22:17:30 -04:00