1 ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=hipstdpar-select-accelerator-code \
2 ; RUN: %s | FileCheck %s
4 $_ZNK8CallableclEPi = comdat any
5 $_ZNK8CallableclEPf = comdat any
6 $_ZNK8Callable6mem_fnEPKi = comdat any
7 $_ZN8Callable13static_mem_fnEPKi = comdat any
8 ; CHECK-NOT: $_ZNK8Callable37another_mem_fn_which_will_get_removedEPKf
9 $_ZNK8Callable37another_mem_fn_which_will_get_removedEPKf = comdat any
10 ; CHECK-NOT: $_ZN8Callable44another_static_mem_fn_which_will_get_removedEPKf
11 $_ZN8Callable44another_static_mem_fn_which_will_get_removedEPKf = comdat any
13 %struct.Callable = type { [64 x i8] }
15 ; CHECK-NOT: @should_be_removed
16 @llvm.compiler.used = appending addrspace(1) global [1 x ptr] [ptr @should_be_removed], section "llvm.metadata"
18 define void @should_be_removed(ptr %p) {
22 declare void @llvm.trap()
24 ; CHECK: define {{.*}} @called_via_chain
25 define void @called_via_chain(ptr %p) {
27 %tobool.not = icmp eq ptr %p, null
28 br i1 %tobool.not, label %if.then, label %if.end
31 tail call void @llvm.trap()
38 ; CHECK: define {{.*}} @directly_called
39 define void @directly_called(ptr %p) {
40 tail call void @called_via_chain(ptr %p)
44 ; CHECK: define {{.*}} amdgpu_kernel {{.*}} @accelerator_execution_root
45 define hidden amdgpu_kernel void @accelerator_execution_root(ptr %p) {
46 tail call void @directly_called(ptr %p)
50 ; CHECK-NOT: @defined_elsewhere_should_be_removed
51 declare void @defined_elsewhere_should_be_removed(ptr)
53 ; CHECK: declare {{.*}} @defined_elsewhere_directly_called
54 declare void @defined_elsewhere_directly_called(ptr)
56 ; CHECK: define {{.*}} amdgpu_kernel {{.*}} @another_accelerator_execution_root
57 define hidden amdgpu_kernel void @another_accelerator_execution_root(ptr %p) {
58 tail call void @defined_elsewhere_directly_called(ptr %p)
62 ; Also test passing a callable object (functor / lambda) to a kernel, which is
63 ; the common pattern for customising algorithms.
65 ; CHECK: define {{.*}} amdgpu_kernel {{.*}} @_Z22accelerator_execution_root_taking_callablePi8Callable
66 define hidden amdgpu_kernel void @_Z22accelerator_execution_root_taking_callablePi8Callable(ptr noundef %p, ptr addrspace(4) nocapture readonly byref(%struct.Callable) align 8 %callable) {
67 %callable_in_generic = addrspacecast ptr addrspace(4) %callable to ptr
68 call void @_ZNK8CallableclEPi(ptr noundef nonnull align 1 dereferenceable(64) %callable_in_generic, ptr noundef %p)
73 ; CHECK: define {{.*}} @_ZNK8CallableclEPi
74 define linkonce_odr dso_local void @_ZNK8CallableclEPi(ptr noundef nonnull align 1 dereferenceable(64) %this, ptr noundef %p) {
75 call void @_ZNK8Callable6mem_fnEPKi(ptr noundef nonnull align 1 dereferenceable(1) %this, ptr noundef %p)
80 ; CHECK: define {{.*}} @_ZNK8Callable6mem_fnEPKi
81 define linkonce_odr dso_local void @_ZNK8Callable6mem_fnEPKi(ptr noundef nonnull align 1 dereferenceable(1) %this, ptr noundef %p) {
82 call void @_ZN8Callable13static_mem_fnEPKi(ptr noundef %p)
87 ; CHECK: define {{.*}} @_ZN8Callable13static_mem_fnEPKi
88 define linkonce_odr dso_local void @_ZN8Callable13static_mem_fnEPKi(ptr noundef %p) {
92 ; CHECK-NOT: define {{.*}} @_Z26non_kernel_taking_callablePf8Callable
93 define dso_local void @_Z26non_kernel_taking_callablePf8Callable(ptr noundef %p, ptr noundef byval(%struct.Callable) align 8 %callable) {
94 call void @_ZNK8CallableclEPf(ptr noundef nonnull align 1 dereferenceable(64) %callable, ptr noundef %p)
99 ; CHECK-NOT: define {{.*}} @_ZNK8CallableclEPf
100 define linkonce_odr dso_local void @_ZNK8CallableclEPf(ptr noundef nonnull align 1 dereferenceable(64) %this, ptr noundef %p) {
101 call void @_ZNK8Callable37another_mem_fn_which_will_get_removedEPKf(ptr noundef nonnull align 1 dereferenceable(64) %this, ptr noundef %p)
106 ; CHECK-NOT: @_ZNK8Callable37another_mem_fn_which_will_get_removedEPKf
107 define linkonce_odr dso_local void @_ZNK8Callable37another_mem_fn_which_will_get_removedEPKf(ptr noundef nonnull align 1 dereferenceable(64) %this, ptr noundef %p) {
108 call void @_ZN8Callable44another_static_mem_fn_which_will_get_removedEPKf(ptr noundef %p)
113 ; CHECK-NOT: @_ZN8Callable44another_static_mem_fn_which_will_get_removedEPKf
114 define linkonce_odr dso_local void @_ZN8Callable44another_static_mem_fn_which_will_get_removedEPKf(ptr noundef %p) {