Commit Graph

10108 Commits

Author SHA1 Message Date
Schuyler Eldridge 1f6dcf84ec
[ci] Fix UBTI trigger option for cxx compiler
The compiler is `g++` not `gcc++`.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-28 15:34:29 -04:00
John Demme 211c3faba6
[PyCDE] Support custom op conversion on import (#8617)
This pull request improves the MLIR import functionality in PyCDE by
supporting custom op conversion during module import. Key changes
include:

- Adding new parameters (module_str, file, importer, debug) to the
  import_mlir function for enhanced flexibility.
- Modifying the lowering passes list with new entries for Kanagawa
  dialect lowering.
- Updating import_hw_module to accept an optional builder_type parameter
  for custom module building.
2025-06-28 00:16:00 -07:00
John Demme c5d50934da
[PyCDE] Support for importing Kanagawa (#8616)
This PR adds support for importing Kanagawa IR into PyCDE and improves
the overall pass management and proxy caching in the system.

- Added a new test file for Kanagawa IR import and lowering.
- Updated the System and _OpCache functionality to change type hints and
  weak reference handling.
- Revised the imported module creation and pass-phase execution logic.
2025-06-27 22:02:27 -07:00
Hideto Ueno 0cb05d9907
[AIG][AIGERRunner] Refactor AIG external solver passes and add continueOnFailure option (#8615)
This commit refactors and adds an option to AIGERRunner. 
1. Create ExternalSolverPass base class to reduce code duplication between AIGERRunner and ABCRunner passes, providing shared options and dependent dialects through inheritance.

2. Add --ignore-abc-failures command line option to circt-synth tool to enable continue-on-failure behavior for ABC optimization. Currently the pass fails if there are multiple clocks so it's convenient to just skip them.
2025-06-27 17:33:13 -07:00
Fabian Schuiki 82a02810ac
[Support] Allow UnusedOpPruner to remove block args
Extend the `UnusedOpPruner` helper to also remove unused block args if
all terminators branching to a block implement the `BranchOpInterface`.
2025-06-27 17:21:47 -07:00
John Demme df6ca02a06
[Kanagawa] Python dialect and pass registration (#8613)
- Register the kanagawa dialect in Python bindings
- Register kanagawa dialect passes
- Add C API header and implementation for kanagawa dialect
- Add integration test for kanagawa dialect and passes

Follows the same pattern as pipeline dialect registration in commit 5c4d8ae.
2025-06-27 13:49:44 -07:00
Schuyler Eldridge 19a9de6b77
[FIRRTL] Update instance graph in GC pass
Fix a bug in the Grand Central pass where it was deleting instances and
modules, but not keeping the instance graph up to date.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-27 15:40:49 -04:00
Schuyler Eldridge 88f5d5a56e
[FIRRTL] Allow GC Companion multi-instantiation
Change the Grand Central View lowering pass to now allow for Grand Central
Companions to be multiply instantiated.  This should have technically been
possible for a long time [[1]] as long as there was a guarantee that there
was never going to be a leaf that was _outside_ the companion.

This is a pretty simple change to just loop over all instances and
extract (add a `lowerToBind` attribute) for the ones which are in the
design.  The other, subtle blocker is that without the `InstanceInfo`,
doing the check of "in the design" was tedious.  Now this is pretty
straightforward.

[1]: 2d3a040f43

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-27 15:40:18 -04:00
Schuyler Eldridge c96689cb50
[FIRRTL] Inline one instance check in GC, NFC
In preparation to remove the exactly-one-instance check of each Grand
Central Companion module, inline the function doing this check and get
this in the right shape to switch it over to allow for multiple
instantiation.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-27 15:39:31 -04:00
John Demme 5c4d8ae62b
[Pipeline] Python dialect and pass registration (#8612)
- Register the pipeline dialect
- Register pipeline dialect passes
- Add passes to the PyCDE pipelines
2025-06-27 12:37:21 -07:00
Schuyler Eldridge 4f348d246d
[FIRRTL] Move all annotations in inject-dut-hier
Change FIRRTL's inject-dut-hier pass to move all annotations onto the
wrapper [^1] when in `moveDut=true` mode.  Additionally, when in this
mode, the WRAPPER will be named using the `name` field of this pass'
controlling annotation.  Previously, this would only move the
`MarkDUTAnnotation` when operating in this mode.  This fixes an internal
issue where Object Model paths were not being updated when using this pass
in `moveDut=true` mode.

[^1]: This is using the terminology of the pass which views this as taking
all the logic inside the original DUT and shoving it into a wrapper
instantiated inside the DUT.  When in `moveDut=true` mode, it is more
natural to think of the pass as creating a wrapper around the original
DUT.  However, to adopt this alternative terminology would be modal.
I.e., "wrapper" would mean something different when in `movedDut=true`
mode which would be confusing.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-27 12:18:51 -04:00
Schuyler Eldridge 4038e1c501
[FIRRTL] Simplify inject-dut-hier code, NFC
Refactor the InjectDUTHierarchy pass to not introduce the notion of a
`newDUT` variable.  This only confuses things.  Instead setup the DUT and
its internal wrapper immediately and then reuse these terms in all places.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-27 12:16:04 -04:00
Fabian Schuiki a69519df00
[Comb] Enable cross-block folds on extract/concat/array-of-mux (#8611)
Re-enable the canonicalizers and constant folders for `comb.extract`,
`comb.concat`, and arrays of `comb.mux` that have operands defined in
different blocks.

Also remove the `hasOperandsOutsideOfBlock` function which is no longer
needed.
2025-06-27 08:30:03 -07:00
Hideto Ueno 9624355227
[firtool] Enable WireElimination pass (#8594)
This adds EliminateWiresPass before IMCP to introduce a lot of more optimization opportunities.
2025-06-27 02:47:21 -07:00
Hideto Ueno f37586773c
[FIRRTL] Improve canonicalization patterns for variadic cat and reduction operations (#8578)
This commit enhances FIRRTL canonicalization with several new optimization patterns:

**Reduction-Cat Patterns:**
- Replace table-driven patterns for AndR/OrR/XorR with cat operands with C++
- AndRCat: Optimizes andr(cat(...)) by handling zero constants (-> 0) and all-ones constants (identity)
- OrRCat: Optimizes orr(cat(...)) by handling non-zero constants (-> 1) and zero constants (identity)
- XorRCat: Optimizes xorr(cat(...)) by preserving non-zero constants and eliminating zero constants

**Cat Optimization Patterns:**
- FlattenCat: Flattens nested cat operations into single cat operations for better optimization opportunities
- CatOfConstant: Folds successive constant operands in cat operations (e.g., cat(x, 3, 5, y) -> cat(x, 29, y))
- BitsOfCat: Optimizes bits extraction from cat operations by extracting directly from the appropriate operand when possible

The new patterns replace the previous table-driven AndRCat*, OrRCat*, and XorRCat* patterns since it's
too complicated to handle the condition in tablegen
2025-06-27 00:55:19 -07:00
Fabian Schuiki 6d08cb4733
[Comb] Enable cross-block folds on replicate/parity/shl/shr/mux/icmp (#8609)
Re-enable the canonicalizers and constant folders for `comb.replicate`,
`comb.parity`, `comb.shl`, `comb.shru`, `comb.shrs`, `comb.mux`, and
`comb.icmp` that have operands defined in different blocks.
2025-06-26 20:58:12 -07:00
Fabian Schuiki d8e2c6c63c
[Comb] Enable cross-block folds on add/sub/mul/div/mod (#8608)
Re-enable the canonicalizers and constant folders for `comb.add`,
`comb.sub`, `comb.mul`, `comb.divu`, `comb.divs`, `comb.modu`, and
`comb.mods` that have operands defined in different blocks.
2025-06-26 18:13:13 -07:00
Hideto Ueno 5658103a96
[FIRRTL] Make CatPrimOp variadic (#8557)
This patch converts CatPrimOp from a binary operation to a variadic operation that can accept multiple operands. The change is mostly mechanical:
- Updating the fold method to handle multiple operands
- Modifying canonicalization patterns to work with the new variadic form (https://mlir.llvm.org/docs/DeclarativeRewrites/#supporting-variadic-ops)
- Updating the FIRRTL to HW lowering to handle variadic concatenation
- Adjusting the FIREmitter FIRRTLVistior
2025-06-26 14:53:18 -07:00
Fabian Schuiki e1fc1023d8
[Comb] Enable cross-block folds on and/or/xor (#8607)
Now that #8517 has landed, re-enable the canonicalizers and constant
folders for `comb.and`, `comb.or`, and `comb.xor` that have operands
defined in different blocks.
2025-06-26 13:29:02 -07:00
Fabian Schuiki 4c6030fd74
[LLHD] Add pass to lower acyclic control flow to mux ops (#8600)
Add the *RemoveControlFlow* pass to the LLHD dialect. It operates on all
`llhd.combinational` ops in an `hw.module` if the op has no side-effects
and the control flow is acyclic. The pass moves all operations in the
`lhld.combinational` op body into its entry block and inserts `comb.mux`
ops to resolve block arguments. All blocks besides the entry block are
then removed.

A future loop unrolling pass would get rid of any cycles in the control
flow, such that this pass can then pick up the remaining control flow
lowering.

This is an important pass in lowering behavioral circuit descriptions,
such as `always` blocks in Verilog or `process`es in VHDL, to a set of
equivalent Comb dialect ops in the module body.

Shoutout to @maerhart for doing all the heavy lifting for this pass on
his experimental branch!

Co-authored-by: Martin Erhart <martin.erhart@sifive.com>
2025-06-26 10:25:13 -07:00
Hideto Ueno fbaa982249
[OM] Use SymbolTable::lookup instead of lookupNearestSymbolFrom (#8602)
SymbolTable::lookupNearestSymbolFrom is a static member function of
SymbolTable and not looks up a pre-populate table, which causes
O(N^2) regression
2025-06-25 17:23:58 -07:00
Schuyler Eldridge ea23107b45
[FIRRTL] Fix use of uninitialized analysis in GC
Fix a bug where an analysis was used before being initialized when
running in debug mode with the Grand Central pass.  This bug was
unreachable when _not_ running in debug mode.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-25 16:22:27 -04:00
Schuyler Eldridge e89e5969ea
[FIRRTL] Move definition closer to use in GC, NFC
Move a definition closer to its usage site in the Grand Central pass.
This is working towards enabling multiple instantiation of Grand Central
Views.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-25 16:22:09 -04:00
Schuyler Eldridge a1f30f645e
[FIRRTL] Use module, not instance in GC, NFC
Tweak the Grand Central pass to use module port info instead of instance
port info when doing annotation validation checking.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-25 16:21:40 -04:00
Mike Urbach 82f49ca26c
[FIRRTL] Allow duplicate tracker annotations in LowerClasses. (#8598)
Historically, we would assert that every tracker was used exactly
once. However, with certain combinations of multiple instantiation and
dedup, we can run into duplicate trackers. Specifically, like in the
test case, if there are two modules that dedup, but they are
instantiated multiple times in modules that do not dedup, we can end
up with duplicate trackers that point to the same thing. When dedup is
working, the paths are distinct, and it is only at the end that we
realize they are pointing to the same thing.

This handles that case, by actually checking the path associated with
duplicated trackers. If the trackers ultimately ended up pointing to
the same thing, this is now allowed. It is still an error to have
the same tracker pointing to multiple different paths through the
hierarchy.

Finally, this removed the sentinel PathInfoTableEntry objects we would
create simply to check uniqueness. Now that we are actually using the
paths to confirm uniqueness or lack thereof, we don't need the sigil,
and putting in a PathInfoTableEntry without a path means we can't
perform the new check. These only existed for unused paths, which the
situation described above in dedup can create. Since they're dead, we
can now safely just skip them.
2025-06-25 11:06:20 -06:00
Hideto Ueno be9f58169a [circt-synth] Mark a top module for longest path analysis
This is a follow up for longest path analysis to use a custom top module.
2025-06-24 18:16:59 -07:00
John Demme 71011a70a4
[Kanagawa] Replace CSE with specialized pass (#8599)
Running CSE on a whole design is neither necessary nor advisable. It forces all the dialects used to support CSE but at least one (which we use) has issues with it. So we add a PR which targets redundant operations in the `kanagawa` dialect which passes assume to be non-redundant.

Also updates `kanagawatool` to add new passes which are now necessary.
2025-06-24 18:09:44 -07:00
Hideto Ueno 55c3fefb8c [CI] Keep at laest one cache for main in GC CI
This commit fixes an issue that caches in main are removed by GC CI
2025-06-24 14:28:58 -07:00
Hideto Ueno ec988bbafb
[CI] Only use ccache for Release builds in nightly integration tests (#8581)
This patch modifies the nightly integration tests workflow to only use
ccache when the build type is Release. This helps optimize CI resources
by avoiding unnecessary caching for debug builds, which have shown cache
hit rates of less than 0.5%. By focusing caching efforts on Release builds,
we can improve overall CI efficiency and reduce storage requirements.
2025-06-24 14:23:19 -07:00
Mike Urbach 0ab5e06471
Bump LLVM to 945ce1aa3d29e24c49720ae9e0bcfbac88f2defd. (#8589)
Update CondBranchOp builders that now require branch weights.

This is required since https://github.com/llvm/llvm-project/commit/70343c8.

Update SymbolCache to store a unique_ptr to SymbolTableCollection.

This is required since https://github.com/llvm/llvm-project/commit/b4ded99.
2025-06-24 13:05:20 -06:00
Fabian Schuiki 765e75d40c [FIRRTL] Fix structure binding capture in lambda
Clang 14 on my macOS machine complains about the `definition` and
`declaration` local bindings being captured by the `allAttrsMatch`
lambda. Looks like this is technically illegal, but gcc and some later
flavors of clang accept this.
2025-06-24 09:49:59 -07:00
Fabian Schuiki e4077164ad
[LLHD] Update function call inlining pass; add to circt-verilog (#8597)
Update the LLHD pass intended to inline all function calls.

This commit renames the pass from "FunctionElimination" to
"InlineCalls", since the updated pass no longer deletes the functions.
Instead, MLIR's SymbolDCE pass should be used after call inlining to get
rid of any unused function definitions.

The pass logic is also adjusted to support nested function calls. This
allows deeply nested call graphs to be completely inlined, which is a
prerequisite for many synthesis-related passes that may follow in the
pipeline. A stack of called functions is used to track function nesting
and prevent recursive calls from infinitely expanding.

As before, the pass produces an error diagnostic for any call op nested
within an HW module that cannot be inlined.

This commit also adds the call inlining pass to the circt-verilog
pipeline, alongside an additional SymbolDCE run to clean up the unused
functions afterwards.

Co-authored-by: Martin Erhart <martin.erhart@sifive.com>
2025-06-24 08:40:41 -07:00
unlsycn 5dc56952a8
[firld] Add firld to link FIRRTL circuits (#8561) 2025-06-24 12:44:54 +08:00
Hideto Ueno 6227f4aec0 [AIG][LongestPathAnalysis] Tweak the cost model of unary and-inverter
This changes the cost model to align with ABC
2025-06-23 19:56:38 -07:00
Schuyler Eldridge d87163d9d1
[FIRRTL] Fix alignment in test, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-23 22:09:05 -04:00
Hideto Ueno fa96ffe4d7
[AIG] Add AIGER runner passes for external logic solver integration (#8592)
This commit introduces a new infrastructure for running external logic
synthesis tools (ABC, Yosys, etc.) on AIG modules through AIGER format
export/import.

The implementation provides two new passes, AIGERRunner and ABCRunner, that
export modules to AIGER format, run external solvers, and import optimized
results back to MLIR. The system includes sophisticated multi-bit value
handling with automatic decomposition during export and reconstruction during
import. The pass integrates seamlessly with the circt-synth tool to support
ABC optimization commands.

The core Converter class tracks bit-level mappings between MLIR and AIGER
representations, enabling accurate reconstruction of multi-bit values after
optimization. String placeholder replacement provides flexible solver command
configuration, supporting various external tools with different command-line
interfaces.

For testing purpose yosys-abc is mainly used
2025-06-23 15:16:59 -07:00
Hideto Ueno 0aeff6271b
[AIG] Refactor longest path analysis to enable caching and improve modularity (#8593)
- Add LongestPathAnalysisWithTrace wrapper class to enable analysis manager
  caching by default enabling trace functionality
- Move PrintLongestPathAnalysisPass implementation to separate file
  (PrintLongestPathAnalysis.cpp) for better separation of concerns
- Update pass to use cached analysis results via getAnalysis<> instead of
  creating new analysis instances
2025-06-23 03:17:07 -07:00
Fabian Schuiki 9db653d65f
[LLHD] Embed procedural ops within modules into llhd.combinational ops (#8590)
Add the WrapProceduralOps pass that takes operations such as `func.call`
or `scf.if` in HW module body and wraps them inside `llhd.combinational`
ops. This allows those operations to be inlined or lowered to the CF
dialect since the `llhd.combinational` op provides an SSACFG region.

Add the pass to the circt-verilog pipeline, alongside a lowering from
SCF to CF. This makes the core dialect output of circt-verilog more
regular, and will allow us to fully inline function calls and fully
unroll loops in the future.
2025-06-22 22:30:13 -07:00
Hideto Ueno b838281b23
[AIG][AIGER] Add AIGER Exporter (#8582)
This commit implements a comprehensive AIGER (And-Inverter Graph) export
functionality for CIRCT, supporting both ASCII (.aag) and binary (.aig)
formats as specified in the AIGER format specification.

The implementation provides complete AIGER export with proper literal 
assignment and encoding for both ASCII and binary AIGER formats using 
LEB128 encoding. Multi-bit values are automatically flattened to individual 
bits to comply with AIGER's single-bit nature. The exporter handles AIG 
operations including and_inv for AND gates and inverters, sequential 
elements through seq.compreg for latches, and combinational operations 
such as comb.concat, comb.extract, and comb.replicate. Constant propagation 
is supported for hw.constant operations, and symbol tables are generated 
with proper bit indexing.

The design includes an extensible handler interface for custom export 
behavior (which is currently not used but will be utilized in a future PR
for the AIGER runner pass) and performs topological sorting to ensure
proper AIGER ordering  constraints. The implementation uses equivalence 
classes for efficient  bit-level value tracking and proper delta encoding for 
binary format AND  gates.
 
This enables CIRCT to export AIG dialect operations to standard
AIGER format for use with external verification and synthesis tools.
2025-06-22 19:21:55 -07:00
Hideto Ueno 09a701bb65
[AIG][ImportAIGER] Fix incorrect tokenization and simplify parser (#8588)
- Fix lexer tokenization by removing premature whitespace skipping
- Add location-aware error reporting with SMLoc tracking throughout parser

The tokenization fix resolves issues where whitespace was being consumed
prematurely, causing parsing errors.
2025-06-22 16:26:41 -07:00
Fabian Schuiki 5abe8c7195
[LLHD] Hoist signals out of llhd.combinational ops
Extend the HoistSignals pass to also run on `llhd.combinational` ops.
This only covers probes for now, similar to how the pass handles
`scf.if` operations.
2025-06-20 16:07:25 -07:00
Fabian Schuiki b5eaffe321
[LLHD] Run mem2reg on llhd.combinational ops
Extend the Mem2Reg pass to also process `llhd.combinational` ops.
2025-06-20 16:07:25 -07:00
Annu Singh e21b0d41b6
[ImportVerilog] Support packed structs in `inside` operator (#8545)
Fixes #8440.
2025-06-20 10:07:08 -07:00
Schuyler Eldridge de46d1dd08
[circt-verilog] Disable registers.sv valgrind test
Don't check Valgrind in a test that is expected to fail due to Slang v3
issues.

Fixes #8587

Co-authored-by: Fabian Schuiki <fabian@schuiki.ch>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-06-19 16:32:25 -04:00
Bea Healy f4995a322c
[Arc] Don't sink ops with nested writes in MergeIfs (#8584) 2025-06-19 18:43:31 +01:00
Tobias Wölfel b6b1ced097
[ImportVerilog] Add support for concurrent assertions (#8559)
Initial setup for handling SystemVerilog Assertions by adding
AssertionExpr class and integrating LTL dialect. This enables the
foundation for converting SVA expressions to LTL.

Handle concurrent assertion statements by inserting Verif operations
assert and assume operations.
Use `AssertionExpr` to parse the expression.

Add a helper function to convert values to MLIR i1 type for LTL operations.
The function validates that moore::IntType inputs are 1-bit wide and creates
a ConversionOp to handle the conversion from SystemVerilog logic types.

SystemVerilog assertions evaluate expressions to Boolean values where only
'true' results in true, with 'unknown' and 'high impedance' values both
evaluating to false.

This conversion is needed for LTL operations, which only work with i1
types.

Add support for simple assertion expressions. Simple assertions consist 
of an expression, handled by 'Expression.h', and an optional repetition.
Add conversion of the expression type to i1, which is the required input
value of LTL operations.

Add additional timing visitor to add LTL clock operation.
2025-06-19 09:54:21 -07:00
Fabian Schuiki 71dda6038f
[circt-verilog] Add updated LLHD passes to the pipeline (#8579)
Enable the LLHD passes that have been updated in the past few months in
circt-verilog's pass pipeline. This contains revised versions of the
Mem2Reg, Deseq, and LowerProcesses passes, alongside a new HoistSignals
pass and the CombineDrives pass factored out of Sig2Reg.

This also disables the SROA pass on LLHD, moving it to only operate on
Moore modules. @maerhart has been looking into fixing an upstream bug in
SROA when it's used on operations in graph regions. Until that is fixed,
we can just skip SROA on HW modules for now.

Also add an end-to-end test for circt-verilog to ensure that the basic
forms of registers get detected and lowered properly.
2025-06-18 21:27:34 -07:00
Bea Healy afc83f5a1c
[Arcilator] Don't try to run JIT if only part of the pipeline is run (#8575) 2025-06-18 10:14:24 +01:00
Bea Healy f995420835
[circt-bmc] Add feature to ignore asserts on some initial cycles (#8573) 2025-06-18 09:52:27 +01:00
John Demme c04dbe6ab2 [Comb] Remove superious include in IntRangeOptimizations
Was causing problems when trying to compile the CIRCTCombTransforms
target individually.
2025-06-18 04:00:31 +00:00