14 #ifndef LLVM_EXECUTIONENGINE_ORC_CORE_H 15 #define LLVM_EXECUTIONENGINE_ORC_CORE_H 32 class AsynchronousSymbolQuery;
33 class ExecutionSession;
34 class MaterializationUnit;
35 class MaterializationResponsibility;
51 using SymbolMap = std::map<SymbolStringPtr, JITEvaluatedSymbol>;
83 std::function<void(const SymbolDependenceMap &)>;
168 void failMaterialization();
175 void replace(std::unique_ptr<MaterializationUnit> MU);
208 : SymbolFlags(
std::move(InitalSymbolFlags)) {}
225 SymbolFlags.erase(Name);
226 discard(V, std::move(Name));
233 virtual void anchor();
248 std::vector<std::unique_ptr<MaterializationUnit>>;
276 inline std::unique_ptr<AbsoluteSymbolsMaterializationUnit>
278 return llvm::make_unique<AbsoluteSymbolsMaterializationUnit>(
285 : Aliasee(
std::move(Aliasee)), AliasFlags(AliasFlags) {}
312 VSO *SourceVSO =
nullptr;
328 inline std::unique_ptr<ReExportsMaterializationUnit>
330 return llvm::make_unique<ReExportsMaterializationUnit>(
nullptr,
336 inline std::unique_ptr<ReExportsMaterializationUnit>
338 return llvm::make_unique<ReExportsMaterializationUnit>(&SourceV,
358 std::function<void(VSO &V, std::unique_ptr<MaterializationUnit> MU)>;
371 std::lock_guard<std::recursive_mutex>
Lock(SessionMutex);
377 this->ReportError = std::move(ReportError);
384 this->DispatchMaterialization = std::move(DispatchMaterialization);
445 bool WaitUntilReady =
true);
449 std::unique_ptr<MaterializationUnit> MU) {
450 DispatchMaterialization(V, std::move(MU));
454 static void logErrorsToStdErr(
Error Err) {
459 materializeOnCurrentThread(
VSO &V, std::unique_ptr<MaterializationUnit> MU) {
460 MU->doMaterialize(V);
463 void runOutstandingMUs();
465 mutable std::recursive_mutex SessionMutex;
466 std::shared_ptr<SymbolStringPool> SSP;
470 materializeOnCurrentThread;
474 mutable std::recursive_mutex OutstandingMUsMutex;
475 std::vector<std::pair<VSO *, std::unique_ptr<MaterializationUnit>>>
506 void handleFullyResolved();
509 void notifySymbolReady();
517 void handleFullyReady();
526 void handleFailed(
Error Err);
534 size_t NotYetResolvedCount;
535 size_t NotYetReadyCount;
551 std::function<SymbolNameSet(VSO &Parent, const SymbolNameSet &Names)>;
554 std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
556 VSO(
const VSO &) =
delete;
557 VSO &operator=(
const VSO &) =
delete;
559 VSO &operator=(
VSO &&) =
delete;
562 const std::string &
getName()
const {
return VSOName; }
572 this->FallbackDefinitionGenerator = std::move(FallbackDefinitionGenerator);
593 void setSearchOrder(
VSOList NewSearchOrder,
bool SearchThisVSOFirst =
true);
596 void addToSearchOrder(
VSO &V);
600 void replaceInSearchOrder(
VSO &OldV,
VSO &NewV);
604 void removeFromSearchOrder(
VSO &V);
607 template <
typename Func>
609 -> decltype(
F(std::declval<const VSOList &>())) {
610 return ES.runSessionLocked([&]() {
return F(SearchOrder); });
615 template <
typename UniquePtrToMaterializationUnit>
616 typename std::enable_if<
618 typename std::decay<UniquePtrToMaterializationUnit>::type,
619 std::unique_ptr<MaterializationUnit>>::value,
621 define(UniquePtrToMaterializationUnit &&MU) {
622 return ES.runSessionLocked([&,
this]() ->
Error {
623 assert(MU &&
"Can't define with a null MU");
625 if (
auto Err = defineImpl(*MU))
629 auto UMI = std::make_shared<UnmaterializedInfo>(std::move(MU));
630 for (
auto &KV : UMI->MU->getSymbols())
631 UnmaterializedInfos[KV.first] = UMI;
652 SymbolNameSet legacyLookup(std::shared_ptr<AsynchronousSymbolQuery> Q,
656 using AsynchronousSymbolQueryList =
657 std::vector<std::shared_ptr<AsynchronousSymbolQuery>>;
659 struct UnmaterializedInfo {
660 UnmaterializedInfo(std::unique_ptr<MaterializationUnit> MU)
661 : MU(std::move(MU)) {}
663 std::unique_ptr<MaterializationUnit> MU;
666 using UnmaterializedInfosMap =
667 std::map<SymbolStringPtr, std::shared_ptr<UnmaterializedInfo>>;
669 struct MaterializingInfo {
670 AsynchronousSymbolQueryList PendingQueries;
673 bool IsFinalized =
false;
676 using MaterializingInfosMap = std::map<SymbolStringPtr, MaterializingInfo>;
678 using LookupImplActionFlags =
enum {
680 NotifyFullyResolved = 1 << 0U,
681 NotifyFullyReady = 1 << 1U,
692 void lodgeQuery(std::shared_ptr<AsynchronousSymbolQuery> &Q,
695 void lodgeQueryImpl(std::shared_ptr<AsynchronousSymbolQuery> &Q,
698 LookupImplActionFlags
699 lookupImpl(std::shared_ptr<AsynchronousSymbolQuery> &Q,
700 std::vector<std::unique_ptr<MaterializationUnit>> &MUs,
706 void transferFinalizedNodeDependencies(MaterializingInfo &DependantMI,
708 MaterializingInfo &FinalizedMI);
712 void replace(std::unique_ptr<MaterializationUnit> MU);
728 UnmaterializedInfosMap UnmaterializedInfos;
729 MaterializingInfosMap MaterializingInfos;
740 std::function<void(VSO &V, std::unique_ptr<MaterializationUnit> MU)>;
749 VSO &createVSO(std::string
Name);
752 std::vector<std::unique_ptr<VSO>> VSOs;
779 #endif // LLVM_EXECUTIONENGINE_ORC_CORE_H
JITSymbolFlags AliasFlags
std::enable_if< std::is_convertible< typename std::decay< UniquePtrToMaterializationUnit >::type, std::unique_ptr< MaterializationUnit > >::value, Error >::type define(UniquePtrToMaterializationUnit &&MU)
Define all symbols provided by the materialization unit to be part of the given VSO.
A parsed version of the target data layout string in and methods for querying it. ...
const SymbolNameSet & getSymbols() const
#define LLVM_MARK_AS_BITMASK_ENUM(LargestValue)
LLVM_MARK_AS_BITMASK_ENUM lets you opt in an individual enum type so you can perform bitwise operatio...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Compute iterated dominance frontiers using a linear time algorithm.
String pool for symbol names used by the JIT.
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases)
Create a ReExportsMaterializationUnit with the given aliases.
A symbol table that supports asynchoronous symbol queries.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner)
Log all errors (if any) in E to OS.
std::function< void(const SymbolDependenceMap &)> RegisterDependenciesFunction
Callback to register the dependencies for a given query.
auto runSessionLocked(Func &&F) -> decltype(F())
Run the given lambda with the session mutex locked.
ExecutionSessionBase & getExecutionSession() const
Get a reference to the ExecutionSession for this VSO.
void releaseVModule(VModuleKey Key)
Return a module key to the ExecutionSession so that it can be re-used.
std::map< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
MaterializationUnit(SymbolFlagsMap InitalSymbolFlags)
uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
Used to notify a VSO that the given set of symbols failed to materialize.
std::unique_ptr< ReExportsMaterializationUnit > reexports(VSO &SourceV, SymbolAliasMap Aliases)
Create a materialization unit for re-exporting symbols from another VSO with alternative names/flags...
std::function< void(Error)> ErrorReporter
For reporting errors.
std::map< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
SymbolFlagsMap SymbolFlags
Mangles symbol names then uniques them in the context of an ExecutionSession.
Tagged union holding either a T or a Error.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
virtual ~MaterializationUnit()
VModuleKey allocateVModule()
Allocate a module key for a new module to add to the JIT.
void reportError(Error Err)
Report a error for this execution session.
Pointer to a pooled string representing a symbol name.
std::function< void(VSO &V, std::unique_ptr< MaterializationUnit > MU)> DispatchMaterializationFunction
For dispatching MaterializationUnit::materialize calls.
std::set< std::shared_ptr< AsynchronousSymbolQuery > > AsynchronousSymbolQuerySet
Expected< SymbolAliasMap > buildSimpleReexportsAliasMap(VSO &SourceV, const SymbolNameSet &Symbols)
Build a SymbolAliasMap for the common case where you want to re-export symbols from another VSO with ...
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
A materialization unit for symbol aliases.
SymbolStringPool & getSymbolStringPool() const
Returns the SymbolStringPool for this ExecutionSession.
auto withSearchOrderDo(Func &&F) -> decltype(F(std::declval< const VSOList &>()))
Do something with the search order (run under the session lock).
FailedToMaterialize(SymbolNameSet Symbols)
std::function< void(Expected< SymbolMap >)> SymbolsResolvedCallback
Callback to notify client that symbols have been resolved.
Flags for symbols in the JIT.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Used to notify clients when symbols can not be found during a lookup.
ExecutionSessionBase & setDispatchMaterialization(DispatchMaterializationFunction DispatchMaterialization)
Set the materialization dispatch function.
VSO & getTargetVSO() const
Returns the target VSO that these symbols are being materialized into.
SymbolFlagsMap getSymbols()
Returns the symbol flags map for this responsibility instance.
void doMaterialize(VSO &V)
Called by materialization dispatchers (see ExecutionSession::DispatchMaterializationFunction) to trig...
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group...
static ErrorSuccess success()
Create a success value.
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Module.h This file contains the declarations for the Module class.
std::map< VSO *, SymbolNameSet > SymbolDependenceMap
A base class for materialization failures that allows the failing symbols to be obtained for logging...
Expected< SymbolMap > lookup(const VSOList &VSOs, SymbolNameSet Names)
Look up the given names in the given VSOs.
std::vector< VSO * > VSOList
A list of VSO pointers.
An ExecutionSession represents a running JIT program.
Base utilities for ExecutionSession.
Represents a symbol that has been evaluated to an address already.
Base class for user error types.
A symbol query that returns results via a callback when results are ready.
std::vector< std::unique_ptr< MaterializationUnit > > MaterializationUnitList
void doDiscard(const VSO &V, SymbolStringPtr Name)
Called by VSOs to notify MaterializationUnits that the given symbol has been overridden.
const SymbolFlagsMap & getSymbols() const
Return the set of symbols that this source provides.
ExecutionSessionBase(std::shared_ptr< SymbolStringPool > SSP=nullptr)
Construct an ExecutionSessionBase.
void setFallbackDefinitionGenerator(FallbackDefinitionGeneratorFunction FallbackDefinitionGenerator)
Set a fallback defenition generator.
A MaterializationUnit implementation for pre-existing absolute symbols.
std::function< SymbolNameSet(std::shared_ptr< AsynchronousSymbolQuery > Q, SymbolNameSet Names)> LegacyAsyncLookupFunction
ExecutionSessionBase & setErrorReporter(ErrorReporter ReportError)
Set the error reporter function.
const SymbolNameSet & getSymbols() const
bool isFullyReady() const
Returns true if all symbols covered by this query are ready.
const std::string & getName() const
Get the name for this VSO.
std::function< void(Error)> SymbolsReadyCallback
Callback to notify client that symbols are ready for execution.
std::function< SymbolNameSet(VSO &Parent, const SymbolNameSet &Names)> FallbackDefinitionGeneratorFunction
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
void dispatchMaterialization(VSO &V, std::unique_ptr< MaterializationUnit > MU)
Materialize the given unit.
This class implements an extremely fast bulk output stream that can only output to a stream...
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
static Expected< std::string > replace(StringRef S, StringRef From, StringRef To)
bool isFullyResolved() const
Returns true if all symbols covered by this query have been resolved.
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
SymbolAliasMapEntry(SymbolStringPtr Aliasee, JITSymbolFlags AliasFlags)
static void LLVM_ATTRIBUTE_NORETURN ReportError(uint32_t StartOffset, const char *ErrorMsg)
raw_ostream & operator<<(raw_ostream &OS, const SymbolNameSet &Symbols)
Render a SymbolNameSet to an ostream.
ExecutionSession(std::shared_ptr< SymbolStringPool > SSP=nullptr)
Construct an ExecutionEngine.
std::map< SymbolStringPtr, SymbolAliasMapEntry > SymbolAliasMap
A map of Symbols to (Symbol, Flags) pairs.
std::set< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.