Commit 842280b6 authored by Matthias Braun's avatar Matthias Braun
Browse files

make some more optimisations independent of current_ir_graph

[r28041]
parent 5dbb8aee
......@@ -81,19 +81,16 @@ typedef enum {
* Called by get_alias_relation().
*/
typedef ir_alias_relation (*DISAMBIGUATOR_FUNC)(
const ir_graph *irg,
const ir_node *adr1, const ir_mode *mode1,
const ir_node *adr2, const ir_mode *mode2);
/**
* Classify a base pointer.
*
* @param irg the graph of the pointer
* @param irn the node representing the base address
* @param ent the base entity of the base address iff any
*/
FIRM_API ir_storage_class_class_t classify_pointer(const ir_graph *irg,
const ir_node *irn,
FIRM_API ir_storage_class_class_t classify_pointer(const ir_node *irn,
const ir_entity *ent);
/**
......@@ -136,7 +133,6 @@ FIRM_API const char *get_ir_alias_relation_name(ir_alias_relation rel);
* interrogated to detect the alias relation.
*/
FIRM_API ir_alias_relation get_alias_relation(
const ir_graph *irg,
const ir_node *adr1, const ir_mode *mode1,
const ir_node *adr2, const ir_mode *mode2);
......@@ -165,7 +161,6 @@ FIRM_API void mem_disambig_init(void);
* @see get_alias_relation()
*/
FIRM_API ir_alias_relation get_alias_relation_ex(
const ir_graph *irg,
const ir_node *adr1, const ir_mode *mode1,
const ir_node *adr2, const ir_mode *mode2);
......
......@@ -424,15 +424,10 @@ static int is_malloc_Result(const ir_node *node)
return 0;
} /* is_malloc_Result */
/**
* Classify a base pointer.
*
* @param irg the graph of the pointer
* @param irn the node representing the base address
* @param ent the base entity of the base address iff any
*/
ir_storage_class_class_t classify_pointer(const ir_graph *irg, const ir_node *irn, const ir_entity *ent)
ir_storage_class_class_t classify_pointer(const ir_node *irn,
const ir_entity *ent)
{
ir_graph *irg = get_irn_irg(irn);
ir_storage_class_class_t res = ir_sc_pointer;
if (is_Global(irn)) {
ir_entity *entity = get_Global_entity(irn);
......@@ -477,7 +472,6 @@ static const ir_node *skip_Bitfield_Sels(const ir_node *adr)
/**
* Determine the alias relation between two addresses.
*
* @param irg the graph of both memory operations
* @param addr1 pointer address of the first memory operation
* @param mode1 the mode of the accessed data through addr1
* @param addr2 pointer address of the second memory operation
......@@ -486,7 +480,6 @@ static const ir_node *skip_Bitfield_Sels(const ir_node *adr)
* @return found memory relation
*/
static ir_alias_relation _get_alias_relation(
const ir_graph *irg,
const ir_node *adr1, const ir_mode *mode1,
const ir_node *adr2, const ir_mode *mode2)
{
......@@ -498,6 +491,7 @@ static ir_alias_relation _get_alias_relation(
const ir_node *base2;
const ir_node *orig_adr1 = adr1;
const ir_node *orig_adr2 = adr2;
ir_graph *irg;
unsigned mode_size;
ir_storage_class_class_t class1, class2, mod1, mod2;
int have_const_offsets;
......@@ -508,6 +502,7 @@ static ir_alias_relation _get_alias_relation(
if (adr1 == adr2)
return ir_sure_alias;
irg = get_irn_irg(adr1);
options = get_irg_memory_disambiguator_options(irg);
/* The Armageddon switch */
......@@ -593,8 +588,8 @@ static ir_alias_relation _get_alias_relation(
return different_sel_offsets(adr1, adr2);
}
mod1 = classify_pointer(irg, base1, ent1);
mod2 = classify_pointer(irg, base2, ent2);
mod1 = classify_pointer(base1, ent1);
mod2 = classify_pointer(base2, ent2);
class1 = GET_BASE_SC(mod1);
class2 = GET_BASE_SC(mod2);
......@@ -680,7 +675,7 @@ leave_type_based_alias:;
/* do we have a language specific memory disambiguator? */
if (language_disambuigator != NULL) {
ir_alias_relation rel = language_disambuigator(irg, orig_adr1, mode1, orig_adr2, mode2);
ir_alias_relation rel = language_disambuigator(orig_adr1, mode1, orig_adr2, mode2);
if (rel != ir_may_alias)
return rel;
}
......@@ -693,11 +688,10 @@ leave_type_based_alias:;
* Determine the alias relation between two addresses.
*/
ir_alias_relation get_alias_relation(
const ir_graph *irg,
const ir_node *adr1, const ir_mode *mode1,
const ir_node *adr2, const ir_mode *mode2)
{
ir_alias_relation rel = _get_alias_relation(irg, adr1, mode1, adr2, mode2);
ir_alias_relation rel = _get_alias_relation(adr1, mode1, adr2, mode2);
DB((dbg, LEVEL_1, "alias(%+F, %+F) = %s\n", adr1, adr2, get_ir_alias_relation_name(rel)));
return rel;
} /* get_alias_relation */
......@@ -747,7 +741,6 @@ void mem_disambig_init(void)
* Determine the alias relation between two addresses.
*/
ir_alias_relation get_alias_relation_ex(
const ir_graph *irg,
const ir_node *adr1, const ir_mode *mode1,
const ir_node *adr2, const ir_mode *mode2)
{
......@@ -772,7 +765,7 @@ ir_alias_relation get_alias_relation_ex(
if (entry != NULL)
return entry->result;
key.result = get_alias_relation(irg, adr1, mode1, adr2, mode2);
key.result = get_alias_relation(adr1, mode1, adr2, mode2);
set_insert(result_cache, &key, sizeof(key), HASH_ENTRY(adr1, adr2));
return key.result;
......
......@@ -315,7 +315,7 @@ static void check_ptr(ir_node *ptr, wlk_env *env)
/* still alias free */
ptr = find_base_adr(ptr, &ent);
sc = GET_BASE_SC(classify_pointer(current_ir_graph, ptr, ent));
sc = GET_BASE_SC(classify_pointer(ptr, ent));
if (sc != ir_sc_localvar && sc != ir_sc_malloced) {
/* non-local memory access */
env->only_local_mem = 0;
......
......@@ -705,7 +705,7 @@ restart:
env->changed = 1;
DB((dbg, LEVEL_1, "boolopt: %+F: fusing (ub %+F lb %+F)\n",
current_ir_graph, upper_block, lower_block));
get_irn_irg(upper_block), upper_block, lower_block));
/* move all expressions on the path to lower/upper block */
move_nodes_to_block(get_Block_cfgpred(block, up_idx), upper_block);
......
......@@ -702,7 +702,6 @@ void optimize_cf(ir_graph *irg)
int i, j, n, changed;
ir_node **in = NULL;
ir_node *cond, *end = get_irg_end(irg);
ir_graph *rem = current_ir_graph;
plist_element_t *el;
merge_env env;
......@@ -712,8 +711,6 @@ void optimize_cf(ir_graph *irg)
assert(get_irg_pinned(irg) != op_pin_state_floats &&
"Control flow optimization need a pinned graph");
current_ir_graph = irg;
/* FIXME: control flow opt destroys block edges. So edges are deactivated here. Fix the edges! */
edges_deactivate(irg);
......@@ -876,8 +873,6 @@ restart:
fprintf(stderr, "VERIFY_BAD in optimize_cf()\n");
}
}
current_ir_graph = rem;
}
/* Creates an ir_graph pass for optimize_cf. */
......
......@@ -77,12 +77,13 @@ static void place_floats_early(ir_node *n, waitq *worklist)
int in_dead_block = is_Block_unreachable(curr_block);
int depth = 0;
ir_node *b = NULL; /* The block to place this node in */
ir_graph *irg = get_irn_irg(n);
assert(!is_Block(n));
if (is_irn_start_block_placed(n)) {
/* These nodes will not be placed by the loop below. */
b = get_irg_start_block(current_ir_graph);
b = get_irg_start_block(irg);
depth = 1;
}
......@@ -133,9 +134,9 @@ static void place_floats_early(ir_node *n, waitq *worklist)
in the backend phase. */
if (depth == 1 &&
get_Block_dom_depth(get_nodes_block(n)) > 1 &&
get_irg_phase_state(current_ir_graph) != phase_backend) {
b = get_Block_cfg_out(get_irg_start_block(current_ir_graph), 0);
assert(b != get_irg_start_block(current_ir_graph));
get_irg_phase_state(irg) != phase_backend) {
b = get_Block_cfg_out(get_irg_start_block(irg), 0);
assert(b != get_irg_start_block(irg));
depth = 2;
}
}
......@@ -231,13 +232,13 @@ static void place_floats_early(ir_node *n, waitq *worklist)
*
* @param worklist a worklist, used for the algorithm, empty on in/output
*/
static void place_early(waitq *worklist)
static void place_early(ir_graph *irg, waitq *worklist)
{
assert(worklist);
inc_irg_visited(current_ir_graph);
inc_irg_visited(irg);
/* this inits the worklist */
place_floats_early(get_irg_end(current_ir_graph), worklist);
place_floats_early(get_irg_end(irg), worklist);
/* Work the content of the worklist. */
while (!waitq_empty(worklist)) {
......@@ -245,7 +246,7 @@ static void place_early(waitq *worklist)
if (!irn_visited(n))
place_floats_early(n, worklist);
}
set_irg_pinned(current_ir_graph, op_pin_state_pinned);
set_irg_pinned(irg, op_pin_state_pinned);
}
/**
......@@ -501,13 +502,13 @@ static void place_floats_late(ir_node *n, pdeq *worklist)
*
* @param worklist the worklist containing the nodes to place
*/
static void place_late(waitq *worklist)
static void place_late(ir_graph *irg, waitq *worklist)
{
assert(worklist);
inc_irg_visited(current_ir_graph);
inc_irg_visited(irg);
/* This fills the worklist initially. */
place_floats_late(get_irg_start_block(current_ir_graph), worklist);
place_floats_late(get_irg_start_block(irg), worklist);
/* And now empty the worklist again... */
while (!waitq_empty(worklist)) {
......@@ -521,9 +522,7 @@ static void place_late(waitq *worklist)
void place_code(ir_graph *irg)
{
waitq *worklist;
ir_graph *rem = current_ir_graph;
current_ir_graph = irg;
remove_critical_cf_edges(irg);
/* Handle graph state */
......@@ -539,19 +538,18 @@ void place_code(ir_graph *irg)
/* Place all floating nodes as early as possible. This guarantees
a legal code placement. */
worklist = new_waitq();
place_early(worklist);
place_early(irg, worklist);
/* Note: place_early changes only blocks, no data edges. So, the
* data out edges are still valid, no need to recalculate them here. */
/* Now move the nodes down in the dominator tree. This reduces the
unnecessary executions of the node. */
place_late(worklist);
place_late(irg, worklist);
set_irg_outs_inconsistent(irg);
set_irg_loopinfo_inconsistent(irg);
del_waitq(worklist);
current_ir_graph = rem;
}
/**
......
......@@ -85,10 +85,8 @@ static void copy_node_dce(ir_node *node, void *env)
}
/**
* Copies the graph reachable from current_ir_graph->end to the obstack
* in current_ir_graph and fixes the environment.
* Then fixes the fields in current_ir_graph containing nodes of the
* graph.
* Copies the graph reachable from the End node to the obstack
* in irg. Then fixes the fields containing nodes of the graph.
*
* @param copy_node_nr If non-zero, the node number will be copied
*/
......@@ -142,7 +140,6 @@ static void copy_graph_env(ir_graph *irg)
*/
void dead_node_elimination(ir_graph *irg)
{
ir_graph *rem;
struct obstack *graveyard_obst = NULL;
struct obstack *rebirth_obst = NULL;
......@@ -151,10 +148,6 @@ void dead_node_elimination(ir_graph *irg)
/* inform statistics that we started a dead-node elimination run */
hook_dead_node_elim(irg, 1);
/* Remember external state of current_ir_graph. */
rem = current_ir_graph;
current_ir_graph = irg;
assert(get_irg_phase_state(irg) != phase_building);
/* Handle graph state */
......@@ -186,8 +179,6 @@ void dead_node_elimination(ir_graph *irg)
/* inform statistics that the run is over */
hook_dead_node_elim(irg, 0);
current_ir_graph = rem;
}
ir_graph_pass_t *dead_node_elimination_pass(const char *name)
......
......@@ -100,7 +100,7 @@ static void collect_const_and_pure_calls(ir_node *node, void *env)
++ctx->n_calls_SymConst;
} else if (get_opt_closed_world() &&
is_Sel(ptr) &&
get_irg_callee_info_state(current_ir_graph) == irg_callee_info_consistent) {
get_irg_callee_info_state(get_irn_irg(node)) == irg_callee_info_consistent) {
/* If all possible callees are const functions, we can remove the memory edge. */
int i, n_callees = get_Call_n_callees(call);
if (n_callees == 0) {
......@@ -176,9 +176,6 @@ static void fix_const_call_lists(ir_graph *irg, env_t *ctx)
{
ir_node *call, *next, *mem, *proj;
int exc_changed = 0;
ir_graph *rem = current_ir_graph;
current_ir_graph = irg;
/* First step: fix all calls by removing their memory input and let
* them floating.
......@@ -251,7 +248,6 @@ static void fix_const_call_lists(ir_graph *irg, env_t *ctx)
/* ... including exception edges */
set_irg_doms_inconsistent(irg);
}
current_ir_graph = rem;
} /* fix_const_call_list */
/**
......@@ -280,7 +276,7 @@ static void collect_nothrow_calls(ir_node *node, void *env)
++ctx->n_calls_SymConst;
} else if (get_opt_closed_world() &&
is_Sel(ptr) &&
get_irg_callee_info_state(current_ir_graph) == irg_callee_info_consistent) {
get_irg_callee_info_state(get_irn_irg(node)) == irg_callee_info_consistent) {
/* If all possible callees are nothrow functions, we can remove the exception edge. */
int i, n_callees = get_Call_n_callees(call);
if (n_callees == 0) {
......@@ -343,9 +339,6 @@ static void fix_nothrow_call_list(ir_graph *irg, ir_node *call_list, ir_node *pr
{
ir_node *call, *next, *proj;
int exc_changed = 0;
ir_graph *rem = current_ir_graph;
current_ir_graph = irg;
/* First step: go through the list of calls and mark them. */
for (call = call_list; call; call = next) {
......@@ -390,7 +383,6 @@ static void fix_nothrow_call_list(ir_graph *irg, ir_node *call_list, ir_node *pr
/* ... including exception edges */
set_irg_doms_inconsistent(irg);
}
current_ir_graph = rem;
} /* fix_nothrow_call_list */
/* marking */
......@@ -474,7 +466,7 @@ static unsigned _follow_mem(ir_node *node)
ir_entity *ent = get_SymConst_entity(ptr);
ir_graph *irg = get_entity_irg(ent);
if (irg == current_ir_graph) {
if (irg == get_irn_irg(node)) {
/* A self-recursive call. The property did not depend on this call. */
} else if (irg == NULL) {
m = get_entity_additional_properties(ent) & (mtp_property_const|mtp_property_pure);
......@@ -522,7 +514,6 @@ static unsigned check_const_or_pure_function(ir_graph *irg, int top)
ir_node *end, *endbl;
int j;
unsigned prop = get_irg_additional_properties(irg);
ir_graph *rem = current_ir_graph;
if (prop & mtp_property_const) {
/* already marked as a const function */
......@@ -548,8 +539,6 @@ static unsigned check_const_or_pure_function(ir_graph *irg, int top)
endbl = get_nodes_block(end);
prop = mtp_property_const;
current_ir_graph = irg;
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
inc_irg_visited(irg);
/* mark the initial mem: recursion of follow_mem() stops here */
......@@ -615,7 +604,6 @@ static unsigned check_const_or_pure_function(ir_graph *irg, int top)
SET_IRG_READY(irg);
CLEAR_IRG_BUSY(irg);
ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
current_ir_graph = rem;
return prop;
} /* check_const_or_pure_function */
......
......@@ -65,7 +65,6 @@ static void start_visit_node(ir_node *node)
if (get_irg_visited(irg) < get_max_irg_visited()) {
set_irg_visited(irg, get_max_irg_visited());
}
current_ir_graph = irg;
irg_walk_2(node, visit_node, NULL, NULL);
}
......
......@@ -1021,7 +1021,6 @@ static unsigned follow_Mem_chain(ir_node *load, ir_node *curr)
if (is_Store(pred)) {
/* check if we can pass through this store */
ir_alias_relation rel = get_alias_relation(
current_ir_graph,
get_Store_ptr(pred),
get_irn_mode(get_Store_value(pred)),
ptr, load_mode);
......@@ -1334,7 +1333,6 @@ static unsigned follow_Mem_chain_for_Store(ir_node *store, ir_node *curr)
if (is_Store(pred)) {
/* check if we can pass through this store */
ir_alias_relation rel = get_alias_relation(
current_ir_graph,
get_Store_ptr(pred),
get_irn_mode(get_Store_value(pred)),
ptr, mode);
......@@ -1344,7 +1342,7 @@ static unsigned follow_Mem_chain_for_Store(ir_node *store, ir_node *curr)
pred = skip_Proj(get_Store_mem(pred));
} else if (is_Load(pred)) {
ir_alias_relation rel = get_alias_relation(
current_ir_graph, get_Load_ptr(pred), get_Load_mode(pred),
get_Load_ptr(pred), get_Load_mode(pred),
ptr, mode);
if (rel != ir_no_alias)
break;
......@@ -1872,7 +1870,6 @@ static void move_loads_out_of_loops(scc *pscc, loop_env *env)
if (is_Store(other)) {
ir_alias_relation rel = get_alias_relation(
current_ir_graph,
get_Store_ptr(other),
get_irn_mode(get_Store_value(other)),
ptr, load_mode);
......@@ -2172,11 +2169,9 @@ static void dfs(ir_node *irn, loop_env *env)
*/
static void do_dfs(ir_graph *irg, loop_env *env)
{
ir_graph *rem = current_ir_graph;
ir_node *endblk, *end;
int i;
current_ir_graph = irg;
inc_irg_visited(irg);
/* visit all memory nodes */
......@@ -2204,7 +2199,6 @@ static void do_dfs(ir_graph *irg, loop_env *env)
if (is_Phi(ka) && !irn_visited(ka))
dfs(ka, env);
}
current_ir_graph = rem;
} /* do_dfs */
/**
......
......@@ -962,7 +962,7 @@ static void partition_for_end_block(ir_node *end_block, environment_t *env)
}
/* collect all no-return blocks */
end = get_irg_end(current_ir_graph);
end = get_irg_end(get_irn_irg(end_block));
for (i = get_End_n_keepalives(end) - 1; i >= 0; --i) {
ir_node *ka = get_End_keepalive(end, i);
ir_node *block;
......@@ -1081,7 +1081,7 @@ static void check_for_cf_meet(ir_node *block, void *ctx)
int i, k, n;
pred_t *preds;
if (block == get_irg_end_block(current_ir_graph)) {
if (block == get_irg_end_block(get_irn_irg(block))) {
/* always create a partition for the end block */
partition_for_end_block(block, env);
return;
......@@ -1198,15 +1198,11 @@ static void add_roots(ir_graph *irg, environment_t *env)
/* Combines congruent end blocks into one. */
int shape_blocks(ir_graph *irg)
{
ir_graph *rem;
environment_t env;
partition_t *part;
block_t *bl;
int res, n;
rem = current_ir_graph;
current_ir_graph = irg;
/* register a debug mask */
FIRM_DBG_REGISTER(dbg, "firm.opt.blocks");
......@@ -1284,7 +1280,6 @@ int shape_blocks(ir_graph *irg)
DEL_ARR_F(env.live_outs);
del_set(env.opcode2id_map);
obstack_free(&env.obst, NULL);
current_ir_graph = rem;
return res;
} /* shape_blocks */
......
......@@ -201,7 +201,7 @@ int value_not_null(const ir_node *n, ir_node_cnst_ptr *confirm)
if (is_Global(n)) {
/* global references are never NULL */
return 1;
} else if (n == get_irg_frame(current_ir_graph)) {
} else if (n == get_irg_frame(get_irn_irg(n))) {
/* local references are never NULL */
return 1;
} else if (is_Alloc(n)) {
......
......@@ -1247,7 +1247,8 @@ static void collect_memops(ir_node *irn, void *ctx)
(void) ctx;
if (is_Proj(irn)) {
/* we can safely ignore ProjM's except the initial memory */
if (irn != get_irg_initial_mem(current_ir_graph))
ir_graph *irg = get_irn_irg(irn);
if (irn != get_irg_initial_mem(irg))
return;
}
......@@ -1380,7 +1381,7 @@ static void kill_memops(const value_t *value)
for (pos = rbitset_next(env.curr_set, 0, 1); pos < end; pos = rbitset_next(env.curr_set, pos + 1, 1)) {
memop_t *op = env.curr_id_2_memop[pos];
if (ir_no_alias != get_alias_relation(current_ir_graph, value->address, value->mode,
if (ir_no_alias != get_alias_relation(value->address, value->mode,
op->value.address, op->value.mode)) {
rbitset_clear(env.curr_set, pos);
env.curr_id_2_memop[pos] = NULL;
......@@ -2306,10 +2307,7 @@ static void kill_unreachable_blocks(ir_graph *irg)
int opt_ldst(ir_graph *irg)
{
block_t *bl;
ir_graph *rem = current_ir_graph;
current_ir_graph = irg;
block_t *bl;
FIRM_DBG_REGISTER(dbg, "firm.opt.ldst");
......@@ -2446,7 +2444,6 @@ end:
DEL_ARR_F(env.id_2_address);
#endif
current_ir_graph = rem;
return env.changed != 0;
} /* opt_ldst */
......
......@@ -489,7 +489,7 @@ static int replace(ir_node *irn, ir_node *iv, ir_node *rc, iv_env *env)
if (result != irn) {
node_entry *e;
hook_strength_red(current_ir_graph, irn);
hook_strength_red(get_irn_irg(irn), irn);
exchange(irn, result);
e = get_irn_ne(result, env);
if (e->pscc == NULL) {
......@@ -1046,13 +1046,11 @@ static void dfs(ir_node *irn, iv_env *env)
*/
static void do_dfs(ir_graph *irg, iv_env *env)
{
ir_graph *rem = current_ir_graph;
ir_node *end = get_irg_end(irg);
int i;
ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
current_ir_graph = irg;
inc_irg_visited(irg);
/* visit all visible nodes */
......@@ -1067,8 +1065,6 @@ static void do_dfs(ir_graph *irg, iv_env *env)
}
ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
current_ir_graph = rem;
} /* do_dfs */
/**
......@@ -1297,12 +1293,8 @@ static void clear_and_fix(ir_node *irn, void *env)
/* Remove any Phi cycles with only one real input. */
void remove_phi_cycles(ir_graph *irg)
{
iv_env env;
ir_graph *rem;
int projs_moved;
rem = current_ir_graph;
current_ir_graph = irg;
iv_env env;
int projs_moved;
FIRM_DBG_REGISTER(dbg, "firm.opt.remove_phi");
......@@ -1348,8 +1340,6 @@ void remove_phi_cycles(ir_graph *irg)
DEL_ARR_F(env.stack);
obstack_free(&env.obst, NULL);
current_ir_graph = rem;
} /* remove_phi_cycles */
ir_graph_pass_t *remove_phi_cycles_pass(const char *name)
......@@ -1416,13 +1406,9 @@ static void fix_adds_and_subs(ir_node *irn, void *ctx)
void opt_osr(ir_graph *irg, unsigned flags)
{
iv_env env;
ir_graph *rem;
int edges;
int projs_moved;
rem = current_ir_graph;
current_ir_graph = irg;
FIRM_DBG_REGISTER(dbg, "firm.opt.osr");
DB((dbg, LEVEL_1, "Doing Operator Strength Reduction for %+F\n", irg));
......@@ -1482,8 +1468,6 @@ void opt_osr(ir_graph *irg, unsigned flags)
if (! edges)
edges_deactivate(irg);
current_ir_graph = rem;
} /* opt_osr */
struct pass_t {
......
......@@ -74,7 +74,7 @@ static void parallelize_load(parallelize_info *pi, ir_node *irn)