Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,42 @@ bool GCNTargetMachine::parseMachineFunctionInfo(
MFI->ArgInfo.WorkItemIDZ, 0, 0)))
return true;

// Parse FirstKernArgPreloadReg separately, since it's a Register,
// not ArgDescriptor.
if (YamlMFI.ArgInfo && YamlMFI.ArgInfo->FirstKernArgPreloadReg) {
const yaml::SIArgument &A = *YamlMFI.ArgInfo->FirstKernArgPreloadReg;

if (!A.IsRegister) {
// For stack arguments, we don't have RegisterName.SourceRange,
// but we should have some location info from the YAML parser
const MemoryBuffer &Buffer =
*PFS.SM->getMemoryBuffer(PFS.SM->getMainFileID());
// Create a minimal valid source range
SMLoc Loc = SMLoc::getFromPointer(Buffer.getBufferStart());
SMRange Range(Loc, Loc);

Error = SMDiagnostic(*PFS.SM, Loc, Buffer.getBufferIdentifier(), 1, 0,
SourceMgr::DK_Error,
"firstKernArgPreloadReg must be a register, not a stack location",
"", {}, {});

SourceRange = Range;
return true;
}

Register Reg;
if (parseNamedRegisterReference(PFS, Reg, A.RegisterName.Value, Error)) {
SourceRange = A.RegisterName.SourceRange;
return true;
}

if (!AMDGPU::SGPR_32RegClass.contains(Reg))
return diagnoseRegisterClass(A.RegisterName);

MFI->ArgInfo.FirstKernArgPreloadReg = Reg;
MFI->NumUserSGPRs += YamlMFI.NumKernargPreloadSGPRs;
}

if (ST.hasIEEEMode())
MFI->Mode.IEEE = YamlMFI.Mode.IEEE;
if (ST.hasDX10ClampMode())
Expand Down
20 changes: 18 additions & 2 deletions llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,6 @@ convertArgumentInfo(const AMDGPUFunctionArgInfo &ArgInfo,
return true;
};

