[llvm] ffa7c78 - [AMDGPU] Emit .actual_access metadata
Changpeng Fang via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 23 12:58:05 PDT 2023
Author: Changpeng Fang
Date: 2023-08-23T12:57:29-07:00
New Revision: ffa7c7897c14223c591249dde41f33ecb3c4c148
URL: https://github.com/llvm/llvm-project/commit/ffa7c7897c14223c591249dde41f33ecb3c4c148
DIFF: https://github.com/llvm/llvm-project/commit/ffa7c7897c14223c591249dde41f33ecb3c4c148.diff
LOG: [AMDGPU] Emit .actual_access metadata
Summary:
Emit .actual_access metadata for the deduced argument access qualifier,
and .access for kernel_arg_access_qual.
Reviewers:
arsenm
Differential Revision:
https://reviews.llvm.org/D157451
Added:
llvm/test/CodeGen/AMDGPU/hsa-metadata-deduced-arg-attr.ll
Modified:
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
llvm/test/CodeGen/AMDGPU/hsa-metadata-deduce-ro-arg.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp b/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
index e83b5edea5efe1..9c7d1ac183188f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
@@ -714,16 +714,20 @@ void MetadataStreamerMsgPackV3::emitKernelArg(const Argument &Arg,
if (Node && ArgNo < Node->getNumOperands())
BaseTypeName = cast<MDString>(Node->getOperand(ArgNo))->getString();
- StringRef AccQual;
- if (Arg.getType()->isPointerTy() && Arg.onlyReadsMemory() &&
- Arg.hasNoAliasAttr()) {
- AccQual = "read_only";
- } else {
- Node = Func->getMetadata("kernel_arg_access_qual");
- if (Node && ArgNo < Node->getNumOperands())
- AccQual = cast<MDString>(Node->getOperand(ArgNo))->getString();
+ StringRef ActAccQual;
+ // Do we really need NoAlias check here?
+ if (Arg.getType()->isPointerTy() && Arg.hasNoAliasAttr()) {
+ if (Arg.onlyReadsMemory())
+ ActAccQual = "read_only";
+ else if (Arg.hasAttribute(Attribute::WriteOnly))
+ ActAccQual = "write_only";
}
+ StringRef AccQual;
+ Node = Func->getMetadata("kernel_arg_access_qual");
+ if (Node && ArgNo < Node->getNumOperands())
+ AccQual = cast<MDString>(Node->getOperand(ArgNo))->getString();
+
StringRef TypeQual;
Node = Func->getMetadata("kernel_arg_type_qual");
if (Node && ArgNo < Node->getNumOperands())
@@ -747,14 +751,15 @@ void MetadataStreamerMsgPackV3::emitKernelArg(const Argument &Arg,
emitKernelArg(DL, ArgTy, ArgAlign,
getValueKind(ArgTy, TypeQual, BaseTypeName), Offset, Args,
- PointeeAlign, Name, TypeName, BaseTypeName, AccQual, TypeQual);
+ PointeeAlign, Name, TypeName, BaseTypeName, ActAccQual,
+ AccQual, TypeQual);
}
void MetadataStreamerMsgPackV3::emitKernelArg(
const DataLayout &DL, Type *Ty, Align Alignment, StringRef ValueKind,
unsigned &Offset, msgpack::ArrayDocNode Args, MaybeAlign PointeeAlign,
StringRef Name, StringRef TypeName, StringRef BaseTypeName,
- StringRef AccQual, StringRef TypeQual) {
+ StringRef ActAccQual, StringRef AccQual, StringRef TypeQual) {
auto Arg = Args.getDocument()->getMapNode();
if (!Name.empty())
@@ -780,7 +785,8 @@ void MetadataStreamerMsgPackV3::emitKernelArg(
if (auto AQ = getAccessQualifier(AccQual))
Arg[".access"] = Arg.getDocument()->getNode(*AQ, /*Copy=*/true);
- // TODO: Emit Arg[".actual_access"].
+ if (auto AAQ = getAccessQualifier(ActAccQual))
+ Arg[".actual_access"] = Arg.getDocument()->getNode(*AAQ, /*Copy=*/true);
SmallVector<StringRef, 1> SplitTypeQuals;
TypeQual.split(SplitTypeQuals, " ", -1, false);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h b/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
index 7d7080e920f5ca..42bc335955bec7 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
@@ -105,8 +105,8 @@ class MetadataStreamerMsgPackV3 : public MetadataStreamer {
msgpack::ArrayDocNode Args,
MaybeAlign PointeeAlign = std::nullopt,
StringRef Name = "", StringRef TypeName = "",
- StringRef BaseTypeName = "", StringRef AccQual = "",
- StringRef TypeQual = "");
+ StringRef BaseTypeName = "", StringRef ActAccQual = "",
+ StringRef AccQual = "", StringRef TypeQual = "");
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
msgpack::ArrayDocNode Args) override;
diff --git a/llvm/test/CodeGen/AMDGPU/hsa-metadata-deduce-ro-arg.ll b/llvm/test/CodeGen/AMDGPU/hsa-metadata-deduce-ro-arg.ll
index f5fc387f419b19..f9cffbc95c2bc5 100644
--- a/llvm/test/CodeGen/AMDGPU/hsa-metadata-deduce-ro-arg.ll
+++ b/llvm/test/CodeGen/AMDGPU/hsa-metadata-deduce-ro-arg.ll
@@ -1,7 +1,7 @@
; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readelf --notes - | FileCheck %s
; CHECK: - .args:
-; CHECK-NEXT: - .access: read_only
+; CHECK-NEXT: - .actual_access: read_only
; CHECK-NEXT: .address_space: global
; CHECK-NEXT: .is_const: true
; CHECK-NEXT: .is_restrict: true
diff --git a/llvm/test/CodeGen/AMDGPU/hsa-metadata-deduced-arg-attr.ll b/llvm/test/CodeGen/AMDGPU/hsa-metadata-deduced-arg-attr.ll
new file mode 100644
index 00000000000000..ec6a6f66ada849
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/hsa-metadata-deduced-arg-attr.ll
@@ -0,0 +1,30 @@
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readelf --notes - | FileCheck %s
+
+; CHECK: amdhsa.kernels:
+; CHECK-NEXT: - .args:
+; CHECK-NEXT: - .actual_access: read_only
+; CHECK-LABEL: .name: test_noalias_ro_arg
+define amdgpu_kernel void @test_noalias_ro_arg(ptr noalias readonly %in) {
+ ret void
+}
+
+; CHECK: - .args:
+; CHECK-NOT: read_only
+; CHECK-LABEL: .name: test_only_ro_arg
+define amdgpu_kernel void @test_only_ro_arg(ptr readonly %in) {
+ ret void
+}
+
+; CHECK: - .args:
+; CHECK-NEXT: - .actual_access: write_only
+; CHECK-LABEL: .name: test_noalias_wo_arg
+define amdgpu_kernel void @test_noalias_wo_arg(ptr noalias writeonly %out) {
+ ret void
+}
+
+; CHECK: - .args:
+; CHECK-NOT: write_only
+; CHECK-LABEL: .name: test_only_wo_arg
+define amdgpu_kernel void @test_only_wo_arg(ptr writeonly %out) {
+ ret void
+}
More information about the llvm-commits
mailing list