@@ -5094,19 +5094,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
50945094
50955095 // Forward -fsycl-default-sub-group-size if in SYCL mode.
50965096 Args.AddLastArg (CmdArgs, options::OPT_fsycl_default_sub_group_size);
5097-
5098- // Add any predefined macros associated with intel_gpu* type targets
5099- // passed in with -fsycl-targets
5100- if (RawTriple.isSPIR () &&
5101- RawTriple.getSubArch () == llvm::Triple::SPIRSubArch_gen) {
5102- StringRef Device = JA.getOffloadingArch ();
5103- if (!Device.empty ())
5104- CmdArgs.push_back (Args.MakeArgString (
5105- Twine (" -D" ) + SYCL::gen::getGenDeviceMacro (Device)));
5106- }
5107- if (RawTriple.isSPIR () &&
5108- RawTriple.getSubArch () == llvm::Triple::SPIRSubArch_x86_64)
5109- CmdArgs.push_back (" -D__SYCL_TARGET_INTEL_X86_64__" );
51105097 }
51115098
51125099 if (IsSYCL) {
@@ -5192,6 +5179,35 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51925179 }
51935180 }
51945181 }
5182+ // Add any predefined macros associated with intel_gpu* type targets
5183+ // passed in with -fsycl-targets
5184+ // TODO: Macros are populated during device compilations and saved for
5185+ // addition to the host compilation. There is no dependence connection
5186+ // between device and host where we should be able to use the offloading
5187+ // arch to add the macro to the host compile.
5188+ auto addTargetMacros = [&](const llvm::Triple &Triple) {
5189+ if (!Triple.isSPIR ())
5190+ return ;
5191+ SmallString<64 > Macro;
5192+ if (Triple.getSubArch () == llvm::Triple::SPIRSubArch_gen) {
5193+ StringRef Device = JA.getOffloadingArch ();
5194+ if (!Device.empty ()) {
5195+ Macro = " -D" ;
5196+ Macro += SYCL::gen::getGenDeviceMacro (Device);
5197+ }
5198+ } else if (Triple.getSubArch () == llvm::Triple::SPIRSubArch_x86_64)
5199+ Macro = " -D__SYCL_TARGET_INTEL_X86_64__" ;
5200+ if (Macro.size ()) {
5201+ CmdArgs.push_back (Args.MakeArgString (Macro));
5202+ D.addSYCLTargetMacroArg (Args, Macro);
5203+ }
5204+ };
5205+ if (IsSYCLOffloadDevice)
5206+ addTargetMacros (RawTriple);
5207+ else {
5208+ for (auto &Macro : D.getSYCLTargetMacroArgs ())
5209+ CmdArgs.push_back (Args.MakeArgString (Macro));
5210+ }
51955211 }
51965212
51975213 if (IsOpenMPDevice) {
0 commit comments