]> 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 4dc4c2696c6d934e18b0e92cec28305eb1853113..d72b3514f673e2835d0ac03c5411b9a2bdbff1c3 100644 (file)
@@ -1,5 +1,5 @@
 /* Callgraph construction.
-   Copyright (C) 2003-2015 Free Software Foundation, Inc.
+   Copyright (C) 2003-2020 Free Software Foundation, Inc.
    Contributed by Jan Hubicka
 
 This file is part of GCC.
@@ -21,40 +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 "alias.h"
-#include "symtab.h"
+#include "backend.h"
 #include "tree.h"
-#include "fold-const.h"
-#include "predict.h"
-#include "hard-reg-set.h"
-#include "function.h"
-#include "dominance.h"
-#include "cfg.h"
-#include "basic-block.h"
-#include "tree-ssa-alias.h"
-#include "internal-fn.h"
-#include "gimple-fold.h"
-#include "gimple-expr.h"
 #include "gimple.h"
-#include "gimple-iterator.h"
-#include "gimple-walk.h"
-#include "langhooks.h"
-#include "intl.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"
-#include "alloc-pool.h"
-#include "symbol-summary.h"
-#include "ipa-prop.h"
-#include "ipa-inline.h"
 
 /* Context of record_reference.  */
 struct record_reference_ctx
 {
   bool only_vars;
-  class varpool_node *varpool_node;
+  struct varpool_node *varpool_node;
 };
 
 /* Walk tree and record all calls and references to functions/variables.
@@ -95,7 +77,7 @@ record_reference (tree *tp, int *walk_subtrees, void *data)
          ctx->varpool_node->create_reference (node, IPA_REF_ADDR);
        }
 
-      if (TREE_CODE (decl) == VAR_DECL)
+      if (VAR_P (decl))
        {
          varpool_node *vnode = varpool_node::get_create (decl);
          ctx->varpool_node->create_reference (vnode, IPA_REF_ADDR);
@@ -132,7 +114,7 @@ record_type_list (cgraph_node *node, tree list)
       if (TREE_CODE (type) == ADDR_EXPR)
        {
          type = TREE_OPERAND (type, 0);
-         if (TREE_CODE (type) == VAR_DECL)
+         if (VAR_P (type))
            {
              varpool_node *vnode = varpool_node::get_create (type);
              node->create_reference (vnode, IPA_REF_ADDR);
@@ -208,27 +190,14 @@ record_eh_tables (cgraph_node *node, function *fun)
 int
 compute_call_stmt_bb_frequency (tree decl, basic_block bb)
 {
-  int entry_freq = ENTRY_BLOCK_PTR_FOR_FN
-                    (DECL_STRUCT_FUNCTION (decl))->frequency;
-  int freq = bb->frequency;
-
-  if (profile_status_for_fn (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, tree addr, tree, void *data)
+mark_address (gimple *stmt, tree addr, tree, void *data)
 {
   addr = get_base_address (addr);
   if (TREE_CODE (addr) == FUNCTION_DECL)
@@ -237,7 +206,7 @@ mark_address (gimple stmt, tree addr, tree, void *data)
       node->mark_address_taken ();
       ((symtab_node *)data)->create_reference (node, IPA_REF_ADDR, stmt);
     }
-  else if (addr && TREE_CODE (addr) == VAR_DECL
+  else if (addr && VAR_P (addr)
           && (TREE_STATIC (addr) || DECL_EXTERNAL (addr)))
     {
       varpool_node *vnode = varpool_node::get_create (addr);
@@ -251,7 +220,7 @@ mark_address (gimple stmt, tree addr, tree, void *data)
 /* Mark load of T.  */
 
 static bool
-mark_load (gimple stmt, tree t, tree, void *data)
+mark_load (gimple *stmt, tree t, tree, void *data)
 {
   t = get_base_address (t);
   if (t && TREE_CODE (t) == FUNCTION_DECL)
@@ -262,8 +231,7 @@ mark_load (gimple stmt, tree t, tree, void *data)
       node->mark_address_taken ();
       ((symtab_node *)data)->create_reference (node, IPA_REF_ADDR, stmt);
     }
