diff mbox

[stage1] Make parloops gate more strict

Message ID 55095B84.4070807@mentor.com
State New
Headers show

Commit Message

Tom de Vries March 18, 2015, 11:03 a.m. UTC
On 18-03-15 11:16, Richard Biener wrote:
> On Fri, Mar 13, 2015 at 4:28 PM, Tom de Vries <Tom_deVries@mentor.com> wrote:
>> On 13-03-15 13:36, Richard Biener wrote:
>>>
>>> On Fri, Mar 13, 2015 at 1:07 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>>>>
>>>> On Fri, Mar 13, 2015 at 01:04:57PM +0100, Richard Biener wrote:
>>>>>
>>>>> Not really (I don't like -fdump-passes ...), but we need to make sure
>>>>> that -fdump-passes doesn't crash (because it runs very early and
>>>>> with cfun == NULL I think)
>>>>
>>>>
>>>> If it runs with cfun == NULL, then supposedly the gates that are
>>>> dependent
>>>> on current function should for -fdump-passes purposes also return true
>>>> if cfun == NULL (well, of course do all the unconditional checks).
>>>> Though of course, with optimize/target attributes this is harder, as
>>>> different functions can use different options.
>>>
>>>
>>> Yes, one reason why I think -fdump-passes is just broken
>>> implementation-wise.
>>>
>>
>> Atm fdump-passes doesn't run with cfun == NULL.
>>
>>  From pass_manager::dump_passes:
>> ...
>>    FOR_EACH_FUNCTION (n)
>>      if (DECL_STRUCT_FUNCTION (n->decl))
>>        {
>>          node = n;
>>          break;
>>        }
>>
>>    if (!node)
>>      return;
>>
>>    push_cfun (DECL_STRUCT_FUNCTION (node->decl));
>
> Um - this now picks a random function which may be one with
> an optimize or target attribute associated to it.
>

Indeed.

Attached patch removes that code, and runs the gates with cfun == NULL for 
-fdump-passes. It at least builds, and allows us to compile 
src/gcc/testsuite/gcc.dg/dump-pass.c with -O2 -fdump-passes.

Should I bootstrap and reg-test, or do you see a problem with this approach?

Thanks,
- Tom

Comments

Richard Biener March 18, 2015, 11:18 a.m. UTC | #1
On Wed, Mar 18, 2015 at 12:03 PM, Tom de Vries <Tom_deVries@mentor.com> wrote:
> On 18-03-15 11:16, Richard Biener wrote:
>>
>> On Fri, Mar 13, 2015 at 4:28 PM, Tom de Vries <Tom_deVries@mentor.com>
>> wrote:
>>>
>>> On 13-03-15 13:36, Richard Biener wrote:
>>>>
>>>>
>>>> On Fri, Mar 13, 2015 at 1:07 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>>>>>
>>>>>
>>>>> On Fri, Mar 13, 2015 at 01:04:57PM +0100, Richard Biener wrote:
>>>>>>
>>>>>>
>>>>>> Not really (I don't like -fdump-passes ...), but we need to make sure
>>>>>> that -fdump-passes doesn't crash (because it runs very early and
>>>>>> with cfun == NULL I think)
>>>>>
>>>>>
>>>>>
>>>>> If it runs with cfun == NULL, then supposedly the gates that are
>>>>> dependent
>>>>> on current function should for -fdump-passes purposes also return true
>>>>> if cfun == NULL (well, of course do all the unconditional checks).
>>>>> Though of course, with optimize/target attributes this is harder, as
>>>>> different functions can use different options.
>>>>
>>>>
>>>>
>>>> Yes, one reason why I think -fdump-passes is just broken
>>>> implementation-wise.
>>>>
>>>
>>> Atm fdump-passes doesn't run with cfun == NULL.
>>>
>>>  From pass_manager::dump_passes:
>>> ...
>>>    FOR_EACH_FUNCTION (n)
>>>      if (DECL_STRUCT_FUNCTION (n->decl))
>>>        {
>>>          node = n;
>>>          break;
>>>        }
>>>
>>>    if (!node)
>>>      return;
>>>
>>>    push_cfun (DECL_STRUCT_FUNCTION (node->decl));
>>
>>
>> Um - this now picks a random function which may be one with
>> an optimize or target attribute associated to it.
>>
>
> Indeed.
>
> Attached patch removes that code, and runs the gates with cfun == NULL for
> -fdump-passes. It at least builds, and allows us to compile
> src/gcc/testsuite/gcc.dg/dump-pass.c with -O2 -fdump-passes.
>
> Should I bootstrap and reg-test, or do you see a problem with this approach?

