fix pr68692: reinstantiate the copy of internal parameters

Adding a testcase and reverting this patch:
[PATCH] remove parameter_rename_map

This map was used in the transition to the new scop detection: with the new scop
detection, we do not need this map anymore.

       * graphite-isl-ast-to-gimple.c (gcc_expression_from_isl_ast_expr_id):
       Remove use of parameter_rename_map.
       (copy_def): Remove.
       (copy_internal_parameters): Remove.
       (graphite_regenerate_ast_isl): Remove call to copy_internal_parameters.
       * sese.c (new_sese_info): Do not initialize parameter_rename_map.
       (free_sese_info): Do not free parameter_rename_map.
       (set_rename): Do not use parameter_rename_map.
       (rename_uses): Update call to set_rename.
       (graphite_copy_stmts_from_block): Do not use parameter_rename_map.
       * sese.h (parameter_rename_map_t): Remove.
       (struct sese_info_t): Remove field parameter_rename_map.

Co-Authored-By: Sebastian Pop <s.pop@samsung.com>

From-SVN: r232659
This commit is contained in:
Aditya Kumar 2016-01-21 02:14:01 +00:00 committed by Sebastian Pop
parent b920a04763
commit 1d198f097b
5 changed files with 195 additions and 1 deletions

View File

@ -1,3 +1,20 @@
2016-01-21 Aditya Kumar <aditya.k7@samsung.com>
Sebastian Pop <s.pop@samsung.com>
Revert commit r229783.
* graphite-isl-ast-to-gimple.c (gcc_expression_from_isl_ast_expr_id):
Remove use of parameter_rename_map.
(copy_def): Remove.
(copy_internal_parameters): Remove.
(graphite_regenerate_ast_isl): Remove call to copy_internal_parameters.
* sese.c (new_sese_info): Do not initialize parameter_rename_map.
(free_sese_info): Do not free parameter_rename_map.
(set_rename): Do not use parameter_rename_map.
(rename_uses): Update call to set_rename.
(graphite_copy_stmts_from_block): Do not use parameter_rename_map.
* sese.h (parameter_rename_map_t): Remove.
(struct sese_info_t): Remove field parameter_rename_map.
2016-01-21 Aditya Kumar <aditya.k7@samsung.com>
Sebastian Pop <s.pop@samsung.com>

View File

