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]

[PATCH] Inlining heuristics


No changelog, as i don't want it approved, and the changelog is split
into 3 diretories (i'm lazy).
For two reasons.

1. Nathan said he'd have inlining heuristic stuff done by friday, so
   this is just for people who want to see what it'll do to their
   compile times, and as a backup in case he gets very busy.
2. Diego's tree basic block stuff will give us the base needed to do
   profile guided inlining. Once that stuff is committed, we can do
   really cool inlining techniques, really easily.

Index: params.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/params.h,v
retrieving revision 1.7
diff -c -3 -p -w -B -b -r1.7 params.h
*** params.h	2001/06/27 14:35:21	1.7
--- params.h	2001/07/10 17:54:18
*************** typedef enum compiler_param
*** 86,91 ****
--- 86,95 ----
  /* Macros for the various parameters.  */
  #define MAX_INLINE_INSNS \
    PARAM_VALUE (PARAM_MAX_INLINE_INSNS)
+ #define MAX_INLINE_GROWTH \
+   PARAM_VALUE (PARAM_MAX_INLINE_GROWTH)
+ #define MAX_INLINE_CALL_COST \
+   PARAM_VALUE (PARAM_MAX_INLINE_CALL_COST)
  #define MAX_DELAY_SLOT_INSN_SEARCH \
    PARAM_VALUE (PARAM_MAX_DELAY_SLOT_INSN_SEARCH)
  #define MAX_DELAY_SLOT_LIVE_SEARCH \
Index: params.def
===================================================================
RCS file: /cvs/gcc/egcs/gcc/params.def,v
retrieving revision 1.6
diff -c -3 -p -w -B -b -r1.6 params.def
*** params.def	2001/06/27 14:35:21	1.6
--- params.def	2001/07/10 17:54:18
*************** DEFPARAM (PARAM_MAX_INLINE_INSNS,
*** 45,51 ****
  	  "max-inline-insns",
  	  "The maximum number of instructions in a function that is eligible for inlining",
  	  10000)
! 
  /* The maximum number of instructions to consider when looking for an
     instruction to fill a delay slot.  If more than this arbitrary
     number of instructions is searched, the time savings from filling
--- 45,62 ----
  	  "max-inline-insns",
  	  "The maximum number of instructions in a function that is eligible for inlining",
  	  10000)
! /* The maximum factor of code growth to allow during inlining. I.E. if
!    this is two, the function can double in size. */
! DEFPARAM (PARAM_MAX_INLINE_GROWTH,
! 	  "max-inline-growth",
! 	  "The maximum growth factor by which to allow a function to grow during inlining",
! 	  2)
! /* The call cost factor for inlining. Anything less costly than this
!    times the estimated call cost will be inlined. */
! DEFPARAM (PARAM_MAX_INLINE_CALL_COST,
! 	  "max-inline-call-cost",
! 	  "The any time the call costs more than this factor times just inlining the function, we inline it",
! 	  3)
  /* The maximum number of instructions to consider when looking for an
     instruction to fill a delay slot.  If more than this arbitrary
     number of instructions is searched, the time savings from filling
Index: cp/optimize.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/optimize.c,v
retrieving revision 1.74
diff -c -3 -p -w -B -b -r1.74 optimize.c
*** optimize.c	2001/07/02 12:16:57	1.74
--- optimize.c	2001/07/10 17:54:20
*************** typedef struct inline_data
*** 84,89 ****
--- 84,92 ----
    /* Hash table used to prevent walk_tree from visiting the same node
       umpteen million times.  */
    htab_t tree_pruner;
+   /* Number of statements in the current function, before we started inlining stuff into it */ 
+   int original_fn_size;
+   
  } inline_data;
  
  /* Prototypes.  */
*************** inlinable_function_p (fn, id)
*** 634,641 ****
    /* If we're not inlining things, then nothing is inlinable.  */
    if (!flag_inline_trees)
      ;
-   /* If the function was not declared `inline', then we don't inline
-      it.  */
    else if (!DECL_INLINE (fn))
      ;
    /* We can't inline varargs functions.  */
--- 636,641 ----
*************** inlinable_function_p (fn, id)
*** 644,649 ****
--- 644,652 ----
    /* We can't inline functions that are too big.  */
    else if (DECL_NUM_STMTS (fn) * INSNS_PER_STMT > MAX_INLINE_INSNS)
      ;
+   /* We don't want to grow the function too much */
+   else if ((MAX_INLINE_GROWTH * id->original_fn_size) < (id->inlined_stmts + id->original_fn_size))
+     ;
    /* All is well.  We can inline this function.  Traditionally, GCC
       has refused to inline functions using alloca, or functions whose
       values are returned in a PARALLEL, and a few other such obscure
*************** inlinable_function_p (fn, id)
*** 651,666 ****
    else
      inlinable = 1;
  
    /* Squirrel away the result so that we don't have to check again.  */
    DECL_UNINLINABLE (fn) = !inlinable;
  
-   /* Even if this function is not itself too big to inline, it might
-      be that we've done so much inlining already that we don't want to
-      risk inlining any more.  */
-   if ((DECL_NUM_STMTS (fn) + id->inlined_stmts) * INSNS_PER_STMT 
-       > MAX_INLINE_INSNS)
-     inlinable = 0;
- 
    /* We can inline a template instantiation only if it's fully
       instantiated.  */
    if (inlinable
--- 654,666 ----
    else
      inlinable = 1;
  
+   /* If the cost to call is greater than the cost to inline, always inline. */
+   if ((list_length (DECL_ARGUMENTS (fn)) * 5) * MAX_INLINE_CALL_COST >  DECL_NUM_STMTS (fn) * INSNS_PER_STMT)
+     inlinable = 1;
+   
    /* Squirrel away the result so that we don't have to check again.  */
    DECL_UNINLINABLE (fn) = !inlinable;
  
    /* We can inline a template instantiation only if it's fully
       instantiated.  */
    if (inlinable
*************** optimize_inline_calls (fn)
*** 951,956 ****
--- 949,955 ----
    /* Don't allow recursion into FN.  */
    VARRAY_TREE_INIT (id.fns, 32, "fns");
    VARRAY_PUSH_TREE (id.fns, fn);
+   id.original_fn_size = DECL_NUM_STMTS (fn);
    /* Or any functions that aren't finished yet.  */
    prev_fn = NULL_TREE;
    if (current_function_decl)
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/doc/invoke.texi,v
retrieving revision 1.36
diff -c -3 -p -w -B -b -r1.36 invoke.texi
*** invoke.texi	2001/07/09 19:42:27	1.36
--- invoke.texi	2001/07/10 17:54:32
*************** If an function contains more than this m
*** 3816,3821 ****
--- 3816,3828 ----
  will not be inlined.  This option is precisely equivalent to
  @option{-finline-limit}.
  
+ @item max-inline-growth
+ The limit to how much a function can grow through inlining.
+ 
+ @item max-inline-call-cost
+ Any called function where max-inline-call-cost * call cost is greater
+ than the cost to inline the function, causes us to inline that function.
+ 
  @end table
  @end table
  

-- 
"I washed mud, off of mud.
"-Steven Wright


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