OSDN Git Service

PR target/37633
[pf3gnuchains/gcc-fork.git] / gcc / config / sh / sh.c
index 57049ea..14892ce 100644 (file)
@@ -51,7 +51,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "intl.h"
 #include "sched-int.h"
 #include "ggc.h"
-#include "tree-gimple.h"
+#include "gimple.h"
 #include "cfgloop.h"
 #include "alloc-pool.h"
 #include "tm-constrs.h"
@@ -241,8 +241,8 @@ static int addsubcosts (rtx);
 static int multcosts (rtx);
 static bool unspec_caller_rtx_p (rtx);
 static bool sh_cannot_copy_insn_p (rtx);
-static bool sh_rtx_costs (rtx, int, int, int *);
-static int sh_address_cost (rtx);
+static bool sh_rtx_costs (rtx, int, int, int *, bool);
+static int sh_address_cost (rtx, bool);
 static int sh_pr_n_sets (void);
 static rtx sh_allocate_initial_value (rtx);
 static int shmedia_target_regs_stack_space (HARD_REG_SET *);
@@ -261,7 +261,7 @@ static bool sh_strict_argument_naming (CUMULATIVE_ARGS *);
 static bool sh_pretend_outgoing_varargs_named (CUMULATIVE_ARGS *);
 static tree sh_build_builtin_va_list (void);
 static void sh_va_start (tree, rtx);
-static tree sh_gimplify_va_arg_expr (tree, tree, tree *, tree *);
+static tree sh_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
 static bool sh_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
                                  const_tree, bool);
 static bool sh_callee_copies (CUMULATIVE_ARGS *, enum machine_mode,
@@ -681,6 +681,9 @@ print_operand_address (FILE *stream, rtx x)
    'd'  print a V2SF reg as dN instead of fpN.
    'm'  print a pair `base,offset' or `base,index', for LD and ST.
    'U'  Likewise for {LD,ST}{HI,LO}.
+   'V'  print the position of a single bit set.
+   'W'  print the position of a single bit cleared.
+   't'  print a memory address which is a register.
    'u'  prints the lowest 16 bits of CONST_INT, as an unsigned value.
    'o'  output an operator.  */
 
@@ -820,6 +823,21 @@ print_operand (FILE *stream, rtx x, int code)
          break;
        }
       break;
+
+    case 't':
+      gcc_assert (GET_CODE (x) == MEM);
+      x = XEXP (x, 0);
+      switch (GET_CODE (x))
+       {
+       case REG:
+       case SUBREG:
+         print_operand (stream, x, 0);
+         break;
+       default:
+         break;
+       }
+      break;
+
     case 'o':
       switch (GET_CODE (x))
        {
@@ -887,6 +905,22 @@ print_operand (FILE *stream, rtx x, int code)
        }
       break;
 
+    case 'V':
+      {
+       int num = exact_log2 (INTVAL (x));
+       gcc_assert (num >= 0);
+       fprintf (stream, "#%d", num);
+      }
+      break;
+
+    case 'W':
+      {
+       int num = exact_log2 (~INTVAL (x));
+       gcc_assert (num >= 0);
+       fprintf (stream, "#%d", num);
+      }
+      break;
+
     case 'd':
       gcc_assert (GET_CODE (x) == REG && GET_MODE (x) == V2SFmode);
 
@@ -997,45 +1031,6 @@ print_operand (FILE *stream, rtx x, int code)
          output_address (XEXP (x, 0));
          break;
 
-       case CONST:
-         if (TARGET_SHMEDIA
-             && (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND
-                 || GET_CODE (XEXP (x, 0)) == ZERO_EXTEND)
-             && (GET_MODE (XEXP (x, 0)) == DImode
-                 || GET_MODE (XEXP (x, 0)) == SImode)
-             && GET_CODE (XEXP (XEXP (x, 0), 0)) == TRUNCATE
-             && GET_MODE (XEXP (XEXP (x, 0), 0)) == HImode)
-           {
-             rtx val = XEXP (XEXP (XEXP (x, 0), 0), 0);
-             rtx val2 = val;
-             bool nested_expr = false;
-
-             fputc ('(', stream);
-             if (GET_CODE (val) == ASHIFTRT)
-               {
-                 fputc ('(', stream);
-                 val2 = XEXP (val, 0);
-               }
-             if (GET_CODE (val2) == CONST
-                 || GET_RTX_CLASS (GET_CODE (val2)) != RTX_OBJ)
-               {
-                 fputc ('(', stream);
-                 nested_expr = true;
-               }
-             output_addr_const (stream, val2);
-             if (nested_expr)
-               fputc (')', stream);
-             if (GET_CODE (val) == ASHIFTRT)
-               {
-                 fputs (" >> ", stream);
-                 output_addr_const (stream, XEXP (val, 1));
-                 fputc (')', stream);
-               }
-             fputs (" & 65535)", stream);
-             break;
-           }
-
-         /* Fall through.  */
        default:
          if (TARGET_SH1)
            fputc ('#', stream);
@@ -1266,9 +1261,9 @@ prepare_move_operands (rtx operands[], enum machine_mode mode)
        {
          /* This is like change_address_1 (operands[0], mode, 0, 1) ,
             except that we can't use that function because it is static.  */
-         rtx new = change_address (operands[0], mode, 0);
-         MEM_COPY_ATTRIBUTES (new, operands[0]);
-         operands[0] = new;
+         rtx new_rtx = change_address (operands[0], mode, 0);
+         MEM_COPY_ATTRIBUTES (new_rtx, operands[0]);
+         operands[0] = new_rtx;
        }
 
       /* This case can happen while generating code to move the result
@@ -1337,8 +1332,7 @@ prepare_move_operands (rtx operands[], enum machine_mode mode)
                  if (flag_schedule_insns)
                    emit_insn (gen_blockage ());
                  emit_insn (gen_GOTaddr2picreg ());
-                 emit_insn (gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode,
-                                                                PIC_REG)));
+                 emit_use (gen_rtx_REG (SImode, PIC_REG));
                  if (flag_schedule_insns)
                    emit_insn (gen_blockage ());
                }
@@ -1651,6 +1645,14 @@ expand_cbranchdi4 (rtx *operands, enum rtx_code comparison)
     {
       rtx taken_label = operands[3];
 
+      /* Operands were possibly modified, but msw_skip doesn't expect this.
+        Always use the original ones.  */
+      if (msw_taken != CODE_FOR_nothing)
+       {
+         operands[1] = op1h;
+         operands[2] = op2h;
+       }
+
       operands[3] = skip_label = gen_label_rtx ();
       expand_cbranchsi4 (operands, msw_skip, msw_skip_prob);
       operands[3] = taken_label;
