Skip to content

Commit 5367ac3

Browse files
committed
[SYCL] Refactoring
Moved changes to clang driver, added test
1 parent 9ca8294 commit 5367ac3

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5984,10 +5984,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
59845984
options::OPT_fno_gnu_inline_asm, true))
59855985
CmdArgs.push_back("-fno-gnu-inline-asm");
59865986

5987+
bool EnableSYCLEarlyOptimizations =
5988+
Args.hasFlag(options::OPT_fsycl_early_optimizations,
5989+
options::OPT_fno_sycl_early_optimizations,
5990+
Triple.getSubArch() != llvm::Triple::SPIRSubArch_fpga);
5991+
59875992
// Enable vectorization per default according to the optimization level
59885993
// selected. For optimization levels that want vectorization we use the alias
59895994
// option to simplify the hasFlag logic.
59905995
bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false);
5996+
if (UseSYCLTriple && EnableSYCLEarlyOptimizations)
5997+
EnableVec = false; // But disable vectorization for SYCL device code
59915998
OptSpecifier VectorizeAliasOption =
59925999
EnableVec ? options::OPT_O_Group : options::OPT_fvectorize;
59936000
if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption,
@@ -5996,6 +6003,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
59966003

59976004
// -fslp-vectorize is enabled based on the optimization level selected.
59986005
bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true);
6006+
if (UseSYCLTriple && EnableSYCLEarlyOptimizations)
6007+
EnableSLPVec = false; // But disable vectorization for SYCL device code
59996008
OptSpecifier SLPVectAliasOption =
60006009
EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
60016010
if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,

clang/test/Driver/sycl-device-optimizations.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,14 @@
3636
// RUN: | FileCheck -check-prefix=CHECK-DAE %s
3737
// CHECK-DAE: clang{{.*}} "-fenable-sycl-dae"
3838
// CHECK-DAE: sycl-post-link{{.*}} "-emit-param-info"
39+
40+
/// Check that vectorizers are disabled by default:
41+
// RUN: %clang -### -fsycl %s 2>&1 \
42+
// RUN: | FileCheck -check-prefix=CHECK-VEC-DEFAULT %s
43+
// CHECK-VEC-DEFAULT-NOT: -vectorize-loops
44+
// CHECK-VEC-DEFAULT-NOT: -vectorize-slp
45+
/// Check that vectorizers can still be enabled manually:
46+
// RUN: %clang -### -fsycl -fvectorize -fslp-vectorize %s 2>&1 \
47+
// RUN: | FileCheck -check-prefix=CHECK-VEC-ENABLE %s
48+
// CHECK-VEC-ENABLE: -vectorize-loops
49+
// CHECK-VEC-ENABLE: -vectorize-slp

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ void PassManagerBuilder::populateModulePassManager(
799799
.needCanonicalLoops(false)
800800
.sinkCommonInsts(true)));
801801

802-
if (SLPVectorize && !SYCLOptimizationMode) {
802+
if (SLPVectorize) {
803803
MPM.add(createSLPVectorizerPass()); // Vectorize parallel scalar chains.
804804
if (OptLevel > 1 && ExtraVectorizerPasses) {
805805
MPM.add(createEarlyCSEPass());

0 commit comments

Comments
 (0)