From patchwork Thu Jul 17 14:08:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gareev X-Patchwork-Id: 371180 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 60D7B140175 for ; Fri, 18 Jul 2014 00:08:20 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=wrZzIEaegi+0b0Bbp9 gC1WNmup84OBDLqiP4ggmnLZ2JBA13pqeGzbtu9IDNRG5AioTA3vIXJu2bv14glS v2+RHgC86rN5pDWkHeVX97eg8YLIyDtjWQqEWRj2s1NBGBn6529X6gG9ivWsqNAM wOuSVt8Ke0/3HlfZMYr0QvW5w= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=oYk1xfbrkHjkTg+OkLZUvhDC n+k=; b=OW/dIJAHU8gv4XOlalTkkgduIjpD3nQg0yXyasvV39Igy3PUIHhRMrdy 03oo0PWIBTO7uy90oYOW4ogoWcDpM1BIeiJgowFCzCE6P7TOdfPeLLKzQZhL/iX6 lFCnLXhFiPYZlz3Z2xaGFS5dxEr06gBNhqe8EW/smm6Glw8EJ60= Received: (qmail 14546 invoked by alias); 17 Jul 2014 14:08:10 -0000 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 Received: (qmail 14511 invoked by uid 89); 17 Jul 2014 14:08:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f45.google.com Received: from mail-pa0-f45.google.com (HELO mail-pa0-f45.google.com) (209.85.220.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 17 Jul 2014 14:08:06 +0000 Received: by mail-pa0-f45.google.com with SMTP id eu11so3446648pac.32 for ; Thu, 17 Jul 2014 07:08:04 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.70.89.139 with SMTP id bo11mr27177176pdb.50.1405606084561; Thu, 17 Jul 2014 07:08:04 -0700 (PDT) Received: by 10.70.128.74 with HTTP; Thu, 17 Jul 2014 07:08:04 -0700 (PDT) In-Reply-To: <53C55264.7070404@grosser.es> References: <53C27B10.6050703@grosser.es> <53C55264.7070404@grosser.es> Date: Thu, 17 Jul 2014 20:08:04 +0600 Message-ID: Subject: Re: [GSoC] generation of Gimple code from isl_ast_node_user From: Roman Gareev To: Tobias Grosser Cc: Mircea Namolaru , gcc-patches@gcc.gnu.org > I see. Could you use vec_safe_grow_cleared(iv_map, loop_num) instead? > This shows probably better that you zero initialize the vector. If I am not mistaken, vec_safe_grow_cleared has the following declaration: vec_safe_grow_cleared (vec *&v, unsigned len CXX_MEM_STAT_INFO) Should we rewrite all the functions, which interact with iv_map? I've added test cases, which produce the following ISL code: isl-ast-gen-single-loop-1.c for (int c1 = 0; c1 <= 49; c1 += 1) S_3(c1); isl-ast-gen-single-loop-2.c for (int c1 = 0; c1 <= -n.0 + 69; c1 += 1) S_5(c1); isl-ast-gen-single-loop-3.c for (int c1 = 0; c1 < n.0; c1 += 1) S_5(c1); The second and the third one use arrays. I wanted to make them similar to the first one, but inability to handle blocks prevented this. For example, /* { dg-do run } */ /* { dg-options "-O2 -fgraphite-identity -fgraphite-code-generator=isl" } */ int n = 25; int foo () { int i, res; for (i = n, res = 0; i < 50; i++) res += i; return res; } extern void abort (); int main (void) { int res = foo (); if (res != 1225) abort (); return 0; } produces the following code: { S_6(); for (int c1 = 0; c1 <= -i + 49; c1 += 1) S_4(c1); } 2014-07-12 Roman Gareev gcc/ * graphite-isl-ast-to-gimple.c: Add inclusion of gimple-ssa.h, tree-into-ssa.h. (ivs_params_clear): (build_iv_mapping): New function. (translate_isl_ast_node_user): Likewise. (translate_isl_ast): Add calling of translate_isl_ast_node_user. gcc/testsuite/gcc.dg/graphite/ * isl-ast-gen-single-loop-1.c: New testcase. * isl-ast-gen-single-loop-2.c: New testcase. * isl-ast-gen-single-loop-3.c: New testcase. Index: gcc/graphite-isl-ast-to-gimple.c =================================================================== --- gcc/graphite-isl-ast-to-gimple.c (revision 212756) +++ gcc/graphite-isl-ast-to-gimple.c (working copy) @@ -51,6 +51,8 @@ #include "sese.h" #include "tree-ssa-loop-manip.h" #include "tree-scalar-evolution.h" +#include "gimple-ssa.h" +#include "tree-into-ssa.h" #include #ifdef HAVE_cloog @@ -541,6 +543,72 @@ return last_e; } +/* Inserts in iv_map a tuple (OLD_LOOP->num, NEW_NAME) for the induction + variables of the loops around GBB in SESE. + + FIXME: Instead of using a vec that maps each loop id to a possible + chrec, we could consider using a map that maps loop ids to the + corresponding tree expressions. */ + +static void +build_iv_mapping (vec iv_map, gimple_bb_p gbb, + __isl_keep isl_ast_expr *user_expr, ivs_params &ip, + sese region) +{ + gcc_assert (isl_ast_expr_get_type (user_expr) == isl_ast_expr_op && + isl_ast_expr_get_op_type (user_expr) == isl_ast_op_call); + int i; + isl_ast_expr *arg_expr; + for (i = 1; i < isl_ast_expr_get_op_n_arg (user_expr); i++) + { + arg_expr = isl_ast_expr_get_op_arg (user_expr, i); + tree type = *graphite_expression_size_type; + tree t = gcc_expression_from_isl_expression (type, arg_expr, ip); + loop_p old_loop = gbb_loop_at_index (gbb, region, i - 1); + iv_map[old_loop->num] = t; + } + +} + +/* Translates an isl_ast_node_user to Gimple. */ + +static edge +translate_isl_ast_node_user (__isl_keep isl_ast_node *node, + edge next_e, ivs_params &ip) +{ + gcc_assert (isl_ast_node_get_type (node) == isl_ast_node_user); + isl_ast_expr *user_expr = isl_ast_node_user_get_expr (node); + isl_ast_expr *name_expr = isl_ast_expr_get_op_arg (user_expr, 0); + gcc_assert (isl_ast_expr_get_type (name_expr) == isl_ast_expr_id); + isl_id *name_id = isl_ast_expr_get_id (name_expr); + poly_bb_p pbb = (poly_bb_p) isl_id_get_user (name_id); + gcc_assert (pbb); + gimple_bb_p gbb = PBB_BLACK_BOX (pbb); + vec iv_map; + isl_ast_expr_free (name_expr); + isl_id_free (name_id); + + gcc_assert (GBB_BB (gbb) != ENTRY_BLOCK_PTR_FOR_FN (cfun) && + "The entry block should not even appear within a scop"); + + loop_p loop = gbb_loop (gbb); + iv_map.create (loop->num + 1); + int i; + for (i = 0; i < loop->num + 1; i++) + iv_map.quick_push (NULL_TREE); + + build_iv_mapping (iv_map, gbb, user_expr, ip, SCOP_REGION (pbb->scop)); + isl_ast_expr_free (user_expr); + next_e = copy_bb_and_scalar_dependences (GBB_BB (gbb), + SCOP_REGION (pbb->scop), next_e, + iv_map, + &graphite_regenerate_error); + iv_map.release (); + mark_virtual_operands_for_renaming (cfun); + update_ssa (TODO_update_ssa); + return next_e; +} + /* Translates an ISL AST node NODE to GCC representation in the context of a SESE. */ @@ -561,7 +629,7 @@ return next_e; case isl_ast_node_user: - return next_e; + return translate_isl_ast_node_user (node, next_e, ip); case isl_ast_node_block: return next_e; Index: gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-1.c =================================================================== --- gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-1.c (revision 0) +++ gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-1.c (working copy) @@ -0,0 +1,28 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fgraphite-identity -fgraphite-code-generator=isl" } */ + +int n = 25; + +int +foo () +{ + int i, res; + + for (i = n, res = 0; i < 50; i++) + res += i; + + return res; +} + +extern void abort (); + +int +main (void) +{ + int res = foo (); + + if (res != 1225) + abort (); + + return 0; +} Index: gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-2.c =================================================================== --- gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-2.c (revision 0) +++ gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-2.c (working copy) @@ -0,0 +1,34 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fgraphite-identity -fgraphite-code-generator=isl" } */ +int n = 50; + +void +foo (int a[]) +{ + int i; + for (i = n - 20; i < 50; i++) + a[i] = i; +} + +int +array_sum (int a[]) +{ + int i; + int res = 0; + for(i = n - 20; i < n; i *= 2) + res += a[i]; + return res; +} + +extern void abort (); + +int +main (void) +{ + int a[50]; + foo (a); + int res = array_sum (a); + if (res != 30) + abort (); + return 0; +} Index: gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-3.c =================================================================== --- gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-3.c (revision 0) +++ gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-3.c (working copy) @@ -0,0 +1,34 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fgraphite-identity -fgraphite-code-generator=isl" } */ +int n = 50; + +void +foo (int a[]) +{ + int i; + for (i = 0; i < n; i++) + a[i] = i; +} + +int +array_sum (int a[]) +{ + int i; + int res = 0; + for(i = 1; i < n; i *= 2) + res += a[i]; + return res; +} + +extern void abort (); + +int +main (void) +{ + int a[50]; + foo (a); + int res = array_sum (a); + if (res != 63) + abort (); + return 0; +}