summaryrefslogtreecommitdiff
path: root/lib/LTO/LTO.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <florian.hahn@arm.com>2018-04-20 10:18:36 +0000
committerFlorian Hahn <florian.hahn@arm.com>2018-04-20 10:18:36 +0000
commita2fbfc91ac4614be0852b6325ff6fd0935d100bf (patch)
tree383873ab31944419e18a4751a31812ec226a527e /lib/LTO/LTO.cpp
parentb1203052374e8e62b50b47c734fc7591e1329f87 (diff)
[LTO] Add stats-file option to LTO/Config.h.
This patch adds a StatsFile option to LTO/Config.h and updates both LLVMGold and llvm-lto2 to set it. Reviewers: MatzeB, tejohnson, espindola Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D45531 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330411 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/LTO/LTO.cpp')
-rw-r--r--lib/LTO/LTO.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/LTO/LTO.cpp b/lib/LTO/LTO.cpp
index e4dffbf296b..186e3d2d3a7 100644
--- a/lib/LTO/LTO.cpp
+++ b/lib/LTO/LTO.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/LTO/LTO.h"
+#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Bitcode/BitcodeReader.h"
@@ -791,9 +792,26 @@ Error LTO::run(AddStreamFn AddStream, NativeObjectCache Cache) {
};
computeDeadSymbols(ThinLTO.CombinedIndex, GUIDPreservedSymbols, isPrevailing);
- if (auto E = runRegularLTO(AddStream))
- return E;
- return runThinLTO(AddStream, Cache);
+ // 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();
+ }
+
+ Error Result = runRegularLTO(AddStream);
+ if (!Result)
+ Result = runThinLTO(AddStream, Cache);
+
+ if (StatsFile)
+ PrintStatisticsJSON(StatsFile->os());
+
+ return Result;
}
Error LTO::runRegularLTO(AddStreamFn AddStream) {