Skip to content

Commit 5976ff0

Browse files
authored
[SYCL] Enable standard optimization pipeline for device code (#2207)
* [SYCL] Enable standard optimization pipeline for device code by default Add new compiler flag to disable optimizations at compile time: -fno-sycl-std-optimizations Temporally disable optimizations in some LIT tests. * Add clang driver test and update one more SYCL runtime test. * Add TODO comment
1 parent 39e7773 commit 5976ff0

File tree

21 files changed

+86
-26
lines changed

21 files changed

+86
-26
lines changed

clang/include/clang/Driver/Options.td

+1-2
Original file line numberDiff line numberDiff line change
@@ -3530,6 +3530,7 @@ def fsycl_esimd : Flag<["-"], "fsycl-explicit-simd">, Group<sycl_Group>, Flags<[
35303530
HelpText<"Enable SYCL explicit SIMD extension">;
35313531
def fno_sycl_esimd : Flag<["-"], "fno-sycl-explicit-simd">, Group<sycl_Group>,
35323532
HelpText<"Disable SYCL explicit SIMD extension">, Flags<[NoArgumentUnused, CoreOption]>;
3533+
defm sycl_std_optimizations : OptOutFFlag<"sycl-std-optimizations", "Enable", "Disable", " standard optimization pipeline for SYCL device compiler">;
35333534

35343535
//===----------------------------------------------------------------------===//
35353536
// CC1 Options
@@ -4454,8 +4455,6 @@ def fsycl_std_layout_kernel_params: Flag<["-"], "fsycl-std-layout-kernel-params"
44544455
def fsycl_allow_func_ptr : Flag<["-"], "fsycl-allow-func-ptr">,
44554456
HelpText<"Allow function pointers in SYCL device.">;
44564457
def fno_sycl_allow_func_ptr : Flag<["-"], "fno-sycl-allow-func-ptr">;
4457-
def fsycl_enable_optimizations: Flag<["-"], "fsycl-enable-optimizations">,
4458-
HelpText<"Experimental flag enabling standard optimization in the front-end.">;
44594458

44604459
} // let Flags = [CC1Option]
44614460

clang/lib/Driver/ToolChains/Clang.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -4102,6 +4102,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41024102
if (Args.hasFlag(options::OPT_fsycl_esimd, options::OPT_fno_sycl_esimd,
41034103
false))
41044104
CmdArgs.push_back("-fsycl-explicit-simd");
4105+
4106+
if (!Args.hasFlag(options::OPT_fsycl_std_optimizations,
4107+
options::OPT_fno_sycl_std_optimizations, true))
4108+
CmdArgs.push_back("-fno-sycl-std-optimizations");
4109+
41054110
// Pass the triple of host when doing SYCL
41064111
auto AuxT = llvm::Triple(llvm::sys::getProcessTriple());
41074112
std::string NormalizedTriple = AuxT.normalize();

clang/lib/Frontend/CompilerInvocation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
823823
Opts.DisableLLVMPasses =
824824
Args.hasArg(OPT_disable_llvm_passes) ||
825825
(Args.hasArg(OPT_fsycl_is_device) && Triple.isSPIR() &&
826-
!Args.hasArg(OPT_fsycl_enable_optimizations) && !IsSyclESIMD);
826+
Args.hasArg(OPT_fno_sycl_std_optimizations) && !IsSyclESIMD);
827827
Opts.DisableLifetimeMarkers = Args.hasArg(OPT_disable_lifetimemarkers);
828828

