This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU/MC: Refactor decoders. Rework decoders for float immediates
ClosedPublic

Authored by Petar.Avramovic on Jan 26 2023, 7:56 AM.

Details

Summary

decodeFPImmed creates immediate operand using register operand width,
but size of created immediate should correspond to OperandType for
RegisterOperand.
e.g. OPW128 could be used for RegisterOperands that use v2f64 v4f32
and v8f16. Each RegisterOperands would have different OperandType and
require that immediate is decoded using 64, 32 and 16 bit immediate
respectively.
decodeOperand_<RegClass> only provides width for register decoding,
introduce decodeOperand_<RegClass>_Imm<ImmWidth> that also provides
width for immediate decoding.
Refactor RegisterOperands:

  • decoders get _Imm<ImmWidth> suffix in some cases
  • removed unused RegisterOperands defined via multiclass
  • use different RegisterOperand in a few places, new RegisterOperand's decoder corresponds to the number of bits used for operand's encoding

Refactor decoder functions:

  • add asserts for the size of encoding that will be decoded
  • regroup them according to the method of decoding

decodeOperand_<RegClass> (register only, no immediate) decoders can now
create immediate of consistent size, use it for better diagnostic of
'invalid immediate'.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 7:56 AM
Petar.Avramovic requested review of this revision.Jan 26 2023, 7:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 7:56 AM

Overall I like the patch. It definitely improves readability.

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
139

The argument name in decodeSrcOp is MandatoryLiteral, so you should probably use the same. Though I am good with it if you want to rename the argument to HasDeferredLiteral or something similar to match the terminology in SIRegisterInfo

1489

This comment should probably be maintained?

llvm/lib/Target/AMDGPU/SIRegisterInfo.td
1078

Spelling: Preffix -> Prefix, here and below

Addressed comments.

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
1489

I should not have deleted that comment.
This patch does not affect since it does not considers values of Imm (case 248).
Apart from that it is most probably fine, case 248 is available on vi and gfx9+, before it was listed as reserved.
There is a feature for it FeatureInv2PiInlineImm that is used in a few places

Thanks, LGTM

Joe_Nash accepted this revision.Feb 1 2023, 7:02 AM
This revision is now accepted and ready to land.Feb 1 2023, 7:02 AM