# HG changeset patch # User lindquist # Date 1196221955 -3600 # Node ID c42d245468ea3efde0ef4f455229d4788c1b7053 # Parent a939ec89fc722afb2be7326da000523dc2d3f3bb [svn r129] Started AA literals. Fixed #15, passing -O will now invoke the optimizer before writing bitcode. diff -r a939ec89fc72 -r c42d245468ea gen/optimizer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gen/optimizer.cpp Wed Nov 28 04:52:35 2007 +0100 @@ -0,0 +1,81 @@ +#include "llvm/PassManager.h" +#include "llvm/LinkAllPasses.h" +#include "llvm/Analysis/LoopPass.h" +#include "llvm/Target/TargetData.h" + +using namespace llvm; + +////////////////////////////////////////////////////////////////////////////////////////// + +// this function runs some or all of the std-compile-opts passes depending on the +// optimization level given. + +void llvmdc_optimize_module(Module* m, char lvl, bool doinline) +{ + assert(lvl >= 0 && lvl <= 5); + if (lvl == 0) + return; + + PassManager pm; + pm.add(new TargetData(m)); + + if (lvl >= 1) + { + pm.add(createRaiseAllocationsPass()); + pm.add(createCFGSimplificationPass()); + pm.add(createPromoteMemoryToRegisterPass()); + } + + if (lvl >= 2) + { + pm.add(createGlobalOptimizerPass()); + pm.add(createGlobalDCEPass()); + pm.add(createIPConstantPropagationPass()); + pm.add(createDeadArgEliminationPass()); + pm.add(createInstructionCombiningPass()); + pm.add(createCFGSimplificationPass()); + pm.add(createPruneEHPass()); + } + + if (doinline) { + pm.add(createFunctionInliningPass()); + } + + if (lvl >= 3) + { + pm.add(createArgumentPromotionPass()); + pm.add(createTailDuplicationPass()); + pm.add(createInstructionCombiningPass()); + pm.add(createCFGSimplificationPass()); + pm.add(createScalarReplAggregatesPass()); + pm.add(createInstructionCombiningPass()); + pm.add(createCondPropagationPass()); + + pm.add(createTailCallEliminationPass()); + pm.add(createCFGSimplificationPass()); + pm.add(createReassociatePass()); + pm.add(createLoopRotatePass()); + pm.add(createLICMPass()); + pm.add(createLoopUnswitchPass()); + pm.add(createInstructionCombiningPass()); + pm.add(createIndVarSimplifyPass()); + pm.add(createLoopUnrollPass()); + pm.add(createInstructionCombiningPass()); + pm.add(createGVNPass()); + pm.add(createSCCPPass()); + + pm.add(createInstructionCombiningPass()); + pm.add(createCondPropagationPass()); + + pm.add(createDeadStoreEliminationPass()); + pm.add(createAggressiveDCEPass()); + pm.add(createCFGSimplificationPass()); + pm.add(createSimplifyLibCallsPass()); + pm.add(createDeadTypeEliminationPass()); + pm.add(createConstantMergePass()); + } + + // level 4 and 5 are linktime optimizations + + pm.run(*m); +} diff -r a939ec89fc72 -r c42d245468ea gen/toir.cpp --- a/gen/toir.cpp Wed Nov 28 03:34:37 2007 +0100 +++ b/gen/toir.cpp Wed Nov 28 04:52:35 2007 +0100 @@ -2574,6 +2574,29 @@ ////////////////////////////////////////////////////////////////////////////////////////// +DValue* AssocArrayLiteralExp::toElem(IRState* p) +{ + Logger::print("AssocArrayLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); + LOG_SCOPE; + + assert(keys); + assert(values); + assert(keys->dim == values->dim); + + const size_t n = keys->dim; + for (size_t i=0; idata[i]; + Expression* eval = (Expression*)values->data[i]; + + Logger::println("(%u) aa[%s] = %s", i, ekey->toChars(), eval->toChars()); + } + + assert(0); +} + +////////////////////////////////////////////////////////////////////////////////////////// + #define STUB(x) DValue *x::toElem(IRState * p) {error("Exp type "#x" not implemented: %s", toChars()); fatal(); return 0; } //STUB(IdentityExp); //STUB(CondExp); @@ -2645,7 +2668,7 @@ //STUB(HaltExp); STUB(RemoveExp); //STUB(ArrayLiteralExp); -STUB(AssocArrayLiteralExp); +//STUB(AssocArrayLiteralExp); //STUB(StructLiteralExp); STUB(TupleExp); diff -r a939ec89fc72 -r c42d245468ea gen/toobj.cpp --- a/gen/toobj.cpp Wed Nov 28 03:34:37 2007 +0100 +++ b/gen/toobj.cpp Wed Nov 28 04:52:35 2007 +0100 @@ -43,8 +43,12 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void -Module::genobjfile() +// in gen/optimize.cpp +void llvmdc_optimize_module(llvm::Module* m, char lvl, bool doinline); + +////////////////////////////////////////////////////////////////////////////////////////// + +void Module::genobjfile() { Logger::cout() << "Generating module: " << (md ? md->toChars() : toChars()) << '\n'; LOG_SCOPE; @@ -112,8 +116,6 @@ // do this again as moduleinfo might have pulled something in! DtoEmptyAllLists(); - gTargetData = 0; - // emit the llvm main function if necessary if (ir.emitMain) { DtoMain(); @@ -134,8 +136,10 @@ } } - // run passes - // TODO + // run optimizer + if (global.params.optimize) { + llvmdc_optimize_module(ir.module, global.params.optimizeLevel, global.params.useInline); + } // write bytecode { @@ -152,6 +156,7 @@ } delete ir.module; + gTargetData = 0; gIR = NULL; } diff -r a939ec89fc72 -r c42d245468ea llvmdc.kdevelop --- a/llvmdc.kdevelop Wed Nov 28 03:34:37 2007 +0100 +++ b/llvmdc.kdevelop Wed Nov 28 04:52:35 2007 +0100 @@ -14,8 +14,8 @@ llvmdc . false - - + + @@ -147,7 +147,7 @@ std=_GLIBCXX_STD;__gnu_cxx=std true false - false + true false false true @@ -156,7 +156,7 @@ .; - + set m_,_ theValue @@ -174,8 +174,8 @@ executable /home/tomas/kdevprojects/llvmdc - - + + /home/tomas/kdevprojects/llvmdc false false @@ -398,13 +398,13 @@ make - + 0 - - - + + + default @@ -415,9 +415,9 @@ 0 0 false - - - + + + default @@ -432,11 +432,11 @@ - - - - - + + + + + true false false diff -r a939ec89fc72 -r c42d245468ea llvmdc.kdevelop.filelist --- a/llvmdc.kdevelop.filelist Wed Nov 28 03:34:37 2007 +0100 +++ b/llvmdc.kdevelop.filelist Wed Nov 28 04:52:35 2007 +0100 @@ -120,6 +120,7 @@ gen/llvm.h gen/logger.cpp gen/logger.h +gen/optimizer.cpp gen/runtime.cpp gen/runtime.h gen/statements.cpp @@ -239,6 +240,7 @@ test/aa3.d test/aa4.d test/aa5.d +test/aa6.d test/alignment.d test/alloca1.d test/arrayinit.d diff -r a939ec89fc72 -r c42d245468ea premake.lua --- a/premake.lua Wed Nov 28 03:34:37 2007 +0100 +++ b/premake.lua Wed Nov 28 04:52:35 2007 +0100 @@ -24,7 +24,7 @@ package.files = { matchfiles("dmd/*.c"), matchfiles("gen/*.cpp") } package.excludes = { "dmd/idgen.c", "dmd/impcnvgen.c" } package.buildoptions = { "-x c++", "`llvm-config --cxxflags`" } -package.linkoptions = { "`llvm-config --libs native bitwriter bitreader`", "`llvm-config --ldflags`" } +package.linkoptions = { "`llvm-config --libs all`", "`llvm-config --ldflags`" } package.defines = { "IN_LLVM", "_DH" } package.config.Release.defines = { "LLVMD_NO_LOGGER" } package.config.Debug.buildoptions = { "-g -O0" }