Skip to content

[SYCL] Fix group local memory sharing issue #3489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,14 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
}

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

switch (Action) {
case Backend_EmitNothing:
Expand Down
30 changes: 24 additions & 6 deletions clang/test/CodeGenSYCL/group-local-memory.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice \
// RUN: -S -emit-llvm -mllvm -debug-pass=Structure -disable-llvm-passes \
// RUN: -o - %s 2>&1 | FileCheck %s
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice \
// RUN: -S -emit-llvm -mllvm -debug-pass=Structure -o - %s 2>&1 \
// RUN: | FileCheck %s
// Check that SYCLLowerWGLocalMemory pass is added to the SYCL device
// compilation pipeline with the inliner pass.

// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm \
// RUN: -mllvm -debug-pass=Structure %s -o - 2>&1 \
// RUN: | FileCheck %s
// CHECK: Function Integration/Inlining
// CHECK: Replace __sycl_allocateLocalMemory with allocation of memory in local address space

// Check that AlwaysInliner pass is always run for compilation of SYCL device
// target code, even if all optimizations are disabled.

// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm \
// RUN: -mllvm -debug-pass=Structure %s -o - -disable-llvm-passes 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-NOPASSES
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm \
// RUN: -mllvm -debug-pass=Structure %s -o - -fno-sycl-early-optimizations 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-NOPASSES
// CHECK-NOPASSES: Inliner for always_inline functions
// CHECK-NOPASSES: Replace __sycl_allocateLocalMemory with allocation of memory in local address space

// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm \
// RUN: -mllvm -debug-pass=Structure %s -o - -O0 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-O0opt
// CHECK-O0opt: Inliner for always_inline functions
// CHECK-O0opt: Replace __sycl_allocateLocalMemory with allocation of memory in local address space