From patchwork Thu Aug 16 13:17:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 177988 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 666E72C009B for ; Thu, 16 Aug 2012 23:20:48 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1345728049; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=3SDg59/40c4AYvCqHsWv V2lLn9k=; b=nRTwptCFaDbP4Bnd3UVQUTiXrtgX3R2nePNW4ZlDpGbq49Ajhbra 6m19Xv5+vvuvHej42pRCVSeRmdrjaw4nFwLLVjHwIn0nfsKKdY6p5InPJ25SbJmT IEsDirgcrdjqOfRiwAi1DOnES1vNpRt8FUk1BTD4enDg6MUfDN7WQSg= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=fm+BaLLGeYu2KSpbBrmsbJQOZfX/6h731lKY309WBeQgeigjjvnO8mls5AZgQG rDRmuKkatmQrJT/YOifebI9+i0gyo8K1I+zqAn/RHt93ZHD9sgFEO1XN3HQ3YLUo yuod0bBiDORD12McnyKzo/m4Ez7AE5nTynuRsBF2M++cM=; Received: (qmail 7277 invoked by alias); 16 Aug 2012 13:20:43 -0000 Received: (qmail 7260 invoked by uid 22791); 16 Aug 2012 13:20:40 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, TW_TM X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Aug 2012 13:20:21 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 0B373A2111 for ; Thu, 16 Aug 2012 15:20:20 +0200 (CEST) Date: Thu, 16 Aug 2012 15:17:57 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix memleaks obvious from PR54146 Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This fixes some memleaks which look obvious when looking at -fmem-report of PR54146. Most important the tree-ssa-loop-im.c leak. Bootstrap and regtest ongoing on x86_64-unknown-linux-gnu. Richard. 2012-08-16 Richard Guenther PR middle-end/54146 * tree-ssa-loop-niter.c (find_loop_niter_by_eval): Free the exit vector. * ipa-pure-const.c (analyze_function): Use FOR_EACH_LOOP_BREAK. * cfgloop.h (FOR_EACH_LOOP_BREAK): Fix. * tree-ssa-structalias.c (handle_lhs_call): Properly free rhsc. * tree-into-ssa.c (get_ssa_name_ann): Allocate info only when needed. * tree-ssa-loop-im.c (analyze_memory_references): Adjust. (tree_ssa_lim_finalize): Free all mem_refs. * tree-ssa-sccvn.c (extract_and_process_scc_for_name): Free scc when bailing out. * modulo-sched.c (sms_schedule): Use FOR_EACH_LOOP_BREAK. * ira-build.c (loop_with_complex_edge_p): Free loop exit vector. * graphite-sese-to-poly.c (scop_ivs_can_be_represented): Use FOR_EACH_LOOP_BREAK. Index: gcc/tree-ssa-loop-niter.c =================================================================== --- gcc/tree-ssa-loop-niter.c (revision 190442) +++ gcc/tree-ssa-loop-niter.c (working copy) @@ -2287,7 +2287,10 @@ find_loop_niter_by_eval (struct loop *lo /* Loops with multiple exits are expensive to handle and less important. */ if (!flag_expensive_optimizations && VEC_length (edge, exits) > 1) - return chrec_dont_know; + { + VEC_free (edge, heap, exits); + return chrec_dont_know; + } FOR_EACH_VEC_ELT (edge, exits, i, ex) { Index: gcc/ipa-pure-const.c =================================================================== --- gcc/ipa-pure-const.c (revision 190442) +++ gcc/ipa-pure-const.c (working copy) @@ -802,7 +802,7 @@ end: if (dump_file) fprintf (dump_file, " can not prove finiteness of loop %i\n", loop->num); l->looping =true; - break; + FOR_EACH_LOOP_BREAK (li); } scev_finalize (); } Index: gcc/cfgloop.h =================================================================== --- gcc/cfgloop.h (revision 190442) +++ gcc/cfgloop.h (working copy) @@ -649,7 +649,7 @@ fel_init (loop_iterator *li, loop_p *loo #define FOR_EACH_LOOP_BREAK(LI) \ { \ - VEC_free (int, heap, (LI)->to_visit); \ + VEC_free (int, heap, (LI).to_visit); \ break; \ } Index: gcc/tree-ssa-structalias.c =================================================================== --- gcc/tree-ssa-structalias.c (revision 190442) +++ gcc/tree-ssa-structalias.c (working copy) @@ -3868,9 +3868,11 @@ handle_lhs_call (gimple stmt, tree lhs, tmpc.offset = 0; tmpc.type = ADDRESSOF; VEC_safe_push (ce_s, heap, rhsc, &tmpc); + process_all_all_constraints (lhsc, rhsc); + VEC_free (ce_s, heap, rhsc); } - - process_all_all_constraints (lhsc, rhsc); + else + process_all_all_constraints (lhsc, rhsc); VEC_free (ce_s, heap, lhsc); } Index: gcc/tree-into-ssa.c =================================================================== --- gcc/tree-into-ssa.c (revision 190442) +++ gcc/tree-into-ssa.c (working copy) @@ -312,22 +312,21 @@ get_ssa_name_ann (tree name) unsigned len = VEC_length (ssa_name_info_p, info_for_ssa_name); struct ssa_name_info *info; + /* Re-allocate the vector at most once per update/into-SSA. */ if (ver >= len) - { - unsigned old_len = VEC_length (ssa_name_info_p, info_for_ssa_name); - unsigned new_len = num_ssa_names; + VEC_safe_grow_cleared (ssa_name_info_p, heap, + info_for_ssa_name, num_ssa_names); - VEC_reserve (ssa_name_info_p, heap, info_for_ssa_name, - new_len - old_len); - while (len++ < new_len) - { - struct ssa_name_info *info = XCNEW (struct ssa_name_info); - info->age = current_info_for_ssa_name_age; - VEC_quick_push (ssa_name_info_p, info_for_ssa_name, info); - } + /* But allocate infos lazily. */ + info = VEC_index (ssa_name_info_p, info_for_ssa_name, ver); + if (!info) + { + info = XCNEW (struct ssa_name_info); + info->age = current_info_for_ssa_name_age; + info->info.need_phi_state = NEED_PHI_STATE_UNKNOWN; + VEC_replace (ssa_name_info_p, info_for_ssa_name, ver, info); } - info = VEC_index (ssa_name_info_p, info_for_ssa_name, ver); if (info->age < current_info_for_ssa_name_age) { info->age = current_info_for_ssa_name_age; Index: gcc/tree-ssa-loop-im.c =================================================================== --- gcc/tree-ssa-loop-im.c (revision 190442) +++ gcc/tree-ssa-loop-im.c (working copy) @@ -1486,9 +1486,8 @@ free_mem_ref_locs (mem_ref_locs_p accs) /* A function to free the mem_ref object OBJ. */ static void -memref_free (void *obj) +memref_free (struct mem_ref *mem) { - struct mem_ref *const mem = (struct mem_ref *) obj; unsigned i; mem_ref_locs_p accs; @@ -1728,8 +1727,7 @@ analyze_memory_references (void) unsigned i; bitmap empty; - memory_accesses.refs - = htab_create (100, memref_hash, memref_eq, memref_free); + memory_accesses.refs = htab_create (100, memref_hash, memref_eq, NULL); memory_accesses.refs_list = NULL; memory_accesses.refs_in_loop = VEC_alloc (bitmap, heap, number_of_loops ()); @@ -2617,6 +2615,7 @@ tree_ssa_lim_finalize (void) basic_block bb; unsigned i; bitmap b; + mem_ref_p ref; free_aux_for_edges (); @@ -2625,9 +2624,12 @@ tree_ssa_lim_finalize (void) pointer_map_destroy (lim_aux_data_map); - VEC_free (mem_ref_p, heap, memory_accesses.refs_list); htab_delete (memory_accesses.refs); + FOR_EACH_VEC_ELT (mem_ref_p, memory_accesses.refs_list, i, ref) + memref_free (ref); + VEC_free (mem_ref_p, heap, memory_accesses.refs_list); + FOR_EACH_VEC_ELT (bitmap, memory_accesses.refs_in_loop, i, b) BITMAP_FREE (b); VEC_free (bitmap, heap, memory_accesses.refs_in_loop); Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 190442) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -3665,6 +3665,8 @@ extract_and_process_scc_for_name (tree n fprintf (dump_file, "WARNING: Giving up with SCCVN due to " "SCC size %u exceeding %u\n", VEC_length (tree, scc), (unsigned)PARAM_VALUE (PARAM_SCCVN_MAX_SCC_SIZE)); + + VEC_free (tree, heap, scc); return false; } Index: gcc/modulo-sched.c =================================================================== --- gcc/modulo-sched.c (revision 190442) +++ gcc/modulo-sched.c (working copy) @@ -1413,7 +1413,7 @@ sms_schedule (void) if (dump_file) fprintf (dump_file, "SMS reached max limit... \n"); - break; + FOR_EACH_LOOP_BREAK (li); } if (dump_file) Index: gcc/ira-build.c =================================================================== --- gcc/ira-build.c (revision 190442) +++ gcc/ira-build.c (working copy) @@ -1846,15 +1846,21 @@ loop_with_complex_edge_p (struct loop *l edge_iterator ei; edge e; VEC (edge, heap) *edges; + bool res; FOR_EACH_EDGE (e, ei, loop->header->preds) if (e->flags & EDGE_EH) return true; edges = get_loop_exit_edges (loop); + res = false; FOR_EACH_VEC_ELT (edge, edges, i, e) if (e->flags & EDGE_COMPLEX) - return true; - return false; + { + res = true; + break; + } + VEC_free (edge, heap, edges); + return res; } #endif Index: gcc/graphite-sese-to-poly.c =================================================================== --- gcc/graphite-sese-to-poly.c (revision 190438) +++ gcc/graphite-sese-to-poly.c (working copy) @@ -3122,6 +3122,7 @@ scop_ivs_can_be_represented (scop_p scop loop_iterator li; loop_p loop; gimple_stmt_iterator psi; + bool result = true; FOR_EACH_LOOP (li, loop, 0) { @@ -3137,11 +3138,16 @@ scop_ivs_can_be_represented (scop_p scop if (TYPE_UNSIGNED (type) && TYPE_PRECISION (type) >= TYPE_PRECISION (long_long_integer_type_node)) - return false; + { + result = false; + break; + } } + if (!result) + FOR_EACH_LOOP_BREAK (li); } - return true; + return result; } /* Builds the polyhedral representation for a SESE region. */