From: Trevor Saunders <[email protected]>

gcc/ChangeLog:

        * config/arc/arc.cc (arc_print_operand, arc600_corereg_hazard,
        arc_adjust_insn_length, arc_predicate_delay_insns): Use
        rtx_sequence accessors instead of XVECEXP.
        * config/cris/cris.cc (cris_postdbr_cmpelim): Likewise.
        * config/mips/mips.cc (mips_classify_branch_p6600, mips_avoid_hazard,
        mips_breakable_sequence_p, mips_reorg_process_insns): Likewise.
        * config/pa/pa.cc (pa_output_function_epilogue,
        pa_adjust_insn_length, pa_print_operand): Likewise.
        * config/pru/pru.cc (pru_insert_loop_label_last): Likewise.
        * config/sparc/sparc.cc (emit_cbcond_nop,
        sparc_asm_function_epilogue): Likewise.
        * config/visium/visium.cc (empty_delay_slot, gr5_hazard_avoidance):
        Likewise.
        * emit-rtl.cc (reset_all_used_flags, verify_rtl_sharing, next_insn,
        link_insn_into_chain, remove_insn): Likewise.
        * final.cc (dbr_sequence_length, shorten_branches, leaf_function_p,
        rest_of_clean_state): Likewise.
        * reorg.cc (stop_search_p, optimize_skip,
        redirect_with_delay_slots_safe_p, try_merge_delay_insns,
        redundant_insn, fill_simple_delay_slots, fill_slots_from_thread,
        relax_delay_slots, make_return_insns, dbr_schedule): Likewise.
        * resource.cc (next_insn_no_annul, mark_referenced_resources,
        mark_set_resources, return_insn_p, mark_target_live_regs):
        Likewise.
        * rtlanal.cc (reg_set_p, verify_jump_tables): Likewise.
        * varasm.cc (mark_constants): Likewise.

Signed-off-by: Trevor Saunders <[email protected]>
---
 gcc/config/arc/arc.cc       |  33 ++++++------
 gcc/config/cris/cris.cc     |   4 +-
 gcc/config/mips/mips.cc     |  24 +++++----
 gcc/config/pa/pa.cc         |  12 +++--
 gcc/config/pru/pru.cc       |   5 +-
 gcc/config/sparc/sparc.cc   |  14 ++---
 gcc/config/visium/visium.cc |   8 +--
 gcc/emit-rtl.cc             |  51 +++++++++---------
 gcc/final.cc                |  22 ++++----
 gcc/reorg.cc                | 104 ++++++++++++++++++------------------
 gcc/resource.cc             |  24 +++++----
 gcc/rtlanal.cc              |  23 ++++----
 gcc/varasm.cc               |   2 +-
 13 files changed, 171 insertions(+), 155 deletions(-)

diff --git a/gcc/config/arc/arc.cc b/gcc/config/arc/arc.cc
index 0f7684fe189..a27e6aaafc5 100644
--- a/gcc/config/arc/arc.cc
+++ b/gcc/config/arc/arc.cc
@@ -5047,7 +5047,7 @@ arc_print_operand (FILE *file, rtx x, int code)
        {
          int cc = get_arc_condition_code (current_insn_predicate);
          /* Is this insn in a delay slot sequence?  */
-         if (!final_sequence || XVECLEN (final_sequence, 0) < 2
+         if (!final_sequence || final_sequence->len () < 2
              || current_insn_predicate
              || CALL_P (final_sequence->insn (0))
              || simplejump_p (final_sequence->insn (0)))
@@ -5067,8 +5067,8 @@ arc_print_operand (FILE *file, rtx x, int code)
            fputs (arc_condition_codes[cc], file);
          else /* An Instruction in a delay slot of a jump or call.  */
            {
-             rtx jump = XVECEXP (final_sequence, 0, 0);
-             rtx insn = XVECEXP (final_sequence, 0, 1);
+             rtx_insn *jump = final_sequence->insn (0);
+             rtx_insn *insn = final_sequence->insn (1);
 
              /* If the insn is annulled and is from the target path, we need
                 to inverse the condition test.  */
@@ -7807,10 +7807,10 @@ arc600_corereg_hazard (rtx_insn *pred, rtx_insn *succ)
 {
   if (!TARGET_ARC600)
     return 0;
-  if (GET_CODE (PATTERN (pred)) == SEQUENCE)
-    pred = as_a <rtx_sequence *> (PATTERN (pred))->insn (1);
-  if (GET_CODE (PATTERN (succ)) == SEQUENCE)
-    succ = as_a <rtx_sequence *> (PATTERN (succ))->insn (0);
+  if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (pred)))
+    pred = seq->insn (1);
+  if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (succ)))
+    succ = seq->insn (0);
   if (recog_memoized (pred) == CODE_FOR_mulsi_600
       || recog_memoized (pred) == CODE_FOR_umul_600
       || recog_memoized (pred) == CODE_FOR_mac_600
@@ -9436,7 +9436,7 @@ arc_adjust_insn_length (rtx_insn *insn, int len, bool)
   if (!INSN_P (insn))
     return len;
   /* We already handle sequences by ignoring the delay sequence flag.  */
-  if (GET_CODE (PATTERN (insn)) == SEQUENCE)
+  if (is_a <rtx_sequence *> (PATTERN (insn)))
     return len;
 
   /* Check for return with but one preceding insn since function
@@ -9448,12 +9448,13 @@ arc_adjust_insn_length (rtx_insn *insn, int len, bool)
       && get_attr_type (insn) == TYPE_RETURN)
     {
       rtx_insn *prev = prev_active_insn (insn);
+      rtx_sequence *prev_seq = nullptr;
 
       if (!prev || !(prev = prev_active_insn (prev))
          || ((NONJUMP_INSN_P (prev)
-              && GET_CODE (PATTERN (prev)) == SEQUENCE)
-             ? CALL_ATTR (as_a <rtx_sequence *> (PATTERN (prev))->insn (0),
-                          NON_SIBCALL)
+              && (prev_seq
+                  = dyn_cast <rtx_sequence *> (PATTERN (prev))))
+             ? CALL_ATTR (prev_seq->insn (0), NON_SIBCALL)
              : CALL_ATTR (prev, NON_SIBCALL)))
        return len + 4;
     }
@@ -9527,14 +9528,16 @@ arc_predicate_delay_insns (void)
 {
   for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
     {
-      rtx pat, jump, dlay, src, cond, *patp;
+      rtx pat, src, cond, *patp;
+      rtx_insn *jump, *dlay;
       int reverse;
+      rtx_sequence *seq;
 
       if (!NONJUMP_INSN_P (insn)
-         || GET_CODE (pat = PATTERN (insn)) != SEQUENCE)
+         || !(seq = dyn_cast <rtx_sequence *> (PATTERN (insn))))
        continue;
-      jump = XVECEXP (pat, 0, 0);
-      dlay = XVECEXP (pat, 0, 1);
+      jump = seq->insn (0);
+      dlay = seq->insn (1);
       if (!JUMP_P (jump) || !INSN_ANNULLED_BRANCH_P (jump))
        continue;
       /* If the branch insn does the annulling, leave the delay insn alone.  */
diff --git a/gcc/config/cris/cris.cc b/gcc/config/cris/cris.cc
index c3cb47b3010..d9dbeea83cf 100644
--- a/gcc/config/cris/cris.cc
+++ b/gcc/config/cris/cris.cc
@@ -403,8 +403,8 @@ cris_postdbr_cmpelim ()
 
       /* Consider filled delay slots; there might be a comparison there.
         It's only the second insn in a sequence that is interesting.  */
-      if (GET_CODE (pat) == SEQUENCE)
-       insn = as_a <rtx_insn *> (XVECEXP (pat, 0, 1));
+      if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (pat))
+       insn = seq->insn (1);
       /* The "else" eliminates temptations to consider an insn in a
         delay slot for elimination; it can only be a prev_cc_setter.  */
       else if (prev_cc_setter != 0 && GET_CODE (pat) == SET)
diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index 1cf3a1ab9b9..bca2f13c71d 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -19357,7 +19357,7 @@ mips_classify_branch_p6600 (rtx_insn *insn)
   /* We ignore sequences here as they represent a filled delay slot.  */
   if (!insn
       || !USEFUL_INSN_P (insn)
-      || GET_CODE (PATTERN (insn)) == SEQUENCE)
+      || is_a<rtx_sequence *> (PATTERN (insn)))
     return UC_UNDEFINED;
 
   if (get_attr_jal (insn) == JAL_INDIRECT /* JIC and JIALC.  */
@@ -19418,7 +19418,7 @@ mips_avoid_hazard (rtx_insn *after, rtx_insn *insn, int 
*hilo_delay,
      imply it is not actually a compact branch anyway) and the current
      insn is not an inline asm, and can't go in a delay slot.  */
   else if (*fs_delay && get_attr_can_delay (insn) == CAN_DELAY_NO
-          && GET_CODE (PATTERN (after)) != SEQUENCE
+          && !is_a<rtx_sequence *> (PATTERN (after))
           && GET_CODE (pattern) != ASM_INPUT
           && asm_noperands (pattern) < 0)
     nops = 1;
@@ -19507,9 +19507,15 @@ mips_emit_speculation_barrier_function ()
 static bool
 mips_breakable_sequence_p (rtx_insn *insn)
 {
-  return (insn && GET_CODE (PATTERN (insn)) == SEQUENCE
-         && TARGET_CB_MAYBE
-         && get_attr_compact_form (SEQ_BEGIN (insn)) != COMPACT_FORM_NEVER);
+  if (!insn || !TARGET_CB_MAYBE)
+    return false;
+
+  auto seq = dyn_cast<rtx_sequence *> (PATTERN (insn));
+  if (!seq)
+    return false;
+  if (INSN_P (insn))
+    insn = seq->insn (0);
+  return get_attr_compact_form (insn) != COMPACT_FORM_NEVER;
 }
 
 /* Remove a SEQUENCE and replace it with the delay slot instruction
@@ -19619,7 +19625,7 @@ mips_reorg_process_insns (void)
       next_insn = NEXT_INSN (insn);
       if (USEFUL_INSN_P (insn))
        {
-         if (GET_CODE (PATTERN (insn)) == SEQUENCE)
+         if (auto seq = dyn_cast<rtx_sequence *> (PATTERN (insn)))
            {
              rtx_insn *next_active = next_active_insn (insn);
              /* Undo delay slots to avoid bubbles if the next instruction can
@@ -19628,11 +19634,11 @@ mips_reorg_process_insns (void)
                 safely breakable.  */
              if (TARGET_CB_MAYBE
                  && mips_breakable_sequence_p (insn)
-                 && INSN_P (SEQ_BEGIN (insn))
-                 && INSN_P (SEQ_END (insn))
+                 && INSN_P (seq->insn (0))
+                 && INSN_P (seq->insn (seq->len () - 1))
                  && ((next_active
                       && INSN_P (next_active)
-                      && GET_CODE (PATTERN (next_active)) != SEQUENCE
+                      && !is_a<rtx_sequence *> (PATTERN (next_active))
                       && get_attr_can_delay (next_active) == CAN_DELAY_YES)
                      || !optimize_size))
                {
diff --git a/gcc/config/pa/pa.cc b/gcc/config/pa/pa.cc
index dba51d6baa6..18f5099a148 100644
--- a/gcc/config/pa/pa.cc
+++ b/gcc/config/pa/pa.cc
@@ -4670,8 +4670,10 @@ pa_output_function_epilogue (FILE *file)
     insn = prev_real_insn (insn);
 
   /* If it is a sequence, then look inside.  */
-  if (insn && NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
-    insn = as_a <rtx_sequence *> (PATTERN (insn))-> insn (0);
+  rtx_sequence *seq;
+  if (insn && NONJUMP_INSN_P (insn)
+      && (seq = dyn_cast <rtx_sequence *> (PATTERN (insn))))
+    insn = seq->insn (0);
 
   /* If insn is a CALL_INSN, then it must be a call to a volatile
      function (otherwise there would be epilogue insns).  */
@@ -5405,8 +5407,8 @@ pa_adjust_insn_length (rtx_insn *insn, int length)
   /* If length is negative or undefined, provide initial length.  */
   if ((unsigned int) length >= INT_MAX)
     {
-      if (GET_CODE (pat) == SEQUENCE)
-       insn = as_a <rtx_insn *> (XVECEXP (pat, 0, 0));
+      if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (pat))
+       insn = seq->insn (0);
 
       switch (get_attr_type (insn))
        {
@@ -5507,7 +5509,7 @@ pa_print_operand (FILE *file, rtx x, int code)
       /* delay slot or nullification is requested.  */
       if (dbr_sequence_length () == 0 ||
          (final_sequence &&
-          INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))))
+          INSN_ANNULLED_BRANCH_P (final_sequence->insn (0))))
         fputs (",n", file);
       return;
     case 'R':
