summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2017-03-01 23:00:10 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2017-03-01 23:00:10 +0000
commite02775f068b3011237edfb4e6e6a347afe131756 (patch)
treecbf1b75475c75f2b0aae262765d573ee981d291a
parent28c2c0e311b3055062213388f967fc75c72976dc (diff)
downloadbcm5719-llvm-e02775f068b3011237edfb4e6e6a347afe131756.tar.gz
bcm5719-llvm-e02775f068b3011237edfb4e6e6a347afe131756.zip
ELF: Add ThinLTO caching support.
This patch adds an option named --thinlto-cache-dir, which specifies the path to a directory in which to cache native object files for ThinLTO incremental builds. Differential Revision: https://reviews.llvm.org/D30509 llvm-svn: 296702
-rw-r--r--lld/ELF/Config.h1
-rw-r--r--lld/ELF/Driver.cpp1
-rw-r--r--lld/ELF/LTO.cpp29
-rw-r--r--lld/ELF/LTO.h1
-rw-r--r--lld/ELF/Options.td2
-rw-r--r--lld/test/ELF/lto/Inputs/cache.ll10
-rw-r--r--lld/test/ELF/lto/cache.ll15
7 files changed, 54 insertions, 5 deletions
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index a47d7cda4af..91d4eb7afc0 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -86,6 +86,7 @@ struct Configuration {
llvm::StringRef OptRemarksFilename;
llvm::StringRef SoName;
llvm::StringRef Sysroot;
+ llvm::StringRef ThinLTOCacheDir;
std::string RPath;
std::vector<VersionDefinition> VersionDefinitions;
std::vector<llvm::StringRef> AuxiliaryList;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 72bb10984ef..97fd5308321 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -583,6 +583,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->Sysroot = getString(Args, OPT_sysroot);
Config->Target1Rel = getArg(Args, OPT_target1_rel, OPT_target1_abs, false);
Config->Target2 = getTarget2(Args);
+ Config->ThinLTOCacheDir = getString(Args, OPT_thinlto_cache_dir);
Config->ThinLTOJobs = getInteger(Args, OPT_thinlto_jobs, -1u);
Config->Threads = getArg(Args, OPT_threads, OPT_no_threads, true);
Config->Trace = Args.hasArg(OPT_trace);
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index eec62e96bb1..9e271a2c6ed 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -18,6 +18,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/DiagnosticPrinter.h"
+#include "llvm/LTO/Caching.h"
#include "llvm/LTO/Config.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Object/SymbolicFile.h"
@@ -142,11 +143,24 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
std::vector<InputFile *> Ret;
unsigned MaxTasks = LTOObj->getMaxTasks();
Buff.resize(MaxTasks);
-
- checkError(LTOObj->run([&](size_t Task) {
- return llvm::make_unique<lto::NativeObjectStream>(
- llvm::make_unique<raw_svector_ostream>(Buff[Task]));
- }));
+ Files.resize(MaxTasks);
+
+ // The --thinlto-cache-dir option specifies the path to a directory in which
+ // to cache native object files for ThinLTO incremental builds. If a path was
+ // specified, configure LTO to use it as the cache directory.
+ lto::NativeObjectCache Cache;
+ if (!Config->ThinLTOCacheDir.empty())
+ Cache = lto::localCache(Config->ThinLTOCacheDir,
+ [&](size_t Task, StringRef Path) {
+ Files[Task] = check(MemoryBuffer::getFile(Path));
+ });
+
+ checkError(LTOObj->run(
+ [&](size_t Task) {
+ return llvm::make_unique<lto::NativeObjectStream>(
+ llvm::make_unique<raw_svector_ostream>(Buff[Task]));
+ },
+ Cache));
for (unsigned I = 0; I != MaxTasks; ++I) {
if (Buff[I].empty())
@@ -160,5 +174,10 @@ std::vector<InputFile *> BitcodeCompiler::compile() {
InputFile *Obj = createObjectFile(MemoryBufferRef(Buff[I], "lto.tmp"));
Ret.push_back(Obj);
}
+
+ for (std::unique_ptr<MemoryBuffer> &File : Files)
+ if (File)
+ Ret.push_back(createObjectFile(*File));
+
return Ret;
}
diff --git a/lld/ELF/LTO.h b/lld/ELF/LTO.h
index b3d734f2d38..28afa0e83ad 100644
--- a/lld/ELF/LTO.h
+++ b/lld/ELF/LTO.h
@@ -49,6 +49,7 @@ public:
private:
std::unique_ptr<llvm::lto::LTO> LTOObj;
std::vector<SmallString<0>> Buff;
+ std::vector<std::unique_ptr<MemoryBuffer>> Files;
};
}
}
diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index 508ab320533..c49306dd1fc 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -392,4 +392,6 @@ def opt_remarks_filename: S<"opt-remarks-filename">,
def opt_remarks_with_hotness: F<"opt-remarks-with-hotness">,
HelpText<"Include hotness informations in the optimization remarks file">;
def save_temps: F<"save-temps">;
+def thinlto_cache_dir: J<"thinlto-cache-dir=">,
+ HelpText<"Path to ThinLTO cached object file directory">;
def thinlto_jobs: J<"thinlto-jobs=">, HelpText<"Number of ThinLTO jobs">;
diff --git a/lld/test/ELF/lto/Inputs/cache.ll b/lld/test/ELF/lto/Inputs/cache.ll
new file mode 100644
index 00000000000..4abbb457137
--- /dev/null
+++ b/lld/test/ELF/lto/Inputs/cache.ll
@@ -0,0 +1,10 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @main() {
+entry:
+ call void (...) @globalfunc()
+ ret i32 0
+}
+
+declare void @globalfunc(...)
diff --git a/lld/test/ELF/lto/cache.ll b/lld/test/ELF/lto/cache.ll
new file mode 100644
index 00000000000..74b1d197f19
--- /dev/null
+++ b/lld/test/ELF/lto/cache.ll
@@ -0,0 +1,15 @@
+; 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 && mkdir %t.cache
+; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3.o %t2.o %t.o
+
+; RUN: ls %t.cache | count 2
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @globalfunc() #0 {
+entry:
+ ret void
+}
OpenPOWER on IntegriCloud