blob: 9f9a6730b2c3071aa2477cd7cf856faa19c4357b [file] [log] [blame]
Lang Hames635fd902018-01-22 03:00:31 +00001//===------- Legacy.cpp - Adapters for ExecutionEngine API interop --------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Lang Hames635fd902018-01-22 03:00:31 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/ExecutionEngine/Orc/Legacy.h"
10
11namespace llvm {
12namespace orc {
13
Lang Hamesfd0c1e712018-07-20 18:31:50 +000014void SymbolResolver::anchor() {}
15
Lang Hamesd261e122018-05-16 22:24:30 +000016JITSymbolResolverAdapter::JITSymbolResolverAdapter(
17 ExecutionSession &ES, SymbolResolver &R, MaterializationResponsibility *MR)
18 : ES(ES), R(R), MR(MR) {}
Lang Hames635fd902018-01-22 03:00:31 +000019
Lang Hamesadde5ba2018-09-25 19:48:46 +000020void JITSymbolResolverAdapter::lookup(const LookupSet &Symbols,
21 OnResolvedFunction OnResolved) {
Lang Hames635fd902018-01-22 03:00:31 +000022 SymbolNameSet InternedSymbols;
23 for (auto &S : Symbols)
Lang Hames71d781c2018-09-30 23:18:24 +000024 InternedSymbols.insert(ES.intern(S));
Lang Hames635fd902018-01-22 03:00:31 +000025
Benjamin Kramerce74c3b2019-09-13 11:35:33 +000026 auto OnResolvedWithUnwrap = [OnResolved = std::move(OnResolved)](
27 Expected<SymbolMap> InternedResult) mutable {
Lang Hamesadde5ba2018-09-25 19:48:46 +000028 if (!InternedResult) {
29 OnResolved(InternedResult.takeError());
30 return;
31 }
32
33 LookupResult Result;
34 for (auto &KV : *InternedResult)
35 Result[*KV.first] = std::move(KV.second);
36 OnResolved(Result);
Lang Hames253584f2018-06-12 20:43:17 +000037 };
Lang Hames635fd902018-01-22 03:00:31 +000038
Lang Hamesadde5ba2018-09-25 19:48:46 +000039 auto Q = std::make_shared<AsynchronousSymbolQuery>(
Benjamin Kramerce74c3b2019-09-13 11:35:33 +000040 InternedSymbols, SymbolState::Resolved, std::move(OnResolvedWithUnwrap));
Lang Hamesadde5ba2018-09-25 19:48:46 +000041
42 auto Unresolved = R.lookup(Q, InternedSymbols);
43 if (Unresolved.empty()) {
Lang Hamesa48d1082018-07-20 22:22:19 +000044 if (MR)
Lang Hamesadde5ba2018-09-25 19:48:46 +000045 MR->addDependenciesForAll(Q->QueryRegistrations);
46 } else
47 ES.legacyFailQuery(*Q, make_error<SymbolsNotFound>(std::move(Unresolved)));
Lang Hames635fd902018-01-22 03:00:31 +000048}
49
Lang Hames6cadc7c2018-08-28 21:18:05 +000050Expected<JITSymbolResolverAdapter::LookupSet>
51JITSymbolResolverAdapter::getResponsibilitySet(const LookupSet &Symbols) {
Lang Hames635fd902018-01-22 03:00:31 +000052 SymbolNameSet InternedSymbols;
53 for (auto &S : Symbols)
Lang Hames71d781c2018-09-30 23:18:24 +000054 InternedSymbols.insert(ES.intern(S));
Lang Hames635fd902018-01-22 03:00:31 +000055
Lang Hames6cadc7c2018-08-28 21:18:05 +000056 auto InternedResult = R.getResponsibilitySet(InternedSymbols);
57 LookupSet Result;
58 for (auto &S : InternedResult) {
59 ResolvedStrings.insert(S);
60 Result.insert(*S);
Lang Hames635fd902018-01-22 03:00:31 +000061 }
62
63 return Result;
64}
65
66} // End namespace orc.
67} // End namespace llvm.