public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][C++][C] Remove cannot_inline_tree_fn langhook
@ 2007-08-21 16:42 Richard Guenther
  2007-08-24  1:14 ` Mark Mitchell
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Guenther @ 2007-08-21 16:42 UTC (permalink / raw)
  To: gcc-patches


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  <rguenther@suse.de>

	* 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 ----

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH][C++][C] Remove cannot_inline_tree_fn langhook
  2007-08-21 16:42 [PATCH][C++][C] Remove cannot_inline_tree_fn langhook Richard Guenther
@ 2007-08-24  1:14 ` Mark Mitchell
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Mitchell @ 2007-08-24  1:14 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

Richard Guenther wrote:

> 	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.

This is OK.  (I suspect that when I changed the C++ front end to always
do unit-at-a-time I obviated the need to do instantiation.)

Yay, thanks!

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-24  1:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-21 16:42 [PATCH][C++][C] Remove cannot_inline_tree_fn langhook Richard Guenther
2007-08-24  1:14 ` Mark Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).