-
Notifications
You must be signed in to change notification settings - Fork 616
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
Chisel plugin bundle elements handler #2306
Conversation
fdc952a
to
a2346bf
Compare
plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala
Outdated
Show resolved
Hide resolved
plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala
Outdated
Show resolved
Hide resolved
plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala
Outdated
Show resolved
Hide resolved
plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala
Outdated
Show resolved
Hide resolved
f80f55a
to
6d3c597
Compare
plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala
Outdated
Show resolved
Hide resolved
plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala
Outdated
Show resolved
Hide resolved
plugin/src/main/scala/chisel3/internal/plugin/ChiselPlugin.scala
Outdated
Show resolved
Hide resolved
plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala
Outdated
Show resolved
Hide resolved
docs/src/appendix/chisel-plugin.md
Outdated
The Chisel plugin provides some operations that are too difficult, or not possbile, | ||
to implement through regular Scala code. | ||
|
||
## Compiler plugin operations | ||
1. Automatically generates the `cloneType` methods of Bundles | ||
2. Records that this plugin ran on a bundle by adding a method `_usingPlugin: Boolean = true` | ||
3. Generates a function that returns list of the hardware fields in a bundle `_elementsImpl` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is useful information, but it feels like a weird mix of "useful to users" and "useful only to contributors". I think it would be better to either split this into 2 files, or at least call out with a ##
level title ("Notes for Contributors") or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed -- for example should this appear on the website?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd generally say the contributor only stuff should not live on the website, but I'm not to fussed either way, it just needs to be clear what is what.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jackkoenig @mwachs5 I agree this is weird. I moved this purposely into the README instead of placing it where it would be picked up by website. This should be a short term option that quickly (maybe by 3.5.2) becomes the default.
I tried to simplify and condense things a bit. Not sure how much more to do here
… `BundleComponent` For each `Bundle` find the relevant visible Chisel field members and construct a hard-coded list of the elements and their types and implement as `_elementsImpl` For more details: See the docs/src/appendix/chisel-plugin.md Enable the Bundle element generator in the Plugin - Should be no change in API - Handles inheritance and mixins - Handles Seq[Data - Tests in BundleElementSpec
- completely refactored BundleElementsSpec to not require BundleComparator - Removed BundleComparator.scala - Based on PR review - renamed flags buildElements* to genBundleElements* - removed cargo cult comments - -
- changed build.sbt to set genBundleElements to be true - changed build.sc to set genBundleElements to be true
- compare data fields as well as names
- Moved `chisel-plugin.md` to `plugins/README.md` as it is strictly for chisel internals work - Implemented wording changes based on PR review comments
- Some small changes to BundleElementsSpec - Added a section of negative tests "plugin tests should fail properly in the following cases" - simplified assertElementsMatchExpected - Added an example of pathological bundle elements `val field: Any = UInt(22.W)`
b84dc3a
to
a118acc
Compare
build.sc
Outdated
@@ -58,7 +58,8 @@ trait CommonModule extends CrossSbtModule with PublishModule with ScalafmtModule | |||
override def scalacOptions = T { | |||
super.scalacOptions() ++ Agg( | |||
"-deprecation", | |||
"-feature" | |||
"-feature", | |||
"-P:chiselplugin:genBundleElements" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to only affect the tests, put it in object test
below.
I have not done super robust benchmarking here, but for a pretty typical large SiFive design, this makes Chisel ~16% faster. Pretty good! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Excellent work @chick!
Adds generation of `Bundle.elements` method to the chores done by the compiler plugin For each `Bundle` find the relevant visible Chisel field members and construct a hard-coded list of the elements and their names implemented as `_elementsImpl` For more details: See plugins/README.md - Should be no change in API - Handles inheritance and mixins - Handles Seq[Data] - Tests in BundleElementSpec Co-authored-by: chick <chick.markley@sifive.com> Co-authored-by: Jack Koenig <koenig@sifive.com> (cherry picked from commit 237200a)
Adds generation of `Bundle.elements` method to the chores done by the compiler plugin For each `Bundle` find the relevant visible Chisel field members and construct a hard-coded list of the elements and their names implemented as `_elementsImpl` For more details: See plugins/README.md - Should be no change in API - Handles inheritance and mixins - Handles Seq[Data] - Tests in BundleElementSpec Co-authored-by: chick <chick.markley@sifive.com> Co-authored-by: Jack Koenig <koenig@sifive.com> (cherry picked from commit 237200a) Co-authored-by: Chick Markley <chick@qrhino.com>
Contributor Checklist
docs/src
?Type of Improvement
Performance improvement
Code refactoring
API Impact
Could affect unusual Bundle constructions.
Some error messages have been changed
Backend Code Generation Impact
This should not impact code generation
Desired Merge Strategy
Release Notes
This eliminates the use of reflection in Aggregate.scala when building the
elements
method of a Bundle.This should result in improvement in elaboration times for large designs.
Reviewer Checklist (only modified by reviewer)
3.3.x
, [small] API extension:3.4.x
, API modification or big change:3.5.0
)?Please Merge
?