@@ -5551,6 +5551,59 @@ class OffloadingActionBuilder final {
5551
5551
/* BoundArch*/ nullptr , ActiveOffloadKinds);
5552
5552
return C.MakeAction <OffloadAction>(HDep, DDeps);
5553
5553
}
5554
+
5555
+ void unbundleStaticArchives (Compilation &C, DerivedArgList &Args,
5556
+ DeviceActionBuilder::PhasesTy &PL) {
5557
+ if (!Args.hasFlag (options::OPT_fsycl, options::OPT_fno_sycl, false ))
5558
+ return ;
5559
+
5560
+ // Go through all of the args, and create a Linker specific argument list.
5561
+ // When dealing with fat static archives each archive is individually
5562
+ // unbundled.
5563
+ SmallVector<const char *, 16 > LinkArgs (getLinkerArgs (C, Args));
5564
+ const llvm::opt::OptTable &Opts = C.getDriver ().getOpts ();
5565
+ auto unbundleStaticLib = [&](types::ID T, const StringRef &A) {
5566
+ Arg *InputArg = MakeInputArg (Args, Opts, Args.MakeArgString (A));
5567
+ Action *Current = C.MakeAction <InputAction>(*InputArg, T);
5568
+ addHostDependenceToDeviceActions (Current, InputArg, Args);
5569
+ addDeviceDependencesToHostAction (Current, InputArg, phases::Link,
5570
+ PL.back (), PL);
5571
+ };
5572
+ for (StringRef LA : LinkArgs) {
5573
+ // At this point, we will process the archives for FPGA AOCO and
5574
+ // individual archive unbundling for Windows.
5575
+ if (!isStaticArchiveFile (LA))
5576
+ continue ;
5577
+ // FPGA AOCX/AOCR files are archives, but we do not want to unbundle them
5578
+ // here as they have already been unbundled and processed for linking.
5579
+ // TODO: The multiple binary checks for FPGA types getting a little out
5580
+ // of hand. Improve this by doing a single scan of the args and holding
5581
+ // that in a data structure for reference.
5582
+ if (hasFPGABinary (C, LA.str (), types::TY_FPGA_AOCX) ||
5583
+ hasFPGABinary (C, LA.str (), types::TY_FPGA_AOCR) ||
5584
+ hasFPGABinary (C, LA.str (), types::TY_FPGA_AOCR_EMU))
5585
+ continue ;
5586
+ // For offload-static-libs we add an unbundling action for each static
5587
+ // archive which produces list files with extracted objects. Device lists
5588
+ // are then added to the appropriate device link actions and host list is
5589
+ // ignored since we are adding offload-static-libs as normal libraries to
5590
+ // the host link command.
5591
+ if (hasOffloadSections (C, LA, Args)) {
5592
+ // Pass along the static libraries to check if we need to add them for
5593
+ // unbundling for FPGA AOT static lib usage. Uses FPGA aoco type to
5594
+ // differentiate if aoco unbundling is needed. Unbundling of aoco is
5595
+ // not needed for emulation, as these are treated as regular archives.
5596
+ if (!C.getDriver ().isFPGAEmulationMode ())
5597
+ unbundleStaticLib (types::TY_FPGA_AOCO, LA);
5598
+ // Do not unbundle any AOCO archive as a regular archive when we are
5599
+ // in FPGA Hardware/Simulation mode.
5600
+ if (!C.getDriver ().isFPGAEmulationMode () &&
5601
+ hasFPGABinary (C, LA.str (), types::TY_FPGA_AOCO))
5602
+ continue ;
5603
+ unbundleStaticLib (types::TY_Archive, LA);
5604
+ }
5605
+ }
5606
+ }
5554
5607
};
5555
5608
} // anonymous namespace.
5556
5609
@@ -5892,52 +5945,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
5892
5945
if (!LinkerInputs.empty () && C.getDriver ().getOffloadStaticLibSeen ())
5893
5946
OffloadBuilder.addDeviceLinkDependenciesFromHost (LinkerInputs);
5894
5947
5895
- // Go through all of the args, and create a Linker specific argument list.
5896
- // When dealing with fat static archives each archive is individually
5897
- // unbundled.
5898
- SmallVector<const char *, 16 > LinkArgs (getLinkerArgs (C, Args));
5899
- const llvm::opt::OptTable &Opts = getOpts ();
5900
- auto unbundleStaticLib = [&](types::ID T, const StringRef &A) {
5901
- Arg *InputArg = MakeInputArg (Args, Opts, Args.MakeArgString (A));
5902
- Action *Current = C.MakeAction <InputAction>(*InputArg, T);
5903
- OffloadBuilder.addHostDependenceToDeviceActions (Current, InputArg, Args);
5904
- OffloadBuilder.addDeviceDependencesToHostAction (
5905
- Current, InputArg, phases::Link, PL.back (), PL);
5906
- };
5907
- for (StringRef LA : LinkArgs) {
5908
- // At this point, we will process the archives for FPGA AOCO and individual
5909
- // archive unbundling for Windows.
5910
- if (!isStaticArchiveFile (LA))
5911
- continue ;
5912
- // FPGA AOCX/AOCR files are archives, but we do not want to unbundle them
5913
- // here as they have already been unbundled and processed for linking.
5914
- // TODO: The multiple binary checks for FPGA types getting a little out
5915
- // of hand. Improve this by doing a single scan of the args and holding
5916
- // that in a data structure for reference.
5917
- if (hasFPGABinary (C, LA.str (), types::TY_FPGA_AOCX) ||
5918
- hasFPGABinary (C, LA.str (), types::TY_FPGA_AOCR) ||
5919
- hasFPGABinary (C, LA.str (), types::TY_FPGA_AOCR_EMU))
5920
- continue ;
5921
- // For offload-static-libs we add an unbundling action for each static
5922
- // archive which produces list files with extracted objects. Device lists
5923
- // are then added to the appropriate device link actions and host list is
5924
- // ignored since we are adding offload-static-libs as normal libraries to
5925
- // the host link command.
5926
- if (hasOffloadSections (C, LA, Args)) {
5927
- // Pass along the static libraries to check if we need to add them for
5928
- // unbundling for FPGA AOT static lib usage. Uses FPGA aoco type to
5929
- // differentiate if aoco unbundling is needed. Unbundling of aoco is not
5930
- // needed for emulation, as these are treated as regular archives.
5931
- if (!C.getDriver ().isFPGAEmulationMode ())
5932
- unbundleStaticLib (types::TY_FPGA_AOCO, LA);
5933
- // Do not unbundle any AOCO archive as a regular archive when we are
5934
- // in FPGA Hardware/Simulation mode.
5935
- if (!C.getDriver ().isFPGAEmulationMode () &&
5936
- hasFPGABinary (C, LA.str (), types::TY_FPGA_AOCO))
5937
- continue ;
5938
- unbundleStaticLib (types::TY_Archive, LA);
5939
- }
5940
- }
5948
+ OffloadBuilder.unbundleStaticArchives (C, Args, PL);
5941
5949
5942
5950
// For an FPGA archive, we add the unbundling step above to take care of
5943
5951
// the device side, but also unbundle here to extract the host side
@@ -5973,7 +5981,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
5973
5981
if (UnbundlerInput && !PL.empty ()) {
5974
5982
if (auto *IA = dyn_cast<InputAction>(UnbundlerInput)) {
5975
5983
std::string FileName = IA->getInputArg ().getAsString (Args);
5976
- Arg *InputArg = MakeInputArg (Args, Opts , FileName);
5984
+ Arg *InputArg = MakeInputArg (Args, getOpts () , FileName);
5977
5985
OffloadBuilder.addHostDependenceToDeviceActions (UnbundlerInput,
5978
5986
InputArg, Args);
5979
5987
OffloadBuilder.addDeviceDependencesToHostAction (
0 commit comments