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 Linting Framework #2435

Merged
merged 26 commits into from
May 6, 2020
Merged

Chisel Linting Framework #2435

merged 26 commits into from
May 6, 2020

Conversation

azidar
Copy link
Contributor

@azidar azidar commented Apr 25, 2020

Type of change: new feature

Impact: API Addition

Development Phase: implementation

Release Notes

  • Added CHISEL_OPTIONS environment variable
  • Added FIRRTL_OPTIONS environment variable
  • Added Chisel linting options (--lint, --lint-options, --lint-whitelist:anon-regs, --lint-whitelist:trunc-widths)

Summary

There have been many instances where consumers of rocket-chip Verilog have to run LEC tools, debuggers, physical design tools. When registers don't have stable names, changes to the generator cause changes to the names of registers, making the lives of those downstream more difficult.

This PR adds the following:

  • A linting check which looks for unnamed registers and reports them to the user as an error
  • A linting check for connections from a larger-width signal to a smaller-width signal

To try it out:

> cd emulator
> CHISEL_OPTIONS="--lint * --lint-options display:*=5" make
...
Exception in thread "main" freechips.rocketchip.linting.LintException: 
Lint rule anon-regs: 102 exceptions!
 - Recommended fix:
     Use named intermediate val, or if that fails use @chiselName or *.suggestName(...)
 - Whitelist file via Chisel cmdline arg:
     --lint-whitelist:anon-regs Arbiter.scala,AtomicAutomata.scala,BTB.scala,Broadcast.scala,CSR.scala,Counter.scala,Counters.scala,DCache.scala,Debug.scala,Deinterleaver.scala,Edges.scala,FIFOFixer.scala,FPU.scala,Fragmenter.scala,Frontend.scala,HellaCacheArbiter.scala,ICache.scala,Interrupts.scala,Monitor.scala,Periphery.scala,Plic.scala,Reg.scala,Replacement.scala,RocketCore.scala,RocketTile.scala,ShiftQueue.scala,SourceShrinker.scala,ToAXI4.scala,ToTL.scala,Valid.scala,Xbar.scala,package.scala
 - Whitelist file via Chisel scala API:
     whitelist("anon-regs", Set("Arbiter.scala","AtomicAutomata.scala","BTB.scala","Broadcast.scala","CSR.scala","Counter.scala","Counters.scala","DCache.scala","Debug.scala","Deinterleaver.scala","Edges.scala","FIFOFixer.scala","FPU.scala","Fragmenter.scala","Frontend.scala","HellaCacheArbiter.scala","ICache.scala","Interrupts.scala","Monitor.scala","Periphery.scala","Plic.scala","Reg.scala","Replacement.scala","RocketCore.scala","RocketTile.scala","ShiftQueue.scala","SourceShrinker.scala","ToAXI4.scala","ToTL.scala","Valid.scala","Xbar.scala","package.scala"))
 - Disable this linting check:
     Omit anon-regs from --lint option
 - Modify display settings with:
     --lint-options ...,display:anon-regs=<number>,...
anon-regs.1: @[Arbiter.scala 21:23]  in Set(TLXbar_7, AXI4ToTL, TLXbar_5, TLXbar, TLXbar_8)
anon-regs.2: @[Arbiter.scala 54:30]  in Set(TLXbar_7, AXI4ToTL, TLBroadcast, TLError_1, TLXbar_5, TLXbar, TLXbar_8, TLAtomicAutomata_1)
anon-regs.3: @[Arbiter.scala 79:26]  in Set(TLXbar_7, AXI4ToTL, TLBroadcast, TLError_1, TLXbar_5, TLXbar, TLXbar_8, TLAtomicAutomata_1)
anon-regs.4: @[AtomicAutomata.scala 76:28]  in Set(TLAtomicAutomata_1)
anon-regs.5: @[AtomicAutomata.scala 77:24]  in Set(TLAtomicAutomata_1)

