From patchwork Wed Oct 18 13:33:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 827602 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-464444-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xWTZbqrH"; dkim-atps=neutral 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 3yHCgY3jfFz9t4c for ; Thu, 19 Oct 2017 00:33:28 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Y2pqDrwVKann9aO9ekG02FXkJe3xJ4W9nL9GmoRuuRHXx6hLjh1Ur b9jFrvJ/Tz5++Bi67goeBMWLTQSbGN447fUQ15gKyTWHqT9+A6QYi+Ol2AL+Noic BnnEWtlmkgGS8rSw79C42QdU9R0n8YT/4M7XFWUj9g+qj9A61mxjdk= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=AeQtfdbg2zeOndX/aKvmTdb5hOs=; b=xWTZbqrHK6ITLxpznIE+ WeTcnA7dmKXpzORldbR3Nu9OpezODGJ6XRfbu3YkOhnNtNrjN8eiiIiMSD8WYawN eAAoRRE9lE3YjMlZd8qxLmhticwGlf3UvRNrAS3X+hdEW88PHtiADgC2sS0Fwavi PmMMA2gPZ4suY+Ib0ruyc6g= Received: (qmail 12937 invoked by alias); 18 Oct 2017 13:33:17 -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 12388 invoked by uid 89); 18 Oct 2017 13:33:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Oct 2017 13:33:14 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6A2DEAAF1 for ; Wed, 18 Oct 2017 13:33:11 +0000 (UTC) Date: Wed, 18 Oct 2017 15:33:11 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH][GRAPHITE] More TLC Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 And using range-info to constain parameters. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2017-10-18 Richard Biener * graphite-isl-ast-to-gimple.c (translate_isl_ast_to_gimple::set_rename): Simplify. (translate_isl_ast_to_gimple::set_rename_for_each_def): Inline... (graphite_copy_stmts_from_block): ... here. (copy_bb_and_scalar_dependences): Simplify. (add_parameters_to_ivs_params): Canonicalize. (generate_entry_out_of_ssa_copies): Simplify. * graphite-sese-to-poly.c (extract_affine_name): Simplify by passing in ISL dimension. (parameter_index_in_region_1): Rename to ... (parameter_index_in_region): ... this. (extract_affine): Adjust assert, pass down parameter index. (add_param_constraints): Use range-info when available. (build_scop_context): Adjust. * sese.c (new_sese_info): Adjust. (free_sese_info): Likewise. * sese.h (bb_map_t, rename_map_t, phi_rename, init_back_edge_pair_t): Remove unused typedefs. (struct sese_info_t): Simplify rename_map, remove incomplete_phis. Index: gcc/graphite-isl-ast-to-gimple.c =================================================================== --- gcc/graphite-isl-ast-to-gimple.c (revision 253848) +++ gcc/graphite-isl-ast-to-gimple.c (working copy) @@ -195,7 +195,6 @@ class translate_isl_ast_to_gimple edge copy_bb_and_scalar_dependences (basic_block bb, edge next_e, vec iv_map); void set_rename (tree old_name, tree expr); - void set_rename_for_each_def (gimple *stmt); void gsi_insert_earliest (gimple_seq seq); bool codegen_error_p () const { return codegen_error; } @@ -932,25 +931,12 @@ set_rename (tree old_name, tree expr) { fprintf (dump_file, "[codegen] setting rename: old_name = "); print_generic_expr (dump_file, old_name); - fprintf (dump_file, ", new_name = "); + fprintf (dump_file, ", new decl = "); print_generic_expr (dump_file, expr); fprintf (dump_file, "\n"); } - - if (old_name == expr) - return; - - vec *renames = region->rename_map->get (old_name); - - if (renames) - renames->safe_push (expr); - else - { - vec r; - r.create (2); - r.safe_push (expr); - region->rename_map->put (old_name, r); - } + bool res = region->rename_map->put (old_name, expr); + gcc_assert (! res); } /* Return an iterator to the instructions comes last in the execution order. @@ -1132,21 +1118,6 @@ should_copy_to_new_region (gimple *stmt, return true; } -/* Create new names for all the definitions created by COPY and add replacement - mappings for each new name. */ - -void translate_isl_ast_to_gimple:: -set_rename_for_each_def (gimple *stmt) -{ - def_operand_p def_p; - ssa_op_iter op_iter; - FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, op_iter, SSA_OP_ALL_DEFS) - { - tree old_name = DEF_FROM_PTR (def_p); - create_new_def_for (old_name, stmt, def_p); - } -} - /* Duplicates the statements of basic block BB into basic block NEW_BB and compute the new induction variables according to the IV_MAP. */ @@ -1192,7 +1163,13 @@ graphite_copy_stmts_from_block (basic_bl gimple_duplicate_stmt_histograms (cfun, copy, cfun, stmt); /* Crete new names for each def in the copied stmt. */ - set_rename_for_each_def (copy); + def_operand_p def_p; + ssa_op_iter op_iter; + FOR_EACH_SSA_DEF_OPERAND (def_p, copy, op_iter, SSA_OP_ALL_DEFS) + { + tree old_name = DEF_FROM_PTR (def_p); + create_new_def_for (old_name, copy, def_p); + } if (codegen_error_p ()) return false; @@ -1244,17 +1221,14 @@ copy_bb_and_scalar_dependences (basic_bl continue; tree new_phi_def; - vec *renames = region->rename_map->get (res); - if (! renames || renames->is_empty ()) + tree *rename = region->rename_map->get (res); + if (! rename) { new_phi_def = create_tmp_reg (TREE_TYPE (res)); set_rename (res, new_phi_def); } else - { - gcc_assert (renames->length () == 1); - new_phi_def = (*renames)[0]; - } + new_phi_def = *rename; gassign *ass = gimple_build_assign (NULL_TREE, new_phi_def); create_new_def_for (res, ass, NULL); @@ -1291,17 +1265,14 @@ copy_bb_and_scalar_dependences (basic_bl continue; tree new_phi_def; - vec *renames = region->rename_map->get (res); - if (! renames || renames->is_empty ()) + tree *rename = region->rename_map->get (res); + if (! rename) { new_phi_def = create_tmp_reg (TREE_TYPE (res)); set_rename (res, new_phi_def); } else - { - gcc_assert (renames->length () == 1); - new_phi_def = (*renames)[0]; - } + new_phi_def = *rename; tree arg = PHI_ARG_DEF_FROM_EDGE (phi, e); if (TREE_CODE (arg) == SSA_NAME @@ -1336,13 +1307,14 @@ add_parameters_to_ivs_params (scop_p sco { sese_info_p region = scop->scop_info; unsigned nb_parameters = isl_set_dim (scop->param_context, isl_dim_param); - gcc_assert (nb_parameters == region->params.length ()); + gcc_assert (nb_parameters == sese_nb_params (region)); unsigned i; - for (i = 0; i < nb_parameters; i++) + tree param; + FOR_EACH_VEC_ELT (region->params, i, param) { isl_id *tmp_id = isl_set_get_dim_id (scop->param_context, isl_dim_param, i); - ip[tmp_id] = region->params[i]; + ip[tmp_id] = param; } } @@ -1417,10 +1389,10 @@ generate_entry_out_of_ssa_copies (edge f continue; /* When there's no out-of-SSA var registered do not bother to create one. */ - vec *renames = region->rename_map->get (res); - if (! renames || renames->is_empty ()) + tree *rename = region->rename_map->get (res); + if (! rename) continue; - tree new_phi_def = (*renames)[0]; + tree new_phi_def = *rename; gassign *ass = gimple_build_assign (new_phi_def, PHI_ARG_DEF_FROM_EDGE (phi, false_entry)); Index: gcc/graphite-sese-to-poly.c =================================================================== --- gcc/graphite-sese-to-poly.c (revision 253848) +++ gcc/graphite-sese-to-poly.c (working copy) @@ -142,11 +142,8 @@ isl_id_for_dr (scop_p s) /* Extract an affine expression from the ssa_name E. */ static isl_pw_aff * -extract_affine_name (scop_p s, tree e, __isl_take isl_space *space) +extract_affine_name (int dimension, __isl_take isl_space *space) { - isl_id *id = isl_id_for_ssa_name (s, e); - int dimension = isl_space_find_dim_by_id (space, isl_dim_param, id); - isl_id_free (id); isl_set *dom = isl_set_universe (isl_space_copy (space)); isl_aff *aff = isl_aff_zero_on_domain (isl_local_space_from_space (space)); aff = isl_aff_add_coefficient_si (aff, isl_dim_param, dimension, 1); @@ -211,17 +208,13 @@ wrap (isl_pw_aff *pwaff, unsigned width) Otherwise returns -1. */ static inline int -parameter_index_in_region_1 (tree name, sese_info_p region) +parameter_index_in_region (tree name, sese_info_p region) { int i; tree p; - - gcc_assert (TREE_CODE (name) == SSA_NAME); - FOR_EACH_VEC_ELT (region->params, i, p) if (p == name) return i; - return -1; } @@ -288,10 +281,13 @@ extract_affine (scop_p s, tree e, __isl_ break; case SSA_NAME: - gcc_assert (-1 != parameter_index_in_region_1 (e, s->scop_info) - || defined_in_sese_p (e, s->scop_info->region)); - res = extract_affine_name (s, e, space); - break; + { + gcc_assert (! defined_in_sese_p (e, s->scop_info->region)); + int dim = parameter_index_in_region (e, s->scop_info); + gcc_assert (dim != -1); + res = extract_affine_name (dim, space); + break; + } case INTEGER_CST: res = extract_affine_int (e, space); @@ -431,54 +427,40 @@ add_conditions_to_domain (poly_bb_p pbb) of P. */ static void -add_param_constraints (scop_p scop, graphite_dim_t p) +add_param_constraints (scop_p scop, graphite_dim_t p, tree parameter) { - tree parameter = scop->scop_info->params[p]; tree type = TREE_TYPE (parameter); - tree lb = NULL_TREE; - tree ub = NULL_TREE; + wide_int min, max; - if (POINTER_TYPE_P (type) || !TYPE_MIN_VALUE (type)) - lb = lower_bound_in_type (type, type); - else - lb = TYPE_MIN_VALUE (type); + gcc_assert (INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type)); - if (POINTER_TYPE_P (type) || !TYPE_MAX_VALUE (type)) - ub = upper_bound_in_type (type, type); + if (INTEGRAL_TYPE_P (type) + && get_range_info (parameter, &min, &max) == VR_RANGE) + ; else - ub = TYPE_MAX_VALUE (type); - - if (lb) { - isl_space *space = isl_set_get_space (scop->param_context); - isl_constraint *c; - isl_val *v; - - c = isl_inequality_alloc (isl_local_space_from_space (space)); - v = isl_val_int_from_wi (scop->isl_context, wi::to_widest (lb)); - v = isl_val_neg (v); - c = isl_constraint_set_constant_val (c, v); - c = isl_constraint_set_coefficient_si (c, isl_dim_param, p, 1); - - scop->param_context = isl_set_coalesce - (isl_set_add_constraint (scop->param_context, c)); + min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type)); + max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); } - if (ub) - { - isl_space *space = isl_set_get_space (scop->param_context); - isl_constraint *c; - isl_val *v; - - c = isl_inequality_alloc (isl_local_space_from_space (space)); - - v = isl_val_int_from_wi (scop->isl_context, wi::to_widest (ub)); - c = isl_constraint_set_constant_val (c, v); - c = isl_constraint_set_coefficient_si (c, isl_dim_param, p, -1); - - scop->param_context = isl_set_coalesce - (isl_set_add_constraint (scop->param_context, c)); - } + isl_space *space = isl_set_get_space (scop->param_context); + isl_constraint *c = isl_inequality_alloc (isl_local_space_from_space (space)); + isl_val *v = isl_val_int_from_wi (scop->isl_context, + widest_int::from (min, TYPE_SIGN (type))); + v = isl_val_neg (v); + c = isl_constraint_set_constant_val (c, v); + c = isl_constraint_set_coefficient_si (c, isl_dim_param, p, 1); + scop->param_context = isl_set_coalesce + (isl_set_add_constraint (scop->param_context, c)); + + space = isl_set_get_space (scop->param_context); + c = isl_inequality_alloc (isl_local_space_from_space (space)); + v = isl_val_int_from_wi (scop->isl_context, + widest_int::from (max, TYPE_SIGN (type))); + c = isl_constraint_set_constant_val (c, v); + c = isl_constraint_set_coefficient_si (c, isl_dim_param, p, -1); + scop->param_context = isl_set_coalesce + (isl_set_add_constraint (scop->param_context, c)); } /* Add a constrain to the ACCESSES polyhedron for the alias set of @@ -930,9 +912,8 @@ build_scop_context (scop_p scop) scop->param_context = isl_set_universe (space); - graphite_dim_t p; - for (p = 0; p < nbp; p++) - add_param_constraints (scop, p); + FOR_EACH_VEC_ELT (region->params, i, e) + add_param_constraints (scop, i, e); } /* Return true when loop A is nested in loop B. */ @@ -1224,7 +1205,7 @@ bool build_poly_scop (scop_p scop) { int old_err = isl_options_get_on_error (scop->isl_context); - isl_options_set_on_error (scop->isl_context, ISL_ON_ERROR_CONTINUE); + isl_options_set_on_error (scop->isl_context, ISL_ON_ERROR_ABORT); build_scop_context (scop); Index: gcc/sese.c =================================================================== --- gcc/sese.c (revision 253848) +++ gcc/sese.c (working copy) @@ -156,10 +156,8 @@ new_sese_info (edge entry, edge exit) region->liveout = NULL; region->debug_liveout = NULL; region->params.create (3); - region->rename_map = new rename_map_t; + region->rename_map = new hash_map ; region->bbs.create (3); - region->incomplete_phis.create (3); - return region; } @@ -173,14 +171,9 @@ free_sese_info (sese_info_p region) BITMAP_FREE (region->liveout); BITMAP_FREE (region->debug_liveout); - for (rename_map_t::iterator it = region->rename_map->begin (); - it != region->rename_map->end (); ++it) - (*it).second.release (); - delete region->rename_map; region->rename_map = NULL; region->bbs.release (); - region->incomplete_phis.release (); XDELETE (region); } Index: gcc/sese.h =================================================================== --- gcc/sese.h (revision 253848) +++ gcc/sese.h (working copy) @@ -22,13 +22,7 @@ along with GCC; see the file COPYING3. #ifndef GCC_SESE_H #define GCC_SESE_H -typedef hash_map > bb_map_t; -typedef hash_map > rename_map_t; typedef struct ifsese_s *ifsese; -/* First phi is the new codegenerated phi second one is original phi. */ -typedef std::pair phi_rename; -/* First edge is the init edge and second is the back edge w.r.t. a loop. */ -typedef std::pair init_back_edge_pair_t; /* A Single Entry, Single Exit region is a part of the CFG delimited by two edges. */ @@ -91,18 +85,12 @@ typedef struct sese_info_t /* Parameters used within the SCOP. */ vec params; - /* Maps an old name to one or more new names. When there are several new - names, one has to select the definition corresponding to the immediate - dominator. */ - rename_map_t *rename_map; + /* Maps an old name to a new decl. */ + hash_map *rename_map; /* Basic blocks contained in this SESE. */ vec bbs; - /* A vector of phi nodes to be updated when all arguments are available. The - pair contains first the old_phi and second the new_phi. */ - vec incomplete_phis; - /* The condition region generated for this sese. */ ifsese if_region;