LLVM: lib/ExecutionEngine/MCJIT/MCJIT.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_MCJIT_H

10#define LLVM_LIB_EXECUTIONENGINE_MCJIT_MCJIT_H

11

17

18namespace llvm {

22

23

24

25

26

28public:

30 std::shared_ptr Resolver)

31 : ParentEngine(Parent), ClientResolver(std::move(Resolver)) {}

32

34

35

39

40private:

41 MCJIT &ParentEngine;

42 std::shared_ptr ClientResolver;

43 void anchor() override;

44};

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

67 MCJIT(std::unique_ptr M, std::unique_ptr tm,

68 std::shared_ptr MemMgr,

69 std::shared_ptr Resolver);

70

72

73 class OwningModuleContainer {

74 public:

75 OwningModuleContainer() = default;

76 ~OwningModuleContainer() {

77 freeModulePtrSet(AddedModules);

78 freeModulePtrSet(LoadedModules);

79 freeModulePtrSet(FinalizedModules);

80 }

81

85 return make_range(begin_added(), end_added());

86 }

87

90

93

94 void addModule(std::unique_ptr M) {

95 AddedModules.insert(M.release());

96 }

97

99 return AddedModules.erase(M) || LoadedModules.erase(M) ||

100 FinalizedModules.erase(M);

101 }

102

103 bool hasModuleBeenAddedButNotLoaded(Module *M) {

104 return AddedModules.contains(M);

105 }

106

107 bool hasModuleBeenLoaded(Module *M) {

108

109

110 return LoadedModules.contains(M) || FinalizedModules.contains(M);

111 }

112

113 bool hasModuleBeenFinalized(Module *M) {

114 return FinalizedModules.contains(M);

115 }

116

117 bool ownsModule(Module* M) {

118 return AddedModules.contains(M) || LoadedModules.contains(M) ||

119 FinalizedModules.contains(M);

120 }

121

122 void markModuleAsLoaded(Module *M) {

123

124

125

127 "markModuleAsLoaded: Module not found in AddedModules");

128

129

130 AddedModules.erase(M);

131

132

133 LoadedModules.insert(M);

134 }

135

136 void markModuleAsFinalized(Module *M) {

137

138

139

140

142 "markModuleAsFinalized: Module not found in LoadedModules");

143

144

145 LoadedModules.erase(M);

146

147

148

149 FinalizedModules.insert(M);

150 }

151

152 void markAllLoadedModulesAsFinalized() {

153 FinalizedModules.insert_range(LoadedModules);

154 LoadedModules.clear();

155 }

156

157 private:

158 ModulePtrSet AddedModules;

159 ModulePtrSet LoadedModules;

160 ModulePtrSet FinalizedModules;

161

162 void freeModulePtrSet(ModulePtrSet& MPS) {

163

164 for (Module *M : MPS)

165 delete M;

167 }

168 };

169

170 std::unique_ptr TM;

172 std::shared_ptr MemMgr;

175 std::vector<JITEventListener*> EventListeners;

176

177 OwningModuleContainer OwnedModules;

178

181

183

184

185

187

191

193 bool AllowInternal,

196

197 void runStaticConstructorsDestructorsInModulePtrSet(bool isDtors,

200

201public:

203

204

205

206 void addModule(std::unique_ptr M) override;

207 void addObjectFile(std::unique_ptrobject::ObjectFile O) override;

211

212

213

214

216

217

218

219

221 bool AllowInternal = false) override;

222

223

225

227 Dyld.setProcessAllSections(ProcessAllSections);

228 }

229

231

232

233

234

235

236

237

238

239

240

244

245

246

247

248

250

252

255

256

257

258

259

260

261

262

263

265 bool AbortOnFailure = true) override;

266

267

268

269

270

272 uint64_t TargetAddress) override {

273 Dyld.mapSectionAddress(LocalAddress, TargetAddress);

274 }

277

278

279

280

283

285

286

287

288

289

293

295 createJIT(std::unique_ptr M, std::string *ErrorStr,

296 std::shared_ptr MemMgr,

297 std::shared_ptr Resolver,

298 std::unique_ptr TM);

299

300

301

302

303

305

306

307

308

309

310

311

312

314 bool CheckFunctionsOnly);

315

316protected:

317

318

319

320

321

323

327

330};

331

332}

333

334#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

This file defines the SmallPtrSet class.

This file defines the SmallVector class.

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

Abstract interface for implementation execution of LLVM modules, designed to support both interpreter...

static ExecutionEngine *(* MCJITCtor)(std::unique_ptr< Module > M, std::string *ErrorStr, std::shared_ptr< MCJITMemoryManager > MM, std::shared_ptr< LegacyJITSymbolResolver > SR, std::unique_ptr< TargetMachine > TM)

ExecutionEngine(DataLayout DL)

JITEventListener - Abstract interface for use by the JIT to notify clients about significant events d...

Represents a symbol in the JIT.

Legacy symbol resolution interface.

