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 = std::move(OnResolved)](
27  Expected<SymbolMap> InternedResult) mutable {
28  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);
37  };
38 
39  auto Q = std::make_shared<AsynchronousSymbolQuery>(
40  InternedSymbols, SymbolState::Resolved, std::move(OnResolvedWithUnwrap));
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.
Queried, materialization begun.
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:327
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:779
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:1852
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:477
An ExecutionSession represents a running JIT program.
Definition: Core.h:761
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:328
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