Yeah - it makes the -fdump-passes "hack" more pervasive throughout
the compiler.

I suppose it should instead build & push a "dummy" sturct function.

Well, or simply don't care for it's brokeness.

Richard.

> Thanks,
> - Tom
>
>
diff mbox

Patch

Fix -fdump-passes

---
 gcc/bb-reorder.c        |  5 +++--
 gcc/cprop.c             |  8 +++++---
 gcc/except.c            | 10 +++++-----
 gcc/gcse.c              | 28 ++++++++++++++++------------
 gcc/loop-init.c         | 11 +++++++----
 gcc/omp-low.c           |  3 ++-
 gcc/passes.c            | 16 +---------------
 gcc/store-motion.c      | 10 ++++++----
 gcc/tree-chkp-opt.c     | 14 ++++++++------
 gcc/tree-chkp.c         | 11 ++++++-----
 gcc/tree-complex.c      |  3 ++-
 gcc/tree-eh.c           | 10 ++++++++--
 gcc/tree-if-conv.c      |  6 +++++-
 gcc/tree-into-ssa.c     |  3 ++-
 gcc/tree-ssa-loop.c     | 16 +++++++++++++---
 gcc/tree-ssa.c          |  3 ++-
 gcc/tree-stdarg.c       |  3 ++-
 gcc/tree-vect-generic.c |  3 ++-
 18 files changed, 95 insertions(+), 68 deletions(-)

diff --git a/gcc/bb-reorder.c b/gcc/bb-reorder.c
index c2a3be3..b8f2a4b 100644
--- a/gcc/bb-reorder.c
+++ b/gcc/bb-reorder.c
@@ -2709,8 +2709,9 @@  pass_partition_blocks::gate (function *fun)
 	  /* See gate_handle_reorder_blocks.  We should not partition if
 	     we are going to omit the reordering.  */
 	  && optimize_function_for_speed_p (fun)
-	  && !DECL_COMDAT_GROUP (current_function_decl)
-	  && !user_defined_section_attribute);
+	  && !user_defined_section_attribute
+	  && (fun == NULL
+	      || !DECL_COMDAT_GROUP (current_function_decl)));
 }
 
 unsigned
diff --git a/gcc/cprop.c b/gcc/cprop.c
index c9fb2fc..bbea008 100644
--- a/gcc/cprop.c
+++ b/gcc/cprop.c
@@ -1961,9 +1961,11 @@  public:
   opt_pass * clone () { return new pass_rtl_cprop (m_ctxt); }
   virtual bool gate (function *fun)
     {
-      return optimize > 0 && flag_gcse
-	&& !fun->calls_setjmp
-	&& dbg_cnt (cprop);
+      return (optimize > 0
+	      && flag_gcse
+	      && (fun == NULL
+		  || (!fun->calls_setjmp
+		      && dbg_cnt (cprop))));
     }
 
   virtual unsigned int execute (function *) { return execute_rtl_cprop (); }
diff --git a/gcc/except.c b/gcc/except.c
index 833ec21..f81ade6 100644
--- a/gcc/except.c
+++ b/gcc/except.c
@@ -2677,14 +2677,14 @@  public:
 }; // class pass_convert_to_eh_region_ranges
 
 bool
-pass_convert_to_eh_region_ranges::gate (function *)
+pass_convert_to_eh_region_ranges::gate (function *fun)
 {
-  /* Nothing to do for SJLJ exceptions or if no regions created.  */
-  if (cfun->eh->region_tree == NULL)
-    return false;
   if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
     return false;
-  return true;
+
+  /* Nothing to do for SJLJ exceptions or if no regions created.  */
+  return (fun == NULL
+	  || fun->eh->region_tree != NULL);
 }
 
 } // anon namespace