Lint rule trunc-widths: 308 exceptions!
 - Recommended fix:
     Truncate width prior to connections
 - Whitelist file via Chisel cmdline arg:
     --lint-whitelist:trunc-widths BTB.scala,Broadcast.scala,BundleMap.scala,CSR.scala,Counters.scala,Custom.scala,DCache.scala,Debug.scala,Deinterleaver.scala,DivSqrtRecFN_small.scala,Edges.scala,FIFOFixer.scala,FPU.scala,Fragmenter.scala,Frontend.scala,HellaCache.scala,HellaCacheArbiter.scala,IBuf.scala,Monitor.scala,MulAddRecFN.scala,PMP.scala,PTW.scala,Plic.scala,PlusArg.scala,RegisterRouter.scala,RocketCore.scala,SimAXIMem.scala,SourceShrinker.scala,TLB.scala,ToAXI4.scala
 - Whitelist file via Chisel scala API:
     whitelist("trunc-widths", Set("BTB.scala","Broadcast.scala","BundleMap.scala","CSR.scala","Counters.scala","Custom.scala","DCache.scala","Debug.scala","Deinterleaver.scala","DivSqrtRecFN_small.scala","Edges.scala","FIFOFixer.scala","FPU.scala","Fragmenter.scala","Frontend.scala","HellaCache.scala","HellaCacheArbiter.scala","IBuf.scala","Monitor.scala","MulAddRecFN.scala","PMP.scala","PTW.scala","Plic.scala","PlusArg.scala","RegisterRouter.scala","RocketCore.scala","SimAXIMem.scala","SourceShrinker.scala","TLB.scala","ToAXI4.scala"))
 - Disable this linting check:
     Omit trunc-widths from --lint option
 - Modify display settings with:
     --lint-options ...,display:trunc-widths=<number>,...
trunc-widths.1: @[:[email protected]] _T_3704 <= _T_3702 // Connecting width 64 to width 16 in Set(CSRFile)
trunc-widths.2: @[:[email protected]] _T_3733 <= wdata // Connecting width 64 to width 32 in Set(CSRFile)
trunc-widths.3: @[:[email protected]] _T_3794 <= _T_3792 // Connecting width 64 to width 16 in Set(CSRFile)
trunc-widths.4: @[:[email protected]] _T_3978 <= _T_3976 // Connecting width 64 to width 8 in Set(CSRFile)
trunc-widths.5: @[:[email protected]] _T_3998 <= _T_3996 // Connecting width 56 to width 8 in Set(CSRFile)
Makefrag-verilator:16: recipe for target '/scratch/adami/work/rocket-chip-dev/rocket-chip-linting/emulator/generated-src/freechips.rocketchip.system.DefaultConfig.v' failed

To see the compiler options, run with:

> cd emulator
> CHISEL_OPTIONS="--help" make
...
freechips.rocketchip.linting.LintReporter
  --lint [*]|[<lintRule>,<lintRule>,...]
                           Enable linting for specified rules, where * is all rules. Available rules: anon-regs,trunc-widths.
  --lint-options (strict|warn)[,displayTotal=<numError>][,display:<lintName>=<numError>]
                           Customize linting options, including strict/warn or number of violations displayed.
freechips.rocketchip.linting.rule.LintAnonymousRegisters
  --lint-whitelist:anon-regs <filename1>.scala[,<filename2>.scala]*
                           Enable linting anonymous registers for all files except provided files.
