[lld] r298036 - ELF: Add cache pruning support.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 16 19:24:16 PDT 2017


Author: pcc
Date: Thu Mar 16 21:24:16 2017
New Revision: 298036

URL: http://llvm.org/viewvc/llvm-project?rev=298036&view=rev
Log:
ELF: Add cache pruning support.

This patch causes us to use pruneCache() to prune the ThinLTO cache after
completing LTO. A new flag --thinlto-cache-policy allows users to configure
the policy.

Differential Revision: https://reviews.llvm.org/D31021

Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/LTO.cpp
    lld/trunk/ELF/Options.td
    lld/trunk/test/ELF/lto/cache.ll

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=298036&r1=298035&r2=298036&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Thu Mar 16 21:24:16 2017
@@ -13,6 +13,7 @@
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/Support/CachePruning.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ELF.h"
 
@@ -72,6 +73,7 @@ struct VersionDefinition {
 struct Configuration {
   InputFile *FirstElf = nullptr;
   uint8_t OSABI = 0;
+  llvm::CachePruningPolicy ThinLTOCachePolicy;
   llvm::StringMap<uint64_t> SectionStartMap;
   llvm::StringRef DynamicLinker;
   llvm::StringRef Entry;

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=298036&r1=298035&r2=298036&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Mar 16 21:24:16 2017
@@ -585,6 +585,9 @@ void LinkerDriver::readConfigs(opt::Inpu
   Config->Target1Rel = getArg(Args, OPT_target1_rel, OPT_target1_abs, false);
   Config->Target2 = getTarget2(Args);
   Config->ThinLTOCacheDir = getString(Args, OPT_thinlto_cache_dir);
+  Config->ThinLTOCachePolicy =
+      check(parseCachePruningPolicy(getString(Args, OPT_thinlto_cache_policy)),
+            "--thinlto-cache-policy: invalid cache policy");
   Config->ThinLTOJobs = getInteger(Args, OPT_thinlto_jobs, -1u);
   Config->Threads = getArg(Args, OPT_threads, OPT_no_threads, true);
   Config->Trace = Args.hasArg(OPT_trace);

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=298036&r1=298035&r2=298036&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Thu Mar 16 21:24:16 2017
@@ -163,6 +163,9 @@ std::vector<InputFile *> BitcodeCompiler
       },
       Cache));
 
+  if (!Config->ThinLTOCacheDir.empty())
+    pruneCache(Config->ThinLTOCacheDir, Config->ThinLTOCachePolicy);
+
   for (unsigned I = 0; I != MaxTasks; ++I) {
     if (Buff[I].empty())
       continue;

Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=298036&r1=298035&r2=298036&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Thu Mar 16 21:24:16 2017
@@ -394,4 +394,6 @@ def opt_remarks_with_hotness: Flag<["--"
 def save_temps: F<"save-temps">;
 def thinlto_cache_dir: J<"thinlto-cache-dir=">,
   HelpText<"Path to ThinLTO cached object file directory">;
+def thinlto_cache_policy: S<"thinlto-cache-policy">,
+  HelpText<"Pruning policy for the ThinLTO cache">;
 def thinlto_jobs: J<"thinlto-jobs=">, HelpText<"Number of ThinLTO jobs">;

Modified: lld/trunk/test/ELF/lto/cache.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/cache.ll?rev=298036&r1=298035&r2=298036&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/cache.ll (original)
+++ lld/trunk/test/ELF/lto/cache.ll Thu Mar 16 21:24:16 2017
@@ -3,10 +3,13 @@
 ; RUN: opt -module-hash -module-summary %s -o %t.o
 ; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o %t2.o
 
-; RUN: rm -Rf %t.cache
-; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o
+; RUN: rm -Rf %t.cache && mkdir %t.cache
+; Create a file that will be removed by cache pruning due to age.
+; RUN: touch -d 1970-01-01 %t.cache/foo
+; RUN: ld.lld --thinlto-cache-dir=%t.cache --thinlto-cache-policy prune_after=1h -o %t3 %t2.o %t.o
 
-; RUN: ls %t.cache | count 2
+; Two cached objects, plus a timestamp file, minus the file we removed.
+; RUN: ls %t.cache | count 3
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"




More information about the llvm-commits mailing list