@@ -1874,14 +1876,14 @@ print_slot (rtx insn)
 const char *
 output_far_jump (rtx insn, rtx op)
 {
-  struct { rtx lab, reg, op; } this;
+  struct { rtx lab, reg, op; } this_jmp;
   rtx braf_base_lab = NULL_RTX;
   const char *jump;
   int far;
   int offset = branch_dest (insn) - INSN_ADDRESSES (INSN_UID (insn));
   rtx prev;
 
-  this.lab = gen_label_rtx ();
+  this_jmp.lab = gen_label_rtx ();
 
   if (TARGET_SH2
       && offset >= -32764
@@ -1907,10 +1909,10 @@ output_far_jump (rtx insn, rtx op)
   if (GET_CODE ((prev = prev_nonnote_insn (insn))) == INSN
       && INSN_CODE (prev) == CODE_FOR_indirect_jump_scratch)
     {
-      this.reg = SET_DEST (XVECEXP (PATTERN (prev), 0, 0));
-      if (REGNO (this.reg) == R0_REG && flag_pic && ! TARGET_SH2)
+      this_jmp.reg = SET_DEST (XVECEXP (PATTERN (prev), 0, 0));
+      if (REGNO (this_jmp.reg) == R0_REG && flag_pic && ! TARGET_SH2)
        jump = "mov.l   r1,@-r15; mova  %O0,r0; mov.l   @r0,r1; add     r1,r0; mov.l    @r15+,r1; jmp   @%1";
-      output_asm_insn (jump, &this.lab);
+      output_asm_insn (jump, &this_jmp.lab);
       if (dbr_sequence_length ())
        print_slot (final_sequence);
       else
@@ -1922,7 +1924,7 @@ output_far_jump (rtx insn, rtx op)
       if (dbr_sequence_length ())
        print_slot (final_sequence);
 
-      this.reg = gen_rtx_REG (SImode, 13);
+      this_jmp.reg = gen_rtx_REG (SImode, 13);
       /* We must keep the stack aligned to 8-byte boundaries on SH5.
         Fortunately, MACL is fixed and call-clobbered, and we never
         need its value across jumps, so save r13 in it instead of in
@@ -1931,7 +1933,7 @@ output_far_jump (rtx insn, rtx op)
        output_asm_insn ("lds   r13, macl", 0);
       else
        output_asm_insn ("mov.l r13,@-r15", 0);
-      output_asm_insn (jump, &this.lab);
+      output_asm_insn (jump, &this_jmp.lab);
       if (TARGET_SH5)
        output_asm_insn ("sts   macl, r13", 0);
       else
@@ -1945,16 +1947,16 @@ output_far_jump (rtx insn, rtx op)
     }
   if (far)
     output_asm_insn (".align   2", 0);
-  (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (this.lab));
-  this.op = op;
+  (*targetm.asm_out.internal_label) (asm_out_file, "L", CODE_LABEL_NUMBER (this_jmp.lab));
+  this_jmp.op = op;
   if (far && flag_pic)
     {
       if (TARGET_SH2)
-       this.lab = braf_base_lab;
-      output_asm_insn (".long  %O2-%O0", &this.lab);
+       this_jmp.lab = braf_base_lab;
+      output_asm_insn (".long  %O2-%O0", &this_jmp.lab);
     }
   else
-    output_asm_insn (far ? ".long      %O2" : ".word %O2-%O0", &this.lab);
+    output_asm_insn (far ? ".long      %O2" : ".word %O2-%O0", &this_jmp.lab);
   return "";
 }
 
@@ -2051,14 +2053,14 @@ output_branch (int logic, rtx insn, rtx *operands)
     }
 }
 
-/* Output a code sequence for INSN using TEMPLATE with OPERANDS; but before,
+/* Output a code sequence for INSN using TEMPL with OPERANDS; but before,
    fill in operands 9 as a label to the successor insn.
    We try to use jump threading where possible.
    IF CODE matches the comparison in the IF_THEN_ELSE of a following jump,
    we assume the jump is taken.  I.e. EQ means follow jmp and bf, NE means
    follow jmp and bt, if the address is in range.  */
 const char *
-output_branchy_insn (enum rtx_code code, const char *template,
+output_branchy_insn (enum rtx_code code, const char *templ,
                     rtx insn, rtx *operands)
 {
   rtx next_insn = NEXT_INSN (insn);
@@ -2074,7 +2076,7 @@ output_branchy_insn (enum rtx_code code, const char *template,
          INSN_ADDRESSES_NEW (operands[9],
                              INSN_ADDRESSES (INSN_UID (next_insn))
                              + get_attr_length (next_insn));
-         return template;
+         return templ;
        }
       else
        {
@@ -2086,7 +2088,7 @@ output_branchy_insn (enum rtx_code code, const char *template,
                /* branch_true */
                src = XEXP (src, 1);
              operands[9] = src;
-             return template;
+             return templ;
            }
        }
     }
@@ -2095,7 +2097,7 @@ output_branchy_insn (enum rtx_code code, const char *template,
   INSN_ADDRESSES_NEW (operands[9],
                      INSN_ADDRESSES (INSN_UID (insn))
                      + get_attr_length (insn));
-  return template;
+  return templ;
 }
 
 const char *
@@ -2150,22 +2152,18 @@ sh_file_start (void)
 static bool
 unspec_caller_rtx_p (rtx pat)
 {
-  switch (GET_CODE (pat))
+  rtx base, offset;
+  int i;
+
+  split_const (pat, &base, &offset);
+  if (GET_CODE (base) == UNSPEC)
     {
-    case CONST:
-      return unspec_caller_rtx_p (XEXP (pat, 0));
-    case PLUS:
-    case MINUS:
-      if (unspec_caller_rtx_p (XEXP (pat, 0)))
+      if (XINT (base, 1) == UNSPEC_CALLER)
        return true;
-      return unspec_caller_rtx_p (XEXP (pat, 1));
-    case UNSPEC:
-      if (XINT (pat, 1) == UNSPEC_CALLER)
-       return true;
-    default:
-      break;
+      for (i = 0; i < XVECLEN (base, 0); i++)
+       if (unspec_caller_rtx_p (XVECEXP (base, 0, i)))
+         return true;
     }
-
   return false;
 }
 
@@ -2320,7 +2318,7 @@ andcosts (rtx x)
          || satisfies_constraint_J16 (XEXP (x, 1)))
        return 1;
       else
-       return 1 + rtx_cost (XEXP (x, 1), AND);
+       return 1 + rtx_cost (XEXP (x, 1), AND, !optimize_size);
     }
 
   /* These constants are single cycle extu.[bw] instructions.  */
@@ -2420,7 +2418,8 @@ multcosts (rtx x ATTRIBUTE_UNUSED)
    scanned.  In either case, *TOTAL contains the cost result.  */
 
 static bool
-sh_rtx_costs (rtx x, int code, int outer_code, int *total)
+sh_rtx_costs (rtx x, int code, int outer_code, int *total,
+             bool speed ATTRIBUTE_UNUSED)
 {
   switch (code)
     {
@@ -2546,7 +2545,8 @@ sh_rtx_costs (rtx x, int code, int outer_code, int *total)
    since it increases pressure on r0.  */
 
 static int
-sh_address_cost (rtx X)
+sh_address_cost (rtx X,
+                bool speed ATTRIBUTE_UNUSED)
 {
   return (GET_CODE (X) == PLUS
          && ! CONSTANT_P (XEXP (X, 1))
@@ -3442,7 +3442,7 @@ static rtx
 add_constant (rtx x, enum machine_mode mode, rtx last_value)
 {
   int i;
-  rtx lab, new;
+  rtx lab, new_rtx;
   label_ref_list_t ref, newref;
 
   /* First see if we've already got it.  */
@@ -3458,14 +3458,14 @@ add_constant (rtx x, enum machine_mode mode, rtx last_value)
            }
          if (rtx_equal_p (x, pool_vector[i].value))
            {
-             lab = new = 0;
+             lab = new_rtx = 0;
              if (! last_value
                  || ! i
                  || ! rtx_equal_p (last_value, pool_vector[i-1].value))
                {
-                 new = gen_label_rtx ();
-                 LABEL_REFS (new) = pool_vector[i].label;
-                 pool_vector[i].label = lab = new;
+                 new_rtx = gen_label_rtx ();
+                 LABEL_REFS (new_rtx) = pool_vector[i].label;
+                 pool_vector[i].label = lab = new_rtx;
                }
              if (lab && pool_window_label)
                {
@@ -3475,8 +3475,8 @@ add_constant (rtx x, enum machine_mode mode, rtx last_value)
                  newref->next = ref;
                  pool_vector[pool_window_last].wend = newref;
                }
-             if (new)
-               pool_window_label = new;
+             if (new_rtx)
+               pool_window_label = new_rtx;
              pool_window_last = i;
              return lab;
            }
@@ -3753,7 +3753,8 @@ broken_move (rtx insn)
                && FP_REGISTER_P (REGNO (SET_DEST (pat))))
          && ! (TARGET_SH2A
                && GET_MODE (SET_DEST (pat)) == SImode
-               && satisfies_constraint_I20 (SET_SRC (pat)))
+               && (satisfies_constraint_I20 (SET_SRC (pat))
+                  || satisfies_constraint_I28 (SET_SRC (pat))))
          && ! satisfies_constraint_I08 (SET_SRC (pat)))
        return 1;
     }
@@ -3786,7 +3787,7 @@ fixup_mova (rtx mova)
     {
       rtx worker = mova;
       rtx lab = gen_label_rtx ();
-      rtx wpat, wpat0, wpat1, wsrc, diff;
+      rtx wpat, wpat0, wpat1, wsrc, target, base, diff;
 
       do
        {
@@ -3805,9 +3806,9 @@ fixup_mova (rtx mova)
                           XEXP (XVECEXP (wsrc, 0, 2), 0), lab,
                           XEXP (wpat1, 0)));
       INSN_CODE (worker) = -1;
-      diff = gen_rtx_MINUS (Pmode, XVECEXP (SET_SRC (PATTERN (mova)), 0, 0),
-                           gen_rtx_LABEL_REF (Pmode, lab));
-      diff = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, diff), UNSPEC_PIC);
+      target = XVECEXP (SET_SRC (PATTERN (mova)), 0, 0);
+      base = gen_rtx_LABEL_REF (Pmode, lab);
+      diff = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, target, base), UNSPEC_SYMOFF);
       SET_SRC (PATTERN (mova)) = gen_rtx_CONST (Pmode, diff);
       INSN_CODE (mova) = -1;
     }
@@ -4379,7 +4380,7 @@ gen_block_redirect (rtx jump, int addr, int need_block)
       rtx scan;
       /* Don't look for the stack pointer as a scratch register,
         it would cause trouble if an interrupt occurred.  */
-      unsigned try = 0x7fff, used;
+      unsigned attempt = 0x7fff, used;
       int jump_left = flag_expensive_optimizations + 1;
 
       /* It is likely that the most recent eligible instruction is wanted for
@@ -4400,7 +4401,7 @@ gen_block_redirect (rtx jump, int addr, int need_block)
              && GET_CODE (PATTERN (scan)) != CLOBBER
              && get_attr_in_delay_slot (scan) == IN_DELAY_SLOT_YES)
            {
-             try &= ~regs_used (PATTERN (scan), 0);
+             attempt &= ~regs_used (PATTERN (scan), 0);
              break;
            }
        }
@@ -4418,9 +4419,9 @@ gen_block_redirect (rtx jump, int addr, int need_block)
              if (code == CALL_INSN)
                used |= regs_used (CALL_INSN_FUNCTION_USAGE (scan), 0);
              dead |= (used >> 16) & ~used;
-             if (dead & try)
+             if (dead & attempt)
                {
-                 dead &= try;
+                 dead &= attempt;
                  break;
                }
              if (code == JUMP_INSN)
@@ -4941,10 +4942,8 @@ sh_reorg (void)
              or pseudo-op.  */
 
          label = gen_label_rtx ();
-         REG_NOTES (link) = gen_rtx_INSN_LIST (REG_LABEL_OPERAND, label,
-                                               REG_NOTES (link));
-         REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL_OPERAND, label,
-                                               REG_NOTES (insn));
+         add_reg_note (link, REG_LABEL_OPERAND, label);
+         add_reg_note (insn, REG_LABEL_OPERAND, label);
          if (rescan)
            {
              scan = link;
@@ -4958,9 +4957,7 @@ sh_reorg (void)
                           && reg_mentioned_p (reg, scan))
                          || ((reg2 = sfunc_uses_reg (scan))
                              && REGNO (reg2) == REGNO (reg))))
-                   REG_NOTES (scan)
-                     = gen_rtx_INSN_LIST (REG_LABEL_OPERAND, label,
-                                          REG_NOTES (scan));
+                   add_reg_note (scan, REG_LABEL_OPERAND, label);
                }
              while (scan != dies);
            }
@@ -5594,16 +5591,16 @@ output_stack_adjust (int size, rtx reg, int epilogue_p,
              if (epilogue_p > 0)
                {
                  int nreg = 0;
-                 if (current_function_return_rtx)
+                 if (crtl->return_rtx)
                    {
                      enum machine_mode mode;
-                     mode = GET_MODE (current_function_return_rtx);
+                     mode = GET_MODE (crtl->return_rtx);
                      if (BASE_RETURN_VALUE_REG (mode) == FIRST_RET_REG)
                        nreg = HARD_REGNO_NREGS (FIRST_RET_REG, mode);
                    }
                  for (i = 0; i < nreg; i++)
                    CLEAR_HARD_REG_BIT (temps, FIRST_RET_REG + i);
-                 if (current_function_calls_eh_return)
+                 if (crtl->calls_eh_return)
                    {
                      CLEAR_HARD_REG_BIT (temps, EH_RETURN_STACKADJ_REGNO);
                      for (i = 0; i <= 3; i++)
@@ -5680,8 +5677,8 @@ output_stack_adjust (int size, rtx reg, int epilogue_p,
              mem = gen_tmp_stack_mem (Pmode, gen_rtx_POST_INC (Pmode, reg));
              emit_move_insn (tmp_reg, mem);
              /* Tell flow the insns that pop r4/r5 aren't dead.  */
-             emit_insn (gen_rtx_USE (VOIDmode, tmp_reg));
-             emit_insn (gen_rtx_USE (VOIDmode, adj_reg));
+             emit_use (tmp_reg);
+             emit_use (adj_reg);
              return;
            }
          const_reg = gen_rtx_REG (GET_MODE (reg), temp);
@@ -5935,9 +5932,9 @@ calc_live_regs (HARD_REG_SET *live_regs_mask)
   /* Force PR to be live if the prologue has to call the SHmedia
      argument decoder or register saver.  */
   if (TARGET_SHCOMPACT
-      && ((current_function_args_info.call_cookie
+      && ((crtl->args.info.call_cookie
           & ~ CALL_COOKIE_RET_TRAMP (1))
-         || current_function_saves_all_registers))
+         || crtl->saves_all_registers))
     pr_live = 1;
   has_call = TARGET_SHMEDIA ? ! leaf_function_p () : pr_live;
   for (count = 0, reg = FIRST_PSEUDO_REGISTER; reg-- != 0; )
@@ -5962,12 +5959,12 @@ calc_live_regs (HARD_REG_SET *live_regs_mask)
          : (/* Only push those regs which are used and need to be saved.  */
             (TARGET_SHCOMPACT
              && flag_pic
-             && current_function_args_info.call_cookie
+             && crtl->args.info.call_cookie
              && reg == PIC_OFFSET_TABLE_REGNUM)
             || (df_regs_ever_live_p (reg)
                 && (!call_really_used_regs[reg]
                     || (trapa_handler && reg == FPSCR_REG && TARGET_FPU_ANY)))
-            || (current_function_calls_eh_return
+            || (crtl->calls_eh_return
                 && (reg == EH_RETURN_DATA_REGNO (0)
                     || reg == EH_RETURN_DATA_REGNO (1)
                     || reg == EH_RETURN_DATA_REGNO (2)
@@ -6117,7 +6114,7 @@ sh5_schedule_saves (HARD_REG_SET *live_regs_mask, save_schedule *schedule,
          && ! FUNCTION_ARG_REGNO_P (i)
          && i != FIRST_RET_REG
          && ! (cfun->static_chain_decl != NULL && i == STATIC_CHAIN_REGNUM)
-         && ! (current_function_calls_eh_return
+         && ! (crtl->calls_eh_return
                && (i == EH_RETURN_STACKADJ_REGNO
                    || ((unsigned) i >= EH_RETURN_DATA_REGNO (0)
                        && (unsigned) i <= EH_RETURN_DATA_REGNO (3)))))
@@ -6210,16 +6207,16 @@ sh_expand_prologue (void)
 
   /* We have pretend args if we had an object sent partially in registers
      and partially on the stack, e.g. a large structure.  */
-  pretend_args = current_function_pretend_args_size;
+  pretend_args = crtl->args.pretend_args_size;
   if (TARGET_VARARGS_PRETEND_ARGS (current_function_decl)
       && (NPARM_REGS(SImode)
-         > current_function_args_info.arg_count[(int) SH_ARG_INT]))
+         > crtl->args.info.arg_count[(int) SH_ARG_INT]))
     pretend_args = 0;
   output_stack_adjust (-pretend_args
-                      - current_function_args_info.stack_regs * 8,
+                      - crtl->args.info.stack_regs * 8,
                       stack_pointer_rtx, 0, NULL);
 
-  if (TARGET_SHCOMPACT && flag_pic && current_function_args_info.call_cookie)
+  if (TARGET_SHCOMPACT && flag_pic && crtl->args.info.call_cookie)
     /* We're going to use the PIC register to load the address of the
        incoming-argument decoder and/or of the return trampoline from
        the GOT, so make sure the PIC register is preserved and
@@ -6227,7 +6224,7 @@ sh_expand_prologue (void)
     df_set_regs_ever_live (PIC_OFFSET_TABLE_REGNUM, true);
 
   if (TARGET_SHCOMPACT
-      && (current_function_args_info.call_cookie & ~ CALL_COOKIE_RET_TRAMP(1)))
+      && (crtl->args.info.call_cookie & ~ CALL_COOKIE_RET_TRAMP(1)))
     {
       int reg;
 
@@ -6235,20 +6232,20 @@ sh_expand_prologue (void)
         be pushed onto the stack live, so that register renaming
         doesn't overwrite them.  */
       for (reg = 0; reg < NPARM_REGS (SImode); reg++)
-       if (CALL_COOKIE_STACKSEQ_GET (current_function_args_info.call_cookie)
+       if (CALL_COOKIE_STACKSEQ_GET (crtl->args.info.call_cookie)
            >= NPARM_REGS (SImode) - reg)
          for (; reg < NPARM_REGS (SImode); reg++)
            emit_insn (gen_shcompact_preserve_incoming_args
                       (gen_rtx_REG (SImode, FIRST_PARM_REG + reg)));
        else if (CALL_COOKIE_INT_REG_GET
-                (current_function_args_info.call_cookie, reg) == 1)
+                (crtl->args.info.call_cookie, reg) == 1)
          emit_insn (gen_shcompact_preserve_incoming_args
                     (gen_rtx_REG (SImode, FIRST_PARM_REG + reg)));
 
       emit_move_insn (gen_rtx_REG (Pmode, MACL_REG),
                      stack_pointer_rtx);
       emit_move_insn (gen_rtx_REG (SImode, R0_REG),
-                     GEN_INT (current_function_args_info.call_cookie));
+                     GEN_INT (crtl->args.info.call_cookie));
       emit_move_insn (gen_rtx_REG (SImode, MACH_REG),
                      gen_rtx_REG (SImode, R0_REG));
     }
@@ -6262,7 +6259,7 @@ sh_expand_prologue (void)
     }
 
   /* Emit the code for SETUP_VARARGS.  */
-  if (current_function_stdarg)
+  if (cfun->stdarg)
     {
       if (TARGET_VARARGS_PRETEND_ARGS (current_function_decl))
        {
@@ -6273,11 +6270,10 @@ sh_expand_prologue (void)
              rtx insn;
 
              if (i >= (NPARM_REGS(SImode)
-                       - current_function_args_info.arg_count[(int) SH_ARG_INT]
+                       - crtl->args.info.arg_count[(int) SH_ARG_INT]
                        ))
                break;
              insn = push (rn);
-             RTX_FRAME_RELATED_P (insn) = 0;
            }
        }
     }
@@ -6533,7 +6529,7 @@ sh_expand_prologue (void)
     frame_insn (GEN_MOV (hard_frame_pointer_rtx, stack_pointer_rtx));
 
   if (TARGET_SHCOMPACT
-      && (current_function_args_info.call_cookie & ~ CALL_COOKIE_RET_TRAMP(1)))
+      && (crtl->args.info.call_cookie & ~ CALL_COOKIE_RET_TRAMP(1)))
     {
       /* This must NOT go through the PLT, otherwise mach and macl
         may be clobbered.  */
@@ -6802,12 +6798,12 @@ sh_expand_epilogue (bool sibcall_p)
     emit_insn (gen_toggle_sz ());
   target_flags = save_flags;
 
-  output_stack_adjust (current_function_pretend_args_size
+  output_stack_adjust (crtl->args.pretend_args_size
                       + save_size + d_rounding
-                      + current_function_args_info.stack_regs * 8,
+                      + crtl->args.info.stack_regs * 8,
                       stack_pointer_rtx, e, NULL);
 
-  if (current_function_calls_eh_return)
+  if (crtl->calls_eh_return)
     emit_insn (GEN_ADD3 (stack_pointer_rtx, stack_pointer_rtx,
                         EH_RETURN_STACKADJ_RTX));
 
@@ -6820,7 +6816,7 @@ sh_expand_epilogue (bool sibcall_p)
      USE PR_MEDIA_REG, since it will be explicitly copied to TR0_REG
      by the return pattern.  */
   if (TEST_HARD_REG_BIT (live_regs_mask, PR_REG))
-    emit_insn (gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, PR_REG)));
+    emit_use (gen_rtx_REG (SImode, PR_REG));
 }
 
 static int sh_need_epilogue_known = 0;
