Commit Graph

291 Commits

Author SHA1 Message Date
Mike Urbach 1cc1069969
[OM] Add C API and Python bindings for IntegerAttr to string. (#6787)
Both the upstream MLIR IntegerAttr and OM IntegerAttr are backed by an
arbitrary precision integer. However, the upstream Python bindings
don't have any mechanism to return an integer larger than 64 bits back
to Python, even though Python ints are also arbitrary precision
integers.

To support this, we can handle this where we explicitly convert OM
IntegerAttrs to Python values. The simplest thing is to print a string
representation of the arbitrary precision integer, and parse that to a
Python int. This adds the necessary C API and Python binding for a "to
string" method, and uses it in the attribute_to_var function.

There are smarter ways we can handle the conversion, but the "to
string" API seems generally useful, so I'm using that in the
conversion for now.
2024-03-07 18:46:37 -07:00
Mike Urbach 675716b168
[OM] Add C API and Python bindings for EvaluatorValue::Reference. (#6785)
In some OM dialect constructs, it is possible to receive
EvaluatorValue::Reference values. In the Python bindings, where we are
converting an EvaluatorValue to a Python value, we need to dereference
the Reference, to get at the underlying EvaluatorValue that was set
during evaluation.

This adds the necessary C APIs, and updates the Python bindings to use
them. If we encounter a Reference, we dereference it and recursively
call the converter function.

A Python test was added using an example IR from the Evaluator unit
tests, which delays evaluation and introduces references.
2024-03-05 15:49:35 -07:00
Schuyler Eldridge 077826e06c
[capi][python] Add Emit Dialect
Add the emit dialect to the C-API and to Python.  This is both missing and
is necessary for downstream Python tooling to not break.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-03-02 17:14:23 -05:00
Asuna d010dd4423 [FIRRTL] Make function `importAnnotationsFromJSONRaw` public 2024-02-24 02:32:24 +08:00
Asuna dd0f4905aa [FIRRTL][CAPI] Add function for importing annotations 2024-02-24 02:32:24 +08:00
Mike Urbach 69b456df34 [CAPI] Try again to fix dependency leading to Python wheel failures.
The previous fix in https://github.com/llvm/circt/pull/6572 did not
get to the root of the issue. In fact, it didn't even work around the
issue correctly, because the added DEPENDS was on the wrong
target. This attempts to remedy that by changing the DEPENDS to the
actual target that was missing before.

The real issue to this problem is in the CFToHandshake.h header, and
tracked here: https://github.com/llvm/circt/issues/6693.
2024-02-13 23:05:49 -07:00
John Demme 5cdff6351f [Python] Register the comb dialect lowerings 2024-01-31 21:20:11 +00:00
Asuna 9ce35f8839 [HW][CAPI] Add instance graph C-API for iterating modules 2024-01-31 06:47:51 +08:00
Sprite 7b7134c4fd [FIRRTL][CAPI] Expose `foldFlow` function 2024-01-18 08:35:52 +08:00
Mike Urbach f02e5ea64c
[FSM] Add CAPI dependency on conversion pass header generation. (#6572)
When the conversion from FSM to SV was added to the CAPI, an include
of the circt/Conversion/Passes.h header was included for the pass
registration function. But nothing guarantees the generated header
that is included by Passes.h actually exists.

We have seen intermittent failures from it not existing, for example:
https://github.com/llvm/circt/actions/runs/7474242994/job/20339994666

This adds a DEPENDS on the target that generates the missing header,
so it will be available.
2024-01-11 12:06:53 -07:00
Nandor Licker cc8fabb16d
[Sim] Initial implementation of the `sim` dialect (#6561) 2024-01-10 18:02:39 +02:00
Amelia 3707c382fb
[HW to BTOR2] btor2 conversion pass (#6378)
* Added missing tool in integration test

* Fixed formatting

* Fixed whitespace issue

* Fixed typo in VerilogGeneration.md

* Added skeleton for btor2 lowering pass

* added pattern match skeleton to lowering pass

* Added initial emission of inputs and hw::constant ops

* added constant emission

* added emission for most operations and final assertion

* Added support for muxes, assumptions and wire aliases

* Added support for inputs in btor2

* fixed bug in input generation

* added support for missing comb operations

* Changed input registration to allow for booleans

* Made input type check more robust

* WIP register state transition system generation

* Added support for registers

* refactored hardcoded string

* added names to btor2 states

* Added state initialization support

* Removed state initializer, it should be a firrtl construct and not a btor one

* Removed temporary file emission

* Added back accidentally removed btor2 string printing

* Ran clang-format

* Ran clang-format

* WIP refactored typeswitch

* refactored giant type switch

* Made all string litterals constexpr

* attempting to fix sanity check

* fixed variable name typo

* Attempting to satisfy clang-tidy

* renamed things to make clang happy

* inlined useless helper methods

* Clarified the necessity of important data structures in comments

* fixed formatting

* Changed pass into a Conversion pass

* refactored helper methods

* Checked for case where next is a port when emitted transitions

* Added newline at EOF

* Inherited visitors instead of using a big typeswitch

* Throw an error for unsupported ops and explicitly ignore the rest

* Removed unnecessary functions and refactored runOnOperation

* Fixed formatting

* Attempted to add some test

* Added in ops that weren't covered by visitors

* Added in missing declaration in header

* Included pass in CAPI CmakeLists

* Added infrastructure for btor integration tests

* Revert "Added infrastructure for btor integration tests"

This reverts commit a5ec3da4ec.

* various nitpicking comments accounted for

* used generalized ids for btor2 testcase

* fixed typo in test

* updated test and found small bug

* clang-format

* added support for arbitrary resets

* Updated test to reflect new handling of reset

* Switched to a DFS strategy for emission

* Updated test to align with preemission of register declarations

* Removed gratuitous lookups.

* inlined a bunch of string constatns

* removed certain silent fails and added out of order test
2023-12-15 20:30:07 +01:00
Will Dietz 2bc975079d [CAPI][Firtool] Don't use default in covered switches over enums.
https://llvm.org/docs/CodingStandards.html#don-t-use-default-labels-in-fully-covered-switches-over-enumerations
2023-12-07 10:26:40 -06:00
Sprite d6b83cc174 [FIRRTL][CAPI] Build open bundle for fields containing non-base types 2023-12-07 02:46:42 +08:00
Sprite 3b7d738056 [FIRRTL][CAPI] Add the rest of setters for options 2023-11-30 16:26:55 +08:00
Fabian Schuiki 878303a1fe
[Python] Add debug dialect bindings (#6471)
Add basic Python bindings for the debug dialect.
2023-11-29 15:02:59 -08:00
Fabian Schuiki 1d7ee186c1
[NFC] Homogenize file headers in CAPI/Python bindings
Adjust the header comments in the CAPI and Python bindings files such
that they are more in-line with the rest of CIRCT.
2023-11-29 13:19:38 -08:00
John Demme 2310234eb8
[ESI][Manifest] Make service records required (#6461)
Build them before calling the generator then let the generator modify
it. Ensures that it is always present even if the generator ignores it.
2023-11-28 19:58:22 -08:00
Andrew Lenharth 12c35d96b4 [NFC] clean up a few attributes which should be symbols attributes 2023-11-28 14:21:46 -06:00
John Demme 0ca237ae7d [ESI][Python] Allow AppIDAttr to have null idx 2023-11-28 07:21:20 +00:00
Andrew Lenharth ae62ffdbc5 [CAPI] Fix broken build 2023-11-27 12:48:51 -06:00
Andrew Lenharth 57aff18faf
[FIRTOOL] Make firtool options behave like the rest of llvm. (#6435)
Move firtool pipeline configuration over to the same mechanism the rest of llvm and mlir use. Export this via the CAPI. Add a couple examples of methods to change options to the CAPI. Interested parties are encouraged to finish out the set of functions.

Since the CAPI has no tests, this breaks nothing.

As an aside, the configuration space of the firrtl pipeline is WAY too big.
2023-11-27 10:57:18 -06:00
fzi-hielscher f37fe720e6
[Firtool][CAPI] Remove dedup option (#6423) 2023-11-17 00:14:53 +01:00
Sprite e118358778 [FIRRTL][CAPI] Add functions for property types 2023-11-14 22:50:26 +08:00
fzi-hielscher b8d69d5cc0
[HW] Reference struct/union fields by index (#6266)
This PR changes the HW StructExtract, StructInject, UnionCreate and UnionExtract ops to reference their accessed field by the respective aggregate type's field index instead of the field name. This allows us to access the field's FieldInfo struct directly instead of having to traverse the array to find the matching name.
2023-11-01 22:29:22 +01:00
Mike Urbach 6e1ae3c390
[OM] Add Python bindings for path types. (#6361)
In order to use the types in Python with isinstance, etc., we need to
provide the mlir_type_subclass bindings. This adds the C API
boilerplate and binds the types.
2023-10-31 15:43:37 -06:00
John Demme 03e1d94d5c
[ESI] Rip out Cap'nProto schema generation (#6349)
This turned out to be a bad idea. We're still using Cap'nProto for Cosim, just with the message being a blob which is already encoded by the client. This is nearly identical to what happens in hardware, just Cap'nProto/DPI as the transport layer.

Goodbye old frenemy.
2023-10-26 19:58:24 -07:00
John Demme d89f7d825b
[ESI] Service requests now track AppIDs rather than instance hierarchy (#6328)
This makes for far more sensible hierarchies. Also makes the index field of AppIDs optional.
2023-10-23 14:00:08 -07:00
Andrew Young 4ec8cb388d
[OM] Add evaluator support for paths (#6320)
This change adds evaluator support for frozen paths.

Two new EvaluatorValues have been added, one for BasePaths, which
represent fragments of paths through the instance hiearchy, and one for
Paths, which represent a full path to a hardware component.

When the evaluator instantiates an OM class, it is expected that it will
usually have to pass in an empty basepath, which signifies that the
class is at the top of the hierarchy. To facilitate this, we exposed the
ability to create an empty basepath value in the python API.

Path values can be transformed in to strings, where in they are printed
as FIRRTL style target paths. In the future, we may want a richer API.
Deleted paths are represented as Path values with the targetKind
attribute nulled out, which is handled specially in the string
serializer.
2023-10-20 09:56:39 -07:00
George Lyon 55505ebcb9
firtoolPopulateCHIRRTLToLowFIRRTL doesn't need a module (#6304) 2023-10-19 12:38:03 -07:00
Andrew Young 8e4992be35
[OM] Overhaul of path operations (#6253)
This PR does an overhaul of how path related operations work in the OM dialect.

When OM classes are created from FIRRTL, a base path is now fed through the
class hieararchy.  All paths to hardware objects are now created relative to
the base path.  The `path` op has been renamed to `path_create`, and now takes
a basepath SSA parameter, which means that it is impossible to create a path
which is not relative to some base.

A second set of operations to create "frozen paths" have been added.  In
FreezePaths, we lower all path operations to hard-coded strings, which allows
us to remove the hardware from the OM IR and still be valid.  These operations
have been changed to return `FrozenPathType`, which is to make sure that people
don't try to inter-mix the two kinds of path types.  The intention is that the
evaluator will only understand frozen paths.

The PathAttr in OM no longer represents the entire target path, but just the
list of instances which lead up to it.

This also adds an OM utility for parsing FIRRTL style target strings, which is
used in the `frozenpath_create` MLIR assembly format.  The existing APIs
contained in FIRRTL were not suitable since these new strings do not include
the circuit name, and we need some restrictions for parsing base paths, which
can not target components. The new parser is a bit more resilient to badly
formed path strings. In the future it may be possible to reunite these two
bodies of code.

The existing python support for paths had to be removed.
2023-10-11 12:33:10 -07:00
Nandor Licker dadf87b742 [NFC][firtool] Fix CAPI 2023-10-11 04:24:33 -07:00
Prithayan Barua cbc8c39613
[OM] Add location info to EvaluatorValue (#6240)
Add the debug locations to the evaluator value, which will be used to generate info fields
 of the object model output json.
2023-10-10 10:06:38 -07:00
Hideto Ueno 5508c1e42a
[OM] Evaluator: Support graph regions (#6249)
This commit adds support for graph regions for evaluator.

`ReferenceValue`, a new subclass of `EvaluatorValue`, is added to behave as pointers. `ReferenceValue` can be used as alias to different values and is created for `class.object.field` operation because `class.object.field` can access fields across class hierarchies and the fields might not be initilized yet. `RefenceValue` is not exposed to outside of evaluator implemenation. `EvaluatorValue::finalize` shrinks intermidiate `RefenceValue` in the evaluator value.

Evaluation algorithm is changed to worklist-based iteration. `instantiae` method first traverses the whole IR including sub-class, and create partially evaluaed values for all values and add these values to the worklist. After that we evaluate values until there is no partially evaluaed value.

Fix https://github.com/llvm/circt/issues/5834
2023-10-06 03:24:38 +09:00
John Demme 77dfbd01c5
[ESI][Python] Expose BundleType to Python (#6248) 2023-10-03 20:55:42 -07:00
Andrew Lenharth f14cbe3b25 [NFC] LLVM bump 2023-10-03 09:24:06 -05:00
Hideto Ueno e05d172607
[OM] Implement PathAttr CAPI and Python binding (#6229)
This commit implements PathAttr CAPI and Python bindings.
2023-10-02 22:10:02 +09:00
Sprite b636edaef1 [Firtool][CAPI] Add options setters and getters 2023-09-30 21:53:23 +08:00
Sprite a01f3db3cc [Firtool][CAPI] Add C-API for Firtool lib 2023-09-30 21:53:23 +08:00
Schuyler Eldridge 48a2c30c67
[FIRRTL] latestFIRVersion -> exportFIRVersion, NFC
Change the name of the constexpr `latestFIRVersion` to `exportFIRVersion`
as this is not the "latest" version, but the version that is used when
exporting FIRRTL.  This will avoid confusion about what this is.

Make the `exportFIRVersion` the same as the `nextFIRVersion`.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-09-28 13:54:45 -04:00
Prithayan Barua 6607338e34
[OM][Bindings] Make Python Evaluator Object hashable (#6204)
Implement the proper `__hash__` and `__eq__` methods for Object, such that it
 can be used in dictionaries. This is required to ensure we use mlir object
 reference for equality and hashing, rather than the default methods provided
 by python.
 Hashable::
 "In Python, a "hashable" object is an object that has a hash value that remains
 constant throughout its lifetime and can be compared to other objects.
 User-defined classes need to implement the `__hash__()` and `__eq__()` methods
 to be hashable."
 In the OM dialect, we want there to be "reference semantics". In other words,
 two objects with identical classes and fields should not be "the same" if they
 are created from separate instances in the elaborated object graph that the
 Evaluator sees. In addition, due to presence of cyclic dependencies, value
 equivalence cannot be determined and reference semantics is required.
2023-09-27 08:35:32 -07:00
Schuyler Eldridge 993732aa1c
Remove GlobalRefOp, GlobalRefAttr
Remove the now unused global reference operations and attributes.  These
have been fully migrated to HierPathOp.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-09-22 11:11:50 -04:00
John Demme 1b901c33b8
[NFC][ESI][MSFT] Move AppIDs over to ESI (#6177)
Since AppIDs serve as system identifiers, they classify as a system
construction feature. So they should be in the ESI dialect, which will
be using them shortly.
2023-09-21 18:11:30 -07:00
John Demme 0510ad8caa [MSFT] AppIDIndex add methods for querying paths
- `getChildAppIDsOf` to inquire about all of the AppIDs contained by a
module.
- `getAppIDPathAttr` to get the path to an AppID from a moduled.
2023-09-21 02:29:20 +00:00
John Demme a9f55cab80
[MSFT] Make AppID discovery an index rather than a pass (#6152)
Discovering AppIDs used to be a pass and only worked on `msft.module`s. Since we're removing them, make AppID discovery an API which creates dynamic instances from AppIDs. Since it'll primarily be used from PyCDE, expose to Python. Test through Python.

Will remove the discover appid pass in a subsequent PR. Progress on #6109.
2023-09-20 13:17:43 -07:00
Prithayan Barua 10da65bf1d
[OM] Python bindings for om integer (#6042)
Implement the python bindings for the `om.integer` attribute. Add support to
 create `om::IntegerAttr` from `mlir::IntegerAttr`. Also ensure all tests use
 `om::IntegerAttr` instead of `mlir::IntegerAttr`.
2023-09-19 13:41:46 -07:00
Hideto Ueno 8129d5de50
[HW][Python] Add name getters for ModuleType (#6149)
`argNames` and `resultNames` attributes were removed from HWModule (https://github.com/llvm/circt/pull/6095) in the presence of ModuleType but downstream python tools are relying these attributes for name look up. However currently there is no CAPI/Python API for ModuleType to query names of ports so this PR adds CAPI and bindings respectively in the same way to port types.
2023-09-20 00:45:01 +09:00
Nandor Licker 0fc8656168
[Seq] Switch all seq ops to use seq.clock (#6139) 2023-09-18 16:38:32 +03:00
John Demme e23e94542f [MSFT] Introduce AppIDPathAttr
Represents a full appid path. Just a list of AppIDAttrs components and a
root module. Expose to Python.
2023-09-14 22:43:49 +00:00
John Demme fec17895c8 [Python] Expose OutputFileAttr to Python 2023-09-14 02:51:41 +00:00
Mike Urbach 6f82696996 [OM] Add C and Python API to get a ClassType name.
Now that the Python bindings for ClassType can return a Python object
of the actual ClassType Python class, it would be useful to get the
ClassType's name from such an object. This includes the usual C API
boilerplate to call the accessor in C++, and the usual Python wrapper
to return a string through pybind.
2023-09-12 15:25:12 -06:00
Mike Urbach d510b5e879 [OM] Add TypeID for ClassType so automatic downcasting works.
A relatively new feature of MLIR Python bindings allows returned
MlirTypes to automatically be downcast to the actual concrete Python
class for the type. To enable this, a C API to get the type's TypeID
must be provided, and the rest just works. Opt-in for the OM dialect's
ClassType.
2023-09-12 14:57:35 -06:00
Hideto Ueno 668adc5f7a
[OM] Evaluator: Support Map (#6045)
This PR add Evaluator support for Map values. 
* EvaluatorValue now takes a MLIR context as a member to make it easy to 
   construct attributes from evaluated values. 
* MapValue is added and created from om.map_create. 
* CAPIs for MapType and StringType are added.
2023-09-12 20:32:46 +09:00
Andrew Lenharth 5ca6052d07
[HW] Convert type storage for modules over to moduletype (#6071)
Down with FunctionType, long live module type.  Next step is to remove the name arrays.
2023-09-11 17:09:26 -05:00
Hideto Ueno 1656984ebe
[Verif][LTL] Add basic python binding support (#6040)
This adds basic python binding support for verif and LTL dialects so that we can parse and analyses output MLIR file with these dialects.
2023-09-06 13:45:35 +09:00
Andrew Lenharth 4d30656e81
[NFC] rename function and move interface to a file (#6021) 2023-09-01 12:53:14 -05:00
Will Dietz 32c9a11eeb [FIRRTL][CAPI][NFC] Drop default case in covered switch, fix warning.
`llvm_unreachable()` only tells the compiler to assume that can't happen
(in release builds w/default build options), so this doesn't help anyway.

cc #3836.
2023-08-31 10:04:51 -05:00
Hideto Ueno e4f127f0fb
[OM] Evaluator: Support tuple (#5903)
This implements Evaluator implementation for tuples, CAPI and python bindings.
2023-08-31 23:30:44 +09:00
Morten Borup Petersen 7a3b9e478b
[Handshake] `StandardToHandshake` -> `CFToHandshake` (#5938)
... long awaited.
2023-08-25 09:24:26 +02:00
Rachit Nigam d35c2de896
Calyx native callout pass (#5879)
* start working on adding a calyx native callout pass

* missing entry in CMakeLists for circt-opt

* emit calyx in pass

* progress

* specify primitives lib

* it works!!

* fewer imports

* fix CMakeList

* cleaup and comments

* remove useless stringref

* better error message when `calyx` binary is missing

* header style

* remove primitives folder option and define pass-pipeline

* remove braces

* add native pass to calyx namespace

* remove empty namespace

* add dependency to CAPI

* clang-tidy
2023-08-24 09:16:54 +05:30
Nandor Licker 325d74c1a0
[OM] Add python accessors to the `om.map` attribute (#5914) 2023-08-23 08:42:50 +03:00
Nandor Licker ac141282dc
[Seq] Merge Seq-to-SV lowering passes (#5901)
The pattern rewriter can be applied alongside the FIR register lowering transforms to eliminate the need for two separate passes.
2023-08-22 22:12:11 +03:00
Robert Young eefcce8509
[FIRRTL] Clean up FIRVersion checking (#5865) 2023-08-16 21:21:33 -04:00
Hideto Ueno 11a9683301
[OM] Change evaluator value representation and evaluate ListCreateOp. (#5820)
This is a PR for new representation of Evaluator and list_create support.

`std::variant` has been used as runtime representation of Evaluator but it's difficult to use it as
data structure for more structured values such as list or map. So this PR instead introduces a base class `EvaluatorValue ` and derived classes, `AttributeValue`, `ListValue` and `ObjectValue`, as runtime representation of values.

Also terminology `ObjectValue` is changed to `EvaluatorValue` since runtime values will not be limited to Object.
Python and C bindings are changed accordingly.
2023-08-16 01:41:10 +09:00
Sprite 17947c6047 [FIRRTL][CAPI] Get latest `FIRVersion` from a new static function 2023-08-14 23:27:24 +08:00
Sprite 9728f92ce2 [FIRRTL][CAPI] Fix undefined reference for `mlirExportFIRRTL` 2023-08-14 23:27:24 +08:00
John Demme 0cd11eee40
[ESI] Remove auto-wrap functionality (#5823)
This functionality was used primarily wrap handshake modules. Now that
handshake uses ESI channels it's no longer necessary. I don't think
there are any other users.
2023-08-10 12:35:18 -07:00
Asuna 841451f07b
[FIRRTL][CAPI] Add a new function to get `ParamDeclAttr` (#5792) 2023-08-08 11:56:53 +08:00
Andrew Young de50525bfe
[HW] Add InnerSymAttr python bindings (#5711)
These binding are very shallow and only support the use case of a single
InnerSymProperties with a fieldID of 0.  Current use cases only require this
limited functionality, and in the future we will probably be changing the
underlying attributes, so it doesn't make sense to expose it all now.
2023-07-28 14:23:03 -07:00
Nandor Licker 7f9ed020e1
[OM] Add Python bindings for ListAttr (#5617) 2023-07-18 18:38:57 +03:00
Schuyler Eldridge 172afc3277
[FIRRTL] Change emitter to v3.0.0
Change the FIRRTL emitter to use v3.0.0 of the FIRRTL specification.
Logic for emitting an older version of the spec is still preserved.  There
is no option for choosing the spec version from the command line right
now.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-06-30 12:02:46 -04:00
Sprite 7d3e3325ef [FIRRTL][CAPI] Change some string types to `MlirIdentifier` 2023-06-27 14:57:28 +08:00
Sprite 7ba9907acd [FIRRTL][CHIRRTL] Make C API names more consistent with other dialects 2023-06-27 14:57:28 +08:00
Asuna 243e6c360e
[FIRRTL][CHIRRTL] Add dialect C API (#5472) 2023-06-26 23:18:44 -04:00
Nandor Licker 4f510750b4
[OM] Expose ReferenceAttr to Python (#5413)
Co-authored-by: Nandor Licker <nandorl@sifive.com>
2023-06-16 15:37:10 +03:00
Prithayan Barua 1ecd327fb0
[OM] Add API to iterate over an Object (#5402)
Add API to get the field names from an object and add a convenient iterator.
2023-06-15 08:48:12 -07:00
Sprite 1a71c4d957 [ExportFIRRTL] Implement C API 2023-06-13 23:46:35 +08:00
Mike Urbach a02644aacb
[OM] Use custom CAPI wrappers for Object. (#5275)
This adds custom CAPI wrap and unwrap functionality for Object to
better align with the std::shared_ptr functionality. Object now
enables the shared_from_this functionality, which allows the unwrap
function to more seamlessly create shared pointers to the Object with
the appropriate reference count. Similarly, the wrap functionality is
updated to always allocate new shared pointers, to ensure reference
counts are incremented appropriately. This was done at the instantiate
API previously, but is now handled generically whenever an Object is
wrapped.

These changes are required to avoid double frees of Objects in
general. A test case has been added that demonstrated the faulty
behavior, which now succeeds.
2023-05-30 10:28:20 -06:00
Mike Urbach e47550d295 [OM] Add CAPI for the ClassType of an Object.
This adds two APIs to the OM dialect, for querying if a Type is a
ClassType and for getting the ClassType from an Object. These simply
wrap the existing C++ functionality directly. A small test is added to
ensure they work as expected.
2023-05-25 15:20:01 -06:00
Mike Urbach 56861ea9d5
[OM] Add initial CAPI for OM dialect Evaluator. (#5248)
This adds the usual CAPI structure and dialect registration
boilerplate, as well as CAPIs around the Evaluator library.

The APIs are intended to be as minimal and straightforward as
possible, simply wrapping and unwrapping the C++ structures when
possible.

One slight divergence is in the ObjectValue type, which is a
std::variant between an Object shared pointer or an Attribute. The
normal approach of casting to and from a void pointer does not work
with std::variant, so a different representation of ObjectValue is
used instead. The discriminated union is simply represented as a
struct which only over has one field set. It might be possible to save
some space using a struct with a C union and a flag, but the
simplicity of the current approach seemed reasonable.

Another minor detail worth mentioning is that we must take some care
to ensure the shared pointers to Objects have their reference count
kept up to date. In the CAPI for the instantiate method, if we simply
return the shared pointer, the reference will be lost as the Object
pointer travels to C as a void pointer, so we allocate a new shared
pointer in the CAPI, which ensures the reference count accurately
reflect that we have handed out another reference.
2023-05-24 09:25:23 -06:00
Nandor Licker acadcaf9dc
LLVM Bump (#5070)
TypedAttr changed requiring adjustments to HWAttributes.
Affine was moved to its own namespace.
2023-04-25 08:43:56 -07:00
John Demme 769d598ad8
[PyCDE] Expose ESI list type (#5060)
Teach PyCDE about the ESI list type.
2023-04-19 10:22:07 -07:00
Fabian Schuiki 811f79d37a
[SV] Move emitAsComment to SVAttributeAttr; remove SVAttributesAttr (#4743)
* [SV] Move emitAsComment to SVAttributeAttr; remove SVAttributesAttr

Move the `emitAsComments` flag from `SVAttributesAttr` (plural) to
`SVAttributeAttr` (singular). Then remove `SVAttributesAttr` (plural)
since it only contains a single array field after `emitAsComments` is
gone.

Add add, remove, and read-modify-write functions to deal with SV
attributes on operations more conveniently. Also enforce deduplicated
SV attributes where easily possible. The new functions now allow for
easy addition and removal of individual SV attributes.

Adapt ExportVerilog to handle the fact that emission as comments is now
a per-attribute option. The emission code now can emit multiple
`/*...*/` and `(*...*)` groups if needed, but tries to pack as many
consecutive attributes with the same `emitAsComment` flag into one
group.

* [ExportVerilog] PP-ify SV attribute emission.

* Test pretty-printing of SV attributes on statements.

* Tweak whitespaces between SV attributes

---------

Co-authored-by: Will Dietz <will.dietz@sifive.com>
2023-03-01 14:34:54 -08:00
John Demme 493e9f0055
[PyCDE] Expose signaling and FIFO0 (#4705)
- Plumbing through signaling and adding it as an optional argument on Channel ports.
- Teach wrap/unwrap how to operate on FIFO0 signaling.
2023-02-23 11:51:13 -08:00
Will Dietz 1050a719d2
LLVM bump: move almost entirely to std::optional, fixes (#4470)
* LLVM.h: drop mlir::Optional.

It's an alias for std::optional now, just drop
instead of adding the templated using alias here as well
(which we'd have to remember to drop).

* Convert Optional -> std::optional.

Drop some unnecessary initializations, but keep them for fields for now.

Particularly:
StandardToHandshake.h: keep init for field, for omission in {} initializers.
FSMToSV: similarly keep the current initialization.
2022-12-22 18:57:38 -06:00
Jiuyang Liu ad85fa9869
Register FIRRTL to CAPI (#4404)
Add FIRRTL to CAPI for future JVM Bindings from Chisel.
2022-12-05 23:30:42 -05:00
John Demme 3f6565e38b
[Python] Register handshake passes (#4290) 2022-11-10 19:01:37 -08:00
John Demme e46ce38942 [ESI] [Services] Plumb through the service declaration op
Some service implementations may need information about the declaration.
By passing it in, they won't have to search for it.
2022-09-16 23:22:12 -07:00
Andrew Lenharth 6bc0cd7cbb [NFC] silence some release warnings 2022-09-02 10:24:40 -05:00
Andrew Young 5be1c59a14
[MSFT][CAPI] Fix library dependencies (#3741)
The CIRCTCAPIMSFT library depends on MSFTTransforms, and is currently
failing to link when creating shared libraries.
2022-08-17 11:46:30 -07:00
John Demme 4e12269350
[PyCDE] Add `Reg` and `Wire` declarations which can be assigned to (#3677)
`Wire` is intended to create backedges. `Reg` is not strictly necessary, but
it should give RTL programmers a warm and fuzzy feeling.
2022-08-08 13:14:06 -07:00
Morten Borup Petersen b078252e67
[MSFT][NFC] Split MSFT passes into separate files (#3683)
Motivation:
1. This file is nearing 2000 LOC. I personally find that having a single file per pass helps in quickly navigating to/between implementations of different passes. Bunching everything into one file makes locating things just a bit harder.
2. This is the style used in the remainder of CIRCT.
3. Uses canonical CMake structure for declaring passes.
2022-08-08 19:41:59 +02:00
Fabian Schuiki 93112d40df
Bump LLVM (#3649)
* Bump LLVM

Bump LLVM to the current top-of-tree.

This requires changing a few `Attribute`s to the new `TypedAttr`
interface, since attributes no longer carry a type by default. We rely
on this type in quite a few places in the CIRCT codebase, which required
a switch over to `TypedAttr`.

See: https://reviews.llvm.org/D130092

Co-authored-by: John Demme <john.demme@microsoft.com>
2022-08-07 09:21:55 +02:00
John Demme 47116c9dee
[ESI] Make service generators registerable in Python (#3667)
Enables writing service generators in Python. Also switches to
string-base 'impl_types' (from Attributes) since Attributes are tied to
a context whereas Passes are not. Simplifies things by not having to
create a registry for each context.
2022-08-05 13:27:25 -07:00
John Demme ea3027f298
[ESI][NFC] Rename Ops and Types to include those suffixes (#3622)
Update the ESI class names to standard naming conventions. Mechanical search and replace.
2022-07-28 11:19:01 -07:00
John Demme 6932198ea9 [ESI] Adding Python binding for `Any` type 2022-07-26 20:57:05 -07:00
Morten Borup Petersen bc4c6874fd
[HWArith] HWArith passes CAPI boilerplate (#3605) 2022-07-26 15:45:01 +02:00
Hideto Ueno b356227991
[SV, Python, ExportVerilog] Create SVAttributesAttr and `emitAsComments` flag (#3509)
This PR adds a `emitAsComments` field to SV attributes.
Unfortunately, some of vendor specific pragmas are not strictly 
valid SV attributes. For example, (* cadence map_to_mux *) is not valid 
SV attribute hence vendor compilers recognize comments as some sort of
attributes. From that reason, this commit provides fine-grained control of 
emission style to users. 

```
%0 = sv.wire {sv.attributes = #sv.attributes<[#sv.attribute<"foo bar">], emitAsComments>} : i1
```
should be emitted as
```
/* foo bar */
wire GEN;
```
2022-07-25 16:33:20 +09:00
Morten Borup Petersen d904317dd1
[HWArith, CAPI] Add CAPI boilerplate for HWArith (#3550) 2022-07-18 15:19:08 +02:00
Morten Borup Petersen 5e9a0b4048 [PyCDE] Also run convert-fsm-to-sv in passes 2022-07-18 10:24:55 +02:00
John Demme aa5c574d2a
[MSFT] Make `PassCommon` public (#3493)
`PassCommon` contains `getAndSortModules`, which is generally useful. Make it general by implementing `HWModuleLike` and `HWInstanceLike` and targeting those OpInterfaces instead. Involves a bit of ugliness when converting to/from the OpInterfaces to concrete module ops, but hopefully that'll go away as we add more functionality to said OpInterfaces.
2022-07-08 15:53:26 -07:00
Morten Borup Petersen 44712fb117
[HW][CAPI] Support ParamDeclRefAttr and hw::IntType in CAPI (#3302) 2022-07-02 08:22:17 +02:00
John Demme cad8cd5be7
[MSFT] AppID attribute (#3425)
An 'AppID' is intended to make browsing the instance hierarchy easier.
Instead of having to reason about instance names, users can specify an
'AppID' consisting of a (name, index) pair and browse the hierarchy that
way. Said browsing also looks through the instance hierarchy (with
several rules about transparency) to mask implementation details at
various levels of the hierarchy.

This commit adds an `AppID` attribute and exposes it through Python.
2022-06-27 15:05:32 -07:00
Morten Borup Petersen d66cbfe9ea
[PyCDE,CAPI] Add support for the FSM dialect (#3400)
This is an initial commit for adding a CAPI for FSM as well as PyCDE support for constructing these.

See `test_fsm.py` for usage.

FSMs are constructed in a similar manner to PyCDE modules through a decorator on a class describing the FSM.
The FSM class may contain inputs (no outputs for now) and must provide
- A dictionary containing the states and their transitions
- A default state

State transitions may be either always taken, or taken based on some guard. This guard is defined by a function provided to the transition, which (like `@generator` functions) acts on the ports of the FSM.

The FSM will then be constructed with an output for each state, asserted when that state is active.

One important implementation note is the fact that the `fsm.machine` operation is treated as a PyCDE Module - there was surprisingly little friction slotting it into the current code and everything works as expected wrt. referencing `fsm.machine` in/out arguments through the transition guard functions.
However, modules instantiating the FSM expect a hardware-like interface, this being the ports of the `fsm.machine` operation + clock and reset signals. An `fsm.machine` op does not have these signals at the top level, since these are added during hardware lowering. To me, this is a sensible design choice, seeing that the FSM dialect should be applicable to both software and hardware representations (...eventually).

To get around this, the user will specify the intended name of the `clock` and optional `reset` signal of an FSM. A wrapper module is then created that provides the correct interface to the instantiating module, as well as instantiating the FSM through a `fsm.hw_instance` operation, doing the proper hoop-jumping to attach the clock signal (see `fsm_wrapper_class`).

There's still some work to do on the CIRCT side of the FSM dialect to clean it up a bit + make it a viable target for a front-end, but this commit represents the brunt of work on the PyCDE side.
2022-06-27 16:14:38 +02:00
John Demme c39757fc81
[Python] Add support for SV attributes (#3349)
Lots of boilerplate which should _really_ be autogenerated. Added support for SystemVerilog attributes to the python bindings for the SV and Seq dialects.
2022-06-14 16:08:42 -07:00
John Demme 6349f22583
[PyCDE] [Python] Teach `LocationVector` bindings about 'None' for optional locations (#3165)
Use `None` to indicate that the location is not specified to/from Python. Also updates `PlacementDB` to deal with empty locations.
2022-05-23 15:07:48 -07:00
John Demme e65aba5117
[MSFT] [Python] Expose LocationVector to Python (#3163)
Add support for LocationVectorAttr to PlacementDB. Tests in subsequent
PRs.
2022-05-20 20:20:56 -07:00
John Demme 41bc38e35a
[MSFT] Teach PlacementDB about LocationVectors (#3162)
Add support for LocationVectorAttr to PlacementDB. Tests in subsequent
PRs.
2022-05-20 20:12:45 -07:00
Nandor Licker 72838a205c
[Seq] Moved pass definition to a separate header (#3143)
Moved the definiton of `Seq` passes to a separate `SeqPasses.h`, similarly to other dialects.
Exposed the `createSeqLowerToSV` function to be used by other clients.
2022-05-19 10:42:27 +03:00
John Demme 86c98bc864 [Python] [HW] Add name and module accessors to InnerRefAttr 2022-04-30 01:59:54 -07:00
John Demme bbd571b9f1 [PyCDE] Cleanups enabled by new MLIR features
MLIR upstream added:
- Default MlirLocations
- C API and Python functions to move blocks
2022-04-15 19:45:49 -07:00
John Demme c270a5af34
[PyCDE] Infer the result type of a SystolicArray PE (#2844)
To simplify the ownership model, MLIR core python bindings don't support
building a block before the operation. So we build a dummy operation
first, build the block, construct the array, move the block, then delete
the dummy op. The core MLIR C API doesn't have a region editing API, so
we need to add a specialized one in the MSFT C API.
2022-04-04 17:56:46 -07:00
John Demme 1722fde995 [MSFT] Removing unused 'getInstance' calls
This was used to refer to dynamic instances, but this was replaced by
the DynamicInstanceOp paradigm.
2022-04-01 13:41:45 -07:00
Martin Erhart 927629810c
[Moore] Add types to C API (#2827)
A first step to have proper support of the Moore types in the C API. This focusses on the functions to create types and some SBV type functions needed to support the already existing moore operations in the external moore frontend compiler.
2022-03-31 12:33:52 +02:00
John Demme 1041dfdab4
[MSFT] [PyCDE] Make placement DB global rather than rooted (#2804)
Since we are generating only pieces of a design (and FPGA resources are
obviously a property of the entire design), the devdb should be
independent of the 'top' module.

Also, since the devdb is supposed to act as an 'alternative view' of the
IR, load the IR's placements by default.
2022-03-25 16:35:01 -07:00
Fabian Schuiki 246d4fdd34
Bump LLVM to 61814586 (#2758) 2022-03-14 14:13:45 +01:00
John Demme 050063d299
[PyCDE] Implement new DynamicInstance operation methodology (#2683) 2022-02-28 13:30:35 -07:00
Fabian Schuiki 312184bd28 [CAPI] Add moore dialect C API
Add the boilerplate code to have the Moore dialect exposed through the
C API.
2022-02-27 09:06:00 +01:00
Andrew Lenharth 2755c0630c [NFC] Move SymCache to its own header 2022-02-24 16:23:32 -06:00
John Demme e2c7151935
[MSFT] [PlacementDB] Refactor around new dynamic instance op (#2637)
- Use the new dynamic instance op and its children to simplify the PlacementDB.
- Switch to new paradigm wherein all placements are done through the device db and get reflected in the IR. So for the life of PlacementDB, it "owns" all the placements.
2022-02-18 21:09:10 -08:00
John Demme 361abefdba
[MSFT] Move physical region to op and rename ops (#2629)
- Rename "PhysicalRegionOp" to "DeclPhysicalRegionOp" to be more
  descriptive of what it does.
- Rename "PhysLocationOp" to be more consistent with asm name.
- Add "PDPhysRegionOp" to eliminate random attribute from globalRef.
- Ditch old ref attribute since it's no longer necessary.
2022-02-14 22:56:24 -08:00
John Demme 0b1c0b15fd
[MSFT] Create PhysLocation operation and use it instead of an attribute on GlobalRef (#2620)
Keep the PhysLocation attribute for the actual physical location. Create
an op to refer to a global ref with the location attribute and the
subpath. Incremental change towards a new approach to dynamic instances.

This PR breaks tcl placement output in the way the integration test and pycde
enters the placements. Will be fixed shortly with the dynamic instance PR.
2022-02-13 15:03:58 -08:00
John Demme 4e79c88a39
[MSFT] [PyCDE] Register the canonicalizer pass (#2594)
Register the canonicalizer pass and add `cleanup` call in PyCDE.
2022-02-07 11:17:55 -08:00
mikeurbach f1f24e6300
[MSFT] Add PlacementDB APIs for removing and moving entities. (#2534)
These complement the main add* APIs for putting entities into the
database and support moving entities around or removing entities
entirely after any initial placements.
2022-01-28 17:31:26 -07:00
mikeurbach 0a0e15c8e6
[MSFT] Add walk order option when walking placements. (#2475)
This allows the user to specify a walk order through the placements'
columns and rows. If specified, the order is used to sort the indices
into the placements' maps. Else, the order is undefined as before.
2022-01-20 15:12:31 -07:00
mikeurbach c9c50d2889
[MSFT] Add optional sub-path to PhysLocationAttr. (#2421)
Previously, a sub-path could be specified by encoding it in the name
of the attribute using a certain scheme. This is brittle and
non-standard. To make this more natural and robust, the sub-path is
added as a field of the attribute definition as a StringRef. It is not
required, in which case an empty StringRef can be used. The attribute
name for placement attributes is no longer used in any logic.
2022-01-05 18:39:54 -07:00
Mike Urbach 13948d32d8 [MSFT] Remove SwitchInstanceAttr and RootedInstancePathAttr.
These attributes and their use cases are now replaced by
hw::GlobalRefOp and hw::InnerRefAttr, respectively.
2021-12-27 13:52:14 -07:00
Mike Urbach a2a058b70e [MSFT] Refactor placement export to use hw::GlobalRefs.
This refactors ExportQuartusTcl to use the hw::GlobalRefs and arrays
of hw::InnerRefAttrs directly. This greatly simplifies the
implementation, and removes the need for SwitchInstanceAttr. That
attribute will be fully removed in a follow up.
2021-12-27 13:51:57 -07:00
Mike Urbach 6d7e0e9118 [HW] Add Python bindings for GlobalRefAttr.
This adds the necessary CAPI boilerplate and a basic Python type for
holding GlobalRefAttr.
2021-12-27 11:32:05 -07:00
Mike Urbach 9f7a01a865 [HW] Add Python bindings for InnerRefAttr.
This adds the necessary CAPI boilerplate and a basic Python type for
holding InnerRefAttr.
2021-12-27 11:32:05 -07:00
Hideto Ueno 6c5e0ce771
[HW] Use StringAttr instead of StringRef in FieldInfo, nfc (#2325)
* [HW] Use StringAttr instead of StringRef in FieldInfo, nfc

This commit changes to use use StringAttr instead of StringRef
in FieldInfo to avoid unnecessary copies of field names.
Changes are mainly about parser/printer and CAPI.
This commit also changes Struct/UnionTypeImpl to use ArrayRefParameter
instead of ArrayRefOfSelfAllocationParameter in their tablegen
definition. And this deletes unnecessary allocators too.
2021-12-12 15:52:52 +09:00
Fabian Schuiki 58279f46dc
[LLHD] Add time attribute C API
Extend the LLHD C API to allow for `TimeAttr` to be created and
inspected.
2021-11-21 13:11:47 +01:00
Fabian Schuiki 36c2d395d2
[LLHD] Add type C API
Add a few functions to LLHD's C API to interact with the LLHD dialect
types.
2021-11-21 13:11:47 +01:00
mikeurbach bd05d96c11
[PyCDE] Add entry method for PhysicalRegions and their references. (#2174)
This add the necessary Python binding boilerplate to create
PhysicalBounds and PhysicalRegionRef attributes. A new API is added to
System, which inserts a PhysicalRegion. A wrapper class for
PhysicalRegion allows creating a region, adding bounds, and getting a
reference attribute suitable for use with the add_attribute API.
2021-11-15 10:02:34 -08:00
mikeurbach a002a849b3
[MSFT] Re-work ExportQuartusTcl to export into verbatim nodes. (#2077)
This is the preferred way to output design collatoral. Closes
https://github.com/llvm/circt/issues/2068.

The ExportQuartusTcl pass is removed, and the functionality is moved
into LowerMSFTToHW. The pass now populates a SymbolCache of the things
we care about in the export, namely instances. It produces verbatim
ops containing the Tcl, which can then be emitted from ExportVerilog.

The old Python API to run the export is removed in favor of the new
approach. PyCDE now exports both System Verilog and Tcl using the
exportSplitVerilog API to output files into a directory.
2021-11-09 19:25:16 -07:00
Mike Urbach 0d864829da [Python] Expose exportSplitVerilog API to Python.
This just needed to be plumbed through the CAPI.
2021-11-09 13:28:54 -07:00
mikeurbach e43d978a56
[MSFT] Move ExportQuartusTcl from a translation to a pass. (#2075)
This keeps the existing functionality based on attributes, and exports
to llvm::outs as part of the pass, in order to keep the existing
tests. Further changes based on the approach in #2068 will follow.
2021-11-03 21:31:21 -06:00
mikeurbach c5bda61046
[Python] Add bindings for hw::ParamVerbatimAttr. (#2051)
This just needs to be plumbed up to Python.
2021-10-28 17:57:44 -06:00
Mike Urbach 8be26b7c9b [Python] Fix bindings after upstream changes to aggregate building.
With the new CMake functionality upstream, we need to set the
ENABLE_AGGREGATION option when we call add_mlir_library. The easiest
way to do this is to just rely on the upstream helper
add_mlir_public_c_api_library, which does this and other important
settings for us.

Also, ensure the MSFT dialect's CAPI marks all of the public functions
as being exported.
2021-10-20 16:51:26 -07:00
John Demme 960e624d7f
[MSFT] [DeviceDB] Teach `walkPlacements` about boundaries (#2000)
`walkPlacements` now takes a bounding rectangle and a primitive type
upon which to filter.
2021-10-15 13:29:53 -07:00
John Demme 07c2778fa7
[MSFT] [DeviceDB] Add bindings to walk functions (#1942) 2021-10-06 21:46:15 -07:00
John Demme 5a4445ec3e [MSFT] [NFC] DeviceDB -> PrimitiveDB, combine all DB code
- Renames DeviceDB to PrimitiveDB.
- Puts both PrimitiveDB and PlacementDB in DeviceDB.h.
- Moves PlacementDB implementation into DeviceDB.cpp.
2021-10-06 14:23:55 -07:00
John Demme d488343996
[MSFT] [DeviceDB] Find nearest free location in column (#1937)
Find the nearest primitive in a column to the desired row. Said primitive should be of a given primitive type, and be unoccupied.
2021-10-06 11:12:01 -07:00
Chris Lattner 0de4aac499 [ExportVerilog] Move into Conversions/ tree.
ExportVerilog was an outlier living as the only child of the Translations
tree, move it into Conversions to be more similar to other passes.
2021-10-04 16:24:12 -07:00
John Demme 12720afe41
[MSFT] Use a DeviceDB to seed a PlacementDB (#1922)
Just checks validity of placements for now.
2021-10-02 17:40:40 -07:00
John Demme ee2a93886c
[MSFT] Adding DeviceDB (#1921)
Created a DeviceDB which doesn't do anything yet. The `devType` to
`primitiveType` change got wrapped up in this change.
2021-10-02 01:28:24 -07:00
John Demme ede291cdd5 [MSFT] Rename `devType` to `primitiveType` on PhysLocation attribute 2021-10-01 23:13:06 -07:00
John Demme daa5dc503e [MSFT] Rename DeviceType enum to PrimitiveType 2021-10-01 22:09:52 -07:00
Parker Mitchell f76fadad6e
[MSFT] Rename DeviceDB to PlacementDB (#1894)
No functional changes. This PR simply renames DeviceDB to PlacementDB within the MSFT dialect. The "DeviceDB" name may be used in a future PR and live alongside the PlacementDB.
2021-10-01 18:24:10 -07:00
John Demme d046e6a7ec
[MSFT] Removing C++ generator code (#1918)
We've switched to Python-based generators. Ping-ponging between IR modifying
C++ and IR modifying Python was a massive mistake for pointer safety reasons.
2021-10-01 16:24:15 -07:00