This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][1/2] Introduce walk_stmt_load_store_addr_ops, prepare to get rid of addresses_taken bitmap per stmt
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Diego Novillo <dnovillo at google dot com>
- Date: Wed, 15 Apr 2009 17:15:18 +0200 (CEST)
- Subject: [PATCH][1/2] Introduce walk_stmt_load_store_addr_ops, prepare to get rid of addresses_taken bitmap per stmt
This is a preparatory patch (which I'd like to get in even if we do not
end up removing addresses_taken) which introduces a gimple stmt walker
to visit loads, stores and address-taking operations on a stmt.
Both ipa-reference and ipa-pure-const are walking all loads and stores,
treating direct loads/stores different (and uses the loaded/stored syms
bitmaps for the latter before the alias-improvements branch merge).
This patch factors the walkers present in these passes into the new
walker. The walker also can walk address-taking operations (needed
by ipa-reference and update_address_taken passes which are the
only users of the addresses_taken bitmap and need it because the
re-compute TREE_ADDRESSABLE).
I have to re-bootstrap and test this patch because I added some
cosmetic changes.
Envisioning future use of this helper is hard, but I added a stmt
parameter to the callback as that sounded useful - I didn't add
a pointer to the original operand as that doesn't fit the single
case of implicit address taking by asm memory operands.
Thanks,
Richard.
2009-04-15 Richard Guenther <rguenther@suse.de>
* gimple.h (walk_stmt_load_store_addr_ops): Declare.
(walk_stmt_load_store_ops): Likewise.
* gimple.c (get_base_loadstore): New function.
(walk_stmt_load_store_addr_ops): Likewise.
(walk_stmt_load_store_ops): Likewise.
* ipa-pure-const.c (check_op): Simplify.
(check_load, check_store): New functions.
(check_stmt): Use walk_stmt_load_store_ops.
* ipa-reference.c (mark_load): Adjust signature.
(mark_store): Likewise.
(scan_stmt_for_static_refs): Use walk_stmt_load_store_addr_ops.
Index: gcc/gimple.h
===================================================================
*** gcc/gimple.h.orig 2009-04-08 13:24:06.000000000 +0200
--- gcc/gimple.h 2009-04-14 14:17:14.000000000 +0200
*************** extern tree get_call_expr_in (tree t);
*** 909,914 ****
--- 909,921 ----
extern void recalculate_side_effects (tree);
extern void count_uses_and_derefs (tree, gimple, unsigned *, unsigned *,
unsigned *);
+ extern bool walk_stmt_load_store_addr_ops (gimple, void *,
+ bool (*)(gimple, tree, void *),
+ bool (*)(gimple, tree, void *),
+ bool (*)(gimple, tree, void *));
+ extern bool walk_stmt_load_store_ops (gimple, void *,
+ bool (*)(gimple, tree, void *),
+ bool (*)(gimple, tree, void *));
/* In gimplify.c */
extern tree create_tmp_var_raw (tree, const char *);
Index: gcc/gimple.c
===================================================================
*** gcc/gimple.c.orig 2009-04-08 13:24:06.000000000 +0200
--- gcc/gimple.c 2009-04-14 14:15:28.000000000 +0200
*************** count_uses_and_derefs (tree ptr, gimple
*** 3194,3197 ****
--- 3194,3395 ----
gcc_assert (*num_uses_p >= *num_loads_p + *num_stores_p);
}
+ /* From a tree operand OP return the base of a load or store operation
+ or NULL_TREE if OP is not a load or a store. */
+
+ static tree
+ get_base_loadstore (tree op)
+ {
+ while (handled_component_p (op))
+ op = TREE_OPERAND (op, 0);
+ if (DECL_P (op)
+ || INDIRECT_REF_P (op)
+ || TREE_CODE (op) == TARGET_MEM_REF)
+ return op;
+ return NULL_TREE;
+ }
+
+ /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
+ VISIT_ADDR if non-NULL on loads, store and address-taken operands
+ passing the STMT, the base of the operand and DATA to it. The base
+ will be either a decl, an indirect reference (including TARGET_MEM_REF)
+ or the argument of an address expression.
+ Returns the results of these callbacks or'ed. */
+
+ bool
+ walk_stmt_load_store_addr_ops (gimple stmt, void *data,
+ bool (*visit_load)(gimple, tree, void *),
+ bool (*visit_store)(gimple, tree, void *),
+ bool (*visit_addr)(gimple, tree, void *))
+ {
+ bool ret = false;
+ unsigned i;
+ if (gimple_assign_single_p (stmt))
+ {
+ tree lhs, rhs;
+ if (visit_store)
+ {
+ lhs = get_base_loadstore (gimple_assign_lhs (stmt));
+ if (lhs)
+ ret |= visit_store (stmt, lhs, data);
+ }
+ rhs = gimple_assign_rhs1 (stmt);
+ if (visit_addr)
+ {
+ if (TREE_CODE (rhs) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
+ else if (TREE_CODE (rhs) == TARGET_MEM_REF
+ && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data);
+ else if (TREE_CODE (rhs) == OBJ_TYPE_REF
+ && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
+ 0), data);
+ }
+ if (visit_load)
+ {
+ rhs = get_base_loadstore (rhs);
+ if (rhs)
+ ret |= visit_load (stmt, rhs, data);
+ }
+ }
+ else if (visit_addr
+ && (is_gimple_assign (stmt)
+ || gimple_code (stmt) == GIMPLE_COND
+ || gimple_code (stmt) == GIMPLE_CHANGE_DYNAMIC_TYPE))
+ {
+ for (i = 0; i < gimple_num_ops (stmt); ++i)
+ if (gimple_op (stmt, i)
+ && TREE_CODE (gimple_op (stmt, i)) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (gimple_op (stmt, i), 0), data);
+ }
+ else if (is_gimple_call (stmt))
+ {
+ if (visit_store)
+ {
+ tree lhs = gimple_call_lhs (stmt);
+ if (lhs)
+ {
+ lhs = get_base_loadstore (lhs);
+ if (lhs)
+ ret |= visit_store (stmt, lhs, data);
+ }
+ }
+ if (visit_load || visit_addr)
+ for (i = 0; i < gimple_call_num_args (stmt); ++i)
+ {
+ tree rhs = gimple_call_arg (stmt, i);
+ if (visit_addr
+ && TREE_CODE (rhs) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
+ else if (visit_load)
+ {
+ rhs = get_base_loadstore (rhs);
+ if (rhs)
+ ret |= visit_load (stmt, rhs, data);
+ }
+ }
+ if (visit_addr
+ && gimple_call_chain (stmt)
+ && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
+ data);
+ }
+ else if (gimple_code (stmt) == GIMPLE_ASM)
+ {
+ unsigned noutputs;
+ const char *constraint;
+ const char **oconstraints;
+ bool allows_mem, allows_reg, is_inout;
+ noutputs = gimple_asm_noutputs (stmt);
+ oconstraints = XALLOCAVEC (const char *, noutputs);
+ if (visit_store || visit_addr)
+ for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
+ {
+ tree link = gimple_asm_output_op (stmt, i);
+ tree op = get_base_loadstore (TREE_VALUE (link));
+ if (op && visit_store)
+ ret |= visit_store (stmt, op, data);
+ if (visit_addr)
+ {
+ constraint = TREE_STRING_POINTER
+ (TREE_VALUE (TREE_PURPOSE (link)));
+ oconstraints[i] = constraint;
+ parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
+ &allows_reg, &is_inout);
+ if (op && !allows_reg && allows_mem)
+ ret |= visit_addr (stmt, op, data);
+ }
+ }
+ if (visit_load || visit_addr)
+ for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
+ {
+ tree link = gimple_asm_input_op (stmt, i);
+ tree op = TREE_VALUE (link);
+ if (visit_addr
+ && TREE_CODE (op) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
+ else if (visit_load || visit_addr)
+ {
+ op = get_base_loadstore (op);
+ if (op)
+ {
+ if (visit_load)
+ ret |= visit_load (stmt, op, data);
+ if (visit_addr)
+ {
+ constraint = TREE_STRING_POINTER
+ (TREE_VALUE (TREE_PURPOSE (link)));
+ parse_input_constraint (&constraint, 0, 0, noutputs,
+ 0, oconstraints,
+ &allows_mem, &allows_reg);
+ if (!allows_reg && allows_mem)
+ ret |= visit_addr (stmt, op, data);
+ }
+ }
+ }
+ }
+ }
+ else if (gimple_code (stmt) == GIMPLE_RETURN)
+ {
+ tree op = gimple_return_retval (stmt);
+ if (op)
+ {
+ if (visit_addr
+ && TREE_CODE (op) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
+ else if (visit_load)
+ {
+ op = get_base_loadstore (op);
+ if (op)
+ ret |= visit_load (stmt, op, data);
+ }
+ }
+ }
+ else if (visit_addr
+ && gimple_code (stmt) == GIMPLE_PHI)
+ {
+ for (i = 0; i < gimple_phi_num_args (stmt); ++i)
+ {
+ tree op = PHI_ARG_DEF (stmt, i);
+ if (TREE_CODE (op) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
+ }
+ }
+
+ return ret;
+ }
+
+ /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
+ should make a faster clone for this case. */
+
+ bool
+ walk_stmt_load_store_ops (gimple stmt, void *data,
+ bool (*visit_load)(gimple, tree, void *),
+ bool (*visit_store)(gimple, tree, void *))
+ {
+ return walk_stmt_load_store_addr_ops (stmt, data,
+ visit_load, visit_store, NULL);
+ }
+
#include "gt-gimple.h"
Index: gcc/ipa-pure-const.c
===================================================================
*** gcc/ipa-pure-const.c.orig 2009-04-08 13:24:06.000000000 +0200
--- gcc/ipa-pure-const.c 2009-04-14 14:16:22.000000000 +0200
*************** check_decl (funct_state local,
*** 209,244 ****
variable T is legal in a function that is either pure or const. */
static inline void
! check_op (funct_state local,
! tree t, bool checking_write)
{
! while (t && handled_component_p (t))
! t = TREE_OPERAND (t, 0);
! if (!t)
! return;
! if (INDIRECT_REF_P (t) || TREE_CODE (t) == TARGET_MEM_REF)
{
! if (TREE_THIS_VOLATILE (t))
! {
! local->pure_const_state = IPA_NEITHER;
! if (dump_file)
! fprintf (dump_file, " Volatile indirect ref is not const/pure\n");
! return;
! }
! else if (checking_write)
! {
! local->pure_const_state = IPA_NEITHER;
! if (dump_file)
! fprintf (dump_file, " Indirect ref write is not const/pure\n");
! return;
! }
! else
! {
! if (dump_file)
! fprintf (dump_file, " Indirect ref read is not const\n");
! if (local->pure_const_state == IPA_CONST)
! local->pure_const_state = IPA_PURE;
! }
}
}
--- 209,236 ----
variable T is legal in a function that is either pure or const. */
static inline void
! check_op (funct_state local, tree t, bool checking_write)
{
! if (TREE_THIS_VOLATILE (t))
{
! local->pure_const_state = IPA_NEITHER;
! if (dump_file)
! fprintf (dump_file, " Volatile indirect ref is not const/pure\n");
! return;
! }
! else if (checking_write)
! {
! local->pure_const_state = IPA_NEITHER;
! if (dump_file)
! fprintf (dump_file, " Indirect ref write is not const/pure\n");
! return;
! }
! else
! {
! if (dump_file)
! fprintf (dump_file, " Indirect ref read is not const\n");
! if (local->pure_const_state == IPA_CONST)
! local->pure_const_state = IPA_PURE;
}
}
*************** check_call (funct_state local, gimple ca
*** 375,380 ****
--- 367,396 ----
/* Direct functions calls are handled by IPA propagation. */
}
+ /* Wrapper around check_decl for loads. */
+
+ static bool
+ check_load (gimple stmt ATTRIBUTE_UNUSED, tree op, void *data)
+ {
+ if (DECL_P (op))
+ check_decl ((funct_state)data, op, false);
+ else
+ check_op ((funct_state)data, op, false);
+ return false;
+ }
+
+ /* Wrapper around check_decl for stores. */
+
+ static bool
+ check_store (gimple stmt ATTRIBUTE_UNUSED, tree op, void *data)
+ {
+ if (DECL_P (op))
+ check_decl ((funct_state)data, op, true);
+ else
+ check_op ((funct_state)data, op, true);
+ return false;
+ }
+
/* Look into pointer pointed to by GSIP and figure out what interesting side
effects it has. */
static void
*************** check_stmt (gimple_stmt_iterator *gsip,
*** 389,433 ****
print_gimple_stmt (dump_file, stmt, 0, 0);
}
! /* Look for direct loads and stores. */
! if (gimple_has_lhs (stmt))
! {
! tree lhs = get_base_address (gimple_get_lhs (stmt));
! if (lhs && DECL_P (lhs))
! check_decl (local, lhs, true);
! }
! if (gimple_assign_single_p (stmt))
! {
! tree rhs = get_base_address (gimple_assign_rhs1 (stmt));
! if (rhs && DECL_P (rhs))
! check_decl (local, rhs, false);
! }
! else if (is_gimple_call (stmt))
! {
! for (i = 0; i < gimple_call_num_args (stmt); ++i)
! {
! tree rhs = get_base_address (gimple_call_arg (stmt, i));
! if (rhs && DECL_P (rhs))
! check_decl (local, rhs, false);
! }
! }
! else if (gimple_code (stmt) == GIMPLE_ASM)
! {
! for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
! {
! tree op = TREE_VALUE (gimple_asm_input_op (stmt, i));
! op = get_base_address (op);
! if (op && DECL_P (op))
! check_decl (local, op, false);
! }
! for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
! {
! tree op = TREE_VALUE (gimple_asm_output_op (stmt, i));
! op = get_base_address (op);
! if (op && DECL_P (op))
! check_decl (local, op, true);
! }
! }
if (gimple_code (stmt) != GIMPLE_CALL
&& stmt_could_throw_p (stmt))
--- 405,412 ----
print_gimple_stmt (dump_file, stmt, 0, 0);
}
! /* Look for loads and stores. */
! walk_stmt_load_store_ops (stmt, local, check_load, check_store);
if (gimple_code (stmt) != GIMPLE_CALL
&& stmt_could_throw_p (stmt))
*************** check_stmt (gimple_stmt_iterator *gsip,
*** 447,459 ****
}
switch (gimple_code (stmt))
{
- case GIMPLE_ASSIGN:
- check_op (local, gimple_assign_lhs (stmt), true);
- i = 1;
- break;
case GIMPLE_CALL:
- check_op (local, gimple_call_lhs (stmt), true);
- i = 1;
check_call (local, stmt, ipa);
break;
case GIMPLE_LABEL:
--- 426,432 ----
*************** check_stmt (gimple_stmt_iterator *gsip,
*** 466,475 ****
}
break;
case GIMPLE_ASM:
- for (i = 0; i < gimple_asm_noutputs (stmt); i++)
- check_op (local, TREE_VALUE (gimple_asm_output_op (stmt, i)), true);
- for (i = 0; i < gimple_asm_ninputs (stmt); i++)
- check_op (local, TREE_VALUE (gimple_asm_input_op (stmt, i)), false);
for (i = 0; i < gimple_asm_nclobbers (stmt); i++)
{
tree op = gimple_asm_clobber_op (stmt, i);
--- 439,444 ----
*************** check_stmt (gimple_stmt_iterator *gsip,
*** 493,501 ****
default:
break;
}
-
- for (; i < gimple_num_ops (stmt); i++)
- check_op (local, gimple_op (stmt, i), false);
}
--- 462,467 ----
Index: gcc/ipa-reference.c
===================================================================
*** gcc/ipa-reference.c.orig 2009-04-08 15:01:23.000000000 +0200
--- gcc/ipa-reference.c 2009-04-14 14:13:41.000000000 +0200
*************** mark_address_taken (tree x)
*** 336,356 ****
/* Mark load of T. */
! static void
! mark_load (ipa_reference_local_vars_info_t local,
! tree t)
{
if (TREE_CODE (t) == VAR_DECL
&& has_proper_scope_for_analysis (t))
bitmap_set_bit (local->statics_read, DECL_UID (t));
}
/* Mark store of T. */
! static void
! mark_store (ipa_reference_local_vars_info_t local,
! tree t)
{
if (TREE_CODE (t) == VAR_DECL
&& has_proper_scope_for_analysis (t))
{
--- 336,357 ----
/* Mark load of T. */
! static bool
! mark_load (gimple stmt ATTRIBUTE_UNUSED, tree t, void *data)
{
+ ipa_reference_local_vars_info_t local = (ipa_reference_local_vars_info_t)data;
if (TREE_CODE (t) == VAR_DECL
&& has_proper_scope_for_analysis (t))
bitmap_set_bit (local->statics_read, DECL_UID (t));
+ return false;
}
/* Mark store of T. */
! static bool
! mark_store (gimple stmt ATTRIBUTE_UNUSED, tree t, void *data)
{
+ ipa_reference_local_vars_info_t local = (ipa_reference_local_vars_info_t)data;
if (TREE_CODE (t) == VAR_DECL
&& has_proper_scope_for_analysis (t))
{
*************** mark_store (ipa_reference_local_vars_inf
*** 361,366 ****
--- 362,368 ----
if (module_statics_written)
bitmap_set_bit (module_statics_written, DECL_UID (t));
}
+ return false;
}
/* Look for memory clobber and set read_all/write_all if present. */
*************** scan_stmt_for_static_refs (gimple_stmt_i
*** 434,479 ****
local = get_reference_vars_info (fn)->local;
/* Look for direct loads and stores. */
! if (gimple_has_lhs (stmt))
! {
! tree lhs = get_base_address (gimple_get_lhs (stmt));
! if (lhs && DECL_P (lhs))
! mark_store (local, lhs);
! }
! if (gimple_assign_single_p (stmt))
! {
! tree rhs = get_base_address (gimple_assign_rhs1 (stmt));
! if (rhs && DECL_P (rhs))
! mark_load (local, rhs);
! }
! else if (is_gimple_call (stmt))
! {
! for (i = 0; i < gimple_call_num_args (stmt); ++i)
! {
! tree rhs = get_base_address (gimple_call_arg (stmt, i));
! if (rhs && DECL_P (rhs))
! mark_load (local, rhs);
! }
! check_call (local, stmt);
! }
else if (gimple_code (stmt) == GIMPLE_ASM)
! {
! for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
! {
! tree op = TREE_VALUE (gimple_asm_input_op (stmt, i));
! op = get_base_address (op);
! if (op && DECL_P (op))
! mark_load (local, op);
! }
! for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
! {
! tree op = TREE_VALUE (gimple_asm_output_op (stmt, i));
! op = get_base_address (op);
! if (op && DECL_P (op))
! mark_store (local, op);
! }
! check_asm_memory_clobber (local, stmt);
! }
if (gimple_addresses_taken (stmt))
EXECUTE_IF_SET_IN_BITMAP (gimple_addresses_taken (stmt), 0, i, bi)
--- 436,447 ----
local = get_reference_vars_info (fn)->local;
/* Look for direct loads and stores. */
! walk_stmt_load_store_addr_ops (stmt, local, mark_load, mark_store, NULL);
!
! if (is_gimple_call (stmt))
! check_call (local, stmt);
else if (gimple_code (stmt) == GIMPLE_ASM)
! check_asm_memory_clobber (local, stmt);
if (gimple_addresses_taken (stmt))
EXECUTE_IF_SET_IN_BITMAP (gimple_addresses_taken (stmt), 0, i, bi)