aboutsummaryrefslogtreecommitdiffstats
path: root/ll.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-01-26 18:25:07 +0000
committerDavid Robillard <d@drobilla.net>2009-01-26 18:25:07 +0000
commitbeb36974ecaafa30296b90f7f61c24235450c2f3 (patch)
tree1976b6ced0334a07ef595a7dca91f7b1c78cdb72 /ll.cpp
parentbca79754d69afec61a18d77f6924410af7e371f6 (diff)
downloadresp-beb36974ecaafa30296b90f7f61c24235450c2f3.tar.gz
resp-beb36974ecaafa30296b90f7f61c24235450c2f3.tar.bz2
resp-beb36974ecaafa30296b90f7f61c24235450c2f3.zip
Shrink.
git-svn-id: http://svn.drobilla.net/resp/llvm-lisp@23 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'll.cpp')
-rw-r--r--ll.cpp45
1 files changed, 13 insertions, 32 deletions
diff --git a/ll.cpp b/ll.cpp
index 13b16af..a906bdc 100644
--- a/ll.cpp
+++ b/ll.cpp
@@ -580,24 +580,18 @@ struct CEnv {
CEnv(PEnv& p, Module* m, const TargetData* target)
: penv(p), tenv(p), module(m), emp(module), fpm(&emp), symID(0)
{
- // Set up the optimizer pipeline.
- // Register info about how the target lays out data structures.
- fpm.add(new TargetData(*target));
- // Do simple "peephole" and bit-twiddling optimizations.
- fpm.add(createInstructionCombiningPass());
- // Reassociate expressions.
- fpm.add(createReassociatePass());
- // Eliminate Common SubExpressions.
- fpm.add(createGVNPass());
- // Simplify control flow graph (delete unreachable blocks, etc).
- fpm.add(createCFGSimplificationPass());
+ // Set up the optimizer pipeline:
+ fpm.add(new TargetData(*target)); // Register target arch
+ fpm.add(createInstructionCombiningPass()); // Simple optimizations
+ fpm.add(createReassociatePass()); // Reassociate expressions
+ fpm.add(createGVNPass()); // Eleminate Common Subexpressions
+ fpm.add(createCFGSimplificationPass()); // Simplify control flow
}
string gensym(const char* base="_") {
ostringstream s; s << base << symID++; return s.str();
}
typedef Env<const AST*, AST*> Code;
typedef Env<const ASTSymbol*, Value*> Vals;
-
PEnv& penv;
TEnv tenv;
IRBuilder<> builder;
@@ -650,7 +644,6 @@ compileFunction(CEnv& cenv, const std::string& name, ASTTuple& prot, const Type*
return f;
}
-
Value*
ASTSymbol::compile(CEnv& cenv)
{
@@ -690,16 +683,11 @@ ASTCall::lift(CEnv& cenv)
c = (val) ? dynamic_cast<ASTClosure*>(*val) : c;
}
- if (!c) {
- ASTTuple::lift(cenv);
- return;
- }
-
- std::cout << "Lifting call to closure" << endl;
-
// Lift arguments
for (size_t i = 1; i < tup.size(); ++i)
tup[i]->lift(cenv);
+
+ if (!c) return;
// Extend environment with bound and typed parameters
cenv.code.push_front();
@@ -709,10 +697,8 @@ ASTCall::lift(CEnv& cenv)
for (size_t i = 1; i < tup.size(); ++i)
cenv.code.def(c->prot->tup[i-1], tup[i]);
- // Lift callee closure
- tup[0]->lift(cenv);
-
- cenv.code.pop_front();
+ tup[0]->lift(cenv); // Lift called closure
+ cenv.code.pop_front(); // Restore environment
}
Value*
@@ -720,11 +706,8 @@ ASTCall::compile(CEnv& cenv)
{
ASTClosure* c = dynamic_cast<ASTClosure*>(tup[0]);
if (!c) {
- std::cout << "LOOKING UP" << endl;
AST** val = cenv.code.ref(tup[0]);
c = (val) ? dynamic_cast<ASTClosure*>(*val) : c;
- } else {
- std::cout << "FOUND" << endl;
}
if (!c) throw CompileError("Call to non-closure");
@@ -754,22 +737,20 @@ ASTIf::compile(CEnv& cenv)
cenv.builder.CreateCondBr(condV, thenBB, elseBB);
- // Emit then value.
+ // Emit then block
cenv.builder.SetInsertPoint(thenBB);
Value* thenV = tup[2]->compile(cenv); // Can change current block, so...
-
cenv.builder.CreateBr(mergeBB);
thenBB = cenv.builder.GetInsertBlock(); // ... update thenBB afterwards
- // Emit else block.
+ // Emit else block
parent->getBasicBlockList().push_back(elseBB);
cenv.builder.SetInsertPoint(elseBB);
Value* elseV = tup[3]->compile(cenv); // Can change current block, so...
-
cenv.builder.CreateBr(mergeBB);
elseBB = cenv.builder.GetInsertBlock(); // ... update elseBB afterwards
- // Emit merge block.
+ // Emit merge block
parent->getBasicBlockList().push_back(mergeBB);
cenv.builder.SetInsertPoint(mergeBB);
PHINode* pn = cenv.builder.CreatePHI(cenv.tenv.type(this)->ctype, "iftmp");