Make it explicit that ExecutionEngine takes ownership of the modules.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215967 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-08-19 04:04:25 +00:00
parent 4d48c3f2a4
commit 3f4ed32b43
27 changed files with 242 additions and 223 deletions

View File

@@ -43,7 +43,7 @@ static struct RegisterJIT {
extern "C" void LLVMLinkInMCJIT() {
}
ExecutionEngine *MCJIT::createJIT(Module *M,
ExecutionEngine *MCJIT::createJIT(std::unique_ptr<Module> M,
std::string *ErrorStr,
RTDyldMemoryManager *MemMgr,
TargetMachine *TM) {
@@ -52,19 +52,14 @@ ExecutionEngine *MCJIT::createJIT(Module *M,
// FIXME: Don't do this here.
sys::DynamicLibrary::LoadLibraryPermanently(nullptr, nullptr);
return new MCJIT(M, TM, MemMgr ? MemMgr : new SectionMemoryManager());
return new MCJIT(std::move(M), TM,
MemMgr ? MemMgr : new SectionMemoryManager());
}
MCJIT::MCJIT(Module *m, TargetMachine *tm, RTDyldMemoryManager *MM)
: ExecutionEngine(m), TM(tm), Ctx(nullptr), MemMgr(this, MM), Dyld(&MemMgr),
ObjCache(nullptr) {
OwnedModules.addModule(m);
setDataLayout(TM->getSubtargetImpl()->getDataLayout());
}
MCJIT::~MCJIT() {
MutexGuard locked(lock);
MCJIT::MCJIT(std::unique_ptr<Module> M, TargetMachine *tm,
RTDyldMemoryManager *MM)
: ExecutionEngine(std::move(M)), TM(tm), Ctx(nullptr), MemMgr(this, MM),
Dyld(&MemMgr), ObjCache(nullptr) {
// FIXME: We are managing our modules, so we do not want the base class
// ExecutionEngine to manage them as well. To avoid double destruction
// of the first (and only) module added in ExecutionEngine constructor
@@ -75,7 +70,16 @@ MCJIT::~MCJIT() {
// If so, additional functions: addModule, removeModule, FindFunctionNamed,
// runStaticConstructorsDestructors could be moved back to EE as well.
//
std::unique_ptr<Module> First = std::move(Modules[0]);
Modules.clear();
OwnedModules.addModule(std::move(First));
setDataLayout(TM->getSubtargetImpl()->getDataLayout());
}
MCJIT::~MCJIT() {
MutexGuard locked(lock);
Dyld.deregisterEHFrames();
LoadedObjectList::iterator it, end;
@@ -93,9 +97,9 @@ MCJIT::~MCJIT() {
delete TM;
}
void MCJIT::addModule(Module *M) {
void MCJIT::addModule(std::unique_ptr<Module> M) {
MutexGuard locked(lock);
OwnedModules.addModule(M);
OwnedModules.addModule(std::move(M));
}
bool MCJIT::removeModule(Module *M) {
@@ -389,7 +393,7 @@ void MCJIT::freeMachineCodeForFunction(Function *F) {
void MCJIT::runStaticConstructorsDestructorsInModulePtrSet(
bool isDtors, ModulePtrSet::iterator I, ModulePtrSet::iterator E) {
for (; I != E; ++I) {
ExecutionEngine::runStaticConstructorsDestructors(*I, isDtors);
ExecutionEngine::runStaticConstructorsDestructors(**I, isDtors);
}
}

View File

@@ -101,7 +101,8 @@ private:
// called.
class MCJIT : public ExecutionEngine {
MCJIT(Module *M, TargetMachine *tm, RTDyldMemoryManager *MemMgr);
MCJIT(std::unique_ptr<Module> M, TargetMachine *tm,
RTDyldMemoryManager *MemMgr);
typedef llvm::SmallPtrSet<Module *, 4> ModulePtrSet;
@@ -124,8 +125,8 @@ class MCJIT : public ExecutionEngine {
ModulePtrSet::iterator begin_finalized() { return FinalizedModules.begin(); }
ModulePtrSet::iterator end_finalized() { return FinalizedModules.end(); }
void addModule(Module *M) {
AddedModules.insert(M);
void addModule(std::unique_ptr<Module> M) {
AddedModules.insert(M.release());
}
bool removeModule(Module *M) {
@@ -237,7 +238,7 @@ public:
/// @name ExecutionEngine interface implementation
/// @{
void addModule(Module *M) override;
void addModule(std::unique_ptr<Module> M) override;
void addObjectFile(std::unique_ptr<object::ObjectFile> O) override;
void addArchive(std::unique_ptr<object::Archive> O) override;
bool removeModule(Module *M) override;
@@ -324,7 +325,7 @@ public:
MCJITCtor = createJIT;
}
static ExecutionEngine *createJIT(Module *M,
static ExecutionEngine *createJIT(std::unique_ptr<Module> M,
std::string *ErrorStr,
RTDyldMemoryManager *MemMgr,
TargetMachine *TM);