diff mbox series

[1/5] emit-rtl.c: more typesafety

Message ID 1528829652-43336-2-git-send-email-dmalcolm@redhat.com
State New
Headers show
Series More rtx->rtx_insn * cleanups | expand

Commit Message

David Malcolm June 12, 2018, 6:54 p.m. UTC
This patch converts various rtx to rtx_insn * (or rtx_code_label *).
It also convert the various "_loc" params from int to location_t

gcc/ChangeLog:
	* emit-rtl.c (next_real_insn): Strengthen param from "rtx"
	to "rtx_insn *".
	(add_insn_after): Likewise for first two params.
	(add_insn_before): Likewise.
	(remove_insn): Likewise for param.
	(emit_pattern_before_noloc): Likewise for second and third params.
	(emit_jump_insn_before_noloc): Convert NULL_RTX to NULL.
	(emit_call_insn_before_noloc): Likewise.
	(emit_debug_insn_before_noloc): Strengthen "before" param from "rtx"
	to "rtx_insn *".
	(emit_barrier_before): Likewise.
	(emit_label_before): Strengthen "label" param from "rtx" to
	"rtx_code_label *".  Strengthen "before" param from "rtx" to
	"rtx_insn *".
	(emit_insn_after_1): Strengthen "after" param from "rtx" to
	"rtx_insn *".
	(emit_pattern_after_noloc): Likewise.
	(emit_insn_after_noloc): Likewise.
	(emit_jump_insn_after_noloc): Likewise.
	(emit_call_insn_after_noloc): Likewise.
	(emit_debug_insn_after_noloc): Likewise.
	(emit_barrier_after): Likewise.
	(emit_label_after): Likewise for both params.
	(emit_pattern_after_setloc): Likewise for "after" param.  Convert
	"loc" param from "int" to "location_t".
	(emit_insn_after_setloc): Likewise.
	(emit_jump_insn_after_setloc): Likewise.
	(emit_call_insn_after_setloc): Likewise.
	(emit_debug_insn_after_setloc): Likewise.
	(emit_pattern_before_setloc): Likewise for "before" param.  Convert
	"loc" param from "int" to "location_t".
	(emit_pattern_before): Convert NULL_RTX to NULL.
	(emit_insn_before_setloc): Convert "loc" param from "int" to
	"location_t".
	(emit_jump_insn_before_setloc): Likewise.
	(emit_call_insn_before_setloc): Likewise.
	(emit_debug_insn_before_setloc): Strengthen "before" param from rtx to
	rtx_insn *.  Convert "loc" param from "int" to "location_t".
	* rtl.h (emit_insn_before_setloc, emit_jump_insn_before_setloc,
	emit_call_insn_before_setloc, emit_debug_insn_before_setloc):
	Convert 3rd param from "int" to "location_t".
	(emit_barrier_before, emit_barrier_after, next_real_insn):
	Strengthen param from rtx to rtx_insn *.
	(emit_label_before): Strengthen 1st param from "rtx" to
	"rtx_code_label *".  Strengthen 2nd param from "rtx" to
	"rtx_insn *".
	(emit_insn_after_noloc, emit_jump_insn_after_noloc,
	emit_call_insn_after_noloc, emit_debug_insn_after_noloc):
	Strengthen 2nd param from "rtx" to "rtx_insn *".
	(emit_insn_after_setloc, emit_jump_insn_after_setloc)
	emit_call_insn_after_setloc, emit_debug_insn_after_setloc):
	Likewise. Convert 3rd param from "int" to "location_t".
	(emit_label_after): Strengthen 1st param from "rtx" to
	"rtx_code_label *".
	(next_real_insn, remove_insn): Strengthen param from "rtx" to
	"rtx_insn *".
	(add_insn_before, add_insn_after): Strengthen 1st and 2nd params
	from "rtx" to "rtx_insn *".
---
 gcc/emit-rtl.c | 84 ++++++++++++++++++++++++++--------------------------------
 gcc/rtl.h      | 41 ++++++++++++++--------------
 2 files changed, 58 insertions(+), 67 deletions(-)

Comments

Jeff Law June 12, 2018, 8:50 p.m. UTC | #1
On 06/12/2018 12:54 PM, David Malcolm wrote:
> This patch converts various rtx to rtx_insn * (or rtx_code_label *).
> It also convert the various "_loc" params from int to location_t
> 
> gcc/ChangeLog:
> 	* emit-rtl.c (next_real_insn): Strengthen param from "rtx"
> 	to "rtx_insn *".
> 	(add_insn_after): Likewise for first two params.
> 	(add_insn_before): Likewise.
> 	(remove_insn): Likewise for param.
> 	(emit_pattern_before_noloc): Likewise for second and third params.
> 	(emit_jump_insn_before_noloc): Convert NULL_RTX to NULL.
> 	(emit_call_insn_before_noloc): Likewise.
> 	(emit_debug_insn_before_noloc): Strengthen "before" param from "rtx"
> 	to "rtx_insn *".
> 	(emit_barrier_before): Likewise.
> 	(emit_label_before): Strengthen "label" param from "rtx" to
> 	"rtx_code_label *".  Strengthen "before" param from "rtx" to
> 	"rtx_insn *".
> 	(emit_insn_after_1): Strengthen "after" param from "rtx" to
> 	"rtx_insn *".
> 	(emit_pattern_after_noloc): Likewise.
> 	(emit_insn_after_noloc): Likewise.
> 	(emit_jump_insn_after_noloc): Likewise.
> 	(emit_call_insn_after_noloc): Likewise.
> 	(emit_debug_insn_after_noloc): Likewise.
> 	(emit_barrier_after): Likewise.
> 	(emit_label_after): Likewise for both params.
> 	(emit_pattern_after_setloc): Likewise for "after" param.  Convert
> 	"loc" param from "int" to "location_t".
> 	(emit_insn_after_setloc): Likewise.
> 	(emit_jump_insn_after_setloc): Likewise.
> 	(emit_call_insn_after_setloc): Likewise.
> 	(emit_debug_insn_after_setloc): Likewise.
> 	(emit_pattern_before_setloc): Likewise for "before" param.  Convert
> 	"loc" param from "int" to "location_t".
> 	(emit_pattern_before): Convert NULL_RTX to NULL.
> 	(emit_insn_before_setloc): Convert "loc" param from "int" to
> 	"location_t".
> 	(emit_jump_insn_before_setloc): Likewise.
> 	(emit_call_insn_before_setloc): Likewise.
> 	(emit_debug_insn_before_setloc): Strengthen "before" param from rtx to
> 	rtx_insn *.  Convert "loc" param from "int" to "location_t".
> 	* rtl.h (emit_insn_before_setloc, emit_jump_insn_before_setloc,
> 	emit_call_insn_before_setloc, emit_debug_insn_before_setloc):
> 	Convert 3rd param from "int" to "location_t".
> 	(emit_barrier_before, emit_barrier_after, next_real_insn):
> 	Strengthen param from rtx to rtx_insn *.
> 	(emit_label_before): Strengthen 1st param from "rtx" to
> 	"rtx_code_label *".  Strengthen 2nd param from "rtx" to
> 	"rtx_insn *".
> 	(emit_insn_after_noloc, emit_jump_insn_after_noloc,
> 	emit_call_insn_after_noloc, emit_debug_insn_after_noloc):
> 	Strengthen 2nd param from "rtx" to "rtx_insn *".
> 	(emit_insn_after_setloc, emit_jump_insn_after_setloc)
> 	emit_call_insn_after_setloc, emit_debug_insn_after_setloc):
> 	Likewise. Convert 3rd param from "int" to "location_t".
> 	(emit_label_after): Strengthen 1st param from "rtx" to
> 	"rtx_code_label *".
> 	(next_real_insn, remove_insn): Strengthen param from "rtx" to
> 	"rtx_insn *".
> 	(add_insn_before, add_insn_after): Strengthen 1st and 2nd params
> 	from "rtx" to "rtx_insn *".
OK.  I think that covers the entire set.

I can't immediately recall if the as-a and safe-as-a are compile or
runtime checks.  Obviously your testing ought to be sufficient for the
former.  Mine will help with the latter since it'll build arc, bfin and
c6x elf targets through newlib.  For sh it'll build a mixture of -elf
things through newlib and it'll bootstrap sh4.

