-Ovoid-return - the last INSTR_RETURN of a void functions is replaced by INSTR_DONE to reduce the instruction count

This commit is contained in:
Wolfgang Bumiller 2012-12-26 10:24:33 +01:00
parent 47f7611ec9
commit af5b552a7f
2 changed files with 17 additions and 6 deletions

22
ir.c
View file

@ -2956,7 +2956,7 @@ tailcall:
static bool gen_function_code(ir_function *self)
{
ir_block *block;
prog_section_statement stmt;
prog_section_statement stmt, *retst;
/* Starting from entry point, we generate blocks "as they come"
* for now. Dead blocks will not be translated obviously.
@ -2976,11 +2976,21 @@ static bool gen_function_code(ir_function *self)
}
/* code_write and qcvm -disasm need to know that the function ends here */
stmt.opcode = INSTR_DONE;
stmt.o1.u1 = 0;
stmt.o2.u1 = 0;
stmt.o3.u1 = 0;
code_push_statement(&stmt, vec_last(code_linenums));
retst = &vec_last(code_statements);
if (OPTS_OPTIMIZATION(OPTIM_VOID_RETURN) &&
self->outtype == TYPE_VOID &&
retst->opcode == INSTR_RETURN &&
!retst->o1.u1 && !retst->o2.u1 && !retst->o3.u1)
{
retst->opcode = INSTR_DONE;
++opts_optimizationcount[OPTIM_VOID_RETURN];
} else {
stmt.opcode = INSTR_DONE;
stmt.o1.u1 = 0;
stmt.o2.u1 = 0;
stmt.o3.u1 = 0;
code_push_statement(&stmt, vec_last(code_linenums));
}
return true;
}

View file

@ -87,6 +87,7 @@
GMQCC_DEFINE_FLAG(STRIP_CONSTANT_NAMES, 1)
GMQCC_DEFINE_FLAG(OVERLAP_STRINGS, 2)
GMQCC_DEFINE_FLAG(CALL_STORES, 1)
GMQCC_DEFINE_FLAG(VOID_RETURN, 1)
#endif
/* some cleanup so we don't have to */