Skip to content

Commit

Permalink
Rewrite UBO tests (#1304)
Browse files Browse the repository at this point in the history
refs #1292
refs #1303

* Fixed a bug in remove unused arguments
  * attributes on parameters weren't handled parameters
* rewrite tests to be more targeted at the actual feature
  • Loading branch information
alan-baker authored Feb 8, 2024
1 parent 47ee627 commit 5bc0eef
Show file tree
Hide file tree
Showing 56 changed files with 1,724 additions and 1,214 deletions.
9 changes: 7 additions & 2 deletions lib/RemoveUnusedArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,25 @@ void clspv::RemoveUnusedArguments::removeUnusedParameters(
f->removeFromParent();

// Rebuild the type.
auto fn_attrs = f->getAttributes();
SmallVector<Type *, 8> arg_types;
uint32_t idx = 0;
for (auto *arg : candidate.args) {
if (arg) {
arg_types.push_back(arg->getType());
} else {
// Remove any parameter attributes for deleted args.
fn_attrs = fn_attrs.removeParamAttributes(M.getContext(), idx);
}
idx++;
}
FunctionType *new_type =
FunctionType::get(f->getReturnType(), arg_types, false);

// Insert the new function. Copy the calling convention, attributes and
// metadata.
auto inserted =
M.getOrInsertFunction(f->getName(), new_type, f->getAttributes())
.getCallee();
M.getOrInsertFunction(f->getName(), new_type, fn_attrs).getCallee();
Function *new_function = cast<Function>(inserted);
new_function->setCallingConv(f->getCallingConv());
new_function->copyMetadata(f, 0);
Expand Down
43 changes: 0 additions & 43 deletions test/UBO/array_stride_32.cl

This file was deleted.

62 changes: 62 additions & 0 deletions test/UBO/array_stride_32.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
; RUN: clspv-opt -constant-args-ubo %s -o %t.ll -producer-out-file=%t.spv -int8=0 --passes=ubo-type-transform,spirv-producer
; RUN: spirv-dis %t.spv -o %t.spvasm
; RUN: spirv-val --target-env vulkan1.0 %t.spv
; RUN: FileCheck %s < %t.spvasm
; RUN: clspv-reflection %t.spv -o %t.map
; RUN: FileCheck --check-prefix=MAP %s < %t.map

; MAP: kernel,foo,arg,data,argOrdinal,0,descriptorSet,0,binding,0,offset,0,argKind,buffer
; MAP-NEXT: kernel,foo,arg,c,argOrdinal,1,descriptorSet,0,binding,1,offset,0,argKind,buffer_ubo

; CHECK-DAG: OpMemberDecorate [[s:%[0-9a-zA-Z_]+]] 0 Offset 0
; CHECK-DAG: OpMemberDecorate [[s]] 1 Offset 4
; CHECK-DAG: OpMemberDecorate [[s]] 2 Offset 16
; CHECK-DAG: OpMemberDecorate [[s]] 3 Offset 20
; CHECK-DAG: OpDecorate [[runtime:%[0-9a-zA-Z_]+]] ArrayStride 32
; CHECK-DAG: OpDecorate [[data:%[0-9a-zA-Z_]+]] Binding 0
; CHECK-DAG: OpDecorate [[data]] DescriptorSet 0
; CHECK-DAG: OpDecorate [[c:%[0-9a-zA-Z_]+]] Binding 1
; CHECK-DAG: OpDecorate [[c]] DescriptorSet 0
; CHECK: [[int:%[0-9a-zA-Z_]+]] = OpTypeInt 32 0
; CHECK: [[s]] = OpTypeStruct [[int]] [[int]] [[int]] [[int]]
; CHECK: [[runtime]] = OpTypeRuntimeArray [[s]]
; CHECK: [[struct:%[0-9a-zA-Z_]+]] = OpTypeStruct [[runtime]]
; CHECK: [[data_ptr:%[0-9a-zA-Z_]+]] = OpTypePointer StorageBuffer [[struct]]
; CHECK: [[int_2048:%[0-9a-zA-Z_]+]] = OpConstant [[int]] 2048
; CHECK: [[array:%[0-9a-zA-Z_]+]] = OpTypeArray [[s]] [[int_2048]]
; CHECK: [[ubo_struct:%[0-9a-zA-Z_]+]] = OpTypeStruct [[array]]
; CHECK: [[c_ptr:%[0-9a-zA-Z_]+]] = OpTypePointer Uniform [[ubo_struct]]
; CHECK: [[data]] = OpVariable [[data_ptr]] StorageBuffer
; CHECK: [[c]] = OpVariable [[c_ptr]] Uniform

target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir-unknown-unknown"

%struct.s = type { i32, [12 x i8], i32, [12 x i8] }

@__spirv_GlobalInvocationId = local_unnamed_addr addrspace(5) global <3 x i32> zeroinitializer
@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer

define dso_local spir_kernel void @foo(ptr addrspace(1) nocapture writeonly align 16 %data, ptr addrspace(2) nocapture readonly align 16 %c) !clspv.pod_args_impl !13 {
entry:
%0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x %struct.s] } zeroinitializer)
%1 = call ptr addrspace(2) @_Z14clspv.resource.1(i32 0, i32 1, i32 1, i32 1, i32 1, i32 0, { [2048 x %struct.s] } zeroinitializer)
%2 = getelementptr <3 x i32>, ptr addrspace(5) @__spirv_GlobalInvocationId, i32 0, i32 0
%3 = load i32, ptr addrspace(5) %2, align 16
%4 = getelementptr { [2048 x %struct.s] }, ptr addrspace(2) %1, i32 0, i32 0, i32 %3, i32 0
%5 = load i32, ptr addrspace(2) %4, align 16
%6 = getelementptr { [0 x %struct.s] }, ptr addrspace(1) %0, i32 0, i32 0, i32 %3, i32 0
store i32 %5, ptr addrspace(1) %6, align 16
%7 = getelementptr { [2048 x %struct.s] }, ptr addrspace(2) %1, i32 0, i32 0, i32 %3, i32 2
%8 = load i32, ptr addrspace(2) %7, align 16
%9 = getelementptr { [0 x %struct.s] }, ptr addrspace(1) %0, i32 0, i32 0, i32 %3, i32 2
store i32 %8, ptr addrspace(1) %9, align 16
ret void
}

declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x %struct.s] })

declare ptr addrspace(2) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [2048 x %struct.s] })

!13 = !{i32 2}

22 changes: 0 additions & 22 deletions test/UBO/can_dra_but_disabled.cl

This file was deleted.

38 changes: 38 additions & 0 deletions test/UBO/can_dra_but_disabled.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
; RUN: clspv-opt %s -o %t.ll -constant-args-ubo --passes=multi-version-ubo-functions,remove-unused-arguments
; RUN: FileCheck %s < %t.ll

; CHECK: define {{.*}} void @foo
; CHECK: call <4 x i32> [[bar:@bar[a-zA-Z0-9_]+]]
; CHECK: define {{.*}} <4 x i32> [[bar]]()
; CHECK: [[res:%[a-zA-Z0-9_.]+]] = call ptr addrspace(2) @_Z14clspv.resource.1
; CHECK: [[gep:%[a-zA-Z0-9_.]+]] = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) [[res]], i32 0, i32 0, i32 0
; CHECK: load <4 x i32>, ptr addrspace(2) [[gep]]

target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir-unknown-unknown"

@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer

define dso_local spir_func <4 x i32> @bar(ptr addrspace(2) nocapture readonly %data) {
entry:
%0 = load <4 x i32>, ptr addrspace(2) %data, align 16
ret <4 x i32> %0
}

define dso_local spir_kernel void @foo(ptr addrspace(1) nocapture writeonly align 16 %out, ptr addrspace(2) nocapture readonly align 16 %in) !clspv.pod_args_impl !16 {
entry:
%0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x <4 x i32>] } zeroinitializer)
%1 = getelementptr { [0 x <4 x i32>] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0
%2 = call ptr addrspace(2) @_Z14clspv.resource.1(i32 0, i32 1, i32 1, i32 1, i32 1, i32 0, { [4096 x <4 x i32>] } zeroinitializer)
%3 = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) %2, i32 0, i32 0, i32 0
%call = tail call spir_func <4 x i32> @bar(ptr addrspace(2) %3)
store <4 x i32> %call, ptr addrspace(1) %1, align 16
ret void
}

declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x <4 x i32>] })

declare ptr addrspace(2) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [4096 x <4 x i32>] })

!16 = !{i32 2}

34 changes: 0 additions & 34 deletions test/UBO/can_dra_but_disabled_two_kernels.cl

This file was deleted.

55 changes: 55 additions & 0 deletions test/UBO/can_dra_but_disabled_two_kernels.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
; RUN: clspv-opt %s -o %t.ll -constant-args-ubo --passes=multi-version-ubo-functions,remove-unused-arguments
; RUN: FileCheck %s < %t.ll

; CHECK: define {{.*}} @k1
; CHECK: call {{.*}} [[bar1:@bar[a-zA-Z0-9_.]+]]()
; CHECK: define {{.*}} @k2
; CHECK: call {{.*}} [[bar2:@bar[a-zA-Z0-9_.]+]]()
; CHECK-DAG: define {{.*}} [[bar1]]()
; CHECK-DAG: [[res:%[a-zA-Z0-9_.]+]] = call ptr addrspace(2) @_Z14clspv.resource.1
; CHECK-DAG: [[gep:%[a-zA-Z0-9_.]+]] = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) [[res]], i32 0, i32 0, i32 0
; CHECK-DAG: load <4 x i32>, ptr addrspace(2) [[gep]]
; CHECK-DAG: define {{.*}} [[bar2]]()
; CHECK-DAG: [[res:%[a-zA-Z0-9_.]+]] = call ptr addrspace(2) @_Z14clspv.resource.1
; CHECK-DAG: [[gep:%[a-zA-Z0-9_.]+]] = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) [[res]], i32 0, i32 0, i32 0
; CHECK-DAG: load <4 x i32>, ptr addrspace(2) [[gep]]

target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir-unknown-unknown"

@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer

define dso_local spir_func <4 x i32> @bar(ptr addrspace(2) nocapture readonly %data) {
entry:
%0 = load <4 x i32>, ptr addrspace(2) %data, align 16
ret <4 x i32> %0
}

define dso_local spir_kernel void @k1(ptr addrspace(1) nocapture writeonly align 16 %out, ptr addrspace(2) nocapture readonly align 16 %in) !clspv.pod_args_impl !17 {
entry:
%0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x <4 x i32>] } zeroinitializer)
%1 = getelementptr { [0 x <4 x i32>] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0
%2 = call ptr addrspace(2) @_Z14clspv.resource.1(i32 0, i32 1, i32 1, i32 1, i32 1, i32 0, { [4096 x <4 x i32>] } zeroinitializer)
%3 = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) %2, i32 0, i32 0, i32 0
%call = tail call spir_func <4 x i32> @bar(ptr addrspace(2) %3)
store <4 x i32> %call, ptr addrspace(1) %1, align 16
ret void
}

define dso_local spir_kernel void @k2(ptr addrspace(1) nocapture writeonly align 16 %out, ptr addrspace(2) nocapture readonly align 16 %in) !clspv.pod_args_impl !17 {
entry:
%0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x <4 x i32>] } zeroinitializer)
%1 = getelementptr { [0 x <4 x i32>] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0
%2 = call ptr addrspace(2) @_Z14clspv.resource.1(i32 0, i32 1, i32 1, i32 1, i32 1, i32 0, { [4096 x <4 x i32>] } zeroinitializer)
%3 = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) %2, i32 0, i32 0, i32 0
%call = tail call spir_func <4 x i32> @bar(ptr addrspace(2) %3)
store <4 x i32> %call, ptr addrspace(1) %1, align 16
ret void
}

declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x <4 x i32>] })

declare ptr addrspace(2) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [4096 x <4 x i32>] })

!17 = !{i32 2}

37 changes: 0 additions & 37 deletions test/UBO/cannot_dra.cl

