1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[ORC] Use JITEvaluatedSymbol for IndirectStubsManager findStub and findPointer.

Existing implementations of these methods do not require lazy materialization,
and switching to JITEvaluatedSymbol allows us to remove error checking on the
client side.

llvm-svn: 333835
This commit is contained in:
Lang Hames 2018-06-03 02:18:03 +00:00
parent a439e2867c
commit bf6632996c
4 changed files with 15 additions and 31 deletions

View File

@ -401,9 +401,8 @@ private:
// Initializers may refer to functions declared (but not defined) in this
// module. Build a materializer to clone decls on demand.
Error MaterializerErrors = Error::success();
auto Materializer = createLambdaMaterializer(
[&LD, &GVsM, &MaterializerErrors](Value *V) -> Value* {
[&LD, &GVsM](Value *V) -> Value* {
if (auto *F = dyn_cast<Function>(V)) {
// Decls in the original module just get cloned.
if (F->isDeclaration())
@ -415,18 +414,8 @@ private:
const DataLayout &DL = GVsM->getDataLayout();
std::string FName = mangle(F->getName(), DL);
unsigned PtrBitWidth = DL.getPointerTypeSizeInBits(F->getType());
JITTargetAddress StubAddr = 0;
// Get the address for the stub. If we encounter an error while
// doing so, stash it in the MaterializerErrors variable and use a
// null address as a placeholder.
if (auto StubSym = LD.StubsMgr->findStub(FName, false)) {
if (auto StubAddrOrErr = StubSym.getAddress())
StubAddr = *StubAddrOrErr;
else
MaterializerErrors = joinErrors(std::move(MaterializerErrors),
StubAddrOrErr.takeError());
}
JITTargetAddress StubAddr =
LD.StubsMgr->findStub(FName, false).getAddress();
ConstantInt *StubAddrCI =
ConstantInt::get(GVsM->getContext(), APInt(PtrBitWidth, StubAddr));
@ -455,15 +444,10 @@ private:
NewA->setAliasee(cast<Constant>(Init));
}
if (MaterializerErrors)
return MaterializerErrors;
// Build a resolver for the globals module and add it to the base layer.
auto LegacyLookup = [this, &LD](const std::string &Name) -> JITSymbol {
if (auto Sym = LD.StubsMgr->findStub(Name, false))
return Sym;
else if (auto Err = Sym.takeError())
return std::move(Err);
if (auto Sym = LD.findSymbol(BaseLayer, Name, false))
return Sym;

View File

@ -188,10 +188,10 @@ public:
/// Find the stub with the given name. If ExportedStubsOnly is true,
/// this will only return a result if the stub's flags indicate that it
/// is exported.
virtual JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) = 0;
virtual JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) = 0;
/// Find the implementation-pointer for the stub.
virtual JITSymbol findPointer(StringRef Name) = 0;
virtual JITEvaluatedSymbol findPointer(StringRef Name) = 0;
/// Change the value of the implementation pointer for the stub.
virtual Error updatePointer(StringRef Name, JITTargetAddress NewAddr) = 0;
@ -226,7 +226,7 @@ public:
return Error::success();
}
JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
auto I = StubIndexes.find(Name);
if (I == StubIndexes.end())
return nullptr;
@ -235,13 +235,13 @@ public:
assert(StubAddr && "Missing stub address");
auto StubTargetAddr =
static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(StubAddr));
auto StubSymbol = JITSymbol(StubTargetAddr, I->second.second);
auto StubSymbol = JITEvaluatedSymbol(StubTargetAddr, I->second.second);
if (ExportedStubsOnly && !StubSymbol.getFlags().isExported())
return nullptr;
return StubSymbol;
}
JITSymbol findPointer(StringRef Name) override {
JITEvaluatedSymbol findPointer(StringRef Name) override {
auto I = StubIndexes.find(Name);
if (I == StubIndexes.end())
return nullptr;
@ -250,7 +250,7 @@ public:
assert(PtrAddr && "Missing pointer address");
auto PtrTargetAddr =
static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(PtrAddr));
return JITSymbol(PtrTargetAddr, I->second.second);
return JITEvaluatedSymbol(PtrTargetAddr, I->second.second);
}
Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override {

View File

@ -358,25 +358,25 @@ public:
return Error::success();
}
JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
auto I = StubIndexes.find(Name);
if (I == StubIndexes.end())
return nullptr;
auto Key = I->second.first;
auto Flags = I->second.second;
auto StubSymbol = JITSymbol(getStubAddr(Key), Flags);
auto StubSymbol = JITEvaluatedSymbol(getStubAddr(Key), Flags);
if (ExportedStubsOnly && !StubSymbol.getFlags().isExported())
return nullptr;
return StubSymbol;
}
JITSymbol findPointer(StringRef Name) override {
JITEvaluatedSymbol findPointer(StringRef Name) override {
auto I = StubIndexes.find(Name);
if (I == StubIndexes.end())
return nullptr;
auto Key = I->second.first;
auto Flags = I->second.second;
return JITSymbol(getPtrAddr(Key), Flags);
return JITEvaluatedSymbol(getPtrAddr(Key), Flags);
}
Error updatePointer(StringRef Name, JITTargetAddress NewAddr) override {

View File

@ -36,11 +36,11 @@ public:
llvm_unreachable("Not implemented");
}
JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
llvm_unreachable("Not implemented");
}
JITSymbol findPointer(StringRef Name) override {
JITEvaluatedSymbol findPointer(StringRef Name) override {
llvm_unreachable("Not implemented");
}