// TODO: Need to serialize kernarg preloads.
bool Any = false;
Any |= convertArg(AI.PrivateSegmentBuffer, ArgInfo.PrivateSegmentBuffer);
Any |= convertArg(AI.DispatchPtr, ArgInfo.DispatchPtr);
Expand All @@ -718,6 +717,20 @@ convertArgumentInfo(const AMDGPUFunctionArgInfo &ArgInfo,
Any |= convertArg(AI.WorkItemIDY, ArgInfo.WorkItemIDY);
Any |= convertArg(AI.WorkItemIDZ, ArgInfo.WorkItemIDZ);

// Write FirstKernArgPreloadReg separately, since it's a Register,
// not ArgDescriptor.
if (ArgInfo.FirstKernArgPreloadReg) {
Register Reg = ArgInfo.FirstKernArgPreloadReg;
assert(Reg.isPhysical() && "FirstKernArgPreloadReg must be a physical register");

yaml::SIArgument SA = yaml::SIArgument::createArgument(true);
raw_string_ostream OS(SA.RegisterName.Value);
OS << printReg(Reg, &TRI);

AI.FirstKernArgPreloadReg = SA;
Any = true;
}

if (Any)
return AI;

Expand Down Expand Up @@ -750,7 +763,8 @@ yaml::SIMachineFunctionInfo::SIMachineFunctionInfo(
Mode(MFI.getMode()), HasInitWholeWave(MFI.hasInitWholeWave()),
IsWholeWaveFunction(MFI.isWholeWaveFunction()),
DynamicVGPRBlockSize(MFI.getDynamicVGPRBlockSize()),
ScratchReservedForDynamicVGPRs(MFI.getScratchReservedForDynamicVGPRs()) {
ScratchReservedForDynamicVGPRs(MFI.getScratchReservedForDynamicVGPRs()),
NumKernargPreloadSGPRs(MFI.getNumKernargPreloadedSGPRs()) {
for (Register Reg : MFI.getSGPRSpillPhysVGPRs())
SpillPhysVGPRS.push_back(regToString(Reg, TRI));

Expand Down Expand Up @@ -799,6 +813,8 @@ bool SIMachineFunctionInfo::initializeBaseYamlFields(
ReturnsVoid = YamlMFI.ReturnsVoid;
IsWholeWaveFunction = YamlMFI.IsWholeWaveFunction;

UserSGPRInfo.allocKernargPreloadSGPRs(YamlMFI.NumKernargPreloadSGPRs);

if (YamlMFI.ScavengeFI) {
auto FIOrErr = YamlMFI.ScavengeFI->getFI(MF.getFrameInfo());
if (!FIOrErr) {
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ struct SIArgumentInfo {
std::optional<SIArgument> DispatchID;
std::optional<SIArgument> FlatScratchInit;
std::optional<SIArgument> PrivateSegmentSize;
std::optional<SIArgument> FirstKernArgPreloadReg;

std::optional<SIArgument> WorkGroupIDX;
std::optional<SIArgument> WorkGroupIDY;
Expand All @@ -195,6 +196,7 @@ template <> struct MappingTraits<SIArgumentInfo> {
YamlIO.mapOptional("dispatchID", AI.DispatchID);
YamlIO.mapOptional("flatScratchInit", AI.FlatScratchInit);
YamlIO.mapOptional("privateSegmentSize", AI.PrivateSegmentSize);
YamlIO.mapOptional("firstKernArgPreloadReg", AI.FirstKernArgPreloadReg);

YamlIO.mapOptional("workGroupIDX", AI.WorkGroupIDX);
YamlIO.mapOptional("workGroupIDY", AI.WorkGroupIDY);
Expand Down Expand Up @@ -305,6 +307,8 @@ struct SIMachineFunctionInfo final : public yaml::MachineFunctionInfo {
unsigned DynamicVGPRBlockSize = 0;
unsigned ScratchReservedForDynamicVGPRs = 0;

unsigned NumKernargPreloadSGPRs = 0;

SIMachineFunctionInfo() = default;
SIMachineFunctionInfo(const llvm::SIMachineFunctionInfo &,
const TargetRegisterInfo &TRI,
Expand Down Expand Up @@ -361,6 +365,7 @@ template <> struct MappingTraits<SIMachineFunctionInfo> {
YamlIO.mapOptional("dynamicVGPRBlockSize", MFI.DynamicVGPRBlockSize, false);
YamlIO.mapOptional("scratchReservedForDynamicVGPRs",
MFI.ScratchReservedForDynamicVGPRs, 0);
YamlIO.mapOptional("numKernargPreloadSGPRs", MFI.NumKernargPreloadSGPRs, 0);
YamlIO.mapOptional("isWholeWaveFunction", MFI.IsWholeWaveFunction, false);
}
};
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/CodeGen/MIR/AMDGPU/long-branch-reg-all-sgpr-used.ll
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
; CHECK-NEXT: hasInitWholeWave: false
; CHECK-NEXT: dynamicVGPRBlockSize: 0
; CHECK-NEXT: scratchReservedForDynamicVGPRs: 0
; CHECK-NEXT: numKernargPreloadSGPRs: 0
; CHECK-NEXT: isWholeWaveFunction: false
; CHECK-NEXT: body:
define amdgpu_kernel void @long_branch_used_all_sgprs(ptr addrspace(1) %arg, i32 %cnd) #0 {
Expand Down Expand Up @@ -320,6 +321,7 @@
; CHECK-NEXT: hasInitWholeWave: false
; CHECK-NEXT: dynamicVGPRBlockSize: 0
; CHECK-NEXT: scratchReservedForDynamicVGPRs: 0
; CHECK-NEXT: numKernargPreloadSGPRs: 0
; CHECK-NEXT: isWholeWaveFunction: false
; CHECK-NEXT: body:
define amdgpu_kernel void @long_branch_high_num_sgprs_used(ptr addrspace(1) %arg, i32 %cnd) #0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
; AFTER-PEI-NEXT: hasInitWholeWave: false
; AFTER-PEI-NEXT: dynamicVGPRBlockSize: 0
; AFTER-PEI-NEXT: scratchReservedForDynamicVGPRs: 0
; AFTER-PEI-NEXT: numKernargPreloadSGPRs: 0
; AFTER-PEI-NEXT: isWholeWaveFunction: false
; AFTER-PEI-NEXT: body:
define amdgpu_kernel void @scavenge_fi(ptr addrspace(1) %out, i32 %in) #0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
; CHECK-NEXT: hasInitWholeWave: false
; CHECK-NEXT: dynamicVGPRBlockSize: 0
; CHECK-NEXT: scratchReservedForDynamicVGPRs: 0
; CHECK-NEXT: numKernargPreloadSGPRs: 0
; CHECK-NEXT: isWholeWaveFunction: false
; CHECK-NEXT: body:
define amdgpu_kernel void @uniform_long_forward_branch_debug(ptr addrspace(1) %arg, i32 %arg1) #0 !dbg !5 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
; CHECK-NEXT: hasInitWholeWave: false
; CHECK-NEXT: dynamicVGPRBlockSize: 0
; CHECK-NEXT: scratchReservedForDynamicVGPRs: 0
; CHECK-NEXT: numKernargPreloadSGPRs: 0
; CHECK-NEXT: isWholeWaveFunction: false
; CHECK-NEXT: body:
define amdgpu_kernel void @uniform_long_forward_branch(ptr addrspace(1) %arg, i32 %arg1) #0 {
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/CodeGen/MIR/AMDGPU/machine-function-info-no-ir.mir
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
# FULL-NEXT: hasInitWholeWave: false
# FULL-NEXT: dynamicVGPRBlockSize: 0
# FULL-NEXT: scratchReservedForDynamicVGPRs: 0
# FULL-NEXT: numKernargPreloadSGPRs: 0
# FULL-NEXT: isWholeWaveFunction: false
# FULL-NEXT: body:

Expand Down Expand Up @@ -167,6 +168,7 @@ body: |
# FULL-NEXT: hasInitWholeWave: false
# FULL-NEXT: dynamicVGPRBlockSize: 0
# FULL-NEXT: scratchReservedForDynamicVGPRs: 0
# FULL-NEXT: numKernargPreloadSGPRs: 0
# FULL-NEXT: isWholeWaveFunction: false
# FULL-NEXT: body:

Expand Down Expand Up @@ -248,6 +250,7 @@ body: |
# FULL-NEXT: hasInitWholeWave: false
# FULL-NEXT: dynamicVGPRBlockSize: 0
# FULL-NEXT: scratchReservedForDynamicVGPRs: 0
# FULL-NEXT: numKernargPreloadSGPRs: 0
# FULL-NEXT: isWholeWaveFunction: false
# FULL-NEXT: body:

Expand Down Expand Up @@ -330,6 +333,7 @@ body: |
# FULL-NEXT: hasInitWholeWave: false
# FULL-NEXT: dynamicVGPRBlockSize: 0
# FULL-NEXT: scratchReservedForDynamicVGPRs: 0
# FULL-NEXT: numKernargPreloadSGPRs: 0
# FULL-NEXT: isWholeWaveFunction: false
# FULL-NEXT: body:

Expand Down
4 changes: 4 additions & 0 deletions llvm/test/CodeGen/MIR/AMDGPU/machine-function-info.ll
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
; CHECK-NEXT: hasInitWholeWave: false
; CHECK-NEXT: dynamicVGPRBlockSize: 0
; CHECK-NEXT: scratchReservedForDynamicVGPRs: 0
; CHECK-NEXT: numKernargPreloadSGPRs: 0
; CHECK-NEXT: isWholeWaveFunction: false
; CHECK-NEXT: body:
define amdgpu_kernel void @kernel(i32 %arg0, i64 %arg1, <16 x i32> %arg2) {
Expand Down Expand Up @@ -110,6 +111,7 @@ define amdgpu_kernel void @kernel(i32 %arg0, i64 %arg1, <16 x i32> %arg2) {
; CHECK-NEXT: hasInitWholeWave: false
; CHECK-NEXT: dynamicVGPRBlockSize: 0
; CHECK-NEXT: scratchReservedForDynamicVGPRs: 0
; CHECK-NEXT: numKernargPreloadSGPRs: 0
; CHECK-NEXT: isWholeWaveFunction: false
; CHECK-NEXT: body:
define amdgpu_ps void @ps_shader(i32 %arg0, i32 inreg %arg1) {
Expand Down Expand Up @@ -186,6 +188,7 @@ define amdgpu_ps void @gds_size_shader(i32 %arg0, i32 inreg %arg1) #5 {
; CHECK-NEXT: hasInitWholeWave: false
; CHECK-NEXT: dynamicVGPRBlockSize: 0
; CHECK-NEXT: scratchReservedForDynamicVGPRs: 0
; CHECK-NEXT: numKernargPreloadSGPRs: 0
; CHECK-NEXT: isWholeWaveFunction: false
; CHECK-NEXT: body:
define void @function() {
Expand Down Expand Up @@ -244,6 +247,7 @@ define void @function() {
; CHECK-NEXT: hasInitWholeWave: false
; CHECK-NEXT: dynamicVGPRBlockSize: 0
; CHECK-NEXT: scratchReservedForDynamicVGPRs: 0
; CHECK-NEXT: numKernargPreloadSGPRs: 0
; CHECK-NEXT: isWholeWaveFunction: false
; CHECK-NEXT: body:
define void @function_nsz() #0 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -start-after=amdgpu-isel -verify-machineinstrs %s -o /dev/null 2>&1 | FileCheck %s

---
# CHECK: error: {{.*}} incorrect register class for field
name: kernarg_preload_wrong_register_class
tracksRegLiveness: true
machineFunctionInfo:
explicitKernArgSize: 4
maxKernArgAlign: 4
numKernargPreloadSGPRs: 1
isEntryFunction: true
argumentInfo:
kernargSegmentPtr: { reg: '$sgpr0_sgpr1' }
firstKernArgPreloadReg: { reg: '$vgpr0' } # ERROR: VGPR instead of SGPR
body: |
bb.0:
S_ENDPGM 0
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -start-after=amdgpu-isel -verify-machineinstrs %s -o /dev/null 2>&1 | FileCheck %s

---
# CHECK: Invalid register name
name: kernarg_preload_invalid_register_name
tracksRegLiveness: true
machineFunctionInfo:
explicitKernArgSize: 4
maxKernArgAlign: 4
numKernargPreloadSGPRs: 1
isEntryFunction: true
argumentInfo:
kernargSegmentPtr: { reg: '$sgpr0_sgpr1' }
firstKernArgPreloadReg: { reg: '$invalid_reg' } # ERROR: Invalid register name
body: |
bb.0:
S_ENDPGM 0
...

Loading
Loading