IR optimization
IR optimization currently very basic, in fact it probably doesn't even improve performance measurably.
This commit is contained in:
parent
850dafbbc9
commit
cf93109f1e
17
ir.c
17
ir.c
@ -124,9 +124,24 @@ void print_ir(IRToks *v, const BuiltinFunc *builtin_funcs) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: ASSERT_UNREACHED(); break;
|
default: ASSERT_UNREACHED();
|
||||||
}
|
}
|
||||||
printf(" ; %zu:%zu", v->toks[i].ln, v->toks[i].col);
|
printf(" ; %zu:%zu", v->toks[i].ln, v->toks[i].col);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void optimize_ir(IRToks *v) {
|
||||||
|
for (size_t i = 0; i < v->len; i++) {
|
||||||
|
switch (v->toks[i].instr) {
|
||||||
|
case IRJmp: {
|
||||||
|
/* resolve jump chains (esp. produced by if-else-if... statements) */
|
||||||
|
size_t ja = i;
|
||||||
|
while (v->toks[ja].instr == IRJmp)
|
||||||
|
ja = v->toks[ja].Jmp.iaddr;
|
||||||
|
v->toks[i].Jmp.iaddr = ja;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2
ir.h
2
ir.h
@ -97,4 +97,6 @@ void irtoks_eat_irtoks(IRToks *v, IRToks *other, size_t jmp_offset);
|
|||||||
|
|
||||||
void print_ir(IRToks *v, const BuiltinFunc *builtin_funcs);
|
void print_ir(IRToks *v, const BuiltinFunc *builtin_funcs);
|
||||||
|
|
||||||
|
void optimize_ir(IRToks *v);
|
||||||
|
|
||||||
#endif /* IR_H */
|
#endif /* IR_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user