Commit a953ba0d authored by Sebastian Hack's avatar Sebastian Hack
Browse files

Added dependency edges

Adapted out edges to the new dependency edges

[r8135]
parent c0641a64
......@@ -1438,34 +1438,54 @@ print_edge_vcgattr(FILE *F, ir_node *from, int to) {
/* dump edges to our inputs */
static void
dump_ir_data_edges(FILE *F, ir_node *n) {
int i;
unsigned long visited = get_irn_visited(n);
if ((get_irn_op(n) == op_End) && (!dump_keepalive))
return;
for (i = 0; i < get_irn_arity(n); i++) {
ir_node * pred = get_irn_n(n, i);
assert(pred);
if ((get_interprocedural_view() && get_irn_visited(pred) < visited))
continue; /* pred not dumped */
if (dump_backedge_information_flag && is_backedge(n, i))
fprintf (F, "backedge: {sourcename: \"");
else
fprintf (F, "edge: {sourcename: \"");
PRINT_NODEID(n);
fprintf (F, "\" targetname: ");
if ((get_opt_dump_const_local()) && is_constlike_node(pred)) {
PRINT_CONSTID(n, pred);
} else {
fprintf(F, "\""); PRINT_NODEID(pred); fprintf(F, "\"");
}
fprintf (F, " label: \"%d\" ", i);
print_edge_vcgattr(F, n, i);
fprintf (F, "}\n");
}
int i;
unsigned long visited = get_irn_visited(n);
if ((get_irn_op(n) == op_End) && (!dump_keepalive))
return;
/* dump the dependency edges. */
for (i = 0; i < get_irn_deps(n); ++i) {
ir_node *dep = get_irn_dep(n, i);
if(dep) {
fprintf(F, "edge: {sourcename: \"");
PRINT_NODEID(n);
fprintf(F, "\" targetname: ");
if ((get_opt_dump_const_local()) && is_constlike_node(dep)) {
PRINT_CONSTID(n, dep);
} else {
fprintf(F, "\"");
PRINT_NODEID(dep);
fprintf(F, "\"");
}
fprintf(F, " label: \"%d\" ", i);
fprintf(F, " color: darkgreen}\n");
}
}
for (i = 0; i < get_irn_arity(n); i++) {
ir_node * pred = get_irn_n(n, i);
assert(pred);
if ((get_interprocedural_view() && get_irn_visited(pred) < visited))
continue; /* pred not dumped */
if (dump_backedge_information_flag && is_backedge(n, i))
fprintf (F, "backedge: {sourcename: \"");
else
fprintf (F, "edge: {sourcename: \"");
PRINT_NODEID(n);
fprintf (F, "\" targetname: ");
if ((get_opt_dump_const_local()) && is_constlike_node(pred)) {
PRINT_CONSTID(n, pred);
} else {
fprintf(F, "\""); PRINT_NODEID(pred); fprintf(F, "\"");
}
fprintf (F, " label: \"%d\" ", i);
print_edge_vcgattr(F, n, i);
fprintf (F, "}\n");
}
}
/** Dumps a node and its edges but not the block edge
......
......@@ -29,6 +29,7 @@
#include "irnode_t.h"
#include "iropt_t.h"
#include "iredgekinds.h"
#include "iredges_t.h"
#include "irgwalk.h"
#include "irdump_t.h"
......@@ -37,6 +38,55 @@
#include "debug.h"
#include "set.h"
/**
* A function that allows for setting an edge.
* This abstraction is necessary since different edge kind have
* different methods of setting edges.
*/
typedef void (set_edge_func_t)(ir_node *src, int pos, ir_node *tgt);
typedef int (get_edge_src_arity_func_t)(const ir_node *src);
typedef int (get_edge_src_first_func_t)(const ir_node *src);
typedef ir_node *(get_edge_src_n_func_t)(const ir_node *src, int pos);
/**
* Additional data for an edge kind.
*/
typedef struct {
const char *name;
set_edge_func_t *set_edge;
get_edge_src_first_func_t *get_first;
get_edge_src_arity_func_t *get_arity;
get_edge_src_n_func_t *get_n;
} ir_edge_kind_info_t;
static int get_zero(const ir_node *irn)
{
return 0;
}
static int get_irn_first(const ir_node *irn)
{
return 0 - !is_Block(irn);
}
static ir_node *get_block_n(const ir_node *irn, int pos)
{
return is_Block(irn) ? get_Block_cfgpred_block((ir_node *) irn, pos) : 0;
}
static const ir_edge_kind_info_t edge_kind_info[EDGE_KIND_LAST] = {
{ "normal" , set_irn_n, get_irn_first, get_irn_arity, get_irn_n },
{ "block succs", NULL, get_zero, get_irn_arity, get_block_n },
{ "dependency", set_irn_dep, get_zero, get_irn_deps, get_irn_dep }
};
#define foreach_tgt(irn, i, n, kind) for(i = edge_kind_info[kind].get_first(irn), n = edge_kind_info[kind].get_arity(irn); i < n; ++i)
#define get_n(irn, pos, kind) (edge_kind_info[kind].get_n(irn, pos))
#define get_kind_str(kind) (edge_kind_info[kind].name)
DEBUG_ONLY(static firm_dbg_module_t *dbg;)
/**
......@@ -76,27 +126,21 @@ static int edge_cmp(const void *p1, const void *p2, size_t len)
* Initialize the out information for a graph.
* @note Dead node elimination can call this on an already initialized graph.
*/
void edges_init_graph(ir_graph *irg)
void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind)
{
if(edges_activated(irg)) {
irg_edge_info_t *info = _get_irg_edge_info(irg);
if(edges_activated_kind(irg, kind)) {
irg_edge_info_t *info = _get_irg_edge_info(irg, kind);
int amount = 2048;
edges_used = 1;
if(info->edges) {
amount = set_count(info->edges);
del_set(info->edges);
}
info->edges = new_set(edge_cmp, amount);
}
}
#define EDGE_SIZE(src) \
(edges_private_size + (is_Block(src) ? sizeof(ir_block_edge_t) : sizeof(ir_edge_t)))
/**
* Get the edge object of an outgoing edge at a node.
* @param irg The graph, the node is in.
......@@ -105,16 +149,15 @@ void edges_init_graph(ir_graph *irg)
* @return The corresponding edge object or NULL,
* if no such edge exists.
*/
const ir_edge_t *get_irn_edge(ir_graph *irg, const ir_node *src, int pos)
const ir_edge_t *get_irn_edge_kind(ir_graph *irg, const ir_node *src, int pos, ir_edge_kind_t kind)
{
if(edges_activated(irg)) {
irg_edge_info_t *info = _get_irg_edge_info(irg);
size_t size = EDGE_SIZE(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 set_find(info->edges, &key, size, edge_hash(&key));
return set_find(info->edges, &key, sizeof(key), edge_hash(&key));
}
return NULL;
......@@ -123,50 +166,35 @@ const ir_edge_t *get_irn_edge(ir_graph *irg, const ir_node *src, int pos)
/**
* Change the out count
*/
static INLINE void edge_change_cnt(ir_node *tgt, int ofs) {
irn_edge_info_t *info = _get_irn_edge_info(tgt);
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;
}
/* The edge from (src, pos) -> old_tgt is redirected to tgt */
void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg)
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 = "";
if(!edges_activated(irg))
if(!edges_activated_kind(irg, kind))
return;
#if 0
assert(node_is_in_irgs_storage(irg, src) && "source not in irg");
#endif
/*
* Only do something, if the old and new target differ.
*/
if(tgt != old_tgt) {
int is_block_edge = is_Block(src);
set *edges = _get_irg_edge_info(irg)->edges;
irg_edge_info_t *info = _get_irg_edge_info(irg, kind);
set *edges = info->edges;
ir_edge_t *templ = alloca(sizeof(templ[0]));
ir_edge_t *edge;
/*
* This is scary, but:
* If two entries in a set do not have the same size, they are
* treated as unequal, ignoring the comparison function.
* So, edges from blocks have extra storage (they are
* ir_block_edge_t's).
*
* Also add the amount of registered private data to the
* size of the edge.
*/
size_t size = EDGE_SIZE(src);
ir_edge_t *templ = alloca(size);
/* Initialize the edge template to search in the set. */
memset(templ, 0, size);
templ->src = src;
templ->pos = pos;
memset(templ, 0, sizeof(templ[0]));
templ->src = src;
templ->pos = pos;
templ->invalid = 0;
templ->present = 0;
templ->kind = kind;
DEBUG_ONLY(templ->src_nr = get_irn_node_nr(src));
/*
......@@ -174,7 +202,7 @@ void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir
*/
if (tgt == NULL) {
/* search the edge in the set. */
edge = set_find(edges, templ, size, edge_hash(templ));
edge = set_find(edges, templ, sizeof(templ[0]), edge_hash(templ));
/* mark the edge invalid if it was found */
if(edge) {
......@@ -185,15 +213,6 @@ void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir
edge->invalid = 1;
edge->pos = -2;
edge->src = NULL;
/*
* If the edge is a cf edge, we delete it also
* from the list of all block successor edges.
*/
if(is_block_edge) {
list_del(&block_edge->succ_list);
edge_change_cnt(old_tgt, -1);
}
}
/* If the edge was not found issue a warning on the debug stream */
......@@ -209,22 +228,8 @@ void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir
* NULL).
*/
else {
struct list_head *head = _get_irn_outs_head(tgt);
/*
* The list head in the block of the edges target.
* Therein all control flow edges directed at that block
* are recorded.
*/
struct list_head *succ_head =
is_block_edge ? _get_block_succ_head(get_nodes_block(tgt)) : NULL;
ir_block_edge_t *block_edge;
struct list_head *head = _get_irn_outs_head(tgt, kind);
#if 0
if(!node_is_in_irgs_storage(irg, tgt))
return;
#endif
assert(head->next && head->prev &&
"target list head must have been initialized");
......@@ -232,8 +237,7 @@ void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir
* insert the edge, if it is not yet in the set or return
* the instance in the set.
*/
edge = set_insert(edges, templ, size, edge_hash(templ));
block_edge = (ir_block_edge_t *) edge;
edge = set_insert(edges, templ, sizeof(templ[0]), edge_hash(templ));
#ifdef DEBUG_libfirm
assert(!edge->invalid && "Invalid edge encountered");
......@@ -244,68 +248,63 @@ void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir
msg = "redirecting";
list_move(&edge->list, head);
/* If the edge is a cf edge, move it from the successor list. */
if(is_block_edge)
list_move(&block_edge->succ_list, succ_head);
edge_change_cnt(old_tgt, -1);
edge_change_cnt(old_tgt, kind, -1);
}
/* The old target was null, thus, the edge is newly created. */
else {
msg = "adding";
list_add(&edge->list, head);
/*
* If the edge is cf edge, enter it into the successor list
* of the target node's block.
*/
if(is_block_edge)
list_add(&block_edge->succ_list, succ_head);
}
edge_change_cnt(tgt, +1);
edge_change_cnt(tgt, kind, +1);
} /* else */
}
/* If the target and the old target are equal, nothing is done. */
DBG((dbg, LEVEL_5, "announce out edge: %+F %d-> %+F(%+F): %s\n",
src, pos, tgt, old_tgt, msg));
DBG((dbg, LEVEL_5, "announce out edge: %+F %d-> %+F(%+F): %s\n", src, pos, tgt, old_tgt, msg));
}
void edges_node_deleted(ir_node *old, ir_graph *irg)
void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg)
{
if(edges_activated(irg)) {
int not_a_block = !is_Block(old);
edges_notify_edge_kind(src, pos, tgt, old_tgt, EDGE_KIND_NORMAL, irg);
if(is_Block(src)) {
ir_node *bl_tgt = tgt ? get_nodes_block(skip_Proj(tgt)) : NULL;
// ir_node *bl_old = old_tgt ? old_tgt : NULL;
ir_node *bl_old = old_tgt ? get_nodes_block(skip_Proj(old_tgt)) : NULL;
edges_notify_edge_kind(src, pos, bl_tgt, bl_old, EDGE_KIND_BLOCK, irg);
}
}
void edges_node_deleted_kind(ir_node *old, ir_edge_kind_t kind, ir_graph *irg)
{
if(edges_activated_kind(irg, kind)) {
int i, n;
DBG((dbg, LEVEL_5, "node deleted: %+F\n", old));
DBG((dbg, LEVEL_5, "node deleted (kind: %s): %+F\n", get_kind_str(kind), old));
/* Change to get_irn_n */
for(i = -not_a_block, n = get_irn_arity(old); i < n; ++i) {
ir_node *old_tgt = get_irn_n(old, i);
DBG((dbg, LEVEL_5, "\tdelete to old target %+F\n", old_tgt));
edges_notify_edge(old, i, NULL, old_tgt, irg);
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);
}
}
}
void edges_invalidate(ir_node *irn, ir_graph *irg) {
edges_node_deleted(irn, irg);
}
struct build_walker {
ir_graph *irg;
ir_edge_kind_t kind;
};
/**
* Post-Walker: notify all edges
*/
static void build_edges_walker(ir_node *irn, void *data) {
ir_graph *irg = data;
int not_a_block = !is_Block(irn);
struct build_walker *w = data;
int i, n;
for (i = -not_a_block, n = get_irn_arity(irn); i < n; ++i)
edges_notify_edge(irn, i, get_irn_n(irn, i), NULL, irg);
foreach_tgt(irn, i, n, w->kind)
edges_notify_edge_kind(irn, i, get_n(irn, i, w->kind), NULL, w->kind, w->irg);
}
/**
......@@ -313,10 +312,9 @@ static void build_edges_walker(ir_node *irn, void *data) {
* of all nodes to 0.
*/
static void init_lh_walker(ir_node *irn, void *data) {
INIT_LIST_HEAD(_get_irn_outs_head(irn));
if (is_Block(irn))
INIT_LIST_HEAD(_get_block_succ_head(irn));
_get_irn_edge_info(irn)->out_count = 0;
struct build_walker *w = data;
INIT_LIST_HEAD(_get_irn_outs_head(irn, w->kind));
_get_irn_edge_info(irn, w->kind)->out_count = 0;
}
/**
......@@ -348,24 +346,28 @@ static void visitor(ir_node *irn, void *data) {
* 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 |identies| >= |V|
* but increase the computation time because the |identities| >= |V|
*
* Currently, we use the last option.
*/
void edges_activate(ir_graph *irg)
void edges_activate_kind(ir_graph *irg, ir_edge_kind_t kind)
{
irg_edge_info_t *info = _get_irg_edge_info(irg);
struct build_walker w;
irg_edge_info_t *info = _get_irg_edge_info(irg, kind);
w.irg = irg;
w.kind = kind;
info->activated = 1;
edges_init_graph(irg);
irg_walk_graph(irg, init_lh_walker, build_edges_walker, irg);
irg_walk_anchors(irg, init_lh_walker, NULL, irg);
visit_all_identities(irg, visitor, irg);
edges_init_graph_kind(irg, kind);
irg_walk_graph(irg, init_lh_walker, build_edges_walker, &w);
irg_walk_anchors(irg, init_lh_walker, NULL, &w);
visit_all_identities(irg, visitor, &w);
}
void edges_deactivate(ir_graph *irg)
void edges_deactivate_kind(ir_graph *irg, ir_edge_kind_t kind)
{
irg_edge_info_t *info = _get_irg_edge_info(irg);
irg_edge_info_t *info = _get_irg_edge_info(irg, kind);
info->activated = 0;
if (info->edges) {
......@@ -374,9 +376,9 @@ void edges_deactivate(ir_graph *irg)
}
}
int (edges_activated)(const ir_graph *irg)
int (edges_activated_kind)(const ir_graph *irg, ir_edge_kind_t kind)
{
return _edges_activated(irg);
return _edges_activated_kind(irg, kind);
}
......@@ -387,70 +389,70 @@ int (edges_activated)(const ir_graph *irg)
* sent to.
* @param irg The graph.
*/
void edges_reroute(ir_node *from, ir_node *to, ir_graph *irg)
void edges_reroute_kind(ir_node *from, ir_node *to, ir_edge_kind_t kind, ir_graph *irg)
{
if(edges_activated(irg)) {
struct list_head *head = _get_irn_outs_head(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);
DBG((dbg, LEVEL_5,
"reroute from %+F to %+F\n", from, to));
DBG((dbg, LEVEL_5, "reroute from %+F to %+F\n", from, to));
while(head != head->next) {
ir_edge_t *edge = list_entry(head->next, ir_edge_t, list);
// DBG((dbg, LEVEL_5, "\t%n %d\n", edge->src, edge->pos));
assert(edge->pos >= -1);
set_irn_n(edge->src, edge->pos, to);
set_edge(edge->src, edge->pos, to);
}
}
}
static void verify_set_presence(ir_node *irn, void *data)
{
ir_graph *irg = data;
set *edges = _get_irg_edge_info(irg)->edges;
int not_a_block = !is_Block(irn);
struct build_walker *w = data;
set *edges = _get_irg_edge_info(w->irg, w->kind)->edges;
int not_a_block = !is_Block(irn);
int i, n;
for(i = 0, n = get_irn_arity(irn) + not_a_block; i < n; ++i) {
ir_block_edge_t space;
ir_edge_t *templ = (ir_edge_t *) &space;
ir_edge_t *e;
size_t size = not_a_block ? sizeof(ir_edge_t) : sizeof(ir_block_edge_t);
foreach_tgt(irn, i, n, w->kind) {
ir_edge_t templ, *e;
templ->src = irn;
templ->pos = i - not_a_block;
templ.src = irn;
templ.pos = i;
e = set_find(edges, templ, size, edge_hash(templ));
e = set_find(edges, &templ, sizeof(templ), edge_hash(&templ));
if(e != NULL)
e->present = 1;
else
DBG((dbg, LEVEL_DEFAULT, "edge %+F,%d is missing\n", irn, templ->pos));
DBG((dbg, LEVEL_DEFAULT, "edge %+F,%d (kind: \"%s\") is missing\n", irn, i, get_kind_str(w->kind)));
}
}
static void verify_list_presence(ir_node *irn, void *data)
{
struct build_walker *w = data;
const ir_edge_t *e;
foreach_out_edge(irn, e) {
ir_node *tgt = get_irn_n(e->src, e->pos);
foreach_out_edge_kind(irn, e, w->kind) {
ir_node *tgt = get_n(e->src, e->pos, w->kind);
if(irn != tgt)
DBG((dbg, LEVEL_DEFAULT, "edge %+F,%d is no out edge of %+F but of %+F\n",
e->src, e->pos, irn, tgt));
DBG((dbg, LEVEL_DEFAULT, "edge %+F,%d (kind \"%s\") is no out edge of %+F but of %+F\n", e->src, e->pos, get_kind_str(w->kind), irn, tgt));
}
}
void edges_verify(ir_graph *irg)
void edges_verify_kind(ir_graph *irg, ir_edge_kind_t kind)
{
set *edges = _get_irg_edge_info(irg)->edges;
struct build_walker w;
set *edges = _get_irg_edge_info(irg, kind)->edges;
ir_edge_t *e;
w.irg = irg;
w.kind = kind;
/* Clear the present bit in all edges available. */
for(e = set_first(edges); e; e = set_next(edges))
e->present = 0;
irg_walk_graph(irg, verify_set_presence, verify_list_presence, irg);
irg_walk_graph(irg, verify_set_presence, verify_list_presence, &w);
/*
* Dump all edges which are not invalid and not present.
......@@ -469,10 +471,38 @@ void init_edges(void)
/* firm_dbg_set_mask(dbg, -1); */
}
void edges_activate(ir_graph *irg)
{
edges_activate_kind(irg, EDGE_KIND_NORMAL);
edges_activate_kind(irg, EDGE_KIND_BLOCK);
}
void edges_deactivate(ir_graph *irg)
{
edges_deactivate_kind(irg, EDGE_KIND_NORMAL);
edges_deactivate_kind(irg, EDGE_KIND_BLOCK);
}
int edges_assure(ir_graph *irg)
{
int activated = edges_activated(irg);
if(!activated)
edges_activate(irg);
return activated;
}
void edges_node_deleted(ir_node *irn, ir_graph *irg)
{
edges_node_deleted_kind(irn, EDGE_KIND_NORMAL, irg);
edges_node_deleted_kind(irn, EDGE_KIND_BLOCK, irg);
}
const ir_edge_t *(get_irn_out_edge_first)(const 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(irn);
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)
......@@ -490,7 +520,20 @@ int (get_edge_src_pos)(const ir_edge_t *edge)