summaryrefslogtreecommitdiff
path: root/regalloc.c
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-03-22 08:48:45 -0400
committerSøren Sandmann <sandmann@redhat.com>2008-03-22 08:48:45 -0400
commit0598dec09709165c91c40d3a6e6c1266a4f3a8aa (patch)
treec5ac4a6e56d1c43d23c76654696d239ae30b091a /regalloc.c
parentda6f5a08a21bf9a361fc23f37f5657d4138fc7cc (diff)
Use only one location list
Diffstat (limited to 'regalloc.c')
-rw-r--r--regalloc.c105
1 files changed, 15 insertions, 90 deletions
diff --git a/regalloc.c b/regalloc.c
index 34c5f51..cb293f9 100644
--- a/regalloc.c
+++ b/regalloc.c
@@ -25,6 +25,7 @@ struct VarInfo
struct Location
{
+ reg_type_t type;
op_t op;
boolean is_home; /* Whether it is the home location for some variable */
boolean is_current; /* Whether it is the current location for some variable */
@@ -39,10 +40,6 @@ struct RegAlloc
int spill_max;
Location * locations;
-
- Location * gp_locations;
- Location * sse_locations;
- Location * mmx_locations;
Asm * as;
};
@@ -78,24 +75,20 @@ static Location *
new_spill (RegAlloc *ra, reg_type_t type)
{
Location *spill = new0 (Location);
- Location **list;
int n_bytes;
switch (type)
{
case REG_TYPE_GP:
n_bytes = 4;
- list = &ra->gp_locations;
break;
case REG_TYPE_MMX:
n_bytes = 8;
- list = &ra->mmx_locations;
break;
case REG_TYPE_SSE:
n_bytes = 16;
- list = &ra->sse_locations;
break;
};
@@ -109,12 +102,13 @@ new_spill (RegAlloc *ra, reg_type_t type)
spill->is_current = FALSE;
spill->next = NULL;
spill->prev = NULL;
+ spill->type = type;
ra->spill_pos += n_bytes;
ra->spill_max = max (ra->spill_pos, ra->spill_max);
- *list = append (*list, spill);
+ ra->locations = append (ra->locations, spill);
return spill;
}
@@ -123,7 +117,6 @@ static Location *
new_register (RegAlloc *ra, reg_type_t type, reg_t reg)
{
Location *location = new0 (Location);
- Location **list;
location->op.type = REG;
location->op.reg.reg = reg;
@@ -131,23 +124,9 @@ new_register (RegAlloc *ra, reg_type_t type, reg_t reg)
location->is_current = FALSE;
location->next = NULL;
location->prev = NULL;
+ location->type = type;
- switch (type)
- {
- case REG_TYPE_GP:
- list = &ra->gp_locations;
- break;
-
- case REG_TYPE_MMX:
- list = &ra->mmx_locations;
- break;
-
- case REG_TYPE_SSE:
- list = &ra->sse_locations;
- break;
- }
-
- *list = append (*list, location);
+ ra->locations = append (ra->locations, location);
return location;
}
@@ -156,34 +135,13 @@ static Location *
get_home_location (RegAlloc *ra, reg_type_t type)
{
Location *location;
-
- switch (type)
- {
- case REG_TYPE_GP:
- location = ra->gp_locations;
- break;
-
- case REG_TYPE_MMX:
- location = ra->mmx_locations;
- break;
- case REG_TYPE_SSE:
- location = ra->sse_locations;
- break;
-
- default:
- return NULL;
- }
-
- while (location)
+ for (location = ra->locations; location != NULL; location = location->next)
{
- if (!location->is_home)
+ if (location->type == type && !location->is_home)
return location;
-
- location = location->next;
}
- /* Nothing available, create a spill location */
return new_spill (ra, type);
}
@@ -208,9 +166,6 @@ reg_alloc_new (Asm *a)
ra->vars = NULL;
ra->spill_pos = 0;
ra->spill_max = 0;
- ra->gp_locations = NULL;
- ra->sse_locations = NULL;
- ra->mmx_locations = NULL;
ra->as = a;
for (i = 0; i < N_ELEMENTS (gp_registers); ++i)
@@ -307,27 +262,10 @@ find_evict_location (RegAlloc *ra, reg_type_t type)
{
Location *location;
- switch (type)
+ for (location = ra->locations; location != NULL; location = location->next)
{
- case REG_TYPE_GP:
- location = ra->gp_locations;
- break;
-
- case REG_TYPE_MMX:
- location = ra->mmx_locations;
- break;
-
- case REG_TYPE_SSE:
- location = ra->sse_locations;
- break;
- }
-
- while (location)
- {
- if (!location->is_current)
+ if (location->type == type && !location->is_current)
return location;
-
- location = location->next;
}
return new_spill (ra, type);
@@ -372,27 +310,14 @@ get_unused_register (RegAlloc *ra, VarInfo *info)
if (info->home_location->op.type == REG && !info->home_location->is_current)
return info->home_location;
- switch (info->reg_type)
+ for (location = ra->locations; location != NULL; location = location->next)
{
- case REG_TYPE_GP:
- location = ra->gp_locations;
- break;
-
- case REG_TYPE_MMX:
- location = ra->mmx_locations;
- break;
-
- case REG_TYPE_SSE:
- location = ra->sse_locations;
- break;
- }
-
- while (location)
- {
- if (location->op.type == REG && !location->is_current)
+ if (location->type == info->reg_type &&
+ location->op.type == REG &&
+ !location->is_current)
+ {
return location;
-
- location = location->next;
+ }
}
/* No register available, evict some variable */