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

Chisel plugin bundle elements handler #2306

Merged
merged 9 commits into from
Feb 1, 2022

Conversation

chick
Copy link
Contributor

@chick chick commented Dec 16, 2021

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you add appropriate documentation in docs/src?
  • Did you state the API impact?
  • Did you specify the code generation impact?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

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)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (Bug fix: 3.3.x, [small] API extension: 3.4.x, API modification or big change: 3.5.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you mark as Please Merge?

@chick chick added code improvement release issue Challenge Issue A nice-to-have but difficult to implement labels Dec 16, 2021
@chick chick requested review from jackkoenig and mwachs5 December 16, 2021 21:52
@chick chick self-assigned this Dec 16, 2021
@jackkoenig jackkoenig force-pushed the chisel-plugin-bundle-elements-handler branch 2 times, most recently from fdc952a to a2346bf Compare January 7, 2022 19:42
@jackkoenig jackkoenig added this to the 3.5.x milestone Jan 20, 2022
@chick chick force-pushed the chisel-plugin-bundle-elements-handler branch from f80f55a to 6d3c597 Compare January 20, 2022 19:55
Comment on lines 3 to 10
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`

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

chick added 7 commits January 31, 2022 11:42
… `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)`
@jackkoenig jackkoenig force-pushed the chisel-plugin-bundle-elements-handler branch from b84dc3a to a118acc Compare January 31, 2022 23:56
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"
Copy link
Contributor

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.

@jackkoenig
Copy link
Contributor

I have not done super robust benchmarking here, but for a pretty typical large SiFive design, this makes Chisel ~16% faster. Pretty good!

Copy link
Contributor

@jackkoenig jackkoenig left a 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!

@jackkoenig jackkoenig marked this pull request as ready for review February 1, 2022 18:24
@jackkoenig jackkoenig enabled auto-merge (squash) February 1, 2022 18:28
@jackkoenig jackkoenig added the Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. label Feb 1, 2022
@jackkoenig jackkoenig merged commit 237200a into master Feb 1, 2022
@jackkoenig jackkoenig deleted the chisel-plugin-bundle-elements-handler branch February 1, 2022 19:10
mergify bot pushed a commit that referenced this pull request Feb 1, 2022
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)
@mergify mergify bot added the Backported This PR has been backported label Feb 1, 2022
mergify bot added a commit that referenced this pull request Feb 1, 2022
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported This PR has been backported Challenge Issue A nice-to-have but difficult to implement code improvement Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. release issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants