@@ -4267,15 +4267,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
42674267 (IsSYCL || IsCuda || IsHIP) ? TC.getAuxTriple () : nullptr ;
42684268 bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment ();
42694269 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);
42794270
42804271 // Adjust IsWindowsXYZ for CUDA/HIP/SYCL compilations. Even when compiling in
42814272 // device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not
@@ -4294,16 +4285,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
42944285
42954286 // Add the "effective" target triple.
42964287 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));
43074289
43084290 if (const Arg *MJ = Args.getLastArg (options::OPT_MJ)) {
43094291 DumpCompilationDatabase (C, MJ->getValue (), TripleStr, Output, Input, Args);
@@ -4349,7 +4331,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
43494331
43504332 Arg *SYCLStdArg = Args.getLastArg (options::OPT_sycl_std_EQ);
43514333
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+
43534341 // We want to compile sycl kernels.
43544342 CmdArgs.push_back (" -fsycl-is-device" );
43554343 CmdArgs.push_back (" -fdeclare-spirv-builtins" );
@@ -4364,18 +4352,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
43644352 CmdArgs.push_back (" -mllvm" );
43654353 CmdArgs.push_back (" -sycl-opt" );
43664354 }
4355+
43674356 // Turn on Dead Parameter Elimination Optimization with early optimizations
43684357 if (!RawTriple.isNVPTX () &&
43694358 Args.hasFlag (options::OPT_fsycl_dead_args_optimization,
43704359 options::OPT_fno_sycl_dead_args_optimization, false ))
43714360 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-
43794361 bool IsMSVC = AuxT.isWindowsMSVCEnvironment ();
43804362 if (IsMSVC) {
43814363 CmdArgs.push_back (" -fms-extensions" );
@@ -4404,22 +4386,67 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
44044386 // along with marking the same function with explicit SYCL_EXTERNAL
44054387 CmdArgs.push_back (" -Wno-sycl-strict" );
44064388 }
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+ }
44074397 }
4408- if (IsSYCL || UseSYCLTriple) {
4398+
4399+ if (IsSYCL) {
44094400 // Set options for both host and device
44104401 if (Arg *A = Args.getLastArg (options::OPT_fsycl_id_queries_fit_in_int,
44114402 options::OPT_fno_sycl_id_queries_fit_in_int))
44124403 A->render (Args, CmdArgs);
4413- }
44144404
4415- if (IsSYCL) {
44164405 if (SYCLStdArg) {
44174406 SYCLStdArg->render (Args, CmdArgs);
44184407 CmdArgs.push_back (" -fsycl-std-layout-kernel-params" );
44194408 } else {
44204409 // Ensure the default version in SYCL mode is 2020
44214410 CmdArgs.push_back (" -sycl-std=2020" );
44224411 }
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+ }
44234450 }
44244451
44254452 if (IsOpenMPDevice) {
@@ -4500,7 +4527,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
45004527 CmdArgs.push_back (" -P" );
45014528 }
45024529 } else if (isa<AssembleJobAction>(JA)) {
4503- if (IsSYCLOffloadDevice && IsSYCLDevice ) {
4530+ if (IsSYCLOffloadDevice) {
45044531 CmdArgs.push_back (" -emit-llvm-bc" );
45054532 } else {
45064533 CmdArgs.push_back (" -emit-obj" );
@@ -5958,10 +5985,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
59585985 // Forward -cl options to -cc1
59595986 RenderOpenCLOptions (Args, CmdArgs, InputType);
59605987
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-
59655988 // Forward -fsycl-instrument-device-code option to cc1. This option can only
59665989 // be used with spir triple.
59675990 if (Arg *A = Args.getLastArg (options::OPT_fsycl_instrument_device_code)) {
@@ -6425,7 +6448,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
64256448 // selected. For optimization levels that want vectorization we use the alias
64266449 // option to simplify the hasFlag logic.
64276450 bool EnableVec = shouldEnableVectorizerAtOLevel (Args, false );
6428- if (UseSYCLTriple && RawTriple.isSPIR () && EnableSYCLEarlyOptimizations)
6451+ if (RawTriple.isSPIR () && EnableSYCLEarlyOptimizations)
64296452 EnableVec = false ; // But disable vectorization for SYCL device code
64306453 OptSpecifier VectorizeAliasOption =
64316454 EnableVec ? options::OPT_O_Group : options::OPT_fvectorize;
@@ -6435,7 +6458,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
64356458
64366459 // -fslp-vectorize is enabled based on the optimization level selected.
64376460 bool EnableSLPVec = shouldEnableVectorizerAtOLevel (Args, true );
6438- if (UseSYCLTriple && RawTriple.isSPIR () && EnableSYCLEarlyOptimizations)
6461+ if (RawTriple.isSPIR () && EnableSYCLEarlyOptimizations)
64396462 EnableSLPVec = false ; // But disable vectorization for SYCL device code
64406463 OptSpecifier SLPVectAliasOption =
64416464 EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
@@ -6640,56 +6663,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
66406663 CmdArgs.push_back (" -fcuda-short-ptr" );
66416664 }
66426665
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-
66936666 if (IsCuda || IsHIP) {
66946667 // Determine the original source input.
66956668 const Action *SourceAction = &JA;
0 commit comments