diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/llvm.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/llvm.cpp b/src/llvm.cpp index 1a944dd..ce684b1 100644 --- a/src/llvm.cpp +++ b/src/llvm.cpp @@ -41,6 +41,7 @@ #include "llvm/PassManager.h" #include "llvm/Support/raw_os_ostream.h" #include "llvm/Support/IRBuilder.h" +#include "llvm/Support/StandardPasses.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetSelect.h" #include "llvm/Transforms/Scalar.h" @@ -92,7 +93,8 @@ private: ExecutionEngine* engine; IRBuilder<> builder; Function* alloc; - FunctionPassManager* opt; + FunctionPassManager* fnOpt; + PassManager* modOpt; CType objectT; PATypeHolder* opaqueT; @@ -111,15 +113,13 @@ LLVMEngine::LLVMEngine() InitializeNativeTarget(); module = new Module("resp", context); engine = EngineBuilder(module).create(); - opt = new FunctionPassManager(module); + fnOpt = new FunctionPassManager(module); + modOpt = new PassManager(); - // 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 + // Set up optimisers + unsigned optLevel = 3; + createStandardFunctionPasses(fnOpt, optLevel); + createStandardModulePasses(modOpt, optLevel, false, true, true, true, false, NULL); // Declare host provided allocation primitive std::vector<const Type*> argsT(1, Type::getInt32Ty(context)); // unsigned size @@ -139,7 +139,8 @@ LLVMEngine::LLVMEngine() LLVMEngine::~LLVMEngine() { delete engine; - delete opt; + delete fnOpt; + delete modOpt; } const Type* @@ -400,7 +401,7 @@ LLVMEngine::finishFn(CEnv& cenv, CFunc f, CVal ret, const AST* retT) throw Error(Cursor(), "Broken module"); } if (cenv.args.find("-g") == cenv.args.end()) - opt->run(*static_cast<Function*>(f)); + fnOpt->run(*static_cast<Function*>(f)); } void @@ -522,6 +523,9 @@ LLVMEngine::compileGlobalGet(CEnv& cenv, const string& sym, CVal val) void LLVMEngine::writeModule(CEnv& cenv, std::ostream& os) { + if (cenv.args.find("-g") == cenv.args.end()) + modOpt->run(*module); + AssemblyAnnotationWriter writer; llvm::raw_os_ostream raw_stream(os); module->print(raw_stream, &writer); |