OSDN Git Service

* ChangeLog: Update entry.
[pf3gnuchains/gcc-fork.git] / gcc / cgraphunit.c
index 81df309..1effef6 100644 (file)
@@ -1,5 +1,5 @@
 /* Callgraph based intraprocedural optimizations.
-   Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
    Contributed by Jan Hubicka
 
 This file is part of GCC.
@@ -105,7 +105,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
        mark_referenced call in assemble_variable functions referenced by
        static variables are noticed too.
 
-       The intra-procedural information is produced and it's existence
+       The intra-procedural information is produced and its existence
        indicated by global_info_ready.  Once this flag is set it is impossible
        to change function from !reachable to reachable and thus
        assemble_variable no longer call mark_referenced.
@@ -142,7 +142,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
         ??? Move this to separate file after tree-ssa merge.
 
        We separate inlining decisions from the inliner itself and store it
-       inside callgraph as so called inline plan.  Reffer to cgraph.c
+       inside callgraph as so called inline plan.  Refer to cgraph.c
        documentation about particular representation of inline plans in the
        callgraph
 
@@ -163,15 +163,18 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
        cgraph_decide_inlining implements heuristics taking whole callgraph
        into account, while cgraph_decide_inlining_incrementally considers
        only one function at a time and is used in non-unit-at-a-time mode.  */
+
+
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
 #include "tree.h"
 #include "rtl.h"
+#include "tree-flow.h"
 #include "tree-inline.h"
 #include "langhooks.h"
-#include "hashtab.h"
+#include "pointer-set.h"
 #include "toplev.h"
 #include "flags.h"
 #include "ggc.h"
@@ -185,6 +188,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "c-common.h"
 #include "intl.h"
 #include "function.h"
+#include "tree-gimple.h"
 
 #define INSNS_PER_CALL 10
 
@@ -207,7 +211,9 @@ static int overall_insns;
    walk_tree_without_duplicates doesn't guarantee each node is visited
    once because it gets a new htab upon each recursive call from
    record_calls_1.  */
-static htab_t visited_nodes;
+static struct pointer_set_t *visited_nodes;
+
+static FILE *cgraph_dump_file;
 
 /* Determine if function DECL is needed.  That is, visible to something
    either outside this translation unit, something magic in the system
@@ -217,7 +223,7 @@ static htab_t visited_nodes;
 static bool
 decide_is_function_needed (struct cgraph_node *node, tree decl)
 {
-  struct cgraph_node *origin;
+  tree origin;
 
   /* If we decided it was needed before, but at the time we didn't have
      the body of the function available, then it's still needed.  We have
@@ -257,8 +263,9 @@ decide_is_function_needed (struct cgraph_node *node, tree decl)
     return false;
   /* Nested functions of extern inline function shall not be emit unless
      we inlined the origin.  */
-  for (origin = node->origin; origin; origin = origin->origin)
-    if (DECL_EXTERNAL (origin->decl))
+  for (origin = decl_function_context (decl); origin;
+       origin = decl_function_context (origin))
+    if (DECL_EXTERNAL (origin))
       return false;
   /* We want to emit COMDAT functions only when absolutely necessary.  */
   if (DECL_COMDAT (decl))
@@ -274,6 +281,8 @@ decide_is_function_needed (struct cgraph_node *node, tree decl)
   return false;
 }
 
+
+
 /* When not doing unit-at-a-time, output all functions enqueued.
    Return true when such a functions were found.  */
 
@@ -337,8 +346,17 @@ cgraph_finalize_function (tree decl, bool nested)
       memset (&node->rtl, 0, sizeof (node->rtl));
       node->analyzed = false;
       node->local.redefined_extern_inline = true;
-      while (node->callees)
-       cgraph_remove_edge (node->callees);
+
+      if (!flag_unit_at_a_time)
+       {
+         struct cgraph_node *n;
+
+         for (n = cgraph_nodes; n; n = n->next)
+           if (n->global.inlined_to == node)
+             cgraph_remove_node (n);
+       }
+
+      cgraph_node_remove_callees (node);
 
       /* We may need to re-queue the node for assembling in case
          we already proceeded it and ignored as not needed.  */
@@ -357,6 +375,9 @@ cgraph_finalize_function (tree decl, bool nested)
   notice_global_symbol (decl);
   node->decl = decl;
   node->local.finalized = true;
+  if (node->nested)
+    lower_nested_functions (decl);
+  gcc_assert (!node->nested);
 
   /* If not unit at a time, then we need to create the call graph
      now, so that called functions can be queued and emitted now.  */
@@ -442,7 +463,7 @@ record_call_1 (tree *tp, int *walk_subtrees, void *data)
     default:
       /* Save some cycles by not walking types and declaration as we
         won't find anything useful there anyway.  */
-      if (DECL_P (*tp) || TYPE_P (*tp))
+      if (IS_TYPE_OR_DECL_P (*tp))
        {
          *walk_subtrees = 0;
          break;
@@ -463,17 +484,16 @@ cgraph_create_edges (struct cgraph_node *node, tree body)
 {
   /* The nodes we're interested in are never shared, so walk
      the tree ignoring duplicates.  */
-  visited_nodes = htab_create (37, htab_hash_pointer,
-                                   htab_eq_pointer, NULL);
+  visited_nodes = pointer_set_create ();
   walk_tree (&body, record_call_1, node, visited_nodes);
-  htab_delete (visited_nodes);
+  pointer_set_destroy (visited_nodes);
   visited_nodes = NULL;
 }
 
 static bool error_found;
 
-/* Callbrack of verify_cgraph_node.  Check that all call_exprs have cgraph
-   nodes.  */
+/* Callback of verify_cgraph_node.  Check that all call_exprs have
+   cgraph nodes.  */
 
 static tree
 verify_cgraph_node_1 (tree *tp, int *walk_subtrees, void *data)
@@ -511,7 +531,7 @@ verify_cgraph_node_1 (tree *tp, int *walk_subtrees, void *data)
 
   /* Save some cycles by not walking types and declaration as we
      won't find anything useful there anyway.  */
-  if (DECL_P (*tp) || TYPE_P (*tp))
+  if (IS_TYPE_OR_DECL_P (*tp))
     *walk_subtrees = 0;
 
   return NULL_TREE;
@@ -776,9 +796,21 @@ cgraph_mark_functions_to_output (void)
          && !DECL_EXTERNAL (decl))
        node->output = 1;
       else
-       /* We should've reclaimed all functions that are not needed.  */
-       gcc_assert (node->global.inlined_to || !DECL_SAVED_TREE (decl)
-                   || DECL_EXTERNAL (decl));
+       {
+         /* We should've reclaimed all functions that are not needed.  */
+#ifdef ENABLE_CHECKING
+         if (!node->global.inlined_to && DECL_SAVED_TREE (decl)
+             && !DECL_EXTERNAL (decl))
+           {
+             dump_cgraph_node (stderr, node);
+             internal_error ("failed to reclaim unneeded function");
+           }
+#endif
+         gcc_assert (node->global.inlined_to || !DECL_SAVED_TREE (decl)
+                     || DECL_EXTERNAL (decl));
+
+       }
+      
     }
 }
 
@@ -808,10 +840,9 @@ cgraph_expand_function (struct cgraph_node *node)
       DECL_SAVED_TREE (node->decl) = NULL;
       DECL_STRUCT_FUNCTION (node->decl) = NULL;
       DECL_INITIAL (node->decl) = error_mark_node;
-      /* Elliminate all call edges.  This is important so the call_expr no longer
+      /* Eliminate all call edges.  This is important so the call_expr no longer
         points to the dead function body.  */
-      while (node->callees)
-       cgraph_remove_edge (node->callees);
+      cgraph_node_remove_callees (node);
     }
 }
 
@@ -877,6 +908,7 @@ cgraph_postorder (struct cgraph_node **order)
   return order_pos;
 }
 