diff --git a/gcc/gcse.c b/gcc/gcse.c
index e03b36c..80bdd5f 100644
--- a/gcc/gcse.c
+++ b/gcc/gcse.c
@@ -4252,10 +4252,12 @@  public:
 bool
 pass_rtl_pre::gate (function *fun)
 {
-  return optimize > 0 && flag_gcse
-    && !fun->calls_setjmp
-    && optimize_function_for_speed_p (fun)
-    && dbg_cnt (pre);
+  return (optimize > 0
+	  && flag_gcse
+	  && optimize_function_for_speed_p (fun)
+	  && (fun == NULL
+	      || (!fun->calls_setjmp
+		  && dbg_cnt (pre))));
 }
 
 } // anon namespace
@@ -4295,15 +4297,17 @@  public:
 }; // class pass_rtl_hoist
 
 bool
-pass_rtl_hoist::gate (function *)
+pass_rtl_hoist::gate (function *fun)
 {
-  return optimize > 0 && flag_gcse
-    && !cfun->calls_setjmp
-    /* It does not make sense to run code hoisting unless we are optimizing
-       for code size -- it rarely makes programs faster, and can make then
-       bigger if we did PRE (when optimizing for space, we don't run PRE).  */
-    && optimize_function_for_size_p (cfun)
-    && dbg_cnt (hoist);
+  return (optimize > 0
+	  && flag_gcse
+	  /* It does not make sense to run code hoisting unless we are optimizing
+	     for code size -- it rarely makes programs faster, and can make then
+	     bigger if we did PRE (when optimizing for space, we don't run PRE).  */
+	  && optimize_function_for_size_p (fun)
+	  && (fun == NULL
+	      || (!fun->calls_setjmp
+		  && dbg_cnt (hoist))));
 }
 
 } // anon namespace
diff --git a/gcc/loop-init.c b/gcc/loop-init.c
index c13d360..a000d9d 100644
--- a/gcc/loop-init.c
+++ b/gcc/loop-init.c
@@ -382,10 +382,13 @@  pass_loop2::gate (function *fun)
     return true;
   else
     {
-      /* No longer preserve loops, remove them now.  */
-      fun->curr_properties &= ~PROP_loops;
-      if (current_loops)
-	loop_optimizer_finalize ();
+      if (fun != NULL)
+	{
+	  /* No longer preserve loops, remove them now.  */
+	  fun->curr_properties &= ~PROP_loops;
+	  if (current_loops)
+	    loop_optimizer_finalize ();
+	}
       return false;
     } 
 }
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 48d73cb..8c57986 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -9557,7 +9557,8 @@  public:
   /* opt_pass methods: */
   virtual bool gate (function *fun)
     {
-      return !(fun->curr_properties & PROP_gimple_eomp);
+      return (fun == NULL
+	      || !(fun->curr_properties & PROP_gimple_eomp));
     }
   virtual unsigned int execute (function *) { return execute_expand_omp (); }
 
diff --git a/gcc/passes.c b/gcc/passes.c
index 23a90d9..27c6558 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -944,29 +944,15 @@  dump_passes (void)
 void
 pass_manager::dump_passes () const
 {
-  struct cgraph_node *n, *node = NULL;
-
   create_pass_tab ();
 
-  FOR_EACH_FUNCTION (n)
-    if (DECL_STRUCT_FUNCTION (n->decl))
-      {
-	node = n;
-	break;
-      }
-
-  if (!node)
-    return;
-
-  push_cfun (DECL_STRUCT_FUNCTION (node->decl));
+  gcc_assert (cfun == NULL);
 
   dump_pass_list (all_lowering_passes, 1);
   dump_pass_list (all_small_ipa_passes, 1);
   dump_pass_list (all_regular_ipa_passes, 1);
   dump_pass_list (all_late_ipa_passes, 1);
   dump_pass_list (all_passes, 1);
-
-  pop_cfun ();
 }
 
 