jeff
David Malcolm June 12, 2018, 9:16 p.m. UTC | #2
On Tue, 2018-06-12 at 14:50 -0600, Jeff Law wrote:
> On 06/12/2018 12:54 PM, David Malcolm wrote:
> > This patch converts various rtx to rtx_insn * (or rtx_code_label
> > *).
> > It also convert the various "_loc" params from int to location_t
> > 
> > gcc/ChangeLog:
> > 	* emit-rtl.c (next_real_insn): Strengthen param from "rtx"
> > 	to "rtx_insn *".
> > 	(add_insn_after): Likewise for first two params.
> > 	(add_insn_before): Likewise.
> > 	(remove_insn): Likewise for param.
> > 	(emit_pattern_before_noloc): Likewise for second and third
> > params.
> > 	(emit_jump_insn_before_noloc): Convert NULL_RTX to NULL.
> > 	(emit_call_insn_before_noloc): Likewise.
> > 	(emit_debug_insn_before_noloc): Strengthen "before" param from
> > "rtx"
> > 	to "rtx_insn *".
> > 	(emit_barrier_before): Likewise.
> > 	(emit_label_before): Strengthen "label" param from "rtx" to
> > 	"rtx_code_label *".  Strengthen "before" param from "rtx" to
> > 	"rtx_insn *".
> > 	(emit_insn_after_1): Strengthen "after" param from "rtx" to
> > 	"rtx_insn *".
> > 	(emit_pattern_after_noloc): Likewise.
> > 	(emit_insn_after_noloc): Likewise.
> > 	(emit_jump_insn_after_noloc): Likewise.
> > 	(emit_call_insn_after_noloc): Likewise.
> > 	(emit_debug_insn_after_noloc): Likewise.
> > 	(emit_barrier_after): Likewise.
> > 	(emit_label_after): Likewise for both params.
> > 	(emit_pattern_after_setloc): Likewise for "after"
> > param.  Convert
> > 	"loc" param from "int" to "location_t".
> > 	(emit_insn_after_setloc): Likewise.
> > 	(emit_jump_insn_after_setloc): Likewise.
> > 	(emit_call_insn_after_setloc): Likewise.
> > 	(emit_debug_insn_after_setloc): Likewise.
> > 	(emit_pattern_before_setloc): Likewise for "before"
> > param.  Convert
> > 	"loc" param from "int" to "location_t".
> > 	(emit_pattern_before): Convert NULL_RTX to NULL.
> > 	(emit_insn_before_setloc): Convert "loc" param from "int" to
> > 	"location_t".
> > 	(emit_jump_insn_before_setloc): Likewise.
> > 	(emit_call_insn_before_setloc): Likewise.
> > 	(emit_debug_insn_before_setloc): Strengthen "before" param from
> > rtx to
> > 	rtx_insn *.  Convert "loc" param from "int" to "location_t".
> > 	* rtl.h (emit_insn_before_setloc, emit_jump_insn_before_setloc,
> > 	emit_call_insn_before_setloc, emit_debug_insn_before_setloc):
> > 	Convert 3rd param from "int" to "location_t".
> > 	(emit_barrier_before, emit_barrier_after, next_real_insn):
> > 	Strengthen param from rtx to rtx_insn *.
> > 	(emit_label_before): Strengthen 1st param from "rtx" to
> > 	"rtx_code_label *".  Strengthen 2nd param from "rtx" to
> > 	"rtx_insn *".
> > 	(emit_insn_after_noloc, emit_jump_insn_after_noloc,
> > 	emit_call_insn_after_noloc, emit_debug_insn_after_noloc):
> > 	Strengthen 2nd param from "rtx" to "rtx_insn *".
> > 	(emit_insn_after_setloc, emit_jump_insn_after_setloc)
> > 	emit_call_insn_after_setloc, emit_debug_insn_after_setloc):
> > 	Likewise. Convert 3rd param from "int" to "location_t".
> > 	(emit_label_after): Strengthen 1st param from "rtx" to
> > 	"rtx_code_label *".
> > 	(next_real_insn, remove_insn): Strengthen param from "rtx" to
> > 	"rtx_insn *".
> > 	(add_insn_before, add_insn_after): Strengthen 1st and 2nd
> > params
> > 	from "rtx" to "rtx_insn *".
> 
> OK.  I think that covers the entire set.
> 
> I can't immediately recall if the as-a and safe-as-a are compile or
> runtime checks.  

Ultimately these boil down to:

gcc_checking_assert (INSN_P (rt)
                     || NOTE_P (rt)
                     || JUMP_TABLE_DATA_P (rt)
                     || BARRIER_P (rt)
                     || LABEL_P (rt));

