summaryrefslogtreecommitdiffstats
path: root/llvm/tools/gold/gold-plugin.cpp
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
commit80186a57d66c4374aea9118045d8489dcdb6071b (patch)
tree757a092ded2644d8663928ae9e30c04f29bb8723 /llvm/tools/gold/gold-plugin.cpp
parent6951707943c771422c4e22ee8b7cd653642272ce (diff)
downloadbcm5719-llvm-80186a57d66c4374aea9118045d8489dcdb6071b.tar.gz
bcm5719-llvm-80186a57d66c4374aea9118045d8489dcdb6071b.zip
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 llvm-svn: 282299
Diffstat (limited to 'llvm/tools/gold/gold-plugin.cpp')
-rw-r--r--llvm/tools/gold/gold-plugin.cpp48
1 files changed, 18 insertions, 30 deletions
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 34696ba16a9..9bdc7abc5b4 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/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)
OpenPOWER on IntegriCloud