@@ -4267,15 +4267,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4267
4267
(IsSYCL || IsCuda || IsHIP) ? TC.getAuxTriple () : nullptr ;
4268
4268
bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment ();
4269
4269
bool IsIAMCU = RawTriple.isOSIAMCU ();
4270
- bool IsSYCLDevice = (RawTriple.getEnvironment () == llvm::Triple::SYCLDevice ||
4271
- Triple.getEnvironment () == llvm::Triple::SYCLDevice);
4272
- // Using just the sycldevice environment is not enough to determine usage
4273
- // of the device triple when considering fat static archives. The
4274
- // compilation path requires the host object to be fed into the partial link
4275
- // step, and being part of the SYCL tool chain causes the incorrect target.
4276
- // FIXME - Is it possible to retain host environment when on a target
4277
- // device toolchain.
4278
- bool UseSYCLTriple = IsSYCLDevice && (!IsSYCL || IsSYCLOffloadDevice);
4279
4270
4280
4271
// Adjust IsWindowsXYZ for CUDA/HIP/SYCL compilations. Even when compiling in
4281
4272
// device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not
@@ -4294,16 +4285,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4294
4285
4295
4286
// Add the "effective" target triple.
4296
4287
CmdArgs.push_back (" -triple" );
4297
- if (!UseSYCLTriple && IsSYCLDevice) {
4298
- // Do not use device triple when we know the device is not SYCL
4299
- // FIXME: We override the toolchain triple in this instance to address a
4300
- // disconnect with fat static archives. We should have a cleaner way of
4301
- // using the Host environment when on a device toolchain.
4302
- std::string NormalizedTriple =
4303
- llvm::Triple (llvm::sys::getProcessTriple ()).normalize ();
4304
- CmdArgs.push_back (Args.MakeArgString (NormalizedTriple));
4305
- } else
4306
- CmdArgs.push_back (Args.MakeArgString (TripleStr));
4288
+ CmdArgs.push_back (Args.MakeArgString (TripleStr));
4307
4289
4308
4290
if (const Arg *MJ = Args.getLastArg (options::OPT_MJ)) {
4309
4291
DumpCompilationDatabase (C, MJ->getValue (), TripleStr, Output, Input, Args);
@@ -4349,7 +4331,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4349
4331
4350
4332
Arg *SYCLStdArg = Args.getLastArg (options::OPT_sycl_std_EQ);
4351
4333
4352
- if (UseSYCLTriple) {
4334
+ if (IsSYCLOffloadDevice) {
4335
+ // Pass the triple of host when doing SYCL
4336
+ llvm::Triple AuxT = C.getDefaultToolChain ().getTriple ();
4337
+ std::string NormalizedTriple = AuxT.normalize ();
4338
+ CmdArgs.push_back (" -aux-triple" );
4339
+ CmdArgs.push_back (Args.MakeArgString (NormalizedTriple));
4340
+
4353
4341
// We want to compile sycl kernels.
4354
4342
CmdArgs.push_back (" -fsycl-is-device" );
4355
4343
CmdArgs.push_back (" -fdeclare-spirv-builtins" );
@@ -4364,18 +4352,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4364
4352
CmdArgs.push_back (" -mllvm" );
4365
4353
CmdArgs.push_back (" -sycl-opt" );
4366
4354
}
4355
+
4367
4356
// Turn on Dead Parameter Elimination Optimization with early optimizations
4368
4357
if (!RawTriple.isNVPTX () &&
4369
4358
Args.hasFlag (options::OPT_fsycl_dead_args_optimization,
4370
4359
options::OPT_fno_sycl_dead_args_optimization, false ))
4371
4360
CmdArgs.push_back (" -fenable-sycl-dae" );
4372
-
4373
- // Pass the triple of host when doing SYCL
4374
- llvm::Triple AuxT = C.getDefaultToolChain ().getTriple ();
4375
- std::string NormalizedTriple = AuxT.normalize ();
4376
- CmdArgs.push_back (" -aux-triple" );
4377
- CmdArgs.push_back (Args.MakeArgString (NormalizedTriple));
4378
-
4379
4361
bool IsMSVC = AuxT.isWindowsMSVCEnvironment ();
4380
4362
if (IsMSVC) {
4381
4363
CmdArgs.push_back (" -fms-extensions" );
@@ -4404,22 +4386,67 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4404
4386
// along with marking the same function with explicit SYCL_EXTERNAL
4405
4387
CmdArgs.push_back (" -Wno-sycl-strict" );
4406
4388
}
4389
+
4390
+ // Add the integration header option to generate the header.
4391
+ StringRef Header (D.getIntegrationHeader (Input.getBaseInput ()));
4392
+ if (!Header.empty ()) {
4393
+ SmallString<128 > HeaderOpt (" -fsycl-int-header=" );
4394
+ HeaderOpt.append (Header);
4395
+ CmdArgs.push_back (Args.MakeArgString (HeaderOpt));
4396
+ }
4407
4397
}
4408
- if (IsSYCL || UseSYCLTriple) {
4398
+
4399
+ if (IsSYCL) {
4409
4400
// Set options for both host and device
4410
4401
if (Arg *A = Args.getLastArg (options::OPT_fsycl_id_queries_fit_in_int,
4411
4402
options::OPT_fno_sycl_id_queries_fit_in_int))
4412
4403
A->render (Args, CmdArgs);
4413
- }
4414
4404
4415
- if (IsSYCL) {
4416
4405
if (SYCLStdArg) {
4417
4406
SYCLStdArg->render (Args, CmdArgs);
4418
4407
CmdArgs.push_back (" -fsycl-std-layout-kernel-params" );
4419
4408
} else {
4420
4409
// Ensure the default version in SYCL mode is 2020
4421
4410
CmdArgs.push_back (" -sycl-std=2020" );
4422
4411
}
4412
+ if (Args.hasArg (options::OPT_fsycl_unnamed_lambda))
4413
+ CmdArgs.push_back (" -fsycl-unnamed-lambda" );
4414
+
4415
+ // Enable generation of USM address spaces for FPGA.
4416
+ // __ENABLE_USM_ADDR_SPACE__ will be used during compilation of SYCL headers
4417
+ if (getToolChain ().getTriple ().getSubArch () ==
4418
+ llvm::Triple::SPIRSubArch_fpga)
4419
+ CmdArgs.push_back (" -D__ENABLE_USM_ADDR_SPACE__" );
4420
+
4421
+ // Add any options that are needed specific to SYCL offload while
4422
+ // performing the host side compilation.
4423
+ if (!IsSYCLOffloadDevice) {
4424
+ // Add the -include option to add the integration header
4425
+ StringRef Header = D.getIntegrationHeader (Input.getBaseInput ());
4426
+ if (types::getPreprocessedType (Input.getType ()) != types::TY_INVALID &&
4427
+ !Header.empty ()) {
4428
+ CmdArgs.push_back (" -include" );
4429
+ CmdArgs.push_back (Args.MakeArgString (Header));
4430
+ // When creating dependency information, filter out the generated
4431
+ // header file.
4432
+ CmdArgs.push_back (" -dependency-filter" );
4433
+ CmdArgs.push_back (Args.MakeArgString (Header));
4434
+ }
4435
+ // Let the FE know we are doing a SYCL offload compilation, but we are
4436
+ // doing the host pass.
4437
+ CmdArgs.push_back (" -fsycl-is-host" );
4438
+
4439
+ if (!D.IsCLMode ()) {
4440
+ // SYCL library is guaranteed to work correctly only with dynamic
4441
+ // MSVC runtime.
4442
+ llvm::Triple AuxT = C.getDefaultToolChain ().getTriple ();
4443
+ if (AuxT.isWindowsMSVCEnvironment ()) {
4444
+ CmdArgs.push_back (" -D_MT" );
4445
+ CmdArgs.push_back (" -D_DLL" );
4446
+ CmdArgs.push_back (" --dependent-lib=msvcrt" );
4447
+ }
4448
+ }
4449
+ }
4423
4450
}
4424
4451
4425
4452
if (IsOpenMPDevice) {
@@ -4500,7 +4527,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
4500
4527
CmdArgs.push_back (" -P" );
4501
4528
}
4502
4529
} else if (isa<AssembleJobAction>(JA)) {
4503
- if (IsSYCLOffloadDevice && IsSYCLDevice ) {
4530
+ if (IsSYCLOffloadDevice) {
4504
4531
CmdArgs.push_back (" -emit-llvm-bc" );
4505
4532
} else {
4506
4533
CmdArgs.push_back (" -emit-obj" );
@@ -5958,10 +5985,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
5958
5985
// Forward -cl options to -cc1
5959
5986
RenderOpenCLOptions (Args, CmdArgs, InputType);
5960
5987
5961
- // Forward -sycl-std option to -cc1 only if -fsycl is enabled.
5962
- if (Args.hasFlag (options::OPT_fsycl, options::OPT_fno_sycl, false ))
5963
- Args.AddLastArg (CmdArgs, options::OPT_sycl_std_EQ);
5964
-
5965
5988
// Forward -fsycl-instrument-device-code option to cc1. This option can only
5966
5989
// be used with spir triple.
5967
5990
if (Arg *A = Args.getLastArg (options::OPT_fsycl_instrument_device_code)) {
@@ -6425,7 +6448,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
6425
6448
// selected. For optimization levels that want vectorization we use the alias
6426
6449
// option to simplify the hasFlag logic.
6427
6450
bool EnableVec = shouldEnableVectorizerAtOLevel (Args, false );
6428
- if (UseSYCLTriple && RawTriple.isSPIR () && EnableSYCLEarlyOptimizations)
6451
+ if (RawTriple.isSPIR () && EnableSYCLEarlyOptimizations)
6429
6452
EnableVec = false ; // But disable vectorization for SYCL device code
6430
6453
OptSpecifier VectorizeAliasOption =
6431
6454
EnableVec ? options::OPT_O_Group : options::OPT_fvectorize;
@@ -6435,7 +6458,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
6435
6458
6436
6459
// -fslp-vectorize is enabled based on the optimization level selected.
6437
6460
bool EnableSLPVec = shouldEnableVectorizerAtOLevel (Args, true );
6438
- if (UseSYCLTriple && RawTriple.isSPIR () && EnableSYCLEarlyOptimizations)
6461
+ if (RawTriple.isSPIR () && EnableSYCLEarlyOptimizations)
6439
6462
EnableSLPVec = false ; // But disable vectorization for SYCL device code
6440
6463
OptSpecifier SLPVectAliasOption =
6441
6464
EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
@@ -6640,56 +6663,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
6640
6663
CmdArgs.push_back (" -fcuda-short-ptr" );
6641
6664
}
6642
6665
6643
- if (IsSYCL) {
6644
- // Add any options that are needed specific to SYCL offload while
6645
- // performing the host side compilation.
6646
- if (!IsSYCLOffloadDevice) {
6647
- // Add the integration header option to generate the header.
6648
- StringRef Header = D.getIntegrationHeader (Input.getBaseInput ());
6649
- if (types::getPreprocessedType (InputType) != types::TY_INVALID &&
6650
- !Header.empty ()) {
6651
- CmdArgs.push_back (" -include" );
6652
- CmdArgs.push_back (Args.MakeArgString (Header));
6653
- // When creating dependency information, filter out the generated
6654
- // header file.
6655
- CmdArgs.push_back (" -dependency-filter" );
6656
- CmdArgs.push_back (Args.MakeArgString (Header));
6657
- }
6658
- // Let the FE know we are doing a SYCL offload compilation, but we are
6659
- // doing the host pass.
6660
- CmdArgs.push_back (" -fsycl-is-host" );
6661
-
6662
- if (!D.IsCLMode ()) {
6663
- // SYCL library is guaranteed to work correctly only with dynamic
6664
- // MSVC runtime.
6665
- llvm::Triple AuxT = C.getDefaultToolChain ().getTriple ();
6666
- if (AuxT.isWindowsMSVCEnvironment ()) {
6667
- CmdArgs.push_back (" -D_MT" );
6668
- CmdArgs.push_back (" -D_DLL" );
6669
- CmdArgs.push_back (" --dependent-lib=msvcrt" );
6670
- }
6671
- }
6672
- }
6673
- if (IsSYCLOffloadDevice) {
6674
- // Add the integration header option to generate the header.
6675
- StringRef Header (D.getIntegrationHeader (Input.getBaseInput ()));
6676
- if (!Header.empty ()) {
6677
- SmallString<128 > HeaderOpt (" -fsycl-int-header=" );
6678
- HeaderOpt.append (Header);
6679
- CmdArgs.push_back (Args.MakeArgString (HeaderOpt));
6680
- }
6681
- }
6682
-
6683
- if (Args.hasArg (options::OPT_fsycl_unnamed_lambda))
6684
- CmdArgs.push_back (" -fsycl-unnamed-lambda" );
6685
-
6686
- // Enable generation of USM address spaces for FPGA.
6687
- // __ENABLE_USM_ADDR_SPACE__ will be used during compilation of SYCL headers
6688
- if (getToolChain ().getTriple ().getSubArch () ==
6689
- llvm::Triple::SPIRSubArch_fpga)
6690
- CmdArgs.push_back (" -D__ENABLE_USM_ADDR_SPACE__" );
6691
- }
6692
-
6693
6666
if (IsCuda || IsHIP) {
6694
6667
// Determine the original source input.
6695
6668
const Action *SourceAction = &JA;
0 commit comments