13#ifndef LLVM_EXECUTIONENGINE_ORC_SPECULATION_H
14#define LLVM_EXECUTIONENGINE_ORC_SPECULATION_H
47 std::optional<AliaseeDetails> getImplFor(
const SymbolStringPtr &StubSymbol) {
48 std::lock_guard<std::mutex> Lockit(ConcurrentAccess);
49 auto Position = Maps.find(StubSymbol);
50 if (Position != Maps.end())
51 return Position->getSecond();
56 std::mutex ConcurrentAccess;
70 std::lock_guard<std::mutex> Lockit(ConcurrentAccess);
71 GlobalSpecMap.insert({ImplAddr, std::move(likelySymbols)});
79 std::lock_guard<std::mutex> Lockit(ConcurrentAccess);
80 auto It = GlobalSpecMap.
find(FAddr);
81 if (It == GlobalSpecMap.
end())
83 CandidateSet = It->getSecond();
88 for (
auto &Callee : CandidateSet) {
89 auto ImplSymbol = AliaseeImplTable.getImplFor(Callee);
93 const auto &ImplSymbolName = ImplSymbol->first;
94 JITDylib *ImplJD = ImplSymbol->second;
95 auto &SymbolsInJD = SpeculativeLookUpImpls[ImplJD];
96 SymbolsInJD.insert(ImplSymbolName);
100 for (
auto &
I : SpeculativeLookUpImpls) {
101 llvm::dbgs() <<
"\n In " <<
I.first->getName() <<
" JITDylib ";
102 for (
auto &
N :
I.second)
109 for (
auto &LookupPair : SpeculativeLookUpImpls)
115 [
this](Expected<SymbolMap>
Result) {
116 if (auto Err = Result.takeError())
117 ES.reportError(std::move(Err));
124 : AliaseeImplTable(Impl), ES(ref), GlobalSpecMap(0) {}
141 for (
auto &SymPair : Candidates) {
142 auto Target = SymPair.first;
143 auto Likely = SymPair.second;
145 auto OnReadyFixUp = [Likely,
Target,
148 auto RDef = (*ReadySymbol)[
Target];
149 registerSymbolsWithAddr(RDef.getAddress(), std::move(Likely));
166 std::mutex ConcurrentAccess;
175 std::optional<DenseMap<StringRef, DenseSet<StringRef>>>;
184 void emit(std::unique_ptr<MaterializationResponsibility> R,
190 assert(!IRNames.empty() &&
"No IRNames received to Intern?");
191 TargetAndLikelies InternedNames;
192 for (
auto &NamePair : IRNames) {
194 for (
auto &TargetNames : NamePair.second)
195 TargetJITNames.
insert(Mangle(TargetNames));
196 InternedNames[Mangle(NamePair.first)] = std::move(TargetJITNames);
198 return InternedNames;
203 MangleAndInterner &Mangle;
204 ResultEval QueryAnalysis;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
Implements a dense probed hash-table based set.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
std::pair< iterator, bool > insert(const ValueT &V)
An ExecutionSession represents a running JIT program.
void reportError(Error Err)
Report a error for this execution session.
Represents an address in the executor process.
IRLayer(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions *&MO)
const IRSymbolMapper::ManglingOptions *& getManglingOptions() const
Get the mangling options for this layer.
IRSpeculationLayer(ExecutionSession &ES, IRLayer &BaseLayer, Speculator &Spec, MangleAndInterner &Mangle, ResultEval Interpreter)
std::function< IRlikiesStrRef(Function &)> ResultEval
std::optional< DenseMap< StringRef, DenseSet< StringRef > > > IRlikiesStrRef
DenseMap< SymbolStringPtr, SymbolNameSet > TargetAndLikelies
LLVM_ABI void trackImpls(SymbolAliasMap ImplMaps, JITDylib *SrcJD)
DenseMap< Alias, AliaseeDetails > ImapTy
std::pair< SymbolStringPtr, JITDylib * > AliaseeDetails
Represents a JIT'd dynamic library.
Mangles symbol names then uniques them in the context of an ExecutionSession.
Speculator(ImplSymbolMap &Impl, ExecutionSession &ref)
ExecutionSession & getES()
Speculator & operator=(const Speculator &)=delete
Speculator & operator=(Speculator &&)=delete
DenseMap< TargetFAddr, SymbolNameSet > StubAddrLikelies
Speculator(Speculator &&)=delete
LLVM_ABI Error addSpeculationRuntime(JITDylib &JD, MangleAndInterner &Mangle)
Define symbols for this Speculator object (__orc_speculator) and the speculation runtime entry point ...
DenseMap< SymbolStringPtr, SymbolNameSet > FunctionCandidatesMap
Speculator(const Speculator &)=delete
void registerSymbols(FunctionCandidatesMap Candidates, JITDylib *JD)
void speculateFor(TargetFAddr StubAddr)
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Pointer to a pooled string representing a symbol name.
An LLVM Module together with a shared ThreadSafeContext.
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
LLVM_ABI RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
DenseMap< JITDylib *, SymbolNameSet > SymbolDependenceMap
A map from JITDylibs to sets of symbols.
DenseSet< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.
@ Ready
Emitted to memory, but waiting on transitive dependencies.
DenseMap< SymbolStringPtr, SymbolAliasMapEntry > SymbolAliasMap
A map of Symbols to (Symbol, Flags) pairs.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.