@@ -3978,14 +3978,24 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
3978
3978
const ArgList &Args, const char *LinkingOutput) const {
3979
3979
const auto &TC = getToolChain ();
3980
3980
const llvm::Triple &RawTriple = TC.getTriple ();
3981
- const llvm::Triple &Triple = TC.getEffectiveTriple ();
3982
- const std::string &TripleStr = Triple.getTriple ();
3981
+ llvm::Triple Triple = TC.getEffectiveTriple ();
3983
3982
3984
3983
bool KernelOrKext =
3985
3984
Args.hasArg (options::OPT_mkernel, options::OPT_fapple_kext);
3986
3985
const Driver &D = TC.getDriver ();
3987
3986
ArgStringList CmdArgs;
3988
3987
3988
+ // -fsycl-device-only implies a SPIRV arch triple. Do not set if current
3989
+ // effective triple is SYCLDevice
3990
+ if (Args.hasArg (options::OPT_fsycl_device_only) &&
3991
+ Triple.getEnvironment () != llvm::Triple::SYCLDevice) {
3992
+ const char *SYCLTargetArch = " spir64" ;
3993
+ if (C.getDefaultToolChain ().getTriple ().getArch () == llvm::Triple::x86)
3994
+ SYCLTargetArch = " spir" ;
3995
+ Triple = C.getDriver ().MakeSYCLDeviceTriple (SYCLTargetArch);
3996
+ }
3997
+ const std::string &TripleStr = Triple.getTriple ();
3998
+
3989
3999
// Check number of inputs for sanity. We need at least one input.
3990
4000
assert (Inputs.size () >= 1 && " Must have at least one input." );
3991
4001
// CUDA/HIP compilation may have multiple inputs (source file + results of
@@ -4000,7 +4010,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4000
4010
bool IsHIP = JA.isOffloading (Action::OFK_HIP);
4001
4011
bool IsOpenMPDevice = JA.isDeviceOffloading (Action::OFK_OpenMP);
4002
4012
bool IsSYCLOffloadDevice = JA.isDeviceOffloading (Action::OFK_SYCL);
4003
- bool IsSYCL = JA.isOffloading (Action::OFK_SYCL);
4013
+ bool IsSYCL = JA.isOffloading (Action::OFK_SYCL) ||
4014
+ Args.hasArg (options::OPT_fsycl_device_only);
4004
4015
bool IsHeaderModulePrecompile = isa<HeaderModulePrecompileJobAction>(JA);
4005
4016
assert ((IsCuda || IsHIP || (IsOpenMPDevice && Inputs.size () == 2 ) || IsSYCL ||
4006
4017
IsHeaderModulePrecompile || Inputs.size () == 1 ) &&
@@ -4048,14 +4059,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4048
4059
(IsSYCL || IsCuda || IsHIP) ? TC.getAuxTriple () : nullptr ;
4049
4060
bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment ();
4050
4061
bool IsIAMCU = RawTriple.isOSIAMCU ();
4051
- bool IsSYCLDevice = (RawTriple.getEnvironment () == llvm::Triple::SYCLDevice);
4062
+ bool IsSYCLDevice = (RawTriple.getEnvironment () == llvm::Triple::SYCLDevice ||
4063
+ Triple.getEnvironment () == llvm::Triple::SYCLDevice);
4052
4064
// Using just the sycldevice environment is not enough to determine usage
4053
4065
// of the device triple when considering fat static archives. The
4054
4066
// compilation path requires the host object to be fed into the partial link
4055
4067
// step, and being part of the SYCL tool chain causes the incorrect target.
4056
4068
// FIXME - Is it possible to retain host environment when on a target
4057
4069
// device toolchain.
4058
- bool UseSYCLTriple = IsSYCLDevice && (!IsSYCL || IsSYCLOffloadDevice);
4070
+ bool UseSYCLTriple =
4071
+ IsSYCLDevice && (!IsSYCL || IsSYCLOffloadDevice ||
4072
+ Args.hasArg (options::OPT_fsycl_device_only));
4059
4073
4060
4074
// Adjust IsWindowsXYZ for CUDA/HIP/SYCL compilations. Even when compiling in
4061
4075
// device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not
@@ -4144,7 +4158,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4144
4158
options::OPT_fno_sycl_early_optimizations,
4145
4159
Triple.getSubArch () != llvm::Triple::SPIRSubArch_fpga))
4146
4160
CmdArgs.push_back (" -fno-sycl-early-optimizations" );
4147
- else if (RawTriple. isSPIR () ) {
4161
+ else if (IsSYCLDevice ) {
4148
4162
// Set `sycl-opt` option to configure LLVM passes for SPIR target
4149
4163
CmdArgs.push_back (" -mllvm" );
4150
4164
CmdArgs.push_back (" -sycl-opt" );
@@ -4157,7 +4171,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4157
4171
4158
4172
// Pass the triple of host when doing SYCL
4159
4173
llvm::Triple AuxT = C.getDefaultToolChain ().getTriple ();
4160
- if (Args.hasFlag (options::OPT_fsycl_device_only, OptSpecifier (), false ))
4174
+ if (Args.hasArg (options::OPT_fsycl_device_only) &&
4175
+ RawTriple.getEnvironment () == llvm::Triple::SYCLDevice)
4161
4176
AuxT = llvm::Triple (llvm::sys::getProcessTriple ());
4162
4177
std::string NormalizedTriple = AuxT.normalize ();
4163
4178
CmdArgs.push_back (" -aux-triple" );
@@ -6812,6 +6827,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
6812
6827
unsigned RTOptionID = options::OPT__SLASH_MT;
6813
6828
bool isNVPTX = getToolChain ().getTriple ().isNVPTX ();
6814
6829
bool isSYCLDevice =
6830
+ Args.hasArg (options::OPT_fsycl_device_only) ||
6815
6831
getToolChain ().getTriple ().getEnvironment () == llvm::Triple::SYCLDevice;
6816
6832
bool isSYCL = Args.hasArg (options::OPT_fsycl) || isSYCLDevice;
6817
6833
// For SYCL Windows, /MD is the default.
@@ -7823,7 +7839,8 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
7823
7839
7824
7840
TranslatorArgs.push_back (" -o" );
7825
7841
TranslatorArgs.push_back (Output.getFilename ());
7826
- if (getToolChain ().getTriple ().isSYCLDeviceEnvironment ()) {
7842
+ if (getToolChain ().getTriple ().isSYCLDeviceEnvironment () ||
7843
+ TCArgs.hasArg (options::OPT_fsycl_device_only)) {
7827
7844
TranslatorArgs.push_back (" -spirv-max-version=1.1" );
7828
7845
TranslatorArgs.push_back (" -spirv-debug-info-version=legacy" );
7829
7846
// Prevent crash in the translator if input IR contains DIExpression
0 commit comments