Skip to content

Commit

Permalink
[Orc] Add conversion to/from RuntimeDyld::SymbolInfo for JITSymbol.
Browse files Browse the repository at this point in the history
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.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271350 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lhames committed May 31, 2016
1 parent 6aef9f9 commit 1fa1983
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/tutorial/BuildingAJIT1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class KaleidoscopeJIT {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class KaleidoscopeJIT {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class KaleidoscopeJIT {
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) {
Expand Down
4 changes: 2 additions & 2 deletions examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class KaleidoscopeJIT {
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) {
Expand Down
4 changes: 2 additions & 2 deletions examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ class KaleidoscopeJIT {
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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/Kaleidoscope/include/KaleidoscopeJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class KaleidoscopeJIT {
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; });
Expand Down
7 changes: 3 additions & 4 deletions include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class CompileOnDemandLayer {
[&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);
},
Expand Down Expand Up @@ -487,9 +487,8 @@ class CompileOnDemandLayer {
// 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);
},
Expand Down
10 changes: 10 additions & 0 deletions include/llvm/ExecutionEngine/Orc/JITSymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -52,6 +53,10 @@ class JITSymbol : public JITSymbolBase {
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; }

Expand All @@ -66,6 +71,11 @@ class JITSymbol : public JITSymbolBase {
return CachedAddr;
}

/// @brief Convert this JITSymbol to a RuntimeDyld::SymbolInfo.
RuntimeDyld::SymbolInfo toRuntimeDyldSymbol() {
return RuntimeDyld::SymbolInfo(getAddress(), getFlags());
}

private:
GetAddressFtor GetAddress;
TargetAddress CachedAddr;
Expand Down
3 changes: 1 addition & 2 deletions include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class ObjectLinkingLayerBase {
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;
Expand Down
2 changes: 1 addition & 1 deletion lib/ExecutionEngine/Orc/OrcCBindingsStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class OrcCBindingsStack {
// 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;

Expand Down
6 changes: 3 additions & 3 deletions lib/ExecutionEngine/Orc/OrcMCJITReplacement.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ class OrcMCJITReplacement : public ExecutionEngine {

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;
}
Expand Down
3 changes: 1 addition & 2 deletions tools/lli/OrcLazyJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ class OrcLazyJIT {
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;

Expand Down
2 changes: 1 addition & 1 deletion unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1fa1983

Please sign in to comment.