Skip to content

Commit c621b1f

Browse files
committed
Document attribute, fix issues with pass being run multiple times.
1 parent 6c2dca4 commit c621b1f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

llvm/docs/AMDGPUUsage.rst

+9
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,10 @@ The AMDGPU backend supports the following LLVM IR attributes.
16391639
function which requires AGPRs is reached through any function marked
16401640
with this attribute.
16411641

1642+
"amdgpu-hidden-argument" This attribute is used internally by the backend to mark function arguments
1643+
as hidden. Hidden arguments are managed by the compiler and are not part of
1644+
the explicit arguments supplied by the user.
1645+
16421646
======================================= ==========================================================
16431647

16441648
Calling Conventions
@@ -5856,6 +5860,11 @@ may insert a trap instruction at the start of the kernel prologue to manage
58565860
situations where kernarg preloading is attempted on hardware with incompatible
58575861
firmware.
58585862

5863+
With code object V5 and later, hidden kernel arguments that are normally accessed
5864+
through the Implicit Argument Ptr, may be preloaded into User SGPRs. These
5865+
arguments are added to the kernel function signature and are marked with the
5866+
attribute "amdgpu-hidden-argument". (See :ref:`amdgpu-llvm-ir-attributes-table`).
5867+
58595868
.. _amdgpu-amdhsa-kernel-prolog:
58605869

58615870
Kernel Prolog

llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ static bool lowerKernelArguments(Function &F, const TargetMachine &TM) {
325325
uint64_t LastExplicitArgOffset = ExplicitArgOffset;
326326
ExplicitArgOffset = alignTo(ExplicitArgOffset, ABITypeAlign) + AllocSize;
327327

328+
// Guard against the situation where hidden arguments have already been lowered
329+
// and added to the kernel function signiture, i.e. in a situation where this
330+
// pass has run twice.
331+
if (Arg.hasAttribute("amdgpu-hidden-argument"))
332+
break;
333+
328334
// Try to preload this argument into user SGPRs.
329335
if (Arg.hasInRegAttr() && InPreloadSequence && ST.hasKernargPreload() &&
330336
!Arg.getType()->isAggregateType())

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2546,7 +2546,9 @@ void SITargetLowering::allocatePreloadKernArgSGPRs(
25462546
if (OffsetBefore != LastExplicitArgOffset) {
25472547
unsigned PaddingSGPRs =
25482548
alignTo(LastExplicitArgOffset - OffsetBefore, 4) / 4;
2549-
Info.allocateUserSGPRs(*Subtarget, PaddingSGPRs);
2549+
if (!Info.allocateUserSGPRs(*Subtarget, PaddingSGPRs))
2550+
break;
2551+
25502552
ArgOffset += PaddingSGPRs * 4;
25512553
}
25522554
AlignedForImplictArgs = true;

0 commit comments

Comments
 (0)