allocate temps based on size rather than type (get better re-usage this way)

put temps onto the local scope.
This commit is contained in:
Bill Currie 2001-06-05 05:22:11 +00:00
parent 17e19f3892
commit a26f799de4
4 changed files with 39 additions and 28 deletions

View file

@ -441,7 +441,7 @@ void PR_NewLine (void);
def_t *PR_GetDef (type_t *type, const char *name, def_t *scope,
qboolean allocate);
def_t *PR_NewDef (type_t *type, const char *name, def_t *scope);
def_t *PR_GetTempDef (type_t *type);
def_t *PR_GetTempDef (type_t *type, def_t *scope);
void PR_FreeTempDefs ();
void PR_ResetTempDefs ();
void PR_FlushScope (def_t *scope);

View file

@ -335,6 +335,7 @@ PR_ParseStatement (void)
def_t *e;
dstatement_t *patch1, *patch2;
PR_FreeTempDefs ();
do {
if (PR_Check (tt_punct, "{")) {
do {
@ -364,6 +365,7 @@ PR_ParseStatement (void)
PR_Expect (tt_punct, ")");
patch1 = &statements[numstatements];
PR_Statement (op_ifnot, e, 0);
PR_FreeTempDefs ();
PR_ParseStatement ();
junkdef.ofs = patch2 - &statements[numstatements];
PR_Statement (op_goto, &junkdef, 0);
@ -394,6 +396,7 @@ PR_ParseStatement (void)
PR_Expect (tt_punct, "(");
e = PR_Expression (TOP_PRIORITY);
PR_Expect (tt_punct, ")");
PR_FreeTempDefs ();
patch1 = &statements[numstatements];
PR_Statement (op_ifnot, e, 0);
@ -560,6 +563,13 @@ PR_ParseDefs (void)
// if (pr_dumpasm)
// PR_PrintFunction (def);
//{
// def_t *d;
// printf ("%s\n", def->name);
// for (d = def->scope_next; d; d = d->scope_next) {
// printf ("%s: %d %d %d\n", d->name, d->ofs, d->type->type, type_size[d->type->type]);
// }
//}
// fill in the dfunction
df = &functions[numfunctions];

View file

@ -27,7 +27,7 @@
def_t *pr_global_defs[MAX_REGS]; // to find def for a global variable
int pr_edict_size;
static def_t *free_temps[ev_type_count];
static def_t *free_temps[4]; // indexted by type size
static def_t temp_scope;
static hashtab_t *defs_by_name;
@ -146,49 +146,49 @@ PR_NewDef (type_t *type, const char *name, def_t *scope)
}
def_t *
PR_GetTempDef (type_t *type)
PR_GetTempDef (type_t *type, def_t *scope)
{
int t = type->type;
def_t *d;
if (free_temps[t]) {
d = free_temps[t];
free_temps[t] = d->next;
int size = type_size[type->type];
def_t *def;
if (free_temps[size]) {
def = free_temps[size];
free_temps[size] = def->next;
def->type = type;
} else {
d = PR_NewDef (type, 0, 0);
def = PR_NewDef (type, 0, scope);
}
if (!d->ofs) {
d->ofs = numpr_globals;
numpr_globals += type_size[t];
if (!def->ofs) {
def->ofs = numpr_globals;
numpr_globals += type_size[size];
}
d->scope_next = temp_scope.scope_next;
temp_scope.scope_next = d;
return d;
def->next = temp_scope.next;
temp_scope.next = def;
return def;
}
void
PR_FreeTempDefs (void)
{
def_t *def;
etype_t type;
def_t *def, *d;
int size;
for (def = temp_scope.scope_next; def; def = def->scope_next) {
type = def->type->type;
def->next = free_temps[type];
free_temps[type] = def;
for (def = temp_scope.next; def; def = d) {
size = type_size[def->type->type];
d = def->next;
def->next = free_temps[size];
free_temps[size] = def;
}
temp_scope.scope_next = 0;
temp_scope.next = 0;
}
void
PR_ResetTempDefs (void)
{
int i;
def_t *d;
//def_t *d;
for (i = 0; i < ev_type_count; i++) {
for (d = free_temps[i]; d && d->ofs; d = d->next) {
d->ofs = 0;
}
free_temps[i] = 0;
}
}
@ -198,6 +198,7 @@ PR_FlushScope (def_t *scope)
def_t *def;
for (def = scope->scope_next; def; def = def->scope_next) {
if (def->name)
Hash_Del (defs_by_name, def->name);
}
}

View file

@ -154,7 +154,7 @@ PR_Statement (opcode_t * op, def_t * var_a, def_t * var_b)
var_c = NULL;
statement->c = 0;
} else { // allocate result space
var_c = PR_GetTempDef (op->type_c->type);
var_c = PR_GetTempDef (op->type_c->type, pr_scope);
statement->c = var_c->ofs;
}