mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-30 08:00:51 +00:00
Split out the statement array building.
This commit is contained in:
parent
17a2f86a22
commit
2bc3a36126
1 changed files with 48 additions and 37 deletions
|
@ -287,12 +287,32 @@ param_symbol (const char *name)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
flow_build_vars (function_t *func)
|
flow_build_statements (function_t *func)
|
||||||
{
|
{
|
||||||
sblock_t *sblock;
|
sblock_t *sblock;
|
||||||
statement_t *s;
|
statement_t *s;
|
||||||
int num_vars = 0;
|
|
||||||
int num_statements = 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;
|
int i;
|
||||||
|
|
||||||
// first, count .return and .param_[0-7] as they are always needed
|
// first, count .return and .param_[0-7] as they are always needed
|
||||||
|
@ -302,44 +322,34 @@ flow_build_vars (function_t *func)
|
||||||
}
|
}
|
||||||
// then run through the statements in the function looking for accessed
|
// then run through the statements in the function looking for accessed
|
||||||
// variables
|
// variables
|
||||||
for (sblock = func->sblock; sblock; sblock = sblock->next) {
|
for (i = 0; i < func->num_statements; i++) {
|
||||||
for (s = sblock->statements; s; s = s->next) {
|
s = func->statements[i];
|
||||||
num_vars += count_operand (s->opa);
|
num_vars += count_operand (s->opa);
|
||||||
num_vars += count_operand (s->opb);
|
num_vars += count_operand (s->opb);
|
||||||
num_vars += count_operand (s->opc);
|
num_vars += count_operand (s->opc);
|
||||||
s->number = num_statements++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (num_vars) {
|
if (!num_vars)
|
||||||
func->vars = malloc (num_vars * sizeof (daglabel_t *));
|
return;
|
||||||
|
|
||||||
func->num_vars = 0; // incremented by add_operand
|
func->vars = malloc (num_vars * sizeof (daglabel_t *));
|
||||||
// first, add .return and .param_[0-7] as they are always needed
|
|
||||||
for (i = 0; i < num_flow_params; i++)
|
func->num_vars = 0; // incremented by add_operand
|
||||||
add_operand (func, &flow_params[i].op);
|
// first, add .return and .param_[0-7] as they are always needed
|
||||||
// then run through the statements in the function adding accessed
|
for (i = 0; i < num_flow_params; i++)
|
||||||
// variables
|
add_operand (func, &flow_params[i].op);
|
||||||
for (sblock = func->sblock; sblock; sblock = sblock->next) {
|
// then run through the statements in the function adding accessed
|
||||||
for (s = sblock->statements; s; s = s->next) {
|
// variables
|
||||||
add_operand (func, s->opa);
|
for (i = 0; i < func->num_statements; i++) {
|
||||||
add_operand (func, s->opb);
|
s = func->statements[i];
|
||||||
add_operand (func, s->opc);
|
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->global_vars = set_new ();
|
||||||
func->statements = malloc (num_statements * sizeof (statement_t *));
|
// mark all global vars (except .return and .param_N)
|
||||||
func->num_statements = num_statements;
|
for (i = num_flow_params; i < func->num_vars; i++) {
|
||||||
for (sblock = func->sblock; sblock; sblock = sblock->next) {
|
if (flowvar_is_global (func->vars[i]))
|
||||||
for (s = sblock->statements; s; s = s->next)
|
set_add (func->global_vars, i);
|
||||||
func->statements[s->number] = s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -961,6 +971,7 @@ flow_data_flow (function_t *func)
|
||||||
set_t *stdef = set_new ();
|
set_t *stdef = set_new ();
|
||||||
set_iter_t *var_i;
|
set_iter_t *var_i;
|
||||||
|
|
||||||
|
flow_build_statements (func);
|
||||||
flow_build_vars (func);
|
flow_build_vars (func);
|
||||||
graph = flow_build_graph (func);
|
graph = flow_build_graph (func);
|
||||||
func->graph = graph;
|
func->graph = graph;
|
||||||
|
|
Loading…
Reference in a new issue