This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add an operand kind to the opcode/imm returned from RISCVMatInt.
ClosedPublic

Authored by craig.topper on May 24 2022, 12:17 PM.

Details

Summary

Instead of matching opcodes to know the format to emit, use an
enum value that comes along with the opcode.

Change the consumers to use fully covered switches so that we get
a compiler warning if a new kind is added. With the opcode checks
it was easier to forget to update one of the 3 consumers.

Diff Detail

Event Timeline

craig.topper created this revision.May 24 2022, 12:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 12:17 PM
craig.topper requested review of this revision.May 24 2022, 12:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 12:17 PM
craig.topper retitled this revision from [RISCV] Add an operand kind to the instruction/imm returned from RISCVMatInt. to [RISCV] Add an operand kind to the opcode/imm returned from RISCVMatInt..May 24 2022, 12:18 PM

I want to suggest an alternate, and possibly simpler change.

Instead of adding a field to Inst, what if we added a helper routine instead which just did the switch on opcode internally and returned the Kind? The client code would look largely the same, but without needing to explicitly track the kind of each opcode at the construction site.

I want to suggest an alternate, and possibly simpler change.

Instead of adding a field to Inst, what if we added a helper routine instead which just did the switch on opcode internally and returned the Kind? The client code would look largely the same, but without needing to explicitly track the kind of each opcode at the construction site.

I like it.

Add a method to convert opcode to operand kind. All opcodes listed with an
unreachable default to make sure it always gets updated if new opcodes are used.

reames accepted this revision.May 24 2022, 2:50 PM

LGTM

This revision is now accepted and ready to land.May 24 2022, 2:50 PM
This revision was landed with ongoing or failed builds.May 24 2022, 3:00 PM
This revision was automatically updated to reflect the committed changes.