From: David Given Date: Fri, 16 Dec 2016 21:16:45 +0000 (+0100) Subject: Add hashtable/set_empty to go with _reset, which removes all items from the X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=8bfb9eed3c7a4d0f37ac190944ecbf629a3d3c87;p=ack.git Add hashtable/set_empty to go with _reset, which removes all items from the table but doesn't free the bucket array or reset the size --- saves an allocation when reusing the hashtable. --- diff --git a/mach/proto/mcg/pass_livevreganalysis.c b/mach/proto/mcg/pass_livevreganalysis.c index 5481c6598..7e361b929 100644 --- a/mach/proto/mcg/pass_livevreganalysis.c +++ b/mach/proto/mcg/pass_livevreganalysis.c @@ -23,32 +23,63 @@ static void preload_blocks(void) } } +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; icount; 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; icount; 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; iphis.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; iprevs.count; i++) { struct basicblock* prev = bb->prevs.item[i]; - finished &= array_appendallu(&prev->liveouts, ¤t); + finished &= add_set_to_array(¤t, &prev->liveouts); } } @@ -67,8 +98,6 @@ void pass_live_vreg_analysis(void) propagate_liveness(dominance.postorder.item[i]); } while (!finished); - - //assert(cfg.entry->liveins.count == 0); } /* vim: set sw=4 ts=4 expandtab : */ diff --git a/mach/proto/mcg/pass_nonlocalphis.c b/mach/proto/mcg/pass_nonlocalphis.c index 55dfed247..8f0fdc732 100644 --- a/mach/proto/mcg/pass_nonlocalphis.c +++ b/mach/proto/mcg/pass_nonlocalphis.c @@ -121,8 +121,8 @@ static void import_ir(struct ir* phi) { int i; - set_reset(&confirmed); - set_reset(&pending); + set_empty(&confirmed); + set_empty(&pending); recursively_add_children_to_pending(current_dest); set_add(&confirmed, current_dest); diff --git a/mach/proto/mcg/pass_removedeadphis.c b/mach/proto/mcg/pass_removedeadphis.c index 8d46b80d2..fb53f751d 100644 --- a/mach/proto/mcg/pass_removedeadphis.c +++ b/mach/proto/mcg/pass_removedeadphis.c @@ -70,7 +70,7 @@ void pass_remove_dead_phis(void) { changed = false; - set_reset(&phis); + set_empty(&phis); for (i=0; ibuckets = calloc(ht->num_buckets, sizeof(struct hashnode*)); } -void hashtable_reset(struct hashtable* ht) +void hashtable_empty(struct hashtable* ht) { while (ht->size) hashtable_pop(ht); +} +void hashtable_reset(struct hashtable* ht) +{ + hashtable_empty(ht); free(ht->buckets); ht->buckets = NULL; } diff --git a/modules/src/data/hashtable.h b/modules/src/data/hashtable.h index e89a05225..2838d81b1 100644 --- a/modules/src/data/hashtable.h +++ b/modules/src/data/hashtable.h @@ -29,6 +29,7 @@ struct hashtable_iterator struct hashnode* node; }; +extern void hashtable_empty(struct hashtable* ht); extern void hashtable_reset(struct hashtable* ht); extern void hashtable_rebucket(struct hashtable* ht, unsigned int num_buckets); diff --git a/modules/src/data/set.c b/modules/src/data/set.c index 4a437d8f2..fd0ab9aac 100644 --- a/modules/src/data/set.c +++ b/modules/src/data/set.c @@ -3,6 +3,11 @@ #include #include "set.h" +void set_empty(struct set* s) +{ + hashtable_empty(&s->table); +} + void set_reset(struct set* s) { hashtable_reset(&s->table); diff --git a/modules/src/data/set.h b/modules/src/data/set.h index 7cce54f24..97956811e 100644 --- a/modules/src/data/set.h +++ b/modules/src/data/set.h @@ -10,6 +10,7 @@ struct set struct hashtable table; }; +extern void set_empty(struct set* s); extern void set_reset(struct set* s); extern bool set_add(struct set* s, void* item);