{
be_chordal_alloc_env_t env;
char buf[256];
- be_lv_t *lv;
const arch_register_class_t *cls = chordal_env->cls;
- int colors_n = arch_register_class_n_regs(cls);
- ir_graph *irg = chordal_env->irg;
-
- lv = be_assure_liveness(irg);
- be_liveness_assure_sets(lv);
- be_liveness_assure_chk(lv);
+ int colors_n = arch_register_class_n_regs(cls);
+ ir_graph *irg = chordal_env->irg;
+ be_assure_live_sets(irg);
assure_doms(irg);
env.chordal_env = chordal_env;
static void draw(draw_chordal_env_t *env, const rect_t *start_box)
{
+ ir_graph *irg = env->chordal_env->irg;
plotter_t *p = env->plotter;
- be_lv_t *lv;
rect_t bbox;
bbox.x = bbox.y = 0;
bbox.w = start_box->w + 2 * env->opts->x_margin;
bbox.h = start_box->h + 2 * env->opts->y_margin;
- lv = be_assure_liveness(env->chordal_env->irg);
- be_liveness_assure_sets(lv);
- be_liveness_assure_chk(lv);
+ be_assure_live_sets(irg);
+ be_assure_live_chk(irg);
p->vtab->begin(p, &bbox);
irg_block_walk_graph(env->chordal_env->irg, draw_block, NULL, env);
chordal_env->border_heads = pmap_create();
chordal_env->allocatable_regs = bitset_malloc(chordal_env->cls->n_regs);
- be_assure_liveness(irg);
- be_liveness_assure_chk(be_get_irg_liveness(irg));
+ be_assure_live_chk(irg);
if (stat_ev_enabled) {
pse->pre_spill_cost = be_estimate_irg_costs(irg, exec_freq);
be_timer_push(T_RA_PROLOG);
- be_assure_liveness(irg);
-
chordal_env.obst = &obst;
chordal_env.opts = &options;
chordal_env.irg = irg;
dump(BE_CH_DUMP_LOWER, irg, NULL, "belower-after-ra");
obstack_free(&obst, NULL);
- be_liveness_invalidate(be_get_irg_liveness(irg));
+ be_invalidate_live_sets(irg);
be_timer_pop(T_RA_EPILOG);
be_timer_pop(T_RA_OTHER);
if (selected_copyopt->copyopt == void_algo)
return;
- be_liveness_assure_chk(be_get_irg_liveness(cenv->irg));
+ be_assure_live_chk(cenv->irg);
co = new_copy_opt(cenv, cost_func);
co_build_ou_structure(co);
#include "belive.h"
#include "bedomfront.h"
-be_lv_t *be_assure_liveness(ir_graph *irg)
-{
- be_irg_t *birg = be_birg_from_irg(irg);
- if (birg->lv != NULL)
- return birg->lv;
-
- return birg->lv = be_liveness(birg->irg);
-}
-
void be_assure_dom_front(ir_graph *irg)
{
be_irg_t *birg = be_birg_from_irg(irg);
birg->dom_front = NULL;
}
+void be_invalidate_live_sets(ir_graph *irg)
+{
+ be_irg_t *birg = be_birg_from_irg(irg);
+ be_liveness_invalidate_sets(birg->lv);
+}
+
+void be_invalidate_live_chk(ir_graph *irg)
+{
+ be_irg_t *birg = be_birg_from_irg(irg);
+ be_liveness_invalidate_chk(birg->lv);
+}
+
+void be_assure_live_sets(ir_graph *irg)
+{
+ be_irg_t *birg = be_birg_from_irg(irg);
+ be_liveness_compute_sets(birg->lv);
+}
+
+void be_assure_live_chk(ir_graph *irg)
+{
+ be_irg_t *birg = be_birg_from_irg(irg);
+ be_liveness_compute_chk(birg->lv);
+}
+
void be_free_birg(ir_graph *irg)
{
be_irg_t *birg = be_birg_from_irg(irg);
#include "be_t.h"
#include "irtypes.h"
-be_lv_t *be_assure_liveness(ir_graph *irg);
-
void be_assure_dom_front(ir_graph *irg);
void be_invalidate_dom_front(ir_graph *irg);
+void be_assure_live_sets(ir_graph *irg);
+void be_assure_live_chk(ir_graph *irg);
+/**
+ * Liveness is invalid (call when nodes have been added but the control
+ * flow has not been changed)
+ */
+void be_invalidate_live_sets(ir_graph *irg);
+/**
+ * Call when control flow has changed.
+ * be_invalidate_live_sets() is called.
+ */
+void be_invalidate_live_chk(ir_graph *irg);
+
/**
* frees all memory allocated by birg structures (liveness, dom_front, ...).
* The memory of the birg structure itself is not freed.
#define LV_STD_SIZE 64
-/* if defined, use binary search for already live nodes, else linear */
-#define LV_USE_BINARY_SEARCH
-#undef LV_INTESIVE_CHECKS
-
-void be_live_chk_compare(be_lv_t *lv, lv_chk_t *lvc);
-
/**
* Filter out some nodes for which we never need liveness.
*
return _be_is_live_xxx(lv, block, irn, be_lv_state_end);
}
-
-#ifdef LV_USE_BINARY_SEARCH
static inline unsigned _be_liveness_bsearch(be_lv_info_t *arr, unsigned idx)
{
be_lv_info_t *payload = arr + 1;
res = lo;
} while (lo < hi);
-#ifdef LV_INTESIVE_CHECKS
- {
- unsigned i;
- for (i = res; i < n; ++i)
- assert(payload[i].node.idx >= idx);
-
- for (i = 0; i < res; ++i)
- assert(payload[i].node.idx < idx);
- }
-#endif
-
return res;
}
-#else
-
-/**
- * This function searches linearly for the node in the array.
- */
-static inline unsigned _be_liveness_bsearch(be_lv_info_t *arr, unsigned idx)
-{
- unsigned n = arr[0].head.n_members;
- unsigned i;
-
- for (i = 0; i < n; ++i) {
- if (arr[i + 1].node.idx == idx)
- return i;
- }
-
- return i;
-}
-#endif
-
be_lv_info_node_t *be_lv_get(const be_lv_t *li, const ir_node *bl,
const ir_node *irn)
{
res->flags = 0;
}
-#ifdef LV_INTESIVE_CHECKS
- {
- unsigned i;
- unsigned n = irn_live[0].head.n_members;
- unsigned last = 0;
- be_lv_info_t *payload = &irn_live[1];
-
- for (i = 0; i < n; ++i) {
- assert(payload[i].node.idx >= last);
- last = payload[i].node.idx;
- }
- }
-#endif
-
return res;
}
nodes[get_irn_idx(irn)] = irn;
}
-static void compute_liveness(be_lv_t *lv)
+void be_liveness_compute_sets(be_lv_t *lv)
{
ir_node **nodes;
- int i, n;
+ int i;
+ int n;
+ unsigned last_idx;
+
+ if (lv->sets_valid)
+ return;
+
+ be_timer_push(T_LIVE);
+ last_idx = get_irg_last_idx(lv->irg);
+ if (last_idx >= bitset_size(lv->nodes)) {
+ bitset_free(lv->nodes);
+ lv->nodes = bitset_malloc(last_idx * 2);
+ } else {
+ bitset_clear_all(lv->nodes);
+ }
+ ir_nodehashmap_init(&lv->map);
+ obstack_init(&lv->obst);
- stat_ev_tim_push();
n = get_irg_last_idx(lv->irg);
nodes = NEW_ARR_F(ir_node *, n);
memset(nodes, 0, sizeof(nodes[0]) * n);
- /*
- * inserting the variables sorted by their ID is probably
+ /* inserting the variables sorted by their ID is probably
* more efficient since the binary sorted set insertion
- * will not need to move around the data.
- */
+ * will not need to move around the data. */
irg_walk_graph(lv->irg, NULL, collect_liveness_nodes, nodes);
re.lv = lv;
DEL_ARR_F(nodes);
free(re.visited);
register_hook(hook_node_info, &lv->hook_info);
- stat_ev_tim_pop("be_lv_sets_cons");
-}
-void be_liveness_assure_sets(be_lv_t *lv)
-{
- if (!lv->nodes) {
- be_timer_push(T_LIVE);
+ be_timer_pop(T_LIVE);
- lv->nodes = bitset_malloc(2 * get_irg_last_idx(lv->irg));
- ir_nodehashmap_init(&lv->map);
- obstack_init(&lv->obst);
- compute_liveness(lv);
- /* be_live_chk_compare(lv, lv->lvc); */
+ lv->sets_valid = true;
+}
- be_timer_pop(T_LIVE);
- }
+void be_liveness_compute_chk(be_lv_t *lv)
+{
+ if (lv->lvc != NULL)
+ return;
+ lv->lvc = lv_chk_new(lv->irg);
}
-void be_liveness_assure_chk(be_lv_t *lv)
+void be_liveness_invalidate_sets(be_lv_t *lv)
{
-#ifndef USE_LIVE_CHK
- be_timer_push(t_verify);
- be_liveness_assure_sets(lv);
- be_timer_pop(t_verify);
-#else
- (void) lv;
-#endif
+ if (!lv->sets_valid)
+ return;
+ unregister_hook(hook_node_info, &lv->hook_info);
+ obstack_free(&lv->obst, NULL);
+ ir_nodehashmap_destroy(&lv->map);
+ lv->sets_valid = false;
}
-void be_liveness_invalidate(be_lv_t *lv)
+void be_liveness_invalidate_chk(be_lv_t *lv)
{
- if (lv && lv->nodes) {
- unregister_hook(hook_node_info, &lv->hook_info);
- obstack_free(&lv->obst, NULL);
- ir_nodehashmap_destroy(&lv->map);
- bitset_free(lv->nodes);
- lv->nodes = NULL;
- }
+ be_liveness_invalidate_sets(lv);
+
+ if (lv->lvc == NULL)
+ return;
+ lv_chk_free(lv->lvc);
+ lv->lvc = NULL;
}
-/* Compute the inter block liveness for a graph. */
-be_lv_t *be_liveness(ir_graph *irg)
+be_lv_t *be_liveness_new(ir_graph *irg)
{
be_lv_t *lv = XMALLOCZ(be_lv_t);
- lv->irg = irg;
-#ifdef USE_LIVE_CHK
- lv->lvc = lv_chk_new(lv->irg);
-#endif
+ lv->irg = irg;
lv->hook_info.context = lv;
lv->hook_info.hook._hook_node_info = be_dump_liveness_block;
+ lv->nodes = bitset_malloc(2 * get_irg_last_idx(lv->irg));
return lv;
}
-void be_liveness_recompute(be_lv_t *lv)
-{
- unsigned last_idx;
-
- be_timer_push(T_LIVE);
- last_idx = get_irg_last_idx(lv->irg);
- if (last_idx >= bitset_size(lv->nodes)) {
- bitset_free(lv->nodes);
- lv->nodes = bitset_malloc(last_idx * 2);
- } else
- bitset_clear_all(lv->nodes);
-
- ir_nodehashmap_destroy(&lv->map);
- obstack_free(&lv->obst, NULL);
-
- ir_nodehashmap_init(&lv->map);
- obstack_init(&lv->obst);
- compute_liveness(lv);
-
- be_timer_pop(T_LIVE);
-}
-
-
void be_liveness_free(be_lv_t *lv)
{
- be_liveness_invalidate(lv);
-#ifdef USE_LIVE_CHK
- lv_chk_free(lv->lvc);
-#endif
+ be_liveness_invalidate_sets(lv);
+ be_liveness_invalidate_chk(lv);
+
+ bitset_free(lv->nodes);
xfree(lv);
}
void be_liveness_remove(be_lv_t *lv, const ir_node *irn)
{
- if (lv->nodes) {
+ if (lv->sets_valid) {
unsigned idx = get_irn_idx(irn);
lv_remove_walker_t w;
void be_liveness_introduce(be_lv_t *lv, ir_node *irn)
{
/* Don't compute liveness information for non-data nodes. */
- if (lv->nodes && is_liveness_node(irn)) {
+ if (lv->sets_valid && is_liveness_node(irn)) {
re.lv = lv;
re.visited = bitset_malloc(get_irg_last_idx(lv->irg));
liveness_for_node(irn);
obstack_ptr_grow(obst, irn);
}
-void be_live_chk_compare(be_lv_t *lv, lv_chk_t *lvc)
+static void be_live_chk_compare(be_lv_t *lv, lv_chk_t *lvc)
{
ir_graph *irg = lv->irg;
BE_REGISTER_MODULE_CONSTRUCTOR(be_init_live)
void be_init_live(void)
{
+ (void)be_live_chk_compare;
FIRM_DBG_REGISTER(dbg, "firm.be.liveness");
}
* Compute the inter block liveness for a graph.
* @param irg The graph.
*/
-be_lv_t *be_liveness(ir_graph *irg);
+be_lv_t *be_liveness_new(ir_graph *irg);
/**
* Free the liveness information.
void be_liveness_free(be_lv_t *lv);
/**
- * Recompute the complete liveness information.
+ * (Re)compute the liveness information if necessary.
*/
-void be_liveness_recompute(be_lv_t *lv);
+void be_liveness_compute_sets(be_lv_t *lv);
+void be_liveness_compute_chk(be_lv_t *lv);
+
+/**
+ * Invalidate the liveness information.
+ * You must call this if you modify the program and do not
+ * update the liveness with the be_liveness_{update,remove,introduce}
+ * functions.
+ * @note If changed the control flow then you must also call
+ * be_liveness_invalidate_chk()
+ */
+void be_liveness_invalidate_sets(be_lv_t *lv);
+void be_liveness_invalidate_chk(be_lv_t *lv);
/**
* Update the liveness information for a single node.
const arch_register_class_t *cls,
const ir_node *pos, ir_nodeset_t *live);
-/**
- * Make sure the live sets are computed.
- * @param lv The liveness information.
- */
-void be_liveness_assure_sets(be_lv_t *lv);
-
-/**
- * Make sure all information needed for liveness checks is available.
- * @param lv The liveness information.
- */
-void be_liveness_assure_chk(be_lv_t *lv);
-
-/**
- * Invalidate the liveness information.
- * You must call this if you modify the program and do not
- * update the liveness with the be_liveness_{update,remove,introduce}
- * functions.
- * @param lv The liveness info.
- */
-void be_liveness_invalidate(be_lv_t *lv);
-
-#endif /* FIRM_BE_BELIVE_H */
+#endif
#ifndef FIRM_BE_BELIVE_T_H
#define FIRM_BE_BELIVE_T_H
+#include <stdbool.h>
#include "be_types.h"
#include "irgraph_t.h"
#include "irnodehashmap.h"
#include "irhooks.h"
+#include "irlivechk.h"
#include "statev.h"
#include "pset.h"
#include "belive.h"
-#define USE_LIVE_CHK
-
-#ifdef USE_LIVE_CHK
-#include "irlivechk.h"
-#endif
-
struct be_lv_t {
ir_nodehashmap_t map;
struct obstack obst;
+ bool sets_valid;
ir_graph *irg;
bitset_t *nodes;
hook_entry_t hook_info;
-#ifdef USE_LIVE_CHK
lv_chk_t *lvc;
-#endif
};
typedef struct be_lv_info_node_t be_lv_info_node_t;
{
unsigned res;
- if (li->nodes != NULL) {
+ if (li->sets_valid) {
be_lv_info_node_t *info = be_lv_get(li, block, irn);
res = info != NULL ? (info->flags & flags) != 0 : 0;
- }
-
-#ifdef USE_LIVE_CHK
- else
+ } else {
res = (lv_chk_bl_xxx(li->lvc, block, irn) & flags) != 0;
-#endif
+ }
return res;
}
ir_nodehashmap_destroy(&cenv.op_set);
obstack_free(&cenv.obst, NULL);
- be_liveness_invalidate(be_get_irg_liveness(irg));
+ be_invalidate_live_sets(irg);
}
-
/**
* Push nodes that do not need to be permed through the Perm.
* This is commonly a reload cascade at block ends.
env.do_copy = do_copy;
/* we will need interference */
- be_liveness_assure_chk(be_get_irg_liveness(irg));
+ be_assure_live_chk(irg);
irg_walk_graph(irg, NULL, lower_nodes_after_ra_walker, &env);
}
birg->irg = irg;
birg->main_env = env;
obstack_init(&birg->obst);
+ birg->lv = be_liveness_new(irg);
edges_deactivate_kind(irg, EDGE_KIND_DEP);
edges_activate_kind(irg, EDGE_KIND_DEP);
printf("#### ----- === Allocating registers of %s (%s) ===\n", cls->name, get_entity_name(get_irg_entity(irg)));
#endif
- lv = be_assure_liveness(irg);
- be_liveness_assure_sets(lv);
- be_liveness_assure_chk(lv);
+ be_assure_live_sets(irg);
+ lv = be_get_irg_liveness(irg);
/* insert perms */
assure_doms(irg);
void be_peephole_opt(ir_graph *irg)
{
+#if 0
/* we sometimes find BadE nodes in float apps like optest_float.c or
* kahansum.c for example... */
- be_liveness_invalidate(be_get_irg_liveness(irg));
- be_liveness_assure_sets(be_assure_liveness(irg));
+ be_invalidate_live_sets(irg);
+#endif
+ be_assure_live_sets(irg);
arch_env = be_get_irg_arch_env(irg);
lv = be_get_irg_liveness(irg);
{
size_t i;
- lv = be_assure_liveness(irg);
- be_liveness_assure_sets(lv);
+ be_assure_live_sets(irg);
+ lv = be_get_irg_liveness(irg);
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
/* we most probably constructed new Phis so liveness info is invalid
* now */
- /* TODO: test liveness_introduce */
- be_liveness_invalidate(lv);
+ be_invalidate_live_sets(irg);
free(normal_regs);
stat_ev_ctx_pop("regcls");
env->curr_time = 0;
env->sched_info = NEW_ARR_F(trace_irn_t, nn);
- env->liveness = be_liveness(irg);
+ env->liveness = be_get_irg_liveness(irg);
FIRM_DBG_REGISTER(env->dbg, "firm.be.sched.trace");
- be_liveness_assure_chk(env->liveness);
+ be_assure_live_chk(irg);
memset(env->sched_info, 0, nn * sizeof(*(env->sched_info)));
return env;
static void trace_free(void *data)
{
trace_env_t *env = (trace_env_t*)data;
- be_liveness_free(env->liveness);
DEL_ARR_F(env->sched_info);
free(env);
}
env.irg = irg;
env.cls = cls;
- be_assure_liveness(irg);
+ be_assure_live_sets(irg);
irg_block_walk_graph(irg, pre_spill_prepare_constr_walker, NULL, &env);
}
{
int i;
- be_liveness_assure_sets(be_assure_liveness(irg));
+ be_assure_live_sets(irg);
stat_ev_tim_push();
assure_loopinfo(irg);
if (n_regs == 0)
return;
- be_liveness_assure_sets(be_assure_liveness(irg));
+ be_assure_live_sets(irg);
spill_env = be_new_spill_env(irg);
cls = new_cls;
{
be_fec_env_t *env = XMALLOCZ(be_fec_env_t);
- be_liveness_assure_chk(be_assure_liveness(irg));
+ be_assure_live_chk(irg);
obstack_init(&env->obst);
env->irg = irg;
/* Matze: In theory be_ssa_construction should take care of the liveness...
* try to disable this again in the future */
- be_liveness_invalidate(be_get_irg_liveness(env->irg));
+ be_invalidate_live_sets(env->irg);
be_remove_dead_nodes_from_schedule(env->irg);
insert_all_perms_env_t insert_perms_env;
pmap *perm_map = pmap_create();
ir_graph *irg = chordal_env->irg;
- be_lv_t *lv = be_assure_liveness(irg);
FIRM_DBG_REGISTER(dbg, "ir.be.ssadestr");
- be_liveness_invalidate(lv);
+ be_invalidate_live_sets(irg);
/* create a map for fast lookup of perms: block --> perm */
irg_walk_graph(irg, clear_link, collect_phis_walker, chordal_env);
insert_perms_env.perm_map = perm_map;
irg_block_walk_graph(irg, insert_all_perms_walker, NULL, &insert_perms_env);
- // Matze: really needed here?
- // Sebastian: Yes. the walker function uses interference.
- be_liveness_invalidate(lv);
-
if (chordal_env->opts->dump_flags & BE_CH_DUMP_SSADESTR)
dump_ir_graph(irg, "ssa_destr_perms_placed");
- be_liveness_assure_chk(lv);
+ be_assure_live_chk(irg);
DBG((dbg, LEVEL_1, "Setting regs and placing dupls...\n"));
irg_block_walk_graph(irg, set_regs_or_place_dupls_walker, NULL, chordal_env);
- /* TODO: unfortunately updating doesn't work yet. */
- be_liveness_invalidate(lv);
+ /* unfortunately updating doesn't work yet. */
+ be_invalidate_live_chk(irg);
if (chordal_env->opts->dump_flags & BE_CH_DUMP_SSADESTR)
dump_ir_graph(irg, "ssa_destr_regs_set");
env.insn_count = 0;
env.max_pressure = 0;
env.regpressure = 0;
- be_liveness_assure_sets(be_assure_liveness(irg));
+ be_assure_live_sets(irg);
env.lv = be_get_irg_liveness(irg);
env.cls = cls;
{
minibelady_env_t env;
spill_info_t *info;
- be_lv_t *lv = be_assure_liveness(irg);
+ be_lv_t *lv = be_get_irg_liveness(irg);
- be_liveness_assure_sets(lv);
+ be_assure_live_sets(irg);
assure_loopinfo(irg);
obstack_init(&env.obst);
free_loop_information(irg);
clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_DOMINANCE);
- be_liveness_invalidate(be_get_irg_liveness(irg));
- /* Hack for now, something is buggy with invalidate liveness... */
- be_birg_from_irg(irg)->lv = NULL;
+ be_invalidate_live_chk(irg);
be_invalidate_dom_front(irg);
/* recalculate edges */
{
be_verify_register_pressure_env_t env;
- env.lv = be_liveness(irg);
+ env.lv = be_liveness_new(irg);
env.irg = irg;
env.cls = cls;
env.registers_available = be_get_n_allocatable_regs(irg, cls);
env.problem_found = 0;
- be_liveness_assure_sets(env.lv);
+ be_liveness_compute_sets(env.lv);
irg_block_walk_graph(irg, verify_liveness_walker, NULL, &env);
be_liveness_free(env.lv);
return ! env.problem_found;
}
-
-
/*--------------------------------------------------------------------------- */
-
-
typedef struct be_verify_schedule_env_t_ {
int problem_found; /**< flags indicating a problem */
bitset_t *scheduled; /**< bitset of scheduled nodes */
{
irg = new_irg;
arch_env = be_get_irg_arch_env(irg);
- lv = be_liveness(irg);
+ lv = be_liveness_new(irg);
problem_found = false;
- be_liveness_assure_sets(lv);
+ be_liveness_compute_sets(lv);
irg_block_walk_graph(irg, verify_block_register_allocation, NULL, NULL);
-
be_liveness_free(lv);
return !problem_found;
void be_liveness_check(be_lv_t *lv)
{
lv_walker_t w;
- be_lv_t *fresh = be_liveness(lv->irg);
+ be_lv_t *fresh = be_liveness_new(lv->irg);
w.lv = lv;
w.data = fresh;
void ia32_calculate_non_address_mode_nodes(ir_graph *irg)
{
- be_lv_t *lv = be_assure_liveness(irg);
+ be_lv_t *lv;
+
+ be_assure_live_chk(irg);
+ lv = be_get_irg_liveness(irg);
non_address_mode_nodes = bitset_malloc(get_irg_last_idx(irg));
be_liveness_update(lv, env.state_nodes[i]);
}
} else {
- be_liveness_invalidate(be_get_irg_liveness(irg));
+ be_invalidate_live_sets(irg);
}
/* set registers for the phis */
be_ssa_construction_destroy(&senv);
DEL_ARR_F(env.state_nodes);
- be_liveness_invalidate(be_get_irg_liveness(irg));
+ be_invalidate_live_sets(irg);
}
void ia32_setup_fpu_mode(ir_graph *irg)
sim.worklist = new_waitq();
waitq_put(sim.worklist, start_block);
- be_assure_liveness(irg);
+ be_assure_live_sets(irg);
sim.lv = be_get_irg_liveness(irg);
- be_liveness_assure_sets(sim.lv);
/* Calculate the liveness for all nodes. We must precalculate this info,
* because the simulator adds new nodes (possible before Phi nodes) which