Commit Graph

1970 Commits

Author SHA1 Message Date
Anurudh Peduri c7330745e5
[Comb] remove redundant builders - use InferTypeOpInterface instead. (#1718)
* [Comb] remove redundant builders - use InferTypeOpInterface instead.
2021-09-04 13:13:25 -07:00
Morten Borup Petersen 44229b44cd
[Calyx] Add emitters for library operations (#1711)
This commit also refactors value emission for instance ops into a generic version based on the cell interface.
2021-09-04 11:04:12 +01:00
Morten Borup Petersen bb8738daf5
[Calyx] Rewrite isPortDrivenByGroup based on Cell interface (#1713) 2021-09-04 10:59:56 +01:00
cgyurgyik 7e64763fed [Calyx] [obvious] formmating. 2021-09-03 22:36:45 -07:00
Chris Gyurgyik 91d3c9be74
[Calyx] Verify the component does something. (#1721) 2021-09-03 22:03:06 -07:00
Chris Gyurgyik bff5e261d2
Add a clock port to the MemoryOp (#1720)
Add a clk port to the MemoryOp
2021-09-03 21:58:14 -07:00
John Demme 730b157be5
[MSFT] DeviceDB C API and Python bindings (#1717) 2021-09-03 20:12:16 -07:00
Andrew Lenharth e28a369934 [NFC] Fix some comments 2021-09-03 21:20:56 -05:00
John Demme 402c110501
[MSFT] Device DB for placed instances (#1704)
- Introduces the DeviceDB class to store spatial data regarding placed instances.
- Adapts ExportTcl to use it, reporting out conflicts.
2021-09-03 17:57:55 -07:00
Fabian Schuiki f002825bd6
[FIREmitter] Add a FIR emitter (#1492)
Add an emitter to export FIRRTL dialect as a .fir file. This is a first
shot at such an emitter, with no output formatting options and no
opinion on output code quality. Expressions for example are all simply
emitted inline, which can lead to some rather nasty nesting and
repetition. Supports pretty much all FIRRTL ops that the `FIRParser`
would generate, except `MemoryPortOp`, `CMemOp`, `MemOp`, and `SMemOp`.

This came out of a quick hacking sprint towards a FIR reduction and
register/wire isolation tool to facilitate debugging.
2021-09-03 20:27:52 +02:00
Martin Erhart 36323daa35
[LLHD] Replace llhd.const with hw.constant (#1702) 2021-09-03 10:19:37 +02:00
Morten Borup Petersen 236a727d21 [Calyx] Add more primitive std operators 2021-09-03 08:43:36 +01:00
Morten Borup Petersen 0957165650
[Calyx] Add a primitive cell instance operation (#1636)
* [Calyx] Add standard library primitive operators

The available operations map to the [native Calyx logical and primitive operations](https://github.com/cucapra/calyx/blob/master/primitives/core.futil).
2021-09-03 08:06:38 +01:00
Fabian Schuiki 47525596e6
[FIRRTL] Clean up generated type parser/printer use (#1637)
Calling `parseFIRRTLType` and `FIRRTLType::print` would currently only
consider the hand-written type parsers and printers. On the other hand,
using the dialect hooks `FIRRTLDialect::parseType` and
`FIRRTLDialect::printType` would properly try to apply the generated
parsers and printers first, and then resort to the manual
implementations.

This commit fixes the inconsistency by introducing local `parseType` and
`printType` functions which appropriately try the generated and the
custom printer/parser to do the work. This decouples generated/custom
implementations from whether a type inherits from `FIRRTLType` or not.
(There are some helper types around `cmemory` that currently do not
inherit from `FIRRTLType`.)

`parseFIRRTLType` then simply calls these functions and performs a
dynamic cast to `FIRRTLType`.
2021-09-03 08:43:18 +02:00
Hanchen Ye 21b757a026
[FSM] Add FSM operations (#1638) 2021-09-02 16:41:04 -05:00
Chris Gyurgyik db49881b25
[Calyx] Update verification of AssignOp to include Cells. (#1697) 2021-09-02 08:36:16 -07:00
Morten Borup Petersen 35c09f2d65
Partially revert #1688 in favor of style used in upstream MLIR (#1698) 2021-09-02 12:32:07 +01:00
John Demme 0066f6dc79
[MSFT] Introduce `RootedInstancePath` and re-factor based on it (#1689)
A RootedInstancePath is just an instance path prepended with the root (aka top) module which the instance path is relative to. If we structure the placements based on this, we no longer have to walk the instance hierarchy while exporting TCL! This patch also removes support for locations not inside of instance switches. That use case required the design be fully elaborated which isn't really done.
2021-09-01 17:41:06 -07:00
mikeurbach a16330a5d9
[Calyx] Add a CellInterface to replace the Cell trait. (#1695)
Besides detecting if an operation "is a Cell", this allows some useful
helpers to be defined. Some existing code is refactored to use them.
2021-09-01 16:57:16 -06:00
John Demme 221e2db01c
Update LLVM submodule (#1687)
Co-authored-by: Andrew Young <youngar17@gmail.com>
2021-09-01 12:46:54 -07:00
Chris Lattner 0c7fa4e3ec [ExportVerilog] Don't force a sign on the RHS of a shift operator.
SystemVerilog is very clear that these are 'self determined' operands
that don't participate in sign inference of >>> operators, and whose
value is always treated as an unsigned value.
2021-09-01 10:58:25 -07:00
Chris Lattner 31070d0e71 [ExportVerilog] Fix Issue #1681, miscompile of >>> operator.
It turns out that Verilog has some weird context sensitive sign inference
thing going on that affects the result type of the >>> operator and causes
it to do an unsigned shift.  I cannot pin down how or why this happens,
so we'll just emit redundant $signed() casts around the operator to make sure
it is controlled appropriately.

I don't feel very good about not understanding this from reading the spec,
but empirically this is how it works with verilog implementations.
2021-09-01 10:54:50 -07:00
Morten Borup Petersen c227f5c3d3
Add boilerplate for an "Analysis" library (#1688)
This commit adds necessary files and code for adding new code under an "Analysis" folder.
2021-09-01 18:12:55 +01:00
Chris Gyurgyik 362cef7d67
[Calyx] Emitter only imports a library if necessary. (#1686)
Adds a struct that walks the program to determine which libraries are necessary to be imported for the 
native Calyx compiler. This is a very simple approach that isn't looking to optimize anything, since the 
# of operations and # of import is relatively small.
2021-09-01 09:20:44 -07:00
Fabian Schuiki 62e7ae3c91
[ExportVerilog] Add verifLabels lowering option (#1693)
Add the `verifLabels` lowering option which assigns an automatically
generated label to all verification statements (assert/assume/cover)
that have no label specified. This works around the issue of
verification EDA tools commonly requiring all verification statements to
be labeled.

This commit adds the labels of these ops to the name manager in the
ExportVerilog prepass, and then uses the manager to uniquify a generic
label generated for unlabeled ops in case the `verifLabels` option is
set.

Fixes #1691.
2021-09-01 17:30:53 +02:00
Andrew Young 6dec086f06
[ExportVerilog] Add always_comb lowering option (#1684)
This add an option to control how `always_comb` is printed by the
verilog exporter.  The default has been changed to print `always_comb`
as `always @(*)`. A lowering option `alwaysComb` has been added, similar
to `alwaysFF`, to use the old printing style.  This change is motivated
by a lack of tool support for the `always_comb` verilog construct.
2021-08-31 18:30:06 -07:00
Chris Gyurgyik c634edc39b
Add assert for modulo wrap. (#1683)
Assertion added to avoid unintended wrap in the indentation.
2021-08-31 18:04:37 -07:00
Chris Gyurgyik 77a1774177
Add ParOp. (#1676)
Adds a Parallel Operation to the Calyx dialect.
2021-08-31 17:24:35 -07:00
Andrew Lenharth 74a97aa8ef
[FIRRTL] Non local annotation scattering (#1682)
Generate NonLocalAnchor and scatter them when parsing firrtl annotation files.
2021-08-31 18:17:48 -05:00
Chris Lattner 05c7a1310c [ExportVerilog] Implement 'disallowLocalVariables' for non-SV compatibility.
This implements `disallowLocalVariables` lowering option with a simple approach:
have ExportVerilog move roughly all expressions to the top level.  This ensures
we don't need to generate automatic temporary variables, which aren't compatible
with classic-verilog consumers.
2021-08-31 13:52:07 -07:00
Anurudh Peduri 34832f42df
[LLHD] Replace llhd.neg with comb.sub (#1654) (#1678)
* [LLHD] Replace llhd.neg with comb.sub (#1654)

* [LLHD][test] remove repeated test for `comb.sub`
2021-08-31 18:21:10 +02:00
Andrew Lenharth ba9c344ace
[FIRTOOL] Allow multiple annotation files (#1674)
A build flow might have multiple annotation files. Allow passing them all.

Co-authored-by: Prithayan Barua <prithayan@gmail.com>
2021-08-31 09:08:45 -05:00
Schuyler Eldridge 8ae1b2857e
[FIRRTL] Fix Subfield/Subindex DontTouch Parsing
Fix a bug in the parser where a DontTouchAnnotation on a subfield would
not cause names to be preserved.  Use the simplest solution here of
using the hasDontTouch method of AnnotationSet as opposed to the older
version of the method of the same name in the parser.  Remove the old
hasDontTouch method in the parser (since this is now unused).

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-31 00:34:24 -04:00
Chris Gyurgyik f99cd12c72
[Calyx] Add more operations for emission to native compiler. (#1662)
Adds emitters for: RegisterOp, MemoryOp, GroupGoOp, GroupDoneOp, SeqOp, 
WhileOp, IfOp, EnableOp, combinational guards. Remove HasParent trait from 
MemoryOp since this is checked by the Cell trait (inherited by CalyxCell). Move 
base class for CalyxPrimitive to CalyxPrimitives.td. Add helper functions for string
literals. Add simple emitter for imports.
2021-08-30 19:34:37 -07:00
Schuyler Eldridge 7e06c705c1
[FIRRTL] Don't fold regreset away if don't touch'd
Add a check that the foldResetMux rewrite pattern isn't used for
firrtl.regreset if the reset has a DontTouchAnnotation.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-30 19:58:57 -04:00
Hanchen Ye bbecc5fc2b
[FSM] Add an empty FSM dialect (#1671) 2021-08-30 17:28:46 -05:00
Martin Erhart 8b5f5e216b
[LLHD] Use integer, array and struct types from HW dialect (#1669)
* [LLHD] Use integer, array and struct types from HW dialect

* Simplify HWDialect declaration
2021-08-30 23:02:16 +02:00
Andrew Lenharth e9763ffc08
[FIRRT] use a cached symbol table for resolution of modules (#1673)
Let passes use a prepopulated symbol table to resolve modules for instances.
2021-08-30 15:30:34 -05:00
Andrew Lenharth e29ecdae62 [FIRRTL] Only resolve symbol once per instance 2021-08-30 15:01:17 -05:00
Chris Gyurgyik 216e07fdc4
[Calyx] Add verifier for AssignOp. (#1661)
Add verifier for AssignOp. This does NOT address drive-ability of `Cell`s.
2021-08-30 11:17:00 -07:00
Fabian Schuiki 1a81fae165
[FIRRTL] Add data taps integration test, fix issues (#1664)
Add the `DataTapTests` from the Scala implementation of FIRRTL as an
integration test for the FIRRTL dialect. This uncovers a few subtle
breakages in the `GrandCentralTaps` introduced by changes to the
annotation scattering code that happened a while back. This fixes those
issues and the test ensures we don't have any regressions of this in the
future.
2021-08-30 17:34:15 +02:00
Andrew Lenharth ec6cfbcdb1
[NFC][FIRRTL] FModuleLike to provide nicer-typed accessors for things you can take instance of (#1650)
Get rid of globals used to unify code for FModule and FExtModule and replace it with FModuleLike interface.
2021-08-30 10:16:43 -05:00
Andrew Lenharth 693a2e2480 [FIRRTL] Add some more aggregate type manipulation utils 2021-08-30 10:14:37 -05:00
Martin Erhart 9146f17b83
[LLHD] Replace standard dialect arithmetic ops with comb ops (#1660)
* [LLHD] Replace standard dialect arithmetic ops with comb ops

* Small fixes

* comb.icmp support

* Support remaining operations

* Small fix
2021-08-30 16:00:56 +02:00
Morten Borup Petersen e371b23583 [Calyx] Fix typo in MemoryOp builder
An "instanceName" attribute is expected for a Cell, not a "name".
2021-08-30 13:36:01 +01:00
Chris Lattner 8197ffd2ec [SV/BindOp] Give sv.bind a symbol for the module enclosing the referenced instance.
This makes lookup much faster, even though it still requires IR scanning.
This speeds up `firtool -extract-test-code -verilog` on a large design from
550s to 120s.  There is still more to go though, as a -verify-each=false
run completes in 60s - we're still spending more time verifying than doing
work.

This resolves issue #1647.
2021-08-29 09:01:32 -07:00
Chris Lattner 3c8b4b47b6 [ExportVerilog] Introduce a new "disallowLocalVariables" lowering option.
This is the first step to supporting verilog implementations like Yosys
and Icarus Verilog that don't support SystemVerilog "automatic logic"
variables in procedural scopes.

For this step we handle side effecting operations (like the RANDOM
macros in FIRRTL lowering) by spilling them to a local reg with a
blocking assignment, the same way SFC does.

This is one step towards resolving Issue #1633
2021-08-28 21:40:22 -07:00
Chris Lattner 5cdf159eea [ExportVerilog] Make isVerilogExpression available to the Prepare pass, NFC. 2021-08-28 21:18:58 -07:00
Chris Lattner 519561658a [PrettifyVerilog] Don't sink side-effecting expressions.
We don't want to change where the effects happen.  This was noticed
by inspection.
2021-08-28 21:01:26 -07:00
Chris Lattner ea883673b4 [ExportVerilog] Emit a loc comment on modules with location info.
FIRRTL files coming out of chisel don't seem to preserve module
locations typically even though they could, but other clients can
produce location info for them, and we should print it.
2021-08-28 17:42:12 -07:00
Chris Lattner 6821299c90 [LowerToHW] Move FIRRTLMem modules and give them a location.
Use of UnknownLoc is not encouraged.  Moving their insertion point
ensures the that file header boilerplate comes out on top.
2021-08-28 17:19:30 -07:00
Chris Lattner 7027a826ac [VerilogEmitter] Fix a race with sv.binds inside of hw.modules.
It turns out that sv.bind can exist inside of a hw.module as well
as at the top level.  These cause non-local references so we need
to make sure not to emit such modules concurrently with the modules
being emitted.

There is no good test for this, I noticed it due to a transient
failure of the existing ExportVerilog/sv-dialect.mlir test.
2021-08-28 12:32:06 -07:00
Andrew Young cf28c165da
[FIRParser] Support parsing larger vector sizes (#1651)
Using an `int32_t` to parse vector types limits our maximum vector
length to 2147483647. We have memory length 1 higher than that maximum,
and we need to use the `int64_t` parser to support it.
2021-08-28 12:20:48 -07:00
Chris Lattner 6a09c52db9 [IMConstProp] Use InstanceGraph more instead of calling "getReferencedModule".
getReferencedModule is a performance tarpit because it has to scan the top
level of the circuit to find the right module.   We already have the
instance graph, we should use it for all lookups.

This speeds up IMConstProp on a large testcase from 24s to 6.3s.
2021-08-28 12:01:34 -07:00
Morten Borup Petersen 5e3c116ce6 [Handshake] Rename dialect from "HandshakeOps" to "Handshake" 2021-08-28 09:03:30 +01:00
Morten Borup Petersen 036a2f2c54
[Handshake] Refactor inclusion of Handshake TableGen'erated files (#1648)
* [Handshake] Refactor handshake tablegen files

No functional changes; this commit creates an identical structure to the rest of the dialects in CIRCT wrt. how and where the various TableGen'erated files are included.
2021-08-28 09:01:10 +01:00
Martin Erhart f5055566f4
[LLHD] Use comb dialects ops where possible (#1649)
* [LLHD] Use comb dialects ops where possible

* Clang-format

* Remove redundant code

* Remove unused includes, add tests, remove redundant code
2021-08-28 08:39:06 +02:00
Chris Lattner 62e02ac1f8 [ExportVerilog] Parallelize printing in the single-file case. NFC.
This parallelizes emission of operations when they are all emitted
to the same file by emitting to string buffers, then concatenating
them all at the end in series (simple map+reduce).

This speeds up emission of a large testcase on my laptop from 17s
to 5.2s, a 3.2x speedup.
2021-08-27 23:35:29 -07:00
Chris Lattner 90418d581c [ExportVerilog] Refactor file emission logic even more. NFC.
This splits the decision of "how to emit ops" from the "mechanics
of emitting them" logic by introducing a new StringOrOpToEmit
struct.
2021-08-27 23:04:18 -07:00
Chris Lattner 3508495800 [ExportVerilog] Print extern modules to only one file in split files mode.
This emits them all to a single extern_modules.sv file, instead of
replicating them in every .sv file.  This resolves Issue #1646.
2021-08-27 22:16:05 -07:00
Chris Lattner a08794cd1c [ExportVerilog] Further narrow the interface used by SharedEmitterState::emitOperation. NFC. 2021-08-27 21:36:35 -07:00
Chris Lattner 3a85c9aa03 [ExportVerilog] Further refactor interface to emitHWModule. NFC.
This pulls "prepare" pass invocation into it, reducing coupling.
2021-08-27 21:31:25 -07:00
Chris Lattner fdca31f460 [ExportVerilog] Refactor the "prepareHWModule" invocation, NFC.
This makes it part of the parallel emission when emitting split files,
and avoids having to keep the `ModuleNameManager` in memory for every
module in the circuit before emitting each file.  This speeds up
split-verilog emission on a large design from 8.3s to 5.8s (~30%).
2021-08-27 21:26:18 -07:00
Chris Lattner 18d7cf2050 [SVExtractTestCode] Put generated modules next to the thing we extracted from.
Previously all the extracted assert/assume modules were put at the top of the
file.  This is a problem because the #ifdef boilerplate needs to come first.
2021-08-27 18:09:47 -07:00
Chris Lattner e5f29613d3 [ExportVerilog] Use SymbolCache in the prepare pass to speed up lookups.
These aren't common, but might as use this since it is available.
2021-08-27 17:55:28 -07:00
Chris Lattner e58d682422 [HW] Make SymbolCache references const correct. NFC. 2021-08-27 17:54:56 -07:00
Chris Lattner 143acdf04b [ExportVerilog] Adopt hw::SymbolCache to speed things up, NFC.
This builds a SymbolCache at setup time, when the verilog exporter
is scanning the ops to see what files they go into.  This cache is
then used when emitting each of the chunks, speeding up the
"getReferencedFoo" calls by turning them into O(1) lookups.

This speeds up export verilog on a large testcase that includes a
bunch of binds from 126s to 17s.  It should also help speedup
other normal cases as well, since each instance has to resolve the
module it refers to.
2021-08-27 17:42:29 -07:00
Chris Lattner 8348c2144c [HW] Introduce a new hw::SymbolCache class to accelerate symbol lookups.
The HW/SV dialects have a bunch of symbols used to map instances, modules,
interfaces etc, and corresponding "getReferencedXXX" methods to resolve
them.  Each of these resolutions is really slow - scanning huge amounts of
the IR to resolve them, so we should have a way to shortcut that when a
client has done a prepass.  The SymbolCache class allows making these faster.

This patch introduces the new functionality, but no clients of it.
2021-08-27 17:41:36 -07:00
Andrew Young 496d54347a
[FIRRTL] Fix crashing regreset canonicalizer
This crashes if `reg.resetValue()` is a block argument and return
`getDefiningOp()` returns nullptr.
2021-08-27 17:36:51 -07:00
Chris Lattner e5b74d2806 Make use of a helper function to simplify some code, NFC. 2021-08-27 17:15:04 -07:00
Chris Lattner 78986e364c [ExportVerilog] Split all the PrepareForEmission stuff out to its own file.
ExportVerilog.cpp is too monolithic, and the logic for this was scattered
around the file.  Pull it together into its own thing.
2021-08-27 14:41:15 -07:00
Fabian Schuiki 8b3aa8c61b
[FIRRTL] Resolve portAnnotations/arg_attrs ambiguity (#1645)
Most of the FIRRTL code base expects port annotations to live in the
`portAnnotations` attribute on `FModuleOp` and `FExtModuleOp`. But the
parser, printer, and some operation builders accidentally store these in
`arg_attrs` through the standard argument attribute mechanism of MLIR.

This commit removes redundant/conflicting uses of `arg_attrs` and
`portAnnotations` in the code base. To keep things ergonomic for the
custom syntax of FIRRTL operations, we still parse and print port
annotations as part of the regular argument attributes (under the
`firrtl.annotations` key), but then immediately separate them out into
the `portAnnotations` attribute where all of our code expects this to
live.
2021-08-27 21:55:22 +02:00
Chris Lattner 49e5cdd668 [ExportVerilog] Refactor RootEmitterBase and subclasses, NFC.
This renames RootEmitterBase -> SharedEmitterState and eliminates
the subclasses.  The code is shorter and easier to understand without
them.
2021-08-27 12:37:01 -07:00
Chris Lattner 83f5500ac8 [firtool] Tidy up some logic, NFC.
No need for "else" after "return" etc.
2021-08-27 12:25:12 -07:00
Andrew Young 4d53480649
[LowerCHIRRTL] Fix inifinite loop in memory direction inference
When infering the direction of a CHIRRTL memory, we look through
subindexes, subfields, and subaccesses looking for connect ops which
could be reading or writing to the memory.  The code to look through
subaccess was broken, leading to an infinite loop. This properly
recurses on the results of the subaccess op instead of the input.
2021-08-26 23:57:31 -07:00
Chris Lattner 3bfa88c4c8 [Comb] Enhance the "extract(sext(x))" rewrite to be smarter about extracting from known sign bits. 2021-08-25 17:13:15 -07:00
Chris Lattner 242ca233d0 [Comb] Canonicalize extract(sext(x) to extract(x) or a smaller sext when possible.
This improves the example in Issue #1639 to:

```
  assign tmp1972 = {inp_db, 1'h0};
```
2021-08-25 16:16:29 -07:00
Andrew Young 9190ea7136
[Comb] Fix shift by constant canonicalizers (#1640)
The shift by constant canonicalizers extract the relevant bits from the
value and prepend/append 0s depending on the direction shifted. The
canonicalizer made a mistake in the extract op generation, chopping off
the high bits when shifting right, and chopping off the low bits when
shifting left. When doing a signed ShrS, it was using the low bit of the value
as the sign bit.
2021-08-25 13:25:36 -07:00
Schuyler Eldridge 6855db960f
[SV] Check that PAssign, BPAssign don't drive Wire (#1628)
Add a verifier to check that sv.passign and sv.bpassign don't drive an
sv.wire.  An sv.wire is a net type and can only be driven by sv.assign.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-25 13:31:01 -04:00
Chris Gyurgyik 307debe3b0
[Calyx] Add helper functions to access RegisterOp ports. (#1634)
Add helper functions to access RegisterOp ports. Each RegisterOp port specifies a specific port value, e.g. `Result(0)` is the `in` port.
2021-08-25 10:28:06 -07:00
mikeurbach eb6b1781c1
[Calyx] Add a MemoryOp primitive. (#1632)
This follows a similar approach to the RegisterOp. Rather than
defining different primitives for different numbers of dimensions like
the Rust compiler, this uses a single operation to represent any
n-dimensional memory.

This generality means we can't enumerate explicit return types.
Rather, the return type is a variadic list of signless integer types.
A helper build method is provided to support this from C++ code, and a
verifier ensures everything lines up.

This also includes a helpful builder for RegisterOp.
2021-08-24 21:14:47 -06:00
Chris Lattner bdd4c30ed9 [HWLegalizeModules] Emit a default case for the last casez entry.
We do this even for fully-covered cases in case the synthesis tool
isn't smart enough to know that it is fully covered.  xref Issue #1592
2021-08-24 16:16:23 -07:00
Schuyler Eldridge 2abd6b7139
[HWMemSimImpl] Remove procedural assign to wire (#1627)
Fix HWMemSimImpl bug where a wire was being procedurally assigned in RW
port code generation.  Update the associated test to reflect this
change.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-24 10:30:58 -04:00
Schuyler Eldridge e218e1c6fe
[HWLegalizeNames] Fix case order
Fix bug in HWLegalizeNames where the case order was generated in reverse
order.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-23 17:07:26 -04:00
Julian Oppermann c07a9ee213
[Scheduling] [3/3] Add scheduler for shared pipelined operators problem: Heuristic algorithm. (#1622)
Finally, add the actual heuristic algorithm, and enable the tests.
2021-08-23 22:15:06 +02:00
Julian Oppermann 44b3fa2b3c
[Scheduling] [2/3] Add scheduler for shared pipelined operators problem: Tableau transformations. (#1621)
This implements the tableau transformations necessary to fix an operation's start time to a certain value.
2021-08-23 21:14:27 +02:00
Julian Oppermann ae1a177f91
[Scheduling] [1/3] Add scheduler for shared pipelined operators problem: Preparations. (#1620)
- Add parameter S to the simplex tableau.
- Keep track of variable locations in the tableau.
- Add entry point in Algorithms.h.
- Set up test pass, prepare test cases.
2021-08-23 19:46:38 +02:00
Schuyler Eldridge c417f11a8d
[HWLegalizeModules] sv.reg, bpassign in mux casez
Change lowering of muxes to casez to use legal Verilog.  Change a wire
driven in an always block to be a reg.  Change non-blocking assignment
to blocking assignment per Verilator lint suggestion.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-23 10:59:01 -04:00
Chris Lattner f6f7d498b1 [ExportVerilog] Indent temporaries correctly when generated from ifdef blocks.
We're previously take the current indentation level, which mismatches
the indent of the insertion point.  This fixes Issue #1625.
2021-08-22 15:55:49 -07:00
Chris Lattner c25ae23e51 [ExportVerilog] Greatly generalize inline-init printing for 'automatic logic's
This allows us to emit an arbitrary expression tree inline so long as
it is safe, including _tmp values generated to avoid line length
restrictions.  This inlines most of them in practice.

This shrinks #lines of a large testcase I play with by 5%.
2021-08-22 15:35:29 -07:00
Chris Lattner b504edeb77 [ExportVerilog] Don't duplicate sv.verbatim.expr.se nodes.
The verilog printer duplicates small verbatim expressions even if
they are used multiple times.  This isn't safe to do for
side-effecting verbatims though, since the side effect will happen
multiple times.

Noticed by inspection.
2021-08-22 15:18:43 -07:00
Chris Lattner 1bdba0b844 [ExportVerilog] Emit some verbatim exprs into automatic logic inits.
This generalizes support for emitting inline initializers "just a
little bit".  This is technically enough to resolve Issue #1567,
but there is more to do.
2021-08-22 14:08:39 -07:00
Chris Lattner 01380a3ad3 [ExportVerilog] Refactor out of line expression emission, NFC.
We previously had a bunch of special cases for constants that
worked but was a bit fragile. The issue is that there was coupling
between stuff that "knew" that out-of-line constants in procedural
regions are emitted in the declaration.

Clean this up a bit by adding a expressionsEmittedIntoDecl set,
which makes this more explicit and easier to generalize.

NFC.
2021-08-22 13:45:12 -07:00
Chris Lattner 5a114f2c35 [ExportVerilog] Elide unnecessary zero extensions on the RHS of shifts.
The RHS of a shift doesn't have to match the LHS, it has "self
determined" width according to the spec.

This resolves issue #1569.
2021-08-22 12:00:17 -07:00
Chris Lattner ae9a7a33f2 [SV/HW] rename the "odsBuilder" parameter to "builder" NFC.
This is a more correct description of what this is, these don't
come from ODS necessarily.
2021-08-21 17:30:00 -07:00
Chris Lattner c6e386e601 [HWLegalizeModules] Give generated wires (somewhat) useful names 2021-08-21 17:25:01 -07:00
Chris Lattner 79a17fa100 [HWLegalizeModules] Legalize arraycreate/get into casez.
Tools like Yosys don't support packed arrays, and we recently started
pattern matching mux chains into them.  Teach HWLegalizeModules about
this idiom, lowering it into casez statements instead.  This produces
uglier but more compatible verilog.  For example, without this flag,
we produce things like:

  wire [3:0][2:0] _T_83 = {{_T_15}, {_T_14}, {_T_13}, {_T_12}};
  wire [3:0][2:0] _T_84 = {{_T_9}, {_T_8}, {_T_7}, {_T_6}};
  wire _T_85 = _T_83[Queue_1_io_deq_bits_id] != _T_84[Queue_1_io_deq_bits_id];

with this flag we produce things like:

  always_comb begin
    casez (Queue_1_io_deq_bits_id)
      2'b00:
        _T_1 <= _T_15;
      2'b01:
        _T_1 <= _T_14;
      2'b10:
        _T_1 <= _T_13;
      2'b11:
        _T_1 <= _T_12;
    endcase
  end // always_comb
  always_comb begin
    casez (Queue_1_io_deq_bits_id)
      2'b00:
        _T_2 <= _T_9;
      2'b01:
        _T_2 <= _T_8;
      2'b10:
        _T_2 <= _T_7;
      2'b11:
        _T_2 <= _T_6;
    endcase
  end // always_comb
  wire _T_79 = _T_1 != _T_2;

This is enabled by passing -lowering-options=disallowPackedArrays to
firtool.  This fixes Issue #1592.
2021-08-21 17:14:18 -07:00
Chris Lattner 199613a9cf [SV] Improve the sv.casez accessors and C++ API to make it easier to work with, NFC. 2021-08-21 17:12:55 -07:00
Chris Lattner f64a15d683 [LoweringOptions] Add serialization of 'disallowPackedArrays' to a string.
Without this, the `-lowering-options=disallowPackedArrays` flag doesn't
work on the firtool command line.
2021-08-21 17:12:01 -07:00
Andrew Young 7d25db6087
[Comb] Link CIRCTSupport for LoweringOptions (#1619)
This should fix the CI builds.
2021-08-21 15:41:25 -07:00
Chris Lattner 7ccdb3d8cc [hw] Introduce a HWLegalizeModules pass and a new `disallowPackedArrays` lowering option.
This pass provides a structured way to handle IR features that are not
supported by all tools, and this lowering option reflects a specific
limitation of the Yosys tool.

Right now the pass isn't super helpful: it just rejects unsupported operations
with an error.  This is progress towards Issue #1592.
2021-08-21 13:28:09 -07:00
Andrew Young 090856418b
[FIRRTL][LowerCHIRRTL] Fix windows build
The Windows+MSVC build doesn't like the constructor used for APInt.
Removing the third argument, which is default false, unsticks the build.
2021-08-21 13:23:05 -07:00
Andrew Young 0a0ee65287
[FIRRTL] Implement SFC's RemoveCHIRRTL pass (#1540)
This adds an implementation of the RemoveCHIRRTL pass called
LowerCHIRRTL.  This pass takes the CHIRRTL memory operations, `seqmem`
and `combmem`, and transforms them into standard FIRRTL `mem`
operations.
2021-08-21 12:23:56 -07:00
Chris Lattner 3b1a6a28b9 [Comb] Simplify KnownBitsAnalysis using llvm::KnownBits.
Thanks for @fyquah for pointing out this class, which takes a lot
of the algebraic stuff out of CIRCT.
2021-08-21 11:48:55 -07:00
John Demme 542fd31c99
[PyCDE] Instance placement API (#1615) 2021-08-20 19:08:51 -07:00
Andrew Lenharth 3dd0638e2a
[FIRRTL][NFC] Add portAnnotations to FModule and FExtModule (#1607)
Add an explicit attribute for port annotations to FModule and FExtModule.  Adding a common name for port annotations, similar to instance, mem, etc, makes manipulating annotations simpler.  Although this could be folded into argattr, having it in the same format as used in other ops makes annotation scatting able to be operation type invariant, thus simplifying it.
2021-08-20 18:26:43 -05:00
John Demme 3ad8be3d88
[MSFT] [Python] Add a function to get an instance (#1613)
Given a root module and an instance path, find the corresponding instance from
the instance hierarchy. Return 'None' if the path wasn't found.
2021-08-20 13:57:35 -07:00
Chris Lattner 14a7212050 [Comb] Fold `extract(lowBit, shl(1, x))` -> `x == lowBit`
This cleans up some onehot patterns, and exposes secondary
optimizations.
2021-08-19 14:32:03 -07:00
Julian Oppermann 1e8c931e20
[Scheduling] [NFC] Adhere more closely to notation in the paper. (#1610) 2021-08-19 17:24:18 +02:00
Fabian Schuiki 499cd357ca
[LLHD] Add C API
Add a minimal C API for the LLHD dialect.
2021-08-19 17:11:43 +02:00
Morten Borup Petersen 5c3422518c
[Calyx] Add IR support for calyx::WhileOp (#1605)
* [Calyx] Add IR support for calyx::WhileOp

This commit adds support for the Calyx While control operation. The operation takes two arguments; a boolean port and a group name. The op has a single body region representing the groups to execute when the condition evaluates to true.

This is solely for IR support and does not include:
- CalyxEmitter support (unsupported for all control ops as of now)
- CompileControl control FSM generation
2021-08-19 08:52:02 +01:00
John Demme 43ccc6584e
[MSFT] [Py] Add physical location and switch instance attributes to python module (#1606) 2021-08-18 20:03:07 -07:00
John Demme 21485874c8
[llvm] Update submodule to latest (#1589)
Co-authored-by: Andrew Lenharth <andrew@lenharth.org>
Co-authored-by: Fabian Schuiki <fabian@schuiki.ch>
Co-authored-by: Andrew Young <youngar17@gmail.com>
2021-08-18 19:37:43 -07:00
Chris Lattner b1ff19677b [Comb] Teach extract folding to look through and/or/xor ops.
With other changes, it is pretty common to end up with a logic op
that doesn't affect the extract.  This implements Issue #1581
2021-08-18 18:08:18 -07:00
Chris Lattner 15e0c6e3e6 [Comb] Teach KnownBitAnalysis about xor and mux. 2021-08-18 16:37:46 -07:00
Chris Lattner 5e64983bf1 [Comb] Move "KnownBitAnalysis" out to its own .cpp file. NFC. 2021-08-18 16:09:22 -07:00
Chris Lattner 6380ae214a [SExtOp] Canonicalize away sext when the sign bit of the operand is known.
This seems to happen a lot when signed operators (like + on SInt in
Chisel) is used on operands that happen to have a known top bit.
2021-08-18 16:00:29 -07:00
Chris Lattner 66791e08f0 [PrettifyVerilog] Sink instances to the end of the module.
This improves verilog emission quality because it allows expressions
to be inlined into input ports of the module.  This eliminates some
extranous wires, shrinking `wc -l` on a big testcase by 3%.  This
fixes Issue #1568
2021-08-18 15:37:38 -07:00
Chris Lattner 92f78c0cc8 [PrettifyVerilog] Sink multiple user expression to NCA in region tree.
This generalizes the previous patch to sink expressions with multiple
users to the deepest common region between all the users.  In the case
of FIRRTL, this sinks a shocking amount of test-only code into
"ifndef SYNTHESIS" blocks, eliminating wires at the top level.

However, because these expressions have multiple uses, they don't get
emitted inline - they get temporaries declared at their local scope,
usually as `automatic logic` values.  These never get their initializer
emitted inline (see Issue #1567), but sinking these is still the right
thing to do IMO.
2021-08-18 15:03:48 -07:00
Chris Lattner 0aaac6e36d [PrettifyVerilog] Sink single-use expressions down the region tree.
This allows the verilog printer to print them inline, for example we'd
turn the example from Issue #1601 into:

```
module test(
  input clock, a, a2, a3);

  wire _T = a2 | a3;
  always @(posedge clock) begin
    `ifndef SYNTHESIS
      if (`PRINTF_COND_ & a)
        $fwrite(32'h80000002, "thing");
      if (`STOP_COND_ & _T)
        $fatal;
    `endif
  end // always @(posedge)
endmodule
```

We now produce: `if (`STOP_COND_ & (a2 | a3))` with no temporary
wire.  This is a pretty huge improvement to lots of things.

There is a more general version of this as well, but it seems best
to split into two patches.
2021-08-18 15:02:53 -07:00
Chris Lattner 001fb742d4 [Verilog] Move "a + -cst" ==> "a - cst" to ExportVerilog.
This allows it to compose with the binary expression tree lowering
work that is already there, allowing us to handle multi-operand
additions that end with a constant.
2021-08-18 14:06:55 -07:00
Chris Lattner b03983676d [ExportVerilog] eliminate emitVariadic, NFC.
Variadic operations are all lowered to binary operations in the
prepass anyway.
2021-08-18 13:49:27 -07:00
Andrew Young c200a29e0b [FIRRTL][InferWidths] Remove unused function
This function is defined but never used.  This fixes a compiler warning.
2021-08-18 13:48:45 -07:00
Andrew Young 61940d3e20 Remove extra semi colons after a function definition 2021-08-18 13:48:45 -07:00
Andrew Young 98ed33b905 [FIRRTL][InferResets] Copy constructor should call parent constructor
This fixing a compiler warning, and could be a real issue if this causes
the state to become inconsistent.
2021-08-18 13:48:45 -07:00
Andrew Young 259a6b5c63 [FIRRTL][GrandCentral] foundAnnotations never used
This variable is set but never used. This fixes a compiler warning.
2021-08-18 13:48:45 -07:00
Andrew Young c4ba156a9b [FIRParser] subIndex is unsigned and never less than 0
This fixes a compiler warning.
2021-08-18 13:48:45 -07:00
Chris Lattner b224645aa5 [PrettifyVerilog] Fix unary sinking to keep constants nearby.
This pass is duplicating unary ops in order to make verilog prettier,
but can result in the op being in a different block than the constant.
This causes the constant to get emitted as a weird local param, which
can even be unused in the generated verilog.  Fix this to duplicate
the constant operands as well.
2021-08-18 13:20:50 -07:00
Morten Borup Petersen a00e3c1ea7
[Calyx] Add IR support for calyx::IfOp (#1582)
* [Calyx] Add IR support for calyx::IfOp

This commit adds support for the Calyx If control operation. The operation takes two arguments; a b boolean SSA value and a group name. The op has two regions, a mandatory 'then' and optional 'else' region.

This is solely for IR support and does not include:
- CalyxEmitter support (unsupported for all control ops as of now)
- CompileControl control FSM generation
2021-08-18 20:58:48 +01:00
Chris Lattner 8cbfcc415f [LowerToHW] Fix issue #1601, changing the uniquing algorithm for always blocks.
When emitting two always/initial/... blocks with the same conditions, leave the
resultant block at the location of the last use, instead of at the location of
the first use.  This ensures that the values used by that block are defined above
it.

This isn't necessary by the semantics of our IR, since hw.module is a graph region,
but leads to better generated verilog and puts less pressure on the cleanup passes.
2021-08-18 10:40:17 -07:00
Hanchen Ye 16d50e9fd6
[SV] Implement build method of AlwaysCombOp (#1598) 2021-08-18 09:01:08 -05:00
Andrew Young fa1a1983fc
[FIRRTL][Parser] Stop removing no-op nodes when parsing (#1588)
When a node is used as the address (aka index) of a CHIRRTL synchronous
read-only memory port, the memory port is enabled at the declaration
location of the node op.  Nodes are being removed by the parser if they
don't carry any annotations. When the node op is removed by the parser,
the enable conditions of the memory change, and sometimes the memory
port is never enabled.

This change removes the small optimization from the FIRParser so that
the memory port enable can be properly inferred.  These node operations
will still be removed later on during canonicalization.
2021-08-18 00:25:56 -07:00
Andrew Young 75a4f73e1b
[FIRRTL][CHIRRTL] Add `memoryport.access` operations (#1539)
The two CHIRRTL memory operations have been renamed from `smem` to
`seqmem` and `cmem` to `combmem`. In addition, instead of returning
`!firrtl.vector<>` types, they return a new type  `!firrtl.cmemory`.
This new type can only be used with CHIRRTL memories and ports, and
prevents some shenanigans where it could be used like a normal vector.

Memory ports in SFC are allowed to be used outside of the scope which they are
defined in. To work around this issue, the memory port declaration was split
into two operations:

1. `firrtl.memoryport`: This operation is the declaration of the memory port,
   and it should be emitted into the body of the module.

2. `firrtl.memoryport.acccess`: This operations is emitted to the location of
   the original memory port declaration, and is used for enable inference.

For more information about these new operations, and why we added them, see the
changes to FIRRTLRational.md.

This include changes to the FIR parser to emit these new operations.
2021-08-17 23:06:27 -07:00
Chris Lattner 292274f09d [LowerToHW] Remove some dead code, NFC.
Beyond being dead, clang-format on the builder disagrees with what my
machine is doing.  Nuking it entirely seems like a good outcome :-)
2021-08-17 22:40:06 -07:00
Chris Lattner f0fa80b451 [comb] Remove the comb.merge operation and supporting logic.
Schuyler points out in Issue #1600 that it isn't correctly implemented,
and there is only one place in the compiler that forms it ... in a
theoretical case.  I added this a long time ago on a theoretical basis.
It is best to remove this until there is a real need for it.

This fixes Issue #1600.
2021-08-17 22:31:51 -07:00
Chris Lattner b7c868965f [LowerToHW] Implicitly CSE sv.read_inout operations when building IR.
This enables LowerToHW's auto-cse of always blocks to kick in in more
cases, e.g. in the example from Issue #1594.  Thanks to Schuyler for
tracking down the root issue here.
2021-08-17 21:46:05 -07:00
Chris Gyurgyik 0ec2965cdb
[Calyx] Add Cell trait. (#1577)
The Cell trait is used to annotate each sub-component within a component. 
This consists of primitives (e.g. RegisterOp) and component instances. This will 
be useful for future passes that want to work on Cells, such as resource-sharing.

I've also renamed the CellOp to InstanceOp.
2021-08-17 20:58:00 -07:00
John Demme f537e0faba
[ESI] [Python] Move functionality through the C API (#1595)
Necessary to avoid linking issues on Windows.
2021-08-17 15:40:14 -07:00
Schuyler Eldridge 71ef06bfc7
[ExportVerilog] Fix localparm splitting begin/end
Fix a bug where a spilled localparam could result in invalid Verilog (a
two-statement always block without a begin/end).

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-17 11:52:40 -04:00
Schuyler Eldridge e50ba2a8cb
[ExportVerilog] clang-formt, NFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-17 10:01:06 -04:00
Fabian Schuiki e0370a201a
[InferResets] Fix iterator invalidation issue in uniquification
Fix an issue where we would iterate over `op->getUses()` for each
`InvalidValueOp` to create a unique instance of the op for every use.
That iterator gets invalidated by the modifications we make though,
which caused only the second (yes, exactly the second) use to be
properly uniquified, with all others remaining the same.

`llvm::make_early_inc_range` to the rescue.

Thanks to @youngar for reducing this down from a much larger test case
and doing the awesome work of hunting this down in a >70M source file.
2021-08-17 11:19:30 +02:00
Fabian Schuiki 54d552ae72
[InferResets] Fix error test cases
Adjust the InferResets test cases to match the updated diagnostics.
2021-08-17 09:51:21 +02:00
Fabian Schuiki 7063ef738b
[InferResets] Show network name for conflicting async/sync drives
Add the reset network name to error messages about conflicting async and
sync drives to the same network. They now read something like:

  error: reset network "foo.io.reset" simulatenously connected to async
  and sync resets
2021-08-17 09:25:00 +02:00
Schuyler Eldridge 415b84213f
[ExportVerilog] Fix zero width comma, newline
Fix issues related to zero width behavior involving trailing commas and
end of instance declarations.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-17 00:00:56 -04:00
Morten Borup Petersen 1627ebf9e5
[Calyx] Make Component port directions an attribute of ComponentOp (#1556)
The implementation of this follows from FIRRTL's implementation of port directions for FIRRTL modules.
2021-08-16 15:47:34 -06:00
Schuyler Eldridge 965082c831
[ExportVerilog] Don't Inline ArrayGet/ArrayCreate
Block inlining of ArrayCreate into ArrayGet users.  This prevents
ExportVerilog from producing invalid Verilog.  Add one test that locks
in this behavior and update existing tests that incorrectly expected
this.

Fixes #1587.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-16 16:59:26 -04:00
Chris Lattner c6fd4f1bcc Fix Issue #1580: mux->array folding got the order backwards.
As extensively discussed in design meeting, the order is a bit
surprising.  operand#0 is not index #0.
2021-08-16 13:32:25 -07:00
Andrew Young 372a58e625
[FIRRTL][ExpandWhens] Simplify muxing of connected values (#1585)
Expand whens takes the following code:
```firrtl
when a:
  x <= 1
else
  x <= 2
```
And transforms it turns it into the (desirable) code:
```firrtl
x <= mux(a, 1, 2)
```

However for nested whens, it was being overly pessimistic in the
condition of the mux.

Expand whens takes the following code:
```firrtl
when a:
  when b:
    x <= 1
  else:
    x <= 2
else
  x <= 3
```

And transforms it into
```firrtl
x <= mux(a, mux(a & b, 1, 2), 3)
```

When it should transform it into:
```firrtl
x <= mux(a, mux(b, 1, 2), 3)
```

In the code change `condition` refers to the condition of the current
WhenOp , and `thenCondition` refers to the all parent `WhenOp`
conditions `and`ed together.  The `thenCondition` is intended to be used
for simulation constructs which are copied directly into the module's
body.

The following example shows how `thenCondition` is used:
```firrtl
when a:
   when b:
     printf(clock, UInt<1>("h1"), "hi")
```

Here, `thenCondition` is `a & b`:
```firrtl
printf(clock, a & b & 1, "hi")
```
2021-08-16 12:01:24 -07:00
Andrew Young 914a00fd6c [FIRRTL][InferReset] Properly infer resets in nested aggregates
When tracing the resets of a connect operation, the pass would
recursively trace the src and dest values. When one of the values came
from a subfield operation, it would associate the resets of the input
bundle of the subfield operation with the resets in result. The pass
neglected to recursively trace the resets of the input of each subfield
operation, which resulted in a failure to determine the correct
reset-network when there were nested aggregates.

To fix this, we need to recursively trace the resets of the input
expression of every subfield operation.

This strategy of recursively visiting the src and dest expressions of a
connect statement probably comes from the SFC, where the result of a
subfield operation can only be used once. In MFC this could result in
visiting the same subfield operation multiple times. It is more
efficient to handle subfield and subindex operations as we walk through
the module. By handling each subfield operation as we see it, we don't
need to recursively trace subfield operations.
2021-08-16 09:58:51 -07:00
Chris Lattner 75feb49bde [Comb] Fix a bug introduced in icmp/xor folding when the xor has multiple uses. 2021-08-16 09:11:11 -07:00
Fabian Schuiki 0afd84d22f
[InferResets] Update extmodule types
Also update the types of extmodule ports that were inferred during reset
inference. In general we do not want to update the type of extmodules,
since these are provided from the outside and the interface is thus
fixed. However in the case of reset inference where the types all map to
the same Verilog, this is okay to do.

This currently uses the types inferred for `InstanceOp`s to determine
what types the corresponding extmodule should have. This works in the
cases we are interested in, but can break in some corner cases where a
reset network is only connected through an extmodule port. In that case,
since we don't have a `Value` for that extmodule port, the two reset
networks can remain disjoint.

This fixes #1578.
2021-08-16 11:09:38 +02:00
Fabian Schuiki ac94c63306
[InferResets] Uniquify InvalidValueOps before inference
The presence of `InvalidValueOp` is problematic during reset inference.
Generally, CSE will ensure that there is at most one `InvalidValueOp` of
a given type. However, if that op is of `ResetType`, it might be
connected to multiple reset networks as a `rst is invalid` connection.
Currently, `InferResets` will consider these reset networks to become
connected along this `InvalidValueOp`, which is incorrect.

This commit adds a `InvalidValueOp` uniquification step to the beginning
of reset inference, which replicates these ops such that they have at
most one use. This is necessary, since that single `ResetType` invalid
value may become part of a `AsyncResetType` and a `UIntType` reset
network, in which case two distinct invalid values are required.

This fixes an issue uncovered by @youngar and @Ramlakshmi3733.
2021-08-16 10:41:07 +02:00
Chris Lattner d6ed0aa746 [Comb] Fold (x^cst1) == cst2 ==> x == (cst1^cst2)
This takes the example in Issue #1560 from:

```
assign a = (auto_in_aw_bits_addr[37:29] ^ 9'h2) == 9'h0;
```

to:

```
assign a = auto_in_aw_bits_addr[37:29] == 9'h2;
```

which is a heck of a lot better than the starting point of:

```
assign a = ~(|({1'h0, auto_in_aw_bits_addr ^ 38'h40000000} & 39'h7FE0000000));
```
2021-08-15 21:48:32 -07:00
Chris Lattner dcc64f28ff [Comb] Simplify and generalize the equality icmp + known bits folding logic.
This now turns things like `(and x, 3) == 1` into `extract x[1:0] == 1`.
This composes very nicely with extract shrinking, but extract shrinking
needs to be taught some new tricks.
2021-08-15 21:27:26 -07:00
Chris Lattner 3d85510d0e [Comb] Enhance the icmp/compare folder to use a "computeMaskedBits" analysis.
This generalizes the analysis beyond literal constants to handle some simple
expressions that generate known bits, starting with 'and' and 'or' expressions.
Given a value with some known and some unknown bits, we extract out the portion
of the expression that is unknown and compare just it instead of the whole
value.  This composes very naturally with our existing 'truncate folding'
optimizations.

This turns the example in Issue #1560 from:

```
  wire [37:0] _tmp = (auto_in_aw_bits_addr ^ 38'h40000000) & 38'h3FE0000000;
  assign a = _tmp == 38'h0;
```

into:

```
  assign a = (auto_in_aw_bits_addr[37:29] ^ 9'h2) == 9'h0;
```

Which is a nice step forward and enables xor folding.  However, I realize
now that this whole thing can be far more general than icmp of concats.
I will take care of this in a follow-up patch.
2021-08-15 20:57:39 -07:00
Chris Lattner fe91e0a29f [Comb] Fold not(icmp(pred,x,y)) -> icmp(!pred,x,y).
This only triggers when the compare has a single use.
2021-08-15 15:45:47 -07:00
Chris Lattner 2936229ba0 [Comb] Canonicalize `icmp(concat, cst)` to reduce concat when possible.
When we know something about the bits in the concat operands we can
simplify equality comparisons, reducing the number of operands to the
concat (and eliminating it entirely in some cases.

This further simplifes the testcase in Issue 1560 from:

```
  wire [37:0] _tmp = (auto_in_aw_bits_addr ^ 38'h40000000) & 38'h3FE0000000;
  assign a = ~(|{1'h0, _tmp});
```

to:

```
assign a = ~(|((auto_in_aw_bits_addr ^ 38'h40000000) & 38'h3FE0000000));
```
2021-08-14 18:22:59 -07:00
Chris Lattner bc5658cf6d [Comb] Fix canonicalize crash on single-argument concat.
The folder for this wasn't properly handling the single-op case
(which is a noop) and the canonicalize hook wasn't prepared to handle
it.

This also includes some minor NFC formatting tweaks.
2021-08-14 18:14:16 -07:00
Chris Lattner 1373056c65 [Comb] Push and/or/xor by a constant into a concat when this simplifies things.
This allows recursive simplification, and generally cleans up generated Verilog.
This is part of Issue #1560.
2021-08-14 12:30:26 -07:00
Chris Lattner eea5187817 [Comb] Fix a crash on "shru x, 0" forming an invalid APInt.
This also folds them correctly to x.
2021-08-14 11:14:28 -07:00
Prithayan Barua 0375e732c8
[FIRRTL] Fold Mux with the same constant high and low (#1566)
Add a fold pattern for mux when the low and high are the same constant.
That is, 
x = mux (cond, <constant1> ,<constant1>) 
can be replaced with, 
x = constant1
This can enable IMConstProp to constant propagate through mux trees.
2021-08-14 02:50:12 -07:00
John Demme c36dd88568
[ExportVerilog] Don't output temporaries for output port assignments (#1571) 2021-08-13 22:27:18 -07:00
Chris Lattner ee45760516 [Comb] Restrict some mux folds to single bit mux's.
A mux is cheaper than a sext+logic op.  This change allows us to
handle the SevenSegmentDecoder example from Issue #675.  We now
produce:

```
  wire [6:0] _T = {1'h0, in == 4'h1 ? 6'h6 : 6'h3F};
  wire [15:0][6:0] _tmp = {{_T}, {_T}, {7'h5B}, {7'h4F}, {7'h66}, {7'h6D}, {7'h7D}, {7'h7}, {7'h7F}, {7'h6F}, {7'h77}, {7'h7C}, {7'h39}, {7'h5E}, {7'h79}, {7'h71}};
  assign out = _tmp[in];
```

which is way nicer than a pile of ternaries.  The extraneous wire
is due to an explicit pad, which I'll file as another opportunity.
2021-08-13 18:55:14 -07:00
Chris Lattner e7a34ea94c [Comb] Stop canonicalizing mux's into multiple other logical operations.
It is useful to strength reduce operations when it makes sense, but
mux's are "as primitive" as and, or and certainly sign extend.  There
is no reasonable cost model that says we should expand them out.

This enables more aggressive analysis of mux trees and resolves
Issue #1549.
2021-08-13 18:10:48 -07:00
Chris Lattner b4128fccf8 [ExportVerilog] Don't introduce temporary wires for ReadInOutOp or bitextracts from wires.
This resolves Issue #1564
2021-08-13 17:55:24 -07:00
Chris Lattner 10459d0e27 [ExportVerilog] Handle FusedLoc when printing location comments.
This fixes Issue #1563
2021-08-13 17:22:45 -07:00
Chris Lattner df37fa11c7
[Comb] Fold a large series of of mux ops into array_create/get (#1559)
[Comb] Fold a large series of of mux ops into array_create/get

This substantially shrinks the size of the IR and generates much
better verilog.  E.g. before:

```
  module top_mod(
    input  [1:0] sel,
    input  [7:0] a, b, c, d,
    output [7:0] y);

    assign y = sel == 2'h0 ? a : sel == 2'h1 ? b : sel == 2'h2 ? c : d;
  endmodule
```

and after:

```
  module top_mod(
    input  [1:0] sel,
    input  [7:0] a, b, c, d,
    output [7:0] y);

    assign y = ({{a}, {b}, {c}, {d}})[sel];
  endmodule
```

This uses a couple heuristics to keep things from going crazy. This
is progress towards closing Issue #675, but it is still not getting
some important cases due to Issue #1549.  Those can be handled as
follow-up patches.
2021-08-13 17:10:28 -07:00
John Demme 8ce903daf6 [Py] Remove `BitcastOp` from `StructCreateOp`
`StructCreateOp` now handles returning `TypeAliasType`s so this is no longer
necessary!
2021-08-13 17:07:11 -07:00
Schuyler Eldridge e53f330cd7
[FIRRTL] Remove designated inits in InferResets
Remove use of designated initializers, a C++20 feature.

Fixes #1565.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-13 17:01:33 -04:00
Hideto Ueno 2f5b7d1d58
[Comb] Canonicalize away shifts by a constant (#1551)
* [Comb] Canonicalize away shifts by a constant

* move some canonicalization to fold

* use c array instead of small vector

* small fix

* add builder to extract op

* clang-format
2021-08-14 05:49:48 +09:00
Julian Oppermann d9dae2d0d6
[Scheduling] [NFC] Refactor simplex schedulers, clarify comments. (#1562) 2021-08-13 21:25:02 +02:00
Prithayan Barua 3a4cef2cfc
[FIRRTL] Refactor isOnlyConnectToValue method of FIRRTLFolds, NFC (#1557)
Update FIRRTLFolds to use the method getSingleConnectUserOf
that scans all the uses of the specified value, checking to see if there is
exactly one connect that sets the value as its destination. This returns
the operation if found and if all the other users are "reads" from the
value.
(Followup to address comments on #1546)
2021-08-13 06:13:29 -07:00
Fabian Schuiki c3573eed43
[FIRRTL] Add InferResets pass (#1304)
* Extract reset-related test cases from the existing Scala FIRRTL
  compiler code; specifically from `InferResets`, `CheckResets`,
  `RemoveReset`, and `FullAsyncResetTransform`.

* Add the `InferResets` transformation pass to the FIRRTL dialect, which
  assigns asynchronous resets to registers without reset, and replaces
  `reset` types with either `uint<1>` or `asyncreset`, as appropriate.

* Add the `--infer-resets` option to firtool, on by default.
2021-08-13 12:15:45 +02:00
mikeurbach d2106fd734
[HW] Support TypeAliasType in return type for aggregate create ops. (#1521)
This was always intended to be supported, but was removed in
862f1b4. This adds it back, and updates the parsers for the relevant
ops to actually support type aliases (they previously didn't).

In order to help avoid the need to cast away aliases everywhere, a new
base class is added to all aggregate types that support aliases. This
class can represent a type alias or the aggregate type. It implicitly
converts to the aggregate type, which helps avoid explicit casts.
2021-08-12 22:47:29 -06:00
Schuyler Eldridge 9298abdc05
[FIRRTL] Fix bug with annotation scattering SExt
Fix a bug where the subindex of a target would be sign extended instead
of zero extended.  This could result in situations where the subindex
would show up as negative and the annotation would not be applied.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-13 00:39:11 -04:00
John Demme 63168725bd
[MSFT] Instance specific placement (#1550)
Placement data can now be filtered to a particular instance. Adds the SwitchInstance attribute to select an attribute from a list keyed off the instance ID (currently just the path in the instance hierarchy). This method is not robust to hierarchy changes, but it's a start.

Modified ExportTcl to respect the SwitchInstance attribute
2021-08-12 11:43:20 -07:00
Schuyler Eldridge 365bb385d8
[FIRRTL] Fix type comparison bug for Bundles
Fix an issue where type equivalency was not existing after verifying
that two bundles were equivalent.  This resulted in a fall-through check
that the widthless type of two bundles _also_ being compared.  This
would cause issues where a bundle with an abstract reset would fail to
type check against a uint<1>.

Add a small test of this behavior.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-12 14:36:01 -04:00
Julian Oppermann b1003cc890
[Scheduling] Add problem model for shared, pipelined operators. (#1552)
Extends the basic problem model with a new operator type property 'limit', representing the maximum number of operations that can "use" a given operator type in each time step.
2021-08-12 18:06:35 +02:00
Prithayan Barua 0a6ad1a2b4
[FIRRTL] Constant prop RegReset with constant reset and constant mux (#1546)
A register with constant reset and a single connection to a mux 
with the same constant can be replaced with that constant
```
  %c11_ui8 = firrtl.constant 11 : !firrtl.uint<8>
  %r = firrtl.regreset %clock, %reset, %c11_ui8  : !firrtl.uint<1>, !firrtl.uint<8>, !firrtl.uint<8>
  %0 = firrtl.mux(%cond, %c11_ui8, %r) 
  firrtl.connect %r, %0 : !firrtl.uint<8>, !firrtl.uint<8>
  firrtl.connect %z, %r : !firrtl.uint<8>, !firrtl.uint<8>
```
can be replaced with 
```
  %c11_ui8 = firrtl.constant 11 : !firrtl.uint<8>
  firrtl.connect %z, %c11_ui8 : !firrtl.uint<8>, !firrtl.uint<8>
```
2021-08-12 08:35:06 -07:00
Julian Oppermann e72c083ddb
[Scheduling] Support for basic problems in the simplex scheduler. (#1535) 2021-08-12 10:15:59 +02:00
Prithayan Barua e2da482100
[SV][ExtractTestCode] Extract assume and asserts to separate modules (#1547)
Extract the assume and assert statements to different modules, this is to mimic the SFC behavior.
2021-08-11 15:42:16 -07:00
Prithayan Barua bd7edb5c44
[FIRRTL] Constant prop registers with self-init to mux pattern (#1536)
Constant propagate registers that are driven by a mux tree 
containing only instances of one constant and self-assigns.

Detect the case if a register only has two possible drivers: 
(1) itself/uninit and (2) constant.
The mux can then be replaced with the constant.

reg = mux(cond1, reg, 3) can be replaced with --> reg = 3
reg = mux(cond2, 3, reg) can be replaced with --> reg = 3

Fixes #1483
2021-08-10 09:47:23 -07:00
Fabian Schuiki 824925c24c [FIRRTL] Add WidthSpec Scala tests, fix issues
Port the `WidthSpec` tests from the Scala FIRRTL implementation over
into an integration test for firtool. This uncovers a few integer
overflow issues in the parser/types, which this fixes alongside the
tests.
2021-08-10 18:04:36 +02:00
Laura Gallo 0649d308d8
Added Tcl bindings for loading an MLIR file. (#1529)
* Added Tcl bindings for loading an MLIR file.

* Ran clang-format

* Updated Tcl library path

* Update simple.tcl

* Implemented Lenharth's suggestions

* Ran clang-format

* Fixed integration test

* Added checks to integration test

* Implemented some of Mike's suggestions

* Added another argument

* Added paths to Tcl debug output in CMAKE
2021-08-10 09:36:46 -04:00
Julian Oppermann d476344380
[Scheduling] Add simplex scheduler for the cyclic problem. (#1526)
This scheduler uses linear programming and a handwritten simplex solver to compute the II and start times for the CyclicProblem. It's an implementation of the approach proposed in:
B. D. de Dinechin, "Simplex Scheduling: More than Lifetime-Sensitive Instruction Scheduling", PRISM 1994.22, 1994.
2021-08-08 20:50:43 +02:00
fyquah 54d3f8df8e
[Comb] Narrow Arithmetic and Bitwise Ops - Take 3 (#1517)
A third-take a implement operation narrowing, after failed attempts in #1475 and #1424 . The main fix introduced by this commit is setting insertion points at appropriate points before calling rewriter.create for narrowed operations.

This optimization rewrite arithmetic (add, mul, sub) and bitwise logical (and, xor, or) operations into the narrowest possible version without needing. For example
    
```mlir
%addResult = add %a, %b : i10
%addResult = extract %addResult from 0 : i10 -> i3
into addition only on bits that will be used
```
    
will be transformed to the following narrowed ops.
    
```mlir
%a'         = extract %a from 0 : i3
%b'         = extract %b from 0 : i3
%addResult' = add %a', %b' : i3
%c0         = hw.constant 0 : i7
%addResult  = concat %c0, %addResult' : (i7, i3) -> i10
%addResult  = extract %addResult from 0 : i10 -> i3
```
2021-08-05 23:14:59 +01:00
Schuyler Eldridge b0add080e2
[FIRRTL] Fix Memory RW Port Order
Fix the port order of read-write ports for FIRRTL memories.  This fixes
an issue where doing an aggregate connect to a FIRRTL read-write memory
would work in the Scala FIRRTL Compiler, but not work in CIRCT.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-05 16:57:04 -04:00
Hanchen Ye 1487eee254
[FIRRTL] Enum the subfields of MemOp ports (#1525) 2021-08-05 12:41:55 -05:00
Hanchen Ye ff3183aa6d [FIRRTL][CheckCombCycles] Signal pass failure if any combinational cycle detected, NFC 2021-08-05 03:28:48 -05:00
Hanchen Ye a81395d2d4 [FIRRTL][CheckCombCycles] Use range-based loop to traverse op users, NFC 2021-08-05 03:05:16 -05:00
Hanchen Ye deaaa6c79f [FIRRTL][LowerTypes] Simplify the annotation handler of MemOp, NFC.
The annotations of all bundle type subfields (`data` and `mask`) of
MemOp ports should be filtered. This patch can avoid the unnecessary
subfield index comparisons.
2021-08-05 03:00:31 -05:00
Schuyler Eldridge 7952543d72
[ExportVerilog] "mkdir -p" output directory
Create parent output directories if needed as opposed to crashing if the
parents don't already exist.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-05 02:20:16 -04:00
Schuyler Eldridge 6cff7a33a2
[FIRRTLToHW] Copy "lowerToBind" "output_file" attr
When lowering a FIRRTL instance marked as "lowerToBind" stop setting a
default output file.  Instead, copy over an "output_file" attribute if
one exists.  This provides more predictable behavior where it is the
responsibility of a FIRRTL pass to setup bind-lowering behavior as
opposed to relying on some default filename derived from a Grand Central
naming convention.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-05 02:20:16 -04:00
Schuyler Eldridge 0938ce4508
[FIRRTLToHW] Copy "output_file" attr on FModuleOp
Copy an "output_file" attribute from a FIRRTL module to a HW module if
such an attribute exists.  This enables FIRRTL transforms to set output
file information in a FIRRTL pass, which may be necessary if such
information is available in an annotation that that pass consumes.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-05 02:20:16 -04:00
Chris Gyurgyik db084be5b9
[Calyx] Emit (unguarded) assignments. (#1519)
Add emitter for unguarded Calyx assignments, i.e. `AssignOp`.
2021-08-04 15:27:37 -07:00
Chris Gyurgyik e1c6592852
[Calyx] Add CalyxToHW scaffolding. (#1502)
Adds scaffolding for a Calyx to HW conversion pass.
2021-08-03 18:34:11 -07:00
Hanchen Ye fefe356aab
[FIRRTL] Add a CheckCombCycles pass (#1388)
This pass runs a strongly connected components (SCC) detection to check
combinational cycles in the IR. The current implementation assumes the
firrtl-lower-types and firrtl-expand-whens has been applied before this pass.
2021-08-03 15:35:14 -05:00
Chris Lattner 10dbca5e46
[FIRParser] Fix a race populating SourceMgr line table. (#1515)
The llvm::SourceMgr class lazily builds a line table, and isn't
internally synchronized.  This can cause crashes with threaded
parsing.  This fixes Issue #1513.
2021-08-03 10:08:53 -07:00
Schuyler Eldridge ee0f736e52
[FIRRTL] Stop or/xor invalid folds if types differ
Stop folding or/xor with invalid operands when the types of the
non-invalid operand doesn't match the result type.  This covers the case
where or and xor can take SInt operands and return a UInt result.

Include a temporary test that checks that this behavior works.

This behavior is expected to be changed in the future via a
canonicalizer that will do the cast as necessary.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-02 23:52:46 -04:00
Hanchen Ye f03271e612
[SV] Add a LocalParamOp (#1505) 2021-08-02 19:23:51 -05:00