From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22026 invoked by alias); 21 Aug 2007 15:58:52 -0000 Received: (qmail 21742 invoked by uid 22791); 21 Aug 2007 15:58:49 -0000 X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 21 Aug 2007 15:58:37 +0000 Received: from Relay2.suse.de (mail2.suse.de [195.135.221.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id D80FB22054 for ; Tue, 21 Aug 2007 17:58:34 +0200 (CEST) Date: Tue, 21 Aug 2007 16:42:00 -0000 From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH][C++][C] Remove cannot_inline_tree_fn langhook Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2007-08/txt/msg01375.txt.bz2 There are two interesting parts in the C and C++ implementation of this langhook. First, the C implementation has some -Winline warnings implemented there, second the C++ implementation did template instantiation from there at some time. The warnings have been folded into the only caller, inlinable_function_p, where appropriate. The template instantiation doesn't trigger anymore (as adding an assert shows) - it probably wouldn't work anymore with inlining gimple/ssa now anyway. Bootstrapped and tested on x86_64-unknown-linux-gnu. Ok for mainline? Thanks, Richard. 2007-08-21 Richard Guenther * Makefile.in (tree-inline.o): Add $(TARGET_H) and $(INTEGRATE_H) dependencies. * c-objc-common.c (c_cannot_inline_tree_fn): Remove. * langhooks.c (lhd_tree_inlining_cannot_inline_tree_fn): Likewise. * tree-inline.c (inlinable_function_p): Fold in common parts of the cannot_inline_tree_fn langhook. * langhooks-def.h (lhd_tree_inlining_cannot_inline_tree_fn): Remove. (LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN): Likewise. (LANG_HOOKS_TREE_INLINING_INITIALIZER): Remove initializer for cannot_inline_tree_fn langhook. * langhooks.h (struct lang_hooks_for_tree_inlining): Remove cannot_inline_tree_fn member. cp/ * tree.c (cp_cannot_inline_tree_fn): Remove. * cp-tree.h (cp_cannot_inline_tree_fn): Likewise. * cp-objcp-common.h (LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN): Remove define. Index: gcc/Makefile.in =================================================================== *** gcc.orig/Makefile.in 2007-08-20 11:54:33.000000000 +0200 --- gcc/Makefile.in 2007-08-21 16:31:56.000000000 +0200 *************** tree-inline.o : tree-inline.c $(CONFIG_H *** 1959,1965 **** $(VARRAY_H) $(HASHTAB_H) $(SPLAY_TREE_H) toplev.h \ langhooks.h $(TREE_INLINE_H) $(CGRAPH_H) intl.h $(FUNCTION_H) $(TREE_GIMPLE_H) \ debug.h $(DIAGNOSTIC_H) $(TREE_FLOW_H) tree-iterator.h tree-mudflap.h \ ! ipa-prop.h value-prof.h print-tree.o : print-tree.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ $(GGC_H) langhooks.h $(REAL_H) tree-iterator.h fixed-value.h stor-layout.o : stor-layout.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ --- 1959,1965 ---- $(VARRAY_H) $(HASHTAB_H) $(SPLAY_TREE_H) toplev.h \ langhooks.h $(TREE_INLINE_H) $(CGRAPH_H) intl.h $(FUNCTION_H) $(TREE_GIMPLE_H) \ debug.h $(DIAGNOSTIC_H) $(TREE_FLOW_H) tree-iterator.h tree-mudflap.h \ ! ipa-prop.h value-prof.h $(TARGET_H) $(INTEGRATE_H) print-tree.o : print-tree.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ $(GGC_H) langhooks.h $(REAL_H) tree-iterator.h fixed-value.h stor-layout.o : stor-layout.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ Index: gcc/c-objc-common.c =================================================================== *** gcc.orig/c-objc-common.c 2007-08-20 13:36:41.000000000 +0200 --- gcc/c-objc-common.c 2007-08-21 17:05:39.000000000 +0200 *************** c_missing_noreturn_ok_p (tree decl) *** 50,100 **** return flag_hosted && MAIN_NAME_P (DECL_ASSEMBLER_NAME (decl)); } - int - c_cannot_inline_tree_fn (tree *fnp) - { - tree fn = *fnp; - bool do_warning = (warn_inline - && DECL_INLINE (fn) - && DECL_DECLARED_INLINE_P (fn) - && !DECL_IN_SYSTEM_HEADER (fn)); - tree always_inline = lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)); - - if (flag_really_no_inline && always_inline == NULL) - { - if (do_warning) - warning (OPT_Winline, "function %q+F can never be inlined because it " - "is suppressed using -fno-inline", fn); - goto cannot_inline; - } - - /* Don't auto-inline anything that might not be bound within - this unit of translation. */ - if (always_inline == NULL - && !DECL_DECLARED_INLINE_P (fn) - && !targetm.binds_local_p (fn)) - { - if (do_warning) - warning (OPT_Winline, "function %q+F can never be inlined because it " - "might not be bound within this unit of translation", fn); - goto cannot_inline; - } - - if (!function_attribute_inlinable_p (fn)) - { - if (do_warning) - warning (OPT_Winline, "function %q+F can never be inlined because it " - "uses attributes conflicting with inlining", fn); - goto cannot_inline; - } - - return 0; - - cannot_inline: - DECL_UNINLINABLE (fn) = 1; - return 1; - } - /* Called from check_global_declarations. */ bool --- 50,55 ---- Index: gcc/cp/tree.c =================================================================== *** gcc.orig/cp/tree.c 2007-08-21 16:06:29.000000000 +0200 --- gcc/cp/tree.c 2007-08-21 17:47:09.000000000 +0200 *************** cp_walk_subtrees (tree *tp, int *walk_su *** 2398,2455 **** #undef WALK_SUBTREE } - /* Decide whether there are language-specific reasons to not inline a - function as a tree. */ - - int - cp_cannot_inline_tree_fn (tree* fnp) - { - tree fn = *fnp; - - /* We can inline a template instantiation only if it's fully - instantiated. */ - if (DECL_TEMPLATE_INFO (fn) - && TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn))) - { - /* Don't instantiate functions that are not going to be - inlined. */ - if (!DECL_INLINE (DECL_TEMPLATE_RESULT - (template_for_substitution (fn)))) - return 1; - - fn = *fnp = instantiate_decl (fn, /*defer_ok=*/0, /*undefined_ok=*/0); - - if (TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn))) - return 1; - } - - if (flag_really_no_inline - && lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL) - return 1; - - /* Don't auto-inline functions that might be replaced at link-time - with an alternative definition. */ - if (!DECL_DECLARED_INLINE_P (fn) && DECL_REPLACEABLE_P (fn)) - { - DECL_UNINLINABLE (fn) = 1; - return 1; - } - - if (varargs_function_p (fn)) - { - DECL_UNINLINABLE (fn) = 1; - return 1; - } - - if (! function_attribute_inlinable_p (fn)) - { - DECL_UNINLINABLE (fn) = 1; - return 1; - } - - return 0; - } - /* Like save_expr, but for C++. */ tree --- 2398,2403 ---- Index: gcc/langhooks.c =================================================================== *** gcc.orig/langhooks.c 2007-08-21 16:06:29.000000000 +0200 --- gcc/langhooks.c 2007-08-21 17:05:06.000000000 +0200 *************** lhd_types_compatible_p (tree x, tree y) *** 276,295 **** return TYPE_MAIN_VARIANT (x) == TYPE_MAIN_VARIANT (y); } - /* lang_hooks.tree_inlining.cannot_inline_tree_fn is called to - determine whether there are language-specific reasons for not - inlining a given function. */ - - int - lhd_tree_inlining_cannot_inline_tree_fn (tree *fnp) - { - if (flag_really_no_inline - && lookup_attribute ("always_inline", DECL_ATTRIBUTES (*fnp)) == NULL) - return 1; - - return 0; - } - /* lang_hooks.tree_dump.dump_tree: Dump language-specific parts of tree nodes. Returns nonzero if it does not want the usual dumping of the second argument. */ --- 276,281 ---- Index: gcc/tree-inline.c =================================================================== *** gcc.orig/tree-inline.c 2007-08-20 13:36:16.000000000 +0200 --- gcc/tree-inline.c 2007-08-21 17:06:04.000000000 +0200 *************** along with GCC; see the file COPYING3. *** 51,56 **** --- 51,58 ---- #include "ipa-prop.h" #include "value-prof.h" #include "tree-pass.h" + #include "target.h" + #include "integrate.h" /* I'm not real happy about this, but we need to handle gimple and non-gimple trees. */ *************** static bool *** 1848,1865 **** inlinable_function_p (tree fn) { bool inlinable = true; /* If we've already decided this function shouldn't be inlined, there's no need to check again. */ if (DECL_UNINLINABLE (fn)) return false; ! /* See if there is any language-specific reason it cannot be ! inlined. (It is important that this hook be called early because ! in C++ it may result in template instantiation.) ! If the function is not inlinable for language-specific reasons, ! it is left up to the langhook to explain why. */ ! inlinable = !lang_hooks.tree_inlining.cannot_inline_tree_fn (&fn); /* If we don't have the function body available, we can't inline it. However, this should not be recorded since we also get here for --- 1850,1893 ---- inlinable_function_p (tree fn) { bool inlinable = true; + bool do_warning; + tree always_inline; /* If we've already decided this function shouldn't be inlined, there's no need to check again. */ if (DECL_UNINLINABLE (fn)) return false; ! /* We only warn for functions declared `inline' by the user. */ ! do_warning = (warn_inline ! && DECL_INLINE (fn) ! && DECL_DECLARED_INLINE_P (fn) ! && !DECL_IN_SYSTEM_HEADER (fn)); ! ! always_inline = lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)); ! ! if (flag_really_no_inline ! && always_inline == NULL) ! { ! if (do_warning) ! warning (OPT_Winline, "function %q+F can never be inlined because it " ! "is suppressed using -fno-inline", fn); ! inlinable = false; ! } ! ! /* Don't auto-inline anything that might not be bound within ! this unit of translation. */ ! else if (!DECL_DECLARED_INLINE_P (fn) ! && DECL_REPLACEABLE_P (fn)) ! inlinable = false; ! ! else if (!function_attribute_inlinable_p (fn)) ! { ! if (do_warning) ! warning (OPT_Winline, "function %q+F can never be inlined because it " ! "uses attributes conflicting with inlining", fn); ! inlinable = false; ! } /* If we don't have the function body available, we can't inline it. However, this should not be recorded since we also get here for *************** inlinable_function_p (tree fn) *** 1893,1906 **** about functions that would for example call alloca. But since this a property of the function, just one warning is enough. As a bonus we can now give more details about the reason why a ! function is not inlinable. ! We only warn for functions declared `inline' by the user. */ ! bool do_warning = (warn_inline ! && DECL_INLINE (fn) ! && DECL_DECLARED_INLINE_P (fn) ! && !DECL_IN_SYSTEM_HEADER (fn)); ! ! if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn))) sorry (inline_forbidden_reason, fn); else if (do_warning) warning (OPT_Winline, inline_forbidden_reason, fn); --- 1921,1928 ---- about functions that would for example call alloca. But since this a property of the function, just one warning is enough. As a bonus we can now give more details about the reason why a ! function is not inlinable. */ ! if (always_inline) sorry (inline_forbidden_reason, fn); else if (do_warning) warning (OPT_Winline, inline_forbidden_reason, fn); Index: gcc/cp/cp-objcp-common.h =================================================================== *** gcc.orig/cp/cp-objcp-common.h 2007-08-21 16:06:29.000000000 +0200 --- gcc/cp/cp-objcp-common.h 2007-08-21 17:06:37.000000000 +0200 *************** extern tree objcp_tsubst_copy_and_build *** 104,112 **** #undef LANG_HOOKS_ATTRIBUTE_TABLE #define LANG_HOOKS_ATTRIBUTE_TABLE cxx_attribute_table - #undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN - #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \ - cp_cannot_inline_tree_fn #undef LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P #define LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P cp_var_mod_type_p #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN --- 104,109 ---- Index: gcc/langhooks-def.h =================================================================== *** gcc.orig/langhooks-def.h 2007-08-21 16:06:29.000000000 +0200 --- gcc/langhooks-def.h 2007-08-21 17:05:24.000000000 +0200 *************** extern tree lhd_expr_to_decl (tree, bool *** 68,74 **** extern tree lhd_builtin_function (tree decl); /* Declarations of default tree inlining hooks. */ - extern int lhd_tree_inlining_cannot_inline_tree_fn (tree *); extern void lhd_initialize_diagnostics (struct diagnostic_context *); extern tree lhd_callgraph_analyze_expr (tree *, int *, tree); --- 68,73 ---- *************** extern void lhd_omp_firstprivatize_type_ *** 131,143 **** #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE NULL /* Tree inlining hooks. */ - #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \ - lhd_tree_inlining_cannot_inline_tree_fn #define LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P \ hook_bool_tree_tree_false #define LANG_HOOKS_TREE_INLINING_INITIALIZER { \ - LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN, \ LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P, \ } --- 130,139 ---- Index: gcc/langhooks.h =================================================================== *** gcc.orig/langhooks.h 2007-08-21 16:06:29.000000000 +0200 --- gcc/langhooks.h 2007-08-21 17:05:14.000000000 +0200 *************** typedef void (*lang_print_tree_hook) (FI *** 35,41 **** struct lang_hooks_for_tree_inlining { - int (*cannot_inline_tree_fn) (tree *); bool (*var_mod_type_p) (tree, tree); }; --- 35,40 ---- Index: gcc/cp/cp-tree.h =================================================================== *** gcc.orig/cp/cp-tree.h 2007-08-21 16:06:29.000000000 +0200 --- gcc/cp/cp-tree.h 2007-08-21 17:47:25.000000000 +0200 *************** extern tree cp_walk_subtrees (tree*, int *** 4739,4745 **** walk_tree_1 (a, b, c, d, cp_walk_subtrees) #define cp_walk_tree_without_duplicates(a,b,c) \ walk_tree_without_duplicates_1 (a, b, c, cp_walk_subtrees) - extern int cp_cannot_inline_tree_fn (tree*); extern tree fold_if_not_in_template (tree); extern tree rvalue (tree); extern tree convert_bitfield_to_declared_type (tree); --- 4739,4744 ----