@@ -1221,9 +1221,11 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
1221
1221
// We need to generate a SYCL toolchain if the user specified -fsycl.
1222
1222
// If -fsycl is supplied without any of these we will assume SPIR-V.
1223
1223
// Use of -fsycl-device-only overrides -fsycl.
1224
+ // Use of -fsyclbin enables SYCL device compilation.
1224
1225
bool IsSYCL = C.getInputArgs ().hasFlag (options::OPT_fsycl,
1225
1226
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);
1227
1229
1228
1230
auto argSYCLIncompatible = [&](OptSpecifier OptId) {
1229
1231
if (!IsSYCL)
@@ -3464,7 +3466,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
3464
3466
Arg *InputTypeArg = nullptr ;
3465
3467
bool IsSYCL =
3466
3468
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 );
3468
3470
3469
3471
// The last /TC or /TP option sets the input type to C or C++ globally.
3470
3472
if (Arg *TCTP = Args.getLastArgNoClaim (options::OPT__SLASH_TC,
@@ -7929,6 +7931,19 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
7929
7931
C.MakeAction <LinkJobAction>(OffloadActions, types::TY_HIP_FATBIN);
7930
7932
DDep.add (*FatbinAction, *C.getSingleOffloadToolChain <Action::OFK_HIP>(),
7931
7933
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);
7932
7947
} else {
7933
7948
// Package all the offloading actions into a single output that can be
7934
7949
// embedded in the host and linked.
@@ -9336,8 +9351,10 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
9336
9351
if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) {
9337
9352
if (Arg *FinalOutput = C.getArgs ().getLastArg (options::OPT_o))
9338
9353
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)
9341
9358
if (Arg *FinalOutput = C.getArgs ().getLastArg (options::OPT__SLASH_o))
9342
9359
return C.addResultFile (FinalOutput->getValue (), &JA);
9343
9360
}
@@ -9506,6 +9523,20 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
9506
9523
else
9507
9524
BaseName = llvm::sys::path::filename (BasePath);
9508
9525
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
+
9509
9540
// Determine what the derived output name should be.
9510
9541
const char *NamedOutput;
9511
9542
0 commit comments