This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Tail recursion optimisation
Hello,
> I wonder if we should move the setting of current_function_stdarg
> from assign_parms to allocate_struct_function.
>
> As far as the rest, I'd like to see
>
> (1) This in a new file. Say tree-tailcall.c.
> (2) The function not being named recursion specific, say,
> tree_optimize_tail_calls.
> (3) This monster function broken up a bit.
here is the patch with these changes.
Zdenek
* tree-tailcall.c: New.
* Makefile.in (tree-tailcall.o): Add.
* function.c (assign_parms): Setting of current_function_stdarg
moved ...
(allocate_struct_function): ... here.
* tree-dump.c (dump_files): Add .tail dump.
* tree-flow.h (tree_optimize_tail_calls): Declare.
* tree-optimize.c (optimize_function_tree): Call
tree_optimize_tail_calls.
* tree.h (enum tree_dump_index): Add TDI_tail.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.903.2.120
diff -c -3 -p -r1.903.2.120 Makefile.in
*** Makefile.in 15 Oct 2003 18:22:59 -0000 1.903.2.120
--- Makefile.in 17 Oct 2003 22:00:37 -0000
*************** OBJS-common = \
*** 866,872 ****
tree-alias-type.o gimplify.o tree-nomudflap.o tree-pretty-print.o \
tree-alias-common.o tree-ssa-ccp.o tree-browser.o @ANDER@ tree-ssa-dce.o \
tree-ssa-pre.o tree-ssa-copyprop.o tree-ssa-live.o tree-must-alias.o \
! tree-ssa-dom.o domwalk.o \
alias.o bb-reorder.o bitmap.o builtins.o caller-save.o calls.o \
cfg.o cfganal.o cfgbuild.o cfgcleanup.o cfglayout.o cfgloop.o \
cfgloopanal.o cfgloopmanip.o loop-init.o loop-unswitch.o loop-unroll.o \
--- 866,872 ----
tree-alias-type.o gimplify.o tree-nomudflap.o tree-pretty-print.o \
tree-alias-common.o tree-ssa-ccp.o tree-browser.o @ANDER@ tree-ssa-dce.o \
tree-ssa-pre.o tree-ssa-copyprop.o tree-ssa-live.o tree-must-alias.o \
! tree-ssa-dom.o domwalk.o tree-tailcall.o \
alias.o bb-reorder.o bitmap.o builtins.o caller-save.o calls.o \
cfg.o cfganal.o cfgbuild.o cfgcleanup.o cfglayout.o cfgloop.o \
cfgloopanal.o cfgloopmanip.o loop-init.o loop-unswitch.o loop-unroll.o \
*************** tree-cfg.o : tree-cfg.c $(TREE_FLOW_H) $
*** 1553,1558 ****
--- 1553,1561 ----
$(RTL_H) $(TREE_H) $(TM_P_H) $(EXPR_H) $(GGC_H) flags.h output.h \
diagnostic.h errors.h function.h $(TIMEVAR_H) $(TM_H) coretypes.h \
$(TREE_DUMP_H) except.h langhooks.h cfgloop.h
+ tree-tailcall.o : tree-tailcall.c $(TREE_FLOW_H) $(CONFIG_H) $(SYSTEM_H) \
+ $(RTL_H) $(TREE_H) $(TM_P_H) function.h $(TM_H) coretypes.h \
+ $(TREE_DUMP_H) diagnostic.h
tree-dfa.o : tree-dfa.c $(TREE_FLOW_H) $(CONFIG_H) $(SYSTEM_H) \
$(RTL_H) $(TREE_H) $(TM_P_H) $(EXPR_H) $(GGC_H) output.h diagnostic.h \
errors.h tree-inline.h $(HASHTAB_H) flags.h function.h $(TIMEVAR_H) \
Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.374.2.27
diff -c -3 -p -r1.374.2.27 function.c
*** function.c 6 Oct 2003 17:36:33 -0000 1.374.2.27
--- function.c 17 Oct 2003 22:00:37 -0000
*************** assign_parms (tree fndecl)
*** 4260,4271 ****
/* Nonzero if function takes extra anonymous args.
This means the last named arg must be on the stack
right before the anonymous ones. */
! int stdarg
! = (TYPE_ARG_TYPES (fntype) != 0
! && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
! != void_type_node));
!
! current_function_stdarg = stdarg;
/* If the reg that the virtual arg pointer will be translated into is
not a fixed reg or is the stack pointer, make a copy of the virtual
--- 4260,4266 ----
/* Nonzero if function takes extra anonymous args.
This means the last named arg must be on the stack
right before the anonymous ones. */
! int stdarg = current_function_stdarg;
/* If the reg that the virtual arg pointer will be translated into is
not a fixed reg or is the stack pointer, make a copy of the virtual
*************** void
*** 6295,6300 ****
--- 6290,6296 ----
allocate_struct_function (tree fndecl)
{
tree result;
+ tree fntype = fndecl ? TREE_TYPE (fndecl) : NULL_TREE;
cfun = ggc_alloc_cleared (sizeof (struct function));
*************** allocate_struct_function (tree fndecl)
*** 6339,6344 ****
--- 6335,6346 ----
current_function_needs_context
= (decl_function_context (current_function_decl) != 0
&& ! DECL_NO_STATIC_CHAIN (current_function_decl));
+
+ current_function_stdarg
+ = (fntype
+ && TYPE_ARG_TYPES (fntype) != 0
+ && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
+ != void_type_node));
}
/* Reset cfun, and other non-struct-function variables to defaults as
Index: tree-dump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-dump.c,v
retrieving revision 1.6.2.41
diff -c -3 -p -r1.6.2.41 tree-dump.c
*** tree-dump.c 24 Sep 2003 21:43:04 -0000 1.6.2.41
--- tree-dump.c 17 Oct 2003 22:00:37 -0000
*************** static struct dump_file_info dump_files[
*** 655,660 ****
--- 655,661 ----
{".eh", "tree-eh", 0, 0},
{".cfg", "tree-cfg", 0, 0},
{".dot", "tree-dot", 0, 0},
+ {".tail", "tree-tail", 0, 0},
{".pta", "tree-pta", 0, 0},
{".alias", "tree-alias", 0, 0},
{".ssa1", "tree-ssa1", 0, 0},
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.129
diff -c -3 -p -r1.1.4.129 tree-flow.h
*** tree-flow.h 16 Oct 2003 14:32:26 -0000 1.1.4.129
--- tree-flow.h 17 Oct 2003 22:00:37 -0000
*************** extern void bsi_move_to_bb_end (block_st
*** 440,445 ****
--- 440,446 ----
extern basic_block label_to_block (tree);
extern bool cleanup_cond_expr_graph (basic_block, tree);
extern bool cleanup_switch_expr_graph (basic_block, tree);
+ extern void tree_optimize_tail_calls (void);
/* In tree-dfa.c */
void find_referenced_vars (tree);
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 1.1.4.55
diff -c -3 -p -r1.1.4.55 tree-optimize.c
*** tree-optimize.c 8 Oct 2003 23:35:08 -0000 1.1.4.55
--- tree-optimize.c 17 Oct 2003 22:00:37 -0000
*************** optimize_function_tree (tree fndecl)
*** 78,87 ****
/* Find all the variables referenced in the function. */
find_referenced_vars (fndecl);
/* Compute aliasing information for all the variables referenced in
the function. */
compute_may_aliases (fndecl);
-
/* BEGIN SSA PASSES
--- 78,89 ----
/* Find all the variables referenced in the function. */
find_referenced_vars (fndecl);
+ /* Eliminate tail recursion calls. */
+ tree_optimize_tail_calls ();
+
/* Compute aliasing information for all the variables referenced in
the function. */
compute_may_aliases (fndecl);
/* BEGIN SSA PASSES
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.342.2.109
diff -c -3 -p -r1.342.2.109 tree.h
*** tree.h 16 Oct 2003 14:32:26 -0000 1.342.2.109
--- tree.h 17 Oct 2003 22:00:37 -0000
*************** enum tree_dump_index
*** 3492,3497 ****
--- 3492,3498 ----
TDI_cfg, /* dump the flowgraph for each function. */
TDI_dot, /* create a dot graph file for each
function's flowgraph. */
+ TDI_tail, /* dump after tail recursion elimination */
TDI_pta, /* dump points-to information for each
function. */
TDI_alias, /* dump aliasing information. */