From adc0e26bef6e2436363784d711732ec37e6a3db7 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Tue, 23 Aug 2016 21:30:12 +0000 Subject: [ThinLTO] Add caching to the new LTO API Add the ability to plug a cache on the LTO API. I tried to write such that a linker implementation can control the cache backend. This is intrusive and I'm not totally happy with it, but I can't figure out a better design right now. Differential Revision: https://reviews.llvm.org/D23599 llvm-svn: 279576 --- llvm/tools/llvm-lto2/llvm-lto2.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'llvm/tools') diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp index b2a83213bb8..722eec677ef 100644 --- a/llvm/tools/llvm-lto2/llvm-lto2.cpp +++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp @@ -16,6 +16,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/LTO/Caching.h" #include "llvm/LTO/LTO.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/TargetSelect.h" @@ -31,6 +32,9 @@ static cl::opt OutputFilename("o", cl::Required, cl::desc("Output filename"), cl::value_desc("filename")); +static cl::opt CacheDir("cache-dir", cl::desc("Cache Directory"), + cl::value_desc("directory")); + static cl::opt SaveTemps("save-temps", cl::desc("Save temporary files")); static cl::opt @@ -187,9 +191,16 @@ int main(int argc, char **argv) { if (HasErrors) return 1; - auto AddOutput = [&](size_t Task) { + auto AddOutput = + [&](size_t Task) -> std::unique_ptr { std::string Path = OutputFilename + "." + utostr(Task); - return llvm::make_unique(std::move(Path)); + if (CacheDir.empty()) + return llvm::make_unique(std::move(Path)); + + return llvm::make_unique( + CacheDir, [Path](std::unique_ptr Buffer) { + *LTOOutput(Path).getStream() << Buffer->getBuffer(); + }); }; check(Lto.run(AddOutput), "LTO::run failed"); -- cgit v1.2.3