@@ -1221,9 +1221,11 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
12211221 // We need to generate a SYCL toolchain if the user specified -fsycl.
12221222 // If -fsycl is supplied without any of these we will assume SPIR-V.
12231223 // Use of -fsycl-device-only overrides -fsycl.
1224+ // Use of -fsyclbin enables SYCL device compilation.
12241225 bool IsSYCL = C.getInputArgs ().hasFlag (options::OPT_fsycl,
12251226 options::OPT_fno_sycl, false ) ||
1226- C.getInputArgs ().hasArg (options::OPT_fsycl_device_only);
1227+ C.getInputArgs ().hasArgNoClaim (options::OPT_fsycl_device_only,
1228+ options::OPT_fsyclbin);
12271229
12281230 auto argSYCLIncompatible = [&](OptSpecifier OptId) {
12291231 if (!IsSYCL)
@@ -3464,7 +3466,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
34643466 Arg *InputTypeArg = nullptr ;
34653467 bool IsSYCL =
34663468 Args.hasFlag (options::OPT_fsycl, options::OPT_fno_sycl, false ) ||
3467- Args.hasArg (options::OPT_fsycl_device_only);
3469+ Args.hasArgNoClaim (options::OPT_fsycl_device_only, options::OPT_fsyclbin );
34683470
34693471 // The last /TC or /TP option sets the input type to C or C++ globally.
34703472 if (Arg *TCTP = Args.getLastArgNoClaim (options::OPT__SLASH_TC,
@@ -7929,6 +7931,19 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
79297931 C.MakeAction <LinkJobAction>(OffloadActions, types::TY_HIP_FATBIN);
79307932 DDep.add (*FatbinAction, *C.getSingleOffloadToolChain <Action::OFK_HIP>(),
79317933 nullptr , Action::OFK_HIP);
7934+ } else if (C.isOffloadingHostKind (Action::OFK_SYCL) &&
7935+ Args.hasArg (options::OPT_fsyclbin)) {
7936+ // With '-fsyclbin', package all the offloading actions into a single output
7937+ // that is sent to the clang-linker-wrapper.
7938+ Action *PackagerAction =
7939+ C.MakeAction <OffloadPackagerJobAction>(OffloadActions, types::TY_Image);
7940+ ActionList PackagerActions;
7941+ PackagerActions.push_back (PackagerAction);
7942+ Action *LinkAction =
7943+ C.MakeAction <LinkerWrapperJobAction>(PackagerActions, types::TY_Image);
7944+ DDep.add (*LinkAction, *C.getSingleOffloadToolChain <Action::OFK_Host>(),
7945+ nullptr , C.getActiveOffloadKinds ());
7946+ return C.MakeAction <OffloadAction>(DDep, types::TY_Nothing);
79327947 } else {
79337948 // Package all the offloading actions into a single output that can be
79347949 // embedded in the host and linked.
@@ -9336,8 +9351,10 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
93369351 if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) {
93379352 if (Arg *FinalOutput = C.getArgs ().getLastArg (options::OPT_o))
93389353 return C.addResultFile (FinalOutput->getValue (), &JA);
9339- // Output to destination for -fsycl-device-only and Windows -o
9340- if (offloadDeviceOnly () && JA.getOffloadingDeviceKind () == Action::OFK_SYCL)
9354+ // Output to destination for -fsycl-device-only/-fsyclbin and Windows -o
9355+ if ((offloadDeviceOnly () ||
9356+ C.getArgs ().hasArgNoClaim (options::OPT_fsyclbin)) &&
9357+ JA.getOffloadingDeviceKind () == Action::OFK_SYCL)
93419358 if (Arg *FinalOutput = C.getArgs ().getLastArg (options::OPT__SLASH_o))
93429359 return C.addResultFile (FinalOutput->getValue (), &JA);
93439360 }
@@ -9506,6 +9523,20 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
95069523 else
95079524 BaseName = llvm::sys::path::filename (BasePath);
95089525
9526+ // When compiling with -fsyclbin, maintain a simple output file name for the
9527+ // resulting image. A '.syclbin' extension is used to represent the resulting
9528+ // output file.
9529+ if (JA.getOffloadingDeviceKind () == Action::OFK_SYCL &&
9530+ C.getArgs ().hasArgNoClaim (options::OPT_fsyclbin) &&
9531+ JA.getType () == types::TY_Image) {
9532+ SmallString<128 > SYCLBinOutput (getDefaultImageName ());
9533+ if (IsCLMode ())
9534+ // Use BaseName for the syclbin output name.
9535+ SYCLBinOutput = BaseName;
9536+ llvm::sys::path::replace_extension (SYCLBinOutput, " .syclbin" );
9537+ return C.addResultFile (C.getArgs ().MakeArgString (SYCLBinOutput), &JA);
9538+ }
9539+
95099540 // Determine what the derived output name should be.
95109541 const char *NamedOutput;
95119542
0 commit comments