diff --git a/gcc/config/pru/pru.cc b/gcc/config/pru/pru.cc
index 6bc80badbab..de06f76d6ec 100644
--- a/gcc/config/pru/pru.cc
+++ b/gcc/config/pru/pru.cc
@@ -2562,8 +2562,9 @@ pru_insert_loop_label_last (rtx_insn *last_insn, 
rtx_code_label *label,
 
        if (NONDEBUG_INSN_P (prev))
          {
-           if (GET_CODE (PATTERN (prev)) == SEQUENCE)
-             prev = as_a <rtx_insn *> (XVECEXP (PATTERN (prev), 0, 1));
+           if (rtx_sequence *seq
+               = dyn_cast <rtx_sequence *> (PATTERN (prev)))
+             prev = seq->insn (1);
 
            /* Other insns that should not be in the last two opcodes.  */
            icode = recog_memoized (prev);
diff --git a/gcc/config/sparc/sparc.cc b/gcc/config/sparc/sparc.cc
index 6fef98195c1..35d2402e98e 100644
--- a/gcc/config/sparc/sparc.cc
+++ b/gcc/config/sparc/sparc.cc
@@ -3997,14 +3997,15 @@ empty_delay_slot (rtx_insn *insn)
 int
 emit_cbcond_nop (rtx_insn *insn)
 {
-  rtx next = next_active_insn (insn);
+  rtx_insn *next = next_active_insn (insn);
 
   if (!next)
     return 1;
 
+  rtx_sequence *seq;
   if (NONJUMP_INSN_P (next)
-      && GET_CODE (PATTERN (next)) == SEQUENCE)
-    next = XVECEXP (PATTERN (next), 0, 0);
+      && (seq = dyn_cast <rtx_sequence *> (PATTERN (next))))
+    next = seq->insn (0);
   else if (CALL_P (next)
           && GET_CODE (PATTERN (next)) == PARALLEL)
     {
@@ -6350,11 +6351,12 @@ sparc_asm_function_epilogue (FILE *file)
 
   rtx_insn *insn = get_last_insn ();
 
-  rtx last_real_insn = prev_real_insn (insn);
+  rtx_insn *last_real_insn = prev_real_insn (insn);
+  rtx_sequence *seq;
   if (last_real_insn
       && NONJUMP_INSN_P (last_real_insn)
-      && GET_CODE (PATTERN (last_real_insn)) == SEQUENCE)
-    last_real_insn = XVECEXP (PATTERN (last_real_insn), 0, 0);
+      && (seq = dyn_cast <rtx_sequence *> (PATTERN (last_real_insn))))
+    last_real_insn = seq->insn (0);
 
   if (last_real_insn
       && CALL_P (last_real_insn)
diff --git a/gcc/config/visium/visium.cc b/gcc/config/visium/visium.cc
index 538676d94be..32fcf7443cb 100644
--- a/gcc/config/visium/visium.cc
+++ b/gcc/config/visium/visium.cc
@@ -986,7 +986,7 @@ empty_delay_slot (rtx_insn *insn)
     return 1;
 
   rtx_insn *seq = NEXT_INSN (PREV_INSN (insn));
-  if (GET_CODE (PATTERN (seq)) == SEQUENCE)
+  if (is_a <rtx_sequence *> (PATTERN (seq)))
     return 0;
 
   return 1;
@@ -1276,10 +1276,10 @@ gr5_hazard_avoidance (void)
       {
        rtx pat = PATTERN (insn);
 
-       if (GET_CODE (pat) == SEQUENCE)
+       if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (pat))
          {
-           for (int i = 0; i < XVECLEN (pat, 0); i++)
-             gr5_avoid_hazard (as_a <rtx_insn *> (XVECEXP (pat, 0, i)),
+           for (int i = 0; i < seq->len (); i++)
+             gr5_avoid_hazard (seq->insn (i),
                                &last_reg, &last_insn_call);
          }
 
diff --git a/gcc/emit-rtl.cc b/gcc/emit-rtl.cc
index e76e0bbb264..763225b57e9 100644
--- a/gcc/emit-rtl.cc
+++ b/gcc/emit-rtl.cc
@@ -3164,7 +3164,7 @@ reset_all_used_flags (void)
            gcc_assert (REG_NOTES (p) == NULL);
            for (int i = 0; i < seq->len (); i++)
              {
-               rtx insn = seq->element (i);
+               rtx_insn *insn = seq->insn (i);
                if (INSN_P (insn))
                  reset_insn_used_flags (insn);
              }
@@ -3205,7 +3205,7 @@ verify_rtl_sharing (void)
        if (rtx_sequence *seq = dyn_cast<rtx_sequence *> (pat))
          for (int i = 0; i < seq->len (); i++)
              {
-               rtx insn = seq->element (i);
+               rtx_insn *insn = seq->insn (i);
                if (INSN_P (insn))
                  verify_insn_sharing (insn);
              }
@@ -3636,9 +3636,9 @@ next_insn (rtx_insn *insn)
   if (insn)
     {
       insn = NEXT_INSN (insn);
-      if (insn && NONJUMP_INSN_P (insn)
-         && GET_CODE (PATTERN (insn)) == SEQUENCE)
-       insn = as_a <rtx_sequence *> (PATTERN (insn))->insn (0);
+      if (insn && NONJUMP_INSN_P (insn))
+       if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
+         insn = seq->insn (0);
     }
 
   return insn;
@@ -4314,28 +4314,27 @@ link_insn_into_chain (rtx_insn *insn, rtx_insn *prev, 
rtx_insn *next)
   if (prev != NULL)
     {
       SET_NEXT_INSN (prev) = insn;
-      if (NONJUMP_INSN_P (prev) && GET_CODE (PATTERN (prev)) == SEQUENCE)
-       {
-         rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (prev));
+      if (NONJUMP_INSN_P (prev))
+       if (rtx_sequence *sequence
+           = dyn_cast <rtx_sequence *> (PATTERN (prev)))
          SET_NEXT_INSN (sequence->insn (sequence->len () - 1)) = insn;
-       }
     }
   if (next != NULL)
     {
       SET_PREV_INSN (next) = insn;
-      if (NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) == SEQUENCE)
-       {
-         rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (next));
+      if (NONJUMP_INSN_P (next))
+       if (rtx_sequence *sequence
+           = dyn_cast <rtx_sequence *> (PATTERN (next)))
          SET_PREV_INSN (sequence->insn (0)) = insn;
-       }
     }
 
-  if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
-    {
-      rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (insn));
-      SET_PREV_INSN (sequence->insn (0)) = prev;
-      SET_NEXT_INSN (sequence->insn (sequence->len () - 1)) = next;
-    }
+  if (NONJUMP_INSN_P (insn))
+    if (rtx_sequence *sequence
+       = dyn_cast <rtx_sequence *> (PATTERN (insn)))
+      {
+       SET_PREV_INSN (sequence->insn (0)) = prev;
+       SET_NEXT_INSN (sequence->insn (sequence->len () - 1)) = next;
+      }
 }
 
 /* Add INSN to the end of the doubly-linked list.
@@ -4499,11 +4498,10 @@ remove_insn (rtx_insn *insn)
   if (prev)
     {
       SET_NEXT_INSN (prev) = next;
-      if (NONJUMP_INSN_P (prev) && GET_CODE (PATTERN (prev)) == SEQUENCE)
-       {
-         rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (prev));
+      if (NONJUMP_INSN_P (prev))
+       if (rtx_sequence *sequence
+           = dyn_cast <rtx_sequence *> (PATTERN (prev)))
          SET_NEXT_INSN (sequence->insn (sequence->len () - 1)) = next;
-       }
     }
   else
     {
@@ -4522,11 +4520,10 @@ remove_insn (rtx_insn *insn)
   if (next)
     {
       SET_PREV_INSN (next) = prev;
-      if (NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) == SEQUENCE)
-       {
-         rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (next));
+      if (NONJUMP_INSN_P (next))
+       if (rtx_sequence *sequence
+           = dyn_cast <rtx_sequence *> (PATTERN (next)))
          SET_PREV_INSN (sequence->insn (0)) = prev;
-       }
     }
   else
     {
diff --git a/gcc/final.cc b/gcc/final.cc
index aeb76fb3bce..9f9bc20f19b 100644
--- a/gcc/final.cc
+++ b/gcc/final.cc
@@ -268,7 +268,7 @@ int
 dbr_sequence_length (void)
 {
   if (final_sequence != 0)
-    return XVECLEN (final_sequence, 0) - 1;
+    return final_sequence->len () - 1;
   else
     return 0;
 }
@@ -1305,9 +1305,10 @@ shorten_branches (rtx_insn *first)
              continue;
            }
 
-         if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
+         rtx_sequence *seqn;
+         if (NONJUMP_INSN_P (insn)
+             && (seqn = dyn_cast <rtx_sequence *> (PATTERN (insn))))
            {
-             rtx_sequence *seqn = as_a <rtx_sequence *> (PATTERN (insn));
              int i;
 
              body = PATTERN (insn);
@@ -4169,10 +4170,11 @@ leaf_function_p (void)
          && ! SIBLING_CALL_P (insn)
          && ! FAKE_CALL_P (insn))
        return false;
+      rtx_sequence *seq;
       if (NONJUMP_INSN_P (insn)
-         && GET_CODE (PATTERN (insn)) == SEQUENCE
-         && CALL_P (XVECEXP (PATTERN (insn), 0, 0))
-         && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
+         && (seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
+         && CALL_P (seq->insn (0))
+         && ! SIBLING_CALL_P (seq->insn (0)))
        return false;
     }
 
@@ -4531,12 +4533,10 @@ rest_of_clean_state (void)
       SET_PREV_INSN (insn) = NULL;
 
       rtx_insn *call_insn = insn;
+      rtx_sequence *seq;
       if (NONJUMP_INSN_P (call_insn)
-         && GET_CODE (PATTERN (call_insn)) == SEQUENCE)
-       {
-         rtx_sequence *seq = as_a <rtx_sequence *> (PATTERN (call_insn));
-         call_insn = seq->insn (0);
-       }
+         && (seq = dyn_cast <rtx_sequence *> (PATTERN (call_insn))))
+       call_insn = seq->insn (0);
       if (CALL_P (call_insn))
        {
          rtx note
diff --git a/gcc/reorg.cc b/gcc/reorg.cc
index fec60aae478..5e7a4d610b8 100644
--- a/gcc/reorg.cc
+++ b/gcc/reorg.cc
@@ -278,7 +278,7 @@ stop_search_p (rtx_insn *insn, bool labels_p)
     case INSN:
       /* OK unless it contains a delay slot or is an `asm' insn of some type.
         We don't know anything about these.  */
