OSDN Git Service

2008-05-01 H.J. Lu <hongjiu.lu@intel.com>
[pf3gnuchains/gcc-fork.git] / gcc / cgraph.c
index 87114e2..86940b8 100644 (file)
@@ -1,12 +1,13 @@
 /* Callgraph handling code.
-   Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
+   Free Software Foundation, Inc.
    Contributed by Jan Hubicka
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
 version.
 
 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -15,9 +16,8 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 /*  This file contains basic routines manipulating call graph
 
@@ -246,7 +246,7 @@ cgraph_node_for_asm (tree asmname)
 static hashval_t
 edge_hash (const void *x)
 {
-  return htab_hash_pointer (((struct cgraph_edge *) x)->call_stmt);
+  return htab_hash_pointer (((const struct cgraph_edge *) x)->call_stmt);
 }
 
 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y.  */
@@ -254,7 +254,7 @@ edge_hash (const void *x)
 static int
 edge_eq (const void *x, const void *y)
 {
-  return ((struct cgraph_edge *) x)->call_stmt == y;
+  return ((const struct cgraph_edge *) x)->call_stmt == y;
 }
 
 /* Return callgraph edge representing CALL_EXPR statement.  */
@@ -441,6 +441,51 @@ cgraph_redirect_edge_callee (struct cgraph_edge *e, struct cgraph_node *n)
   e->callee = n;
 }
 
+/* Update or remove corresponding cgraph edge if a call OLD_CALL
+   in OLD_STMT changed into NEW_STMT.  */
+
+void
+cgraph_update_edges_for_call_stmt (tree old_stmt, tree old_call,
+                                  tree new_stmt)
+{
+  tree new_call = get_call_expr_in (new_stmt);
+  struct cgraph_node *node = cgraph_node (cfun->decl);
+
+  if (old_call != new_call)
+    {
+      struct cgraph_edge *e = cgraph_edge (node, old_stmt);
+      struct cgraph_edge *ne = NULL;
+      tree new_decl;
+
+      if (e)
+       {
+         gcov_type count = e->count;
+         int frequency = e->frequency;
+         int loop_nest = e->loop_nest;
+
+         cgraph_remove_edge (e);
+         if (new_call)
+           {
+             new_decl = get_callee_fndecl (new_call);
+             if (new_decl)
+               {
+                 ne = cgraph_create_edge (node, cgraph_node (new_decl),
+                                          new_stmt, count, frequency,
+                                          loop_nest);
+                 gcc_assert (ne->inline_failed);
+               }
+           }
+       }
+    }
+  else if (old_stmt != new_stmt)
+    {
+      struct cgraph_edge *e = cgraph_edge (node, old_stmt);
+
+      if (e)
+       cgraph_set_call_stmt (e, new_stmt);
+    }
+}
+
 /* Remove all callees from the node.  */
 
 void
@@ -658,7 +703,9 @@ cgraph_node_name (struct cgraph_node *node)
 const char * const cgraph_availability_names[] =
   {"unset", "not_available", "overwrittable", "available", "local"};
 
-/* Dump given cgraph node.  */
+
+/* Dump call graph node NODE to file F.  */
+
 void
 dump_cgraph_node (FILE *f, struct cgraph_node *node)
 {
@@ -743,7 +790,17 @@ dump_cgraph_node (FILE *f, struct cgraph_node *node)
   fprintf (f, "\n");
 }
 
-/* Dump the callgraph.  */
+
+/* Dump call graph node NODE to stderr.  */
+
+void
+debug_cgraph_node (struct cgraph_node *node)
+{
+  dump_cgraph_node (stderr, node);
+}
+
+
+/* Dump the callgraph to file F.  */
 
 void
 dump_cgraph (FILE *f)
@@ -755,7 +812,18 @@ dump_cgraph (FILE *f)
     dump_cgraph_node (f, node);
 }
 
+
+/* Dump the call graph to stderr.  */
+
+void
+debug_cgraph (void)
+{
+  dump_cgraph (stderr);
+}
+
+
 /* Set the DECL_ASSEMBLER_NAME and update cgraph hashtables.  */
+
 void
 change_decl_assembler_name (tree decl, tree name)
 {
@@ -1002,7 +1070,7 @@ cgraph_add_new_function (tree fndecl, bool lowered)
           tree_lowering_passes (fndecl);
        bitmap_obstack_initialize (NULL);
        if (!gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl)) && optimize)
-         execute_pass_list (pass_early_local_passes.sub);
+         execute_pass_list (pass_early_local_passes.pass.sub);
        bitmap_obstack_release (NULL);
        tree_rest_of_compilation (fndecl);
        pop_cfun ();