Skip to content

Commit ffa7c78

Browse files
committed
[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
1 parent 0661533 commit ffa7c78

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -714,16 +714,20 @@ void MetadataStreamerMsgPackV3::emitKernelArg(const Argument &Arg,
714714
if (Node && ArgNo < Node->getNumOperands())
715715
BaseTypeName = cast<MDString>(Node->getOperand(ArgNo))->getString();
716716

717-
StringRef AccQual;
718-
if (Arg.getType()->isPointerTy() && Arg.onlyReadsMemory() &&
719-
Arg.hasNoAliasAttr()) {
720-
AccQual = "read_only";
721-
} else {
722-
Node = Func->getMetadata("kernel_arg_access_qual");
723-
if (Node && ArgNo < Node->getNumOperands())
724-
AccQual = cast<MDString>(Node->getOperand(ArgNo))->getString();
717+
StringRef ActAccQual;
718+
// Do we really need NoAlias check here?
719+
if (Arg.getType()->isPointerTy() && Arg.hasNoAliasAttr()) {
720+
if (Arg.onlyReadsMemory())
721+
ActAccQual = "read_only";
722+
else if (Arg.hasAttribute(Attribute::WriteOnly))
723+
ActAccQual = "write_only";
725724
}
726725

726+
StringRef AccQual;
727+
Node = Func->getMetadata("kernel_arg_access_qual");
728+
if (Node && ArgNo < Node->getNumOperands())
729+
AccQual = cast<MDString>(Node->getOperand(ArgNo))->getString();
730+
727731
StringRef TypeQual;
728732
Node = Func->getMetadata("kernel_arg_type_qual");
729733
if (Node && ArgNo < Node->getNumOperands())
@@ -747,14 +751,15 @@ void MetadataStreamerMsgPackV3::emitKernelArg(const Argument &Arg,
747751

748752
emitKernelArg(DL, ArgTy, ArgAlign,
749753
getValueKind(ArgTy, TypeQual, BaseTypeName), Offset, Args,
750-
PointeeAlign, Name, TypeName, BaseTypeName, AccQual, TypeQual);
754+
PointeeAlign, Name, TypeName, BaseTypeName, ActAccQual,
755+
AccQual, TypeQual);
751756
}
752757

753758
void MetadataStreamerMsgPackV3::emitKernelArg(
754759
const DataLayout &DL, Type *Ty, Align Alignment, StringRef ValueKind,
755760
unsigned &Offset, msgpack::ArrayDocNode Args, MaybeAlign PointeeAlign,
756761
StringRef Name, StringRef TypeName, StringRef BaseTypeName,
757-
StringRef AccQual, StringRef TypeQual) {
762+
StringRef ActAccQual, StringRef AccQual, StringRef TypeQual) {
758763
auto Arg = Args.getDocument()->getMapNode();
759764

760765
if (!Name.empty())
@@ -780,7 +785,8 @@ void MetadataStreamerMsgPackV3::emitKernelArg(
780785
if (auto AQ = getAccessQualifier(AccQual))
781786
Arg[".access"] = Arg.getDocument()->getNode(*AQ, /*Copy=*/true);
782787

783-
// TODO: Emit Arg[".actual_access"].
788+
if (auto AAQ = getAccessQualifier(ActAccQual))
789+
Arg[".actual_access"] = Arg.getDocument()->getNode(*AAQ, /*Copy=*/true);
784790

785791
SmallVector<StringRef, 1> SplitTypeQuals;
786792
TypeQual.split(SplitTypeQuals, " ", -1, false);

llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class MetadataStreamerMsgPackV3 : public MetadataStreamer {
105105
msgpack::ArrayDocNode Args,
106106
MaybeAlign PointeeAlign = std::nullopt,
107107
StringRef Name = "", StringRef TypeName = "",
108-
StringRef BaseTypeName = "", StringRef AccQual = "",
109-
StringRef TypeQual = "");
108+
StringRef BaseTypeName = "", StringRef ActAccQual = "",
109+
StringRef AccQual = "", StringRef TypeQual = "");
110110

111111
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
112112
msgpack::ArrayDocNode Args) override;

llvm/test/CodeGen/AMDGPU/hsa-metadata-deduce-ro-arg.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readelf --notes - | FileCheck %s
22

33
; CHECK: - .args:
4-
; CHECK-NEXT: - .access: read_only
4+
; CHECK-NEXT: - .actual_access: read_only
55
; CHECK-NEXT: .address_space: global
66
; CHECK-NEXT: .is_const: true
77
; CHECK-NEXT: .is_restrict: true
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readelf --notes - | FileCheck %s
2+
3+
; CHECK: amdhsa.kernels:
4+
; CHECK-NEXT: - .args:
5+
; CHECK-NEXT: - .actual_access: read_only
6+
; CHECK-LABEL: .name: test_noalias_ro_arg
7+
define amdgpu_kernel void @test_noalias_ro_arg(ptr noalias readonly %in) {
8+
ret void
9+
}
10+
11+
; CHECK: - .args:
12+
; CHECK-NOT: read_only
13+
; CHECK-LABEL: .name: test_only_ro_arg
14+
define amdgpu_kernel void @test_only_ro_arg(ptr readonly %in) {
15+
ret void
16+
}
17+
18+
; CHECK: - .args:
19+
; CHECK-NEXT: - .actual_access: write_only
20+
; CHECK-LABEL: .name: test_noalias_wo_arg
21+
define amdgpu_kernel void @test_noalias_wo_arg(ptr noalias writeonly %out) {
22+
ret void
23+
}
24+
25+
; CHECK: - .args:
26+
; CHECK-NOT: write_only
27+
; CHECK-LABEL: .name: test_only_wo_arg
28+
define amdgpu_kernel void @test_only_wo_arg(ptr writeonly %out) {
29+
ret void
30+
}

0 commit comments

Comments
 (0)