/* Gimple walk support.
- Copyright (C) 2007-2013 Free Software Foundation, Inc.
+ Copyright (C) 2007-2015 Free Software Foundation, Inc.
Contributed by Aldy Hernandez <aldyh@redhat.com>
This file is part of GCC.
#include "system.h"
#include "coretypes.h"
#include "tm.h"
+#include "alias.h"
+#include "symtab.h"
#include "tree.h"
+#include "predict.h"
+#include "hard-reg-set.h"
+#include "function.h"
+#include "gimple-expr.h"
+#include "tree-ssa-alias.h"
+#include "basic-block.h"
+#include "fold-const.h"
#include "gimple.h"
#include "gimple-iterator.h"
#include "gimple-walk.h"
-#include "gimple-walk.h"
-#include "demangle.h"
+#include "stmt.h"
/* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt
on each one. WI is as in walk_gimple_stmt.
/* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
static tree
-walk_gimple_asm (gimple stmt, walk_tree_fn callback_op,
+walk_gimple_asm (gasm *stmt, walk_tree_fn callback_op,
struct walk_stmt_info *wi)
{
tree ret, op;
op = gimple_asm_output_op (stmt, i);
constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
oconstraints[i] = constraint;
- parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg,
- &is_inout);
if (wi)
- wi->val_only = (allows_reg || !allows_mem);
+ {
+ if (parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
+ &allows_reg, &is_inout))
+ wi->val_only = (allows_reg || !allows_mem);
+ }
ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
if (ret)
return ret;
{
op = gimple_asm_input_op (stmt, i);
constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
- parse_input_constraint (&constraint, 0, 0, noutputs, 0,
- oconstraints, &allows_mem, &allows_reg);
+
if (wi)
{
- wi->val_only = (allows_reg || !allows_mem);
- /* Although input "m" is not really a LHS, we need a lvalue. */
- wi->is_lhs = !wi->val_only;
+ if (parse_input_constraint (&constraint, 0, 0, noutputs, 0,
+ oconstraints, &allows_mem, &allows_reg))
+ {
+ wi->val_only = (allows_reg || !allows_mem);
+ /* Although input "m" is not really a LHS, we need a lvalue. */
+ wi->is_lhs = !wi->val_only;
+ }
}
ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
if (ret)
walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
struct walk_stmt_info *wi)
{
- struct pointer_set_t *pset = (wi) ? wi->pset : NULL;
+ hash_set<tree> *pset = (wi) ? wi->pset : NULL;
unsigned i;
tree ret = NULL_TREE;
wi->val_only = true;
}
- ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset);
+ ret = walk_tree (gimple_call_chain_ptr (as_a <gcall *> (stmt)),
+ callback_op, wi, pset);
if (ret)
return ret;
break;
case GIMPLE_CATCH:
- ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
- pset);
+ ret = walk_tree (gimple_catch_types_ptr (as_a <gcatch *> (stmt)),
+ callback_op, wi, pset);
if (ret)
return ret;
break;
break;
case GIMPLE_ASM:
- ret = walk_gimple_asm (stmt, callback_op, wi);
+ ret = walk_gimple_asm (as_a <gasm *> (stmt), callback_op, wi);
if (ret)
return ret;
break;
case GIMPLE_OMP_CONTINUE:
- ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt),
- callback_op, wi, pset);
- if (ret)
- return ret;
-
- ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt),
- callback_op, wi, pset);
- if (ret)
- return ret;
+ {
+ gomp_continue *cont_stmt = as_a <gomp_continue *> (stmt);
+ ret = walk_tree (gimple_omp_continue_control_def_ptr (cont_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+
+ ret = walk_tree (gimple_omp_continue_control_use_ptr (cont_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ }
break;
case GIMPLE_OMP_CRITICAL:
- ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi,
- pset);
- if (ret)
- return ret;
+ {
+ gomp_critical *omp_stmt = as_a <gomp_critical *> (stmt);
+ ret = walk_tree (gimple_omp_critical_name_ptr (omp_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ }
break;
case GIMPLE_OMP_FOR:
return ret;
ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
wi, pset);
+ if (ret)
+ return ret;
}
- if (ret)
- return ret;
break;
case GIMPLE_OMP_PARALLEL:
- ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
- wi, pset);
- if (ret)
- return ret;
- ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
- wi, pset);
- if (ret)
- return ret;
- ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
- wi, pset);
- if (ret)
- return ret;
+ {
+ gomp_parallel *omp_par_stmt = as_a <gomp_parallel *> (stmt);
+ ret = walk_tree (gimple_omp_parallel_clauses_ptr (omp_par_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ ret = walk_tree (gimple_omp_parallel_child_fn_ptr (omp_par_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ ret = walk_tree (gimple_omp_parallel_data_arg_ptr (omp_par_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ }
break;
case GIMPLE_OMP_TASK:
wi, pset);
if (ret)
return ret;
-
ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
wi, pset);
if (ret)
break;
case GIMPLE_OMP_TARGET:
- ret = walk_tree (gimple_omp_target_clauses_ptr (stmt), callback_op, wi,
- pset);
- if (ret)
- return ret;
+ {
+ gomp_target *omp_stmt = as_a <gomp_target *> (stmt);
+ ret = walk_tree (gimple_omp_target_clauses_ptr (omp_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ ret = walk_tree (gimple_omp_target_child_fn_ptr (omp_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ ret = walk_tree (gimple_omp_target_data_arg_ptr (omp_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ }
break;
case GIMPLE_OMP_TEAMS:
break;
case GIMPLE_OMP_ATOMIC_LOAD:
- ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi,
- pset);
- if (ret)
- return ret;
-
- ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
- pset);
- if (ret)
- return ret;
+ {
+ gomp_atomic_load *omp_stmt = as_a <gomp_atomic_load *> (stmt);
+ ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (omp_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (omp_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ }
break;
case GIMPLE_OMP_ATOMIC_STORE:
- ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op,
- wi, pset);
- if (ret)
- return ret;
+ {
+ gomp_atomic_store *omp_stmt = as_a <gomp_atomic_store *> (stmt);
+ ret = walk_tree (gimple_omp_atomic_store_val_ptr (omp_stmt),
+ callback_op, wi, pset);
+ if (ret)
+ return ret;
+ }
break;
case GIMPLE_TRANSACTION:
- ret = walk_tree (gimple_transaction_label_ptr (stmt), callback_op,
- wi, pset);
+ ret = walk_tree (gimple_transaction_label_ptr (
+ as_a <gtransaction *> (stmt)),
+ callback_op, wi, pset);
if (ret)
return ret;
break;
switch (gimple_code (stmt))
{
case GIMPLE_BIND:
- ret = walk_gimple_seq_mod (gimple_bind_body_ptr (stmt), callback_stmt,
- callback_op, wi);
+ ret = walk_gimple_seq_mod (gimple_bind_body_ptr (as_a <gbind *> (stmt)),
+ callback_stmt, callback_op, wi);
if (ret)
return wi->callback_result;
break;
case GIMPLE_CATCH:
- ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt), callback_stmt,
- callback_op, wi);
+ ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (
+ as_a <gcatch *> (stmt)),
+ callback_stmt, callback_op, wi);
if (ret)
return wi->callback_result;
break;
break;
case GIMPLE_EH_ELSE:
- ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (stmt),
- callback_stmt, callback_op, wi);
- if (ret)
- return wi->callback_result;
- ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (stmt),
- callback_stmt, callback_op, wi);
- if (ret)
- return wi->callback_result;
+ {
+ geh_else *eh_else_stmt = as_a <geh_else *> (stmt);
+ ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (eh_else_stmt),
+ callback_stmt, callback_op, wi);
+ if (ret)
+ return wi->callback_result;
+ ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (eh_else_stmt),
+ callback_stmt, callback_op, wi);
+ if (ret)
+ return wi->callback_result;
+ }
break;
case GIMPLE_TRY:
break;
case GIMPLE_TRANSACTION:
- ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (stmt),
+ ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (
+ as_a <gtransaction *> (stmt)),
callback_stmt, callback_op, wi);
if (ret)
return wi->callback_result;
/* 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.
+ passing the STMT, the base of the operand, the operand itself containing
+ the base 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 *))
+ walk_stmt_load_store_addr_fn visit_load,
+ walk_stmt_load_store_addr_fn visit_store,
+ walk_stmt_load_store_addr_fn visit_addr)
{
bool ret = false;
unsigned i;
if (gimple_assign_single_p (stmt))
{
- tree lhs, rhs;
+ tree lhs, rhs, arg;
if (visit_store)
{
- lhs = get_base_loadstore (gimple_assign_lhs (stmt));
+ arg = gimple_assign_lhs (stmt);
+ lhs = get_base_loadstore (arg);
if (lhs)
- ret |= visit_store (stmt, lhs, data);
+ ret |= visit_store (stmt, lhs, arg, data);
}
- rhs = gimple_assign_rhs1 (stmt);
+ arg = gimple_assign_rhs1 (stmt);
+ rhs = arg;
while (handled_component_p (rhs))
rhs = TREE_OPERAND (rhs, 0);
if (visit_addr)
{
if (TREE_CODE (rhs) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
+ ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), arg, 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);
+ ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), arg,
+ 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);
+ 0), arg, data);
else if (TREE_CODE (rhs) == CONSTRUCTOR)
{
unsigned int ix;
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
if (TREE_CODE (val) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (val, 0), data);
+ ret |= visit_addr (stmt, TREE_OPERAND (val, 0), arg, data);
else if (TREE_CODE (val) == OBJ_TYPE_REF
&& TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
ret |= visit_addr (stmt,
TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
- 0), data);
+ 0), arg, data);
}
lhs = gimple_assign_lhs (stmt);
if (TREE_CODE (lhs) == TARGET_MEM_REF
&& TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data);
+ ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), lhs, data);
}
if (visit_load)
{
rhs = get_base_loadstore (rhs);
if (rhs)
- ret |= visit_load (stmt, rhs, data);
+ ret |= visit_load (stmt, rhs, arg, data);
}
}
else if (visit_addr
if (op == NULL_TREE)
;
else if (TREE_CODE (op) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
+ ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
/* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
tree with two operands. */
else if (i == 1 && COMPARISON_CLASS_P (op))
{
if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
- 0), data);
+ 0), op, data);
if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
- 0), data);
+ 0), op, data);
}
}
}
- else if (is_gimple_call (stmt))
+ else if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
{
if (visit_store)
{
- tree lhs = gimple_call_lhs (stmt);
- if (lhs)
+ tree arg = gimple_call_lhs (call_stmt);
+ if (arg)
{
- lhs = get_base_loadstore (lhs);
+ tree lhs = get_base_loadstore (arg);
if (lhs)
- ret |= visit_store (stmt, lhs, data);
+ ret |= visit_store (stmt, lhs, arg, data);
}
}
if (visit_load || visit_addr)
- for (i = 0; i < gimple_call_num_args (stmt); ++i)
+ for (i = 0; i < gimple_call_num_args (call_stmt); ++i)
{
- tree rhs = gimple_call_arg (stmt, i);
+ tree arg = gimple_call_arg (call_stmt, i);
if (visit_addr
- && TREE_CODE (rhs) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
+ && TREE_CODE (arg) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (arg, 0), arg, data);
else if (visit_load)
{
- rhs = get_base_loadstore (rhs);
+ tree rhs = get_base_loadstore (arg);
if (rhs)
- ret |= visit_load (stmt, rhs, data);
+ ret |= visit_load (stmt, rhs, arg, 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);
+ && gimple_call_chain (call_stmt)
+ && TREE_CODE (gimple_call_chain (call_stmt)) == ADDR_EXPR)
+ ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (call_stmt), 0),
+ gimple_call_chain (call_stmt), data);
if (visit_addr
- && gimple_call_return_slot_opt_p (stmt)
- && gimple_call_lhs (stmt) != NULL_TREE
- && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
- ret |= visit_addr (stmt, gimple_call_lhs (stmt), data);
+ && gimple_call_return_slot_opt_p (call_stmt)
+ && gimple_call_lhs (call_stmt) != NULL_TREE
+ && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (call_stmt))))
+ ret |= visit_addr (stmt, gimple_call_lhs (call_stmt),
+ gimple_call_lhs (call_stmt), data);
}
- else if (gimple_code (stmt) == GIMPLE_ASM)
+ else if (gasm *asm_stmt = dyn_cast <gasm *> (stmt))
{
unsigned noutputs;
const char *constraint;
const char **oconstraints;
bool allows_mem, allows_reg, is_inout;
- noutputs = gimple_asm_noutputs (stmt);
+ noutputs = gimple_asm_noutputs (asm_stmt);
oconstraints = XALLOCAVEC (const char *, noutputs);
if (visit_store || visit_addr)
- for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
+ for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
{
- tree link = gimple_asm_output_op (stmt, i);
+ tree link = gimple_asm_output_op (asm_stmt, i);
tree op = get_base_loadstore (TREE_VALUE (link));
if (op && visit_store)
- ret |= visit_store (stmt, op, data);
+ ret |= visit_store (stmt, op, TREE_VALUE (link), data);
if (visit_addr)
{
constraint = TREE_STRING_POINTER
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);
+ ret |= visit_addr (stmt, op, TREE_VALUE (link), data);
}
}
if (visit_load || visit_addr)
- for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
+ for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
{
- tree link = gimple_asm_input_op (stmt, i);
+ tree link = gimple_asm_input_op (asm_stmt, i);
tree op = TREE_VALUE (link);
if (visit_addr
&& TREE_CODE (op) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
+ ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
else if (visit_load || visit_addr)
{
op = get_base_loadstore (op);
if (op)
{
if (visit_load)
- ret |= visit_load (stmt, op, data);
+ ret |= visit_load (stmt, op, TREE_VALUE (link), data);
if (visit_addr)
{
constraint = TREE_STRING_POINTER
0, oconstraints,
&allows_mem, &allows_reg);
if (!allows_reg && allows_mem)
- ret |= visit_addr (stmt, op, data);
+ ret |= visit_addr (stmt, op, TREE_VALUE (link),
+ data);
}
}
}
}
}
- else if (gimple_code (stmt) == GIMPLE_RETURN)
+ else if (greturn *return_stmt = dyn_cast <greturn *> (stmt))
{
- tree op = gimple_return_retval (stmt);
+ tree op = gimple_return_retval (return_stmt);
if (op)
{
if (visit_addr
&& TREE_CODE (op) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
+ ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
else if (visit_load)
{
- op = get_base_loadstore (op);
- if (op)
- ret |= visit_load (stmt, op, data);
+ tree base = get_base_loadstore (op);
+ if (base)
+ ret |= visit_load (stmt, base, op, data);
}
}
}
{
tree op = gimple_phi_arg_def (stmt, i);
if (TREE_CODE (op) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
+ ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
}
}
else if (visit_addr
{
tree op = gimple_goto_dest (stmt);
if (TREE_CODE (op) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
+ ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
}
return ret;
bool
walk_stmt_load_store_ops (gimple stmt, void *data,
- bool (*visit_load)(gimple, tree, void *),
- bool (*visit_store)(gimple, tree, void *))
+ walk_stmt_load_store_addr_fn visit_load,
+ walk_stmt_load_store_addr_fn visit_store)
{
return walk_stmt_load_store_addr_ops (stmt, data,
visit_load, visit_store, NULL);