mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
[Orc] Add conversion to/from RuntimeDyld::SymbolInfo for JITSymbol.
This tidies up some code that was manually constructing RuntimeDyld::SymbolInfo instances from JITSymbols. It will save more mess in the future when JITSymbol::getAddress is extended to return an Expected<TargetAddress> rather than just a TargetAddress, since we'll be able to embed the error checking in the conversion. llvm-svn: 271350
This commit is contained in:
parent
fa4e4af5c9
commit
96b587081e
@ -190,7 +190,7 @@ available for execution.
|
||||
auto Resolver = createLambdaResolver(
|
||||
[&](const std::string &Name) {
|
||||
if (auto Sym = CompileLayer.findSymbol(Name, false))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
return RuntimeDyld::SymbolInfo(nullptr);
|
||||
},
|
||||
[](const std::string &S) {
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
auto Resolver = createLambdaResolver(
|
||||
[&](const std::string &Name) {
|
||||
if (auto Sym = CompileLayer.findSymbol(Name, false))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
return RuntimeDyld::SymbolInfo(nullptr);
|
||||
},
|
||||
[](const std::string &Name) {
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
auto Resolver = createLambdaResolver(
|
||||
[&](const std::string &Name) {
|
||||
if (auto Sym = OptimizeLayer.findSymbol(Name, false))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
return RuntimeDyld::SymbolInfo(nullptr);
|
||||
},
|
||||
[](const std::string &Name) {
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
auto Resolver = createLambdaResolver(
|
||||
[&](const std::string &Name) {
|
||||
if (auto Sym = CODLayer.findSymbol(Name, false))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
return RuntimeDyld::SymbolInfo(nullptr);
|
||||
},
|
||||
[](const std::string &Name) {
|
||||
|
@ -106,9 +106,9 @@ public:
|
||||
auto Resolver = createLambdaResolver(
|
||||
[&](const std::string &Name) {
|
||||
if (auto Sym = IndirectStubsMgr->findStub(Name, false))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
if (auto Sym = OptimizeLayer.findSymbol(Name, false))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
return RuntimeDyld::SymbolInfo(nullptr);
|
||||
},
|
||||
[](const std::string &Name) {
|
||||
|
@ -122,9 +122,9 @@ public:
|
||||
auto Resolver = createLambdaResolver(
|
||||
[&](const std::string &Name) {
|
||||
if (auto Sym = IndirectStubsMgr->findStub(Name, false))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
if (auto Sym = OptimizeLayer.findSymbol(Name, false))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
return RuntimeDyld::SymbolInfo(nullptr);
|
||||
},
|
||||
[&](const std::string &Name) {
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
auto Resolver = createLambdaResolver(
|
||||
[&](const std::string &Name) {
|
||||
if (auto Sym = findMangledSymbol(Name))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
return RuntimeDyld::SymbolInfo(nullptr);
|
||||
},
|
||||
[](const std::string &S) { return nullptr; });
|
||||
|
@ -360,7 +360,7 @@ private:
|
||||
[&LD, LMH](const std::string &Name) {
|
||||
auto &LMResources = LD.getLogicalModuleResources(LMH);
|
||||
if (auto Sym = LMResources.StubsMgr->findStub(Name, false))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
auto &LDResolver = LD.getDylibResources().ExternalSymbolResolver;
|
||||
return LDResolver->findSymbolInLogicalDylib(Name);
|
||||
},
|
||||
@ -487,9 +487,8 @@ private:
|
||||
// Create memory manager and symbol resolver.
|
||||
auto Resolver = createLambdaResolver(
|
||||
[this, &LD, LMH](const std::string &Name) {
|
||||
if (auto Symbol = LD.findSymbolInternally(LMH, Name))
|
||||
return RuntimeDyld::SymbolInfo(Symbol.getAddress(),
|
||||
Symbol.getFlags());
|
||||
if (auto Sym = LD.findSymbolInternally(LMH, Name))
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
auto &LDResolver = LD.getDylibResources().ExternalSymbolResolver;
|
||||
return LDResolver->findSymbolInLogicalDylib(Name);
|
||||
},
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
|
||||
|
||||
#include "llvm/ExecutionEngine/JITSymbolFlags.h"
|
||||
#include "llvm/ExecutionEngine/RuntimeDyld.h"
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
@ -52,6 +53,10 @@ public:
|
||||
JITSymbol(GetAddressFtor GetAddress, JITSymbolFlags Flags)
|
||||
: JITSymbolBase(Flags), GetAddress(std::move(GetAddress)), CachedAddr(0) {}
|
||||
|
||||
/// @brief Create a JITSymbol from a RuntimeDyld::SymbolInfo.
|
||||
JITSymbol(const RuntimeDyld::SymbolInfo &Sym)
|
||||
: JITSymbolBase(Sym.getFlags()), CachedAddr(Sym.getAddress()) {}
|
||||
|
||||
/// @brief Returns true if the symbol exists, false otherwise.
|
||||
explicit operator bool() const { return CachedAddr || GetAddress; }
|
||||
|
||||
@ -66,6 +71,11 @@ public:
|
||||
return CachedAddr;
|
||||
}
|
||||
|
||||
/// @brief Convert this JITSymbol to a RuntimeDyld::SymbolInfo.
|
||||
RuntimeDyld::SymbolInfo toRuntimeDyldSymbol() {
|
||||
return RuntimeDyld::SymbolInfo(getAddress(), getFlags());
|
||||
}
|
||||
|
||||
private:
|
||||
GetAddressFtor GetAddress;
|
||||
TargetAddress CachedAddr;
|
||||
|
@ -57,8 +57,7 @@ protected:
|
||||
if (!Finalized)
|
||||
return JITSymbol(getSymbolMaterializer(Name),
|
||||
SymEntry->second.getFlags());
|
||||
return JITSymbol(SymEntry->second.getAddress(),
|
||||
SymEntry->second.getFlags());
|
||||
return JITSymbol(SymEntry->second);
|
||||
}
|
||||
protected:
|
||||
StringMap<RuntimeDyld::SymbolInfo> SymbolTable;
|
||||
|
@ -145,7 +145,7 @@ public:
|
||||
// 3. External resolver (if present).
|
||||
|
||||
if (auto Sym = CODLayer.findSymbol(Name, true))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
if (auto Sym = CXXRuntimeOverrides.searchOverrides(Name))
|
||||
return Sym;
|
||||
|
||||
|
@ -245,11 +245,11 @@ private:
|
||||
|
||||
RuntimeDyld::SymbolInfo findMangledSymbol(StringRef Name) {
|
||||
if (auto Sym = LazyEmitLayer.findSymbol(Name, false))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
if (auto Sym = ClientResolver->findSymbol(Name))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym;
|
||||
if (auto Sym = scanArchives(Name))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -83,8 +83,7 @@ public:
|
||||
orc::createLambdaResolver(
|
||||
[this](const std::string &Name) {
|
||||
if (auto Sym = CODLayer.findSymbol(Name, true))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(),
|
||||
Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
if (auto Sym = CXXRuntimeOverrides.searchOverrides(Name))
|
||||
return Sym;
|
||||
|
||||
|
@ -165,7 +165,7 @@ TEST_F(ObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
|
||||
createLambdaResolver(
|
||||
[&](const std::string &Name) {
|
||||
if (auto Sym = ObjLayer.findSymbol(Name, true))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
return Sym.toRuntimeDyldSymbol();
|
||||
return RuntimeDyld::SymbolInfo(nullptr);
|
||||
},
|
||||
[](const std::string &Name) {
|
||||
|
Loading…
Reference in New Issue
Block a user