llvm.org GIT mirror llvm / 1fa1983
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271350 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 3 years ago
14 changed file(s) with 29 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
189189 auto Resolver = createLambdaResolver(
190190 [&](const std::string &Name) {
191191 if (auto Sym = CompileLayer.findSymbol(Name, false))
192 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
192 return Sym.toRuntimeDyldSymbol();
193193 return RuntimeDyld::SymbolInfo(nullptr);
194194 },
195195 [](const std::string &S) {
6161 auto Resolver = createLambdaResolver(
6262 [&](const std::string &Name) {
6363 if (auto Sym = CompileLayer.findSymbol(Name, false))
64 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
64 return Sym.toRuntimeDyldSymbol();
6565 return RuntimeDyld::SymbolInfo(nullptr);
6666 },
6767 [](const std::string &Name) {
7171 auto Resolver = createLambdaResolver(
7272 [&](const std::string &Name) {
7373 if (auto Sym = OptimizeLayer.findSymbol(Name, false))
74 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
74 return Sym.toRuntimeDyldSymbol();
7575 return RuntimeDyld::SymbolInfo(nullptr);
7676 },
7777 [](const std::string &Name) {
8181 auto Resolver = createLambdaResolver(
8282 [&](const std::string &Name) {
8383 if (auto Sym = CODLayer.findSymbol(Name, false))
84 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
84 return Sym.toRuntimeDyldSymbol();
8585 return RuntimeDyld::SymbolInfo(nullptr);
8686 },
8787 [](const std::string &Name) {
105105 auto Resolver = createLambdaResolver(
106106 [&](const std::string &Name) {
107107 if (auto Sym = IndirectStubsMgr->findStub(Name, false))
108 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
108 return Sym.toRuntimeDyldSymbol();
109109 if (auto Sym = OptimizeLayer.findSymbol(Name, false))
110 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
110 return Sym.toRuntimeDyldSymbol();
111111 return RuntimeDyld::SymbolInfo(nullptr);
112112 },
113113 [](const std::string &Name) {
121121 auto Resolver = createLambdaResolver(
122122 [&](const std::string &Name) {
123123 if (auto Sym = IndirectStubsMgr->findStub(Name, false))
124 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
124 return Sym.toRuntimeDyldSymbol();
125125 if (auto Sym = OptimizeLayer.findSymbol(Name, false))
126 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
126 return Sym.toRuntimeDyldSymbol();
127127 return RuntimeDyld::SymbolInfo(nullptr);
128128 },
129129 [&](const std::string &Name) {
5959 auto Resolver = createLambdaResolver(
6060 [&](const std::string &Name) {
6161 if (auto Sym = findMangledSymbol(Name))
62 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
62 return Sym.toRuntimeDyldSymbol();
6363 return RuntimeDyld::SymbolInfo(nullptr);
6464 },
6565 [](const std::string &S) { return nullptr; });
359359 [&LD, LMH](const std::string &Name) {
360360 auto &LMResources = LD.getLogicalModuleResources(LMH);
361361 if (auto Sym = LMResources.StubsMgr->findStub(Name, false))
362 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
362 return Sym.toRuntimeDyldSymbol();
363363 auto &LDResolver = LD.getDylibResources().ExternalSymbolResolver;
364364 return LDResolver->findSymbolInLogicalDylib(Name);
365365 },
486486 // Create memory manager and symbol resolver.
487487 auto Resolver = createLambdaResolver(
488488 [this, &LD, LMH](const std::string &Name) {
489 if (auto Symbol = LD.findSymbolInternally(LMH, Name))
490 return RuntimeDyld::SymbolInfo(Symbol.getAddress(),
491 Symbol.getFlags());
489 if (auto Sym = LD.findSymbolInternally(LMH, Name))
490 return Sym.toRuntimeDyldSymbol();
492491 auto &LDResolver = LD.getDylibResources().ExternalSymbolResolver;
493492 return LDResolver->findSymbolInLogicalDylib(Name);
494493 },
1414 #define LLVM_EXECUTIONENGINE_ORC_JITSYMBOL_H
1515
1616 #include "llvm/ExecutionEngine/JITSymbolFlags.h"
17 #include "llvm/ExecutionEngine/RuntimeDyld.h"
1718 #include "llvm/Support/DataTypes.h"
1819 #include
1920 #include
5152 JITSymbol(GetAddressFtor GetAddress, JITSymbolFlags Flags)
5253 : JITSymbolBase(Flags), GetAddress(std::move(GetAddress)), CachedAddr(0) {}
5354
55 /// @brief Create a JITSymbol from a RuntimeDyld::SymbolInfo.
56 JITSymbol(const RuntimeDyld::SymbolInfo &Sym)
57 : JITSymbolBase(Sym.getFlags()), CachedAddr(Sym.getAddress()) {}
58
5459 /// @brief Returns true if the symbol exists, false otherwise.
5560 explicit operator bool() const { return CachedAddr || GetAddress; }
5661
6570 return CachedAddr;
6671 }
6772
73 /// @brief Convert this JITSymbol to a RuntimeDyld::SymbolInfo.
74 RuntimeDyld::SymbolInfo toRuntimeDyldSymbol() {
75 return RuntimeDyld::SymbolInfo(getAddress(), getFlags());
76 }
77
6878 private:
6979 GetAddressFtor GetAddress;
7080 TargetAddress CachedAddr;
5656 if (!Finalized)
5757 return JITSymbol(getSymbolMaterializer(Name),
5858 SymEntry->second.getFlags());
59 return JITSymbol(SymEntry->second.getAddress(),
60 SymEntry->second.getFlags());
59 return JITSymbol(SymEntry->second);
6160 }
6261 protected:
6362 StringMap SymbolTable;
144144 // 3. External resolver (if present).
145145
146146 if (auto Sym = CODLayer.findSymbol(Name, true))
147 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
147 return Sym.toRuntimeDyldSymbol();
148148 if (auto Sym = CXXRuntimeOverrides.searchOverrides(Name))
149149 return Sym;
150150
244244
245245 RuntimeDyld::SymbolInfo findMangledSymbol(StringRef Name) {
246246 if (auto Sym = LazyEmitLayer.findSymbol(Name, false))
247 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
247 return Sym.toRuntimeDyldSymbol();
248248 if (auto Sym = ClientResolver->findSymbol(Name))
249 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
249 return Sym;
250250 if (auto Sym = scanArchives(Name))
251 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
251 return Sym.toRuntimeDyldSymbol();
252252
253253 return nullptr;
254254 }
8282 orc::createLambdaResolver(
8383 [this](const std::string &Name) {
8484 if (auto Sym = CODLayer.findSymbol(Name, true))
85 return RuntimeDyld::SymbolInfo(Sym.getAddress(),
86 Sym.getFlags());
85 return Sym.toRuntimeDyldSymbol();
8786 if (auto Sym = CXXRuntimeOverrides.searchOverrides(Name))
8887 return Sym;
8988
164164 createLambdaResolver(
165165 [&](const std::string &Name) {
166166 if (auto Sym = ObjLayer.findSymbol(Name, true))
167 return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
167 return Sym.toRuntimeDyldSymbol();
168168 return RuntimeDyld::SymbolInfo(nullptr);
169169 },
170170 [](const std::string &Name) {