LLVM  9.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, OnResolvedWithUnwrap,
40  [this](Error Err) { ES.reportError(std::move(Err)); });
41 
42  auto Unresolved = R.lookup(Q, InternedSymbols);
43  if (Unresolved.empty()) {
44  if (MR)
45  MR->addDependenciesForAll(Q->QueryRegistrations);
46  } else
47  ES.legacyFailQuery(*Q, make_error<SymbolsNotFound>(std::move(Unresolved)));
48 }
49 
52  SymbolNameSet InternedSymbols;
53  for (auto &S : Symbols)
54  InternedSymbols.insert(ES.intern(S));
55 
56  auto InternedResult = R.getResponsibilitySet(InternedSymbols);
57  LookupSet Result;
58  for (auto &S : InternedResult) {
59  ResolvedStrings.insert(S);
60  Result.insert(*S);
61  }
62 
63  return Result;
64 }
65 
66 } // End namespace orc.
67 } // End namespace llvm.
std::function< void(Expected< LookupResult >)> OnResolvedFunction
Definition: JITSymbol.h:347
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:345
Expected< LookupSet > getResponsibilitySet(const LookupSet &Symbols) override
Returns the subset of the given symbols that should be materialized by the caller.
Definition: Legacy.cpp:51
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:714
Tagged union holding either a T or a Error.
Definition: CachePruning.h:22
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:154
void legacyFailQuery(AsynchronousSymbolQuery &Q, Error Err)
Definition: Core.cpp:1634
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:503
An ExecutionSession represents a running JIT program.
Definition: Core.h:696
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.
void reportError(Error Err)
Report a error for this execution session.
Definition: Core.h:761
std::map< StringRef, JITEvaluatedSymbol > LookupResult
Definition: JITSymbol.h:346
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
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