Commit Graph

587 Commits

Author SHA1 Message Date
Schuyler Eldridge 968b6dcedb
[FIRRTL] Improve RegOp/RegInitOp Verification (#95)
* [FIRRTL] Correct RegInitOp description

Fix copy-paste typo where the description of RegInitOp uses the "reg"
keyword instead of "reginit" keyword.

* [FIRRTL] Enforce register op clock is a clock type

Change the type of the clock connection for RegOp and RegInitOp from
AnyType to ClockType.

* [FIRRTL] Add checks the register clock is a clock

Add tests for RegOp and RegInitOp that the type of the clock
connection is actually a clock.

* [FIRRTL] Add FIRRTLType.isResetType

Add a method that determines if a FIRRTLType is a valid reset type. A
valid reset is one that is either an abstract reset, a concrete 1-bit
UInt, or a concrete asynchronous reset.

* [FIRRTL] Add constraints to ResetType

Use new FIRRTLType::isResetType to assert that a ResetType is actually
a valid reset type.

* [FIRRTL] Require RegInitOp reset is ResetType

Change the required type of the reset connection in a RegInitOp from
AnyType to ResetType. This relies on constraint checking of ResetType
and will accept any abstract reset, concrete asynchronous reset, or
concrete 1-bit UInt.

* [FIRRTL] Test rejection of bad RegInitOp resets

Add a test that a 2-bit UInt reset connection is rejected as invalid
FIRRTL.
2020-09-21 19:10:28 -04:00
stephenneuendorffer 26d4f4861d
Update to MLIR 84a6da67e6b2a7 (#96)
Mostly this fixes changes in how APInt is used for op and builder interfaces.
Overall, we are able to remove extra APIs that used to exist to provide int/unsigned
native type interfaces.
2020-09-21 13:20:00 -07:00
Schuyler Eldridge 7cc6518de0
[FIRRTL] Add Circuit Op Verification (#88)
* [FIRRTL] Fix tests so "main" matches a module

Fix FIRRTL tests to make them valid FIRRTL IR. Previously, the example
FIRRTL IR or FIRRTL MLIR dialect examples could contain a circuit
whose name (what FIRRTL IR calls the "main" or, equivalently, the top
module) did not match the name of a module in the circuit. This commit
changes the tests so that this invariant holds.

* [FIRRTL] Add circuit verifier

Add a new function, verifyCircuitOp, that is used to verify a FIRRTL
circuit op. This checks the following two conditions:

  1. The circuit must have a name ("main" in FIRRTL IR/the top module)
  2. The circuit must contain a module matching the circuit name

This brings the FIRRTL dialect in line with the current implementation
of the FIRRTL compiler where condition (1) is nonsensical and
condition (2) is rejected.

* [FIRRTL] Test circuit verifier

Add a test for the FIRRTL dialect that the user is provided with an
error if they provide FIRRTL MLIR whose name (it's "main" or top
module) does not match the name of any modules in the circuit.

Add a test that the FIRRTL dialect circuit op has a non-empty name.
2020-09-20 21:33:44 -04:00
Chris Gyurgyik 3180b16405
[RTL] Add ShlOp. (#92)
* [RTL] Add 'and' idompotent case for canonicalization.

* [RTL] Add 'and' constant folding canonicalization pattern.

* [RTL] Add non-constant to cstfold mlir check file test.

* [RTL] Implement ShlOp.

* [RTL] Add test to EmitVerilog for shl.

* [rtl] Change module name to "shl" for EmitVerilog test.
2020-09-20 19:42:59 -04:00
Chris Gyurgyik 8c3d96d3a8
[RTL] Add 'and' constant folding case for canonicalization. (#91)
* [RTL] Add 'and' idompotent case for canonicalization.

* [RTL] Add 'and' constant folding canonicalization pattern.

* [RTL] Add non-constant to cstfold mlir check file test.
2020-09-19 21:45:40 -04:00
Chris Lattner 4a41c429a0 [RTL] Implement a new rtl.mux operation, including support for
EmitVerilog and LowerToRTL.
2020-09-19 11:50:18 -07:00
Chris Lattner 86940236f8 [LowerToRTL] Implement support for lowering firrtl.neg and firrtl.not. 2020-09-19 11:17:17 -07:00
Chris Lattner 88679509e9 [LowerToRTL] Implement lowering for firrtl.cvt and firrtl.node. 2020-09-19 10:34:25 -07:00
Chris Gyurgyik 51d805e7dc
[RTL] Add 'and' idompotent case for canonicalization. (#85) 2020-09-17 13:35:19 -04:00
Hanchen Ye 2d6f833e8d
[HandshakeToFIRRTL] A code rewrite using Handshake visitor (#79)
* code rewrite using Handshake visitor

* small fix

* include buildOpLogic methods into HandshakeBuilder class; buildBinaryLogic into StdExprBuilder
2020-09-16 13:03:46 -05:00
Ruizhe Zhao 3842d113fd
[StandardToHandshake] Use isa instead of dyn_cast for conditions (#87) 2020-09-16 15:24:53 +01:00
Amalee Wilson eeec4b26fd
Rename RTLInstanceOp verifier to verifyRTLInstanceOp (#86) 2020-09-15 13:21:01 -07:00
Amalee Wilson 7a04e08d88
Add support for RTL module and instance, update EmitVerilog (#76)
Initial support for RTL Module and Instance ops. #72 outlines step 2 for each op.
2020-09-14 15:23:05 -07:00
Chris Lattner 8582458834 [LowerToRTL] Implement lowering of mul/div/rem, including the goofy
implicit extension/truncation semantics for the operands and results.
2020-09-12 23:40:26 -07:00
Chris Lattner 23da302595 [LowerToRTL] Implement lowering of reduction ops to RTL. 2020-09-12 14:37:13 -07:00
Chris Lattner 7c63e7bc12 [firtool] Add a new -lower-to-rtl flag that enables the firrtl->rtl lowering pass.
This makes it easier to test out while in development: it should
eventually be on by default.
2020-09-12 14:11:29 -07:00
mikeurbach 2ce50b87da
Update LLVM to 1d3d9b9cd808ef37f3dacd3ada81bff1353cd24b (#78)
This picks up some enhancements to ODS, as well as a few changes:

* Dialect registration is being updated. For now, the global dialect
  registry is enabled for backwards compatibility while we update
  the dialect registry mechanisms
* Kinds are removed from Types and Attributes. This is a mostly
  mechanical change to use isa and TypeSwitch
* Generated passes are registered differently. The approach here is
  to define the registerPasses function in an anonymous namespace
  and call it from within the existing static helpers.
* Upstream LLVM dialect has updated how types are printed, and the
  LLHDToLLVM tests are updated accordingly
2020-09-11 17:20:56 -07:00
Hanchen Ye 36ea880836
Add a Handshake visitor (#77)
* add visitor for handshake dialect

* some small renamings

* small fixes
2020-09-11 16:33:06 -05:00
Chris Lattner 72e580f16e [EmitVerilog] Fix a bug handling rtl::ExtractOp from an operand that
must be emitted out of line (due to verilog language limitations).

This allows us to get the entire verilog-basic.fir testcase through
the LowerToRTL/EmitVerilog path.  Not all constructs are supported
though.
2020-09-07 10:19:57 -07:00
Chris Lattner 744e5a89af [FIRRTL] Enhance LowerToRTL to handle the failure-to-convert cases
more correctly, emitting an error and propagating up failure instead
of crashing.
2020-09-07 10:12:39 -07:00
Chris Lattner a0fcf444f7 [SV] Implement $fatal, $finish, lowering of firrtl::StopOp, and
EmitVerilog support for them.
2020-09-07 09:55:18 -07:00
Chris Lattner cdf0ac589f [SV Dialect] Implement sv.fwrite support for operands. Implement
lowering support for operands in LowerToRTL, and implement support
for them in EmitVerilog.
2020-09-07 09:24:01 -07:00
Chris Lattner 89306a780c Tidy up two things I noticed in my last commit, NFC. 2020-09-06 16:21:22 -07:00
Chris Lattner 6028585212 [FIRRTL] Enhance the "LowerToRTL" pass to lower firrtl::PrintFOp into
SV constructs, at least in the zero operand case.
2020-09-06 16:17:54 -07:00
Chris Lattner 439750f5f3 [SV Dialect] Add custom builders to SV control flow ops that guarantee
their terminator.  This makes the builder->build<IfOp>() construct work
better.

This is something that ODS should arguably do in general, I'll file an
enhancement request.
2020-09-06 16:11:59 -07:00
Chris Lattner e4d14a9fb7 [EmitVerilog] Make use of without_terminator and llvm::hasSingleElement
to tidy up some code.  NFC

Thanks to River Riddle for pointing this out!
2020-08-29 11:50:10 -07:00
Martin Erhart 6d1c0ebbaf
[LLHD] Add memory to block argument promotion pass (#52)
* [LLHD] Add memory to block argument promotion pass

* Promote memory locations allocated with llhd.var to block arguments to allow further optimizations.
* This pass is also required to lower behavioral LLHD to structural LLHD, because all control-flow has to be eliminated and structural LLHD has no memory model
* For this version pointers may not be used in operations apart from llhd.load and llhd.store, it may also not be created by a function call.
* It is limited to llhd.proc for now as functions have to be completely inlined for the lowering anyways
* There may not be any operations with nested regions in llhd.proc which are not isolated from above. This only affects the llhd.for operation which has to be completely unrolled for the lowering anyways
* Some of those restrictions can be lifted in a future commit

* Fix typos and better data structures
2020-08-28 13:29:09 +02:00
Martin Erhart 74b446f60b
[LLHD] Add folders and canonicalization patterns for extract operations (#50)
* [LLHD] Add folders and canonicalization patterns for extract operations

* Use m_Constant pattern to match constant value

* Remove unnecessary includes

* Use tablegen patterns to canonicalize dynamic extract operations
2020-08-27 21:49:47 +02:00
Chris Lattner 0810c6bb65 Add suggestions about using Discourse to the README, suggested by Mehdi. 2020-08-26 22:20:22 -07:00
Chris Lattner e8428eaf05 [README] Spiff up the README a bit. 2020-08-24 15:33:32 -07:00
Chris Lattner a25a0b45a6 [SV Dialect] Implement Visitor and EmitVerilog support for SV. 2020-08-15 16:45:59 -07:00
Chris Lattner 485f6cec53 [SV] Introduce a new SV dialect with operations that provide access to
if/ifdef/always @ posedge, fwrite, and macro expressions.

This is still very simple and early on, but is a reasonable starting
point to expand the capabilities for the verilog printer.
2020-08-15 15:20:30 -07:00
Hanchen Ye 9ab7d667f9
[Handshake] Add StaticLogic Dialect and Pipeline Operation (#62)
* add pipeline operation

* add staticlogic dialect lib

* add standard-to-staticlogic pass

* update standard-to-staticlogic pass

* update conversion pass

* complete initial design of -create-pipeline pass

* format fixed; add testcase for -create-pipeline pass

* update references

* update pipeline operation defination; update standard-to-pipeline pass; update testcase

* add endline

* update pipeline operation and lowering pass: isolate from above, but not single-producer single-consumer; update test case.
2020-08-03 22:29:40 -07:00
Hanchen Ye d284b0dddc
[Handshake] Pass for removing single-input merge operations (#58)
* add pass for removing redundant components (e.g. single-input merge) in handshake representation

* remove the pass; update testcase.
2020-08-03 22:28:50 -07:00
Sora Morimoto 438fdef6e3
Update actions/cache to v2 (#64)
Signed-off-by: Sora Morimoto <sora@morimoto.io>
2020-08-02 22:10:19 -07:00
Martin Erhart 0333f1e586
[LLHD] Add Early Code Motion pass (#55)
* This pass moves all instructions without side-effect and llhd.prb as
  far up in the CFG as possible as preparation for the Temporal Code
  Motion pass and to enable total control-flow elimination
* This also includes a Temporal Region analysis to evaluate which blocks
  are guaranteed to execute at the same physical time. This is needed to
  move llhd.prb instructions as they are not allowed to be moved to
  blocks which could be executed at another physical time and thus probe
  an older or newer state of the signal. It will also be needed for the
  Temporal Code Motion pass and Desequentialization
2020-08-01 09:19:31 +02:00
stephenneuendorffer ad075335b8
Update LLVM version to c89e46e76 (#63)
* Update LLVM version to c89e46e76

A small fixup is required to avoid conflicts between ODS-generated build
methods because of default arguments.  Also, since this keeps failing, I've
updated the llvm cache so that it runs in a separate job.  Otherwise the cache is not updated when the CIRCT build fails.

* [LLHD] Add `SigType` conversion

* [LLHD] Add time type and constants conversion

Previously time constants were converted by their users, by creating a constant for each of the three time attributes. This makes time constants LLVM arrays containing the three time values instead, allowing more a more flexible use (e.g. passing time operands as block arguments).
* Add time type conversion.
* Add tme constants conversion.
* Add time operands to the process persistence state.
* Fix affected tests.

* [LLHD] Set LLVM::DialectCastOp as legal during `InstOp` lowering

This works around the PartialConversion failing because of the introduction of (unused) `DialectCastOps`, that will be dealt with later during the full conversion.

Co-authored-by: rodonisi <simon@rodoni.ch>
2020-07-31 11:32:38 -07:00
Amalee Wilson 5fd07b26a9
[RTL] Fix RTL test pattern matching (#61)
Fix pattern matching for RTL tests.
2020-07-30 14:54:38 -07:00
Stephen Neuendorffer 6f538803bf update .gitignore 2020-07-30 14:41:50 -07:00
Martin Erhart 75a9dd9fbc
[LLHD] Mark prb as a memory read operation (#53)
* This fixes a kind of bug where prb operations of the same signal were CSEd despite being in different temporal regions
2020-07-30 22:32:20 +02:00
rodonisi ad114bf05b [LLHD] Use 2-space indents in conversion tests 2020-07-30 18:48:28 +02:00
Simon Rodoni 4db5979b23
[LLHD] Improve simulator signal representation (#49)
* [LLHD] Improve simulator signal representation

Previously signals lowered to the LLVM dialect where represented as just an index in the state's global signal table. That required to query the state to gather the signal information for each signal, and also to store temporary subsignals in the state itself. This improves how signals are represented in the lowered code and state:

* Directly represent signals in the lowered code as a pointer to the detail struct, containing the signal's information. This allows to represent subsignals without adding them to the state.
* Directly pass the list of detail structs as a function argument to the lowered unit function, instead of a list of indices. This allows to get rid of the runtime function that was used to query the state for that info.
* Merge the signal, input and output tables in the instance state. This distinction is not required here and added unnecessary complexity. This also fixes a wrong behavior, where instances did not get triggered by changes in output signals.
* Use the `SignalDetail` struct for instance signal tables directly,
  instead of indices.
* Adjust affected tests.

* Add outputs to process sense table
2020-07-30 18:42:21 +02:00
Amalee Wilson 3368e448b8
[RTL] Add pattern matching to rtl tests (#59)
Update RTL tests to use pattern matching
2020-07-29 11:41:14 -07:00
Aliaksei Chapyzhenka 9057abaef9
added circt logo (#57) 2020-07-28 12:53:08 -07:00
Shawn Landden 6060a96930
[Global] Clarify license as Apache 2.0 with LLVM Exceptions (#56)
As discussed with Chris Lattner in #54, this was always the intent.

The file include/circt/Dialect/FIRRTL/Passes.h already indicated the LLVM exceptions
apply.

This will be posted to discourse. If you are a significant contributor and
object, we need to hear from you.
2020-07-26 11:53:57 -07:00
Martin Erhart 03d4f0454d
[LLHD] Replace vectors with LLHD array type (#48)
* [LLHD] Replace vectors with LLHD array type

* Rename overlooked vector type
2020-07-22 08:58:50 +02:00
Hanchen Ye 07c3a5fbc4
Support sequential module; initial implement of lowering BufferOp (#42)
* add clock and reset signals to create*ModuleOp() function

* add BufferOp to HandshakeOps.td

* add insertBufferOps() method

* add -insert-buffer pass for handshake

* add test_insert_buffer test case

* update references and remove the real stack structure

* support sequential submodules

* add initial buildBufferLogic() method

* add  attribute to buffer operation

* fix small issues, and mechanical rename all passes from DF to Handshake

* update createInstOp() and getSubModuleName() for supporting sequential modules

* add test_buffer.mlir test case

* add test_buffer.mlir test case

* support multiple clocks; fix small issues
2020-07-20 14:21:50 -07:00
Martin Erhart 2465a5e66d [LLHD] Add missing return in FunctionEliminationPass 2020-07-20 14:33:13 +02:00
Simon Rodoni 00bcb86ede
[LLHD] Add memory type and operations (#34)
* [LLHD] Add memory type and operations

* Add `llhd.ptr<T>` type to represent pointers LLHD types.
* Add var (allocate stack space with an initial value), load and store operations.
* Rename `LLHD_AnySigUnderlyingType` -> `LLHD_AnyUnderlyingType` in `LLHD.td` as this can be shared between signal and memory operations.
* Add test case for memory operations.

* Two-space indents

* Remove NoSideEffects

* Add memory SideEffects traits

* Change `ptr` -> `pointer` in type description

* Add memory `cse`/`dce` test

* Use sentence fragments for Arg/Res description

* Add missing line at end of file
2020-07-20 11:07:18 +02:00
Martin Erhart e6e09561b5
Enhance bitwise folders and add canonicalization patterns (#43)
* Add folders for bitwise operations

* Fold bitwise operations having complements as arguments
* Fold double not
* Convert xor with one operand being all ones to a not

* Add equality operation canonicalization patterns

* Move shift folding tests to new canonicalization folder
* Merge old bitwise and arithmetic folding tests

* Add newlines

* clang-format
2020-07-20 10:58:41 +02:00