Skip to content

Commit

Permalink
[SYCL][NewPM] Add SYCLLowerWGLocalMemory pass into optimization (#5301)
Browse files Browse the repository at this point in the history
Add `SYCLLowerWGLocalMemory` pass into clang optimizations pipeline when using
new Pass Manager.

Signed-off-by: Mikhail Lychkov <mikhail.lychkov@intel.com>
  • Loading branch information
mlychkov authored Jan 20, 2022
1 parent eec22ed commit 25acbd2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
11 changes: 11 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,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.
Expand Down
24 changes: 24 additions & 0 deletions clang/test/CodeGenSYCL/group-local-memory-legacy-pm.cpp
Original file line number Diff line number Diff line change
@@ -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
34 changes: 16 additions & 18 deletions clang/test/CodeGenSYCL/group-local-memory.cpp
Original file line number Diff line number Diff line change
@@ -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]
4 changes: 2 additions & 2 deletions sycl/test/check_device_code/id_queries_fit_int.cpp
Original file line number Diff line number Diff line change
@@ -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 <CL/sycl.hpp>

Expand Down

0 comments on commit 25acbd2

Please sign in to comment.