gcc/gcc/tree-ssa-ter.c

740 lines
23 KiB
C
Raw Normal View History

New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
/* Routines for performing Temporary Expression Replacement (TER) in SSA trees.
Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
Contributed by Andrew MacLeod <amacleod@redhat.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "diagnostic.h"
#include "bitmap.h"
#include "tree-flow.h"
#include "tree-dump.h"
#include "tree-ssa-live.h"
/* Temporary Expression Replacement (TER)
Replace SSA version variables during out-of-ssa with their defining
expression if there is only one use of the variable.
This pass is required in order for the RTL expansion pass to see larger
chunks of code. This allows it to make better choices on RTL pattern
selection. When expand is rewritten and merged with out-of-ssa, and
understands SSA, this should be eliminated.
A pass is made through the function, one block at a time. No cross block
information is tracked.
Variables which only have one use, and whose defining stmt is considered
a replaceable expression (see is_replaceable_p) are tracked to see whether
they can be replaced at their use location.
n_12 = C * 10
a_2 = b_5 + 6
v_9 = a_2 * n_12
if there are the only use of n_12 and a_2, TER will substitute in their
expressions in v_9, and end up with:
v_9 = (b_5 + 6) * (C * 10)
which will then have the ssa_name assigned to regular variables, and the
resulting code which will be passed ot the expander looks something like:
v = (b + 6) * (C * 10)
This requires ensuring that none of the variables used by the expression
change between the def point and where it is used. Furthermore, if any
of the ssa_names used in this expression are themselves replaceable, we
have to ensure none of that expressions' arguments change either.
Although SSA_NAMES themselves don't change, this pass is performed after
coalescing has coalesced different SSA_NAMES together, so there could be a
definition of an SSA_NAME which is coalesced with a use that causes a
problem. ie
PHI b_5 = <b_8(2), b_14(1)>
<...>
a_2 = b_5 + 6
b_8 = c_4 + 4
v_9 = a_2 * n_12
<...>
If b_5, b_8 and b_14 are all coalesced together...
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
The expression b_5 + 6 CANNOT replace the use in the statement defining v_9
because b_8 is in fact killing the value of b_5 since they share a partition
and will be assigned the same memory or register location.
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
TER implements this but stepping through the instructions in a block and
tracking potential expressions for replacement, and the partitions they are
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
dependent on. Expressions are represented by the SSA_NAME_VERSION of the
DEF on the LHS of a GIMPLE_MODIFY_STMT and the expression is the RHS.
When a stmt is determined to be a possible replacement expression, the
following steps are taken:
EXPR_DECL_UID bitmap is allocated and set to the base variable UID of the
def and any uses in the expression. non-NULL means the expression is being
tracked. The UID's themselves are used to prevent TER substitution into
accumulating sequences.
ie
x = x + y
x = x + z
x = x + w
etc.
this can result in very large expressions which don't accomplish anything
see PR tree-optimization/17549.
PARTITION_DEPENDENCIES is another bitmap array, and it has a bit set for any
partition which is used in the expression. This is primarily used to remove
an expression from the partition kill lists when a decision is made whether
to replace it or not. This is indexed by ssa version number as well, and
indicates a partition number. virtual operands are not tracked individually,
but they are summarized by an artificial partition called VIRTUAL_PARTITION.
This means a MAY or MUST def will kill *ALL* expressions that are dependent
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
on a virtual operand.
Note that the EXPR_DECL_UID and this bitmap represent very similar
information, but the info in one is not easy to obtain from the other.
KILL_LIST is yet another bitmap array, this time it is indexed by partition
number, and represents a list of active expressions which will will no
longer be valid if a definition into this partition takes place.
PARTITION_IN_USE is simply a bitmap which is used to track which partitions
currently have something in their kill list. This is used at the end of
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
a block to clear out the KILL_LIST bitmaps at the end of each block.
NEW_REPLACEABLE_DEPENDENCIES is used as a temporary place to store
dependencies which will be reused by the current definition. ALl the uses
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
on an expression are processed before anything else is done. If a use is
determined to be a replaceable expression AND the current stmt is also going
to be replaceable, all the dependencies of this replaceable use will be
picked up by the current stmt's expression. Rather than recreate them, they
are simply copied here and then copied into the new expression when it is
processed.
a_2 = b_5 + 6
v_8 = a_2 + c_4
a_2's expression 'b_5 + 6' is determined to be replaceable at the use
location. It is dependent on the partition 'b_5' is in. This is cached into
the NEW_REPLACEABLE_DEPENDENCIES bitmap. and when v_8 is examined for
replaceablility, it is a candidate, and it is dependent on the partition
b_5 is in *NOT* a_2, as well as c_4's partition.
if v_8 is also replaceable:
x_9 = v_8 * 5
x_9 is dependent on partitions b_5, and c_4
if a statement is found which has either of those partitions written to
before x_9 is used, then x_9 itself is NOT replaceable. */
/* Temporary Expression Replacement (TER) table information. */
typedef struct temp_expr_table_d
{
var_map map;
bitmap *partition_dependencies; /* Partitions expr is dependent on. */
tree *replaceable_expressions; /* Replacement expression table. */
bitmap *expr_decl_uids; /* Base uids of exprs. */
bitmap *kill_list; /* Expr's killed by a partition. */
int virtual_partition; /* Pseudo partition for virtual ops. */
bitmap partition_in_use; /* Partitions with kill entries. */
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
bitmap new_replaceable_dependencies; /* Holding place for pending dep's. */
int *num_in_part; /* # of ssa_names in a partition. */
} *temp_expr_table_p;
[multiple changes] 2006-12-11 Diego Novillo <dnovillo@redhat.com> * doc/tree-ssa.texi: Update documentation for virtual operands and the use of push_stmt_changes/pop_stmt_changes. * doc/invoke.texi: Remove documentation for params global-var-threshold. Update documentation on max-aliased-vops. * tree-into-ssa.c: Cleanup comments, variables and spacing in various functions. (regs_to_rename): Declare. (mem_syms_to_rename): Declare. (dump_update_ssa): Declare. (debug_update_ssa): Declare. (dump_names_replaced_by): Declare. (debug_names_replaced_by): Declare. (dump_def_blocks): Declare. (debug_def_blocks): Declare. (dump_defs_stack): Declare. (debug_defs_stack): Declare. (dump_currdefs): Declare. (debug_currdefs): Declare. (mark_def_sites): Do not handle virtual operands. (compute_idf): Rename from find_idf. Update users. (register_new_def): Make local. Convert second argument to 'tree'. Use BLOCK_DEFS_STACK directly. If pushing a non-register, also push the underlying symbol. (rewrite_stmt): Do not handle virtual operands. (dump_tree_ssa): Call dump_def_blocks, dump_defs_stack, dump_currdefs and dump_tree_ssa_stats. (dump_tree_ssa_stats): Also dump REPL_TBL. (replace_use): Remove. Update all users to call SET_USE instead. (rewrite_blocks): Move code to free memory to fini_ssa_renamer. (mark_def_site_blocks): Move initialization code to init_ssa_renamer. (init_ssa_renamer): New. (fini_ssa_renamer): New. (rewrite_into_ssa): Call them. (prepare_block_for_update): Process SSA_OP_ALL_USES first and SSA_OP_ALL_DEFS later. Do not process virtual operands separately. (dump_update_ssa): Call dump_decl_set. (init_update_ssa): Initialize regs_to_rename and mem_syms_to_rename. Call init_ssa_renamer. (delete_update_ssa): Call fini_ssa_renamer. Free blocks_with_phis_to_rewrite. (mark_sym_for_renaming): If the variable has sub-variables, also mark them. If the variable belongs to a partition, also mark it. (mark_set_for_renaming): Call mark_sym_for_renaming on every symbol in the set. (switch_virtuals_to_full_rewrite): Call mark_set_for_renaming. (update_ssa): Separate syms_to_rename into regs_to_rename and mem_syms_to_rename. * tree-dump.c (dump_options): Add TDF_MEMSYMS. * tree-pretty-print.c (debug_generic_expr): Add TDF_MEMSYMS. (debug_generic_stmt): Likewise. (debug_tree_chain): Likewise. (dump_symbols): New. (dump_generic_node): Check for TDF_MEMSYMS. Handle MEMORY_PARTITION_TAG. If the statement references memory and TDF_MEMSYMS is given, call dump_symbols. Indicate default names with (D). (dump_vops): Update for new virtual operator format. * tree.c (init_ttree): Add MEMORY_PARTITION_TAG to tree_contains_struct. (tree_code_size): Handle MEMORY_PARTITION_TAG. (tree_node_structure): Likewise. (needs_to_live_in_memory): Handle SSA names. * tree.h (MTAG_P): Likewise. (struct tree_memory_partition_tag): Declare. (MPT_SYMBOLS): Define. (union tree_node): Add field 'mpt'. * treestruct.def (TS_MEMORY_PARTITION_TAG): Define. * tree.def (MEMORY_PARTITION_TAG): Define. * tree-pass.h (TDF_MEMSYMS): Define. * params.h (GLOBAL_VAR_THRESHOLD): Remove. * tree-ssa-alias.c: Include pointer-set.h (struct alias_map_d): Remove fields total_alias_vops, grouped_p and may_aliases. Update all users. (struct mp_info_def): Declare. (mp_info_t): New type. (get_smt_for): Rename from get_tmt_for. Update all users. (add_may_alias): Add argument ALREADY_ADDED. If given, use it to avoid adding duplicate entries to alias sets. (replace_may_alias): Remove. Update all users. (total_alias_vops_cmp): Remove. Update all users. (group_aliases_into): Remove. Update all users. (tree_pointer_compare): Remove. Update all users. (compact_name_tags): Remove. Update all users. (group_aliases): Remove. Update all users. (mark_non_addressable): Move from tree-flow-inline.h. Remove the symbol from the partition holding it, if needed. (dump_mp_info): New. (debug_mp_info): New. (sort_mp_info): New. (create_partition_for): New. (rewrite_alias_set_for): New. (compute_memory_partitions): New. (compute_may_aliases): Call it. (init_alias_info): If computing aliases for the first time, mark every memory symbol for renaming. (have_common_aliases_p): New. (compute_flow_insensitive_aliasing): Call it. (setup_pointers_and_addressables): Do not cache num_referenced_vars. For register promoted symbols, mark their former partition for renaming. (maybe_create_global_var): Only create .GLOBAL_VAR if there are no call-clobbered variables and a mix of pure and non-pure functions were found. (may_alias_p): Tidy comments. (create_tag_raw): Remove unused variable new_type. (dump_alias_info): call dump_memory_partitions. (dump_points_to_info_for): Call dump_decl_set. (may_be_aliased): Tidy comments and formatting. * timevar.def (TV_MEMORY_PARTITIONING): Define. * tree-vectorizer.c (vect_memsyms_to_rename): Rename from vect_vnames_to_rename. Set DECL_UIDs instead of SSA name versions in it. (slpeel_update_phi_nodes_for_guard1): Ignore memory PHIs. * tree-vect-transform.c (vect_transform_loop): Call mark_set_for_renaming with vect_memsyms_to_rename. * tree-flow-inline.h (zero_imm_uses_p): New. (memory_partition): New. (set_memory_partition): New. (factoring_name_p): New. (symbol_mem_tag): New. Update every function that used to access the annotation directly. (set_symbol_mem_tag): Likewise. * tree-ssa-copy.c (may_propagate_copy): Allow copies between a partition and a symbol as long as the symbol belongs to the partition. (merge_alias_info): Ignore merge requests when memory partitions are involved. * tree-ssa.c (verify_ssa_name): Check that default definitions have empty defining statements. (verify_use): Remove argument IS_VIRTUAL. Don't call verify_ssa_name. (verify_phi_args): Call verify_ssa_name. (verify_flow_insensitive_alias_info): Handle MPTs. (verify_flow_sensitive_alias_info): Likewise. (verify_name_tags): Likewise. (verify_call_clobbering): Likewise. (verify_ssa): Check for VOPs only after aliasing information is available. Check virtuals and real operands separately. Call verify_ssa_name on every operand. (stmt_references_memory_p): Move to tree-ssa-operands.c. (walk_use_def_chains_1): Guard against NULL PHI arguments. * tree-ssa-operands.c (stmt_references_memory_p): Move from tree-ssa.c. (get_mpt_for): New. (dump_memory_partitions): New. (debug_memory_partitions): New. * tree-flow.h (struct var_ann_d): Add field mpt. (struct stmt_ann_d): Add bitfield references_memory. * Makefile.in (tree-ssa-structalias.o): Include pointer-set.h (tree-ssa-alias.o): Likewise. * tree-ssa-structalias.c: (update_alias_info): Use STORED_SYMS to determine which variables are being written to by the store operation. * tree-ssa-structalias.h (struct alias_info) <total_alias_vops>: Remove. Update all users. <written_vars>: Change to a pointer set. Update all users. <dereferenced_ptrs_store>: Likewise. <dereferenced_ptrs_load>: Likewise. (NUM_REFERENCES): Remove. Update all users. (NUM_REFERENCES_CLEAR): Remove. Update all users. (NUM_REFERENCES_INC): Remove. Update all users. (NUM_REFERENCES_SET): Remove. Update all users. * params.def (PARAM_GLOBAL_VAR_THRESHOLD): Remove. Update all users. (PARAM_MAX_ALIASED_VOPS): Set to 10. * tree-ssanames.c (make_ssa_name): Initialize SSA_NAME_IS_DEFAULT_DEF to 0. 2006-12-11 Aldy Hernandez <aldyh@redhat.com> * tree-ssa-dse.c (aggregate_vardecl_d): New. (dse_global_data): Add aggregate_vardecl field. (dse_possible_dead_store_p): New. Add prev_defvar variable. Allow immediate uses and previous immediate uses to differ if they are setting different parts of the whole. (get_aggregate_vardecl): New. (dse_record_partial_aggregate_store): New. (dse_whole_aggregate_clobbered_p): New. (dse_partial_kill_p): New. (dse_optimize_stmt): Abstract code checking a possible dead store into new function dse_possible_dead_store_p(). Call dse_maybe_record_aggregate_store(). When checking whether a STMT and its USE_STMT refer to the same memory address, check also for partial kills that clobber the whole. Move some variable definitions to the block where they are used. (aggregate_vardecl_hash): New. (aggregate_vardecl_eq): New. (aggregate_vardecl_free): New. (aggregate_whole_store_p): New. (tree_ssa_dse): Initialize and free aggregate_vardecl. Mark which aggregate stores we care about. 2006-12-11 Andrew Macleod <amacleod@redhat.com> * tree-ssa-operands.h (struct vuse_element_d): Declare. (vuse_element_t): Declare. (struct vuse_vec_d): Declare. (vuse_vec_p): Declare. (VUSE_VECT_NUM_ELEM): Define. (VUSE_VECT_ELEMENT_NC): Define. (VUSE_ELEMENT_PTR_NC): Define. (VUSE_ELEMENT_VAR_NC): Define. (VUSE_VECT_ELEMENT): Define. (VUSE_ELEMENT_PTR): Define. (VUSE_ELEMENT_VAR): Define. (struct maydef_optype_d) <use_var>: Remove. <use_ptr>: Remove. <usev>: Add. (struct vuse_optype_d) <kill_var>: Remove. <use_ptr>: Remove. <usev>: Add. (struct mustdef_optype_d) <kill_var>: Remove. <use_ptr>: Remove. <usev>: Add. (VUSE_OP_PTR): Add argument. Use VUSE_ELEMENT_PTR. (VUSE_OP): Add argument. Use VUSE_ELEMENT_PTR. (VUSE_NUM): Define. (VUSE_VECT): Define. (MAYDEF_OP_PTR): Add argument. Use VUSE_OP_PTR. (MAYDEF_OP): Add argument. Use VUSE_OP. (MAYDEF_NUM): Define. (MAYDEF_VECT): Define. (MUSTDEF_KILL_PTR): Use VUSE_OP_PTR. (MUSTDEF_KILL): Use VUSE_OP. (MUSTDEF_NUM): Define. (MUSTDEF_VECT): Define. (realloc_maydef): Declare. (realloc_vuse): Declare. (struct ssa_operand_iterator_d) <vuse_index>: Add. <mayuse_index>: Add. (LOADED_SYMS): Define. (STORED_SYMS): Define. (FOR_EACH_SSA_MUSTDEF_OPERAND): Call op_iter_next_mustdef. * tree-into-ssa.c: Adapt for multi-operand V_MAY_DEF and VUSE operators. * tree-pretty-print.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-flow-inline.h: Likewise. (op_iter_next_mustdef): New. * tree-ssa-operands.c: Likewise. (ALLOC_OPTYPE): Remove. Update all users. (alloc_def): New. (alloc_use): New. (alloc_maydef): New. (alloc_vuse): New. (alloc_mustdef): New. (realloc_maydef): New. (realloc_vuse): New. 2006-12-11 Aldy Hernandez <aldyh@redhat.com> * tree-ssa-operands.c: Remove build_v_must_defs. (init_ssa_operands): Delete build_v_must_defs. (finalize_ssa_v_must_def_ops): Remove. (finalize_ssa_v_must_defs): Remove. (finalize_ssa_stmt_operands): Do not call finalize_ssa_v_must_defs. (start_ssa_stmt_operands): Do not check build_v_must_defs. (append_v_must_def): Delete. (copy_virtual_operands): Do not copy V_MUST_DEFs. (get_modify_expr_operands): Remove reference to V_MUST_DEF from comment. Remove opf_kill_def. (build_ssa_operands): Remove references to v_must_defs. (copy_virtual_operands): Same. (copy_virtual_operands): Same. (fini_ssa_operands): Same. (free_ssa_operands): Same. (add_mustdef_op): Remove. Remove mustdef_optype_p. (alloc_mustdef): Remove. Remove references to V_MUST_DEFs in comment at top of file. (get_expr_operands): Remove opf_kill_def. (opf_kill_def): Remove. (add_virtual_operand): Remove opf_kill_def. (get_indirect_ref_operands): Same. (get_tmr_operands): Same. * tree-vectorizer.c (rename_variables_in_bb): Remove SSA_OP_ALL_KILLS. * tree-ssa-loop-manip.c (find_uses_to_rename_stmt): Remove SSA_OP_ALL_KILLS. (check_loop_closed_ssa_stmt): Same. * tree-ssa.c (verify_def): Remove V_MUST_DEF from comment. (verify_use): Same. (verify_ssa): Remove V_MUST_DEFs traces. (verify_ssa): Remove SSA_OP_ALL_KILLS. * tree-into-ssa.c (mark_def_sites): Change SSA_OP_VMUSTDEF to SSA_OP_VMAYDEF. (rewrite_update_stmt): Remove SSA_OP_VIRTUAL_KILLS. (rewrite_stmt): Remove SSA_OP_ALL_KILLS. * tree-ssa-operands.h (struct stmt_operands_d): Remove V_MUST_DEF references. (MUSTDEF_OPS): Remove. (SSA_OP_VMUSTDEF): Remove. (FOR_EACH_SSA_MUSTDEF_OPERAND): Remove. (struct mustdef_optype_d): Remove. Remove mustdef_optype_p. (struct stmt_operands_d): Remove mustdef_ops. (ssa_operand_iterator_d): Remove mustdefs and mustkills. (SSA_OP_VIRTUAL_DEFS): Remove SSA_OP_VMUSTDEF. (MUSTDEF_RESULT_PTR): Remove. (MUSTDEF_RESULT): Remove. (MUSTDEF_KILL_PTR): Remove. (MUSTDEF_KILL): Remove. (MUSTDEF_NUM): Remove. (MUSTDEF_VECT): Remove. (SSA_OP_VIRTUAL_KILLS): Remove. (SSA_OP_ALL_VIRTUALS): Remove SSA_OP_VIRTUAL_KILLS. (SSA_OP_VMUSTKILL): Remove. (SSA_OP_ALL_KILLS): Remove. (SSA_OP_ALL_OPERANDS): Remove SSA_OP_ALL_KILLS. * tree-flow-inline.h (op_iter_init_def): Remove SSA_OP_VIRTUAL_KILLS. (delink_stmt_imm_use): Remove SSA_OP_ALL_KILLS. * tree-ssa-pre.c (compute_rvuse_and_antic_safe): Remove SSA_OP_VIRTUAL_KILLS. * tree-ssa-loop-im.c (determine_max_movement): Remove SSA_OP_VIRTUAL_KILLS. (gather_mem_refs_stmt): Same. (gather_mem_refs_stmt): Same. * tree-ssa-dce.c (mark_really_necessary_kill_operand_phis): Delete. (perform_tree_ssa_dce): Remove call to mark_really_necessary_kill_operand_phis. * tree-flow-inline.h (op_iter_init): Remove setting of mustdefs and mustkills. (op_iter_next_use): Do not check mustkills. (op_iter_next_def): Do not check mustdefs. (op_iter_next_tree): Do not check mustkills or mustdefs. (clear_and_done_ssa_iter): Do not set mustdefs or mustkills. (op_iter_next_maymustdef): Do not check mustkills. (op_iter_init_must_and_may_def): Remove SSA_OP_VMUSTKILL. (op_iter_init_mustdef): Remove. * tree-ssa-live.c (create_ssa_var_map): Change SSA_OP_VMUSTDEF to SSA_OP_VMAYDEF. * tree-ssa-dse.c (dse_optimize_stmt): Remove SSA_OP_VMUSTDEF. * tree-ssa-ccp.c: Remove V_MUST_DEF traces from comments. (visit_assignment): Same. * tree-ssa-copy.c (copy_prop_visit_assignment): Same. * tree-sra.c (mark_all_v_defs_1): Remove V_MUST_DEF from comment. * tree-outof-ssa.c (check_replaceable): Remove SSA_OP_VMUSTDEF. * tree-pretty-print.c (dump_vops): Remove printing of V_MUST_DEF. Remove kill_p variable. * tree-dfa.c (struct dfa_stats_d): Remove num_v_must_defs. (dump_dfa_stats): Remove code related to V_MUST_DEFs. (collect_dfa_stats_r): Do not set num_v_must_defs. (mark_new_vars_to_rename): Remove v_must_defs_{before,after} code. * tree-into-ssa.c (mark_def_sites): Change SSA_OP_VMUSTKILL to SSA_OP_VMAYUSE. * tree-ssa-pre.c (compute_rvuse_and_antic_safe): Remove SSA_OP_VMUSTDEF and SSA_OP_VMUSTKILL. * tree-ssa-propagate.c (stmt_makes_single_store): Remove SSA_OP_VMUSTDEF. From-SVN: r119760
2006-12-12 02:48:51 +01:00
/* Used to indicate a dependency on VDEFs. */
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
#define VIRTUAL_PARTITION(table) (table->virtual_partition)
#ifdef ENABLE_CHECKING
extern void debug_ter (FILE *, temp_expr_table_p);
#endif
/* Create a new TER table for MAP. */
static temp_expr_table_p
new_temp_expr_table (var_map map)
{
temp_expr_table_p t;
unsigned x;
t = XNEW (struct temp_expr_table_d);
t->map = map;
t->partition_dependencies = XCNEWVEC (bitmap, num_ssa_names + 1);
t->expr_decl_uids = XCNEWVEC (bitmap, num_ssa_names + 1);
t->kill_list = XCNEWVEC (bitmap, num_var_partitions (map) + 1);
t->partition_in_use = BITMAP_ALLOC (NULL);
t->virtual_partition = num_var_partitions (map);
t->new_replaceable_dependencies = BITMAP_ALLOC (NULL);
t->replaceable_expressions = NULL;
t->num_in_part = XCNEWVEC (int, num_var_partitions (map));
for (x = 1; x < num_ssa_names; x++)
{
int p;
tree name = ssa_name (x);
if (!name)
continue;
p = var_to_partition (map, name);
if (p != NO_PARTITION)
t->num_in_part[p]++;
}
return t;
}
/* Free TER table T. If there are valid replacements, return the expression
vector. */
static tree *
free_temp_expr_table (temp_expr_table_p t)
{
tree *ret = NULL;
unsigned i;
#ifdef ENABLE_CHECKING
unsigned x;
for (x = 0; x <= num_var_partitions (t->map); x++)
gcc_assert (!t->kill_list[x]);
#endif
BITMAP_FREE (t->partition_in_use);
for (i = 0; i <= num_ssa_names; i++)
if (t->expr_decl_uids[i])
BITMAP_FREE (t->expr_decl_uids[i]);
free (t->expr_decl_uids);
free (t->kill_list);
free (t->partition_dependencies);
if (t->replaceable_expressions)
ret = t->replaceable_expressions;
free (t);
return ret;
}
/* Return TRUE if VERSION is to be replaced by an expression in TAB. */
static inline bool
version_to_be_replaced_p (temp_expr_table_p tab, int version)
{
if (!tab->replaceable_expressions)
return false;
return tab->replaceable_expressions[version] != NULL_TREE;
}
/* Add partition P to the list if partitions VERSION is dependent on. TAB is
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
the expression table */
static inline void
make_dependent_on_partition (temp_expr_table_p tab, int version, int p)
{
if (!tab->partition_dependencies[version])
tab->partition_dependencies[version] = BITMAP_ALLOC (NULL);
bitmap_set_bit (tab->partition_dependencies[version], p);
}
/* Add VER to the kill list for P. TAB is the expression table */
static inline void
add_to_partition_kill_list (temp_expr_table_p tab, int p, int ver)
{
if (!tab->kill_list[p])
{
tab->kill_list[p] = BITMAP_ALLOC (NULL);
bitmap_set_bit (tab->partition_in_use, p);
}
bitmap_set_bit (tab->kill_list[p], ver);
}
/* Remove VER from the partition kill list for P. TAB is the expression
table. */
static inline void
remove_from_partition_kill_list (temp_expr_table_p tab, int p, int version)
{
#ifdef ENABLE_CHECKING
gcc_assert (tab->kill_list[p]);
#endif
bitmap_clear_bit (tab->kill_list[p], version);
if (bitmap_empty_p (tab->kill_list[p]))
{
bitmap_clear_bit (tab->partition_in_use, p);
BITMAP_FREE (tab->kill_list[p]);
}
}
/* Add a dependency between the def of ssa VERSION and VAR. If VAR is
replaceable by an expression, add a dependence each of the elements of the
expression. These are contained in the new_replaceable list. TAB is the
expression table. */
static void
add_dependence (temp_expr_table_p tab, int version, tree var)
{
int i;
bitmap_iterator bi;
unsigned x;
i = SSA_NAME_VERSION (var);
if (version_to_be_replaced_p (tab, i))
{
if (!bitmap_empty_p (tab->new_replaceable_dependencies))
{
/* Version will now be killed by a write to any partition the
substituted expression would have been killed by. */
EXECUTE_IF_SET_IN_BITMAP (tab->new_replaceable_dependencies, 0, x, bi)
add_to_partition_kill_list (tab, x, version);
/* Rather than set partition_dependencies and in_use lists bit by
bit, simply OR in the new_replaceable_dependencies bits. */
if (!tab->partition_dependencies[version])
tab->partition_dependencies[version] = BITMAP_ALLOC (NULL);
bitmap_ior_into (tab->partition_dependencies[version],
tab->new_replaceable_dependencies);
bitmap_ior_into (tab->partition_in_use,
tab->new_replaceable_dependencies);
/* It is only necessary to add these once. */
bitmap_clear (tab->new_replaceable_dependencies);
}
}
else
{
i = var_to_partition (tab->map, var);
#ifdef ENABLE_CHECKING
gcc_assert (i != NO_PARTITION);
gcc_assert (tab->num_in_part[i] != 0);
#endif
/* Only dependencies on ssa_names which are coalesced with something need
to be tracked. Partitions with containing only a single SSA_NAME
*cannot* have their value changed. */
if (tab->num_in_part[i] > 1)
{
add_to_partition_kill_list (tab, i, version);
make_dependent_on_partition (tab, version, i);
}
}
}
/* Return TRUE if expression STMT is suitable for replacement. */
static inline bool
is_replaceable_p (tree stmt)
{
tree call_expr;
use_operand_p use_p;
tree def, use_stmt;
/* Only consider modify stmts. */
if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
return false;
/* If the statement may throw an exception, it cannot be replaced. */
if (tree_could_throw_p (stmt))
return false;
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
/* Punt if there is more than 1 def. */
def = SINGLE_SSA_TREE_OPERAND (stmt, SSA_OP_DEF);
if (!def)
return false;
/* Only consider definitions which have a single use. */
if (!single_imm_use (def, &use_p, &use_stmt))
return false;
/* If the use isn't in this block, it wont be replaced either. */
if (bb_for_stmt (use_stmt) != bb_for_stmt (stmt))
return false;
/* Used in this block, but at the TOP of the block, not the end. */
if (TREE_CODE (use_stmt) == PHI_NODE)
return false;
[multiple changes] 2006-12-11 Diego Novillo <dnovillo@redhat.com> * doc/tree-ssa.texi: Update documentation for virtual operands and the use of push_stmt_changes/pop_stmt_changes. * doc/invoke.texi: Remove documentation for params global-var-threshold. Update documentation on max-aliased-vops. * tree-into-ssa.c: Cleanup comments, variables and spacing in various functions. (regs_to_rename): Declare. (mem_syms_to_rename): Declare. (dump_update_ssa): Declare. (debug_update_ssa): Declare. (dump_names_replaced_by): Declare. (debug_names_replaced_by): Declare. (dump_def_blocks): Declare. (debug_def_blocks): Declare. (dump_defs_stack): Declare. (debug_defs_stack): Declare. (dump_currdefs): Declare. (debug_currdefs): Declare. (mark_def_sites): Do not handle virtual operands. (compute_idf): Rename from find_idf. Update users. (register_new_def): Make local. Convert second argument to 'tree'. Use BLOCK_DEFS_STACK directly. If pushing a non-register, also push the underlying symbol. (rewrite_stmt): Do not handle virtual operands. (dump_tree_ssa): Call dump_def_blocks, dump_defs_stack, dump_currdefs and dump_tree_ssa_stats. (dump_tree_ssa_stats): Also dump REPL_TBL. (replace_use): Remove. Update all users to call SET_USE instead. (rewrite_blocks): Move code to free memory to fini_ssa_renamer. (mark_def_site_blocks): Move initialization code to init_ssa_renamer. (init_ssa_renamer): New. (fini_ssa_renamer): New. (rewrite_into_ssa): Call them. (prepare_block_for_update): Process SSA_OP_ALL_USES first and SSA_OP_ALL_DEFS later. Do not process virtual operands separately. (dump_update_ssa): Call dump_decl_set. (init_update_ssa): Initialize regs_to_rename and mem_syms_to_rename. Call init_ssa_renamer. (delete_update_ssa): Call fini_ssa_renamer. Free blocks_with_phis_to_rewrite. (mark_sym_for_renaming): If the variable has sub-variables, also mark them. If the variable belongs to a partition, also mark it. (mark_set_for_renaming): Call mark_sym_for_renaming on every symbol in the set. (switch_virtuals_to_full_rewrite): Call mark_set_for_renaming. (update_ssa): Separate syms_to_rename into regs_to_rename and mem_syms_to_rename. * tree-dump.c (dump_options): Add TDF_MEMSYMS. * tree-pretty-print.c (debug_generic_expr): Add TDF_MEMSYMS. (debug_generic_stmt): Likewise. (debug_tree_chain): Likewise. (dump_symbols): New. (dump_generic_node): Check for TDF_MEMSYMS. Handle MEMORY_PARTITION_TAG. If the statement references memory and TDF_MEMSYMS is given, call dump_symbols. Indicate default names with (D). (dump_vops): Update for new virtual operator format. * tree.c (init_ttree): Add MEMORY_PARTITION_TAG to tree_contains_struct. (tree_code_size): Handle MEMORY_PARTITION_TAG. (tree_node_structure): Likewise. (needs_to_live_in_memory): Handle SSA names. * tree.h (MTAG_P): Likewise. (struct tree_memory_partition_tag): Declare. (MPT_SYMBOLS): Define. (union tree_node): Add field 'mpt'. * treestruct.def (TS_MEMORY_PARTITION_TAG): Define. * tree.def (MEMORY_PARTITION_TAG): Define. * tree-pass.h (TDF_MEMSYMS): Define. * params.h (GLOBAL_VAR_THRESHOLD): Remove. * tree-ssa-alias.c: Include pointer-set.h (struct alias_map_d): Remove fields total_alias_vops, grouped_p and may_aliases. Update all users. (struct mp_info_def): Declare. (mp_info_t): New type. (get_smt_for): Rename from get_tmt_for. Update all users. (add_may_alias): Add argument ALREADY_ADDED. If given, use it to avoid adding duplicate entries to alias sets. (replace_may_alias): Remove. Update all users. (total_alias_vops_cmp): Remove. Update all users. (group_aliases_into): Remove. Update all users. (tree_pointer_compare): Remove. Update all users. (compact_name_tags): Remove. Update all users. (group_aliases): Remove. Update all users. (mark_non_addressable): Move from tree-flow-inline.h. Remove the symbol from the partition holding it, if needed. (dump_mp_info): New. (debug_mp_info): New. (sort_mp_info): New. (create_partition_for): New. (rewrite_alias_set_for): New. (compute_memory_partitions): New. (compute_may_aliases): Call it. (init_alias_info): If computing aliases for the first time, mark every memory symbol for renaming. (have_common_aliases_p): New. (compute_flow_insensitive_aliasing): Call it. (setup_pointers_and_addressables): Do not cache num_referenced_vars. For register promoted symbols, mark their former partition for renaming. (maybe_create_global_var): Only create .GLOBAL_VAR if there are no call-clobbered variables and a mix of pure and non-pure functions were found. (may_alias_p): Tidy comments. (create_tag_raw): Remove unused variable new_type. (dump_alias_info): call dump_memory_partitions. (dump_points_to_info_for): Call dump_decl_set. (may_be_aliased): Tidy comments and formatting. * timevar.def (TV_MEMORY_PARTITIONING): Define. * tree-vectorizer.c (vect_memsyms_to_rename): Rename from vect_vnames_to_rename. Set DECL_UIDs instead of SSA name versions in it. (slpeel_update_phi_nodes_for_guard1): Ignore memory PHIs. * tree-vect-transform.c (vect_transform_loop): Call mark_set_for_renaming with vect_memsyms_to_rename. * tree-flow-inline.h (zero_imm_uses_p): New. (memory_partition): New. (set_memory_partition): New. (factoring_name_p): New. (symbol_mem_tag): New. Update every function that used to access the annotation directly. (set_symbol_mem_tag): Likewise. * tree-ssa-copy.c (may_propagate_copy): Allow copies between a partition and a symbol as long as the symbol belongs to the partition. (merge_alias_info): Ignore merge requests when memory partitions are involved. * tree-ssa.c (verify_ssa_name): Check that default definitions have empty defining statements. (verify_use): Remove argument IS_VIRTUAL. Don't call verify_ssa_name. (verify_phi_args): Call verify_ssa_name. (verify_flow_insensitive_alias_info): Handle MPTs. (verify_flow_sensitive_alias_info): Likewise. (verify_name_tags): Likewise. (verify_call_clobbering): Likewise. (verify_ssa): Check for VOPs only after aliasing information is available. Check virtuals and real operands separately. Call verify_ssa_name on every operand. (stmt_references_memory_p): Move to tree-ssa-operands.c. (walk_use_def_chains_1): Guard against NULL PHI arguments. * tree-ssa-operands.c (stmt_references_memory_p): Move from tree-ssa.c. (get_mpt_for): New. (dump_memory_partitions): New. (debug_memory_partitions): New. * tree-flow.h (struct var_ann_d): Add field mpt. (struct stmt_ann_d): Add bitfield references_memory. * Makefile.in (tree-ssa-structalias.o): Include pointer-set.h (tree-ssa-alias.o): Likewise. * tree-ssa-structalias.c: (update_alias_info): Use STORED_SYMS to determine which variables are being written to by the store operation. * tree-ssa-structalias.h (struct alias_info) <total_alias_vops>: Remove. Update all users. <written_vars>: Change to a pointer set. Update all users. <dereferenced_ptrs_store>: Likewise. <dereferenced_ptrs_load>: Likewise. (NUM_REFERENCES): Remove. Update all users. (NUM_REFERENCES_CLEAR): Remove. Update all users. (NUM_REFERENCES_INC): Remove. Update all users. (NUM_REFERENCES_SET): Remove. Update all users. * params.def (PARAM_GLOBAL_VAR_THRESHOLD): Remove. Update all users. (PARAM_MAX_ALIASED_VOPS): Set to 10. * tree-ssanames.c (make_ssa_name): Initialize SSA_NAME_IS_DEFAULT_DEF to 0. 2006-12-11 Aldy Hernandez <aldyh@redhat.com> * tree-ssa-dse.c (aggregate_vardecl_d): New. (dse_global_data): Add aggregate_vardecl field. (dse_possible_dead_store_p): New. Add prev_defvar variable. Allow immediate uses and previous immediate uses to differ if they are setting different parts of the whole. (get_aggregate_vardecl): New. (dse_record_partial_aggregate_store): New. (dse_whole_aggregate_clobbered_p): New. (dse_partial_kill_p): New. (dse_optimize_stmt): Abstract code checking a possible dead store into new function dse_possible_dead_store_p(). Call dse_maybe_record_aggregate_store(). When checking whether a STMT and its USE_STMT refer to the same memory address, check also for partial kills that clobber the whole. Move some variable definitions to the block where they are used. (aggregate_vardecl_hash): New. (aggregate_vardecl_eq): New. (aggregate_vardecl_free): New. (aggregate_whole_store_p): New. (tree_ssa_dse): Initialize and free aggregate_vardecl. Mark which aggregate stores we care about. 2006-12-11 Andrew Macleod <amacleod@redhat.com> * tree-ssa-operands.h (struct vuse_element_d): Declare. (vuse_element_t): Declare. (struct vuse_vec_d): Declare. (vuse_vec_p): Declare. (VUSE_VECT_NUM_ELEM): Define. (VUSE_VECT_ELEMENT_NC): Define. (VUSE_ELEMENT_PTR_NC): Define. (VUSE_ELEMENT_VAR_NC): Define. (VUSE_VECT_ELEMENT): Define. (VUSE_ELEMENT_PTR): Define. (VUSE_ELEMENT_VAR): Define. (struct maydef_optype_d) <use_var>: Remove. <use_ptr>: Remove. <usev>: Add. (struct vuse_optype_d) <kill_var>: Remove. <use_ptr>: Remove. <usev>: Add. (struct mustdef_optype_d) <kill_var>: Remove. <use_ptr>: Remove. <usev>: Add. (VUSE_OP_PTR): Add argument. Use VUSE_ELEMENT_PTR. (VUSE_OP): Add argument. Use VUSE_ELEMENT_PTR. (VUSE_NUM): Define. (VUSE_VECT): Define. (MAYDEF_OP_PTR): Add argument. Use VUSE_OP_PTR. (MAYDEF_OP): Add argument. Use VUSE_OP. (MAYDEF_NUM): Define. (MAYDEF_VECT): Define. (MUSTDEF_KILL_PTR): Use VUSE_OP_PTR. (MUSTDEF_KILL): Use VUSE_OP. (MUSTDEF_NUM): Define. (MUSTDEF_VECT): Define. (realloc_maydef): Declare. (realloc_vuse): Declare. (struct ssa_operand_iterator_d) <vuse_index>: Add. <mayuse_index>: Add. (LOADED_SYMS): Define. (STORED_SYMS): Define. (FOR_EACH_SSA_MUSTDEF_OPERAND): Call op_iter_next_mustdef. * tree-into-ssa.c: Adapt for multi-operand V_MAY_DEF and VUSE operators. * tree-pretty-print.c: Likewise. * tree-ssa-dse.c: Likewise. * tree-flow-inline.h: Likewise. (op_iter_next_mustdef): New. * tree-ssa-operands.c: Likewise. (ALLOC_OPTYPE): Remove. Update all users. (alloc_def): New. (alloc_use): New. (alloc_maydef): New. (alloc_vuse): New. (alloc_mustdef): New. (realloc_maydef): New. (realloc_vuse): New. 2006-12-11 Aldy Hernandez <aldyh@redhat.com> * tree-ssa-operands.c: Remove build_v_must_defs. (init_ssa_operands): Delete build_v_must_defs. (finalize_ssa_v_must_def_ops): Remove. (finalize_ssa_v_must_defs): Remove. (finalize_ssa_stmt_operands): Do not call finalize_ssa_v_must_defs. (start_ssa_stmt_operands): Do not check build_v_must_defs. (append_v_must_def): Delete. (copy_virtual_operands): Do not copy V_MUST_DEFs. (get_modify_expr_operands): Remove reference to V_MUST_DEF from comment. Remove opf_kill_def. (build_ssa_operands): Remove references to v_must_defs. (copy_virtual_operands): Same. (copy_virtual_operands): Same. (fini_ssa_operands): Same. (free_ssa_operands): Same. (add_mustdef_op): Remove. Remove mustdef_optype_p. (alloc_mustdef): Remove. Remove references to V_MUST_DEFs in comment at top of file. (get_expr_operands): Remove opf_kill_def. (opf_kill_def): Remove. (add_virtual_operand): Remove opf_kill_def. (get_indirect_ref_operands): Same. (get_tmr_operands): Same. * tree-vectorizer.c (rename_variables_in_bb): Remove SSA_OP_ALL_KILLS. * tree-ssa-loop-manip.c (find_uses_to_rename_stmt): Remove SSA_OP_ALL_KILLS. (check_loop_closed_ssa_stmt): Same. * tree-ssa.c (verify_def): Remove V_MUST_DEF from comment. (verify_use): Same. (verify_ssa): Remove V_MUST_DEFs traces. (verify_ssa): Remove SSA_OP_ALL_KILLS. * tree-into-ssa.c (mark_def_sites): Change SSA_OP_VMUSTDEF to SSA_OP_VMAYDEF. (rewrite_update_stmt): Remove SSA_OP_VIRTUAL_KILLS. (rewrite_stmt): Remove SSA_OP_ALL_KILLS. * tree-ssa-operands.h (struct stmt_operands_d): Remove V_MUST_DEF references. (MUSTDEF_OPS): Remove. (SSA_OP_VMUSTDEF): Remove. (FOR_EACH_SSA_MUSTDEF_OPERAND): Remove. (struct mustdef_optype_d): Remove. Remove mustdef_optype_p. (struct stmt_operands_d): Remove mustdef_ops. (ssa_operand_iterator_d): Remove mustdefs and mustkills. (SSA_OP_VIRTUAL_DEFS): Remove SSA_OP_VMUSTDEF. (MUSTDEF_RESULT_PTR): Remove. (MUSTDEF_RESULT): Remove. (MUSTDEF_KILL_PTR): Remove. (MUSTDEF_KILL): Remove. (MUSTDEF_NUM): Remove. (MUSTDEF_VECT): Remove. (SSA_OP_VIRTUAL_KILLS): Remove. (SSA_OP_ALL_VIRTUALS): Remove SSA_OP_VIRTUAL_KILLS. (SSA_OP_VMUSTKILL): Remove. (SSA_OP_ALL_KILLS): Remove. (SSA_OP_ALL_OPERANDS): Remove SSA_OP_ALL_KILLS. * tree-flow-inline.h (op_iter_init_def): Remove SSA_OP_VIRTUAL_KILLS. (delink_stmt_imm_use): Remove SSA_OP_ALL_KILLS. * tree-ssa-pre.c (compute_rvuse_and_antic_safe): Remove SSA_OP_VIRTUAL_KILLS. * tree-ssa-loop-im.c (determine_max_movement): Remove SSA_OP_VIRTUAL_KILLS. (gather_mem_refs_stmt): Same. (gather_mem_refs_stmt): Same. * tree-ssa-dce.c (mark_really_necessary_kill_operand_phis): Delete. (perform_tree_ssa_dce): Remove call to mark_really_necessary_kill_operand_phis. * tree-flow-inline.h (op_iter_init): Remove setting of mustdefs and mustkills. (op_iter_next_use): Do not check mustkills. (op_iter_next_def): Do not check mustdefs. (op_iter_next_tree): Do not check mustkills or mustdefs. (clear_and_done_ssa_iter): Do not set mustdefs or mustkills. (op_iter_next_maymustdef): Do not check mustkills. (op_iter_init_must_and_may_def): Remove SSA_OP_VMUSTKILL. (op_iter_init_mustdef): Remove. * tree-ssa-live.c (create_ssa_var_map): Change SSA_OP_VMUSTDEF to SSA_OP_VMAYDEF. * tree-ssa-dse.c (dse_optimize_stmt): Remove SSA_OP_VMUSTDEF. * tree-ssa-ccp.c: Remove V_MUST_DEF traces from comments. (visit_assignment): Same. * tree-ssa-copy.c (copy_prop_visit_assignment): Same. * tree-sra.c (mark_all_v_defs_1): Remove V_MUST_DEF from comment. * tree-outof-ssa.c (check_replaceable): Remove SSA_OP_VMUSTDEF. * tree-pretty-print.c (dump_vops): Remove printing of V_MUST_DEF. Remove kill_p variable. * tree-dfa.c (struct dfa_stats_d): Remove num_v_must_defs. (dump_dfa_stats): Remove code related to V_MUST_DEFs. (collect_dfa_stats_r): Do not set num_v_must_defs. (mark_new_vars_to_rename): Remove v_must_defs_{before,after} code. * tree-into-ssa.c (mark_def_sites): Change SSA_OP_VMUSTKILL to SSA_OP_VMAYUSE. * tree-ssa-pre.c (compute_rvuse_and_antic_safe): Remove SSA_OP_VMUSTDEF and SSA_OP_VMUSTKILL. * tree-ssa-propagate.c (stmt_makes_single_store): Remove SSA_OP_VMUSTDEF. From-SVN: r119760
2006-12-12 02:48:51 +01:00
/* There must be no VDEFs. */
if (!(ZERO_SSA_OPERANDS (stmt, SSA_OP_VDEF)))
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
return false;
/* Float expressions must go through memory if float-store is on. */
if (flag_float_store
&& FLOAT_TYPE_P (TREE_TYPE (GENERIC_TREE_OPERAND (stmt, 1))))
return false;
/* An assignment with a register variable on the RHS is not
replaceable. */
if (TREE_CODE (GENERIC_TREE_OPERAND (stmt, 1)) == VAR_DECL
&& DECL_HARD_REGISTER (GENERIC_TREE_OPERAND (stmt, 1)))
return false;
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
/* Calls to functions with side-effects cannot be replaced. */
if ((call_expr = get_call_expr_in (stmt)) != NULL_TREE)
{
int call_flags = call_expr_flags (call_expr);
if (TREE_SIDE_EFFECTS (call_expr)
&& !(call_flags & (ECF_PURE | ECF_CONST | ECF_NORETURN)))
return false;
}
/* Leave any stmt with volatile operands alone as well. */
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
if (stmt_ann (stmt)->has_volatile_ops)
return false;
return true;
}
/* This function will remove the expression for VERSION from replacement
consideration in table TAB. If FREE_EXPR is true, then remove the
expression from consideration as well by freeing the decl uid bitmap. */
static void
finished_with_expr (temp_expr_table_p tab, int version, bool free_expr)
{
unsigned i;
bitmap_iterator bi;
/* Remove this expression from its dependent lists. The partition dependence
list is retained and transfered later to whomever uses this version. */
if (tab->partition_dependencies[version])
{
EXECUTE_IF_SET_IN_BITMAP (tab->partition_dependencies[version], 0, i, bi)
remove_from_partition_kill_list (tab, i, version);
BITMAP_FREE (tab->partition_dependencies[version]);
}
if (free_expr)
BITMAP_FREE (tab->expr_decl_uids[version]);
}
/* Create an expression entry fora replaceable expression. */
static void
process_replaceable (temp_expr_table_p tab, tree stmt)
{
tree var, def, basevar;
int version;
ssa_op_iter iter;
bitmap def_vars, use_vars;
#ifdef ENABLE_CHECKING
gcc_assert (is_replaceable_p (stmt));
#endif
def = SINGLE_SSA_TREE_OPERAND (stmt, SSA_OP_DEF);
version = SSA_NAME_VERSION (def);
basevar = SSA_NAME_VAR (def);
def_vars = BITMAP_ALLOC (NULL);
bitmap_set_bit (def_vars, DECL_UID (basevar));
/* Add this expression to the dependency list for each use partition. */
FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE)
{
int var_version = SSA_NAME_VERSION (var);
use_vars = tab->expr_decl_uids[var_version];
add_dependence (tab, version, var);
if (use_vars)
{
bitmap_ior_into (def_vars, use_vars);
BITMAP_FREE (tab->expr_decl_uids[var_version]);
}
else
bitmap_set_bit (def_vars, DECL_UID (SSA_NAME_VAR (var)));
}
tab->expr_decl_uids[version] = def_vars;
/* If there are VUSES, add a dependence on virtual defs. */
if (!ZERO_SSA_OPERANDS (stmt, SSA_OP_VUSE))
{
make_dependent_on_partition (tab, version, VIRTUAL_PARTITION (tab));
add_to_partition_kill_list (tab, VIRTUAL_PARTITION (tab), version);
}
}
/* This function removes any expression in TAB which is dependent on PARTITION
from consideration, making it not replaceable. */
static inline void
kill_expr (temp_expr_table_p tab, int partition)
{
unsigned version;
/* Mark every active expr dependent on this var as not replaceable.
finished_with_expr can modify the bitmap, so we can't execute over it. */
while (tab->kill_list[partition])
{
version = bitmap_first_set_bit (tab->kill_list[partition]);
finished_with_expr (tab, version, true);
}
#ifdef ENABLE_CHECKING
gcc_assert (!tab->kill_list[partition]);
#endif
}
/* This function kills all expressions in TAB which are dependent on virtual
partitions. */
static inline void
kill_virtual_exprs (temp_expr_table_p tab)
{
kill_expr (tab, VIRTUAL_PARTITION (tab));
}
/* Mark the expression associated with VAR as replaceable, and enter
the defining stmt into the partition_dependencies table TAB. if
MORE_REPLACING is true, accumulate the pending partition dependencies. */
static void
mark_replaceable (temp_expr_table_p tab, tree var, bool more_replacing)
{
int version = SSA_NAME_VERSION (var);
/* Move the dependence list to the pending listpending. */
if (more_replacing && tab->partition_dependencies[version])
bitmap_ior_into (tab->new_replaceable_dependencies,
tab->partition_dependencies[version]);
finished_with_expr (tab, version, !more_replacing);
/* Set the replaceable expression. */
if (!tab->replaceable_expressions)
tab->replaceable_expressions = XCNEWVEC (tree, num_ssa_names + 1);
tab->replaceable_expressions[version] = SSA_NAME_DEF_STMT (var);
}
/* This function processes basic block BB, and looks for variables which can
be replaced by their expressions. Results are stored in the table TAB. */
static void
find_replaceable_in_bb (temp_expr_table_p tab, basic_block bb)
{
block_stmt_iterator bsi;
tree stmt, def, use;
stmt_ann_t ann;
int partition;
var_map map = tab->map;
ssa_op_iter iter;
bool stmt_replaceable;
for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
{
stmt = bsi_stmt (bsi);
ann = stmt_ann (stmt);
stmt_replaceable = is_replaceable_p (stmt);
/* Determine if this stmt finishes an existing expression. */
FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
{
unsigned ver = SSA_NAME_VERSION (use);
/* If this use is a potential replacement variable, process it. */
if (tab->expr_decl_uids[ver])
{
bool same_root_var = false;
ssa_op_iter iter2;
bitmap vars = tab->expr_decl_uids[ver];
/* See if the root variables are the same. If they are, we
do not want to do the replacement to avoid problems with
code size, see PR tree-optimization/17549. */
if (!bitmap_empty_p (vars))
FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter2, SSA_OP_DEF)
{
if (bitmap_bit_p (vars, DECL_UID (SSA_NAME_VAR (def))))
{
same_root_var = true;
break;
}
}
/* Mark expression as replaceable unless stmt is volatile or the
def variable has the same root variable as something in the
substitution list. */
if (ann->has_volatile_ops || same_root_var)
finished_with_expr (tab, ver, true);
else
mark_replaceable (tab, use, stmt_replaceable);
}
}
/* Next, see if this stmt kills off an active expression. */
FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_DEF)
{
partition = var_to_partition (map, def);
if (partition != NO_PARTITION && tab->kill_list[partition])
kill_expr (tab, partition);
}
/* Now see if we are creating a new expression or not. */
if (stmt_replaceable)
process_replaceable (tab, stmt);
/* Free any unused dependency lists. */
bitmap_clear (tab->new_replaceable_dependencies);
/* A V_{MAY,MUST}_DEF kills any expression using a virtual operand,
including the current stmt. */
if (!ZERO_SSA_OPERANDS (stmt, SSA_OP_VIRTUAL_DEFS))
kill_virtual_exprs (tab);
}
}
/* This function is the driver routine for replacement of temporary expressions
in the SSA->normal phase, operating on MAP. If there are replaceable
expressions, a table is returned which maps SSA versions to the
expressions they should be replaced with. A NULL_TREE indicates no
replacement should take place. If there are no replacements at all,
NULL is returned by the function, otherwise an expression vector indexed
by SSA_NAME version numbers. */
extern tree *
find_replaceable_exprs (var_map map)
{
basic_block bb;
temp_expr_table_p table;
tree *ret;
table = new_temp_expr_table (map);
FOR_EACH_BB (bb)
{
find_replaceable_in_bb (table, bb);
gcc_assert (bitmap_empty_p (table->partition_in_use));
#ifdef ENABLE_CHECKING
{
unsigned i;
/* Make sure all the tables have been cleared out. */
for (i = 0; i < num_ssa_names + 1; i++)
{
gcc_assert (table->partition_dependencies[i] == NULL);
gcc_assert (table->expr_decl_uids[i] == NULL);
if (i < num_var_partitions (map))
gcc_assert (table->kill_list[i] == NULL);
}
}
#endif
}
ret = free_temp_expr_table (table);
return ret;
}
/* Dump TER expression table EXPR to file F. */
extern void
dump_replaceable_exprs (FILE *f, tree *expr)
{
tree stmt, var;
int x;
fprintf (f, "\nReplacing Expressions\n");
for (x = 0; x < (int)num_ssa_names; x++)
if (expr[x])
{
stmt = expr[x];
var = SINGLE_SSA_TREE_OPERAND (stmt, SSA_OP_DEF);
gcc_assert (var != NULL_TREE);
print_generic_expr (f, var, TDF_SLIM);
fprintf (f, " replace with --> ");
print_generic_expr (f, GENERIC_TREE_OPERAND (stmt, 1),
TDF_SLIM);
New TER code. 2006-12-08 Andrew MacLeod <amacleod@redhat.com> * Makefile.in: Add new file tree-ssa-ter.c. * tree-outof-ssa.c (struct temp_expr_table_d, new_temp_expr_table, free_temp_expr_table, add_value_to_version_list, add_value_to_partition_list, remove_value_from_partition_list, add_dependence, check_replaceable, finish_expr, mark_replaceable, kill_expr, kill_virtual_exprs, find_replaceable_in_bb, find_replaceable_exprs, dump_replaceable_exprs): Move to tree-ssa-ter.c. * tree-ssa-live.h (find_replaceable_exprs, dump_replaceable_exprs): Add prototypes. * tree-ssa-ter.c: New file using code moved from tree-outof-ssa.c. (struct value_expr_d): Remove. (struct temp_expr_table_d): Rename fields, add explicit vector of replaceable expressions instead of sharing. Change value_expr_p's to bitmap. Delete free_list. (new_temp_expr_table): Rename fields, count number of ssa_names in each partition. (free_temp_expr_table): Rename field, free new fields. (new_value_expr, free_value_expr, find_value_in_list, add_value_to_list, add_info_to_list, remove_value_from_list): Delete. (version_to_be_replaced_p): New. Is an ssa-name replaceable? (make_dependent_on_partition): New. Set bit in version list, allocating a bitmap if need be. (add_to_partition_kill_list): New. Set bit in the partition list, allocating a bitmap if need be. (remove_from_partition_kill_list): New. Remove a bit from the partition list, free the bitmap if it is empty. (add_dependence): Use renamed field, cleanup. Don't add a dependence on partitions with only one member. (is_replaceable_p): New. Split out replaceability check from check_replaceable. (process_replaceable): New. Replacement code split from check_replaceable. (check_replaceable): Removed. (finished_with_expr): Renamed from finish_expr. (kill_expr): Use renamed fields. Less parameters. (kill_virtual_exprs): Less parameters. (mark_replaceable): Use renamed fields. (find_replaceable_in_bb): Use renamed fields, cleanup. (find_replaceable_exprs): Use renamed routines, cleanup. (dump_replaceable_exprs): don;t go past end of ssa_names list. (debug_ter): New. Debug routine to dump state. From-SVN: r119657
2006-12-08 15:07:53 +01:00
fprintf (f, "\n");
}
fprintf (f, "\n");
}
#ifdef ENABLE_CHECKING
/* Dump the status of the various tables in the expression table. This is used
exclusively to debug TER. F is the place to send debug info and T is the
table being debugged. */
extern void
debug_ter (FILE *f, temp_expr_table_p t)
{
unsigned x, y;
bitmap_iterator bi;
fprintf (f, "\nDumping current state of TER\n virtual partition = %d\n",
VIRTUAL_PARTITION (t));
if (t->replaceable_expressions)
dump_replaceable_exprs (f, t->replaceable_expressions);
fprintf (f, "Currently tracking the following expressions:\n");
for (x = 1; x < num_ssa_names; x++)
if (t->expr_decl_uids[x])
{
print_generic_expr (stderr, ssa_name (x), TDF_SLIM);
fprintf (f, " dep-parts : ");
if (t->partition_dependencies[x]
&& !bitmap_empty_p (t->partition_dependencies[x]))
{
EXECUTE_IF_SET_IN_BITMAP (t->partition_dependencies[x], 0, y, bi)
fprintf (f, "P%d ",y);
}
fprintf (stderr, " basedecls: ");
EXECUTE_IF_SET_IN_BITMAP (t->expr_decl_uids[x], 0, y, bi)
fprintf (f, "%d ",y);
fprintf (stderr, "\n");
}
bitmap_print (f, t->partition_in_use, "Partitions in use ",
"\npartition KILL lists:\n");
for (x = 0; x <= num_var_partitions (t->map); x++)
if (t->kill_list[x])
{
fprintf (f, "Partition %d : ", x);
EXECUTE_IF_SET_IN_BITMAP (t->kill_list[x], 0, y, bi)
fprintf (f, "_%d ",y);
}
fprintf (f, "\n----------\n");
}
#endif