/// Make sure the given GlobalValue is fully read.
///
- virtual std::error_code Materialize(GlobalValue *GV) = 0;
+ virtual std::error_code materialize(GlobalValue *GV) = 0;
/// If the given GlobalValue is read in, and if the GVMaterializer supports
/// it, release the memory for the GV, and set it up to be materialized
#include "llvm/IR/Constant.h"
#include "llvm/IR/DerivedTypes.h"
+#include <system_error>
+
namespace llvm {
class Comdat;
/// Make sure this GlobalValue is fully read. If the module is corrupt, this
/// returns true and fills in the optional string with information about the
/// problem. If successful, this returns false.
- bool Materialize(std::string *ErrInfo = nullptr);
+ std::error_code materialize();
/// If this GlobalValue is read in, and if the GVMaterializer supports it,
/// release the memory for the function, and set it up to be materialized
/// Make sure the GlobalValue is fully read. If the module is corrupt, this
/// returns true and fills in the optional string with information about the
/// problem. If successful, this returns false.
- bool Materialize(GlobalValue *GV, std::string *ErrInfo = nullptr);
+ std::error_code materialize(GlobalValue *GV);
/// If the GlobalValue is read in, and if the GVMaterializer supports it,
/// release the memory for the function, and set it up to be materialized
/// lazily. If !isDematerializable(), this method is a noop.
return Error(BitcodeError::NeverResolvedFunctionFromBlockAddress);
// Try to materialize F.
- if (std::error_code EC = Materialize(F))
+ if (std::error_code EC = materialize(F))
return EC;
}
assert(BasicBlockFwdRefs.empty() && "Function missing from queue");
void BitcodeReader::releaseBuffer() { Buffer.release(); }
-std::error_code BitcodeReader::Materialize(GlobalValue *GV) {
+std::error_code 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())
for (Module::iterator F = TheModule->begin(), E = TheModule->end();
F != E; ++F) {
if (F->isMaterializable()) {
- if (std::error_code EC = Materialize(F))
+ if (std::error_code EC = materialize(F))
return EC;
}
}
void releaseBuffer();
bool isDematerializable(const GlobalValue *GV) const override;
- std::error_code Materialize(GlobalValue *GV) override;
+ std::error_code materialize(GlobalValue *GV) override;
std::error_code MaterializeModule(Module *M) override;
void Dematerialize(GlobalValue *GV) override;
bool GlobalValue::isDematerializable() const {
return getParent() && getParent()->isDematerializable(this);
}
-bool GlobalValue::Materialize(std::string *ErrInfo) {
- return getParent()->Materialize(this, ErrInfo);
+std::error_code GlobalValue::materialize() {
+ return getParent()->materialize(this);
}
void GlobalValue::Dematerialize() {
getParent()->Dematerialize(this);
///
bool FunctionPassManager::run(Function &F) {
if (F.isMaterializable()) {
- std::string errstr;
- if (F.Materialize(&errstr))
- report_fatal_error("Error reading bitcode file: " + Twine(errstr));
+ if (std::error_code EC = F.materialize())
+ report_fatal_error("Error reading bitcode file: " + EC.message());
}
return FPM->run(F);
}
return false;
}
-bool Module::Materialize(GlobalValue *GV, std::string *ErrInfo) {
+std::error_code Module::materialize(GlobalValue *GV) {
if (!Materializer)
- return false;
-
- std::error_code EC = Materializer->Materialize(GV);
- if (!EC)
- return false;
- if (ErrInfo)
- *ErrInfo = EC.message();
- return true;
+ return std::error_code();
+
+ return Materializer->materialize(GV);
}
void Module::Dematerialize(GlobalValue *GV) {
// Materialize if needed.
if (SF->isMaterializable()) {
- if (SF->Materialize(&ErrorMsg))
+ if (std::error_code EC = SF->materialize()) {
+ ErrorMsg = EC.message();
return true;
+ }
}
// Skip if no body (function is external).
// Materialize if needed.
if (SF->isMaterializable()) {
- if (SF->Materialize(&ErrorMsg))
+ if (std::error_code EC = SF->materialize()) {
+ ErrorMsg = EC.message();
return true;
+ }
}
// Skip if no body (function is external).
Module *M = GO->getParent();
GlobalObject *Ret;
if (auto *F = dyn_cast<Function>(GO)) {
- if (F->isMaterializable())
- F->Materialize();
+ if (F->isMaterializable()) {
+ if (std::error_code EC = F->materialize())
+ message(LDPL_FATAL, "LLVM gold plugin has failed to read a function");
+
+ }
auto *NewF = Function::Create(F->getFunctionType(), F->getLinkage(),
F->getName(), M);
for (size_t i = 0, e = GVs.size(); i != e; ++i) {
GlobalValue *GV = GVs[i];
if (GV->isMaterializable()) {
- std::string ErrInfo;
- if (GV->Materialize(&ErrInfo)) {
- errs() << argv[0] << ": error reading input: " << ErrInfo << "\n";
+ if (std::error_code EC = GV->materialize()) {
+ errs() << argv[0] << ": error reading input: " << EC.message()
+ << "\n";
return 1;
}
}
SmallPtrSet<GlobalValue *, 8> GVSet(GVs.begin(), GVs.end());
for (auto &G : M->globals()) {
if (!GVSet.count(&G) && G.isMaterializable()) {
- std::string ErrInfo;
- if (G.Materialize(&ErrInfo)) {
- errs() << argv[0] << ": error reading input: " << ErrInfo << "\n";
+ if (std::error_code EC = G.materialize()) {
+ errs() << argv[0] << ": error reading input: " << EC.message()
+ << "\n";
return 1;
}
}
}
for (auto &F : *M) {
if (!GVSet.count(&F) && F.isMaterializable()) {
- std::string ErrInfo;
- if (F.Materialize(&ErrInfo)) {
- errs() << argv[0] << ": error reading input: " << ErrInfo << "\n";
+ if (std::error_code EC = F.materialize()) {
+ errs() << argv[0] << ": error reading input: " << EC.message()
+ << "\n";
return 1;
}
}
EXPECT_FALSE(verifyModule(*M, &dbgs()));
- M->getFunction("func")->Materialize();
+ M->getFunction("func")->materialize();
EXPECT_FALSE(M->getFunction("func")->empty());
EXPECT_TRUE(M->getFunction("func")->getLinkage() ==
GlobalValue::InternalLinkage);
EXPECT_FALSE(verifyModule(*M, &dbgs()));
// Materialize @before, pulling in @func.
- EXPECT_FALSE(M->getFunction("before")->Materialize());
+ EXPECT_FALSE(M->getFunction("before")->materialize());
EXPECT_FALSE(M->getFunction("func")->empty());
EXPECT_TRUE(M->getFunction("other")->empty());
EXPECT_FALSE(verifyModule(*M, &dbgs()));
EXPECT_FALSE(verifyModule(*M, &dbgs()));
// Materialize @after, pulling in @func.
- EXPECT_FALSE(M->getFunction("after")->Materialize());
+ EXPECT_FALSE(M->getFunction("after")->materialize());
EXPECT_FALSE(M->getFunction("func")->empty());
EXPECT_TRUE(M->getFunction("other")->empty());
EXPECT_FALSE(verifyModule(*M, &dbgs()));