2121#include " llvm/LTO/LTO.h"
2222#include " llvm/Object/Archive.h"
2323#include " llvm/Support/FileSystem.h"
24- #include " llvm/Support/ManagedStatic.h"
2524#include " llvm/Support/MemoryBufferRef.h"
2625#include " llvm/Support/Path.h"
2726#include " llvm/Support/Process.h"
2827#include " llvm/Support/Signals.h"
2928#include " llvm/Support/TimeProfiler.h"
3029#include " llvm/Support/raw_ostream.h"
3130
32- #include < iostream>
3331#include < string>
3432
3533using namespace llvm ;
@@ -135,25 +133,29 @@ lto::DTLTO::addInput(std::unique_ptr<lto::InputFile> InputPtr) {
135133 StringRef ModuleId = Input->getName ();
136134 StringRef ArchivePath = Input->getArchivePath ();
137135
138- // Only process archive members.
139- if (ArchivePath.empty ())
136+ // In most cases, the module ID already points to an individual bitcode file
137+ // on disk, so no further preparation for distribution is required.
138+ if (ArchivePath.empty () && !Input->isFatLTOObject ())
140139 return Input;
141140
142141 SmallString<64 > NewModuleId;
143142 BitcodeModule &BM = Input->getPrimaryBitcodeModule ();
144143
145- // Check if the archive is a thin archive.
146- Expected<bool > IsThin = isThinArchive (ArchivePath);
147- if (!IsThin)
148- return IsThin.takeError ();
144+ // For a member of a thin archive that is not a FatLTO object, there is an
145+ // existing file on disk that can be used, so we can avoid having to
146+ // materialize.
147+ Expected<bool > UseThinMember =
148+ Input->isFatLTOObject () ? false : isThinArchive (ArchivePath);
149+ if (!UseThinMember)
150+ return UseThinMember.takeError ();
149151
150- if (*IsThin ) {
152+ if (*UseThinMember ) {
151153 // For thin archives, use the path to the actual file.
152154 NewModuleId =
153155 computeThinArchiveMemberPath (ArchivePath, Input->getMemberName ());
154156 } else {
155- // For regular archives, generate a unique name.
156- Input->memberOfArchive (true );
157+ // For regular archives and FatLTO objects , generate a unique name.
158+ Input->setSerializeForDistribution (true );
157159
158160 // Create unique identifier using process ID and sequence number.
159161 std::string PID = utohexstr (sys::Process::getProcessId ());
@@ -175,8 +177,8 @@ lto::DTLTO::addInput(std::unique_ptr<lto::InputFile> InputPtr) {
175177// previously terminated linker process and can be safely overwritten.
176178Error lto::DTLTO::saveInputArchiveMember (lto::InputFile *Input) {
177179 StringRef ModuleId = Input->getName ();
178- if (Input->isMemberOfArchive ()) {
179- TimeTraceScope TimeScope (" Save input archive member for DTLTO" , ModuleId);
180+ if (Input->getSerializeForDistribution ()) {
181+ TimeTraceScope TimeScope (" Serialize bitcode input for DTLTO" , ModuleId);
180182 // Cleanup this file on abnormal process exit.
181183 if (!SaveTemps)
182184 llvm::sys::RemoveFileOnSignal (ModuleId);
@@ -216,7 +218,7 @@ void lto::DTLTO::cleanup() {
216218 if (!SaveTemps) {
217219 TimeTraceScope TimeScope (" Remove temporary inputs for DTLTO" );
218220 for (auto &Input : InputFiles) {
219- if (!Input->isMemberOfArchive ())
221+ if (!Input->getSerializeForDistribution ())
220222 continue ;
221223 std::error_code EC =
222224 sys::fs::remove (Input->getName (), /* IgnoreNonExisting=*/ true );
0 commit comments