IA MCU psABI support: changes to libraries
[gcc.git] / gcc / ipa-reference.c
index b421f63fcb72bb56dcb3759e4ec29af1c15493bd..d53abb6ffe885f7df978f17477c963f50102974b 100644 (file)
@@ -1,5 +1,5 @@
 /* Callgraph based analysis of static variables.
-   Copyright (C) 2004-2014 Free Software Foundation, Inc.
+   Copyright (C) 2004-2015 Free Software Foundation, Inc.
    Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
 
 This file is part of GCC.
@@ -40,28 +40,23 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "alias.h"
+#include "symtab.h"
+#include "options.h"
 #include "tree.h"
+#include "fold-const.h"
 #include "calls.h"
 #include "predict.h"
-#include "vec.h"
-#include "hashtab.h"
-#include "hash-set.h"
-#include "machmode.h"
 #include "hard-reg-set.h"
-#include "input.h"
 #include "function.h"
 #include "basic-block.h"
 #include "tree-ssa-alias.h"
 #include "internal-fn.h"
 #include "gimple-expr.h"
-#include "is-a.h"
 #include "gimple.h"
 #include "tree-inline.h"
 #include "tree-pass.h"
 #include "splay-tree.h"
-#include "hash-map.h"
-#include "plugin-api.h"
-#include "ipa-ref.h"
 #include "cgraph.h"
 #include "ipa-utils.h"
 #include "bitmap.h"
@@ -125,6 +120,9 @@ static splay_tree reference_vars_to_consider;
    static we are considering.  This is added to the local info when asm
    code is found that clobbers all memory.  */
 static bitmap all_module_statics;
+/* Set of all statics that should be ignored becuase they are touched by
+   -fno-ipa-reference code.  */
+static bitmap ignore_module_statics;
 
 /* Obstack holding bitmaps of local analysis (live from analysis to
    propagation)  */
@@ -140,6 +138,7 @@ static struct cgraph_node_hook_list *node_removal_hook_holder;
    Indexed by UID of call graph nodes.  */
 static vec<ipa_reference_vars_info_t> ipa_reference_vars_vector;
 
+/* TODO: find a place where we should release the vector.  */
 static vec<ipa_reference_optimization_summary_t> ipa_reference_opt_sum_vector;
 
 /* Return the ipa_reference_vars structure starting from the cgraph NODE.  */
@@ -191,6 +190,9 @@ set_reference_optimization_summary (struct cgraph_node *node,
 bitmap
 ipa_reference_get_not_read_global (struct cgraph_node *fn)
 {
+  if (!opt_for_fn (fn->decl, flag_ipa_reference)
+      || !opt_for_fn (current_function_decl, flag_ipa_reference))
+    return NULL;
   ipa_reference_optimization_summary_t info =
     get_reference_optimization_summary (fn->function_symbol (NULL));
   if (info)
@@ -209,6 +211,9 @@ ipa_reference_get_not_read_global (struct cgraph_node *fn)
 bitmap
 ipa_reference_get_not_written_global (struct cgraph_node *fn)
 {
+  if (!opt_for_fn (fn->decl, flag_ipa_reference)
+      || !opt_for_fn (current_function_decl, flag_ipa_reference))
+    return NULL;
   ipa_reference_optimization_summary_t info =
     get_reference_optimization_summary (fn);
   if (info)
@@ -220,21 +225,6 @@ ipa_reference_get_not_written_global (struct cgraph_node *fn)
 }
 
 \f
-
-/* Add VAR to all_module_statics and the two
-   reference_vars_to_consider* sets.  */
-
-static inline void
-add_static_var (tree var)
-{
-  int uid = DECL_UID (var);
-  gcc_assert (TREE_CODE (var) == VAR_DECL);
-  if (dump_file)
-    splay_tree_insert (reference_vars_to_consider,
-                      uid, (splay_tree_value)var);
-  bitmap_set_bit (all_module_statics, uid);
-}
-
 /* Return true if the variable T is the right kind of static variable to
    perform compilation unit scope escape analysis.  */
 
@@ -266,12 +256,8 @@ is_proper_for_analysis (tree t)
     return false;
 
   /* TODO: Check aliases.  */
-
-  /* This is a variable we care about.  Check if we have seen it
-     before, and if not add it the set of variables we care about.  */
-  if (all_module_statics
-      && !bitmap_bit_p (all_module_statics, DECL_UID (t)))
-    add_static_var (t);
+  if (bitmap_bit_p (ignore_module_statics, DECL_UID (t)))
+    return false;
 
   return true;
 }
@@ -374,8 +360,9 @@ propagate_bits (ipa_reference_global_vars_info_t x_global, struct cgraph_node *x
 
       /* Only look into nodes we can propagate something.  */
       int flags = flags_from_decl_or_type (y->decl);
-      if (avail > AVAIL_INTERPOSABLE
-         || (avail == AVAIL_INTERPOSABLE && (flags & ECF_LEAF)))
+      if (opt_for_fn (y->decl, flag_ipa_reference)
+         && (avail > AVAIL_INTERPOSABLE
+             || (avail == AVAIL_INTERPOSABLE && (flags & ECF_LEAF))))
        {
          if (get_reference_vars_info (y))
            {
@@ -430,6 +417,7 @@ ipa_init (void)
   bitmap_obstack_initialize (&local_info_obstack);
   bitmap_obstack_initialize (&optimization_summary_obstack);
   all_module_statics = BITMAP_ALLOC (&optimization_summary_obstack);
+  ignore_module_statics = BITMAP_ALLOC (&optimization_summary_obstack);
 
   node_removal_hook_holder =
       symtab->add_cgraph_removal_hook (&remove_node_data, NULL);
@@ -467,6 +455,8 @@ analyze_function (struct cgraph_node *fn)
   int i;
   tree var;
 
+  if (!opt_for_fn (fn->decl, flag_ipa_reference))
+    return;
   local = init_function_info (fn);
   for (i = 0; fn->iterate_reference (i, ref); i++)
     {
@@ -475,6 +465,15 @@ analyze_function (struct cgraph_node *fn)
       var = ref->referred->decl;
       if (!is_proper_for_analysis (var))
        continue;
+      /* This is a variable we care about.  Check if we have seen it
+        before, and if not add it the set of variables we care about.  */
+      if (all_module_statics
+         && bitmap_set_bit (all_module_statics, DECL_UID (var)))
+       {
+         if (dump_file)
+           splay_tree_insert (reference_vars_to_consider,
+                              DECL_UID (var), (splay_tree_value)var);
+       }
       switch (ref->use)
        {
        case IPA_REF_LOAD:
@@ -551,6 +550,22 @@ generate_summary (void)
   ipa_init ();
 
   /* Process all of the functions next.  */
+  FOR_EACH_DEFINED_FUNCTION (node)
+    if (!node->alias && !opt_for_fn (node->decl, flag_ipa_reference))
+      {
+        struct ipa_ref *ref = NULL;
+        int i;
+        tree var;
+       for (i = 0; node->iterate_reference (i, ref); i++)
+         {
+           if (!is_a <varpool_node *> (ref->referred))
+             continue;
+           var = ref->referred->decl;
+           if (!is_proper_for_analysis (var))
+             continue;
+           bitmap_set_bit (ignore_module_statics, DECL_UID (var));
+         }
+      }
   FOR_EACH_DEFINED_FUNCTION (node)
     analyze_function (node);
 
@@ -563,7 +578,8 @@ generate_summary (void)
 
   if (dump_file)
     FOR_EACH_DEFINED_FUNCTION (node)
-      if (node->get_availability () >= AVAIL_INTERPOSABLE)
+      if (node->get_availability () >= AVAIL_INTERPOSABLE
+         && opt_for_fn (node->decl, flag_ipa_reference))
        {
          ipa_reference_local_vars_info_t l;
          unsigned int index;
@@ -600,7 +616,7 @@ read_write_all_from_decl (struct cgraph_node *node,
   tree decl = node->decl;
   int flags = flags_from_decl_or_type (decl);
   if ((flags & ECF_LEAF)
-      && node->get_availability () <= AVAIL_INTERPOSABLE)
+      && node->get_availability () < AVAIL_INTERPOSABLE)
     ;
   else if (flags & ECF_CONST)
     ;
@@ -633,7 +649,8 @@ get_read_write_all_from_node (struct cgraph_node *node,
   struct cgraph_edge *e, *ie;
 
   /* When function is overwritable, we can not assume anything.  */
-  if (node->get_availability () <= AVAIL_INTERPOSABLE)
+  if (node->get_availability () <= AVAIL_INTERPOSABLE
+      || (node->analyzed && !opt_for_fn (node->decl, flag_ipa_reference)))
     read_write_all_from_decl (node, read_all, write_all);
 
   for (e = node->callees;
@@ -643,7 +660,8 @@ get_read_write_all_from_node (struct cgraph_node *node,
       enum availability avail;
       struct cgraph_node *callee = e->callee->function_symbol (&avail);
       gcc_checking_assert (callee);
-      if (avail <= AVAIL_INTERPOSABLE)
+      if (avail <= AVAIL_INTERPOSABLE
+          || (callee->analyzed && !opt_for_fn (callee->decl, flag_ipa_reference)))
        read_write_all_from_decl (callee, read_all, write_all);
     }
 
@@ -665,6 +683,18 @@ get_read_write_all_from_node (struct cgraph_node *node,
       }
 }
 
+/* Skip edges from and to nodes without ipa_reference enables.  This leave
+   them out of strongy connected coponents and makes them easyto skip in the
+   propagation loop bellow.  */
+
+static bool
+ignore_edge_p (cgraph_edge *e)
+{
+  return (!opt_for_fn (e->caller->decl, flag_ipa_reference)
+          || !opt_for_fn (e->callee->function_symbol ()->decl,
+                         flag_ipa_reference));
+}
+
 /* Produce the global information by preforming a transitive closure
    on the local information that was produced by ipa_analyze_function.  */
 
@@ -676,18 +706,19 @@ propagate (void)
     XCNEWVEC (struct cgraph_node *, symtab->cgraph_count);
   int order_pos;
   int i;
+  bool remove_p;
 
   if (dump_file)
     cgraph_node::dump_cgraph (dump_file);
 
-  ipa_discover_readonly_nonaddressable_vars ();
+  remove_p = ipa_discover_readonly_nonaddressable_vars ();
   generate_summary ();
 
   /* Propagate the local information through the call graph to produce
      the global information.  All the nodes within a cycle will have
      the same info so we collapse cycles first.  Then we can do the
      propagation in one pass from the leaves to the roots.  */
-  order_pos = ipa_reduced_postorder (order, true, true, NULL);
+  order_pos = ipa_reduced_postorder (order, true, true, ignore_edge_p);
   if (dump_file)
     ipa_print_order (dump_file, "reduced", order, order_pos);
 
@@ -702,7 +733,7 @@ propagate (void)
       bool write_all = false;
 
       node = order[i];
-      if (node->alias)
+      if (node->alias || !opt_for_fn (node->decl, flag_ipa_reference))
        continue;
 
       node_info = get_reference_vars_info (node);
@@ -780,7 +811,7 @@ propagate (void)
          struct cgraph_node *w;
 
          node = order[i];
-         if (node->alias)
+          if (node->alias || !opt_for_fn (node->decl, flag_ipa_reference))
            continue;
 
          fprintf (dump_file,
@@ -821,7 +852,7 @@ propagate (void)
       ipa_reference_optimization_summary_t opt;
 
       node_info = get_reference_vars_info (node);
-      if (!node->alias
+      if (!node->alias && opt_for_fn (node->decl, flag_ipa_reference)
          && (node->get_availability () > AVAIL_INTERPOSABLE
              || (flags_from_decl_or_type (node->decl) & ECF_LEAF)))
        {
@@ -867,7 +898,7 @@ propagate (void)
   if (dump_file)
     splay_tree_delete (reference_vars_to_consider);
   reference_vars_to_consider = NULL;
-  return 0;
+  return remove_p ? TODO_remove_functions : 0;
 }
 
 /* Return true if we need to write summary of NODE. */
@@ -1130,7 +1161,8 @@ ipa_reference_read_optimization_summary (void)
        /* Fatal error here.  We do not want to support compiling ltrans units with
           different version of compiler or different flags than the WPA unit, so
           this should never happen.  */
-       fatal_error ("ipa reference summary is missing in ltrans unit");
+       fatal_error (input_location,
+                    "ipa reference summary is missing in ltrans unit");
     }
 }
 
@@ -1170,7 +1202,7 @@ public:
   /* opt_pass methods: */
   virtual bool gate (function *)
     {
-      return (flag_ipa_reference
+      return ((in_lto_p || flag_ipa_reference)
              /* Don't bother doing anything if the program has errors.  */
              && !seen_error ());
     }
@@ -1193,5 +1225,20 @@ make_pass_ipa_reference (gcc::context *ctxt)
 void
 ipa_reference_c_finalize (void)
 {
-  ipa_init_p = false;
+  if (ipa_init_p)
+    {
+      bitmap_obstack_release (&optimization_summary_obstack);
+      ipa_init_p = false;
+    }
+
+  if (node_removal_hook_holder)
+    {
+      symtab->remove_cgraph_removal_hook (node_removal_hook_holder);
+      node_removal_hook_holder = NULL;
+    }
+  if (node_duplication_hook_holder)
+    {
+      symtab->remove_cgraph_duplication_hook (node_duplication_hook_holder);
+      node_duplication_hook_holder = NULL;
+    }
 }