-      return (GET_CODE (PATTERN (insn)) == SEQUENCE
+      return (is_a <rtx_sequence *> (PATTERN (insn))
              || GET_CODE (PATTERN (insn)) == ASM_INPUT
              || asm_noperands (PATTERN (insn)) >= 0);
 
@@ -680,7 +680,7 @@ optimize_skip (rtx_jump_insn *insn, vec<rtx_insn *> 
*delay_list)
 
   if (trial == 0
       || !NONJUMP_INSN_P (trial)
-      || GET_CODE (PATTERN (trial)) == SEQUENCE
+      || is_a <rtx_sequence *> (PATTERN (trial))
       || recog_memoized (trial) < 0
       || (! eligible_for_annul_false (insn, 0, trial, flags)
          && ! eligible_for_annul_true (insn, 0, trial, flags))
@@ -900,7 +900,7 @@ redirect_with_delay_slots_safe_p (rtx_jump_insn *jump, rtx 
newlabel,
 #endif
 #if ANNUL_IFTRUE_SLOTS
           (INSN_ANNULLED_BRANCH_P (jump)
-           && ! INSN_FROM_TARGET_P (XVECEXP (pat, 0, i)))
+           && ! INSN_FROM_TARGET_P (pat->insn (i)))
           ? eligible_for_annul_true (jump, i - 1, pat->insn (i), flags) :
 #endif
           eligible_for_delay (jump, i - 1, pat->insn (i), flags)))
