diff options
-rw-r--r-- | GNUmakefile | 2 | ||||
-rw-r--r-- | MLKLLVMCompiler.mm | 18 |
2 files changed, 16 insertions, 4 deletions
diff --git a/GNUmakefile b/GNUmakefile index 4b7ba22..9bd1c2f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -76,7 +76,7 @@ ifeq ($(USE_LLVM),YES) ADDITIONAL_OBJCCFLAGS = $(ADDITIONAL_OBJCFLAGS) ToiletKit_OBJCC_FILES = MLKLLVMCompiler.mm ToiletKit_OBJCCFLAGS = `llvm-config --cxxflags` $(ToiletKit_OBJCFLAGS) -ToiletKit_LDFLAGS += `llvm-config --ldflags` `llvm-config --libs backend engine linker codegen` +ToiletKit_LDFLAGS += `llvm-config --ldflags` `llvm-config --libs backend engine linker codegen transformutils scalaropts analysis` endif #TOOL_NAME = etoilet diff --git a/MLKLLVMCompiler.mm b/MLKLLVMCompiler.mm index f09e03f..3ad0c10 100644 --- a/MLKLLVMCompiler.mm +++ b/MLKLLVMCompiler.mm @@ -33,6 +33,8 @@ #include <llvm/ModuleProvider.h> #include <llvm/PassManager.h> #include <llvm/Support/IRBuilder.h> +#include <llvm/Target/TargetData.h> +#include <llvm/Transforms/Scalar.h> #include <llvm/Value.h> #include <deque> @@ -46,6 +48,7 @@ static llvm::Module *module; static IRBuilder builder; static FunctionPassManager *fpm; static PointerType *PointerTy; +static ModuleProvider *module_provider; static Constant @@ -72,6 +75,13 @@ static Constant module = new llvm::Module ("MLKLLVMModule"); execution_engine = ExecutionEngine::create (module); PointerTy = PointerType::get(Type::Int8Ty, 0); + module_provider = new ExistingModuleProvider (module); + fpm = new FunctionPassManager (module_provider); + fpm->add (new TargetData (*execution_engine->getTargetData())); + fpm->add (createInstructionCombiningPass()); + fpm->add (createReassociatePass()); + fpm->add (createGVNPass()); + fpm->add (createCFGSimplificationPass()); } +(id) compile:(id)object @@ -100,7 +110,7 @@ static Constant builder.CreateRet (v); function->dump(); verifyFunction (*function); - //fpm->run (*function); + fpm->run (*function); // JIT-compile. fn = (id (*)()) execution_engine->getPointerToFunction (function); @@ -449,9 +459,11 @@ static Constant function->dump(); NSLog (@"Verify..."); verifyFunction (*function); - // NSLog (@"FPM..."); - // fpm->run (*function); + NSLog (@"Optimise..."); + fpm->run (*function); NSLog (@"Done."); + function->dump(); + NSLog (@"Function built."); builder.SetInsertPoint (outerBlock); |