14 #ifndef LLVM_EXECUTIONENGINE_ORC_CORE_H 15 #define LLVM_EXECUTIONENGINE_ORC_CORE_H 26 #define DEBUG_TYPE "orc" 32 class AsynchronousSymbolQuery;
33 class ExecutionSession;
34 class MaterializationUnit;
35 class MaterializationResponsibility;
99 std::function<void(const SymbolDependenceMap &)>;
212 void failMaterialization();
219 void replace(std::unique_ptr<MaterializationUnit> MU);
255 : SymbolFlags(
std::move(InitalSymbolFlags)), K(
std::move(K)) {}
277 SymbolFlags.erase(Name);
278 discard(JD, std::move(Name));
286 virtual void anchor();
301 std::vector<std::unique_ptr<MaterializationUnit>>;
331 inline std::unique_ptr<AbsoluteSymbolsMaterializationUnit>
333 return llvm::make_unique<AbsoluteSymbolsMaterializationUnit>(
334 std::move(Symbols), std::move(K));
340 : Aliasee(
std::move(Aliasee)), AliasFlags(AliasFlags) {}
372 bool MatchNonExported =
false;
387 inline std::unique_ptr<ReExportsMaterializationUnit>
389 return llvm::make_unique<ReExportsMaterializationUnit>(
390 nullptr,
true, std::move(Aliases), std::move(K));
398 inline std::unique_ptr<ReExportsMaterializationUnit>
401 return llvm::make_unique<ReExportsMaterializationUnit>(
402 &SourceJD, MatchNonExported, std::move(Aliases), std::move(K));
426 bool MatchNonExported =
false;
458 void handleFullyResolved();
461 void notifySymbolReady();
469 void handleFullyReady();
478 void handleFailed(
Error Err);
486 size_t NotYetResolvedCount;
487 size_t NotYetReadyCount;
505 std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
513 const std::string &
getName()
const {
return JITDylibName; }
523 this->DefGenerator = std::move(DefGenerator);
546 bool SearchThisJITDylibFirst =
true,
547 bool MatchNonExportedInThisDylib =
true);
551 void addToSearchOrder(
JITDylib &JD,
bool MatcNonExported =
false);
556 bool MatchNonExported =
false);
560 void removeFromSearchOrder(
JITDylib &JD);
563 template <
typename Func>
564 auto withSearchOrderDo(Func &&
F)
565 -> decltype(
F(std::declval<const JITDylibSearchList &>()));
572 template <
typename MaterializationUnitType>
573 Error define(std::unique_ptr<MaterializationUnitType> &&MU);
582 template <
typename MaterializationUnitType>
583 Error define(std::unique_ptr<MaterializationUnitType> &MU);
612 SymbolNameSet legacyLookup(std::shared_ptr<AsynchronousSymbolQuery> Q,
616 using AsynchronousSymbolQueryList =
617 std::vector<std::shared_ptr<AsynchronousSymbolQuery>>;
619 struct UnmaterializedInfo {
620 UnmaterializedInfo(std::unique_ptr<MaterializationUnit> MU)
621 : MU(std::move(MU)) {}
623 std::unique_ptr<MaterializationUnit> MU;
629 struct MaterializingInfo {
630 AsynchronousSymbolQueryList PendingQueries;
633 bool IsEmitted =
false;
638 using LookupImplActionFlags =
enum {
640 NotifyFullyResolved = 1 << 0U,
641 NotifyFullyReady = 1 << 1U,
652 void lodgeQuery(std::shared_ptr<AsynchronousSymbolQuery> &Q,
656 void lodgeQueryImpl(std::shared_ptr<AsynchronousSymbolQuery> &Q,
660 LookupImplActionFlags
661 lookupImpl(std::shared_ptr<AsynchronousSymbolQuery> &Q,
662 std::vector<std::unique_ptr<MaterializationUnit>> &MUs,
668 void transferEmittedNodeDependencies(MaterializingInfo &DependantMI,
670 MaterializingInfo &EmittedMI);
674 void replace(std::unique_ptr<MaterializationUnit> MU);
688 std::string JITDylibName;
707 JITDylib &JD, std::unique_ptr<MaterializationUnit> MU)>;
722 std::lock_guard<std::recursive_mutex>
Lock(SessionMutex);
732 bool AddToMainDylibSearchOrder =
true);
736 return runSessionLocked([
this]() {
return ++LastKey; });
747 this->ReportError = std::move(ReportError);
759 this->DispatchMaterialization = std::move(DispatchMaterialization);
811 NoDependenciesToRegister,
812 bool WaitUntilReady =
true);
834 std::unique_ptr<MaterializationUnit> MU) {
836 dbgs() <<
"Compiling, for " << JD.
getName() <<
", " << *MU
839 DispatchMaterialization(JD, std::move(MU));
846 static void logErrorsToStdErr(
Error Err) {
851 materializeOnCurrentThread(
JITDylib &JD,
852 std::unique_ptr<MaterializationUnit> MU) {
853 MU->doMaterialize(JD);
856 void runOutstandingMUs();
858 mutable std::recursive_mutex SessionMutex;
859 std::shared_ptr<SymbolStringPool> SSP;
863 materializeOnCurrentThread;
865 std::vector<std::unique_ptr<JITDylib>> JDs;
869 mutable std::recursive_mutex OutstandingMUsMutex;
870 std::vector<std::pair<JITDylib *, std::unique_ptr<MaterializationUnit>>>
874 template <
typename Func>
876 -> decltype(
F(std::declval<const JITDylibSearchList &>())) {
877 return ES.runSessionLocked([&]() {
return F(SearchOrder); });
880 template <
typename MaterializationUnitType>
882 assert(MU &&
"Can not define with a null MU");
883 return ES.runSessionLocked([&,
this]() ->
Error {
884 if (
auto Err = defineImpl(*MU))
888 auto UMI = std::make_shared<UnmaterializedInfo>(std::move(MU));
889 for (
auto &KV : UMI->MU->getSymbols())
890 UnmaterializedInfos[KV.first] = UMI;
896 template <
typename MaterializationUnitType>
898 assert(MU &&
"Can not define with a null MU");
900 return ES.runSessionLocked([&,
this]() ->
Error {
901 if (
auto Err = defineImpl(*MU))
905 auto UMI = std::make_shared<UnmaterializedInfo>(std::move(MU));
906 for (
auto &KV : UMI->MU->getSymbols())
907 UnmaterializedInfos[KV.first] = UMI;
928 #undef DEBUG_TYPE // "orc" 930 #endif // LLVM_EXECUTIONENGINE_ORC_CORE_H
JITSymbolFlags AliasFlags
A parsed version of the target data layout string in and methods for querying it. ...
std::shared_ptr< SymbolStringPool > getSymbolStringPool() const
Returns a shared_ptr to the SymbolStringPool for this ExecutionSession.
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...
ExecutionSession & setDispatchMaterialization(DispatchMaterializationFunction DispatchMaterialization)
Set the materialization dispatch function.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
This class represents lattice values for constants.
void dispatchMaterialization(JITDylib &JD, std::unique_ptr< MaterializationUnit > MU)
Materialize the given unit.
Implements a dense probed hash-table based set.
std::function< void(const SymbolDependenceMap &)> RegisterDependenciesFunction
Callback to register the dependencies for a given query.
void doDiscard(const JITDylib &JD, const SymbolStringPtr &Name)
Called by JITDylibs to notify MaterializationUnits that the given symbol has been overridden...
void setGenerator(GeneratorFunction DefGenerator)
Set a definition generator.
uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
Used to notify a JITDylib that the given set of symbols failed to materialize.
std::function< bool(SymbolStringPtr)> SymbolPredicate
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols, VModuleKey K=VModuleKey())
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
void doMaterialize(JITDylib &JD)
Called by materialization dispatchers (see ExecutionSession::DispatchMaterializationFunction) to trig...
amdgpu Simplify well known AMD library false Value Value const Twine & Name
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
std::function< SymbolNameSet(JITDylib &Parent, const SymbolNameSet &Names)> GeneratorFunction
std::vector< std::pair< JITDylib *, bool > > JITDylibSearchList
A list of (JITDylib*, bool) pairs.
SymbolFlagsMap SymbolFlags
Error define(std::unique_ptr< MaterializationUnitType > &&MU)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Mangles symbol names then uniques them in the context of an ExecutionSession.
static StringRef getName(Value *V)
raw_ostream & operator<<(raw_ostream &OS, const SymbolStringPtr &Sym)
Render a SymbolStringPtr.
Tagged union holding either a T or a Error.
std::function< SymbolNameSet(std::shared_ptr< AsynchronousSymbolQuery > Q, SymbolNameSet Names)> LegacyAsyncLookupFunction
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
virtual ~MaterializationUnit()
void releaseVModule(VModuleKey Key)
Return a module key to the ExecutionSession so that it can be re-used.
auto withSearchOrderDo(Func &&F) -> decltype(F(std::declval< const JITDylibSearchList &>()))
Do something with the search order (run under the session lock).
std::set< std::shared_ptr< AsynchronousSymbolQuery > > AsynchronousSymbolQuerySet
llvm::detail::DenseMapPair< SymbolStringPtr, JITSymbolFlags > value_type
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Legacy adapter. Remove once we kill off the old ORC layers.
JITDylib & getTargetJITDylib() const
Returns the target JITDylib that these symbols are being materialized into.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
std::unique_ptr< ReExportsMaterializationUnit > reexports(JITDylib &SourceJD, SymbolAliasMap Aliases, bool MatchNonExported=false, VModuleKey K=VModuleKey())
Create a materialization unit for re-exporting symbols from another JITDylib with alternative names/f...
Expected< SymbolAliasMap > buildSimpleReexportsAliasMap(JITDylib &SourceJD, const SymbolNameSet &Symbols)
Build a SymbolAliasMap for the common case where you want to re-export symbols from another JITDylib ...
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases, VModuleKey K=VModuleKey())
Create a ReExportsMaterializationUnit with the given aliases.
Pointer to a pooled string representing a symbol name.
DenseSet< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
VModuleKey getVModuleKey() const
Returns the VModuleKey for this instance.
A materialization unit for symbol aliases.
const SymbolNameSet & getSymbols() const
FailedToMaterialize(SymbolNameSet Symbols)
VModuleKey allocateVModule()
Allocate a module key for a new module to add to the JIT.
std::function< void(Expected< SymbolMap >)> SymbolsResolvedCallback
Callback to notify client that symbols have been resolved.
Flags for symbols in the JIT.
static void replace(Module &M, GlobalVariable *Old, GlobalVariable *New)
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.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group...
static ErrorSuccess success()
Create a success value.
Module.h This file contains the declarations for the Module class.
An ExecutionSession represents a running JIT program.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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
const SymbolFlagsMap & getSymbols() const
Return the set of symbols that this source provides.
void reportError(Error Err)
Report a error for this execution session.
auto runSessionLocked(Func &&F) -> decltype(F())
Run the given lambda with the session mutex locked.
A MaterializationUnit implementation for pre-existing absolute symbols.
const std::string & getName() const
Get the name for this JITDylib.
ExecutionSession & 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.
std::function< void(Error)> SymbolsReadyCallback
Callback to notify client that symbols are ready for execution.
MaterializationUnit(SymbolFlagsMap InitalSymbolFlags, VModuleKey K)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const SymbolFlagsMap & getSymbols()
Returns the symbol flags map for this responsibility instance.
Lightweight error class with error context and mandatory checking.
Used to notify clients that a set of symbols could not be removed.
std::function< void(Error)> ErrorReporter
For reporting errors.
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.
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)
std::function< void(JITDylib &JD, std::unique_ptr< MaterializationUnit > MU)> DispatchMaterializationFunction
For dispatching MaterializationUnit::materialize calls.
A symbol table that supports asynchoronous symbol queries.
ReexportsGenerator can be used with JITDylib::setGenerator to automatically re-export a subset of the...