summaryrefslogtreecommitdiffstats
path: root/tools/gold
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-09-23 21:33:43 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-09-23 21:33:43 +0000
commit91d99c6edff66edebc3d390abf99fe05efb2a5e0 (patch)
treea7273185ceaf73a5f07786e3c486f54c2dff14f4 /tools/gold
parentdc7e3f0651cc366f0f1a748c2330f0b99dd9e2e6 (diff)
LTO: Simplify caching interface.
The NativeObjectOutput class has a design problem: it mixes up the caching policy with the interface for output streams, which makes the client-side code hard to follow and would for example make it harder to replace the cache implementation in an arbitrary client. This change separates the two aspects by moving the caching policy to a separate field in Config, replacing NativeObjectOutput with a NativeObjectStream class which only deals with streams and does not need to be overridden by most clients and introducing an AddFile callback for adding files (e.g. from the cache) to the link. Differential Revision: https://reviews.llvm.org/D24622 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282299 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/gold')
-rw-r--r--tools/gold/gold-plugin.cpp48
1 files changed, 18 insertions, 30 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp
index 34696ba16a97..9bdc7abc5b4f 100644
--- a/tools/gold/gold-plugin.cpp
+++ b/tools/gold/gold-plugin.cpp
@@ -675,24 +675,6 @@ static void getThinLTOOldAndNewPrefix(std::string &OldPrefix,
NewPrefix = Split.second.str();
}
-namespace {
-// Define the LTOOutput handling
-class LTOOutput : public lto::NativeObjectOutput {
- StringRef Path;
-
-public:
- LTOOutput(StringRef Path) : Path(Path) {}
- // Open the filename \p Path and allocate a stream.
- std::unique_ptr<raw_pwrite_stream> getStream() override {
- int FD;
- std::error_code EC = sys::fs::openFileForWrite(Path, FD, sys::fs::F_None);
- if (EC)
- message(LDPL_FATAL, "Could not open file: %s", EC.message().c_str());
- return llvm::make_unique<llvm::raw_fd_ostream>(FD, true);
- }
-};
-}
-
static std::unique_ptr<LTO> createLTO() {
Config Conf;
ThinBackend Backend;
@@ -831,21 +813,27 @@ static ld_plugin_status allSymbolsReadHook() {
std::vector<uintptr_t> IsTemporary(MaxTasks);
std::vector<SmallString<128>> Filenames(MaxTasks);
- auto AddOutput =
- [&](size_t Task) -> std::unique_ptr<lto::NativeObjectOutput> {
- auto &OutputName = Filenames[Task];
- getOutputFileName(Filename, /*TempOutFile=*/!SaveTemps, OutputName,
+ auto AddStream =
+ [&](size_t Task) -> std::unique_ptr<lto::NativeObjectStream> {
+ IsTemporary[Task] = !SaveTemps;
+ getOutputFileName(Filename, /*TempOutFile=*/!SaveTemps, Filenames[Task],
MaxTasks > 1 ? Task : -1);
- IsTemporary[Task] = !SaveTemps && options::cache_dir.empty();
- if (options::cache_dir.empty())
- return llvm::make_unique<LTOOutput>(OutputName);
-
- return llvm::make_unique<CacheObjectOutput>(
- options::cache_dir,
- [&OutputName](std::string EntryPath) { OutputName = EntryPath; });
+ int FD;
+ std::error_code EC =
+ sys::fs::openFileForWrite(Filenames[Task], FD, sys::fs::F_None);
+ if (EC)
+ message(LDPL_FATAL, "Could not open file: %s", EC.message().c_str());
+ return llvm::make_unique<lto::NativeObjectStream>(
+ llvm::make_unique<llvm::raw_fd_ostream>(FD, true));
};
- check(Lto->run(AddOutput));
+ auto AddFile = [&](size_t Task, StringRef Path) { Filenames[Task] = Path; };
+
+ NativeObjectCache Cache;
+ if (!options::cache_dir.empty())
+ Cache = localCache(options::cache_dir, AddFile);
+
+ check(Lto->run(AddStream, Cache));
if (options::TheOutputType == options::OT_DISABLE ||
options::TheOutputType == options::OT_BC_ONLY)