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]

-foptimize-sibling-calls



Hi
Here is patch for -foptimize-sibling-calls.
It enables both sibling calls and tail recursion optimizations. If someone
thinks it is usefull to add -foptimize-tail-recursion independently, I can
do this easilly. I think it is resonable to look at tail recursion optimization
as an subset of sibling calls opts, so I didn't implemented it so.

Sat Mar 25 14:02:48 CET 2000  Jan Hubicka  <jh@suse.cz>
	* flags.h (flag_optimize_sibling_calls): Declare.
	* calls.c (expand_call): Fail sibcall when
	!flag_optimize_sibling_calls
	* invoke.texi (flag_optimize_sibling_calls): Document.
	* toplev.c (flag_optimize_sibling_calls): New global variable.
	(f_options): Add flag_optimize_sibling_calls.
	(rest_of_compilation): Conditionize
	optimize_sibling_and_tail_recursive_calls by
	flag_optimize_sibling_calls.
	(main): Set flag_optimize_sibling_calls for -O2.
	* stmt.c (optimize_tail_recursion): Conditionize by
	flag_optimize_sibling_calls, not by optimize.

*** flags.h.old	Sat Mar 25 12:02:23 2000
--- flags.h	Sat Mar 25 12:06:03 2000
*************** extern int flag_volatile_static;
*** 299,304 ****
--- 299,308 ----
  
  extern int flag_fast_math;
  
+ /* Nonzero allows GCC to optimize sibling and tail recursive calls.  */
+ 
+ extern int flag_optimize_sibling_calls;
+ 
  /* Nonzero means the front end generally wants `errno' maintained by math
     operations, like built-in SQRT, unless overridden by flag_fast_math.  */
  
*** invoke.texi.old	Sat Mar 25 13:12:17 2000
--- invoke.texi	Sat Mar 25 13:15:09 2000
*************** in the following sections.
*** 164,171 ****
  -finline-functions  -finline-limit=@var{n}  -fkeep-inline-functions
  -fmove-all-movables  -fno-default-inline  -fno-defer-pop
  -fno-function-cse  -fno-inline  -fno-peephole
! -fomit-frame-pointer  -foptimize-register-moves  -fregmove
! -frerun-cse-after-loop  -frerun-loop-opt  -freduce-all-givs
  -fschedule-insns  -fschedule-insns2  -fstrength-reduce
  -fstrict-aliasing  -fthread-jumps  -funroll-all-loops
  -funroll-loops
--- 164,171 ----
  -finline-functions  -finline-limit=@var{n}  -fkeep-inline-functions
  -fmove-all-movables  -fno-default-inline  -fno-defer-pop
  -fno-function-cse  -fno-inline  -fno-peephole
! -fomit-frame-pointer  -foptimize-register-moves -foptimize-sibling-calls
! -fregmove -frerun-cse-after-loop  -frerun-loop-opt  -freduce-all-givs
  -fschedule-insns  -fschedule-insns2  -fstrength-reduce
  -fstrict-aliasing  -fthread-jumps  -funroll-all-loops
  -funroll-loops
*************** worse than produced by PCC without @samp
*** 2372,2383 ****
  With @samp{-O}, the compiler tries to reduce code size and execution
  time.
  
! When you specify @samp{-O}, the compiler turns on @samp{-fthread-jumps}
! and @samp{-fdefer-pop} on all machines.  The compiler turns on
! @samp{-fdelayed-branch} on machines that have delay slots, and
! @samp{-fomit-frame-pointer} on machines that can support debugging even
! without a frame pointer.  On some machines the compiler also turns
! on other flags.@refill
  
  @item -O2
  Optimize even more.  GCC performs nearly all supported optimizations
--- 2372,2383 ----
  With @samp{-O}, the compiler tries to reduce code size and execution
  time.
  
! When you specify @samp{-O}, the compiler turns on @samp{-fthread-jumps},
! @samp{-foptimize-sibling-calls} and @samp{-fdefer-pop} on all machines.  The
! compiler turns on @samp{-fdelayed-branch} on machines that have delay slots,
! and @samp{-fomit-frame-pointer} on machines that can support debugging even
! without a frame pointer.  On some machines the compiler also turns on other
! flags.@refill
  
  @item -O2
  Optimize even more.  GCC performs nearly all supported optimizations
