@@ -183,10 +183,11 @@ static void thinLTOCreateEmptyIndexFiles() {
183
183
184
184
// Merge all the bitcode files we have seen, codegen the result
185
185
// and return the resulting objects.
186
- std::vector<StringRef > BitcodeCompiler::compile () {
186
+ std::vector<MemoryBufferRef > BitcodeCompiler::compile () {
187
187
unsigned maxTasks = ltoObj->getMaxTasks ();
188
188
buf.resize (maxTasks);
189
189
files.resize (maxTasks);
190
+ filenames.resize (maxTasks);
190
191
191
192
// The --thinlto-cache-dir option specifies the path to a directory in which
192
193
// to cache native object files for ThinLTO incremental builds. If a path was
@@ -233,15 +234,21 @@ std::vector<StringRef> BitcodeCompiler::compile() {
233
234
if (!ctx.arg .thinLTOCacheDir .empty ())
234
235
pruneCache (ctx.arg .thinLTOCacheDir , ctx.arg .thinLTOCachePolicy , files);
235
236
236
- std::vector<StringRef > ret;
237
+ std::vector<MemoryBufferRef > ret;
237
238
for (unsigned i = 0 ; i != maxTasks; ++i) {
238
239
StringRef objBuf = buf[i].second ;
239
240
StringRef bitcodeFilePath = buf[i].first ;
241
+ if (files[i]) {
242
+ // When files[i] is not null, we get the native relocatable file from the
243
+ // cache. filenames[i] contains the original BitcodeFile's identifier.
244
+ objBuf = files[i]->getBuffer ();
245
+ bitcodeFilePath = filenames[i];
246
+ } else {
247
+ objBuf = buf[i].second ;
248
+ bitcodeFilePath = buf[i].first ;
249
+ }
240
250
if (objBuf.empty ())
241
251
continue ;
242
- ret.emplace_back (objBuf.data (), objBuf.size ());
243
- if (!ctx.arg .saveTemps )
244
- continue ;
245
252
246
253
// If the input bitcode file is path/to/x.o and -o specifies a.out, the
247
254
// corresponding native relocatable file path will look like:
@@ -266,7 +273,9 @@ std::vector<StringRef> BitcodeCompiler::compile() {
266
273
sys::path::remove_dots (path, true );
267
274
ltoObjName = saver ().save (path.str ());
268
275
}
269
- saveBuffer (objBuf, ltoObjName);
276
+ if (ctx.arg .saveTemps )
277
+ saveBuffer (objBuf, ltoObjName);
278
+ ret.emplace_back (MemoryBufferRef (objBuf, ltoObjName));
270
279
}
271
280
272
281
if (!ctx.arg .ltoObjPath .empty ()) {
@@ -275,10 +284,6 @@ std::vector<StringRef> BitcodeCompiler::compile() {
275
284
saveBuffer (buf[i].second , ctx.arg .ltoObjPath + Twine (i));
276
285
}
277
286
278
- for (std::unique_ptr<MemoryBuffer> &file : files)
279
- if (file)
280
- ret.push_back (file->getBuffer ());
281
-
282
287
return ret;
283
288
}
284
289
0 commit comments