@@ -3989,14 +3989,24 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
3989
3989
const ArgList &Args, const char *LinkingOutput) const {
3990
3990
const auto &TC = getToolChain ();
3991
3991
const llvm::Triple &RawTriple = TC.getTriple ();
3992
- const llvm::Triple &Triple = TC.getEffectiveTriple ();
3993
- const std::string &TripleStr = Triple.getTriple ();
3992
+ llvm::Triple Triple = TC.getEffectiveTriple ();
3994
3993
3995
3994
bool KernelOrKext =
3996
3995
Args.hasArg (options::OPT_mkernel, options::OPT_fapple_kext);
3997
3996
const Driver &D = TC.getDriver ();
3998
3997
ArgStringList CmdArgs;
3999
3998
3999
+ // -fsycl-device-only implies a SPIRV arch triple. Do not set if current
4000
+ // effective triple is SYCLDevice
4001
+ if (Args.hasArg (options::OPT_fsycl_device_only) &&
4002
+ Triple.getEnvironment () != llvm::Triple::SYCLDevice) {
4003
+ const char *SYCLTargetArch = " spir64" ;
4004
+ if (C.getDefaultToolChain ().getTriple ().getArch () == llvm::Triple::x86)
4005
+ SYCLTargetArch = " spir" ;
4006
+ Triple = C.getDriver ().MakeSYCLDeviceTriple (SYCLTargetArch);
4007
+ }
4008
+ const std::string &TripleStr = Triple.getTriple ();
4009
+
4000
4010
// Check number of inputs for sanity. We need at least one input.
4001
4011
assert (Inputs.size () >= 1 && " Must have at least one input." );
4002
4012
// CUDA/HIP compilation may have multiple inputs (source file + results of
@@ -4011,7 +4021,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4011
4021
bool IsHIP = JA.isOffloading (Action::OFK_HIP);
4012
4022
bool IsOpenMPDevice = JA.isDeviceOffloading (Action::OFK_OpenMP);
4013
4023
bool IsSYCLOffloadDevice = JA.isDeviceOffloading (Action::OFK_SYCL);
4014
- bool IsSYCL = JA.isOffloading (Action::OFK_SYCL);
4024
+ bool IsSYCL = JA.isOffloading (Action::OFK_SYCL) ||
4025
+ Args.hasArg (options::OPT_fsycl_device_only);
4015
4026
bool IsHeaderModulePrecompile = isa<HeaderModulePrecompileJobAction>(JA);
4016
4027
assert ((IsCuda || IsHIP || (IsOpenMPDevice && Inputs.size () == 2 ) || IsSYCL ||
4017
4028
IsHeaderModulePrecompile || Inputs.size () == 1 ) &&
@@ -4059,14 +4070,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4059
4070
(IsSYCL || IsCuda || IsHIP) ? TC.getAuxTriple () : nullptr ;
4060
4071
bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment ();
4061
4072
bool IsIAMCU = RawTriple.isOSIAMCU ();
4062
- bool IsSYCLDevice = (RawTriple.getEnvironment () == llvm::Triple::SYCLDevice);
4073
+ bool IsSYCLDevice = (RawTriple.getEnvironment () == llvm::Triple::SYCLDevice ||
4074
+ Triple.getEnvironment () == llvm::Triple::SYCLDevice);
4063
4075
// Using just the sycldevice environment is not enough to determine usage
4064
4076
// of the device triple when considering fat static archives. The
4065
4077
// compilation path requires the host object to be fed into the partial link
4066
4078
// step, and being part of the SYCL tool chain causes the incorrect target.
4067
4079
// FIXME - Is it possible to retain host environment when on a target
4068
4080
// device toolchain.
4069
- bool UseSYCLTriple = IsSYCLDevice && (!IsSYCL || IsSYCLOffloadDevice);
4081
+ bool UseSYCLTriple =
4082
+ IsSYCLDevice && (!IsSYCL || IsSYCLOffloadDevice ||
4083
+ Args.hasArg (options::OPT_fsycl_device_only));
4070
4084
4071
4085
// Adjust IsWindowsXYZ for CUDA/HIP/SYCL compilations. Even when compiling in
4072
4086
// device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not
@@ -4155,7 +4169,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4155
4169
options::OPT_fno_sycl_early_optimizations,
4156
4170
Triple.getSubArch () != llvm::Triple::SPIRSubArch_fpga))
4157
4171
CmdArgs.push_back (" -fno-sycl-early-optimizations" );
4158
- else if (RawTriple. isSPIR () ) {
4172
+ else if (IsSYCLDevice ) {
4159
4173
// Set `sycl-opt` option to configure LLVM passes for SPIR target
4160
4174
CmdArgs.push_back (" -mllvm" );
4161
4175
CmdArgs.push_back (" -sycl-opt" );
@@ -4168,7 +4182,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4168
4182
4169
4183
// Pass the triple of host when doing SYCL
4170
4184
llvm::Triple AuxT = C.getDefaultToolChain ().getTriple ();
4171
- if (Args.hasFlag (options::OPT_fsycl_device_only, OptSpecifier (), false ))
4185
+ if (Args.hasArg (options::OPT_fsycl_device_only) &&
4186
+ RawTriple.getEnvironment () == llvm::Triple::SYCLDevice)
4172
4187
AuxT = llvm::Triple (llvm::sys::getProcessTriple ());
4173
4188
std::string NormalizedTriple = AuxT.normalize ();
4174
4189
CmdArgs.push_back (" -aux-triple" );
@@ -6828,6 +6843,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
6828
6843
unsigned RTOptionID = options::OPT__SLASH_MT;
6829
6844
bool isNVPTX = getToolChain ().getTriple ().isNVPTX ();
6830
6845
bool isSYCLDevice =
6846
+ Args.hasArg (options::OPT_fsycl_device_only) ||
6831
6847
getToolChain ().getTriple ().getEnvironment () == llvm::Triple::SYCLDevice;
6832
6848
bool isSYCL = Args.hasArg (options::OPT_fsycl) || isSYCLDevice;
6833
6849
// For SYCL Windows, /MD is the default.
@@ -7839,7 +7855,8 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
7839
7855
7840
7856
TranslatorArgs.push_back (" -o" );
7841
7857
TranslatorArgs.push_back (Output.getFilename ());
7842
- if (getToolChain ().getTriple ().isSYCLDeviceEnvironment ()) {
7858
+ if (getToolChain ().getTriple ().isSYCLDeviceEnvironment () ||
7859
+ TCArgs.hasArg (options::OPT_fsycl_device_only)) {
7843
7860
TranslatorArgs.push_back (" -spirv-max-version=1.1" );
7844
7861
TranslatorArgs.push_back (" -spirv-debug-info-version=legacy" );
7845
7862
// Prevent crash in the translator if input IR contains DIExpression
0 commit comments