Skip to content

Commit

Permalink
[AMDGPU] Kernel arg metadata: added support for "__hip_texture" type.
Browse files Browse the repository at this point in the history
Summary:
Hip texture type is equivalent to OpenCL image. So, we need to set the Image type for kernel arguments with __hip_texture type.

Differential revision: https://reviews.llvm.org/D63850

llvm-svn: 365073
  • Loading branch information
kpyzhov committed Jul 3, 2019
1 parent 14f1543 commit 6f419a3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
Expand Up @@ -104,6 +104,11 @@ ValueKind MetadataStreamerV2::getValueKind(Type *Ty, StringRef TypeQual,
if (TypeQual.find("pipe") != StringRef::npos)
return ValueKind::Pipe;

if (isa<PointerType>(Ty) && Ty->getPointerElementType()->isStructTy() &&
Ty->getPointerElementType()->getStructName() == "struct.__hip_texture") {
return ValueKind::Image;
}

return StringSwitch<ValueKind>(BaseTypeName)
.Case("image1d_t", ValueKind::Image)
.Case("image1d_array_t", ValueKind::Image)
Expand Down Expand Up @@ -541,6 +546,11 @@ StringRef MetadataStreamerV3::getValueKind(Type *Ty, StringRef TypeQual,
if (TypeQual.find("pipe") != StringRef::npos)
return "pipe";

if (isa<PointerType>(Ty) && Ty->getPointerElementType()->isStructTy() &&
Ty->getPointerElementType()->getStructName() == "struct.__hip_texture") {
return "image";
}

return StringSwitch<StringRef>(BaseTypeName)
.Case("image1d_t", "image")
.Case("image1d_array_t", "image")
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full-v3.ll
Expand Up @@ -13,6 +13,7 @@
%opencl.pipe_t = type opaque
%struct.B = type { i32 addrspace(1)*}
%opencl.clk_event_t = type opaque
%struct.__hip_texture = type opaque

@__test_block_invoke_kernel_runtime_handle = external addrspace(1) externally_initialized constant i8 addrspace(1)*

Expand Down Expand Up @@ -1496,6 +1497,18 @@ define amdgpu_kernel void @unknown_addrspace_kernarg(i32 addrspace(12345)* %ptr)
ret void
}

; CHECK: - .args:
; CHECK-NEXT: - .address_space: generic
; CHECK-NEXT: .offset: 0
; CHECK-NEXT: .size: 8
; CHECK-NEXT: .value_kind: image
; CHECK-NEXT: .value_type: struct
; CHECK: .name: _Z5EmptyP13__hip_texture
; CHECK: .symbol: _Z5EmptyP13__hip_texture.kd
define protected amdgpu_kernel void @_Z5EmptyP13__hip_texture(%struct.__hip_texture* nocapture) local_unnamed_addr #1 {
ret void
}

; CHECK: amdhsa.printf:
; CHECK-NEXT: - '1:1:4:%d\n'
; CHECK-NEXT: - '2:1:8:%g\n'
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll
Expand Up @@ -13,6 +13,7 @@
%opencl.pipe_t = type opaque
%struct.B = type { i32 addrspace(1)*}
%opencl.clk_event_t = type opaque
%struct.__hip_texture = type opaque

@__test_block_invoke_kernel_runtime_handle = external addrspace(1) externally_initialized constant i8 addrspace(1)*

Expand Down Expand Up @@ -1484,6 +1485,16 @@ define amdgpu_kernel void @unknown_addrspace_kernarg(i32 addrspace(12345)* %ptr)
ret void
}

; CHECK: - Name: _Z5EmptyP13__hip_texture
; CHECK: Args:
; CHECK-NEXT: - Size: 8
; CHECK-NEXT: Align: 8
; CHECK-NEXT: ValueKind: Image
; CHECK-NEXT: ValueType: Struct
define protected amdgpu_kernel void @_Z5EmptyP13__hip_texture(%struct.__hip_texture* nocapture) local_unnamed_addr #1 {
ret void
}

attributes #0 = { "amdgpu-implicitarg-num-bytes"="48" }
attributes #1 = { "amdgpu-implicitarg-num-bytes"="48" "runtime-handle"="__test_block_invoke_kernel_runtime_handle" }
attributes #2 = { "amdgpu-implicitarg-num-bytes"="48" "calls-enqueue-kernel" }
Expand Down

0 comments on commit 6f419a3

Please sign in to comment.