@@ -53,13 +53,31 @@ const char *SYCL::Linker::constructLLVMSpirvCommand(Compilation &C,
5353}
5454
5555const char *SYCL::Linker::constructLLVMLinkCommand (
56- Compilation &C, const JobAction &JA, StringRef SubArchName ,
57- StringRef OutputFilePrefix,
56+ Compilation &C, const JobAction &JA, const ArgList &Args ,
57+ StringRef SubArchName, StringRef OutputFilePrefix,
5858 const llvm::opt::ArgStringList &InputFiles) const {
5959 ArgStringList CmdArgs;
6060 // Add the input bc's created by compile step.
61- for (const auto &II : InputFiles)
62- CmdArgs.push_back (II);
61+ // When offloading, the input file(s) could be from unbundled partially
62+ // linked archives. The unbundled information is a list of files and not
63+ // an actual object/archive. Take that list and pass those to the linker
64+ // instead of the original object.
65+ if (JA.isDeviceOffloading (Action::OFK_SYCL) &&
66+ Args.hasArg (options::OPT_foffload_static_lib_EQ)) {
67+ // Go through the Inputs to the link. When an object is encountered, we
68+ // know it is an unbundled generated list.
69+ // FIXME - properly add objects from list to be removed when compilation is
70+ // complete.
71+ for (const auto &II : InputFiles) {
72+ // Read each line of the generated unbundle file and add them to the link.
73+ std::string FileName (II);
74+ CmdArgs.push_back (C.getArgs ().MakeArgString (" @" + FileName));
75+ }
76+ }
77+ else
78+ for (const auto &II : InputFiles)
79+ CmdArgs.push_back (II);
80+
6381 // Add an intermediate output file.
6482 CmdArgs.push_back (" -o" );
6583 SmallString<128 > TmpName (C.getDriver ().GetTemporaryPath (
@@ -77,7 +95,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
7795void SYCL::Linker::constructLlcCommand (Compilation &C, const JobAction &JA,
7896 const InputInfo &Output, const char *InputFileName) const {
7997 // Construct llc command.
80- // The output is an object file
98+ // The output is an object file.
8199 ArgStringList LlcArgs{" -filetype=obj" , " -o" , Output.getFilename (),
82100 InputFileName};
83101 SmallString<128 > LlcPath (C.getDriver ().Dir );
@@ -88,7 +106,7 @@ void SYCL::Linker::constructLlcCommand(Compilation &C, const JobAction &JA,
88106
89107// For SYCL the inputs of the linker job are SPIR-V binaries and output is
90108// a single SPIR-V binary. Input can also be bitcode when specified by
91- // the user
109+ // the user.
92110void SYCL::Linker::ConstructJob (Compilation &C, const JobAction &JA,
93111 const InputInfo &Output,
94112 const InputInfoList &Inputs,
@@ -112,7 +130,8 @@ void SYCL::Linker::ConstructJob(Compilation &C, const JobAction &JA,
112130 if (!II.isFilename ())
113131 continue ;
114132 if (Args.hasFlag (options::OPT_fsycl_use_bitcode,
115- options::OPT_fno_sycl_use_bitcode, true ))
133+ options::OPT_fno_sycl_use_bitcode, true ) ||
134+ Args.hasArg (options::OPT_foffload_static_lib_EQ))
116135 SpirvInputs.push_back (II.getFilename ());
117136 else {
118137 const char *LLVMSpirvOutputFile =
@@ -122,7 +141,7 @@ void SYCL::Linker::ConstructJob(Compilation &C, const JobAction &JA,
122141 }
123142 }
124143 const char *LLVMLinkOutputFile =
125- constructLLVMLinkCommand (C, JA, SubArchName, Prefix, SpirvInputs);
144+ constructLLVMLinkCommand (C, JA, Args, SubArchName, Prefix, SpirvInputs);
126145 constructLLVMSpirvCommand (C, JA, Output, Prefix, false , LLVMLinkOutputFile);
127146}
128147
0 commit comments