This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add support for custom CSRs for Sifive S76.
ClosedPublic

Authored by garvitgupta08 on Jun 21 2023, 11:09 PM.

Details

Summary

Support for below CSRs is addeed -

  1. Branch Prediction Mode CSR
  2. Feature Disable CSR
  3. Power Dial CSR
  4. RNMI CSRs

spec:https://sifive.cdn.prismic.io/sifive/767804da-53b2-4893-97d5-b7c030ae0a94_s76mc_core_complex_manual_21G3.pdf

This patch removes AltName field from SysReg class because we are now using
separate class for custom vendor CSRs. Also, all use of AltName have been changed
to DeprecatedName because both were interchangeably used for old names which are
not in use in latest RISCV spec.

Diff Detail

Event Timeline

garvitgupta08 created this revision.Jun 21 2023, 11:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2023, 11:09 PM
garvitgupta08 requested review of this revision.Jun 21 2023, 11:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2023, 11:09 PM
craig.topper added inline comments.
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1843

Space after if

1843

Line exceeds 80 characters

Addressed the comments

craig.topper added inline comments.Jun 22 2023, 11:36 PM
llvm/lib/Target/RISCV/RISCVFeatures.td
757 ↗(On Diff #533867)

Drop "for S76"

llvm/test/MC/RISCV/xsfcie-invalid.s
5

Are we able to tell the user which option?

garvitgupta08 marked 3 inline comments as done.
garvitgupta08 added inline comments.
llvm/test/MC/RISCV/xsfcie-invalid.s
5

The existing implementation will need change to tell precisely which options need to be enabled. For now, this patch is using the same implementation of erroring out as earlier if subtarget does not have required features.

garvitgupta08 marked an inline comment as not done.

Hi @craig.topper, since custom instruction patch is merged now, can we also go ahead and merge this patch? Thanks

craig.topper added inline comments.Jun 26 2023, 10:27 PM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1831

"a alternate" -> "an alternate"

llvm/lib/Target/RISCV/RISCVSystemOperands.td
22

Do we only allow one vendor to implement an alternate name?

326

Remove S76.

craig.topper added inline comments.Jun 26 2023, 10:28 PM
llvm/lib/Target/RISCV/RISCVSystemOperands.td
40

I wonder if maybe we should have a separate table for alternate registers?

Will this prevent supporting the Smrnmi which uses these same CSR names. See most recent development copy of the privilege specificvation https://github.com/riscv/riscv-isa-manual/releases/download/riscv-isa-release-1239329-2023-05-23/riscv-privileged.pdf

Will this prevent supporting the Smrnmi which uses these same CSR names. See most recent development copy of the privilege specificvation https://github.com/riscv/riscv-isa-manual/releases/download/riscv-isa-release-1239329-2023-05-23/riscv-privileged.pdf

To add support for these CSRs, only one line change is needed in RISCVAsmParser. I have included that change in the latest patchset so that if we have to add those CSRs, we can easily do so without modifying the Parsing logic.

garvitgupta08 marked 2 inline comments as done.Jun 28 2023, 2:12 PM
garvitgupta08 added inline comments.
llvm/lib/Target/RISCV/RISCVSystemOperands.td
22

Currently yes.

40

Can you elaborate on this?

Should vendor-specific CSRs not have vendor-prefixed names just as vendor-specific instructions do? Having their names collide with standard ones sounds like a terrible idea.

That is, sf.mnstatus etc.

I think SiFive core IPs once used the old addresses. Newer versions of cores from SiFive use the standard addresses.

craig.topper added inline comments.Jun 28 2023, 11:26 PM
llvm/lib/Target/RISCV/RISCVSystemOperands.td
40

SysReg and SysRegsList together generate a "searchable table". This patch adds extra fields to every CSR in that table just for a couple CSRs. That makes the table larger.

May we should have AltSysReg and AltSysRegsList create a separate second search table for these 2 registers. Or SiFiveSysReg and SiFiveRegsList if we wanted a table per vendor.

garvitgupta08 edited the summary of this revision. (Show Details)

Addressing the comments

craig.topper added inline comments.Jul 12 2023, 7:55 AM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1825

space after if

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
366

Wasn't this field added by a previous version of this patch? Did you upload with the wrong base?

garvitgupta08 marked an inline comment as done.Jul 12 2023, 8:37 AM
garvitgupta08 added inline comments.
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
366

No, In previous version I added AltFeaturesRequired field. AltName field already existed in the SysReg for aliasing but was apparently being used for deprecated names. As mentioned in the commit message that we now have separate class for custom vendor CSRs therefore there is no need for AltName field anymore.

garvitgupta08 marked an inline comment as done.Jul 12 2023, 8:39 AM
craig.topper added inline comments.Jul 12 2023, 8:47 AM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1824

No need for else after return

garvitgupta08 marked 3 inline comments as done and an inline comment as not done.
craig.topper added inline comments.Jul 12 2023, 9:56 AM
llvm/lib/Target/RISCV/RISCVSystemOperands.td
312

Does this now print the warning "is a deprecated alias for"? Should we have a test for that?

356

Same here

garvitgupta08 marked 2 inline comments as done.

Added test case for diagnostic message.

Fixing Premerge checks

This revision is now accepted and ready to land.Jul 13 2023, 10:55 PM
garvitgupta08 added a comment.EditedJul 13 2023, 10:57 PM

LGTM

Can you commit this on my behalf?
Name - Garvit Gupta
Username - garvitgupta08
Mail id - quic_garvgupt@quicinc.com

This revision was landed with ongoing or failed builds.Jul 14 2023, 9:51 AM
This revision was automatically updated to reflect the committed changes.
zixuan-wu added inline comments.
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1839

Could this move forward more? Constructing more abstract infra to support all vendor reg instead of just SiFive.