* [PATCH][varmap] Also handle simple reg replacements in out-of-ssa
@ 2007-11-13 17:51 Richard Guenther
0 siblings, 0 replies; only message in thread
From: Richard Guenther @ 2007-11-13 17:51 UTC (permalink / raw)
To: gcc-patches
This patch makes sure to also annotate vars during out-of-ssa if they
represent multiple names. It also splits common code into a function
and makes dumping honor flags such as -uid.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to
var-mappings-branch.
Richard.
2007-11-13 Richard Guenther <rguenther@suse.de>
* tree.h (ssa_varmap_exprmap_merge_name): Declare.
* tree-ssanames.c (ssa_varmap_process_copy_1): Use dump_flags
for dumping.
(ssa_varmap_add_var): Likewise.
(ssa_varmap_process_phi): Likewise.
(print_ssa_varmap): Likewise.
(ssa_varmap_exprmap_merge_name): New helper function, split
out from ...
* tree-outof-ssa.c (replace_use_variable): ... here. Use
it also for simple variable replacement.
* gcc.dg/tree-ssa/vars-6.c: New testcase.
Index: tree.h
===================================================================
*** tree.h (revision 130134)
--- tree.h (working copy)
*************** extern void ssa_varmap_process_phi (tree
*** 3913,3918 ****
--- 3913,3919 ----
void ssa_varmap_add_ref (tree);
extern bitmap ssa_varmap_exprmap_lookup (tree);
extern void ssa_varmap_exprmap_insert (tree, bitmap);
+ extern void ssa_varmap_exprmap_merge_name (tree expr, tree name);
extern void ssa_varmap_build_exprmap (tree *);
#ifdef BUFSIZ
extern void print_ssa_varmap (FILE *);
Index: tree-ssanames.c
===================================================================
*** tree-ssanames.c (revision 130134)
--- tree-ssanames.c (working copy)
*************** ssa_varmap_process_copy_1 (tree lhs, tre
*** 409,417 ****
if (dump_file && dump_flags & TDF_VARS)
{
fprintf (dump_file, "Processing copy relation ");
! print_generic_expr (dump_file, lhs, 0);
fprintf (dump_file, " = ");
! print_generic_expr (dump_file, rhs, 0);
fprintf (dump_file, "\n");
}
--- 409,417 ----
if (dump_file && dump_flags & TDF_VARS)
{
fprintf (dump_file, "Processing copy relation ");
! print_generic_expr (dump_file, lhs, dump_flags);
fprintf (dump_file, " = ");
! print_generic_expr (dump_file, rhs, dump_flags);
fprintf (dump_file, "\n");
}
*************** ssa_varmap_add_var (tree name, tree var)
*** 482,490 ****
if (dump_file && dump_flags & TDF_VARS)
{
fprintf (dump_file, "Adding variable ");
! print_generic_expr (dump_file, var, 0);
fprintf (dump_file, " to SSA_NAME ");
! print_generic_expr (dump_file, name, 0);
fprintf (dump_file, " map\n");
}
--- 482,490 ----
if (dump_file && dump_flags & TDF_VARS)
{
fprintf (dump_file, "Adding variable ");
! print_generic_expr (dump_file, var, dump_flags);
fprintf (dump_file, " to SSA_NAME ");
! print_generic_expr (dump_file, name, dump_flags);
fprintf (dump_file, " map\n");
}
*************** ssa_varmap_process_phi (tree stmt)
*** 527,533 ****
if (dump_file && dump_flags & TDF_VARS)
{
fprintf (dump_file, "Processing merge relation ");
! print_generic_expr (dump_file, stmt, 0);
fprintf (dump_file, "\n");
}
--- 527,533 ----
if (dump_file && dump_flags & TDF_VARS)
{
fprintf (dump_file, "Processing merge relation ");
! print_generic_expr (dump_file, stmt, dump_flags);
fprintf (dump_file, "\n");
}
*************** ssa_varmap_exprmap_insert (tree expr, bi
*** 628,633 ****
--- 628,664 ----
(*loc)->map = vars;
}
+ /* Merge vars from SSA_NAME NAME to EXPR. */
+
+ void
+ ssa_varmap_exprmap_merge_name (tree expr, tree name)
+ {
+ bitmap name_vars = ssa_varmap_lookup (name);
+ bitmap expr_vars = ssa_varmap_exprmap_lookup (expr);
+ tree var = SSA_NAME_VAR (name);
+
+ if (expr_vars && name_vars)
+ bitmap_ior_into (expr_vars, name_vars);
+ else if (expr_vars && !name_vars)
+ {
+ if (!DECL_ARTIFICIAL (var))
+ bitmap_set_bit (expr_vars, DECL_UID (var));
+ }
+ else if (!expr_vars && name_vars)
+ {
+ expr_vars = BITMAP_GGC_ALLOC ();
+ bitmap_copy (expr_vars, name_vars);
+ ssa_varmap_exprmap_insert (expr, expr_vars);
+ }
+ else if (expr != var
+ && !DECL_ARTIFICIAL (var))
+ {
+ expr_vars = BITMAP_GGC_ALLOC ();
+ bitmap_set_bit (expr_vars, DECL_UID (var));
+ ssa_varmap_exprmap_insert (expr, expr_vars);
+ }
+ }
+
/* Build a map from expressions that define ssa names *VALUES to
the variable bitmap. */
*************** print_ssa_varmap (FILE *file)
*** 679,692 ****
continue;
with_map++;
fprintf (file, " ");
! print_generic_expr (file, name, 0);
fprintf (file, ": ");
EXECUTE_IF_SET_IN_BITMAP (vars, 0, i, bi)
{
tree var = ssa_varmap_get_ref (i);
n++;
if (var)
! print_generic_expr (file, var, 0);
else
fprintf (file, "%u", i);
fprintf (file, " ");
--- 710,723 ----
continue;
with_map++;
fprintf (file, " ");
! print_generic_expr (file, name, dump_flags);
fprintf (file, ": ");
EXECUTE_IF_SET_IN_BITMAP (vars, 0, i, bi)
{
tree var = ssa_varmap_get_ref (i);
n++;
if (var)
! print_generic_expr (file, var, dump_flags);
else
fprintf (file, "%u", i);
fprintf (file, " ");
Index: testsuite/gcc.dg/tree-ssa/vars-6.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/vars-6.c (revision 0)
--- testsuite/gcc.dg/tree-ssa/vars-6.c (revision 0)
***************
*** 0 ****
--- 1,25 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -fdump-tree-optimized-vars" } */
+
+ inline int foo(int i, int k)
+ {
+ int j = i*k;
+ return j;
+ }
+ int foobar(int l)
+ {
+ int m = foo(l, l+1);
+ return m;
+ }
+
+ /* We want to retain the name j for i * k in foo and the name
+ m for (l + 1) * l in foobar. Questionably also the name j
+ for the latter value, as well as i for l and k for l + 1. */
+
+ /* We manage to do only k for l + 1 and m for (l + 1) * l in foobar. */
+
+ /* { dg-final { scan-tree-dump "k \\\* i E{ j }" "optimized" } } */
+ /* { dg-final { scan-tree-dump "l \\\+ 1 E{ k }" "optimized" } } */
+ /* { dg-final { scan-tree-dump "l E{ i l }" "optimized" { xfail *-*-* } } } */
+ /* { dg-final { scan-tree-dump "E{ m j }" "optimized" { xfail *-*-* } } } */
+ /* { dg-final { cleanup-tree-dump "optimized" } } */
Index: tree-outof-ssa.c
===================================================================
*** tree-outof-ssa.c (revision 130134)
--- tree-outof-ssa.c (working copy)
*************** replace_use_variable (var_map map, use_o
*** 559,578 ****
int version = SSA_NAME_VERSION (var);
if (expr[version])
{
- bitmap vars;
tree new_expr = GIMPLE_STMT_OPERAND (expr[version], 1);
SET_USE (p, new_expr);
/* For this replaced expression, record its names, if available. */
! vars = ssa_varmap_lookup (var);
! if (!vars
! && !DECL_ARTIFICIAL (SSA_NAME_VAR (var)))
! {
! vars = BITMAP_GGC_ALLOC ();
! bitmap_set_bit (vars, DECL_UID (SSA_NAME_VAR (var)));
! }
! if (vars)
! ssa_varmap_exprmap_insert (new_expr, vars);
/* Clear the stmt's RHS, or GC might bite us. */
GIMPLE_STMT_OPERAND (expr[version], 1) = NULL_TREE;
--- 559,569 ----
int version = SSA_NAME_VERSION (var);
if (expr[version])
{
tree new_expr = GIMPLE_STMT_OPERAND (expr[version], 1);
SET_USE (p, new_expr);
/* For this replaced expression, record its names, if available. */
! ssa_varmap_exprmap_merge_name (new_expr, var);
/* Clear the stmt's RHS, or GC might bite us. */
GIMPLE_STMT_OPERAND (expr[version], 1) = NULL_TREE;
*************** replace_use_variable (var_map map, use_o
*** 585,590 ****
--- 576,583 ----
{
SET_USE (p, new_var);
set_is_used (new_var);
+ /* For this replaced variable, record its names, if available. */
+ ssa_varmap_exprmap_merge_name (new_var, var);
return true;
}
return false;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-11-13 16:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-13 17:51 [PATCH][varmap] Also handle simple reg replacements in out-of-ssa Richard Guenther
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).