This file was deleted.

61 changes: 61 additions & 0 deletions test/UBO/cannot_dra.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
; RUN: clspv-opt %s -o %t.ll -constant-args-ubo --passes=multi-version-ubo-functions,remove-unused-arguments
; RUN: FileCheck %s < %t.ll

; CHECK: define {{.*}} @k1
; CHECK: call {{.*}} [[bar1:@bar[a-zA-Z0-9_.]+]]
; CHECK: define {{.*}} @k2
; CHECK: call {{.*}} [[bar2:@bar[a-zA-Z0-9_.]+]]
; CHECK-DAG: define {{.*}} [[bar1]]()
; CHECK-DAG: [[res:%[a-zA-Z0-9_.]+]] = call ptr addrspace(2) @_Z14clspv.resource.1
; CHECK-DAG: [[gep:%[a-zA-Z0-9_.]+]] = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) [[res]], i32 0, i32 0, i32 0
; CHECK-DAG: load <4 x i32>, ptr addrspace(2) [[gep]]
; CHECK-DAG: define {{.*}} [[bar2]]()
; CHECK-DAG: [[res:%[a-zA-Z0-9_.]+]] = call ptr addrspace(2) @_Z14clspv.resource.1
; CHECK-DAG: [[gep:%[a-zA-Z0-9_.]+]] = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) [[res]], i32 0, i32 0, i32 1
; CHECK-DAG: load <4 x i32>, ptr addrspace(2) [[gep]]

target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir-unknown-unknown"

@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer

define dso_local spir_func <4 x i32> @bar(ptr addrspace(2) nocapture readonly %data) {
entry:
%0 = load <4 x i32>, ptr addrspace(2) %data, align 16
ret <4 x i32> %0
}

define dso_local spir_kernel void @k1(ptr addrspace(1) nocapture writeonly align 16 %out, ptr addrspace(2) nocapture readonly align 16 %in) !clspv.pod_args_impl !17 {
entry:
%0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x <4 x i32>] } zeroinitializer)
%1 = getelementptr { [0 x <4 x i32>] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0
%2 = call ptr addrspace(2) @_Z14clspv.resource.1(i32 0, i32 1, i32 1, i32 1, i32 1, i32 0, { [4096 x <4 x i32>] } zeroinitializer)
%3 = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) %2, i32 0, i32 0, i32 0
%call = tail call spir_func <4 x i32> @bar(ptr addrspace(2) %3)
store <4 x i32> %call, ptr addrspace(1) %1, align 16
ret void
}

define spir_kernel void @k2(ptr addrspace(1) nocapture writeonly align 16 %out, ptr addrspace(2) nocapture readonly align 16 %in) !clspv.pod_args_impl !17 {
entry:
%0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x <4 x i32>] } zeroinitializer)
%1 = getelementptr { [0 x <4 x i32>] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0
%2 = call ptr addrspace(2) @_Z14clspv.resource.1(i32 0, i32 1, i32 1, i32 1, i32 1, i32 0, { [4096 x <4 x i32>] } zeroinitializer)
%3 = call ptr addrspace(9) @_Z14clspv.resource.2(i32 -1, i32 2, i32 5, i32 2, i32 2, i32 0, { { i32 } } zeroinitializer)
%4 = getelementptr { { i32 } }, ptr addrspace(9) %3, i32 0, i32 0
%5 = load { i32 }, ptr addrspace(9) %4, align 4
%x = extractvalue { i32 } %5, 0
%6 = getelementptr { [4096 x <4 x i32>] }, ptr addrspace(2) %2, i32 0, i32 0, i32 1
%call.i = tail call spir_func <4 x i32> @bar(ptr addrspace(2) %6)
store <4 x i32> %call.i, ptr addrspace(1) %1, align 16
ret void
}

declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x <4 x i32>] })

declare ptr addrspace(2) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [4096 x <4 x i32>] })

declare ptr addrspace(9) @_Z14clspv.resource.2(i32, i32, i32, i32, i32, i32, { { i32 } })

!17 = !{i32 2}

Loading

0 comments on commit 5bc0eef

Please sign in to comment.