LLVM: include/llvm/ExecutionEngine/Orc/Speculation.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_EXECUTIONENGINE_ORC_SPECULATION_H

14#define LLVM_EXECUTIONENGINE_ORC_SPECULATION_H

15

22#include

23#include

24

25namespace llvm {

26namespace orc {

27

29

30

31

32

33

36

37public:

38 using AliaseeDetails = std::pair<SymbolStringPtr, JITDylib *>;

42

43private:

44

45

46 std::optional getImplFor(const SymbolStringPtr &StubSymbol) {

47 std::lock_guardstd::mutex Lockit(ConcurrentAccess);

48 auto Position = Maps.find(StubSymbol);

49 if (Position != Maps.end())

50 return Position->getSecond();

51 else

52 return std::nullopt;

53 }

54

55 std::mutex ConcurrentAccess;

57};

58

59

61public:

65

66private:

67 void registerSymbolsWithAddr(TargetFAddr ImplAddr,

69 std::lock_guardstd::mutex Lockit(ConcurrentAccess);

70 GlobalSpecMap.insert({ImplAddr, std::move(likelySymbols)});

71 }

72

75

76

77 {

78 std::lock_guardstd::mutex Lockit(ConcurrentAccess);

79 auto It = GlobalSpecMap.find(FAddr);

80 if (It == GlobalSpecMap.end())

81 return;

82 CandidateSet = It->getSecond();

83 }

84

86

87 for (auto &Callee : CandidateSet) {

88 auto ImplSymbol = AliaseeImplTable.getImplFor(Callee);

89

90 if (!ImplSymbol)

91 continue;

92 const auto &ImplSymbolName = ImplSymbol->first;

93 JITDylib *ImplJD = ImplSymbol->second;

94 auto &SymbolsInJD = SpeculativeLookUpImpls[ImplJD];

95 SymbolsInJD.insert(ImplSymbolName);

96 }

97

99 for (auto &I : SpeculativeLookUpImpls) {

100 llvm::dbgs() << "\n In " << I.first->getName() << " JITDylib ";

101 for (auto &N : I.second)

102 llvm::dbgs() << "\n Likely Symbol : " << N;

103 }

104 });

105

106

107

108 for (auto &LookupPair : SpeculativeLookUpImpls)

114 [this](Expected Result) {

115 if (auto Err = Result.takeError())

116 ES.reportError(std::move(Err));

117 },

119 }

120

121public:

123 : AliaseeImplTable(Impl), ES(ref), GlobalSpecMap(0) {}

128

129

130

131

133

134

135

137

138

140 for (auto &SymPair : Candidates) {

141 auto Target = SymPair.first;

142 auto Likely = SymPair.second;

143

144 auto OnReadyFixUp = [Likely, Target,

146 if (ReadySymbol) {

147 auto RDef = (*ReadySymbol)[Target];

148 registerSymbolsWithAddr(RDef.getAddress(), std::move(Likely));

149 } else

151 };

152

153 ES.lookup(

158 }

159 }

160

162

163private:

164 static void speculateForEntryPoint(Speculator *Ptr, uint64_t StubId);

165 std::mutex ConcurrentAccess;

169};

170

172public:

174 std::optional<DenseMap<StringRef, DenseSet>>;

177

182

183 void emit(std::unique_ptr R,

185

186private:

187 TargetAndLikelies

189 assert(!IRNames.empty() && "No IRNames received to Intern?");

190 TargetAndLikelies InternedNames;

191 for (auto &NamePair : IRNames) {

193 for (auto &TargetNames : NamePair.second)

194 TargetJITNames.insert(Mangle(TargetNames));

195 InternedNames[Mangle(NamePair.first)] = std::move(TargetJITNames);

196 }

197 return InternedNames;

198 }

199

200 IRLayer &NextLayer;

201 Speculator &S;

202 MangleAndInterner &Mangle;

203 ResultEval QueryAnalysis;

204};

205

206}

207}

208

209#endif

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)

Definition Speculation.h:178

std::function< IRlikiesStrRef(Function &)> ResultEval

Definition Speculation.h:175

std::optional< DenseMap< StringRef, DenseSet< StringRef > > > IRlikiesStrRef

Definition Speculation.h:173

DenseMap< SymbolStringPtr, SymbolNameSet > TargetAndLikelies

Definition Speculation.h:176

Definition Speculation.h:34

LLVM_ABI void trackImpls(SymbolAliasMap ImplMaps, JITDylib *SrcJD)

friend class Speculator

Definition Speculation.h:35

SymbolStringPtr Alias

Definition Speculation.h:39

DenseMap< Alias, AliaseeDetails > ImapTy

Definition Speculation.h:40

std::pair< SymbolStringPtr, JITDylib * > AliaseeDetails

Definition Speculation.h:38

Represents a JIT'd dynamic library.

Mangles symbol names then uniques them in the context of an ExecutionSession.

Definition Speculation.h:60

Speculator(ImplSymbolMap &Impl, ExecutionSession &ref)

Definition Speculation.h:122

ExecutionSession & getES()

Definition Speculation.h:161

Speculator & operator=(const Speculator &)=delete

Speculator & operator=(Speculator &&)=delete

DenseMap< TargetFAddr, SymbolNameSet > StubAddrLikelies

Definition Speculation.h:64

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 ...

ExecutorAddr TargetFAddr

Definition Speculation.h:62

DenseMap< SymbolStringPtr, SymbolNameSet > FunctionCandidatesMap

Definition Speculation.h:63

Speculator(const Speculator &)=delete

void registerSymbols(FunctionCandidatesMap Candidates, JITDylib *JD)

Definition Speculation.h:139

void speculateFor(TargetFAddr StubAddr)

Definition Speculation.h:136

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.