Skip to content

Commit 5860468

Browse files
authored
[SYCL] Fix group local memory sharing issue (#3489)
Group local memory functions depend on inlining pass. When all optimizations are disabled then those functions are not inlined. If a user adds several group local memory calls with the same template argument then only one group local memory function is specialized and then one memory buffer is allocated. Thus all variables that save a result of the group local memory call point to the same buffer. Enable AlwaysInliner pass even when all llvm passes are disabled as a workaround.
1 parent 4e030a1 commit 5860468

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,14 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
998998
}
999999

10001000
// Allocate static local memory in SYCL kernel scope for each allocation call.
1001-
if (LangOpts.SYCLIsDevice)
1001+
if (LangOpts.SYCLIsDevice) {
1002+
// Group local memory pass depends on inlining. Turn it on even in case if
1003+
// all llvm passes or SYCL early optimizations are disabled.
1004+
// FIXME: Remove this workaround when dependency on inlining is eliminated.
1005+
if (CodeGenOpts.DisableLLVMPasses)
1006+
PerModulePasses.add(createAlwaysInlinerLegacyPass(false));
10021007
PerModulePasses.add(createSYCLLowerWGLocalMemoryLegacyPass());
1008+
}
10031009

10041010
switch (Action) {
10051011
case Backend_EmitNothing:
Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice \
2-
// RUN: -S -emit-llvm -mllvm -debug-pass=Structure -disable-llvm-passes \
3-
// RUN: -o - %s 2>&1 | FileCheck %s
4-
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice \
5-
// RUN: -S -emit-llvm -mllvm -debug-pass=Structure -o - %s 2>&1 \
6-
// RUN: | FileCheck %s
1+
// Check that SYCLLowerWGLocalMemory pass is added to the SYCL device
2+
// compilation pipeline with the inliner pass.
73

4+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm \
5+
// RUN: -mllvm -debug-pass=Structure %s -o - 2>&1 \
6+
// RUN: | FileCheck %s
7+
// CHECK: Function Integration/Inlining
88
// CHECK: Replace __sycl_allocateLocalMemory with allocation of memory in local address space
9+
10+
// Check that AlwaysInliner pass is always run for compilation of SYCL device
11+
// target code, even if all optimizations are disabled.
12+
13+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm \
14+
// RUN: -mllvm -debug-pass=Structure %s -o - -disable-llvm-passes 2>&1 \
15+
// RUN: | FileCheck %s --check-prefix=CHECK-NOPASSES
16+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm \
17+
// RUN: -mllvm -debug-pass=Structure %s -o - -fno-sycl-early-optimizations 2>&1 \
18+
// RUN: | FileCheck %s --check-prefix=CHECK-NOPASSES
19+
// CHECK-NOPASSES: Inliner for always_inline functions
20+
// CHECK-NOPASSES: Replace __sycl_allocateLocalMemory with allocation of memory in local address space
21+
22+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm \
23+
// RUN: -mllvm -debug-pass=Structure %s -o - -O0 2>&1 \
24+
// RUN: | FileCheck %s --check-prefix=CHECK-O0opt
25+
// CHECK-O0opt: Inliner for always_inline functions
26+
// CHECK-O0opt: Replace __sycl_allocateLocalMemory with allocation of memory in local address space

0 commit comments

Comments
 (0)