More jump removal

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-12-18 13:40:59 +01:00
parent 19deac0707
commit dccafd65ac
3 changed files with 20 additions and 2 deletions

6
code.c
View file

@ -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}};

View file

@ -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

15
ir.c
View file

@ -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;