mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-31 05:00:35 +00:00
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:
parent
17e19f3892
commit
a26f799de4
4 changed files with 39 additions and 28 deletions
|
@ -441,7 +441,7 @@ void PR_NewLine (void);
|
||||||
def_t *PR_GetDef (type_t *type, const char *name, def_t *scope,
|
def_t *PR_GetDef (type_t *type, const char *name, def_t *scope,
|
||||||
qboolean allocate);
|
qboolean allocate);
|
||||||
def_t *PR_NewDef (type_t *type, const char *name, def_t *scope);
|
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_FreeTempDefs ();
|
||||||
void PR_ResetTempDefs ();
|
void PR_ResetTempDefs ();
|
||||||
void PR_FlushScope (def_t *scope);
|
void PR_FlushScope (def_t *scope);
|
||||||
|
|
|
@ -335,6 +335,7 @@ PR_ParseStatement (void)
|
||||||
def_t *e;
|
def_t *e;
|
||||||
dstatement_t *patch1, *patch2;
|
dstatement_t *patch1, *patch2;
|
||||||
|
|
||||||
|
PR_FreeTempDefs ();
|
||||||
do {
|
do {
|
||||||
if (PR_Check (tt_punct, "{")) {
|
if (PR_Check (tt_punct, "{")) {
|
||||||
do {
|
do {
|
||||||
|
@ -364,6 +365,7 @@ PR_ParseStatement (void)
|
||||||
PR_Expect (tt_punct, ")");
|
PR_Expect (tt_punct, ")");
|
||||||
patch1 = &statements[numstatements];
|
patch1 = &statements[numstatements];
|
||||||
PR_Statement (op_ifnot, e, 0);
|
PR_Statement (op_ifnot, e, 0);
|
||||||
|
PR_FreeTempDefs ();
|
||||||
PR_ParseStatement ();
|
PR_ParseStatement ();
|
||||||
junkdef.ofs = patch2 - &statements[numstatements];
|
junkdef.ofs = patch2 - &statements[numstatements];
|
||||||
PR_Statement (op_goto, &junkdef, 0);
|
PR_Statement (op_goto, &junkdef, 0);
|
||||||
|
@ -394,6 +396,7 @@ PR_ParseStatement (void)
|
||||||
PR_Expect (tt_punct, "(");
|
PR_Expect (tt_punct, "(");
|
||||||
e = PR_Expression (TOP_PRIORITY);
|
e = PR_Expression (TOP_PRIORITY);
|
||||||
PR_Expect (tt_punct, ")");
|
PR_Expect (tt_punct, ")");
|
||||||
|
PR_FreeTempDefs ();
|
||||||
|
|
||||||
patch1 = &statements[numstatements];
|
patch1 = &statements[numstatements];
|
||||||
PR_Statement (op_ifnot, e, 0);
|
PR_Statement (op_ifnot, e, 0);
|
||||||
|
@ -560,6 +563,13 @@ PR_ParseDefs (void)
|
||||||
|
|
||||||
// if (pr_dumpasm)
|
// if (pr_dumpasm)
|
||||||
// PR_PrintFunction (def);
|
// 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
|
// fill in the dfunction
|
||||||
df = &functions[numfunctions];
|
df = &functions[numfunctions];
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
def_t *pr_global_defs[MAX_REGS]; // to find def for a global variable
|
def_t *pr_global_defs[MAX_REGS]; // to find def for a global variable
|
||||||
int pr_edict_size;
|
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 def_t temp_scope;
|
||||||
|
|
||||||
static hashtab_t *defs_by_name;
|
static hashtab_t *defs_by_name;
|
||||||
|
@ -146,49 +146,49 @@ PR_NewDef (type_t *type, const char *name, def_t *scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
def_t *
|
def_t *
|
||||||
PR_GetTempDef (type_t *type)
|
PR_GetTempDef (type_t *type, def_t *scope)
|
||||||
{
|
{
|
||||||
int t = type->type;
|
int size = type_size[type->type];
|
||||||
def_t *d;
|
def_t *def;
|
||||||
if (free_temps[t]) {
|
if (free_temps[size]) {
|
||||||
d = free_temps[t];
|
def = free_temps[size];
|
||||||
free_temps[t] = d->next;
|
free_temps[size] = def->next;
|
||||||
|
def->type = type;
|
||||||
} else {
|
} else {
|
||||||
d = PR_NewDef (type, 0, 0);
|
def = PR_NewDef (type, 0, scope);
|
||||||
}
|
}
|
||||||
if (!d->ofs) {
|
if (!def->ofs) {
|
||||||
d->ofs = numpr_globals;
|
def->ofs = numpr_globals;
|
||||||
numpr_globals += type_size[t];
|
numpr_globals += type_size[size];
|
||||||
}
|
}
|
||||||
d->scope_next = temp_scope.scope_next;
|
def->next = temp_scope.next;
|
||||||
temp_scope.scope_next = d;
|
temp_scope.next = def;
|
||||||
return d;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PR_FreeTempDefs (void)
|
PR_FreeTempDefs (void)
|
||||||
{
|
{
|
||||||
def_t *def;
|
def_t *def, *d;
|
||||||
etype_t type;
|
int size;
|
||||||
|
|
||||||
for (def = temp_scope.scope_next; def; def = def->scope_next) {
|
for (def = temp_scope.next; def; def = d) {
|
||||||
type = def->type->type;
|
size = type_size[def->type->type];
|
||||||
def->next = free_temps[type];
|
d = def->next;
|
||||||
free_temps[type] = def;
|
def->next = free_temps[size];
|
||||||
|
free_temps[size] = def;
|
||||||
}
|
}
|
||||||
temp_scope.scope_next = 0;
|
temp_scope.next = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PR_ResetTempDefs (void)
|
PR_ResetTempDefs (void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
def_t *d;
|
//def_t *d;
|
||||||
|
|
||||||
for (i = 0; i < ev_type_count; i++) {
|
for (i = 0; i < ev_type_count; i++) {
|
||||||
for (d = free_temps[i]; d && d->ofs; d = d->next) {
|
free_temps[i] = 0;
|
||||||
d->ofs = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,6 +198,7 @@ PR_FlushScope (def_t *scope)
|
||||||
def_t *def;
|
def_t *def;
|
||||||
|
|
||||||
for (def = scope->scope_next; def; def = def->scope_next) {
|
for (def = scope->scope_next; def; def = def->scope_next) {
|
||||||
Hash_Del (defs_by_name, def->name);
|
if (def->name)
|
||||||
|
Hash_Del (defs_by_name, def->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ PR_Statement (opcode_t * op, def_t * var_a, def_t * var_b)
|
||||||
var_c = NULL;
|
var_c = NULL;
|
||||||
statement->c = 0;
|
statement->c = 0;
|
||||||
} else { // allocate result space
|
} 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;
|
statement->c = var_c->ofs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue