[svn r129] Started AA literals.

Fixed #15, passing -O will now invoke the optimizer before writing bitcode.
This commit is contained in:
Tomas Lindquist Olsen
2007-11-28 04:52:35 +01:00
parent c4d1ae5d54
commit 5ab2166b05
6 changed files with 137 additions and 26 deletions

81
gen/optimizer.cpp Normal file
View File

@@ -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);
}

View File

@@ -2574,6 +2574,29 @@ DValue* InExp::toElem(IRState* p)
//////////////////////////////////////////////////////////////////////////////////////////
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; i<n; ++i)
{
Expression* ekey = (Expression*)keys->data[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(BoolExp);
//STUB(HaltExp);
STUB(RemoveExp);
//STUB(ArrayLiteralExp);
STUB(AssocArrayLiteralExp);
//STUB(AssocArrayLiteralExp);
//STUB(StructLiteralExp);
STUB(TupleExp);

View File

@@ -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 @@ Module::genobjfile()
// 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 @@ Module::genobjfile()
}
}
// 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 @@ Module::genobjfile()
}
delete ir.module;
gTargetData = 0;
gIR = NULL;
}

View File

@@ -14,8 +14,8 @@
<projectname>llvmdc</projectname>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
<description/>
<defaultencoding/>
<description></description>
<defaultencoding></defaultencoding>
</general>
<kdevautoproject>
<general/>
@@ -147,7 +147,7 @@
<namespaceAliases>std=_GLIBCXX_STD;__gnu_cxx=std</namespaceAliases>
<processPrimaryTypes>true</processPrimaryTypes>
<processFunctionArguments>false</processFunctionArguments>
<preProcessAllHeaders>false</preProcessAllHeaders>
<preProcessAllHeaders>true</preProcessAllHeaders>
<parseMissingHeadersExperimental>false</parseMissingHeadersExperimental>
<resolveIncludePathsUsingMakeExperimental>false</resolveIncludePathsUsingMakeExperimental>
<alwaysParseInBackground>true</alwaysParseInBackground>
@@ -156,7 +156,7 @@
<includePaths>.;</includePaths>
</codecompletion>
<creategettersetter>
<prefixGet/>
<prefixGet></prefixGet>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
@@ -174,8 +174,8 @@
<run>
<directoryradio>executable</directoryradio>
<mainprogram>/home/tomas/kdevprojects/llvmdc</mainprogram>
<programargs/>
<globaldebugarguments/>
<programargs></programargs>
<globaldebugarguments></globaldebugarguments>
<globalcwd>/home/tomas/kdevprojects/llvmdc</globalcwd>
<useglobalprogram>false</useglobalprogram>
<terminal>false</terminal>
@@ -398,13 +398,13 @@
</blacklist>
<build>
<buildtool>make</buildtool>
<builddir/>
<builddir></builddir>
</build>
<other>
<prio>0</prio>
<otherbin/>
<defaulttarget/>
<otheroptions/>
<otherbin></otherbin>
<defaulttarget></defaulttarget>
<otheroptions></otheroptions>
<selectedenvironment>default</selectedenvironment>
<environments>
<default/>
@@ -415,9 +415,9 @@
<numberofjobs>0</numberofjobs>
<prio>0</prio>
<dontact>false</dontact>
<makebin/>
<defaulttarget/>
<makeoptions/>
<makebin></makebin>
<defaulttarget></defaulttarget>
<makeoptions></makeoptions>
<selectedenvironment>default</selectedenvironment>
<environments>
<default/>
@@ -432,11 +432,11 @@
</cppsupportpart>
<kdevdebugger>
<general>
<gdbpath/>
<dbgshell/>
<configGdbScript/>
<runShellScript/>
<runGdbScript/>
<gdbpath></gdbpath>
<dbgshell></dbgshell>
<configGdbScript></configGdbScript>
<runShellScript></runShellScript>
<runGdbScript></runGdbScript>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>

View File

@@ -120,6 +120,7 @@ gen/irstate.h
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/aa2.d
test/aa3.d
test/aa4.d
test/aa5.d
test/aa6.d
test/alignment.d
test/alloca1.d
test/arrayinit.d

View File

@@ -24,7 +24,7 @@ package.language = "c++"
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" }