]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/cgraphbuild.c
gcc-changelog: come up with GitInfo wrapper.
[thirdparty/gcc.git] / gcc / cgraphbuild.c
index 02c373aa29953d03782abc38ec0abd0970de732f..d72b3514f673e2835d0ac03c5411b9a2bdbff1c3 100644 (file)
@@ -1,6 +1,5 @@
 /* Callgraph construction.
-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
-   Free Software Foundation, Inc.
+   Copyright (C) 2003-2020 Free Software Foundation, Inc.
    Contributed by Jan Hubicka
 
 This file is part of GCC.
@@ -22,21 +21,22 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
+#include "backend.h"
 #include "tree.h"
-#include "tree-flow.h"
-#include "langhooks.h"
-#include "pointer-set.h"
-#include "cgraph.h"
-#include "intl.h"
 #include "gimple.h"
 #include "tree-pass.h"
+#include "cgraph.h"
+#include "gimple-fold.h"
+#include "gimple-iterator.h"
+#include "gimple-walk.h"
 #include "ipa-utils.h"
+#include "except.h"
 
 /* Context of record_reference.  */
 struct record_reference_ctx
 {
   bool only_vars;
+  struct varpool_node *varpool_node;
 };
 
 /* Walk tree and record all calls and references to functions/variables.
@@ -49,7 +49,13 @@ record_reference (tree *tp, int *walk_subtrees, void *data)
 {
   tree t = *tp;
   tree decl;
-  struct record_reference_ctx *ctx = (struct record_reference_ctx *)data;
+  record_reference_ctx *ctx = (record_reference_ctx *)data;
+
+  t = canonicalize_constructor_val (t, NULL);
+  if (!t)
+    t = *tp;
+  else if (t != *tp)
+    *tp = t;
 
   switch (TREE_CODE (t))
     {
@@ -63,15 +69,18 @@ record_reference (tree *tp, int *walk_subtrees, void *data)
       /* Record dereferences to the functions.  This makes the
         functions reachable unconditionally.  */
       decl = get_base_var (*tp);
-      if (TREE_CODE (decl) == FUNCTION_DECL && !ctx->only_vars)
-       cgraph_mark_address_taken_node (cgraph_node (decl));
+      if (TREE_CODE (decl) == FUNCTION_DECL)
+       {
+         cgraph_node *node = cgraph_node::get_create (decl);
+         if (!ctx->only_vars)
+           node->mark_address_taken ();
+         ctx->varpool_node->create_reference (node, IPA_REF_ADDR);
+       }
 
-      if (TREE_CODE (decl) == VAR_DECL)
+      if (VAR_P (decl))
        {
-         gcc_assert (TREE_STATIC (decl) || DECL_EXTERNAL (decl));
-         if (lang_hooks.callgraph.analyze_expr)
-           lang_hooks.callgraph.analyze_expr (&decl, walk_subtrees);
-         varpool_mark_needed_node (varpool_node (decl));
+         varpool_node *vnode = varpool_node::get_create (decl);
+         ctx->varpool_node->create_reference (vnode, IPA_REF_ADDR);
        }
       *walk_subtrees = 0;
       break;
@@ -84,35 +93,95 @@ record_reference (tree *tp, int *walk_subtrees, void *data)
          *walk_subtrees = 0;
          break;
        }
-
-      if ((unsigned int) TREE_CODE (t) >= LAST_AND_UNUSED_TREE_CODE)
-       return lang_hooks.callgraph.analyze_expr (tp, walk_subtrees);
       break;
     }
 
   return NULL_TREE;
 }
 
-/* Reset inlining information of all incoming call edges of NODE.  */
+/* Record references to typeinfos in the type list LIST.  */
 
