X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firedges.c;h=73a52146133f206f5a23e46e6f7400f4933a3135;hb=1b092e5efbe2f3ae70b83bf89b20144002728569;hp=7eb0197aa44ecf04a73f2e8df40058ba927e8a09;hpb=12b680b45d40312393d75644484cf72f8215666d;p=libfirm diff --git a/ir/ir/iredges.c b/ir/ir/iredges.c index 7eb0197aa..73a521461 100644 --- a/ir/ir/iredges.c +++ b/ir/ir/iredges.c @@ -27,9 +27,7 @@ * This are out-edges (also called def-use edges) that are dynamically * updated as the graph changes. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include "irnode_t.h" #include "iropt_t.h" @@ -38,11 +36,10 @@ #include "irgwalk.h" #include "irdump_t.h" #include "irprintf.h" -#include "irhooks.h" #include "debug.h" #include "set.h" #include "bitset.h" -#include "xmalloc.h" +#include "error.h" #include "iredgeset.h" #include "hashptr.h" @@ -54,7 +51,7 @@ #define ValueType ir_edge_t* #define NullValue NULL #define DeletedValue ((ir_edge_t*)-1) -#define Hash(this,key) (HASH_PTR(key->src) ^ key->pos) +#define Hash(this,key) (HASH_PTR(key->src) ^ (key->pos * 40013)) #define KeysEqual(this,key1,key2) ((key1->src) == (key2->src) && (key1->pos == key2->pos)) #define SetRangeEmpty(ptr,size) memset(ptr, 0, (size) * sizeof((ptr)[0])) @@ -138,7 +135,7 @@ static int edges_dbg = 0; static long last_edge_num = -1; #endif -static INLINE long edge_get_id(const ir_edge_t *e) { +static inline long edge_get_id(const ir_edge_t *e) { #ifdef DEBUG_libfirm return e->edge_nr; #else /* DEBUG_libfirm */ @@ -166,12 +163,12 @@ int edges_register_private_data(size_t n) { return res; } -/** +/* * Reset the user's private data at offset 'offset' * The user has to remember his offset and the size of his data! * Caution: Using wrong values here can destroy other users private data! */ -void edges_reset_private_data(ir_graph *irg, int offset, size_t size) { +void edges_reset_private_data(ir_graph *irg, int offset, unsigned size) { irg_edge_info_t *info = _get_irg_edge_info(irg, EDGE_KIND_NORMAL); ir_edge_t *edge; ir_edgeset_iterator_t iter; @@ -194,7 +191,7 @@ void edges_reset_private_data(ir_graph *irg, int offset, size_t size) { void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind) { if (edges_activated_kind(irg, kind)) { irg_edge_info_t *info = _get_irg_edge_info(irg, kind); - size_t amount = 32; + size_t amount = irg->estimated_node_count * 2; edges_used = 1; if(info->allocated) { @@ -203,6 +200,7 @@ void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind) { obstack_free(&info->edges_obst, NULL); } obstack_init(&info->edges_obst); + INIT_LIST_HEAD(&info->free_edges); ir_edgeset_init_size(&info->edges, amount); info->allocated = 1; } @@ -248,7 +246,7 @@ const ir_edge_t *get_irn_edge(ir_graph *irg, const ir_node *src, int pos) { * @param tgt the edge target * @param kind the kind of the edge */ -static INLINE void edge_change_cnt(ir_node *tgt, ir_edge_kind_t kind, int ofs) { +static inline void edge_change_cnt(ir_node *tgt, ir_edge_kind_t kind, int ofs) { irn_edge_info_t *info = _get_irn_edge_info(tgt, kind); info->out_count += ofs; @@ -277,7 +275,7 @@ static INLINE void edge_change_cnt(ir_node *tgt, ir_edge_kind_t kind, int ofs) { * Verify the edge list of a node, ie. ensure it's a loop: * head -> e_1 -> ... -> e_n -> head */ -static INLINE void vrfy_list_head(ir_node *irn, ir_edge_kind_t kind) { +static inline void vrfy_list_head(ir_node *irn, ir_edge_kind_t kind) { int err = 0; int num = 0; pset *lh_set = pset_new_ptr(16); @@ -343,6 +341,8 @@ void edges_notify_edge_kind(ir_node *src, int pos, ir_node *tgt, if (edge) { msg = "deleting"; list_del(&edge->list); + ir_edgeset_remove(edges, edge); + list_add(&edge->list, &info->free_edges); edge->invalid = 1; edge->pos = -2; edge->src = NULL; @@ -350,21 +350,17 @@ void edges_notify_edge_kind(ir_node *src, int pos, ir_node *tgt, edge->edge_nr = -1; #endif /* DEBUG_libfirm */ edge_change_cnt(old_tgt, kind, -1); - } - - /* If the edge was not found issue a warning on the debug stream */ - else { + } else { + /* If the edge was not found issue a warning on the debug stream */ msg = "edge to delete not found!\n"; } - } /* if */ - - /* - * The target is not NULL and the old target differs - * from the new target, the edge shall be moved (if the - * old target was != NULL) or added (if the old target was - * NULL). - */ - else { + } else { + /* + * The target is not NULL and the old target differs + * from the new target, the edge shall be moved (if the + * old target was != NULL) or added (if the old target was + * NULL). + */ struct list_head *head = _get_irn_outs_head(tgt, kind); assert(head->next && head->prev && @@ -380,33 +376,36 @@ void edges_notify_edge_kind(ir_node *src, int pos, ir_node *tgt, list_move(&edge->list, head); edge_change_cnt(old_tgt, kind, -1); - } - - /* The old target was null, thus, the edge is newly created. */ - else { + } else { + /* The old target was NULL, thus, the edge is newly created. */ ir_edge_t *new_edge; - ir_edge_t *edge - = obstack_alloc(&info->edges_obst, EDGE_SIZE); - memset(edge, 0, EDGE_SIZE); - edge->src = src; - edge->pos = pos; - edge->kind = kind; + ir_edge_t *edge; + + if (list_empty(&info->free_edges)) { + edge = obstack_alloc(&info->edges_obst, EDGE_SIZE); + } else { + edge = list_entry(info->free_edges.next, ir_edge_t, list); + list_del(&edge->list); + } + + edge->src = src; + edge->pos = pos; + edge->invalid = 0; + edge->present = 0; + edge->kind = kind; + edge->list.next = NULL; + edge->list.prev = NULL; + memset(((char*)edge) + sizeof(ir_edge_t), 0, edges_private_size); DEBUG_ONLY(edge->src_nr = get_irn_node_nr(src)); new_edge = ir_edgeset_insert(edges, edge); - if(new_edge != edge) { - obstack_free(&info->edges_obst, edge); + if (new_edge != edge) { + panic("new edge exists already"); } - assert(! edge->invalid && "Freshly inserted edge is invalid?!?"); - assert(edge->list.next == NULL && edge->list.prev == NULL && - "New edge must not have list head initialized"); - msg = "adding"; list_add(&edge->list, head); -#ifdef DEBUG_libfirm - edge->edge_nr = ++last_edge_num; -#endif /* DEBUG_libfirm */ + DEBUG_ONLY(edge->edge_nr = ++last_edge_num); } edge_change_cnt(tgt, kind, +1); @@ -485,9 +484,6 @@ static void build_edges_walker(ir_node *irn, void *data) { ir_graph *irg = w->irg; get_edge_src_n_func_t *get_n; - if (! edges_activated_kind(irg, kind)) - return; - get_n = edge_kind_info[kind].get_n; foreach_tgt(irn, i, n, kind) { ir_node *pred = get_n(irn, i, kind); @@ -502,18 +498,56 @@ static void build_edges_walker(ir_node *irn, void *data) { static void init_lh_walker(ir_node *irn, void *data) { struct build_walker *w = data; ir_edge_kind_t kind = w->kind; - INIT_LIST_HEAD(_get_irn_outs_head(irn, kind)); + list_head *head = _get_irn_outs_head(irn, kind); + INIT_LIST_HEAD(head); _get_irn_edge_info(irn, kind)->out_count = 0; } +/** + * Pre-Walker: initializes the list-heads and set the out-count + * of all nodes to 0. + * + * Additionally touches DEP nodes, as they might be DEAD. + * THIS IS UGLY, but I don't find a better way until we + * + * a) ensure that dead nodes are not used as input + * b) it might be sufficient to add those stupid NO_REG nodes + * to the anchor + */ +static void init_lh_walker_dep(ir_node *irn, void *data) { + struct build_walker *w = data; + ir_edge_kind_t kind = w->kind; + list_head *head = _get_irn_outs_head(irn, kind); + int i; + + INIT_LIST_HEAD(head); + _get_irn_edge_info(irn, kind)->out_count = 0; + + for (i = get_irn_deps(irn) - 1; i >= 0; --i) { + ir_node *dep = get_irn_dep(irn, i); + + head = _get_irn_outs_head(dep, kind); + + INIT_LIST_HEAD(head); + _get_irn_edge_info(dep, kind)->out_count = 0; + } +} + +typedef struct visitor_info_t { + irg_walk_func *visit; + void *data; +} visitor_info_t; + /** * Visitor: initializes the list-heads and set the out-count * of all nodes to 0 of nodes that are not seen so far. */ static void visitor(ir_node *irn, void *data) { - if (irn_not_visited(irn)) { + visitor_info_t *info = data; + + if (!irn_visited(irn)) { mark_irn_visited(irn); - init_lh_walker(irn, data); + info->visit(irn, info->data); } } @@ -542,15 +576,29 @@ static void visitor(ir_node *irn, void *data) { void edges_activate_kind(ir_graph *irg, ir_edge_kind_t kind) { struct build_walker w; - irg_edge_info_t *info = _get_irg_edge_info(irg, kind); + irg_edge_info_t *info = _get_irg_edge_info(irg, kind); + visitor_info_t visit; w.irg = irg; w.kind = kind; + visit.data = &w; + + assert(!info->activated); + info->activated = 1; edges_init_graph_kind(irg, kind); - irg_walk_anchors(irg, init_lh_walker, build_edges_walker, &w); - visit_all_identities(irg, visitor, &w); + if (kind == EDGE_KIND_DEP) { + irg_walk_anchors(irg, init_lh_walker_dep, NULL, &w); + /* Argh: Dep nodes might be dead, so we MUST visit identities first */ + visit.visit = init_lh_walker_dep; + visit_all_identities(irg, visitor, &visit); + irg_walk_anchors(irg, NULL, build_edges_walker, &w); + } else { + irg_walk_anchors(irg, init_lh_walker, build_edges_walker, &w); + visit.visit = init_lh_walker; + visit_all_identities(irg, visitor, &visit); + } } void edges_deactivate_kind(ir_graph *irg, ir_edge_kind_t kind) @@ -834,18 +882,31 @@ void edges_init_dbg(int do_dbg) { void edges_activate(ir_graph *irg) { edges_activate_kind(irg, EDGE_KIND_NORMAL); edges_activate_kind(irg, EDGE_KIND_BLOCK); + if (get_irg_phase_state(irg) == phase_backend) + edges_activate_kind(irg, EDGE_KIND_DEP); } void edges_deactivate(ir_graph *irg) { - edges_deactivate_kind(irg, EDGE_KIND_NORMAL); + if (get_irg_phase_state(irg) == phase_backend) + edges_deactivate_kind(irg, EDGE_KIND_DEP); edges_deactivate_kind(irg, EDGE_KIND_BLOCK); + edges_deactivate_kind(irg, EDGE_KIND_NORMAL); } -int edges_assure(ir_graph *irg) { - int activated = edges_activated(irg); +int edges_assure(ir_graph *irg) +{ + int activated = 0; - if (!activated) - edges_activate(irg); + if (edges_activated_kind(irg, EDGE_KIND_BLOCK)) { + activated = 1; + } else { + edges_activate_kind(irg, EDGE_KIND_BLOCK); + } + if (edges_activated_kind(irg, EDGE_KIND_NORMAL)) { + activated = 1; + } else { + edges_activate_kind(irg, EDGE_KIND_NORMAL); + } return activated; } @@ -902,7 +963,7 @@ static void irg_block_edges_walk2(ir_node *bl, void *env) { const ir_edge_t *edge, *next; - if (Block_not_block_visited(bl)) { + if (!Block_block_visited(bl)) { mark_Block_block_visited(bl); if (pre) @@ -919,8 +980,6 @@ static void irg_block_edges_walk2(ir_node *bl, } } -/* Walks only over Block nodes in the graph. Has it's own visited - flag, so that it can be interleaved with the other walker. */ void irg_block_edges_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env) { @@ -928,6 +987,10 @@ void irg_block_edges_walk(ir_node *node, assert(edges_activated(current_ir_graph)); assert(is_Block(node)); + ir_reserve_resources(current_ir_graph, IR_RESOURCE_BLOCK_VISITED); + inc_irg_block_visited(current_ir_graph); irg_block_edges_walk2(node, pre, post, env); + + ir_free_resources(current_ir_graph, IR_RESOURCE_BLOCK_VISITED); }