omp-builtins.def (BUILT_IN_GOMP_LOOP_NONMONOTONIC_RUNTIME_START, [...]): Fix up funct...
[gcc.git] / gcc / ipa-inline-transform.c
index 98c7f96fbb69e4f8d401062493284f20ad1dc43e..0e7499852911e43794c6562a3f99b22b8f2a0aec 100644 (file)
@@ -1,5 +1,5 @@
 /* Callgraph transformations to handle inlining
-   Copyright (C) 2003-2016 Free Software Foundation, Inc.
+   Copyright (C) 2003-2018 Free Software Foundation, Inc.
    Contributed by Jan Hubicka
 
 This file is part of GCC.
@@ -39,38 +39,37 @@ along with GCC; see the file COPYING3.  If not see
 #include "cgraph.h"
 #include "tree-cfg.h"
 #include "symbol-summary.h"
+#include "tree-vrp.h"
 #include "ipa-prop.h"
+#include "ipa-fnsummary.h"
 #include "ipa-inline.h"
 #include "tree-inline.h"
+#include "function.h"
+#include "cfg.h"
+#include "basic-block.h"
 
 int ncalls_inlined;
 int nfunctions_inlined;
 
-/* Scale frequency of NODE edges by FREQ_SCALE.  */
+/* Scale counts of NODE edges by NUM/DEN.  */
 
 static void