@@ -6874,7 +6870,7 @@ sh_set_return_address (rtx ra, rtx tmp)
 
       emit_insn (GEN_MOV (rr, ra));
       /* Tell flow the register for return isn't dead.  */
-      emit_insn (gen_rtx_USE (VOIDmode, rr));
+      emit_use (rr);
       return;
     }
 
@@ -6921,11 +6917,11 @@ static rtx
 sh_builtin_saveregs (void)
 {
   /* First unnamed integer register.  */
-  int first_intreg = current_function_args_info.arg_count[(int) SH_ARG_INT];
+  int first_intreg = crtl->args.info.arg_count[(int) SH_ARG_INT];
   /* Number of integer registers we need to save.  */
   int n_intregs = MAX (0, NPARM_REGS (SImode) - first_intreg);
   /* First unnamed SFmode float reg */
-  int first_floatreg = current_function_args_info.arg_count[(int) SH_ARG_FLOAT];
+  int first_floatreg = crtl->args.info.arg_count[(int) SH_ARG_FLOAT];
   /* Number of SFmode float regs to save.  */
   int n_floatregs = MAX (0, NPARM_REGS (SFmode) - first_floatreg);
   rtx regbuf, fpregs;
@@ -6940,25 +6936,25 @@ sh_builtin_saveregs (void)
 
          while (pushregs < NPARM_REGS (SImode) - 1
                 && (CALL_COOKIE_INT_REG_GET
-                       (current_function_args_info.call_cookie,
+                       (crtl->args.info.call_cookie,
                         NPARM_REGS (SImode) - pushregs)
                     == 1))
            {
-             current_function_args_info.call_cookie
+             crtl->args.info.call_cookie
                &= ~ CALL_COOKIE_INT_REG (NPARM_REGS (SImode)
                                          - pushregs, 1);
              pushregs++;
            }
 
          if (pushregs == NPARM_REGS (SImode))
-           current_function_args_info.call_cookie
+           crtl->args.info.call_cookie
              |= (CALL_COOKIE_INT_REG (0, 1)
                  | CALL_COOKIE_STACKSEQ (pushregs - 1));
          else
-           current_function_args_info.call_cookie
+           crtl->args.info.call_cookie
              |= CALL_COOKIE_STACKSEQ (pushregs);
 
-         current_function_pretend_args_size += 8 * n_intregs;
+         crtl->args.pretend_args_size += 8 * n_intregs;
        }
       if (TARGET_SHCOMPACT)
        return const0_rtx;
@@ -7152,38 +7148,38 @@ sh_va_start (tree valist, rtx nextarg)
   /* Call __builtin_saveregs.  */
   u = make_tree (sizetype, expand_builtin_saveregs ());
   u = fold_convert (ptr_type_node, u);
-  t = build2 (GIMPLE_MODIFY_STMT, ptr_type_node, next_fp, u);
+  t = build2 (MODIFY_EXPR, ptr_type_node, next_fp, u);
   TREE_SIDE_EFFECTS (t) = 1;
   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
 
-  nfp = current_function_args_info.arg_count[SH_ARG_FLOAT];
+  nfp = crtl->args.info.arg_count[SH_ARG_FLOAT];
   if (nfp < 8)
     nfp = 8 - nfp;
   else
     nfp = 0;
   u = fold_build2 (POINTER_PLUS_EXPR, ptr_type_node, u,
                   size_int (UNITS_PER_WORD * nfp));
-  t = build2 (GIMPLE_MODIFY_STMT, ptr_type_node, next_fp_limit, u);
+  t = build2 (MODIFY_EXPR, ptr_type_node, next_fp_limit, u);
   TREE_SIDE_EFFECTS (t) = 1;
   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
 
-  t = build2 (GIMPLE_MODIFY_STMT, ptr_type_node, next_o, u);
+  t = build2 (MODIFY_EXPR, ptr_type_node, next_o, u);
   TREE_SIDE_EFFECTS (t) = 1;
   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
 
-  nint = current_function_args_info.arg_count[SH_ARG_INT];
+  nint = crtl->args.info.arg_count[SH_ARG_INT];
   if (nint < 4)
     nint = 4 - nint;
   else
     nint = 0;
   u = fold_build2 (POINTER_PLUS_EXPR, ptr_type_node, u,
                   size_int (UNITS_PER_WORD * nint));
-  t = build2 (GIMPLE_MODIFY_STMT, ptr_type_node, next_o_limit, u);
+  t = build2 (MODIFY_EXPR, ptr_type_node, next_o_limit, u);
   TREE_SIDE_EFFECTS (t) = 1;
   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
 
   u = make_tree (ptr_type_node, nextarg);
-  t = build2 (GIMPLE_MODIFY_STMT, ptr_type_node, next_stack, u);
+  t = build2 (MODIFY_EXPR, ptr_type_node, next_stack, u);
   TREE_SIDE_EFFECTS (t) = 1;
   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
 }
