diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2016-11-11 19:50:39 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-11-11 19:50:39 +0000 |
commit | aeb2eff8d24105d890b5f46944bcda2bb95a5538 (patch) | |
tree | 0e00d34aa81c73090f72abb1cc9722d49d2369de /tools/llvm-lto | |
parent | 9b252f03d92e5474d84036822e4472f07763e1d6 (diff) |
Bitcode: Change getModuleSummaryIndex() to return an llvm::Expected.
Differential Revision: https://reviews.llvm.org/D26539
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286624 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-lto')
-rw-r--r-- | tools/llvm-lto/llvm-lto.cpp | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/tools/llvm-lto/llvm-lto.cpp b/tools/llvm-lto/llvm-lto.cpp index d883f3cc229..2f0a1dfb9fa 100644 --- a/tools/llvm-lto/llvm-lto.cpp +++ b/tools/llvm-lto/llvm-lto.cpp @@ -197,7 +197,7 @@ static void handleDiagnostics(lto_codegen_diagnostic_severity_t Severity, } static std::string CurrentActivity; -static void diagnosticHandler(const DiagnosticInfo &DI) { +static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) { raw_ostream &OS = errs(); OS << "llvm-lto: "; switch (DI.getSeverity()) { @@ -226,11 +226,6 @@ static void diagnosticHandler(const DiagnosticInfo &DI) { exit(1); } -static void diagnosticHandlerWithContext(const DiagnosticInfo &DI, - void *Context) { - diagnosticHandler(DI); -} - static void error(const Twine &Msg) { errs() << "llvm-lto: " << Msg << '\n'; exit(1); @@ -260,7 +255,7 @@ getLocalLTOModule(StringRef Path, std::unique_ptr<MemoryBuffer> &Buffer, Buffer = std::move(BufferOrErr.get()); CurrentActivity = ("loading file '" + Path + "'").str(); std::unique_ptr<LLVMContext> Context = llvm::make_unique<LLVMContext>(); - Context->setDiagnosticHandler(diagnosticHandlerWithContext, nullptr, true); + Context->setDiagnosticHandler(diagnosticHandler, nullptr, true); ErrorOr<std::unique_ptr<LTOModule>> Ret = LTOModule::createInLocalContext( std::move(Context), Buffer->getBufferStart(), Buffer->getBufferSize(), Options, Path); @@ -272,12 +267,9 @@ getLocalLTOModule(StringRef Path, std::unique_ptr<MemoryBuffer> &Buffer, /// Print some statistics on the index for each input files. void printIndexStats() { for (auto &Filename : InputFilenames) { - CurrentActivity = "loading file '" + Filename + "'"; - ErrorOr<std::unique_ptr<ModuleSummaryIndex>> IndexOrErr = - llvm::getModuleSummaryIndexForFile(Filename, diagnosticHandler); - error(IndexOrErr, "error " + CurrentActivity); - std::unique_ptr<ModuleSummaryIndex> Index = std::move(IndexOrErr.get()); - CurrentActivity = ""; + ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename + "': "); + std::unique_ptr<ModuleSummaryIndex> Index = + ExitOnErr(llvm::getModuleSummaryIndexForFile(Filename)); // Skip files without a module summary. if (!Index) report_fatal_error(Filename + " does not contain an index"); @@ -330,12 +322,9 @@ static void createCombinedModuleSummaryIndex() { ModuleSummaryIndex CombinedIndex; uint64_t NextModuleId = 0; for (auto &Filename : InputFilenames) { - CurrentActivity = "loading file '" + Filename + "'"; - ErrorOr<std::unique_ptr<ModuleSummaryIndex>> IndexOrErr = - llvm::getModuleSummaryIndexForFile(Filename, diagnosticHandler); - error(IndexOrErr, "error " + CurrentActivity); - std::unique_ptr<ModuleSummaryIndex> Index = std::move(IndexOrErr.get()); - CurrentActivity = ""; + ExitOnError ExitOnErr("llvm-lto: error loading file '" + Filename + "': "); + std::unique_ptr<ModuleSummaryIndex> Index = + ExitOnErr(llvm::getModuleSummaryIndexForFile(Filename)); // Skip files without a module summary. if (!Index) continue; @@ -400,11 +389,9 @@ loadAllFilesForIndex(const ModuleSummaryIndex &Index) { std::unique_ptr<ModuleSummaryIndex> loadCombinedIndex() { if (ThinLTOIndex.empty()) report_fatal_error("Missing -thinlto-index for ThinLTO promotion stage"); - auto CurrentActivity = "loading file '" + ThinLTOIndex + "'"; - ErrorOr<std::unique_ptr<ModuleSummaryIndex>> IndexOrErr = - llvm::getModuleSummaryIndexForFile(ThinLTOIndex, diagnosticHandler); - error(IndexOrErr, "error " + CurrentActivity); - return std::move(IndexOrErr.get()); + ExitOnError ExitOnErr("llvm-lto: error loading file '" + ThinLTOIndex + + "': "); + return ExitOnErr(llvm::getModuleSummaryIndexForFile(ThinLTOIndex)); } static std::unique_ptr<Module> loadModule(StringRef Filename, @@ -802,7 +789,7 @@ int main(int argc, char **argv) { unsigned BaseArg = 0; LLVMContext Context; - Context.setDiagnosticHandler(diagnosticHandlerWithContext, nullptr, true); + Context.setDiagnosticHandler(diagnosticHandler, nullptr, true); LTOCodeGenerator CodeGen(Context); |