*************** don't need one.  This avoids the instruc
*** 2460,2465 ****
--- 2460,2468 ----
  restore frame pointers; it also makes an extra register available
  in many functions.  @strong{It also makes debugging impossible on
  some machines.}
+ 
+ @item -foptimize-sibling-calls
+ Optimize sibling and tail recursive calls.
  
  @ifset INTERNALS
  On some machines, such as the Vax, this flag has no effect, because
*** stmt.c.old	Sat Mar 25 14:08:35 2000
--- stmt.c	Sat Mar 25 14:08:25 2000
*************** optimize_tail_recursion (call_expr, last
*** 3100,3106 ****
       It's unsafe if any auto variable in this function
       has its address taken; for simplicity,
       require stack frame to be empty.  */
!   if (optimize
        && call_expr != 0
        && frame_offset == 0
        && TREE_CODE (call_expr) == CALL_EXPR
--- 3100,3106 ----
       It's unsafe if any auto variable in this function
       has its address taken; for simplicity,
       require stack frame to be empty.  */
!   if (flag_optimize_sibling_calls
        && call_expr != 0
        && frame_offset == 0
        && TREE_CODE (call_expr) == CALL_EXPR
*** toplev.c.old	Sat Mar 25 12:02:16 2000
--- toplev.c	Sat Mar 25 14:16:25 2000
*************** int flag_no_peephole = 0;
*** 518,523 ****
--- 518,527 ----
  
  int flag_fast_math = 0;
  
+ /* Nonzero allows GCC to optimize sibling and tail recursive calls.  */
+ 
+ int flag_optimize_sibling_calls = 0;
+ 
  /* Nonzero means the front end generally wants `errno' maintained by math
     operations, like built-in SQRT, unless overridden by flag_fast_math.  */
  
*************** lang_independent_options f_options[] =
*** 862,867 ****
--- 866,873 ----
     "Defer popping functions args from stack until later" },
    {"omit-frame-pointer", &flag_omit_frame_pointer, 1,
     "When possible do not generate stack frames"},
+   {"optimize-sibling-calls", &flag_optimize_sibling_calls, 1,
+    "Optimize sibling and tail recursive calls" },
    {"cse-follow-jumps", &flag_cse_follow_jumps, 1,
     "When running CSE, follow jumps to their targets" },
    {"cse-skip-blocks", &flag_cse_skip_blocks, 1,
*************** rest_of_compilation (decl)
*** 2990,2996 ****
    /* We may have potential sibling or tail recursion sites.  Select one
       (of possibly multiple) methods of performing the call.  */
    init_EXPR_INSN_LIST_cache ();
!   if (optimize)
      optimize_sibling_and_tail_recursive_calls ();
    
    if (ggc_p)
--- 2996,3002 ----
    /* We may have potential sibling or tail recursion sites.  Select one
       (of possibly multiple) methods of performing the call.  */
    init_EXPR_INSN_LIST_cache ();
!   if (flag_optimize_sibling_calls)
      optimize_sibling_and_tail_recursive_calls ();
    
    if (ggc_p)
*************** main (argc, argv)
*** 4729,4734 ****
--- 4735,4741 ----
  
    if (optimize >= 2)
      {
+       flag_optimize_sibling_calls = 1;
        flag_cse_follow_jumps = 1;
        flag_cse_skip_blocks = 1;
        flag_gcse = 1;
*** calls.c.old	Sat Mar 25 12:02:02 2000
--- calls.c	Sat Mar 25 14:15:38 2000
*************** expand_call (exp, target, ignore)
*** 2018,2024 ****
       each argument in an UNSAVE_EXPR.  */
  
    safe_for_reeval = 0;
!   if (optimize >= 2
        && currently_expanding_call == 1
        && stmt_loop_nest_empty ()
        && ! any_pending_cleanups (1))
--- 2018,2024 ----
       each argument in an UNSAVE_EXPR.  */
  
    safe_for_reeval = 0;
!   if (flag_optimize_sibling_calls
        && currently_expanding_call == 1
        && stmt_loop_nest_empty ()
        && ! any_pending_cleanups (1))

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