From patchwork Fri Mar 11 21:38:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Pop X-Patchwork-Id: 86461 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 7ABE5B6F93 for ; Sat, 12 Mar 2011 08:40:19 +1100 (EST) Received: (qmail 25175 invoked by alias); 11 Mar 2011 21:40:15 -0000 Received: (qmail 25118 invoked by uid 22791); 11 Mar 2011 21:40:11 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, SPF_NEUTRAL, TW_TM X-Spam-Check-By: sourceware.org Received: from tx2ehsobe004.messaging.microsoft.com (HELO TX2EHSOBE009.bigfish.com) (65.55.88.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 Mar 2011 21:39:51 +0000 Received: from mail24-tx2-R.bigfish.com (10.9.14.252) by TX2EHSOBE009.bigfish.com (10.9.40.29) with Microsoft SMTP Server id 14.1.225.8; Fri, 11 Mar 2011 21:39:49 +0000 Received: from mail24-tx2 (localhost.localdomain [127.0.0.1]) by mail24-tx2-R.bigfish.com (Postfix) with ESMTP id E024713203C2; Fri, 11 Mar 2011 21:39:48 +0000 (UTC) X-SpamScore: -14 X-BigFish: VS-14(zzbb2cK936eK154dM4015Lzz1202hzz8275bh8275dhz2ei87h668h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:ausb3twp01.amd.com; RD:none; EFVD:NLI X-FB-DOMAIN-IP-MATCH: fail Received: from mail24-tx2 (localhost.localdomain [127.0.0.1]) by mail24-tx2 (MessageSwitch) id 1299879573330051_3099; Fri, 11 Mar 2011 21:39:33 +0000 (UTC) Received: from TX2EHSMHS037.bigfish.com (unknown [10.9.14.254]) by mail24-tx2.bigfish.com (Postfix) with ESMTP id 5F0341310058; Fri, 11 Mar 2011 21:39:31 +0000 (UTC) Received: from ausb3twp01.amd.com (163.181.249.108) by TX2EHSMHS037.bigfish.com (10.9.99.137) with Microsoft SMTP Server id 14.1.225.8; Fri, 11 Mar 2011 21:39:28 +0000 X-M-MSG: Received: from sausexedgep02.amd.com (sausexedgep02-ext.amd.com [163.181.249.73]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 2E378102864A; Fri, 11 Mar 2011 15:39:23 -0600 (CST) Received: from sausexhtp01.amd.com (163.181.3.165) by sausexedgep02.amd.com (163.181.36.59) with Microsoft SMTP Server (TLS) id 8.3.106.1; Fri, 11 Mar 2011 15:46:10 -0600 Received: from storexhtp01.amd.com (172.24.4.3) by sausexhtp01.amd.com (163.181.3.165) with Microsoft SMTP Server (TLS) id 8.3.83.0; Fri, 11 Mar 2011 15:39:27 -0600 Received: from storexbh1.amd.com (10.1.1.17) by storexhtp01.amd.com (172.24.4.3) with Microsoft SMTP Server id 8.3.83.0; Fri, 11 Mar 2011 16:39:26 -0500 Received: from sausexmb1.amd.com ([163.181.3.156]) by storexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 11 Mar 2011 16:39:24 -0500 Received: from napoca ([10.236.48.32]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 11 Mar 2011 15:39:23 -0600 Received: by napoca (sSMTP sendmail emulation); Fri, 11 Mar 2011 15:38:51 -0600 From: Sebastian Pop To: CC: , Sebastian Pop Subject: [PATCH] Fix PR47127: call cloog_state_malloc and cloog_state_free only once. Date: Fri, 11 Mar 2011 15:38:49 -0600 Message-ID: <1299879529-9652-1-git-send-email-sebpop@gmail.com> MIME-Version: 1.0 X-OriginatorOrg: amd.com X-IsSubscribed: yes 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 Hi, we currently call cloog_state_malloc and cloog_state_free too many times. In CLooG-Parma, these functions contain the init and fini functions of PPL, and so calling these in the middle of graphite would finalize all the PPL data structures, leading to memory corruption. This patch fixes this problem. It passed make -k check RUNTESTFLAGS=graphite.exp with CLooG-ISL and CLooG-Parma (with only one ICE remaining as reported in http://gcc.gnu.org/PR47128 ). Full regstrap with CLooG-ISL in progress on amd64-linux. Ok for trunk? Thanks, Sebastian 2011-03-11 Sebastian Pop PR tree-optimization/47127 * graphite-clast-to-gimple.c (build_cloog_prog): Removed state parameter. (set_cloog_options): Same. (scop_to_clast): Same. (print_clast_stmt): Do not call cloog_state_malloc and cloog_state_free. (print_generated_program): Same. (gloog): Same. * graphite-clast-to-gimple.h (cloog_state): Declared. (scop_to_clast): Adjust declaration. * graphite.c (cloog_state): Defined here. (graphite_initialize): Call cloog_state_malloc. (graphite_finalize): Call cloog_state_free. --- gcc/ChangeLog | 17 +++++++++++++++++ gcc/graphite-clast-to-gimple.c | 37 +++++++++++++++---------------------- gcc/graphite-clast-to-gimple.h | 7 +++++-- gcc/graphite.c | 4 ++++ 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3f58172..76ebc1a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,20 @@ +2011-03-11 Sebastian Pop + + PR tree-optimization/47127 + * graphite-clast-to-gimple.c (build_cloog_prog): Removed state + parameter. + (set_cloog_options): Same. + (scop_to_clast): Same. + (print_clast_stmt): Do not call cloog_state_malloc and + cloog_state_free. + (print_generated_program): Same. + (gloog): Same. + * graphite-clast-to-gimple.h (cloog_state): Declared. + (scop_to_clast): Adjust declaration. + * graphite.c (cloog_state): Defined here. + (graphite_initialize): Call cloog_state_malloc. + (graphite_finalize): Call cloog_state_free. + 2011-03-02 Richard Sandiford PR rtl-optimization/47925 diff --git a/gcc/graphite-clast-to-gimple.c b/gcc/graphite-clast-to-gimple.c index 47a03d5..41356dc 100644 --- a/gcc/graphite-clast-to-gimple.c +++ b/gcc/graphite-clast-to-gimple.c @@ -1236,7 +1236,7 @@ init_cloog_input_file (int scop_number) static void build_cloog_prog (scop_p scop, CloogProgram *prog, - CloogOptions *options, CloogState *state ATTRIBUTE_UNUSED) + CloogOptions *options) { int i; int max_nb_loops = scop_max_loop_depth (scop); @@ -1249,7 +1249,7 @@ build_cloog_prog (scop_p scop, CloogProgram *prog, cloog_program_set_context (prog, new_Cloog_Domain_from_ppl_Pointset_Powerset (SCOP_CONTEXT (scop), - scop_nb_params (scop), state)); + scop_nb_params (scop), cloog_state)); nbs = unify_scattering_dimensions (scop); scaldims = (int *) xmalloc (nbs * (sizeof (int))); cloog_program_set_nb_scattdims (prog, nbs); @@ -1267,16 +1267,16 @@ build_cloog_prog (scop_p scop, CloogProgram *prog, continue; /* Build the new statement and its block. */ - stmt = cloog_statement_alloc (state, pbb_index (pbb)); + stmt = cloog_statement_alloc (cloog_state, pbb_index (pbb)); dom = new_Cloog_Domain_from_ppl_Pointset_Powerset (PBB_DOMAIN (pbb), scop_nb_params (scop), - state); + cloog_state); block = cloog_block_alloc (stmt, 0, NULL, pbb_dim_iter_domain (pbb)); cloog_statement_set_usr (stmt, pbb); /* Build loop list. */ { - CloogLoop *new_loop_list = cloog_loop_malloc (state); + CloogLoop *new_loop_list = cloog_loop_malloc (cloog_state); cloog_loop_set_next (new_loop_list, loop_list); cloog_loop_set_domain (new_loop_list, dom); cloog_loop_set_block (new_loop_list, block); @@ -1303,7 +1303,7 @@ build_cloog_prog (scop_p scop, CloogProgram *prog, scat = PBB_TRANSFORMED_SCATTERING (pbb); dom = new_Cloog_Scattering_from_ppl_Polyhedron (scat, scop_nb_params (scop), pbb_nb_scattering_transform (pbb), - state); + cloog_state); cloog_set_next_scattering (new_scattering, scattering); cloog_set_scattering (new_scattering, dom); @@ -1360,9 +1360,9 @@ build_cloog_prog (scop_p scop, CloogProgram *prog, /* Return the options that will be used in GLOOG. */ static CloogOptions * -set_cloog_options (CloogState *state ATTRIBUTE_UNUSED) +set_cloog_options (void) { - CloogOptions *options = cloog_options_malloc (state); + CloogOptions *options = cloog_options_malloc (cloog_state); /* Change cloog output language to C. If we do use FORTRAN instead, cloog will stop e.g. with "ERROR: unbounded loops not allowed in FORTRAN.", if @@ -1411,12 +1411,10 @@ set_cloog_options (CloogState *state ATTRIBUTE_UNUSED) void print_clast_stmt (FILE *file, struct clast_stmt *stmt) { - CloogState *state = cloog_state_malloc (); - CloogOptions *options = set_cloog_options (state); + CloogOptions *options = set_cloog_options (); clast_pprint (file, stmt, 0, options); cloog_options_free (options); - cloog_state_free (state); } /* Prints STMT to STDERR. */ @@ -1432,14 +1430,14 @@ debug_clast_stmt (struct clast_stmt *stmt) without a program. */ cloog_prog_clast -scop_to_clast (scop_p scop, CloogState *state) +scop_to_clast (scop_p scop) { - CloogOptions *options = set_cloog_options (state); + CloogOptions *options = set_cloog_options (); cloog_prog_clast pc; /* Connect new cloog prog generation to graphite. */ pc.prog = cloog_program_malloc (); - build_cloog_prog (scop, pc.prog, options, state); + build_cloog_prog (scop, pc.prog, options); pc.prog = cloog_program_generate (pc.prog, options); pc.stmt = cloog_clast_create (pc.prog, options); @@ -1452,10 +1450,9 @@ scop_to_clast (scop_p scop, CloogState *state) void print_generated_program (FILE *file, scop_p scop) { - CloogState *state = cloog_state_malloc (); - CloogOptions *options = set_cloog_options (state); + CloogOptions *options = set_cloog_options (); - cloog_prog_clast pc = scop_to_clast (scop, state); + cloog_prog_clast pc = scop_to_clast (scop); fprintf (file, " (prog: \n"); cloog_program_print (file, pc.prog); @@ -1506,13 +1503,11 @@ gloog (scop_p scop, htab_t bb_pbb_mapping) ifsese if_region = NULL; htab_t newivs_index, params_index; cloog_prog_clast pc; - CloogState *state; - state = cloog_state_malloc (); timevar_push (TV_GRAPHITE_CODE_GEN); gloog_error = false; - pc = scop_to_clast (scop, state); + pc = scop_to_clast (scop); if (dump_file && (dump_flags & TDF_DETAILS)) { @@ -1577,8 +1572,6 @@ gloog (scop_p scop, htab_t bb_pbb_mapping) num_no_dependency); } - cloog_state_free (state); - return !gloog_error; } #endif diff --git a/gcc/graphite-clast-to-gimple.h b/gcc/graphite-clast-to-gimple.h index cd3cbca..9d599d6 100644 --- a/gcc/graphite-clast-to-gimple.h +++ b/gcc/graphite-clast-to-gimple.h @@ -22,6 +22,9 @@ along with GCC; see the file COPYING3. If not see #define GCC_GRAPHITE_CLAST_TO_GIMPLE_H #include "graphite-cloog-util.h" + +extern CloogState *cloog_state; + /* Data structure for CLooG program representation. */ typedef struct cloog_prog_clast { @@ -35,10 +38,10 @@ typedef struct bb_pbb_def { basic_block bb; poly_bb_p pbb; -}bb_pbb_def; +} bb_pbb_def; extern bool gloog (scop_p, htab_t); -extern cloog_prog_clast scop_to_clast (scop_p, CloogState *); +extern cloog_prog_clast scop_to_clast (scop_p); extern void debug_clast_stmt (struct clast_stmt *); extern void print_clast_stmt (FILE *, struct clast_stmt *); diff --git a/gcc/graphite.c b/gcc/graphite.c index 70c3d46..b013447 100644 --- a/gcc/graphite.c +++ b/gcc/graphite.c @@ -54,6 +54,8 @@ along with GCC; see the file COPYING3. If not see #include "graphite-clast-to-gimple.h" #include "graphite-sese-to-poly.h" +CloogState *cloog_state; + /* Print global statistics to FILE. */ static void @@ -206,6 +208,7 @@ graphite_initialize (void) ppl_initialized = ppl_initialize (); gcc_assert (ppl_initialized == 0); + cloog_state = cloog_state_malloc (); cloog_initialize (); if (dump_file && dump_flags) @@ -229,6 +232,7 @@ graphite_finalize (bool need_cfg_cleanup_p) tree_estimate_probability (); } + cloog_state_free (cloog_state); cloog_finalize (); ppl_finalize (); free_original_copy_tables ();