Skip to content

Commit 25acbd2

Browse files
authored
[SYCL][NewPM] Add SYCLLowerWGLocalMemory pass into optimization (#5301)
Add `SYCLLowerWGLocalMemory` pass into clang optimizations pipeline when using new Pass Manager. Signed-off-by: Mikhail Lychkov <mikhail.lychkov@intel.com>
1 parent eec22ed commit 25acbd2

File tree

4 files changed

+53
-20
lines changed

4 files changed

+53
-20
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,17 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
14791479
MPM.addPass(SYCLMutatePrintfAddrspacePass());
14801480
}
14811481

1482+
// Allocate static local memory in SYCL kernel scope for each allocation
1483+
// call. It should be called after inlining pass.
1484+
if (LangOpts.SYCLIsDevice) {
1485+
// Group local memory pass depends on inlining. Turn it on even in case if
1486+
// all llvm passes or SYCL early optimizations are disabled.
1487+
// FIXME: Remove this workaround when dependency on inlining is eliminated.
1488+
if (CodeGenOpts.DisableLLVMPasses)
1489+
MPM.addPass(AlwaysInlinerPass(false));
1490+
MPM.addPass(SYCLLowerWGLocalMemoryPass());
1491+
}
1492+
14821493
// Add a verifier pass if requested. We don't have to do this if the action
14831494
// requires code generation because there will already be a verifier pass in
14841495
// the code-generation pipeline.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Check that SYCLLowerWGLocalMemory pass is added to the SYCL device
2+
// compilation pipeline with the inliner pass.
3+
4+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm \
5+
// RUN: -flegacy-pass-manager -mllvm -debug-pass=Structure %s -o /dev/null 2>&1 \
6+
// RUN: | FileCheck %s -check-prefixes=CHECK-INL,CHECK
7+
8+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -O0 \
9+
// RUN: -flegacy-pass-manager -mllvm -debug-pass=Structure %s -o /dev/null 2>&1 \
10+
// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK
11+
12+
// Check that AlwaysInliner pass is always run for compilation of SYCL device
13+
// target code, even if all optimizations are disabled.
14+
15+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -disable-llvm-passes \
16+
// RUN: -flegacy-pass-manager -mllvm -debug-pass=Structure %s -o /dev/null 2>&1 \
17+
// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK
18+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -fno-sycl-early-optimizations \
19+
// RUN: -flegacy-pass-manager -mllvm -debug-pass=Structure %s -o /dev/null 2>&1 \
20+
// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK
21+
22+
// CHECK-INL: Function Integration/Inlining
23+
// CHECK-ALWINL: Inliner for always_inline functions
24+
// CHECK: Replace __sycl_allocateLocalMemory with allocation of memory in local address space
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
// Check that SYCLLowerWGLocalMemory pass is added to the SYCL device
2-
// compilation pipeline with the inliner pass.
2+
// compilation pipeline with the inliner pass (new Pass Manager).
33

44
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm \
5-
// RUN: -mllvm -debug-pass=Structure %s -o - 2>&1 \
6-
// RUN: | FileCheck %s
7-
// CHECK: Function Integration/Inlining
8-
// CHECK: Replace __sycl_allocateLocalMemory with allocation of memory in local address space
5+
// RUN: -fno-legacy-pass-manager -mdebug-pass Structure %s -o /dev/null 2>&1 \
6+
// RUN: | FileCheck %s -check-prefixes=CHECK-INL,CHECK
7+
8+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -O0 \
9+
// RUN: -fno-legacy-pass-manager -mdebug-pass Structure %s -o /dev/null 2>&1 \
10+
// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK
911

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

13-
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -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 -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
15+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -disable-llvm-passes \
16+
// RUN: -fno-legacy-pass-manager -mdebug-pass Structure %s -o /dev/null 2>&1 \
17+
// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK
18+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -emit-llvm -fno-sycl-early-optimizations \
19+
// RUN: -fno-legacy-pass-manager -mdebug-pass Structure %s -o /dev/null 2>&1 \
20+
// RUN: | FileCheck %s --check-prefixes=CHECK-ALWINL,CHECK
2121

22-
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -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
22+
// CHECK-INL: Running pass: ModuleInlinerWrapperPass on [module]
23+
// CHECK-ALWINL: Running pass: AlwaysInlinerPass on [module]
24+
// CHECK: Running pass: SYCLLowerWGLocalMemoryPass on [module]

sycl/test/check_device_code/id_queries_fit_int.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clangxx -fsycl-device-only -fsycl-id-queries-fit-in-int -fno-sycl-early-optimizations -S -o %t.ll %s
2-
// RUN: FileCheck %s --input-file %t.ll
1+
// RUN: %clangxx -fsycl-device-only -fsycl-id-queries-fit-in-int -fno-sycl-early-optimizations -S %s -flegacy-pass-manager -o - | FileCheck %s
2+
// RUN: %clangxx -fsycl-device-only -fsycl-id-queries-fit-in-int -fno-sycl-early-optimizations -S %s -fno-legacy-pass-manager -o - | FileCheck %s
33

44
#include <CL/sycl.hpp>
55

0 commit comments

Comments
 (0)