Skip to content

Commit 3e1c1bf

Browse files
authored
[ESIMD] Don't force-inline VCStackCall functions. (#6175)
* [ESIMD] Don't force-inline VCStackCall functions. Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent a8ca5bf commit 3e1c1bf

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

llvm/lib/SYCLLowerIR/ESIMD/LowerESIMD.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,10 +1650,15 @@ size_t SYCLLowerESIMDPass::runOnFunction(Function &F,
16501650
// There is a current limitation of GPU vector backend that requires kernel
16511651
// functions to be inlined into the kernel itself. To overcome this
16521652
// limitation, mark every function called from ESIMD kernel with
1653-
// 'alwaysinline' attribute.
1653+
// 'alwaysinline' attribute, except few cases:
1654+
// - kernels are not called from device code, so can't be inlined
16541655
if ((F.getCallingConv() != CallingConv::SPIR_KERNEL) &&
1656+
// - 'noninline' should not be overridden
16551657
!F.hasFnAttribute(Attribute::NoInline) &&
1656-
!F.hasFnAttribute(Attribute::AlwaysInline))
1658+
// - 'alwaysinline' should not be duplicated
1659+
!F.hasFnAttribute(Attribute::AlwaysInline) &&
1660+
// - VC BE forbids 'alwaysinline' and "VCStackCall" on the same function
1661+
!F.hasFnAttribute(llvm::genx::VCFunctionMD::VCStackCall))
16571662
F.addFnAttr(Attribute::AlwaysInline);
16581663

16591664
SmallVector<CallInst *, 32> ESIMDIntrCalls;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; This test checks that LowerESIMD pass adds alwaysinline attribute to
2+
; functions, except those marked with
3+
; - spir_kernel
4+
; - noinline
5+
; - "VCStackCall"
6+
7+
; RUN: opt -passes=LowerESIMD -S < %s | FileCheck %s
8+
9+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
10+
target triple = "spir64-unknown-unknown"
11+
12+
; Function w/o attributes, must be marked with "alwaysinline"
13+
define dso_local spir_func void @no_attrs_func(float addrspace(4)* %ptr) {
14+
; CHECK: define dso_local spir_func void @no_attrs_func(float addrspace(4)* %ptr) #[[ATTRS1:[0-9]+]] {
15+
store float 2.0, float addrspace(4)* %ptr
16+
ret void
17+
}
18+
19+
; VCStackCall function, must not be marked with "alwaysinline"
20+
define dso_local spir_func void @vc_stack_call_func(float addrspace(4)* %ptr) #0 {
21+
; CHECK: define dso_local spir_func void @vc_stack_call_func(float addrspace(4)* %ptr) #[[ATTRS2:[0-9]+]] {
22+
store float 1.0, float addrspace(4)* %ptr
23+
ret void
24+
}
25+
26+
; Function with "noinline" attribute", must not be marked with "alwaysinline"
27+
define dso_local spir_func void @noinline_func(float addrspace(4)* %ptr) #1 {
28+
; CHECK: define dso_local spir_func void @noinline_func(float addrspace(4)* %ptr) #[[ATTRS3:[0-9]+]] {
29+
store float 2.0, float addrspace(4)* %ptr
30+
ret void
31+
}
32+
33+
; Kernel, must not be marked with "alwaysinline"
34+
define dso_local spir_kernel void @KERNEL(float addrspace(4)* %ptr) !sycl_explicit_simd !0 !intel_reqd_sub_group_size !1 {
35+
; CHECK: define dso_local spir_kernel void @KERNEL(float addrspace(4)* %ptr) #[[ATTRS4:[0-9]+]] !sycl_explicit_simd !{{.*}} !intel_reqd_sub_group_size !{{.*}} {
36+
store float 2.0, float addrspace(4)* %ptr
37+
ret void
38+
}
39+
40+
41+
attributes #0 = { "VCStackCall" }
42+
attributes #1 = { noinline }
43+
; CHECK-DAG: attributes #[[ATTRS1]] = { alwaysinline }
44+
; CHECK-DAG: attributes #[[ATTRS2]] = { "VCStackCall" }
45+
; CHECK-DAG: attributes #[[ATTRS3]] = { noinline }
46+
; CHECK-DAG: attributes #[[ATTRS4]] = { "CMGenxMain" "oclrt"="1" }
47+
48+
!0 = !{}
49+
!1 = !{i32 1}

0 commit comments

Comments
 (0)