From: Davide Italiano Date: Fri, 10 Feb 2017 22:16:17 +0000 (+0000) Subject: [lib/LTO] Rework optimization remarkers setup. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54c3fcaeb17f8176823331579bb753da8ab71adc;p=llvm [lib/LTO] Rework optimization remarkers setup. This makes this code much more similar to what ThinLTO is using (also API wise), so now we can probably use a single code path instead of copying stuff around. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294792 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/LTO/legacy/LTOCodeGenerator.h b/include/llvm/LTO/legacy/LTOCodeGenerator.h index f1468211128..64833c094ea 100644 --- a/include/llvm/LTO/legacy/LTOCodeGenerator.h +++ b/include/llvm/LTO/legacy/LTOCodeGenerator.h @@ -41,6 +41,7 @@ #include "llvm/ADT/StringSet.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/Module.h" +#include "llvm/Support/Error.h" #include "llvm/Support/ToolOutputFile.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" @@ -206,7 +207,7 @@ private: void emitError(const std::string &ErrMsg); void emitWarning(const std::string &ErrMsg); - bool setupOptimizationRemarks(); + Expected> setupOptimizationRemarks(); void finishOptimizationRemarks(); LLVMContext &Context; diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 6af31e61f94..4853751e0e4 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -506,23 +506,22 @@ void LTOCodeGenerator::verifyMergedModuleOnce() { report_fatal_error("Broken module found, compilation aborted!"); } -bool LTOCodeGenerator::setupOptimizationRemarks() { - if (LTORemarksFilename != "") { - std::error_code EC; - DiagnosticOutputFile = llvm::make_unique( - LTORemarksFilename, EC, sys::fs::F_None); - if (EC) { - emitError(EC.message()); - return false; - } - Context.setDiagnosticsOutputFile( - llvm::make_unique(DiagnosticOutputFile->os())); - } +Expected> +LTOCodeGenerator::setupOptimizationRemarks() { + if (LTORemarksFilename.empty()) + return nullptr; + + std::error_code EC; + auto DiagnosticFile = llvm::make_unique( + LTORemarksFilename, EC, sys::fs::F_None); + if (EC) + return errorCodeToError(EC); + Context.setDiagnosticsOutputFile( + llvm::make_unique(DiagnosticFile->os())); if (LTOPassRemarksWithHotness) Context.setDiagnosticHotnessRequested(true); - - return true; + return std::move(DiagnosticFile); } void LTOCodeGenerator::finishOptimizationRemarks() { @@ -540,8 +539,12 @@ bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline, if (!this->determineTarget()) return false; - if (!setupOptimizationRemarks()) - return false; + auto DiagFileOrErr = setupOptimizationRemarks(); + if (!DiagFileOrErr) { + errs() << "Error: " << toString(DiagFileOrErr.takeError()) << "\n"; + report_fatal_error("Can't get an output file for the remarks"); + } + DiagnosticOutputFile = std::move(*DiagFileOrErr); // We always run the verifier once on the merged module, the `DisableVerify` // parameter only applies to subsequent verify.