diff --git a/gcc/store-motion.c b/gcc/store-motion.c
index 530766f..6bc3680 100644
--- a/gcc/store-motion.c
+++ b/gcc/store-motion.c
@@ -1297,10 +1297,12 @@  public:
 bool
 pass_rtl_store_motion::gate (function *fun)
 {
-  return optimize > 0 && flag_gcse_sm
-    && !fun->calls_setjmp
-    && optimize_function_for_speed_p (fun)
-    && dbg_cnt (store_motion);
+  return (optimize > 0
+	  && flag_gcse_sm
+	  && optimize_function_for_speed_p (fun)
+	  && (fun == NULL
+	      || (fun->calls_setjmp
+		  && dbg_cnt (store_motion))));
 }
 
 } // anon namespace
diff --git a/gcc/tree-chkp-opt.c b/gcc/tree-chkp-opt.c
index 3fa2380..e7f8ee8 100644
--- a/gcc/tree-chkp-opt.c
+++ b/gcc/tree-chkp-opt.c
@@ -1337,11 +1337,13 @@  chkp_opt_execute (void)
 
 /* Pass gate.  */
 static bool
-chkp_opt_gate (void)
+chkp_opt_gate (function *fun)
 {
-  return chkp_function_instrumented_p (cfun->decl)
-    && (flag_chkp_optimize > 0
-	|| (flag_chkp_optimize == -1 && optimize > 0));
+  return ((flag_chkp_optimize > 0
+	   || (flag_chkp_optimize == -1
+	       && optimize > 0))
+	  && (fun == NULL 
+	      || chkp_function_instrumented_p (fun->decl)));
 }
 
 namespace {
@@ -1373,9 +1375,9 @@  public:
       return new pass_chkp_opt (m_ctxt);
     }
 
-  virtual bool gate (function *)
+  virtual bool gate (function *fun)
     {
-      return chkp_opt_gate ();
+      return chkp_opt_gate (fun);
     }
 
   virtual unsigned int execute (function *)
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index d2df4ba..6ab2b3e 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -4335,10 +4335,10 @@  chkp_execute (void)
 
 /* Instrumentation pass gate.  */
 static bool
-chkp_gate (void)
+chkp_gate (function *fun)
 {
-  return cgraph_node::get (cfun->decl)->instrumentation_clone
-    || lookup_attribute ("chkp ctor", DECL_ATTRIBUTES (cfun->decl));
+  return cgraph_node::get (fun->decl)->instrumentation_clone
+    || lookup_attribute ("chkp ctor", DECL_ATTRIBUTES (fun->decl));
 }
 
 namespace {
@@ -4370,9 +4370,10 @@  public:
       return new pass_chkp (m_ctxt);
     }
 
-  virtual bool gate (function *)
+  virtual bool gate (function *fun)
     {
-      return chkp_gate ();
+      return (fun == NULL
+	      || chkp_gate (fun));
     }
 
   virtual unsigned int execute (function *)
diff --git a/gcc/tree-complex.c b/gcc/tree-complex.c
index c5b8688..2e07276 100644
--- a/gcc/tree-complex.c
+++ b/gcc/tree-complex.c
@@ -1754,7 +1754,8 @@  public:
     {
       /* With errors, normal optimization passes are not run.  If we don't
 	 lower complex operations at all, rtl expansion will abort.  */
-      return !(fun->curr_properties & PROP_gimple_lcx);
+      return (fun == NULL
+	      || !(fun->curr_properties & PROP_gimple_lcx));
     }
 
   virtual unsigned int execute (function *) { return tree_lower_complex (); }
diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index a111e9d93..38f6ebc 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -3751,7 +3751,11 @@  public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *fun) { return fun->eh->region_tree != NULL; }
+  virtual bool gate (function *fun)
+    {
+      return (fun == NULL
+	      || fun->eh->region_tree != NULL);
+    }
   virtual unsigned int execute (function *);
 
 }; // class pass_lower_eh_dispatch