@ -527,7 +527,11 @@ gcc_expression_from_isl_ast_expr_id (tree type,
"Could not map isl_id to tree expression");
isl_ast_expr_free (expr_id);
tree t = res->second;
return fold_convert (type, t);
tree *val = region->parameter_rename_map->get(t);
if (!val)
val = &t;
return fold_convert (type, *val);
}
/* Converts an isl_ast_expr_int expression E to a GCC expression tree of
@ -1495,6 +1499,13 @@ translate_isl_ast_to_gimple::set_rename (tree old_name, tree expr)
r.safe_push (expr);
region->rename_map->put (old_name, r);
}
tree t;
int i;
/* For a parameter of a scop we don't want to rename it. */
FOR_EACH_VEC_ELT (region->params, i, t)
if (old_name == t)
region->parameter_rename_map->put(old_name, expr);
}
/* Return an iterator to the instructions comes last in the execution order.
@ -2755,6 +2766,14 @@ should_copy_to_new_region (gimple *stmt, sese_info_p region)
&& scev_analyzable_p (lhs, region->region))
return false;
/* Do not copy parameters that have been generated in the header of the
scop. */
if (is_gimple_assign (stmt)
&& (lhs = gimple_assign_lhs (stmt))
&& TREE_CODE (lhs) == SSA_NAME
&& region->parameter_rename_map->get(lhs))
return false;
return true;
}
@ -2820,6 +2839,25 @@ translate_isl_ast_to_gimple::graphite_copy_stmts_from_block (basic_block bb,
if (codegen_error_p ())
return false;
/* For each SSA_NAME in the parameter_rename_map rename their usage. */
ssa_op_iter iter;
use_operand_p use_p;
if (!is_gimple_debug (copy))
FOR_EACH_SSA_USE_OPERAND (use_p, copy, iter, SSA_OP_USE)
{
tree old_name = USE_FROM_PTR (use_p);
if (TREE_CODE (old_name) != SSA_NAME
|| SSA_NAME_IS_DEFAULT_DEF (old_name))
continue;
tree *new_expr = region->parameter_rename_map->get (old_name);
if (!new_expr)
continue;
replace_exp (use_p, *new_expr);
}
update_stmt (copy);
}
@ -3270,6 +3308,70 @@ translate_isl_ast_to_gimple::scop_to_isl_ast (scop_p scop, ivs_params &ip)
return ast_isl;
}
/* Copy def from sese REGION to the newly created TO_REGION. TR is defined by
DEF_STMT. GSI points to entry basic block of the TO_REGION. */
static void
copy_def (tree tr, gimple *def_stmt, sese_info_p region, sese_info_p to_region,
gimple_stmt_iterator *gsi)
{
if (!defined_in_sese_p (tr, region->region))
return;
ssa_op_iter iter;
use_operand_p use_p;
FOR_EACH_SSA_USE_OPERAND (use_p, def_stmt, iter, SSA_OP_USE)
{
tree use_tr = USE_FROM_PTR (use_p);
/* Do not copy parameters that have been generated in the header of the
scop. */
if (region->parameter_rename_map->get(use_tr))
continue;
gimple *def_of_use = SSA_NAME_DEF_STMT (use_tr);
if (!def_of_use)
continue;
copy_def (use_tr, def_of_use, region, to_region, gsi);
}
gimple *copy = gimple_copy (def_stmt);
gsi_insert_after (gsi, copy, GSI_NEW_STMT);
/* Create new names for all the definitions created by COPY and
add replacement mappings for each new name. */
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);
tree new_name = create_new_def_for (old_name, copy, def_p);
region->parameter_rename_map->put(old_name, new_name);
}
update_stmt (copy);
}
static void
copy_internal_parameters (sese_info_p region, sese_info_p to_region)
{
/* For all the parameters which definitino is in the if_region->false_region,
insert code on true_region (if_region->true_region->entry). */
int i;
tree tr;
gimple_stmt_iterator gsi = gsi_start_bb(to_region->region.entry->dest);
FOR_EACH_VEC_ELT (region->params, i, tr)
{
// If def is not in region.
gimple *def_stmt = SSA_NAME_DEF_STMT (tr);
if (def_stmt)
copy_def (tr, def_stmt, region, to_region, &gsi);
}
}
/* GIMPLE Loop Generator: generates loops from STMT in GIMPLE form for
the given SCOP. Return true if code generation succeeded.
@ -3304,6 +3406,9 @@ graphite_regenerate_ast_isl (scop_p scop)
loop_p context_loop = region->region.entry->src->loop_father;
/* Copy all the parameters which are defined in the region. */
copy_internal_parameters(if_region->false_region, if_region->true_region);
edge e = single_succ_edge (if_region->true_region->region.entry->dest);
basic_block bb = split_edge (e);

View File

@ -181,10 +181,12 @@ new_sese_info (edge entry, edge exit)
region->loop_nest.create (3);
region->params.create (3);
region->rename_map = new rename_map_t;
region->parameter_rename_map = new parameter_rename_map_t;
region->copied_bb_map = new bb_map_t;
region->bbs.create (3);
region->incomplete_phis.create (3);
return region;
}
@ -205,9 +207,11 @@ free_sese_info (sese_info_p region)
(*it).second.release ();
delete region->rename_map;
delete region->parameter_rename_map;
delete region->copied_bb_map;
region->rename_map = NULL;
region->parameter_rename_map = NULL;
region->copied_bb_map = NULL;
region->bbs.release ();

