/*
- * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
- *
* This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
*/
/**
* @brief Always available outs.
* @author Sebastian Hack, Michael Beck, Andreas Schoesser
* @date 14.1.2005
- * @version $Id$
* @brief
* This are out-edges (also called def-use edges) that are dynamically
* updated as the graph changes.
#define ValueType ir_edge_t*
#define NullValue NULL
#define DeletedValue ((ir_edge_t*)-1)
-#define Hash(this,key) (HASH_PTR(key->src) ^ (key->pos * 40013))
+#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]))
#define hashset_iterator_next ir_edgeset_iterator_next
#define hashset_remove_iterator ir_edgeset_remove_iterator
-#include "hashset.c"
+#include "hashset.c.inl"
/**
* A function that allows for setting an edge.
return NULL;
}
+static ir_node *get_irn_safe_n(const ir_node *node, int n)
+{
+ if (n == -1 && is_Block(node))
+ return NULL;
+ return get_irn_n(node, n);
+}
+
static const ir_edge_kind_info_t edge_kind_info[EDGE_KIND_LAST] = {
- { "normal" , set_irn_n, -1, get_irn_arity, get_irn_n },
- { "block succs", NULL, 0, get_irn_arity, get_block_n },
- { "dependency", set_irn_dep, 0, get_irn_deps, get_irn_dep }
+ { "normal" , set_irn_n, -1, get_irn_arity, get_irn_safe_n },
+ { "block succs", NULL, 0, get_irn_arity, get_block_n },
+ { "dependency", set_irn_dep, 0, get_irn_deps, get_irn_dep }
};
#define foreach_tgt(irn, i, n, kind) for (i = edge_kind_info[kind].first_idx, n = edge_kind_info[kind].get_arity(irn); i < n; ++i)
*/
static int edges_used = 0;
-/**
- * Summed size of all users private data
- */
-
-static size_t edges_private_size = 0;
-#define EDGE_SIZE (sizeof(ir_edge_t) + edges_private_size)
-
/**
* If set to 1, the list heads are checked every time an edge is changed.
*/
return (long)e;
}
-/**
- * Announce to reserve extra space for each edge to be allocated.
- *
- * @param n: Size of the space to reserve
- *
- * @return Offset at which the private data will begin
- *
- * Several users can reserve extra space for private usage.
- * Each user has to remember his given offset and the size of his private data.
- * To be called before FIRM is initialized.
- */
-size_t edges_register_private_data(size_t n)
-{
- size_t res = edges_private_size;
-
- assert(!edges_used && "you cannot register private edge data, if edges have been initialized");
-
- edges_private_size += 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, unsigned size)
-{
- irg_edge_info_t *info = _get_irg_edge_info(irg, EDGE_KIND_NORMAL);
- ir_edge_t *edge;
- ir_edgeset_iterator_t iter;
-
- foreach_ir_edgeset(&info->edges, edge, iter) {
- memset(edge + sizeof(*edge) + offset, 0, size);
- }
-}
-
-#define TIMES37(x) (((x) << 5) + ((x) << 2) + (x))
-
-#define get_irn_out_list_head(irn) (&get_irn_out_info(irn)->outs)
-
-#define edge_hash(edge) (TIMES37((edge)->pos) + HASH_PTR((edge)->src))
-
-/**
- * Initialize the out information for a graph.
- * @note Dead node elimination can call this on an already initialized graph.
- */
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 = irg->estimated_node_count * 2;
+ irg_edge_info_t *info = get_irg_edge_info(irg, kind);
+ size_t amount = get_irg_last_idx(irg) * 5 / 4;
edges_used = 1;
if (info->allocated) {
}
}
-/**
- * Get the edge object of an outgoing edge at a node.
- * @param irg The graph, the node is in.
- * @param src The node at which the edge originates.
- * @param pos The position of the edge.
- * @param kind The kind of the edge.
- * @return The corresponding edge object or NULL,
- * if no such edge exists.
- */
-const ir_edge_t *get_irn_edge_kind(const ir_node *src, int pos, ir_edge_kind_t kind)
-{
- ir_graph *irg = get_irn_irg(src);
- if (edges_activated_kind(irg, kind)) {
- irg_edge_info_t *info = _get_irg_edge_info(irg, kind);
- ir_edge_t key;
-
- key.src = (ir_node *)src;
- key.pos = pos;
-
- return ir_edgeset_find(&info->edges, &key);
- }
-
- return NULL;
-}
-
/**
* Change the out count
*
*/
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);
+ irn_edge_info_t *info = get_irn_edge_info(tgt, kind);
info->out_count += ofs;
}
/**
- * Verify the edge list of a node, ie. ensure it's a loop:
+ * Verify the edge list of a node, i.e. ensure it's a loop:
* head -> e_1 -> ... -> e_n -> head
*/
static inline void verify_list_head(ir_node *irn, ir_edge_kind_t kind)
{
- int err = 0;
- int num = 0;
- pset *lh_set = pset_new_ptr(16);
- const struct list_head *head = _get_irn_outs_head(irn, kind);
+ int err = 0;
+ int num = 0;
+ pset *lh_set = pset_new_ptr(16);
+ const struct list_head *head = &get_irn_edge_info(irn, kind)->outs_head;
const struct list_head *pos;
list_for_each(pos, head) {
ir_fprintf(stderr, "EDGE Verifier: edge list broken (self loop not to head) for %+F:\n", irn);
fprintf(stderr, "- at list entry %d\n", num);
- if (edge->invalid)
- fprintf(stderr, "- edge(%ld) is invalid\n", edge_get_id(edge));
if (edge->src)
ir_fprintf(stderr, "- edge(%ld) %+F(%d)\n", edge_get_id(edge), edge->src, edge->pos);
err = 1;
if (!edges_activated_kind(irg, kind))
return;
- info = _get_irg_edge_info(irg, kind);
+ info = get_irg_edge_info(irg, kind);
edges = &info->edges;
foreach_ir_edgeset(edges, e, iter) {
- ir_printf("%+F %d %d\n", e->src, e->pos, e->invalid);
+ ir_printf("%+F %d\n", e->src, e->pos);
}
}
-/* The edge from (src, pos) -> old_tgt is redirected to tgt */
+static void add_edge(ir_node *src, int pos, ir_node *tgt, ir_edge_kind_t kind,
+ ir_graph *irg)
+{
+ assert(edges_activated_kind(irg, kind));
+ irg_edge_info_t *info = get_irg_edge_info(irg, kind);
+ ir_edgeset_t *edges = &info->edges;
+
+ struct list_head *head = &get_irn_edge_info(tgt, kind)->outs_head;
+ assert(head->next && head->prev &&
+ "target list head must have been initialized");
+
+ /* The old target was NULL, thus, the edge is newly created. */
+ ir_edge_t *edge;
+ if (list_empty(&info->free_edges)) {
+ edge = OALLOC(&info->edges_obst, ir_edge_t);
+ } else {
+ edge = list_entry(info->free_edges.next, ir_edge_t, list);
+ list_del(&edge->list);
+ }
+
+ edge->src = src;
+ edge->pos = pos;
+#ifdef DEBUG_libfirm
+ edge->present = 0;
+#endif
+
+ ir_edge_t *new_edge = ir_edgeset_insert(edges, edge);
+ assert(new_edge == edge);
+ (void)new_edge;
+
+ list_add(&edge->list, head);
+
+ edge_change_cnt(tgt, kind, +1);
+}
+
+static void delete_edge(ir_node *src, int pos, ir_node *old_tgt,
+ ir_edge_kind_t kind, ir_graph *irg)
+{
+ assert(edges_activated_kind(irg, kind));
+
+ irg_edge_info_t *info = get_irg_edge_info(irg, kind);
+ ir_edgeset_t *edges = &info->edges;
+
+ /* Initialize the edge template to search in the set. */
+ ir_edge_t templ;
+ templ.src = src;
+ templ.pos = pos;
+
+ /* search the edge in the set. */
+ ir_edge_t *edge = ir_edgeset_find(edges, &templ);
+
+ /* mark the edge invalid if it was found */
+ if (edge == NULL)
+ return;
+
+ list_del(&edge->list);
+ ir_edgeset_remove(edges, edge);
+ list_add(&edge->list, &info->free_edges);
+ edge->pos = -2;
+ edge->src = NULL;
+ edge_change_cnt(old_tgt, kind, -1);
+}
+
void edges_notify_edge_kind(ir_node *src, int pos, ir_node *tgt,
ir_node *old_tgt, ir_edge_kind_t kind,
ir_graph *irg)
{
- const char *msg = "";
- irg_edge_info_t *info;
- ir_edgeset_t *edges;
- ir_edge_t templ;
+ if (old_tgt == NULL) {
+ add_edge(src, pos, tgt, kind, irg);
+ return;
+ } else if (tgt == NULL) {
+ delete_edge(src, pos, old_tgt, kind, irg);
+ return;
+ }
+
+ /* Only do something, if the old and new target differ. */
+ if (tgt == old_tgt)
+ return;
assert(edges_activated_kind(irg, kind));
+ irg_edge_info_t *info = get_irg_edge_info(irg, kind);
+ ir_edgeset_t *edges = &info->edges;
/*
- * Only do something, if the old and new target differ.
+ * 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).
*/
- if (tgt == old_tgt)
- return;
+ struct list_head *head = &get_irn_edge_info(tgt, kind)->outs_head;
- info = _get_irg_edge_info(irg, kind);
- edges = &info->edges;
+ assert(head->next && head->prev &&
+ "target list head must have been initialized");
/* Initialize the edge template to search in the set. */
+ ir_edge_t templ;
templ.src = src;
templ.pos = pos;
- /*
- * If the target is NULL, the edge shall be deleted.
- */
- if (tgt == NULL) {
- /* search the edge in the set. */
- ir_edge_t *edge = ir_edgeset_find(edges, &templ);
-
- /* mark the edge invalid if it was found */
- 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;
- edge_change_cnt(old_tgt, kind, -1);
- } else {
- /* If the edge was not found issue a warning on the debug stream */
- msg = "edge to delete not found!\n";
- }
- } 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 &&
- "target list head must have been initialized");
-
- /* If the old target is not null, the edge is moved. */
- if (old_tgt) {
- ir_edge_t *edge = ir_edgeset_find(edges, &templ);
- assert(edge && "edge to redirect not found!");
- assert(! edge->invalid && "Invalid edge encountered");
-
- msg = "redirecting";
-
- list_move(&edge->list, head);
- edge_change_cnt(old_tgt, kind, -1);
- } else {
- /* The old target was NULL, thus, the edge is newly created. */
- ir_edge_t *new_edge;
- ir_edge_t *edge;
-
- if (list_empty(&info->free_edges)) {
- edge = (ir_edge_t*)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(edge + 1, 0, edges_private_size);
-
- new_edge = ir_edgeset_insert(edges, edge);
- if (new_edge != edge) {
- panic("new edge exists already");
- }
+ ir_edge_t *edge = ir_edgeset_find(edges, &templ);
+ assert(edge && "edge to redirect not found!");
- msg = "adding";
- list_add(&edge->list, head);
- }
-
- edge_change_cnt(tgt, kind, +1);
- } /* else */
+ list_move(&edge->list, head);
+ edge_change_cnt(old_tgt, kind, -1);
+ edge_change_cnt(tgt, kind, +1);
#ifndef DEBUG_libfirm
/* verify list heads */
verify_list_head(old_tgt, kind);
}
#endif
-
- DBG((dbg, LEVEL_5, "announce out edge: %+F %d-> %+F(%+F): %s\n", src, pos, tgt, old_tgt, msg));
}
void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt,
edges_notify_edge_kind(src, pos, bl_tgt, bl_old, EDGE_KIND_BLOCK, irg);
} else if (get_irn_mode(src) == mode_X && old_tgt != NULL && is_Block(old_tgt)) {
/* moving a jump node from one block to another */
- const ir_edge_t *edge;
- const ir_edge_t *next;
- foreach_out_edge_kind_safe(old_tgt, edge, next, EDGE_KIND_BLOCK) {
+ foreach_out_edge_kind_safe(old_tgt, edge, EDGE_KIND_BLOCK) {
ir_node *succ = get_edge_src_irn(edge);
int succ_pos = get_edge_src_pos(edge);
ir_node *block_pred = get_Block_cfgpred(succ, succ_pos);
foreach_tgt(old, i, n, kind) {
ir_node *old_tgt = get_n(old, i, kind);
- edges_notify_edge_kind(old, i, NULL, old_tgt, kind, irg);
+ delete_edge(old, i, old_tgt, kind, irg);
}
}
if (!edges_activated_kind(irg, kind))
return;
- info = _get_irn_edge_info(irn, kind);
+ info = get_irn_edge_info(irn, kind);
if (info->edges_built)
return;
foreach_tgt(irn, i, n, kind) {
ir_node *tgt = get_n(irn, i, kind);
- edges_notify_edge_kind(irn, i, tgt, NULL, kind, irg);
+ add_edge(irn, i, tgt, kind, irg);
}
info->edges_built = 1;
}
foreach_tgt(irn, i, n, kind) {
ir_node *pred = get_n(irn, i, kind);
- edges_notify_edge_kind(irn, i, pred, NULL, kind, irg);
+ if (pred != NULL)
+ add_edge(irn, i, pred, kind, irg);
}
- _get_irn_edge_info(irn, kind)->edges_built = 1;
+ get_irn_edge_info(irn, kind)->edges_built = 1;
}
/**
{
build_walker *w = (build_walker*)data;
ir_edge_kind_t kind = w->kind;
- list_head *head = _get_irn_outs_head(irn, kind);
+ list_head *head = &get_irn_edge_info(irn, kind)->outs_head;
INIT_LIST_HEAD(head);
- _get_irn_edge_info(irn, kind)->edges_built = 0;
- _get_irn_edge_info(irn, kind)->out_count = 0;
+ get_irn_edge_info(irn, kind)->edges_built = 0;
+ get_irn_edge_info(irn, kind)->out_count = 0;
}
/**
{
build_walker *w = (build_walker*)data;
ir_edge_kind_t kind = w->kind;
- list_head *head = _get_irn_outs_head(irn, kind);
+ list_head *head = &get_irn_edge_info(irn, kind)->outs_head;
int i;
INIT_LIST_HEAD(head);
- _get_irn_edge_info(irn, kind)->edges_built = 0;
- _get_irn_edge_info(irn, kind)->out_count = 0;
+ get_irn_edge_info(irn, kind)->edges_built = 0;
+ 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);
+ head = &get_irn_edge_info(dep, kind)->outs_head;
INIT_LIST_HEAD(head);
- _get_irn_edge_info(dep, kind)->edges_built = 0;
- _get_irn_edge_info(dep, kind)->out_count = 0;
+ get_irn_edge_info(dep, kind)->edges_built = 0;
+ get_irn_edge_info(dep, kind)->out_count = 0;
}
}
}
}
-/*
- * Build the initial edge set.
- * Beware, this is not a simple task because it suffers from two
- * difficulties:
- * - the anchor set allows access to Nodes that may not be reachable from
- * the End node
- * - the identities add nodes to the "root set" that are not yet reachable
- * from End. However, after some transformations, the CSE may revival these
- * nodes
- *
- * These problems can be fixed using different strategies:
- * - Add an age flag to every node. Whenever the edge of a node is older
- * then the current edge, invalidate the edges of this node.
- * While this would help for revivaled nodes, it increases memory and runtime.
- * - Delete the identities set.
- * Solves the revival problem, but may increase the memory consumption, as
- * nodes cannot be revivaled at all.
- * - Manually iterate over the identities root set. This did not consume more memory
- * but increase the computation time because the |identities| >= |V|
- *
- * Currently, we use the last option.
- */
void edges_activate_kind(ir_graph *irg, ir_edge_kind_t kind)
{
+ /*
+ * Build the initial edge set.
+ * Beware, this is not a simple task because it suffers from two
+ * difficulties:
+ * - the anchor set allows access to Nodes that may not be reachable from
+ * the End node
+ * - the identities add nodes to the "root set" that are not yet reachable
+ * from End. However, after some transformations, the CSE may revival these
+ * nodes
+ *
+ * These problems can be fixed using different strategies:
+ * - Add an age flag to every node. Whenever the edge of a node is older
+ * then the current edge, invalidate the edges of this node.
+ * While this would help for revivaled nodes, it increases memory and runtime.
+ * - Delete the identities set.
+ * Solves the revival problem, but may increase the memory consumption, as
+ * nodes cannot be revivaled at all.
+ * - Manually iterate over the identities root set. This did not consume more memory
+ * but increase the computation time because the |identities| >= |V|
+ *
+ * Currently, we use the last option.
+ */
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.kind = kind;
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);
+ irg_walk_anchors(irg, init_lh_walker, build_edges_walker, &w);
}
}
void edges_deactivate_kind(ir_graph *irg, ir_edge_kind_t kind)
{
- irg_edge_info_t *info = _get_irg_edge_info(irg, kind);
+ irg_edge_info_t *info = get_irg_edge_info(irg, kind);
info->activated = 0;
if (info->allocated) {
ir_edgeset_destroy(&info->edges);
info->allocated = 0;
}
+ clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES);
}
int (edges_activated_kind)(const ir_graph *irg, ir_edge_kind_t kind)
{
- return _edges_activated_kind(irg, kind);
+ return edges_activated_kind_(irg, kind);
}
+int (edges_activated)(const ir_graph *irg)
+{
+ return edges_activated_(irg);
+}
-/**
- * Reroute all use-edges from a node to another.
- * @param from The node whose use-edges shall be withdrawn.
- * @param to The node to which all the use-edges of @p from shall be
- * sent to.
- * @param irg The graph.
- */
void edges_reroute_kind(ir_node *from, ir_node *to, ir_edge_kind_t kind)
{
ir_graph *irg = get_irn_irg(from);
set_edge_func_t *set_edge = edge_kind_info[kind].set_edge;
if (set_edge && edges_activated_kind(irg, kind)) {
- struct list_head *head = _get_irn_outs_head(from, kind);
+ struct list_head *head = &get_irn_edge_info(from, kind)->outs_head;
DBG((dbg, LEVEL_5, "reroute from %+F to %+F\n", from, to));
}
}
+void edges_reroute(ir_node *from, ir_node *to)
+{
+ edges_reroute_kind(from, to, EDGE_KIND_NORMAL);
+}
+
+void edges_reroute_except(ir_node *from, ir_node *to, ir_node *exception)
+{
+ foreach_out_edge_safe(from, edge) {
+ ir_node *src = get_edge_src_irn(edge);
+ if (src == exception)
+ continue;
+ set_irn_n(src, edge->pos, to);
+ }
+}
+
+#ifdef DEBUG_libfirm
static void verify_set_presence(ir_node *irn, void *data)
{
build_walker *w = (build_walker*)data;
ir_graph *irg = get_irn_irg(irn);
- ir_edgeset_t *edges = &_get_irg_edge_info(irg, w->kind)->edges;
+ ir_edgeset_t *edges = &get_irg_edge_info(irg, w->kind)->edges;
int i, n;
foreach_tgt(irn, i, n, w->kind) {
static void verify_list_presence(ir_node *irn, void *data)
{
- build_walker *w = (build_walker*)data;
- const ir_edge_t *e;
+ build_walker *w = (build_walker*)data;
bitset_set(w->reachable, get_irn_idx(irn));
}
}
}
+#endif
int edges_verify_kind(ir_graph *irg, ir_edge_kind_t kind)
{
+#ifdef DEBUG_libfirm
struct build_walker w;
- ir_edgeset_t *edges = &_get_irg_edge_info(irg, kind)->edges;
+ ir_edgeset_t *edges = &get_irg_edge_info(irg, kind)->edges;
ir_edge_t *e;
ir_edgeset_iterator_t iter;
* edge set is wrong.
*/
foreach_ir_edgeset(edges, e, iter) {
- if (! e->invalid && ! e->present && bitset_is_set(w.reachable, get_irn_idx(e->src))) {
+ if (! e->present && bitset_is_set(w.reachable, get_irn_idx(e->src))) {
w.problem_found = 1;
ir_fprintf(stderr, "Edge Verifier: edge(%ld) %+F,%d is superfluous\n", edge_get_id(e), e->src, e->pos);
}
}
return w.problem_found;
+#else
+ (void)irg;
+ (void)kind;
+ return 0;
+#endif
}
#define IGNORE_NODE(irn) (is_Bad((irn)) || is_Block((irn)))
*/
static void verify_edge_counter(ir_node *irn, void *env)
{
- build_walker *w = (build_walker*)env;
- bitset_t *bs;
- int list_cnt;
- int ref_cnt;
- int edge_cnt;
- size_t idx;
- const struct list_head *head;
- const struct list_head *pos;
- ir_graph *irg;
-
+ build_walker *w = (build_walker*)env;
if (IGNORE_NODE(irn))
return;
- bs = (bitset_t*)get_irn_link(irn);
- list_cnt = 0;
- ref_cnt = 0;
- edge_cnt = _get_irn_edge_info(irn, EDGE_KIND_NORMAL)->out_count;
- head = _get_irn_outs_head(irn, EDGE_KIND_NORMAL);
+ bitset_t *bs = (bitset_t*)get_irn_link(irn);
+ int list_cnt = 0;
+ int edge_cnt = get_irn_edge_info(irn, EDGE_KIND_NORMAL)->out_count;
+ const struct list_head *head
+ = &get_irn_edge_info(irn, EDGE_KIND_NORMAL)->outs_head;
/* We can iterate safely here, list heads have already been verified. */
+ const struct list_head *pos;
list_for_each(pos, head) {
++list_cnt;
}
/* check all nodes that reference us and count edges that point number
* of ins that actually point to us */
- irg = get_irn_irg(irn);
- ref_cnt = 0;
+ ir_graph *irg = get_irn_irg(irn);
+ int ref_cnt = 0;
bitset_foreach(bs, idx) {
int i, arity;
ir_node *src = get_idx_irn(irg, idx);
bitset_free(bs);
}
-/**
- * Verifies the out edges of an irg.
- */
int edges_verify(ir_graph *irg)
{
struct build_walker w;
return 0;
}
-/* Creates an ir_graph pass for edges_verify(). */
ir_graph_pass_t *irg_verify_edges_pass(const char *name, unsigned assert_on_problem)
{
pass_t *pass = XMALLOCZ(pass_t);
void init_edges(void)
{
- FIRM_DBG_REGISTER(dbg, DBG_EDGES);
+ FIRM_DBG_REGISTER(dbg, "firm.ir.edges");
}
void edges_init_dbg(int do_dbg)
{
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);
+ edges_activate_kind(irg, EDGE_KIND_DEP);
}
void edges_deactivate(ir_graph *irg)
{
- if (get_irg_phase_state(irg) == phase_backend)
- edges_deactivate_kind(irg, EDGE_KIND_DEP);
+ 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)
+void assure_edges(ir_graph *irg)
{
- int activated = 0;
-
- 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;
+ assure_edges_kind(irg, EDGE_KIND_BLOCK);
+ assure_edges_kind(irg, EDGE_KIND_NORMAL);
+ assure_edges_kind(irg, EDGE_KIND_DEP);
+ add_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES);
}
-int edges_assure_kind(ir_graph *irg, ir_edge_kind_t kind)
+void assure_edges_kind(ir_graph *irg, ir_edge_kind_t kind)
{
- int activated = edges_activated_kind(irg, kind);
-
- if (!activated)
+ if (!edges_activated_kind(irg, kind))
edges_activate_kind(irg, kind);
-
- return activated;
}
void edges_node_deleted(ir_node *irn)
{
edges_node_deleted_kind(irn, EDGE_KIND_NORMAL);
edges_node_deleted_kind(irn, EDGE_KIND_BLOCK);
+ edges_node_deleted_kind(irn, EDGE_KIND_DEP);
}
void edges_node_revival(ir_node *irn)
const ir_edge_t *(get_irn_out_edge_first_kind)(const ir_node *irn, ir_edge_kind_t kind)
{
- return _get_irn_out_edge_first_kind(irn, kind);
+ return get_irn_out_edge_first_kind_(irn, kind);
}
-const ir_edge_t *(get_irn_out_edge_next)(const ir_node *irn, const ir_edge_t *last)
+const ir_edge_t *(get_irn_out_edge_first)(const ir_node *irn)
{
- return _get_irn_out_edge_next(irn, last);
+ return get_irn_out_edge_first_kind_(irn, EDGE_KIND_NORMAL);
+}
+
+const ir_edge_t *(get_block_succ_first)(const ir_node *block)
+{
+ return get_irn_out_edge_first_kind_(block, EDGE_KIND_BLOCK);
+}
+
+const ir_edge_t *(get_irn_out_edge_next)(const ir_node *irn, const ir_edge_t *last, ir_edge_kind_t kind)
+{
+ return get_irn_out_edge_next_(irn, last, kind);
}
ir_node *(get_edge_src_irn)(const ir_edge_t *edge)
{
- return _get_edge_src_irn(edge);
+ return get_edge_src_irn_(edge);
}
int (get_edge_src_pos)(const ir_edge_t *edge)
{
- return _get_edge_src_pos(edge);
+ return get_edge_src_pos_(edge);
}
int (get_irn_n_edges_kind)(const ir_node *irn, ir_edge_kind_t kind)
{
- return _get_irn_n_edges_kind(irn, kind);
+ return get_irn_n_edges_kind_(irn, kind);
}
static void irg_walk_edges2(ir_node *node, irg_walk_func *pre,
irg_walk_func *post, void *env)
{
- const ir_edge_t *edge, *next;
-
if (irn_visited_else_mark(node))
return;
if (pre != NULL)
pre(node, env);
- foreach_out_edge_kind_safe(node, edge, next, EDGE_KIND_NORMAL) {
+ foreach_out_edge_kind_safe(node, edge, EDGE_KIND_NORMAL) {
/* find the corresponding successor block. */
ir_node *pred = get_edge_src_irn(edge);
irg_walk_edges2(pred, pre, post, env);
static void irg_block_edges_walk2(ir_node *bl, irg_walk_func *pre,
irg_walk_func *post, void *env)
{
- const ir_edge_t *edge, *next;
-
if (!Block_block_visited(bl)) {
mark_Block_block_visited(bl);
if (pre)
pre(bl, env);
- foreach_out_edge_kind_safe(bl, edge, next, EDGE_KIND_BLOCK) {
+ foreach_out_edge_kind_safe(bl, edge, EDGE_KIND_BLOCK) {
/* find the corresponding successor block. */
ir_node *pred = get_edge_src_irn(edge);
irg_block_edges_walk2(pred, pre, post, env);