Commit b6de8e65 authored by Matthias Braun's avatar Matthias Braun
Browse files

copyopt: miscellaneous code cleanups

parent 846df681
......@@ -1229,7 +1229,7 @@ static void process(co2_t *env)
xfree(clouds);
}
int co_solve_heuristic_new(copy_opt_t *co)
static int co_solve_heuristic_new(copy_opt_t *co)
{
char buf[256];
co2_t env;
......
......@@ -25,6 +25,8 @@
*/
#include "config.h"
#include <stdbool.h>
#include "irtools.h"
#include "irprintf.h"
......@@ -103,7 +105,7 @@ size_red_t *new_size_red(copy_opt_t *co)
/**
* Checks if a node is simplicial in the graph heeding the already removed nodes.
*/
static inline int sr_is_simplicial(size_red_t *sr, const ir_node *ifn)
static inline bool sr_is_simplicial(size_red_t *sr, const ir_node *ifn)
{
be_ifg_t *ifg = sr->co->cenv->ifg;
neighbours_iter_t iter;
......@@ -122,37 +124,40 @@ static inline int sr_is_simplicial(size_red_t *sr, const ir_node *ifn)
for (i=0; i<size; ++i)
for (o=i+1; o<size; ++o)
if (!be_ifg_connected(ifg, all[i], all[o]))
return 0;
return false;
/* all edges exist so this is a clique */
return 1;
return true;
}
void sr_remove(size_red_t *sr)
{
ir_node *irn;
int redo = 1;
bool redo = true;
const be_ifg_t *ifg = sr->co->cenv->ifg;
nodes_iter_t iter;
while (redo) {
redo = 0;
redo = false;
be_ifg_foreach_node(ifg, &iter, irn) {
const arch_register_req_t *req = arch_get_irn_register_req(irn);
coloring_suffix_t *cs;
if (!arch_register_req_is(req, limited) && !sr_is_removed(sr, irn) && !co_gs_is_optimizable(sr->co, irn)) {
if (sr_is_simplicial(sr, irn)) {
coloring_suffix_t *cs = OALLOC(&sr->ob, coloring_suffix_t);
if (arch_register_req_is(req, limited) || sr_is_removed(sr, irn))
continue;
if (co_gs_is_optimizable(sr->co, irn))
continue;
if (!sr_is_simplicial(sr, irn))
continue;
cs->irn = irn;
cs->next = sr->col_suff;
sr->col_suff = cs;
cs = OALLOC(&sr->ob, coloring_suffix_t);
cs->irn = irn;
cs->next = sr->col_suff;
sr->col_suff = cs;
pset_insert_ptr(sr->all_removed, irn);
pset_insert_ptr(sr->all_removed, irn);
redo = 1;
}
}
redo = true;
}
}
}
......@@ -220,28 +225,18 @@ ilp_env_t *new_ilp_env(copy_opt_t *co, ilp_callback build, ilp_callback apply, v
lpp_sol_state_t ilp_go(ilp_env_t *ienv)
{
be_options_t *options = be_get_irg_options(ienv->co->irg);
ir_graph *irg = ienv->co->irg;
be_options_t *options = be_get_irg_options(irg);
sr_remove(ienv->sr);
ienv->build(ienv);
lpp_set_time_limit(ienv->lp, time_limit);
if (solve_log)
lpp_set_log(ienv->lp, stdout);
lpp_solve(ienv->lp, options->ilp_server, options->ilp_solver);
//be_stat_ev_dbl("co_ilp_objval", ienv->lp->objval);
//be_stat_ev_dbl("co_ilp_best_bound", ienv->lp->best_bound);
be_stat_ev ("co_ilp_iter", lpp_get_iter_cnt(ienv->lp));
be_stat_ev_dbl("co_ilp_sol_time", lpp_get_sol_time(ienv->lp));
if (dump_flags & DUMP_ILP) {
char buf[128];
FILE *f;
ir_snprintf(buf, sizeof(buf), "%F_%s-co.ilp", ienv->co->cenv->irg,
ir_snprintf(buf, sizeof(buf), "%F_%s-co.ilp", irg,
ienv->co->cenv->cls->name);
f = fopen(buf, "wt");
if (f == NULL) {
......@@ -251,6 +246,17 @@ lpp_sol_state_t ilp_go(ilp_env_t *ienv)
fclose(f);
}
lpp_set_time_limit(ienv->lp, time_limit);
if (solve_log)
lpp_set_log(ienv->lp, stdout);
lpp_solve(ienv->lp, options->ilp_server, options->ilp_solver);
//be_stat_ev_dbl("co_ilp_objval", ienv->lp->objval);
//be_stat_ev_dbl("co_ilp_best_bound", ienv->lp->best_bound);
be_stat_ev ("co_ilp_iter", lpp_get_iter_cnt(ienv->lp));
be_stat_ev_dbl("co_ilp_sol_time", lpp_get_sol_time(ienv->lp));
ienv->apply(ienv);
sr_reinsert(ienv->sr);
......
......@@ -512,8 +512,11 @@ static void ilp2_apply(ilp_env_t *ienv)
lpp_sol_state_t state = lpp_get_solution(ienv->lp, sol, lenv->first_x_var, lenv->last_x_var);
if (state != lpp_optimal) {
printf("WARNING %s: Solution state is not 'optimal': %d\n", ienv->co->name, (int)state);
assert(state >= lpp_feasible && "The solution should at least be feasible!");
printf("WARNING %s: Solution state is not 'optimal': %d\n",
ienv->co->name, (int)state);
if (state < lpp_feasible) {
panic("Copy coalescing solution not feasible!");
}
}
for (i=0; i<count; ++i) {
......@@ -545,17 +548,13 @@ static void ilp2_apply(ilp_env_t *ienv)
#endif
}
BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copyilp2)
void be_init_copyilp2(void)
{
static co_algo_info copyheur = {
co_solve_ilp2, 1
};
be_register_copyopt("ilp", &copyheur);
}
int co_solve_ilp2(copy_opt_t *co)
/**
* Solves the problem using mixed integer programming
* @returns 1 iff solution state was optimal
* Uses the OU and the GRAPH data structure
* Dependency of the OU structure can be removed
*/
static int co_solve_ilp2(copy_opt_t *co)
{
lpp_sol_state_t sol_state;
ilp_env_t *ienv;
......@@ -583,3 +582,13 @@ int co_solve_ilp2(copy_opt_t *co)
return sol_state == lpp_optimal;
}
BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copyilp2)
void be_init_copyilp2(void)
{
static co_algo_info copyheur = {
co_solve_ilp2, 1
};
be_register_copyopt("ilp", &copyheur);
}
......@@ -86,6 +86,16 @@ static const lc_opt_enum_mask_items_t dump_items[] = {
{ NULL, 0 }
};
/**
* Flags for dumping the IFG.
*/
enum {
CO_IFG_DUMP_COLORS = 1 << 0, /**< Dump the graph colored. */
CO_IFG_DUMP_LABELS = 1 << 1, /**< Dump node/edge labels. */
CO_IFG_DUMP_SHAPE = 1 << 2, /**< Give constrained nodes special shapes. */
CO_IFG_DUMP_CONSTR = 1 << 3, /**< Dump the node constraints in the label. */
};
static const lc_opt_enum_mask_items_t style_items[] = {
{ "color", CO_IFG_DUMP_COLORS },
{ "labels", CO_IFG_DUMP_LABELS },
......@@ -1102,12 +1112,6 @@ void co_dump_ifg_dot(const copy_opt_t *co, FILE *f, unsigned flags)
be_ifg_dump_dot(co->cenv->ifg, co->irg, f, &ifg_dot_cb, &cod);
}
void co_solve_park_moon(copy_opt_t *opt)
{
(void) opt;
}
/*
__ __ _ ____ _
| \/ | __ _(_)_ __ | _ \ _ __(_)_ _____ _ __
......
......@@ -32,44 +32,21 @@
#define FIRM_BE_BECOPYOPT_H
#include <stdio.h>
#include <stdbool.h>
#include "firm_types.h"
#include "bechordal.h"
#include "beutil.h"
/**
* Flags for dumping the IFG.
*/
enum {
CO_IFG_DUMP_COLORS = 1, /**< Dump the graph colored. */
CO_IFG_DUMP_LABELS = 2, /**< Dump node/edge labels. */
CO_IFG_DUMP_SHAPE = 4, /**< Give constrained nodes special shapes. */
CO_IFG_DUMP_CONSTR = 8 /**< Dump the node constraints in the label. */
};
/**
* Algorithms.
*/
enum {
CO_ALGO_NONE,
CO_ALGO_HEUR,
CO_ALGO_HEUR2,
CO_ALGO_HEUR4,
CO_ALGO_ILP,
CO_ALGO_PBQP,
CO_ALGO_LAST
};
typedef struct copy_opt_t copy_opt_t;
typedef int(*cost_fct_t)(const copy_opt_t *, ir_node *, ir_node *, int);
typedef struct {
int (*copyopt)(copy_opt_t *co); /**< function ptr to run copyopt */
int can_improve_existing;
bool can_improve_existing;
} co_algo_info;
/**
* Register a new copy optimization algorithm.
*
......@@ -82,9 +59,6 @@ void be_register_copyopt(const char *name, co_algo_info *copyopt);
/** The driver for copy minimization. */
void co_driver(be_chordal_env_t *cenv);
/** A coalescing algorithm. */
typedef int (co_algo_t)(copy_opt_t *);
/**
* Generate the problem. Collect all information and optimizable nodes.
*/
......@@ -157,18 +131,6 @@ void co_free_ou_structure(copy_opt_t *co);
*/
int co_solve_heuristic(copy_opt_t *co);
/**
* Apply Park/Moon coalescing to the graph.
* @param co The copy optimization data structure.
*/
void co_solve_park_moon(copy_opt_t *co);
/**
* Solves the copy minimization problem using another heuristic approach.
* Uses the OU and the GRAPH data structure.
*/
int co_solve_heuristic_new(copy_opt_t *co);
/**
* Returns the maximal costs possible, i.e. the costs if all
* pairs would be assigned different registers.
......@@ -233,14 +195,6 @@ void co_build_graph_structure(copy_opt_t *co);
*/
void co_free_graph_structure(copy_opt_t *co);
/**
* Solves the problem using mixed integer programming
* @returns 1 iff solution state was optimal
* Uses the OU and the GRAPH data structure
* Dependency of the OU structure can be removed
*/
int co_solve_ilp2(copy_opt_t *co);
/**
* Checks if a node is optimizable, viz has something to do with coalescing.
* Uses the GRAPH data structure
......
......@@ -130,7 +130,8 @@ struct affinity_node_t {
};
static inline affinity_node_t *get_affinity_info(const copy_opt_t *co, const ir_node *irn) {
static inline affinity_node_t *get_affinity_info(const copy_opt_t *co, const ir_node *irn)
{
affinity_node_t find;
ASSERT_GS_AVAIL(co);
......@@ -146,5 +147,4 @@ static inline affinity_node_t *get_affinity_info(const copy_opt_t *co, const ir_
#define co_gs_foreach_aff_node(co, aff_node) for (aff_node = (affinity_node_t*)co_gs_nodes_begin(co); aff_node != NULL; aff_node = (affinity_node_t*)co_gs_nodes_next(co))
#define co_gs_foreach_neighb(aff_node, neighb) for (neighb = (neighb_t*)aff_node->neighbours; neighb != NULL; neighb = (neighb_t*)neighb->next)
#endif /* FIRM_BE_BECOPYOPT_T_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment