aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYi Kong <yikong@google.com>2017-09-18 23:24:55 +0000
committerYi Kong <yikong@google.com>2017-09-18 23:24:55 +0000
commitbb4b4eef61d3377863a2fa7688db0d0c67fe5285 (patch)
treefc9ba8c656cc2e67691af8ad9f3864b962268689
parenta026eb5f503d5af41f65897235bdd421dd1adb68 (diff)
downloadllvm-bb4b4eef61d3377863a2fa7688db0d0c67fe5285.zip
llvm-bb4b4eef61d3377863a2fa7688db0d0c67fe5285.tar.gz
llvm-bb4b4eef61d3377863a2fa7688db0d0c67fe5285.tar.bz2
[ThinLTO/gold] Implement ThinLTO cache pruning support
Differential Revision: https://reviews.llvm.org/D37993 llvm-svn: 313592
-rw-r--r--llvm/test/tools/gold/X86/cache.ll36
-rw-r--r--llvm/tools/gold/gold-plugin.cpp11
2 files changed, 47 insertions, 0 deletions
diff --git a/llvm/test/tools/gold/X86/cache.ll b/llvm/test/tools/gold/X86/cache.ll
index 8d22a86..d507fc1 100644
--- a/llvm/test/tools/gold/X86/cache.ll
+++ b/llvm/test/tools/gold/X86/cache.ll
@@ -24,6 +24,42 @@
; RUN: ls %t.cache | count 2
+
+; Create two files that would be removed by cache pruning due to age.
+; We should only remove files matching the pattern "llvmcache-*".
+
+; RUN: touch -t 197001011200 %t.cache/llvmcache-foo %t.cache/foo
+; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
+; RUN: --plugin-opt=thinlto \
+; RUN: --plugin-opt=cache-dir=%t.cache \
+; RUN: --plugin-opt=cache-policy=prune_after=1h \
+; RUN: -o %t3.o %t2.o %t.o
+
+; Two cached objects, plus a timestamp file and "foo", minus the file we removed.
+; RUN: ls %t.cache | count 4
+
+
+; Create a file of size 64KB.
+; RUN: %python -c "print(' ' * 65536)" > %t.cache/llvmcache-foo
+
+; This should leave the file in place.
+; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
+; RUN: --plugin-opt=thinlto \
+; RUN: --plugin-opt=cache-dir=%t.cache \
+; RUN: --plugin-opt=cache-policy=cache_size_bytes=128k \
+; RUN: -o %t3.o %t2.o %t.o
+; RUN: ls %t.cache | count 5
+
+
+; This should remove it.
+; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
+; RUN: --plugin-opt=thinlto \
+; RUN: --plugin-opt=cache-dir=%t.cache \
+; RUN: --plugin-opt=cache-policy=cache_size_bytes=32k \
+; RUN: -o %t3.o %t2.o %t.o
+; RUN: ls %t.cache | count 4
+
+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 947fc2d..b0538b35 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -22,6 +22,7 @@
#include "llvm/LTO/Caching.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Object/Error.h"
+#include "llvm/Support/CachePruning.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
@@ -174,6 +175,8 @@ namespace options {
static std::string thinlto_object_suffix_replace;
// Optional path to a directory for caching ThinLTO objects.
static std::string cache_dir;
+ // Optional pruning policy for ThinLTO caches.
+ static std::string cache_policy;
// 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.
@@ -222,6 +225,8 @@ namespace options {
"thinlto-object-suffix-replace expects 'old;new' format");
} else if (opt.startswith("cache-dir=")) {
cache_dir = opt.substr(strlen("cache-dir="));
+ } else if (opt.startswith("cache-policy=")) {
+ cache_policy = opt.substr(strlen("cache-policy="));
} 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");
@@ -971,5 +976,11 @@ static ld_plugin_status cleanup_hook(void) {
EC.message().c_str());
}
+ // Prune cache
+ if (!options::cache_policy.empty()) {
+ CachePruningPolicy policy = check(parseCachePruningPolicy(options::cache_policy));
+ pruneCache(options::cache_dir, policy);
+ }
+
return LDPS_OK;
}