diff options
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
| -rw-r--r-- | llvm/lib/LTO/LTO.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 1accbf40b96..ab5b78071c6 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); +} |

