From: Wolfgang (Blub) Bumiller Date: Tue, 18 Dec 2012 12:40:59 +0000 (+0100) Subject: More jump removal X-Git-Tag: 0.1.9~59 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=dccafd65ac55b806b5f6e7232de5f184d8403b2d;p=xonotic%2Fgmqcc.git More jump removal --- diff --git a/code.c b/code.c index 964797f..3c418b1 100644 --- a/code.c +++ b/code.c @@ -39,6 +39,12 @@ void code_push_statement(prog_section_statement *stmt, int linenum) vec_push(code_linenums, linenum); } +void code_pop_statement() +{ + vec_pop(code_statements); + vec_pop(code_linenums); +} + void code_init() { prog_section_function empty_function = {0,0,0,0,0,0,0,{0}}; prog_section_statement empty_statement = {0,{0},{0},{0}}; diff --git a/gmqcc.h b/gmqcc.h index b95bac4..df123c6 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -573,6 +573,7 @@ qcint code_alloc_field (size_t qcsize); /* this function is used to keep statements and linenumbers together */ void code_push_statement(prog_section_statement *stmt, int linenum); +void code_pop_statement(); /* * A shallow copy of a lex_file to remember where which ast node diff --git a/ir.c b/ir.c index 6bc766c..2375d55 100644 --- a/ir.c +++ b/ir.c @@ -2743,8 +2743,7 @@ tailcall: ontrue = tmp; } stidx = vec_size(code_statements); - if (stmt.o2.s1 != 1) - code_push_statement(&stmt, instr->context.line); + code_push_statement(&stmt, instr->context.line); /* on false we jump, so add ontrue-path */ if (!gen_blocks_recursive(func, ontrue)) return false; @@ -2754,6 +2753,12 @@ tailcall: if (onfalse->generated) { /* fixup the jump address */ code_statements[stidx].o2.s1 = (onfalse->code_start) - (stidx); + if (code_statements[stidx].o2.s1 == 1) { + code_statements[stidx] = code_statements[stidx+1]; + if (code_statements[stidx].o1.s1 < 0) + code_statements[stidx].o1.s1++; + code_pop_statement(); + } stmt.opcode = vec_last(code_statements).opcode; if (stmt.opcode == INSTR_GOTO || stmt.opcode == INSTR_IF || @@ -2773,6 +2778,12 @@ tailcall: code_push_statement(&stmt, instr->context.line); return true; } + else if (code_statements[stidx].o2.s1 == 1) { + code_statements[stidx] = code_statements[stidx+1]; + if (code_statements[stidx].o1.s1 < 0) + code_statements[stidx].o1.s1++; + code_pop_statement(); + } /* if not, generate now */ block = onfalse; goto tailcall;