Skip to content

Commit bb604df

Browse files
committed
[SYCL] Update aspect propagation logic for virtual functions
1 parent 5e0db3e commit bb604df

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

llvm/lib/SYCLLowerIR/SYCLPropagateAspectsUsage.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,24 @@ void processDeclaredVirtualFunctionSets(
665665
StringMap<SmallVector<Function *, 4>> &VirtualFunctionSets) {
666666
if (!F->hasFnAttribute("calls-indirectly"))
667667
return;
668+
669+
// "Construction" kernels which reference vtables but do not actually
670+
// perform any virtual calls have the calls-indirectly attribute
671+
// attached by SYCLVirtualFunctionAnalysis pass. We do not want to
672+
// attach sycl_used_aspects metadata to such kernels.
673+
bool hasVirtualCall = false;
674+
for (const Instruction &I : instructions(F)) {
675+
const auto *CI = dyn_cast<CallInst>(&I);
676+
if (!CI)
677+
continue;
678+
if (CI->isIndirectCall() && CI->hasFnAttr("virtual-call")) {
679+
hasVirtualCall = true;
680+
break;
681+
}
682+
}
683+
if (!hasVirtualCall)
684+
return;
685+
668686
Attribute CallsIndirectlyAttr = F->getFnAttribute("calls-indirectly");
669687
SmallVector<StringRef, 4> DeclaredVirtualFunctionSetNames;
670688
CallsIndirectlyAttr.getValueAsString().split(DeclaredVirtualFunctionSetNames,

llvm/test/SYCLLowerIR/PropagateAspectsUsage/VirtualFunctions/virtual-functions-1.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ define spir_func void @vfn() #0 {
66
ret void
77
}
88

9-
; CHECK: @foo() #1 !sycl_used_aspects ![[#aspects]]
10-
define spir_kernel void @foo() #1 {
9+
; CHECK: @foo({{.*}}) #1 !sycl_used_aspects ![[#aspects]]
10+
define spir_kernel void @foo(ptr %f) #1 {
11+
call void %f() #2
1112
ret void
1213
}
1314

1415
; CHECK: ![[#aspects]] = !{i32 6}
1516

1617
attributes #0 = { "indirectly-callable"="_ZTSv" }
1718
attributes #1 = { "calls-indirectly"="_ZTSv" }
19+
attributes #2 = { "virtual-call" }
1820

1921
!sycl_aspects = !{!0}
2022
!0 = !{!"fp64", i32 6}

llvm/test/SYCLLowerIR/PropagateAspectsUsage/VirtualFunctions/virtual-functions-2.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ define spir_func void @vfnBar() #1 {
1515
ret void
1616
}
1717

18-
; CHECK: @kernel() #2 !sycl_used_aspects ![[#aspectsKernel:]]
19-
define spir_kernel void @kernel() #2 {
18+
; CHECK: @kernel({{.*}}) #2 !sycl_used_aspects ![[#aspectsKernel:]]
19+
define spir_kernel void @kernel(ptr %f) #2 {
20+
call void %f() #3
2021
ret void
2122
}
2223

@@ -27,6 +28,7 @@ define spir_kernel void @kernel() #2 {
2728
attributes #0 = { "indirectly-callable"="setFoo" }
2829
attributes #1 = { "indirectly-callable"="setBar" }
2930
attributes #2 = { "calls-indirectly"="setFoo,setBar" }
31+
attributes #3 = { "virtual-call" }
3032

3133
!sycl_aspects = !{!0}
3234
!0 = !{!"fp64", i32 6}

llvm/test/SYCLLowerIR/PropagateAspectsUsage/VirtualFunctions/virtual-functions-3.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ define spir_func void @subBar() {
2525
ret void
2626
}
2727

28-
; CHECK: @kernelA() #2 !sycl_used_aspects ![[#aspectsFoo]]
29-
define spir_kernel void @kernelA() #2 {
28+
; CHECK: @kernelA({{.*}}) #2 !sycl_used_aspects ![[#aspectsFoo]]
29+
define spir_kernel void @kernelA(ptr %f) #2 {
30+
call void %f() #4
3031
ret void
3132
}
3233

33-
; CHECK: @kernelB() #3 !sycl_used_aspects ![[#aspectsBar]]
34-
define spir_kernel void @kernelB() #3 {
34+
; CHECK: @kernelB({{.*}}) #3 !sycl_used_aspects ![[#aspectsBar]]
35+
define spir_kernel void @kernelB(ptr %f) #3 {
36+
call void %f() #4
3537
ret void
3638
}
3739

@@ -42,6 +44,7 @@ attributes #0 = { "indirectly-callable"="setFoo" }
4244
attributes #1 = { "indirectly-callable"="setBar" }
4345
attributes #2 = { "calls-indirectly"="setFoo" }
4446
attributes #3 = { "calls-indirectly"="setBar" }
47+
attributes #4 = { "virtual-call" }
4548

4649
!sycl_aspects = !{!0}
4750
!0 = !{!"fp64", i32 6}

llvm/test/SYCLLowerIR/PropagateAspectsUsage/VirtualFunctions/virtual-functions-4.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,29 @@ entry:
1111
ret void
1212
}
1313

14+
; "Construction" kernels which reference vtables but do not actually
15+
; perform any virtual calls should not have aspects propagated to them.
1416
; CHECK-NOT: @construct({{.*}}){{.*}}!sycl_used_aspects
1517
define weak_odr dso_local spir_kernel void @construct(ptr addrspace(1) noundef align 8 %_arg_StorageAcc) {
1618
entry:
1719
store ptr addrspace(1) getelementptr inbounds inrange(-16, 8) (i8, ptr addrspace(1) @vtable, i64 16), ptr addrspace(1) %_arg_StorageAcc, align 8
1820
ret void
1921
}
2022

23+
; Note: after SYCLVirtualFunctionAnalysis pass, the construction kernels will have
24+
; "calls-indirectly" attribute, but even so they should not have aspects propagated
25+
; to them (as the construction kernels have no virtual calls).
26+
; CHECK-NOT: @construct2({{.*}}){{.*}}!sycl_used_aspects
27+
define weak_odr dso_local spir_kernel void @construct2(ptr addrspace(1) noundef align 8 %_arg_StorageAcc) #1 {
28+
entry:
29+
store ptr addrspace(1) getelementptr inbounds inrange(-16, 8) (i8, ptr addrspace(1) @vtable, i64 16), ptr addrspace(1) %_arg_StorageAcc, align 8
30+
ret void
31+
}
32+
2133
; CHECK: ![[#aspects]] = !{i32 6}
2234

2335
attributes #0 = { "indirectly-callable"="set-foo" }
36+
attributes #1 = { "calls-indirectly"="set-foo" }
2437

2538
!sycl_aspects = !{!0}
2639
!0 = !{!"fp64", i32 6}

0 commit comments

Comments
 (0)