*/
static long get_Sel_array_index_long(ir_node *n, int dim) {
ir_node *index = get_Sel_index(n, dim);
- assert(get_irn_op(index) == op_Const);
+ assert(is_Const(index));
return get_tarval_long(get_Const_tarval(index));
} /* get_Sel_array_index_long */
res |= CF_CHANGED;
}
- if (variability_constant == get_entity_variability(ent)
- && is_atomic_entity(ent)) {
- /* Might not be atomic after
- lowering of Sels. In this
- case we could also load, but
- it's more complicated. */
- /* more simpler case: we load the content of a constant value:
- * replace it by the constant itself
- */
-
- /* no memory */
- if (info->projs[pn_Load_M]) {
- exchange(info->projs[pn_Load_M], mem);
- res |= DF_CHANGED;
- }
- /* no result :-) */
- if (info->projs[pn_Load_res]) {
- if (is_atomic_entity(ent)) {
- ir_node *c = copy_const_value(get_irn_dbg_info(load), get_atomic_ent_value(ent));
-
- DBG_OPT_RC(load, c);
- exchange(info->projs[pn_Load_res], c);
- res |= DF_CHANGED;
- }
- }
- exchange(load, new_Bad());
- reduce_adr_usage(ptr);
- return res;
- } else if (variability_constant == get_entity_variability(ent)) {
- compound_graph_path *path = get_accessed_path(ptr);
-
- if (path) {
- ir_node *c;
-
- assert(is_proper_compound_graph_path(path, get_compound_graph_path_length(path)-1));
- /*
- {
- int j;
- for (j = 0; j < get_compound_graph_path_length(path); ++j) {
- ir_entity *node = get_compound_graph_path_node(path, j);
- fprintf(stdout, ".%s", get_entity_name(node));
- if (is_Array_type(get_entity_owner(node)))
- fprintf(stdout, "[%d]", get_compound_graph_path_array_index(path, j));
- }
- printf("\n");
- }
- */
-
- c = get_compound_ent_value_by_path(ent, path);
- free_compound_graph_path(path);
-
- /* printf(" cons: "); DDMN(c); */
-
+ if (variability_constant == get_entity_variability(ent)) {
+ if (is_atomic_entity(ent)) {
+ /* Might not be atomic after
+ lowering of Sels. In this
+ case we could also load, but
+ it's more complicated. */
+ /* more simpler case: we load the content of a constant value:
+ * replace it by the constant itself
+ */
+
+ /* no memory */
if (info->projs[pn_Load_M]) {
exchange(info->projs[pn_Load_M], mem);
res |= DF_CHANGED;
}
+ /* no result :-) */
if (info->projs[pn_Load_res]) {
- exchange(info->projs[pn_Load_res], copy_const_value(get_irn_dbg_info(load), c));
- res |= DF_CHANGED;
+ if (is_atomic_entity(ent)) {
+ ir_node *c = copy_const_value(get_irn_dbg_info(load), get_atomic_ent_value(ent));
+
+ DBG_OPT_RC(load, c);
+ exchange(info->projs[pn_Load_res], c);
+ res |= DF_CHANGED;
+ }
}
exchange(load, new_Bad());
reduce_adr_usage(ptr);
return res;
} else {
- /* We can not determine a correct access path. E.g., in jack, we load
- a byte from an object to generate an exception. Happens in test program
- Reflectiontest.
- printf(">>>>>>>>>>>>> Found access to constant entity %s in function %s\n", get_entity_name(ent),
- get_entity_name(get_irg_entity(current_ir_graph)));
- printf(" load: "); DDMN(load);
- printf(" ptr: "); DDMN(ptr);
- */
+ compound_graph_path *path = get_accessed_path(ptr);
+
+ if (path) {
+ ir_node *c;
+
+ assert(is_proper_compound_graph_path(path, get_compound_graph_path_length(path)-1));
+ /*
+ {
+ int j;
+ for (j = 0; j < get_compound_graph_path_length(path); ++j) {
+ ir_entity *node = get_compound_graph_path_node(path, j);
+ fprintf(stdout, ".%s", get_entity_name(node));
+ if (is_Array_type(get_entity_owner(node)))
+ fprintf(stdout, "[%d]", get_compound_graph_path_array_index(path, j));
+ }
+ printf("\n");
+ }
+ */
+
+ c = get_compound_ent_value_by_path(ent, path);
+ free_compound_graph_path(path);
+
+ /* printf(" cons: "); DDMN(c); */
+
+ if (info->projs[pn_Load_M]) {
+ exchange(info->projs[pn_Load_M], mem);
+ res |= DF_CHANGED;
+ }
+ if (info->projs[pn_Load_res]) {
+ exchange(info->projs[pn_Load_res], copy_const_value(get_irn_dbg_info(load), c));
+ res |= DF_CHANGED;
+ }
+ exchange(load, new_Bad());
+ reduce_adr_usage(ptr);
+ return res;
+ } else {
+ /* We can not determine a correct access path. E.g., in jack, we load
+ a byte from an object to generate an exception. Happens in test program
+ Reflectiontest.
+ printf(">>>>>>>>>>>>> Found access to constant entity %s in function %s\n", get_entity_name(ent),
+ get_entity_name(get_irg_entity(current_ir_graph)));
+ printf(" load: "); DDMN(load);
+ printf(" ptr: "); DDMN(ptr);
+ */
+ }
}
}
}
next = ne->next;
/* check all memory Phi's */
- if (! is_Phi(phi) || get_irn_mode(phi) != mode_M)
+ if (! is_Phi(phi))
continue;
+ assert(get_irn_mode(phi) == mode_M && "DFS geturn non-memory Phi");
+
for (j = get_irn_arity(phi) - 1; j >= 0; --j) {
ir_node *pred = get_irn_n(phi, j);
node_entry *pe = get_irn_ne(pred, env);
}
}
/* no Phis no fun */
- if (phi_list == NULL)
- return;
+ assert(phi_list != NULL && "DFS found a loop without Phi");
for (load = pscc->head; load; load = next) {
ir_mode *load_mode;
process_loop(pscc, env);
}
} /* process_scc */
+
/**
* Do Tarjan's SCC algorithm and drive load/store optimization.
*
mark_irn_visited(irn);
- /* do not put blocks into the scc */
- if (is_Block(irn)) {
- n = get_irn_arity(irn);
- for (i = 0; i < n; ++i) {
- ir_node *pred = get_irn_n(irn, i);
-
- if (irn_not_visited(pred))
- dfs(pred, env);
- }
- }
- else {
- ir_node *block = get_nodes_block(irn);
-
- node->DFSnum = env->nextDFSnum++;
- node->low = node->DFSnum;
- push(env, irn);
-
- /* handle the block */
- if (irn_not_visited(block))
- dfs(block, env);
+ node->DFSnum = env->nextDFSnum++;
+ node->low = node->DFSnum;
+ push(env, irn);
+ /* handle preds */
+ if (is_Phi(irn) || is_Sync(irn)) {
n = get_irn_arity(irn);
for (i = 0; i < n; ++i) {
ir_node *pred = get_irn_n(irn, i);
if (o->DFSnum < node->DFSnum && o->in_stack)
node->low = MIN(o->DFSnum, node->low);
}
- if (node->low == node->DFSnum) {
- scc *pscc = phase_alloc(&env->ph, sizeof(*pscc));
- ir_node *x;
-
- pscc->head = NULL;
- do {
- node_entry *e;
-
- x = pop(env);
- e = get_irn_ne(x, env);
- e->pscc = pscc;
- e->next = pscc->head;
- pscc->head = x;
- } while (x != irn);
-
- process_scc(pscc, env);
+ } else if (is_fragile_op(irn)) {
+ ir_node *pred = get_fragile_op_mem(irn);
+ node_entry *o = get_irn_ne(pred, env);
+
+ if (irn_not_visited(pred)) {
+ dfs(pred, env);
+ node->low = MIN(node->low, o->low);
}
+ if (o->DFSnum < node->DFSnum && o->in_stack)
+ node->low = MIN(o->DFSnum, node->low);
+ } else if (is_Proj(irn)) {
+ ir_node *pred = get_Proj_pred(irn);
+ node_entry *o = get_irn_ne(pred, env);
+
+ if (irn_not_visited(pred)) {
+ dfs(pred, env);
+ node->low = MIN(node->low, o->low);
+ }
+ if (o->DFSnum < node->DFSnum && o->in_stack)
+ node->low = MIN(o->DFSnum, node->low);
+ }
+ else {
+ /* IGNORE predecessors */
+ }
+
+ if (node->low == node->DFSnum) {
+ scc *pscc = phase_alloc(&env->ph, sizeof(*pscc));
+ ir_node *x;
+
+ pscc->head = NULL;
+ do {
+ node_entry *e;
+
+ x = pop(env);
+ e = get_irn_ne(x, env);
+ e->pscc = pscc;
+ e->next = pscc->head;
+ pscc->head = x;
+ } while (x != irn);
+
+ process_scc(pscc, env);
}
} /* dfs */
/**
- * Do the DFS by starting at the End node of a graph.
+ * Do the DFS on the memory edges a graph.
*
* @param irg the graph to process
* @param env the loop environment
*/
static void do_dfs(ir_graph *irg, loop_env *env) {
ir_graph *rem = current_ir_graph;
- ir_node *end = get_irg_end(irg);
- int i, n;
+ ir_node *endblk, *end;
+ int i;
current_ir_graph = irg;
inc_irg_visited(irg);
- /* visit all visible nodes */
- dfs(end, env);
+ /* visit all memory nodes */
+ endblk = get_irg_end_block(irg);
+ for (i = get_Block_n_cfgpreds(endblk) - 1; i >= 0; --i) {
+ ir_node *pred = get_Block_cfgpred(endblk, i);
+
+ if (is_Return(pred))
+ dfs(get_Return_mem(pred), env);
+ else if (is_Raise(pred))
+ dfs(get_Raise_mem(pred), env);
+ else if (is_fragile_op(pred))
+ dfs(get_fragile_op_mem(pred), env);
+ else {
+ assert(0 && "Unknown EndBlock predecessor");
+ }
+ }
/* visit the keep-alives */
- n = get_End_n_keepalives(end);
- for (i = 0; i < n; ++i) {
+ end = get_irg_end(irg);
+ for (i = get_End_n_keepalives(end) - 1; i >= 0; --i) {
ir_node *ka = get_End_keepalive(end, i);
- if (irn_not_visited(ka))
+ if (is_Phi(ka) && irn_not_visited(ka))
dfs(ka, env);
}
current_ir_graph = rem;
walk_env_t env;
FIRM_DBG_REGISTER(dbg, "firm.opt.ldstopt");
-// firm_dbg_set_mask(dbg, SET_LEVEL_1);
assert(get_irg_phase_state(irg) != phase_building);
assert(get_irg_pinned(irg) != op_pin_state_floats &&
edges_assure(irg);
- /* loop optimizations need dominators ... */
- assure_doms(irg);
-
/* for Phi optimization post-dominators are needed ... */
assure_postdoms(irg);