]> granicus.if.org Git - clang/commitdiff
[SYCL] Add clang front-end option to enable SYCL device compilation flow.
authorAlexey Bader <alexey.bader@intel.com>
Mon, 25 Feb 2019 11:48:48 +0000 (11:48 +0000)
committerAlexey Bader <alexey.bader@intel.com>
Mon, 25 Feb 2019 11:48:48 +0000 (11:48 +0000)
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

include/clang/Basic/LangOptions.def
include/clang/Driver/CC1Options.td
lib/Frontend/CompilerInvocation.cpp
lib/Frontend/InitPreprocessor.cpp
test/Preprocessor/sycl-macro.cpp [new file with mode: 0644]

index 106f776ad15dbd11cc02a5f4eee24742a15e506f..7b2ab7a66fa6dd5e1c04cef079b4f2b674eabe62 100644 (file)
@@ -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")
index cead87201eee743b06c05179e18171b53a955ece..f4f8fae39e30e702a767957bc0f1372ff651bee0 100644 (file)
@@ -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
index 3c4196d3ddc15ad20c80951243cbd88c4bf634f9..b1a886241adb6d3df9739161eea45578a2eaf442 100644 (file)
@@ -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);
index c9f9f644f37c13db6f47e738837543faa6a9c592..b0fb124251e6911e6e65a30d6b835d6af1fe3380 100644 (file)
@@ -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 (file)
index 0000000..186df4f
--- /dev/null
@@ -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