Skip to content

Conversation

@jackkoenig
Copy link
Contributor

@jackkoenig jackkoenig commented Feb 27, 2025

Future work TODO:

  • Stop running the Converter
  • Stop using firrtl.ir.Type in Properties
  • Stop using firrtl.ir.Type in type aliases
  • Delete the Converter
  • Delete firrtl.ir.Serializer
  • Lazily serialize Annotations
  • Lazily serialize Module ports

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 request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • Performance improvement

Desired Merge Strategy

  • Squash

Release Notes

This reduces peak memory use when serializing to .fir. It heavily depends on the design, but for designs with a single very large module, we have measured 20-25% reductions in peak memory use. For most cases, the reduction will likely be more modest.

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels? (Select the most appropriate one based on the "Type of Improvement")
  • Did you mark the proper milestone (Bug fix: 3.6.x, 5.x, or 6.x depending on impact, API modification or big change: 7.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you do one of the following when ready to merge:
    • Squash: You/ the contributor Enable auto-merge (squash) and clean up the commit message.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

@jackkoenig jackkoenig added the Feature New feature, will be included in release notes label Feb 27, 2025
@jackkoenig jackkoenig force-pushed the jackkoenig/serialize-chiselir branch 6 times, most recently from de34960 to 104f96f Compare February 28, 2025 23:56
@jackkoenig jackkoenig marked this pull request as ready for review February 28, 2025 23:57
@jackkoenig jackkoenig added Performance Improves performance, will be included in release notes and removed Feature New feature, will be included in release notes labels Feb 28, 2025
@jackkoenig
Copy link
Contributor Author

I think this is good to go to get the ball rolling. I think the TODO items should be done in separate PRs.

@jackkoenig jackkoenig force-pushed the jackkoenig/serialize-chiselir branch 3 times, most recently from 5300633 to 86fcf32 Compare March 1, 2025 17:24
@jackkoenig jackkoenig force-pushed the jackkoenig/serialize-chiselir branch from 86fcf32 to 7c7e78f Compare March 1, 2025 17:25
@jackkoenig jackkoenig requested a review from seldridge March 1, 2025 17:34
Copy link
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

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

Superficial review given the mechanical nature of this.

Thank you for doing this tedious work.

What is the path now to deprecate the emission flows that we don't want to support?


case class ULit(n: BigInt, w: Width) extends LitArg(n, w) {
def name: String = "UInt" + width + "(0h0" + num.toString(16) + ")"
def name: String = "UInt" + width + "(0h" + num.toString(16) + ")"
Copy link
Member

Choose a reason for hiding this comment

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

This is the kind of thing that could cause a bug. However, this looks fine. This should also cause simulations to fail if it was a problem (hopefully).

This is 💯 cleaner output, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I could back this out--this change will be needed once I updated Properties to stop using FIRRTL IR and the converter, but it seems I backed out the rest of that change but not this. I do think we should still do this because it makes it consistent with what the serializer is doing (and ultimately we can call this from the serializer). I'll check for issues though of course.

import chisel3.reflect.DataMirror
import chisel3.simulator.scalatest.ChiselSim
import chisel3.simulator.stimulus.RunUntilFinished
import chisel3.testing.scalatest.FileCheck
Copy link
Member

Choose a reason for hiding this comment

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

🐐

@jackkoenig
Copy link
Contributor Author

What is the path now to deprecate the emission flows that we don't want to support?

Deprecate the Convert phase any APIs that imply it (e.g. ChiselStage.convert). We can either backport the deprecation to 6.7.0 or just do it in 7.0, I'm not that fussed either way.

The other piece is to just make sure nothing about the Converter nor firrtl.ir.Serializer are load bearing. There's a couple of small pieces that are (types in Properties as I've mentioned).

@jackkoenig
Copy link
Contributor Author

I tested this on a large set of designs and found no Verilog diff except like a dozen literal assignments reordered (out of millions of lines of Verilog). Obviously identical by inspection.

Note that the emitted FIRRTL will differ slightly, primarily in these 3 ways:

  • The current (old) emitter puts a couple of blank new lines after layerblocks, this new one does not
  • This new emitter puts one extra new line after module bodies. I probably should fix this but have already qualified it as is so probably in follow on work.
  • This current (old) emitter won't emit SInt literals, it converts them to UInts then wraps in asUInt. The new emitter just emits the SInt literal. This is a real change thus the need to check that Verilog is identical.

@jackkoenig jackkoenig merged commit c1b5135 into main Mar 4, 2025
15 checks passed
@jackkoenig jackkoenig deleted the jackkoenig/serialize-chiselir branch March 4, 2025 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Performance Improves performance, will be included in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants