Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git-subtree add sifive/chisel-circt #2477

Merged
merged 36 commits into from
Aug 4, 2022
Merged

Conversation

seldridge
Copy link
Member

@seldridge seldridge commented Apr 6, 2022

This commit is the first step towards enabling CIRCT-compiled Chisel natively inside Chisel (as opposed to relying on a separate library).

This does three things:

  1. It uses git-subtree to add https://github.com/sifive/chisel-circt (with history) as a directory called circt/.
  2. It moves and updates the contents of circt/ into src/main/scala/circt/ or src/test/scala/circt/.
  3. It removes unnecessary files (build.sbt/build.sc) from the circt tree and updates the README to reference the fact that this is no longer a separate dependency.

This PR is expected to fail until we have a way of adding CIRCT as a dependency to the CI.

seldridge and others added 27 commits January 13, 2021 21:02
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add a "handover" option that augments circt.stage.ChiselStage to lower
using a combination of the Scala FIRRTL Compiler (SFC) followed by
CIRCT.  The handover can be set at CHIRRTL (don't run the SFC), High
FIRRTL, Middle FIRRTL, Low FIRRTL, or Optimized Low FIRRTL.

Include tests of this behavior by looking at the
FirrtlCircuitAnnotation that exists before running CIRCT for different
handover values.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add --handover option to lower partially using SFC
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
- Add Maven release, Sonatype snapshots, and Javadoc.io badges
- Improve setup instructions

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add an option to output using a "*.v" suffix.  This is still using the
CIRCT SystemVerilog back end, though.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Change command line option passed to "firtool" due to upstream change.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
* add mill build system
* bump to Chisel 3.5.0
* use cross build to select Scala version.
* add gitignore
* Add/use Compiler Plugin
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Change the default handover from optimized low FIRRTL to CHIRRTL.  This
is done because CIRCT is an essentially complete FIRRTL compiler now.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Change ChiselStage to pass annotations to firtool via a file.  Also, add
logic to remove lots of annotations and convert them to equivalent
firtool options.

Any annotations that we don't know what to do with are passed on to firtool to
let it deal with them.  This has the effect of both communicating things like
DontTouchAnnotation and also providing information to the user that they are
passing annotations that firtool doesn't know how to handle.  To do the latter
checking "-warn-on-unprocessed-annotations" is turned on.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add numerous tests that are checking the behavior of annotation passing
and consumption by CIRCT.  This adds tests for:

  - InlineInstance
  - FlattenInstance
  - dontTouch (of wires and nodes)
  - forceName (of modules only)
  - Deduplication and doNotDedup

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add Annotation support and conversion to firtool CLI options.
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Add an annotation, FirtoolOption, that can be used to pass a command
line option directly to firtool.  More than one FirtoolOption can be
specified.  Add a test that shows using this to enable case statement
emission through a "--lowering-option".

Fixes #12.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@ekiwi
Copy link
Contributor

ekiwi commented Apr 6, 2022

Should this be in an experimental package or otherwise marked as not meant for general usage until stable binary releases for firtool are available for Mac and Linux?

@seldridge
Copy link
Member Author

Good point, Kevin. My plan is to block this PR (keep it as a draft) until we have binary releases available for CIRCT.

@ekiwi
Copy link
Contributor

ekiwi commented Apr 6, 2022

Good point, Kevin. My plan is to block this PR (keep it as a draft) until we have binary releases available for CIRCT.

Sounds good. Do you think it would be feasible to have some code that automatically determines the platform we are on and then downloads the latest firtool release (or a compatible version) for the current platform from github?
That way it would be just as easy as using the old firrtl compiler.

mwachs5 and others added 2 commits July 6, 2022 20:30
* Add scalafmt files from chisel3
* Enable scalafmt in SBT
* Scalafmt all the files
* Add scalafmt check to CI
Add support for the new, finer-grained aggregate preservation options
that were added to CIRCT/firtool.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@mwachs5
Copy link
Contributor

mwachs5 commented Aug 3, 2022

firtool binaries is now published on each release of CIRCT, so I plan to resurrect this PR

@seldridge seldridge force-pushed the dev/seldridge/chisel-circt branch from 6d87c27 to fb844be Compare August 4, 2022 05:15
@CLAassistant
Copy link

CLAassistant commented Aug 4, 2022

CLA assistant check
All committers have signed the CLA.

@seldridge
Copy link
Member Author

firtool binaries is now published on each release of CIRCT, so I plan to resurrect this PR

Specifically, this was added in llvm/circt#3617 and is automatically published as part of the release assets for CIRCT. E.g., the SiFive 1.11.0 release of CIRCT binaries are available here: https://github.com/llvm/circt/releases/tag/sifive%2F1%2F11%2F0 This is also what I'm using for CI in this PR.

@seldridge seldridge marked this pull request as ready for review August 4, 2022 05:36
@seldridge seldridge added the Merge with merge commit Please merge with a merge commit, do not squash and merg label Aug 4, 2022
Change GitHub CI to use a tagged, published Ubuntu binary of CIRCT
instead of relying on a nightly docker image.  This is both: (1) more
stable and (2) way faster.  This also removes a barrier to upstreaming
chisel-circt with chisel3.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@seldridge seldridge requested a review from jackkoenig August 4, 2022 06:14
@seldridge
Copy link
Member Author

Logistically, any feedback on this PR that actually requests code modifications I'll address on upstream chisel-circt and then fold into this PR. I'd like to keep this PR as a pure: (1) git subtree add, (2) mv circt/ src/main/scala/, (3) enable CI, and (4) tag a final release of chisel-circt and archive it. If there are more nitty concerns with the code that can wait, I'm signing myself up to fix these after this lands.

@mwachs5
Copy link
Contributor

mwachs5 commented Aug 4, 2022

ok, so you would prefer to merge outstanding chisel-circt PRs first before merging into chisel3?

EDIT i misread the comment. Does this PR currently include at least the scalafmt change?

@seldridge
Copy link
Member Author

ok, so you would prefer to merge outstanding chisel-circt PRs first before merging into chisel3?

I'd rather not block this on those PRs. We can move them over here once this lands.

I was instead saying if Jack comes in and wants me to rewrite CIRCTStage.scala, I would instead go do that on sifive/chisel-circt and then rework this PR here to incorporate that. I'm aiming to have a clean break where sifive/chisel-circt ends development and is archived and that end point is where development in chisel3 starts.

blackbox = true
false
/* Any emitters should not be passed to firtool. */
case _: firrtl.Emitter => false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you specify the target if you emitters are ignored? Like how would I distinguish between generating Firrtl or SystemVerilog?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a CIRCTTargetAnnotation that will control it. They main issue here is that there isn't a good way of adding multiple RunFirrtlTransformAnnotation(_: firrtl.Emitter)s to CIRCT as it's trying to work towards a fixed target, e.g., FIRRTL Dialect, HW Dialect, SV Dialect, or SV.

It's reasonable that if there was one RunFirrtlTransformAnnotation(_ : firrtl.Emitter) that this could be used to tell CIRCT what to compile to. However, it seemed cleaner to just strip this and force users to use the new annotation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this a bit more... it would probably be better to actually error on this. I can do this in a follow-up.

This should be basically dead code right now as the expectation is that a user is going to use circt.stage.ChiselStage which is not going to use a RunFirrtlTransformAnnotation to tell CIRCT what emitter to use. There's a separate API/Annotation for that, CIRCTTargetAnnotation. A user could see weird behavior if they are doing one of the following:

  1. Generating a RunFirrtlTransformAnnotation(_ : Emitter) inside a ChiselAnnotation.
  2. Building a custom stage out of Chisel3 phases and CIRCT phases.
  3. Possibly other weird things.

@mwachs5
Copy link
Contributor

mwachs5 commented Aug 4, 2022

I agree that if there are tweaks we want to make to chisel-circt we can do that here once this is on.

What is the story for backporting and backwards compatability binary checking for this chunk of code? For now will we just have this on master branch and worry about the binary compatability story once it gets into 3.6?

@jackkoenig
Copy link
Contributor

What is the story for backporting and backwards compatability binary checking for this chunk of code? For now will we just have this on master branch and worry about the binary compatability story once it gets into 3.6?

No backporting, this is a Chisel 3.6 addition.

@mwachs5
Copy link
Contributor

mwachs5 commented Aug 4, 2022

Ok, if this is a 3.6 addition and we are stopping any development on the chisel-circt repo, that is a bit tricky for anyone who wants to use 3.5.x and chisel-circt and needs chisel-circt improvements... But I'm Ok with a workflow that makes parallel PRs to chisel-circt and this repo until this is actually released w chisel

@seldridge
Copy link
Member Author

seldridge commented Aug 4, 2022

that is a bit tricky for anyone who wants to use 3.5.x and chisel-circt and needs chisel-circt improvements

I wouldn't worry about this. chisel-circt is ranked 607574 on Maven. chisel3 is ranked 17385. Also, chisel-circt was always an extremely experimental thing. I don't see a good reason to commit to maintenance of sifive/chisel-circt for a hypothetical user on 3.5.x when the answer is: (1) use SFC for 3.5.x (which is the official policy) or (2) switch to 3.6 (which should be easy if somebody is already relying on chisel-circt which has limitations around supporting experimental Chisel APIs).

mwachs5 and others added 5 commits August 4, 2022 15:24
…rrtool (#15)

- Fix handling of EmitAllModulesAnnotation
- Fix stderr handling/erroring out if firtool errors during compile
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
git-subtree-dir: circt
git-subtree-mainline: 0b2c211
git-subtree-split: 7dd9f0e
Move the git-subtree added sifive/chisel-circt repository from "circt/"
into "src/main/scala/circt/" and "src/test/scala/circtTests/".  Update
the chisel-circt README, which now lives in the src directory, to not
indicate that this is a published dependency anymore.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
Use the published Ubuntu 20.04 binary of CIRCT to enable chisel-circt
tests in CI.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@seldridge seldridge force-pushed the dev/seldridge/chisel-circt branch from fb844be to abab0dd Compare August 4, 2022 19:32
@seldridge
Copy link
Member Author

I force pushed this after landing a PR that @mwachs5 needed. That closes out any known needed development on sifive/chisel-circt.

@seldridge seldridge merged commit cc55936 into master Aug 4, 2022
@seldridge seldridge deleted the dev/seldridge/chisel-circt branch August 4, 2022 20:21
@seldridge
Copy link
Member Author

Merging after verbal approval from @jackkoenig.

Copy link
Member

@sequencer sequencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late view, but not too late, glad we didn't version 3.6.0 now.
Just some small questions:

  1. Is possible to add as less as possible public APIs to make room for future improvements.
  2. IIRC, the handover behavior will be removed eventually, what's the roadmap of this.

Comment on lines +6 to +19
object Implicits {

/** Helpers for working with Boolean */
implicit class BooleanImplicits(a: Boolean) {

/** Construct an Option from a Boolean. */
def option[A](b: => A): Option[A] =
if (a)
Some(b)
else
None
}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought these APIs may not be public?

Comment on lines +6 to +19
object Implicits {

/** Helpers for working with Boolean */
implicit class BooleanImplicits(a: Boolean) {

/** Construct an Option from a Boolean. */
def option[A](b: => A): Option[A] =
if (a)
Some(b)
else
None
}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay review:
Should we private these to avoid introducing more public APIs?

Comment on lines +45 to +49
- name: Install CIRCT
run: |
mkdir usr
wget https://github.com/llvm/circt/releases/download/sifive%2F1%2F11%2F0/circt-bin-ubuntu-20.04.tar.gz -O - | tar -zx -C usr/
echo "$(pwd)/usr/bin" >> $GITHUB_PATH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope we can have a better way to install CIRCT in the system.


}

object CIRCTHandover extends HasShellOptions {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we might eventually get rid of the Handover behavior. Am I right?

import firrtl.AnnotationSeq
import firrtl.options.Phase

class AddDefaults extends Phase {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be private too?

import firrtl.options.Viewer.view
import firrtl.stage.{Forms, RunFirrtlTransformAnnotation}

class MaybeSFC extends Phase {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merge with merge commit Please merge with a merge commit, do not squash and merg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants