Commit Graph

291 Commits

Author SHA1 Message Date
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
Jacques Pienaar 7f1c3399e4
Update to new builder format. (#8785)
Basically did

set(CMAKE_CXX_CLANG_TIDY local/clang-tidy -checks=-*,llvm-use-new-mlir-op-builder -fix)

and then fixed cases where temporary OpBuilders were used (as passed in
by reference now).
2025-07-26 04:55:06 -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
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
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
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
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
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
Martin Erhart 56625bf811
[RTG] Add Randomization Pipeline (#8675) 2025-07-10 14:14:24 +01: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
Hideto Ueno 4bb54cdf9d
[AIG][CAPI] Add C API for LongestPathAnalysis (#8652)
This commit introduces C API bindings for AIG LongestPathAnalysis and LongestPathCollection, enabling longest path analysis of AIG circuits from C and other languages.

The API uses JSON serialization for path data exchange, providing a stable interface while the underlying data structures evolve. Paths are automatically sorted by delay in descending order for efficient critical path analysis.
2025-07-04 19:28:56 -07:00
Schuyler Eldridge c4ce58c90c
[HW] Remove defensive, unnecessary default
Remove some defensive coding that added a default case to a fully covered
switch statement.  This is a compile time warning if not removed.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-07-03 14:36:37 -04:00
Hideto Ueno 8fbefed670
[Python] Add Python bindings for AIG dialect (#8646)
This commit adds comprehensive Python bindings for the AIG (And-Inverter Graph) dialect.

The implementation includes an AIG C API header with dialect registration and an AIG C API implementation with pass registration.
It adds an AIG Python dialect TableGen file and Python dialect module. The AIG Python module C++ bindings are implemented using nanobind.

The implementation follows the pattern used by other CIRCT dialects
and enables Python users to work with AIG operations like and_inv through the
circt.dialects.aig module.
2025-07-03 09:04:50 -07:00
Martin Erhart ae167116fa
[RTG] Add CAPI and python bindings to register passes (#8632) 2025-07-01 13:30:29 +01: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
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
Hideto Ueno 5dc12802ef
[OM][Python] Support string and list as evaluator arguments (#8556)
Add support for passing Python strings and lists directly as arguments to
the OM evaluator's instantiate method:

* Fix Attribute value creation to work well with list evaluation.
* Add StringType C API to construct typed strings in Python bindings
* Implement conversion between Python lists and OM ListAttr
2025-06-12 16:38:13 -07:00
Martin Erhart 641708ecc6
[RTG] Add MemoryAllocation pass to pipeline (#8397) 2025-06-06 19:04:20 +02:00
Asuna 31aeba1846
[HW][CAPI] Add a function for getting port info from module (#8491) 2025-05-31 16:34:43 +08:00
Martin Erhart 38aac96d30
[RTG] Add any_context attribute (#8373) 2025-05-14 11:13:42 +01:00
Martin Erhart 3c9922be92
[RTG] Add memory type and operations (#8368) 2025-05-14 11:07:03 +01:00
Martin Erhart 391ee7d4e9
[RTG] Add MemoryBlock type and decl op (#8356) 2025-05-13 10:30:23 +01:00
Schuyler Eldridge 5cffc8537b
[firrtl] Move LowerLayers after LowerXMR (#8405)
Move the `LowerLayers` pass after the `LowerXMR` pass.  To do this, all
passes at the end of the CHIRRTL to Low FIRRTL pipeline are moved after
`LowerXMR`.  This is necessary because the `LowerLayers` pass cannot, at
present, be moved after the passes at the end of the pipeline.

This is done to enable forcing out of layers.  By lowering probes to XMRs,
the layers can be lowered trivially to modules/instances and their XMRs
will now (seemingly) magically just work.  By doing the loweirng in this
way, it avoids ever having to represent an input probe in the FIRRTL
dialect.

A consequence of this is that there are now simplifying
assumptions (preconditions) that can be made about the `LowerLayers` pass:

1. It will never see a number of probe ops because the `LowerXMR` pass has
   a postcondition that all of these are removed.

2. Input and output ports can never be created on modules created from
   layer blocks.

While I am generally always in favor of passes being relocatable anywhere
in the pipeline, this is one pass that really does _not_ make sense to be
relocatable.  In effect, this pass is part of the lowering from FIRRTL to
HW.  There is no point in being able to use it earlier in the pipeline.
That said, it still is tested to work with things which we may one-day
preserve, like `WhenOp`s.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2025-04-24 11:02:55 -04:00
Maksim Levental d07c799f60
[LLVM] bump to 9deb08a and integrate upstream SMT C APIs (#8424) 2025-04-17 15:26:22 -04:00
Martin Erhart 89420182cd
[RTG] Add array type (#8359) 2025-04-15 11:39:28 +02:00
Maksim Levental 7ea40140a1
[LLVM] integrate upstream SMT (#8408) 2025-04-14 14:34:14 -04:00
Martin Erhart 908e29e58a
[RTGTest] Switch to new immediate types (#8315) 2025-04-01 10:12:31 +01:00
Martin Erhart 1db8b4dec7
[RTG] Add immediate type and attribute (#8314)
This adds an immediate type and attribute that support any bitwidth and will replace the immediate types and attributes in the RTGTest dialect. Also adds a constant operation that can create an SSA value for any typed attribute. I also moved the labels type to form a kind of ISA subdialect with the immediates and made that explicit in the textual IR. We can do the same for relevant ops in the future.
2025-04-01 09:53:51 +01:00
Mike Urbach 5019720715
[Python] Add binding for OutputFileAttr filename. (#8337)
We already have a binding for the OutputFileAttr, but it didn't
provide any useful accessor. This adds a safe, typed accessor to read
out the filename as a string.
2025-03-21 15:00:22 -06:00
unlsycn d46f0bb29d
[OM] Add missing CAPI omTypeIsAMapType (#8321)
Signed-off-by: unlsycn <unlsycn@unlsycn.com>
2025-03-18 14:35:24 -06:00
Clo91eaf 17fb5b522f [SMT][CAPI] Add more SMT C API
Signed-off-by: Clo91eaf <Clo91eaf@qq.com>
2025-02-28 08:50:19 +08:00
Clo91eaf 257426e53b [ExportSMTLIB] Implement C API
Signed-off-by: Clo91eaf <Clo91eaf@qq.com>
2025-02-22 12:25:31 +08:00
Martin Erhart 435dceeaf5
[RTG][CAPI] Expose getter for bag and set element type (#8227) 2025-02-19 13:29:33 +00:00
Martin Erhart f97a45339f
[RTG] Add on_context and context_switch operations (#8150) 2025-02-18 22:18:23 +00:00
Martin Erhart e4eb532604
[RTG] Separate operation for sequence randomization and randomized sequence type (#8147) 2025-02-04 16:35:48 +00:00
Martin Erhart e4d67daaf5
[RTG] Custom parser/printer for sequence op and type for sequence families (#8146)
Allow type parameters in the sequence type and attach it as a type attribute to the sequence op. That way ops referring to a sequence don't have to access the operation's body to verify the type.
2025-02-04 16:33:48 +00:00
Martin Erhart 5aa1cc3157
[RTGTest] Add the last remaining ops for RV32I (#8142) 2025-02-03 08:32:37 +00:00
Martin Erhart deb88ba5ec
[RTGTest] Add integer register type API (#8141) 2025-02-03 07:59:22 +00:00
Martin Erhart 518f3a1906
[RTG] Add label visibility API (#8140) 2025-02-03 07:58:45 +00:00
Martin Erhart 82dcb9f36b
[RTG] Populate pipeline with new passes (#8139)
Add the new passes to the pipeline and pass their options through to the frontend
2025-02-03 07:56:45 +00:00
Martin Erhart bbe57d8014
[RTGTest] Add branch instructions (#8105) 2025-01-31 19:11:28 +00:00
Martin Erhart a4fa04d143
[RTGTest] Add representation for immediates (#8053) 2025-01-31 09:57:17 +00:00
Martin Erhart 0bf7f7d841
[RTGTest] Improved register representation (#8052) 2025-01-24 13:47:34 +00:00
Martin Erhart e075079fc2
[RTG] Add context resource attribute interface (#8034) 2025-01-16 20:47:49 +00:00
Maksim Levental ca92024004
[CAPI] disambiguate mlirRegisterConversionPasses (#8072) 2025-01-13 16:40:28 -05:00
Maksim Levental baea6c20c8
[SMT][python] enable python bindings (#8071) 2025-01-13 08:59:35 -05:00
Jiuyang Liu fab24cbd8a [FIRRTL][CAPI] add LayerConvention Enum and Attr 2025-01-13 12:27:43 +08:00
John Demme 405b6b873f
[PyCDE] Improving support for Any type (#8044)
- Adds a `castable` method to Type which passes through to the
`checkInnerTypeMatch` C++ function.
- Use that method to type check the results of BundleSignal.unpack.
2025-01-08 15:29:11 -08:00
John Demme bcc1e01cdb [DC CAPI][PyCDE] Add cmerge and demux handshake ops
- Adds cmerge and demux functions to the handshake pycde module.
- Lowering them requires fixes to the conversion pass and the CAPI code.
2024-12-19 01:21:14 +00:00