This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Change handling of s_endpgm's optional operand. NFC.
ClosedPublic

Authored by foad on Dec 6 2022, 3:55 AM.

Details

Reviewers
dp
Group Reviewers
Restricted Project
Commits
rGb4ce9e952174: [AMDGPU] Change handling of s_endpgm's optional operand. NFC.
Summary

s_endpgm is a special SOPP instruction in that its operand is optional
and if it is not present then we don't want to print a space after the
mnemonic.

Previously this was handled by defaulting real_name to the mnemonic with
a trailing space, and having s_endpgm override it to be the mnemonic
with no trailing space.

This patch implements a different approach where the separator between
Mnemonic and AsmOperands defaults to a space, but s_endpgm overrides it
to be the empty string.

Diff Detail

Event Timeline

foad created this revision.Dec 6 2022, 3:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 3:55 AM
foad requested review of this revision.Dec 6 2022, 3:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 3:55 AM
foad added a subscriber: dp.Dec 6 2022, 4:00 AM
foad added inline comments.
llvm/lib/Target/AMDGPU/SOPInstructions.td
1942

@dp what do you think of this patch? Personally I like it because it simplifies all these SOPP_Real multiclasses, by removing all the machinery for passing around and overriding real_name. But I am open to other opinions.

dp added inline comments.Dec 6 2022, 6:30 AM
llvm/lib/Target/AMDGPU/SOPInstructions.td
1942

Your patch is definitely an improvement.

After looking at the original code I noticed that SOP opcodes without operands have a space after mnemonic. I only checked s_endpgm_saved and s_set_gpr_idx_off but it looks like other opcodes w/o operands have a similar issue. Your patch seems to address this issue though it is not mentioned in the description.

Most definitions use SOPP_Pseudo with an operand starting from a space. Shouldn't SOPP_Pseudo add a space automatically? This looks feasible; endpgm case may be handled by a subclass of SOPP_Pseudo.

foad added inline comments.Dec 6 2022, 6:41 AM
llvm/lib/Target/AMDGPU/SOPInstructions.td
1942

I only checked endpgm because there is a special strict-whitespace test for it: test/MC/AMDGPU/s_endpgm.s

foad updated this revision to Diff 480511.EditedDec 6 2022, 8:58 AM

Change approach based on @dp's comments.

foad edited the summary of this revision. (Show Details)Dec 6 2022, 8:59 AM
dp accepted this revision.Dec 6 2022, 9:22 AM

LGTM.

This revision is now accepted and ready to land.Dec 6 2022, 9:22 AM
This revision was landed with ongoing or failed builds.Dec 7 2022, 12:25 AM
This revision was automatically updated to reflect the committed changes.