From 7ad22167dcae1c37c0e15173e60580064a09808d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 31 Dec 2010 22:22:48 +0000 Subject: Use standard LLVM optimization passes, and optimize entire module (much more aggressive optimization than previous code). git-svn-id: http://svn.drobilla.net/resp/resp@398 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- Makefile | 4 ++-- src/llvm.cpp | 26 +++++++++++++++----------- test/ack.resp | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index cbb3ace..00aee1e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -LLVM_CXXFLAGS=`llvm-config-2.7 --cppflags core jit native` -LLVM_LDFLAGS=`llvm-config-2.7 --ldflags --libs core jit native` +LLVM_CXXFLAGS=`llvm-config-2.7 --cppflags core jit native codegen ipo` +LLVM_LDFLAGS=`llvm-config-2.7 --ldflags --libs core jit native codegen ipo` #LLVM_CXXFLAGS=`llvm-config-2.7 --cppflags all` #LLVM_LDFLAGS=`llvm-config-2.7 --ldflags --libs all` 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 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(f)); + fnOpt->run(*static_cast(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); diff --git a/test/ack.resp b/test/ack.resp index 76fb397..3d9544b 100644 --- a/test/ack.resp +++ b/test/ack.resp @@ -3,5 +3,5 @@ (= 0 n) (ack (- m 1) 1) (ack (- m 1) (ack m (- n 1))))) -(ack 3 10) +(ack 3 12) -- cgit v1.2.1