Commit Graph

8980 Commits

Author SHA1 Message Date
Schuyler Eldridge dabd7d2c02
[FIRRTL] Use walk, InstanceInfo in AddSeqMemPorts (#7599)
Change the `AddSeqMemPorts` pass (which adds MBIST ports to memories) to
use a walk when adding ports to memories.  This will visit any region, but
will skip memories which instantiated under LayerBlockOps.  Memories and
instances which are instantiated under WhenOps will now get ports added to
them.  Any output ports created for a memory under a WhenOp will be
invalidated.

This change is prerequisite work to move the `LowerLayers` after
`AddSeqMemPorts` while still preserving the functionality of the original
pass order.  Unfortunately, layers do not compose sanely with
`AddSeqMemPorts`.  This is a failing of the original pass and its
assumptions about what is "design" vs. "verification" as opposed to any
fundamental issue with layers.  Generally, layers are intended as
verification features.  However, there is no actual requirement or
expectation that they will be used this way.  Going forward,
`AddSeqMemPorts` is intended to be removed and replaced with a feature in
Chisel.

Additionally, this this commit includes a small change to the pass output
where the connects created are placed immediately following the memory
instance.  This is necessary to create the connects inside the layer
blocks.  However, it is also slightly better output than before.  (This
changed one test superficially.)

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-26 22:26:12 -04:00
Will Dietz 253a70bffe
[firtool] Move LowerLayers later in pipeline. (#7639)
LowerLayers belongs with the other passes that lower out of FIRRTL.

Start moving it, now that first batch of passes have been fixed
to handle enough FIRRTL IR to run in presence of layer operations.
2024-09-26 12:52:44 -05:00
Will Dietz 9322802886
[FIRRTL] Inliner: Support for ops with regions. (#7398)
inlineInstances/flattenInstances:
* Walk entire body, not only top-level operations.
  Fixes missing instances and allows inlining them
  when conservatively legal.
* Reject inlining instances under when/match.

inlineInto/flattenInto:
  Walk entire body using new `inliningWalk` method
  that drives the per-operations handling but also
  handles cloning "structure" operations that have
  regions (when/match/layer) and managing what
  should be cloned where.

  This allows inlining modules that contain these
  operations.

Inliner now may produce errors, thread throughout.

This allows the inliner to run earlier in the pipeline,
particularly before LowerLayers.
2024-09-26 11:54:25 -05:00
Will Dietz fee3deccfc [FIRRTL][Inliner][NFC] rename module -> moduleOp.
Per reviewer feedback and recent trend.
Thanks, @seldridge!
2024-09-26 08:40:55 -05:00
Will Dietz a81a8c5892 [FIRRTL][Inliner][NFC] Drop braces on single-statement for.
Pointed out in review of PR touching this file.
(thanks @seldridge!)
2024-09-26 08:37:32 -05:00
Schuyler Eldridge 3ffc39c888
[FIRRTL] Add verifier of single MarkDUTAnnotation (#7633)
Add a CircuitOp verifier that guarantees that there is zero or one modules
annotated with a `MarkDUTAnnotation`.  This is important as many passes
assume that this is the case.  Moving this check into a verifier means
that logic checking this behavior in each pass can be removed.  I am
slightly concerned of the performance cost of doing this as examining the
annotations is non-trivial and this will cause that examination to now
happen more often.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-26 02:08:26 -04:00
Fabian Schuiki ee8e605ac6
[ImportVerilog] Add support for elaboration system tasks (#7632)
Simply skip the elaboration system tasks `$info`, `$warning`, `$error`,
and `$fatal` outside procedural code. Slang already processes these
tasks and generates the corresponding diagnostics for us.
2024-09-25 13:11:43 -07:00
Schuyler Eldridge b7e2e2005d
[LLHD] Silence unused variable warning, NFC
Slap a `maybe_unused` on an unused variable to silence a compiler warning.
There may be a cleaner way to do this with a `resize`/`std::fill` pattern
rather than going the unused route.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-25 15:58:33 -04:00
Fabian Schuiki 687f7fb38f
[Moore] Drop named_constant op in favor of dbg.variable (#7624)
Remove the `NamedConstantOp` and replace its uses with `VariableOp` from
the debug dialect.

The op was originally added to track the value of constant parameters,
localparams, and specparams in the IR. In ImportVerilog, such parameters
would generate a corresponding `named_constant` op and all references to
the parameter by name would be replaced with the `named_constant`'s
result.

This doesn't really work well for parameters defined outside a module,
such as in packages or at the root of the Verilog source file. (Modules
are isolated from above, preventing the use of `named_constant`s from
outside the module.) Therefore expressions would generally fall back to
materializing constants directly where they were used.

Since the named constant ops are only there to track a constant value in
the IR for the user's debugging convenience, using the debug dialect
directly feels a lot more appropriate.
2024-09-25 09:46:00 -07:00
Martin Erhart 0ecbd6f3b8
[LLHD] Add Sig2Reg pass for graph regions (#7623) 2024-09-25 15:08:22 +01:00
Martin Erhart e99d952fbe
[LLHD] Add DesequentializationPass (#7616) 2024-09-25 14:51:49 +01:00
Martin Erhart 7c80a60acf
[MooreToCore] Return early on non-convertable type (#7631) 2024-09-25 14:20:57 +01:00
Bea Healy 77f49fb290
[circt-bmc] Add `circt-bmc` tool (#7621)
Co-authored-by: Martin Erhart <maerhart@outlook.com>
2024-09-25 14:17:57 +01:00
Martin Erhart 337dad5839
[MooreToCore] Alternative conditional lowering and type conversion fixes (#7625) 2024-09-25 09:43:09 +01:00
Hideto Ueno f8a95aa45c
[SV] Add MacroRefOp to represet macro statement (#7607)
There has been MacroRefExprOp and MacroRefExprSEOp to use macro symbols as expressions but it was not possible to use macro as a statement. This commit adds `sv.macro.ref` op to represent a statement. Since `sv.macro.ref` mnemonic was used by MacroRefExprOp this commit also renames `sv.macro.ref` to `sv.macro.ref.expr` at the same time.
2024-09-25 17:29:57 +09:00
Schuyler Eldridge 3fbec15b79
[FIRRTL] Switch to IPO instead of RPO
Change FIRRTL's `InstanceInfo` analysis to use `llvm::inverse_post_order`
instead of `ReversePostOrderTraversal`.  This may be slightly faster/more
efficient as it doesn't build a vector of what to visit in a post order
walk and this will visit all modules, not just those under the top module.

h/t @youngar for the pattern and the reasoning behind why to favor this
pattern.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-24 23:59:24 -04:00
Schuyler Eldridge dc28bc5dee
[FIRRTL] Use InstanceInfo in LowerMemory
Change the `LowerMemory` pass to use the `InstanceInfo` analysis to
determine when doing computations about what is under vs. not under the
design-under test.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-24 20:20:26 -04:00
Fabian Schuiki 76f3ca59f0
[ImportVerilog] Add debug info switch
Add an option to ImportVerilog to enable debug info generation. If set,
the Verilog importer should generate additional `dbg.*` ops in the IR to
track variables and constants defined by the user in the Verilog source
text. No such ops are generated yet.

Also add a corresponding `-g` option to `circt-verilog`.
2024-09-24 16:48:17 -07:00
Fabian Schuiki 24715e4d31
[ImportVerilog] Refactor constant materialization; NFC
Factor the materialization of Slang `SVInt`s and `ConstantValue`s out
into a helper function on the import context. This will allow for easier
access to constant materialization from outside the expression
conversion code.
2024-09-24 16:48:17 -07:00
Fabian Schuiki 9f952e166c
[MooreToCore] Pass through debug dialect ops
Add support for the Debug dialect to the MooreToCore conversion. The
conversion simply updates the types of `dbg.variable`, `dbg.array`, and
`dbg.struct` as the values they observe are being lowered. Debug ops
referring to Moore-typed values will refer to the corresponding HW-typed
values after conversion.
2024-09-24 16:48:17 -07:00
Schuyler Eldridge fa3de1e7d2
[FIRRTL] Simplify InstanceInfo function names
Change the functions for the `InstanceInfo` analysis to use "any" instead
of "atLeastOne".  The former is far simpler and better aligns with the
"all" member functions.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-24 19:28:14 -04:00
Schuyler Eldridge 52c9d4c388
[FIRRTL] Add "effective" functions to InstanceInfo
Add two new functions for computing if a module is under the "effective"
design-under-test (DUT):

  - atLeastOneInstanceUnderEffectiveDut
  - allInstancesUnderEffectiveDut

These functions are very simple.  However, their use comes up in a number
of passes and this makes _reading_ those passes more straightforward.
I.e., it's quicker to grok what is going on with these functions than with
`!hasDut() || atLeastOneInstanceUnderEffectiveDut()`.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-24 19:27:52 -04:00
Schuyler Eldridge 19c4a3fbf1
[FIRRTL][LowerMemory] Insert modules above users
Change the location where the `LowerMemory` pass creates modules from
creating modules at the end of the circuit to inserting them just above
the module where they have a first user.  This has two benefits: (1) this
is a more natural place to insert these modules (a minor IR/Verilog
quality concern) and (2) this avoids revisiting these modules
unnecessarily because the pass is doing a linear walk of the circuit from
top to bottom.

The latter benefit avoids some potential problems where an analysis that
is computed before the modules gets inserted has no knowledge of the new
modules.  Any queries of these analyses may then crash and burn.  Namely,
this affects switching this pass to use the `InstanceInfo` analysis and
avoiding precomputation of which modules are under the
design-under-test (DUT).

This should have no effect on names in the final Verilog since module
names (symbol names) must be unique.  I.e., the order of FIRRTL modules
won't affect final module names.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-24 18:26:31 -04:00
Bea Healy c601695bee
Add `verif.bmc` VerifToSMT lowering (#7603)
Co-authored-by: Martin Erhart <maerhart@outlook.com>
2024-09-24 17:32:04 +01:00
Schuyler Eldridge 685cc3bdd5
[FIRRTL] Rename C++20 "module" AddSeqMemPorts, NFC
Change usage of `module` to `moduleOp` for better C++20 hygiene.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-24 11:36:31 -04:00
Schuyler Eldridge 618c0700c8
[FIRRTL] Fix AddSeqMemPorts lint warning, NFC
Change usages of `size()` to `empty()` to align with what the linter
suggests.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-24 11:36:02 -04:00
Schuyler Eldridge bf7aad754e
[FIRRTL] Add features, cleanup InstanceInfo (again) (#7618)
[FIRRTL] Add features, cleanup InstanceInfo (again)

This fixes problems with a commit [[1]] that was reverted [[2]].  The commit
message below is unchanged.

Add a number of new features to FIRRTL's `InstanceInfo` analysis.  These
changes were made after downstream efforts (uncommitted work) to use this
in the `AddSeqMemPorts` pass.  These new features include:

  - `hasDut` to check if a circuit has a design-under-test
  - `getDut` to get the design-under-test if it exists
  - `getEffectiveDut` to get the "effective" design-under-test
  - `isEffectiveDut` to check if a module is the "effective"
     design-under-test

The "effective" design-under-test (DUT) is a weird artifact of how some
SFC-derived passes have historically worked.  If a circuit has no
DUT (indicated by a circuit which contains no module annotated with a
`MarkDUTAnnotation`), then some passes will treat the top module as if it
were the DUT.  This "effective" DUT concept shows up in `AddSeqMemPorts`,
`GrandCentral`, and other passes.  For now, enshrine the _computation_ of
this in the `InstanceInfo` analysis to avoid having to scatter logic for
computing this across serverl passes.

Widen the accepted type of parameters that can be passed to `InstanceInfo`
member functions from `FModuleOp` to `igraph::ModuleOpInterface`.  This
already works without modifications and makes these member functions much
more usable.

[1]: 7e9cedd07
[2]: 2683f6772

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-24 10:59:17 -04:00
Martin Erhart 952f54219a
[LLHD] Make process lowering best-effort and allow constants from outside the region (#7617) 2024-09-24 13:26:32 +01:00
Schuyler Eldridge 2683f6772a
Revert "[FIRRTL] Add features, cleanup InstanceInfo"
This reverts commit 7e9cedd07b.  This commit
is showing problems with short integration tests hanging.  I'm reverting
it temporarily to prevent any issues from leaking into main.
2024-09-24 00:13:56 -04:00
Schuyler Eldridge 7e9cedd07b
[FIRRTL] Add features, cleanup InstanceInfo
Add a number of new features to FIRRTL's `InstanceInfo` analysis.  These
changes were made after downstream efforts (uncommitted work) to use this
in the `AddSeqMemPorts` pass.  These new features include:

  - `hasDut` to check if a circuit has a design-under-test
  - `getDut` to get the design-under-test if it exists
  - `getEffectiveDut` to get the "effective" design-under-test
  - `isEffectiveDut` to check if a module is the "effective"
     design-under-test

The "effective" design-under-test (DUT) is a weird artifact of how some
SFC-derived passes have historically worked.  If a circuit has no
DUT (indicated by a circuit which contains no module annotated with a
`MarkDUTAnnotation`), then some passes will treat the top module as if it
were the DUT.  This "effective" DUT concept shows up in `AddSeqMemPorts`,
`GrandCentral`, and other passes.  For now, enshrine the _computation_ of
this in the `InstanceInfo` analysis to avoid having to scatter logic for
computing this across serverl passes.

Widen the accepted type of parameters that can be passed to `InstanceInfo`
member functions from `FModuleOp` to `igraph::ModuleOpInterface`.  This
already works without modifications and makes these member functions much
more usable.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-23 21:07:58 -04:00
Martin Erhart 05664fa0ad
[LLHD][TCM] Simplify region directly (#7615)
The simple canonicalizer does not do this simplification for us if too many blocks have to be merged.
2024-09-23 22:22:33 +01:00
Schuyler Eldridge fe34e15e41
[FIRRTL] Add InstanceInfo Analysis (#7612)
Add a new InstanceInfo analysis.  This analysis provides common
information which can be computed from a single walk of the InstanceGraph.
The idea behind this is that there are a large amount of common
information that different passes want to compute which all follows this
same walk (and therefore has the same algorithmic complexity to compute
it).  Move all this information into a single, common analysis.

This analysis currently enables O(1) queries of if something is the DUT,
is instantiated under the DUT, or is instantiated under a layer.  More
queries can be added as they are identified.

This new analysis naturally depends on the InstanceGraph analysis.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-23 12:50:46 -04:00
Mike Urbach 002427065e
[FIRRTL] Allow local targets to be multiply-instantiated. (#7613)
The existing path support was built up based on the assumption that
every target is unique. That is true for FIRRTL produced by standard
Chisel code, which elaborates unique modules for each instance. We
definitely don't want to limit ourselves to this world, and we should
support targeting things that are multiply instantiated when it is not
ambiguous what we refer to.

This patch relaxes the single-instantiation constraints for local
targets, which refer to a module or something inside a module,
regardless of how many times or at what paths that particular module
was instantiated.

This required a couple changes through the pipeline:

ResolvePaths already had an early exit for the local path case, but
this needed to come before the single-instantiation check.

LowerClasses needed a couple small changes to not enforce the
single-instantiation check in the local path case, and to build a
hierpath that just has a single element.

While this is not a new requirement, we can still get ambiguous local
targets, for instance from nested module prefixing. The error message
in LowerClasses for this case was made a little more clear.
2024-09-20 19:50:55 -06:00
Schuyler Eldridge afd61f26ef
[FIRRTL] Avoid module keyword in CheckLayers, NFC
Change uses of "module" to "moduleOp" to avoid collision with C++20.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-20 15:18:23 -04:00
Hailong Sun d5314f79fe
[Moore] Add assert, assume, and conver ops. (#7589)
These immediate assertion ops borrow from the SV dialect.
2024-09-20 10:42:30 +08:00
John Demme de5bdf6104 [NFC][ESI] Move around services code
Move some code which was in the MSFT dialect (which used to be used both there
and in ESI) into the ESI pass which actually uses it. Also, reorg the code in
the services impl.
2024-09-19 16:17:02 -07:00
Martin Erhart 57b6336667
LLVM Bump (#7609) 2024-09-19 20:36:16 +01:00
Martin Erhart 71710bbb57
[CMake] Consistently declare conversion libraries and simplify circt-opt link target list (#7610) 2024-09-19 20:35:45 +01:00
Hideto Ueno d35c7c6c56
[Arc] Fully support initialization through seq.initial (#7605)
This PR implements state initialization using `seq.initial` not limited to constants
2024-09-20 02:10:29 +09:00
Schuyler Eldridge 7db6951f02
[FIRRTL] Remove unused allUnder utility
Remove an unused utility function.  This was previously used by
GrandCentral, but this is no longer load bearing.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-16 19:45:25 -04:00
Martin Erhart 5aba666e00
[HW] Add reduction patterns to trim port list of top-level module (#7587) 2024-09-16 19:47:26 +01:00
Schuyler Eldridge 478e0db04e
[FIRRTL] Fix pre-order walk in IMCP
IMCP needs to use a post-order walk as it is deleting operations (and the
operations are not skipped after erasure).  This should fix observed
failures in nightly CI [[1]].

[1]: 46014cd277 (commitcomment-146717821)

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-16 11:10:54 -04:00
Schuyler Eldridge f9ca6b0ba8
[FIRRTL] Test whitespace cleanup, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-13 22:49:16 -04:00
Schuyler Eldridge 3eadefcedc
[FIRRTL] Make IMCP work with Layers
Change IMCP to recurse into layers.  This has the effect of allowing IMCP
to sink constants into layers and to properly visit instances which are
instantiated under layers.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-13 16:45:33 -04:00
Schuyler Eldridge 46014cd277
[FIRRTL] Convert IMCP to walk
Change IMCP's module update to use a walk instead of only visiting
top-level ops.  This is intended to be an entirely mechanical change and
is broken out in a separate commit because of its mechanical nature.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-13 16:44:35 -04:00
Schuyler Eldridge d61cdc9a84
[FIRRTL] Fix iteration over set
Fix incorrect iteration over a set to do operation erasure.  The order of
operations is operations is important to avoid erasing an op before all
its users are erased.  Avoid this with a SetVector.

h/t @dtzSiFive for identifying the problem/fix.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-12 21:51:14 -04:00
Schuyler Eldridge d22b9cd802
[FIRRTL] Error if InferReadWrite sees WhenOps
Change the InferReadWrite pass to fail if it ever sees a WhenOp.  If this
happens, the pass can silently do the wrong thing when trying to determine
signal drivers.  This is a conservative check (with false positives), but
will have no false negatives.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-12 18:38:07 -04:00
Schuyler Eldridge 944ec93c5f
[FIRRTL] Change InferReadWrite to use a walk
Fix the InferReadWrite pass to walk into nested regions instead of only
visiting the top-level ops immediately in an FModuleOp's body.  This has
the effect of allowing it to work on memories that are declared inside
layers.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-12 18:38:03 -04:00
Martin Erhart a50540ecdb
LLVM Bump (#7595) 2024-09-12 16:16:14 +01:00
Schuyler Eldridge 9b4512df7e
[FIRRTL] Convert LowerMemory to walk
Change LowerMemory to use a walk as opposed to iteration over operations.
This is done to make this pass work with operations which have regions and
may contain memories, i.e., to make this pass work with layers and whens.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2024-09-12 10:12:30 -04:00