Run optimizations.

It is always on for now just to make sure the bots are happy. If they
are, I will add a -O option and update the makefile.
This commit is contained in:
Rafael Ávila de Espíndola 2011-04-07 12:12:21 -04:00
parent 2e90bd94de
commit 25320da099
2 changed files with 100 additions and 5 deletions

View File

@ -741,6 +741,40 @@ native mod llvm = llvm_lib {
/** Adds a verification pass. */
fn LLVMAddVerifierPass(PassManagerRef PM);
fn LLVMAddGlobalOptimizerPass(PassManagerRef PM);
fn LLVMAddIPSCCPPass(PassManagerRef PM);
fn LLVMAddDeadArgEliminationPass(PassManagerRef PM);
fn LLVMAddInstructionCombiningPass(PassManagerRef PM);
fn LLVMAddCFGSimplificationPass(PassManagerRef PM);
fn LLVMAddFunctionInliningPass(PassManagerRef PM);
fn LLVMAddFunctionAttrsPass(PassManagerRef PM);
fn LLVMAddScalarReplAggregatesPass(PassManagerRef PM);
// fn LLVMAddScalarReplAggregatesPassSSA(PassManagerRef PM);
fn LLVMAddJumpThreadingPass(PassManagerRef PM);
fn LLVMAddConstantPropagationPass(PassManagerRef PM);
fn LLVMAddReassociatePass(PassManagerRef PM);
fn LLVMAddLoopRotatePass(PassManagerRef PM);
fn LLVMAddLICMPass(PassManagerRef PM);
fn LLVMAddLoopUnswitchPass(PassManagerRef PM);
fn LLVMAddLoopDeletionPass(PassManagerRef PM);
fn LLVMAddLoopUnrollPass(PassManagerRef PM);
fn LLVMAddGVNPass(PassManagerRef PM);
fn LLVMAddMemCpyOptPass(PassManagerRef PM);
fn LLVMAddSCCPPass(PassManagerRef PM);
fn LLVMAddDeadStoreEliminationPass(PassManagerRef PM);
fn LLVMAddStripDeadPrototypesPass(PassManagerRef PM);
fn LLVMAddDeadTypeEliminationPass(PassManagerRef PM);
fn LLVMAddConstantMergePass(PassManagerRef PM);
fn LLVMAddArgumentPromotionPass(PassManagerRef PM);
fn LLVMAddTailCallEliminationPass(PassManagerRef PM);
fn LLVMAddIndVarSimplifyPass(PassManagerRef PM);
fn LLVMAddAggressiveDCEPass(PassManagerRef PM);
fn LLVMAddGlobalDCEPass(PassManagerRef PM);
// fn LLVMAddCorrelatedValuePropagationPass(PassManagerRef PM);
fn LLVMAddPruneEHPass(PassManagerRef PM);
fn LLVMAddSimplifyLibCallsPass(PassManagerRef PM);
// fn LLVMAddLoopIdiomPass(PassManagerRef PM);
/** Destroys a memory buffer. */
fn LLVMDisposeMemoryBuffer(MemoryBufferRef MemBuf);

View File

@ -6599,12 +6599,71 @@ fn trap(@block_ctxt bcx) {
bcx.build.Call(bcx.fcx.ccx.intrinsics.get("llvm.trap"), v);
}
fn check_module(ModuleRef llmod) {
fn run_passes(ModuleRef llmod, bool opt) {
auto pm = mk_pass_manager();
llvm.LLVMAddVerifierPass(pm.llpm);
llvm.LLVMRunPassManager(pm.llpm, llmod);
// TODO: run the linter here also, once there are llvm-c bindings for it.
// FIXME: This is mostly a copy of the bits of opt's -O2 that are
// available in the C api.
// FIXME2: We might want to add optmization levels like -O1, -O2, -Os, etc
// FIXME3: Should we expose and use the pass lists used by the opt tool?
if (opt) {
auto fpm = mk_pass_manager();
// createStandardFunctionPasses
llvm.LLVMAddCFGSimplificationPass(fpm.llpm);
llvm.LLVMAddScalarReplAggregatesPass(fpm.llpm);
//llvm.LLVMAddEarlyCSEPass(fpm.llpm);
llvm.LLVMRunPassManager(fpm.llpm, llmod);
// createStandardModulePasses
llvm.LLVMAddGlobalOptimizerPass(pm.llpm);
llvm.LLVMAddIPSCCPPass(pm.llpm);
llvm.LLVMAddDeadArgEliminationPass(pm.llpm);
llvm.LLVMAddInstructionCombiningPass(pm.llpm);
llvm.LLVMAddCFGSimplificationPass(pm.llpm);
llvm.LLVMAddPruneEHPass(pm.llpm);
llvm.LLVMAddFunctionInliningPass(pm.llpm);
// FIXME: crashes!
// llvm.LLVMAddFunctionAttrsPass(pm.llpm);
// llvm.LLVMAddScalarReplAggregatesPassSSA(pm.llpm);
// llvm.LLVMAddEarlyCSEPass(pm.llpm);
llvm.LLVMAddSimplifyLibCallsPass(pm.llpm);
llvm.LLVMAddJumpThreadingPass(pm.llpm);
// llvm.LLVMAddCorrelatedValuePropagationPass(pm.llpm);
llvm.LLVMAddCFGSimplificationPass(pm.llpm);
llvm.LLVMAddInstructionCombiningPass(pm.llpm);
llvm.LLVMAddTailCallEliminationPass(pm.llpm);
llvm.LLVMAddCFGSimplificationPass(pm.llpm);
llvm.LLVMAddReassociatePass(pm.llpm);
llvm.LLVMAddLoopRotatePass(pm.llpm);
llvm.LLVMAddLICMPass(pm.llpm);
llvm.LLVMAddLoopUnswitchPass(pm.llpm);
llvm.LLVMAddInstructionCombiningPass(pm.llpm);
llvm.LLVMAddIndVarSimplifyPass(pm.llpm);
// llvm.LLVMAddLoopIdiomPass(pm.llpm);
llvm.LLVMAddLoopDeletionPass(pm.llpm);
llvm.LLVMAddLoopUnrollPass(pm.llpm);
llvm.LLVMAddInstructionCombiningPass(pm.llpm);
llvm.LLVMAddGVNPass(pm.llpm);
llvm.LLVMAddMemCpyOptPass(pm.llpm);
llvm.LLVMAddSCCPPass(pm.llpm);
llvm.LLVMAddInstructionCombiningPass(pm.llpm);
llvm.LLVMAddJumpThreadingPass(pm.llpm);
// llvm.LLVMAddCorrelatedValuePropagationPass(pm.llpm);
llvm.LLVMAddDeadStoreEliminationPass(pm.llpm);
llvm.LLVMAddAggressiveDCEPass(pm.llpm);
llvm.LLVMAddCFGSimplificationPass(pm.llpm);
llvm.LLVMAddStripDeadPrototypesPass(pm.llpm);
llvm.LLVMAddDeadTypeEliminationPass(pm.llpm);
llvm.LLVMAddConstantMergePass(pm.llpm);
}
llvm.LLVMAddVerifierPass(pm.llpm);
llvm.LLVMRunPassManager(pm.llpm, llmod);
}
fn decl_no_op_type_glue(ModuleRef llmod, type_names tn) -> ValueRef {
@ -6962,7 +7021,8 @@ fn make_common_glue(str output) {
trans_exit_task_glue(glues, new_str_hash[ValueRef](), tn, llmod);
check_module(llmod);
run_passes(llmod, true);
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));
llvm.LLVMDisposeModule(llmod);
}
@ -7031,7 +7091,8 @@ fn trans_crate(session.session sess, @ast.crate crate,
// Translate the metadata.
middle.metadata.write_metadata(cx, crate);
check_module(llmod);
// FIXME: Add an -O option
run_passes(llmod, true);
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));
llvm.LLVMDisposeModule(llmod);