}
}
+static bool add_set_to_array(struct set* set, void* arrayp)
+{
+ bool nochange = true;
+ struct array* array = arrayp;
+ struct set_iterator sit = {};
+
+ while (set_next(set, &sit))
+ nochange &= array_appendu(array, sit.item);
+
+ return nochange;
+}
+
+static void add_array_to_set(void* arrayp, struct set* set)
+{
+ struct array* array = arrayp;
+ int i;
+
+ for (i=0; i<array->count; i++)
+ set_add(set, array->item[i]);
+}
+
+static void remove_array_from_set(void* arrayp, struct set* set)
+{
+ struct array* array = arrayp;
+ int i;
+
+ for (i=0; i<array->count; i++)
+ set_remove(set, array->item[i]);
+}
+
static void propagate_liveness(struct basicblock* bb)
{
- static ARRAYOF(struct vreg) current;
- int i;
+ static struct set current;
+ int i, j;
- current.count = 0;
- array_appendall(¤t, &bb->liveouts);
+ set_empty(¤t);
+
+ add_array_to_set(&bb->liveouts, ¤t);
for (i=bb->hops.count-1; i>=0; i--)
{
struct hop* hop = bb->hops.item[i];
- array_removeall(¤t, &hop->outs);
- finished &= array_appendallu(&hop->throughs, ¤t);
- array_appendallu(¤t, &hop->ins);
+ remove_array_from_set(&hop->outs, ¤t);
+ finished &= add_set_to_array(¤t, &hop->throughs);
+ add_array_to_set(&hop->ins, ¤t);
}
for (i=0; i<bb->phis.count; i++)
- array_remove(¤t, bb->phis.item[i].left);
+ set_remove(¤t, bb->phis.item[i].left);
- finished &= array_appendallu(&bb->liveins, ¤t);
+ finished &= add_set_to_array(¤t, &bb->liveins);
for (i=0; i<bb->prevs.count; i++)
{
struct basicblock* prev = bb->prevs.item[i];
- finished &= array_appendallu(&prev->liveouts, ¤t);
+ finished &= add_set_to_array(¤t, &prev->liveouts);
}
}
propagate_liveness(dominance.postorder.item[i]);
}
while (!finished);
-
- //assert(cfg.entry->liveins.count == 0);
}
/* vim: set sw=4 ts=4 expandtab : */