diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index eededed3da8d3..1e4bbea0ac17a 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -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: diff --git a/clang/test/CodeGenSYCL/group-local-memory.cpp b/clang/test/CodeGenSYCL/group-local-memory.cpp index 600771b674349..e37c9ee468986 100644 --- a/clang/test/CodeGenSYCL/group-local-memory.cpp +++ b/clang/test/CodeGenSYCL/group-local-memory.cpp @@ -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