diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 90db69b44f864..654113e88f414 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1481,6 +1481,17 @@ void EmitAssemblyHelper::RunOptimizationPipeline( MPM.addPass(SYCLMutatePrintfAddrspacePass()); } + // Allocate static local memory in SYCL kernel scope for each allocation + // call. It should be called after inlining pass. + 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) + MPM.addPass(AlwaysInlinerPass(false)); + MPM.addPass(SYCLLowerWGLocalMemoryPass()); + } + // Add a verifier pass if requested. We don't have to do this if the action // requires code generation because there will already be a verifier pass in // the code-generation pipeline. diff --git a/clang/test/CodeGenSYCL/group-local-memory-legacy-pm.cpp b/clang/test/CodeGenSYCL/group-local-memory-legacy-pm.cpp new file mode 100644 index 0000000000000..da9d41b9b51ef --- /dev/null +++ b/clang/test/CodeGenSYCL/group-local-memory-legacy-pm.cpp @@ -0,0 +1,24 @@ +// 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 -emit-llvm \ +// RUN: -flegacy-pass-manager -mllvm -debug-pass=Structure %s -o /dev/null 2>&1 \ +// RUN: | FileCheck %s -check-prefixes=CHECK-INL,CHECK + +// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -O0 \ +// RUN: -flegacy-pass-manager -mllvm -debug-pass=Structure %s -o /dev/null 2>&1 \ +// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK + +// 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 -emit-llvm -disable-llvm-passes \ +// RUN: -flegacy-pass-manager -mllvm -debug-pass=Structure %s -o /dev/null 2>&1 \ +// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK +// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -fno-sycl-early-optimizations \ +// RUN: -flegacy-pass-manager -mllvm -debug-pass=Structure %s -o /dev/null 2>&1 \ +// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK + +// CHECK-INL: Function Integration/Inlining +// CHECK-ALWINL: Inliner for always_inline functions +// CHECK: Replace __sycl_allocateLocalMemory with allocation of memory in local address space diff --git a/clang/test/CodeGenSYCL/group-local-memory.cpp b/clang/test/CodeGenSYCL/group-local-memory.cpp index 7556116471930..630e83107e7d1 100644 --- a/clang/test/CodeGenSYCL/group-local-memory.cpp +++ b/clang/test/CodeGenSYCL/group-local-memory.cpp @@ -1,26 +1,24 @@ // Check that SYCLLowerWGLocalMemory pass is added to the SYCL device -// compilation pipeline with the inliner pass. +// compilation pipeline with the inliner pass (new Pass Manager). // RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -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 +// RUN: -fno-legacy-pass-manager -mdebug-pass Structure %s -o /dev/null 2>&1 \ +// RUN: | FileCheck %s -check-prefixes=CHECK-INL,CHECK + +// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -O0 \ +// RUN: -fno-legacy-pass-manager -mdebug-pass Structure %s -o /dev/null 2>&1 \ +// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK // 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 -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 -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 -emit-llvm -disable-llvm-passes \ +// RUN: -fno-legacy-pass-manager -mdebug-pass Structure %s -o /dev/null 2>&1 \ +// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK +// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -fno-sycl-early-optimizations \ +// RUN: -fno-legacy-pass-manager -mdebug-pass Structure %s -o /dev/null 2>&1 \ +// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK -// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -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 +// CHECK-INL: Running pass: ModuleInlinerWrapperPass on [module] +// CHECK-ALWINL: Running pass: AlwaysInlinerPass on [module] +// CHECK: Running pass: SYCLLowerWGLocalMemoryPass on [module] diff --git a/sycl/test/check_device_code/id_queries_fit_int.cpp b/sycl/test/check_device_code/id_queries_fit_int.cpp index 1da1f86e504ef..1d8359be58eb6 100644 --- a/sycl/test/check_device_code/id_queries_fit_int.cpp +++ b/sycl/test/check_device_code/id_queries_fit_int.cpp @@ -1,5 +1,5 @@ -// RUN: %clangxx -fsycl-device-only -fsycl-id-queries-fit-in-int -fno-sycl-early-optimizations -S -o %t.ll %s -// RUN: FileCheck %s --input-file %t.ll +// RUN: %clangxx -fsycl-device-only -fsycl-id-queries-fit-in-int -fno-sycl-early-optimizations -S %s -flegacy-pass-manager -o - | FileCheck %s +// RUN: %clangxx -fsycl-device-only -fsycl-id-queries-fit-in-int -fno-sycl-early-optimizations -S %s -fno-legacy-pass-manager -o - | FileCheck %s #include