@@ -2469,6 +2469,14 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
2469
2469
Diag (diag::note_use_dashdash);
2470
2470
}
2471
2471
}
2472
+ else if (A->getOption ().matches (options::OPT_offload_lib_Group)) {
2473
+ // Add the foffload-static-lib library to the command line to allow
2474
+ // processing when no source or object is supplied as well as proper
2475
+ // host link.
2476
+ Arg *InputArg = MakeInputArg (Args, Opts, A->getValue ());
2477
+ Inputs.push_back (std::make_pair (types::TY_Object, InputArg));
2478
+ A->claim ();
2479
+ }
2472
2480
}
2473
2481
if (CCCIsCPP () && Inputs.empty ()) {
2474
2482
// If called as standalone preprocessor, stdin is processed
@@ -3336,7 +3344,7 @@ class OffloadingActionBuilder final {
3336
3344
3337
3345
std::string InputName = IA->getInputArg ().getAsString (Args);
3338
3346
// Objects should already be consumed with -foffload-static-lib
3339
- if (Args.hasArg (options::OPT_foffload_static_lib_EQ ) &&
3347
+ if (Args.hasArg (options::OPT_offload_lib_Group ) &&
3340
3348
IA->getType () == types::TY_Object && isObjectFile (InputName))
3341
3349
return ABRT_Inactive;
3342
3350
@@ -3870,7 +3878,7 @@ class OffloadingActionBuilder final {
3870
3878
if (C.getDefaultToolChain ().getTriple ().isWindowsMSVCEnvironment () ||
3871
3879
!(HostAction->getType () == types::TY_Object &&
3872
3880
isObjectFile (InputName) &&
3873
- Args.hasArg (options::OPT_foffload_static_lib_EQ ))) {
3881
+ Args.hasArg (options::OPT_offload_lib_Group ))) {
3874
3882
ActionList HostActionList;
3875
3883
Action *A (HostAction);
3876
3884
// Only check for FPGA device information when using fpga SubArch.
@@ -3887,15 +3895,11 @@ class OffloadingActionBuilder final {
3887
3895
else if (hasFPGABinary (C, InputName, types::TY_FPGA_AOCR))
3888
3896
A = C.MakeAction <InputAction>(*InputArg, types::TY_FPGA_AOCR);
3889
3897
}
3890
- HostActionList.push_back (A);
3891
- if (!HostActionList.empty ()) {
3892
- auto UnbundlingHostAction =
3893
- C.MakeAction <OffloadUnbundlingJobAction>(HostActionList);
3894
- UnbundlingHostAction->registerDependentActionInfo (
3898
+ auto UnbundlingHostAction = C.MakeAction <OffloadUnbundlingJobAction>(A);
3899
+ UnbundlingHostAction->registerDependentActionInfo (
3895
3900
C.getSingleOffloadToolChain <Action::OFK_Host>(),
3896
3901
/* BoundArch=*/ StringRef (), Action::OFK_Host);
3897
- HostAction = UnbundlingHostAction;
3898
- }
3902
+ HostAction = UnbundlingHostAction;
3899
3903
}
3900
3904
}
3901
3905
@@ -3945,11 +3949,11 @@ class OffloadingActionBuilder final {
3945
3949
if (!IsValid || InputActionList.empty ())
3946
3950
return true ;
3947
3951
3948
- auto *DeviceUnbundlingAction =
3949
- C. MakeAction <OffloadUnbundlingJobAction>( InputActionList);
3952
+ auto *DeviceUnbundlingAction = C. MakeAction <OffloadUnbundlingJobAction>(
3953
+ InputActionList, types::TY_Object );
3950
3954
DeviceUnbundlingAction->registerDependentActionInfo (
3951
- C.getSingleOffloadToolChain <Action::OFK_Host>(),
3952
- /* BoundArch=*/ StringRef (), Action::OFK_Host);
3955
+ C.getSingleOffloadToolChain <Action::OFK_Host>(),
3956
+ /* BoundArch=*/ StringRef (), Action::OFK_Host);
3953
3957
HostAction = DeviceUnbundlingAction;
3954
3958
3955
3959
// Register the offload kinds that are used.
@@ -4357,59 +4361,69 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
4357
4361
// When a static fat archive is provided, create a new unbundling step
4358
4362
// for all of the objects.
4359
4363
if (!C.getDefaultToolChain ().getTriple ().isWindowsMSVCEnvironment () &&
4360
- Args.hasArg (options::OPT_foffload_static_lib_EQ) &&
4361
- !LinkerInputs.empty ()) {
4364
+ Args.hasArg (options::OPT_offload_lib_Group)) {
4362
4365
ActionList UnbundlerInputs;
4363
- ActionList TempLinkerInputs;
4364
4366
for (const auto &LI : LinkerInputs) {
4365
4367
// Unbundler only handles objects.
4366
4368
if (auto *IA = dyn_cast<InputAction>(LI)) {
4367
4369
std::string FileName = IA->getInputArg ().getAsString (Args);
4368
4370
if ((IA->getType () == types::TY_Object && !isObjectFile (FileName)) ||
4369
4371
IA->getInputArg ().getOption ().hasFlag (options::LinkerInput))
4370
- // Pass the Input along to linker.
4371
- TempLinkerInputs.push_back (LI);
4372
- else
4373
- // Add to unbundler.
4374
- UnbundlerInputs.push_back (LI);
4375
- } else
4372
+ // Pass the Input along to linker only.
4373
+ continue ;
4376
4374
UnbundlerInputs.push_back (LI);
4375
+ }
4377
4376
}
4378
- LinkerInputs.clear ();
4377
+ const Arg *LastArg;
4378
+ auto addUnbundlerInput = [&](types::ID T, const Arg *A) {
4379
+ const llvm::opt::OptTable &Opts = getOpts ();
4380
+ Arg *InputArg = MakeInputArg (Args, Opts, A->getValue ());
4381
+ LastArg = InputArg;
4382
+ Action *Current = C.MakeAction <InputAction>(*InputArg, T);
4383
+ UnbundlerInputs.push_back (Current);
4384
+ };
4385
+ for (const auto *A : Args.filtered (options::OPT_foffload_static_lib_EQ))
4386
+ addUnbundlerInput (types::TY_Archive, A);
4387
+ for (const auto *A :
4388
+ Args.filtered (options::OPT_foffload_whole_static_lib_EQ))
4389
+ addUnbundlerInput (types::TY_WholeArchive, A);
4379
4390
if (!UnbundlerInputs.empty ()) {
4380
- Action *Current;
4381
- const Arg *LastArg = Args.getLastArg (options::OPT_foffload_static_lib_EQ);
4391
+ Action *Current = C.MakeAction <InputAction>(*LastArg, types::TY_Archive);
4382
4392
OffloadBuilder.addHostDependenceToUnbundlingAction (Current,
4383
- UnbundlerInputs, LastArg);
4393
+ UnbundlerInputs, LastArg);
4384
4394
Current = OffloadBuilder.addDeviceDependencesToHostAction (Current,
4385
- LastArg, phases::Link, PL.back (), PL);
4386
- LinkerInputs.push_back (Current);
4395
+ LastArg, phases::Link, PL.back (), PL);
4387
4396
}
4388
- for (const auto &TLI : TempLinkerInputs)
4389
- LinkerInputs.push_back (TLI);
4390
4397
}
4391
4398
const llvm::opt::OptTable &Opts = getOpts ();
4399
+ auto unbundleStaticLib = [&](types::ID T, const Arg *A) {
4400
+ Arg *InputArg = MakeInputArg (Args, Opts, A->getValue ());
4401
+ Action *Current = C.MakeAction <InputAction>(*InputArg, T);
4402
+ OffloadBuilder.addHostDependenceToDeviceActions (Current, InputArg, Args);
4403
+ OffloadBuilder.addDeviceDependencesToHostAction (
4404
+ Current, InputArg, phases::Link, PL.back (), PL);
4405
+ };
4392
4406
for (const auto *A : Args.filtered (options::OPT_foffload_static_lib_EQ)) {
4393
- auto unbundleStaticLib = [&](types::ID T) {
4394
- Arg *InputArg = MakeInputArg (Args, Opts, A->getValue ());
4395
- Action *Current = C.MakeAction <InputAction>(*InputArg, T);
4396
- OffloadBuilder.addHostDependenceToDeviceActions (Current, InputArg, Args);
4397
- OffloadBuilder.addDeviceDependencesToHostAction (
4398
- Current, InputArg, phases::Link, PL.back (), PL);
4399
- };
4400
4407
// In MSVC environment offload-static-libs are handled slightly different
4401
4408
// because of missing support for partial linking in the linker. We add an
4402
4409
// unbundling action for each static archive which produces list files with
4403
4410
// extracted objects. Device lists are then added to the appropriate device
4404
4411
// link actions and host list is ignored since we are adding
4405
4412
// offload-static-libs as normal libraries to the host link command.
4406
4413
if (C.getDefaultToolChain ().getTriple ().isWindowsMSVCEnvironment ())
4407
- unbundleStaticLib (types::TY_Archive);
4414
+ unbundleStaticLib (types::TY_Archive, A );
4408
4415
// Pass along the -foffload-static-lib values to check if we need to
4409
4416
// add them for unbundling for FPGA AOT static lib usage. Uses FPGA
4410
4417
// aoco type to differentiate if aoco unbundling is needed.
4411
4418
if (Args.hasArg (options::OPT_fintelfpga))
4412
- unbundleStaticLib (types::TY_FPGA_AOCO);
4419
+ unbundleStaticLib (types::TY_FPGA_AOCO, A);
4420
+ }
4421
+ for (const auto *A :
4422
+ Args.filtered (options::OPT_foffload_whole_static_lib_EQ)) {
4423
+ if (C.getDefaultToolChain ().getTriple ().isWindowsMSVCEnvironment ())
4424
+ unbundleStaticLib (types::TY_WholeArchive, A);
4425
+ if (Args.hasArg (options::OPT_fintelfpga))
4426
+ unbundleStaticLib (types::TY_FPGA_AOCO, A);
4413
4427
}
4414
4428
4415
4429
// For an FPGA archive, we add the unbundling step above to take care of
@@ -5282,13 +5296,11 @@ InputInfo Driver::BuildJobsForActionNoCache(
5282
5296
bool IsFPGAObjLink = (JA->getType () == types::TY_Object &&
5283
5297
C.getInputArgs ().hasArg (options::OPT_fintelfpga) &&
5284
5298
C.getInputArgs ().hasArg (options::OPT_fsycl_link_EQ));
5285
- if (C.getInputArgs ().hasArg (options::OPT_foffload_static_lib_EQ ) &&
5299
+ if (C.getInputArgs ().hasArg (options::OPT_offload_lib_Group ) &&
5286
5300
((JA->getType () == types::TY_Archive && IsMSVCEnv) ||
5287
- (UI.DependentOffloadKind != Action::OFK_Host &&
5288
- (JA->getType () == types::TY_Object && !IsMSVCEnv)))) {
5301
+ (JA->getType () == types::TY_Object && !IsMSVCEnv))) {
5289
5302
// Host part of the unbundled static archive is not used.
5290
- if (UI.DependentOffloadKind == Action::OFK_Host &&
5291
- JA->getType () == types::TY_Archive && IsMSVCEnv)
5303
+ if (UI.DependentOffloadKind == Action::OFK_Host)
5292
5304
continue ;
5293
5305
// Host part of the unbundled object when -fintelfpga -fsycl-link is
5294
5306
// enabled is not used
0 commit comments