return (hreg->attrs & c->attrs);
}
+static struct hreg* find_input_reg(struct vreg* vreg)
+{
+ int i;
+ struct hreg* hreg = NULL;
+
+ for (i=0; i<hregs.count; i++)
+ {
+ hreg = hregs.item[i];
+ if (allocatable(hreg, vreg) &&
+ !pmap_findleft(current_ins, hreg))
+ {
+ return hreg;
+ }
+ }
+
+ return NULL;
+}
+
+static struct hreg* find_output_reg(struct vreg* vreg)
+{
+ int i;
+ struct hreg* hreg = NULL;
+
+ for (i=0; i<hregs.count; i++)
+ {
+ hreg = hregs.item[i];
+ if (allocatable(hreg, vreg) &&
+ !pmap_findleft(current_outs, hreg))
+ {
+ return hreg;
+ }
+ }
+
+ return NULL;
+}
+
+static struct hreg* find_through_reg(struct vreg* vreg)
+{
+ int i;
+ struct hreg* hreg = NULL;
+
+ for (i=0; i<hregs.count; i++)
+ {
+ hreg = hregs.item[i];
+ if (allocatable(hreg, vreg) &&
+ !pmap_findleft(current_ins, hreg) &&
+ !pmap_findleft(current_outs, hreg))
+ {
+ return hreg;
+ }
+ }
+
+ return NULL;
+}
+
static void add_input_register(struct vreg* vreg, struct hreg* hreg)
{
int i;
/* Find an unused input register of the right class. */
- hreg = NULL;
- for (i=0; i<hregs.count; i++)
- {
- hreg = hregs.item[i];
- if (allocatable(hreg, vreg) &&
- !pmap_findright(current_ins, vreg))
- {
- /* Got one --- use it. */
- pmap_add(current_ins, hreg, vreg);
- return;
- }
- }
+ hreg = find_input_reg(vreg);
+ if (!hreg)
+ hreg = evict(hreg);
- /* Um, oops --- ran out of registers. Evict one and try again. */
- assert(false);
+ pmap_add(current_ins, hreg, vreg);
}
static void add_output_register(struct vreg* vreg)
* way: we try to allocate a matched set of input and output registers.
* */
- hreg = NULL;
- for (i=0; i<hregs.count; i++)
- {
- hreg = hregs.item[i];
- if (allocatable(hreg, vreg) &&
- !pmap_findleft(current_ins, hreg) &&
- !pmap_findleft(current_outs, hreg))
- {
- goto found1;
- }
- }
-
- /* If we couldn't find one, evict a register. */
+ hreg = find_through_reg(vreg);
+ if (!hreg)
+ hreg = evict(vreg);
- hreg = evict(vreg);
- found1:
pmap_add(current_outs, hreg, vreg);
+ tracef('R', "R: output equality constraint requires extra move of %%%d => %s\n",
+ c->equals_to->id, hreg->name);
pmap_add(current_ins, hreg, c->equals_to);
}
else
{
/* This is an ordinary new register. */
- hreg = NULL;
- for (i=0; i<hregs.count; i++)
- {
- hreg = hregs.item[i];
- if (allocatable(hreg, vreg) &&
- !pmap_findleft(current_outs, hreg))
- {
- goto found2;
- }
- }
-
- /* If we couldn't find one, evict a register. */
-
- hreg = evict(vreg);
+ hreg = find_output_reg(vreg);
+ if (!hreg)
+ hreg = evict(vreg);
- found2:
pmap_add(current_outs, hreg, vreg);
}
}