llvm.org GIT mirror llvm / d80408f
[ThinLTO] Move loading of cache entry to client Summary: Have the cache pass back the path to the cache entry when it is ready to be loaded, instead of a buffer. For gold-plugin we can simply pass this file back to gold directly, which avoids expensive writing of a separate tmp file. Ensure the cache entry is not deleted on cleanup by adjusting the setting of the IsTemporary flags. Moved the loading of the buffer into llvm-lto2 to maintain current behavior. Reviewers: mehdi_amini Subscribers: llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D23946 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279883 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 4 years ago
4 changed file(s) with 17 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
2121 namespace llvm {
2222 namespace lto {
2323 /// Type for client-supplied callback when a buffer is loaded from the cache.
24 typedef std::functionunique_ptr)> AddBufferFn;
24 typedef std::functionstring)> AddBufferFn;
2525
2626 /// Manage caching on the filesystem.
2727 ///
6464 /// Path to temporary file used to buffer output that will be committed to the
6565 /// cache entry when this object is destroyed
6666 SmallString<128> TempFilename;
67 /// User-supplied callback, called when the buffer is pulled out of the cache
67 /// User-supplied callback, used to provide path to cache entry
6868 /// (potentially after creating it).
6969 AddBufferFn AddBuffer;
7070
7676 /// Create a CacheObjectOutput: the client is supposed to create it in the
7777 /// callback supplied to LTO::run. The \p CacheDirectoryPath points to the
7878 /// directory on disk where to store the cache, and \p AddBuffer will be
79 /// called when the buffer is pulled out of the cache (potentially after
80 /// creating it).
79 /// called when the buffer is ready to be pulled out of the cache
80 /// (potentially after creating it).
8181 CacheObjectOutput(StringRef CacheDirectoryPath, AddBufferFn AddBuffer)
8282 : CacheDirectoryPath(CacheDirectoryPath), AddBuffer(AddBuffer) {}
8383
6363 // We commit the tempfile into the cache now, by moving it to EntryPath.
6464 commitEntry(TempFilename, EntryPath);
6565 }
66 // Load the entry from the cache now.
67 auto ReloadedBufferOrErr = MemoryBuffer::getFile(EntryPath);
68 if (auto EC = ReloadedBufferOrErr.getError())
69 report_fatal_error(Twine("Can't reload cached file '") + EntryPath + "': " +
70 EC.message() + "\n");
71
72 // Supply the resulting buffer to the user.
73 AddBuffer(std::move(*ReloadedBufferOrErr));
66 // Supply the cache path to the user.
67 AddBuffer(EntryPath.str());
7468 }
7569
7670 // Return an allocated stream for the output, or null in case of failure.
801801 auto &OutputName = Filenames[Task];
802802 getOutputFileName(Filename, /*TempOutFile=*/!SaveTemps, OutputName,
803803 MaxTasks > 1 ? Task : -1);
804 IsTemporary[Task] = !SaveTemps;
804 IsTemporary[Task] = !SaveTemps && options::cache_dir.empty();
805805 if (options::cache_dir.empty())
806806 return llvm::make_unique(OutputName);
807807
808808 return llvm::make_unique(
809 options::cache_dir, [OutputName](std::unique_ptr Buffer) {
810 *LTOOutput(OutputName).getStream() << Buffer->getBuffer();
811 });
809 options::cache_dir,
810 [&OutputName](std::string EntryPath) { OutputName = EntryPath; });
812811 };
813812
814813 check(Lto->run(AddOutput));
197197 return llvm::make_unique(std::move(Path));
198198
199199 return llvm::make_unique(
200 CacheDir, [Path](std::unique_ptr Buffer) {
201 *LTOOutput(Path).getStream() << Buffer->getBuffer();
200 CacheDir, [Path](std::string EntryPath) {
201 // Load the entry from the cache now.
202 auto ReloadedBufferOrErr = MemoryBuffer::getFile(EntryPath);
203 if (auto EC = ReloadedBufferOrErr.getError())
204 report_fatal_error(Twine("Can't reload cached file '") + EntryPath +
205 "': " + EC.message() + "\n");
206
207 *LTOOutput(Path).getStream() << (*ReloadedBufferOrErr)->getBuffer();
202208 });
203209 };
204210