[PATCH] D23836: [ThinLTO/gold] Add caching support to gold-plugin
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 24 08:19:56 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279631: [ThinLTO/gold] Add caching support to gold-plugin (authored by tejohnson).
Changed prior to commit:
https://reviews.llvm.org/D23836?vs=69109&id=69123#toc
Repository:
rL LLVM
https://reviews.llvm.org/D23836
Files:
llvm/trunk/test/tools/gold/X86/Inputs/cache.ll
llvm/trunk/test/tools/gold/X86/cache.ll
llvm/trunk/tools/gold/gold-plugin.cpp
Index: llvm/trunk/test/tools/gold/X86/Inputs/cache.ll
===================================================================
--- llvm/trunk/test/tools/gold/X86/Inputs/cache.ll
+++ llvm/trunk/test/tools/gold/X86/Inputs/cache.ll
@@ -0,0 +1,9 @@
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @main() {
+entry:
+ call void (...) @globalfunc()
+ ret i32 0
+}
+
+declare void @globalfunc(...)
Index: llvm/trunk/test/tools/gold/X86/cache.ll
===================================================================
--- llvm/trunk/test/tools/gold/X86/cache.ll
+++ llvm/trunk/test/tools/gold/X86/cache.ll
@@ -0,0 +1,18 @@
+; RUN: opt -module-summary %s -o %t.o
+; RUN: opt -module-summary %p/Inputs/cache.ll -o %t2.o
+
+; Verify that enabling caching is working
+; RUN: rm -Rf %t.cache && mkdir %t.cache
+; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
+; RUN: --plugin-opt=thinlto \
+; RUN: --plugin-opt=cache-dir=%t.cache \
+; RUN: -o %t3.o %t2.o %t.o
+
+; RUN: ls %t.cache | count 2
+
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @globalfunc() #0 {
+entry:
+ ret void
+}
Index: llvm/trunk/tools/gold/gold-plugin.cpp
===================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp
+++ llvm/trunk/tools/gold/gold-plugin.cpp
@@ -17,6 +17,7 @@
#include "llvm/Config/config.h" // plugin-api.h requires HAVE_STDINT_H
#include "llvm/IR/Constants.h"
#include "llvm/IR/DiagnosticPrinter.h"
+#include "llvm/LTO/Caching.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
@@ -161,6 +162,8 @@
// corresponding bitcode file, will use a path formed by replacing the
// bitcode file's path prefix matching oldprefix with newprefix.
static std::string thinlto_prefix_replace;
+ // Optional path to a directory for caching ThinLTO objects.
+ static std::string cache_dir;
// Additional options to pass into the code generator.
// Note: This array will contain all plugin options which are not claimed
// as plugin exclusive to pass to the code generator.
@@ -199,6 +202,8 @@
thinlto_prefix_replace = opt.substr(strlen("thinlto-prefix-replace="));
if (thinlto_prefix_replace.find(";") == std::string::npos)
message(LDPL_FATAL, "thinlto-prefix-replace expects 'old;new' format");
+ } else if (opt.startswith("cache-dir=")) {
+ cache_dir = opt.substr(strlen("cache-dir="));
} else if (opt.size() == 2 && opt[0] == 'O') {
if (opt[1] < '0' || opt[1] > '3')
message(LDPL_FATAL, "Optimization level must be between 0 and 3");
@@ -792,12 +797,19 @@
std::vector<uintptr_t> IsTemporary(MaxTasks);
std::vector<SmallString<128>> Filenames(MaxTasks);
- auto AddOutput = [&](size_t Task) {
+ auto AddOutput =
+ [&](size_t Task) -> std::unique_ptr<lto::NativeObjectOutput> {
auto &OutputName = Filenames[Task];
getOutputFileName(Filename, /*TempOutFile=*/!SaveTemps, OutputName,
MaxTasks > 1 ? Task : -1);
IsTemporary[Task] = !SaveTemps;
- return llvm::make_unique<LTOOutput>(OutputName);
+ 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();
+ });
};
check(Lto->run(AddOutput));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23836.69123.patch
Type: text/x-patch
Size: 3482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160824/d9caa691/attachment.bin>
More information about the llvm-commits
mailing list