Commit 1f0e7894 authored by Michael Beck's avatar Michael Beck
Browse files

Fixed bad memory leak:

The obstack inside a chordal_env was overwritten with an old version, causing lost allocated blocks

[r13480]
parent 32c52ed3
...@@ -109,10 +109,10 @@ static INLINE border_t *border_add(be_chordal_env_t *env, struct list_head *head ...@@ -109,10 +109,10 @@ static INLINE border_t *border_add(be_chordal_env_t *env, struct list_head *head
if(!is_def) { if(!is_def) {
border_t *def; border_t *def;
b = obstack_alloc(&env->obst, sizeof(*b)); b = obstack_alloc(env->obst, sizeof(*b));
/* also allocate the def and tie it to the use. */ /* also allocate the def and tie it to the use. */
def = obstack_alloc(&env->obst, sizeof(*def)); def = obstack_alloc(env->obst, sizeof(*def));
memset(def, 0, sizeof(*def)); memset(def, 0, sizeof(*def));
b->other_end = def; b->other_end = def;
def->other_end = b; def->other_end = b;
...@@ -206,7 +206,7 @@ static be_insn_t *chordal_scan_insn(be_chordal_env_t *env, ir_node *irn) ...@@ -206,7 +206,7 @@ static be_insn_t *chordal_scan_insn(be_chordal_env_t *env, ir_node *irn)
ie.ignore_colors = env->ignore_colors; ie.ignore_colors = env->ignore_colors;
ie.aenv = env->birg->main_env->arch_env; ie.aenv = env->birg->main_env->arch_env;
ie.obst = &env->obst; ie.obst = env->obst;
ie.cls = env->cls; ie.cls = env->cls;
return be_scan_insn(&ie, irn); return be_scan_insn(&ie, irn);
} }
...@@ -328,7 +328,7 @@ static ir_node *prepare_constr_insn(be_chordal_env_t *env, ir_node *irn) ...@@ -328,7 +328,7 @@ static ir_node *prepare_constr_insn(be_chordal_env_t *env, ir_node *irn)
} }
end: end:
obstack_free(&env->obst, insn); obstack_free(env->obst, insn);
return insn->next_insn; return insn->next_insn;
} }
...@@ -443,7 +443,7 @@ static ir_node *pre_process_constraints(be_chordal_alloc_env_t *alloc_env, ...@@ -443,7 +443,7 @@ static ir_node *pre_process_constraints(be_chordal_alloc_env_t *alloc_env,
the live sets may change. the live sets may change.
*/ */
// be_liveness_recompute(lv); // be_liveness_recompute(lv);
obstack_free(&env->obst, insn); obstack_free(env->obst, insn);
*the_insn = insn = chordal_scan_insn(env, insn->irn); *the_insn = insn = chordal_scan_insn(env, insn->irn);
/* /*
...@@ -480,7 +480,7 @@ static ir_node *handle_constraints(be_chordal_alloc_env_t *alloc_env, ir_node *i ...@@ -480,7 +480,7 @@ static ir_node *handle_constraints(be_chordal_alloc_env_t *alloc_env, ir_node *i
ir_node *perm = NULL; ir_node *perm = NULL;
int match_res, cost; int match_res, cost;
be_chordal_env_t *env = alloc_env->chordal_env; be_chordal_env_t *env = alloc_env->chordal_env;
void *base = obstack_base(&env->obst); void *base = obstack_base(env->obst);
be_insn_t *insn = chordal_scan_insn(env, irn); be_insn_t *insn = chordal_scan_insn(env, irn);
ir_node *res = insn->next_insn; ir_node *res = insn->next_insn;
int be_silent = *silent; int be_silent = *silent;
...@@ -658,7 +658,7 @@ static ir_node *handle_constraints(be_chordal_alloc_env_t *alloc_env, ir_node *i ...@@ -658,7 +658,7 @@ static ir_node *handle_constraints(be_chordal_alloc_env_t *alloc_env, ir_node *i
pmap_destroy(partners); pmap_destroy(partners);
end: end:
obstack_free(&env->obst, base); obstack_free(env->obst, base);
return res; return res;
} }
...@@ -724,7 +724,7 @@ static void pressure(ir_node *block, void *env_ptr) ...@@ -724,7 +724,7 @@ static void pressure(ir_node *block, void *env_ptr)
bitset_clear_all(live); bitset_clear_all(live);
/* Set up the border list in the block info */ /* Set up the border list in the block info */
head = obstack_alloc(&env->obst, sizeof(*head)); head = obstack_alloc(env->obst, sizeof(*head));
INIT_LIST_HEAD(head); INIT_LIST_HEAD(head);
assert(pmap_get(env->border_heads, block) == NULL); assert(pmap_get(env->border_heads, block) == NULL);
pmap_insert(env->border_heads, block, head); pmap_insert(env->border_heads, block, head);
......
...@@ -544,6 +544,7 @@ static void be_ra_chordal_main(be_irg_t *birg) ...@@ -544,6 +544,7 @@ static void be_ra_chordal_main(be_irg_t *birg)
be_options_t *main_opts = main_env->options; be_options_t *main_opts = main_env->options;
int j, m; int j, m;
be_chordal_env_t chordal_env; be_chordal_env_t chordal_env;
struct obstack obst;
BE_TIMER_INIT(main_opts); BE_TIMER_INIT(main_opts);
BE_TIMER_PUSH(ra_timer.t_other); BE_TIMER_PUSH(ra_timer.t_other);
...@@ -552,6 +553,7 @@ static void be_ra_chordal_main(be_irg_t *birg) ...@@ -552,6 +553,7 @@ static void be_ra_chordal_main(be_irg_t *birg)
be_assure_dom_front(birg); be_assure_dom_front(birg);
be_assure_liveness(birg); be_assure_liveness(birg);
chordal_env.obst = &obst;
chordal_env.opts = &options; chordal_env.opts = &options;
chordal_env.irg = irg; chordal_env.irg = irg;
chordal_env.birg = birg; chordal_env.birg = birg;
...@@ -559,7 +561,7 @@ static void be_ra_chordal_main(be_irg_t *birg) ...@@ -559,7 +561,7 @@ static void be_ra_chordal_main(be_irg_t *birg)
chordal_env.ifg = NULL; chordal_env.ifg = NULL;
chordal_env.ignore_colors = NULL; chordal_env.ignore_colors = NULL;
obstack_init(&chordal_env.obst); obstack_init(&obst);
BE_TIMER_POP(ra_timer.t_prolog); BE_TIMER_POP(ra_timer.t_prolog);
...@@ -612,7 +614,7 @@ static void be_ra_chordal_main(be_irg_t *birg) ...@@ -612,7 +614,7 @@ static void be_ra_chordal_main(be_irg_t *birg)
lower_nodes_after_ra(birg, options.lower_perm_opt & BE_CH_LOWER_PERM_COPY ? 1 : 0); lower_nodes_after_ra(birg, options.lower_perm_opt & BE_CH_LOWER_PERM_COPY ? 1 : 0);
dump(BE_CH_DUMP_LOWER, irg, NULL, "-belower-after-ra", dump_ir_block_graph_sched); dump(BE_CH_DUMP_LOWER, irg, NULL, "-belower-after-ra", dump_ir_block_graph_sched);
obstack_free(&chordal_env.obst, NULL); obstack_free(&obst, NULL);
be_invalidate_liveness(birg); be_invalidate_liveness(birg);
BE_TIMER_POP(ra_timer.t_epilog); BE_TIMER_POP(ra_timer.t_epilog);
......
...@@ -57,7 +57,7 @@ struct border_t { ...@@ -57,7 +57,7 @@ struct border_t {
* Environment for each of the chordal register allocator phases * Environment for each of the chordal register allocator phases
*/ */
struct be_chordal_env_t { struct be_chordal_env_t {
struct obstack obst; /**< An obstack for temporary storage. */ struct obstack *obst; /**< An obstack for temporary storage. */
be_ra_chordal_opts_t *opts; /**< A pointer to the chordal ra options. */ be_ra_chordal_opts_t *opts; /**< A pointer to the chordal ra options. */
be_irg_t *birg; /**< Back-end IRG session. */ be_irg_t *birg; /**< Back-end IRG session. */
ir_graph *irg; /**< The graph under examination. */ ir_graph *irg; /**< The graph under examination. */
......
Markdown is supported
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