829829
const llvm::Triple::ArchType DebugEntryValueArchs[] = {

clang/test/CodeGenSYCL/inline_asm.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-enable-optimizations -triple spir64-unknown-unknown-sycldevice -emit-llvm -x c++ %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm -x c++ %s -o - | FileCheck %s
22

33
class kernel;
44

clang/test/CodeGenSYCL/remove-ur-inst.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fno-sycl-std-optimizations -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | FileCheck %s
12
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | FileCheck %s
2-
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-enable-optimizations -triple spir64-unknown-unknown-sycldevice -emit-llvm %s -o - | FileCheck %s
33

44
SYCL_EXTERNAL void doesNotReturn() throw() __attribute__((__noreturn__));
55

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// Check that optimizations for sycl device are enabled by default:
2+
// RUN: %clang -### -fsycl %s 2>&1 \
3+
// RUN: | FileCheck -check-prefix=CHECK-DEFAULT %s
4+
// RUN: %clang -### -fsycl -fsycl-device-only %s 2>&1 \
5+
// RUN: | FileCheck -check-prefix=CHECK-DEFAULT %s
6+
// CHECK-DEFAULT-NOT: "-fno-sycl-std-optimizations"
7+
// CHECK-DEFAULT-NOT: "-disable-llvm-passes"
8+
9+
/// Check "-fno-sycl-std-optimizations" is passed to the front-end:
10+
// RUN: %clang -### -fsycl -fno-sycl-std-optimizations %s 2>&1 \
11+
// RUN: | FileCheck -check-prefix=CHECK-NO-SYCL-STD-OPTS %s
12+
// RUN: %clang -### -fsycl -fsycl-device-only -fno-sycl-std-optimizations %s 2>&1 \
13+
// RUN: | FileCheck -check-prefix=CHECK-NO-SYCL-STD-OPTS %s
14+
// CHECK-NO-SYCL-STD-OPTS: "-fno-sycl-std-optimizations"

sycl/test/basic_tests/accessor/accessor.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
4+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
25
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
36
// RUN: %CPU_RUN_PLACEHOLDER %t.out
47
// RUN: %GPU_RUN_PLACEHOLDER %t.out

sycl/test/basic_tests/boolean.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
4+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
25
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
36
// RUN: %CPU_RUN_PLACEHOLDER %t.out
47
// RUN: %GPU_RUN_PLACEHOLDER %t.out

sycl/test/basic_tests/stream/stream.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
4+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
25
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out | FileCheck %s
36
// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER
47
// RUN: %GPU_RUN_ON_LINUX_PLACEHOLDER %t.out %GPU_CHECK_ON_LINUX_PLACEHOLDER

sycl/test/check_device_code/fpga_ihs_float.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
// RUN: %clangxx -I %sycl_include -S -emit-llvm -fsycl -fsycl-device-only %s -o - | FileCheck %s
10-
// RUN: %clangxx -I %sycl_include -S -emit-llvm -fsycl -fsycl-device-only %s -Xclang -fsycl-enable-optimizations -o - | FileCheck %s
10+
// RUN: %clangxx -I %sycl_include -S -emit-llvm -fsycl -fno-sycl-std-optimizations -fsycl-device-only %s -o - | FileCheck %s
1111

1212
#include "CL/__spirv/spirv_ops.hpp"
1313

sycl/test/fpga_tests/fpga_lsu.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %clangxx -fsycl %s -o %t.out
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
4+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations %s -o %t.out
25
// RUNx: %ACC_RUN_PLACEHOLDER %t.out
36
//==----------------- fpga_lsu.cpp - SYCL FPGA LSU test --------------------==//
47
//

sycl/test/hier_par/hier_par_wgscope.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
4+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
5+
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
6+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
7+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
8+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
9+
110
//==- hier_par_wgscope.cpp --- hierarchical parallelism test for WG scope---==//
211
//
312
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -6,12 +15,6 @@
615
//
716
//===----------------------------------------------------------------------===//
817

9-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
10-
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
11-
// RUN: %CPU_RUN_PLACEHOLDER %t.out
12-
// RUN: %GPU_RUN_PLACEHOLDER %t.out
13-
// RUN: %ACC_RUN_PLACEHOLDER %t.out
14-
1518
// This test checks correctness of hierarchical kernel execution when there is
1619
// code and data in the work group scope.
1720

sycl/test/regression/group.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
4+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
25
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
36
// RUN: %CPU_RUN_PLACEHOLDER %t.out
47
// RUN: %GPU_RUN_PLACEHOLDER %t.out

sycl/test/spec_const/spec_const_hw.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
14
// UNSUPPORTED: cuda || level_zero
25
//
3-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
6+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
47
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
58
// RUN: %CPU_RUN_PLACEHOLDER %t.out
69
// RUN: %GPU_RUN_PLACEHOLDER %t.out

sycl/test/sub_group/generic-shuffle.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
14
// UNSUPPORTED: cuda
25
// CUDA compilation and runtime do not yet support sub-groups.
36
//
4-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
7+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
58
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
69
// RUN: %CPU_RUN_PLACEHOLDER %t.out
710
// RUN: %GPU_RUN_PLACEHOLDER %t.out

sycl/test/sub_group/generic_reduce.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
14
// UNSUPPORTED: cuda
25
// CUDA compilation and runtime do not yet support sub-groups.
36
//
4-
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -std=c++14 %s -o %t.out
5-
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple -std=c++14 -D SG_GPU %s -o %t_gpu.out
7+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-unnamed-lambda -std=c++14 %s -o %t.out
8+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple -std=c++14 -D SG_GPU %s -o %t_gpu.out
69
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
710
// RUN: %CPU_RUN_PLACEHOLDER %t.out
811
// RUN: %GPU_RUN_PLACEHOLDER %t_gpu.out

sycl/test/sub_group/load_store.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
14
// UNSUPPORTED: cuda || cpu
25
// CUDA compilation and runtime do not yet support sub-groups.
36
// #2252 Disable until all variants of built-ins are available in OpenCL CPU
47
// runtime for every supported ISA
58
//
6-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
9+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
710
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
811
// RUN: %CPU_RUN_PLACEHOLDER %t.out
912
// RUN: %GPU_RUN_PLACEHOLDER %t.out

sycl/test/sub_group/scan_fp16.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
14
// UNSUPPORTED: cuda
25
// CUDA compilation and runtime do not yet support sub-groups.
36
//
4-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
7+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
58
// RUN: %GPU_RUN_PLACEHOLDER %t.out
69

710
//==--------------- scan_fp16.cpp - SYCL sub_group scan test --------*- C++ -*---==//

sycl/test/sub_group/shuffle.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
14
// UNSUPPORTED: cuda
25
// CUDA compilation and runtime do not yet support sub-groups.
36
//
4-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
7+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
58
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
69
// RUN: %CPU_RUN_PLACEHOLDER %t.out
710
// RUN: %GPU_RUN_PLACEHOLDER %t.out

sycl/test/sub_group/shuffle_fp16.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
14
// UNSUPPORTED: cuda
25
// CUDA compilation and runtime do not yet support sub-groups.
36
//
4-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
7+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
58
// RUN: %GPU_RUN_PLACEHOLDER %t.out
69
//
710
//==------------ shuffle_fp16.cpp - SYCL sub_group shuffle test -----*- C++ -*---==//

sycl/test/sub_group/shuffle_fp64.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// TODO: Enable compilation w/o -fno-sycl-std-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
14
// UNSUPPORTED: cuda
25
// CUDA compilation and runtime do not yet support sub-groups.
36
//
4-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
7+
// RUN: %clangxx -fsycl -fno-sycl-std-optimizations -fsycl-targets=%sycl_triple %s -o %t.out
58
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
69
// RUN: %CPU_RUN_PLACEHOLDER %t.out
710
// RUN: %GPU_RUN_PLACEHOLDER %t.out

0 commit comments

Comments
 (0)