MCJIT.h revision 5e206fcf3065950f081bd39a3116b3c3c3bbb9f7
1551ccae044b0ff658fe629dd67edd5ffe75d10e8Reid Spencer//===-- MCJIT.h - Class definition for the MCJIT ----------------*- C++ -*-===//
263b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman//
3b2109ce97881269a610fa4afbcbca350e975174dJohn Criswell//                     The LLVM Compiler Infrastructure
4b2109ce97881269a610fa4afbcbca350e975174dJohn Criswell//
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details.
763b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman//
8b2109ce97881269a610fa4afbcbca350e975174dJohn Criswell//===----------------------------------------------------------------------===//
995b923d548ed2e0f0993bb613868c871646f120cChris Lattner
1095b923d548ed2e0f0993bb613868c871646f120cChris Lattner#ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_H
1195b923d548ed2e0f0993bb613868c871646f120cChris Lattner#define LLVM_LIB_EXECUTIONENGINE_MCJIT_H
1295b923d548ed2e0f0993bb613868c871646f120cChris Lattner
1395b923d548ed2e0f0993bb613868c871646f120cChris Lattner#include "llvm/ADT/DenseMap.h"
1495b923d548ed2e0f0993bb613868c871646f120cChris Lattner#include "llvm/ADT/SmallVector.h"
1595b923d548ed2e0f0993bb613868c871646f120cChris Lattner#include "llvm/ExecutionEngine/ExecutionEngine.h"
1695b923d548ed2e0f0993bb613868c871646f120cChris Lattner#include "llvm/ExecutionEngine/ObjectCache.h"
1795b923d548ed2e0f0993bb613868c871646f120cChris Lattner#include "llvm/ExecutionEngine/ObjectImage.h"
1895b923d548ed2e0f0993bb613868c871646f120cChris Lattner#include "llvm/ExecutionEngine/RuntimeDyld.h"
1995b923d548ed2e0f0993bb613868c871646f120cChris Lattner#include "llvm/PassManager.h"
2095b923d548ed2e0f0993bb613868c871646f120cChris Lattner
2195b923d548ed2e0f0993bb613868c871646f120cChris Lattnernamespace llvm {
2295b923d548ed2e0f0993bb613868c871646f120cChris Lattner
23551ccae044b0ff658fe629dd67edd5ffe75d10e8Reid Spencerclass MCJIT;
24551ccae044b0ff658fe629dd67edd5ffe75d10e8Reid Spencer
2595b923d548ed2e0f0993bb613868c871646f120cChris Lattner// This is a helper class that the MCJIT execution engine uses for linking
26551ccae044b0ff658fe629dd67edd5ffe75d10e8Reid Spencer// functions across modules that it owns.  It aggregates the memory manager
27103289e9383ad1eb66caf28c9b166aebce963a35Chris Lattner// that is passed in to the MCJIT constructor and defers most functionality
28551ccae044b0ff658fe629dd67edd5ffe75d10e8Reid Spencer// to that object.
299d5b532de9bdca37810a59a93a69128441b02c55Reid Spencerclass LinkingMemoryManager : public RTDyldMemoryManager {
3052883e7a9a637c0d6dea091917090a8ac63e7736Bill Wendlingpublic:
31229509a8bc2390c4c9c1bd20f777acf29911d452David Greene  LinkingMemoryManager(MCJIT *Parent, RTDyldMemoryManager *MM)
3295b923d548ed2e0f0993bb613868c871646f120cChris Lattner    : ParentEngine(Parent), ClientMM(MM) {}
33d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
34d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke  virtual uint64_t getSymbolAddress(const std::string &Name);
3595b923d548ed2e0f0993bb613868c871646f120cChris Lattner
36103289e9383ad1eb66caf28c9b166aebce963a35Chris Lattner  // Functions deferred to client memory manager
3795b923d548ed2e0f0993bb613868c871646f120cChris Lattner  virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
3895b923d548ed2e0f0993bb613868c871646f120cChris Lattner                                       unsigned SectionID, StringRef SectionName) {
3900ad26ff5760ff2d1b24acb18718e63541088923David Greene    return ClientMM->allocateCodeSection(Size, Alignment, SectionID, SectionName);
4000ad26ff5760ff2d1b24acb18718e63541088923David Greene  }
4100ad26ff5760ff2d1b24acb18718e63541088923David Greene
4200ad26ff5760ff2d1b24acb18718e63541088923David Greene  virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
4300ad26ff5760ff2d1b24acb18718e63541088923David Greene                                       unsigned SectionID, StringRef SectionName,
4400ad26ff5760ff2d1b24acb18718e63541088923David Greene                                       bool IsReadOnly) {
4500ad26ff5760ff2d1b24acb18718e63541088923David Greene    return ClientMM->allocateDataSection(Size, Alignment,
4600ad26ff5760ff2d1b24acb18718e63541088923David Greene                                         SectionID, SectionName, IsReadOnly);
4700ad26ff5760ff2d1b24acb18718e63541088923David Greene  }
4865b660743ccce5393f70d3667ac4e2b0b76e5236Daniel Dunbar
4900ad26ff5760ff2d1b24acb18718e63541088923David Greene  virtual void notifyObjectLoaded(ExecutionEngine *EE,
50fe2cce63aa26d0916fa7be32c6bf7fa8fb059ee7Misha Brukman                                  const ObjectImage *Obj) {
5195b923d548ed2e0f0993bb613868c871646f120cChris Lattner    ClientMM->notifyObjectLoaded(EE, Obj);
528c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  }
53103289e9383ad1eb66caf28c9b166aebce963a35Chris Lattner
548c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  virtual void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) {
5595b923d548ed2e0f0993bb613868c871646f120cChris Lattner    ClientMM->registerEHFrames(Addr, LoadAddr, Size);
568c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  }
578c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner
588c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  virtual void deregisterEHFrames(uint8_t *Addr,
598c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner                                  uint64_t LoadAddr,
608c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner                                  size_t Size) {
61a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser    ClientMM->deregisterEHFrames(Addr, LoadAddr, Size);
62c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser  }
63c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser
64c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser  virtual bool finalizeMemory(std::string *ErrMsg = 0) {
65c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser    return ClientMM->finalizeMemory(ErrMsg);
66c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser  }
67c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser
68c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosserprivate:
69c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser  MCJIT *ParentEngine;
70c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser  OwningPtr<RTDyldMemoryManager> ClientMM;
71a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser};
72c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser
73c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// About Module states:
74c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser//
75c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// The purpose of the "added" state is having modules in standby. (added=known
76c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// but not compiled). The idea is that you can add a module to provide function
77c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// definitions but if nothing in that module is referenced by a module in which
78c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// a function is executed (note the wording here because it�s not exactly the
79c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// ideal case) then the module never gets compiled. This is sort of lazy
80c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// compilation.
81a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser//
82c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// The purpose of the "loaded" state (loaded=compiled and required sections
83c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// copied into local memory but not yet ready for execution) is to have an
84c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// intermediate state wherein clients can remap the addresses of sections, using
85c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// MCJIT::mapSectionAddress, (in preparation for later copying to a new location
86c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// or an external process) before relocations and page permissions are applied.
87c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser//
88c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// It might not be obvious at first glance, but the "remote-mcjit" case in the
89c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser// lli tool does this.  In that case, the intermediate action is taken by the
908c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner// RemoteMemoryManager in response to the notifyObjectLoaded function being
9156f4ef3232850e29c4635d0923910acce8887bd0Tobias Grosser// called.
92640e74207eb75ebc1f22b3cf1c1c39b32bbf232dDan Gohman
93640e74207eb75ebc1f22b3cf1c1c39b32bbf232dDan Gohmanclass MCJIT : public ExecutionEngine {
94dc05fffe2bbbdecf2e0dc0bb691b8967777edc9aChris Lattner  MCJIT(Module *M, TargetMachine *tm, RTDyldMemoryManager *MemMgr,
95cce563cf1cdbdcb470a1823f1e917960dde3aad6Dan Gohman        bool AllocateGVsWithCode);
96f7e2ca9e161140f658a2ae65ad67e508b703ac8cDan Gohman
97d73b908f263d538f380e7fbee508d4e9a1a71791Dan Gohman  enum ModuleState {
98f7e2ca9e161140f658a2ae65ad67e508b703ac8cDan Gohman    ModuleAdded,
99f7e2ca9e161140f658a2ae65ad67e508b703ac8cDan Gohman    ModuleEmitted,
100d73b908f263d538f380e7fbee508d4e9a1a71791Dan Gohman    ModuleLoading,
101f7e2ca9e161140f658a2ae65ad67e508b703ac8cDan Gohman    ModuleLoaded,
102f7e2ca9e161140f658a2ae65ad67e508b703ac8cDan Gohman    ModuleFinalizing,
103d73b908f263d538f380e7fbee508d4e9a1a71791Dan Gohman    ModuleFinalized
104f7e2ca9e161140f658a2ae65ad67e508b703ac8cDan Gohman  };
105f7e2ca9e161140f658a2ae65ad67e508b703ac8cDan Gohman
106d73b908f263d538f380e7fbee508d4e9a1a71791Dan Gohman  class MCJITModuleState {
107f7e2ca9e161140f658a2ae65ad67e508b703ac8cDan Gohman  public:
108f7e2ca9e161140f658a2ae65ad67e508b703ac8cDan Gohman    MCJITModuleState() : State(ModuleAdded) {}
1094c6809d8e38b9690898700085ebbd913e035c2e2Dan Gohman
110a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser    MCJITModuleState & operator=(ModuleState s) { State = s; return *this; }
111afbd0737e7593f1b79ed5060e506749558e82ab9Dan Gohman    bool hasBeenEmitted() { return State != ModuleAdded; }
1124c6809d8e38b9690898700085ebbd913e035c2e2Dan Gohman    bool hasBeenLoaded() { return State != ModuleAdded &&
1134c6809d8e38b9690898700085ebbd913e035c2e2Dan Gohman                                  State != ModuleEmitted; }
114afbd0737e7593f1b79ed5060e506749558e82ab9Dan Gohman    bool hasBeenFinalized() { return State == ModuleFinalized; }
115358f5ac9721f02eec68145bba012322ebc78d58cDan Gohman
116afbd0737e7593f1b79ed5060e506749558e82ab9Dan Gohman  private:
117afbd0737e7593f1b79ed5060e506749558e82ab9Dan Gohman    ModuleState State;
11895b923d548ed2e0f0993bb613868c871646f120cChris Lattner  };
119a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser
12089a1ed58399045d2b2c7b246571945b068f2e5e1Chris Lattner  TargetMachine *TM;
12189a1ed58399045d2b2c7b246571945b068f2e5e1Chris Lattner  MCContext *Ctx;
1224c6809d8e38b9690898700085ebbd913e035c2e2Dan Gohman  LinkingMemoryManager MemMgr;
1234c6809d8e38b9690898700085ebbd913e035c2e2Dan Gohman  RuntimeDyld Dyld;
1242d3ff5a7aee24024765629d17ebff351ea11c9bbDan Gohman  SmallVector<JITEventListener*, 2> EventListeners;
1258c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner
126a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser  typedef DenseMap<Module *, MCJITModuleState> ModuleStateMap;
1278c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  ModuleStateMap  ModuleStates;
1288c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner
1298c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  typedef DenseMap<Module *, ObjectImage *> LoadedObjectMap;
130dc05fffe2bbbdecf2e0dc0bb691b8967777edc9aChris Lattner  LoadedObjectMap  LoadedObjects;
1318c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner
1328c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  // An optional ObjectCache to be notified of compiled objects and used to
1338c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  // perform lookup of pre-compiled code to avoid re-compilation.
13495b923d548ed2e0f0993bb613868c871646f120cChris Lattner  ObjectCache *ObjCache;
1358c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner
1368c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattnerpublic:
1378c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  ~MCJIT();
1388c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner
13989938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  /// @name ExecutionEngine interface implementation
14089938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  /// @{
14189938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  virtual void addModule(Module *M);
14289938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman
14389938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  /// Sets the object manager that MCJIT should use to avoid compilation.
14489938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  virtual void setObjectCache(ObjectCache *manager);
14589938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman
14689938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  virtual void generateCodeForModule(Module *M);
14789938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman
14889938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  /// finalizeObject - ensure the module is fully processed and is usable.
14989938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  ///
15089938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  /// It is the user-level function for completing the process of making the
15189938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  /// object usable for execution. It should be called after sections within an
15289938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  /// object have been relocated using mapSectionAddress.  When this method is
15396345186a5fefff5c88195f6f2505232215b258eTed Kremenek  /// called the MCJIT execution engine will reapply relocations for a loaded
154fe2cce63aa26d0916fa7be32c6bf7fa8fb059ee7Misha Brukman  /// object.
15596345186a5fefff5c88195f6f2505232215b258eTed Kremenek  /// Is it OK to finalize a set of modules, add modules and finalize again.
15696345186a5fefff5c88195f6f2505232215b258eTed Kremenek  // FIXME: Do we really need both of these?
1578c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  virtual void finalizeObject();
15863b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman  virtual void finalizeModule(Module *);
159ce393a609ba1df701cfba9e96749275a16e22adeChris Lattner  void finalizeLoadedModules();
160ce393a609ba1df701cfba9e96749275a16e22adeChris Lattner
161ce393a609ba1df701cfba9e96749275a16e22adeChris Lattner  virtual void *getPointerToBasicBlock(BasicBlock *BB);
16263b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman
1638c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  virtual void *getPointerToFunction(Function *F);
164a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser
16563b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman  virtual void *recompileAndRelinkFunction(Function *F);
1667953f3781077b6feaba3708fb96ef917f8e8fc89Dan Gohman
16795b923d548ed2e0f0993bb613868c871646f120cChris Lattner  virtual void freeMachineCodeForFunction(Function *F);
16889a1ed58399045d2b2c7b246571945b068f2e5e1Chris Lattner
16989a1ed58399045d2b2c7b246571945b068f2e5e1Chris Lattner  virtual GenericValue runFunction(Function *F,
170a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser                                   const std::vector<GenericValue> &ArgValues);
17156f4ef3232850e29c4635d0923910acce8887bd0Tobias Grosser
17263b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman  /// getPointerToNamedFunction - This method returns the address of the
173f85a55b09657094a1e3954728c7f4ca5bdb6f56aChris Lattner  /// specified function by using the dlsym function call.  As such it is only
174a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser  /// useful for resolving library symbols, not code generated symbols.
175f85a55b09657094a1e3954728c7f4ca5bdb6f56aChris Lattner  ///
176f85a55b09657094a1e3954728c7f4ca5bdb6f56aChris Lattner  /// If AbortOnFailure is false and no function with the given name is
177f85a55b09657094a1e3954728c7f4ca5bdb6f56aChris Lattner  /// found, this function silently returns a null pointer. Otherwise,
178c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser  /// it prints a message to stderr and aborts.
179795eb2ae8eacba3d9d9e55353475b94de5d5d94cBenjamin Kramer  ///
180c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser  virtual void *getPointerToNamedFunction(const std::string &Name,
181c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser                                          bool AbortOnFailure = true);
182c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser
183a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser  /// mapSectionAddress - map a section to its target address space value.
18463b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman  /// Map the address of a JIT section as returned from the memory manager
185c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser  /// to the address in the target process as the running code will see it.
18663b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman  /// This is the address which will be used for relocation resolution.
187a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser  virtual void mapSectionAddress(const void *LocalAddress,
18895b923d548ed2e0f0993bb613868c871646f120cChris Lattner                                 uint64_t TargetAddress) {
189f85a55b09657094a1e3954728c7f4ca5bdb6f56aChris Lattner    Dyld.mapSectionAddress(LocalAddress, TargetAddress);
190a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser  }
19156f4ef3232850e29c4635d0923910acce8887bd0Tobias Grosser  virtual void RegisterJITEventListener(JITEventListener *L);
19263b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman  virtual void UnregisterJITEventListener(JITEventListener *L);
193f85a55b09657094a1e3954728c7f4ca5bdb6f56aChris Lattner
194a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser  // If successful, these function will implicitly finalize all loaded objects.
195f85a55b09657094a1e3954728c7f4ca5bdb6f56aChris Lattner  // To get a function address within MCJIT without causing a finalize, use
196f85a55b09657094a1e3954728c7f4ca5bdb6f56aChris Lattner  // getSymbolAddress.
197f85a55b09657094a1e3954728c7f4ca5bdb6f56aChris Lattner  virtual uint64_t getGlobalValueAddress(const std::string &Name);
198a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser  virtual uint64_t getFunctionAddress(const std::string &Name);
199358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman
200358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman  /// @}
201a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser  /// @name (Private) Registration Interfaces
202358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman  /// @{
203358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman
2045b296e307f71bcaf3d31eff4a04ba5d2016eb628Dan Gohman  static void Register() {
2055b296e307f71bcaf3d31eff4a04ba5d2016eb628Dan Gohman    MCJITCtor = createJIT;
206358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman  }
207358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman
208358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman  static ExecutionEngine *createJIT(Module *M,
209358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman                                    std::string *ErrorStr,
210358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman                                    RTDyldMemoryManager *MemMgr,
211358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman                                    bool GVsWithCode,
212358033102ffaef4d1afb1c0b7e96440906f0b48fDan Gohman                                    TargetMachine *TM);
213b78ea801cd762ede7586c6e8ae37f8009100289aJim Laskey
21463b3afa98460ce38a1c48d3c44ef6edfdaf37b77Misha Brukman  // @}
21595b923d548ed2e0f0993bb613868c871646f120cChris Lattner
216c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser  // This is not directly exposed via the ExecutionEngine API, but it is
217c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser  // used by the LinkingMemoryManager.
2188c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  uint64_t getSymbolAddress(const std::string &Name,
21989938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman                          bool CheckFunctionsOnly);
22089938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman
2216a6dd6f487bfda1fe8fbb4ab7cb0a9fa1fbadbcfChris Lattnerprotected:
22289938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  /// emitObject -- Generate a JITed object in memory from the specified module
22389938ce0ad6a0c13104495e2a00d3cc745e34068Dan Gohman  /// Currently, MCJIT only supports a single module and the module passed to
2248c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  /// this function call is expected to be the contained module.  The module
2258c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  /// is passed as a parameter here to prepare for multiple module support in
2268c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  /// the future.
2278c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  ObjectBufferStream* emitObject(Module *M);
22896f549310013eaf751ff401b5ad3cbe01542e9b1Chris Lattner
229a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser  void NotifyObjectEmitted(const ObjectImage& Obj);
230a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser  void NotifyFreeingObject(const ObjectImage& Obj);
2318c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner
2328c836ce4f86713376b626e30765494f0a4f7e4b3Chris Lattner  uint64_t getExistingSymbolAddress(const std::string &Name);
23334cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng  Module *findModuleForSymbol(const std::string &Name,
23434cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng                              bool CheckFunctionsOnly);
2358b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner};
23695b923d548ed2e0f0993bb613868c871646f120cChris Lattner
23796f549310013eaf751ff401b5ad3cbe01542e9b1Chris Lattner} // End llvm namespace
238a10d598602308549d87d2c5d9848f5a72fda2b43Tobias Grosser
239c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser#endif
240c500566d9fb70472a17f62b4cf1689062c52e095Tobias Grosser