llvm.org GIT mirror llvm / 9f2f142
simplify creation of the interpreter, make ExecutionEngine ctor protected, delete one ExecutionEngine ctor, minor cleanup. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44646 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
7 changed file(s) with 43 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #ifndef EXECUTION_ENGINE_H
15 #define EXECUTION_ENGINE_H
14 #ifndef LLVM_EXECUTION_ENGINE_H
15 #define LLVM_EXECUTION_ENGINE_H
1616
1717 #include
1818 #include
3333 class TargetData;
3434 class Type;
3535 class MutexGuard;
36 class JITMemoryManager;
3637
3738 class ExecutionEngineState {
3839 private:
8990 /// any of those classes.
9091 sys::Mutex lock; // Used to make this class and subclasses thread-safe
9192
92 ExecutionEngine(ModuleProvider *P);
93 ExecutionEngine(Module *M);
93 //===----------------------------------------------------------------------===//
94 // ExecutionEngine Startup
95 //===----------------------------------------------------------------------===//
96
9497 virtual ~ExecutionEngine();
9598
96 const TargetData *getTargetData() const { return TD; }
97
98 /// addModuleProvider - Add a ModuleProvider to the list of modules that we
99 /// can JIT from. Note that this takes ownership of the ModuleProvider: when
100 /// the ExecutionEngine is destroyed, it destroys the MP as well.
101 void addModuleProvider(ModuleProvider *P) {
102 Modules.push_back(P);
103 }
104
105 /// removeModuleProvider - Remove a ModuleProvider from the list of modules.
106 /// Release module from ModuleProvider.
107 Module* removeModuleProvider(ModuleProvider *P, std::string *ErrInfo = 0);
108
109 /// FindFunctionNamed - Search all of the active modules to find the one that
110 /// defines FnName. This is very slow operation and shouldn't be used for
111 /// general code.
112 Function *FindFunctionNamed(const char *FnName);
113
11499 /// create - This is the factory method for creating an execution engine which
115100 /// is appropriate for the current machine. This takes ownership of the
116101 /// module provider.
117102 static ExecutionEngine *create(ModuleProvider *MP,
118103 bool ForceInterpreter = false,
119104 std::string *ErrorStr = 0);
120
105
121106 /// create - This is the factory method for creating an execution engine which
122107 /// is appropriate for the current machine. This takes ownership of the
123108 /// module.
124109 static ExecutionEngine *create(Module *M);
110
111
112 /// addModuleProvider - Add a ModuleProvider to the list of modules that we
113 /// can JIT from. Note that this takes ownership of the ModuleProvider: when
114 /// the ExecutionEngine is destroyed, it destroys the MP as well.
115 void addModuleProvider(ModuleProvider *P) {
116 Modules.push_back(P);
117 }
118
119 //===----------------------------------------------------------------------===//
120
121 const TargetData *getTargetData() const { return TD; }
122
123
124 /// removeModuleProvider - Remove a ModuleProvider from the list of modules.
125 /// Release module from ModuleProvider.
126 Module* removeModuleProvider(ModuleProvider *P, std::string *ErrInfo = 0);
127
128 /// FindFunctionNamed - Search all of the active modules to find the one that
129 /// defines FnName. This is very slow operation and shouldn't be used for
130 /// general code.
131 Function *FindFunctionNamed(const char *FnName);
125132
126133 /// runFunction - Execute the specified function with the specified arguments,
127134 /// and return the result.
232239 }
233240
234241 protected:
242 ExecutionEngine(ModuleProvider *P);
243
235244 void emitGlobals();
236245
237246 // EmitGlobalVariable - This method emits the specified global variable to the
3636 LazyCompilationDisabled = false;
3737 Modules.push_back(P);
3838 assert(P && "ModuleProvider is null?");
39 }
40
41 ExecutionEngine::ExecutionEngine(Module *M) : LazyFunctionCreator(0) {
42 LazyCompilationDisabled = false;
43 assert(M && "Module is null?");
44 Modules.push_back(new ExistingModuleProvider(M));
4539 }
4640
4741 ExecutionEngine::~ExecutionEngine() {
3232 ///
3333 ExecutionEngine *Interpreter::create(ModuleProvider *MP, std::string* ErrStr) {
3434 // Tell this ModuleProvide to materialize and release the module
35 Module *M = MP->releaseModule(ErrStr);
36 if (!M)
35 if (!MP->materializeModule(ErrStr))
3736 // We got an error, just return 0
3837 return 0;
3938
40 // This is a bit nasty, but the ExecutionEngine won't be able to delete the
41 // module due to use/def issues if we don't delete this MP here. Below we
42 // construct a new Interpreter with the Module we just got. This creates a
43 // new ExistingModuleProvider in the EE instance. Consequently, MP is left
44 // dangling and it contains references into the module which cause problems
45 // when the module is deleted via the ExistingModuleProvide via EE.
46 delete MP;
47
48 return new Interpreter(M);
39 return new Interpreter(MP);
4940 }
5041
5142 //===----------------------------------------------------------------------===//
5243 // Interpreter ctor - Initialize stuff
5344 //
54 Interpreter::Interpreter(Module *M) : ExecutionEngine(M), TD(M) {
45 Interpreter::Interpreter(ModuleProvider *M)
46 : ExecutionEngine(M), TD(M->getModule()) {
5547
5648 memset(&ExitValue.Untyped, 0, sizeof(ExitValue.Untyped));
5749 setTargetData(&TD);
9393 std::vector AtExitHandlers;
9494
9595 public:
96 explicit Interpreter(Module *M);
96 explicit Interpreter(ModuleProvider *M);
9797 ~Interpreter();
9898
9999 /// runAtExitHandlers - Run any functions registered by the program's calls to
6565 setTargetData(TM.getTargetData());
6666
6767 // Initialize MCE
68 MCE = createEmitter(*this);
68 MCE = createEmitter(*this, 0);
6969
7070 // Add target data
7171 MutexGuard locked(lock);
120120 /// getCodeEmitter - Return the code emitter this JIT is emitting into.
121121 MachineCodeEmitter *getCodeEmitter() const { return MCE; }
122122 private:
123 static MachineCodeEmitter *createEmitter(JIT &J);
123 static MachineCodeEmitter *createEmitter(JIT &J, JITMemoryManager *JMM);
124124 void runJITOnFunction (Function *F);
125125 };
126126
311311 /// Resolver - This contains info about the currently resolved functions.
312312 JITResolver Resolver;
313313 public:
314 JITEmitter(JIT &jit) : Resolver(jit) {
315 MemMgr = JITMemoryManager::CreateDefaultMemManager();
314 JITEmitter(JIT &jit, JITMemoryManager *JMM) : Resolver(jit) {
315 MemMgr = JMM ? JMM : JITMemoryManager::CreateDefaultMemManager();
316316 if (jit.getJITInfo().needsGOT()) {
317317 MemMgr->AllocateGOT();
318318 DOUT << "JIT is managing a GOT\n";
636636 // Public interface to this file
637637 //===----------------------------------------------------------------------===//
638638
639 MachineCodeEmitter *JIT::createEmitter(JIT &jit) {
640 return new JITEmitter(jit);
639 MachineCodeEmitter *JIT::createEmitter(JIT &jit, JITMemoryManager *JMM) {
640 return new JITEmitter(jit, JMM);
641641 }
642642
643643 // getPointerToNamedFunction - This function is used as a global wrapper to