Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ struct AMDGPUPromoteKernelArgumentsPass
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};

ModulePass *createAMDGPUSplitKernelArgumentsPass();
void initializeAMDGPUSplitKernelArgumentsPass(PassRegistry &);
extern char &AMDGPUSplitKernelArgumentsID;

struct AMDGPUSplitKernelArgumentsPass
: PassInfoMixin<AMDGPUSplitKernelArgumentsPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};

ModulePass *createAMDGPULowerKernelAttributesPass();
void initializeAMDGPULowerKernelAttributesPass(PassRegistry &);
extern char &AMDGPULowerKernelAttributesID;
Expand Down
33 changes: 30 additions & 3 deletions llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,38 @@ void MetadataStreamerMsgPackV4::emitKernelArg(const Argument &Arg,
Align ArgAlign;
std::tie(ArgTy, ArgAlign) = getArgumentTypeAlign(Arg, DL);

// Assuming the argument is not split from struct-type argument by default,
// unless we find it in function attribute amdgpu-argument-mapping.
unsigned OriginalArgIndex = ~0U;
uint64_t OriginalArgOffset = 0;
Attribute Attr =
Func->getAttributes().getParamAttr(ArgNo, "amdgpu-original-arg");
if (Attr.isValid()) {
StringRef MappingStr = Attr.getValueAsString();
SmallVector<StringRef, 2> Elements;
MappingStr.split(Elements, ':');
if (Elements.size() == 2) {
if (Elements[0].getAsInteger(10, OriginalArgIndex))
report_fatal_error(
"Invalid original argument index in amdgpu-original-arg attribute");
if (Elements[1].getAsInteger(10, OriginalArgOffset))
report_fatal_error("Invalid original argument offset in "
"amdgpu-original-arg attribute");
}
}

emitKernelArg(DL, ArgTy, ArgAlign,
getValueKind(ArgTy, TypeQual, BaseTypeName), Offset, Args,
PointeeAlign, Name, TypeName, BaseTypeName, ActAccQual,
AccQual, TypeQual);
PointeeAlign, Name, TypeName, BaseTypeName, ActAccQual, AccQual,
TypeQual, OriginalArgIndex, OriginalArgOffset);
}

void MetadataStreamerMsgPackV4::emitKernelArg(
const DataLayout &DL, Type *Ty, Align Alignment, StringRef ValueKind,
unsigned &Offset, msgpack::ArrayDocNode Args, MaybeAlign PointeeAlign,
StringRef Name, StringRef TypeName, StringRef BaseTypeName,
StringRef ActAccQual, StringRef AccQual, StringRef TypeQual) {
StringRef ActAccQual, StringRef AccQual, StringRef TypeQual,
unsigned OriginalArgIndex, uint64_t OriginalArgOffset) {
auto Arg = Args.getDocument()->getMapNode();

if (!Name.empty())
Expand Down Expand Up @@ -409,6 +430,12 @@ void MetadataStreamerMsgPackV4::emitKernelArg(
Arg[".is_pipe"] = Arg.getDocument()->getNode(true);
}

// Add original argument index and offset to the metadata
if (OriginalArgIndex != ~0U) {
Arg[".original_arg_index"] = Arg.getDocument()->getNode(OriginalArgIndex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I agree with @arsenm that this is indeed an ABI breaking change, even though the ABI change seems to be transparent to end users.

Arg[".original_arg_offset"] = Arg.getDocument()->getNode(OriginalArgOffset);
}

Args.push_back(Arg);
}

Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ class LLVM_EXTERNAL_VISIBILITY MetadataStreamerMsgPackV4
MaybeAlign PointeeAlign = std::nullopt,
StringRef Name = "", StringRef TypeName = "",
StringRef BaseTypeName = "", StringRef ActAccQual = "",
StringRef AccQual = "", StringRef TypeQual = "");
StringRef AccQual = "", StringRef TypeQual = "",
unsigned OriginalArgIndex = ~0U,
uint64_t OriginalArgOffset = 0);

void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
msgpack::ArrayDocNode Args) override;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ MODULE_PASS("amdgpu-printf-runtime-binding", AMDGPUPrintfRuntimeBindingPass())
MODULE_PASS("amdgpu-remove-incompatible-functions", AMDGPURemoveIncompatibleFunctionsPass(*this))
MODULE_PASS("amdgpu-sw-lower-lds", AMDGPUSwLowerLDSPass(*this))
MODULE_PASS("amdgpu-unify-metadata", AMDGPUUnifyMetadataPass())
MODULE_PASS("amdgpu-split-kernel-arguments", AMDGPUSplitKernelArgumentsPass())
#undef MODULE_PASS

#ifndef MODULE_PASS_WITH_PARAMS
Expand Down
Loading
Loading