This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU: Move handling of allocation of fixed ABI inputs
ClosedPublic

Authored by arsenm on Jan 11 2021, 9:27 AM.

Details

Summary

For the fixed ABI, set this in the initial argument constructor,
rather than relying on the allocation logic to set the values. Also
stop passing them for amdgpu_gfx, since the DAG path seems to skip
these. I'm unclear on what amdgpu_gfx's expectations are. This will
allow moving the special input registers out of the normal argument
range

Diff Detail

Event Timeline

arsenm created this revision.Jan 11 2021, 9:27 AM
arsenm requested review of this revision.Jan 11 2021, 9:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 11 2021, 9:27 AM
Herald added a subscriber: wdng. · View Herald Transcript

Also stop passing them for amdgpu_gfx, since the DAG path seems to skip these. I'm unclear on what amdgpu_gfx's expectations are.

As far as I understand, the “special inputs” are arguments relevant for HSA only and depending on EnableFixedFunctionABI they are added in the beginning or end of arguments.
So, passSpecialInputs should be guarded by “is HSA” instead of “is not amdgpu_gfx”?

I think we only want to pass the stack pointer into functions for our usage of amdgpu_gfx (and other implicit arguments like exec). All other arguments are added by the frontend.

Also stop passing them for amdgpu_gfx, since the DAG path seems to skip these. I'm unclear on what amdgpu_gfx's expectations are.

As far as I understand, the “special inputs” are arguments relevant for HSA only and depending on EnableFixedFunctionABI they are added in the beginning or end of arguments.
So, passSpecialInputs should be guarded by “is HSA” instead of “is not amdgpu_gfx”?

That breaks down for the other compute users too. Mesa/clover will also need most of the same inputs. Conversely, there are also inputs we don't try to handle which graphics may need (e.g. llvm.amdgcn.implicit.buffer.ptr, although I think that one is only needed in the entry point)

I think we only want to pass the stack pointer into functions for our usage of amdgpu_gfx (and other implicit arguments like exec). All other arguments are added by the frontend.

At a minimum the common ABI should defined the SP and SRD location. We also should defined the FP/BP commonly although they aren't passed (which they are now, but I'm thinking about moving them)

madhur13490 added inline comments.Jan 12 2021, 9:30 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
1886

Why do we HAVE to allocate?

llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
67

The constructor needs to be improved. ArgInfo will now hold allocated registers but the code ahead (line 93-99) is setting bools to true which is not useful and logically a dead code. Ideally, we should just do the necessary allocation in fixedABI and return.

arsenm added inline comments.Jan 12 2021, 9:38 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
1886

Otherwise another argument may end up allocated to the same register

llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
67

It's not logically dead. Whether the argument is used/needed and whether it assigned are different things. Fixed ABI is just setting the positions, and not doing the allocation. No allocation can really occur here since that's the calling convention lowering's responsibility

madhur13490 added inline comments.Jan 12 2021, 10:03 AM
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
67

Well, I meant that for fixed function ABI, we surely know that certain bools are going to be true, so why not set them, set the positions and return? Something like,

if (UseFixedABI && CC != ...) {
  PrivateSegmentBuffer = true;
  DispatchId = true;
  ImplicitArgPtr = true;
  ...
  ArgInfo = AMDGPUArgumentUsageInfo::FixedABIFunctionInfo;
  return;
}
arsenm added inline comments.Jan 12 2021, 11:38 AM
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
67

We do that below. There are some problems with the interaction between amdgpu_gfx and the input setting I'm going to fix in a separate patch

arsenm updated this revision to Diff 316189.Jan 12 2021, 12:02 PM

Fix amdgpu_gfx handling

Flakebi added inline comments.Jan 26 2021, 8:04 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
1879–1881

This comment does make more sense in the function above, where the register is allocated in the CCInfo.

1883–1884

This should assign to Arg probably

1890–1891

This should assign to Arg probably

arsenm updated this revision to Diff 319421.Jan 26 2021, 3:26 PM

Address comments

Flakebi accepted this revision.Jan 27 2021, 12:11 AM
This revision is now accepted and ready to land.Jan 27 2021, 12:11 AM