View File

@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see
#ifndef GCC_SESE_H
#define GCC_SESE_H
typedef hash_map<tree, tree> parameter_rename_map_t;
typedef hash_map<basic_block, vec<basic_block> > bb_map_t;
typedef hash_map<tree, vec<tree> > rename_map_t;
typedef struct ifsese_s *ifsese;
@ -85,6 +86,9 @@ typedef struct sese_info_t
dominator. */
rename_map_t *rename_map;
/* Parameters to be renamed. */
parameter_rename_map_t *parameter_rename_map;
/* Loops completely contained in this SESE. */
vec<loop_p> loop_nest;

View File

@ -0,0 +1,64 @@
! { dg-options "-floop-nest-optimize -O3" }
MODULE spme
INTEGER, PARAMETER :: dp=8
PRIVATE
PUBLIC :: get_patch
CONTAINS
SUBROUTINE get_patch ( part, box, green, npts, p, rhos, is_core, is_shell,&
unit_charge, charges, coeff, n )
INTEGER, POINTER :: box
REAL(KIND=dp), &
DIMENSION(-(n-1):n-1, 0:n-1), &
INTENT(IN) :: coeff
INTEGER, DIMENSION(3), INTENT(IN) :: npts
REAL(KIND=dp), DIMENSION(:, :, :), &
INTENT(OUT) :: rhos
REAL(KIND=dp) :: q
REAL(KIND=dp), DIMENSION(3) :: delta, r
CALL get_delta ( box, r, npts, delta, nbox )
CALL spme_get_patch ( rhos, nbox, delta, q, coeff )
END SUBROUTINE get_patch
SUBROUTINE spme_get_patch ( rhos, n, delta, q, coeff )
REAL(KIND=dp), DIMENSION(:, :, :), &
INTENT(OUT) :: rhos
REAL(KIND=dp), DIMENSION(3), INTENT(IN) :: delta
REAL(KIND=dp), INTENT(IN) :: q
REAL(KIND=dp), &
DIMENSION(-(n-1):n-1, 0:n-1), &
INTENT(IN) :: coeff
INTEGER, PARAMETER :: nmax = 12
REAL(KIND=dp), DIMENSION(3, -nmax:nmax) :: w_assign
REAL(KIND=dp), DIMENSION(3, 0:nmax-1) :: deltal
REAL(KIND=dp), DIMENSION(3, 1:nmax) :: f_assign
DO l = 1, n-1
deltal ( 3, l ) = deltal ( 3, l-1 ) * delta ( 3 )
END DO
DO j = -(n-1), n-1, 2
DO l = 0, n-1
w_assign ( 1, j ) = w_assign ( 1, j ) + &
coeff ( j, l ) * deltal ( 1, l )
END DO
f_assign (3, i ) = w_assign ( 3, j )
DO i2 = 1, n
DO i1 = 1, n
rhos ( i1, i2, i3 ) = r2 * f_assign ( 1, i1 )
END DO
END DO
END DO
END SUBROUTINE spme_get_patch
SUBROUTINE get_delta ( box, r, npts, delta, n )
INTEGER, POINTER :: box
REAL(KIND=dp), DIMENSION(3), INTENT(IN) :: r
INTEGER, DIMENSION(3), INTENT(IN) :: npts
REAL(KIND=dp), DIMENSION(3), INTENT(OUT) :: delta
INTEGER, DIMENSION(3) :: center
REAL(KIND=dp), DIMENSION(3) :: ca, grid_i, s
CALL real_to_scaled(s,r,box)
s = s - REAL ( NINT ( s ),KIND=dp)
IF ( MOD ( n, 2 ) == 0 ) THEN
ca ( : ) = REAL ( center ( : ) )
END IF
delta ( : ) = grid_i ( : ) - ca ( : )
END SUBROUTINE get_delta
END MODULE spme