Re: [PATCH 1/9] [SFN] adjust RTL insn-walking API

2017-10-09 Thread Richard Biener
On Sat, Sep 30, 2017 at 11:08 AM, Alexandre Oliva  wrote:
> This patch removes unused RTL functions, introduces alternate ones for
> use in a later SFN patch, and regroups other related functions so that
> they appear in a more consistent order.

Ok.

Thanks,
Richard.

> for  gcc/ChangeLog
>
> * emit-rtl.c (next_nondebug_insn, prev_nondebug_insn): Reorder.
> (next_nonnote_nondebug_insn, prev_nonnote_nondebug_insn): Reorder.
> (next_nonnote_nondebug_insn_bb): New.
> (prev_nonnote_nondebug_insn_bb): New.
> (prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.
> * rtl.h (prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove decls.
> (prev_nonnote_nondebug_insn_bb): Declare.
> (next_nonnote_nondebug_insn_bb): Declare.
> * cfgbuild.c (find_bb_boundaries): Adjust to skip debug insns.
> * cfgrtl.c (get_last_bb_insn): Likewise.
> * lra.c (push_insns): Likewise.
> ---
>  gcc/cfgbuild.c |  2 +-
>  gcc/cfgrtl.c   |  4 ++--
>  gcc/emit-rtl.c | 69 
> --
>  gcc/lra.c  |  2 +-
>  gcc/rtl.h  |  4 ++--
>  5 files changed, 44 insertions(+), 37 deletions(-)
>
> diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c
> index 62956b2..76c21d7 100644
> --- a/gcc/cfgbuild.c
> +++ b/gcc/cfgbuild.c
> @@ -512,7 +512,7 @@ find_bb_boundaries (basic_block bb)
>  the middle of a BB.  We need to split it in the same manner as
>  if the barrier were preceded by a control_flow_insn_p insn.  */
>   if (!flow_transfer_insn)
> -   flow_transfer_insn = prev_nonnote_insn_bb (insn);
> +   flow_transfer_insn = prev_nonnote_nondebug_insn_bb (insn);
> }
>
>if (control_flow_insn_p (insn))
> diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
> index 6ef47b7..bce56b4 100644
> --- a/gcc/cfgrtl.c
> +++ b/gcc/cfgrtl.c
> @@ -2274,11 +2274,11 @@ get_last_bb_insn (basic_block bb)
>  end = table;
>
>/* Include any barriers that may follow the basic block.  */
> -  tmp = next_nonnote_insn_bb (end);
> +  tmp = next_nonnote_nondebug_insn_bb (end);
>while (tmp && BARRIER_P (tmp))
>  {
>end = tmp;
> -  tmp = next_nonnote_insn_bb (end);
> +  tmp = next_nonnote_nondebug_insn_bb (end);
>  }
>
>return end;
> diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
> index e790cbc..68c1f11 100644
> --- a/gcc/emit-rtl.c
> +++ b/gcc/emit-rtl.c
> @@ -3355,20 +3355,17 @@ next_nonnote_insn (rtx_insn *insn)
>return insn;
>  }
>
> -/* Return the next insn after INSN that is not a NOTE, but stop the
> -   search before we enter another basic block.  This routine does not
> -   look inside SEQUENCEs.  */
> +/* Return the next insn after INSN that is not a DEBUG_INSN.  This
> +   routine does not look inside SEQUENCEs.  */
>
>  rtx_insn *
> -next_nonnote_insn_bb (rtx_insn *insn)
> +next_nondebug_insn (rtx_insn *insn)
>  {
>while (insn)
>  {
>insn = NEXT_INSN (insn);
> -  if (insn == 0 || !NOTE_P (insn))
> +  if (insn == 0 || !DEBUG_INSN_P (insn))
> break;
> -  if (NOTE_INSN_BASIC_BLOCK_P (insn))
> -   return NULL;
>  }
>
>return insn;
> @@ -3390,67 +3387,70 @@ prev_nonnote_insn (rtx_insn *insn)
>return insn;
>  }
>
> -/* Return the previous insn before INSN that is not a NOTE, but stop
> -   the search before we enter another basic block.  This routine does
> -   not look inside SEQUENCEs.  */
> +/* Return the previous insn before INSN that is not a DEBUG_INSN.
> +   This routine does not look inside SEQUENCEs.  */
>
>  rtx_insn *
> -prev_nonnote_insn_bb (rtx_insn *insn)
> +prev_nondebug_insn (rtx_insn *insn)
>  {
> -
>while (insn)
>  {
>insn = PREV_INSN (insn);
> -  if (insn == 0 || !NOTE_P (insn))
> +  if (insn == 0 || !DEBUG_INSN_P (insn))
> break;
> -  if (NOTE_INSN_BASIC_BLOCK_P (insn))
> -   return NULL;
>  }
>
>return insn;
>  }
>
> -/* Return the next insn after INSN that is not a DEBUG_INSN.  This
> -   routine does not look inside SEQUENCEs.  */
> +/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN.
> +   This routine does not look inside SEQUENCEs.  */
>
>  rtx_insn *
> -next_nondebug_insn (rtx_insn *insn)
> +next_nonnote_nondebug_insn (rtx_insn *insn)
>  {
>while (insn)
>  {
>insn = NEXT_INSN (insn);
> -  if (insn == 0 || !DEBUG_INSN_P (insn))
> +  if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
> break;
>  }
>
>return insn;
>  }
>
> -/* Return the previous insn before INSN that is not a DEBUG_INSN.
> -   This routine does not look inside SEQUENCEs.  */
> +/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN,
> +   but stop the search before we enter another basic block.  This
> +   routine does not look inside SEQUENCEs.  */
>
>  rtx_insn *
> -prev_nondebug_insn (rtx_insn *insn)
> +next_nonnote_nondebug_insn_bb (rtx_insn *insn)
>  {
>

[PATCH 1/9] [SFN] adjust RTL insn-walking API

2017-09-30 Thread Alexandre Oliva
This patch removes unused RTL functions, introduces alternate ones for
use in a later SFN patch, and regroups other related functions so that
they appear in a more consistent order.

for  gcc/ChangeLog

* emit-rtl.c (next_nondebug_insn, prev_nondebug_insn): Reorder.
(next_nonnote_nondebug_insn, prev_nonnote_nondebug_insn): Reorder.
(next_nonnote_nondebug_insn_bb): New.
(prev_nonnote_nondebug_insn_bb): New.
(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.
* rtl.h (prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove decls.
(prev_nonnote_nondebug_insn_bb): Declare.
(next_nonnote_nondebug_insn_bb): Declare.
* cfgbuild.c (find_bb_boundaries): Adjust to skip debug insns.
* cfgrtl.c (get_last_bb_insn): Likewise.
* lra.c (push_insns): Likewise.
---
 gcc/cfgbuild.c |  2 +-
 gcc/cfgrtl.c   |  4 ++--
 gcc/emit-rtl.c | 69 --
 gcc/lra.c  |  2 +-
 gcc/rtl.h  |  4 ++--
 5 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c
index 62956b2..76c21d7 100644
--- a/gcc/cfgbuild.c
+++ b/gcc/cfgbuild.c
@@ -512,7 +512,7 @@ find_bb_boundaries (basic_block bb)
 the middle of a BB.  We need to split it in the same manner as
 if the barrier were preceded by a control_flow_insn_p insn.  */
  if (!flow_transfer_insn)
-   flow_transfer_insn = prev_nonnote_insn_bb (insn);
+   flow_transfer_insn = prev_nonnote_nondebug_insn_bb (insn);
}
 
   if (control_flow_insn_p (insn))
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 6ef47b7..bce56b4 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -2274,11 +2274,11 @@ get_last_bb_insn (basic_block bb)
 end = table;
 
   /* Include any barriers that may follow the basic block.  */
-  tmp = next_nonnote_insn_bb (end);
+  tmp = next_nonnote_nondebug_insn_bb (end);
   while (tmp && BARRIER_P (tmp))
 {
   end = tmp;
-  tmp = next_nonnote_insn_bb (end);
+  tmp = next_nonnote_nondebug_insn_bb (end);
 }
 
   return end;
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index e790cbc..68c1f11 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3355,20 +3355,17 @@ next_nonnote_insn (rtx_insn *insn)
   return insn;
 }
 
-/* Return the next insn after INSN that is not a NOTE, but stop the
-   search before we enter another basic block.  This routine does not
-   look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a DEBUG_INSN.  This
+   routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nonnote_insn_bb (rtx_insn *insn)
+next_nondebug_insn (rtx_insn *insn)
 {
   while (insn)
 {
   insn = NEXT_INSN (insn);
-  if (insn == 0 || !NOTE_P (insn))
+  if (insn == 0 || !DEBUG_INSN_P (insn))
break;
-  if (NOTE_INSN_BASIC_BLOCK_P (insn))
-   return NULL;
 }
 
   return insn;
@@ -3390,67 +3387,70 @@ prev_nonnote_insn (rtx_insn *insn)
   return insn;
 }
 
-/* Return the previous insn before INSN that is not a NOTE, but stop
-   the search before we enter another basic block.  This routine does
-   not look inside SEQUENCEs.  */
+/* Return the previous insn before INSN that is not a DEBUG_INSN.
+   This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nonnote_insn_bb (rtx_insn *insn)
+prev_nondebug_insn (rtx_insn *insn)
 {
-
   while (insn)
 {
   insn = PREV_INSN (insn);
-  if (insn == 0 || !NOTE_P (insn))
+  if (insn == 0 || !DEBUG_INSN_P (insn))
break;
-  if (NOTE_INSN_BASIC_BLOCK_P (insn))
-   return NULL;
 }
 
   return insn;
 }
 
-/* Return the next insn after INSN that is not a DEBUG_INSN.  This
-   routine does not look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN.
+   This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nondebug_insn (rtx_insn *insn)
+next_nonnote_nondebug_insn (rtx_insn *insn)
 {
   while (insn)
 {
   insn = NEXT_INSN (insn);
-  if (insn == 0 || !DEBUG_INSN_P (insn))
+  if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
break;
 }
 
   return insn;
 }
 
-/* Return the previous insn before INSN that is not a DEBUG_INSN.
-   This routine does not look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN,
+   but stop the search before we enter another basic block.  This
+   routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nondebug_insn (rtx_insn *insn)
+next_nonnote_nondebug_insn_bb (rtx_insn *insn)
 {
   while (insn)
 {
-  insn = PREV_INSN (insn);
-  if (insn == 0 || !DEBUG_INSN_P (insn))
+  insn = NEXT_INSN (insn);
+  if (insn == 0)
+   break;
+  if (DEBUG_INSN_P (insn))
+   continue;
+  if (!NOTE_P (insn))
break;
+  if (NOTE_INSN_BASIC_BLOCK_P (insn))
+   return NULL;
 }
 
   return insn;
 }
 
-/* Return 

[PATCH 1/9] [SFN] adjust RTL insn-walking API

2017-08-31 Thread Alexandre Oliva
This patch removes unused RTL functions, introduces alternate ones for
use in a later SFN patch, and regroups other related functions so that
they appear in a more consistent order.

for  gcc/ChangeLog

* emit-rtl.c (next_nondebug_insn, prev_nondebug_insn): Reorder.
(next_nonnote_nondebug_insn, prev_nonnote_nondebug_insn): Reorder.
(next_nonnote_nondebug_insn_bb): New.
(prev_nonnote_nondebug_insn_bb): New.
(prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove.
* rtl.h (prev_nonnote_insn_bb, next_nonnote_insn_bb): Remove decls.
(prev_nonnote_nondebug_insn_bb): Declare.
(next_nonnote_nondebug_insn_bb): Declare.
* cfgbuild.c (find_bb_boundaries): Adjust to skip debug insns.
* cfgrtl.c (get_last_bb_insn): Likewise.
* lra.c (push_insns): Likewise.
---
 gcc/cfgbuild.c |  2 +-
 gcc/cfgrtl.c   |  4 ++--
 gcc/emit-rtl.c | 69 --
 gcc/lra.c  |  2 +-
 gcc/rtl.h  |  4 ++--
 5 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c
index 2fe74c4..4a3d903 100644
--- a/gcc/cfgbuild.c
+++ b/gcc/cfgbuild.c
@@ -489,7 +489,7 @@ find_bb_boundaries (basic_block bb)
 the middle of a BB.  We need to split it in the same manner as
 if the barrier were preceded by a control_flow_insn_p insn.  */
  if (!flow_transfer_insn)
-   flow_transfer_insn = prev_nonnote_insn_bb (insn);
+   flow_transfer_insn = prev_nonnote_nondebug_insn_bb (insn);
}
 
   if (control_flow_insn_p (insn))
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 6ef47b7..bce56b4 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -2274,11 +2274,11 @@ get_last_bb_insn (basic_block bb)
 end = table;
 
   /* Include any barriers that may follow the basic block.  */