(with an "if (rt)" for the safe_a_a variant), and hence they're runtime
checks (and only enabled when #if CHECKING_P).

> Obviously your testing ought to be sufficient for the
> former.  Mine will help with the latter since it'll build arc, bfin
> and
> c6x elf targets through newlib.  For sh it'll build a mixture of -elf
> things through newlib and it'll bootstrap sh4.

Is this testing something that you've already triggered, or does it
happen upon commit to trunk?

(The sh changes are the only aspect of this kit that I'm keen for
review/testing of, as it needed extra casts; I *think* everywhere I
added them are places where rtx are already being unconditionally
treated as instruction nodes, but your eyes/testing would be helpful).

Thanks
Dave
Jeff Law June 12, 2018, 9:23 p.m. UTC | #3
On 06/12/2018 03:16 PM, David Malcolm wrote:
> On Tue, 2018-06-12 at 14:50 -0600, Jeff Law wrote:
> 
> Ultimately these boil down to:
> 
> gcc_checking_assert (INSN_P (rt)
>                      || NOTE_P (rt)
>                      || JUMP_TABLE_DATA_P (rt)
>                      || BARRIER_P (rt)
>                      || LABEL_P (rt));
> 
> (with an "if (rt)" for the safe_a_a variant), and hence they're runtime
> checks (and only enabled when #if CHECKING_P).
Ack.

> 
>> Obviously your testing ought to be sufficient for the
>> former.  Mine will help with the latter since it'll build arc, bfin
>> and
>> c6x elf targets through newlib.  For sh it'll build a mixture of -elf
>> things through newlib and it'll bootstrap sh4.
> 
> Is this testing something that you've already triggered, or does it
> happen upon commit to trunk?
THe jobs poll the various relevant git servers (gcc, binutils, newlib,
glibc, linux kernel) once per day .  When a change is detected in any of
the repos a full build is started.


> 
> (The sh changes are the only aspect of this kit that I'm keen for
> review/testing of, as it needed extra casts; I *think* everywhere I
> added them are places where rtx are already being unconditionally
> treated as instruction nodes, but your eyes/testing would be helpful).
They looked reasonable to me.  Thankfully sh is one that we can actually
bootstrap GCC within a chroot using qemu, so it'll get fairly extensive
testing.   It takes ~8hrs, but that's not too bad :-)

jeff
David Malcolm June 13, 2018, 1:50 p.m. UTC | #4
On Tue, 2018-06-12 at 15:23 -0600, Jeff Law wrote:
> On 06/12/2018 03:16 PM, David Malcolm wrote:
> > On Tue, 2018-06-12 at 14:50 -0600, Jeff Law wrote:
> > 
> > Ultimately these boil down to:
> > 
> > gcc_checking_assert (INSN_P (rt)
> >                      || NOTE_P (rt)
> >                      || JUMP_TABLE_DATA_P (rt)
> >                      || BARRIER_P (rt)
> >                      || LABEL_P (rt));
> > 
> > (with an "if (rt)" for the safe_a_a variant), and hence they're
> > runtime
> > checks (and only enabled when #if CHECKING_P).
> 
> Ack.
> 
> > 
> > > Obviously your testing ought to be sufficient for the
> > > former.  Mine will help with the latter since it'll build arc,
> > > bfin
> > > and
> > > c6x elf targets through newlib.  For sh it'll build a mixture of
> > > -elf
> > > things through newlib and it'll bootstrap sh4.
> > 
> > Is this testing something that you've already triggered, or does it
> > happen upon commit to trunk?
> 
> THe jobs poll the various relevant git servers (gcc, binutils,
> newlib,
> glibc, linux kernel) once per day .  When a change is detected in any
> of
> the repos a full build is started.
> 
> 
> > 
> > (The sh changes are the only aspect of this kit that I'm keen for
> > review/testing of, as it needed extra casts; I *think* everywhere I
> > added them are places where rtx are already being unconditionally
> > treated as instruction nodes, but your eyes/testing would be
> > helpful).
> 
> They looked reasonable to me.  Thankfully sh is one that we can
> actually
> bootstrap GCC within a chroot using qemu, so it'll get fairly
> extensive
> testing.   It takes ~8hrs, but that's not too bad :-)

Thanks.  For reference, I've committed the combination of the patches
to trunk as r261547.

Dave

(I also smoketested the build of arc, since I noticed some changes
there since my earlier testing).
diff mbox series

Patch

diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 613030f..a327ff2 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3602,10 +3602,8 @@  prev_nonnote_nondebug_insn_bb (rtx_insn *insn)
    SEQUENCEs.  */
 
 rtx_insn *
-next_real_insn (rtx uncast_insn)
+next_real_insn (rtx_insn *insn)
 {
-  rtx_insn *insn = safe_as_a <rtx_insn *> (uncast_insn);
-
   while (insn)
     {
       insn = NEXT_INSN (insn);
@@ -4230,10 +4228,8 @@  add_insn_before_nobb (rtx_insn *insn, rtx_insn *before)
    they know how to update a SEQUENCE. */
 
 void
-add_insn_after (rtx uncast_insn, rtx uncast_after, basic_block bb)
+add_insn_after (rtx_insn *insn, rtx_insn *after, basic_block bb)
 {
-  rtx_insn *insn = as_a <rtx_insn *> (uncast_insn);
-  rtx_insn *after = as_a <rtx_insn *> (uncast_after);
   add_insn_after_nobb (insn, after);
   if (!BARRIER_P (after)
       && !BARRIER_P (insn)
@@ -4260,10 +4256,8 @@  add_insn_after (rtx uncast_insn, rtx uncast_after, basic_block bb)
    they know how to update a SEQUENCE. */
 
 void
-add_insn_before (rtx uncast_insn, rtx uncast_before, basic_block bb)
+add_insn_before (rtx_insn *insn, rtx_insn *before, basic_block bb)
 {
-  rtx_insn *insn = as_a <rtx_insn *> (uncast_insn);
-  rtx_insn *before = as_a <rtx_insn *> (uncast_before);
   add_insn_before_nobb (insn, before);
 
   if (!bb
@@ -4313,9 +4307,8 @@  set_insn_deleted (rtx insn)
    To really delete an insn and related DF information, use delete_insn.  */
 
 void
-remove_insn (rtx uncast_insn)
+remove_insn (rtx_insn *insn)
 {
-  rtx_insn *insn = as_a <rtx_insn *> (uncast_insn);
   rtx_insn *next = NEXT_INSN (insn);
   rtx_insn *prev = PREV_INSN (insn);
   basic_block bb;
@@ -4518,7 +4511,8 @@  reorder_insns (rtx_insn *from, rtx_insn *to, rtx_insn *after)
    generated would almost certainly die right after it was created.  */
 
 static rtx_insn *
-emit_pattern_before_noloc (rtx x, rtx before, rtx last, basic_block bb,
+emit_pattern_before_noloc (rtx x, rtx_insn *before, rtx_insn *last,
+			   basic_block bb,
                            rtx_insn *(*make_raw) (rtx))
 {
   rtx_insn *insn;
@@ -4526,7 +4520,7 @@  emit_pattern_before_noloc (rtx x, rtx before, rtx last, basic_block bb,
   gcc_assert (before);
 
   if (x == NULL_RTX)
-    return safe_as_a <rtx_insn *> (last);
+    return last;
 
   switch (GET_CODE (x))
     {
@@ -4559,7 +4553,7 @@  emit_pattern_before_noloc (rtx x, rtx before, rtx last, basic_block bb,
       break;
     }
 
-  return safe_as_a <rtx_insn *> (last);
+  return last;
 }
 
 /* Make X be output before the instruction BEFORE.  */
@@ -4577,7 +4571,7 @@  rtx_jump_insn *
 emit_jump_insn_before_noloc (rtx x, rtx_insn *before)
 {
   return as_a <rtx_jump_insn *> (
-		emit_pattern_before_noloc (x, before, NULL_RTX, NULL,
+		emit_pattern_before_noloc (x, before, NULL, NULL,
 					   make_jump_insn_raw));
 }
 
@@ -4587,7 +4581,7 @@  emit_jump_insn_before_noloc (rtx x, rtx_insn *before)
 rtx_insn *
 emit_call_insn_before_noloc (rtx x, rtx_insn *before)
 {
-  return emit_pattern_before_noloc (x, before, NULL_RTX, NULL,
+  return emit_pattern_before_noloc (x, before, NULL, NULL,
 				    make_call_insn_raw);
 }
 
@@ -4595,9 +4589,9 @@  emit_call_insn_before_noloc (rtx x, rtx_insn *before)
    and output it before the instruction BEFORE.  */
 
 rtx_insn *
-emit_debug_insn_before_noloc (rtx x, rtx before)
+emit_debug_insn_before_noloc (rtx x, rtx_insn *before)
 {
-  return emit_pattern_before_noloc (x, before, NULL_RTX, NULL,
+  return emit_pattern_before_noloc (x, before, NULL, NULL,
 				    make_debug_insn_raw);
 }
 
@@ -4605,7 +4599,7 @@  emit_debug_insn_before_noloc (rtx x, rtx before)
    and output it before the insn BEFORE.  */
 
 rtx_barrier *
-emit_barrier_before (rtx before)
+emit_barrier_before (rtx_insn *before)
 {
   rtx_barrier *insn = as_a <rtx_barrier *> (rtx_alloc (BARRIER));
 
@@ -4618,21 +4612,20 @@  emit_barrier_before (rtx before)
 /* Emit the label LABEL before the insn BEFORE.  */
 
 rtx_code_label *
-emit_label_before (rtx label, rtx_insn *before)
+emit_label_before (rtx_code_label *label, rtx_insn *before)
 {
   gcc_checking_assert (INSN_UID (label) == 0);
   INSN_UID (label) = cur_insn_uid++;
   add_insn_before (label, before, NULL);
-  return as_a <rtx_code_label *> (label);
+  return label;
 }
 
 /* Helper for emit_insn_after, handles lists of instructions
    efficiently.  */
 
 static rtx_insn *
-emit_insn_after_1 (rtx_insn *first, rtx uncast_after, basic_block bb)
+emit_insn_after_1 (rtx_insn *first, rtx_insn *after, basic_block bb)
 {
-  rtx_insn *after = safe_as_a <rtx_insn *> (uncast_after);
   rtx_insn *last;
   rtx_insn *after_after;
   if (!bb && !BARRIER_P (after))
@@ -4674,10 +4667,9 @@  emit_insn_after_1 (rtx_insn *first, rtx uncast_after, basic_block bb)
 }
 
 static rtx_insn *
-emit_pattern_after_noloc (rtx x, rtx uncast_after, basic_block bb,
+emit_pattern_after_noloc (rtx x, rtx_insn *after, basic_block bb,
 			  rtx_insn *(*make_raw)(rtx))
 {
-  rtx_insn *after = safe_as_a <rtx_insn *> (uncast_after);
   rtx_insn *last = after;
 
   gcc_assert (after);
@@ -4716,7 +4708,7 @@  emit_pattern_after_noloc (rtx x, rtx uncast_after, basic_block bb,
    BB is NULL, an attempt is made to infer the BB from AFTER.  */
 
 rtx_insn *
-emit_insn_after_noloc (rtx x, rtx after, basic_block bb)
+emit_insn_after_noloc (rtx x, rtx_insn *after, basic_block bb)
 {
   return emit_pattern_after_noloc (x, after, bb, make_insn_raw);
 }
@@ -4726,7 +4718,7 @@  emit_insn_after_noloc (rtx x, rtx after, basic_block bb)
    and output it after the insn AFTER.  */
 
 rtx_jump_insn *
-emit_jump_insn_after_noloc (rtx x, rtx after)
+emit_jump_insn_after_noloc (rtx x, rtx_insn *after)
 {
   return as_a <rtx_jump_insn *> (
 		emit_pattern_after_noloc (x, after, NULL, make_jump_insn_raw));
@@ -4736,7 +4728,7 @@  emit_jump_insn_after_noloc (rtx x, rtx after)
    and output it after the instruction AFTER.  */
 
 rtx_insn *
-emit_call_insn_after_noloc (rtx x, rtx after)
+emit_call_insn_after_noloc (rtx x, rtx_insn *after)
 {
   return emit_pattern_after_noloc (x, after, NULL, make_call_insn_raw);
 }
@@ -4745,7 +4737,7 @@  emit_call_insn_after_noloc (rtx x, rtx after)
    and output it after the instruction AFTER.  */
 
 rtx_insn *
-emit_debug_insn_after_noloc (rtx x, rtx after)
+emit_debug_insn_after_noloc (rtx x, rtx_insn *after)
 {
   return emit_pattern_after_noloc (x, after, NULL, make_debug_insn_raw);
 }
@@ -4754,7 +4746,7 @@  emit_debug_insn_after_noloc (rtx x, rtx after)
    and output it after the insn AFTER.  */
 
 rtx_barrier *
-emit_barrier_after (rtx after)
+emit_barrier_after (rtx_insn *after)
 {
   rtx_barrier *insn = as_a <rtx_barrier *> (rtx_alloc (BARRIER));
 
@@ -4767,12 +4759,12 @@  emit_barrier_after (rtx after)
 /* Emit the label LABEL after the insn AFTER.  */
 
 rtx_insn *
-emit_label_after (rtx label, rtx_insn *after)
+emit_label_after (rtx_insn *label, rtx_insn *after)
 {
   gcc_checking_assert (INSN_UID (label) == 0);
   INSN_UID (label) = cur_insn_uid++;
   add_insn_after (label, after, NULL);
-  return as_a <rtx_insn *> (label);
+  return label;
 }
 
 /* Notes require a bit of special handling: Some notes need to have their
@@ -4842,10 +4834,9 @@  emit_note_before (enum insn_note subtype, rtx_insn *before)
    MAKE_RAW indicates how to turn PATTERN into a real insn.  */
 
 static rtx_insn *
-emit_pattern_after_setloc (rtx pattern, rtx uncast_after, int loc,
+emit_pattern_after_setloc (rtx pattern, rtx_insn *after, location_t loc,
 			   rtx_insn *(*make_raw) (rtx))
 {
-  rtx_insn *after = safe_as_a <rtx_insn *> (uncast_after);
   rtx_insn *last = emit_pattern_after_noloc (pattern, after, NULL, make_raw);
 
   if (pattern == NULL_RTX || !loc)
@@ -4889,7 +4880,7 @@  emit_pattern_after (rtx pattern, rtx uncast_after, bool skip_debug_insns,
 
 /* Like emit_insn_after_noloc, but set INSN_LOCATION according to LOC.  */
 rtx_insn *
-emit_insn_after_setloc (rtx pattern, rtx after, int loc)
+emit_insn_after_setloc (rtx pattern, rtx_insn *after, location_t loc)
 {
   return emit_pattern_after_setloc (pattern, after, loc, make_insn_raw);
 }
@@ -4903,7 +4894,7 @@  emit_insn_after (rtx pattern, rtx after)
 
 /* Like emit_jump_insn_after_noloc, but set INSN_LOCATION according to LOC.  */
 rtx_jump_insn *
-emit_jump_insn_after_setloc (rtx pattern, rtx after, int loc)
+emit_jump_insn_after_setloc (rtx pattern, rtx_insn *after, location_t loc)
 {
   return as_a <rtx_jump_insn *> (
 	emit_pattern_after_setloc (pattern, after, loc, make_jump_insn_raw));
@@ -4919,7 +4910,7 @@  emit_jump_insn_after (rtx pattern, rtx after)
 
 /* Like emit_call_insn_after_noloc, but set INSN_LOCATION according to LOC.  */
 rtx_insn *
-emit_call_insn_after_setloc (rtx pattern, rtx after, int loc)
+emit_call_insn_after_setloc (rtx pattern, rtx_insn *after, location_t loc)
 {
   return emit_pattern_after_setloc (pattern, after, loc, make_call_insn_raw);
 }
@@ -4933,7 +4924,7 @@  emit_call_insn_after (rtx pattern, rtx after)
 
 /* Like emit_debug_insn_after_noloc, but set INSN_LOCATION according to LOC.  */
 rtx_insn *
-emit_debug_insn_after_setloc (rtx pattern, rtx after, int loc)
+emit_debug_insn_after_setloc (rtx pattern, rtx_insn *after, location_t loc)
 {
   return emit_pattern_after_setloc (pattern, after, loc, make_debug_insn_raw);
 }
@@ -4951,13 +4942,12 @@  emit_debug_insn_after (rtx pattern, rtx after)
    CALL_INSN, etc.  */
 
 static rtx_insn *
-emit_pattern_before_setloc (rtx pattern, rtx uncast_before, int loc, bool insnp,
-			    rtx_insn *(*make_raw) (rtx))
+emit_pattern_before_setloc (rtx pattern, rtx_insn *before, location_t loc,
+			    bool insnp, rtx_insn *(*make_raw) (rtx))
 {
-  rtx_insn *before = as_a <rtx_insn *> (uncast_before);
   rtx_insn *first = PREV_INSN (before);
   rtx_insn *last = emit_pattern_before_noloc (pattern, before,
-					      insnp ? before : NULL_RTX,
+					      insnp ? before : NULL,
 					      NULL, make_raw);
 
   if (pattern == NULL_RTX || !loc)
@@ -5001,13 +4991,13 @@  emit_pattern_before (rtx pattern, rtx uncast_before, bool skip_debug_insns,
 				       insnp, make_raw);
   else
     return emit_pattern_before_noloc (pattern, before,
-				      insnp ? before : NULL_RTX,
+				      insnp ? before : NULL,
                                       NULL, make_raw);
 }
 
 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC.  */
 rtx_insn *
-emit_insn_before_setloc (rtx pattern, rtx_insn *before, int loc)
+emit_insn_before_setloc (rtx pattern, rtx_insn *before, location_t loc)
 {
   return emit_pattern_before_setloc (pattern, before, loc, true,
 				     make_insn_raw);
@@ -5022,7 +5012,7 @@  emit_insn_before (rtx pattern, rtx before)
 
 /* like emit_insn_before_noloc, but set INSN_LOCATION according to LOC.  */
 rtx_jump_insn *
-emit_jump_insn_before_setloc (rtx pattern, rtx_insn *before, int loc)
+emit_jump_insn_before_setloc (rtx pattern, rtx_insn *before, location_t loc)
 {
   return as_a <rtx_jump_insn *> (
 	emit_pattern_before_setloc (pattern, before, loc, false,
@@ -5040,7 +5030,7 @@  emit_jump_insn_before (rtx pattern, rtx before)
 
 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC.  */
 rtx_insn *
-emit_call_insn_before_setloc (rtx pattern, rtx_insn *before, int loc)
+emit_call_insn_before_setloc (rtx pattern, rtx_insn *before, location_t loc)
 {
   return emit_pattern_before_setloc (pattern, before, loc, false,
 				     make_call_insn_raw);
@@ -5057,7 +5047,7 @@  emit_call_insn_before (rtx pattern, rtx_insn *before)
 
 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC.  */
 rtx_insn *
-emit_debug_insn_before_setloc (rtx pattern, rtx before, int loc)
+emit_debug_insn_before_setloc (rtx pattern, rtx_insn *before, location_t loc)
 {
   return emit_pattern_before_setloc (pattern, before, loc, false,
 				     make_debug_insn_raw);
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 0341ba0..1870dab 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -3221,33 +3221,34 @@  extern void decide_function_section (tree);
 /* In emit-rtl.c */
 extern rtx_insn *emit_insn_before (rtx, rtx);
 extern rtx_insn *emit_insn_before_noloc (rtx, rtx_insn *, basic_block);
-extern rtx_insn *emit_insn_before_setloc (rtx, rtx_insn *, int);
+extern rtx_insn *emit_insn_before_setloc (rtx, rtx_insn *, location_t);
 extern rtx_jump_insn *emit_jump_insn_before (rtx, rtx);
 extern rtx_jump_insn *emit_jump_insn_before_noloc (rtx, rtx_insn *);
-extern rtx_jump_insn *emit_jump_insn_before_setloc (rtx, rtx_insn *, int);
+extern rtx_jump_insn *emit_jump_insn_before_setloc (rtx, rtx_insn *,
+						    location_t);
 extern rtx_insn *emit_call_insn_before (rtx, rtx_insn *);
 extern rtx_insn *emit_call_insn_before_noloc (rtx, rtx_insn *);
-extern rtx_insn *emit_call_insn_before_setloc (rtx, rtx_insn *, int);
+extern rtx_insn *emit_call_insn_before_setloc (rtx, rtx_insn *, location_t);
 extern rtx_insn *emit_debug_insn_before (rtx, rtx_insn *);
 extern rtx_insn *emit_debug_insn_before_noloc (rtx, rtx);
-extern rtx_insn *emit_debug_insn_before_setloc (rtx, rtx, int);
-extern rtx_barrier *emit_barrier_before (rtx);
-extern rtx_code_label *emit_label_before (rtx, rtx_insn *);
+extern rtx_insn *emit_debug_insn_before_setloc (rtx, rtx_insn *, location_t);
+extern rtx_barrier *emit_barrier_before (rtx_insn *);
+extern rtx_code_label *emit_label_before (rtx_code_label *, rtx_insn *);
 extern rtx_note *emit_note_before (enum insn_note, rtx_insn *);
 extern rtx_insn *emit_insn_after (rtx, rtx);
-extern rtx_insn *emit_insn_after_noloc (rtx, rtx, basic_block);
-extern rtx_insn *emit_insn_after_setloc (rtx, rtx, int);
+extern rtx_insn *emit_insn_after_noloc (rtx, rtx_insn *, basic_block);
+extern rtx_insn *emit_insn_after_setloc (rtx, rtx_insn *, location_t);
 extern rtx_jump_insn *emit_jump_insn_after (rtx, rtx);
-extern rtx_jump_insn *emit_jump_insn_after_noloc (rtx, rtx);
-extern rtx_jump_insn *emit_jump_insn_after_setloc (rtx, rtx, int);
+extern rtx_jump_insn *emit_jump_insn_after_noloc (rtx, rtx_insn *);
+extern rtx_jump_insn *emit_jump_insn_after_setloc (rtx, rtx_insn *, location_t);
 extern rtx_insn *emit_call_insn_after (rtx, rtx);
-extern rtx_insn *emit_call_insn_after_noloc (rtx, rtx);
-extern rtx_insn *emit_call_insn_after_setloc (rtx, rtx, int);
+extern rtx_insn *emit_call_insn_after_noloc (rtx, rtx_insn *);
+extern rtx_insn *emit_call_insn_after_setloc (rtx, rtx_insn *, location_t);
 extern rtx_insn *emit_debug_insn_after (rtx, rtx);
-extern rtx_insn *emit_debug_insn_after_noloc (rtx, rtx);
-extern rtx_insn *emit_debug_insn_after_setloc (rtx, rtx, int);
-extern rtx_barrier *emit_barrier_after (rtx);
-extern rtx_insn *emit_label_after (rtx, rtx_insn *);
+extern rtx_insn *emit_debug_insn_after_noloc (rtx, rtx_insn *);
+extern rtx_insn *emit_debug_insn_after_setloc (rtx, rtx_insn *, location_t);
+extern rtx_barrier *emit_barrier_after (rtx_insn *);
+extern rtx_insn *emit_label_after (rtx_insn *, rtx_insn *);
 extern rtx_note *emit_note_after (enum insn_note, rtx_insn *);
 extern rtx_insn *emit_insn (rtx);
 extern rtx_insn *emit_debug_insn (rtx);
@@ -3276,7 +3277,7 @@  extern rtx_insn *prev_nonnote_nondebug_insn_bb (rtx_insn *);
 extern rtx_insn *next_nonnote_nondebug_insn (rtx_insn *);
 extern rtx_insn *next_nonnote_nondebug_insn_bb (rtx_insn *);
 extern rtx_insn *prev_real_insn (rtx_insn *);
-extern rtx_insn *next_real_insn (rtx);
+extern rtx_insn *next_real_insn (rtx_insn *);
 extern rtx_insn *prev_real_nondebug_insn (rtx_insn *);
 extern rtx_insn *next_real_nondebug_insn (rtx);
 extern rtx_insn *prev_active_insn (rtx_insn *);
@@ -3968,9 +3969,9 @@  extern void unshare_all_rtl_again (rtx_insn *);
 extern void unshare_all_rtl_in_chain (rtx_insn *);
 extern void verify_rtl_sharing (void);
 extern void add_insn (rtx_insn *);
-extern void add_insn_before (rtx, rtx, basic_block);
-extern void add_insn_after (rtx, rtx, basic_block);
-extern void remove_insn (rtx);
+extern void add_insn_before (rtx_insn *, rtx_insn *, basic_block);
+extern void add_insn_after (rtx_insn *, rtx_insn *, basic_block);
+extern void remove_insn (rtx_insn *);
 extern rtx_insn *emit (rtx, bool = true);
 extern void emit_insn_at_entry (rtx);
 extern rtx gen_lowpart_SUBREG (machine_mode, rtx);