llvm.org GIT mirror llvm / 57b248a
[ThinLTO/gold] Add caching support to gold-plugin Summary: With support now in the new LTO API for caching (r279576), add optional ThinLTO caching in the gold-plugin. Reviewers: mehdi_amini Subscribers: mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D23836 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279631 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 4 years ago
3 changed file(s) with 41 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 target triple = "x86_64-unknown-linux-gnu"
1
2 define i32 @main() {
3 entry:
4 call void (...) @globalfunc()
5 ret i32 0
6 }
7
8 declare void @globalfunc(...)
0 ; RUN: opt -module-summary %s -o %t.o
1 ; RUN: opt -module-summary %p/Inputs/cache.ll -o %t2.o
2
3 ; Verify that enabling caching is working
4 ; RUN: rm -Rf %t.cache && mkdir %t.cache
5 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
6 ; RUN: --plugin-opt=thinlto \
7 ; RUN: --plugin-opt=cache-dir=%t.cache \
8 ; RUN: -o %t3.o %t2.o %t.o
9
10 ; RUN: ls %t.cache | count 2
11
12 target triple = "x86_64-unknown-linux-gnu"
13
14 define void @globalfunc() #0 {
15 entry:
16 ret void
17 }
1616 #include "llvm/Config/config.h" // plugin-api.h requires HAVE_STDINT_H
1717 #include "llvm/IR/Constants.h"
1818 #include "llvm/IR/DiagnosticPrinter.h"
19 #include "llvm/LTO/Caching.h"
1920 #include "llvm/LTO/LTO.h"
2021 #include "llvm/Support/CommandLine.h"
2122 #include "llvm/Support/ManagedStatic.h"
160161 // corresponding bitcode file, will use a path formed by replacing the
161162 // bitcode file's path prefix matching oldprefix with newprefix.
162163 static std::string thinlto_prefix_replace;
164 // Optional path to a directory for caching ThinLTO objects.
165 static std::string cache_dir;
163166 // Additional options to pass into the code generator.
164167 // Note: This array will contain all plugin options which are not claimed
165168 // as plugin exclusive to pass to the code generator.
198201 thinlto_prefix_replace = opt.substr(strlen("thinlto-prefix-replace="));
199202 if (thinlto_prefix_replace.find(";") == std::string::npos)
200203 message(LDPL_FATAL, "thinlto-prefix-replace expects 'old;new' format");
204 } else if (opt.startswith("cache-dir=")) {
205 cache_dir = opt.substr(strlen("cache-dir="));
201206 } else if (opt.size() == 2 && opt[0] == 'O') {
202207 if (opt[1] < '0' || opt[1] > '3')
203208 message(LDPL_FATAL, "Optimization level must be between 0 and 3");
791796 std::vector IsTemporary(MaxTasks);
792797 std::vector> Filenames(MaxTasks);
793798
794 auto AddOutput = [&](size_t Task) {
799 auto AddOutput =
800 [&](size_t Task) -> std::unique_ptr {
795801 auto &OutputName = Filenames[Task];
796802 getOutputFileName(Filename, /*TempOutFile=*/!SaveTemps, OutputName,
797803 MaxTasks > 1 ? Task : -1);
798804 IsTemporary[Task] = !SaveTemps;
799 return llvm::make_unique(OutputName);
805 if (options::cache_dir.empty())
806 return llvm::make_unique(OutputName);
807
808 return llvm::make_unique(
809 options::cache_dir, [OutputName](std::unique_ptr Buffer) {
810 *LTOOutput(OutputName).getStream() << Buffer->getBuffer();
811 });
800812 };
801813
802814 check(Lto->run(AddOutput));