[llvm-commits] [llvm] r43210 - in /llvm/trunk: include/llvm/ExecutionEngine/ExecutionEngine.h lib/ExecutionEngine/ExecutionEngine.cpp lib/ExecutionEngine/JIT/Intercept.cpp
Chris Lattner
sabre at nondot.org
Sun Oct 21 19:50:12 PDT 2007
Author: lattner
Date: Sun Oct 21 21:50:12 2007
New Revision: 43210
URL: http://llvm.org/viewvc/llvm-project?rev=43210&view=rev
Log:
add a mechanism for the JIT to invoke a function to lazily create functions as they are referenced.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp
Modified: llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=43210&r1=43209&r2=43210&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Sun Oct 21 21:50:12 2007
@@ -64,6 +64,7 @@
const TargetData *TD;
ExecutionEngineState state;
bool LazyCompilationDisabled;
+
protected:
/// Modules - This is a list of ModuleProvider's that we are JIT'ing from. We
/// use a smallvector to optimize for the case where there is only one module.
@@ -78,7 +79,11 @@
// at startup time if they are linked in.
typedef ExecutionEngine *(*EECtorFn)(ModuleProvider*, std::string*);
static EECtorFn JITCtor, InterpCtor;
-
+
+ /// LazyFunctionCreator - If an unknown function is needed, this function
+ /// pointer is invoked to create it. If this returns null, the JIT will abort.
+ void* (*LazyFunctionCreator)(const std::string &);
+
public:
/// lock - This lock is protects the ExecutionEngine, JIT, JITResolver and
/// JITEmitter classes. It must be held while changing the internal state of
@@ -218,6 +223,14 @@
bool isLazyCompilationDisabled() const {
return LazyCompilationDisabled;
}
+
+
+ /// InstallLazyFunctionCreator - If an unknown function is needed, the
+ /// specified function pointer is invoked to create it. If it returns null,
+ /// the JIT will abort.
+ void InstallLazyFunctionCreator(void* (*P)(const std::string &)) {
+ LazyFunctionCreator = P;
+ }
protected:
void emitGlobals();
Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?rev=43210&r1=43209&r2=43210&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp Sun Oct 21 21:50:12 2007
@@ -33,13 +33,13 @@
ExecutionEngine::EECtorFn ExecutionEngine::JITCtor = 0;
ExecutionEngine::EECtorFn ExecutionEngine::InterpCtor = 0;
-ExecutionEngine::ExecutionEngine(ModuleProvider *P) {
+ExecutionEngine::ExecutionEngine(ModuleProvider *P) : LazyFunctionCreator(0) {
LazyCompilationDisabled = false;
Modules.push_back(P);
assert(P && "ModuleProvider is null?");
}
-ExecutionEngine::ExecutionEngine(Module *M) {
+ExecutionEngine::ExecutionEngine(Module *M) : LazyFunctionCreator(0) {
LazyCompilationDisabled = false;
assert(M && "Module is null?");
Modules.push_back(new ExistingModuleProvider(M));
Modified: llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp?rev=43210&r1=43209&r2=43210&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp Sun Oct 21 21:50:12 2007
@@ -101,6 +101,11 @@
Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr+1);
if (Ptr) return Ptr;
}
+
+ /// If a LazyFunctionCreator is installed, use it to get/create the function.
+ if (LazyFunctionCreator)
+ if (void *RP = LazyFunctionCreator(Name))
+ return RP;
cerr << "ERROR: Program used external function '" << Name
<< "' which could not be resolved!\n";
More information about the llvm-commits
mailing list