diff options
| author | Mehdi Amini <mehdi.amini@apple.com> | 2016-08-17 06:23:09 +0000 |
|---|---|---|
| committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-08-17 06:23:09 +0000 |
| commit | 970800e0c8c7cadcb36be28f6ea300108b9fc551 (patch) | |
| tree | b6123cbebf9891a70690b7c374c74066f09dd310 /llvm/tools/llvm-lto2 | |
| parent | 406aa22c6f9663c969e1951fdfac3b745ac63ceb (diff) | |
| download | bcm5719-llvm-970800e0c8c7cadcb36be28f6ea300108b9fc551.tar.gz bcm5719-llvm-970800e0c8c7cadcb36be28f6ea300108b9fc551.zip | |
[LTO] Introduce an Output class to wrap the output stream creation (NFC)
Summary:
While NFC for now, this will allow more flexibility on the client side
to hold state necessary to back up the stream.
Also when adding caching, this class will grow in complexity.
Note I blindly modified the gold-plugin as I can't compile it.
Reviewers: tejohnson
Subscribers: mehdi_amini, llvm-commits
Differential Revision: https://reviews.llvm.org/D23542
llvm-svn: 278907
Diffstat (limited to 'llvm/tools/llvm-lto2')
| -rw-r--r-- | llvm/tools/llvm-lto2/llvm-lto2.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp index b9300b93990..370c7086af7 100644 --- a/llvm/tools/llvm-lto2/llvm-lto2.cpp +++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp @@ -74,6 +74,22 @@ template <typename T> static T check(ErrorOr<T> E, std::string Msg) { return T(); } +namespace { +// Define the LTOOutput handling +class LTOOutput : public lto::NativeObjectOutput { + StringRef Path; + +public: + LTOOutput(StringRef Path) : Path(Path) {} + std::unique_ptr<raw_pwrite_stream> getStream() override { + std::error_code EC; + auto S = llvm::make_unique<raw_fd_ostream>(Path, EC, sys::fs::F_None); + check(EC, Path); + return std::move(S); + } +}; +} + int main(int argc, char **argv) { InitializeAllTargets(); InitializeAllTargetMCs(); @@ -156,13 +172,10 @@ int main(int argc, char **argv) { if (HasErrors) return 1; - auto AddStream = [&](size_t Task) { + auto AddOutput = [&](size_t Task) { std::string Path = OutputFilename + "." + utostr(Task); - std::error_code EC; - auto S = llvm::make_unique<raw_fd_ostream>(Path, EC, sys::fs::F_None); - check(EC, Path); - return S; + return llvm::make_unique<LTOOutput>(Path); }; - check(Lto.run(AddStream), "LTO::run failed"); + check(Lto.run(AddOutput), "LTO::run failed"); } |

