From 9bfc434b7aa052e8d9175d3eca8fc355618e6fab Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Fri, 8 Apr 2011 12:19:45 +0000 Subject: [PATCH] gimple.h (gimple_call_fntype): New function. 2011-04-08 Richard Guenther * gimple.h (gimple_call_fntype): New function. (gimple_call_return_type): Use it. * expr.c (expand_expr_real_1): Use gimple_call_fntype. * gimple-low.c (gimple_check_call_args): Likewise. * gimple.c (gimple_call_flags): Likewise. (gimple_call_arg_flags): Likewise. (gimple_call_return_flags): Likewise. * tree-cfg.c (verify_gimple_call): Likewise. (do_warn_unused_result): Likewise. * tree-ssa-ccp.c (ccp_fold_stmt): Likewise. * value-prof.c (gimple_ic_transform): Fix fndecl check. From-SVN: r172178 --- gcc/ChangeLog | 14 ++++++++++++++ gcc/expr.c | 3 +-- gcc/gimple-low.c | 5 ++--- gcc/gimple.c | 14 ++++++++------ gcc/gimple.h | 15 +++++++++------ gcc/tree-cfg.c | 4 ++-- gcc/tree-ssa-ccp.c | 2 +- gcc/value-prof.c | 5 +---- 8 files changed, 38 insertions(+), 24 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 75ebe6f7119..0372c2f1a6d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2011-04-08 Richard Guenther + + * gimple.h (gimple_call_fntype): New function. + (gimple_call_return_type): Use it. + * expr.c (expand_expr_real_1): Use gimple_call_fntype. + * gimple-low.c (gimple_check_call_args): Likewise. + * gimple.c (gimple_call_flags): Likewise. + (gimple_call_arg_flags): Likewise. + (gimple_call_return_flags): Likewise. + * tree-cfg.c (verify_gimple_call): Likewise. + (do_warn_unused_result): Likewise. + * tree-ssa-ccp.c (ccp_fold_stmt): Likewise. + * value-prof.c (gimple_ic_transform): Fix fndecl check. + 2011-04-08 Dmitry Melnik PR rtl-optimization/48235 diff --git a/gcc/expr.c b/gcc/expr.c index d521f648b23..6dc45666dad 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -8533,8 +8533,7 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode, && (g = SSA_NAME_DEF_STMT (ssa_name)) && gimple_code (g) == GIMPLE_CALL) pmode = promote_function_mode (type, mode, &unsignedp, - TREE_TYPE - (TREE_TYPE (gimple_call_fn (g))), + gimple_call_fntype (g), 2); else pmode = promote_decl_mode (exp, &unsignedp); diff --git a/gcc/gimple-low.c b/gcc/gimple-low.c index 9d774429bab..9968493cd2c 100644 --- a/gcc/gimple-low.c +++ b/gcc/gimple-low.c @@ -222,11 +222,10 @@ gimple_check_call_args (gimple stmt) /* Get argument types for verification. */ fndecl = gimple_call_fndecl (stmt); - parms = NULL_TREE; if (fndecl) parms = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); - else if (POINTER_TYPE_P (TREE_TYPE (gimple_call_fn (stmt)))) - parms = TYPE_ARG_TYPES (TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt)))); + else + parms = TYPE_ARG_TYPES (gimple_call_fntype (stmt)); /* Verify if the type of the argument matches that of the function declaration. If we cannot verify this or there is a mismatch, diff --git a/gcc/gimple.c b/gcc/gimple.c index 8881aaa460d..4675d14193e 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -1780,15 +1780,17 @@ gimple_call_flags (const_gimple stmt) { int flags; tree decl = gimple_call_fndecl (stmt); - tree t; if (decl) flags = flags_from_decl_or_type (decl); else { - t = TREE_TYPE (gimple_call_fn (stmt)); - if (t && TREE_CODE (t) == POINTER_TYPE) - flags = flags_from_decl_or_type (TREE_TYPE (t)); + tree t = TREE_TYPE (gimple_call_fn (stmt)); + /* ??? We can end up being called from gimple_set_modified from + gsi_remove in which case the function being called can + be a released SSA name. Give up in that case. */ + if (t) + flags = flags_from_decl_or_type (gimple_call_fntype (stmt)); else flags = 0; } @@ -1804,7 +1806,7 @@ gimple_call_flags (const_gimple stmt) int gimple_call_arg_flags (const_gimple stmt, unsigned arg) { - tree type = TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt))); + tree type = gimple_call_fntype (stmt); tree attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type)); if (!attr) return 0; @@ -1848,7 +1850,7 @@ gimple_call_return_flags (const_gimple stmt) if (gimple_call_flags (stmt) & ECF_MALLOC) return ERF_NOALIAS; - type = TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt))); + type = gimple_call_fntype (stmt); attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type)); if (!attr) return 0; diff --git a/gcc/gimple.h b/gcc/gimple.h index cc35b6099b0..be45e4b921d 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -2011,6 +2011,13 @@ gimple_call_fn (const_gimple gs) return gimple_op (gs, 1); } +/* Return the function type of the function called by GS. */ + +static inline tree +gimple_call_fntype (const_gimple gs) +{ + return TREE_TYPE (TREE_TYPE (gimple_call_fn (gs))); +} /* Return a pointer to the tree node representing the function called by call statement GS. */ @@ -2073,13 +2080,9 @@ gimple_call_fndecl (const_gimple gs) static inline tree gimple_call_return_type (const_gimple gs) { - tree fn = gimple_call_fn (gs); - tree type = TREE_TYPE (fn); - - /* See through the pointer. */ - type = TREE_TYPE (type); + tree type = gimple_call_fntype (gs); - /* The type returned by a FUNCTION_DECL is the type of its + /* The type returned by a function is the type of its function type. */ return TREE_TYPE (type); } diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index e6dac6fa0e2..fc8c94033bc 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -3086,7 +3086,7 @@ verify_gimple_call (gimple stmt) return true; } - fntype = TREE_TYPE (TREE_TYPE (fn)); + fntype = gimple_call_fntype (stmt); if (gimple_call_lhs (stmt) && !useless_type_conversion_p (TREE_TYPE (gimple_call_lhs (stmt)), TREE_TYPE (fntype)) @@ -7441,7 +7441,7 @@ do_warn_unused_result (gimple_seq seq) LHS. All calls whose value is ignored should be represented like this. Look for the attribute. */ fdecl = gimple_call_fndecl (g); - ftype = TREE_TYPE (TREE_TYPE (gimple_call_fn (g))); + ftype = gimple_call_fntype (g); if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (ftype))) { diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 059274a3513..4775a2a567f 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -1727,7 +1727,7 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi) this can use the argument slot types for type verification instead of the current argument type. We also can safely drop qualifiers here as we are dealing with constants anyway. */ - argt = TYPE_ARG_TYPES (TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt)))); + argt = TYPE_ARG_TYPES (gimple_call_fntype (stmt)); for (i = 0; i < gimple_call_num_args (stmt) && argt; ++i, argt = TREE_CHAIN (argt)) { diff --git a/gcc/value-prof.c b/gcc/value-prof.c index 8491c776f7c..71e889dfdf5 100644 --- a/gcc/value-prof.c +++ b/gcc/value-prof.c @@ -1230,16 +1230,13 @@ gimple_ic_transform (gimple stmt) histogram_value histogram; gcov_type val, count, all, bb_all; gcov_type prob; - tree callee; gimple modify; struct cgraph_node *direct_call; if (gimple_code (stmt) != GIMPLE_CALL) return false; - callee = gimple_call_fn (stmt); - - if (TREE_CODE (callee) == FUNCTION_DECL) + if (gimple_call_fndecl (stmt) != NULL_TREE) return false; histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_INDIR_CALL); -- 2.30.2