mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 07:11:41 +00:00
Implement jump threading.
First real optimization :)
This commit is contained in:
parent
78a9ba2557
commit
43b5edf46b
2 changed files with 49 additions and 0 deletions
|
@ -1036,6 +1036,37 @@ remove_label_from_dest (ex_label_t *label)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
thread_jumps (sblock_t *blocks)
|
||||
{
|
||||
sblock_t *sblock;
|
||||
ex_label_t *label, *l;
|
||||
statement_t *s;
|
||||
|
||||
if (!blocks)
|
||||
return;
|
||||
for (sblock = blocks; sblock->next; sblock = sblock->next) {
|
||||
s = (statement_t *) sblock->tail;
|
||||
if (!strcmp (s->opcode, "<GOTO>"))
|
||||
label = s->opa->o.label;
|
||||
else if (!strncmp (s->opcode, "<IF", 3))
|
||||
label = s->opb->o.label;
|
||||
else
|
||||
continue;
|
||||
for (l = label;
|
||||
(l->dest->statements
|
||||
&& !strcmp (l->dest->statements->opcode, "<GOTO>"));
|
||||
l = l->dest->statements->opa->o.label) {
|
||||
}
|
||||
if (l != label) {
|
||||
if (!strcmp (s->opcode, "<GOTO>"))
|
||||
s->opa->o.label = l;
|
||||
else if (!strncmp (s->opcode, "<IF", 3))
|
||||
s->opb->o.label = l;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
remove_dead_blocks (sblock_t *blocks)
|
||||
{
|
||||
|
@ -1127,6 +1158,8 @@ make_statements (expr_t *e)
|
|||
sblock_t *sblock = new_sblock ();
|
||||
// print_expr (e);
|
||||
statement_slist (sblock, e);
|
||||
// print_flow (sblock);
|
||||
thread_jumps (sblock);
|
||||
// print_flow (sblock);
|
||||
remove_dead_blocks (sblock);
|
||||
// print_flow (sblock);
|
||||
|
|
16
tools/qfcc/test/thread-jumps.r
Normal file
16
tools/qfcc/test/thread-jumps.r
Normal file
|
@ -0,0 +1,16 @@
|
|||
int
|
||||
foo (int bar)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
for (x = 0; x < bar; x++) {
|
||||
for (y = 0; y < bar; y++) {
|
||||
if (x * y > bar)
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return x * y;
|
||||
}
|
Loading…
Reference in a new issue