[llvm] r279883 - [ThinLTO] Move loading of cache entry to client

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 26 16:29:15 PDT 2016


Author: tejohnson
Date: Fri Aug 26 18:29:14 2016
New Revision: 279883

URL: http://llvm.org/viewvc/llvm-project?rev=279883&view=rev
Log:
[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

Modified:
    llvm/trunk/include/llvm/LTO/Caching.h
    llvm/trunk/lib/LTO/Caching.cpp
    llvm/trunk/tools/gold/gold-plugin.cpp
    llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp

Modified: llvm/trunk/include/llvm/LTO/Caching.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/Caching.h?rev=279883&r1=279882&r2=279883&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/Caching.h (original)
+++ llvm/trunk/include/llvm/LTO/Caching.h Fri Aug 26 18:29:14 2016
@@ -22,7 +22,7 @@
 namespace llvm {
 namespace lto {
 /// Type for client-supplied callback when a buffer is loaded from the cache.
-typedef std::function<void(std::unique_ptr<MemoryBuffer>)> AddBufferFn;
+typedef std::function<void(std::string)> AddBufferFn;
 
 /// Manage caching on the filesystem.
 ///
@@ -65,7 +65,7 @@ class CacheObjectOutput : public NativeO
   /// Path to temporary file used to buffer output that will be committed to the
   /// cache entry when this object is destroyed
   SmallString<128> TempFilename;
-  /// User-supplied callback, called when the buffer is pulled out of the cache
+  /// User-supplied callback, used to provide path to cache entry
   /// (potentially after creating it).
   AddBufferFn AddBuffer;
 
@@ -77,8 +77,8 @@ public:
   /// Create a CacheObjectOutput: the client is supposed to create it in the
   /// callback supplied to LTO::run. The \p CacheDirectoryPath points to the
   /// directory on disk where to store the cache, and \p AddBuffer will be
-  /// called when the buffer is pulled out of the cache (potentially after
-  /// creating it).
+  /// called when the buffer is ready to be pulled out of the cache
+  /// (potentially after creating it).
   CacheObjectOutput(StringRef CacheDirectoryPath, AddBufferFn AddBuffer)
       : CacheDirectoryPath(CacheDirectoryPath), AddBuffer(AddBuffer) {}
 

Modified: llvm/trunk/lib/LTO/Caching.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/Caching.cpp?rev=279883&r1=279882&r2=279883&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/Caching.cpp (original)
+++ llvm/trunk/lib/LTO/Caching.cpp Fri Aug 26 18:29:14 2016
@@ -64,14 +64,8 @@ CacheObjectOutput::~CacheObjectOutput()
       // We commit the tempfile into the cache now, by moving it to EntryPath.
       commitEntry(TempFilename, EntryPath);
   }
-  // Load the entry from the cache now.
-  auto ReloadedBufferOrErr = MemoryBuffer::getFile(EntryPath);
-  if (auto EC = ReloadedBufferOrErr.getError())
-    report_fatal_error(Twine("Can't reload cached file '") + EntryPath + "': " +
-                       EC.message() + "\n");
-
-  // Supply the resulting buffer to the user.
-  AddBuffer(std::move(*ReloadedBufferOrErr));
+  // Supply the cache path to the user.
+  AddBuffer(EntryPath.str());
 }
 
 // Return an allocated stream for the output, or null in case of failure.

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=279883&r1=279882&r2=279883&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Fri Aug 26 18:29:14 2016
@@ -802,14 +802,13 @@ static ld_plugin_status allSymbolsReadHo
     auto &OutputName = Filenames[Task];
     getOutputFileName(Filename, /*TempOutFile=*/!SaveTemps, OutputName,
                       MaxTasks > 1 ? Task : -1);
-    IsTemporary[Task] = !SaveTemps;
+    IsTemporary[Task] = !SaveTemps && options::cache_dir.empty();
     if (options::cache_dir.empty())
       return llvm::make_unique<LTOOutput>(OutputName);
 
     return llvm::make_unique<CacheObjectOutput>(
-        options::cache_dir, [OutputName](std::unique_ptr<MemoryBuffer> Buffer) {
-          *LTOOutput(OutputName).getStream() << Buffer->getBuffer();
-        });
+        options::cache_dir,
+        [&OutputName](std::string EntryPath) { OutputName = EntryPath; });
   };
 
   check(Lto->run(AddOutput));

Modified: llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp?rev=279883&r1=279882&r2=279883&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp (original)
+++ llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp Fri Aug 26 18:29:14 2016
@@ -198,8 +198,14 @@ int main(int argc, char **argv) {
       return llvm::make_unique<LTOOutput>(std::move(Path));
 
     return llvm::make_unique<CacheObjectOutput>(
-        CacheDir, [Path](std::unique_ptr<MemoryBuffer> Buffer) {
-          *LTOOutput(Path).getStream() << Buffer->getBuffer();
+        CacheDir, [Path](std::string EntryPath) {
+          // Load the entry from the cache now.
+          auto ReloadedBufferOrErr = MemoryBuffer::getFile(EntryPath);
+          if (auto EC = ReloadedBufferOrErr.getError())
+            report_fatal_error(Twine("Can't reload cached file '") + EntryPath +
+                               "': " + EC.message() + "\n");
+
+          *LTOOutput(Path).getStream() << (*ReloadedBufferOrErr)->getBuffer();
         });
   };
 




More information about the llvm-commits mailing list