@@ -183,10 +183,11 @@ static void thinLTOCreateEmptyIndexFiles() {
183183
184184// Merge all the bitcode files we have seen, codegen the result
185185// and return the resulting objects.
186- std::vector<StringRef > BitcodeCompiler::compile () {
186+ SmallVector<InputFile *, 0 > BitcodeCompiler::compile () {
187187 unsigned maxTasks = ltoObj->getMaxTasks ();
188188 buf.resize (maxTasks);
189189 files.resize (maxTasks);
190+ filenames.resize (maxTasks);
190191
191192 // The --thinlto-cache-dir option specifies the path to a directory in which
192193 // to cache native object files for ThinLTO incremental builds. If a path was
@@ -233,15 +234,21 @@ std::vector<StringRef> BitcodeCompiler::compile() {
233234 if (!ctx.arg .thinLTOCacheDir .empty ())
234235 pruneCache (ctx.arg .thinLTOCacheDir , ctx.arg .thinLTOCachePolicy , files);
235236
236- std::vector<StringRef > ret;
237+ SmallVector<InputFile *, 0 > ret;
237238 for (unsigned i = 0 ; i != maxTasks; ++i) {
238239 StringRef objBuf = buf[i].second ;
239240 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+ }
240250 if (objBuf.empty ())
241251 continue ;
242- ret.emplace_back (objBuf.data (), objBuf.size ());
243- if (!ctx.arg .saveTemps )
244- continue ;
245252
246253 // If the input bitcode file is path/to/x.o and -o specifies a.out, the
247254 // corresponding native relocatable file path will look like:
@@ -266,7 +273,9 @@ std::vector<StringRef> BitcodeCompiler::compile() {
266273 sys::path::remove_dots (path, true );
267274 ltoObjName = saver ().save (path.str ());
268275 }
269- saveBuffer (objBuf, ltoObjName);
276+ if (ctx.arg .saveTemps )
277+ saveBuffer (objBuf, ltoObjName);
278+ ret.emplace_back (createObjectFile (MemoryBufferRef (objBuf, ltoObjName)));
270279 }
271280
272281 if (!ctx.arg .ltoObjPath .empty ()) {
@@ -275,10 +284,6 @@ std::vector<StringRef> BitcodeCompiler::compile() {
275284 saveBuffer (buf[i].second , ctx.arg .ltoObjPath + Twine (i));
276285 }
277286
278- for (std::unique_ptr<MemoryBuffer> &file : files)
279- if (file)
280- ret.push_back (file->getBuffer ());
281-
282287 return ret;
283288}
284289
0 commit comments