DBG((dbg, LEVEL_2, "Applying solution...\n"));
#ifdef DO_STAT
- curr_vals[I_ILP_ITER] += lpp_get_iter_cnt(pi->curr_lp);
- curr_vals[I_ILP_TIME] += lpp_get_sol_time(pi->curr_lp);
+ copystat_add_ilp_time(lpp_get_sol_time(pi->curr_lp));
+ copystat_add_ilp_iter(lpp_get_iter_cnt(pi->curr_lp));
#endif
sol = xmalloc((pi->last_x_var+1) * sizeof(*sol));
assert(is_curr_reg_class(arg) && "Argument not in same register class.");
if (arg == root)
continue;
+ /* TODO or arg live at root.*/
if (nodes_interfere(co->chordal_env, root, arg)) {
unit->inevitable_costs += co->get_costs(root, arg, i);
continue;
return 1;
}
+int co_get_max_copy_costs(const copy_opt_t *co) {
+ int i, res = 0;
+ unit_t *curr;
+
+ list_for_each_entry(unit_t, curr, &co->units, units) {
+ res += curr->inevitable_costs;
+ for (i=1; i<curr->node_count; ++i)
+ res += curr->costs[i];
+ }
+ return res;
+}
+
+int co_get_inevit_copy_costs(const copy_opt_t *co) {
+ int res = 0;
+ unit_t *curr;
+
+ list_for_each_entry(unit_t, curr, &co->units, units)
+ res += curr->inevitable_costs;
+ return res;
+}
+
int co_get_copy_costs(const copy_opt_t *co) {
int i, res = 0;
unit_t *curr;
*/
int get_costs_all_one(ir_node *root, ir_node* arg, int pos);
+/**
+ * Returns the maximal costs possible, i.e. the costs if all
+ * pairs would be assigned different registers.
+ */
+int co_get_max_copy_costs(const copy_opt_t *co);
+
+/**
+ * Returns the inevitable costs, i.e. the costs of
+ * all copy pairs which interfere.
+ */
+int co_get_inevit_copy_costs(const copy_opt_t *co);
+
/**
* Returns the current costs the copies are causing.
* The result includes inevitable costs and the costs
copy_opt_t *co;
int lb, copy_costs;
- /* BETTER: You can remove this if you replace all `grep get_irn_out *.c`*/
+ /* BETTER: You can remove this if you replace all
+ * `grep get_irn_out *.c` by the irouts.h module.*/
compute_outs(chordal_env->session_env->irg);
co = new_copy_opt(chordal_env, get_costs_loop_depth);
#ifdef DO_STAT
lb = co_get_lower_bound(co);
copy_costs = co_get_copy_costs(co);
- curr_vals[I_COPIES_INIT] += copy_costs;
+ copystat_add_max_costs(co_get_max_copy_costs(co));
+ copystat_add_inevit_costs(co_get_inevit_copy_costs(co));
+ copystat_add_init_costs(copy_costs);
DBG((dbg, LEVEL_1, "Init costs: %3d <= %3d\n", lb, copy_costs));
#endif
co_heur_opt(co);
#ifdef DO_STAT
copy_costs = co_get_copy_costs(co);
- curr_vals[I_COPIES_HEUR] += copy_costs;
+ copystat_add_heur_costs(copy_costs);
DBG((dbg, LEVEL_1, "Heur costs: %3d <= %3d\n", lb, copy_costs));
#endif
#endif
assert(copy_costs>=lb && "At least one computation of these two is boooogy");
if (copy_costs > lb) {
co_ilp_opt(co);
- be_ra_chordal_check(chordal_env);
}
#ifdef DO_STAT
copy_costs = co_get_copy_costs(co);
assert(copy_costs>=lb && "At least one computation of these two is boooogy");
- curr_vals[I_COPIES_OPT] += copy_costs;
+ copystat_add_opt_costs(copy_costs);
DBG((dbg, LEVEL_1, "Opt costs: %3d <= %3d\n", lb, copy_costs));
#endif
#endif
#define DEBUG_LVL 0 //SET_LEVEL_1
static firm_dbg_module_t *dbg = NULL;
+#define MAX_ARITY 10
+#define MAX_CLS_SIZE 10
+#define MAX_CLS_PHIS 10
+#define MAX_PHASE 2
+
+/**
+ * For an explanation of these values see the code of copystat_dump_pretty
+ */
+enum vals_t {
+ I_ALL_NODES = 0,
+ I_BLOCKS,
+
+ /* phi nodes */
+ I_PHI_CNT, /* number of phi nodes */
+ I_PHI_ARG_CNT, /* number of arguments of phis */
+ I_PHI_ARG_SELF, /* number of arguments of phis being the phi itself */
+ I_PHI_ARG_CONST, /* number of arguments of phis being consts */
+ I_PHI_ARG_PRED, /* ... being defined in a cf-pred */
+ I_PHI_ARG_GLOB, /* ... being defined elsewhere */
+ I_PHI_ARITY_S,
+ I_PHI_ARITY_E = I_PHI_ARITY_S+MAX_ARITY,
+
+ /* copy nodes */
+ I_CPY_CNT, /* number of copynodes */
+
+ /* phi classes */
+ I_CLS_CNT, /* number of phi classes */
+ I_CLS_IF_FREE, /* number of pc having no interference */
+ I_CLS_IF_MAX, /* number of possible interferences in all classes */
+ I_CLS_IF_CNT, /* number of actual interferences in all classes */
+ I_CLS_SIZE_S,
+ I_CLS_SIZE_E = I_CLS_SIZE_S+MAX_CLS_SIZE,
+ I_CLS_PHIS_S,
+ I_CLS_PHIS_E = I_CLS_PHIS_S+MAX_CLS_PHIS,
+
+ /* ilp values */
+ I_ILP_TIME, /* !external set! solving time in seconds */
+ I_ILP_ITER, /* !external set! number of simplex iterations */
+
+ /* copy instructions */
+ I_COPIES_MAX, /* !external set! max possible costs of copies*/
+ I_COPIES_INIT, /* !external set! number of copies in initial allocation */
+ I_COPIES_HEUR, /* !external set! number of copies after heuristic */
+ I_COPIES_OPT, /* !external set! number of copies after ilp */
+ I_COPIES_IF, /* number of copies inevitable due to root-arg-interf */
+
+ ASIZE
+};
+
+/**
+ * Holds current values. Values are added till next copystat_reset
+ */
+int curr_vals[ASIZE];
+
static pset *all_phi_nodes;
static pset *all_phi_classes;
static pset *all_copy_nodes;
/* type of argument {self, const, pred, glob} */
for (i = 0; i < arity; i++) {
ir_node *block_of_arg, *block_ith_pred;
- ir_node *arg = get_irn_n(phi, i);
-
- if (phi != arg) {
- curr_vals[I_COPIES_MAX]++; /* if arg!=phi this is a possible copy */
- if (nodes_interfere(chordal_env, phi, arg)) {
- DBG((dbg, LEVEL_1, "%e -- In Block %N: %n %N %n %N\n",
- get_irg_entity(chordal_env->session_env->irg), get_nodes_block(phi), phi, phi, arg, arg));
- curr_vals[I_COPIES_IF]++;
- }
- }
+ ir_node *cfg_node, *arg = get_irn_n(phi, i);
if (arg == phi) {
curr_vals[I_PHI_ARG_SELF]++;
continue;
}
- block_of_arg = get_Block_cfgpred_block(get_nodes_block(phi), i);
- block_ith_pred = get_nodes_block(get_irn_n(get_nodes_block(phi), i));
+ block_of_arg = get_nodes_block(arg);
+
+ /* get the pred block skipping blocks on critical edges */
+ cfg_node = get_irn_n(get_nodes_block(phi), i);
+ block_ith_pred = get_nodes_block(cfg_node);
+ if (get_irn_opcode(cfg_node) == iro_Jmp && get_irn_arity(block_ith_pred) == 1) {
+ /* Then cfg_node_block has exactly 1 pred and 1 succ block,
+ * thus it must have been inserted during remove_critical_edges */
+ block_ith_pred = get_Block_cfgpred_block(block_ith_pred, 0);
+ }
+
if (block_of_arg == block_ith_pred) {
curr_vals[I_PHI_ARG_PRED]++;
continue;
}
}
+void copystat_add_max_costs(int costs) {
+ curr_vals[I_COPIES_MAX] += costs;
+}
+void copystat_add_inevit_costs(int costs) {
+ curr_vals[I_COPIES_IF] += costs;
+}
+void copystat_add_init_costs(int costs) {
+ curr_vals[I_COPIES_INIT] += costs;
+}
+void copystat_add_heur_costs(int costs) {
+ curr_vals[I_COPIES_HEUR] += costs;
+}
+void copystat_add_opt_costs(int costs) {
+ curr_vals[I_COPIES_OPT] += costs;
+}
+void copystat_add_ilp_time(int time) {
+ curr_vals[I_ILP_TIME] += time;
+}
+void copystat_add_ilp_iter(int iters) {
+ curr_vals[I_ILP_ITER] += iters;
+}
+
void copystat_dump(ir_graph *irg) {
int i;
char buf[1024];
#define _BECOPYSTAT_H
#define DO_STAT
+
#ifdef DO_STAT
#include "irgraph.h"
-
-#define MAX_ARITY 10
-#define MAX_CLS_SIZE 10
-#define MAX_CLS_PHIS 10
-#define MAX_PHASE 2
-
-/**
- * For an explanation of these values see the code of copystat_dump_pretty
- */
-enum vals_t {
- I_ALL_NODES = 0,
- I_BLOCKS,
-
- /* phi nodes */
- I_PHI_CNT, /* number of phi nodes */
- I_PHI_ARG_CNT, /* number of arguments of phis */
- I_PHI_ARG_SELF, /* number of arguments of phis being the phi itself */
- I_PHI_ARG_CONST, /* number of arguments of phis being consts */
- I_PHI_ARG_PRED, /* ... being defined in a cf-pred */
- I_PHI_ARG_GLOB, /* ... being defined elsewhere */
- I_PHI_ARITY_S,
- I_PHI_ARITY_E = I_PHI_ARITY_S+MAX_ARITY,
-
- /* copy nodes */
- I_CPY_CNT, /* number of copynodes */
-
- /* phi classes */
- I_CLS_CNT, /* number of phi classes */
- I_CLS_IF_FREE, /* number of pc having no interference */
- I_CLS_IF_MAX, /* number of possible interferences in all classes */
- I_CLS_IF_CNT, /* number of actual interferences in all classes */
- I_CLS_SIZE_S,
- I_CLS_SIZE_E = I_CLS_SIZE_S+MAX_CLS_SIZE,
- I_CLS_PHIS_S,
- I_CLS_PHIS_E = I_CLS_PHIS_S+MAX_CLS_PHIS,
-
- /* ilp values */
- I_ILP_TIME, /* !external set! solving time in seconds */
- I_ILP_ITER, /* !external set! number of simplex iterations */
-
- /* copy instructions */
- I_COPIES_MAX, /* max number of copies possible */
- I_COPIES_INIT, /* !external set! number of copies in initial allocation */
- I_COPIES_HEUR, /* !external set! number of copies after heuristic */
- I_COPIES_OPT, /* !external set! number of copies after ilp */
- I_COPIES_IF, /* number of copies inevitable due to root-arg-interf */
-
- ASIZE
-};
-
-/**
- * Holds current values. Values are added till next copystat_reset
- */
-int curr_vals[ASIZE];
+#include "bearch.h"
+#include "bechordal_t.h"
void copystat_init(void);
void copystat_reset(void);
void copystat_collect_irg(ir_graph *irg, arch_env_t *arch_env);
void copystat_collect_cls(be_chordal_env_t *chordal_env);
+void copystat_add_max_costs(int costs);
+void copystat_add_inevit_costs(int costs);
+void copystat_add_init_costs(int costs);
+void copystat_add_heur_costs(int costs);
+void copystat_add_opt_costs(int costs);
+void copystat_add_ilp_time(int time);
+void copystat_add_ilp_iter(int iters);
void copystat_dump(ir_graph *irg);
void copystat_dump_pretty(ir_graph *irg);
#define copystat_reset();
#define copystat_collect_irg(irg, arch_env);
#define copystat_collect_cls(env);
+#define copystat_add_max_costs(costs);
+#define copystat_add_inevit_costs(costs);
+#define copystat_add_init_costs(costs);
+#define copystat_add_heur_costs(costs);
+#define copystat_add_opt_costs(costs);
+#define copystat_add_ilp_time(int time);
+#define copystat_add_ilp_iter(int iters);
#define copystat_dump(irg);
#define copystat_dump(irg);
#define copystat_dump_pretty(irg);