@@ -4626,7 +4630,9 @@  public:
   opt_pass * clone () { return new pass_cleanup_eh (m_ctxt); }
   virtual bool gate (function *fun)
     {
-      return fun->eh != NULL && fun->eh->region_tree != NULL;
+      return (fun == NULL
+	      || (fun->eh != NULL
+		  && fun->eh->region_tree != NULL));
     }
 
   virtual unsigned int execute (function *);
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index 400ee01..7ca4086 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -2817,7 +2817,11 @@  public:
 bool
 pass_if_conversion::gate (function *fun)
 {
-  return (((flag_tree_loop_vectorize || fun->has_force_vectorize_loops)
+  bool do_vectorize = (flag_tree_loop_vectorize
+		       || (fun == NULL
+			   || fun->has_force_vectorize_loops));
+
+  return ((do_vectorize
 	   && flag_tree_loop_if_convert != 0)
 	  || flag_tree_loop_if_convert == 1
 	  || flag_tree_loop_if_convert_stores == 1);
diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c
index 2589628..aac5ae0 100644
--- a/gcc/tree-into-ssa.c
+++ b/gcc/tree-into-ssa.c
@@ -2373,7 +2373,8 @@  public:
   virtual bool gate (function *fun)
     {
       /* Do nothing for funcions that was produced already in SSA form.  */
-      return !(fun->curr_properties & PROP_ssa);
+      return (fun == NULL
+	      || !(fun->curr_properties & PROP_ssa));
     }
 
   virtual unsigned int execute (function *);
diff --git a/gcc/tree-ssa-loop.c b/gcc/tree-ssa-loop.c
index ccb8f97..837c572 100644
--- a/gcc/tree-ssa-loop.c
+++ b/gcc/tree-ssa-loop.c
@@ -151,7 +151,11 @@  public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *fn) { return gate_loop (fn); }
+  virtual bool gate (function *fn)
+    {
+      return (fn == NULL
+	      || gate_loop (fn));
+    }
 
 }; // class pass_tree_loop
 
@@ -188,7 +192,11 @@  public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *fn) { return !gate_loop (fn); }
+  virtual bool gate (function *fn)
+    {
+      return (fn == NULL
+	      || !gate_loop (fn));
+    }
 
 }; // class pass_tree_no_loop
 
@@ -279,7 +287,9 @@  public:
   /* opt_pass methods: */
   virtual bool gate (function *fun)
     {
-      return flag_tree_loop_vectorize || fun->has_force_vectorize_loops;
+      return (flag_tree_loop_vectorize 
+	      || (fun == NULL
+		  || fun->has_force_vectorize_loops));
     }
 
   virtual unsigned int execute (function *);
diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c
index 10d3314..716fcd4 100644
--- a/gcc/tree-ssa.c
+++ b/gcc/tree-ssa.c
@@ -1118,7 +1118,8 @@  public:
   virtual bool gate (function *fun)
     {
       /* Do nothing for funcions that was produced already in SSA form.  */
-      return !(fun->curr_properties & PROP_ssa);
+      return (fun == NULL
+	      || !(fun->curr_properties & PROP_ssa));
     }
 
   virtual unsigned int execute (function *)
diff --git a/gcc/tree-stdarg.c b/gcc/tree-stdarg.c
index 0c70790..9503960 100644
--- a/gcc/tree-stdarg.c
+++ b/gcc/tree-stdarg.c
@@ -713,7 +713,8 @@  public:
 	      && !in_lto_p
 #endif
 	      /* This optimization is only for stdarg functions.  */
-	      && fun->stdarg != 0);
+	      && (fun == NULL
+		  || fun->stdarg != 0));
     }
 
   virtual unsigned int execute (function *);
diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c
index dc11028..603b1d3 100644
--- a/gcc/tree-vect-generic.c
+++ b/gcc/tree-vect-generic.c
@@ -1754,7 +1754,8 @@  public:
   /* opt_pass methods: */
   virtual bool gate (function *fun)
     {
-      return !(fun->curr_properties & PROP_gimple_lvec);
+      return (fun == NULL
+	      || !(fun->curr_properties & PROP_gimple_lvec));
     }
 
   virtual unsigned int execute (function *)
-- 
1.9.1