diff options
author | Alexey Bader <alexey.bader@intel.com> | 2019-02-25 11:48:48 +0000 |
---|---|---|
committer | Alexey Bader <alexey.bader@intel.com> | 2019-02-25 11:48:48 +0000 |
commit | 915f39b66a1d2bb7676b6395e6360ee4011e1b34 (patch) | |
tree | 82d16a998e97d9cc7aaae3e768fc048f398c7973 | |
parent | fa9d46ba3370f10f6936d4c8e94d64e0d2430c77 (diff) |
[SYCL] Add clang front-end option to enable SYCL device compilation flow.
Patch by Mariya Podchishchaeva <mariya.podchishchaeva@intel.com>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354773 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/LangOptions.def | 2 | ||||
-rw-r--r-- | include/clang/Driver/CC1Options.td | 8 | ||||
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 2 | ||||
-rw-r--r-- | lib/Frontend/InitPreprocessor.cpp | 6 | ||||
-rw-r--r-- | test/Preprocessor/sycl-macro.cpp | 5 |
5 files changed, 22 insertions, 1 deletions
diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def index 106f776ad1..7b2ab7a66f 100644 --- a/include/clang/Basic/LangOptions.def +++ b/include/clang/Basic/LangOptions.def @@ -217,6 +217,8 @@ LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "treating unattributed constexpr function LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate transcendental functions") LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code") +LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device") + LANGOPT(SizedDeallocation , 1, 0, "sized deallocation") LANGOPT(AlignedAllocation , 1, 0, "aligned allocation") LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are unavailable") diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index cead87201e..f4f8fae39e 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -836,8 +836,14 @@ def fopenmp_is_device : Flag<["-"], "fopenmp-is-device">, def fopenmp_host_ir_file_path : Separate<["-"], "fopenmp-host-ir-file-path">, HelpText<"Path to the IR file produced by the frontend for the host.">; -} // let Flags = [CC1Option] +//===----------------------------------------------------------------------===// +// SYCL Options +//===----------------------------------------------------------------------===// +def fsycl_is_device : Flag<["-"], "fsycl-is-device">, + HelpText<"Generate code for SYCL device.">; + +} // let Flags = [CC1Option] //===----------------------------------------------------------------------===// // cc1as-only Options diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 3c4196d3dd..b1a886241a 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2879,6 +2879,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, << Opts.OMPHostIRFile; } + Opts.SYCLIsDevice = Args.hasArg(options::OPT_fsycl_is_device); + // Set CUDA mode for OpenMP target NVPTX if specified in options Opts.OpenMPCUDAMode = Opts.OpenMPIsDevice && T.isNVPTX() && Args.hasArg(options::OPT_fopenmp_cuda_mode); diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index c9f9f644f3..b0fb124251 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -1057,6 +1057,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI, Builder.defineMacro("__CLANG_CUDA_APPROX_TRANSCENDENTALS__"); } + // Define a macro indicating that the source file is being compiled with a + // SYCL device compiler which doesn't produce host binary. + if (LangOpts.SYCLIsDevice) { + Builder.defineMacro("__SYCL_DEVICE_ONLY__", "1"); + } + // OpenCL definitions. if (LangOpts.OpenCL) { #define OPENCLEXT(Ext) \ diff --git a/test/Preprocessor/sycl-macro.cpp b/test/Preprocessor/sycl-macro.cpp new file mode 100644 index 0000000000..186df4ff56 --- /dev/null +++ b/test/Preprocessor/sycl-macro.cpp @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -E -dM | FileCheck %s +// RUN: %clang_cc1 %s -fsycl-is-device -E -dM | FileCheck --check-prefix=CHECK-SYCL %s + +// CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1 +// CHECK-SYCL:#define __SYCL_DEVICE_ONLY__ 1 |