Split out the statement array building.

This commit is contained in:
Bill Currie 2012-12-09 21:12:53 +09:00
parent 17a2f86a22
commit 2bc3a36126

View file

@ -287,12 +287,32 @@ param_symbol (const char *name)
}
static void
flow_build_vars (function_t *func)
flow_build_statements (function_t *func)
{
sblock_t *sblock;
statement_t *s;
int num_vars = 0;
int num_statements = 0;
for (sblock = func->sblock; sblock; sblock = sblock->next) {
for (s = sblock->statements; s; s = s->next)
s->number = num_statements++;
}
if (!num_statements)
return;
func->statements = malloc (num_statements * sizeof (statement_t *));
func->num_statements = num_statements;
for (sblock = func->sblock; sblock; sblock = sblock->next) {
for (s = sblock->statements; s; s = s->next)
func->statements[s->number] = s;
}
}
static void
flow_build_vars (function_t *func)
{
statement_t *s;
int num_vars = 0;
int i;
// first, count .return and .param_[0-7] as they are always needed
@ -302,15 +322,15 @@ flow_build_vars (function_t *func)
}
// then run through the statements in the function looking for accessed
// variables
for (sblock = func->sblock; sblock; sblock = sblock->next) {
for (s = sblock->statements; s; s = s->next) {
for (i = 0; i < func->num_statements; i++) {
s = func->statements[i];
num_vars += count_operand (s->opa);
num_vars += count_operand (s->opb);
num_vars += count_operand (s->opc);
s->number = num_statements++;
}
}
if (num_vars) {
if (!num_vars)
return;
func->vars = malloc (num_vars * sizeof (daglabel_t *));
func->num_vars = 0; // incremented by add_operand
@ -319,28 +339,18 @@ flow_build_vars (function_t *func)
add_operand (func, &flow_params[i].op);
// then run through the statements in the function adding accessed
// variables
for (sblock = func->sblock; sblock; sblock = sblock->next) {
for (s = sblock->statements; s; s = s->next) {
for (i = 0; i < func->num_statements; i++) {
s = func->statements[i];
add_operand (func, s->opa);
add_operand (func, s->opb);
add_operand (func, s->opc);
}
}
func->global_vars = set_new ();
// mark all global vars (except .return and .param_N)
for (i = num_flow_params; i < func->num_vars; i++) {
if (flowvar_is_global (func->vars[i]))
set_add (func->global_vars, i);
}
}
if (num_statements) {
func->statements = malloc (num_statements * sizeof (statement_t *));
func->num_statements = num_statements;
for (sblock = func->sblock; sblock; sblock = sblock->next) {
for (s = sblock->statements; s; s = s->next)
func->statements[s->number] = s;
}
}
}
static void
@ -961,6 +971,7 @@ flow_data_flow (function_t *func)
set_t *stdef = set_new ();
set_iter_t *var_i;
flow_build_statements (func);
flow_build_vars (func);
graph = flow_build_graph (func);
func->graph = graph;