freechips.rocketchip.linting.rule.LintTruncatingWidths
  --lint-whitelist:trunc-widths <filename1>.scala[,<filename2>.scala]*
                           Enable linting anonymous registers for all files except provided files.`1
...

TODO:

  • Add scaladoc to all files
  • Solicit feedback from the community on ideas/implementation

@jackkoenig
Copy link
Contributor

This looks great overall. I would be more specific than just "linting" since there are other possible lint rules we may want to add some day. I would call this --lint-register-names or something like that.

@aswaterman
Copy link
Member

Can't we fix 80+% of these with @chiselName instead of the more verbose suggestName approach?

@aswaterman
Copy link
Member

... or perhaps the suggestName ones are the ones where @chiselName doesn't cut it.

aswaterman
aswaterman previously approved these changes Apr 25, 2020
Copy link
Member

@aswaterman aswaterman left a comment

Choose a reason for hiding this comment

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

rocket changes lgtm.

@jackkoenig
Copy link
Contributor

... or perhaps the suggestName ones are the ones where @chiselName doesn't cut it.

Yeah I think @chiselName is missing them, bug to-be-fixed but no reason to suffer with bad register names in the meantime.

@hcook
Copy link
Member

hcook commented Apr 25, 2020

Seems like an ok way to document @chiselName failures; @azidar can confirm but I think he attempted @chiselName first in most cases.

@azidar
Copy link
Contributor Author

azidar commented Apr 25, 2020

Yeah, @chiselName didn't fix the majority of these. I think there is a serious bug, but in the meantime this PR highlights where we can fix these.

Copy link
Contributor

@mwachs5 mwachs5 left a comment

Choose a reason for hiding this comment

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

Thanks!
Your PR mentions modules, but I think you only fixed registers. Does that mean unnamed
Modules aren’t detected by the linter, or aren’t actually present?

In general I see the naming algorithm you applied, but in some cases when you had to make up a name you said “reg_foo” and in others “foo_reg”, not sure if that was intentional in those cases? FWIW I prefer the latter

Makefrag Outdated Show resolved Hide resolved
src/main/scala/rocket/Frontend.scala Outdated Show resolved Hide resolved
src/main/scala/rocket/RocketCore.scala Outdated Show resolved Hide resolved
src/main/scala/rocket/RocketCore.scala Outdated Show resolved Hide resolved
src/main/scala/tilelink/FIFOFixer.scala Outdated Show resolved Hide resolved
src/main/scala/tilelink/Monitor.scala Outdated Show resolved Hide resolved
src/main/scala/util/Counters.scala Outdated Show resolved Hide resolved
@azidar
Copy link
Contributor Author

azidar commented Apr 27, 2020

Ok so my plan is to make this PR only add the Linting transform and options, but not run the linter by default and not include any of the name fixes so all the regressions pass. That will let us incrementally change names but still get this PR in.

azidar and others added 6 commits April 27, 2020 13:19
* Update some uses of @chiselName to disable new prefixing behavior
* Update Stage/Phase dependencies to new Dependency instead of Class
* Technically bumped to merge-base of each tag with their respective
  release branches: 3.3.x for chisel3 and 1.3.x for firrtl
  This better supports Wit dependencies
* Include all chisel3 class files on FIRRTL run classpath
* Bump api-chisel3-sifive to resolve Wit conflicts and bump
  api-scala-sifive to support Wit >= v0.13.0
@azidar azidar changed the title Chisel Linting for unnamed Regs and Instances Chisel Linting for unnamed Regs Apr 28, 2020
jackkoenig
jackkoenig previously approved these changes Apr 28, 2020
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.

Generally looks good. A few nits but I'm okay with leaving them for later improvement

src/main/scala/linting/LintAnonymousRegisters.scala Outdated Show resolved Hide resolved
src/main/scala/linting/LintAnonymousRegisters.scala Outdated Show resolved Hide resolved
src/main/scala/linting/LintAnonymousRegisters.scala Outdated Show resolved Hide resolved
@azidar azidar changed the base branch from master to chisel-3-3 April 30, 2020 21:29
@azidar azidar dismissed aswaterman’s stale review April 30, 2020 21:31

No longer including changes to rocketchip RTL

@azidar azidar dismissed jackkoenig’s stale review April 30, 2020 21:32

Major changes since review

azidar and others added 7 commits April 30, 2020 14:33
* Update some uses of @chiselName to disable new prefixing behavior
* Update Stage/Phase dependencies to new Dependency instead of Class
* Technically bumped to merge-base of each tag with their respective
  release branches: 3.3.x for chisel3 and 1.3.x for firrtl
  This better supports Wit dependencies
* Include all chisel3 class files on FIRRTL run classpath
* Bump api-chisel3-sifive to resolve Wit conflicts and bump
  api-scala-sifive to support Wit >= v0.13.0
@azidar azidar changed the title Chisel Linting for unnamed Regs Chisel Linting Framework May 1, 2020
src/main/scala/linting/LintAnnotation.scala Outdated Show resolved Hide resolved
src/main/scala/linting/LintAnnotation.scala Outdated Show resolved Hide resolved
@jackkoenig
Copy link
Contributor

@azidar hey sorry I force pushed the chisel-3-3 branch so you'll need to rebase, I didn't realize this was against that branch. Why is this PRed against that branch instead of master? Does it rely on Chisel 3.3 stuff?

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, but please retarget against master

@azidar azidar changed the base branch from chisel-3-3 to master May 5, 2020 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants