LLVM  8.0.1
Legacy.cpp
Go to the documentation of this file.
1 //===------- Legacy.cpp - Adapters for ExecutionEngine API interop --------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 
12 namespace llvm {
13 namespace orc {
14 
15 void SymbolResolver::anchor() {}
16 
19  : ES(ES), R(R), MR(MR) {}
20 
22  OnResolvedFunction OnResolved) {
23  SymbolNameSet InternedSymbols;
24  for (auto &S : Symbols)
25  InternedSymbols.insert(ES.intern(S));
26 
27  auto OnResolvedWithUnwrap = [OnResolved](Expected<SymbolMap> InternedResult) {
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, OnResolvedWithUnwrap,
41  [this](Error Err) { ES.reportError(std::move(Err)); });
42 
43  auto Unresolved = R.lookup(Q, InternedSymbols);
44  if (Unresolved.empty()) {
45  if (MR)
46  MR->addDependenciesForAll(Q->QueryRegistrations);
47  } else
48  ES.legacyFailQuery(*Q, make_error<SymbolsNotFound>(std::move(Unresolved)));
49 }
50 
53  SymbolNameSet InternedSymbols;
54  for (auto &S : Symbols)
55  InternedSymbols.insert(ES.intern(S));
56 
57  auto InternedResult = R.getResponsibilitySet(InternedSymbols);
58  LookupSet Result;
59  for (auto &S : InternedResult) {
60  ResolvedStrings.insert(S);
61  Result.insert(*S);
62  }
63 
64  return Result;
65 }
66 
67 } // End namespace orc.
68 } // End namespace llvm.
std::function< void(Expected< LookupResult >)> OnResolvedFunction
Definition: JITSymbol.h:348
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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:346
Expected< LookupSet > getResponsibilitySet(const LookupSet &Symbols) override
Returns the subset of the given symbols that should be materialized by the caller.
Definition: Legacy.cpp:52
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:715
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:155
void legacyFailQuery(AsynchronousSymbolQuery &Q, Error Err)
Definition: Core.cpp:1596
JITSymbolResolverAdapter(ExecutionSession &ES, SymbolResolver &R, MaterializationResponsibility *MR)
Definition: Legacy.cpp:17
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:188
void addDependenciesForAll(const SymbolDependenceMap &Dependencies)
Add dependencies that apply to all symbols covered by this instance.
Definition: Core.cpp:496
An ExecutionSession represents a running JIT program.
Definition: Core.h:697
SymbolResolver is a composable interface for looking up symbol flags and addresses using the Asynchro...
Definition: Legacy.h:30
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:754
std::map< StringRef, JITEvaluatedSymbol > LookupResult
Definition: JITSymbol.h:347
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
void lookup(const LookupSet &Symbols, OnResolvedFunction OnResolved) override
Returns the fully resolved address and flags for each of the given symbols.
Definition: Legacy.cpp:21