This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Merge RISCVMCInstLower.cpp into RISCVAsmPrinter.cpp.
ClosedPublic

Authored by craig.topper on Jun 6 2023, 2:46 PM.

Details

Summary

The separation here doesn't make much sense. I think it's a
leftover from the creation of the MC layer that has been
replicated to new targets.

By merging them we can avoid passing the AsmPrinter to the
MCInstLowering functions. We can make them member functions instead.

I think we can still do more integration of lowerSymbolOperand
and lowerRISCVVMachineInstrToMCInst, but I wanted to get feedback
on the direction first.

Diff Detail

Event Timeline

craig.topper created this revision.Jun 6 2023, 2:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2023, 2:46 PM
craig.topper requested review of this revision.Jun 6 2023, 2:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2023, 2:46 PM
asb added a comment.Jun 6 2023, 8:24 PM

This is definitely something I just copied from other backends and I like the idea of merging it. There is some value in uniformity with other backends though, so if other targets were dead set against ever considering something similar then perhaps we'd consider if it's better to stay matching everyone else.

This is definitely something I just copied from other backends and I like the idea of merging it. There is some value in uniformity with other backends though, so if other targets were dead set against ever considering something similar then perhaps we'd consider if it's better to stay matching everyone else.

I think there's already inconsistency in the structure of the files. I surveyed some of the targets.

X86 has a X86MCInstLower class that is instantiated on each call to X86AsmPrinter::emitInstruction. X86AsmPrinter::emitInstruction is implemented in X86MCInstLower.cpp

RISC-V does not have a MCInstLower class.

AArch64 has a AArch64MCInstLower object that is a member of AArch64AsmPrinter so its only instantiated once.

ARM, Hexagon, PowerPC, and SystemZ seem similar to RISC-V.

SystemZ has a SystemZMCInstLower instatiated from SystemZAsmPrinter::emitInstruction. SystemZAsmPrinter::emitInstruction is in SystemZAsmPrinter.cpp

AMDGPU has a AMDGPUMCInstLower instantiated from AMDGPUAsmPrinter::emitInstruction. AMDGPUAsmPrinter::emitInstruction lives in AMDGPUMCInstLower.cpp.

Mips has a MipsMCInstLower member of MipsAsmPrinter so it's only instantiated once.

I'm in favour of this. I think you explained the inconsistencies well. I believe RISCV has served as an example for new backends (I don't know if that's still the case) so I think there's a good argument (given the aforementioned inconsistencies) to forge a path forward.

asb added a comment.EditedJun 7 2023, 12:27 AM

This is definitely something I just copied from other backends and I like the idea of merging it. There is some value in uniformity with other backends though, so if other targets were dead set against ever considering something similar then perhaps we'd consider if it's better to stay matching everyone else.

I think there's already inconsistency in the structure of the files. I surveyed some of the targets.
(snip)

Thanks - I upgrade my view from supportive to _very_ supportive!

This is definitely something I just copied from other backends and I like the idea of merging it. There is some value in uniformity with other backends though, so if other targets were dead set against ever considering something similar then perhaps we'd consider if it's better to stay matching everyone else.

I think there's already inconsistency in the structure of the files. I surveyed some of the targets.
(snip)

Thanks - I upgrade my view from supportive to _very_ supportive!

Anything else I need to do to move forward with this?

barannikov88 accepted this revision.Jun 9 2023, 10:04 AM
barannikov88 added a subscriber: barannikov88.
barannikov88 added inline comments.
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
158–159

(nit) Can this be renamed to OutMI or OutInst or something more meaningful?

This revision is now accepted and ready to land.Jun 9 2023, 10:04 AM
asb accepted this revision.Jun 12 2023, 7:55 AM

LGTM

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp