This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] Cleanup tree-optimize.c
- From: Jan Hubicka <jh at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org, rth at redhat dot com
- Date: Tue, 2 Dec 2003 14:15:46 +0100
- Subject: [tree-ssa] Cleanup tree-optimize.c
Hi,
As promised at sunday, here is patch to remove some of confussion in
tree-optimize.c. We no longer need to clear DECL_RTL, as we always
duplicate everything so we neved set DECL_RTL in the orignal body
(verified by adding abort ()), also GGCing of nested functions can be
reorganized and we don't need to duplicate function body when we are not
going to inline it (I've invented new function for this as I plan to
improve this soon in cgraphunit side)
I also killed some code duplication in between cgraph_expand_function
and tree-optimize. The split in between these two needs to be
re-tought. I think cgraph_optimize can go completely into
tree-optimize.
Bootstrapped/rgtested x86_64-unknown-linux, i686-pc-gnu-linux
and in addition C only with gc,gcac checking.
Honza
2003-12-02 Jan Hubicka <jh@suse.cz>
* Makefile.in (tree-optimize.o): Depend on cgraph.h
* cgraph.h (cgraph_preserve_function_body_p): Declare.
* cgraphunit.c (cgraph_preserve_function_body_p): New function.
* tree-optimize.c: Include cgraph.h
(clear_decl_rtl): Kill.
(tree_rest_of_compilation): Use cgraph_preserve_function_body_p;
do not clear DECL_RTL; do final ggc in the pushed context for nested
functions;
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.903.2.146
diff -c -3 -p -r1.903.2.146 Makefile.in
*** Makefile.in 30 Nov 2003 12:54:40 -0000 1.903.2.146
--- Makefile.in 1 Dec 2003 21:26:54 -0000
*************** tree-optimize.o : tree-optimize.c $(TREE
*** 1591,1597 ****
$(SYSTEM_H) $(RTL_H) $(TREE_H) $(TM_P_H) $(EXPR_H) \
$(GGC_H) output.h diagnostic.h errors.h flags.h tree-alias-common.h \
$(TIMEVAR_H) $(TM_H) coretypes.h $(TREE_DUMP_H) toplev.h function.h \
! langhooks.h flags.h cgraph.h tree-inline.h tree-mudflap.h $(GGC_H)
c-simplify.o : c-simplify.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) errors.h \
$(C_TREE_H) $(C_COMMON_H) diagnostic.h $(TREE_SIMPLE_H) varray.h flags.h \
langhooks.h toplev.h rtl.h $(TREE_FLOW_H) langhooks-def.h \
--- 1591,1598 ----
$(SYSTEM_H) $(RTL_H) $(TREE_H) $(TM_P_H) $(EXPR_H) \
$(GGC_H) output.h diagnostic.h errors.h flags.h tree-alias-common.h \
$(TIMEVAR_H) $(TM_H) coretypes.h $(TREE_DUMP_H) toplev.h function.h \
! langhooks.h flags.h cgraph.h tree-inline.h tree-mudflap.h $(GGC_H) \
! cgraph.h
c-simplify.o : c-simplify.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) errors.h \
$(C_TREE_H) $(C_COMMON_H) diagnostic.h $(TREE_SIMPLE_H) varray.h flags.h \
langhooks.h toplev.h rtl.h $(TREE_FLOW_H) langhooks-def.h \
Index: cgraph.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraph.h,v
retrieving revision 1.1.4.8
diff -c -3 -p -r1.1.4.8 cgraph.h
*** cgraph.h 28 Oct 2003 14:56:10 -0000 1.1.4.8
--- cgraph.h 1 Dec 2003 21:26:54 -0000
*************** void cgraph_optimize (void);
*** 182,186 ****
--- 182,187 ----
void cgraph_mark_needed_node (struct cgraph_node *);
void cgraph_mark_reachable_node (struct cgraph_node *);
bool cgraph_inline_p (tree, tree);
+ bool cgraph_preserve_function_body_p (tree);
#endif /* GCC_CGRAPH_H */
Index: cgraphunit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraphunit.c,v
retrieving revision 1.1.4.15
diff -c -3 -p -r1.1.4.15 cgraphunit.c
*** cgraphunit.c 30 Nov 2003 16:35:21 -0000 1.1.4.15
--- cgraphunit.c 1 Dec 2003 21:26:54 -0000
*************** cgraph_expand_function (struct cgraph_no
*** 495,502 ****
via lang_expand_decl_stmt. */
(*lang_hooks.callgraph.expand_function) (decl);
- if (!cgraph_function_possibly_inlined_p (decl))
- DECL_SAVED_TREE (decl) = NULL;
current_function_decl = NULL;
}
--- 495,500 ----
*************** cgraph_mark_local_functions (void)
*** 1438,1443 ****
--- 1436,1453 ----
}
if (cgraph_dump_file)
fprintf (cgraph_dump_file, "\n\n");
+ }
+
+ /* Return true when function body of DECL still needs to be kept around
+ for later re-use. */
+ bool
+ cgraph_preserve_function_body_p (tree decl)
+ {
+ /* Keep the body; we're going to dump it. */
+ if (dump_enabled_p (TDI_all))
+ return true;
+ /* Too conservative, but OK for now. */
+ return cgraph_function_possibly_inlined_p (decl);
}
/* Perform simple optimizations based on callgraph. */
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 1.1.4.81
diff -c -3 -p -r1.1.4.81 tree-optimize.c
*** tree-optimize.c 30 Nov 2003 21:47:38 -0000 1.1.4.81
--- tree-optimize.c 1 Dec 2003 21:26:55 -0000
*************** Boston, MA 02111-1307, USA. */
*** 44,49 ****
--- 44,50 ----
#include "tree-inline.h"
#include "tree-mudflap.h"
#include "ggc.h"
+ #include "cgraph.h"
/* Rewrite a function tree to the SSA form and perform the SSA-based
optimizations on it. */
*************** set_save_expr_context (tree *tp,
*** 222,264 ****
return NULL;
}
- /* Clear out the DECL_RTL for the non-static local variables in BLOCK and
- its sub-blocks. DATA is the decl of the function being processed. */
-
- static tree
- clear_decl_rtl (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, void *data)
- {
- bool nonstatic_p, local_p;
- tree t = *tp;
-
- switch (TREE_CODE (t))
- {
- case VAR_DECL:
- nonstatic_p = !TREE_STATIC (t) && !DECL_EXTERNAL (t);
- local_p = DECL_CONTEXT (t) == data;
- break;
-
- case PARM_DECL:
- case LABEL_DECL:
- nonstatic_p = true;
- local_p = DECL_CONTEXT (t) == data;
- break;
-
- case RESULT_DECL:
- nonstatic_p = local_p = true;
- break;
-
- default:
- nonstatic_p = local_p = false;
- break;
- }
-
- if (nonstatic_p && local_p)
- SET_DECL_RTL (t, NULL);
-
- return NULL;
- }
-
/* For functions-as-trees languages, this performs all optimization and
compilation for FNDECL. */
--- 223,228 ----
*************** tree_rest_of_compilation (tree fndecl, b
*** 292,298 ****
/* We might need the body of this function so that we can expand
it inline somewhere else. This means not lowering some constructs
such as exception handling. */
! if (DECL_INLINE (fndecl) && flag_inline_trees)
cfun->saved_tree = save_body (fndecl, &cfun->saved_args);
/* Mudflap-instrument any relevant declarations. */
--- 256,262 ----
/* We might need the body of this function so that we can expand
it inline somewhere else. This means not lowering some constructs
such as exception handling. */
! if (cgraph_preserve_function_body_p (fndecl))
cfun->saved_tree = save_body (fndecl, &cfun->saved_args);
/* Mudflap-instrument any relevant declarations. */
*************** tree_rest_of_compilation (tree fndecl, b
*** 396,411 ****
/* Run the optimizers and output the assembler code for this function. */
rest_of_compilation (fndecl);
- /* Undo the GC context switch. */
- if (nested_p)
- ggc_pop_context ();
-
/* Restore original body if still needed. */
if (cfun->saved_tree)
{
DECL_SAVED_TREE (fndecl) = cfun->saved_tree;
DECL_ARGUMENTS (fndecl) = cfun->saved_args;
}
cfun = 0;
DECL_SAVED_INSNS (fndecl) = 0;
--- 360,373 ----
/* Run the optimizers and output the assembler code for this function. */
rest_of_compilation (fndecl);
/* Restore original body if still needed. */
if (cfun->saved_tree)
{
DECL_SAVED_TREE (fndecl) = cfun->saved_tree;
DECL_ARGUMENTS (fndecl) = cfun->saved_args;
}
+ else
+ DECL_SAVED_TREE (fndecl) = NULL;
cfun = 0;
DECL_SAVED_INSNS (fndecl) = 0;
*************** tree_rest_of_compilation (tree fndecl, b
*** 433,450 ****
}
}
! /* Since we don't need the RTL for this function anymore, stop pointing to
! it. That's especially important for LABEL_DECLs, since you can reach all
! the instructions in the function from the CODE_LABEL stored in the
! DECL_RTL for the LABEL_DECL. Walk the BLOCK-tree, clearing DECL_RTL for
! LABEL_DECLs and non-static local variables. Note that we must check the
! context of the variables, otherwise processing a nested function can kill
! the rtl of a variable from an outer function. */
! walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl),
! clear_decl_rtl,
! fndecl);
!
! if (DECL_SAVED_INSNS (fndecl) == 0 && !nested_p && !flag_inline_trees)
{
/* Stop pointing to the local nodes about to be freed.
But DECL_INITIAL must remain nonzero so we know this
--- 395,401 ----
}
}
! if (!nested_p && !flag_inline_trees)
{
/* Stop pointing to the local nodes about to be freed.
But DECL_INITIAL must remain nonzero so we know this
*************** tree_rest_of_compilation (tree fndecl, b
*** 459,465 ****
input_location = saved_loc;
! if (!nested_p)
! ggc_collect ();
timevar_pop (TV_EXPAND);
}
--- 410,419 ----
input_location = saved_loc;
! ggc_collect ();
!
! /* Undo the GC context switch. */
! if (nested_p)
! ggc_pop_context ();
timevar_pop (TV_EXPAND);
}