@@ -7212,8 +7208,8 @@ find_sole_member (tree type)
 /* Implement `va_arg'.  */
 
 static tree
-sh_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p,
-                        tree *post_p ATTRIBUTE_UNUSED)
+sh_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
+                        gimple_seq *post_p ATTRIBUTE_UNUSED)
 {
   HOST_WIDE_INT size, rsize;
   tree tmp, pptr_type_node;
@@ -7302,20 +7298,19 @@ sh_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p,
          tree cmp;
          bool is_double = size == 8 && TREE_CODE (eff_type) == REAL_TYPE;
 
-         tmp = build1 (ADDR_EXPR, pptr_type_node, next_fp);
-         tmp = build2 (GIMPLE_MODIFY_STMT, void_type_node, addr, tmp);
-         gimplify_and_add (tmp, pre_p);
+         tmp = build1 (ADDR_EXPR, pptr_type_node, unshare_expr (next_fp));
+         gimplify_assign (unshare_expr (addr), tmp, pre_p);
 
-         tmp = build2 (GIMPLE_MODIFY_STMT, ptr_type_node, next_fp_tmp, valist);
-         gimplify_and_add (tmp, pre_p);
+         gimplify_assign (unshare_expr (next_fp_tmp), valist, pre_p);
          tmp = next_fp_limit;
          if (size > 4 && !is_double)
-           tmp = build2 (POINTER_PLUS_EXPR, TREE_TYPE (tmp), tmp,
-                         size_int (4 - size));
-         tmp = build2 (GE_EXPR, boolean_type_node, next_fp_tmp, tmp);
+           tmp = build2 (POINTER_PLUS_EXPR, TREE_TYPE (tmp),
+                         unshare_expr (tmp), size_int (4 - size));
+         tmp = build2 (GE_EXPR, boolean_type_node,
+                       unshare_expr (next_fp_tmp), unshare_expr (tmp));
          cmp = build3 (COND_EXPR, void_type_node, tmp,
-                       build1 (GOTO_EXPR, void_type_node, lab_false),
-                       NULL_TREE);
+                       build1 (GOTO_EXPR, void_type_node,
+                               unshare_expr (lab_false)), NULL_TREE);
          if (!is_double)
            gimplify_and_add (cmp, pre_p);
 
@@ -7326,10 +7321,8 @@ sh_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p,
              tmp = build2 (BIT_AND_EXPR, sizetype, tmp,
                            size_int (UNITS_PER_WORD));
              tmp = build2 (POINTER_PLUS_EXPR, ptr_type_node,
-                           next_fp_tmp, tmp);
-             tmp = build2 (GIMPLE_MODIFY_STMT, ptr_type_node,
-                           next_fp_tmp, tmp);
-             gimplify_and_add (tmp, pre_p);
+                           unshare_expr (next_fp_tmp), tmp);
+             gimplify_assign (unshare_expr (next_fp_tmp), tmp, pre_p);
            }
          if (is_double)
            gimplify_and_add (cmp, pre_p);
@@ -7349,62 +7342,60 @@ sh_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p,
                = std_gimplify_va_arg_expr (next_fp_tmp, subtype, pre_p, NULL);
              real = get_initialized_tmp_var (real, pre_p, NULL);
 
-             result = build2 (COMPLEX_EXPR, type, real, imag);
+             result = build2 (COMPLEX_EXPR, eff_type, real, imag);
+             if (type != eff_type)
+               result = build1 (VIEW_CONVERT_EXPR, type, result);
              result = get_initialized_tmp_var (result, pre_p, NULL);
            }
 #endif /* FUNCTION_ARG_SCmode_WART */
 
-         tmp = build1 (GOTO_EXPR, void_type_node, lab_over);
+         tmp = build1 (GOTO_EXPR, void_type_node, unshare_expr (lab_over));
          gimplify_and_add (tmp, pre_p);
 
-         tmp = build1 (LABEL_EXPR, void_type_node, lab_false);
+         tmp = build1 (LABEL_EXPR, void_type_node, unshare_expr (lab_false));
          gimplify_and_add (tmp, pre_p);
 
-         tmp = build1 (ADDR_EXPR, pptr_type_node, next_stack);
-         tmp = build2 (GIMPLE_MODIFY_STMT, void_type_node, addr, tmp);
-         gimplify_and_add (tmp, pre_p);
-         tmp = build2 (GIMPLE_MODIFY_STMT, ptr_type_node, next_fp_tmp, valist);
-         gimplify_and_add (tmp, pre_p);
+         tmp = build1 (ADDR_EXPR, pptr_type_node, unshare_expr (next_stack));
+         gimplify_assign (unshare_expr (addr), tmp, pre_p);
+         gimplify_assign (unshare_expr (next_fp_tmp),
+                          unshare_expr (valist), pre_p);
 
-         tmp = build2 (GIMPLE_MODIFY_STMT, ptr_type_node, valist, next_fp_tmp);
-         gimplify_and_add (tmp, post_p);
+         gimplify_assign (unshare_expr (valist),
+                          unshare_expr (next_fp_tmp), post_p);
          valist = next_fp_tmp;
        }
       else
        {
-         tmp = build2 (POINTER_PLUS_EXPR, ptr_type_node, next_o,
-                       size_int (rsize));
-         tmp = build2 (GT_EXPR, boolean_type_node, tmp, next_o_limit);
+         tmp = build2 (POINTER_PLUS_EXPR, ptr_type_node,
+                       unshare_expr (next_o), size_int (rsize));
+         tmp = build2 (GT_EXPR, boolean_type_node, tmp,
+                       unshare_expr (next_o_limit));
          tmp = build3 (COND_EXPR, void_type_node, tmp,
-                       build1 (GOTO_EXPR, void_type_node, lab_false),
-                       NULL_TREE);
+                       build1 (GOTO_EXPR, void_type_node,
+                               unshare_expr (lab_false)),
+                       NULL_TREE);
          gimplify_and_add (tmp, pre_p);
 
-         tmp = build1 (ADDR_EXPR, pptr_type_node, next_o);
-         tmp = build2 (GIMPLE_MODIFY_STMT, void_type_node, addr, tmp);
-         gimplify_and_add (tmp, pre_p);
+         tmp = build1 (ADDR_EXPR, pptr_type_node, unshare_expr (next_o));
+         gimplify_assign (unshare_expr (addr), tmp, pre_p);
 
-         tmp = build1 (GOTO_EXPR, void_type_node, lab_over);
+         tmp = build1 (GOTO_EXPR, void_type_node, unshare_expr (lab_over));
          gimplify_and_add (tmp, pre_p);
 
-         tmp = build1 (LABEL_EXPR, void_type_node, lab_false);
+         tmp = build1 (LABEL_EXPR, void_type_node, unshare_expr (lab_false));
          gimplify_and_add (tmp, pre_p);
 
          if (size > 4 && ! (TARGET_SH4 || TARGET_SH2A))
-           {
-             tmp = build2 (GIMPLE_MODIFY_STMT, ptr_type_node,
-                           next_o, next_o_limit);
-             gimplify_and_add (tmp, pre_p);
-           }
+           gimplify_assign (unshare_expr (next_o),
+                            unshare_expr (next_o_limit), pre_p);
 
-         tmp = build1 (ADDR_EXPR, pptr_type_node, next_stack);
-         tmp = build2 (GIMPLE_MODIFY_STMT, void_type_node, addr, tmp);
-         gimplify_and_add (tmp, pre_p);
+         tmp = build1 (ADDR_EXPR, pptr_type_node, unshare_expr (next_stack));
+         gimplify_assign (unshare_expr (addr), tmp, pre_p);
        }
 
       if (!result)
        {
-         tmp = build1 (LABEL_EXPR, void_type_node, lab_over);
+         tmp = build1 (LABEL_EXPR, void_type_node, unshare_expr (lab_over));
          gimplify_and_add (tmp, pre_p);
        }
     }
@@ -7415,10 +7406,9 @@ sh_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p,
   tmp = std_gimplify_va_arg_expr (valist, type, pre_p, NULL);
   if (result)
     {
-      tmp = build2 (GIMPLE_MODIFY_STMT, void_type_node, result, tmp);
-      gimplify_and_add (tmp, pre_p);
+      gimplify_assign (result, tmp, pre_p);
 
-      tmp = build1 (LABEL_EXPR, void_type_node, lab_over);
+      tmp = build1 (LABEL_EXPR, void_type_node, unshare_expr (lab_over));
       gimplify_and_add (tmp, pre_p);
     }
   else
@@ -7821,7 +7811,7 @@ sh_setup_incoming_varargs (CUMULATIVE_ARGS *ca,
                           int *pretend_arg_size,
                           int second_time ATTRIBUTE_UNUSED)
 {
-  gcc_assert (current_function_stdarg);
+  gcc_assert (cfun->stdarg);
   if (TARGET_VARARGS_PRETEND_ARGS (current_function_decl))
     {
       int named_parm_regs, anon_parm_regs;
@@ -7885,11 +7875,11 @@ initial_elimination_offset (int from, int to)
 
   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
     return total_saved_regs_space + total_auto_space
-      + current_function_args_info.byref_regs * 8;
+      + crtl->args.info.byref_regs * 8;
 
   if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
     return total_saved_regs_space + total_auto_space
-      + current_function_args_info.byref_regs * 8;
+      + crtl->args.info.byref_regs * 8;
 
   /* Initial gap between fp and sp is 0.  */
   if (from == HARD_FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
@@ -7931,6 +7921,68 @@ initial_elimination_offset (int from, int to)
   else
     return total_auto_space;
 }
+
+/* Parse the -mfixed-range= option string.  */
+void
+sh_fix_range (const char *const_str)
+{
+  int i, first, last;
+  char *str, *dash, *comma;
+  
+  /* str must be of the form REG1'-'REG2{,REG1'-'REG} where REG1 and
+     REG2 are either register names or register numbers.  The effect
+     of this option is to mark the registers in the range from REG1 to
+     REG2 as ``fixed'' so they won't be used by the compiler.  */
+  
+  i = strlen (const_str);
+  str = (char *) alloca (i + 1);
+  memcpy (str, const_str, i + 1);
+  
+  while (1)
+    {
+      dash = strchr (str, '-');
+      if (!dash)
+       {
+         warning (0, "value of -mfixed-range must have form REG1-REG2");
+         return;
+       }
+      *dash = '\0';
+      comma = strchr (dash + 1, ',');
+      if (comma)
+       *comma = '\0';
+      
+      first = decode_reg_name (str);
+      if (first < 0)
+       {
+         warning (0, "unknown register name: %s", str);
+         return;
+       }
+      
+      last = decode_reg_name (dash + 1);
+      if (last < 0)
+       {
+         warning (0, "unknown register name: %s", dash + 1);
+         return;
+       }
+      
+      *dash = '-';
+      
+      if (first > last)
+       {
+         warning (0, "%s-%s is an empty range", str, dash + 1);
+         return;
+       }
+      
+      for (i = first; i <= last; ++i)
+       fixed_regs[i] = call_used_regs[i] = 1;
+
+      if (!comma)
+       break;
+
+      *comma = ',';
+      str = comma + 1;
+    }
+}
 \f
 /* Insert any deferred function attributes from earlier pragmas.  */
 static void
@@ -8684,14 +8736,14 @@ sh_insn_length_adjustment (rtx insn)
     {
       int sum = 0;
       rtx body = PATTERN (insn);
-      const char *template;
+      const char *templ;
       char c;
       int maybe_label = 1;
 
       if (GET_CODE (body) == ASM_INPUT)
-       template = XSTR (body, 0);
+       templ = XSTR (body, 0);
       else if (asm_noperands (body) >= 0)
-       template
+       templ
          = decode_asm_operands (body, NULL, NULL, NULL, NULL, NULL);
       else
        return 0;
@@ -8700,20 +8752,20 @@ sh_insn_length_adjustment (rtx insn)
          int ppi_adjust = 0;
 
          do
-           c = *template++;
+           c = *templ++;
          while (c == ' ' || c == '\t');
          /* all sh-dsp parallel-processing insns start with p.
             The only non-ppi sh insn starting with p is pref.
             The only ppi starting with pr is prnd.  */
-         if ((c == 'p' || c == 'P') && strncasecmp ("re", template, 2))
+         if ((c == 'p' || c == 'P') && strncasecmp ("re", templ, 2))
            ppi_adjust = 2;
          /* The repeat pseudo-insn expands two three insns, a total of
             six bytes in size.  */
          else if ((c == 'r' || c == 'R')
-                  && ! strncasecmp ("epeat", template, 5))
+                  && ! strncasecmp ("epeat", templ, 5))
            ppi_adjust = 4;
          while (c && c != '\n'
-                && ! IS_ASM_LOGICAL_LINE_SEPARATOR (c, template))
+                && ! IS_ASM_LOGICAL_LINE_SEPARATOR (c, templ))
            {
              /* If this is a label, it is obviously not a ppi insn.  */
              if (c == ':' && maybe_label)
@@ -8723,7 +8775,7 @@ sh_insn_length_adjustment (rtx insn)
                }
              else if (c == '\'' || c == '"')
                maybe_label = 0;
-             c = *template++;
+             c = *templ++;
            }
          sum += ppi_adjust;
          maybe_label = c != ':';
@@ -8758,7 +8810,9 @@ nonpic_symbol_mentioned_p (rtx x)
          || XINT (x, 1) == UNSPEC_GOTPLT
          || XINT (x, 1) == UNSPEC_GOTTPOFF
          || XINT (x, 1) == UNSPEC_DTPOFF
-         || XINT (x, 1) == UNSPEC_PLT))
+         || XINT (x, 1) == UNSPEC_PLT
+         || XINT (x, 1) == UNSPEC_SYMOFF
+         || XINT (x, 1) == UNSPEC_PCREL_SYMOFF))
     return 0;
 
   fmt = GET_RTX_FORMAT (GET_CODE (x));
@@ -9171,9 +9225,9 @@ sh_allocate_initial_value (rtx hard_reg)
       if (current_function_is_leaf
          && ! sh_pr_n_sets ()
          && ! (TARGET_SHCOMPACT
-               && ((current_function_args_info.call_cookie
+               && ((crtl->args.info.call_cookie
                     & ~ CALL_COOKIE_RET_TRAMP (1))
-                   || current_function_saves_all_registers)))
+                   || crtl->saves_all_registers)))
        x = hard_reg;
       else
        x = gen_frame_mem (Pmode, return_address_pointer_rtx);
@@ -9770,7 +9824,7 @@ sh_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
 {
   return (1
          && (! TARGET_SHCOMPACT
-             || current_function_args_info.stack_regs == 0)
+             || crtl->args.info.stack_regs == 0)
          && ! sh_cfun_interrupt_handler_p ()
          && (! flag_pic
              || (decl && ! TREE_PUBLIC (decl))
@@ -10139,28 +10193,130 @@ sh_expand_binop_v2sf (enum rtx_code code, rtx op0, rtx op1, rtx op2)
   emit_insn (gen_binary_sf_op1 (op0, op1, op2, op));
 }
 
+/* Return true if hard register REGNO can hold a value of machine-mode MODE.
+   We can allow any mode in any general register.  The special registers
+   only allow SImode.  Don't allow any mode in the PR.
+
+   We cannot hold DCmode values in the XD registers because alter_reg
+   handles subregs of them incorrectly.  We could work around this by
+   spacing the XD registers like the DR registers, but this would require
+   additional memory in every compilation to hold larger register vectors.
+   We could hold SFmode / SCmode values in XD registers, but that
+   would require a tertiary reload when reloading from / to memory,
+   and a secondary reload to reload from / to general regs; that
+   seems to be a loosing proposition.
+
+   We want to allow TImode FP regs so that when V4SFmode is loaded as TImode,
+   it won't be ferried through GP registers first.  */
+
+bool
+sh_hard_regno_mode_ok (unsigned int regno, enum machine_mode mode)
+{
+  if (SPECIAL_REGISTER_P (regno))
+    return mode == SImode;
+
+  if (regno == FPUL_REG)
+    return (mode == SImode || mode == SFmode);
+
+  if (FP_REGISTER_P (regno) && mode == SFmode)
+    return true;
+
+  if (mode == V2SFmode)
+    {
+      if (((FP_REGISTER_P (regno) && (regno - FIRST_FP_REG) % 2 == 0)
+          || GENERAL_REGISTER_P (regno)))
+       return true;
+      else
+       return false;
+    }
+
+  if (mode == V4SFmode)
+    {
+      if ((FP_REGISTER_P (regno) && (regno - FIRST_FP_REG) % 4 == 0)
+         || GENERAL_REGISTER_P (regno))
+       return true;
+      else
+       return false;
+    }
+
+  if (mode == V16SFmode)
+    {
+      if (TARGET_SHMEDIA)
+       {
+         if (FP_REGISTER_P (regno) && (regno - FIRST_FP_REG) % 16 == 0)
+           return true;
+         else
+           return false;
+       }
+      else
+       return regno == FIRST_XD_REG;
+    }
+
+  if (FP_REGISTER_P (regno))
+    {
+      if (mode == SFmode
+         || mode == SImode
+         || ((TARGET_SH2E || TARGET_SHMEDIA) && mode == SCmode)
+         || ((((TARGET_SH4 || TARGET_SH2A_DOUBLE) && mode == DFmode)
+              || mode == DCmode
+              || (TARGET_SHMEDIA
+                  && (mode == DFmode || mode == DImode
+                      || mode == V2SFmode || mode == TImode)))
+             && ((regno - FIRST_FP_REG) & 1) == 0)
+         || ((TARGET_SH4 || TARGET_SHMEDIA) && mode == TImode
+             && ((regno - FIRST_FP_REG) & 3) == 0))
+       return true;
+      else
+       return false;
+    }
+
+  if (XD_REGISTER_P (regno))
+    return mode == DFmode;
+
+  if (TARGET_REGISTER_P (regno))
+    return (mode == DImode || mode == SImode || mode == PDImode);
+
+  if (regno == PR_REG)
+    return mode == SImode;
+
+  if (regno == FPSCR_REG)
+    return mode == PSImode;
+
+  /* FIXME.  This works around PR target/37633 for -O0.  */
+  if (!optimize && TARGET_SHMEDIA32 && GET_MODE_SIZE (mode) > 4)
+    {
+      unsigned int n = GET_MODE_SIZE (mode) / 8;
+
+      if (regno >= FIRST_GENERAL_REG + 10 - n + 1
+         && regno <= FIRST_GENERAL_REG + 14)
+       return false;
+    }
+
+  return true;
+}
+
 /* Return the class of registers for which a mode change from FROM to TO
    is invalid.  */
 bool
 sh_cannot_change_mode_class (enum machine_mode from, enum machine_mode to,
-                            enum reg_class class)
+                            enum reg_class rclass)
 {
   /* We want to enable the use of SUBREGs as a means to
      VEC_SELECT a single element of a vector.  */
   if (to == SFmode && VECTOR_MODE_P (from) && GET_MODE_INNER (from) == SFmode)
-    return (reg_classes_intersect_p (GENERAL_REGS, class));
+    return (reg_classes_intersect_p (GENERAL_REGS, rclass));
 
   if (GET_MODE_SIZE (from) != GET_MODE_SIZE (to))
     {
       if (TARGET_LITTLE_ENDIAN)
        {
          if (GET_MODE_SIZE (to) < 8 || GET_MODE_SIZE (from) < 8)
-           return reg_classes_intersect_p (DF_REGS, class);
+           return reg_classes_intersect_p (DF_REGS, rclass);
        }
       else
        {
          if (GET_MODE_SIZE (from) < 8)
-           return reg_classes_intersect_p (DF_HI_REGS, class);
+           return reg_classes_intersect_p (DF_HI_REGS, rclass);
        }
     }
   return 0;
@@ -10280,7 +10436,7 @@ sh_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
 {
   CUMULATIVE_ARGS cum;
   int structure_value_byref = 0;
-  rtx this, this_value, sibcall, insns, funexp;
+  rtx this_rtx, this_value, sibcall, insns, funexp;
   tree funtype = TREE_TYPE (function);
   int simple_add = CONST_OK_FOR_ADD (delta);
   int did_load = 0;
@@ -10308,7 +10464,7 @@ sh_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
 
       FUNCTION_ARG_ADVANCE (cum, Pmode, ptype, 1);
     }
-  this = FUNCTION_ARG (cum, Pmode, ptr_type_node, 1);
+  this_rtx = FUNCTION_ARG (cum, Pmode, ptr_type_node, 1);
 
   /* For SHcompact, we only have r0 for a scratch register: r1 is the
      static chain pointer (even if you can't have nested virtual functions
@@ -10349,7 +10505,7 @@ sh_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
        error ("Need a call-clobbered target register");
     }
 
-  this_value = plus_constant (this, delta);
+  this_value = plus_constant (this_rtx, delta);
   if (vcall_offset
       && (simple_add || scratch0 != scratch1)
       && strict_memory_address_p (ptr_mode, this_value))
@@ -10361,11 +10517,11 @@ sh_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
   if (!delta)
     ; /* Do nothing.  */
   else if (simple_add)
-    emit_move_insn (this, this_value);
+    emit_move_insn (this_rtx, this_value);
   else
     {
       emit_move_insn (scratch1, GEN_INT (delta));
-      emit_insn (gen_add2_insn (this, scratch1));
+      emit_insn (gen_add2_insn (this_rtx, scratch1));
     }
 
   if (vcall_offset)
@@ -10373,7 +10529,7 @@ sh_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
       rtx offset_addr;
 
       if (!did_load)
-       emit_load_ptr (scratch0, this);
+       emit_load_ptr (scratch0, this_rtx);
 
       offset_addr = plus_constant (scratch0, vcall_offset);
       if (strict_memory_address_p (ptr_mode, offset_addr))
@@ -10383,7 +10539,7 @@ sh_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
          /* scratch0 != scratch1, and we have indexed loads.  Get better
             schedule by loading the offset into r1 and using an indexed
             load - then the load of r1 can issue before the load from
-             (this + delta) finishes.  */
+             (this_rtx + delta) finishes.  */
          emit_move_insn (scratch1, GEN_INT (vcall_offset));
          offset_addr = gen_rtx_PLUS (Pmode, scratch0, scratch1);
        }
@@ -10404,7 +10560,7 @@ sh_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
 
       if (Pmode != ptr_mode)
        scratch0 = gen_rtx_TRUNCATE (ptr_mode, scratch0);
-      emit_insn (gen_add2_insn (this, scratch0));
+      emit_insn (gen_add2_insn (this_rtx, scratch0));
     }
 
   /* Generate a tail call to the target function.  */
@@ -10439,7 +10595,7 @@ sh_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
     }
   sibcall = emit_call_insn (sibcall);
   SIBLING_CALL_P (sibcall) = 1;