@@ -1200,11 +1200,12 @@ static void
 try_merge_delay_insns (rtx_insn *insn, rtx_insn *thread)
 {
   rtx_insn *trial, *next_trial;
-  rtx_insn *delay_insn = as_a <rtx_insn *> (XVECEXP (PATTERN (insn), 0, 0));
+  rtx_sequence *insn_pat = as_a <rtx_sequence *> (PATTERN (insn));
+  rtx_insn *delay_insn = insn_pat->insn (0);
   bool annul_p = JUMP_P (delay_insn) && INSN_ANNULLED_BRANCH_P (delay_insn);
   int slot_number = 1;
-  int num_slots = XVECLEN (PATTERN (insn), 0);
-  rtx next_to_match = XVECEXP (PATTERN (insn), 0, slot_number);
+  int num_slots = insn_pat->len ();
+  rtx_insn *next_to_match = insn_pat->insn (slot_number);
   struct resources set, needed, modified;
   auto_vec<std::pair<rtx_insn *, bool>, 10> merged_insns;
   int flags;
@@ -1222,9 +1223,8 @@ try_merge_delay_insns (rtx_insn *insn, rtx_insn *thread)
      a kludge, but I don't see a better way.)  */
   if (! annul_p)
     for (int i = 1; i < num_slots; i++)
-      if (XVECEXP (PATTERN (insn), 0, i))
-       mark_referenced_resources (XVECEXP (PATTERN (insn), 0, i), &needed,
-                                  true);
+      if (insn_pat->insn (i))
+       mark_referenced_resources (insn_pat->insn (i), &needed, true);
 
   for (trial = thread; !stop_search_p (trial, true); trial = next_trial)
     {
@@ -1268,7 +1268,7 @@ try_merge_delay_insns (rtx_insn *insn, rtx_insn *thread)
          if (++slot_number == num_slots)
            break;
 
-         next_to_match = XVECEXP (PATTERN (insn), 0, slot_number);
+         next_to_match = insn_pat->insn (slot_number);
        }
 
       mark_set_resources (trial, &set, 0, MARK_SRC_DEST_CALL);
@@ -1277,14 +1277,14 @@ try_merge_delay_insns (rtx_insn *insn, rtx_insn *thread)
 
   /* See if we stopped on a filled insn.  If we did, try to see if its
      delay slots match.  */
+  rtx_sequence *pat;
   if (slot_number != num_slots
       && trial && NONJUMP_INSN_P (trial)
-      && GET_CODE (PATTERN (trial)) == SEQUENCE
-      && !(JUMP_P (XVECEXP (PATTERN (trial), 0, 0))
-           && INSN_ANNULLED_BRANCH_P (XVECEXP (PATTERN (trial), 0, 0))))
+      && (pat = dyn_cast <rtx_sequence *> (PATTERN (trial)))
+      && !(JUMP_P (pat->insn (0))
+          && INSN_ANNULLED_BRANCH_P (pat->insn (0))))
     {
-      rtx_sequence *pat = as_a <rtx_sequence *> (PATTERN (trial));
-      rtx filled_insn = XVECEXP (pat, 0, 0);
+      rtx_insn *filled_insn = pat->insn (0);
 
       /* Account for resources set/needed by the filled insn.  */
       mark_set_resources (filled_insn, &set, 0, MARK_SRC_DEST_CALL);
@@ -1298,12 +1298,12 @@ try_merge_delay_insns (rtx_insn *insn, rtx_insn *thread)
          /* Account for resources set by the insn following NEXT_TO_MATCH
             inside INSN's delay list. */
          for (int j = 1; slot_number + j < num_slots; j++)
-           mark_set_resources (XVECEXP (PATTERN (insn), 0, slot_number + j),
+           mark_set_resources (insn_pat->insn (slot_number + j),
                                &modified, 0, MARK_SRC_DEST_CALL);
          /* Account for resources set by the insn before DTRIAL and inside
             TRIAL's delay list. */
          for (int j = 1; j < i; j++)
-           mark_set_resources (XVECEXP (pat, 0, j),
+           mark_set_resources (pat->insn (j),
                                &modified, 0, MARK_SRC_DEST_CALL);
          if (! insn_references_resource_p (dtrial, &set, true)
              && ! insn_sets_resource_p (dtrial, &set, true)
@@ -1333,7 +1333,7 @@ try_merge_delay_insns (rtx_insn *insn, rtx_insn *thread)
              if (++slot_number == num_slots)
                break;
 
-             next_to_match = XVECEXP (PATTERN (insn), 0, slot_number);
+             next_to_match = insn_pat->insn (slot_number);
            }
          else
            {
@@ -1369,8 +1369,8 @@ try_merge_delay_insns (rtx_insn *insn, rtx_insn *thread)
 
       INSN_ANNULLED_BRANCH_P (delay_insn) = 0;
 
-      for (int i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
-       INSN_FROM_TARGET_P (XVECEXP (PATTERN (insn), 0, i)) = 0;
+      for (int i = 0; i < insn_pat->len (); i++)
+       INSN_FROM_TARGET_P (insn_pat->insn (i)) = 0;
     }
 }
 
@@ -1478,8 +1478,11 @@ redundant_insn (rtx_insn *insn, rtx_insn *target,
   mark_referenced_resources (insn, &needed, true);
 
   /* If TARGET is a SEQUENCE, get the main insn.  */
-  if (NONJUMP_INSN_P (target) && GET_CODE (PATTERN (target)) == SEQUENCE)
-    target_main = XVECEXP (PATTERN (target), 0, 0);
+  rtx_sequence *target_seq = nullptr;
+  if (NONJUMP_INSN_P (target))
+    target_seq = dyn_cast <rtx_sequence *> (PATTERN (target));
+  if (target_seq)
+    target_main = target_seq->insn (0);
 
   if (resource_conflicts_p (&needed, &set)
       /* The insn requiring the delay may not set anything needed or set by
@@ -1502,10 +1505,9 @@ redundant_insn (rtx_insn *insn, rtx_insn *target,
     if (insn_sets_resource_p (temp, &needed, true))
       return 0;
 
-  if (NONJUMP_INSN_P (target) && GET_CODE (PATTERN (target)) == SEQUENCE)
-    for (i = 1; i < XVECLEN (PATTERN (target), 0); i++)
-      if (insn_sets_resource_p (XVECEXP (PATTERN (target), 0, i), &needed,
-                               true))
+  if (target_seq)
+    for (i = 1; i < target_seq->len (); i++)
+      if (insn_sets_resource_p (target_seq->insn (i), &needed, true))
        return 0;
 
   /* Scan backwards until we reach a label or an insn that uses something
@@ -1823,7 +1825,7 @@ fill_simple_delay_slots (bool non_jumps_p)
       if (insn == 0
          || insn->deleted ()
          || (NONJUMP_INSN_P (insn)
-             && GET_CODE (PATTERN (insn)) == SEQUENCE)
+             && is_a <rtx_sequence *> (PATTERN (insn)))
          || (JUMP_P (insn) && non_jumps_p)
          || (!JUMP_P (insn) && ! non_jumps_p))
        continue;
@@ -2085,8 +2087,9 @@ fill_simple_delay_slots (bool non_jumps_p)
 
              /* If this already has filled delay slots, get the insn needing
                 the delay slots.  */
-             if (GET_CODE (pat) == SEQUENCE)
-               trial_delay = XVECEXP (pat, 0, 0);
+             rtx_sequence *delay_seq = dyn_cast <rtx_sequence *> (pat);
+             if (delay_seq)
+               trial_delay = delay_seq->insn (0);
              else
                trial_delay = trial;
 
@@ -2095,7 +2098,7 @@ fill_simple_delay_slots (bool non_jumps_p)
                break;
 
              /* See if we have a resource problem before we try to split.  */
-             if (GET_CODE (pat) != SEQUENCE
+             if (!delay_seq
                  && ! insn_references_resource_p (trial, &set, true)
                  && ! insn_sets_resource_p (trial, &set, true)
                  && ! insn_sets_resource_p (trial, &needed, true)
@@ -2137,7 +2140,7 @@ fill_simple_delay_slots (bool non_jumps_p)
              && simplejump_p (trial)
              && (next_trial = next_active_insn (JUMP_LABEL_AS_INSN (trial))) 
!= 0
              && ! (NONJUMP_INSN_P (next_trial)
-                   && GET_CODE (PATTERN (next_trial)) == SEQUENCE)
+                   && is_a <rtx_sequence *> (PATTERN (next_trial)))
              && !JUMP_P (next_trial)
              && ! insn_references_resource_p (next_trial, &set, true)
              && ! insn_sets_resource_p (next_trial, &set, true)
@@ -2601,11 +2604,11 @@ fill_slots_from_thread (rtx_jump_insn *insn, rtx 
condition,
   rtx thread_tail = new_thread;
   /* If we stopped on a branch insn that has delay slots, see if we can
      steal some of the insns in those slots.  */
+  rtx_sequence *sequence;
   if (trial && NONJUMP_INSN_P (trial)
-      && GET_CODE (PATTERN (trial)) == SEQUENCE
-      && JUMP_P (XVECEXP (PATTERN (trial), 0, 0)))
+      && (sequence = dyn_cast <rtx_sequence *> (PATTERN (trial)))
+      && JUMP_P (sequence->insn (0)))
     {
-      rtx_sequence *sequence = as_a <rtx_sequence *> (PATTERN (trial));
       /* If this is the `true' thread, we will want to follow the jump,
         so we can only do this if we have taken everything up to here.  */
       if (thread_if_true && trial == thread_tail)
@@ -3194,10 +3197,9 @@ relax_delay_slots (rtx_insn *first)
        }
 
       /* Now look only at cases where we have a filled delay slot.  */
-      if (!NONJUMP_INSN_P (insn) || GET_CODE (PATTERN (insn)) != SEQUENCE)
+      if (!NONJUMP_INSN_P (insn)
+         || !(pat = dyn_cast <rtx_sequence *> (PATTERN (insn))))
        continue;
-
-      pat = as_a <rtx_sequence *> (PATTERN (insn));
       delay_insn = pat->insn (0);
 
       /* See if the first insn in the delay slot is redundant with some
@@ -3241,8 +3243,8 @@ relax_delay_slots (rtx_insn *first)
 
             Clear the from target bit, since these insns are no longer
             in delay slots.  */
-         for (i = 0; i < XVECLEN (pat, 0); i++)
-           INSN_FROM_TARGET_P (XVECEXP (pat, 0, i)) = 0;
+         for (i = 0; i < pat->len (); i++)
+           INSN_FROM_TARGET_P (pat->insn (i)) = 0;
 
          rtx_insn *prev = PREV_INSN (insn);
          delete_related_insns (insn);
@@ -3367,8 +3369,8 @@ relax_delay_slots (rtx_insn *first)
 
             Clear the from target bit, since these insns are no longer
             in delay slots.  */
-         for (i = 0; i < XVECLEN (pat, 0); i++)
-           INSN_FROM_TARGET_P (XVECEXP (pat, 0, i)) = 0;
+         for (i = 0; i < pat->len (); i++)
+           INSN_FROM_TARGET_P (pat->insn (i)) = 0;
 
          rtx_insn *prev = PREV_INSN (insn);
          delete_related_insns (insn);
@@ -3387,7 +3389,7 @@ relax_delay_slots (rtx_insn *first)
       if (next && NONJUMP_INSN_P (next)
          && label_before_next_insn (next, insn) == target_label
          && simplejump_p (insn)
-         && XVECLEN (pat, 0) == 2
+         && pat->len () == 2
          && rtx_equal_p (PATTERN (next), PATTERN (pat->insn (1))))
        {
          delete_related_insns (insn);
@@ -3430,9 +3432,9 @@ relax_delay_slots (rtx_insn *first)
                  /* Must update the INSN_FROM_TARGET_P bits now that
                     the branch is reversed, so that mark_target_live_regs
                     will handle the delay slot insn correctly.  */
-                 for (int i = 1; i < XVECLEN (PATTERN (insn), 0); i++)
+                 for (int i = 1; i < pat->len (); i++)
                    {
-                     rtx slot = XVECEXP (PATTERN (insn), 0, i);
+                     rtx_insn *slot = pat->insn (i);
                      INSN_FROM_TARGET_P (slot) = ! INSN_FROM_TARGET_P (slot);
                    }
 
@@ -3517,11 +3519,10 @@ make_return_insns (rtx_insn *first)
       if (!NONJUMP_INSN_P (insn))
        continue;
 
-      if (GET_CODE (PATTERN (insn)) != SEQUENCE)
+      rtx_sequence *pat = dyn_cast <rtx_sequence *> (PATTERN (insn));
+      if (!pat)
        continue;
 
-      rtx_sequence *pat = as_a <rtx_sequence *> (PATTERN (insn));
-
       if (!jump_to_label_p (pat->insn (0)))
        continue;
 
@@ -3557,7 +3558,7 @@ make_return_insns (rtx_insn *first)
 
       flags = get_jump_flags (jump_insn, JUMP_LABEL (jump_insn));
       slots = num_delay_slots (jump_insn);
-      if (slots >= XVECLEN (pat, 0) - 1)
+      if (slots >= pat->len () - 1)
        {
          for (i = 1; i < XVECLEN (pat, 0); i++)
            if (! (
@@ -3774,13 +3775,12 @@ dbr_schedule (rtx_insn *first)
              && GET_CODE (PATTERN (insn)) != USE
              && GET_CODE (PATTERN (insn)) != CLOBBER)
            {
-             if (GET_CODE (PATTERN (insn)) == SEQUENCE)
+             if (auto *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
                {
-                  rtx control;
-                 j = XVECLEN (PATTERN (insn), 0) - 1;
+                 rtx_insn *control = seq->insn (0);
+                 j = seq->len () - 1;
                  if (j > MAX_DELAY_HISTOGRAM)
                    j = MAX_DELAY_HISTOGRAM;
-                  control = XVECEXP (PATTERN (insn), 0, 0);
                  if (JUMP_P (control) && INSN_ANNULLED_BRANCH_P (control))
                    total_annul_slots[j]++;
                  else
diff --git a/gcc/resource.cc b/gcc/resource.cc
index f377fe99e51..d5adefecefb 100644
--- a/gcc/resource.cc
+++ b/gcc/resource.cc
@@ -179,9 +179,9 @@ next_insn_no_annul (rtx_insn *insn)
        }
 
       insn = NEXT_INSN (insn);
-      if (insn && NONJUMP_INSN_P (insn)
-         && GET_CODE (PATTERN (insn)) == SEQUENCE)
-       insn = as_a <rtx_sequence *> (PATTERN (insn))->insn (0);
+      if (insn && NONJUMP_INSN_P (insn))
+       if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
+         insn = seq->insn (0);
     }
 
   return insn;
@@ -347,7 +347,7 @@ mark_referenced_resources (rtx x, struct resources *res,
                {
                  for (i = 1; i < seq_size; i++)
                    {
-                     rtx slot_pat = PATTERN (sequence->element (i));
+                     rtx slot_pat = PATTERN (sequence->insn (i));
                      if (GET_CODE (slot_pat) == SET
                          && rtx_equal_p (SET_DEST (slot_pat),
                                          XEXP (XEXP (link, 0), 0)))
@@ -511,7 +511,7 @@ mark_set_resources (rtx x, struct resources *res, int 
in_dest,
         mark_set_resources (control, res, 0, mark_type);
         for (i = seq->len () - 1; i >= 0; --i)
          {
-           rtx elt = seq->element (i);
+           rtx_insn *elt = seq->insn (i);
            if (!annul_p && INSN_FROM_TARGET_P (elt))
              mark_set_resources (elt, res, 0, mark_type);
          }
@@ -625,8 +625,10 @@ return_insn_p (const rtx_insn *insn)
   if (JUMP_P (insn) && ANY_RETURN_P (PATTERN (insn)))
     return true;
 
-  if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
-    return return_insn_p (as_a <rtx_insn *> (XVECEXP (PATTERN (insn), 0, 0)));
+  rtx_sequence *seq;
+  if (NONJUMP_INSN_P (insn)
+      && (seq = dyn_cast <rtx_sequence *> (PATTERN (insn))))
+    return return_insn_p (seq->insn (0));
 
   return false;
 }
@@ -766,12 +768,12 @@ mark_target_live_regs (rtx_insn *insns, rtx 
target_maybe_return, struct resource
                    insns : BB_HEAD (BASIC_BLOCK_FOR_FN (cfun, b)));
       stop_insn = target;
 
-      if (NONJUMP_INSN_P (start_insn)
-         && GET_CODE (PATTERN (start_insn)) == SEQUENCE)
-       start_insn = as_a <rtx_sequence *> (PATTERN (start_insn))->insn (0);
+      if (NONJUMP_INSN_P (start_insn))
+       if (auto *seq = dyn_cast <rtx_sequence *> (PATTERN (start_insn)))
+         start_insn = seq->insn (0);
 
       if (NONJUMP_INSN_P (stop_insn)
-         && GET_CODE (PATTERN (stop_insn)) == SEQUENCE)
+         && is_a <rtx_sequence *> (PATTERN (stop_insn)))
        stop_insn = next_insn (PREV_INSN (stop_insn));
 
       for (insn = start_insn; insn != stop_insn;
diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
index e64faf47236..568c9eaca11 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -1243,10 +1243,12 @@ reg_set_p (const_rtx reg, const_rtx uncast_insn)
 
   /* After delay slot handling, call and branch insns might be in a
      sequence.  Check all the elements there.  */
-  if (INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
+  rtx_sequence *seq;
+  if (INSN_P (insn)
+      && (seq = dyn_cast <rtx_sequence *> (PATTERN (insn))))
     {
-      for (int i = 0; i < XVECLEN (PATTERN (insn), 0); ++i)
-       if (reg_set_p (reg, XVECEXP (PATTERN (insn), 0, i)))
+      for (int i = 0; i < seq->len (); ++i)
+       if (reg_set_p (reg, seq->element (i)))
          return true;
 
       return false;
@@ -3601,13 +3603,14 @@ verify_jump_tables (void)
        }
       else if (JUMP_P (insn))
        jumps.safe_push (insn);
-      else if (NONDEBUG_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
-       for (int i = 0; i < XVECLEN (PATTERN (insn), 0); ++i)
-         {
-           rtx_insn *part = as_a<rtx_insn *> (XVECEXP (PATTERN (insn), 0, i));
-           if (JUMP_P (part))
-             jumps.safe_push (part);
-         }
+      else if (NONDEBUG_INSN_P (insn))
+       if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
+         for (int i = 0; i < seq->len (); ++i)
+           {
+             rtx_insn *part = seq->insn (i);
+             if (JUMP_P (part))
+               jumps.safe_push (part);
+           }
     }
 
   for (rtx_jump_table_data *table : tables)
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 0c5f80165e9..14637cbe626 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -4545,7 +4545,7 @@ mark_constants (rtx_insn *insn)
       int i, n = seq->len ();
       for (i = 0; i < n; ++i)
        {
-         rtx subinsn = seq->element (i);
+         rtx_insn *subinsn = seq->insn (i);
          if (INSN_P (subinsn))
            mark_constants_in_pattern (subinsn);
        }
-- 
2.53.0

Reply via email to