LLVM  10.0.0svn
Legacy.cpp
Go to the documentation of this file.
1 //===------- Legacy.cpp - Adapters for ExecutionEngine API interop --------===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 namespace llvm {
12 namespace orc {
13 
14 void SymbolResolver::anchor() {}
15 
18  : ES(ES), R(R), MR(MR) {}
19 
21  OnResolvedFunction OnResolved) {
22  SymbolNameSet InternedSymbols;
23  for (auto &S : Symbols)
24  InternedSymbols.insert(ES.intern(S));
25 
26  auto OnResolvedWithUnwrap = [OnResolved](Expected<SymbolMap> InternedResult) {
27  if (!InternedResult) {
28  OnResolved(InternedResult.takeError());
29  return;
30  }
31 
32  LookupResult Result;
33  for (auto &KV : *InternedResult)
34  Result[*KV.first] = std::move(KV.second);
35  OnResolved(Result);
36  };
37 
38  auto Q = std::make_shared<AsynchronousSymbolQuery>(
39  InternedSymbols, SymbolState::Resolved, OnResolvedWithUnwrap);
40 
41  auto Unresolved = R.lookup(Q, InternedSymbols);
42  if (Unresolved.empty()) {
43  if (MR)
44  MR->addDependenciesForAll(Q->QueryRegistrations);
45  } else
46  ES.legacyFailQuery(*Q, make_error<SymbolsNotFound>(std::move(Unresolved)));
47 }
48 
51  SymbolNameSet InternedSymbols;
52  for (auto &S : Symbols)
53  InternedSymbols.insert(ES.intern(S));
54 
55  auto InternedResult = R.getResponsibilitySet(InternedSymbols);
56  LookupSet Result;
57  for (auto &S : InternedResult) {
58  ResolvedStrings.insert(S);
59  Result.insert(*S);
60  }
61 
62  return Result;
63 }
64 
65 } // End namespace orc.
66 } // End namespace llvm.
Queried, materialization begun.
std::function< void(Expected< LookupResult >)> OnResolvedFunction
Definition: JITSymbol.h:328
This class represents lattice values for constants.
Definition: AllocatorList.h:23
virtual SymbolNameSet getResponsibilitySet(const SymbolNameSet &Symbols)=0
Returns the subset of the given symbols that the caller is responsible for materializing.
std::set< StringRef > LookupSet
Definition: JITSymbol.h:326
Expected< LookupSet > getResponsibilitySet(const LookupSet &Symbols) override
Returns the subset of the given symbols that should be materialized by the caller.
Definition: Legacy.cpp:50
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:761
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:171
void legacyFailQuery(AsynchronousSymbolQuery &Q, Error Err)
Definition: Core.cpp:1654
JITSymbolResolverAdapter(ExecutionSession &ES, SymbolResolver &R, MaterializationResponsibility *MR)
Definition: Legacy.cpp:16
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:187
void addDependenciesForAll(const SymbolDependenceMap &Dependencies)
Add dependencies that apply to all symbols covered by this instance.
Definition: Core.cpp:471
An ExecutionSession represents a running JIT program.
Definition: Core.h:743
SymbolResolver is a composable interface for looking up symbol flags and addresses using the Asynchro...
Definition: Legacy.h:29
virtual SymbolNameSet lookup(std::shared_ptr< AsynchronousSymbolQuery > Query, SymbolNameSet Symbols)=0
For each symbol in Symbols that can be found, assigns that symbols value in Query.
std::map< StringRef, JITEvaluatedSymbol > LookupResult
Definition: JITSymbol.h:327
void lookup(const LookupSet &Symbols, OnResolvedFunction OnResolved) override
Returns the fully resolved address and flags for each of the given symbols.
Definition: Legacy.cpp:20