-update_noncloned_frequencies (struct cgraph_node *node,
-                             int freq_scale)
+update_noncloned_counts (struct cgraph_node *node, 
+                        profile_count num, profile_count den)
 {
   struct cgraph_edge *e;
 
-  /* We do not want to ignore high loop nest after freq drops to 0.  */
-  if (!freq_scale)
-    freq_scale = 1;
+  profile_count::adjust_for_ipa_scaling (&num, &den);
+
   for (e = node->callees; e; e = e->next_callee)
     {
-      e->frequency = e->frequency * (gcov_type) freq_scale / CGRAPH_FREQ_BASE;
-      if (e->frequency > CGRAPH_FREQ_MAX)
-        e->frequency = CGRAPH_FREQ_MAX;
       if (!e->inline_failed)
-        update_noncloned_frequencies (e->callee, freq_scale);
+        update_noncloned_counts (e->callee, num, den);
+      e->count = e->count.apply_scale (num, den);
     }
   for (e = node->indirect_calls; e; e = e->next_callee)
-    {
-      e->frequency = e->frequency * (gcov_type) freq_scale / CGRAPH_FREQ_BASE;
-      if (e->frequency > CGRAPH_FREQ_MAX)
-        e->frequency = CGRAPH_FREQ_MAX;
-    }
+    e->count = e->count.apply_scale (num, den);
+  node->count = node->count.apply_scale (num, den);
 }
 
 /* We removed or are going to remove the last call to NODE.
@@ -158,12 +157,11 @@ master_clone_with_noninline_clones_p (struct cgraph_node *node)
    By default the offline copy is removed, when it appears dead after inlining.
    UPDATE_ORIGINAL prevents this transformation.
    If OVERALL_SIZE is non-NULL, the size is updated to reflect the
-   transformation.
-   FREQ_SCALE specify the scaling of frequencies of call sites.  */
+   transformation.  */
 
 void
 clone_inlined_nodes (struct cgraph_edge *e, bool duplicate,
-                    bool update_original, int *overall_size, int freq_scale)
+                    bool update_original, int *overall_size)
 {
   struct cgraph_node *inlining_into;
   struct cgraph_edge *next;
@@ -202,22 +200,22 @@ clone_inlined_nodes (struct cgraph_edge *e, bool duplicate,
            {
              gcc_assert (!e->callee->alias);
              if (overall_size)
-               *overall_size -= inline_summaries->get (e->callee)->size;
+               *overall_size -= ipa_fn_summaries->get (e->callee)->size;
              nfunctions_inlined++;
            }
          duplicate = false;
          e->callee->externally_visible = false;
-          update_noncloned_frequencies (e->callee, e->frequency);
+          update_noncloned_counts (e->callee, e->count, e->callee->count);
+
+         dump_callgraph_transformation (e->callee, inlining_into,
+                                        "inlining to");
        }
       else
        {
          struct cgraph_node *n;
 
-         if (freq_scale == -1)
-           freq_scale = e->frequency;
          n = e->callee->create_clone (e->callee->decl,
-                                      MIN (e->count, e->callee->count),
-                                      freq_scale,
+                                      e->count,
                                       update_original, vNULL, true,
                                       inlining_into,
                                       NULL);
@@ -235,7 +233,7 @@ clone_inlined_nodes (struct cgraph_edge *e, bool duplicate,
     {
       next = e->next_callee;
       if (!e->inline_failed)
-        clone_inlined_nodes (e, duplicate, update_original, overall_size, freq_scale);
+        clone_inlined_nodes (e, duplicate, update_original, overall_size);
     }
 }
 
@@ -271,7 +269,7 @@ mark_all_inlined_calls_cdtor (cgraph_node *node)
     {
       cs->in_polymorphic_cdtor = true;
       if (!cs->inline_failed)
-    mark_all_inlined_calls_cdtor (cs->callee);
+       mark_all_inlined_calls_cdtor (cs->callee);
     }
   for (cgraph_edge *cs = node->indirect_calls; cs; cs = cs->next_callee)
     cs->in_polymorphic_cdtor = true;
@@ -283,7 +281,7 @@ mark_all_inlined_calls_cdtor (cgraph_node *node)
    indirect edges are discovered in the process, add them to NEW_EDGES, unless
    it is NULL. If UPDATE_OVERALL_SUMMARY is false, do not bother to recompute overall
    size of caller after inlining. Caller is required to eventually do it via
-   inline_update_overall_summary.
+   ipa_update_overall_fn_summary.
    If callee_removed is non-NULL, set it to true if we removed callee node.
 
    Return true iff any new callgraph edges were discovered as a
@@ -336,6 +334,8 @@ inline_call (struct cgraph_edge *e, bool update_original,
   if (DECL_FUNCTION_PERSONALITY (callee->decl))
     DECL_FUNCTION_PERSONALITY (to->decl)
       = DECL_FUNCTION_PERSONALITY (callee->decl);
+
+  bool reload_optimization_node = false;
   if (!opt_for_fn (callee->decl, flag_strict_aliasing)
       && opt_for_fn (to->decl, flag_strict_aliasing))
     {
@@ -344,14 +344,15 @@ inline_call (struct cgraph_edge *e, bool update_original,
       cl_optimization_restore (&opts, opts_for_fn (to->decl));
       opts.x_flag_strict_aliasing = false;
       if (dump_file)
-       fprintf (dump_file, "Dropping flag_strict_aliasing on %s:%i\n",
-                to->name (), to->order);
+       fprintf (dump_file, "Dropping flag_strict_aliasing on %s\n",
+                to->dump_name ());
       DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
         = build_optimization_node (&opts);
+      reload_optimization_node = true;
     }
 
-  inline_summary *caller_info = inline_summaries->get (to);
-  inline_summary *callee_info = inline_summaries->get (callee);
+  ipa_fn_summary *caller_info = ipa_fn_summaries->get (to);
+  ipa_fn_summary *callee_info = ipa_fn_summaries->get (callee);
   if (!caller_info->fp_expressions && callee_info->fp_expressions)
     {
       caller_info->fp_expressions = true;
@@ -404,13 +405,18 @@ inline_call (struct cgraph_edge *e, bool update_original,
          opts.x_flag_errno_math
            = opt_for_fn (callee->decl, flag_errno_math);
          if (dump_file)
-           fprintf (dump_file, "Copying FP flags from %s:%i to %s:%i\n",
-                    callee->name (), callee->order, to->name (), to->order);
+           fprintf (dump_file, "Copying FP flags from %s to %s\n",
+                    callee->dump_name (), to->dump_name ());
          DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
             = build_optimization_node (&opts);
+         reload_optimization_node = true;
        }
     }
 
+  /* Reload global optimization flags.  */
+  if (reload_optimization_node && DECL_STRUCT_FUNCTION (to->decl) == cfun)
+    set_cfun (cfun, true);
+
   /* If aliases are involved, redirect edge to the actual destination and
      possibly remove the aliases.  */
   if (e->callee != callee)
@@ -434,26 +440,26 @@ inline_call (struct cgraph_edge *e, bool update_original,
        }
     }
 
-  clone_inlined_nodes (e, true, update_original, overall_size, e->frequency);
+  clone_inlined_nodes (e, true, update_original, overall_size);
 
   gcc_assert (curr->callee->global.inlined_to == to);
 
-  old_size = inline_summaries->get (to)->size;
-  inline_merge_summary (e);
+  old_size = ipa_fn_summaries->get (to)->size;
+  ipa_merge_fn_summary_after_inlining (e);
   if (e->in_polymorphic_cdtor)
     mark_all_inlined_calls_cdtor (e->callee);
   if (opt_for_fn (e->caller->decl, optimize))
     new_edges_found = ipa_propagate_indirect_call_infos (curr, new_edges);
   check_speculations (e->callee);
   if (update_overall_summary)
-    inline_update_overall_summary (to);
+    ipa_update_overall_fn_summary (to);
   else
     /* Update self size by the estimate so overall function growth limits
        work for further inlining into this function.  Before inlining
        the function we inlined to again we expect the caller to update
        the overall summary.  */
-    inline_summaries->get (to)->size += estimated_growth;
-  new_size = inline_summaries->get (to)->size;
+    ipa_fn_summaries->get (to)->size += estimated_growth;
+  new_size = ipa_fn_summaries->get (to)->size;
 
   if (callee->calls_comdat_local)
     to->calls_comdat_local = true;
@@ -472,7 +478,7 @@ inline_call (struct cgraph_edge *e, bool update_original,
      See PR 65654.  */
 #if 0
   /* Verify that estimated growth match real growth.  Allow off-by-one
-     error due to INLINE_SIZE_SCALE roudoff errors.  */
+     error due to ipa_fn_summary::size_scale roudoff errors.  */
   gcc_assert (!update_overall_summary || !overall_size || new_edges_found
              || abs (estimated_growth - (new_size - old_size)) <= 1
              || speculation_removed
@@ -487,7 +493,7 @@ inline_call (struct cgraph_edge *e, bool update_original,
     *overall_size += new_size - old_size;
   ncalls_inlined++;
 
-  /* This must happen after inline_merge_summary that rely on jump
+  /* This must happen after ipa_merge_fn_summary_after_inlining that rely on jump
      functions of callee to not be updated.  */
   return new_edges_found;
 }
@@ -648,7 +654,33 @@ inline_transform (struct cgraph_node *node)
 
   timevar_push (TV_INTEGRATION);
   if (node->callees && (opt_for_fn (node->decl, optimize) || has_inline))
-    todo = optimize_inline_calls (current_function_decl);
+    {
+      profile_count num = node->count;
+      profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
+      bool scale = num.initialized_p () && !(num == den);
+      if (scale)
+       {
+         profile_count::adjust_for_ipa_scaling (&num, &den);
+         if (dump_file)
+           {
+             fprintf (dump_file, "Applying count scale ");
+             num.dump (dump_file);
+             fprintf (dump_file, "/");
+             den.dump (dump_file);
+             fprintf (dump_file, "\n");
+           }
+
+         basic_block bb;
+         cfun->cfg->count_max = profile_count::uninitialized ();
+         FOR_ALL_BB_FN (bb, cfun)
+           {
+             bb->count = bb->count.apply_scale (num, den);
+             cfun->cfg->count_max = cfun->cfg->count_max.max (bb->count);
+           }
+         ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count;
+       }
+      todo = optimize_inline_calls (current_function_decl);
+   }
   timevar_pop (TV_INTEGRATION);
 
   cfun->always_inline_functions_inlined = true;