Commit Graph

2220 Commits

Author SHA1 Message Date
Andrew Young 7d25db6087
[Comb] Link CIRCTSupport for LoweringOptions (#1619)
This should fix the CI builds.
2021-08-21 15:41:25 -07:00
Andrew Young 0413d52355
[firtool] move BlackboxMemory before LowerTypes (#1618)
BlackBoxMemory creates modules with bundles types to replace memory
operations.  If this runs after LowerTypes, then we hit the LowerToHW
pass with a bunch of bundle types around.  This pass is not often used,
and this must have regressed at some point.

This also adds an integration test to ensure that CHIRRTL memories are being
properly lowered to verilog.
2021-08-21 15:29:04 -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
John Demme ca7cf2494f
[PyCDE] Instance hierarchy walks (#1614) 2021-08-20 18:13:37 -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
John Demme 3d91752243
[PyCDE] Value naming enhancements (#1609)
Provide a name property on Value and use it to better name registers, array gets, and struct field gets.
2021-08-19 23:49:13 -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 577313a37d Another LLVM submodule bump 2021-08-19 00:15:44 -07: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
mikeurbach 31299c1624
[CI] Directly use the cache action in the nightly build. (#1593)
Different build configurations were previously trampling on the same
cache directory on the build host. The cache directory wasn't
configurable, so just use the cache action directly.
2021-08-18 15:22:46 -06: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
Fabian Schuiki 0c0f314301
[firtool] Add --parse-only option (#1603)
Add a `--parse-only` option to `firtool` which causes the program to
stop after the FIR/MLIR and annotation input files have been parsed and
processed, and writes the resulting MLIR module to the output. This is
interesting and useful since `firtool` performs a unique combination of
input translation and annotation scattering that is not trivially
reproduced with `circt-translate` and `circt-opt`. Useful for test case
reduction.
2021-08-18 18:36:03 +02:00
Fabian Schuiki cacbaf7210
[reduce] Add a first proof-of-concept reducer implementation with sample FIRRTL dialect reducers (#1591)
- Update/rewrite the `circt-reduce` tool with a custom proof-of-concept
  reducer for the FIRRTL dialect. This is supposed to be a pathfinding
  exercise and just uses FIRRTL as an example. The intent is for other
  dialects to be able to produce sets of their own reducers that will
  then be combined by the tool to operate on some input IR.

  At this point, `circt-reduce` can be used to reduce FIRRTL test cases by
  converting as many `firrtl.module` ops into `firrtl.extmodule` ops as
  possible while still maintaining some interesting characteristic.

- Extend `circt-reduce` to support exploratively applying passes to the
  input in an effort to reduce its size. Also add the ability to specify
  an entire list of potential reduction strategies/patterns which are
  tried in order. This allows for reductions with big effect, like
  removing entire modules, to be tried first, before taking a closer
  look at individual instructions.

- Add reduction strategies to `circt-reduce` that try to replace the
  right hand side of FIRRTL connects with `invalidvalue`, and generally 
  try to remove operations if they have no results or no users of their 
  results.

- Add a reduction pattern to `circt-reduce` that replaces instances of
  `firrtl.extmodule` with a `firrtl.wire` for each port. This can
  significantly reduce the complexity of test cases by pruning the
  module hierarchy of unused modules.

- Move the `Reduction` class and sample implementations into a separate
  header and implementation file. These currently live in
  `tools/circt-reduce`, but should later move into a dedicated reduction
  framework, maybe in `include/circt/Reduce`, where dialects can easily
  access them and provide their own reduction implementations.
2021-08-18 17:22:43 +02: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 a22c21e19b [Tests] Rework this test to not use comb.merge for no reason, NFC. 2021-08-17 22:28:31 -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 18b5b57e1e
[ExportVerilog] Legal Verilog in tests, NFC
Modify sv-dialect.mlir to generate legal Verilog, with properly defined
`defines so that the output can be directly checked with a linter.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-17 12:24:14 -04: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 94625d7f58
[ExportVerilog] Emit legal Verilog in test, NFC
Change sv-dialect test to emit legal Verilog (a comment) from an
sv.verbatim op as opposed to raw strings that are illegal Verilog.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
2021-08-17 11:25:12 -04:00