/* Perform optimizations on tree structure.
- Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004
+ Free Software Foundation, Inc.
Written by Mark Michell (mark@codesourcery.com).
This file is part of GCC.
#include "hashtab.h"
#include "debug.h"
#include "tree-inline.h"
+#include "flags.h"
+#include "langhooks.h"
+#include "diagnostic.h"
+#include "tree-dump.h"
+#include "tree-gimple.h"
/* Prototypes. */
-static tree calls_setjmp_r (tree *, int *, void *);
static void update_cloned_parm (tree, tree);
-static void dump_function (enum tree_dump_index, tree);
-
-/* Optimize the body of FN. */
-
-void
-optimize_function (tree fn)
-{
- dump_function (TDI_original, fn);
-
- /* While in this function, we may choose to go off and compile
- another function. For example, we might instantiate a function
- in the hopes of inlining it. Normally, that wouldn't trigger any
- actual RTL code-generation -- but it will if the template is
- actually needed. (For example, if it's address is taken, or if
- some other function already refers to the template.) If
- code-generation occurs, then garbage collection will occur, so we
- must protect ourselves, just as we do while building up the body
- of the function. */
- ++function_depth;
-
- if (flag_inline_trees
- /* We do not inline thunks, as (a) the backend tries to optimize
- the call to the thunkee, (b) tree based inlining breaks that
- optimization, (c) virtual functions are rarely inlineable,
- and (d) TARGET_ASM_OUTPUT_MI_THUNK is there to DTRT anyway. */
- && !DECL_THUNK_P (fn))
- {
- optimize_inline_calls (fn);
-
- dump_function (TDI_inlined, fn);
- }
-
- /* Undo the call to ggc_push_context above. */
- --function_depth;
-
- dump_function (TDI_optimized, fn);
-}
-
-/* Called from calls_setjmp_p via walk_tree. */
-
-static tree
-calls_setjmp_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
- void *data ATTRIBUTE_UNUSED)
-{
- /* We're only interested in FUNCTION_DECLS. */
- if (TREE_CODE (*tp) != FUNCTION_DECL)
- return NULL_TREE;
-
- return setjmp_call_p (*tp) ? *tp : NULL_TREE;
-}
-
-/* Returns nonzero if FN calls `setjmp' or some other function that
- can return more than once. This function is conservative; it may
- occasionally return a nonzero value even when FN does not actually
- call `setjmp'. */
-
-bool
-calls_setjmp_p (tree fn)
-{
- return walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
- calls_setjmp_r,
- NULL) != NULL_TREE;
-}
/* CLONED_PARM is a copy of CLONE, generated for a cloned constructor
or destructor. Update it to ensure that the source-position for
maybe_clone_body (tree fn)
{
tree clone;
- bool first = true;
/* We only clone constructors and destructors. */
if (!DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
list. */
for (clone = TREE_CHAIN (fn);
clone && DECL_CLONED_FUNCTION_P (clone);
- clone = TREE_CHAIN (clone), first = false)
+ clone = TREE_CHAIN (clone))
{
tree parm;
tree clone_parm;
DECL_INTERFACE_KNOWN (clone) = DECL_INTERFACE_KNOWN (fn);
DECL_NOT_REALLY_EXTERN (clone) = DECL_NOT_REALLY_EXTERN (fn);
TREE_PUBLIC (clone) = TREE_PUBLIC (fn);
+ DECL_VISIBILITY (clone) = DECL_VISIBILITY (fn);
/* Adjust the parameter names and locations. */
parm = DECL_ARGUMENTS (fn);
clone_parm = TREE_CHAIN (clone_parm);
for (; parm;
parm = TREE_CHAIN (parm), clone_parm = TREE_CHAIN (clone_parm))
- {
- /* Update this parameter. */
- update_cloned_parm (parm, clone_parm);
- /* We should only give unused information for one clone. */
- if (!first)
- TREE_USED (clone_parm) = 1;
- }
+ /* Update this parameter. */
+ update_cloned_parm (parm, clone_parm);
/* Start processing the function. */
push_to_top_level ();
/* Clone the body. */
clone_body (clone, fn, decl_map);
- /* There are as many statements in the clone as in the
- original. */
- DECL_ESTIMATED_INSNS (clone) = DECL_ESTIMATED_INSNS (fn);
-
/* Clean up. */
splay_tree_delete (decl_map);
/* We don't need to process the original function any further. */
return 1;
}
-
-/* Dump FUNCTION_DECL FN as tree dump PHASE. */
-
-static void
-dump_function (enum tree_dump_index phase, tree fn)
-{
- FILE *stream;
- int flags;
-
- stream = dump_begin (phase, &flags);
- if (stream)
- {
- fprintf (stream, "\n;; Function %s",
- decl_as_string (fn, TFF_DECL_SPECIFIERS));
- fprintf (stream, " (%s)\n",
- decl_as_string (DECL_ASSEMBLER_NAME (fn), 0));
- fprintf (stream, ";; enabled by -fdump-%s\n", dump_flag_name (phase));
- fprintf (stream, "\n");
-
- dump_node (fn, TDF_SLIM | flags, stream);
- dump_end (phase, stream);
- }
-}