1; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=hipstdpar-select-accelerator-code \ 2; RUN: %s | FileCheck %s 3 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 12 13%struct.Callable = type { [64 x i8] } 14 15; CHECK-NOT: @should_be_removed 16@llvm.compiler.used = appending addrspace(1) global [1 x ptr] [ptr @should_be_removed], section "llvm.metadata" 17 18define void @should_be_removed(ptr %p) { 19 ret void 20} 21 22declare void @llvm.trap() 23 24; CHECK: define {{.*}} @called_via_chain 25define void @called_via_chain(ptr %p) { 26 entry: 27 %tobool.not = icmp eq ptr %p, null 28 br i1 %tobool.not, label %if.then, label %if.end 29 30 if.then: 31 tail call void @llvm.trap() 32 unreachable 33 34 if.end: 35 ret void 36} 37 38; CHECK: define {{.*}} @directly_called 39define void @directly_called(ptr %p) { 40 tail call void @called_via_chain(ptr %p) 41 ret void 42} 43 44; CHECK: define {{.*}} amdgpu_kernel {{.*}} @accelerator_execution_root 45define hidden amdgpu_kernel void @accelerator_execution_root(ptr %p) { 46 tail call void @directly_called(ptr %p) 47 ret void 48} 49 50; CHECK-NOT: @defined_elsewhere_should_be_removed 51declare void @defined_elsewhere_should_be_removed(ptr) 52 53; CHECK: declare {{.*}} @defined_elsewhere_directly_called 54declare void @defined_elsewhere_directly_called(ptr) 55 56; CHECK: define {{.*}} amdgpu_kernel {{.*}} @another_accelerator_execution_root 57define hidden amdgpu_kernel void @another_accelerator_execution_root(ptr %p) { 58 tail call void @defined_elsewhere_directly_called(ptr %p) 59 ret void 60} 61 62; Also test passing a callable object (functor / lambda) to a kernel, which is 63; the common pattern for customising algorithms. 64 65; CHECK: define {{.*}} amdgpu_kernel {{.*}} @_Z22accelerator_execution_root_taking_callablePi8Callable 66define 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) 69 70 ret void 71} 72 73; CHECK: define {{.*}} @_ZNK8CallableclEPi 74define 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) 76 77 ret void 78} 79 80; CHECK: define {{.*}} @_ZNK8Callable6mem_fnEPKi 81define 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) 83 84 ret void 85} 86 87; CHECK: define {{.*}} @_ZN8Callable13static_mem_fnEPKi 88define linkonce_odr dso_local void @_ZN8Callable13static_mem_fnEPKi(ptr noundef %p) { 89 ret void 90} 91 92; CHECK-NOT: define {{.*}} @_Z26non_kernel_taking_callablePf8Callable 93define 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) 95 96 ret void 97} 98 99; CHECK-NOT: define {{.*}} @_ZNK8CallableclEPf 100define 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) 102 103 ret void 104} 105 106; CHECK-NOT: @_ZNK8Callable37another_mem_fn_which_will_get_removedEPKf 107define 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) 109 110 ret void 111} 112 113; CHECK-NOT: @_ZN8Callable44another_static_mem_fn_which_will_get_removedEPKf 114define linkonce_odr dso_local void @_ZN8Callable44another_static_mem_fn_which_will_get_removedEPKf(ptr noundef %p) { 115 ret void 116}