-void
-reset_inline_failed (struct cgraph_node *node)
+static void
+record_type_list (cgraph_node *node, tree list)
+{
+  for (; list; list = TREE_CHAIN (list))
+    {
+      tree type = TREE_VALUE (list);
+      
+      if (TYPE_P (type))
+       type = lookup_type_for_runtime (type);
+      STRIP_NOPS (type);
+      if (TREE_CODE (type) == ADDR_EXPR)
+       {
+         type = TREE_OPERAND (type, 0);
+         if (VAR_P (type))
+           {
+             varpool_node *vnode = varpool_node::get_create (type);
+             node->create_reference (vnode, IPA_REF_ADDR);
+           }
+       }
+    }
+}
+
+/* Record all references we will introduce by producing EH tables
+   for NODE.  */
+
+static void
+record_eh_tables (cgraph_node *node, function *fun)
 {
-  struct cgraph_edge *e;
+  eh_region i;
 
-  for (e = node->callers; e; e = e->next_caller)
+  if (DECL_FUNCTION_PERSONALITY (node->decl))
     {
-      e->callee->global.inlined_to = NULL;
-      if (!node->analyzed)
-       e->inline_failed = CIF_BODY_NOT_AVAILABLE;
-      else if (node->local.redefined_extern_inline)
-       e->inline_failed = CIF_REDEFINED_EXTERN_INLINE;
-      else if (!node->local.inlinable)
-       e->inline_failed = CIF_FUNCTION_NOT_INLINABLE;
-      else if (e->call_stmt_cannot_inline_p)
-       e->inline_failed = CIF_MISMATCHED_ARGUMENTS;
+      tree per_decl = DECL_FUNCTION_PERSONALITY (node->decl);
+      cgraph_node *per_node = cgraph_node::get_create (per_decl);
+
+      node->create_reference (per_node, IPA_REF_ADDR);
+      per_node->mark_address_taken ();
+    }
+
+  i = fun->eh->region_tree;
+  if (!i)
+    return;
+
+  while (1)
+    {
+      switch (i->type)
+       {
+       case ERT_CLEANUP:
+       case ERT_MUST_NOT_THROW:
+         break;
+
+       case ERT_TRY:
+         {
+           eh_catch c;
+           for (c = i->u.eh_try.first_catch; c; c = c->next_catch)
+             record_type_list (node, c->type_list);
+         }
+         break;
+
+       case ERT_ALLOWED_EXCEPTIONS:
+         record_type_list (node, i->u.allowed.type_list);
+         break;
+       }
+      /* If there are sub-regions, process them.  */
+      if (i->inner)
+       i = i->inner;
+      /* If there are peers, process them.  */
+      else if (i->next_peer)
+       i = i->next_peer;
+      /* Otherwise, step back up the tree to the next peer.  */
       else
-       e->inline_failed = CIF_FUNCTION_NOT_CONSIDERED;
+       {
+         do
+           {
+             i = i->outer;
+             if (i == NULL)
+               return;
+           }
+         while (i->next_peer == NULL);
+         i = i->next_peer;
+       }
     }
 }
 
@@ -121,47 +190,28 @@ reset_inline_failed (struct cgraph_node *node)
 int
 compute_call_stmt_bb_frequency (tree decl, basic_block bb)
 {
-  int entry_freq = ENTRY_BLOCK_PTR_FOR_FUNCTION
-                    (DECL_STRUCT_FUNCTION (decl))->frequency;
-  int freq = bb->frequency;
-
-  if (profile_status_for_function (DECL_STRUCT_FUNCTION (decl)) == PROFILE_ABSENT)
-    return CGRAPH_FREQ_BASE;
-
-  if (!entry_freq)
-    entry_freq = 1, freq++;
-
-  freq = freq * CGRAPH_FREQ_BASE / entry_freq;
-  if (freq > CGRAPH_FREQ_MAX)
-    freq = CGRAPH_FREQ_MAX;
-
-  return freq;
+  return bb->count.to_cgraph_frequency
+      (ENTRY_BLOCK_PTR_FOR_FN (DECL_STRUCT_FUNCTION (decl))->count);
 }
 
 /* Mark address taken in STMT.  */
 
 static bool
