Commit Graph

4327 Commits

Author SHA1 Message Date
Andrew Lenharth 0b226442cd Silence Warning and fix analysis preservation. 2023-02-17 15:33:03 -06:00
Hideto Ueno f4a12353a7
[HW] Add a canonicalization to swap constant index and unknown index of array gets (#4668)
This implements canonicalizer to sink constant index to inner array create. 

```
array_get const, (array_get sel, (array_create a, b, c, d)) --> 
array_get sel, (array_create (array_get const a), (array_get const b), (array_get const c), (array_get c d))
```

Though this might increase the size of IR we can reduce the size of a temporary created by array create op.
2023-02-17 13:18:54 +09:00
Will Dietz 6d043ddc37
[FIRRTL][LegacyWiring] Fix insertion point for fieldID. (#4664)
Fixes #4663.
2023-02-15 17:43:44 -06:00
John Demme 52d989755d [MSFT] Support `msft.instance` in non-MSFT/HW modules
Lowering `msft.instances` required the `__INST_HIER` parameter to exist,
so when lowering inside of a non-HWModuleOp it would fail. Now the
lowering detects that situation and instead assumes that the containing
module is the top level.
2023-02-15 23:13:11 +00:00
John Demme dc8cdc0330
[ESI] Lower pure modules into HW modules (#4658)
Implement a lowering which converts `esi.pure_module`s into `hw.module`s. Uses the `esi.pure_module.inputs` and `esi.pure_module.output` as ports, then splices and fixes up the other block IR as appropriate.
2023-02-15 14:41:28 -08:00
John Demme 80f59df265 [ESI] Run the service generators in HWModuleLike
Modules which implement HWModuleLike can run service generators. We only
need the mutability to surface requests.
2023-02-15 22:07:56 +00:00
John Demme 73cd4d9154 [ESI] Make ESIPureModuleOp implement HWModuleLike 2023-02-15 21:59:47 +00:00
John Demme 5ae8a5f7be
[ESI] Introduce `pure_module.input` and `pure_module.output` (#4657)
These ops are intended to be produced by service implementation generators to translate service requests into top-level ports when lowering into an RTL level module.
2023-02-15 13:46:52 -08:00
Prithayan Barua 535def1265
[CheckCombCycles] Iterative Tarjan's SCC to detect cycles (#4642)
Re-implement the pass using an iterative Tarjan's SCC algorithm instead of the
current recursive implementation. Should handle aggregates and subaccess op.
Overview of the algorithm:
Process each module in the InstanceGraph by traversing it bottom up.
For each module, build a map of all the FieldRefs that each Value
can refer to, and the map of all the Values that refer to a FieldRef.
Given any Value, we can compute the set of Values that alias with it,
that is refer to the same FieldRef.
Now perform a DFS over the "interesting" ops in the module.
The set of Values whose successors are currently being visited are recorded
in the Visiting set. Once all the successors of a Value are visited, it is
 removed from the Visiting set. If a Value is visited and it already exists
 in the Visiting set, then a Cycle exists in the graph.
 The Combinational paths of a module are inlined at the instance, to detect
 combinational cycles across modules.
2023-02-14 21:49:49 -08:00
John Demme 1149618917
[ESI] Add specification to build signals into SV interface or not (#4653)
Support both modes wherein external modules' signaling are bundled in SV interfaces and just appended with `_valid` and `_ready`. Default to not bundled since that seems to be far more common. 95% of this was just updating to use the op interface rather than just hwmodule directly.
2023-02-14 10:46:56 -08:00
Hideto Ueno b16d03ff34
[LowerTypes] Track public modules and lower ports properly (#4655)
This changes LowerTypes to look up module visibilities. `module.isPublic()` cannot be called from a different thread because of a race condition so this PR first creates a set of public modules and checks the visibility by querying to the set.
2023-02-15 02:29:02 +09:00
Nandor Licker cc1a5ee8e8
[FIRRTL][MemOp] Removed unused bits from memories (#4652) 2023-02-14 18:53:34 +02:00
John Demme e31e7f2e77 [HW][NFC] Modify ports shouldn't touch the body block
As per the [documentation in
HWOpInterfaces.td](a054073460/include/circt/Dialect/HW/HWOpInterfaces.td (L110)),
don't touch the body block when modifying ports. Only ESI and MSFT code
was relying on this behavior.
2023-02-14 00:18:44 +00:00
John Demme 3338609341 [ESI] Add signaling standard to channel type
In the past, ESI has only supported valid-ready signaling, so we didn't
need to encode the signaling standard. Since we're about to add FIFO
signaling, we need a way to encode the signaling standard. Create an
enum and add it as a parameter to the channel type, defaulting to
ReadyValid so we don't have to fix a bunch of tests.
2023-02-11 00:56:42 +00:00
Andrew Lenharth db40efbcdc
[FIRRTL] Simple points-to like analysis (#4637)
This analysis maps values back to their definitions (operations which produce a new value) and provides an indexing path in the original definition to produce the current value.
Subaccesses produce a -1 (wildcard) in the path.
The analysis provides the user with a stable summary node for each value which is suitable to use in other data-structures.

wire a : firrtl.vector<bundle<f1: uint, f2: uint>, 4> => definition, is a root (empty path)
v = subindex(a, 2) => derived from a with path {2}
w = subfield(v, f2) => derived from a with path {2, 1}
2023-02-09 07:37:04 -06:00
Schuyler Eldridge 0285a98d96
[FIRRTL] Fix missing BlackBoxPathAnno Lowering
Add a known and supported annotation to the LowerAnnotations Annotation
table.  This was accidentally never added, even though it works.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-08 23:48:27 -05:00
Andrew Lenharth ffa319f9bd [NFC] spelling 2023-02-08 16:38:47 -06:00
Will Dietz abdc30da6f
[FIRRTL][AddSeqMemPorts] Fix use of DenseMap entry after invalidated. (#4643) 2023-02-08 13:25:30 -06:00
Will Dietz d87ebfa0f3
[SV][ETC] Name port after instance.result_name, as well. (#4640)
Fix case where port is named "" (_GEN), teach to grab name from instance.

Add test based on case found in the wild.
2023-02-08 11:32:01 -06:00
John Demme 28c132d1cc
[PyCDE] ESI pure module entry (#4635)
Teach PyCDE about ESI pure modules.
2023-02-07 14:41:33 -08:00
John Demme f50b5c737f
[ESI] Introduce ESI pure module op (#4633)
A module containing only ESI channels and modules with only ESI ports. All non-local connectivity is done through ESI services. If this module is the top level in the design, then the design's actual top level ports are defined by a BSP.

Useful for both simulation and synthesis via ESI BSPs.
2023-02-07 14:40:48 -08:00
Schuyler Eldridge fef7ca7d30
[FIRRTL] Improve BoringUtils Names (don't use pin)
Change the way that BoringUtils-backing infrastructure creates wiring
problems to not suggest a name derived from the "pin".  This is often
auto-generated and may introduce a name collision between the port and
the source/sink, causing the source/sink to be renamed.  Instead, rely
on the default behavior for how WiringProblems generate names to create
better names that are derived from the source/sink name.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-07 15:47:30 -05:00
Schuyler Eldridge 203b78283b
[FIRRTL] Don't Remove File-init Read-Only Memories
Block removal of read-only memories that are initialized via a file.
This is a common FPGA ROM pattern (and is also used by the upstream
Chisel tests of file initialization API).

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-07 11:15:33 -05:00
Will Dietz 508a885cb4 [FIRRTL][NFC] resize SmallVectors to hold at least initializer.
Size to largest size they might take since only a few more.
2023-02-07 09:12:20 -06:00
Hideto Ueno 2b612a2dcd
[HWLegalizeModules] Legalize aggregate constant (#4626)
This PR extends HWLegalizeModules to support aggregate constants. 
Also `signalPassFailure` is called when we fail to legalize expressions.


Fix https://github.com/llvm/circt/issues/4623.
2023-02-07 19:56:28 +09:00
sam-shahrestani 05ca6572e0
[LowerAnnotations] Resolve legacy wiring annotations as WiringProblems (#4496)
Resolve legacy wiring annotations as WiringProblems.

Support Chisel BoringUtils.
2023-02-07 00:39:43 -05:00
Schuyler Eldridge b6dd1c3ecd
[HWMemSimImpl] Add Memory File Initialization
Add support to HWMemSimImpl for doing file-based memory initialization.
This comes in two flavors:

  1. Inline initialization
  2. Bind-based initialization

In (1), a ReadMemOp is used to initialize the memory from a file.
In (2), a separate module is created that initializes the memory via
ReadMemOp using an XMRRefOp.  This new module is then instantiated in
the memory module via a bind.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-06 23:43:39 -05:00
Schuyler Eldridge a8bb279d48
[LowerToHW] Add Memory Initialization Support
Add FIRRTL memory initialization via file support.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-06 23:43:39 -05:00
Schuyler Eldridge 822da7fcbe
[FIRRTL] Add Memory Initialization to FIRRTL Infra
Add Memory Initialization information to FIRRTL pipeline infrastructure.
This information is dropped at LowerToHW right now.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-06 23:43:39 -05:00
Schuyler Eldridge b387c034f0
[FIRRTL] Add Memory Annotation Parsing
Add parsing of the two memory initialization annotations which implement
the Chisel loadMemoryFromFile and loadMemoryFromFileInline APIs:

  - firrtl.annotations.LoadMemoryAnnotation
  - firrtl.annotations.MemoryFileInlineAnnotation

These are parsed into the optional MemoryInitAttr on CHIRRTL or FIRRTL
memory operations.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-06 23:43:39 -05:00
Schuyler Eldridge 8a2d2bb83d
[FIRRTL] Add MemoryInit to CHIRRTL memories
Add a MemoryInitAttr to CHIRRTL memories (CombMemOp and SeqMemOp) to
record information about file-based memory initialization.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-06 23:43:39 -05:00
Schuyler Eldridge 20e30e2cde
[FIRRTL] Add MemoryInitAttr to FIRRTL Memories
Add an optional attribute of type MemoryInitAttr to FIRRTL's MemOp in
order to capture external memory initialization behavior.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-06 23:43:38 -05:00
Robert Young 32f3efe1d4
[FIRRTL][SV][SystemC][ESI] Remove extra whitespace around optional attr dicts (#4324)
Often, we unconditionally print a space before printing optional attribute
dictionaries. However, the majority of the time, the attr dict is elided, so
that we end up with a double-space in our output. It turns out, the underlying
utility in MLIR, printOptionalAttrDict, will print a leading space if it has to
print the attr dict, so it's pointless for us to be outputting one ourselves.
This PR removes the extra whitespace for a number of ops.

A large number of ops use a custom directive to print the attributes. To
suppress leading whitespace in this case, we can use an empty literal (``) in
the asm format.

Modified Ops:

firrtl.circuit
firrtl.module
firrtl.wire
firrtl.mem
firrtl.node
firrtl.printf
firrtl.reg
firrtl.regreset
firrtl.instance
sv.wire
sv.reg
sv.logic
sv.interface.instance
sv.localparam
systemc.cpp.variable
esi.buffer
esi.pipeline

Co-authored-by: Robert Young <robert.young@shopify.com>
2023-02-06 14:35:17 -05:00
Andrew Lenharth d65914cd88 [ExportVerilog] bindfile is a sv file and should be marked as such 2023-02-06 11:59:21 -06:00
Will Dietz 90b1bc50d4
[FIRRTL][NFC] Remove unused port boring/LCA methods. (#4630) 2023-02-06 11:44:18 -06:00
Hideto Ueno 0e70371b2c
[ExportVerilog][PrettifyVerilog] Fix exprInEventControl (#4625)
This commit fixes bugs in spilling logic regarding expressions used in sensitivity list.

* PrettifyVerilog is changed to check lowering options so that CSEd expressions are not cloned into users when `exprInEventControl` is enabled.
* There was a duplicated logic in isExpressionUnableToInline and PrepareForEmission so the logic was unified into isExpressionUnableToInline.

Fix https://github.com/llvm/circt/issues/4620
2023-02-07 02:38:51 +09:00
Will Dietz da4a2072e4
[GC] Update numXMRs statistic. (#4628)
Fixes #4542.
2023-02-06 11:06:56 -06:00
Hideto Ueno c7767562b6 [ExportVerilog] Return empty string if location is empty
This fixes an issue introduced by 92011d that an empty location is emitted
when a lowering option `locationInfoStyle=wrapInAtSquareBracket` is used.
2023-02-06 06:00:56 -08:00
John Demme c17842cf6d
[LLVM] Bump for CVE-2022-24439 (#4621) 2023-02-03 19:36:01 -08:00
Schuyler Eldridge a29c037ca8
[SV] Change ReadMemOp to use SSA Value
Change the existing ReadMemOp to use an SSA Value for its destination
memory as opposed to a symbol.  This more closely models how the
operation actually works and enables the operation to be used to be used
with XMRRefOp to initialize memories that are not in the current module.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2023-02-03 18:15:13 -05:00
Robert Young c62e623705
Migrate to the new folding api (#4619)
* Migrate to the new folding api

In the old folding API, folders would get an array of attributes, where each
entry corresponds to an input operand of the op.

In the new folding API, this array is wrapped by an op-specific FoldAdaptor,
which gives us structured and nicely named accessors to the underlying array of
attributes.

This new folding API will soon be the only way to write folders, and as such,
ODS generates a warning when a dialect has not switched over to the new folding
API.

This commit moves every dialect in circt to the new folding API.

* Make constFoldFIRRTLBinaryOp's calculate callback take input by const ref

APInts are not trivially copyable, so passing them by const-reference might
save us some allocations. This change was suggested by clang-tidy.
2023-02-03 15:00:34 -05:00
Andrew Young 92011de1c0
Add port location information to verilog output (#4540)
The goal of this PR is to parse in FIRRTL debug source locations for module ports, and maintain them through the pipeline, eventually printing the locations as part of the port list.  To accomplish this whole pipeline support, changes were required to the FIRRTL and HW dialects.  The changes to HW modules motivated changes to the MSFT dialect to ensure that the generic module functionality still worked for both dialects.  The port locations give better error messages when emitting a diagnostic on a block argument value.

The first design point is that I decided to support port locations on FIRRTL `FExtModuleOp`s.  With regular modules, we can attach port locations to all the block arguments.  For `FExtModuleOp`s we require a `portLocations` attribute of type `ArrayAttr<LocationAttr>` to track the port locations. To keep things simple, I decided to add the `portLocation` attribute to all kinds of FIRRTL modules.  For regular `FModuleOp`s, we copy these locations into the block argument values and add a verifier to ensure that these are kept in sync.

The FIRRTL parser was storing the Module's location in each of the block arguments, despite having code for parsing port specific location information.  It was modified to stop overriding the port's parsed location.

Port location information was added to the `FModuleLike` op interface.

Some internal FIRRTL helpers were refactored to have only common functionality, with `FModuleOp` handling the specifics of owning a region after calling the generic helpers.

The FIRRTL MLIR module printer was modified to print the debug locations when the `--mlir-print-debuginfo` option is specified.  There appears to be a problem in the printer's support for debuginfo, and it will create attribute aliases for all locations even if it does not end up printing the location.  To get around this, we query the OpPrinterFlags directly, which will be populated by the command line options.  The downside of this approach is that if someone is programmatically modifying the printer's OpPrinterOptions, we will not respect those settings. I don't think this will be an issue in practice, but it would be nice to fix this upstream.

The FIRRTL IR module parser was modified to read in an optional source location when parsing the port list.  If no location is found, it uses a location pointing to the MLIR file.

Dedup was modified to properly combine the location information of modules and their block arguments.

LowerTypes was modified to spread the port location information to each lowered port.

LowerToHW was modified to properly transfer the location information during lowering.

In the HW dialect, I continued the design point to allow port location information to be tracked by `hw.module.extern`, which required adding two attributes for tracking locations; an `argLocs` and a `resultLocs` attribute was added to HW modules.

Similar to the FIRRTL dialect many HW module helpers were updated to support these new attributes.

The HW pass StripDebugInfoWithPred now strips location information from the port location attributes.

The HW pass FlattenIO was modified to spread the locations to flattened ports the same way as LowerTypes, as well as fix the block locations which were removed by signature conversion.

HWArithToHWPass restores the block argument locations after SignatureConversion deletes them

ExportVerilog was updated to allow the printing of location attributes directly, instead of taking a set of operations.  Some printer bugs were fixed here especially around consecutive 0-width ports, and some better alignment.  See `test/Conversion/ExportVerilog/port-decl-sharing.mlir` for some tests. @dtzSiFive Will you please take a look at these changes, I see sometimes we are using nbsp and other times space literals and I don't know the difference.

ExportVerilog now always prints the closing `);` on a newline when there is a non-empty port-list.  This was needed to support trailing location comments.  Technically, we could still print it on the same line when location information is not emitted for the last port in the list, but I didn't consider it worth the effort. As an example:
```verilog
// Was:
module Foo(
  output [3:0] if_0);

// Now:
module Foo(
  output [3:0] if_0 // foo.scala:10:20
);
``` 

The MSFT and SystemC dialects has to be updated to support these new attributes.  The MSFT module was updated to support the same form of location attributes as HW modules.  SystemC modules are, for now, using the common functionality but throwing away the attributes. This way, we could maintain a common set of code for creating, parsing, printing, updating modules.

Added a verifier to the MSFTModuleOp that made sure that the location attributes matched the block argument attributes

The ESI ESIPortsPass was updated to spread the locations of `ChannelTypes` to the ready/valid ports it lowers them to.

MSFTPartition pass now preserves the location information.

The python bindings were updated to attach these new attributes to `HWModuleOp`s.  These location always default to `unkown`, for the time being. Since `LocationAttr`s are not represented in the upstream MLIR API, we had to create the attribute by calling out to the MLIR parser.
2023-02-03 10:59:43 -08:00
Hideto Ueno 945c2a83a9
[LowerToHW] Lower aggregate constant (#4608)
This PR reimplements #4451 revered by #4465. The bug was that `getOrCreateAggregateConstantAttribute` re-used IntegerAttribute used by firrtl.aggregateconstant op. In FIRRTL dialect, integer attrs are APSIntAttr, which aren't compatible with normal integer attributes. 103e595556 includes a fix to explicitly convert APSIntAttr into normal integer attrs.
2023-02-03 18:07:00 +09:00
Mike Urbach b798060130 [AffineToPipeline] Fix side-effect within assertion.
This moves the side-effecting call (`insertDependence`) out of an
assert. It still asserts the call succeeded.

Fixes https://github.com/llvm/circt/issues/4614.
2023-02-02 11:52:59 -07:00
Mike Urbach a249d6e1df
Bump LLVM to 95e49f5a74c9e79778a62cc58b15875613cf9e59. (#4609)
Co-authored-by: Ram Sunder <ram.sunder@sifive.com>
2023-02-02 10:25:02 -07:00
Andrew Young da062b1225 [MSFT] Fix handling of inout block arguments
This fixes a problem where we do not respect the `isInOut` flag of the
PortInfo when adding block arguments. This bug has already been fixed in
HWModuleOps.  This also adds verifiers are taken from the HW module op.
2023-02-02 09:07:00 -08:00
Andrew Young 321948dc3d [HW] Fix creating modules with InOut typed ports
When we create the PortInfo object for a module, if the port is a
HW::InOutType, we strip it and set the isInOut field to true.  When we create a
module from a PortInfo object we respect this field while constructing the
function type, but were not respecting the isInOut when creating the block
arguments.

This change starts respecting the `isInOut` field of port info when
constructing the block argument types.  This also adds a verifier that the
function type of the module matches the block argument types.
2023-02-02 09:07:00 -08:00
Andrew Young 2417e7f403
[FIRRTL][GC] Always generate the scope yaml file (#4612)
When we added the flag to directly instantiate companions, we also
stopped generating interfaces.  This flag skipped generating the
interface metadata file, which caused issues for flows which still
expected it to be generated.  This commit changes the logic to skip
adding interfaces to the worklist instead of an early break, which
causes us to still generate the metadata, but with no entries.
2023-02-02 09:01:57 -08:00
Matt H 17f758c76a
[Pipeline] Plumb values through the pipeline + Support multi-cycle Ops (#4414)
* explicit plumbing of values through the pipeline given gap between arrival time and use time
2023-02-01 13:43:45 -05:00
John Demme a83f6d914d
[PyCDE] Type system refactoring (#4604)
- Hide the CIRCT type behind `Type` -- most of the changes stem from this change.
- Uniquify PyCDE types.
- Renames: mostly remove "Type" from names. Allows one to use `UInt(3)`.
- Improve type string representations.
2023-01-31 18:17:34 -08:00