@@ -53,13 +53,31 @@ const char *SYCL::Linker::constructLLVMSpirvCommand(Compilation &C,
53
53
}
54
54
55
55
const 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,
58
58
const llvm::opt::ArgStringList &InputFiles) const {
59
59
ArgStringList CmdArgs;
60
60
// 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
+
63
81
// Add an intermediate output file.
64
82
CmdArgs.push_back (" -o" );
65
83
SmallString<128 > TmpName (C.getDriver ().GetTemporaryPath (
@@ -77,7 +95,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
77
95
void SYCL::Linker::constructLlcCommand (Compilation &C, const JobAction &JA,
78
96
const InputInfo &Output, const char *InputFileName) const {
79
97
// Construct llc command.
80
- // The output is an object file
98
+ // The output is an object file.
81
99
ArgStringList LlcArgs{" -filetype=obj" , " -o" , Output.getFilename (),
82
100
InputFileName};
83
101
SmallString<128 > LlcPath (C.getDriver ().Dir );
@@ -88,7 +106,7 @@ void SYCL::Linker::constructLlcCommand(Compilation &C, const JobAction &JA,
88
106
89
107
// For SYCL the inputs of the linker job are SPIR-V binaries and output is
90
108
// a single SPIR-V binary. Input can also be bitcode when specified by
91
- // the user
109
+ // the user.
92
110
void SYCL::Linker::ConstructJob (Compilation &C, const JobAction &JA,
93
111
const InputInfo &Output,
94
112
const InputInfoList &Inputs,
@@ -112,7 +130,8 @@ void SYCL::Linker::ConstructJob(Compilation &C, const JobAction &JA,
112
130
if (!II.isFilename ())
113
131
continue ;
114
132
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))
116
135
SpirvInputs.push_back (II.getFilename ());
117
136
else {
118
137
const char *LLVMSpirvOutputFile =
@@ -122,7 +141,7 @@ void SYCL::Linker::ConstructJob(Compilation &C, const JobAction &JA,
122
141
}
123
142
}
124
143
const char *LLVMLinkOutputFile =
125
- constructLLVMLinkCommand (C, JA, SubArchName, Prefix, SpirvInputs);
144
+ constructLLVMLinkCommand (C, JA, Args, SubArchName, Prefix, SpirvInputs);
126
145
constructLLVMSpirvCommand (C, JA, Output, Prefix, false , LLVMLinkOutputFile);
127
146
}
128
147
0 commit comments