summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp39
-rw-r--r--llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp8
-rw-r--r--llvm/lib/IR/Globals.cpp3
-rw-r--r--llvm/lib/IR/LegacyPassManager.cpp6
-rw-r--r--llvm/lib/IR/Module.cpp13
-rw-r--r--llvm/lib/LTO/LTO.cpp3
-rw-r--r--llvm/lib/LTO/LTOBackend.cpp3
-rw-r--r--llvm/lib/LTO/ThinLTOCodeGenerator.cpp3
-rw-r--r--llvm/lib/Linker/IRMover.cpp8
-rw-r--r--llvm/lib/Transforms/IPO/FunctionImport.cpp30
10 files changed, 63 insertions, 53 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index dad56f12e1c..57b03e80fa6 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -370,10 +370,8 @@ public:
Error materializeForwardReferencedFunctions();
- std::error_code materialize(GlobalValue *GV) override;
- Error materializeImpl(GlobalValue *GV);
- std::error_code materializeModule() override;
- Error materializeModuleImpl();
+ Error materialize(GlobalValue *GV) override;
+ Error materializeModule() override;
std::vector<StructType *> getIdentifiedStructTypes() const override;
/// \brief Main interface to parsing a bitcode buffer.
@@ -394,8 +392,7 @@ public:
static uint64_t decodeSignRotatedValue(uint64_t V);
/// Materialize any deferred Metadata block.
- std::error_code materializeMetadata() override;
- Error materializeMetadataImpl();
+ Error materializeMetadata() override;
void setStripDebugInfo() override;
@@ -677,7 +674,7 @@ Error BitcodeReader::materializeForwardReferencedFunctions() {
return error("Never resolved function from blockaddress");
// Try to materialize F.
- if (Error Err = materializeImpl(F))
+ if (Error Err = materialize(F))
return Err;
}
assert(BasicBlockFwdRefs.empty() && "Function missing from queue");
@@ -3580,11 +3577,7 @@ Error BitcodeReader::rememberAndSkipMetadata() {
return Error::success();
}
-std::error_code BitcodeReader::materializeMetadata() {
- return errorToErrorCodeAndEmitErrors(Context, materializeMetadataImpl());
-}
-
-Error BitcodeReader::materializeMetadataImpl() {
+Error BitcodeReader::materializeMetadata() {
for (uint64_t BitPos : DeferredMetadataInfo) {
// Move the bit stream to the saved position.
Stream.JumpToBit(BitPos);
@@ -5856,11 +5849,7 @@ Error BitcodeReader::findFunctionInStream(
// GVMaterializer implementation
//===----------------------------------------------------------------------===//
-std::error_code BitcodeReader::materialize(GlobalValue *GV) {
- return errorToErrorCodeAndEmitErrors(Context, materializeImpl(GV));
-}
-
-Error BitcodeReader::materializeImpl(GlobalValue *GV) {
+Error BitcodeReader::materialize(GlobalValue *GV) {
Function *F = dyn_cast<Function>(GV);
// If it's not a function or is already material, ignore the request.
if (!F || !F->isMaterializable())
@@ -5875,7 +5864,7 @@ Error BitcodeReader::materializeImpl(GlobalValue *GV) {
return Err;
// Materialize metadata before parsing any function bodies.
- if (Error Err = materializeMetadataImpl())
+ if (Error Err = materializeMetadata())
return Err;
// Move the bit stream to the saved position of the deferred function body.
@@ -5915,12 +5904,8 @@ Error BitcodeReader::materializeImpl(GlobalValue *GV) {
return materializeForwardReferencedFunctions();
}
-std::error_code BitcodeReader::materializeModule() {
- return errorToErrorCodeAndEmitErrors(Context, materializeModuleImpl());
-}
-
-Error BitcodeReader::materializeModuleImpl() {
- if (Error Err = materializeMetadataImpl())
+Error BitcodeReader::materializeModule() {
+ if (Error Err = materializeMetadata())
return Err;
// Promise to materialize all forward references.
@@ -5929,7 +5914,7 @@ Error BitcodeReader::materializeModuleImpl() {
// Iterate over the module, deserializing any functions that are still on
// disk.
for (Function &F : *TheModule) {
- if (Error Err = materializeImpl(&F))
+ if (Error Err = materialize(&F))
return Err;
}
// At this point, if there are any function bodies, parse the rest of
@@ -6664,8 +6649,8 @@ getLazyBitcodeModuleImpl(MemoryBufferRef Buffer, LLVMContext &Context,
if (MaterializeAll) {
// Read in the entire module, and destroy the BitcodeReader.
- if (std::error_code EC = M->materializeAll())
- return EC;
+ if (Error Err = M->materializeAll())
+ return errorToErrorCodeAndEmitErrors(Context, std::move(Err));
} else {
// Resolve forward references from blockaddresses.
if (Error Err = R->materializeForwardReferencedFunctions())
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp
index bc7da2e4f6a..9818adfff82 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp
@@ -35,9 +35,13 @@ extern "C" void LLVMLinkInInterpreter() { }
ExecutionEngine *Interpreter::create(std::unique_ptr<Module> M,
std::string *ErrStr) {
// Tell this Module to materialize everything and release the GVMaterializer.
- if (std::error_code EC = M->materializeAll()) {
+ if (Error Err = M->materializeAll()) {
+ std::string Msg;
+ handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
+ Msg = EIB.message();
+ });
if (ErrStr)
- *ErrStr = EC.message();
+ *ErrStr = Msg;
// We got an error, just return 0
return nullptr;
}
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 58fc25a1d18..f8ac37f9fc3 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -21,6 +21,7 @@
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
@@ -33,7 +34,7 @@ bool GlobalValue::isMaterializable() const {
return F->isMaterializable();
return false;
}
-std::error_code GlobalValue::materialize() {
+Error GlobalValue::materialize() {
return getParent()->materialize(this);
}
diff --git a/llvm/lib/IR/LegacyPassManager.cpp b/llvm/lib/IR/LegacyPassManager.cpp
index d5b2ef6d03b..458aeb8a38f 100644
--- a/llvm/lib/IR/LegacyPassManager.cpp
+++ b/llvm/lib/IR/LegacyPassManager.cpp
@@ -20,6 +20,7 @@
#include "llvm/Support/Chrono.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Mutex.h"
@@ -1377,8 +1378,9 @@ void FunctionPassManager::add(Pass *P) {
/// so, return true.
///
bool FunctionPassManager::run(Function &F) {
- if (std::error_code EC = F.materialize())
- report_fatal_error("Error reading bitcode file: " + EC.message());
+ handleAllErrors(F.materialize(), [&](ErrorInfoBase &EIB) {
+ report_fatal_error("Error reading bitcode file: " + EIB.message());
+ });
return FPM->run(F);
}
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 9824a1dfda2..1911f84340c 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -25,6 +25,7 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/TypeFinder.h"
#include "llvm/Support/Dwarf.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/RandomNumberGenerator.h"
@@ -405,23 +406,23 @@ void Module::setMaterializer(GVMaterializer *GVM) {
Materializer.reset(GVM);
}
-std::error_code Module::materialize(GlobalValue *GV) {
+Error Module::materialize(GlobalValue *GV) {
if (!Materializer)
- return std::error_code();
+ return Error::success();
return Materializer->materialize(GV);
}
-std::error_code Module::materializeAll() {
+Error Module::materializeAll() {
if (!Materializer)
- return std::error_code();
+ return Error::success();
std::unique_ptr<GVMaterializer> M = std::move(Materializer);
return M->materializeModule();
}
-std::error_code Module::materializeMetadata() {
+Error Module::materializeMetadata() {
if (!Materializer)
- return std::error_code();
+ return Error::success();
return Materializer->materializeMetadata();
}
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index ed95ac6598c..b599830d092 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -350,7 +350,8 @@ Error LTO::addRegularLTO(std::unique_ptr<InputFile> Input,
std::unique_ptr<object::IRObjectFile> Obj = std::move(*ObjOrErr);
Module &M = Obj->getModule();
- M.materializeMetadata();
+ if (Error Err = M.materializeMetadata())
+ return Err;
UpgradeDebugInfo(M);
SmallPtrSet<GlobalValue *, 8> Used;
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 0885c0b8484..fb1cfed96bb 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -359,7 +359,8 @@ Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream,
};
FunctionImporter Importer(CombinedIndex, ModuleLoader);
- Importer.importFunctions(Mod, ImportList);
+ if (Error Err = Importer.importFunctions(Mod, ImportList).takeError())
+ return Err;
if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
return Error();
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 2bf4f7a569f..5baecc2bdac 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -152,7 +152,8 @@ crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index,
const FunctionImporter::ImportMapTy &ImportList) {
ModuleLoader Loader(TheModule.getContext(), ModuleMap);
FunctionImporter Importer(Index, Loader);
- Importer.importFunctions(TheModule, ImportList);
+ if (!Importer.importFunctions(TheModule, ImportList))
+ report_fatal_error("importFunctions failed");
}
static void optimizeModule(Module &TheModule, TargetMachine &TM) {
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index ad57134ec7f..3c58d54802d 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -963,8 +963,8 @@ Error IRLinker::linkFunctionBody(Function &Dst, Function &Src) {
assert(Dst.isDeclaration() && !Src.isDeclaration());
// Materialize if needed.
- if (std::error_code EC = Src.materialize())
- return errorCodeToError(EC);
+ if (Error Err = Src.materialize())
+ return Err;
// Link in the operands without remapping.
if (Src.hasPrefixData())
@@ -1191,8 +1191,8 @@ static std::string mergeTriples(const Triple &SrcTriple,
Error IRLinker::run() {
// Ensure metadata materialized before value mapping.
if (SrcM->getMaterializer())
- if (std::error_code EC = SrcM->getMaterializer()->materializeMetadata())
- return errorCodeToError(EC);
+ if (Error Err = SrcM->getMaterializer()->materializeMetadata())
+ return Err;
// Inherit the target data from the source module if the destination module
// doesn't have one already.
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index c9f4ea06a90..8b252507f0e 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -606,7 +606,7 @@ void llvm::thinLTOInternalizeModule(Module &TheModule,
// Automatically import functions in Module \p DestModule based on the summaries
// index.
//
-bool FunctionImporter::importFunctions(
+Expected<bool> FunctionImporter::importFunctions(
Module &DestModule, const FunctionImporter::ImportMapTy &ImportList,
bool ForceImportReferencedDiscardableSymbols) {
DEBUG(dbgs() << "Starting import for Module "
@@ -630,7 +630,8 @@ bool FunctionImporter::importFunctions(
// If modules were created with lazy metadata loading, materialize it
// now, before linking it (otherwise this will be a noop).
- SrcModule->materializeMetadata();
+ if (Error Err = SrcModule->materializeMetadata())
+ return std::move(Err);
UpgradeDebugInfo(*SrcModule);
auto &ImportGUIDs = FunctionsToImportPerModule->second;
@@ -645,7 +646,8 @@ bool FunctionImporter::importFunctions(
<< " " << F.getName() << " from "
<< SrcModule->getSourceFileName() << "\n");
if (Import) {
- F.materialize();
+ if (Error Err = F.materialize())
+ return std::move(Err);
if (EnableImportMetadata) {
// Add 'thinlto_src_module' metadata for statistics and debugging.
F.setMetadata(
@@ -667,7 +669,8 @@ bool FunctionImporter::importFunctions(
<< " " << GV.getName() << " from "
<< SrcModule->getSourceFileName() << "\n");
if (Import) {
- GV.materialize();
+ if (Error Err = GV.materialize())
+ return std::move(Err);
GlobalsToImport.insert(&GV);
}
}
@@ -693,9 +696,11 @@ bool FunctionImporter::importFunctions(
<< " " << GO->getName() << " from "
<< SrcModule->getSourceFileName() << "\n");
#endif
- GO->materialize();
+ if (Error Err = GO->materialize())
+ return std::move(Err);
GlobalsToImport.insert(GO);
- GA.materialize();
+ if (Error Err = GA.materialize())
+ return std::move(Err);
GlobalsToImport.insert(&GA);
}
}
@@ -799,8 +804,17 @@ static bool doImportingForModule(Module &M, const ModuleSummaryIndex *Index) {
return loadFile(Identifier, M.getContext());
};
FunctionImporter Importer(*Index, ModuleLoader);
- return Importer.importFunctions(M, ImportList,
- !DontForceImportReferencedDiscardableSymbols);
+ Expected<bool> Result = Importer.importFunctions(
+ M, ImportList, !DontForceImportReferencedDiscardableSymbols);
+
+ // FIXME: Probably need to propagate Errors through the pass manager.
+ if (!Result) {
+ logAllUnhandledErrors(Result.takeError(), errs(),
+ "Error importing module: ");
+ return false;
+ }
+
+ return *Result;
}
namespace {
OpenPOWER on IntegriCloud