This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add -fobey-inline (was: Re: Inlining and estimate_num_insns)


On Sun, 27 Feb 2005, Mark Mitchell wrote:

> 5. However, it really might be sensible to have the C++ front end treat
> "inline" as a command, rather than a hint, by default.  It might be that
> explicit uses of inline should be pretty much unconditionally honored.
> (I'd say that functions defined in a class, but not marked inline,
> should not be given this behavior.  That's partly because other
> compilers already treat "inline" in a class definition as more emphatic
> than just defining the function there, so there's a body of existing
> code out there that relies on this.)  I suspect that having the C++
> front end treat "inline" as a command would fix most of the C++ inlining
> problems without requiring any tuning of the inlining algorithms.  Has
> anybody experimented with that potentially much less intrusive fix?

I found a patch to add -fobey-inline that does exactly this lying around
here and updated it.  Bootstrapped on x86_64-unknown-linux-gnu.

If somebody thinks this is a good idea, approve it for mainline/4.0
and I'll apply it.  There is a previous (lengthy) discussion of this
in the thread starting at http://gcc.gnu.org/ml/gcc/2003-03/msg00792.html
(an interesting read ;) - a conclusion is that we at least have a
documentation page on the GCC policy on inlining, maybe with some
optimization hints).

Some quick numbers for my favorite benchmark (tramp3d-v3) shows
                   compile time    binary size      run time
-O2                 1m0s            4506771          1m59s
-O2 -fobey-inline  after waiting 35min I pressed Ctrl-c here...

This also shows why obeying inline by default for C++ like Mark
suggests is not a good idea (the numbers above are with
checking disabled and the old code size estimate).  It also
hints at a fact that we have algorithms that are not linear
in function (or BB) size.

Thanks,
Richard.


2005-Feb-28  Richard Guenther  <rguenth@gcc.gnu.org>

	* common.opt: Add -fobey-inline.
	* doc/invoke.texi: Document.
	* langhooks.c (lhd_tree_inlining_disregard_inline_limit):
	Honour flag_obey_inline.
	* c-objc-common.c (c_disregard_inline_limits): Likewise.


Index: common.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/common.opt,v
retrieving revision 1.62
diff -c -3 -p -r1.62 common.opt
*** common.opt	24 Feb 2005 09:24:13 -0000	1.62
--- common.opt	28 Feb 2005 10:48:55 -0000
*************** fnon-call-exceptions
*** 551,556 ****
--- 551,560 ----
  Common Report Var(flag_non_call_exceptions)
  Support synchronous non-call exceptions

+ fobey-inline
+ Common Report Var(flag_obey_inline)
+ Obey inline keyword and always inline, regardless of size
+
  fomit-frame-pointer
  Common Report Var(flag_omit_frame_pointer)
  When possible do not generate stack frames
Index: langhooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.c,v
retrieving revision 1.81
diff -c -3 -p -r1.81 langhooks.c
*** langhooks.c	21 Feb 2005 14:39:50 -0000	1.81
--- langhooks.c	28 Feb 2005 10:55:02 -0000
*************** lhd_tree_inlining_disregard_inline_limit
*** 327,333 ****
    if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) != NULL)
      return 1;

!   return 0;
  }

  /* lang_hooks.tree_inlining.add_pending_fn_decls is called before
--- 327,333 ----
    if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) != NULL)
      return 1;

!   return flag_obey_inline && DECL_DECLARED_INLINE_P (fn);
  }

  /* lang_hooks.tree_inlining.add_pending_fn_decls is called before
Index: c-objc-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-objc-common.c,v
retrieving revision 1.62
diff -c -3 -p -r1.62 c-objc-common.c
*** c-objc-common.c	27 Jan 2005 18:22:19 -0000	1.62
--- c-objc-common.c	28 Feb 2005 10:48:55 -0000
*************** c_disregard_inline_limits (tree fn)
*** 61,67 ****
      return 1;

    return (!flag_really_no_inline && DECL_DECLARED_INLINE_P (fn)
! 	  && DECL_EXTERNAL (fn));
  }

  int
--- 61,67 ----
      return 1;

    return (!flag_really_no_inline && DECL_DECLARED_INLINE_P (fn)
! 	  && (DECL_EXTERNAL (fn) || flag_obey_inline));
  }

  int
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.583.2.1
diff -c -3 -p -r1.583.2.1 invoke.texi
*** doc/invoke.texi	26 Feb 2005 01:41:38 -0000	1.583.2.1
--- doc/invoke.texi	28 Feb 2005 10:48:56 -0000
*************** Objective-C and Objective-C++ Dialects}.
*** 300,306 ****
  -fno-inline  -fno-math-errno  -fno-peephole  -fno-peephole2 @gol
  -funsafe-math-optimizations  -ffinite-math-only @gol
  -fno-trapping-math  -fno-zero-initialized-in-bss @gol
! -fomit-frame-pointer  -foptimize-register-move @gol
  -foptimize-sibling-calls  -fprefetch-loop-arrays @gol
  -fprofile-generate -fprofile-use @gol
  -fregmove  -frename-registers @gol
--- 300,306 ----
  -fno-inline  -fno-math-errno  -fno-peephole  -fno-peephole2 @gol
  -funsafe-math-optimizations  -ffinite-math-only @gol
  -fno-trapping-math  -fno-zero-initialized-in-bss @gol
! -fobey-inline -fomit-frame-pointer  -foptimize-register-move @gol
  -foptimize-sibling-calls  -fprefetch-loop-arrays @gol
  -fprofile-generate -fprofile-use @gol
  -fregmove  -frename-registers @gol
*************** Don't pay attention to the @code{inline}
*** 4237,4242 ****
--- 4237,4248 ----
  is used to keep the compiler from expanding any functions inline.
  Note that if you are not optimizing, no functions can be expanded inline.

+ @item -fobey-inline
+ @opindex fobey-inline
+ Make the @code{inline} keyword imperative; inline every function marked
+ with the @code{inline} keyword, regardless of size.  By default, the
+ @code{inline} keyword is used as a hint only and heuristics are applied.
+
  @item -finline-functions
  @opindex finline-functions
  Integrate all simple functions into their callers.  The compiler





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]