* @date 14.12.2005
* @version $Id$
*/
-#ifdef HAVE_CONFIG_H
#include "config.h"
-#endif
#include <stdlib.h>
#include "irgmod.h"
#include "iredges_t.h"
#include "irgwalk.h"
+#include "array_t.h"
#include "bearch_t.h"
#include "belower.h"
/** Lowering walker environment. */
typedef struct _lower_env_t {
be_irg_t *birg;
- const arch_env_t *arch_env;
unsigned do_copy : 1;
DEBUG_ONLY(firm_dbg_module_t *dbg_module;)
} lower_env_t;
}
/* assume worst case: all remaining pairs build a cycle or chain */
- cycle->elems = xcalloc((n - n_pairs_done) * 2, sizeof(cycle->elems[0]));
+ cycle->elems = XMALLOCNZ(const arch_register_t*, (n - n_pairs_done) * 2);
cycle->n_elems = 2; /* initial number of elements is 2 */
cycle->elems[0] = pairs[start].in_reg;
cycle->elems[1] = pairs[start].out_reg;
static void lower_perm_node(ir_node *irn, void *walk_env) {
ir_graph *irg = get_irn_irg(irn);
const arch_register_class_t *reg_class;
- const arch_env_t *arch_env;
lower_env_t *env = walk_env;
int real_size = 0;
int keep_perm = 0;
int n, i, pn, do_copy, j, n_ops;
reg_pair_t *pairs;
const ir_edge_t *edge;
- perm_cycle_t *cycle;
ir_node *sched_point, *block, *in[2];
ir_node *arg1, *arg2, *res1, *res2;
ir_node *cpyxchg = NULL;
DEBUG_ONLY(firm_dbg_module_t *mod;)
- arch_env = env->arch_env;
do_copy = env->do_copy;
DEBUG_ONLY(mod = env->dbg_module;)
block = get_nodes_block(irn);
n = get_irn_arity(irn);
assert(n == get_irn_n_edges(irn) && "perm's in and out numbers different");
- reg_class = arch_get_irn_register(arch_env, get_irn_n(irn, 0))->reg_class;
+ reg_class = arch_get_irn_register(get_irn_n(irn, 0))->reg_class;
pairs = alloca(n * sizeof(pairs[0]));
/* build the list of register pairs (in, out) */
pn = get_Proj_proj(pairs[i].out_node);
pairs[i].in_node = get_irn_n(irn, pn);
- pairs[i].in_reg = arch_get_irn_register(arch_env, pairs[i].in_node);
- pairs[i].out_reg = arch_get_irn_register(arch_env, pairs[i].out_node);
+ pairs[i].in_reg = arch_get_irn_register(pairs[i].in_node);
+ pairs[i].out_reg = arch_get_irn_register(pairs[i].out_node);
pairs[i].checked = 0;
i++;
real_size = n - get_n_checked_pairs(pairs, n);
- be_do_stat_perm(reg_class->name, reg_class->n_regs, irn, block, n, real_size);
-
/* check for cycles and chains */
while (get_n_checked_pairs(pairs, n) < n) {
+ perm_cycle_t *cycle;
+
i = n_ops = 0;
/* go to the first not-checked pair */
while (pairs[i].checked) i++;
- cycle = xcalloc(1, sizeof(*cycle));
+ cycle = XMALLOCZ(perm_cycle_t);
cycle = get_perm_cycle(cycle, pairs, n, i);
DB((mod, LEVEL_1, "%+F: following %s created:\n ", irn, cycle->type == PERM_CHAIN ? "chain" : "cycle"));
set_Proj_pred(res1, cpyxchg);
set_Proj_proj(res1, 1);
- arch_set_irn_register(arch_env, res2, cycle->elems[i + 1]);
- arch_set_irn_register(arch_env, res1, cycle->elems[i]);
+ arch_set_irn_register(res2, cycle->elems[i + 1]);
+ arch_set_irn_register(res1, cycle->elems[i]);
/* insert the copy/exchange node in schedule after the magic schedule node (see above) */
sched_add_after(sched_point, cpyxchg);
irn, arg1, cycle->elems[i]->name, res2, cycle->elems[i + 1]->name));
cpyxchg = be_new_Copy(reg_class, irg, block, arg1);
- arch_set_irn_register(arch_env, cpyxchg, cycle->elems[i + 1]);
+ arch_set_irn_register(cpyxchg, cycle->elems[i + 1]);
n_ops++;
/* exchange copy node and proj */
}
}
- be_do_stat_permcycle(reg_class->name, irn, block, cycle->type == PERM_CHAIN, cycle->n_elems, n_ops);
-
free((void *) cycle->elems);
free(cycle);
}
return irn;
}
-static ir_node *find_copy(constraint_env_t *env, ir_node *irn, ir_node *op) {
- const arch_env_t *arch_env = be_get_birg_arch_env(env->birg);
- ir_node *block = get_nodes_block(irn);
- ir_node *cur_node;
+static ir_node *find_copy(ir_node *irn, ir_node *op)
+{
+ ir_node *block = get_nodes_block(irn);
+ ir_node *cur_node;
for (cur_node = sched_prev(irn);
! is_Block(cur_node) && be_is_Copy(cur_node) && get_nodes_block(cur_node) == block;
cur_node = sched_prev(cur_node))
{
- if (be_get_Copy_op(cur_node) == op && arch_irn_is(arch_env, cur_node, dont_spill))
+ if (be_get_Copy_op(cur_node) == op && arch_irn_is(cur_node, dont_spill))
return cur_node;
}
be_irg_t *birg = env->birg;
ir_graph *irg = be_get_birg_irg(birg);
pset *op_set = env->op_set;
- const arch_env_t *arch_env = be_get_birg_arch_env(birg);
ir_node *block = get_nodes_block(irn);
- const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, other_different, -1);
+ const arch_register_class_t *cls = arch_get_irn_reg_class(other_different, -1);
ir_node *in[2], *keep, *cpy;
op_copy_assoc_t key, *entry;
DEBUG_ONLY(firm_dbg_module_t *mod = env->dbg;)
- if (arch_irn_is(arch_env, other_different, ignore) || ! mode_is_datab(get_irn_mode(other_different))) {
+ if (arch_irn_is(other_different, ignore) ||
+ !mode_is_datab(get_irn_mode(other_different))) {
DBG((mod, LEVEL_1, "ignore constraint for %+F because other_irn is ignore or not a datab node\n", irn));
return;
}
/* The copy is optimized later if not needed */
/* check if already exists such a copy in the schedule immediately before */
- cpy = find_copy(env, belower_skip_proj(irn), other_different);
+ cpy = find_copy(belower_skip_proj(irn), other_different);
if (! cpy) {
cpy = be_new_Copy(cls, irg, block, other_different);
be_node_set_flags(cpy, BE_OUT_POS(0), arch_irn_flags_dont_spill);
* then to assure the constraint.
*/
static void assure_different_constraints(ir_node *irn, constraint_env_t *env) {
- const arch_register_req_t *req;
- const arch_env_t *arch_env = be_get_birg_arch_env(env->birg);
-
- req = arch_get_register_req(arch_env, irn, -1);
+ ir_node *skipped_irn = belower_skip_proj(irn);
+ const arch_register_req_t *req = arch_get_register_req(irn, -1);
if (arch_register_req_is(req, must_be_different)) {
const unsigned other = req->other_different;
* We can safely ignore a should_be_same x must_be_different y
* IFF both inputs are equal!
*/
- if (get_irn_n(irn, idx_other) == get_irn_n(irn, idx_same)) {
+ if (get_irn_n(skipped_irn, idx_other) == get_irn_n(skipped_irn, idx_same)) {
return;
}
}
}
for (i = 0; 1U << i <= other; ++i) {
if (other & (1U << i)) {
- ir_node *different_from = get_irn_n(belower_skip_proj(irn), i);
+ ir_node *different_from = get_irn_n(skipped_irn, i);
gen_assure_different_pattern(irn, different_from, env);
}
}
*/
void assure_constraints(be_irg_t *birg) {
ir_graph *irg = be_get_birg_irg(birg);
- const arch_env_t *arch_env = be_get_birg_arch_env(birg);
constraint_env_t cenv;
op_copy_assoc_t *entry;
ir_node **nodes;
FIRM_DBG_REGISTER(firm_dbg_module_t *mod, "firm.be.lower.constr");
- be_assure_dom_front(birg);
-
DEBUG_ONLY(cenv.dbg = mod;)
cenv.birg = birg;
cenv.op_set = new_pset(cmp_op_copy_assoc, 16);
ir_node *keep;
int n = get_irn_arity(cp);
- keep = be_new_Keep(arch_get_irn_reg_class(arch_env, cp, -1),
+ keep = be_new_Keep(arch_get_irn_reg_class(cp, -1),
irg, get_nodes_block(cp), n, get_irn_in(cp) + 1);
sched_add_before(cp, keep);
*/
static int push_through_perm(ir_node *perm, void *data)
{
- lower_env_t *env = data;
- const arch_env_t *aenv = env->arch_env;
+ lower_env_t *env = data;
ir_graph *irg = get_irn_irg(perm);
ir_node *bl = get_nodes_block(perm);
bitset_t *moved = bitset_alloca(arity);
int n_moved;
int new_size;
- ir_node *frontier = sched_first(bl);
+ ir_node *frontier = bl;
FIRM_DBG_REGISTER(firm_dbg_module_t *mod, "firm.be.lower.permmove");
int i, n;
const ir_edge_t *edge;
- ir_node *last_proj = NULL, *irn;
+ ir_node *one_proj = NULL, *irn;
const arch_register_class_t *cls = NULL;
DBG((mod, LEVEL_1, "perm move %+F irg %+F\n", perm, irg));
- /* get some proj and find out the register class of the proj. */
- foreach_out_edge (perm, edge) {
- last_proj = get_edge_src_irn(edge);
- cls = arch_get_irn_reg_class(aenv, last_proj, -1);
- assert(is_Proj(last_proj));
- break;
- }
+ /* get some Proj and find out the register class of that Proj. */
+ edge = get_irn_out_edge_first_kind(perm, EDGE_KIND_NORMAL);
+ one_proj = get_edge_src_irn(edge);
+ assert(is_Proj(one_proj));
+ cls = arch_get_irn_reg_class(one_proj, -1);
- /* find the point in the schedule after which the
+ /* Find the point in the schedule after which the
* potentially movable nodes must be defined.
- * A perm will only be pushed up to first instruction
- * which lets an operand of itself die. */
-
+ * A Perm will only be pushed up to first instruction
+ * which lets an operand of itself die.
+ * If we would allow to move the Perm above this instruction,
+ * the former dead operand would be live now at the point of
+ * the Perm, increasing the register pressure by one.
+ */
sched_foreach_reverse_from (sched_prev(perm), irn) {
- for(i = get_irn_arity(irn) - 1; i >= 0; --i) {
+ for (i = get_irn_arity(irn) - 1; i >= 0; --i) {
ir_node *op = get_irn_n(irn, i);
- if(arch_irn_consider_in_reg_alloc(aenv, cls, op)
- && !values_interfere(env->birg, op, last_proj)) {
- frontier = sched_next(irn);
+ if (arch_irn_consider_in_reg_alloc(cls, op) &&
+ !values_interfere(env->birg, op, one_proj)) {
+ frontier = irn;
goto found_front;
}
}
int input = -1;
ir_node *proj;
+ /* search if node is a INPUT of Perm */
foreach_out_edge(perm, edge) {
ir_node *out = get_edge_src_irn(edge);
int pn = get_Proj_proj(out);
ir_node *in = get_irn_n(perm, pn);
- if(node == in) {
+ if (node == in) {
proj = out;
input = pn;
break;
break;
if(!sched_comes_after(frontier, node))
break;
- if(arch_irn_is(aenv, node, modify_flags))
+ if (arch_irn_is(node, modify_flags))
break;
if(is_Proj(node)) {
- req = arch_get_register_req(aenv, get_Proj_pred(node),
+ req = arch_get_register_req(get_Proj_pred(node),
-1 - get_Proj_proj(node));
} else {
- req = arch_get_register_req(aenv, node, -1);
+ req = arch_get_register_req(node, -1);
}
if(req->type != arch_register_req_type_normal)
break;
for(i = get_irn_arity(node) - 1; i >= 0; --i) {
ir_node *opop = get_irn_n(node, i);
- if (arch_irn_consider_in_reg_alloc(aenv, cls, opop)) {
+ if (arch_irn_consider_in_reg_alloc(cls, opop)) {
break;
}
}
sched_add_after(perm, node);
/* give it the proj's register */
- arch_set_irn_register(aenv, node, arch_get_irn_register(aenv, proj));
+ arch_set_irn_register(node, arch_get_irn_register(proj));
/* reroute all users of the proj to the moved node. */
edges_reroute(proj, node, irg);
lower_env_t env;
ir_graph *irg = be_get_birg_irg(birg);
- env.birg = birg;
- env.arch_env = be_get_birg_arch_env(birg);
- env.do_copy = do_copy;
+ env.birg = birg;
+ env.do_copy = do_copy;
FIRM_DBG_REGISTER(env.dbg_module, "firm.be.lower");
/* we will need interference */