-mark_address (gimple stmt ATTRIBUTE_UNUSED, tree addr,
-             void *data ATTRIBUTE_UNUSED)
+mark_address (gimple *stmt, tree addr, tree, void *data)
 {
+  addr = get_base_address (addr);
   if (TREE_CODE (addr) == FUNCTION_DECL)
     {
-      struct cgraph_node *node = cgraph_node (addr);
-      cgraph_mark_address_taken_node (node);
+      cgraph_node *node = cgraph_node::get_create (addr);
+      node->mark_address_taken ();
+      ((symtab_node *)data)->create_reference (node, IPA_REF_ADDR, stmt);
     }
-  else
+  else if (addr && VAR_P (addr)
+          && (TREE_STATIC (addr) || DECL_EXTERNAL (addr)))
     {
-      addr = get_base_address (addr);
-      if (addr && TREE_CODE (addr) == VAR_DECL
-         && (TREE_STATIC (addr) || DECL_EXTERNAL (addr)))
-       {
-         struct varpool_node *vnode = varpool_node (addr);
-         int walk_subtrees;
+      varpool_node *vnode = varpool_node::get_create (addr);
 
-         if (lang_hooks.callgraph.analyze_expr)
-           lang_hooks.callgraph.analyze_expr (&addr, &walk_subtrees);
-         varpool_mark_needed_node (vnode);
-       }
+      ((symtab_node *)data)->create_reference (vnode, IPA_REF_ADDR, stmt);
     }
 
   return false;
@@ -170,19 +220,22 @@ mark_address (gimple stmt ATTRIBUTE_UNUSED, tree addr,
 /* Mark load of T.  */
 
 static bool
-mark_load (gimple stmt ATTRIBUTE_UNUSED, tree t,
-          void *data ATTRIBUTE_UNUSED)
+mark_load (gimple *stmt, tree t, tree, void *data)
 {
   t = get_base_address (t);
-  if (TREE_CODE (t) == VAR_DECL
-      && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
+  if (t && TREE_CODE (t) == FUNCTION_DECL)
     {
-      struct varpool_node *vnode = varpool_node (t);
-      int walk_subtrees;
+      /* ??? This can happen on platforms with descriptors when these are
+        directly manipulated in the code.  Pretend that it's an address.  */
+      cgraph_node *node = cgraph_node::get_create (t);
+      node->mark_address_taken ();
+      ((symtab_node *)data)->create_reference (node, IPA_REF_ADDR, stmt);
+    }
+  else if (t && VAR_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
+    {
+      varpool_node *vnode = varpool_node::get_create (t);
 
-      if (lang_hooks.callgraph.analyze_expr)
-       lang_hooks.callgraph.analyze_expr (&t, &walk_subtrees);
-      varpool_mark_needed_node (vnode);
+      ((symtab_node *)data)->create_reference (vnode, IPA_REF_LOAD, stmt);
     }
   return false;
 }
@@ -190,106 +243,132 @@ mark_load (gimple stmt ATTRIBUTE_UNUSED, tree t,
 /* Mark store of T.  */
 
 static bool
-mark_store (gimple stmt ATTRIBUTE_UNUSED, tree t,
-           void *data ATTRIBUTE_UNUSED)
+mark_store (gimple *stmt, tree t, tree, void *data)
 {
   t = get_base_address (t);
-  if (TREE_CODE (t) == VAR_DECL
-      && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
+  if (t && VAR_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
     {
-      struct varpool_node *vnode = varpool_node (t);
-      int walk_subtrees;
+      varpool_node *vnode = varpool_node::get_create (t);
 
-      if (lang_hooks.callgraph.analyze_expr)
-       lang_hooks.callgraph.analyze_expr (&t, &walk_subtrees);
-      varpool_mark_needed_node (vnode);
+      ((symtab_node *)data)->create_reference (vnode, IPA_REF_STORE, stmt);
      }
   return false;
 }
 
+/* Record all references from cgraph_node that are taken in statement STMT.  */
+
+void
+cgraph_node::record_stmt_references (gimple *stmt)
+{
+  walk_stmt_load_store_addr_ops (stmt, this, mark_load, mark_store,
+                                mark_address);
+}
+
 /* Create cgraph edges for function calls.
    Also look for functions and variables having addresses taken.  */
 
-static unsigned int
-build_cgraph_edges (void)
+namespace {
+
+const pass_data pass_data_build_cgraph_edges =
+{
+  GIMPLE_PASS, /* type */
+  "*build_cgraph_edges", /* name */
+  OPTGROUP_NONE, /* optinfo_flags */
+  TV_NONE, /* tv_id */
+  PROP_cfg, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  0, /* todo_flags_finish */
+};
+
+class pass_build_cgraph_edges : public gimple_opt_pass
+{
+public:
+  pass_build_cgraph_edges (gcc::context *ctxt)
+    : gimple_opt_pass (pass_data_build_cgraph_edges, ctxt)
+  {}
+
+  /* opt_pass methods: */
+  virtual unsigned int execute (function *);
+
+}; // class pass_build_cgraph_edges
+
+unsigned int
+pass_build_cgraph_edges::execute (function *fun)
 {
   basic_block bb;
-  struct cgraph_node *node = cgraph_node (current_function_decl);
-  struct pointer_set_t *visited_nodes = pointer_set_create ();
+  cgraph_node *node = cgraph_node::get (current_function_decl);
   gimple_stmt_iterator gsi;
-  tree step;
+  tree decl;
+  unsigned ix;
 
   /* Create the callgraph edges and record the nodes referenced by the function.
      body.  */
-  FOR_EACH_BB (bb)
+  FOR_EACH_BB_FN (bb, fun)
     {
       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
        {
-         gimple stmt = gsi_stmt (gsi);
+         gimple *stmt = gsi_stmt (gsi);
          tree decl;
 
-         if (is_gimple_call (stmt) && (decl = gimple_call_fndecl (stmt)))
-           cgraph_create_edge (node, cgraph_node (decl), stmt,
-                               bb->count,
-                               compute_call_stmt_bb_frequency
-                                 (current_function_decl, bb),
-                               bb->loop_depth);
-         walk_stmt_load_store_addr_ops (stmt, node, mark_load,
-                                        mark_store, mark_address);
-         if (gimple_code (stmt) == GIMPLE_OMP_PARALLEL
-             && gimple_omp_parallel_child_fn (stmt))
+         if (is_gimple_debug (stmt))
+           continue;
+
+         if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
            {
-             tree fn = gimple_omp_parallel_child_fn (stmt);
-             cgraph_mark_needed_node (cgraph_node (fn));
+             decl = gimple_call_fndecl (call_stmt);
+             if (decl)
+               node->create_edge (cgraph_node::get_create (decl), call_stmt, bb->count);
+             else if (gimple_call_internal_p (call_stmt))
+               ;
+             else
+               node->create_indirect_edge (call_stmt,
+                                           gimple_call_flags (call_stmt),
+                                           bb->count);
+           }
+         node->record_stmt_references (stmt);
+         if (gomp_parallel *omp_par_stmt = dyn_cast <gomp_parallel *> (stmt))
+           {
+             tree fn = gimple_omp_parallel_child_fn (omp_par_stmt);
+             node->create_reference (cgraph_node::get_create (fn),
+                                     IPA_REF_ADDR, stmt);
            }
          if (gimple_code (stmt) == GIMPLE_OMP_TASK)
            {
              tree fn = gimple_omp_task_child_fn (stmt);
              if (fn)
-               cgraph_mark_needed_node (cgraph_node (fn));
+               node->create_reference (cgraph_node::get_create (fn),
+                                       IPA_REF_ADDR, stmt);
              fn = gimple_omp_task_copy_fn (stmt);
              if (fn)
-               cgraph_mark_needed_node (cgraph_node (fn));
+               node->create_reference (cgraph_node::get_create (fn),
+                                       IPA_REF_ADDR, stmt);
            }
        }
-      for (gsi = gsi_start (phi_nodes (bb)); !gsi_end_p (gsi); gsi_next (&gsi))
-       walk_stmt_load_store_addr_ops (gsi_stmt (gsi), node,
-                                      mark_load, mark_store, mark_address);
+      for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+       node->record_stmt_references (gsi_stmt (gsi));
    }
 
   /* Look for initializers of constant variables and private statics.  */
-  for (step = cfun->local_decls;
-       step;
-       step = TREE_CHAIN (step))
-    {
-      tree decl = TREE_VALUE (step);
-      if (TREE_CODE (decl) == VAR_DECL
-         && (TREE_STATIC (decl) && !DECL_EXTERNAL (decl)))
-       varpool_finalize_decl (decl);
-    }
+  FOR_EACH_LOCAL_DECL (fun, ix, decl)
+    if (VAR_P (decl)
+       && (TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
+       && !DECL_HAS_VALUE_EXPR_P (decl)
+       && TREE_TYPE (decl) != error_mark_node)
+      varpool_node::finalize_decl (decl);
+  record_eh_tables (node, fun);
 
-  pointer_set_destroy (visited_nodes);
   return 0;
 }
 
-struct gimple_opt_pass pass_build_cgraph_edges =
+} // anon namespace
+
+gimple_opt_pass *
+make_pass_build_cgraph_edges (gcc::context *ctxt)
 {
- {
-  GIMPLE_PASS,
-  "*build_cgraph_edges",                       /* name */
-  NULL,                                        /* gate */
-  build_cgraph_edges,                  /* execute */
-  NULL,                                        /* sub */
-  NULL,                                        /* next */
-  0,                                   /* static_pass_number */
-  TV_NONE,                             /* tv_id */
-  PROP_cfg,                            /* properties_required */
-  0,                                   /* properties_provided */
-  0,                                   /* properties_destroyed */
-  0,                                   /* todo_flags_start */
-  0                                    /* todo_flags_finish */
- }
-};
+  return new pass_build_cgraph_edges (ctxt);
+}
 
 /* Record references to functions and other variables present in the
    initial value of DECL, a variable.
@@ -298,97 +377,173 @@ struct gimple_opt_pass pass_build_cgraph_edges =
 void
 record_references_in_initializer (tree decl, bool only_vars)
 {
-  struct pointer_set_t *visited_nodes = pointer_set_create ();
-  struct record_reference_ctx ctx = {false};
+  varpool_node *node = varpool_node::get_create (decl);
+  hash_set<tree> visited_nodes;
+  record_reference_ctx ctx = {false, NULL};
 
+  ctx.varpool_node = node;
   ctx.only_vars = only_vars;
   walk_tree (&DECL_INITIAL (decl), record_reference,
-             &ctx, visited_nodes);
-  pointer_set_destroy (visited_nodes);
+             &ctx, &visited_nodes);
 }
 
 /* Rebuild cgraph edges for current function node.  This needs to be run after
    passes that don't update the cgraph.  */
 
 unsigned int
-rebuild_cgraph_edges (void)
+cgraph_edge::rebuild_edges (void)
 {
   basic_block bb;
-  struct cgraph_node *node = cgraph_node (current_function_decl);
+  cgraph_node *node = cgraph_node::get (current_function_decl);
   gimple_stmt_iterator gsi;
 
-  cgraph_node_remove_callees (node);
+  node->remove_callees ();
+  node->remove_all_references ();
 
-  node->count = ENTRY_BLOCK_PTR->count;
+  node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
 
-  FOR_EACH_BB (bb)
+  FOR_EACH_BB_FN (bb, cfun)
     {
       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
        {
-         gimple stmt = gsi_stmt (gsi);
+         gimple *stmt = gsi_stmt (gsi);
          tree decl;
 
-         if (is_gimple_call (stmt) && (decl = gimple_call_fndecl (stmt)))
-           cgraph_create_edge (node, cgraph_node (decl), stmt,
-                               bb->count,
-                               compute_call_stmt_bb_frequency
-                                 (current_function_decl, bb),
-                               bb->loop_depth);
-         walk_stmt_load_store_addr_ops (stmt, node, mark_load,
-                                        mark_store, mark_address);
-
+         if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
+           {
+             decl = gimple_call_fndecl (call_stmt);
+             if (decl)
+               node->create_edge (cgraph_node::get_create (decl), call_stmt,
+                                  bb->count);
+             else if (gimple_call_internal_p (call_stmt))
+               ;
+             else
+               node->create_indirect_edge (call_stmt,
+                                           gimple_call_flags (call_stmt),
+                                           bb->count);
+           }
+         node->record_stmt_references (stmt);
        }
-      for (gsi = gsi_start (phi_nodes (bb)); !gsi_end_p (gsi); gsi_next (&gsi))
-       walk_stmt_load_store_addr_ops (gsi_stmt (gsi), node,
-                                      mark_load, mark_store, mark_address);
+      for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+       node->record_stmt_references (gsi_stmt (gsi));
     }
-  gcc_assert (!node->global.inlined_to);
-
+  record_eh_tables (node, cfun);
+  gcc_assert (!node->inlined_to);
   return 0;
 }
 
-struct gimple_opt_pass pass_rebuild_cgraph_edges =
+/* Rebuild cgraph references for current function node.  This needs to be run
+   after passes that don't update the cgraph.  */
+
+void
+cgraph_edge::rebuild_references (void)
+{
+  basic_block bb;
+  cgraph_node *node = cgraph_node::get (current_function_decl);
+  gimple_stmt_iterator gsi;
+  ipa_ref *ref = NULL;
+  int i;
+
+  /* Keep speculative references for further cgraph edge expansion.  */
+  for (i = 0; node->iterate_reference (i, ref);)
+    if (!ref->speculative)
+      ref->remove_reference ();
+    else
+      i++;
+
+  FOR_EACH_BB_FN (bb, cfun)
+    {
+      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+       node->record_stmt_references (gsi_stmt (gsi));
+      for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+       node->record_stmt_references (gsi_stmt (gsi));
+    }
+  record_eh_tables (node, cfun);
+}
+
+namespace {
+
+const pass_data pass_data_rebuild_cgraph_edges =
 {
- {
-  GIMPLE_PASS,
-  "*rebuild_cgraph_edges",             /* name */
-  NULL,                                        /* gate */
-  rebuild_cgraph_edges,                        /* execute */
-  NULL,                                        /* sub */
-  NULL,                                        /* next */
-  0,                                   /* static_pass_number */
-  TV_NONE,                             /* tv_id */
-  PROP_cfg,                            /* properties_required */
-  0,                                   /* properties_provided */
-  0,                                   /* properties_destroyed */
-  0,                                   /* todo_flags_start */
-  0,                                   /* todo_flags_finish */
- }
+  GIMPLE_PASS, /* type */
+  "*rebuild_cgraph_edges", /* name */
+  OPTGROUP_NONE, /* optinfo_flags */
+  TV_CGRAPH, /* tv_id */
+  PROP_cfg, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  0, /* todo_flags_finish */
 };
 
+class pass_rebuild_cgraph_edges : public gimple_opt_pass
+{
+public:
+  pass_rebuild_cgraph_edges (gcc::context *ctxt)
+    : gimple_opt_pass (pass_data_rebuild_cgraph_edges, ctxt)
+  {}
+
+  /* opt_pass methods: */
+  opt_pass * clone () { return new pass_rebuild_cgraph_edges (m_ctxt); }
+  virtual unsigned int execute (function *)
+  {
+    return cgraph_edge::rebuild_edges ();
+  }
 
-static unsigned int
-remove_cgraph_callee_edges (void)
+}; // class pass_rebuild_cgraph_edges
+
+} // anon namespace
+
+gimple_opt_pass *
+make_pass_rebuild_cgraph_edges (gcc::context *ctxt)
 {
-  cgraph_node_remove_callees (cgraph_node (current_function_decl));
-  return 0;
+  return new pass_rebuild_cgraph_edges (ctxt);
 }
 
-struct gimple_opt_pass pass_remove_cgraph_callee_edges =
+
+namespace {
+
+const pass_data pass_data_remove_cgraph_callee_edges =
 {
- {
-  GIMPLE_PASS,
-  "*remove_cgraph_callee_edges",               /* name */
-  NULL,                                        /* gate */
-  remove_cgraph_callee_edges,          /* execute */
-  NULL,                                        /* sub */
-  NULL,                                        /* next */
-  0,                                   /* static_pass_number */
-  TV_NONE,                             /* tv_id */
-  0,                                   /* properties_required */
-  0,                                   /* properties_provided */
-  0,                                   /* properties_destroyed */
-  0,                                   /* todo_flags_start */
-  0,                                   /* todo_flags_finish */
- }
+  GIMPLE_PASS, /* type */
+  "*remove_cgraph_callee_edges", /* name */
+  OPTGROUP_NONE, /* optinfo_flags */
+  TV_NONE, /* tv_id */
+  0, /* properties_required */
+  0, /* properties_provided */
+  0, /* properties_destroyed */
+  0, /* todo_flags_start */
+  0, /* todo_flags_finish */
 };
+
+class pass_remove_cgraph_callee_edges : public gimple_opt_pass
+{
+public:
+  pass_remove_cgraph_callee_edges (gcc::context *ctxt)
+    : gimple_opt_pass (pass_data_remove_cgraph_callee_edges, ctxt)
+  {}
+
+  /* opt_pass methods: */
+  opt_pass * clone () {
+    return new pass_remove_cgraph_callee_edges (m_ctxt);
+  }
+  virtual unsigned int execute (function *);
+
+}; // class pass_remove_cgraph_callee_edges
+
+unsigned int
+pass_remove_cgraph_callee_edges::execute (function *)
+{
+  cgraph_node *node = cgraph_node::get (current_function_decl);
+  node->remove_callees ();
+  node->remove_all_references ();
+  return 0;
+}
+
+} // anon namespace
+
+gimple_opt_pass *
+make_pass_remove_cgraph_callee_edges (gcc::context *ctxt)
+{
+  return new pass_remove_cgraph_callee_edges (ctxt);
+}