LinkingSymbolResolver(MCJIT &Parent, std::shared_ptr< LegacyJITSymbolResolver > Resolver)

Definition MCJIT.h:29

JITSymbol findSymbol(const std::string &Name) override

This method returns the address of the specified function or variable.

JITSymbol findSymbolInLogicalDylib(const std::string &Name) override

This method returns the address of the specified symbol if it exists within the logical dynamic libra...

Definition MCJIT.h:36

Context object for machine code objects.

GenericValue runFunction(Function *F, ArrayRef< GenericValue > ArgValues) override

runFunction - Execute the specified function with the specified arguments, and return the result.

void setProcessAllSections(bool ProcessAllSections) override

setProcessAllSections (MCJIT Only): By default, only sections that are "required for execution" are p...

Definition MCJIT.h:226

void * getPointerToNamedFunction(StringRef Name, bool AbortOnFailure=true) override

getPointerToNamedFunction - This method returns the address of the specified function by using the dl...

void RegisterJITEventListener(JITEventListener *L) override

Registers a listener to be called back on various events within the JIT.

static ExecutionEngine * createJIT(std::unique_ptr< Module > M, std::string *ErrorStr, std::shared_ptr< MCJITMemoryManager > MemMgr, std::shared_ptr< LegacyJITSymbolResolver > Resolver, std::unique_ptr< TargetMachine > TM)

void runStaticConstructorsDestructors(bool isDtors) override

runStaticConstructorsDestructors - This method is used to execute all of the static constructors or d...

Module * findModuleForSymbol(const std::string &Name, bool CheckFunctionsOnly)

void addArchive(object::OwningBinary< object::Archive > O) override

addArchive - Add an Archive to the execution engine.

Function * FindFunctionNamed(StringRef FnName) override

FindFunctionNamed - Search all of the active modules to find the function that defines FnName.

void finalizeObject() override

finalizeObject - ensure the module is fully processed and is usable.

void finalizeLoadedModules()

void notifyObjectLoaded(const object::ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &L)

void generateCodeForModule(Module *M) override

generateCodeForModule - Run code generation for the specified module and load it into memory.

uint64_t getFunctionAddress(const std::string &Name) override

getFunctionAddress - Return the address of the specified function.

void addObjectFile(std::unique_ptr< object::ObjectFile > O) override

addObjectFile - Add an ObjectFile to the execution engine.

std::unique_ptr< MemoryBuffer > emitObject(Module *M)

emitObject – Generate a JITed object in memory from the specified module Currently,...

TargetMachine * getTargetMachine() override

Return the target machine (if available).

Definition MCJIT.h:284

static void Register()

Definition MCJIT.h:290

void UnregisterJITEventListener(JITEventListener *L) override

bool removeModule(Module *M) override

removeModule - Removes a Module from the list of modules, but does not free the module's memory.

void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress) override

mapSectionAddress - map a section to its target address space value.

Definition MCJIT.h:271

JITSymbol findExistingSymbol(const std::string &Name)

GlobalVariable * FindGlobalVariableNamed(StringRef Name, bool AllowInternal=false) override

FindGlobalVariableNamed - Search all of the active modules to find the global variable that defines N...

uint64_t getGlobalValueAddress(const std::string &Name) override

getGlobalValueAddress - Return the address of the specified global value.

uint64_t getSymbolAddress(const std::string &Name, bool CheckFunctionsOnly)

void notifyFreeingObject(const object::ObjectFile &Obj)

virtual void finalizeModule(Module *)

JITSymbol findSymbol(const std::string &Name, bool CheckFunctionsOnly)

void * getPointerToFunction(Function *F) override

getPointerToFunction - The different EE's represent function bodies in different ways.

void setObjectCache(ObjectCache *manager) override

Sets the object manager that MCJIT should use to avoid compilation.

void addModule(std::unique_ptr< Module > M) override

Add a Module to the list of modules that we can JIT from.

A Module instance is used to store all the information related to an LLVM module.

This is the base ObjectCache type which can be provided to an ExecutionEngine for the purpose of avoi...

Interface for looking up the initializer for a variable name, used by Init::resolveReferences.

Information about the loaded object.

bool erase(PtrType Ptr)

Remove pointer from the set.

size_type count(ConstPtrType Ptr) const

count - Return 1 if the specified pointer is in the set, 0 otherwise.

void insert_range(Range &&R)

std::pair< iterator, bool > insert(PtrType Ptr)

Inserts Ptr if and only if there is no element in the container equal to Ptr.

SmallPtrSetIterator< PtrType > iterator

bool contains(ConstPtrType Ptr) const

SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

Primary interface to the complete machine description for the target machine.

A range adaptor for a pair of iterators.

This class is the base class for all object file types.

This is an optimization pass for GlobalISel generic memory operations.

iterator_range< T > make_range(T x, T y)

Convenience function for iterating over sub-ranges.

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

Implement std::hash so that hash_code can be used in STL containers.