Commit c8e1cf6a authored by Matthias Braun's avatar Matthias Braun
Browse files

remove lots of unnecessary and dangerous current_ir_graph usages

[r27944]
parent 269be573
......@@ -256,7 +256,7 @@ static void fix_loops(ir_node *node)
}
if (changed) {
identify_remember(current_ir_graph->value_table, node);
identify_remember(node);
}
}
......@@ -361,7 +361,6 @@ static void transform_nodes(ir_graph *irg, arch_pretrans_nodes *pre_transform)
fix_loops(anchor);
set_irn_n(new_anchor, i, anchor);
}
set_nodes_block(new_anchor, get_irg_anchor(irg, anchor_end_block));
del_waitq(env.worklist);
free_End(old_end);
......@@ -445,8 +444,7 @@ void be_transform_graph(ir_graph *irg, arch_pretrans_nodes *func)
irg_invalidate_phases(irg);
/* create new value table for CSE */
del_identities(irg->value_table);
irg->value_table = new_identities();
new_identities(irg);
/* enter special helper */
op_Block->ops.generic = (op_func)gen_Block;
......
......@@ -170,10 +170,9 @@ static ir_node *get_new_node(const ir_node *old_node)
void irn_rewire_inputs(ir_node *node)
{
ir_graph *new_irg;
ir_node *new_node;
int arity;
int i;
ir_node *new_node;
int arity;
int i;
new_node = get_new_node(node);
......@@ -199,8 +198,7 @@ void irn_rewire_inputs(ir_node *node)
}
/* Now the new node is complete. We can add it to the hash table for CSE. */
new_irg = get_irn_irg(new_node);
add_identities(new_irg->value_table, new_node);
add_identities(new_node);
}
void firm_pset_dump(pset *set)
......
......@@ -61,7 +61,7 @@ static uninitialized_local_variable_func_t *default_initialize_local_variable =
static ir_node *new_bd_Start(dbg_info *db, ir_node *block)
{
ir_node *res;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(block);
res = new_ir_node(db, irg, block, op_Start, mode_T, 0, NULL);
......@@ -72,7 +72,7 @@ static ir_node *new_bd_Start(dbg_info *db, ir_node *block)
static ir_node *new_bd_End(dbg_info *db, ir_node *block)
{
ir_node *res;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(block);
res = new_ir_node(db, irg, block, op_End, mode_X, -1, NULL);
......@@ -87,7 +87,7 @@ static ir_node *new_bd_End(dbg_info *db, ir_node *block)
static ir_node *new_bd_Phi(dbg_info *db, ir_node *block, int arity, ir_node **in, ir_mode *mode)
{
ir_node *res;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(block);
int i;
int has_unknown = 0;
......@@ -162,7 +162,7 @@ static ir_node *new_bd_Sel(dbg_info *db, ir_node *block, ir_node *store,
ir_node **r_in;
ir_node *res;
int r_arity;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(block);
ir_mode *mode = is_Method_type(get_entity_type(ent)) ? mode_P_code : mode_P_data;
assert(ent != NULL && is_entity(ent) && "entity expected in Sel construction");
......@@ -186,7 +186,7 @@ static ir_node *new_bd_SymConst_type(dbg_info *db, ir_node *block,
ir_mode *mode, symconst_symbol value,
symconst_kind symkind, ir_type *tp)
{
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(block);
ir_node *res = new_ir_node(db, irg, block, op_SymConst, mode, 0, NULL);
res->attr.symc.kind = symkind;
......@@ -201,7 +201,7 @@ static ir_node *new_bd_SymConst_type(dbg_info *db, ir_node *block,
static ir_node *new_bd_Sync(dbg_info *db, ir_node *block)
{
ir_node *res;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(block);
res = new_ir_node(db, irg, block, op_Sync, mode_M, -1, NULL);
/* no need to call optimize node here, Sync are always created with no predecessors */
......@@ -215,7 +215,7 @@ static ir_node *new_bd_ASM(dbg_info *db, ir_node *block, int arity,
ident *clobber[], ident *text)
{
ir_node *res;
ir_graph *irg = current_ir_graph;
ir_graph *irg = get_irn_irg(block);
res = new_ir_node(db, irg, block, op_ASM, mode_T, arity, in);
res->attr.assem.pin_state = op_pin_state_pinned;
......@@ -1444,6 +1444,14 @@ ir_node *new_ASM(int arity, ir_node *in[], ir_asm_constraint *inputs,
ir_node *new_Anchor(ir_graph *irg)
{
ir_node *in[anchor_last];
ir_node *res;
memset(in, 0, sizeof(in));
return new_ir_node(NULL, irg, NULL, op_Anchor, mode_ANY, anchor_last, in);
res = new_ir_node(NULL, irg, NULL, op_Anchor, mode_ANY, anchor_last, in);
/* hack to get get_irn_irg working: set block to ourself and allow
* get_Block_irg for anchor */
res->attr.irg.irg = irg;
res->in[0] = res;
return res;
}
......@@ -273,6 +273,7 @@ static inline void edge_change_cnt(ir_node *tgt, ir_edge_kind_t kind, int ofs)
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 it's last user */
......@@ -281,12 +282,12 @@ static inline void edge_change_cnt(ir_node *tgt, ir_edge_kind_t kind, int ofs)
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, current_ir_graph);
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, current_ir_graph);
edges_notify_edge_kind(tgt, i, NULL, prev, EDGE_KIND_DEP, irg);
}
}
......
......@@ -71,18 +71,19 @@ static void optimize_in_place_wrapper(ir_node *n, void *env)
*/
static inline void do_local_optimize(ir_node *n)
{
ir_graph *irg = get_irn_irg(n);
/* Handle graph state */
assert(get_irg_phase_state(current_ir_graph) != phase_building);
assert(get_irg_phase_state(irg) != phase_building);
if (get_opt_global_cse())
set_irg_pinned(current_ir_graph, op_pin_state_floats);
set_irg_outs_inconsistent(current_ir_graph);
set_irg_doms_inconsistent(current_ir_graph);
set_irg_loopinfo_inconsistent(current_ir_graph);
set_irg_pinned(irg, op_pin_state_floats);
set_irg_outs_inconsistent(irg);
set_irg_doms_inconsistent(irg);
set_irg_loopinfo_inconsistent(irg);
/* Clean the value_table in irg for the CSE. */
del_identities(current_ir_graph->value_table);
current_ir_graph->value_table = new_identities();
new_identities(irg);
/* walk over the graph */
irg_walk(n, firm_clear_link, optimize_in_place_wrapper, NULL);
......@@ -184,11 +185,10 @@ int optimize_graph_df(ir_graph *irg)
state = edges_assure(irg);
if (get_opt_global_cse())
set_irg_pinned(current_ir_graph, op_pin_state_floats);
set_irg_pinned(irg, op_pin_state_floats);
/* Clean the value_table in irg for the CSE. */
del_identities(irg->value_table);
irg->value_table = new_identities();
new_identities(irg);
if (get_irg_dom_state(irg) == dom_consistent)
irg_block_walk_graph(irg, NULL, kill_dead_blocks, NULL);
......
......@@ -188,8 +188,7 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc)
res->last_node_idx = 0;
res->value_table = new_identities(); /* value table for global value
numbering for optimizing use in iropt.c */
new_identities(res);
res->outs = NULL;
res->inline_property = irg_inline_any;
......@@ -305,7 +304,7 @@ ir_graph *new_const_code_irg(void)
res->fp_model = fp_model_precise;
/* value table for global value numbering for optimizing use in iropt.c */
res->value_table = new_identities();
new_identities(res);
res->ent = NULL;
res->frame_type = NULL;
......@@ -424,7 +423,7 @@ ir_graph *create_irg_copy(ir_graph *irg)
res->extblk_state = ir_extblk_info_none;
res->fp_model = irg->fp_model;
res->value_table = new_identities();
new_identities(res);
/* clone the frame type here for safety */
irp_reserve_resources(irp, IR_RESOURCE_ENTITY_LINK);
......@@ -481,8 +480,7 @@ void free_ir_graph(ir_graph *irg)
free_irg_outs(irg);
if (irg->frame_type)
free_type(irg->frame_type);
if (irg->value_table)
del_identities(irg->value_table);
del_identities(irg);
if (irg->ent) {
set_entity_irg(irg->ent, NULL); /* not set in const code irg */
}
......
......@@ -263,6 +263,7 @@ ir_node *(get_irn_n)(const ir_node *node, int n)
void set_irn_n(ir_node *node, int n, ir_node *in)
{
ir_graph *irg = get_irn_irg(node);
assert(node && node->kind == k_ir_node);
assert(-1 <= n);
assert(n < get_irn_arity(node));
......@@ -272,7 +273,7 @@ void set_irn_n(ir_node *node, int n, ir_node *in)
hook_set_irn_n(node, n, in, node->in[n + 1]);
/* Here, we rely on src and tgt being in the current ir graph */
edges_notify_edge(node, n, in, node->in[n + 1], current_ir_graph);
edges_notify_edge(node, n, in, node->in[n + 1], irg);
node->in[n + 1] = in;
}
......@@ -613,7 +614,6 @@ void (set_Block_block_visited)(ir_node *node, ir_visited_t visit)
_set_Block_block_visited(node, visit);
}
/* For this current_ir_graph must be set. */
void (mark_Block_block_visited)(ir_node *node)
{
_mark_Block_block_visited(node);
......@@ -1162,9 +1162,11 @@ ir_entity *get_Call_callee(const ir_node *node, int pos)
void set_Call_callee_arr(ir_node *node, const int n, ir_entity ** arr)
{
ir_graph *irg = get_irn_irg(node);
assert(is_Call(node));
if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) {
node->attr.call.callee_arr = NEW_ARR_D(ir_entity *, current_ir_graph->obst, n);
node->attr.call.callee_arr = NEW_ARR_D(ir_entity *, irg->obst, n);
}
memcpy(node->attr.call.callee_arr, arr, n * sizeof(ir_entity *));
}
......
......@@ -408,7 +408,6 @@ static inline void _set_Block_block_visited(ir_node *node, ir_visited_t visit)
node->attr.block.block_visited = visit;
}
/* For this current_ir_graph must be set. */
static inline void _mark_Block_block_visited(ir_node *node)
{
ir_graph *irg = get_Block_irg(node);
......@@ -443,7 +442,7 @@ static inline int _is_Block_dead(const ir_node *block)
static inline ir_graph *_get_Block_irg(const ir_node *block)
{
assert(is_Block(block) || is_Bad(block));
assert(is_Block(block) || is_Bad(block) || is_Anchor(block));
return block->attr.irg.irg;
}
......
This diff is collapsed.
......@@ -52,21 +52,20 @@ ir_node *equivalent_node(ir_node *n);
/**
* Creates a new value table used for storing CSE identities.
* The value table is used to identify common expressions.
*
*/
pset *new_identities(void);
void new_identities(ir_graph *irg);
/**
* Deletes a identities value table.
*
* @param value_table the identity set
*/
void del_identities(pset *value_table);
void del_identities(ir_graph *irg);
/**
* Add a node to the identities value table.
*/
void add_identities(pset *value_table, ir_node *node);
void add_identities(ir_node *node);
/**
* Compare function for two nodes in the hash table. Gets two
......@@ -79,7 +78,7 @@ int identities_cmp(const void *elt, const void *key);
* Looks up the node in a hash table, enters it in the table
* if it isn't there yet.
*/
ir_node *identify_remember(pset *value_table, ir_node *n);
ir_node *identify_remember(ir_node *n);
/** Visit each node in the value table of a graph. */
void visit_all_identities(ir_graph *irg, irg_walk_func visit, void *env);
......
......@@ -125,7 +125,7 @@ struct ir_mode {
/* ir node attributes */
/** first attribute of Bad and Block nodes */
/** first attribute of Bad, Block, Anchor nodes */
typedef struct {
ir_graph *irg; /**< The graph this block like node belongs to. */
} irg_attr;
......
......@@ -400,10 +400,9 @@ static void lower_mode_b_walker(ir_node *node, void *env)
changed = true;
}
if (changed) {
ir_graph *irg = get_irn_irg(node);
bool *global_changed = env;
*global_changed = true;
add_identities(irg->value_table, node);
add_identities(node);
}
}
......
......@@ -175,8 +175,7 @@ void dead_node_elimination(ir_graph *irg)
irg->last_node_idx = 0;
/* We also need a new value table for CSE */
del_identities(irg->value_table);
irg->value_table = new_identities();
new_identities(irg);
/* Copy the graph from the old to the new obstack */
copy_graph_env(irg);
......
......@@ -83,7 +83,6 @@ typedef struct pre_env {
char first_iter; /**< non-zero for first iteration */
} pre_env;
static pset *value_table;
static ir_nodemap_t value_map;
/** The debug module handle. */
......@@ -117,14 +116,14 @@ static ir_node *add(ir_node *e, ir_node *v)
{
if (is_Proj(v)) {
ir_node *pred = get_Proj_pred(v);
ir_node *v_pred = identify_remember(value_table, pred);
ir_node *v_pred = identify_remember(pred);
if (v_pred != pred) {
/* must create a new value here */
v = new_r_Proj(v_pred, get_irn_mode(v), get_Proj_proj(v));
}
}
v = identify_remember(value_table, v);
v = identify_remember(v);
ir_nodemap_insert(&value_map, e, v);
return v;
} /* add */
......@@ -141,7 +140,7 @@ static ir_node *lookup(ir_node *e)
{
ir_node *value = ir_nodemap_get(&value_map, e);
if (value != NULL)
return identify_remember(value_table, value);
return identify_remember(value);
return NULL;
} /* lookup */
......@@ -395,7 +394,7 @@ static ir_node *phi_translate(ir_node *node, ir_node *block, int pos, ir_valuese
nn = new_ir_node(
get_irn_dbg_info(node),
current_ir_graph,
NULL,
get_nodes_block(node),
get_irn_op(node),
get_irn_mode(node),
arity,
......@@ -404,7 +403,6 @@ static ir_node *phi_translate(ir_node *node, ir_node *block, int pos, ir_valuese
node might depend on that. */
copy_node_attr(current_ir_graph, node, nn);
set_nodes_block(nn, get_nodes_block(node));
for (i = 0; i < arity; ++i) {
ir_node *pred = get_irn_n(node, i);
ir_node *leader = lookup(pred);
......@@ -807,7 +805,7 @@ void do_gvn_pre(ir_graph *irg)
/* edges will crash if enabled due to our allocate on other obstack trick */
edges_deactivate(irg);
value_table = new_identities();
new_identities(irg);
ir_nodemap_init(&value_map);
obstack_init(&obst);
......@@ -891,10 +889,8 @@ void do_gvn_pre(ir_graph *irg)
if (bl_info->new_set)
ir_valueset_del(bl_info->new_set);
}
del_identities(value_table);
ir_nodemap_destroy(&value_map);
obstack_free(&obst, NULL);
value_table = NULL;
/* pin the graph again: This is needed due to the use of set_opt_global_cse(1) */
set_irg_pinned(irg, op_pin_state_pinned);
......
......@@ -53,6 +53,7 @@ class Anchor(Op):
arity = "variable"
flags = [ "dump_noblock" ]
pinned = "yes"
attr_struct = "irg_attr"
knownBlock = True
singleton = True
......
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