llvm.org GIT mirror llvm / d958a5a
add a mechanism for the JIT to invoke a function to lazily create functions as they are referenced. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43210 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
3 changed file(s) with 21 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
6363 const TargetData *TD;
6464 ExecutionEngineState state;
6565 bool LazyCompilationDisabled;
66
6667 protected:
6768 /// Modules - This is a list of ModuleProvider's that we are JIT'ing from. We
6869 /// use a smallvector to optimize for the case where there is only one module.
7778 // at startup time if they are linked in.
7879 typedef ExecutionEngine *(*EECtorFn)(ModuleProvider*, std::string*);
7980 static EECtorFn JITCtor, InterpCtor;
80
81
82 /// LazyFunctionCreator - If an unknown function is needed, this function
83 /// pointer is invoked to create it. If this returns null, the JIT will abort.
84 void* (*LazyFunctionCreator)(const std::string &);
85
8186 public:
8287 /// lock - This lock is protects the ExecutionEngine, JIT, JITResolver and
8388 /// JITEmitter classes. It must be held while changing the internal state of
217222 bool isLazyCompilationDisabled() const {
218223 return LazyCompilationDisabled;
219224 }
225
226
227 /// InstallLazyFunctionCreator - If an unknown function is needed, the
228 /// specified function pointer is invoked to create it. If it returns null,
229 /// the JIT will abort.
230 void InstallLazyFunctionCreator(void* (*P)(const std::string &)) {
231 LazyFunctionCreator = P;
232 }
220233
221234 protected:
222235 void emitGlobals();
3232 ExecutionEngine::EECtorFn ExecutionEngine::JITCtor = 0;
3333 ExecutionEngine::EECtorFn ExecutionEngine::InterpCtor = 0;
3434
35 ExecutionEngine::ExecutionEngine(ModuleProvider *P) {
35 ExecutionEngine::ExecutionEngine(ModuleProvider *P) : LazyFunctionCreator(0) {
3636 LazyCompilationDisabled = false;
3737 Modules.push_back(P);
3838 assert(P && "ModuleProvider is null?");
3939 }
4040
41 ExecutionEngine::ExecutionEngine(Module *M) {
41 ExecutionEngine::ExecutionEngine(Module *M) : LazyFunctionCreator(0) {
4242 LazyCompilationDisabled = false;
4343 assert(M && "Module is null?");
4444 Modules.push_back(new ExistingModuleProvider(M));
100100 Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
101101 if (Ptr) return Ptr;
102102 }
103
104 /// If a LazyFunctionCreator is installed, use it to get/create the function.
105 if (LazyFunctionCreator)
106 if (void *RP = LazyFunctionCreator(Name))
107 return RP;
103108
104109 cerr << "ERROR: Program used external function '" << Name
105110 << "' which could not be resolved!\n";