Index: llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h =================================================================== --- llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h +++ llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h @@ -299,7 +299,8 @@ * SavedObjectsDirectoryPath. */ std::string writeGeneratedObject(int count, StringRef CacheEntryPath, - const MemoryBuffer &OutputBuffer); + const MemoryBuffer &OutputBuffer, + StringRef objectFileName = ""); /**@}*/ private: Index: llvm/lib/LTO/ThinLTOCodeGenerator.cpp =================================================================== --- llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -964,11 +964,16 @@ /// Returns the path to the generated file in SavedObjectsDirectoryPath. std::string ThinLTOCodeGenerator::writeGeneratedObject(int count, StringRef CacheEntryPath, - const MemoryBuffer &OutputBuffer) { + const MemoryBuffer &OutputBuffer, + StringRef objectFileName) { auto ArchName = TMBuilder.TheTriple.getArchName(); SmallString<128> OutputPath(SavedObjectsDirectoryPath); - llvm::sys::path::append(OutputPath, - Twine(count) + "." + ArchName + ".thinlto.o"); + if (objectFileName.empty()) + llvm::sys::path::append(OutputPath, + Twine(count) + "." + ArchName + ".thinlto.o"); + else + llvm::sys::path::append(OutputPath, Twine(count) + "." + ArchName + "." + + objectFileName + ".thinlto.o"); OutputPath.c_str(); // Ensure the string is null terminated. if (sys::fs::exists(OutputPath)) sys::fs::remove(OutputPath); @@ -1164,6 +1169,10 @@ auto &Mod = Modules[IndexCount]; Pool.async([&](int count) { auto ModuleIdentifier = Mod->getName(); + + StringRef moduleIdentifierFileName = + llvm::sys::path::filename(ModuleIdentifier); + auto &ExportList = ExportLists[ModuleIdentifier]; auto &DefinedGVSummaries = ModuleToDefinedGVSummaries[ModuleIdentifier]; @@ -1188,7 +1197,8 @@ ProducedBinaries[count] = std::move(ErrOrBuffer.get()); else ProducedBinaryFiles[count] = writeGeneratedObject( - count, CacheEntryPath, *ErrOrBuffer.get()); + count, CacheEntryPath, *ErrOrBuffer.get(), + moduleIdentifierFileName); return; } } @@ -1246,7 +1256,7 @@ return; } ProducedBinaryFiles[count] = writeGeneratedObject( - count, CacheEntryPath, *OutputBuffer); + count, CacheEntryPath, *OutputBuffer, moduleIdentifierFileName); }, IndexCount); } } Index: llvm/test/ThinLTO/X86/save_objects.ll =================================================================== --- llvm/test/ThinLTO/X86/save_objects.ll +++ llvm/test/ThinLTO/X86/save_objects.ll @@ -21,7 +21,7 @@ ; RUN: ls %t.cache | count 3 ; Check the name of object in directory has arch name included. -; RUN: ls %t.thin.out | grep x86_64.thinlto.o | count 2 +; RUN: ls %t.thin.out | grep "x86_64\..*thinlto\.o" | count 2 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"