This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][NFC] Use TableGen 'foreach' to simplify repetitive CSR definitions
ClosedPublic

Authored by asb on Jan 13 2022, 7:44 AM.

Details

Summary

Make the definitions of hpmcounter3-hpmcounter31,
hpmcounter3h-hpmcounter31h, mhpmcounter3-mhpmcounter31,
mhpmcounter3h-mhpmcounter31h, pmpaddr0-pmpaddr63, mhpmevent3-31, and
pmpcfg0-15 substantially less repetitive using a foreach loop.

Diff Detail

Event Timeline

asb created this revision.Jan 13 2022, 7:44 AM
asb requested review of this revision.Jan 13 2022, 7:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 13 2022, 7:44 AM
Herald added a subscriber: MaskRay. · View Herald Transcript
llvm/lib/Target/RISCV/RISCVSystemOperands.td
268–269

I think pmpcfg can also be compressed.

asb added inline comments.Jan 13 2022, 8:12 AM
llvm/lib/Target/RISCV/RISCVSystemOperands.td
268–269

It could, but I wasn't convinced it would be an improvement given the interleaving of the RV32-only odd registers along with the RV32/RV64 even registers.

llvm/lib/Target/RISCV/RISCVSystemOperands.td
268–269

// pmpcfg0-pmpcfg15 at 0x3A0-0x3AF.
foreach i = 0...15 in

let isRV32Only = !and(i, 1) in
def : SysReg<"pmpcfg"#i, !add(0x3A0, i)>;
asb updated this revision to Diff 399686.Jan 13 2022, 8:42 AM
asb marked 2 inline comments as done.
asb edited the summary of this revision. (Show Details)

Address review comments and fix a typo.

llvm/lib/Target/RISCV/RISCVSystemOperands.td
268–269
// pmpcfg0-pmpcfg15 at 0x3A0-0x3AF.
foreach i = 0...15 in
  let isRV32Only = !and(i, 1) in
  def : SysReg<"pmpcfg"#i, !add(0x3A0, i)>;

How about this way?

asb added inline comments.Jan 13 2022, 8:47 AM
llvm/lib/Target/RISCV/RISCVSystemOperands.td
268–269

Thanks, I've adopted that.

How about this way?

LGTM. Thanks! And sorry for my this comment.

This revision is now accepted and ready to land.Jan 13 2022, 8:47 AM