diff options
Diffstat (limited to 'src/llvm.cpp')
-rw-r--r-- | src/llvm.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/llvm.cpp b/src/llvm.cpp index fa4e99e..5010775 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -92,16 +92,16 @@ struct LLVMEngine : public Engine { LLVMEngine() : module(new Module("tuplr")) , engine(ExecutionEngine::create(module)) - , emp(module) - , opt(&emp) + , emp(new ExistingModuleProvider(module)) + , opt(new FunctionPassManager(emp)) { // Set up optimiser pipeline const TargetData* target = engine->getTargetData(); - opt.add(new TargetData(*target)); // Register target arch - opt.add(createInstructionCombiningPass()); // Simple optimizations - opt.add(createReassociatePass()); // Reassociate expressions - opt.add(createGVNPass()); // Eliminate Common Subexpressions - opt.add(createCFGSimplificationPass()); // Simplify control flow + opt->add(new TargetData(*target)); // Register target arch + opt->add(createInstructionCombiningPass()); // Simple optimizations + opt->add(createReassociatePass()); // Reassociate expressions + opt->add(createGVNPass()); // Eliminate Common Subexpressions + opt->add(createCFGSimplificationPass()); // Simplify control flow // Declare host provided allocation primitive std::vector<const Type*> argsT(1, Type::Int32Ty); // unsigned size @@ -110,6 +110,14 @@ struct LLVMEngine : public Engine { "tuplr_gc_allocate", module); } + ~LLVMEngine() + { + emp->releaseModule(); + delete engine; + delete opt; + delete emp; + } + CFunc startFunction(CEnv& cenv, const std::string& name, const AType* retT, const ATuple& argsT, const vector<string> argNames) @@ -153,7 +161,7 @@ struct LLVMEngine : public Engine { verifyFunction(*static_cast<Function*>(f)); if (cenv.args.find("-g") == cenv.args.end()) - opt.run(*static_cast<Function*>(f)); + opt->run(*static_cast<Function*>(f)); } void eraseFunction(CEnv& cenv, CFunc f) { @@ -201,12 +209,12 @@ struct LLVMEngine : public Engine { return ss.str(); } - Module* module; - ExecutionEngine* engine; - IRBuilder<> builder; - Function* alloc; - ExistingModuleProvider emp; - FunctionPassManager opt; + Module* module; + ExecutionEngine* engine; + IRBuilder<> builder; + Function* alloc; + ExistingModuleProvider* emp; + FunctionPassManager* opt; }; Engine* |