diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-05-16 19:11:59 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-05-16 19:11:59 +0000 |
commit | 001bb4155621f9e992ee95d6ea092d3b3adbe4f6 (patch) | |
tree | 44377d0a177409d7aa37912f9ee73bb10468aabe /llvm/lib/LTO/ThinLTOCodeGenerator.cpp | |
parent | 804749c942fa15d6f0f0e6fde2ad7407e8bedb8b (diff) | |
download | bcm5719-llvm-001bb4155621f9e992ee95d6ea092d3b3adbe4f6.tar.gz bcm5719-llvm-001bb4155621f9e992ee95d6ea092d3b3adbe4f6.zip |
ThinLTO caching: reload cached file with mmap and drop heap-allocated memory buffer
This is reducing pressure on the OS memory system, and is NFC
when not using a cache.
I measure a 10x memory consumption reduction when linking opt
with full debug info.
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 269682
Diffstat (limited to 'llvm/lib/LTO/ThinLTOCodeGenerator.cpp')
-rw-r--r-- | llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index 2867c730125..a91cf4f8d4a 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -484,9 +484,10 @@ public: } // Cache the Produced object file - void write(MemoryBufferRef OutputBuffer) { + std::unique_ptr<MemoryBuffer> + write(std::unique_ptr<MemoryBuffer> OutputBuffer) { if (EntryPath.empty()) - return; + return OutputBuffer; // Write to a temporary to avoid race condition SmallString<128> TempFilename; @@ -499,7 +500,7 @@ public: } { raw_fd_ostream OS(TempFD, /* ShouldClose */ true); - OS << OutputBuffer.getBuffer(); + OS << OutputBuffer->getBuffer(); } // Rename to final destination (hopefully race condition won't matter here) EC = sys::fs::rename(TempFilename, EntryPath); @@ -509,8 +510,16 @@ public: if (EC) report_fatal_error(Twine("Failed to open ") + EntryPath + " to save cached entry\n"); - OS << OutputBuffer.getBuffer(); + OS << OutputBuffer->getBuffer(); + } + auto ReloadedBufferOrErr = MemoryBuffer::getFile(EntryPath); + if (auto EC = ReloadedBufferOrErr.getError()) { + // FIXME diagnose + errs() << "error: can't reload cached file '" << EntryPath + << "': " << EC.message() << "\n"; + return OutputBuffer; } + return std::move(*ReloadedBufferOrErr); } }; @@ -943,7 +952,7 @@ void ThinLTOCodeGenerator::run() { ExportList, GUIDPreservedSymbols, ResolvedODR, CacheOptions, DisableCodeGen, SaveTempsDir, count); - CacheEntry.write(*OutputBuffer); + OutputBuffer = CacheEntry.write(std::move(OutputBuffer)); ProducedBinaries[count] = std::move(OutputBuffer); }, count); count++; |