From 60789e419e04c260e36af9a1add5ad316313e490 Mon Sep 17 00:00:00 2001 From: Nate Begeman Date: Fri, 23 Jan 2009 19:27:28 +0000 Subject: [PATCH] Add support for deleting a module provider from a JIT in such a way that it does not cause the owned module to be fully materialized. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62864 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/ExecutionEngine/ExecutionEngine.h | 8 +++++++- lib/ExecutionEngine/ExecutionEngine.cpp | 20 ++++++++++++++++++- lib/ExecutionEngine/JIT/JIT.cpp | 13 ++++++++++++ lib/ExecutionEngine/JIT/JIT.h | 9 +++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/include/llvm/ExecutionEngine/ExecutionEngine.h b/include/llvm/ExecutionEngine/ExecutionEngine.h index a26c755ee76..3559ede31c3 100644 --- a/include/llvm/ExecutionEngine/ExecutionEngine.h +++ b/include/llvm/ExecutionEngine/ExecutionEngine.h @@ -143,10 +143,16 @@ public: /// removeModuleProvider - Remove a ModuleProvider from the list of modules. - /// Release module from ModuleProvider. + /// Relases the Module from the ModuleProvider, materializing it in the + /// process, and returns the materialized Module. virtual Module* removeModuleProvider(ModuleProvider *P, std::string *ErrInfo = 0); + /// deleteModuleProvider - Remove a ModuleProvider from the list of modules, + /// and deletes the ModuleProvider and owned Module. Avoids materializing + /// the underlying module. + virtual void deleteModuleProvider(ModuleProvider *P,std::string *ErrInfo = 0); + /// FindFunctionNamed - Search all of the active modules to find the one that /// defines FnName. This is very slow operation and shouldn't be used for /// general code. diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index d1a406c9960..9fea1f5753f 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -59,7 +59,8 @@ char* ExecutionEngine::getMemoryForGV(const GlobalVariable* GV) { } /// removeModuleProvider - Remove a ModuleProvider from the list of modules. -/// Release module from ModuleProvider. +/// Relases the Module from the ModuleProvider, materializing it in the +/// process, and returns the materialized Module. Module* ExecutionEngine::removeModuleProvider(ModuleProvider *P, std::string *ErrInfo) { for(SmallVector::iterator I = Modules.begin(), @@ -74,6 +75,23 @@ Module* ExecutionEngine::removeModuleProvider(ModuleProvider *P, return NULL; } +/// deleteModuleProvider - Remove a ModuleProvider from the list of modules, +/// and deletes the ModuleProvider and owned Module. Avoids materializing +/// the underlying module. +void ExecutionEngine::deleteModuleProvider(ModuleProvider *P, + std::string *ErrInfo) { + for(SmallVector::iterator I = Modules.begin(), + E = Modules.end(); I != E; ++I) { + ModuleProvider *MP = *I; + if (MP == P) { + Modules.erase(I); + clearGlobalMappingsFromModule(MP->getModule()); + delete MP; + return; + } + } +} + /// FindFunctionNamed - Search all of the active modules to find the one that /// defines FnName. This is very slow operation and shouldn't be used for /// general code. diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index fd69e69c44d..7fc7b2fdceb 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -297,6 +297,19 @@ Module *JIT::removeModuleProvider(ModuleProvider *MP, std::string *E) { return result; } +/// deleteModuleProvider - Remove a ModuleProvider from the list of modules, +/// and deletes the ModuleProvider and owned Module. Avoids materializing +/// the underlying module. +void JIT::deleteModuleProvider(ModuleProvider *MP, std::string *E) { + ExecutionEngine::deleteModuleProvider(MP, E); + + MutexGuard locked(lock); + if (Modules.empty()) { + delete jitstate; + jitstate = 0; + } +} + /// run - Start execution with the specified function and arguments. /// GenericValue JIT::runFunction(Function *F, diff --git a/lib/ExecutionEngine/JIT/JIT.h b/lib/ExecutionEngine/JIT/JIT.h index b9299996033..7c085e360e2 100644 --- a/lib/ExecutionEngine/JIT/JIT.h +++ b/lib/ExecutionEngine/JIT/JIT.h @@ -77,9 +77,18 @@ public: } virtual void addModuleProvider(ModuleProvider *MP); + + /// removeModuleProvider - Remove a ModuleProvider from the list of modules. + /// Relases the Module from the ModuleProvider, materializing it in the + /// process, and returns the materialized Module. virtual Module *removeModuleProvider(ModuleProvider *MP, std::string *ErrInfo = 0); + /// deleteModuleProvider - Remove a ModuleProvider from the list of modules, + /// and deletes the ModuleProvider and owned Module. Avoids materializing + /// the underlying module. + virtual void deleteModuleProvider(ModuleProvider *P,std::string *ErrInfo = 0); + /// runFunction - Start execution with the specified function and arguments. /// virtual GenericValue runFunction(Function *F,