aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO/LTO.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2019-04-19 12:36:41 +0000
committerFlorian Hahn <flo@fhahn.com>2019-04-19 12:36:41 +0000
commitb340497f7640344ed6c085645b450f9e02c8b20d (patch)
treeb4a3ad29a171f6c4fefba8c5b5a125276a79fca0 /llvm/lib/LTO/LTO.cpp
parentb4788b26e2be3291c3b900b0b5b2a2dd2d847d06 (diff)
downloadllvm-b340497f7640344ed6c085645b450f9e02c8b20d.zip
llvm-b340497f7640344ed6c085645b450f9e02c8b20d.tar.gz
llvm-b340497f7640344ed6c085645b450f9e02c8b20d.tar.bz2
[LTO] Add plumbing to save stats during LTO on Darwin.
Gold and ld on Linux already support saving stats, but the infrastructure is missing on Darwin. Unfortunately it seems like the configuration from lib/LTO/LTO.cpp is not used. This patch adds a new LTOStatsFile option and adds plumbing in Clang to use it on Darwin, similar to the way remarks are handled. Currnetly the handling of LTO flags seems quite spread out, with a bunch of duplication. But I am not sure if there is an easy way to improve that? Reviewers: anemet, tejohnson, thegameg, steven_wu Reviewed By: steven_wu Differential Revision: https://reviews.llvm.org/D60516 llvm-svn: 358753
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r--llvm/lib/LTO/LTO.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 1accbf4..ab5b780 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -885,16 +885,10 @@ Error LTO::run(AddStreamFn AddStream, NativeObjectCache Cache) {
isPrevailing, Conf.OptLevel > 0);
// Setup output file to emit statistics.
- std::unique_ptr<ToolOutputFile> StatsFile = nullptr;
- if (!Conf.StatsFile.empty()) {
- EnableStatistics(false);
- std::error_code EC;
- StatsFile =
- llvm::make_unique<ToolOutputFile>(Conf.StatsFile, EC, sys::fs::F_None);
- if (EC)
- return errorCodeToError(EC);
- StatsFile->keep();
- }
+ auto StatsFileOrErr = setupStatsFile(Conf.StatsFile);
+ if (!StatsFileOrErr)
+ return StatsFileOrErr.takeError();
+ std::unique_ptr<ToolOutputFile> StatsFile = std::move(StatsFileOrErr.get());
// Finalize linking of regular LTO modules containing summaries now that
// we have computed liveness information.
@@ -1343,3 +1337,20 @@ lto::setupOptimizationRemarks(LLVMContext &Context,
DiagnosticFile->keep();
return std::move(DiagnosticFile);
}
+
+Expected<std::unique_ptr<ToolOutputFile>>
+lto::setupStatsFile(StringRef StatsFilename) {
+ // Setup output file to emit statistics.
+ if (StatsFilename.empty())
+ return nullptr;
+
+ llvm::EnableStatistics(false);
+ std::error_code EC;
+ auto StatsFile =
+ llvm::make_unique<ToolOutputFile>(StatsFilename, EC, sys::fs::F_None);
+ if (EC)
+ return errorCodeToError(EC);
+
+ StatsFile->keep();
+ return std::move(StatsFile);
+}