X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeilpsched.c;h=a6a3eb42fb8ab9b7322a8b30e1296cf13a3bc7a4;hb=205396c4f4f5abe7abd6dc2350c8c398a7623afc;hp=04f22f09ecac87d6307caafaec44e5b5b8e0eea0;hpb=9462414965bcf01e5661f4e3dafb6e0052e348f3;p=libfirm diff --git a/ir/be/beilpsched.c b/ir/be/beilpsched.c index 04f22f09e..a6a3eb42f 100644 --- a/ir/be/beilpsched.c +++ b/ir/be/beilpsched.c @@ -3,6 +3,7 @@ * An ILP scheduler based on * "ILP-based Instruction Scheduling for IA-64" * by Daniel Kaestner and Sebastian Winkel + * extended with register pressure constraints by Christian Wuerdig * * @date 22.10.2005 * @author Christian Wuerdig @@ -30,24 +31,27 @@ #include "debug.h" #include "irtools.h" #include "irdump.h" +#include "irprintf.h" #include "plist.h" +#include "irprintf.h" #include #include -#ifdef WITH_LIBCORE #include #include #include -#endif /* WITH_LIBCORE */ #include "be.h" #include "benode_t.h" #include "besched_t.h" #include "beilpsched.h" +#include "beutil.h" +#include "bestat.h" +#include "beirg_t.h" typedef struct _ilpsched_options_t { - unsigned limit_dead; + unsigned regpress; unsigned time_limit; char log_file[1024]; } ilpsched_options_t; @@ -63,10 +67,18 @@ typedef struct _unit_type_info_t { typedef struct _ilp_var_types_t { int *x; /* x_{nt}^k variables */ int *a; /* a_{nt}^k variables */ - int *d; /* d_{nt}^k variables */ int *y; /* y_{nt}^k variables */ } ilp_var_types_t; +/** + * Holds alive variables for a node live-in to a block. + */ +typedef struct _ilp_livein_node_t { + ir_node *irn; + unsigned max_alive_steps; + int *a; +} ilp_livein_node_t; + /* attributes for a node */ typedef struct _ilpsched_node_attr_t { unsigned asap; /**< The ASAP scheduling control step */ @@ -83,7 +95,7 @@ typedef struct _ilpsched_node_attr_t { unsigned is_dummy_node : 1; /**< this node is assigned to DUMMY unit */ bitset_t *transitive_block_nodes; /**< Set of transitive block nodes (predecessors for ASAP, successors for ALAP */ - unsigned n_unit_types; /**< number of allowed execution unit types */ + unsigned n_unit_types; /**< number of allowed execution unit types */ unit_type_info_t *type_info; /**< list of allowed execution unit types */ ilp_var_types_t ilp_vars; /**< the different ILP variables */ } ilpsched_node_attr_t; @@ -95,6 +107,7 @@ typedef struct _ilpsched_block_attr_t { unsigned max_steps; /**< Upper bound for block execution */ plist_t *root_nodes; /**< A list of nodes having no user in current block */ ir_node *head_ilp_nodes; /**< A linked list of nodes which will contribute to ILP */ + pset *livein_nodes; /**< A set of nodes which are live-in to this block */ } ilpsched_block_attr_t; typedef union _ilpsched_attr_ { @@ -110,7 +123,7 @@ typedef struct { /* The ILP scheduling environment */ typedef struct { - phase_t ph; /**< The phase */ + ir_phase ph; /**< The phase */ ir_graph *irg; /**< The current irg */ heights_t *height; /**< The heights object of the irg */ void *irg_env; /**< An environment for the irg scheduling, provided by the backend */ @@ -120,6 +133,8 @@ typedef struct { const be_main_env_t *main_env; const be_machine_t *cpu; /**< the current abstract machine */ ilpsched_options_t *opts; /**< the ilp options for current irg */ + const be_irg_t *birg; /**< The birg object */ + be_options_t *be_opts; /**< backend options */ const ilp_sched_selector_t *sel; /**< The ILP sched selector provided by the backend */ DEBUG_ONLY(firm_dbg_module_t *dbg); } be_ilpsched_env_t; @@ -130,9 +145,6 @@ typedef struct { #define get_ilpsched_block_attr(block) (&(block)->attr.block_attr) #define get_ilpsched_node_attr(node) (&(node)->attr.node_attr) -/* iterate over a list of ir_nodes linked by link field */ -#define foreach_linked_irns(head, iter) for ((iter) = (head); (iter); (iter) = get_irn_link((iter))) - /* check if node is considered for ILP scheduling */ #define consider_for_sched(isa, irn) \ (! (is_Block(irn) || \ @@ -160,32 +172,24 @@ typedef struct { /* check if a double value is within an epsilon environment of 0 */ #define LPP_VALUE_IS_0(dbl) (fabs((dbl)) <= 1e-10) -#ifdef WITH_LIBCORE - #define ilp_timer_push(t) lc_timer_push((t)) - #define ilp_timer_pop() lc_timer_pop() - #define ilp_timer_elapsed_usec(t) lc_timer_elapsed_usec((t)) -#else /* WITH_LIBCORE */ - #define ilp_timer_push(t) - #define ilp_timer_pop() - #define ilp_timer_elapsed_usec(t) 0.0 -#endif /* WITH_LIBCORE */ +#define ilp_timer_push(t) lc_timer_push((t)) +#define ilp_timer_pop() lc_timer_pop() +#define ilp_timer_elapsed_usec(t) lc_timer_elapsed_usec((t)) /* option variable */ static ilpsched_options_t ilp_opts = { - 70, /* if we have more than 70 nodes: use alive nodes constraint */ + 1, /* default is with register pressure constraints */ 300, /* 300 sec per block time limit */ "" /* no log file */ }; -#ifdef WITH_LIBCORE /* ILP options */ static const lc_opt_table_entry_t ilpsched_option_table[] = { - LC_OPT_ENT_INT("limit_dead", "Upto how many nodes the dead node constraint should be used", &ilp_opts.limit_dead), + LC_OPT_ENT_BOOL("regpress", "Use register pressure constraints", &ilp_opts.regpress), LC_OPT_ENT_INT("time_limit", "ILP time limit per block", &ilp_opts.time_limit), LC_OPT_ENT_STR("lpp_log", "LPP logfile (stderr and stdout are supported)", ilp_opts.log_file, sizeof(ilp_opts.log_file)), { NULL } }; -#endif /* WITH_LIBCORE */ /* We need this global variable as we compare nodes dependent on heights, @@ -218,6 +222,12 @@ static INLINE int fixed_latency(const ilp_sched_selector_t *sel, ir_node *irn, v return lat; } +static int cmp_live_in_nodes(const void *a, const void *b) { + const ilp_livein_node_t *n1 = a; + const ilp_livein_node_t *n2 = b; + + return n1->irn != n2->irn; +} /** * Compare scheduling time steps of two be_ilpsched_irn's. @@ -250,7 +260,7 @@ static int cmp_ilpsched_irn(const void *a, const void *b) { /** * In case there is no phase information for irn, initialize it. */ -static void *init_ilpsched_irn(phase_t *ph, ir_node *irn, void *old) { +static void *init_ilpsched_irn(ir_phase *ph, ir_node *irn, void *old) { be_ilpsched_irn_t *res = old ? old : phase_alloc(ph, sizeof(res[0])); if (res == old) { @@ -287,6 +297,7 @@ static void *init_ilpsched_irn(phase_t *ph, ir_node *irn, void *old) { ba->block_last_idx = 0; ba->root_nodes = plist_new(); ba->head_ilp_nodes = NULL; + ba->livein_nodes = new_pset(cmp_live_in_nodes, 16); ba->max_steps = 0; } else { @@ -306,6 +317,7 @@ static void build_block_idx(ir_node *irn, void *walk_env) { ilpsched_node_attr_t *na; ilpsched_block_attr_t *ba; + set_irn_link(irn, NULL); if (! consider_for_sched(env->arch_env->isa, irn)) return; @@ -420,6 +432,9 @@ static void collect_alap_root_nodes(ir_node *irn, void *walk_env) { /* mark user visited by this node */ ua->consumer_idx = idx; } + else if (get_nodes_block(user) != block) { + n_consumer++; + } } } @@ -589,7 +604,7 @@ static void calculate_block_alap(ir_node *block, void *walk_env) { } /** - * We can free the list of root nodes here. + * Free list of root nodes and the set of live-in nodes. */ static void clear_unwanted_data(ir_node *block, void *walk_env) { be_ilpsched_env_t *env = walk_env; @@ -598,6 +613,8 @@ static void clear_unwanted_data(ir_node *block, void *walk_env) { plist_free(ba->root_nodes); ba->root_nodes = NULL; + del_pset(ba->livein_nodes); + ba->livein_nodes = NULL; } /** @@ -690,8 +707,11 @@ static void add_to_sched(be_ilpsched_env_t *env, ir_node *block, ir_node *irn, u foreach_out_edge(irn, edge) { ir_node *user = get_edge_src_irn(edge); - if (to_appear_in_schedule(user) || get_irn_mode(user) == mode_b) + if ((to_appear_in_schedule(user) || get_irn_mode(user) == mode_b) && + get_irn_n_edges(user) > 0) + { notified_sched_add_before(env, block, user, cycle); + } check_for_keeps(keeps, block, user); } @@ -750,6 +770,20 @@ static void apply_solution(be_ilpsched_env_t *env, lpp_t *lpp, ir_node *block) { cur_var = 0; found = 0; + if (! na->is_dummy_node) { + for (tp_idx = na->n_unit_types - 1; ! found && tp_idx >= 0; --tp_idx) { + for (t = na->asap - 1; ! found && t <= na->alap - 1; ++t) { + double cost = lpp_get_var_sol(lpp, na->ilp_vars.y[cur_var]); + + if (! LPP_VALUE_IS_0(cost)) { + DBG((env->dbg, LEVEL_3, "%+F has additional regpressure costs of %f\n", irn, cost)); + found = 1; + } + } + } + } + + found = 0; /* go over all variables of a node until the non-zero one is found */ for (tp_idx = na->n_unit_types - 1; ! found && tp_idx >= 0; --tp_idx) { for (t = na->asap - 1; ! found && t <= na->alap - 1; ++t) { @@ -759,7 +793,7 @@ static void apply_solution(be_ilpsched_env_t *env, lpp_t *lpp, ir_node *block) { if (! LPP_VALUE_IS_0(val)) { na->sched_point = t; ARR_APP1(be_ilpsched_irn_t *, sched_nodes, node); - DBG((env->dbg, LEVEL_1, "Schedpoint of %+F is %u at unit type %s\n", + DBG((env->dbg, LEVEL_2, "Schedpoint of %+F is %u at unit type %s\n", irn, t, na->type_info[tp_idx].tp->name)); found = 1; } @@ -845,20 +879,74 @@ static INLINE int is_valid_unit_type_for_node(const be_execution_unit_type_t *tp * ************************************************/ +static int be_ilpsched_set_type_info(be_ilpsched_env_t *env, ir_node *irn, struct obstack *obst) { + const be_execution_unit_t ***execunits = arch_isa_get_allowed_execution_units(env->arch_env->isa, irn); + unsigned n_unit_types = 0; + be_ilpsched_irn_t *node; + ilpsched_node_attr_t *na; + unsigned unit_idx, tp_idx; + + /* count number of available unit types for this node */ + for (n_unit_types = 0; execunits[n_unit_types]; ++n_unit_types) + /* just count */ ; + + node = get_ilpsched_irn(env, irn); + na = get_ilpsched_node_attr(node); + + if (! na->type_info) { + na->n_unit_types = n_unit_types; + na->type_info = NEW_ARR_D(unit_type_info_t, obst, n_unit_types); + + /* fill the type info array */ + for (tp_idx = 0; tp_idx < n_unit_types; ++tp_idx) { + for (unit_idx = 0; execunits[tp_idx][unit_idx]; ++unit_idx) { + /* beware: we also count number of available units here */ + if (be_machine_is_dummy_unit(execunits[tp_idx][unit_idx])) + na->is_dummy_node = 1; + } + + na->type_info[tp_idx].tp = execunits[tp_idx][0]->tp; + na->type_info[tp_idx].n_units = unit_idx; + } + } + + return n_unit_types; +} + +/** + * Returns the largest alap time of a user of @p irn. + * The user must be in block @p block. + */ +static unsigned be_ilpsched_get_max_alap_user(be_ilpsched_env_t *env, ir_node *irn, ir_node *block) { + const ir_edge_t *edge; + unsigned max_alap = 0; + + foreach_out_edge(irn, edge) { + ir_node *user = get_edge_src_irn(edge); + + if (get_nodes_block(user) == block) { + be_ilpsched_irn_t *node = get_ilpsched_irn(env, user); + ilpsched_node_attr_t *na = get_ilpsched_node_attr(node); + + max_alap = MAX(max_alap, na->alap); + } + } + + assert(max_alap > 0); + return max_alap; +} + /** * Create the following variables: * - x_{nt}^k binary weigthed with: t * node n is scheduled at time step t to unit type k * ==>> These variables represent the schedule * - * - d_{nt}^k binary weighted with: t - * node n dies at time step t on unit type k * - a_{nt}^k binary weighted with num_nodes * node n is alive at time step t on unit type k * - * - y_{nt}^k binary weighted with: num_nodes^2 - * node n is scheduled at time step t to unit type k - * although all units of this type are occupied + * - y_{nt}^k continuous weighted with: num_nodes^2 + * register pressure over limit for unit type k * ==>> These variables represent the register pressure * */ @@ -866,42 +954,23 @@ static void create_variables(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn char buf[1024]; ir_node *irn; unsigned num_block_var, num_nodes; + ilp_livein_node_t *livein; ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); unsigned weigth_y = ba->n_interesting_nodes * ba->n_interesting_nodes; -#ifdef WITH_LIBCORE lc_timer_t *t_var = lc_timer_register("beilpsched_var", "create ilp variables"); -#endif /* WITH_LIBCORE */ ilp_timer_push(t_var); num_block_var = num_nodes = 0; foreach_linked_irns(ba->head_ilp_nodes, irn) { - const be_execution_unit_t ***execunits = arch_isa_get_allowed_execution_units(env->arch_env->isa, irn); - be_ilpsched_irn_t *node; - ilpsched_node_attr_t *na; - unsigned n_unit_types, tp_idx, unit_idx, n_var, cur_unit; - unsigned cur_var_ad, cur_var_x, cur_var_y, num_ad; - - /* count number of available unit types for this node */ - for (n_unit_types = 0; execunits[n_unit_types]; ++n_unit_types) - /* just count */ ; - - node = get_ilpsched_irn(env, irn); - na = get_ilpsched_node_attr(node); - - na->n_unit_types = n_unit_types; - na->type_info = NEW_ARR_D(unit_type_info_t, var_obst, n_unit_types); + be_ilpsched_irn_t *node; + ilpsched_node_attr_t *na; + unsigned n_unit_types, tp_idx, n_var, cur_unit; + unsigned cur_var_ad, cur_var_x, cur_var_y, num_ad; + int i; - /* fill the type info array */ - for (tp_idx = 0; tp_idx < n_unit_types; ++tp_idx) { - for (unit_idx = 0; execunits[tp_idx][unit_idx]; ++unit_idx) { - /* beware: we also count number of available units here */ - if (be_machine_is_dummy_unit(execunits[tp_idx][unit_idx])) - na->is_dummy_node = 1; - } - - na->type_info[tp_idx].tp = execunits[tp_idx][0]->tp; - na->type_info[tp_idx].n_units = unit_idx; - } + node = get_ilpsched_irn(env, irn); + na = get_ilpsched_node_attr(node); + n_unit_types = be_ilpsched_set_type_info(env, irn, var_obst); /* allocate space for ilp variables */ na->ilp_vars.x = NEW_ARR_D(int, var_obst, n_unit_types * VALID_SCHED_INTERVAL(na)); @@ -912,16 +981,9 @@ static void create_variables(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn na->ilp_vars.y = NEW_ARR_D(int, var_obst, n_unit_types * VALID_SCHED_INTERVAL(na)); memset(na->ilp_vars.y, -1, ARR_LEN(na->ilp_vars.y) * sizeof(na->ilp_vars.y[0])); - num_ad = ba->max_steps - na->asap + 1; - - if (ba->n_interesting_nodes > env->opts->limit_dead) { - na->ilp_vars.a = NEW_ARR_D(int, var_obst, n_unit_types * num_ad); - memset(na->ilp_vars.a, -1, ARR_LEN(na->ilp_vars.a) * sizeof(na->ilp_vars.a[0])); - } - else { - na->ilp_vars.d = NEW_ARR_D(int, var_obst, n_unit_types * num_ad); - memset(na->ilp_vars.d, -1, ARR_LEN(na->ilp_vars.d) * sizeof(na->ilp_vars.d[0])); - } + num_ad = ba->max_steps - na->asap + 1; + na->ilp_vars.a = NEW_ARR_D(int, var_obst, n_unit_types * num_ad); + memset(na->ilp_vars.a, -1, ARR_LEN(na->ilp_vars.a) * sizeof(na->ilp_vars.a[0])); } DBG((env->dbg, LEVEL_3, "\thandling %+F (asap %u, alap %u, unit types %u):\n", @@ -946,7 +1008,7 @@ static void create_variables(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn /* y_{nt}^k variables */ snprintf(buf, sizeof(buf), "y_n%u_%s_%u", get_irn_idx(irn), na->type_info[tp_idx].tp->name, t); - na->ilp_vars.y[cur_var_y++] = lpp_add_var(lpp, buf, lpp_binary, (double)(weigth_y)); + na->ilp_vars.y[cur_var_y++] = lpp_add_var(lpp, buf, lpp_continous, (double)(weigth_y)); DBG((env->dbg, LEVEL_4, "\t\tcreated ILP variable %s\n", buf)); /* variable counter */ @@ -959,18 +1021,10 @@ static void create_variables(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn if (! na->is_dummy_node) { for (t = na->asap - 1; t <= ba->max_steps; ++t) { - if (ba->n_interesting_nodes > env->opts->limit_dead) { - /* a_{nt}^k variables */ - snprintf(buf, sizeof(buf), "a_n%u_%s_%u", - get_irn_idx(irn), na->type_info[tp_idx].tp->name, t); - na->ilp_vars.a[cur_var_ad++] = lpp_add_var(lpp, buf, lpp_binary, (double)(ba->n_interesting_nodes)); - } - else { - /* d_{nt}^k variables */ - snprintf(buf, sizeof(buf), "d_n%u_%s_%u", - get_irn_idx(irn), na->type_info[tp_idx].tp->name, t); - na->ilp_vars.d[cur_var_ad++] = lpp_add_var(lpp, buf, lpp_binary, (double)(t + 1)); - } + /* a_{nt}^k variables */ + snprintf(buf, sizeof(buf), "a_n%u_%s_%u", + get_irn_idx(irn), na->type_info[tp_idx].tp->name, t); + na->ilp_vars.a[cur_var_ad++] = lpp_add_var(lpp, buf, lpp_binary, (double)(ba->n_interesting_nodes)); DBG((env->dbg, LEVEL_4, "\t\tcreated ILP variable %s\n", buf)); /* variable counter */ @@ -978,11 +1032,58 @@ static void create_variables(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn num_block_var++; } } + + /* collect live-in nodes */ + for (i = get_irn_arity(irn) - 1; i >= 0; --i) { + ir_node *pred = get_irn_n(irn, i); + + if (get_nodes_block(pred) != block_node->irn && consider_for_sched(env->arch_env->isa, pred)) { + be_ilpsched_set_type_info(env, pred, var_obst); + if (! na->is_dummy_node) { + ilp_livein_node_t *entry = obstack_alloc(var_obst, sizeof(*entry)); + entry->irn = pred; + entry->a = NULL; + pset_insert(ba->livein_nodes, entry, (unsigned)get_irn_idx(pred)); + } + } + } } DB((env->dbg, LEVEL_3, "%u variables created\n", n_var)); num_nodes++; } + + /* create alive variables a_{nt}^k for live-ins */ + foreach_pset(ba->livein_nodes, livein) { + be_ilpsched_irn_t *node; + ilpsched_node_attr_t *na; + unsigned tp_idx, var_idx; + ir_node *irn; + + irn = livein->irn; + node = get_ilpsched_irn(env, irn); + na = get_ilpsched_node_attr(node); + + livein->max_alive_steps = be_ilpsched_get_max_alap_user(env, irn, block_node->irn); + + livein->a = NEW_ARR_D(int, var_obst, na->n_unit_types * livein->max_alive_steps); + var_idx = 0; + + /* create variables */ + for (tp_idx = 0; tp_idx < na->n_unit_types; ++tp_idx) { + unsigned t; + + for (t = 0; t < livein->max_alive_steps; ++t) { + /* a_{nt}^k variables */ + snprintf(buf, sizeof(buf), "al_n%u_%s_%u", + get_irn_idx(irn), na->type_info[tp_idx].tp->name, t); + livein->a[var_idx++] = lpp_add_var(lpp, buf, lpp_binary, (double)(ba->n_interesting_nodes)); + DBG((env->dbg, LEVEL_4, "\t\tcreated ILP variable %s\n", buf)); + num_block_var++; + } + } + } + ilp_timer_pop(); DBG((env->dbg, LEVEL_1, "... %u variables for %u nodes created (%g sec)\n", num_block_var, num_nodes, ilp_timer_elapsed_usec(t_var) / 1000000.0)); @@ -998,6 +1099,33 @@ static void create_variables(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn * *******************************************************/ +/** + * Collect all operands and nodes @p irn depends on. + * If there is a Proj within the dependencies, all other Projs of the parent node are added as well. + */ +static nodeset *sta_collect_in_deps(ir_node *irn, nodeset *deps) { + int i; + + for (i = get_irn_ins_or_deps(irn) - 1; i >= 0; --i) { + ir_node *p = get_irn_in_or_dep(irn, i); + + if (is_Proj(p)) { + const ir_edge_t *edge; + + p = get_Proj_pred(p); + foreach_out_edge(p, edge) { + ir_node *src = get_edge_src_irn(edge); + nodeset_insert(deps, src); + } + } + else { + nodeset_insert(deps, p); + } + } + + return deps; +} + /** * Create following ILP constraints: * - the assignment constraints: @@ -1013,18 +1141,17 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env, ir_node *irn; ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); bitset_t *bs_block_irns = bitset_alloca(ba->block_last_idx); -#ifdef WITH_LIBCORE - lc_timer_t *t_cst_assign = lc_timer_register("beilpsched_cst_assign", "create assignment constraints"); - lc_timer_t *t_cst_dead = lc_timer_register("beilpsched_cst_assign_dead", "create dead node assignment constraints"); - lc_timer_t *t_cst_prec = lc_timer_register("beilpsched_cst_prec", "create precedence constraints"); -#endif /* WITH_LIBCORE */ + lc_timer_t *t_cst_assign = lc_timer_register("beilpsched_cst_assign", "create assignment constraints"); + lc_timer_t *t_cst_prec = lc_timer_register("beilpsched_cst_prec", "create precedence constraints"); num_cst_assign = num_cst_prec = num_cst_dead = 0; foreach_linked_irns(ba->head_ilp_nodes, irn) { - int cst, tp_idx, i; + int cst, tp_idx; unsigned cur_var; be_ilpsched_irn_t *node; ilpsched_node_attr_t *na; + ir_node *pred; + nodeset *deps = new_nodeset(16); node = get_ilpsched_irn(env, irn); na = get_ilpsched_node_attr(node); @@ -1040,17 +1167,6 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env, lpp_set_factor_fast_bulk(lpp, cst, na->ilp_vars.x, ARR_LEN(na->ilp_vars.x), 1.0); ilp_timer_pop(); - /* the dead node assignment constraint */ - if (! na->is_dummy_node && ba->n_interesting_nodes <= env->opts->limit_dead) { - ilp_timer_push(t_cst_dead); - snprintf(buf, sizeof(buf), "dead_node_assign_cst_n%u", get_irn_idx(irn)); - cst = lpp_add_cst_uniq(lpp, buf, lpp_less, 1.0); - DBG((env->dbg, LEVEL_2, "added constraint %s\n", buf)); - - lpp_set_factor_fast_bulk(lpp, cst, na->ilp_vars.d, ARR_LEN(na->ilp_vars.d), 1.0); - ilp_timer_pop(); - } - /* We have separate constraints for Projs and Keeps */ // ILP becomes infeasible ?!? // if (is_Proj(irn) || be_is_Keep(irn)) @@ -1059,13 +1175,15 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env, /* the precedence constraints */ ilp_timer_push(t_cst_prec); bs_block_irns = bitset_clear_all(bs_block_irns); - for (i = get_irn_ins_or_deps(irn) - 1; i >= 0; --i) { - ir_node *pred = skip_normal_Proj(env->arch_env->isa, get_irn_in_or_dep(irn, i)); + + deps = sta_collect_in_deps(irn, deps); + foreach_nodeset(deps, pred) { unsigned t_low, t_high, t; be_ilpsched_irn_t *pred_node; ilpsched_node_attr_t *pna; unsigned delay; + pred = skip_normal_Proj(env->arch_env->isa, pred); if (is_Phi(pred) || block_node->irn != get_nodes_block(pred) || is_NoMem(pred)) continue; @@ -1132,6 +1250,7 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env, DEL_ARR_F(tmp_var_idx); } } + del_nodeset(deps); ilp_timer_pop(); } DBG((env->dbg, LEVEL_1, "\t%u assignement constraints (%g sec)\n", @@ -1150,9 +1269,7 @@ static void create_ressource_constraints(be_ilpsched_env_t *env, lpp_t *lpp, be_ char buf[1024]; unsigned num_cst_resrc = 0; ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); -#ifdef WITH_LIBCORE lc_timer_t *t_cst_rsrc = lc_timer_register("beilpsched_cst_rsrc", "create resource constraints"); -#endif /* WITH_LIBCORE */ ilp_timer_push(t_cst_rsrc); for (glob_type_idx = env->cpu->n_unit_types - 1; glob_type_idx >= 0; --glob_type_idx) { @@ -1208,9 +1325,7 @@ static void create_bundle_constraints(be_ilpsched_env_t *env, lpp_t *lpp, be_ilp unsigned num_cst_bundle = 0; unsigned n_instr_max = env->cpu->bundle_size * env->cpu->bundels_per_cycle; ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); -#ifdef WITH_LIBCORE lc_timer_t *t_cst_bundle = lc_timer_register("beilpsched_cst_bundle", "create bundle constraints"); -#endif /* WITH_LIBCORE */ ilp_timer_push(t_cst_bundle); for (t = 0; t < ba->max_steps; ++t) { @@ -1258,101 +1373,15 @@ static void create_bundle_constraints(be_ilpsched_env_t *env, lpp_t *lpp, be_ilp } /** - * Create ILP dying nodes constraints: - * - set variable d_{nt}^k to 1 if nodes n dies at step t on unit k + * Create ILP alive nodes constraints: + * - set variable a_{nt}^k to 1 if nodes n is alive at step t on unit k */ -static void create_dying_nodes_constraint(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn_t *block_node) { - char buf[1024]; - unsigned t; - unsigned num_cst = 0; - ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); -#ifdef WITH_LIBCORE - lc_timer_t *t_cst = lc_timer_register("beilpsched_cst_dying_nodes", "create dying nodes constraints"); -#endif /* WITH_LIBCORE */ - - ilp_timer_push(t_cst); - /* check all time_steps */ - for (t = 0; t < ba->max_steps; ++t) { - ir_node *irn; - - /* for all nodes */ - foreach_linked_irns(ba->head_ilp_nodes, irn) { - be_ilpsched_irn_t *node = get_ilpsched_irn(env, irn); - ilpsched_node_attr_t *na = get_ilpsched_node_attr(node); - - /* if node has no consumer within current block, it cannot die here */ - /* we also ignore nodes assigned to dummy unit */ - if (ARR_LEN(na->block_consumer) < 1 || na->is_dummy_node) - continue; - - /* node can only die here if t at least asap(n) */ - if (t >= na->asap - 1) { - int node_tp_idx; - - /* for all unit types */ - for (node_tp_idx = na->n_unit_types - 1; node_tp_idx >= 0; --node_tp_idx) { - int tp_idx, i, cst; - int *tmp_var_idx = NEW_ARR_F(int, 0); - - snprintf(buf, sizeof(buf), "dying_node_cst_%u_n%u", t, get_irn_idx(irn)); - cst = lpp_add_cst_uniq(lpp, buf, lpp_less, (double)(na->n_consumer - 1)); - DBG((env->dbg, LEVEL_2, "added constraint %s\n", buf)); - num_cst++; - - /* number of consumer scheduled till t */ - for (i = ARR_LEN(na->block_consumer) - 1; i >= 0; --i) { - be_ilpsched_irn_t *cons = get_ilpsched_irn(env, na->block_consumer[i]); - ilpsched_node_attr_t *ca = get_ilpsched_node_attr(cons); - - for (tp_idx = ca->n_unit_types - 1; tp_idx >= 0; --tp_idx) { - unsigned tm; - - for (tm = ca->asap - 1; tm <= t && tm <= ca->alap - 1; ++tm) { - int idx = ILPVAR_IDX(ca, tp_idx, tm); - ARR_APP1(int, tmp_var_idx, ca->ilp_vars.x[idx]); - } - } - } - - /* could be that no consumer can be scheduled at this point */ - if (ARR_LEN(tmp_var_idx)) { - int idx; - unsigned tn; - - /* subtract possible prior kill points */ - for (tn = na->asap - 1; tn < t; ++tn) { - idx = ILPVAR_IDX_DEAD(ba, na, node_tp_idx, tn); - lpp_set_factor_fast(lpp, cst, na->ilp_vars.d[idx], -1.0); - } - - idx = ILPVAR_IDX_DEAD(ba, na, node_tp_idx, t); - lpp_set_factor_fast(lpp, cst, na->ilp_vars.d[idx], 0.0 - (double)(na->n_consumer)); - lpp_set_factor_fast_bulk(lpp, cst, tmp_var_idx, ARR_LEN(tmp_var_idx), 1.0); - } - - DEL_ARR_F(tmp_var_idx); - } - } - - } - } - ilp_timer_pop(); - DBG((env->dbg, LEVEL_1, "\t%u dying nodes constraints (%g sec)\n", - num_cst, ilp_timer_elapsed_usec(t_cst) / 1000000.0)); -} - -/** -* Create ILP alive nodes constraints: -* - set variable a_{nt}^k to 1 if nodes n is alive at step t on unit k -*/ static void create_alive_nodes_constraint(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn_t *block_node) { char buf[1024]; ir_node *irn; unsigned num_cst = 0; ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); -#ifdef WITH_LIBCORE lc_timer_t *t_cst = lc_timer_register("beilpsched_cst_alive_nodes", "create alive nodes constraints"); -#endif /* WITH_LIBCORE */ ilp_timer_push(t_cst); /* for each node */ @@ -1426,103 +1455,80 @@ static void create_alive_nodes_constraint(be_ilpsched_env_t *env, lpp_t *lpp, be } /** - * Create ILP pressure constraints, based on dead nodes: - * - add additional costs to objective function if a node is scheduled - * on a unit although all units of this type are currently occupied + * Create ILP alive nodes constraints for live-in nodes: + * - set variable a_{nt}^k to 1 if nodes n is alive at step t on unit k */ -static void create_pressure_dead_constraint(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn_t *block_node) { +static void create_alive_livein_nodes_constraint(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn_t *block_node) { char buf[1024]; - ir_node *cur_irn; + ilp_livein_node_t *livein; unsigned num_cst = 0; ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); -#ifdef WITH_LIBCORE - lc_timer_t *t_cst = lc_timer_register("beilpsched_cst_pressure", "create pressure constraints"); -#endif /* WITH_LIBCORE */ + lc_timer_t *t_cst = lc_timer_register("beilpsched_cst_alive_livein_nodes", "create alive livein nodes constraints"); ilp_timer_push(t_cst); - /* y_{nt}^k is set for each node and timestep and unit type */ - foreach_linked_irns(ba->head_ilp_nodes, cur_irn) { - unsigned cur_idx = get_irn_idx(cur_irn); - be_ilpsched_irn_t *cur_node = get_ilpsched_irn(env, cur_irn); - ilpsched_node_attr_t *cur_na = get_ilpsched_node_attr(cur_node); - int glob_type_idx; - - /* we ignore nodes assigned to DUMMY unit here */ - if (cur_na->is_dummy_node) - continue; - - /* for all types */ - for (glob_type_idx = env->cpu->n_unit_types - 1; glob_type_idx >= 0; --glob_type_idx) { - be_execution_unit_type_t *cur_tp = &env->cpu->unit_types[glob_type_idx]; - int cur_tp_idx; - unsigned t; - - /* BEWARE: the DUMMY unit types is not in CPU, so it's skipped automatically */ - - /* check if node can be executed on this unit type */ - cur_tp_idx = is_valid_unit_type_for_node(cur_tp, cur_node); - if (cur_tp_idx < 0) - continue; + /* for each node */ + foreach_pset(ba->livein_nodes, livein) { + ir_node *irn = livein->irn; + be_ilpsched_irn_t *node = get_ilpsched_irn(env, irn); + ilpsched_node_attr_t *na = get_ilpsched_node_attr(node); + unsigned t; - /* check all time_steps */ - for (t = cur_na->asap - 1; t <= cur_na->alap - 1; ++t) { - int cst, y_idx; - ir_node *irn; - int *tmp_idx_1 = NEW_ARR_F(int, 0); - int *tmp_idx_m1 = NEW_ARR_F(int, 0); + /* check check all time steps: 0 <= t < max_alive_steps */ + for (t = 0; t < livein->max_alive_steps; ++t) { + int node_tp_idx; - snprintf(buf, sizeof(buf), "pressure_cst_n%u_%u_%s", cur_idx, t, cur_tp->name); - cst = lpp_add_cst_uniq(lpp, buf, lpp_less, (double)(cur_tp->n_units - 1)); - DBG((env->dbg, LEVEL_2, "added constraint %s\n", buf)); - num_cst++; + /* for all unit types available for this node */ + for (node_tp_idx = na->n_unit_types - 1; node_tp_idx >= 0; --node_tp_idx) { + const ir_edge_t *edge; + unsigned idx; + int cst, num_block_user; + int *tmp_var_idx_m = NEW_ARR_F(int, 0); - /* - - accumulate all nodes scheduled on unit type k till t - - subtract all nodes died on unit type k till t - */ - foreach_linked_irns(ba->head_ilp_nodes, irn) { - be_ilpsched_irn_t *node = get_ilpsched_irn(env, irn); - ilpsched_node_attr_t *na = get_ilpsched_node_attr(node); - unsigned tn, tmax; + /* check the number of consumer scheduled so far */ + num_block_user = 0; + foreach_out_edge(irn, edge) { + ir_node *user = get_edge_src_irn(edge); + be_ilpsched_irn_t *cons; + ilpsched_node_attr_t *ca; int tp_idx; + unsigned tm, tm_max; - tmax = MIN(t, na->alap - 1); - tp_idx = is_valid_unit_type_for_node(cur_tp, node); - - /* current unit type is not suitable for current node */ - if (tp_idx < 0) + /* check only users within current block */ + if (get_nodes_block(user) != block_node->irn) continue; - for (tn = na->asap - 1; tn <= tmax; ++tn) { - int idx; - - /* node scheduled */ - idx = ILPVAR_IDX(na, tp_idx, tn); - ARR_APP1(int, tmp_idx_1, na->ilp_vars.x[idx]); + num_block_user++; + cons = get_ilpsched_irn(env, user); + ca = get_ilpsched_node_attr(cons); - /* node dead */ - idx = ILPVAR_IDX_DEAD(ba, na, tp_idx, tn); - ARR_APP1(int, tmp_idx_m1, na->ilp_vars.d[idx]); + tm_max = MIN(ca->alap - 1, t); + for (tp_idx = ca->n_unit_types - 1; tp_idx >= 0; --tp_idx) { + for (tm = ca->asap - 1; tm <= tm_max; ++tm) { + int idx = ILPVAR_IDX(ca, tp_idx, tm); + ARR_APP1(int, tmp_var_idx_m, ca->ilp_vars.x[idx]); + } } } - if (ARR_LEN(tmp_idx_1) > 0) - lpp_set_factor_fast_bulk(lpp, cst, tmp_idx_1, ARR_LEN(tmp_idx_1), 1.0); - - if (ARR_LEN(tmp_idx_m1) > 0) - lpp_set_factor_fast_bulk(lpp, cst, tmp_idx_m1, ARR_LEN(tmp_idx_m1), -1.0); + snprintf(buf, sizeof(buf), "alive_livein_node_cst_%u_n%u_%s", + t, get_irn_idx(irn), na->type_info[node_tp_idx].tp->name); + cst = lpp_add_cst_uniq(lpp, buf, lpp_greater, (double)num_block_user); + DBG((env->dbg, LEVEL_2, "added constraint %s\n", buf)); + num_cst++; - /* BEWARE: t is unsigned, so (double)(-t) won't work */ - y_idx = ILPVAR_IDX(cur_na, cur_tp_idx, t); - lpp_set_factor_fast(lpp, cst, cur_na->ilp_vars.y[y_idx], 0.0 - (double)(t)); + /* sum(scheduled users) */ + if (ARR_LEN(tmp_var_idx_m) > 0) + lpp_set_factor_fast_bulk(lpp, cst, tmp_var_idx_m, ARR_LEN(tmp_var_idx_m), 1.0); + DEL_ARR_F(tmp_var_idx_m); - DEL_ARR_F(tmp_idx_1); - DEL_ARR_F(tmp_idx_m1); + /* + c * a_{nt}^k */ + idx = node_tp_idx * livein->max_alive_steps + t; + lpp_set_factor_fast(lpp, cst, livein->a[idx], (double)(num_block_user)); } } } ilp_timer_pop(); - DBG((env->dbg, LEVEL_1, "\t%u pressure constraints (%g sec)\n", + DBG((env->dbg, LEVEL_1, "\t%u alive livein nodes constraints (%g sec)\n", num_cst, ilp_timer_elapsed_usec(t_cst) / 1000000.0)); } @@ -1536,9 +1542,7 @@ static void create_pressure_alive_constraint(be_ilpsched_env_t *env, lpp_t *lpp, ir_node *cur_irn; unsigned num_cst = 0; ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); -#ifdef WITH_LIBCORE lc_timer_t *t_cst = lc_timer_register("beilpsched_cst_pressure", "create pressure constraints"); -#endif /* WITH_LIBCORE */ ilp_timer_push(t_cst); /* y_{nt}^k is set for each node and timestep and unit type */ @@ -1570,6 +1574,7 @@ static void create_pressure_alive_constraint(be_ilpsched_env_t *env, lpp_t *lpp, int cst, y_idx; ir_node *irn; int *tmp_var_idx = NEW_ARR_F(int, 0); + ilp_livein_node_t *livein; snprintf(buf, sizeof(buf), "pressure_cst_n%u_%u_%s", cur_idx, t, cur_tp->name); cst = lpp_add_cst_uniq(lpp, buf, lpp_less, (double)(cur_tp->n_units - 1)); @@ -1595,6 +1600,25 @@ static void create_pressure_alive_constraint(be_ilpsched_env_t *env, lpp_t *lpp, a_idx = ILPVAR_IDX_DEAD(ba, na, tp_idx, t); ARR_APP1(int, tmp_var_idx, na->ilp_vars.a[a_idx]); } + /* do the same for livein nodes */ + foreach_pset(ba->livein_nodes, livein) { + ir_node *irn = livein->irn; + be_ilpsched_irn_t *node = get_ilpsched_irn(env, irn); + int a_idx, tp_idx; + + /* check if node can be alive here */ + if (t >= livein->max_alive_steps) + continue; + + tp_idx = is_valid_unit_type_for_node(cur_tp, node); + + /* current type is not suitable */ + if (tp_idx < 0) + continue; + + a_idx = tp_idx * livein->max_alive_steps + t; + ARR_APP1(int, tmp_var_idx, livein->a[a_idx]); + } if (ARR_LEN(tmp_var_idx) > 0) lpp_set_factor_fast_bulk(lpp, cst, tmp_var_idx, ARR_LEN(tmp_var_idx), 1.0); @@ -1602,7 +1626,7 @@ static void create_pressure_alive_constraint(be_ilpsched_env_t *env, lpp_t *lpp, /* - num_nodes * y_{nt}^k */ y_idx = ILPVAR_IDX(cur_na, cur_tp_idx, t); - lpp_set_factor_fast(lpp, cst, cur_na->ilp_vars.y[y_idx], 0.0 - (double)(ba->n_interesting_nodes)); + lpp_set_factor_fast(lpp, cst, cur_na->ilp_vars.y[y_idx], -1.0); } } } @@ -1611,15 +1635,109 @@ static void create_pressure_alive_constraint(be_ilpsched_env_t *env, lpp_t *lpp, num_cst, ilp_timer_elapsed_usec(t_cst) / 1000000.0)); } +/** + * Create ILP branch constraints: + * Assure, alle nodes are scheduled prior to cfg op. + */ +static void create_branch_constraint(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn_t *block_node) { + char buf[1024]; + ir_node *cur_irn, *cfop; + unsigned num_cst = 0; + unsigned num_non_branches = 0; + ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); + lc_timer_t *t_cst = lc_timer_register("beilpsched_cst_branch", "create branch constraints"); + + ilp_timer_push(t_cst); + cfop = NULL; + /* determine number of non-branch nodes and the one and only branch node */ + foreach_linked_irns(ba->head_ilp_nodes, cur_irn) { + switch (get_irn_opcode(cur_irn)) { + case iro_Phi: + case iro_Start: + case iro_End: + case iro_Proj: + case iro_Bad: + case iro_Unknown: + num_non_branches++; + break; + default: + if (is_cfop(cur_irn)) { + assert(cfop == NULL && "Highlander - there can be only one to be constrained"); + cfop = cur_irn; + } + else { + num_non_branches++; + } + break; + } + } + + if (cfop) { + be_ilpsched_irn_t *cf_node = get_ilpsched_irn(env, cfop); + ilpsched_node_attr_t *cf_na = get_ilpsched_node_attr(cf_node); + unsigned t; + + /* for each time step */ + for (t = cf_na->asap - 1; t <= cf_na->alap - 1; ++t) { + int *non_branch_vars, *branch_vars; + int cst; + + snprintf(buf, sizeof(buf), "branch_cst_%u_n%u", t, get_irn_idx(cfop)); + cst = lpp_add_cst_uniq(lpp, buf, lpp_greater, 0.0); + DBG((env->dbg, LEVEL_2, "added constraint %s\n", buf)); + num_cst++; + + /* sum(overall non branches: n)x_{nt}^k - sum(overall branches: b)(num_non_branches * x_{bt}^k >= 0) */ + non_branch_vars = NEW_ARR_F(int, 0); + branch_vars = NEW_ARR_F(int, 0); + foreach_linked_irns(ba->head_ilp_nodes, cur_irn) { + be_ilpsched_irn_t *node = get_ilpsched_irn(env, cur_irn); + ilpsched_node_attr_t *na = get_ilpsched_node_attr(node); + int tp_idx; + + if (cur_irn == cfop) { + /* for all unit types available for this node */ + for (tp_idx = na->n_unit_types - 1; tp_idx >= 0; --tp_idx) { + unsigned idx = ILPVAR_IDX(na, tp_idx, t); + ARR_APP1(int, branch_vars, na->ilp_vars.x[idx]); + } + } + else { + /* sum up all possible schedule points for this node upto current timestep */ + for (tp_idx = na->n_unit_types - 1; tp_idx >= 0; --tp_idx) { + unsigned tn; + unsigned tmax = MIN(t, na->alap - 1); + + for (tn = na->asap - 1; tn <= tmax; ++tn) { + unsigned idx = ILPVAR_IDX(na, tp_idx, tn); + ARR_APP1(int, non_branch_vars, na->ilp_vars.x[idx]); + } + } + } + + } + + if (ARR_LEN(non_branch_vars) > 0) + lpp_set_factor_fast_bulk(lpp, cst, non_branch_vars, ARR_LEN(non_branch_vars), 1.0); + if (ARR_LEN(branch_vars) > 0) + lpp_set_factor_fast_bulk(lpp, cst, branch_vars, ARR_LEN(branch_vars), 0.0 - (double)num_non_branches); + + DEL_ARR_F(branch_vars); + DEL_ARR_F(non_branch_vars); + } + } + ilp_timer_pop(); + DBG((env->dbg, LEVEL_1, "\t%u branch constraints (%g sec)\n", + num_cst, ilp_timer_elapsed_usec(t_cst) / 1000000.0)); +} + #if 0 static void create_proj_keep_constraints(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn_t *block_node) { char buf[1024]; ir_node *irn; unsigned num_cst = 0; ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); -#ifdef WITH_LIBCORE lc_timer_t *t_cst = lc_timer_register("beilpsched_cst_projkeep", "create proj and keep constraints"); -#endif /* WITH_LIBCORE */ ilp_timer_push(t_cst); /* check all nodes */ @@ -1685,7 +1803,7 @@ static void create_proj_keep_constraints(be_ilpsched_env_t *env, lpp_t *lpp, be_ DBG((env->dbg, LEVEL_1, "\t%u Proj and Keep constraints (%g sec)\n", num_cst, ilp_timer_elapsed_usec(t_cst) / 1000000.0)); } -#endif +#endif /* if 0 */ /*************************************************** * _____ _ _____ _ @@ -1706,6 +1824,7 @@ static void create_ilp(ir_node *block, void *walk_env) { ilpsched_block_attr_t *ba = get_ilpsched_block_attr(block_node); FILE *logfile = NULL; lpp_t *lpp = NULL; + int need_heur = 0; struct obstack var_obst; char name[1024]; @@ -1721,13 +1840,13 @@ static void create_ilp(ir_node *block, void *walk_env) { /* if we have less than two interesting nodes, there is no need to create the ILP */ if (ba->n_interesting_nodes > 1) { - double fact_var = ba->n_interesting_nodes > 25 ? 1.1 : 1.2; - double fact_cst = ba->n_interesting_nodes > 25 ? 0.7 : 1.5; + double fact_var = ba->n_interesting_nodes > 25 ? 2.3 : 3; + double fact_cst = ba->n_interesting_nodes > 25 ? 3 : 4.5; int base_num = ba->n_interesting_nodes * ba->n_interesting_nodes; int estimated_n_var = (int)((double)base_num * fact_var); int estimated_n_cst = (int)((double)base_num * fact_cst); - DBG((env->dbg, LEVEL_1, "Creating LPP with estimed numbers: %d vars, %d cst\n", + DBG((env->dbg, LEVEL_1, "Creating LPP with estimated numbers: %d vars, %d cst\n", estimated_n_var, estimated_n_cst)); /* set up the LPP object */ @@ -1736,9 +1855,9 @@ static void create_ilp(ir_node *block, void *walk_env) { lpp = new_lpp_userdef( (const char *)name, lpp_minimize, - estimated_n_cst + 1, /* num vars */ - estimated_n_cst + 20, /* num cst */ - 1.2); /* grow factor */ + estimated_n_cst, /* num vars */ + estimated_n_cst + 1, /* num cst */ + 1.3); /* grow factor */ obstack_init(&var_obst); /* create ILP variables */ @@ -1749,22 +1868,20 @@ static void create_ilp(ir_node *block, void *walk_env) { create_assignment_and_precedence_constraints(env, lpp, block_node); create_ressource_constraints(env, lpp, block_node); create_bundle_constraints(env, lpp, block_node); + create_branch_constraint(env, lpp, block_node); //create_proj_keep_constraints(env, lpp, block_node); -#if 0 - if (ba->n_interesting_nodes > env->opts->limit_dead) { + + if (env->opts->regpress) { create_alive_nodes_constraint(env, lpp, block_node); + create_alive_livein_nodes_constraint(env, lpp, block_node); create_pressure_alive_constraint(env, lpp, block_node); - } else { - create_dying_nodes_constraint(env, lpp, block_node); - create_pressure_dead_constraint(env, lpp, block_node); } -#endif DBG((env->dbg, LEVEL_1, "ILP to solve: %u variables, %u constraints\n", lpp->var_next, lpp->cst_next)); /* debug stuff, dump lpp when debugging is on */ DEBUG_ONLY( - if (firm_dbg_get_mask(env->dbg) > 0) { + if (firm_dbg_get_mask(env->dbg) > 1) { char buf[1024]; FILE *f; @@ -1806,20 +1923,26 @@ static void create_ilp(ir_node *block, void *walk_env) { char buf[1024]; FILE *f; - snprintf(buf, sizeof(buf), "lpp_block_%lu.assert.txt", get_irn_node_nr(block)); - f = fopen(buf, "w"); - lpp_dump_plain(lpp, f); - fclose(f); - snprintf(buf, sizeof(buf), "lpp_block_%lu.assert.mps", get_irn_node_nr(block)); - lpp_dump(lpp, buf); - dump_ir_block_graph(env->irg, "-assert"); + DEBUG_ONLY( + if (firm_dbg_get_mask(env->dbg) >= 2) { + snprintf(buf, sizeof(buf), "lpp_block_%lu.infeasible.txt", get_irn_node_nr(block)); + f = fopen(buf, "w"); + lpp_dump_plain(lpp, f); + fclose(f); + snprintf(buf, sizeof(buf), "lpp_block_%lu.infeasible.mps", get_irn_node_nr(block)); + lpp_dump(lpp, buf); + dump_ir_block_graph(env->irg, "-infeasible"); + } + ) - assert(0 && "ILP solution is not feasible!"); + ir_fprintf(stderr, "ILP found no solution within time (%+F, %+F), falling back to heuristics.\n", block, env->irg); + need_heur = 1; } DBG((env->dbg, LEVEL_1, "\nSolution:\n")); DBG((env->dbg, LEVEL_1, "\tsend time: %g sec\n", lpp->send_time / 1000000.0)); DBG((env->dbg, LEVEL_1, "\treceive time: %g sec\n", lpp->recv_time / 1000000.0)); + DBG((env->dbg, LEVEL_1, "\tmatrix: %u elements, density %.2f%%, size %.2fMB\n", lpp->n_elems, lpp->density, (double)lpp->matrix_mem / 1024.0 / 1024.0)); DBG((env->dbg, LEVEL_1, "\titerations: %d\n", lpp->iterations)); DBG((env->dbg, LEVEL_1, "\tsolution time: %g\n", lpp->sol_time)); DBG((env->dbg, LEVEL_1, "\tobjective function: %g\n", LPP_VALUE_IS_0(lpp->objval) ? 0.0 : lpp->objval)); @@ -1829,7 +1952,38 @@ static void create_ilp(ir_node *block, void *walk_env) { } /* apply solution */ - apply_solution(env, lpp, block); +#ifdef FIRM_STATISTICS + if (be_stat_ev_is_active()) { + be_stat_ev("nodes", ba->block_last_idx); + be_stat_ev("vars", lpp ? lpp->var_next : 0); + be_stat_ev("csts", lpp ? lpp->cst_next : 0); + } +#endif /* FIRM_STATISTICS */ + if (need_heur) { +#ifdef FIRM_STATISTICS + if (be_stat_ev_is_active()) { + be_stat_ev("time", -1); + be_stat_ev_dbl("opt", 0.0); + } +#endif /* FIRM_STATISTICS */ + list_sched_single_block(env->birg, block, env->be_opts); + } + else { +#ifdef FIRM_STATISTICS + if (be_stat_ev_is_active()) { + if (lpp) { + double opt = lpp->sol_state == lpp_optimal ? 100.0 : 100.0 * lpp->best_bound / lpp->objval; + be_stat_ev_dbl("time", lpp->sol_time); + be_stat_ev_dbl("opt", opt); + } + else { + be_stat_ev_dbl("time", 0.0); + be_stat_ev_dbl("opt", 100.0); + } + } +#endif /* FIRM_STATISTICS */ + apply_solution(env, lpp, block); + } if (lpp) free_lpp(lpp); @@ -1841,24 +1995,35 @@ static void create_ilp(ir_node *block, void *walk_env) { /** * Perform ILP scheduling on the given irg. */ -void be_ilp_sched(const be_irg_t *birg) { +void be_ilp_sched(const be_irg_t *birg, be_options_t *be_opts) { be_ilpsched_env_t env; - const char *name = "be ilp scheduling"; - arch_isa_t *isa = birg->main_env->arch_env->isa; - const ilp_sched_selector_t *sel = isa->impl->get_ilp_sched_selector(isa); + const char *name = "be ilp scheduling"; + ir_graph *irg = be_get_birg_irg(birg); + const arch_env_t *arch_env = be_get_birg_arch_env(birg); + const arch_isa_t *isa = arch_env->isa; + const ilp_sched_selector_t *sel = isa->impl->get_ilp_sched_selector(isa); FIRM_DBG_REGISTER(env.dbg, "firm.be.sched.ilp"); - //firm_dbg_set_mask(env.dbg, 31); +#ifdef FIRM_STATISTICS + if (be_stat_ev_is_active()) { + be_stat_tags[STAT_TAG_CLS] = "ilpsched"; + be_stat_ev_push(be_stat_tags, STAT_TAG_LAST, be_stat_file); + } +#endif /* FIRM_STATISTICS */ - env.irg_env = be_ilp_sched_init_irg_ilp_schedule(sel, birg->irg); +// firm_dbg_set_mask(env.dbg, 1); + + env.irg_env = be_ilp_sched_init_irg_ilp_schedule(sel, irg); env.sel = sel; - env.irg = birg->irg; - env.height = heights_new(birg->irg); + env.irg = irg; + env.height = heights_new(irg); env.main_env = birg->main_env; - env.arch_env = birg->main_env->arch_env; - env.cpu = arch_isa_get_machine(birg->main_env->arch_env->isa); + env.arch_env = arch_env; + env.cpu = arch_isa_get_machine(arch_env->isa); env.opts = &ilp_opts; + env.birg = birg; + env.be_opts = be_opts; phase_init(&env.ph, name, env.irg, PHASE_DEFAULT_GROWTH, init_ilpsched_irn); /* assign a unique per block number to all interesting nodes */ @@ -1881,7 +2046,7 @@ void be_ilp_sched(const be_irg_t *birg) { irg_walk_in_or_dep_blkwise_graph(env.irg, NULL, refine_asap_alap_times, &env); /* perform ILP scheduling */ - irg_block_walk_graph(env.irg, clear_unwanted_data, create_ilp, &env); + irg_block_walk_graph(env.irg, NULL, create_ilp, &env); DEBUG_ONLY( if (firm_dbg_get_mask(env.dbg)) { @@ -1892,15 +2057,23 @@ void be_ilp_sched(const be_irg_t *birg) { } ); + /* free data allocated dynamically */ + irg_block_walk_graph(env.irg, NULL, clear_unwanted_data, &env); + /* free all allocated object */ phase_free(&env.ph); heights_free(env.height); /* notify backend */ be_ilp_sched_finish_irg_ilp_schedule(sel, birg->irg, env.irg_env); + +#ifdef FIRM_STATISTICS + if (be_stat_ev_is_active()) { + be_stat_ev_pop(); + } +#endif /* FIRM_STATISTICS */ } -#ifdef WITH_LIBCORE /** * Register ILP scheduler options. */ @@ -1911,7 +2084,6 @@ void be_init_ilpsched(void) lc_opt_add_table(sched_grp, ilpsched_option_table); } -#endif /* WITH_LIBCORE */ #else /* WITH_ILP */