-  use_reg (&CALL_INSN_FUNCTION_USAGE (sibcall), this);
+  use_reg (&CALL_INSN_FUNCTION_USAGE (sibcall), this_rtx);
   emit_barrier ();
 
   /* Run just enough of rest_of_compilation to do scheduling and get
@@ -10480,7 +10636,7 @@ sh_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
   if (optimize > 0)
     {
       if (! cfun->cfg)
-       init_flow ();
+       init_flow (cfun);
       split_all_insns_noflow ();
     }
 #endif
@@ -10494,6 +10650,7 @@ sh_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
   final_start_function (insns, file, 1);
   final (insns, file, 1);
   final_end_function ();
+  free_after_compilation (cfun);
 
   reload_completed = 0;
   epilogue_completed = 0;
@@ -10566,9 +10723,9 @@ sh_get_pr_initial_val (void)
      PR register on SHcompact, because it might be clobbered by the prologue.
      We check first if that is known to be the case.  */
   if (TARGET_SHCOMPACT
-      && ((current_function_args_info.call_cookie
+      && ((crtl->args.info.call_cookie
           & ~ CALL_COOKIE_RET_TRAMP (1))
-         || current_function_saves_all_registers))
+         || crtl->saves_all_registers))
     return gen_frame_mem (SImode, return_address_pointer_rtx);
 
   /* If we haven't finished rtl generation, there might be a nonlocal label
@@ -10604,9 +10761,12 @@ sh_expand_t_scc (enum rtx_code code, rtx target)
   val = INTVAL (sh_compare_op1);
   if ((code == EQ && val == 1) || (code == NE && val == 0))
     emit_insn (gen_movt (result));
+  else if (TARGET_SH2A && ((code == EQ && val == 0)
+                           || (code == NE && val == 1)))
+    emit_insn (gen_movrt (result));
   else if ((code == EQ && val == 0) || (code == NE && val == 1))
     {
-      emit_insn (gen_rtx_CLOBBER (VOIDmode, result));
+      emit_clobber (result);
       emit_insn (gen_subc (result, result, result));
       emit_insn (gen_addsi3 (result, result, const1_rtx));
     }
@@ -10835,19 +10995,19 @@ replace_n_hard_rtx (rtx x, rtx *replacements, int n_replacements, int modify)
 
   if (GET_CODE (x) == SUBREG)
     {
-      rtx new = replace_n_hard_rtx (SUBREG_REG (x), replacements,
+      rtx new_rtx = replace_n_hard_rtx (SUBREG_REG (x), replacements,
                                    n_replacements, modify);
 
-      if (GET_CODE (new) == CONST_INT)
+      if (GET_CODE (new_rtx) == CONST_INT)
        {
-         x = simplify_subreg (GET_MODE (x), new,
+         x = simplify_subreg (GET_MODE (x), new_rtx,
                               GET_MODE (SUBREG_REG (x)),
                               SUBREG_BYTE (x));
          if (! x)
            abort ();
        }
       else if (modify)
-       SUBREG_REG (x) = new;
+       SUBREG_REG (x) = new_rtx;
 
       return x;
     }
@@ -10895,18 +11055,18 @@ replace_n_hard_rtx (rtx x, rtx *replacements, int n_replacements, int modify)
     }
   else if (GET_CODE (x) == ZERO_EXTEND)
     {
-      rtx new = replace_n_hard_rtx (XEXP (x, 0), replacements,
+      rtx new_rtx = replace_n_hard_rtx (XEXP (x, 0), replacements,
                                    n_replacements, modify);
 
-      if (GET_CODE (new) == CONST_INT)
+      if (GET_CODE (new_rtx) == CONST_INT)
        {
          x = simplify_unary_operation (ZERO_EXTEND, GET_MODE (x),
-                                       new, GET_MODE (XEXP (x, 0)));
+                                       new_rtx, GET_MODE (XEXP (x, 0)));
          if (! x)
            abort ();
        }
       else if (modify)
-       XEXP (x, 0) = new;
+       XEXP (x, 0) = new_rtx;
 
       return x;
     }
@@ -10914,26 +11074,26 @@ replace_n_hard_rtx (rtx x, rtx *replacements, int n_replacements, int modify)
   fmt = GET_RTX_FORMAT (GET_CODE (x));
   for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
     {
-      rtx new;
+      rtx new_rtx;
 
       if (fmt[i] == 'e')
        {
-         new = replace_n_hard_rtx (XEXP (x, i), replacements,
+         new_rtx = replace_n_hard_rtx (XEXP (x, i), replacements,
                                    n_replacements, modify);
-         if (!new)
+         if (!new_rtx)
            return NULL_RTX;
          if (modify)
-           XEXP (x, i) = new;
+           XEXP (x, i) = new_rtx;
        }
       else if (fmt[i] == 'E')
        for (j = XVECLEN (x, i) - 1; j >= 0; j--)
          {
-           new = replace_n_hard_rtx (XVECEXP (x, i, j), replacements,
+           new_rtx = replace_n_hard_rtx (XVECEXP (x, i, j), replacements,
                                      n_replacements, modify);
-         if (!new)
+         if (!new_rtx)
            return NULL_RTX;
            if (modify)
-             XVECEXP (x, i, j) = new;
+             XVECEXP (x, i, j) = new_rtx;
          }
     }
 
@@ -11067,12 +11227,12 @@ shmedia_prepare_call_address (rtx fnaddr, int is_sibcall)
 }
 
 enum reg_class
-sh_secondary_reload (bool in_p, rtx x, enum reg_class class,
+sh_secondary_reload (bool in_p, rtx x, enum reg_class rclass,
                     enum machine_mode mode, secondary_reload_info *sri)
 {
   if (in_p)
     {
-      if (REGCLASS_HAS_FP_REG (class)
+      if (REGCLASS_HAS_FP_REG (rclass)
          && ! TARGET_SHMEDIA
          && immediate_operand ((x), mode)
          && ! ((fp_zero_operand (x) || fp_one_operand (x))
@@ -11092,13 +11252,13 @@ sh_secondary_reload (bool in_p, rtx x, enum reg_class class,
          default:
            abort ();
          }
-      if (class == FPUL_REGS
+      if (rclass == FPUL_REGS
           && ((GET_CODE (x) == REG
                && (REGNO (x) == MACL_REG || REGNO (x) == MACH_REG
                    || REGNO (x) == T_REG))
               || GET_CODE (x) == PLUS))
         return GENERAL_REGS;
-      if (class == FPUL_REGS && immediate_operand (x, mode))
+      if (rclass == FPUL_REGS && immediate_operand (x, mode))
        {
          if (satisfies_constraint_I08 (x) || fp_zero_operand (x))
            return GENERAL_REGS;
@@ -11107,11 +11267,11 @@ sh_secondary_reload (bool in_p, rtx x, enum reg_class class,
          sri->icode = CODE_FOR_reload_insi__i_fpul;
          return NO_REGS;
        }
-      if (class == FPSCR_REGS
+      if (rclass == FPSCR_REGS
           && ((GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
               || (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == PLUS)))
         return GENERAL_REGS;
-      if (REGCLASS_HAS_FP_REG (class)
+      if (REGCLASS_HAS_FP_REG (rclass)
           && TARGET_SHMEDIA
           && immediate_operand (x, mode)
           && x != CONST0_RTX (GET_MODE (x))
@@ -11124,24 +11284,24 @@ sh_secondary_reload (bool in_p, rtx x, enum reg_class class,
                        ? CODE_FOR_reload_inqi : CODE_FOR_reload_inhi);
          return NO_REGS;
        }
-      if (TARGET_SHMEDIA && class == GENERAL_REGS
-          && (GET_CODE (x) == LABEL_REF || PIC_DIRECT_ADDR_P (x)))
+      if (TARGET_SHMEDIA && rclass == GENERAL_REGS
+          && (GET_CODE (x) == LABEL_REF || PIC_ADDR_P (x)))
         return TARGET_REGS;
     } /* end of input-only processing.  */
 
-  if (((REGCLASS_HAS_FP_REG (class)
+  if (((REGCLASS_HAS_FP_REG (rclass)
        && (GET_CODE (x) == REG
            && (GENERAL_OR_AP_REGISTER_P (REGNO (x))
                || (FP_REGISTER_P (REGNO (x)) && mode == SImode
                    && TARGET_FMOVD))))
-       || (REGCLASS_HAS_GENERAL_REG (class)
+       || (REGCLASS_HAS_GENERAL_REG (rclass)
           && GET_CODE (x) == REG
           && FP_REGISTER_P (REGNO (x))))
       && ! TARGET_SHMEDIA
       && (mode == SFmode || mode == SImode))
     return FPUL_REGS;
-  if ((class == FPUL_REGS
-       || (REGCLASS_HAS_FP_REG (class)
+  if ((rclass == FPUL_REGS
+       || (REGCLASS_HAS_FP_REG (rclass)
            && ! TARGET_SHMEDIA && mode == SImode))
       && (GET_CODE (x) == MEM
           || (GET_CODE (x) == REG
@@ -11149,20 +11309,20 @@ sh_secondary_reload (bool in_p, rtx x, enum reg_class class,
                   || REGNO (x) == T_REG
                   || system_reg_operand (x, VOIDmode)))))
     {
-      if (class == FPUL_REGS)
+      if (rclass == FPUL_REGS)
        return GENERAL_REGS;
       return FPUL_REGS;
     }
-  if ((class == TARGET_REGS
-       || (TARGET_SHMEDIA && class == SIBCALL_REGS))
+  if ((rclass == TARGET_REGS
+       || (TARGET_SHMEDIA && rclass == SIBCALL_REGS))
       && !satisfies_constraint_Csy (x)
       && (GET_CODE (x) != REG || ! GENERAL_REGISTER_P (REGNO (x))))
     return GENERAL_REGS;
-  if ((class == MAC_REGS || class == PR_REGS)
+  if ((rclass == MAC_REGS || rclass == PR_REGS)
       && GET_CODE (x) == REG && ! GENERAL_REGISTER_P (REGNO (x))
-      && class != REGNO_REG_CLASS (REGNO (x)))
+      && rclass != REGNO_REG_CLASS (REGNO (x)))
     return GENERAL_REGS;
-  if (class != GENERAL_REGS && GET_CODE (x) == REG
+  if (rclass != GENERAL_REGS && GET_CODE (x) == REG
       && TARGET_REGISTER_P (REGNO (x)))
     return GENERAL_REGS;
   return NO_REGS;