This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Use tablegen for argument indices
ClosedPublic

Authored by Flakebi on Aug 20 2020, 2:12 AM.

Details

Summary

Use tablegen generic tables to get the index of image intrinsic
arguments.
Before, the computation of which image intrinsic argument is at which
index was scattered in a few places, tablegen, the SDag instruction
selection and GlobalISel. This patch changes that, so only tablegen
contains code to compute indices and the ImageDimIntrinsicInfo table
provides these information.

Diff Detail

Event Timeline

Flakebi created this revision.Aug 20 2020, 2:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 20 2020, 2:12 AM
Flakebi requested review of this revision.Aug 20 2020, 2:12 AM
arsenm added inline comments.Aug 20 2020, 12:51 PM
llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.h
56

uint8_t should be enough for all of these?

foad added a subscriber: foad.Aug 21 2020, 12:10 AM
Flakebi updated this revision to Diff 286966.Aug 21 2020, 1:16 AM

Right, changed unsigned to uint8_t for offsets in ImageDimIntrinsicInfo.

foad added inline comments.Aug 21 2020, 1:29 AM
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
698

Would it make more sense to daisy-chain these so e.g. SampArgIndex is just !add(RSrcArgIndex, NumRSrcArgs)?

Flakebi added inline comments.Sep 16 2020, 1:33 AM
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
698

I don’t care much about which variant to use. The more obvious the index of an argument gets, the better.

Here are both variants for comparison:

// No daisy-chaining
int DmaskArgIndex = NumDataArgs;
int VAddrArgIndex = !add(NumDataArgs, NumDmaskArgs);
int GradientArgIndex = !add(NumDataArgs, NumDmaskArgs, NumExtraAddrArgs);
int CoordArgIndex = !add(NumDataArgs, NumDmaskArgs, NumExtraAddrArgs, NumGradientArgs);
int LodArgIndex = !add(NumDataArgs, NumDmaskArgs, NumVAddrArgs, -1);
int MipArgIndex = LodArgIndex;
int RsrcArgIndex = !add(NumDataArgs, NumDmaskArgs, NumVAddrArgs);
int SampArgIndex = !add(NumDataArgs, NumDmaskArgs, NumVAddrArgs, NumRSrcArgs);
int UnormArgIndex = !add(NumDataArgs, NumDmaskArgs, NumVAddrArgs, NumRSrcArgs, 1);
int TexFailCtrlArgIndex = !add(NumDataArgs, NumDmaskArgs, NumVAddrArgs, NumRSrcArgs, NumSampArgs);
int CachePolicyArgIndex = !add(TexFailCtrlArgIndex, 1);

// Daisy-chaining
int DmaskArgIndex = NumDataArgs;
int VAddrArgIndex = !add(DmaskArgIndex, NumDmaskArgs);
int GradientArgIndex = !add(VAddrArgIndex, NumExtraAddrArgs);
int CoordArgIndex = !add(GradientArgIndex, NumGradientArgs);
int LodArgIndex = !add(VAddrArgIndex, NumVAddrArgs, -1);
int MipArgIndex = LodArgIndex;
int RsrcArgIndex = !add(VAddrArgIndex, NumVAddrArgs);
int SampArgIndex = !add(RsrcArgIndex, NumRSrcArgs);
int UnormArgIndex = !add(SampArgIndex, 1);
int TexFailCtrlArgIndex = !add(SampArgIndex, NumSampArgs);
int CachePolicyArgIndex = !add(TexFailCtrlArgIndex, 1);

friendly ping for review

It looks like nobody has strong opinions on whether to use daisy-chaining or not, so this should be fine to push?

foad accepted this revision.Sep 30 2020, 5:03 AM

I prefer the daisy chaining but I won't insist. LGTM either way.

This revision is now accepted and ready to land.Sep 30 2020, 5:03 AM
Flakebi updated this revision to Diff 295246.Sep 30 2020, 5:19 AM

So someone has a preference :)

I’ll push this tomorrow if there are no objections.

This revision was automatically updated to reflect the committed changes.
uabelho added inline comments.
llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
3808

Hi!
gcc warns on this and the next line about signed/unsigned comparisons:

../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp:3945:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
            (I == Intr->GradientStart + (Intr->NumGradients / 2) - 1 ||
             ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp:3946:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             I == Intr->GradientStart + Intr->NumGradients - 1)) ||
             ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I suppose it's because I changed from signed to unsigned.