From af5b552a7f08b0115f620d999043e5722d6cdadb Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 26 Dec 2012 10:24:33 +0100 Subject: [PATCH] -Ovoid-return - the last INSTR_RETURN of a void functions is replaced by INSTR_DONE to reduce the instruction count --- ir.c | 22 ++++++++++++++++------ opts.def | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ir.c b/ir.c index 6f9e488..ec87bd7 100644 --- a/ir.c +++ b/ir.c @@ -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; } diff --git a/opts.def b/opts.def index 3fbe104..5d76039 100644 --- a/opts.def +++ b/opts.def @@ -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 */ -- 2.39.2