Commit Graph

8675 Commits

Author SHA1 Message Date
Martin Erhart 9d207a3899
[MooreToCore] Support AssignedVariableOp (#7500) 2024-08-10 16:10:36 +01:00
lonely eagle 286e73e86c
[calyx] fix calyx canonicalization. (#7456)
* add calyx canonicalization.

* Added more checks to calyx.component, fix some details.

* update CmakeLists.txt.

* Update lib/Dialect/Calyx/CalyxOps.cpp

Optimized code.

Co-authored-by: Chris Gyurgyik <Gyurgyikcp@gmail.com>

* Update lib/Dialect/Calyx/CalyxOps.cpp

Optimize error reporting.

Co-authored-by: Chris Gyurgyik <Gyurgyikcp@gmail.com>

* use clang-format and add calyx.par test.

* Optimised code.

---------

Co-authored-by: Chris Gyurgyik <Gyurgyikcp@gmail.com>
2024-08-10 10:02:08 -04:00
Martin Erhart 62cd9aca7f
[MooreToCore] More extract op lowerings (#7499) 2024-08-10 14:22:53 +01:00
Fabian Schuiki 49c82be57a
[Moore] Fix mem2reg implementation (#7498)
Fix a few issues in the mem2reg interface implementations of VariableOp,
ReadOp, and BlockingAssignOp. Add tests reduced from the Snitch core
that used to fail before this fix.
2024-08-09 20:15:45 -07:00
Will Dietz b3a54e3557
LLVM bump to include upstream verifier performance fix. (#7496)
Bump LLVM [1] to include an upstream verifier performance fix [2].

This required two minor fixes to CIRCT:

  * [HW] Qualify types for safer use in other dialects.
  * [ImportVerilog] Fix ternary with diff types, both become Value.

[1]: 5689cccead...c69b8c445a
[2]: 7a98071da2
2024-08-09 19:56:27 -04:00
Martin Erhart bfed5353fd
[MooreToCore] Support StructExtractRefOp (#7497) 2024-08-10 00:07:48 +01:00
Martin Erhart 09fc725631
[Moore] Power operator folders and canonicalizers (#7494) 2024-08-10 00:05:26 +01:00
Schuyler Eldridge d4e7857649
fixup! [FIRRTL] Don't capture non-passives in LowerLayers 2024-08-09 18:41:15 -04:00
Schuyler Eldridge 73c053de32
[FIRRTL] Don't capture non-passives in LowerLayers
Fix a bug where the LowerLayers pass could create output ports on a module
lowered from a bind convention layer.  Avoid this _almost_ entirely by moving
all subfield, subindex, and subaccess operations (sub-* ops) out of layerblocks
before modules are created (when this is possible).

LowerLayers works by converting "captured" values into ports.  However,
the sub-* ops may capture non-passive types allowably, but then never
drive them.  E.g., consider the following:

    %0 = firrtl.wire : !firrtl.bundle<a : uint<1>, b flip: uint<1>>
    firrtl.layerblock @A {
      %1 = firrtl.subfield %0[a] : !firrtl.bundle<a : uint<1>, b flip: uint<1>>
      %2 = firrtl.node %1 : !firrtl.uint<1>
    }

Naively, this "captures" the non-passive %0.  However, this is really only
capturing the _passive portion_ of %0 through a subfield.  Without this
commit, LowerLayers will try to create a port with the same type as %0
when it should be creating a port with the same type of %1.  In order to
determine what the port is, LowerLayers needs to know what is actually
captured and not blindly assume that anything captured needs to be a port.

Because this analysis may be tricky, instead solve this by moving the
sub-* ops outside the layerblock before computing captures.  The captures
can then _continue_ to be naively computed by seeing if a value is defined
outside the layerblock.

This approach always works for subfield and subindex.  However, this approach
does not work if the subaccess index is defined inside the layerblock.  If this
happens, error.  This can be revisited later with a complete solution.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-08-09 18:41:15 -04:00
Megan Wachs 9f1d9f98ee
bump llvm to tip of main (#7440)
Co-authored-by: Fabian Schuiki <fabian@schuiki.ch>
Co-authored-by: Martin Erhart <maerhart@outlook.com>
Co-authored-by: Will Dietz <will.dietz@sifive.com>
2024-08-09 17:10:30 -05:00
Fabian Schuiki 7c32ed42e2
[Moore] Add constant materialization, fold constant conversions (#7478)
Implement the `materializeConstant` function for the Moore dialect and
mark the `ConstantOp` as a `ConstantLike` operation. This now allows us
to write constant folders for various operations. As a first example,
add a constant folder for `ConversionOp` that directly applies domain
conversions (e.g., `i42` to `l42` or vice versa) to constants.
2024-08-09 14:23:44 -07:00
Fabian Schuiki 450c968235
[Moore] Add more AssignedVariableOp canonicalizations (#7477)
Change the `AssignedVariableOp` to directly return type `T` instead of
the `ref<T>`. This removes the implied allocation and assignment, and
makes this op behave essentially like `hw.wire`.

The canonicalizers for `VariableOp` and `NetOp` can now replace all
reads from the old variable or net with the value of
`AssignedVariableOp` directly, since there is no more `ref<T>` type
involved. This also allows us to fully eliminate unnamed variables and
nets that have a unique continuous assignment.

Also add canonicalizers that remove `AssignedVariableOp` if they shadow
an input or output port of the same name, or if there are multiple such
variables with the same name in a chain.

At a later stage we may want to replace `AssignedVariableOp` entirely
with `dbg.variable`.
2024-08-09 14:18:23 -07:00
John Demme 562036cde8
[HWArith] Make `hwarith.icmp` result an `i1` (#7413)
As discussed in #7406. Resolves #7406.
2024-08-09 22:24:32 +02:00
Mike Urbach 36a3a424fc
[OM] Add ListType C API and Python bindings. (#7490)
We want to expose this type through the Python bindings for isinstance
queries, etc., so add the necessary boilerplate.
2024-08-09 13:53:25 -06:00
Mike Urbach 61d2719269
[OM] Add AnyType C API and Python bindings. (#7488)
We want to expose this type through the Python bindings for isinstance
queries, etc., so add the necessary boilerplate.
2024-08-09 11:56:40 -06:00
Schuyler Eldridge a6028eea60
[FIRRTL] Fix sub-* op in layer block verifier
Fix issues with verification of subfield, subindex, and subaccess
operations which appear in a layer block.  These operations are allowed to
occur in a layer block even if they capture non-passive operands.

This requires reworking layer block verification to no longer check for
operations using non-passive operands.  The spec requires that no
operation in a layer block _drives_ a value declared outside the layer
block.  However, this is exceedingly difficult to verify due to the fact
that non-passive destinations in ConnectLike operations can be
source-to-destination, destination-to-source, or bi-directional.  If the
verifier sees this, just allow it.  The FIRRTL pass pipeline will later
canonicalize away flips (i.e., make all types passive) which will then
allow the verifier to check these.  This should be revisited in the
future.

Fixes #7451.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>

Don't check non-passive connects.
2024-08-09 12:06:41 -04:00
John Demme 46e129756e [ExportVerilog] Fix broken test: prepare-for-emission
Mitigates #7414, but the true fix is likely #7484.
2024-08-09 12:50:19 +00:00
Hideto Ueno a2c44c1e4f
[FIRRTL] Canonicalize multibit_mux with narrow index (#7373)
This adds a canonicalization to optimize multibit_mux whose index has narrow width. Close https://github.com/llvm/circt/issues/7361
2024-08-09 20:51:11 +09:00
Martin Erhart 273439ec61
[MooreToCore] Fix variable op lowering of aggregate types (#7481) (#7362) 2024-08-09 09:58:03 +01:00
Martin Erhart 84d73b94aa
[MooreToCore] Fix variable op lowering of aggregate types (#7481) 2024-08-09 08:46:31 +01:00
Jack Koenig fa95071921
[FIRRTL][InferResets] Generalize FART to support sync reset (#7476)
The FullAsyncResetAnnotation is deprecated and replaced by
FullResetAnnotation which includes a resetType argument that must be
'sync' or 'async'.  IgnoreFullAsyncResetAnnotation is deprecated and
replaced by ExcludeFromFullResetAnnotation. The new annotations are in
package circt.

The behavior of FullResetAnnotation with resetType == 'async' is
identical to that of the old FullAsyncResetAnnotation. The behavior of
FullResetAnnotation with resetType == 'sync' is very similar, except the
type of the reset wired through will be UInt<1>, and any registers with
an existing reset at all (both sync or async) will be left unchanged
(resetType == 'async' will add async resets to registers with existing
sync resets).
2024-08-08 21:39:25 -07:00
Martin Erhart 2f869728d5
[MooreToCore] Struct extract lowering support (#7475) 2024-08-09 00:37:45 +01:00
Martin Erhart 1c8abbced3
[MooreToCore] Fix conversion and dyn_extract operation lowering (#7473)
The lowering pattern of these two operations crashed when used on aggregate types. This PR adds type conversions for array and struct types and fixes the two lowering patterns by adding support for these types
2024-08-08 23:00:15 +01:00
Schuyler Eldridge d8d7574eab
[FIRRTL] isAncestorOfValueOwner in LowerLayers
Change the LowerLayers pass to use the new utility,
`circt::isAncestorOfValueOwner`.  This was created from the existing
static function of the same name inside LowerLayers with a streamlined
implementation.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-08-08 15:38:08 -04:00
Schuyler Eldridge 75b8b02e1c
[Support] Add circt::isAncestorOfValueOwner util
Add a utility `crict::isAncestorOfValueOwner` that can be used to compute
if an Operation is an ancestor of a Value.  This frequently comes up when
trying to compute if a Value is defined _outside_ an Operation with a
region.

The implementation of this is based on @dtzSiFive suggestions.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-08-08 15:38:05 -04:00
Will Dietz 46148b263b Revert "[FIRRTL][Dedup] Reduce size of integer data hashed. (#7469)"
Revisit with unambiguous methods.

This reverts commit da2428ac1f.
2024-08-08 14:33:03 -05:00
Will Dietz 7dded4e860
[FIRRTL][LowerLayers] Plumb support for errors. (#7470) 2024-08-08 14:04:45 -05:00
Will Dietz da2428ac1f
[FIRRTL][Dedup] Reduce size of integer data hashed. (#7469)
Don't always zext to size_t.

Use smaller integer sizes for ValueId and add to hash together.
2024-08-08 13:55:30 -05:00
Fabian Schuiki d8c1f6dbad
[Moore] Support four-valued integers in ConstantOp (#7463)
Extend Moore's `ConstantOp` to use the new `FVIntegerAttr`, which now
allows us to materialize four-valued integer constants in the IR. Also
adjust ImportVerilog to finally properly captured integer literals with
X and Z bits.

With this change, `circt-verilog` is now capable of fully parsing the
Snitch RISC-V core used as a benchmark in the original LLHD paper at
PLDI 2020, and to produce a corresponding blob of IR.

Examples of the extended op:

    moore.constant 0 : i32
    moore.constant 2 : i2
    moore.constant -2 : i2
    moore.constant h123456789ABCDEF0 : i64
    moore.constant h123456789ABCDEF0XZ : l72
    moore.constant b1010 : i8
    moore.constant b1010XZ : l8
2024-08-08 10:38:33 -07:00
Schuyler Eldridge 27968fcfe7
[Support] Sort CMakeLists lines, NFC
Sort lines in a CMakeLists.txt file.  I'm doing this because I want to add
something to this in a later commit and would like to put it in a sane
place.

h/t @dtzSiFive for the suggestion.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-08-08 13:12:15 -04:00
Fabian Schuiki 04ba6a3fa3
[Moore] Add FVIntegerAttr (#7461)
Add the `FVIntegerAttr`, an attribute containing an `FVInt` value. This
allows four-valued integer constants to be used as attributes on
operations and for constant folding to occur on such values. In contrast
to the builtin `IntegerAttr`, `FVIntegerAttr` does not have a type yet.
The type can be added later as soon as we have a concrete use case.

I expect us to eventually move `FVIntegerAttr` into the HW dialect once
we are happy with its design. Other parts of CIRCT will eventually want
to reason about four-valued integers as well.

The parsing and printing of the attribute tries to make the `FVInt` read
like a plain old `APInt` when there are no X or Z bits present.
Otherwise it falls back to printing as hexadecimal or binary number.
To distinguish the different representations and to allow constants with
X or Z to be parsed as keywords, a `h` and `b` prefix is used for the
hexadecimal and binary formatting, respectively.

Examples of the attribute:

    #moore.fvint<42 : 32>
    #moore.fvint<-42 : 32>
    #moore.fvint<1234567890123456789012345678901234567890 : 131>
    #moore.fvint<hABCDEFXZ0123456789 : 72>
    #moore.fvint<b1010XZ01 : 8>
2024-08-08 08:57:55 -07:00
John Demme 5bc663c446 [ESI][Runtime] Minor cleanups
- Got an integration test which wasn't running working.
- Fixed a pybind11_stubgen error.
- Fixed an AppID constructor warning.
- Mitigated a poor hash function.
2024-08-08 12:21:02 +00:00
John Demme ad91378465
[ESI][Runtime] Poll method and optional service thread polling (#7460)
Add a poll method to ports, a master poll method to the Accelerator, and the ability to poll from the service thread. Also, only spin up the service thread if it's requested.

The service thread polling (in particular) required some ownership changes: Accelerator objects now belong to the AcceleratorConnection so that the ports aren't destructed before the service thread gets shutdown (which causes an invalid memory access). This particular binding isn't ideal, is brittle, and will be an issue for anything doing the polling. Resolving #7457 should mitigate this issue.

Backends are now _required_ to call `disconnect` in their destructor.
2024-08-08 03:53:42 -07:00
Morten Borup Petersen caab217642
[ESI] Add option to build runtime as a static library (#7455)
* [ESI] Add option to build runtime as a static library

* review comments

---------

Co-authored-by: Morten Borup Petersen <mpetersen@microsoft.com>
2024-08-08 11:02:19 +02:00
Hideto Ueno 12822ad0d0
[SimToSV] Add include guards to DPI import (#7459)
This adds include guards `__CIRCT_DPI_IMPORT_*` to DPI import statements generated in SimToSV. 

Fix https://github.com/llvm/circt/issues/7458.
2024-08-08 15:40:35 +09:00
Hideto Ueno a9436263bd
[ExportVerilog] Add a lowering option to fix up empty modules (#7454)
This commit adds a new lowering option to sanitize empty modules by
creating a dummy wire in it.
2024-08-08 15:39:05 +09:00
Fabian Schuiki 1d417e2d30
[FVInt] Add resizing utilities, allow hashing
Add more utilities to help with resizing `FVInt`s, including

- counting the active bits for signed and unsigned interpretation
- truncation
- zero/sign extension

Also add a default constructor that produces a zero-bit zero value,
allow `FVInt`s to be hashed, and consider bit width for equality
comparisons.
2024-08-07 17:53:24 -07:00
Fabian Schuiki aae791b1e9
[FVInt] Fix printing when bit width is less than one full digit
Printing of `FVInt`s would continuously shift the value right by the
log2 of the radix. This triggers an assertion in `APInt` in the case
where the bit width is less than the number of bits being shifted.
2024-08-07 17:53:24 -07:00
Schuyler Eldridge fcdefe5a1a
[FIRRTL] Whitespace cleanup, NFC
Fix a trailing double newline.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-08-07 20:40:45 -04:00
Schuyler Eldridge c08ac4bd78
[FIRRTL] Cache symbol table in LowerLayers (#7436)
Precompute a symbol to layer mapping inside LowerLayers and uses this
instead of a symbol table.  This is both faster and avoids problems of
trying to compute a symbol table while modules may be created.

Repurpose the functions that were being used to create macro declarations
to also compute this symbol to layer mapping.  Rename these to indicate
that they are now doing generic layer preprocessing.

Fixes #7434.

h/t @youngar for the fix suggestion.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-08-07 11:50:05 -04:00
Hideto Ueno cadbfe0e5e
[circt-lec] Accept two MLIR inputs (#7450)
Practically it is very useful to verify equivalence between modules in two different MLIR files. This commit changes `inputFilename` to a list and implements a very simple module merge that moves operations in the second module to the first by resolving the symbol.
2024-08-08 00:21:51 +09:00
Leon Hielscher 07179af7d9 [NFC] Remove trailing whitespace 2024-08-07 17:03:40 +02:00
fzi-hielscher 30ed753d53
[arcilator] Add JIT runtime environment library and stdio hooks (#7445) 2024-08-07 16:06:30 +02:00
Hideto Ueno 4c215e8ab8
[arcilator] Add an option to load shared lib into JIT engine (#7453)
This PR adds an option `--shared-libs` to load shared lib in the JIT engine in a similar way to what circt-lec does for loading z3 shared lib. With this change DPI library could be linked in arcilator.
2024-08-07 21:16:12 +09:00
Hideto Ueno 9828707817
[Arc][Sim] Lower Sim DPI func to func.func and support dpi call in Arc (#7386)
This PR implements initial support for lowering Sim DPI operations to Arc. 

* sim::LowerDPIFuncPass implements lowering from `sim.dpi.func` to `func.func` that respects C-level ABI. 
* arc::LowerStatePass is modified to allocate states and call functions for `sim.dpi.call` op. 

Currently unclocked call is not supported yet.
2024-08-07 13:51:14 +09:00
jpien13 1a8f82e7a6
[FIRRTL] Replaced 'replicate' to correctly named 'replace' flags (#7442)
Renamed and replaced shouldReplicateSequentialMemories to shouldReplaceSequentialMemories per issue #7384
2024-08-06 14:47:47 -07:00
Will Dietz 1645d71c1d
[FIRRTL] Tweak printing of layers to avoid extra space. (#7449)
Before:

firrtl.layer @A  inline

After:

firrtl.layer @A inline
2024-08-06 11:25:28 -05:00
Martin Erhart cac5b3a285 [SMT] Add convenience builder 2024-08-06 17:10:54 +01:00
Will Dietz 4415b9c2f7
[FIRRTL] Verify RWProbeOp target has layer requirements. (#7372)
RWProbe conservatively means a write to the target, so check
that the target is indeed writeable from where the rwprobe is.
2024-08-06 11:03:10 -05:00
Morten Borup Petersen 0b93783aae
[Ibis] Don't include design name in namespace in IbisContainersToHW (#7425)
The ibis.design op will be removed after the IbisContainersToHW pass, and there may be ibis.component's inside the design that have the same name as the design; we want that name to persist, and not be falsely considered a duplicate.

Co-authored-by: Morten Borup Petersen <mpetersen@microsoft.com>
2024-08-06 17:34:41 +02:00