Skip to content

Commit f509e63

Browse files
committed
[SYCL] Add SYCL device compilation flow.
Signed-off-by: Vladimir Lazarev <[email protected]>
1 parent 65f8c24 commit f509e63

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "treating unattributed constexpr function
215215
LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate transcendental functions")
216216
LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code")
217217

218+
LANGOPT(SYCL , 1, 0, "Generate code for SYCL device")
218219
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
219220
LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
220221
LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are unavailable")

clang/include/clang/Driver/CC1Options.td

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,14 @@ def fopenmp_is_device : Flag<["-"], "fopenmp-is-device">,
833833
def fopenmp_host_ir_file_path : Separate<["-"], "fopenmp-host-ir-file-path">,
834834
HelpText<"Path to the IR file produced by the frontend for the host.">;
835835

836-
} // let Flags = [CC1Option]
836+
//===----------------------------------------------------------------------===//
837+
// SYCL Options
838+
//===----------------------------------------------------------------------===//
837839

840+
def fsycl_is_device : Flag<["-"], "fsycl-is-device">,
841+
HelpText<"Generate code for SYCL device.">;
842+
843+
} // let Flags = [CC1Option]
838844

839845
//===----------------------------------------------------------------------===//
840846
// cc1as-only Options

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,6 +3122,8 @@ defm stack_arrays : BooleanFFlag<"stack-arrays">, Group<gfortran_Group>;
31223122
defm underscoring : BooleanFFlag<"underscoring">, Group<gfortran_Group>;
31233123
defm whole_file : BooleanFFlag<"whole-file">, Group<gfortran_Group>;
31243124

3125+
def sycl : Flag<["--"], "sycl">,
3126+
HelpText<"Compile SYCL kernels for device">;
31253127

31263128
include "CC1Options.td"
31273129

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,6 +3417,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
34173417
bool IsWindowsCygnus = RawTriple.isWindowsCygwinEnvironment();
34183418
bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment();
34193419
bool IsIAMCU = RawTriple.isOSIAMCU();
3420+
bool IsSYCL = Args.hasArg(options::OPT_sycl);
34203421

34213422
// Adjust IsWindowsXYZ for CUDA/HIP compilations. Even when compiling in
34223423
// device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not
@@ -3465,6 +3466,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
34653466
CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
34663467
}
34673468

3469+
if (IsSYCL) {
3470+
// We want to compile sycl kernels.
3471+
CmdArgs.push_back("-std=c++11");
3472+
CmdArgs.push_back("-fsycl-is-device");
3473+
}
3474+
34683475
if (IsOpenMPDevice) {
34693476
// We have to pass the triple of the host if compiling for an OpenMP device.
34703477
std::string NormalizedTriple =

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,6 +2872,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
28722872
<< Opts.OMPHostIRFile;
28732873
}
28742874

2875+
Opts.SYCL = Args.hasArg(options::OPT_fsycl_is_device);
2876+
28752877
// Set CUDA mode for OpenMP target NVPTX if specified in options
28762878
Opts.OpenMPCUDAMode = Opts.OpenMPIsDevice && T.isNVPTX() &&
28772879
Args.hasArg(options::OPT_fopenmp_cuda_mode);

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,10 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
10561056
Builder.defineMacro("__CLANG_CUDA_APPROX_TRANSCENDENTALS__");
10571057
}
10581058

1059+
if (LangOpts.SYCL) {
1060+
Builder.defineMacro("__SYCL_DEVICE_ONLY__");
1061+
}
1062+
10591063
// OpenCL definitions.
10601064
if (LangOpts.OpenCL) {
10611065
#define OPENCLEXT(Ext) \

0 commit comments

Comments
 (0)