-  else if (t && TREE_CODE (t) == VAR_DECL
-          && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
+  else if (t && VAR_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
     {
       varpool_node *vnode = varpool_node::get_create (t);
 
@@ -275,11 +243,10 @@ mark_load (gimple stmt, tree t, tree, void *data)
 /* Mark store of T.  */
 
 static bool
-mark_store (gimple stmt, tree t, tree, void *data)
+mark_store (gimple *stmt, tree t, tree, void *data)
 {
   t = get_base_address (t);
-  if (t && TREE_CODE (t) == VAR_DECL
-      && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
+  if (t && VAR_P (t) && (TREE_STATIC (t) || DECL_EXTERNAL (t)))
     {
       varpool_node *vnode = varpool_node::get_create (t);
 
@@ -291,7 +258,7 @@ mark_store (gimple stmt, tree t, tree, void *data)
 /* Record all references from cgraph_node that are taken in statement STMT.  */
 
 void
-cgraph_node::record_stmt_references (gimple stmt)
+cgraph_node::record_stmt_references (gimple *stmt)
 {
   walk_stmt_load_store_addr_ops (stmt, this, mark_load, mark_store,
                                 mark_address);
@@ -342,7 +309,7 @@ pass_build_cgraph_edges::execute (function *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_debug (stmt))
@@ -350,17 +317,15 @@ pass_build_cgraph_edges::execute (function *fun)
 
          if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
            {
-             int freq = compute_call_stmt_bb_frequency (current_function_decl,
-                                                        bb);
              decl = gimple_call_fndecl (call_stmt);
              if (decl)
-               node->create_edge (cgraph_node::get_create (decl), call_stmt, bb->count, freq);
+               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, freq);
+                                           bb->count);
            }
          node->record_stmt_references (stmt);
          if (gomp_parallel *omp_par_stmt = dyn_cast <gomp_parallel *> (stmt))
@@ -387,9 +352,10 @@ pass_build_cgraph_edges::execute (function *fun)
 
   /* Look for initializers of constant variables and private statics.  */
   FOR_EACH_LOCAL_DECL (fun, ix, decl)
-    if (TREE_CODE (decl) == VAR_DECL
+    if (VAR_P (decl)
        && (TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
-       && !DECL_HAS_VALUE_EXPR_P (decl))
+       && !DECL_HAS_VALUE_EXPR_P (decl)
+       && TREE_TYPE (decl) != error_mark_node)
       varpool_node::finalize_decl (decl);
   record_eh_tables (node, fun);
 
@@ -440,23 +406,21 @@ cgraph_edge::rebuild_edges (void)
     {
       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 (gcall *call_stmt = dyn_cast <gcall *> (stmt))
            {
-             int freq = compute_call_stmt_bb_frequency (current_function_decl,
-                                                        bb);
              decl = gimple_call_fndecl (call_stmt);
              if (decl)
                node->create_edge (cgraph_node::get_create (decl), call_stmt,
-                                  bb->count, freq);
+                                  bb->count);
              else if (gimple_call_internal_p (call_stmt))
                ;
              else
                node->create_indirect_edge (call_stmt,
                                            gimple_call_flags (call_stmt),
-                                           bb->count, freq);
+                                           bb->count);
            }
          node->record_stmt_references (stmt);
        }
@@ -464,12 +428,7 @@ cgraph_edge::rebuild_edges (void)
        node->record_stmt_references (gsi_stmt (gsi));
     }
   record_eh_tables (node, cfun);
-  gcc_assert (!node->global.inlined_to);
-
-  if (node->instrumented_version
-      && !node->instrumentation_clone)
-    node->create_reference (node->instrumented_version, IPA_REF_CHKP, NULL);
-
+  gcc_assert (!node->inlined_to);
   return 0;
 }
 
@@ -492,8 +451,6 @@ cgraph_edge::rebuild_references (void)
     else
       i++;
 
-  node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
-
   FOR_EACH_BB_FN (bb, cfun)
     {
       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
@@ -502,10 +459,6 @@ cgraph_edge::rebuild_references (void)
        node->record_stmt_references (gsi_stmt (gsi));
     }
   record_eh_tables (node, cfun);
-
-  if (node->instrumented_version
-      && !node->instrumentation_clone)
-    node->create_reference (node->instrumented_version, IPA_REF_CHKP, NULL);
 }
 
 namespace {