summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp28
-rw-r--r--llvm/lib/LTO/LTO.cpp7
-rw-r--r--llvm/lib/LTO/ThinLTOCodeGenerator.cpp18
-rw-r--r--llvm/lib/Object/ModuleSummaryIndexObjectFile.cpp37
-rw-r--r--llvm/lib/Transforms/IPO/FunctionImport.cpp41
5 files changed, 36 insertions, 95 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 357f283529b..bb58674a1f1 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -841,19 +841,6 @@ std::error_code llvm::errorToErrorCodeAndEmitErrors(LLVMContext &Ctx,
return std::error_code();
}
-std::error_code llvm::errorToErrorCodeAndEmitErrors(
- const DiagnosticHandlerFunction &DiagHandler, Error Err) {
- if (Err) {
- std::error_code EC;
- handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
- EC = EIB.convertToErrorCode();
- DiagHandler(DiagnosticInfoInlineAsm(EIB.message()));
- });
- return EC;
- }
- return std::error_code();
-}
-
BitcodeReader::BitcodeReader(BitstreamCursor Stream, LLVMContext &Context)
: BitcodeReaderBase(std::move(Stream)), Context(Context), ValueList(Context),
MetadataList(Context) {}
@@ -6663,22 +6650,19 @@ Expected<std::string> llvm::getBitcodeProducerString(MemoryBufferRef Buffer) {
}
// Parse the specified bitcode buffer, returning the function info index.
-ErrorOr<std::unique_ptr<ModuleSummaryIndex>> llvm::getModuleSummaryIndex(
- MemoryBufferRef Buffer,
- const DiagnosticHandlerFunction &DiagnosticHandler) {
+Expected<std::unique_ptr<ModuleSummaryIndex>>
+llvm::getModuleSummaryIndex(MemoryBufferRef Buffer) {
Expected<BitstreamCursor> StreamOrErr = initStream(Buffer);
if (!StreamOrErr)
- return errorToErrorCodeAndEmitErrors(DiagnosticHandler,
- StreamOrErr.takeError());
+ return StreamOrErr.takeError();
ModuleSummaryIndexBitcodeReader R(std::move(*StreamOrErr));
auto Index = llvm::make_unique<ModuleSummaryIndex>();
- if (std::error_code EC = errorToErrorCodeAndEmitErrors(
- DiagnosticHandler,
- R.parseSummaryIndexInto(Index.get(), Buffer.getBufferIdentifier())))
- return EC;
+ if (Error Err =
+ R.parseSummaryIndexInto(Index.get(), Buffer.getBufferIdentifier()))
+ return std::move(Err);
return std::move(Index);
}
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 4ff1bfb1471..cf40bfd4ebc 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -417,11 +417,10 @@ Error LTO::addThinLTO(std::unique_ptr<InputFile> Input,
collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
MemoryBufferRef MBRef = Input->Obj->getMemoryBufferRef();
- ErrorOr<std::unique_ptr<object::ModuleSummaryIndexObjectFile>>
- SummaryObjOrErr =
- object::ModuleSummaryIndexObjectFile::create(MBRef, Conf.DiagHandler);
+ Expected<std::unique_ptr<object::ModuleSummaryIndexObjectFile>>
+ SummaryObjOrErr = object::ModuleSummaryIndexObjectFile::create(MBRef);
if (!SummaryObjOrErr)
- return errorCodeToError(SummaryObjOrErr.getError());
+ return SummaryObjOrErr.takeError();
ThinLTO.CombinedIndex.mergeFrom((*SummaryObjOrErr)->takeIndex(),
ThinLTO.ModuleMap.size());
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 77f1d342e11..86968a736e6 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -69,12 +69,6 @@ namespace {
static cl::opt<int>
ThreadCount("threads", cl::init(llvm::heavyweight_hardware_concurrency()));
-static void diagnosticHandler(const DiagnosticInfo &DI) {
- DiagnosticPrinterRawOStream DP(errs());
- DI.print(DP);
- errs() << '\n';
-}
-
// Simple helper to save temporary files for debug.
static void saveTempBitcode(const Module &TheModule, StringRef TempDir,
unsigned count, StringRef Suffix) {
@@ -513,13 +507,13 @@ std::unique_ptr<ModuleSummaryIndex> ThinLTOCodeGenerator::linkCombinedIndex() {
std::unique_ptr<ModuleSummaryIndex> CombinedIndex;
uint64_t NextModuleId = 0;
for (auto &ModuleBuffer : Modules) {
- ErrorOr<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr =
- object::ModuleSummaryIndexObjectFile::create(ModuleBuffer,
- diagnosticHandler);
- if (std::error_code EC = ObjOrErr.getError()) {
+ Expected<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr =
+ object::ModuleSummaryIndexObjectFile::create(ModuleBuffer);
+ if (!ObjOrErr) {
// FIXME diagnose
- errs() << "error: can't create ModuleSummaryIndexObjectFile for buffer: "
- << EC.message() << "\n";
+ logAllUnhandledErrors(
+ ObjOrErr.takeError(), errs(),
+ "error: can't create ModuleSummaryIndexObjectFile for buffer: ");
return nullptr;
}
auto Index = (*ObjOrErr)->takeIndex();
diff --git a/llvm/lib/Object/ModuleSummaryIndexObjectFile.cpp b/llvm/lib/Object/ModuleSummaryIndexObjectFile.cpp
index e597fc20a1f..d37530b1abb 100644
--- a/llvm/lib/Object/ModuleSummaryIndexObjectFile.cpp
+++ b/llvm/lib/Object/ModuleSummaryIndexObjectFile.cpp
@@ -70,44 +70,37 @@ ModuleSummaryIndexObjectFile::findBitcodeInMemBuffer(MemoryBufferRef Object) {
// Parse module summary index in the given memory buffer.
// Return new ModuleSummaryIndexObjectFile instance containing parsed
// module summary/index.
-ErrorOr<std::unique_ptr<ModuleSummaryIndexObjectFile>>
-ModuleSummaryIndexObjectFile::create(
- MemoryBufferRef Object,
- const DiagnosticHandlerFunction &DiagnosticHandler) {
- std::unique_ptr<ModuleSummaryIndex> Index;
-
+Expected<std::unique_ptr<ModuleSummaryIndexObjectFile>>
+ModuleSummaryIndexObjectFile::create(MemoryBufferRef Object) {
ErrorOr<MemoryBufferRef> BCOrErr = findBitcodeInMemBuffer(Object);
if (!BCOrErr)
- return BCOrErr.getError();
-
- ErrorOr<std::unique_ptr<ModuleSummaryIndex>> IOrErr =
- getModuleSummaryIndex(BCOrErr.get(), DiagnosticHandler);
+ return errorCodeToError(BCOrErr.getError());
- if (std::error_code EC = IOrErr.getError())
- return EC;
+ Expected<std::unique_ptr<ModuleSummaryIndex>> IOrErr =
+ getModuleSummaryIndex(BCOrErr.get());
- Index = std::move(IOrErr.get());
+ if (!IOrErr)
+ return std::move(IOrErr.takeError());
+ std::unique_ptr<ModuleSummaryIndex> Index = std::move(IOrErr.get());
return llvm::make_unique<ModuleSummaryIndexObjectFile>(Object,
std::move(Index));
}
// Parse the module summary index out of an IR file and return the summary
// index object if found, or nullptr if not.
-ErrorOr<std::unique_ptr<ModuleSummaryIndex>> llvm::getModuleSummaryIndexForFile(
- StringRef Path, const DiagnosticHandlerFunction &DiagnosticHandler) {
+Expected<std::unique_ptr<ModuleSummaryIndex>>
+llvm::getModuleSummaryIndexForFile(StringRef Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(Path);
std::error_code EC = FileOrErr.getError();
if (EC)
- return EC;
+ return errorCodeToError(EC);
MemoryBufferRef BufferRef = (FileOrErr.get())->getMemBufferRef();
- ErrorOr<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr =
- object::ModuleSummaryIndexObjectFile::create(BufferRef,
- DiagnosticHandler);
- EC = ObjOrErr.getError();
- if (EC)
- return EC;
+ Expected<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr =
+ object::ModuleSummaryIndexObjectFile::create(BufferRef);
+ if (!ObjOrErr)
+ return ObjOrErr.takeError();
object::ModuleSummaryIndexObjectFile &Obj = **ObjOrErr;
return Obj.takeIndex();
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 8b252507f0e..2a351b30119 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -739,36 +739,6 @@ static cl::opt<std::string>
SummaryFile("summary-file",
cl::desc("The summary file to use for function importing."));
-static void diagnosticHandler(const DiagnosticInfo &DI) {
- raw_ostream &OS = errs();
- DiagnosticPrinterRawOStream DP(OS);
- DI.print(DP);
- OS << '\n';
-}
-
-/// Parse the summary index out of an IR file and return the summary
-/// index object if found, or nullptr if not.
-static std::unique_ptr<ModuleSummaryIndex> getModuleSummaryIndexForFile(
- StringRef Path, std::string &Error,
- const DiagnosticHandlerFunction &DiagnosticHandler) {
- std::unique_ptr<MemoryBuffer> Buffer;
- ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
- MemoryBuffer::getFile(Path);
- if (std::error_code EC = BufferOrErr.getError()) {
- Error = EC.message();
- return nullptr;
- }
- Buffer = std::move(BufferOrErr.get());
- ErrorOr<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr =
- object::ModuleSummaryIndexObjectFile::create(Buffer->getMemBufferRef(),
- DiagnosticHandler);
- if (std::error_code EC = ObjOrErr.getError()) {
- Error = EC.message();
- return nullptr;
- }
- return (*ObjOrErr)->takeIndex();
-}
-
static bool doImportingForModule(Module &M, const ModuleSummaryIndex *Index) {
if (SummaryFile.empty() && !Index)
report_fatal_error("error: -function-import requires -summary-file or "
@@ -777,13 +747,14 @@ static bool doImportingForModule(Module &M, const ModuleSummaryIndex *Index) {
if (!SummaryFile.empty()) {
if (Index)
report_fatal_error("error: -summary-file and index from frontend\n");
- std::string Error;
- IndexPtr =
- getModuleSummaryIndexForFile(SummaryFile, Error, diagnosticHandler);
- if (!IndexPtr) {
- errs() << "Error loading file '" << SummaryFile << "': " << Error << "\n";
+ Expected<std::unique_ptr<ModuleSummaryIndex>> IndexPtrOrErr =
+ getModuleSummaryIndexForFile(SummaryFile);
+ if (!IndexPtrOrErr) {
+ logAllUnhandledErrors(IndexPtrOrErr.takeError(), errs(),
+ "Error loading file '" + SummaryFile + "': ");
return false;
}
+ IndexPtr = std::move(*IndexPtrOrErr);
Index = IndexPtr.get();
}
OpenPOWER on IntegriCloud