-  tmp = next_nonnote_insn_bb (end);
+  tmp = next_nonnote_nondebug_insn_bb (end);
   while (tmp && BARRIER_P (tmp))
 {
   end = tmp;
-  tmp = next_nonnote_insn_bb (end);
+  tmp = next_nonnote_nondebug_insn_bb (end);
 }
 
   return end;
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 6951f61..a6efdd8 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3346,20 +3346,17 @@ next_nonnote_insn (rtx_insn *insn)
   return insn;
 }
 
-/* Return the next insn after INSN that is not a NOTE, but stop the
-   search before we enter another basic block.  This routine does not
-   look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a DEBUG_INSN.  This
+   routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nonnote_insn_bb (rtx_insn *insn)
+next_nondebug_insn (rtx_insn *insn)
 {
   while (insn)
 {
   insn = NEXT_INSN (insn);
-  if (insn == 0 || !NOTE_P (insn))
+  if (insn == 0 || !DEBUG_INSN_P (insn))
break;
-  if (NOTE_INSN_BASIC_BLOCK_P (insn))
-   return NULL;
 }
 
   return insn;
@@ -3381,67 +3378,70 @@ prev_nonnote_insn (rtx_insn *insn)
   return insn;
 }
 
-/* Return the previous insn before INSN that is not a NOTE, but stop
-   the search before we enter another basic block.  This routine does
-   not look inside SEQUENCEs.  */
+/* Return the previous insn before INSN that is not a DEBUG_INSN.
+   This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nonnote_insn_bb (rtx_insn *insn)
+prev_nondebug_insn (rtx_insn *insn)
 {
-
   while (insn)
 {
   insn = PREV_INSN (insn);
-  if (insn == 0 || !NOTE_P (insn))
+  if (insn == 0 || !DEBUG_INSN_P (insn))
break;
-  if (NOTE_INSN_BASIC_BLOCK_P (insn))
-   return NULL;
 }
 
   return insn;
 }
 
-/* Return the next insn after INSN that is not a DEBUG_INSN.  This
-   routine does not look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN.
+   This routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-next_nondebug_insn (rtx_insn *insn)
+next_nonnote_nondebug_insn (rtx_insn *insn)
 {
   while (insn)
 {
   insn = NEXT_INSN (insn);
-  if (insn == 0 || !DEBUG_INSN_P (insn))
+  if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
break;
 }
 
   return insn;
 }
 
-/* Return the previous insn before INSN that is not a DEBUG_INSN.
-   This routine does not look inside SEQUENCEs.  */
+/* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN,
+   but stop the search before we enter another basic block.  This
+   routine does not look inside SEQUENCEs.  */
 
 rtx_insn *
-prev_nondebug_insn (rtx_insn *insn)
+next_nonnote_nondebug_insn_bb (rtx_insn *insn)
 {
   while (insn)
 {
-  insn = PREV_INSN (insn);
-  if (insn == 0 || !DEBUG_INSN_P (insn))
+  insn = NEXT_INSN (insn);
+  if (insn == 0)
+   break;
+  if (DEBUG_INSN_P (insn))
+   continue;
+  if (!NOTE_P (insn))
break;
+  if (NOTE_INSN_BASIC_BLOCK_P (insn))
+   return NULL;
 }
 
   return insn;
 }
 
-/* Return