From: Martin Liska Date: Mon, 9 Nov 2015 15:45:59 +0000 (+0100) Subject: Fix memory leaks and use a pool_allocator X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=af121e828eb03233d731b25b590d1f7c5dd2693d;p=gcc.git Fix memory leaks and use a pool_allocator * gcc.c (record_temp_file): Release name string. * ifcvt.c (noce_convert_multiple_sets): Use auto_vec instead of vec. * lra-lives.c (free_live_range_list): Utilize lra_live_range_pool for allocation and deallocation. (create_live_range): Likewise. (copy_live_range): Likewise. (lra_merge_live_ranges): Likewise. (remove_some_program_points_and_update_live_ranges): Likewise. (lra_create_live_ranges_1): Release point_freq_vec that can be not freed from previous iteration of the function. * tree-eh.c (lower_try_finally_switch): Use auto_vec instead of vec. * tree-sra.c (sra_deinitialize): Release all vectors in base_access_vec. * tree-ssa-dom.c (free_dom_edge_info): Make the function extern. * tree-ssa-threadupdate.c (remove_ctrl_stmt_and_useless_edges): Release edge_info for a removed edge. (thread_through_all_blocks): Free region vector. * tree-ssa.h (free_dom_edge_info): Declare function extern. From-SVN: r230027 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9ee6c72d711..1d60b7084e0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,26 @@ +2015-11-09 Martin Liska + + * gcc.c (record_temp_file): Release name string. + * ifcvt.c (noce_convert_multiple_sets): Use auto_vec instead + of vec. + * lra-lives.c (free_live_range_list): Utilize + lra_live_range_pool for allocation and deallocation. + (create_live_range): Likewise. + (copy_live_range): Likewise. + (lra_merge_live_ranges): Likewise. + (remove_some_program_points_and_update_live_ranges): Likewise. + (lra_create_live_ranges_1): Release point_freq_vec that can + be not freed from previous iteration of the function. + * tree-eh.c (lower_try_finally_switch): Use auto_vec instead of + vec. + * tree-sra.c (sra_deinitialize): Release all vectors in + base_access_vec. + * tree-ssa-dom.c (free_dom_edge_info): Make the function extern. + * tree-ssa-threadupdate.c (remove_ctrl_stmt_and_useless_edges): + Release edge_info for a removed edge. + (thread_through_all_blocks): Free region vector. + * tree-ssa.h (free_dom_edge_info): Declare function extern. + 2015-11-09 Ilya Enkovich * optabs.c (expand_vec_cond_expr): Always get sign from type. diff --git a/gcc/gcc.c b/gcc/gcc.c index bbc9b23acdd..8bbf5be831a 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -2345,7 +2345,10 @@ record_temp_file (const char *filename, int always_delete, int fail_delete) struct temp_file *temp; for (temp = always_delete_queue; temp; temp = temp->next) if (! filename_cmp (name, temp->name)) - goto already1; + { + free (name); + goto already1; + } temp = XNEW (struct temp_file); temp->next = always_delete_queue; diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 59bda5e02c0..c830b3cb8c4 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -3101,12 +3101,12 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) rtx_code cond_code = GET_CODE (cond); /* The true targets for a conditional move. */ - vec targets = vNULL; + auto_vec targets; /* The temporaries introduced to allow us to not consider register overlap. */ - vec temporaries = vNULL; + auto_vec temporaries; /* The insns we've emitted. */ - vec unmodified_insns = vNULL; + auto_vec unmodified_insns; int count = 0; FOR_BB_INSNS (then_bb, insn) diff --git a/gcc/lra-lives.c b/gcc/lra-lives.c index 1655c4768c3..9453759a521 100644 --- a/gcc/lra-lives.c +++ b/gcc/lra-lives.c @@ -103,7 +103,7 @@ free_live_range_list (lra_live_range_t lr) while (lr != NULL) { next = lr->next; - delete lr; + lra_live_range_pool.remove (lr); lr = next; } } @@ -112,7 +112,7 @@ free_live_range_list (lra_live_range_t lr) static lra_live_range_t create_live_range (int regno, int start, int finish, lra_live_range_t next) { - lra_live_range_t p = new lra_live_range; + lra_live_range_t p = lra_live_range_pool.allocate (); p->regno = regno; p->start = start; p->finish = finish; @@ -124,7 +124,7 @@ create_live_range (int regno, int start, int finish, lra_live_range_t next) static lra_live_range_t copy_live_range (lra_live_range_t r) { - return new lra_live_range (*r); + return new (lra_live_range_pool) lra_live_range (*r); } /* Copy live range list given by its head R and return the result. */ @@ -167,7 +167,7 @@ lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2) r1->start = r2->start; lra_live_range_t temp = r2; r2 = r2->next; - delete temp; + lra_live_range_pool.remove (temp); } else { @@ -1081,7 +1081,7 @@ remove_some_program_points_and_update_live_ranges (void) } prev_r->start = r->start; prev_r->next = next_r; - delete r; + lra_live_range_pool.remove (r); } } } @@ -1240,7 +1240,9 @@ lra_create_live_ranges_1 (bool all_p, bool dead_insn_p) dead_set = sparseset_alloc (max_regno); unused_set = sparseset_alloc (max_regno); curr_point = 0; - point_freq_vec.create (get_max_uid () * 2); + unsigned new_length = get_max_uid () * 2; + if (point_freq_vec.length () < new_length) + point_freq_vec.safe_grow (new_length); lra_point_freq = point_freq_vec.address (); int *post_order_rev_cfg = XNEWVEC (int, last_basic_block_for_fn (cfun)); int n_blocks_inverted = inverted_post_order_compute (post_order_rev_cfg); diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c index 617d6579948..9f68f31d091 100644 --- a/gcc/tree-eh.c +++ b/gcc/tree-eh.c @@ -1362,7 +1362,7 @@ lower_try_finally_switch (struct leh_state *state, struct leh_tf_state *tf) int return_index, eh_index, fallthru_index; int nlabels, ndests, j, last_case_index; tree last_case; - vec case_label_vec; + auto_vec case_label_vec; gimple_seq switch_body = NULL; gimple *x; geh_else *eh_else; diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index a89630876c7..30aee19aae7 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -674,6 +674,12 @@ sra_deinitialize (void) assign_link_pool.release (); obstack_free (&name_obstack, NULL); + /* TODO: hash_map does not support traits that can release + value type of the hash_map. */ + for (hash_map >::iterator it = + base_access_vec->begin (); it != base_access_vec->end (); ++it) + (*it).second.release (); + delete base_access_vec; } diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 3887bbe1799..5cb26441b51 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -121,8 +121,8 @@ static void dump_dominator_optimization_stats (FILE *file, /* Free the edge_info data attached to E, if it exists. */ -static void -free_edge_info (edge e) +void +free_dom_edge_info (edge e) { struct edge_info *edge_info = (struct edge_info *)e->aux; @@ -142,7 +142,7 @@ allocate_edge_info (edge e) struct edge_info *edge_info; /* Free the old one, if it exists. */ - free_edge_info (e); + free_dom_edge_info (e); edge_info = XCNEW (struct edge_info); @@ -167,7 +167,7 @@ free_all_edge_infos (void) { FOR_EACH_EDGE (e, ei, bb->preds) { - free_edge_info (e); + free_dom_edge_info (e); e->aux = NULL; } } diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c index 184cf3402a9..c527206409a 100644 --- a/gcc/tree-ssa-threadupdate.c +++ b/gcc/tree-ssa-threadupdate.c @@ -290,7 +290,10 @@ remove_ctrl_stmt_and_useless_edges (basic_block bb, basic_block dest_bb) for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); ) { if (e->dest != dest_bb) - remove_edge (e); + { + free_dom_edge_info (e); + remove_edge (e); + } else ei_next (&ei); } @@ -2522,6 +2525,7 @@ thread_through_all_blocks (bool may_peel_loop_headers) delete_jump_thread_path (path); paths.unordered_remove (i); + free (region); } /* Remove from PATHS all the jump-threads starting with an edge already diff --git a/gcc/tree-ssa-threadupdate.h b/gcc/tree-ssa-threadupdate.h index 984b6c4d972..e0eb3f5c724 100644 --- a/gcc/tree-ssa-threadupdate.h +++ b/gcc/tree-ssa-threadupdate.h @@ -46,4 +46,5 @@ extern void register_jump_thread (vec *); extern void remove_jump_threads_including (edge); extern void delete_jump_thread_path (vec *); extern void remove_ctrl_stmt_and_useless_edges (basic_block, basic_block); +extern void free_dom_edge_info (edge); #endif