+
 /* Perform reachability analysis and reclaim all unreachable nodes.
    This function also remove unneeded bodies of extern inline functions
    and thus needs to be done only after inlining decisions has been made.  */
@@ -972,8 +1004,7 @@ cgraph_remove_unreachable_nodes (void)
                      DECL_STRUCT_FUNCTION (node->decl) = NULL;
                      DECL_INITIAL (node->decl) = error_mark_node;
                    }
-                 while (node->callees)
-                   cgraph_remove_edge (node->callees);
+                 cgraph_node_remove_callees (node);
                  node->analyzed = false;
                }
              else
@@ -1625,6 +1656,8 @@ cgraph_inline_p (struct cgraph_edge *e, const char **reason)
   return !e->inline_failed;
 }
 
+
+
 /* Expand all functions that must be output.
 
    Attempt to topologically sort the nodes so function is output when
@@ -1644,8 +1677,6 @@ cgraph_expand_all_functions (void)
   int order_pos = 0, new_order_pos = 0;
   int i;
 
-  cgraph_mark_functions_to_output ();
-
   order_pos = cgraph_postorder (order);
   gcc_assert (order_pos == cgraph_n_nodes);
 
@@ -1669,32 +1700,33 @@ cgraph_expand_all_functions (void)
 }
 
 /* Mark all local functions.
-
-   A local function is one whose calls can occur only in the
-   current compilation unit and all its calls are explicit,
-   so we can change its calling convention.
-   We simply mark all static functions whose address is not taken
-   as local.  */
+   
+   A local function is one whose calls can occur only in the current
+   compilation unit and all its calls are explicit, so we can change
+   its calling convention.  We simply mark all static functions whose
+   address is not taken as local.  */
 
 static void
 cgraph_mark_local_functions (void)
 {
   struct cgraph_node *node;
 
-  if (cgraph_dump_file)
-    fprintf (cgraph_dump_file, "\nMarking local functions:");
-
   /* Figure out functions we want to assemble.  */
   for (node = cgraph_nodes; node; node = node->next)
     {
       node->local.local = (!node->needed
                           && DECL_SAVED_TREE (node->decl)
                           && !TREE_PUBLIC (node->decl));
-      if (cgraph_dump_file && node->local.local)
-       fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
     }
+
   if (cgraph_dump_file)
-    fprintf (cgraph_dump_file, "\n\n");
+    {
+      fprintf (cgraph_dump_file, "\nMarking local functions:");
+      for (node = cgraph_nodes; node; node = node->next)
+       if (node->local.local)
+         fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
+      fprintf (cgraph_dump_file, "\n\n");
+    }
 }
 
 /* Return true when function body of DECL still needs to be kept around
@@ -1725,6 +1757,9 @@ cgraph_optimize (void)
 #endif
   if (!flag_unit_at_a_time)
     return;
+
+  process_pending_assemble_externals ();
+
   timevar_push (TV_CGRAPHOPT);
   if (!quiet_flag)
     fprintf (stderr, "Performing intraprocedural optimizations\n");
@@ -1752,6 +1787,9 @@ cgraph_optimize (void)
 #ifdef ENABLE_CHECKING
   verify_cgraph ();
 #endif
+  
+  cgraph_mark_functions_to_output ();
+  
   cgraph_expand_all_functions ();
   if (cgraph_dump_file)
     {
@@ -1839,7 +1877,7 @@ cgraph_build_static_cdtor (char which, tree body, int priority)
 
   /* ??? We will get called LATE in the compilation process.  */
   if (cgraph_global_info_ready)
-    tree_rest_of_compilation (decl, false);
+    tree_rest_of_compilation (decl);
   else
     cgraph_finalize_function (decl, 0);
   
@@ -1854,3 +1892,9 @@ cgraph_build_static_cdtor (char which, tree body, int priority)
       fn (XEXP (DECL_RTL (decl), 0), priority);
     }
 }
+
+void
+init_cgraph (void)
+{
+  cgraph_dump_file = dump_begin (TDI_cgraph, NULL);
+}