Commit 8c1f62ae authored by Matthias Braun's avatar Matthias Braun
Browse files

cleanup iredges API a bit

parent 222b77d2
......@@ -112,7 +112,7 @@ FIRM_API int get_edge_src_pos(const ir_edge_t *edge);
* @return The corresponding edge object or NULL,
* if no such edge exists.
*/
FIRM_API const ir_edge_t *get_irn_edge_kind(ir_graph *irg, const ir_node *irn,
FIRM_API const ir_edge_t *get_irn_edge_kind(const ir_node *irn,
int pos, ir_edge_kind_t kind);
/**
......@@ -155,10 +155,8 @@ FIRM_API void edges_deactivate_kind(ir_graph *irg, ir_edge_kind_t kind);
* @param old the old node
* @param nw the new node
* @param kind the edge kind
* @param irg the graph on which the rerouting occurs
*/
FIRM_API void edges_reroute_kind(ir_node *old, ir_node *nw, ir_edge_kind_t kind,
ir_graph *irg);
FIRM_API void edges_reroute_kind(ir_node *old, ir_node *nw, ir_edge_kind_t kind);
/**
* Verifies the out edges of graph @p irg.
......@@ -188,7 +186,7 @@ FIRM_API void edges_init_dbg(int do_dbg);
FIRM_API ir_graph_pass_t *irg_verify_edges_pass(const char *name,
unsigned assert_on_problem);
#define edges_reroute(old, nw, irg) edges_reroute_kind(old, nw, EDGE_KIND_NORMAL, irg)
#define edges_reroute(old, nw) edges_reroute_kind(old, nw, EDGE_KIND_NORMAL)
#define edges_activated(irg) (edges_activated_kind(irg, EDGE_KIND_NORMAL) && edges_activated_kind(irg, EDGE_KIND_BLOCK))
#ifndef get_irn_n_edges
......@@ -243,13 +241,7 @@ FIRM_API int edges_assure(ir_graph *irg);
*/
FIRM_API int edges_assure_kind(ir_graph *irg, ir_edge_kind_t kind);
FIRM_API void edges_node_deleted(ir_node *irn, ir_graph *irg);
/**
* Notify normal and block edges.
*/
FIRM_API void edges_notify_edge(ir_node *src, int pos, ir_node *tgt,
ir_node *old_tgt, ir_graph *irg);
FIRM_API void edges_node_deleted(ir_node *irn);
/**
* Walks only over Block nodes in the graph. Uses the block visited
......
......@@ -1494,7 +1494,7 @@ static void fix_address_of_parameter_access(be_abi_irg_t *env, ir_graph *irg,
restore_optimization_state(&state);
/* reroute all edges to the new memory source */
edges_reroute(imem, nmem, irg);
edges_reroute(imem, nmem);
store = NULL;
mem = imem;
......
......@@ -110,7 +110,7 @@ static void ia32_transform_sub_to_neg_add(ir_node *irn)
set_ia32_ls_mode(res, get_ia32_ls_mode(irn));
/* exchange the add and the sub */
edges_reroute(irn, res, irg);
edges_reroute(irn, res);
/* add to schedule */
sched_add_before(irn, res);
......@@ -148,7 +148,7 @@ static void ia32_transform_sub_to_neg_add(ir_node *irn)
set_ia32_commutative(res);
/* exchange the add and the sub */
edges_reroute(irn, res, irg);
edges_reroute(irn, res);
/* add to schedule */
sched_add_before(irn, res);
......
......@@ -70,9 +70,8 @@ void ia32_handle_intrinsics(void)
* @param proj the pn_Call_T_result Proj
* @param l_res the lower 32 bit result
* @param h_res the upper 32 bit result or NULL
* @param irg the graph to replace on
*/
static void reroute_result(ir_node *proj, ir_node *l_res, ir_node *h_res, ir_graph *irg)
static void reroute_result(ir_node *proj, ir_node *l_res, ir_node *h_res)
{
const ir_edge_t *edge, *next;
......@@ -81,9 +80,9 @@ static void reroute_result(ir_node *proj, ir_node *l_res, ir_node *h_res, ir_gra
long pn = get_Proj_proj(proj);
if (pn == 0) {
edges_reroute(proj, l_res, irg);
edges_reroute(proj, l_res);
} else if (pn == 1 && h_res != NULL) {
edges_reroute(proj, h_res, irg);
edges_reroute(proj, h_res);
} else {
panic("Unsupported Result-Proj from Call found");
}
......@@ -126,19 +125,19 @@ static void resolve_call(ir_node *call, ir_node *l_res, ir_node *h_res, ir_graph
set_opt_cse(0);
jmp = new_r_Jmp(block);
set_opt_cse(old_cse);
edges_reroute(proj, jmp, irg);
edges_reroute(proj, jmp);
break;
case pn_Call_X_except:
/* should not happen here */
edges_reroute(proj, bad, irg);
edges_reroute(proj, bad);
break;
case pn_Call_M:
/* should not happen here */
edges_reroute(proj, nomem, irg);
edges_reroute(proj, nomem);
break;
case pn_Call_T_result:
reroute_result(proj, l_res, h_res, irg);
reroute_result(proj, l_res, h_res);
break;
default:
panic("Wrong Proj from Call");
......
......@@ -283,7 +283,7 @@ static void peephole_ia32_Test(ir_node *node)
if (get_irn_n_edges(left) != 2) {
ir_node *res = new_r_Proj(left, mode_Iu, pn_ia32_res);
edges_reroute(left, res, current_ir_graph);
edges_reroute(left, res);
/* Reattach the result proj to left */
set_Proj_pred(res, left);
}
......
......@@ -5804,7 +5804,7 @@ static void postprocess_fp_call_results(void)
new_mem = new_r_Proj(xld, mode_M, pn_ia32_xLoad_M);
if (old_mem != NULL) {
edges_reroute(old_mem, new_mem, current_ir_graph);
edges_reroute(old_mem, new_mem);
kill_node(old_mem);
}
}
......
......@@ -1222,7 +1222,7 @@ static int sim_store(x87_state *state, ir_node *n, ir_op *op, ir_op *op_p)
arch_set_irn_register(rproj, op2);
/* reroute all former users of the store memory to the load memory */
edges_reroute(mem, mproj, irg);
edges_reroute(mem, mproj);
/* set the memory input of the load to the store memory */
set_irn_n(vfld, n_ia32_vfld_mem, mem);
......
......@@ -93,7 +93,7 @@ void instrument_initcall(ir_graph *irg, ir_entity *ent)
new_mem = new_r_Proj(call, mode_M, pn_Call_M);
initial_mem = get_irg_initial_mem(irg);
edges_reroute(initial_mem, new_mem, irg);
edges_reroute(initial_mem, new_mem);
/* beware: reroute routes anchor edges also, revert this */
set_irg_initial_mem(irg, initial_mem);
set_Call_mem(call, initial_mem);
......
......@@ -142,21 +142,12 @@ static size_t edges_private_size = 0;
*/
static int edges_dbg = 0;
#ifdef DEBUG_libfirm
/* a static variable holding the last number assigned to a new edge */
static long last_edge_num = -1;
#endif
/**
* Returns an ID for the given edge.
*/
static inline long edge_get_id(const ir_edge_t *e)
{
#ifdef DEBUG_libfirm
return e->edge_nr;
#else /* DEBUG_libfirm */
return (long)e;
#endif /* DEBUG_libfirm */
}
/**
......@@ -234,8 +225,9 @@ void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind)
* @return The corresponding edge object or NULL,
* if no such edge exists.
*/
const ir_edge_t *get_irn_edge_kind(ir_graph *irg, const ir_node *src, int pos, ir_edge_kind_t kind)
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;
......@@ -259,27 +251,6 @@ 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;
#if 0
ir_graph *irg = get_irn_irg(tgt);
assert(info->out_count >= 0);
if (info->out_count == 0 && kind == EDGE_KIND_NORMAL) {
/* tgt lost its last user */
int i;
for (i = get_irn_arity(tgt) - 1; i >= -1; --i) {
ir_node *prev = get_irn_n(tgt, i);
edges_notify_edge(tgt, i, NULL, prev, irg);
}
for (i = get_irn_deps(tgt) - 1; i >= 0; --i) {
ir_node *prev = get_irn_dep(tgt, i);
edges_notify_edge_kind(tgt, i, NULL, prev, EDGE_KIND_DEP, irg);
}
}
#endif
}
/**
......@@ -375,9 +346,6 @@ void edges_notify_edge_kind(ir_node *src, int pos, ir_node *tgt,
edge->invalid = 1;
edge->pos = -2;
edge->src = NULL;
#ifdef DEBUG_libfirm
edge->edge_nr = -1;
#endif /* DEBUG_libfirm */
edge_change_cnt(old_tgt, kind, -1);
} else {
/* If the edge was not found issue a warning on the debug stream */
......@@ -425,7 +393,6 @@ void edges_notify_edge_kind(ir_node *src, int pos, ir_node *tgt,
edge->list.next = NULL;
edge->list.prev = NULL;
memset(edge + 1, 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) {
......@@ -434,7 +401,6 @@ void edges_notify_edge_kind(ir_node *src, int pos, ir_node *tgt,
msg = "adding";
list_add(&edge->list, head);
DEBUG_ONLY(edge->edge_nr = ++last_edge_num);
}
edge_change_cnt(tgt, kind, +1);
......@@ -453,7 +419,8 @@ void edges_notify_edge_kind(ir_node *src, int pos, ir_node *tgt,
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, 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_kind(irg, EDGE_KIND_NORMAL)) {
edges_notify_edge_kind(src, pos, tgt, old_tgt, EDGE_KIND_NORMAL, irg);
......@@ -477,9 +444,10 @@ void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir
* @param kind the kind of edges to remove
* @param irg the irg of the old node
*/
static void edges_node_deleted_kind(ir_node *old, ir_edge_kind_t kind, ir_graph *irg)
static void edges_node_deleted_kind(ir_node *old, ir_edge_kind_t kind)
{
int i, n;
ir_graph *irg = get_irn_irg(old);
if (!edges_activated_kind(irg, kind))
return;
......@@ -499,10 +467,11 @@ static void edges_node_deleted_kind(ir_node *old, ir_edge_kind_t kind, ir_graph
* @param kind the kind of edges to remove
* @param irg the irg of the old node
*/
static void edges_node_revival_kind(ir_node *irn, ir_edge_kind_t kind, ir_graph *irg)
static void edges_node_revival_kind(ir_node *irn, ir_edge_kind_t kind)
{
irn_edge_info_t *info;
int i, n;
ir_graph *irg = get_irn_irg(irn);
if (!edges_activated_kind(irg, kind))
return;
......@@ -521,7 +490,6 @@ static void edges_node_revival_kind(ir_node *irn, ir_edge_kind_t kind, ir_graph
}
typedef struct build_walker {
ir_graph *irg;
ir_edge_kind_t kind;
bitset_t *reachable;
unsigned problem_found;
......@@ -535,7 +503,7 @@ static void build_edges_walker(ir_node *irn, void *data)
build_walker *w = (build_walker*)data;
int i, n;
ir_edge_kind_t kind = w->kind;
ir_graph *irg = w->irg;
ir_graph *irg = get_irn_irg(irn);
get_edge_src_n_func_t *get_n;
get_n = edge_kind_info[kind].get_n;
......@@ -642,7 +610,6 @@ void edges_activate_kind(ir_graph *irg, ir_edge_kind_t 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;
......@@ -689,8 +656,9 @@ int (edges_activated_kind)(const ir_graph *irg, ir_edge_kind_t kind)
* sent to.
* @param irg The graph.
*/
void edges_reroute_kind(ir_node *from, ir_node *to, ir_edge_kind_t kind, ir_graph *irg)
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)) {
......@@ -709,7 +677,8 @@ void edges_reroute_kind(ir_node *from, ir_node *to, ir_edge_kind_t kind, ir_grap
static void verify_set_presence(ir_node *irn, void *data)
{
build_walker *w = (build_walker*)data;
ir_edgeset_t *edges = &_get_irg_edge_info(w->irg, w->kind)->edges;
ir_graph *irg = get_irn_irg(irn);
ir_edgeset_t *edges = &_get_irg_edge_info(irg, w->kind)->edges;
int i, n;
foreach_tgt(irn, i, n, w->kind) {
......@@ -723,10 +692,6 @@ static void verify_set_presence(ir_node *irn, void *data)
e->present = 1;
} else {
w->problem_found = 1;
#if 0
ir_fprintf(stderr, "Edge Verifier: edge %+F,%d -> %+F (kind: \"%s\") is missing\n",
irn, i, get_n(irn, i, w->kind), get_kind_str(w->kind));
#endif
}
}
}
......@@ -746,10 +711,6 @@ static void verify_list_presence(ir_node *irn, void *data)
if (w->kind == EDGE_KIND_NORMAL && get_irn_arity(e->src) <= e->pos) {
w->problem_found = 1;
#if 0
ir_fprintf(stderr, "Edge Verifier: edge(%ld) %+F -> %+F recorded at src position %d, but src has arity %d\n",
edge_get_id(e), e->src, irn, e->pos, get_irn_arity(e->src));
#endif
continue;
}
......@@ -757,10 +718,6 @@ static void verify_list_presence(ir_node *irn, void *data)
if (irn != tgt) {
w->problem_found = 1;
#if 0
ir_fprintf(stderr, "Edge Verifier: edge(%ld) %+F,%d (kind \"%s\") is no out edge of %+F but of %+F\n",
edge_get_id(e), e->src, e->pos, get_kind_str(w->kind), irn, tgt);
#endif
}
}
}
......@@ -772,7 +729,6 @@ int edges_verify_kind(ir_graph *irg, ir_edge_kind_t kind)
ir_edge_t *e;
ir_edgeset_iterator_t iter;
w.irg = irg;
w.kind = kind;
w.reachable = bitset_alloca(get_irg_last_idx(irg));
w.problem_found = 0;
......@@ -806,15 +762,17 @@ int edges_verify_kind(ir_graph *irg, ir_edge_kind_t kind)
*/
static void clear_links(ir_node *irn, void *env)
{
build_walker *w = (build_walker*)env;
bitset_t *bs;
ir_graph *irg;
(void) env;
if (IGNORE_NODE(irn)) {
set_irn_link(irn, NULL);
return;
}
bs = bitset_malloc(get_irg_last_idx(w->irg));
irg = get_irn_irg(irn);
bs = bitset_malloc(get_irg_last_idx(irg));
set_irn_link(irn, bs);
}
......@@ -850,6 +808,7 @@ static void verify_edge_counter(ir_node *irn, void *env)
size_t idx;
const struct list_head *head;
const struct list_head *pos;
ir_graph *irg;
if (IGNORE_NODE(irn))
return;
......@@ -867,10 +826,11 @@ static void verify_edge_counter(ir_node *irn, void *env)
/* 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;
bitset_foreach(bs, idx) {
int i, arity;
ir_node *src = get_idx_irn(w->irg, idx);
ir_node *src = get_idx_irn(irg, idx);
arity = get_irn_arity(src);
for (i = 0; i < arity; ++i) {
......@@ -890,26 +850,6 @@ static void verify_edge_counter(ir_node *irn, void *env)
w->problem_found = 1;
ir_fprintf(stderr, "Edge Verifier: %+F reachable by %d node(s), but the list contains %d edge(s)\n",
irn, ref_cnt, list_cnt);
/* Matze: buggy if a node has multiple ins pointing at irn */
#if 0
list_for_each(pos, head) {
ir_edge_t *edge = list_entry(pos, ir_edge_t, list);
bitset_flip(bs, get_irn_idx(edge->src));
}
if (ref_cnt < list_cnt)
fprintf(stderr," following nodes are recorded in list, but not as user:\n");
else
fprintf(stderr," following nodes are user, but not recorded in list:\n");
fprintf(stderr," ");
bitset_foreach(bs, idx) {
ir_node *src = get_idx_irn(w->irg, idx);
ir_fprintf(stderr, " %+F", src);
}
fprintf(stderr, "\n");
#endif
}
bitset_free(bs);
......@@ -926,7 +866,6 @@ int edges_verify(ir_graph *irg)
/* verify normal edges only */
problem_found = edges_verify_kind(irg, EDGE_KIND_NORMAL);
w.irg = irg;
w.kind = EDGE_KIND_NORMAL;
w.problem_found = 0;
......@@ -1024,16 +963,16 @@ int edges_assure_kind(ir_graph *irg, ir_edge_kind_t kind)
return activated;
}
void edges_node_deleted(ir_node *irn, ir_graph *irg)
void edges_node_deleted(ir_node *irn)
{
edges_node_deleted_kind(irn, EDGE_KIND_NORMAL, irg);
edges_node_deleted_kind(irn, EDGE_KIND_BLOCK, irg);
edges_node_deleted_kind(irn, EDGE_KIND_NORMAL);
edges_node_deleted_kind(irn, EDGE_KIND_BLOCK);
}
void edges_node_revival(ir_node *irn, ir_graph *irg)
void edges_node_revival(ir_node *irn)
{
edges_node_revival_kind(irn, EDGE_KIND_NORMAL, irg);
edges_node_revival_kind(irn, EDGE_KIND_BLOCK, irg);
edges_node_revival_kind(irn, EDGE_KIND_NORMAL);
edges_node_revival_kind(irn, EDGE_KIND_BLOCK);
}
const ir_edge_t *(get_irn_out_edge_first_kind)(const ir_node *irn, ir_edge_kind_t kind)
......
......@@ -50,10 +50,6 @@ struct ir_edge_t {
unsigned present : 1; /**< Used by the verifier. Don't rely on its content. */
unsigned kind : 4; /**< The kind of the edge. */
struct list_head list; /**< The list head to queue all out edges at a node. */
#ifdef DEBUG_libfirm
long src_nr; /**< The node number of the source node. */
long edge_nr; /**< A unique number identifying the edge. */
#endif
};
......@@ -103,16 +99,7 @@ static inline const ir_edge_t *_get_irn_out_edge_next(const ir_node *irn, const
*/
static inline int _get_irn_n_edges_kind(const ir_node *irn, int kind)
{
/* Perhaps out_count was buggy. This code does it more safely. */
#if 0
int res = 0;
const struct list_head *pos, *head = _get_irn_outs_head(irn, kind);
list_for_each(pos, head)
res++;
return res;
#else
return _get_irn_edge_info(irn, kind)->out_count;
#endif
}
static inline int _edges_activated_kind(const ir_graph *irg, ir_edge_kind_t kind)
......@@ -135,9 +122,9 @@ void edges_init_graph_kind(ir_graph *irg, ir_edge_kind_t kind);
/**
* A node might be revivaled by CSE.
*/
void edges_node_revival(ir_node *node, ir_graph *irg);
void edges_node_revival(ir_node *node);
void edges_invalidate_kind(ir_node *irn, ir_edge_kind_t kind, ir_graph *irg);
void edges_invalidate_kind(ir_node *irn, ir_edge_kind_t kind);
/**
* Register additional memory in an edge.
......@@ -177,7 +164,7 @@ static inline int _get_edge_src_pos(const ir_edge_t *edge)
*/
extern void init_edges(void);
void edges_invalidate_all(ir_node *irn, ir_graph *irg);
void edges_invalidate_all(ir_node *irn);
/**
* Helper function to dump the edge set of a graph,
......@@ -185,6 +172,12 @@ void edges_invalidate_all(ir_node *irn, ir_graph *irg);
*/
void edges_dump_kind(ir_graph *irg, ir_edge_kind_t kind);
/**
* Notify normal and block edges.
*/
void edges_notify_edge(ir_node *src, int pos, ir_node *tgt,
ir_node *old_tgt, ir_graph *irg);
#define get_irn_n_edges_kind(irn, kind) _get_irn_n_edges_kind(irn, kind)
#define get_edge_src_irn(edge) _get_edge_src_irn(edge)
#define get_edge_src_pos(edge) _get_edge_src_pos(edge)
......
......@@ -82,9 +82,9 @@ void exchange(ir_node *old, ir_node *nw)
/* copy all dependencies from old to new */
add_irn_deps(nw, old);
edges_reroute(old, nw, irg);
edges_reroute_kind(old, nw, EDGE_KIND_DEP, irg);
edges_node_deleted(old, irg);
edges_reroute(old, nw);
edges_reroute_kind(old, nw, EDGE_KIND_DEP);
edges_node_deleted(old);
/* noone is allowed to reference this node anymore */
set_irn_op(old, op_Deleted);
} else {
......
......@@ -6222,7 +6222,7 @@ ir_node *identify_remember(ir_node *n)
if (nn != n) {
/* n is reachable again */
edges_node_revival(nn, get_irn_irg(nn));
edges_node_revival(nn);
}
return nn;
......@@ -6386,7 +6386,7 @@ ir_node *optimize_node(ir_node *n)
Run always for transformation induced Bads. */
n = gigo(n);
if (n != oldn) {
edges_node_deleted(oldn, irg);
edges_node_deleted(oldn);
/* We found an existing, better node, so we can deallocate the old node. */
irg_kill_node(irg, oldn);
......@@ -6417,7 +6417,7 @@ ir_node *optimize_node(ir_node *n)
memcpy(oldn->in, n->in, ARR_LEN(n->in) * sizeof(n->in[0]));
/* note the inplace edges module */
edges_node_deleted(n, irg);
edges_node_deleted(n);
/* evaluation was successful -- replace the node. */
irg_kill_node(irg, n);
......@@ -6448,7 +6448,7 @@ ir_node *optimize_node(ir_node *n)
n = identify_cons(n);
if (n != oldn) {
edges_node_deleted(oldn, irg);
edges_node_deleted(oldn);
/* We found an existing, better node, so we can deallocate the old node. */
irg_kill_node(irg, oldn);
......
......@@ -85,7 +85,7 @@ static void maybe_kill_node(ir_node *node)
}
set_nodes_block(node, new_r_Bad(irg));
edges_node_deleted(node, irg);
edges_node_deleted(node);
}
static ir_node *create_not(dbg_info *dbgi, ir_node *node)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment