This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU][PEI] Callee saves for amdgpu_cs_chain[_preserve]
ClosedPublic

Authored by rovka on Jul 27 2023, 3:14 AM.

Details

Summary

Teach prolog epilog insertion how to handle functions with the
amdgpu_cs_chain or amdgpu_cs_chain_preserve calling conventions.

For amdgpu_cs_chain functions, we only need to preserve the inactive
lanes of VGPRs above v8, and only in the presence of calls via
@llvm.amdgcn.cs.chain.

For amdgpu_cs_chain_preserve functions, we will also need to preserve
the active lanes for registers above the last argument VGPR. AFAICT
there's no direct way to find out what the last argument VGPR is, so
instead the patch uses the fact that chain calls from
amdgpu_cs_chain_preserve functions can't use more VGPRs than the
caller's VGPR arguments. In other words, it removes the operands of
SI_TCRETURN instructions from the list of callee saved registers.

For both calling conventions, registers v0-v7 never need to be saved and
restored, so we should never add them as WWM spills.

Diff Detail

Event Timeline

rovka created this revision.Jul 27 2023, 3:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2023, 3:14 AM
rovka requested review of this revision.Jul 27 2023, 3:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2023, 3:14 AM
rovka retitled this revision from [AMDGPU] Callee saves for amdgpu_cs_chain[_preserve] to [AMDGPU][PEI] Callee saves for amdgpu_cs_chain[_preserve].
rovka updated this revision to Diff 545088.Jul 28 2023, 3:32 AM

Fixup WWM handling & add more tests.

arsenm added inline comments.Jul 28 2023, 4:09 AM
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
310

Can you put this special register property as some kind of helper in SIRegisterInfo?

310

Alternatively add the inverse of CSR_AMDGPU_CS_ChainPreserve and test that?

rovka updated this revision to Diff 545105.Jul 28 2023, 5:09 AM

Add helper to SIRegisterInfo. Is smth like this what you had in mind?

arsenm accepted this revision.Aug 17 2023, 11:57 AM
This revision is now accepted and ready to land.Aug 17 2023, 11:57 AM
This revision was landed with ongoing or failed builds.Nov 7 2023, 11:28 PM
This revision was automatically updated to reflect the committed changes.