home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / config / sparc / sparc.c < prev    next >
C/C++ Source or Header  |  1996-06-12  |  145KB  |  4,877 lines

  1. /* Subroutines for insn-output.c for Sun SPARC.
  2.    Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
  3.    Contributed by Michael Tiemann (tiemann@cygnus.com)
  4.    64 bit SPARC V9 support by Michael Tiemann, Jim Wilson, and Doug Evans,
  5.    at Cygnus Support.
  6.  
  7. This file is part of GNU CC.
  8.  
  9. GNU CC is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2, or (at your option)
  12. any later version.
  13.  
  14. GNU CC is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with GNU CC; see the file COPYING.  If not, write to
  21. the Free Software Foundation, 59 Temple Place - Suite 330,
  22. Boston, MA 02111-1307, USA.  */
  23.  
  24. #include <stdio.h>
  25. #include "config.h"
  26. #include "tree.h"
  27. #include "rtl.h"
  28. #include "regs.h"
  29. #include "hard-reg-set.h"
  30. #include "real.h"
  31. #include "insn-config.h"
  32. #include "conditions.h"
  33. #include "insn-flags.h"
  34. #include "output.h"
  35. #include "insn-attr.h"
  36. #include "flags.h"
  37. #include "expr.h"
  38. #include "recog.h"
  39.  
  40. #ifdef MACHO_PIC
  41. #include "next/machopic.h"
  42. #endif
  43.  
  44. /* 1 if the caller has placed an "unimp" insn immediately after the call.
  45.    This is used in v8 code when calling a function that returns a structure.
  46.    v9 doesn't have this.  */
  47.  
  48. #define SKIP_CALLERS_UNIMP_P (!TARGET_V9 && current_function_returns_struct)
  49.  
  50. /* Global variables for machine-dependent things.  */
  51.  
  52. /* Says what architecture we're compiling for.  */
  53. enum arch_type sparc_arch_type;
  54.  
  55. /* Size of frame.  Need to know this to emit return insns from leaf procedures.
  56.    ACTUAL_FSIZE is set by compute_frame_size() which is called during the
  57.    reload pass.  This is important as the value is later used in insn
  58.    scheduling (to see what can go in a delay slot).
  59.    APPARENT_FSIZE is the size of the stack less the register save area and less
  60.    the outgoing argument area.  It is used when saving call preserved regs.  */
  61. static int apparent_fsize;
  62. static int actual_fsize;
  63.  
  64. /* Save the operands last given to a compare for use when we
  65.    generate a scc or bcc insn.  */
  66.  
  67. rtx sparc_compare_op0, sparc_compare_op1;
  68.  
  69. /* Count of named arguments (v9 only).
  70.    ??? INIT_CUMULATIVE_ARGS initializes these, and FUNCTION_ARG_ADVANCE
  71.    increments SPARC_ARG_COUNT. They are then used by
  72.    FUNCTION_ARG_CALLEE_COPIES to determine if the argument is really a named
  73.    argument or not.  This hack is necessary because the NAMED argument to the
  74.    FUNCTION_ARG_XXX macros is not what it says it is: it does not include the
  75.    last named argument.  */
  76.  
  77. int sparc_arg_count;
  78. int sparc_n_named_args;
  79.  
  80. /* We may need an epilogue if we spill too many registers.
  81.    If this is non-zero, then we branch here for the epilogue.  */
  82. static rtx leaf_label;
  83.  
  84. #ifdef LEAF_REGISTERS
  85.  
  86. /* Vector to say how input registers are mapped to output
  87.    registers.  FRAME_POINTER_REGNUM cannot be remapped by
  88.    this function to eliminate it.  You must use -fomit-frame-pointer
  89.    to get that.  */
  90. char leaf_reg_remap[] =
  91. { 0, 1, 2, 3, 4, 5, 6, 7,
  92.   -1, -1, -1, -1, -1, -1, 14, -1,
  93.   -1, -1, -1, -1, -1, -1, -1, -1,
  94.   8, 9, 10, 11, 12, 13, -1, 15,
  95.  
  96.   32, 33, 34, 35, 36, 37, 38, 39,
  97.   40, 41, 42, 43, 44, 45, 46, 47,
  98.   48, 49, 50, 51, 52, 53, 54, 55,
  99.   56, 57, 58, 59, 60, 61, 62, 63,
  100.   64, 65, 66, 67, 68, 69, 70, 71,
  101.   72, 73, 74, 75, 76, 77, 78, 79,
  102.   80, 81, 82, 83, 84, 85, 86, 87,
  103.   88, 89, 90, 91, 92, 93, 94, 95,
  104.   96, 97, 98, 99};
  105.  
  106. #endif
  107.  
  108. /* Name of where we pretend to think the frame pointer points.
  109.    Normally, this is "%fp", but if we are in a leaf procedure,
  110.    this is "%sp+something".  We record "something" separately as it may be
  111.    too big for reg+constant addressing.  */
  112.  
  113. static char *frame_base_name;
  114. static int frame_base_offset;
  115.  
  116. static rtx find_addr_reg ();
  117. static void sparc_init_modes ();
  118.  
  119. /* Option handling.  */
  120.  
  121. /* Validate and override various options, and do some machine dependent
  122.    initialization.  */
  123.  
  124. void
  125. sparc_override_options ()
  126. {
  127.   /* Check for any conflicts in the choice of options.  */
  128.   /* ??? This stuff isn't really usable yet.  */
  129.  
  130.   if (! TARGET_V9)
  131.     {
  132.       if (target_flags & MASK_CODE_MODEL)
  133.     error ("code model support is only available with -mv9");
  134.       if (TARGET_INT64)
  135.     error ("-mint64 is only available with -mv9");
  136.       if (TARGET_LONG64)
  137.     error ("-mlong64 is only available with -mv9");
  138.       if (TARGET_PTR64)
  139.     error ("-mptr64 is only available with -mv9");
  140.       if (TARGET_ENV32)
  141.     error ("-menv32 is only available with -mv9");
  142.       if (TARGET_STACK_BIAS)
  143.     error ("-mstack-bias is only available with -mv9");
  144.     }
  145.   else
  146.     {
  147.       /* ??? Are there any options that aren't usable with v9.
  148.      -munaligned-doubles?  */
  149.     }
  150.  
  151.   /* Check for conflicts in cpu specification.
  152.      If we use -mcpu=xxx, this can be removed.  */
  153.  
  154.   if ((TARGET_V8 != 0) + (TARGET_SPARCLITE != 0) + (TARGET_V9 != 0) > 1)
  155.     error ("conflicting architectures defined");
  156.  
  157.   /* Do various machine dependent initializations.  */
  158.   sparc_init_modes ();
  159. }
  160.  
  161. /* Float conversions (v9 only).
  162.  
  163.    The floating point registers cannot hold DImode values because SUBREG's
  164.    on them get the wrong register.   "(subreg:SI (reg:DI M int-reg) 0)" is the
  165.    same as "(subreg:SI (reg:DI N float-reg) 1)", but gcc doesn't know how to
  166.    turn the "0" to a "1".  Therefore, we must explicitly do the conversions
  167.    to/from int/fp regs.  `sparc64_fpconv_stack_slot' is the address of an
  168.    8 byte stack slot used during the transfer.
  169.    ??? I could have used [%fp-16] but I didn't want to add yet another
  170.    dependence on this.  */
  171. /* ??? Can we use assign_stack_temp here?  */
  172.  
  173. static rtx fpconv_stack_temp;
  174.  
  175. /* Called once for each function.  */
  176.  
  177. void
  178. sparc64_init_expanders ()
  179. {
  180.   fpconv_stack_temp = NULL_RTX;
  181. }
  182.  
  183. /* Assign a stack temp for fp/int DImode conversions.  */
  184.  
  185. rtx
  186. sparc64_fpconv_stack_temp ()
  187. {
  188.   if (fpconv_stack_temp == NULL_RTX)
  189.       fpconv_stack_temp =
  190.     assign_stack_local (DImode, GET_MODE_SIZE (DImode), 0);
  191.  
  192.     return fpconv_stack_temp;
  193. }
  194.  
  195. /* Miscellaneous utilities.  */
  196.  
  197. /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
  198.    or branch on register contents instructions.  */
  199.  
  200. int
  201. v9_regcmp_p (code)
  202.      enum rtx_code code;
  203. {
  204.   return (code == EQ || code == NE || code == GE || code == LT
  205.       || code == LE || code == GT);
  206. }
  207.  
  208. /* Operand constraints.  */
  209.  
  210. /* Return non-zero only if OP is a register of mode MODE,
  211.    or const0_rtx.  */
  212. int
  213. reg_or_0_operand (op, mode)
  214.      rtx op;
  215.      enum machine_mode mode;
  216. {
  217.   if (op == const0_rtx || register_operand (op, mode))
  218.     return 1;
  219.   if (GET_MODE (op) == VOIDmode && GET_CODE (op) == CONST_DOUBLE
  220.       && CONST_DOUBLE_HIGH (op) == 0
  221.       && CONST_DOUBLE_LOW (op) == 0)
  222.     return 1;
  223.   if (GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT
  224.       && GET_CODE (op) == CONST_DOUBLE
  225.       && fp_zero_operand (op))
  226.     return 1;
  227.   return 0;
  228. }
  229.  
  230. /* Nonzero if OP is a floating point value with value 0.0.  */
  231. int
  232. fp_zero_operand (op)
  233.      rtx op;
  234. {
  235.   REAL_VALUE_TYPE r;
  236.  
  237.   REAL_VALUE_FROM_CONST_DOUBLE (r, op);
  238.   return REAL_VALUES_EQUAL (r, dconst0);
  239. }
  240.  
  241. /* Nonzero if OP is an integer register.  */
  242.  
  243. int
  244. intreg_operand (op, mode)
  245.      rtx op;
  246.      enum machine_mode mode;
  247. {
  248.   return (register_operand (op, SImode)
  249.       || (TARGET_V9 && register_operand (op, DImode)));
  250. }
  251.  
  252. /* Nonzero if OP is a floating point condition code register.  */
  253.  
  254. int
  255. ccfp_reg_operand (op, mode)
  256.      rtx op;
  257.      enum machine_mode mode;
  258. {
  259.   /* This can happen when recog is called from combine.  Op may be a MEM.
  260.      Fail instead of calling abort in this case.  */
  261.   if (GET_CODE (op) != REG || REGNO (op) == 0)
  262.     return 0;
  263.   if (GET_MODE (op) != mode)
  264.     return 0;
  265.  
  266. #if 0    /* ??? ==> 1 when %fcc1-3 are pseudos first.  See gen_compare_reg().  */
  267.   if (reg_renumber == 0)
  268.     return REGNO (op) >= FIRST_PSEUDO_REGISTER;
  269.   return REGNO_OK_FOR_CCFP_P (REGNO (op));
  270. #else
  271.   return (unsigned) REGNO (op) - 96 < 4;
  272. #endif
  273. }
  274.  
  275. /* Nonzero if OP can appear as the dest of a RESTORE insn.  */
  276. int
  277. restore_operand (op, mode)
  278.      rtx op;
  279.      enum machine_mode mode;
  280. {
  281.   return (GET_CODE (op) == REG && GET_MODE (op) == mode
  282.       && (REGNO (op) < 8 || (REGNO (op) >= 24 && REGNO (op) < 32)));
  283. }
  284.  
  285. /* Call insn on SPARC can take a PC-relative constant address, or any regular
  286.    memory address.  */
  287.  
  288. int
  289. call_operand (op, mode)
  290.      rtx op;
  291.      enum machine_mode mode;
  292. {
  293.   if (GET_CODE (op) != MEM)
  294.     abort ();
  295.   op = XEXP (op, 0);
  296.   return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
  297. }
  298.  
  299. int
  300. call_operand_address (op, mode)
  301.      rtx op;
  302.      enum machine_mode mode;
  303. {
  304.   return (symbolic_operand (op, mode) || memory_address_p (Pmode, op));
  305. }
  306.  
  307. /* Returns 1 if OP is either a symbol reference or a sum of a symbol
  308.    reference and a constant.  */
  309.  
  310. int
  311. symbolic_operand (op, mode)
  312.      register rtx op;
  313.      enum machine_mode mode;
  314. {
  315.   switch (GET_CODE (op))
  316.     {
  317.     case SYMBOL_REF:
  318.     case LABEL_REF:
  319.       return 1;
  320.  
  321.     case CONST:
  322.       op = XEXP (op, 0);
  323.       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
  324.            || GET_CODE (XEXP (op, 0)) == LABEL_REF)
  325.           && GET_CODE (XEXP (op, 1)) == CONST_INT);
  326.  
  327.       /* ??? This clause seems to be irrelevant.  */
  328.     case CONST_DOUBLE:
  329.       return GET_MODE (op) == mode;
  330.  
  331.     default:
  332.       return 0;
  333.     }
  334. }
  335.  
  336. /* Return truth value of statement that OP is a symbolic memory
  337.    operand of mode MODE.  */
  338.  
  339. int
  340. symbolic_memory_operand (op, mode)
  341.      rtx op;
  342.      enum machine_mode mode;
  343. {
  344.   if (GET_CODE (op) == SUBREG)
  345.     op = SUBREG_REG (op);
  346.   if (GET_CODE (op) != MEM)
  347.     return 0;
  348.   op = XEXP (op, 0);
  349.   return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
  350.       || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
  351. }
  352.  
  353. /* Return 1 if the operand is a data segment reference.  This includes
  354.    the readonly data segment, or in other words anything but the text segment.
  355.    This is needed in the medium/anywhere code model on v9.  These values
  356.    are accessed with MEDANY_BASE_REG.  */
  357.  
  358. int
  359. data_segment_operand (op, mode)
  360.      rtx op;
  361.      enum machine_mode mode;
  362. {
  363.   switch (GET_CODE (op))
  364.     {
  365.     case SYMBOL_REF :
  366.       return ! SYMBOL_REF_FLAG (op);
  367.     case PLUS :
  368.       /* Assume canonical format of symbol + constant.  */
  369.     case CONST :
  370.       return data_segment_operand (XEXP (op, 0));
  371.     default :
  372.       return 0;
  373.     }
  374. }
  375.  
  376. /* Return 1 if the operand is a text segment reference.
  377.    This is needed in the medium/anywhere code model on v9.  */
  378.  
  379. int
  380. text_segment_operand (op, mode)
  381.      rtx op;
  382.      enum machine_mode mode;
  383. {
  384.   switch (GET_CODE (op))
  385.     {
  386.     case LABEL_REF :
  387.       return 1;
  388.     case SYMBOL_REF :
  389.       return SYMBOL_REF_FLAG (op);
  390.     case PLUS :
  391.       /* Assume canonical format of symbol + constant.  */
  392.     case CONST :
  393.       return text_segment_operand (XEXP (op, 0));
  394.     default :
  395.       return 0;
  396.     }
  397. }
  398.  
  399. /* Return 1 if the operand is either a register or a memory operand that is
  400.    not symbolic.  */
  401.  
  402. int
  403. reg_or_nonsymb_mem_operand (op, mode)
  404.     register rtx op;
  405.     enum machine_mode mode;
  406. {
  407.   if (register_operand (op, mode))
  408.     return 1;
  409.  
  410.   if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode))
  411.     return 1;
  412.  
  413.   return 0;
  414. }
  415.  
  416. int
  417. sparc_operand (op, mode)
  418.      rtx op;
  419.      enum machine_mode mode;
  420. {
  421.   if (register_operand (op, mode))
  422.     return 1;
  423.   if (GET_CODE (op) == CONST_INT)
  424.     return SMALL_INT (op);
  425.   if (GET_MODE (op) != mode)
  426.     return 0;
  427.   if (GET_CODE (op) == SUBREG)
  428.     op = SUBREG_REG (op);
  429.   if (GET_CODE (op) != MEM)
  430.     return 0;
  431.  
  432.   op = XEXP (op, 0);
  433.   if (GET_CODE (op) == LO_SUM)
  434.     return (GET_CODE (XEXP (op, 0)) == REG
  435.         && symbolic_operand (XEXP (op, 1), Pmode));
  436.   return memory_address_p (mode, op);
  437. }
  438.  
  439. int
  440. move_operand (op, mode)
  441.      rtx op;
  442.      enum machine_mode mode;
  443. {
  444.   if (mode == DImode && arith_double_operand (op, mode))
  445.     return 1;
  446.   if (register_operand (op, mode))
  447.     return 1;
  448.   if (GET_CODE (op) == CONST_INT)
  449.     return (SMALL_INT (op) || (INTVAL (op) & 0x3ff) == 0);
  450.  
  451.   if (GET_MODE (op) != mode)
  452.     return 0;
  453.   if (GET_CODE (op) == SUBREG)
  454.     op = SUBREG_REG (op);
  455.   if (GET_CODE (op) != MEM)
  456.     return 0;
  457.   op = XEXP (op, 0);
  458.   if (GET_CODE (op) == LO_SUM)
  459.     return (register_operand (XEXP (op, 0), Pmode)
  460.         && CONSTANT_P (XEXP (op, 1)));
  461.   return memory_address_p (mode, op);
  462. }
  463.  
  464. int
  465. move_pic_label (op, mode)
  466.      rtx op;
  467.      enum machine_mode mode;
  468. {
  469.   /* Special case for PIC.  */
  470.   if (flag_pic && GET_CODE (op) == LABEL_REF)
  471.     return 1;
  472.   return 0;
  473. }
  474.  
  475. int
  476. splittable_symbolic_memory_operand (op, mode)
  477.      rtx op;
  478.      enum machine_mode mode;
  479. {
  480.   if (GET_CODE (op) != MEM)
  481.     return 0;
  482.   if (! symbolic_operand (XEXP (op, 0), Pmode))
  483.     return 0;
  484.   return 1;
  485. }
  486.  
  487. int
  488. splittable_immediate_memory_operand (op, mode)
  489.      rtx op;
  490.      enum machine_mode mode;
  491. {
  492.   if (GET_CODE (op) != MEM)
  493.     return 0;
  494.   if (! immediate_operand (XEXP (op, 0), Pmode))
  495.     return 0;
  496.   return 1;
  497. }
  498.  
  499. /* Return truth value of whether OP is EQ or NE.  */
  500.  
  501. int
  502. eq_or_neq (op, mode)
  503.      rtx op;
  504.      enum machine_mode mode;
  505. {
  506.   return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
  507. }
  508.  
  509. /* Return 1 if this is a comparison operator, but not an EQ, NE, GEU,
  510.    or LTU for non-floating-point.  We handle those specially.  */
  511.  
  512. int
  513. normal_comp_operator (op, mode)
  514.      rtx op;
  515.      enum machine_mode mode;
  516. {
  517.   enum rtx_code code = GET_CODE (op);
  518.  
  519.   if (GET_RTX_CLASS (code) != '<')
  520.     return 0;
  521.  
  522.   if (GET_MODE (XEXP (op, 0)) == CCFPmode
  523.       || GET_MODE (XEXP (op, 0)) == CCFPEmode)
  524.     return 1;
  525.  
  526.   return (code != NE && code != EQ && code != GEU && code != LTU);
  527. }
  528.  
  529. /* Return 1 if this is a comparison operator.  This allows the use of
  530.    MATCH_OPERATOR to recognize all the branch insns.  */
  531.  
  532. int
  533. noov_compare_op (op, mode)
  534.     register rtx op;
  535.     enum machine_mode mode;
  536. {
  537.   enum rtx_code code = GET_CODE (op);
  538.  
  539.   if (GET_RTX_CLASS (code) != '<')
  540.     return 0;
  541.  
  542.   if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode)
  543.     /* These are the only branches which work with CC_NOOVmode.  */
  544.     return (code == EQ || code == NE || code == GE || code == LT);
  545.   return 1;
  546. }
  547.  
  548. /* Nonzero if OP is a comparison operator suitable for use in v9
  549.    conditional move or branch on register contents instructions.  */
  550.  
  551. int
  552. v9_regcmp_op (op, mode)
  553.      register rtx op;
  554.      enum machine_mode mode;
  555. {
  556.   enum rtx_code code = GET_CODE (op);
  557.  
  558.   if (GET_RTX_CLASS (code) != '<')
  559.     return 0;
  560.  
  561.   return v9_regcmp_p (code);
  562. }
  563.  
  564. /* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation.  */
  565.  
  566. int
  567. extend_op (op, mode)
  568.      rtx op;
  569.      enum machine_mode mode;
  570. {
  571.   return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND;
  572. }
  573.  
  574. /* Return nonzero if OP is an operator of mode MODE which can set
  575.    the condition codes explicitly.  We do not include PLUS and MINUS
  576.    because these require CC_NOOVmode, which we handle explicitly.  */
  577.  
  578. int
  579. cc_arithop (op, mode)
  580.      rtx op;
  581.      enum machine_mode mode;
  582. {
  583.   if (GET_CODE (op) == AND
  584.       || GET_CODE (op) == IOR
  585.       || GET_CODE (op) == XOR)
  586.     return 1;
  587.  
  588.   return 0;
  589. }
  590.  
  591. /* Return nonzero if OP is an operator of mode MODE which can bitwise
  592.    complement its second operand and set the condition codes explicitly.  */
  593.  
  594. int
  595. cc_arithopn (op, mode)
  596.      rtx op;
  597.      enum machine_mode mode;
  598. {
  599.   /* XOR is not here because combine canonicalizes (xor (not ...) ...)
  600.      and (xor ... (not ...)) to (not (xor ...)).   */
  601.   return (GET_CODE (op) == AND
  602.       || GET_CODE (op) == IOR);
  603. }
  604.  
  605. /* Return true if OP is a register, or is a CONST_INT that can fit in a 13
  606.    bit immediate field.  This is an acceptable SImode operand for most 3
  607.    address instructions.  */
  608.  
  609. int
  610. arith_operand (op, mode)
  611.      rtx op;
  612.      enum machine_mode mode;
  613. {
  614.   return (register_operand (op, mode)
  615.       || (GET_CODE (op) == CONST_INT && SMALL_INT (op)));
  616. }
  617.  
  618. /* Return true if OP is a register, or is a CONST_INT that can fit in an 11
  619.    bit immediate field.  This is an acceptable SImode operand for the movcc
  620.    instructions.  */
  621.  
  622. int
  623. arith11_operand (op, mode)
  624.      rtx op;
  625.      enum machine_mode mode;
  626. {
  627.   return (register_operand (op, mode)
  628.       || (GET_CODE (op) == CONST_INT
  629.           && ((unsigned) (INTVAL (op) + 0x400) < 0x800)));
  630. }
  631.  
  632. /* Return true if OP is a register, or is a CONST_INT that can fit in an 10
  633.    bit immediate field.  This is an acceptable SImode operand for the movrcc
  634.    instructions.  */
  635.  
  636. int
  637. arith10_operand (op, mode)
  638.      rtx op;
  639.      enum machine_mode mode;
  640. {
  641.   return (register_operand (op, mode)
  642.       || (GET_CODE (op) == CONST_INT
  643.           && ((unsigned) (INTVAL (op) + 0x200) < 0x400)));
  644. }
  645.  
  646. /* Return true if OP is a register, is a CONST_INT that fits in a 13 bit
  647.    immediate field, or is a CONST_DOUBLE whose both parts fit in a 13 bit
  648.    immediate field.
  649.    v9: Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
  650.    can fit in a 13 bit immediate field.  This is an acceptable DImode operand
  651.    for most 3 address instructions.  */
  652.  
  653. int
  654. arith_double_operand (op, mode)
  655.      rtx op;
  656.      enum machine_mode mode;
  657. {
  658.   return (register_operand (op, mode)
  659.       || (GET_CODE (op) == CONST_INT && SMALL_INT (op))
  660.       || (! TARGET_V9
  661.           && GET_CODE (op) == CONST_DOUBLE
  662.           && (unsigned) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
  663.           && (unsigned) (CONST_DOUBLE_HIGH (op) + 0x1000) < 0x2000)
  664.       || (TARGET_V9
  665.           && GET_CODE (op) == CONST_DOUBLE
  666.           && (unsigned) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000
  667.           && ((CONST_DOUBLE_HIGH (op) == -1
  668.            && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000)
  669.           || (CONST_DOUBLE_HIGH (op) == 0
  670.               && (CONST_DOUBLE_LOW (op) & 0x1000) == 0))));
  671. }
  672.  
  673. /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
  674.    can fit in an 11 bit immediate field.  This is an acceptable DImode
  675.    operand for the movcc instructions.  */
  676. /* ??? Replace with arith11_operand?  */
  677.  
  678. int
  679. arith11_double_operand (op, mode)
  680.      rtx op;
  681.      enum machine_mode mode;
  682. {
  683.   return (register_operand (op, mode)
  684.       || (GET_CODE (op) == CONST_DOUBLE
  685.           && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
  686.           && (unsigned) (CONST_DOUBLE_LOW (op) + 0x400) < 0x800
  687.           && ((CONST_DOUBLE_HIGH (op) == -1
  688.            && (CONST_DOUBLE_LOW (op) & 0x400) == 0x400)
  689.           || (CONST_DOUBLE_HIGH (op) == 0
  690.               && (CONST_DOUBLE_LOW (op) & 0x400) == 0)))
  691.       || (GET_CODE (op) == CONST_INT
  692.           && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
  693.           && (unsigned) (INTVAL (op) + 0x400) < 0x800));
  694. }
  695.  
  696. /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that
  697.    can fit in an 10 bit immediate field.  This is an acceptable DImode
  698.    operand for the movrcc instructions.  */
  699. /* ??? Replace with arith10_operand?  */
  700.  
  701. int
  702. arith10_double_operand (op, mode)
  703.      rtx op;
  704.      enum machine_mode mode;
  705. {
  706.   return (register_operand (op, mode)
  707.       || (GET_CODE (op) == CONST_DOUBLE
  708.           && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
  709.           && (unsigned) (CONST_DOUBLE_LOW (op) + 0x200) < 0x400
  710.           && ((CONST_DOUBLE_HIGH (op) == -1
  711.            && (CONST_DOUBLE_LOW (op) & 0x200) == 0x200)
  712.           || (CONST_DOUBLE_HIGH (op) == 0
  713.               && (CONST_DOUBLE_LOW (op) & 0x200) == 0)))
  714.       || (GET_CODE (op) == CONST_INT
  715.           && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
  716.           && (unsigned) (INTVAL (op) + 0x200) < 0x400));
  717. }
  718.  
  719. /* Return truth value of whether OP is a integer which fits the
  720.    range constraining immediate operands in most three-address insns,
  721.    which have a 13 bit immediate field.  */
  722.  
  723. int
  724. small_int (op, mode)
  725.      rtx op;
  726.      enum machine_mode mode;
  727. {
  728.   return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
  729. }
  730.  
  731. /* Recognize operand values for the umul instruction.  That instruction sign
  732.    extends immediate values just like all other sparc instructions, but
  733.    interprets the extended result as an unsigned number.  */
  734.  
  735. int
  736. uns_small_int (op, mode)
  737.      rtx op;
  738.      enum machine_mode mode;
  739. {
  740. #if HOST_BITS_PER_WIDE_INT > 32
  741.   /* All allowed constants will fit a CONST_INT.  */
  742.   return (GET_CODE (op) == CONST_INT
  743.       && ((INTVAL (op) >= 0 && INTVAL (op) < 0x1000)
  744.           || (INTVAL (op) >= 0xFFFFF000 && INTVAL (op) < 0x100000000L)));
  745. #else
  746.   return ((GET_CODE (op) == CONST_INT && (unsigned) INTVAL (op) < 0x1000)
  747.       || (GET_CODE (op) == CONST_DOUBLE
  748.           && CONST_DOUBLE_HIGH (op) == 0
  749.           && (unsigned) CONST_DOUBLE_LOW (op) - 0xFFFFF000 < 0x1000));
  750. #endif
  751. }
  752.  
  753. int
  754. uns_arith_operand (op, mode)
  755.      rtx op;
  756.      enum machine_mode mode;
  757. {
  758.   return register_operand (op, mode) || uns_small_int (op, mode);
  759. }
  760.  
  761. /* Return truth value of statement that OP is a call-clobbered register.  */
  762. int
  763. clobbered_register (op, mode)
  764.      rtx op;
  765.      enum machine_mode mode;
  766. {
  767.   return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]);
  768. }
  769.  
  770. /* X and Y are two things to compare using CODE.  Emit the compare insn and
  771.    return the rtx for the cc reg in the proper mode.  */
  772.  
  773. rtx
  774. gen_compare_reg (code, x, y)
  775.      enum rtx_code code;
  776.      rtx x, y;
  777. {
  778.   enum machine_mode mode = SELECT_CC_MODE (code, x, y);
  779.   rtx cc_reg;
  780.  
  781.   /* ??? We don't have movcc patterns so we cannot generate pseudo regs for the
  782.      fpcc regs (cse can't tell they're really call clobbered regs and will
  783.      remove a duplicate comparison even if there is an intervening function
  784.      call - it will then try to reload the cc reg via an int reg which is why
  785.      we need the movcc patterns).  It is possible to provide the movcc
  786.      patterns by using the ldxfsr/stxfsr v9 insns.  I tried it: you need two
  787.      registers (say %g1,%g5) and it takes about 6 insns.  A better fix would be
  788.      to tell cse that CCFPE mode registers (even pseudos) are call
  789.      clobbered.  */
  790.  
  791.   /* ??? This is an experiment.  Rather than making changes to cse which may
  792.      or may not be easy/clean, we do our own cse.  This is possible because
  793.      we will generate hard registers.  Cse knows they're call clobbered (it
  794.      doesn't know the same thing about pseudos). If we guess wrong, no big
  795.      deal, but if we win, great!  */
  796.  
  797.   if (TARGET_V9 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
  798. #if 1 /* experiment */
  799.     {
  800.       int reg;
  801.       /* We cycle through the registers to ensure they're all exercised.  */
  802.       static int next_fpcc_reg = 0;
  803.       /* Previous x,y for each fpcc reg.  */
  804.       static rtx prev_args[4][2];
  805.  
  806.       /* Scan prev_args for x,y.  */
  807.       for (reg = 0; reg < 4; reg++)
  808.     if (prev_args[reg][0] == x && prev_args[reg][1] == y)
  809.       break;
  810.       if (reg == 4)
  811.     {
  812.       reg = next_fpcc_reg;
  813.       prev_args[reg][0] = x;
  814.       prev_args[reg][1] = y;
  815.       next_fpcc_reg = (next_fpcc_reg + 1) & 3;
  816.     }
  817.       cc_reg = gen_rtx (REG, mode, reg + 96);
  818.     }
  819. #else
  820.     cc_reg = gen_reg_rtx (mode);
  821. #endif /* ! experiment */
  822.   else
  823.     cc_reg = gen_rtx (REG, mode, 0);
  824.  
  825.   emit_insn (gen_rtx (SET, VOIDmode, cc_reg,
  826.               gen_rtx (COMPARE, mode, x, y)));
  827.  
  828.   return cc_reg;
  829. }
  830.  
  831. /* This function is used for v9 only.
  832.    CODE is the code for an Scc's comparison.
  833.    OPERANDS[0] is the target of the Scc insn.
  834.    OPERANDS[1] is the value we compare against const0_rtx (which hasn't
  835.    been generated yet).
  836.  
  837.    This function is needed to turn
  838.  
  839.        (set (reg:SI 110)
  840.            (gt (reg:CCX 0 %g0)
  841.                (const_int 0)))
  842.    into
  843.        (set (reg:SI 110)
  844.            (gt:DI (reg:CCX 0 %g0)
  845.                (const_int 0)))
  846.  
  847.    IE: The instruction recognizer needs to see the mode of the comparison to
  848.    find the right instruction. We could use "gt:DI" right in the
  849.    define_expand, but leaving it out allows us to handle DI, SI, etc.
  850.  
  851.    We refer to the global sparc compare operands sparc_compare_op0 and
  852.    sparc_compare_op1.  
  853.  
  854.    ??? Some of this is outdated as the scc insns set the mode of the
  855.    comparison now.
  856.  
  857.    ??? We optimize for the case where op1 is 0 and the comparison allows us to
  858.    use the "movrCC" insns. This reduces the generated code from three to two
  859.    insns.  This way seems too brute force though.  Is there a more elegant way
  860.    to achieve the same effect?
  861.  
  862.    Currently, this function always returns 1.  ??? Can it ever fail?  */
  863.  
  864. int
  865. gen_v9_scc (compare_code, operands)
  866.      enum rtx_code compare_code;
  867.      register rtx *operands;
  868. {
  869.   rtx temp;
  870.  
  871.   if (GET_MODE_CLASS (GET_MODE (sparc_compare_op0)) == MODE_INT
  872.       && sparc_compare_op1 == const0_rtx
  873.       && (compare_code == EQ || compare_code == NE
  874.       || compare_code == LT || compare_code == LE
  875.       || compare_code == GT || compare_code == GE))
  876.     {
  877.       /* Special case for op0 != 0.  This can be done with one instruction if
  878.      op0 can be clobbered.  We store to a temp, and then clobber the temp,
  879.      but the combiner will remove the first insn.  */
  880.  
  881.       if (compare_code == NE
  882.       && GET_MODE (operands[0]) == DImode
  883.       && GET_MODE (sparc_compare_op0) == DImode)
  884.     {
  885.       emit_insn (gen_rtx (SET, VOIDmode, operands[0], sparc_compare_op0));
  886.       emit_insn (gen_rtx (SET, VOIDmode, operands[0],
  887.                   gen_rtx (IF_THEN_ELSE, VOIDmode,
  888.                        gen_rtx (compare_code, DImode,
  889.                         sparc_compare_op0, const0_rtx),
  890.                        const1_rtx,
  891.                        operands[0])));
  892.       return 1;
  893.     }
  894.  
  895.       emit_insn (gen_rtx (SET, VOIDmode, operands[0], const0_rtx));
  896.       if (GET_MODE (sparc_compare_op0) != DImode)
  897.     {
  898.       temp = gen_reg_rtx (DImode);
  899.       convert_move (temp, sparc_compare_op0, 0);
  900.     }
  901.       else
  902.     {
  903.       temp = sparc_compare_op0;
  904.     }
  905.       emit_insn (gen_rtx (SET, VOIDmode, operands[0],
  906.               gen_rtx (IF_THEN_ELSE, VOIDmode,
  907.                    gen_rtx (compare_code, DImode,
  908.                         temp, const0_rtx),
  909.                    const1_rtx,
  910.                    operands[0])));
  911.       return 1;
  912.     }
  913.   else
  914.     {
  915.       operands[1] = gen_compare_reg (compare_code,
  916.                      sparc_compare_op0, sparc_compare_op1);
  917.  
  918.       switch (GET_MODE (operands[1]))
  919.     {
  920.       case CCmode :
  921.       case CCXmode :
  922.       case CCFPEmode :
  923.       case CCFPmode :
  924.         break;
  925.       default :
  926.         abort ();
  927.     }
  928.     emit_insn (gen_rtx (SET, VOIDmode, operands[0], const0_rtx));
  929.     emit_insn (gen_rtx (SET, VOIDmode, operands[0],
  930.                 gen_rtx (IF_THEN_ELSE, VOIDmode,
  931.                      gen_rtx (compare_code,
  932.                           GET_MODE (operands[1]),
  933.                           operands[1], const0_rtx),
  934.                           const1_rtx, operands[0])));
  935.     return 1;
  936.     }
  937. }
  938.  
  939. /* Emit a conditional jump insn for the v9 architecture using comparison code
  940.    CODE and jump target LABEL.
  941.    This function exists to take advantage of the v9 brxx insns.  */
  942.  
  943. void
  944. emit_v9_brxx_insn (code, op0, label)
  945.      enum rtx_code code;
  946.      rtx op0, label;
  947. {
  948.   emit_jump_insn (gen_rtx (SET, VOIDmode,
  949.                pc_rtx,
  950.                gen_rtx (IF_THEN_ELSE, VOIDmode,
  951.                     gen_rtx (code, GET_MODE (op0),
  952.                          op0, const0_rtx),
  953.                     gen_rtx (LABEL_REF, VOIDmode, label),
  954.                     pc_rtx)));
  955. }
  956.  
  957. /* Return nonzero if a return peephole merging return with
  958.    setting of output register is ok.  */
  959. int
  960. leaf_return_peephole_ok ()
  961. {
  962.   return (actual_fsize == 0);
  963. }
  964.  
  965. /* Return nonzero if TRIAL can go into the function epilogue's
  966.    delay slot.  SLOT is the slot we are trying to fill.  */
  967.  
  968. int
  969. eligible_for_epilogue_delay (trial, slot)
  970.      rtx trial;
  971.      int slot;
  972. {
  973.   rtx pat, src;
  974.  
  975.   if (slot >= 1)
  976.     return 0;
  977.   if (GET_CODE (trial) != INSN
  978.       || GET_CODE (PATTERN (trial)) != SET)
  979.     return 0;
  980.   if (get_attr_length (trial) != 1)
  981.     return 0;
  982.  
  983.   /* In the case of a true leaf function, anything can go into the delay slot.
  984.      A delay slot only exists however if the frame size is zero, otherwise
  985.      we will put an insn to adjust the stack after the return.  */
  986.   if (leaf_function)
  987.     {
  988.       if (leaf_return_peephole_ok ())
  989.     return (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE);
  990.       return 0;
  991.     }
  992.  
  993.   /* Otherwise, only operations which can be done in tandem with
  994.      a `restore' insn can go into the delay slot.  */
  995.   pat = PATTERN (trial);
  996.   if (GET_CODE (SET_DEST (pat)) != REG
  997.       || REGNO (SET_DEST (pat)) == 0
  998.       || REGNO (SET_DEST (pat)) >= 32
  999.       || REGNO (SET_DEST (pat)) < 24)
  1000.     return 0;
  1001.  
  1002.   src = SET_SRC (pat);
  1003.   if (arith_operand (src, GET_MODE (src)))
  1004.     return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode);
  1005.   if (arith_double_operand (src, GET_MODE (src)))
  1006.     return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode);
  1007.   if (GET_CODE (src) == PLUS)
  1008.     {
  1009.       if (register_operand (XEXP (src, 0), SImode)
  1010.       && arith_operand (XEXP (src, 1), SImode))
  1011.     return 1;
  1012.       if (register_operand (XEXP (src, 1), SImode)
  1013.       && arith_operand (XEXP (src, 0), SImode))
  1014.     return 1;
  1015.       if (register_operand (XEXP (src, 0), DImode)
  1016.       && arith_double_operand (XEXP (src, 1), DImode))
  1017.     return 1;
  1018.       if (register_operand (XEXP (src, 1), DImode)
  1019.       && arith_double_operand (XEXP (src, 0), DImode))
  1020.     return 1;
  1021.     }
  1022.   if (GET_CODE (src) == MINUS
  1023.       && register_operand (XEXP (src, 0), SImode)
  1024.       && small_int (XEXP (src, 1), VOIDmode))
  1025.     return 1;
  1026.   if (GET_CODE (src) == MINUS
  1027.       && register_operand (XEXP (src, 0), DImode)
  1028.       && !register_operand (XEXP (src, 1), DImode)
  1029.       && arith_double_operand (XEXP (src, 1), DImode))
  1030.     return 1;
  1031.   return 0;
  1032. }
  1033.  
  1034. int
  1035. short_branch (uid1, uid2)
  1036.      int uid1, uid2;
  1037. {
  1038.   unsigned int delta = insn_addresses[uid1] - insn_addresses[uid2];
  1039.   if (delta + 1024 < 2048)
  1040.     return 1;
  1041.   /* warning ("long branch, distance %d", delta); */
  1042.   return 0;
  1043. }
  1044.  
  1045. /* Return non-zero if REG is not used after INSN.
  1046.    We assume REG is a reload reg, and therefore does
  1047.    not live past labels or calls or jumps.  */
  1048. int
  1049. reg_unused_after (reg, insn)
  1050.      rtx reg;
  1051.      rtx insn;
  1052. {
  1053.   enum rtx_code code, prev_code = UNKNOWN;
  1054.  
  1055.   while (insn = NEXT_INSN (insn))
  1056.     {
  1057.       if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)])
  1058.     return 1;
  1059.  
  1060.       code = GET_CODE (insn);
  1061.       if (GET_CODE (insn) == CODE_LABEL)
  1062.     return 1;
  1063.  
  1064.       if (GET_RTX_CLASS (code) == 'i')
  1065.     {
  1066.       rtx set = single_set (insn);
  1067.       int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set));
  1068.       if (set && in_src)
  1069.         return 0;
  1070.       if (set && reg_overlap_mentioned_p (reg, SET_DEST (set)))
  1071.         return 1;
  1072.       if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn)))
  1073.         return 0;
  1074.     }
  1075.       prev_code = code;
  1076.     }
  1077.   return 1;
  1078. }
  1079.  
  1080. /* The rtx for the global offset table which is a special form
  1081.    that *is* a position independent symbolic constant.  */
  1082. static rtx pic_pc_rtx;
  1083.  
  1084. /* Ensure that we are not using patterns that are not OK with PIC.  */
  1085.  
  1086. int
  1087. check_pic (i)
  1088.      int i;
  1089. {
  1090.   switch (flag_pic)
  1091.     {
  1092.     case 1:
  1093.       if (GET_CODE (recog_operand[i]) == SYMBOL_REF
  1094.       || (GET_CODE (recog_operand[i]) == CONST
  1095.           && ! rtx_equal_p (pic_pc_rtx, recog_operand[i])))
  1096.     abort ();
  1097.     case 2:
  1098.     default:
  1099.       return 1;
  1100.     }
  1101. }
  1102.  
  1103. /* Return true if X is an address which needs a temporary register when 
  1104.    reloaded while generating PIC code.  */
  1105.  
  1106. int
  1107. pic_address_needs_scratch (x)
  1108.      rtx x;
  1109. {
  1110.   /* An address which is a symbolic plus a non SMALL_INT needs a temp reg.  */
  1111.   if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
  1112.       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
  1113.       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
  1114.       && ! SMALL_INT (XEXP (XEXP (x, 0), 1)))
  1115.     return 1;
  1116.  
  1117.   return 0;
  1118. }
  1119.  
  1120. /* Legitimize PIC addresses.  If the address is already position-independent,
  1121.    we return ORIG.  Newly generated position-independent addresses go into a
  1122.    reg.  This is REG if non zero, otherwise we allocate register(s) as
  1123.    necessary.  */
  1124.  
  1125. rtx
  1126. legitimize_pic_address (orig, mode, reg)
  1127.      rtx orig;
  1128.      enum machine_mode mode;
  1129.      rtx reg;
  1130. {
  1131. #ifdef MACHO_PIC
  1132.     if (reg == 0 && ! reload_in_progress && ! reload_completed) {
  1133.         reg = gen_reg_rtx(Pmode);
  1134.     }
  1135.  
  1136.       if (GET_CODE (orig) == CONST) {
  1137.       rtx base, offset;
  1138.  
  1139.       if (GET_CODE (XEXP (orig, 0)) == PLUS
  1140.       && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
  1141.         return orig;
  1142.  
  1143.       if (GET_CODE (XEXP (orig, 0)) == PLUS) {
  1144.         base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
  1145.         offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
  1146.                      reg);
  1147.       } else
  1148.         abort ();
  1149.  
  1150.       if (GET_CODE (offset) == CONST_INT) {
  1151.         if (SMALL_INT (offset))
  1152.           return plus_constant_for_output (base, INTVAL (offset));
  1153.         else if (! reload_in_progress && ! reload_completed)
  1154.           offset = force_reg (Pmode, offset);
  1155.         else
  1156.           abort ();
  1157.       }
  1158.       return gen_rtx (PLUS, Pmode, base, offset);
  1159.     }
  1160.     return (rtx) machopic_legitimize_pic_address (orig, mode, reg);
  1161. #endif /*  MACHO_PIC */
  1162.  
  1163.   if (GET_CODE (orig) == SYMBOL_REF)
  1164.     {
  1165.       rtx pic_ref, address;
  1166.       rtx insn;
  1167.  
  1168.       if (reg == 0)
  1169.     {
  1170.       if (reload_in_progress || reload_completed)
  1171.         abort ();
  1172.       else
  1173.         reg = gen_reg_rtx (Pmode);
  1174.     }
  1175.  
  1176.       if (flag_pic == 2)
  1177.     {
  1178.       /* If not during reload, allocate another temp reg here for loading
  1179.          in the address, so that these instructions can be optimized
  1180.          properly.  */
  1181.       rtx temp_reg = ((reload_in_progress || reload_completed)
  1182.               ? reg : gen_reg_rtx (Pmode));
  1183.  
  1184.       /* Must put the SYMBOL_REF inside an UNSPEC here so that cse
  1185.          won't get confused into thinking that these two instructions
  1186.          are loading in the true address of the symbol.  If in the
  1187.          future a PIC rtx exists, that should be used instead.  */
  1188.       emit_insn (gen_rtx (SET, VOIDmode, temp_reg,
  1189.                   gen_rtx (HIGH, Pmode,
  1190.                        gen_rtx (UNSPEC, Pmode,
  1191.                         gen_rtvec (1, orig),
  1192.                         0))));
  1193.       emit_insn (gen_rtx (SET, VOIDmode, temp_reg,
  1194.                   gen_rtx (LO_SUM, Pmode, temp_reg,
  1195.                        gen_rtx (UNSPEC, Pmode,
  1196.                         gen_rtvec (1, orig),
  1197.                         0))));
  1198.       address = temp_reg;
  1199.     }
  1200.       else
  1201.     address = orig;
  1202.  
  1203.       pic_ref = gen_rtx (MEM, Pmode,
  1204.              gen_rtx (PLUS, Pmode,
  1205.                   pic_offset_table_rtx, address));
  1206.       current_function_uses_pic_offset_table = 1;
  1207.       RTX_UNCHANGING_P (pic_ref) = 1;
  1208.       insn = emit_move_insn (reg, pic_ref);
  1209.       /* Put a REG_EQUAL note on this insn, so that it can be optimized
  1210.      by loop.  */
  1211.       REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_EQUAL, orig,
  1212.                   REG_NOTES (insn));
  1213.       return reg;
  1214.     }
  1215.   else if (GET_CODE (orig) == CONST)
  1216.     {
  1217.       rtx base, offset;
  1218.  
  1219.       if (GET_CODE (XEXP (orig, 0)) == PLUS
  1220.       && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
  1221.     return orig;
  1222.  
  1223.       if (reg == 0)
  1224.     {
  1225.       if (reload_in_progress || reload_completed)
  1226.         abort ();
  1227.       else
  1228.         reg = gen_reg_rtx (Pmode);
  1229.     }
  1230.  
  1231.       if (GET_CODE (XEXP (orig, 0)) == PLUS)
  1232.     {
  1233.       base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
  1234.       offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
  1235.                      base == reg ? 0 : reg);
  1236.     }
  1237.       else
  1238.     abort ();
  1239.  
  1240.       if (GET_CODE (offset) == CONST_INT)
  1241.     {
  1242.       if (SMALL_INT (offset))
  1243.         return plus_constant_for_output (base, INTVAL (offset));
  1244.       else if (! reload_in_progress && ! reload_completed)
  1245.         offset = force_reg (Pmode, offset);
  1246.       else
  1247.         /* If we reach here, then something is seriously wrong.  */
  1248.         abort ();
  1249.     }
  1250.       return gen_rtx (PLUS, Pmode, base, offset);
  1251.     }
  1252.   else if (GET_CODE (orig) == LABEL_REF)
  1253.     current_function_uses_pic_offset_table = 1;
  1254.  
  1255.   return orig;
  1256. }
  1257.  
  1258. /* Set up PIC-specific rtl.  This should not cause any insns
  1259.    to be emitted.  */
  1260.  
  1261. void
  1262. initialize_pic ()
  1263. {
  1264. }
  1265.  
  1266. /* Emit special PIC prologues and epilogues.  */
  1267.  
  1268. void
  1269. finalize_pic ()
  1270. {
  1271.   /* The table we use to reference PIC data.  */
  1272.   rtx global_offset_table;
  1273.   /* Labels to get the PC in the prologue of this function.  */
  1274.   rtx l1, l2;
  1275.   rtx seq;
  1276.   int orig_flag_pic = flag_pic;
  1277. #ifdef MACHO_PIC
  1278.   rtx first;
  1279. #endif
  1280.  
  1281.   if (current_function_uses_pic_offset_table == 0)
  1282.     return;
  1283.  
  1284.   if (! flag_pic)
  1285.     abort ();
  1286.  
  1287.   flag_pic = 0;
  1288.   l1 = gen_label_rtx ();
  1289.   l2 = gen_label_rtx ();
  1290.  
  1291.   start_sequence ();
  1292.  
  1293. #ifdef MACHO_PIC        /* generate a machopic pic base label */
  1294.     XSTR (l1, 4) = machopic_function_base_name ();
  1295. #endif /*  MACHO_PIC */
  1296.  
  1297.   emit_label (l1);
  1298.   /* Note that we pun calls and jumps here!  */
  1299.   emit_jump_insn (gen_rtx (PARALLEL, VOIDmode,
  1300.                          gen_rtvec (2,
  1301.                                     gen_rtx (SET, VOIDmode, pc_rtx, gen_rtx (LABEL_REF, VOIDmode, l2)),
  1302.                                     gen_rtx (SET, VOIDmode, gen_rtx (REG, SImode, 15), gen_rtx (LABEL_REF, VOIDmode, l2)))));
  1303.   emit_label (l2);
  1304.  
  1305. #ifdef MACHO_PIC
  1306.   first = gen_rtx (SET, VOIDmode, gen_rtx(REG, Pmode, PIC_OFFSET_TABLE_REGNUM),
  1307.                                                                 gen_rtx(REG, Pmode, 15));
  1308.     emit_insn (first);
  1309. #else /*  ! MACHO_PIC */
  1310.   /* Initialize every time through, since we can't easily
  1311.      know this to be permanent.  */
  1312.   global_offset_table = gen_rtx (SYMBOL_REF, Pmode, "_GLOBAL_OFFSET_TABLE_");
  1313.   pic_pc_rtx = gen_rtx (CONST, Pmode,
  1314.             gen_rtx (MINUS, Pmode,
  1315.                  global_offset_table,
  1316.                  gen_rtx (CONST, Pmode,
  1317.                       gen_rtx (MINUS, Pmode,
  1318.                            gen_rtx (LABEL_REF, VOIDmode, l1),
  1319.                            pc_rtx))));
  1320.  
  1321.   if (Pmode == DImode)
  1322.     emit_insn (gen_rtx (PARALLEL, VOIDmode,
  1323.             gen_rtvec (2,
  1324.                    gen_rtx (SET, VOIDmode, pic_offset_table_rtx,
  1325.                         gen_rtx (HIGH, Pmode, pic_pc_rtx)),
  1326.                    gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, Pmode, 1)))));
  1327.   else
  1328.     emit_insn (gen_rtx (SET, VOIDmode, pic_offset_table_rtx,
  1329.             gen_rtx (HIGH, Pmode, pic_pc_rtx)));
  1330.  
  1331.   emit_insn (gen_rtx (SET, VOIDmode,
  1332.               pic_offset_table_rtx,
  1333.               gen_rtx (LO_SUM, Pmode,
  1334.                    pic_offset_table_rtx, pic_pc_rtx)));
  1335.   emit_insn (gen_rtx (SET, VOIDmode,
  1336.               pic_offset_table_rtx,
  1337.               gen_rtx (PLUS, Pmode,
  1338.                    pic_offset_table_rtx, gen_rtx (REG, Pmode, 15))));
  1339.   /* emit_insn (gen_rtx (ASM_INPUT, VOIDmode, "!#PROLOGUE# 1")); */
  1340. #endif /* not MACHO_PIC */
  1341.  
  1342.   LABEL_PRESERVE_P (l1) = 1;
  1343.   LABEL_PRESERVE_P (l2) = 1;
  1344.   flag_pic = orig_flag_pic;
  1345.  
  1346.   seq = gen_sequence ();
  1347.   end_sequence ();
  1348.   emit_insn_after (seq, get_insns ());
  1349.  
  1350.   /* Need to emit this whether or not we obey regdecls,
  1351.      since setjmp/longjmp can cause life info to screw up.  */
  1352.   emit_insn (gen_rtx (USE, VOIDmode, pic_offset_table_rtx));
  1353. }
  1354.  
  1355. /* Emit insns to move operands[1] into operands[0].
  1356.  
  1357.    Return 1 if we have written out everything that needs to be done to
  1358.    do the move.  Otherwise, return 0 and the caller will emit the move
  1359.    normally.  */
  1360.  
  1361. int
  1362. emit_move_sequence (operands, mode)
  1363.      rtx *operands;
  1364.      enum machine_mode mode;
  1365. {
  1366.   register rtx operand0 = operands[0];
  1367.   register rtx operand1 = operands[1];
  1368.  
  1369.   if (CONSTANT_P (operand1) && flag_pic
  1370.       && pic_address_needs_scratch (operand1))
  1371.     operands[1] = operand1 = legitimize_pic_address (operand1, mode, 0);
  1372.  
  1373.   /* Handle most common case first: storing into a register.  */
  1374.   if (register_operand (operand0, mode))
  1375.     {
  1376.       if (register_operand (operand1, mode)
  1377.       || (GET_CODE (operand1) == CONST_INT && SMALL_INT (operand1))
  1378.       || (GET_CODE (operand1) == CONST_DOUBLE
  1379.           && arith_double_operand (operand1, DImode))
  1380.       || (GET_CODE (operand1) == HIGH && GET_MODE (operand1) != DImode)
  1381.       /* Only `general_operands' can come here, so MEM is ok.  */
  1382.       || GET_CODE (operand1) == MEM)
  1383.     {
  1384.       /* Run this case quickly.  */
  1385.       emit_insn (gen_rtx (SET, VOIDmode, operand0, operand1));
  1386.       return 1;
  1387.     }
  1388.     }
  1389.   else if (GET_CODE (operand0) == MEM)
  1390.     {
  1391.       if (register_operand (operand1, mode) || operand1 == const0_rtx)
  1392.     {
  1393.       /* Run this case quickly.  */
  1394.       emit_insn (gen_rtx (SET, VOIDmode, operand0, operand1));
  1395.       return 1;
  1396.     }
  1397.       if (! reload_in_progress)
  1398.     {
  1399.       operands[0] = validize_mem (operand0);
  1400.       operands[1] = operand1 = force_reg (mode, operand1);
  1401.     }
  1402.     }
  1403.  
  1404.   /* Simplify the source if we need to.  Must handle DImode HIGH operators
  1405.      here because such a move needs a clobber added.  */
  1406.   if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode))
  1407.       || (GET_CODE (operand1) == HIGH && GET_MODE (operand1) == DImode))
  1408.     {
  1409.       if (flag_pic && symbolic_operand (operand1, mode))
  1410.     {
  1411.       rtx temp_reg = reload_in_progress ? operand0 :
  1412. #ifdef MACHO_PIC
  1413.                gen_reg_rtx(Pmode);
  1414. #else
  1415.                0;
  1416. #endif
  1417.  
  1418.       operands[1] = legitimize_pic_address (operand1, mode, temp_reg);
  1419.     }
  1420.       else if (GET_CODE (operand1) == CONST_INT
  1421.            ? (! SMALL_INT (operand1)
  1422.           && (INTVAL (operand1) & 0x3ff) != 0)
  1423.            : (GET_CODE (operand1) == CONST_DOUBLE
  1424.           ? ! arith_double_operand (operand1, DImode)
  1425.           : 1))
  1426.     {
  1427.       /* For DImode values, temp must be operand0 because of the way
  1428.          HI and LO_SUM work.  The LO_SUM operator only copies half of
  1429.          the LSW from the dest of the HI operator.  If the LO_SUM dest is
  1430.          not the same as the HI dest, then the MSW of the LO_SUM dest will
  1431.          never be set.
  1432.  
  1433.          ??? The real problem here is that the ...(HI:DImode pattern emits
  1434.          multiple instructions, and the ...(LO_SUM:DImode pattern emits
  1435.          one instruction.  This fails, because the compiler assumes that
  1436.          LO_SUM copies all bits of the first operand to its dest.  Better
  1437.          would be to have the HI pattern emit one instruction and the
  1438.          LO_SUM pattern multiple instructions.  Even better would be
  1439.          to use four rtl insns.  */
  1440.       rtx temp = ((reload_in_progress || mode == DImode)
  1441.               ? operand0 : gen_reg_rtx (mode));
  1442.  
  1443.       if (TARGET_V9 && mode == DImode)
  1444.         {
  1445.           int high_operand = 0;
  1446.  
  1447.           /* If the operand is already a HIGH, then remove the HIGH so
  1448.          that we won't get duplicate HIGH operators in this insn.
  1449.          Also, we must store the result into the original dest,
  1450.          because that is where the following LO_SUM expects it.  */
  1451.           if (GET_CODE (operand1) == HIGH)
  1452.         {
  1453.           operand1 = XEXP (operand1, 0);
  1454.           high_operand = 1;
  1455.         }
  1456.  
  1457.           emit_insn (gen_rtx (PARALLEL, VOIDmode,
  1458.                   gen_rtvec (2,
  1459.                          gen_rtx (SET, VOIDmode, temp,
  1460.                               gen_rtx (HIGH, mode, operand1)),
  1461.                          gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, DImode, 1)))));
  1462.  
  1463.           /* If this was a high operand, then we are now finished.  */
  1464.           if (high_operand)
  1465.         return 1;
  1466.         }
  1467.       else
  1468.         emit_insn (gen_rtx (SET, VOIDmode, temp,
  1469.                 gen_rtx (HIGH, mode, operand1)));
  1470.  
  1471.       operands[1] = gen_rtx (LO_SUM, mode, temp, operand1);
  1472.     }
  1473.     }
  1474.  
  1475.   if (GET_CODE (operand1) == LABEL_REF && flag_pic)
  1476.     {
  1477.       /* The procedure for doing this involves using a call instruction to
  1478.      get the pc into o7.  We need to indicate this explicitly because
  1479.      the tablejump pattern assumes that it can use this value also.  */
  1480.       emit_insn (gen_rtx (PARALLEL, VOIDmode,
  1481.               gen_rtvec (2,
  1482.                      gen_rtx (SET, VOIDmode, operand0,
  1483.                           operand1),
  1484.                      gen_rtx (SET, VOIDmode,
  1485.                           gen_rtx (REG, mode, 15),
  1486.                           pc_rtx))));
  1487.       return 1;
  1488.     }
  1489.  
  1490.   /* Now have insn-emit do whatever it normally does.  */
  1491.   return 0;
  1492. }
  1493.  
  1494. /* Return the best assembler insn template
  1495.    for moving operands[1] into operands[0] as a fullword.  */
  1496.  
  1497. char *
  1498. singlemove_string (operands)
  1499.      rtx *operands;
  1500. {
  1501.   if (GET_CODE (operands[0]) == MEM)
  1502.     {
  1503.       if (GET_CODE (operands[1]) != MEM)
  1504.     return "st %r1,%0";
  1505.       else
  1506.     abort ();
  1507.     }
  1508.   else if (GET_CODE (operands[1]) == MEM)
  1509.     return "ld %1,%0";
  1510.   else if (GET_CODE (operands[1]) == CONST_DOUBLE)
  1511.     {
  1512.       REAL_VALUE_TYPE r;
  1513.       long i;
  1514.  
  1515.       /* Must be SFmode, otherwise this doesn't make sense.  */
  1516.       if (GET_MODE (operands[1]) != SFmode)
  1517.     abort ();
  1518.  
  1519.       REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
  1520.       REAL_VALUE_TO_TARGET_SINGLE (r, i);
  1521.       operands[1] = gen_rtx (CONST_INT, VOIDmode, i);
  1522.  
  1523.       if (CONST_OK_FOR_LETTER_P (i, 'I'))
  1524.     return "mov %1,%0";
  1525.       else if ((i & 0x000003FF) != 0)
  1526.     return "sethi %%hi(%a1),%0\n\tor %0,%%lo(%a1),%0";
  1527.       else
  1528.     return "sethi %%hi(%a1),%0";
  1529.     }
  1530.   else if (GET_CODE (operands[1]) == CONST_INT
  1531.        && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'I'))
  1532.     {
  1533.       int i = INTVAL (operands[1]);
  1534.  
  1535.       /* If all low order 10 bits are clear, then we only need a single
  1536.      sethi insn to load the constant.  */
  1537.       if ((i & 0x000003FF) != 0)
  1538.     return "sethi %%hi(%a1),%0\n\tor %0,%%lo(%a1),%0";
  1539.       else
  1540.     return "sethi %%hi(%a1),%0";
  1541.     }
  1542.   /* Operand 1 must be a register, or a 'I' type CONST_INT.  */
  1543.   return "mov %1,%0";
  1544. }
  1545.  
  1546. /* Return non-zero if it is OK to assume that the given memory operand is
  1547.    aligned at least to a 8-byte boundary.  This should only be called
  1548.    for memory accesses whose size is 8 bytes or larger.  */
  1549.  
  1550. int
  1551. mem_aligned_8 (mem)
  1552.      register rtx mem;
  1553. {
  1554.   register rtx addr;
  1555.   register rtx base;
  1556.   register rtx offset;
  1557.  
  1558.   if (GET_CODE (mem) != MEM)
  1559.     return 0;    /* It's gotta be a MEM! */
  1560.  
  1561.   addr = XEXP (mem, 0);
  1562.  
  1563.   /* Now that all misaligned double parms are copied on function entry,
  1564.      we can assume any 64-bit object is 64-bit aligned except those which
  1565.      are at unaligned offsets from the stack or frame pointer.  If the
  1566.      TARGET_UNALIGNED_DOUBLES switch is given, we do not make this
  1567.      assumption.  */
  1568.  
  1569.   /* See what register we use in the address.  */
  1570.   base = 0;
  1571.   if (GET_CODE (addr) == PLUS)
  1572.     {
  1573.       if (GET_CODE (XEXP (addr, 0)) == REG
  1574.       && GET_CODE (XEXP (addr, 1)) == CONST_INT)
  1575.     {
  1576.       base = XEXP (addr, 0);
  1577.       offset = XEXP (addr, 1);
  1578.     }
  1579.     }
  1580.   else if (GET_CODE (addr) == REG)
  1581.     {
  1582.       base = addr;
  1583.       offset = const0_rtx;
  1584.     }
  1585.  
  1586.   /* If it's the stack or frame pointer, check offset alignment.
  1587.      We can have improper alignment in the function entry code.  */
  1588.   if (base
  1589.       && (REGNO (base) == FRAME_POINTER_REGNUM
  1590.       || REGNO (base) == STACK_POINTER_REGNUM))
  1591.     {
  1592.       if (((INTVAL (offset) - SPARC_STACK_BIAS) & 0x7) == 0)
  1593.     return 1;
  1594.     }
  1595.   /* Anything else we know is properly aligned unless TARGET_UNALIGNED_DOUBLES
  1596.      is true, in which case we can only assume that an access is aligned if
  1597.      it is to a constant address, or the address involves a LO_SUM.
  1598.  
  1599.      We used to assume an address was aligned if MEM_IN_STRUCT_P was true.
  1600.      That assumption was deleted so that gcc generated code can be used with
  1601.      memory allocators that only guarantee 4 byte alignment.  */
  1602.   else if (! TARGET_UNALIGNED_DOUBLES || CONSTANT_P (addr)
  1603.        || GET_CODE (addr) == LO_SUM)
  1604.     return 1;
  1605.  
  1606.   /* An obviously unaligned address.  */
  1607.   return 0;
  1608. }
  1609.  
  1610. enum optype { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP };
  1611.  
  1612. /* Output assembler code to perform a doubleword move insn
  1613.    with operands OPERANDS.  This is very similar to the following
  1614.    output_move_quad function.  */
  1615.  
  1616. char *
  1617. output_move_double (operands)
  1618.      rtx *operands;
  1619. {
  1620.   register rtx op0 = operands[0];
  1621.   register rtx op1 = operands[1];
  1622.   register enum optype optype0;
  1623.   register enum optype optype1;
  1624.   rtx latehalf[2];
  1625.   rtx addreg0 = 0;
  1626.   rtx addreg1 = 0;
  1627.   int highest_first = 0;
  1628.   int no_addreg1_decrement = 0;
  1629.  
  1630.   /* First classify both operands.  */
  1631.  
  1632.   if (REG_P (op0))
  1633.     optype0 = REGOP;
  1634.   else if (offsettable_memref_p (op0))
  1635.     optype0 = OFFSOP;
  1636.   else if (GET_CODE (op0) == MEM)
  1637.     optype0 = MEMOP;
  1638.   else
  1639.     optype0 = RNDOP;
  1640.  
  1641.   if (REG_P (op1))
  1642.     optype1 = REGOP;
  1643.   else if (CONSTANT_P (op1))
  1644.     optype1 = CNSTOP;
  1645.   else if (offsettable_memref_p (op1))
  1646.     optype1 = OFFSOP;
  1647.   else if (GET_CODE (op1) == MEM)
  1648.     optype1 = MEMOP;
  1649.   else
  1650.     optype1 = RNDOP;
  1651.  
  1652.   /* Check for the cases that the operand constraints are not
  1653.      supposed to allow to happen.  Abort if we get one,
  1654.      because generating code for these cases is painful.  */
  1655.  
  1656.   if (optype0 == RNDOP || optype1 == RNDOP
  1657.       || (optype0 == MEM && optype1 == MEM))
  1658.     abort ();
  1659.  
  1660.   /* If an operand is an unoffsettable memory ref, find a register
  1661.      we can increment temporarily to make it refer to the second word.  */
  1662.  
  1663.   if (optype0 == MEMOP)
  1664.     addreg0 = find_addr_reg (XEXP (op0, 0));
  1665.  
  1666.   if (optype1 == MEMOP)
  1667.     addreg1 = find_addr_reg (XEXP (op1, 0));
  1668.  
  1669.   /* Ok, we can do one word at a time.
  1670.      Set up in LATEHALF the operands to use for the
  1671.      high-numbered (least significant) word and in some cases alter the
  1672.      operands in OPERANDS to be suitable for the low-numbered word.  */
  1673.  
  1674.   if (optype0 == REGOP)
  1675.     latehalf[0] = gen_rtx (REG, SImode, REGNO (op0) + 1);
  1676.   else if (optype0 == OFFSOP)
  1677.     latehalf[0] = adj_offsettable_operand (op0, 4);
  1678.   else
  1679.     latehalf[0] = op0;
  1680.  
  1681.   if (optype1 == REGOP)
  1682.     latehalf[1] = gen_rtx (REG, SImode, REGNO (op1) + 1);
  1683.   else if (optype1 == OFFSOP)
  1684.     latehalf[1] = adj_offsettable_operand (op1, 4);
  1685.   else if (optype1 == CNSTOP)
  1686.     {
  1687.       if (TARGET_V9)
  1688.     {
  1689.       if (arith_double_operand (op1, DImode))
  1690.         {
  1691.           operands[1] = gen_rtx (CONST_INT, VOIDmode,
  1692.                      CONST_DOUBLE_LOW (op1));
  1693.           return "mov %1,%0";
  1694.         }
  1695.       else
  1696.         {
  1697.           /* The only way to handle CONST_DOUBLEs or other 64 bit
  1698.          constants here is to use a temporary, such as is done
  1699.          for the V9 DImode sethi insn pattern.  This is not
  1700.          a practical solution, so abort if we reach here.
  1701.          The md file should always force such constants to
  1702.          memory.  */
  1703.           abort ();
  1704.         }
  1705.     }
  1706.       else
  1707.     split_double (op1, &operands[1], &latehalf[1]);
  1708.     }
  1709.   else
  1710.     latehalf[1] = op1;
  1711.  
  1712.   /* Easy case: try moving both words at once.  Check for moving between
  1713.      an even/odd register pair and a memory location.  */
  1714.   if ((optype0 == REGOP && optype1 != REGOP && optype1 != CNSTOP
  1715.        && (TARGET_V9 || (REGNO (op0) & 1) == 0))
  1716.       || (optype0 != REGOP && optype0 != CNSTOP && optype1 == REGOP
  1717.       && (TARGET_V9 || (REGNO (op1) & 1) == 0)))
  1718.     {
  1719.       register rtx mem,reg;
  1720.  
  1721.       if (optype0 == REGOP)
  1722.     mem = op1, reg = op0;
  1723.       else
  1724.     mem = op0, reg = op1;
  1725.  
  1726.       /* In v9, ldd can be used for word aligned addresses, so technically
  1727.      some of this logic is unneeded.  We still avoid ldd if the address
  1728.      is obviously unaligned though.  */
  1729.  
  1730.       if (mem_aligned_8 (mem)
  1731.       /* If this is a floating point register higher than %f31,
  1732.          then we *must* use an aligned load, since `ld' will not accept
  1733.          the register number.  */
  1734.       || (TARGET_V9 && REGNO (reg) >= 64))
  1735.     {
  1736.       if (FP_REG_P (reg) || ! TARGET_V9)
  1737.         return (mem == op1 ? "ldd %1,%0" : "std %1,%0");
  1738.       else
  1739.         return (mem == op1 ? "ldx %1,%0" : "stx %1,%0");
  1740.     }
  1741.     }
  1742.  
  1743.   if (TARGET_V9)
  1744.     {
  1745.       if (optype0 == REGOP && optype1 == REGOP)
  1746.     {
  1747.       if (FP_REG_P (op0))
  1748.         return "fmovd %1,%0";
  1749.       else
  1750.         return "mov %1,%0";
  1751.     }
  1752.     }
  1753.  
  1754.   /* If the first move would clobber the source of the second one,
  1755.      do them in the other order.  */
  1756.  
  1757.   /* Overlapping registers.  */
  1758.   if (optype0 == REGOP && optype1 == REGOP
  1759.       && REGNO (op0) == REGNO (latehalf[1]))
  1760.     {
  1761.       /* Do that word.  */
  1762.       output_asm_insn (singlemove_string (latehalf), latehalf);
  1763.       /* Do low-numbered word.  */
  1764.       return singlemove_string (operands);
  1765.     }
  1766.   /* Loading into a register which overlaps a register used in the address.  */
  1767.   else if (optype0 == REGOP && optype1 != REGOP
  1768.        && reg_overlap_mentioned_p (op0, op1))
  1769.     {
  1770.       /* If both halves of dest are used in the src memory address,
  1771.      add the two regs and put them in the low reg (op0).
  1772.      Then it works to load latehalf first.  */
  1773.       if (reg_mentioned_p (op0, XEXP (op1, 0))
  1774.       && reg_mentioned_p (latehalf[0], XEXP (op1, 0)))
  1775.     {
  1776.       rtx xops[2];
  1777.       xops[0] = latehalf[0];
  1778.       xops[1] = op0;
  1779.       output_asm_insn ("add %1,%0,%1", xops);
  1780.       operands[1] = gen_rtx (MEM, DImode, op0);
  1781.       latehalf[1] = adj_offsettable_operand (operands[1], 4);
  1782.       addreg1 = 0;
  1783.       highest_first = 1;
  1784.     }
  1785.       /* Only one register in the dest is used in the src memory address,
  1786.      and this is the first register of the dest, so we want to do
  1787.      the late half first here also.  */
  1788.       else if (! reg_mentioned_p (latehalf[0], XEXP (op1, 0)))
  1789.     highest_first = 1;
  1790.       /* Only one register in the dest is used in the src memory address,
  1791.      and this is the second register of the dest, so we want to do
  1792.      the late half last.  If addreg1 is set, and addreg1 is the same
  1793.      register as latehalf, then we must suppress the trailing decrement,
  1794.      because it would clobber the value just loaded.  */
  1795.       else if (addreg1 && reg_mentioned_p (addreg1, latehalf[0]))
  1796.     no_addreg1_decrement = 1;
  1797.     }
  1798.  
  1799.   /* Normal case: do the two words, low-numbered first.
  1800.      Overlap case (highest_first set): do high-numbered word first.  */
  1801.  
  1802.   if (! highest_first)
  1803.     output_asm_insn (singlemove_string (operands), operands);
  1804.  
  1805.   /* Make any unoffsettable addresses point at high-numbered word.  */
  1806.   if (addreg0)
  1807.     output_asm_insn ("add %0,0x4,%0", &addreg0);
  1808.   if (addreg1)
  1809.     output_asm_insn ("add %0,0x4,%0", &addreg1);
  1810.  
  1811.   /* Do that word.  */
  1812.   output_asm_insn (singlemove_string (latehalf), latehalf);
  1813.  
  1814.   /* Undo the adds we just did.  */
  1815.   if (addreg0)
  1816.     output_asm_insn ("add %0,-0x4,%0", &addreg0);
  1817.   if (addreg1 && ! no_addreg1_decrement)
  1818.     output_asm_insn ("add %0,-0x4,%0", &addreg1);
  1819.  
  1820.   if (highest_first)
  1821.     output_asm_insn (singlemove_string (operands), operands);
  1822.  
  1823.   return "";
  1824. }
  1825.  
  1826. /* Output assembler code to perform a quadword move insn
  1827.    with operands OPERANDS.  This is very similar to the preceding
  1828.    output_move_double function.  */
  1829.  
  1830. char *
  1831. output_move_quad (operands)
  1832.      rtx *operands;
  1833. {
  1834.   register rtx op0 = operands[0];
  1835.   register rtx op1 = operands[1];
  1836.   register enum optype optype0;
  1837.   register enum optype optype1;
  1838.   rtx wordpart[4][2];
  1839.   rtx addreg0 = 0;
  1840.   rtx addreg1 = 0;
  1841.  
  1842.   /* First classify both operands.  */
  1843.  
  1844.   if (REG_P (op0))
  1845.     optype0 = REGOP;
  1846.   else if (offsettable_memref_p (op0))
  1847.     optype0 = OFFSOP;
  1848.   else if (GET_CODE (op0) == MEM)
  1849.     optype0 = MEMOP;
  1850.   else
  1851.     optype0 = RNDOP;
  1852.  
  1853.   if (REG_P (op1))
  1854.     optype1 = REGOP;
  1855.   else if (CONSTANT_P (op1))
  1856.     optype1 = CNSTOP;
  1857.   else if (offsettable_memref_p (op1))
  1858.     optype1 = OFFSOP;
  1859.   else if (GET_CODE (op1) == MEM)
  1860.     optype1 = MEMOP;
  1861.   else
  1862.     optype1 = RNDOP;
  1863.  
  1864.   /* Check for the cases that the operand constraints are not
  1865.      supposed to allow to happen.  Abort if we get one,
  1866.      because generating code for these cases is painful.  */
  1867.  
  1868.   if (optype0 == RNDOP || optype1 == RNDOP
  1869.       || (optype0 == MEM && optype1 == MEM))
  1870.     abort ();
  1871.  
  1872.   /* If an operand is an unoffsettable memory ref, find a register
  1873.      we can increment temporarily to make it refer to the later words.  */
  1874.  
  1875.   if (optype0 == MEMOP)
  1876.     addreg0 = find_addr_reg (XEXP (op0, 0));
  1877.  
  1878.   if (optype1 == MEMOP)
  1879.     addreg1 = find_addr_reg (XEXP (op1, 0));
  1880.  
  1881.   /* Ok, we can do one word at a time.
  1882.      Set up in wordpart the operands to use for each word of the arguments.  */
  1883.  
  1884.   if (optype0 == REGOP)
  1885.     {
  1886.       wordpart[0][0] = gen_rtx (REG, SImode, REGNO (op0) + 0);
  1887.       wordpart[1][0] = gen_rtx (REG, SImode, REGNO (op0) + 1);
  1888.       wordpart[2][0] = gen_rtx (REG, SImode, REGNO (op0) + 2);
  1889.       wordpart[3][0] = gen_rtx (REG, SImode, REGNO (op0) + 3);
  1890.     }
  1891.   else if (optype0 == OFFSOP)
  1892.     {
  1893.       wordpart[0][0] = adj_offsettable_operand (op0, 0);
  1894.       wordpart[1][0] = adj_offsettable_operand (op0, 4);
  1895.       wordpart[2][0] = adj_offsettable_operand (op0, 8);
  1896.       wordpart[3][0] = adj_offsettable_operand (op0, 12);
  1897.     }
  1898.   else
  1899.     {
  1900.       wordpart[0][0] = op0;
  1901.       wordpart[1][0] = op0;
  1902.       wordpart[2][0] = op0;
  1903.       wordpart[3][0] = op0;
  1904.     }
  1905.  
  1906.   if (optype1 == REGOP)
  1907.     {
  1908.       wordpart[0][1] = gen_rtx (REG, SImode, REGNO (op1) + 0);
  1909.       wordpart[1][1] = gen_rtx (REG, SImode, REGNO (op1) + 1);
  1910.       wordpart[2][1] = gen_rtx (REG, SImode, REGNO (op1) + 2);
  1911.       wordpart[3][1] = gen_rtx (REG, SImode, REGNO (op1) + 3);
  1912.     }
  1913.   else if (optype1 == OFFSOP)
  1914.     {
  1915.       wordpart[0][1] = adj_offsettable_operand (op1, 0);
  1916.       wordpart[1][1] = adj_offsettable_operand (op1, 4);
  1917.       wordpart[2][1] = adj_offsettable_operand (op1, 8);
  1918.       wordpart[3][1] = adj_offsettable_operand (op1, 12);
  1919.     }
  1920.   else if (optype1 == CNSTOP)
  1921.     {
  1922.       REAL_VALUE_TYPE r;
  1923.       long l[4];
  1924.  
  1925.       /* This only works for TFmode floating point constants.  */
  1926.       if (GET_CODE (op1) != CONST_DOUBLE || GET_MODE (op1) != TFmode)
  1927.     abort ();
  1928.  
  1929.       REAL_VALUE_FROM_CONST_DOUBLE (r, op1);
  1930.       REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
  1931.       
  1932.       wordpart[0][1] = GEN_INT (l[0]);
  1933.       wordpart[1][1] = GEN_INT (l[1]);
  1934.       wordpart[2][1] = GEN_INT (l[2]);
  1935.       wordpart[3][1] = GEN_INT (l[3]);
  1936.     }
  1937.   else
  1938.     {
  1939.       wordpart[0][1] = op1;
  1940.       wordpart[1][1] = op1;
  1941.       wordpart[2][1] = op1;
  1942.       wordpart[3][1] = op1;
  1943.     }
  1944.  
  1945.   /* Easy case: try moving the quad as two pairs.  Check for moving between
  1946.      an even/odd register pair and a memory location.
  1947.      Also handle new v9 fp regs here.  */
  1948.   /* ??? Should also handle the case of non-offsettable addresses here.
  1949.      We can at least do the first pair as a ldd/std, and then do the third
  1950.      and fourth words individually.  */
  1951.   if ((optype0 == REGOP && optype1 == OFFSOP && (REGNO (op0) & 1) == 0)
  1952.       || (optype0 == OFFSOP && optype1 == REGOP && (REGNO (op1) & 1) == 0))
  1953.     {
  1954.       rtx mem, reg;
  1955.  
  1956.       if (optype0 == REGOP)
  1957.     mem = op1, reg = op0;
  1958.       else
  1959.     mem = op0, reg = op1;
  1960.  
  1961.       if (mem_aligned_8 (mem)
  1962.       /* If this is a floating point register higher than %f31,
  1963.          then we *must* use an aligned load, since `ld' will not accept
  1964.          the register number.  */
  1965.       || (TARGET_V9 && REGNO (reg) >= 64))
  1966.     {
  1967.       if (TARGET_V9 && FP_REG_P (reg))
  1968.         {
  1969.           if ((REGNO (reg) & 3) != 0)
  1970.         abort ();
  1971.           return (mem == op1 ? "ldq %1,%0" : "stq %1,%0");
  1972.         }
  1973.       operands[2] = adj_offsettable_operand (mem, 8);
  1974.       if (mem == op1)
  1975.         return TARGET_V9 ? "ldx %1,%0;ldx %2,%R0" : "ldd %1,%0;ldd %2,%S0";
  1976.       else
  1977.         return TARGET_V9 ? "stx %1,%0;stx %R1,%2" : "std %1,%0;std %S1,%2";
  1978.     }
  1979.     }
  1980.  
  1981.   /* If the first move would clobber the source of the second one,
  1982.      do them in the other order.  */
  1983.  
  1984.   /* Overlapping registers.  */
  1985.   if (optype0 == REGOP && optype1 == REGOP
  1986.       && (REGNO (op0) == REGNO (wordpart[1][3])
  1987.       || REGNO (op0) == REGNO (wordpart[1][2])
  1988.       || REGNO (op0) == REGNO (wordpart[1][1])))
  1989.     {
  1990.       /* Do fourth word.  */
  1991.       output_asm_insn (singlemove_string (wordpart[3]), wordpart[3]);
  1992.       /* Do the third word.  */
  1993.       output_asm_insn (singlemove_string (wordpart[2]), wordpart[2]);
  1994.       /* Do the second word.  */
  1995.       output_asm_insn (singlemove_string (wordpart[1]), wordpart[1]);
  1996.       /* Do lowest-numbered word.  */
  1997.       return singlemove_string (wordpart[0]);
  1998.     }
  1999.   /* Loading into a register which overlaps a register used in the address.  */
  2000.   if (optype0 == REGOP && optype1 != REGOP
  2001.       && reg_overlap_mentioned_p (op0, op1))
  2002.     {
  2003.       /* ??? Not implemented yet.  This is a bit complicated, because we
  2004.      must load which ever part overlaps the address last.  If the address
  2005.      is a double-reg address, then there are two parts which need to
  2006.      be done last, which is impossible.  We would need a scratch register
  2007.      in that case.  */
  2008.       abort ();
  2009.     }
  2010.  
  2011.   /* Normal case: move the four words in lowest to highest address order.  */
  2012.  
  2013.   output_asm_insn (singlemove_string (wordpart[0]), wordpart[0]);
  2014.  
  2015.   /* Make any unoffsettable addresses point at the second word.  */
  2016.   if (addreg0)
  2017.     output_asm_insn ("add %0,0x4,%0", &addreg0);
  2018.   if (addreg1)
  2019.     output_asm_insn ("add %0,0x4,%0", &addreg1);
  2020.  
  2021.   /* Do the second word.  */
  2022.   output_asm_insn (singlemove_string (wordpart[1]), wordpart[1]);
  2023.  
  2024.   /* Make any unoffsettable addresses point at the third word.  */
  2025.   if (addreg0)
  2026.     output_asm_insn ("add %0,0x4,%0", &addreg0);
  2027.   if (addreg1)
  2028.     output_asm_insn ("add %0,0x4,%0", &addreg1);
  2029.  
  2030.   /* Do the third word.  */
  2031.   output_asm_insn (singlemove_string (wordpart[2]), wordpart[2]);
  2032.  
  2033.   /* Make any unoffsettable addresses point at the fourth word.  */
  2034.   if (addreg0)
  2035.     output_asm_insn ("add %0,0x4,%0", &addreg0);
  2036.   if (addreg1)
  2037.     output_asm_insn ("add %0,0x4,%0", &addreg1);
  2038.  
  2039.   /* Do the fourth word.  */
  2040.   output_asm_insn (singlemove_string (wordpart[3]), wordpart[3]);
  2041.  
  2042.   /* Undo the adds we just did.  */
  2043.   if (addreg0)
  2044.     output_asm_insn ("add %0,-0xc,%0", &addreg0);
  2045.   if (addreg1)
  2046.     output_asm_insn ("add %0,-0xc,%0", &addreg1);
  2047.  
  2048.   return "";
  2049. }
  2050.  
  2051. /* Output assembler code to perform a doubleword move insn with operands
  2052.    OPERANDS, one of which must be a floating point register.  */
  2053.  
  2054. char *
  2055. output_fp_move_double (operands)
  2056.      rtx *operands;
  2057. {
  2058.   if (FP_REG_P (operands[0]))
  2059.     {
  2060.       if (FP_REG_P (operands[1]))
  2061.     {
  2062.       if (TARGET_V9)
  2063.         return "fmovd %1,%0";
  2064.       else
  2065.         return "fmovs %1,%0\n\tfmovs %R1,%R0";
  2066.     }
  2067.       else if (GET_CODE (operands[1]) == REG)
  2068.     abort ();
  2069.       else
  2070.     return output_move_double (operands);
  2071.     }
  2072.   else if (FP_REG_P (operands[1]))
  2073.     {
  2074.       if (GET_CODE (operands[0]) == REG)
  2075.     abort ();
  2076.       else
  2077.     return output_move_double (operands);
  2078.     }
  2079.   else abort ();
  2080. }
  2081.  
  2082. /* Output assembler code to perform a quadword move insn with operands
  2083.    OPERANDS, one of which must be a floating point register.  */
  2084.  
  2085. char *
  2086. output_fp_move_quad (operands)
  2087.      rtx *operands;
  2088. {
  2089.   register rtx op0 = operands[0];
  2090.   register rtx op1 = operands[1];
  2091.  
  2092.   if (FP_REG_P (op0))
  2093.     {
  2094.       if (FP_REG_P (op1))
  2095.     {
  2096.       if (TARGET_V9)
  2097.         return "fmovq %1,%0";
  2098.       else
  2099.         return "fmovs %1,%0\n\tfmovs %R1,%R0\n\tfmovs %S1,%S0\n\tfmovs %T1,%T0";
  2100.     }
  2101.       else if (GET_CODE (op1) == REG)
  2102.     abort ();
  2103.       else
  2104.     return output_move_quad (operands);
  2105.     }
  2106.   else if (FP_REG_P (op1))
  2107.     {
  2108.       if (GET_CODE (op0) == REG)
  2109.     abort ();
  2110.       else
  2111.     return output_move_quad (operands);
  2112.     }
  2113.   else
  2114.     abort ();
  2115. }
  2116.  
  2117. /* Return a REG that occurs in ADDR with coefficient 1.
  2118.    ADDR can be effectively incremented by incrementing REG.  */
  2119.  
  2120. static rtx
  2121. find_addr_reg (addr)
  2122.      rtx addr;
  2123. {
  2124.   while (GET_CODE (addr) == PLUS)
  2125.     {
  2126.       /* We absolutely can not fudge the frame pointer here, because the
  2127.      frame pointer must always be 8 byte aligned.  It also confuses
  2128.      debuggers.  */
  2129.       if (GET_CODE (XEXP (addr, 0)) == REG
  2130.       && REGNO (XEXP (addr, 0)) != FRAME_POINTER_REGNUM)
  2131.     addr = XEXP (addr, 0);
  2132.       else if (GET_CODE (XEXP (addr, 1)) == REG
  2133.            && REGNO (XEXP (addr, 1)) != FRAME_POINTER_REGNUM)
  2134.     addr = XEXP (addr, 1);
  2135.       else if (CONSTANT_P (XEXP (addr, 0)))
  2136.     addr = XEXP (addr, 1);
  2137.       else if (CONSTANT_P (XEXP (addr, 1)))
  2138.     addr = XEXP (addr, 0);
  2139.       else
  2140.     abort ();
  2141.     }
  2142.   if (GET_CODE (addr) == REG)
  2143.     return addr;
  2144.   abort ();
  2145. }
  2146.  
  2147. #if 0 /* not currently used */
  2148.  
  2149. void
  2150. output_sized_memop (opname, mode, signedp)
  2151.      char *opname;
  2152.      enum machine_mode mode;
  2153.      int signedp;
  2154. {
  2155.   static char *ld_size_suffix_u[] = { "ub", "uh", "", "?", "d" };
  2156.   static char *ld_size_suffix_s[] = { "sb", "sh", "", "?", "d" };
  2157.   static char *st_size_suffix[] = { "b", "h", "", "?", "d" };
  2158.   char **opnametab, *modename;
  2159.  
  2160.   if (opname[0] == 'l')
  2161.     if (signedp)
  2162.       opnametab = ld_size_suffix_s;
  2163.     else
  2164.       opnametab = ld_size_suffix_u;
  2165.   else
  2166.     opnametab = st_size_suffix;
  2167.   modename = opnametab[GET_MODE_SIZE (mode) >> 1];
  2168.  
  2169.   fprintf (asm_out_file, "\t%s%s", opname, modename);
  2170. }
  2171.  
  2172. void
  2173. output_move_with_extension (operands)
  2174.      rtx *operands;
  2175. {
  2176.   if (GET_MODE (operands[2]) == HImode)
  2177.     output_asm_insn ("sll %2,0x10,%0", operands);
  2178.   else if (GET_MODE (operands[2]) == QImode)
  2179.     output_asm_insn ("sll %2,0x18,%0", operands);
  2180.   else
  2181.     abort ();
  2182. }
  2183. #endif /* not currently used */
  2184.  
  2185. #if 0
  2186. /* ??? These are only used by the movstrsi pattern, but we get better code
  2187.    in general without that, because emit_block_move can do just as good a
  2188.    job as this function does when alignment and size are known.  When they
  2189.    aren't known, a call to strcpy may be faster anyways, because it is
  2190.    likely to be carefully crafted assembly language code, and below we just
  2191.    do a byte-wise copy.
  2192.  
  2193.    Also, emit_block_move expands into multiple read/write RTL insns, which
  2194.    can then be optimized, whereas our movstrsi pattern can not be optimized
  2195.    at all.  */
  2196.  
  2197. /* Load the address specified by OPERANDS[3] into the register
  2198.    specified by OPERANDS[0].
  2199.  
  2200.    OPERANDS[3] may be the result of a sum, hence it could either be:
  2201.  
  2202.    (1) CONST
  2203.    (2) REG
  2204.    (2) REG + CONST_INT
  2205.    (3) REG + REG + CONST_INT
  2206.    (4) REG + REG  (special case of 3).
  2207.  
  2208.    Note that (3) is not a legitimate address.
  2209.    All cases are handled here.  */
  2210.  
  2211. void
  2212. output_load_address (operands)
  2213.      rtx *operands;
  2214. {
  2215.   rtx base, offset;
  2216.  
  2217.   if (CONSTANT_P (operands[3]))
  2218.     {
  2219.       output_asm_insn ("set %3,%0", operands);
  2220.       return;
  2221.     }
  2222.  
  2223.   if (REG_P (operands[3]))
  2224.     {
  2225.       if (REGNO (operands[0]) != REGNO (operands[3]))
  2226.     output_asm_insn ("mov %3,%0", operands);
  2227.       return;
  2228.     }
  2229.  
  2230.   if (GET_CODE (operands[3]) != PLUS)
  2231.     abort ();
  2232.  
  2233.   base = XEXP (operands[3], 0);
  2234.   offset = XEXP (operands[3], 1);
  2235.  
  2236.   if (GET_CODE (base) == CONST_INT)
  2237.     {
  2238.       rtx tmp = base;
  2239.       base = offset;
  2240.       offset = tmp;
  2241.     }
  2242.  
  2243.   if (GET_CODE (offset) != CONST_INT)
  2244.     {
  2245.       /* Operand is (PLUS (REG) (REG)).  */
  2246.       base = operands[3];
  2247.       offset = const0_rtx;
  2248.     }
  2249.  
  2250.   if (REG_P (base))
  2251.     {
  2252.       operands[6] = base;
  2253.       operands[7] = offset;
  2254.       if (SMALL_INT (offset))
  2255.     output_asm_insn ("add %6,%7,%0", operands);
  2256.       else
  2257.     output_asm_insn ("set %7,%0\n\tadd %0,%6,%0", operands);
  2258.     }
  2259.   else if (GET_CODE (base) == PLUS)
  2260.     {
  2261.       operands[6] = XEXP (base, 0);
  2262.       operands[7] = XEXP (base, 1);
  2263.       operands[8] = offset;
  2264.  
  2265.       if (SMALL_INT (offset))
  2266.     output_asm_insn ("add %6,%7,%0\n\tadd %0,%8,%0", operands);
  2267.       else
  2268.     output_asm_insn ("set %8,%0\n\tadd %0,%6,%0\n\tadd %0,%7,%0", operands);
  2269.     }
  2270.   else
  2271.     abort ();
  2272. }
  2273.  
  2274. /* Output code to place a size count SIZE in register REG.
  2275.    ALIGN is the size of the unit of transfer.
  2276.  
  2277.    Because block moves are pipelined, we don't include the
  2278.    first element in the transfer of SIZE to REG.  */
  2279.  
  2280. static void
  2281. output_size_for_block_move (size, reg, align)
  2282.      rtx size, reg;
  2283.      rtx align;
  2284. {
  2285.   rtx xoperands[3];
  2286.  
  2287.   xoperands[0] = reg;
  2288.   xoperands[1] = size;
  2289.   xoperands[2] = align;
  2290.   if (GET_CODE (size) == REG)
  2291.     output_asm_insn ("sub %1,%2,%0", xoperands);
  2292.   else
  2293.     {
  2294.       xoperands[1]
  2295.     = gen_rtx (CONST_INT, VOIDmode, INTVAL (size) - INTVAL (align));
  2296.       output_asm_insn ("set %1,%0", xoperands);
  2297.     }
  2298. }
  2299.  
  2300. /* Emit code to perform a block move.
  2301.  
  2302.    OPERANDS[0] is the destination.
  2303.    OPERANDS[1] is the source.
  2304.    OPERANDS[2] is the size.
  2305.    OPERANDS[3] is the alignment safe to use.
  2306.    OPERANDS[4] is a register we can safely clobber as a temp.  */
  2307.  
  2308. char *
  2309. output_block_move (operands)
  2310.      rtx *operands;
  2311. {
  2312.   /* A vector for our computed operands.  Note that load_output_address
  2313.      makes use of (and can clobber) up to the 8th element of this vector.  */
  2314.   rtx xoperands[10];
  2315.   rtx zoperands[10];
  2316.   static int movstrsi_label = 0;
  2317.   int i;
  2318.   rtx temp1 = operands[4];
  2319.   rtx sizertx = operands[2];
  2320.   rtx alignrtx = operands[3];
  2321.   int align = INTVAL (alignrtx);
  2322.   char label3[30], label5[30];
  2323.  
  2324.   xoperands[0] = operands[0];
  2325.   xoperands[1] = operands[1];
  2326.   xoperands[2] = temp1;
  2327.  
  2328.   /* We can't move more than this many bytes at a time because we have only
  2329.      one register, %g1, to move them through.  */
  2330.   if (align > UNITS_PER_WORD)
  2331.     {
  2332.       align = UNITS_PER_WORD;
  2333.       alignrtx = gen_rtx (CONST_INT, VOIDmode, UNITS_PER_WORD);
  2334.     }
  2335.  
  2336.   /* We consider 8 ld/st pairs, for a total of 16 inline insns to be
  2337.      reasonable here.  (Actually will emit a maximum of 18 inline insns for
  2338.      the case of size == 31 and align == 4).  */
  2339.  
  2340.   if (GET_CODE (sizertx) == CONST_INT && (INTVAL (sizertx) / align) <= 8
  2341.       && memory_address_p (QImode, plus_constant_for_output (xoperands[0],
  2342.                                  INTVAL (sizertx)))
  2343.       && memory_address_p (QImode, plus_constant_for_output (xoperands[1],
  2344.                                  INTVAL (sizertx))))
  2345.     {
  2346.       int size = INTVAL (sizertx);
  2347.       int offset = 0;
  2348.  
  2349.       /* We will store different integers into this particular RTX.  */
  2350.       xoperands[2] = rtx_alloc (CONST_INT);
  2351.       PUT_MODE (xoperands[2], VOIDmode);
  2352.  
  2353.       /* This case is currently not handled.  Abort instead of generating
  2354.      bad code.  */
  2355.       if (align > UNITS_PER_WORD)
  2356.     abort ();
  2357.  
  2358.       if (TARGET_V9 && align >= 8)
  2359.     {
  2360.       for (i = (size >> 3) - 1; i >= 0; i--)
  2361.         {
  2362.           INTVAL (xoperands[2]) = (i << 3) + offset;
  2363.           output_asm_insn ("ldx [%a1+%2],%%g1\n\tstx %%g1,[%a0+%2]",
  2364.                    xoperands);
  2365.         }
  2366.       offset += (size & ~0x7);
  2367.       size = size & 0x7;
  2368.       if (size == 0)
  2369.         return "";
  2370.     }
  2371.  
  2372.       if (align >= 4)
  2373.     {
  2374.       for (i = (size >> 2) - 1; i >= 0; i--)
  2375.         {
  2376.           INTVAL (xoperands[2]) = (i << 2) + offset;
  2377.           output_asm_insn ("ld [%a1+%2],%%g1\n\tst %%g1,[%a0+%2]",
  2378.                    xoperands);
  2379.         }
  2380.       offset += (size & ~0x3);
  2381.       size = size & 0x3;
  2382.       if (size == 0)
  2383.         return "";
  2384.     }
  2385.  
  2386.       if (align >= 2)
  2387.     {
  2388.       for (i = (size >> 1) - 1; i >= 0; i--)
  2389.         {
  2390.           INTVAL (xoperands[2]) = (i << 1) + offset;
  2391.           output_asm_insn ("lduh [%a1+%2],%%g1\n\tsth %%g1,[%a0+%2]",
  2392.                    xoperands);
  2393.         }
  2394.       offset += (size & ~0x1);
  2395.       size = size & 0x1;
  2396.       if (size == 0)
  2397.         return "";
  2398.     }
  2399.  
  2400.       if (align >= 1)
  2401.     {
  2402.       for (i = size - 1; i >= 0; i--)
  2403.         {
  2404.           INTVAL (xoperands[2]) = i + offset;
  2405.           output_asm_insn ("ldub [%a1+%2],%%g1\n\tstb %%g1,[%a0+%2]",
  2406.                    xoperands);
  2407.         }
  2408.       return "";
  2409.     }
  2410.  
  2411.       /* We should never reach here.  */
  2412.       abort ();
  2413.     }
  2414.  
  2415.   /* If the size isn't known to be a multiple of the alignment,
  2416.      we have to do it in smaller pieces.  If we could determine that
  2417.      the size was a multiple of 2 (or whatever), we could be smarter
  2418.      about this.  */
  2419.   if (GET_CODE (sizertx) != CONST_INT)
  2420.     align = 1;
  2421.   else
  2422.     {
  2423.       int size = INTVAL (sizertx);
  2424.       while (size % align)
  2425.     align >>= 1;
  2426.     }
  2427.  
  2428.   if (align != INTVAL (alignrtx))
  2429.     alignrtx = gen_rtx (CONST_INT, VOIDmode, align);
  2430.  
  2431.   xoperands[3] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++);
  2432.   xoperands[4] = gen_rtx (CONST_INT, VOIDmode, align);
  2433.   xoperands[5] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++);
  2434.  
  2435.   ASM_GENERATE_INTERNAL_LABEL (label3, "Lm", INTVAL (xoperands[3]));
  2436.   ASM_GENERATE_INTERNAL_LABEL (label5, "Lm", INTVAL (xoperands[5]));
  2437.  
  2438.   /* This is the size of the transfer.  Emit code to decrement the size
  2439.      value by ALIGN, and store the result in the temp1 register.  */
  2440.   output_size_for_block_move (sizertx, temp1, alignrtx);
  2441.  
  2442.   /* Must handle the case when the size is zero or negative, so the first thing
  2443.      we do is compare the size against zero, and only copy bytes if it is
  2444.      zero or greater.  Note that we have already subtracted off the alignment
  2445.      once, so we must copy 1 alignment worth of bytes if the size is zero
  2446.      here.
  2447.  
  2448.      The SUN assembler complains about labels in branch delay slots, so we
  2449.      do this before outputting the load address, so that there will always
  2450.      be a harmless insn between the branch here and the next label emitted
  2451.      below.  */
  2452.  
  2453.   {
  2454.     char pattern[100];
  2455.  
  2456.     sprintf (pattern, "cmp %%2,0\n\tbl %s", &label5[1]);
  2457.     output_asm_insn (pattern, xoperands);
  2458.   }
  2459.  
  2460.   zoperands[0] = operands[0];
  2461.   zoperands[3] = plus_constant_for_output (operands[0], align);
  2462.   output_load_address (zoperands);
  2463.  
  2464.   /* ??? This might be much faster if the loops below were preconditioned
  2465.      and unrolled.
  2466.  
  2467.      That is, at run time, copy enough bytes one at a time to ensure that the
  2468.      target and source addresses are aligned to the the largest possible
  2469.      alignment.  Then use a preconditioned unrolled loop to copy say 16
  2470.      bytes at a time.  Then copy bytes one at a time until finish the rest.  */
  2471.  
  2472.   /* Output the first label separately, so that it is spaced properly.  */
  2473.  
  2474.   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "Lm", INTVAL (xoperands[3]));
  2475.  
  2476.   {
  2477.     char pattern[200];
  2478.     register char *ld_suffix = ((align == 1) ? "ub" : (align == 2) ? "uh"
  2479.                 : (align == 8 && TARGET_V9) ? "x" : "");
  2480.     register char *st_suffix = ((align == 1) ? "b" : (align == 2) ? "h"
  2481.                 : (align == 8 && TARGET_V9) ? "x" : "");
  2482.  
  2483.     sprintf (pattern, "ld%s [%%1+%%2],%%%%g1\n\tsubcc %%2,%%4,%%2\n\tbge %s\n\tst%s %%%%g1,[%%0+%%2]\n%s:", ld_suffix, &label3[1], st_suffix, &label5[1]);
  2484.     output_asm_insn (pattern, xoperands);
  2485.   }
  2486.  
  2487.   return "";
  2488. }
  2489. #endif
  2490.  
  2491. /* Output reasonable peephole for set-on-condition-code insns.
  2492.    Note that these insns assume a particular way of defining
  2493.    labels.  Therefore, *both* sparc.h and this function must
  2494.    be changed if a new syntax is needed.    */
  2495.  
  2496. char *
  2497. output_scc_insn (operands, insn)
  2498.      rtx operands[];
  2499.      rtx insn;
  2500. {
  2501.   static char string[100];
  2502.   rtx label = 0, next = insn;
  2503.   int need_label = 0;
  2504.  
  2505.   /* Try doing a jump optimization which jump.c can't do for us
  2506.      because we did not expose that setcc works by using branches.
  2507.  
  2508.      If this scc insn is followed by an unconditional branch, then have
  2509.      the jump insn emitted here jump to that location, instead of to
  2510.      the end of the scc sequence as usual.  */
  2511.  
  2512.   do
  2513.     {
  2514.       if (GET_CODE (next) == CODE_LABEL)
  2515.     label = next;
  2516.       next = NEXT_INSN (next);
  2517.       if (next == 0)
  2518.     break;
  2519.     }
  2520.   while (GET_CODE (next) == NOTE || GET_CODE (next) == CODE_LABEL);
  2521.  
  2522.   /* If we are in a sequence, and the following insn is a sequence also,
  2523.      then just following the current insn's next field will take us to the
  2524.      first insn of the next sequence, which is the wrong place.  We don't
  2525.      want to optimize with a branch that has had its delay slot filled.
  2526.      Avoid this by verifying that NEXT_INSN (PREV_INSN (next)) == next
  2527.      which fails only if NEXT is such a branch.  */
  2528.  
  2529.   if (next && GET_CODE (next) == JUMP_INSN && simplejump_p (next)
  2530.       && (! final_sequence || NEXT_INSN (PREV_INSN (next)) == next))
  2531.     label = JUMP_LABEL (next);
  2532.   /* If not optimizing, jump label fields are not set.  To be safe, always
  2533.      check here to whether label is still zero.  */
  2534.   if (label == 0)
  2535.     {
  2536.       label = gen_label_rtx ();
  2537.       need_label = 1;
  2538.     }
  2539.  
  2540.   LABEL_NUSES (label) += 1;
  2541.  
  2542.   operands[2] = label;
  2543.  
  2544.   /* If we are in a delay slot, assume it is the delay slot of an fpcc
  2545.      insn since our type isn't allowed anywhere else.  */
  2546.  
  2547.   /* ??? Fpcc instructions no longer have delay slots, so this code is
  2548.      probably obsolete.  */
  2549.  
  2550.   /* The fastest way to emit code for this is an annulled branch followed
  2551.      by two move insns.  This will take two cycles if the branch is taken,
  2552.      and three cycles if the branch is not taken.
  2553.  
  2554.      However, if we are in the delay slot of another branch, this won't work,
  2555.      because we can't put a branch in the delay slot of another branch.
  2556.      The above sequence would effectively take 3 or 4 cycles respectively
  2557.      since a no op would have be inserted between the two branches.
  2558.      In this case, we want to emit a move, annulled branch, and then the
  2559.      second move.  This sequence always takes 3 cycles, and hence is faster
  2560.      when we are in a branch delay slot.  */
  2561.  
  2562.   if (final_sequence)
  2563.     {
  2564.       strcpy (string, "mov 0,%0\n\t");
  2565.       strcat (string, output_cbranch (operands[1], 0, 2, 0, 1, 0));
  2566.       strcat (string, "\n\tmov 1,%0");
  2567.     }
  2568.   else
  2569.     {
  2570.       strcpy (string, output_cbranch (operands[1], 0, 2, 0, 1, 0));
  2571.       strcat (string, "\n\tmov 1,%0\n\tmov 0,%0");
  2572.     }
  2573.  
  2574.   if (need_label)
  2575.     strcat (string, "\n%l2:");
  2576.  
  2577.   return string;
  2578. }
  2579.  
  2580. /* Vectors to keep interesting information about registers where it can easily
  2581.    be got.  We use to use the actual mode value as the bit number, but there
  2582.    are more than 32 modes now.  Instead we use two tables: one indexed by
  2583.    hard register number, and one indexed by mode.  */
  2584.  
  2585. /* The purpose of sparc_mode_class is to shrink the range of modes so that
  2586.    they all fit (as bit numbers) in a 32 bit word (again).  Each real mode is
  2587.    mapped into one sparc_mode_class mode.  */
  2588.  
  2589. enum sparc_mode_class {
  2590.   C_MODE, CCFP_MODE,
  2591.   S_MODE, D_MODE, T_MODE, O_MODE,
  2592.   SF_MODE, DF_MODE, TF_MODE, OF_MODE
  2593. };
  2594.  
  2595. /* Modes for condition codes.  */
  2596. #define C_MODES ((1 << (int) C_MODE) | (1 << (int) CCFP_MODE))
  2597. #define CCFP_MODES (1 << (int) CCFP_MODE)
  2598.  
  2599. /* Modes for single-word and smaller quantities.  */
  2600. #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
  2601.  
  2602. /* Modes for double-word and smaller quantities.  */
  2603. #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
  2604.  
  2605. /* Modes for quad-word and smaller quantities.  */
  2606. #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
  2607.  
  2608. /* Modes for single-float quantities.  We must allow any single word or
  2609.    smaller quantity.  This is because the fix/float conversion instructions
  2610.    take integer inputs/outputs from the float registers.  */
  2611. #define SF_MODES (S_MODES)
  2612.  
  2613. /* Modes for double-float and smaller quantities.  */
  2614. #define DF_MODES (S_MODES | D_MODES)
  2615.  
  2616. /* ??? Sparc64 fp regs cannot hold DImode values.  */
  2617. #define DF_MODES64 (SF_MODES | DF_MODE /* | D_MODE*/)
  2618.  
  2619. /* Modes for double-float only quantities.  */
  2620. /* ??? Sparc64 fp regs cannot hold DImode values.  */
  2621. #define DF_ONLY_MODES ((1 << (int) DF_MODE) /*| (1 << (int) D_MODE)*/)
  2622.  
  2623. /* Modes for double-float and larger quantities.  */
  2624. #define DF_UP_MODES (DF_ONLY_MODES | TF_ONLY_MODES)
  2625.  
  2626. /* Modes for quad-float only quantities.  */
  2627. #define TF_ONLY_MODES (1 << (int) TF_MODE)
  2628.  
  2629. /* Modes for quad-float and smaller quantities.  */
  2630. #define TF_MODES (DF_MODES | TF_ONLY_MODES)
  2631.  
  2632. /* ??? Sparc64 fp regs cannot hold DImode values.  */
  2633. #define TF_MODES64 (DF_MODES64 | TF_ONLY_MODES)
  2634.  
  2635. /* Value is 1 if register/mode pair is acceptable on sparc.
  2636.    The funny mixture of D and T modes is because integer operations
  2637.    do not specially operate on tetra quantities, so non-quad-aligned
  2638.    registers can hold quadword quantities (except %o4 and %i4 because
  2639.    they cross fixed registers.  */
  2640.  
  2641. /* This points to either the 32 bit or the 64 bit version.  */
  2642. int *hard_regno_mode_classes;
  2643.  
  2644. static int hard_32bit_mode_classes[] = {
  2645.   C_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
  2646.   T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
  2647.   T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
  2648.   T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES,
  2649.  
  2650.   TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
  2651.   TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
  2652.   TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
  2653.   TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES,
  2654. };
  2655.  
  2656. static int hard_64bit_mode_classes[] = {
  2657.   C_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
  2658.   T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
  2659.   T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
  2660.   T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES, T_MODES, D_MODES,
  2661.  
  2662.   TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, TF_MODES64, SF_MODES, DF_MODES64, SF_MODES,
  2663.   TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, TF_MODES64, SF_MODES, DF_MODES64, SF_MODES,
  2664.   TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, TF_MODES64, SF_MODES, DF_MODES64, SF_MODES,
  2665.   TF_MODES64, SF_MODES, DF_MODES64, SF_MODES, TF_MODES64, SF_MODES, DF_MODES64, SF_MODES,
  2666.  
  2667.   /* The remaining registers do not exist on a non-v9 sparc machine.
  2668.      FP regs f32 to f63.  Only the even numbered registers actually exist,
  2669.      and none can hold SFmode/SImode values.  */
  2670.   DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0,
  2671.   DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0,
  2672.   DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0,
  2673.   DF_UP_MODES, 0, DF_ONLY_MODES, 0, DF_UP_MODES, 0, DF_ONLY_MODES, 0,
  2674.  
  2675.   /* %fcc[0123] */
  2676.   CCFP_MODE, CCFP_MODE, CCFP_MODE, CCFP_MODE
  2677. };
  2678.  
  2679. int sparc_mode_class [NUM_MACHINE_MODES];
  2680.  
  2681. static void
  2682. sparc_init_modes ()
  2683. {
  2684.   int i;
  2685.  
  2686.   sparc_arch_type = TARGET_V9 ? ARCH_64BIT : ARCH_32BIT;
  2687.  
  2688.   for (i = 0; i < NUM_MACHINE_MODES; i++)
  2689.     {
  2690.       switch (GET_MODE_CLASS (i))
  2691.     {
  2692.     case MODE_INT:
  2693.     case MODE_PARTIAL_INT:
  2694.     case MODE_COMPLEX_INT:
  2695.       if (GET_MODE_SIZE (i) <= 4)
  2696.         sparc_mode_class[i] = 1 << (int) S_MODE;
  2697.       else if (GET_MODE_SIZE (i) == 8)
  2698.         sparc_mode_class[i] = 1 << (int) D_MODE;
  2699.       else if (GET_MODE_SIZE (i) == 16)
  2700.         sparc_mode_class[i] = 1 << (int) T_MODE;
  2701.       else if (GET_MODE_SIZE (i) == 32)
  2702.         sparc_mode_class[i] = 1 << (int) O_MODE;
  2703.       else 
  2704.         sparc_mode_class[i] = 0;
  2705.       break;
  2706.     case MODE_FLOAT:
  2707.     case MODE_COMPLEX_FLOAT:
  2708.       if (GET_MODE_SIZE (i) <= 4)
  2709.         sparc_mode_class[i] = 1 << (int) SF_MODE;
  2710.       else if (GET_MODE_SIZE (i) == 8)
  2711.         sparc_mode_class[i] = 1 << (int) DF_MODE;
  2712.       else if (GET_MODE_SIZE (i) == 16)
  2713.         sparc_mode_class[i] = 1 << (int) TF_MODE;
  2714.       else if (GET_MODE_SIZE (i) == 32)
  2715.         sparc_mode_class[i] = 1 << (int) OF_MODE;
  2716.       else 
  2717.         sparc_mode_class[i] = 0;
  2718.       break;
  2719.     case MODE_CC:
  2720.     default:
  2721.       /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so
  2722.          we must explicitly check for them here.  */
  2723.       if (i == (int) CCFPmode || i == (int) CCFPEmode)
  2724.         sparc_mode_class[i] = 1 << (int) CCFP_MODE;
  2725.       else if (i == (int) CCmode || i == (int) CC_NOOVmode
  2726. #ifdef SPARCV9
  2727.            || i == (int) CCXmode
  2728.            || i == (int) CCX_NOOVmode
  2729. #endif
  2730.            )
  2731.         sparc_mode_class[i] = 1 << (int) C_MODE;
  2732.       else
  2733.         sparc_mode_class[i] = 0;
  2734.       break;
  2735.     }
  2736.     }
  2737.  
  2738.   if (TARGET_V9)
  2739.     hard_regno_mode_classes = hard_64bit_mode_classes;
  2740.   else
  2741.     hard_regno_mode_classes = hard_32bit_mode_classes;
  2742. }
  2743.  
  2744. /* Save non call used registers from LOW to HIGH at BASE+OFFSET.
  2745.    N_REGS is the number of 4-byte regs saved thus far.  This applies even to
  2746.    v9 int regs as it simplifies the code.  */
  2747.  
  2748. #ifdef __GNUC__
  2749. __inline__
  2750. #endif
  2751. static int
  2752. save_regs (file, low, high, base, offset, n_regs)
  2753.      FILE *file;
  2754.      int low, high;
  2755.      char *base;
  2756.      int offset;
  2757.      int n_regs;
  2758. {
  2759.   int i;
  2760.  
  2761.   if (TARGET_V9 && high <= 32)
  2762.     {
  2763.       for (i = low; i < high; i++)
  2764.     {
  2765.       if (regs_ever_live[i] && ! call_used_regs[i])
  2766.         fprintf (file, "\tstx %s,[%s+%d]\n",
  2767.           reg_names[i], base, offset + 4 * n_regs),
  2768.         n_regs += 2;
  2769.     }
  2770.     }
  2771.   else
  2772.     {
  2773.       for (i = low; i < high; i += 2)
  2774.     {
  2775.       if (regs_ever_live[i] && ! call_used_regs[i])
  2776.         if (regs_ever_live[i+1] && ! call_used_regs[i+1])
  2777.           fprintf (file, "\tstd %s,[%s+%d]\n",
  2778.                reg_names[i], base, offset + 4 * n_regs),
  2779.           n_regs += 2;
  2780.         else
  2781.           fprintf (file, "\tst %s,[%s+%d]\n",
  2782.                reg_names[i], base, offset + 4 * n_regs),
  2783.           n_regs += 2;
  2784.       else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
  2785.         fprintf (file, "\tst %s,[%s+%d]\n",
  2786.              reg_names[i+1], base, offset + 4 * n_regs + 4),
  2787.         n_regs += 2;
  2788.     }
  2789.     }
  2790.   return n_regs;
  2791. }
  2792.  
  2793. /* Restore non call used registers from LOW to HIGH at BASE+OFFSET.
  2794.  
  2795.    N_REGS is the number of 4-byte regs saved thus far.  This applies even to
  2796.    v9 int regs as it simplifies the code.  */
  2797.  
  2798. #ifdef __GNUC__
  2799. __inline__
  2800. #endif
  2801. static int
  2802. restore_regs (file, low, high, base, offset, n_regs)
  2803.      FILE *file;
  2804.      int low, high;
  2805.      char *base;
  2806.      int offset;
  2807.      int n_regs;
  2808. {
  2809.   int i;
  2810.  
  2811.   if (TARGET_V9 && high <= 32)
  2812.     {
  2813.       for (i = low; i < high; i++)
  2814.     {
  2815.       if (regs_ever_live[i] && ! call_used_regs[i])
  2816.         fprintf (file, "\tldx [%s+%d], %s\n",
  2817.           base, offset + 4 * n_regs, reg_names[i]),
  2818.         n_regs += 2;
  2819.     }
  2820.     }
  2821.   else
  2822.     {
  2823.       for (i = low; i < high; i += 2)
  2824.     {
  2825.       if (regs_ever_live[i] && ! call_used_regs[i])
  2826.         if (regs_ever_live[i+1] && ! call_used_regs[i+1])
  2827.           fprintf (file, "\tldd [%s+%d], %s\n",
  2828.                base, offset + 4 * n_regs, reg_names[i]),
  2829.           n_regs += 2;
  2830.         else
  2831.           fprintf (file, "\tld [%s+%d],%s\n",
  2832.                base, offset + 4 * n_regs, reg_names[i]),
  2833.           n_regs += 2;
  2834.       else if (regs_ever_live[i+1] && ! call_used_regs[i+1])
  2835.         fprintf (file, "\tld [%s+%d],%s\n",
  2836.              base, offset + 4 * n_regs + 4, reg_names[i+1]),
  2837.         n_regs += 2;
  2838.     }
  2839.     }
  2840.   return n_regs;
  2841. }
  2842.  
  2843. /* Static variables we want to share between prologue and epilogue.  */
  2844.  
  2845. /* Number of live general or floating point registers needed to be saved
  2846.    (as 4-byte quantities).  This is only done if TARGET_EPILOGUE.  */
  2847. static int num_gfregs;
  2848.  
  2849. /* Compute the frame size required by the function.  This function is called
  2850.    during the reload pass and also by output_function_prologue().  */
  2851.  
  2852. int
  2853. compute_frame_size (size, leaf_function)
  2854.      int size;
  2855.      int leaf_function;
  2856. {
  2857.   int n_regs = 0, i;
  2858.   int outgoing_args_size = (current_function_outgoing_args_size
  2859. #ifndef SPARCV9
  2860.                 + REG_PARM_STACK_SPACE (current_function_decl)
  2861. #endif
  2862.                 );
  2863.  
  2864.   if (TARGET_EPILOGUE)
  2865.     {
  2866.       /* N_REGS is the number of 4-byte regs saved thus far.  This applies
  2867.      even to v9 int regs to be consistent with save_regs/restore_regs.  */
  2868.  
  2869.       if (TARGET_V9)
  2870.     {
  2871.       for (i = 0; i < 8; i++)
  2872.         if (regs_ever_live[i] && ! call_used_regs[i])
  2873.           n_regs += 2;
  2874.     }
  2875.       else
  2876.     {
  2877.       for (i = 0; i < 8; i += 2)
  2878.         if ((regs_ever_live[i] && ! call_used_regs[i])
  2879.         || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
  2880.           n_regs += 2;
  2881.     }
  2882.  
  2883.       for (i = 32; i < (TARGET_V9 ? 96 : 64); i += 2)
  2884.     if ((regs_ever_live[i] && ! call_used_regs[i])
  2885.         || (regs_ever_live[i+1] && ! call_used_regs[i+1]))
  2886.       n_regs += 2;
  2887.     }
  2888.  
  2889.   /* Set up values for use in `function_epilogue'.  */
  2890.   num_gfregs = n_regs;
  2891.  
  2892.   if (leaf_function && n_regs == 0
  2893.       && size == 0 && current_function_outgoing_args_size == 0)
  2894.     {
  2895.       actual_fsize = apparent_fsize = 0;
  2896.     }
  2897.   else
  2898.     {
  2899.       /* We subtract STARTING_FRAME_OFFSET, remember it's negative.
  2900.          The stack bias (if any) is taken out to undo its effects.  */
  2901.       apparent_fsize = (size - STARTING_FRAME_OFFSET + SPARC_STACK_BIAS + 7) & -8;
  2902.       apparent_fsize += n_regs * 4;
  2903.       actual_fsize = apparent_fsize + ((outgoing_args_size + 7) & -8);
  2904.     }
  2905.  
  2906.   /* Make sure nothing can clobber our register windows.
  2907.      If a SAVE must be done, or there is a stack-local variable,
  2908.      the register window area must be allocated.
  2909.      ??? For v9 we need an additional 8 bytes of reserved space, apparently
  2910.      it's needed by v8 as well.  */
  2911.   if (leaf_function == 0 || size > 0)
  2912.     actual_fsize += (16 * UNITS_PER_WORD) + 8;
  2913.  
  2914.   return SPARC_STACK_ALIGN (actual_fsize);
  2915. }
  2916.  
  2917. /* Build a (32 bit) big number in a register.  */
  2918. /* ??? We may be able to use the set macro here too.  */
  2919.  
  2920. static void
  2921. build_big_number (file, num, reg)
  2922.      FILE *file;
  2923.      int num;
  2924.      char *reg;
  2925. {
  2926.   if (num >= 0 || ! TARGET_V9)
  2927.     {
  2928.       fprintf (file, "\tsethi %%hi(%d),%s\n", num, reg);
  2929.       if ((num & 0x3ff) != 0)
  2930.     fprintf (file, "\tor %s,%%lo(%d),%s\n", reg, num, reg);
  2931.     }
  2932.   else /* num < 0 && TARGET_V9 */
  2933.     {
  2934.       /* Sethi does not sign extend, so we must use a little trickery
  2935.      to use it for negative numbers.  Invert the constant before
  2936.      loading it in, then use xor immediate to invert the loaded bits
  2937.      (along with the upper 32 bits) to the desired constant.  This
  2938.      works because the sethi and immediate fields overlap.  */
  2939.       int asize = num;
  2940.       int inv = ~asize;
  2941.       int low = -0x400 + (asize & 0x3FF);
  2942.       
  2943.       fprintf (file, "\tsethi %%hi(%d),%s\n\txor %s,%d,%s\n",
  2944.            inv, reg, reg, low, reg);
  2945.     }
  2946. }
  2947.  
  2948. /* Output code for the function prologue.  */
  2949.  
  2950. void
  2951. output_function_prologue (file, size, leaf_function)
  2952.      FILE *file;
  2953.      int size;
  2954.      int leaf_function;
  2955. {
  2956.   /* Need to use actual_fsize, since we are also allocating
  2957.      space for our callee (and our own register save area).  */
  2958.   actual_fsize = compute_frame_size (size, leaf_function);
  2959.  
  2960.   if (leaf_function)
  2961.     {
  2962.       frame_base_name = "%sp";
  2963.       frame_base_offset = actual_fsize + SPARC_STACK_BIAS;
  2964.     }
  2965.   else
  2966.     {
  2967.       frame_base_name = "%fp";
  2968.       frame_base_offset = SPARC_STACK_BIAS;
  2969.     }
  2970.  
  2971.   /* This is only for the human reader.  */
  2972.   fprintf (file, "\t!#PROLOGUE# 0\n");
  2973.  
  2974.   if (actual_fsize == 0)
  2975.     /* do nothing.  */ ;
  2976.   else if (actual_fsize <= 4096)
  2977.     {
  2978.       if (! leaf_function)
  2979.     fprintf (file, "\tsave %%sp,-%d,%%sp\n", actual_fsize);
  2980.       else
  2981.     fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize);
  2982.     }
  2983.   else if (actual_fsize <= 8192)
  2984.     {
  2985.       /* For frames in the range 4097..8192, we can use just two insns.  */
  2986.       if (! leaf_function)
  2987.     {
  2988.       fprintf (file, "\tsave %%sp,-4096,%%sp\n");
  2989.       fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize - 4096);
  2990.     }
  2991.       else
  2992.     {
  2993.       fprintf (file, "\tadd %%sp,-4096,%%sp\n");
  2994.       fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize - 4096);
  2995.     }
  2996.     }
  2997.   else
  2998.     {
  2999.       build_big_number (file, -actual_fsize, "%g1");
  3000.       if (! leaf_function)
  3001.     fprintf (file, "\tsave %%sp,%%g1,%%sp\n");
  3002.       else
  3003.     fprintf (file, "\tadd %%sp,%%g1,%%sp\n");
  3004.     }
  3005.  
  3006.   /* If doing anything with PIC, do it now.  */
  3007.   if (! flag_pic)
  3008.     fprintf (file, "\t!#PROLOGUE# 1\n");
  3009.  
  3010.   /* Call saved registers are saved just above the outgoing argument area.  */
  3011.   if (num_gfregs)
  3012.     {
  3013.       int offset, n_regs;
  3014.       char *base;
  3015.  
  3016.       offset = -apparent_fsize + frame_base_offset;
  3017.       if (offset < -4096 || offset + num_gfregs * 4 > 4096)
  3018.     {
  3019.       /* ??? This might be optimized a little as %g1 might already have a
  3020.          value close enough that a single add insn will do.  */
  3021.       /* ??? Although, all of this is probably only a temporary fix
  3022.          because if %g1 can hold a function result, then
  3023.          output_function_epilogue will lose (the result will get
  3024.          clobbered).  */
  3025.       build_big_number (file, offset, "%g1");
  3026.       fprintf (file, "\tadd %s,%%g1,%%g1\n", frame_base_name);
  3027.       base = "%g1";
  3028.       offset = 0;
  3029.     }
  3030.       else
  3031.     {
  3032.       base = frame_base_name;
  3033.     }
  3034.  
  3035.       if (TARGET_EPILOGUE && ! leaf_function)
  3036.     /* ??? Originally saved regs 0-15 here.  */
  3037.     n_regs = save_regs (file, 0, 8, base, offset, 0);
  3038.       else if (leaf_function)
  3039.     /* ??? Originally saved regs 0-31 here.  */
  3040.     n_regs = save_regs (file, 0, 8, base, offset, 0);
  3041.       if (TARGET_EPILOGUE)
  3042.     save_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs);
  3043.     }
  3044.  
  3045.   leaf_label = 0;
  3046.   if (leaf_function && actual_fsize != 0)
  3047.     {
  3048.       /* warning ("leaf procedure with frame size %d", actual_fsize); */
  3049.       if (! TARGET_EPILOGUE)
  3050.     leaf_label = gen_label_rtx ();
  3051.     }
  3052. }
  3053.  
  3054. /* Output code for the function epilogue.  */
  3055.  
  3056. void
  3057. output_function_epilogue (file, size, leaf_function)
  3058.      FILE *file;
  3059.      int size;
  3060.      int leaf_function;
  3061. {
  3062.   char *ret;
  3063.  
  3064.   if (leaf_label)
  3065.     {
  3066.       emit_label_after (leaf_label, get_last_insn ());
  3067.       final_scan_insn (get_last_insn (), file, 0, 0, 1);
  3068.     }
  3069.  
  3070.   /* Restore any call saved registers.  */
  3071.   if (num_gfregs)
  3072.     {
  3073.       int offset, n_regs;
  3074.       char *base;
  3075.  
  3076.       offset = -apparent_fsize + frame_base_offset;
  3077.       if (offset < -4096 || offset + num_gfregs * 4 > 4096 - 8 /*double*/)
  3078.     {
  3079.       build_big_number (file, offset, "%g1");
  3080.       fprintf (file, "\tadd %s,%%g1,%%g1\n", frame_base_name);
  3081.       base = "%g1";
  3082.       offset = 0;
  3083.     }
  3084.       else
  3085.     {
  3086.       base = frame_base_name;
  3087.     }
  3088.  
  3089.       if (TARGET_EPILOGUE && ! leaf_function)
  3090.     /* ??? Originally saved regs 0-15 here.  */
  3091.     n_regs = restore_regs (file, 0, 8, base, offset, 0);
  3092.       else if (leaf_function)
  3093.     /* ??? Originally saved regs 0-31 here.  */
  3094.     n_regs = restore_regs (file, 0, 8, base, offset, 0);
  3095.       if (TARGET_EPILOGUE)
  3096.     restore_regs (file, 32, TARGET_V9 ? 96 : 64, base, offset, n_regs);
  3097.     }
  3098.  
  3099.   /* Work out how to skip the caller's unimp instruction if required.  */
  3100.   if (leaf_function)
  3101.     ret = (SKIP_CALLERS_UNIMP_P ? "jmp %o7+12" : "retl");
  3102.   else
  3103.     ret = (SKIP_CALLERS_UNIMP_P ? "jmp %i7+12" : "ret");
  3104.  
  3105.   if (TARGET_EPILOGUE || leaf_label)
  3106.     {
  3107.       int old_target_epilogue = TARGET_EPILOGUE;
  3108.       target_flags &= ~old_target_epilogue;
  3109.  
  3110.       if (! leaf_function)
  3111.     {
  3112.       /* If we wound up with things in our delay slot, flush them here.  */
  3113.       if (current_function_epilogue_delay_list)
  3114.         {
  3115.           rtx insn = emit_jump_insn_after (gen_rtx (RETURN, VOIDmode),
  3116.                            get_last_insn ());
  3117.           PATTERN (insn) = gen_rtx (PARALLEL, VOIDmode,
  3118.                     gen_rtvec (2,
  3119.                            PATTERN (XEXP (current_function_epilogue_delay_list, 0)),
  3120.                            PATTERN (insn)));
  3121.           final_scan_insn (insn, file, 1, 0, 1);
  3122.         }
  3123.       else
  3124.         fprintf (file, "\t%s\n\trestore\n", ret);
  3125.     }
  3126.       /* All of the following cases are for leaf functions.  */
  3127.       else if (current_function_epilogue_delay_list)
  3128.     {
  3129.       /* eligible_for_epilogue_delay_slot ensures that if this is a
  3130.          leaf function, then we will only have insn in the delay slot
  3131.          if the frame size is zero, thus no adjust for the stack is
  3132.          needed here.  */
  3133.       if (actual_fsize != 0)
  3134.         abort ();
  3135.       fprintf (file, "\t%s\n", ret);
  3136.       final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
  3137.                file, 1, 0, 1);
  3138.     }
  3139.       /* Output 'nop' instead of 'sub %sp,-0,%sp' when no frame, so as to
  3140.      avoid generating confusing assembly language output.  */
  3141.       else if (actual_fsize == 0)
  3142.     fprintf (file, "\t%s\n\tnop\n", ret);
  3143.       else if (actual_fsize <= 4096)
  3144.     fprintf (file, "\t%s\n\tsub %%sp,-%d,%%sp\n", ret, actual_fsize);
  3145.       else if (actual_fsize <= 8192)
  3146.     fprintf (file, "\tsub %%sp,-4096,%%sp\n\t%s\n\tsub %%sp,-%d,%%sp\n",
  3147.          ret, actual_fsize - 4096);
  3148.       else if ((actual_fsize & 0x3ff) == 0)
  3149.     fprintf (file, "\tsethi %%hi(%d),%%g1\n\t%s\n\tadd %%sp,%%g1,%%sp\n",
  3150.          actual_fsize, ret);
  3151.       else         
  3152.     fprintf (file, "\tsethi %%hi(%d),%%g1\n\tor %%g1,%%lo(%d),%%g1\n\t%s\n\tadd %%sp,%%g1,%%sp\n",
  3153.          actual_fsize, actual_fsize, ret);
  3154.       target_flags |= old_target_epilogue;
  3155.     }
  3156. }
  3157.  
  3158. /* Do what is necessary for `va_start'.  The argument is ignored.
  3159.    !v9: We look at the current function to determine if stdarg or varargs
  3160.    is used and return the address of the first unnamed parameter.
  3161.    v9: We save the argument integer and floating point regs in a buffer, and
  3162.    return the address of this buffer.  The rest is handled in va-sparc.h.  */
  3163. /* ??? This is currently conditioned on #ifdef SPARCV9 because
  3164.    current_function_args_info is different in each compiler.  */
  3165.  
  3166. #ifdef SPARCV9
  3167.  
  3168. rtx
  3169. sparc_builtin_saveregs (arglist)
  3170.      tree arglist;
  3171. {
  3172.   tree fntype = TREE_TYPE (current_function_decl);
  3173.   /* First unnamed integer register.  */
  3174.   int first_intreg = current_function_args_info.arg_count[(int) SPARC_ARG_INT];
  3175.   /* Number of integer registers we need to save.  */
  3176.   int n_intregs = MAX (0, NPARM_REGS (SImode) - first_intreg);
  3177.   /* First unnamed SFmode float reg (no, you can't pass SFmode floats as
  3178.      unnamed arguments, we just number them that way).  We must round up to
  3179.      the next double word float reg - that is the first one to save.  */
  3180.   int first_floatreg = current_function_args_info.arg_count[(int) SPARC_ARG_FLOAT] + 1 & ~1;
  3181.   /* Number of SFmode float regs to save.  */
  3182.   int n_floatregs = MAX (0, NPARM_REGS (SFmode) - first_floatreg);
  3183.   int ptrsize = GET_MODE_SIZE (Pmode);
  3184.   rtx valist, regbuf, fpregs;
  3185.   int bufsize, adjust, regno;
  3186.  
  3187.   /* Allocate block of memory for the regs.
  3188.      We only allocate as much as we need, but we must ensure quadword float
  3189.      regs are stored with the appropriate alignment.  */
  3190.   /* ??? If n_intregs + n_floatregs == 0, should we allocate at least 1 byte?
  3191.      Or can assign_stack_local accept a 0 SIZE argument?  */
  3192.  
  3193.   bufsize = (n_intregs * UNITS_PER_WORD) + (n_floatregs * (UNITS_PER_WORD / 2));
  3194.   /* Add space in front of the int regs to ensure proper alignment of quadword
  3195.      fp regs.  We must add the space in front because va_start assumes this.  */
  3196.   if (n_floatregs >= 4)
  3197.     adjust = ((n_intregs + first_floatreg / 2) % 2) * UNITS_PER_WORD;
  3198.   else
  3199.     adjust = 0;
  3200.  
  3201.   regbuf = assign_stack_local (BLKmode, bufsize + adjust,
  3202.                    GET_MODE_BITSIZE (TFmode));
  3203.   regbuf = gen_rtx (MEM, BLKmode, plus_constant (XEXP (regbuf, 0), adjust));
  3204.   MEM_IN_STRUCT_P (regbuf) = 1;
  3205.  
  3206.   /* Save int args.
  3207.      This is optimized to only save the regs that are necessary.  Explicitly
  3208.      named args need not be saved.  */
  3209.  
  3210.   if (n_intregs > 0)
  3211.     move_block_from_reg (BASE_INCOMING_ARG_REG (SImode) + first_intreg,
  3212.              regbuf, n_intregs, n_intregs * UNITS_PER_WORD);
  3213.  
  3214.   /* Save float args.
  3215.      This is optimized to only save the regs that are necessary.  Explicitly
  3216.      named args need not be saved.
  3217.      We explicitly build a pointer to the buffer because it halves the insn
  3218.      count when not optimizing (otherwise the pointer is built for each reg
  3219.      saved).  */
  3220.  
  3221.   fpregs = gen_reg_rtx (Pmode);
  3222.   emit_move_insn (fpregs, plus_constant (XEXP (regbuf, 0),
  3223.                      n_intregs * UNITS_PER_WORD));
  3224.   for (regno = first_floatreg; regno < NPARM_REGS (SFmode); regno += 2)
  3225.     emit_move_insn (gen_rtx (MEM, DFmode,
  3226.                  plus_constant (fpregs,
  3227.                         GET_MODE_SIZE (SFmode)
  3228.                         * (regno - first_floatreg))),
  3229.             gen_rtx (REG, DFmode,
  3230.                  BASE_INCOMING_ARG_REG (DFmode) + regno));
  3231.  
  3232.   /* Return the address of the regbuf.  */
  3233.  
  3234.   return XEXP (regbuf, 0);
  3235. }
  3236.  
  3237. #else /* ! SPARCV9 */
  3238.  
  3239. rtx
  3240. sparc_builtin_saveregs (arglist)
  3241.      tree arglist;
  3242. {
  3243.   tree fntype = TREE_TYPE (current_function_decl);
  3244.   int stdarg = (TYPE_ARG_TYPES (fntype) != 0
  3245.         && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
  3246.             != void_type_node));
  3247.   int first_reg = current_function_args_info;
  3248.   rtx address;
  3249.   int regno;
  3250.  
  3251. #if 0 /* This code seemed to have no effect except to make
  3252.      varargs not work right when va_list wasn't the first arg.  */
  3253.   if (! stdarg)
  3254.     first_reg = 0;
  3255. #endif
  3256.  
  3257.   for (regno = first_reg; regno < NPARM_REGS (SImode); regno++)
  3258.     emit_move_insn (gen_rtx (MEM, word_mode,
  3259.                  gen_rtx (PLUS, Pmode,
  3260.                       frame_pointer_rtx,
  3261.                       GEN_INT (STACK_POINTER_OFFSET
  3262.                            + UNITS_PER_WORD * regno))),
  3263.             gen_rtx (REG, word_mode, BASE_INCOMING_ARG_REG (word_mode)
  3264.                  + regno));
  3265.  
  3266.   address = gen_rtx (PLUS, Pmode,
  3267.              frame_pointer_rtx,
  3268.              GEN_INT (STACK_POINTER_OFFSET
  3269.                   + UNITS_PER_WORD * first_reg));
  3270.  
  3271.   return address;
  3272. }
  3273.  
  3274. #endif /* ! SPARCV9 */
  3275.  
  3276. /* Return the string to output a conditional branch to LABEL, which is
  3277.    the operand number of the label.  OP is the conditional expression.  The
  3278.    mode of register 0 says what kind of comparison we made.
  3279.  
  3280.    FP_COND_REG indicates which fp condition code register to use if this is
  3281.    a floating point branch.
  3282.  
  3283.    REVERSED is non-zero if we should reverse the sense of the comparison.
  3284.  
  3285.    ANNUL is non-zero if we should generate an annulling branch.
  3286.  
  3287.    NOOP is non-zero if we have to follow this branch by a noop.  */
  3288.  
  3289. char *
  3290. output_cbranch (op, fp_cond_reg, label, reversed, annul, noop)
  3291.      rtx op, fp_cond_reg;
  3292.      int label;
  3293.      int reversed, annul, noop;
  3294. {
  3295.   static char string[20];
  3296.   enum rtx_code code = GET_CODE (op);
  3297.   enum machine_mode mode = GET_MODE (XEXP (op, 0));
  3298.   static char v8_labelno[] = " %lX";
  3299.   static char v9_icc_labelno[] = " %%icc,%lX";
  3300.   static char v9_xcc_labelno[] = " %%xcc,%lX";
  3301.   static char v9_fcc_labelno[] = " %%fccX,%lY";
  3302.   char *labelno;
  3303.   int labeloff;
  3304.  
  3305.   /* ??? !v9: FP branches cannot be preceded by another floating point insn.
  3306.      Because there is currently no concept of pre-delay slots, we can fix
  3307.      this only by always emitting a nop before a floating point branch.  */
  3308.  
  3309.   if ((mode == CCFPmode || mode == CCFPEmode) && ! TARGET_V9)
  3310.     strcpy (string, "nop\n\t");
  3311.   else
  3312.     string[0] = '\0';
  3313.  
  3314.   /* If not floating-point or if EQ or NE, we can just reverse the code.  */
  3315.   if (reversed
  3316.       && ((mode != CCFPmode && mode != CCFPEmode) || code == EQ || code == NE))
  3317.     code = reverse_condition (code), reversed = 0;
  3318.  
  3319.   /* Start by writing the branch condition.  */
  3320.   switch (code)
  3321.     {
  3322.     case NE:
  3323.       if (mode == CCFPmode || mode == CCFPEmode)
  3324.     strcat (string, "fbne");
  3325.       else
  3326.     strcpy (string, "bne");
  3327.       break;
  3328.  
  3329.     case EQ:
  3330.       if (mode == CCFPmode || mode == CCFPEmode)
  3331.     strcat (string, "fbe");
  3332.       else
  3333.     strcpy (string, "be");
  3334.       break;
  3335.  
  3336.     case GE:
  3337.       if (mode == CCFPmode || mode == CCFPEmode)
  3338.     {
  3339.       if (reversed)
  3340.         strcat (string, "fbul");
  3341.       else
  3342.         strcat (string, "fbge");
  3343.     }
  3344.       else if (mode == CC_NOOVmode)
  3345.     strcpy (string, "bpos");
  3346.       else
  3347.     strcpy (string, "bge");
  3348.       break;
  3349.  
  3350.     case GT:
  3351.       if (mode == CCFPmode || mode == CCFPEmode)
  3352.     {
  3353.       if (reversed)
  3354.         strcat (string, "fbule");
  3355.       else
  3356.         strcat (string, "fbg");
  3357.     }
  3358.       else
  3359.     strcpy (string, "bg");
  3360.       break;
  3361.  
  3362.     case LE:
  3363.       if (mode == CCFPmode || mode == CCFPEmode)
  3364.     {
  3365.       if (reversed)
  3366.         strcat (string, "fbug");
  3367.       else
  3368.         strcat (string, "fble");
  3369.     }
  3370.       else
  3371.     strcpy (string, "ble");
  3372.       break;
  3373.  
  3374.     case LT:
  3375.       if (mode == CCFPmode || mode == CCFPEmode)
  3376.     {
  3377.       if (reversed)
  3378.         strcat (string, "fbuge");
  3379.       else
  3380.         strcat (string, "fbl");
  3381.     }
  3382.       else if (mode == CC_NOOVmode)
  3383.     strcpy (string, "bneg");
  3384.       else
  3385.     strcpy (string, "bl");
  3386.       break;
  3387.  
  3388.     case GEU:
  3389.       strcpy (string, "bgeu");
  3390.       break;
  3391.  
  3392.     case GTU:
  3393.       strcpy (string, "bgu");
  3394.       break;
  3395.  
  3396.     case LEU:
  3397.       strcpy (string, "bleu");
  3398.       break;
  3399.  
  3400.     case LTU:
  3401.       strcpy (string, "blu");
  3402.       break;
  3403.     }
  3404.  
  3405.   /* Now add the annulling, the label, and a possible noop.  */
  3406.   if (annul)
  3407.     strcat (string, ",a");
  3408.  
  3409.   /* ??? If v9, optional prediction bit ",pt" or ",pf" goes here.  */
  3410.  
  3411.   if (! TARGET_V9)
  3412.     {
  3413.       labeloff = 3;
  3414.       labelno = v8_labelno;
  3415.     }
  3416.   else
  3417.     {
  3418.       labeloff = 9;
  3419.       if (mode == CCFPmode || mode == CCFPEmode)
  3420.     {
  3421.       labeloff = 10;
  3422.       labelno = v9_fcc_labelno;
  3423.       /* Set the char indicating the number of the fcc reg to use.  */
  3424.       labelno[6] = REGNO (fp_cond_reg) - 96 + '0';
  3425.     }
  3426.       else if (mode == CCXmode || mode == CCX_NOOVmode)
  3427.     labelno = v9_xcc_labelno;
  3428.       else
  3429.     labelno = v9_icc_labelno;
  3430.     }
  3431.   /* Set the char indicating the number of the operand containing the
  3432.      label_ref.  */
  3433.   labelno[labeloff] = label + '0';
  3434.   strcat (string, labelno);
  3435.  
  3436.   if (noop)
  3437.     strcat (string, "\n\tnop");
  3438.  
  3439.   return string;
  3440. }
  3441.  
  3442. /* Return the string to output a conditional branch to LABEL, testing
  3443.    register REG.  LABEL is the operand number of the label; REG is the
  3444.    operand number of the reg.  OP is the conditional expression.  The mode
  3445.    of REG says what kind of comparison we made.
  3446.  
  3447.    REVERSED is non-zero if we should reverse the sense of the comparison.
  3448.  
  3449.    ANNUL is non-zero if we should generate an annulling branch.
  3450.  
  3451.    NOOP is non-zero if we have to follow this branch by a noop.  */
  3452.  
  3453. char *
  3454. output_v9branch (op, reg, label, reversed, annul, noop)
  3455.      rtx op;
  3456.      int reg, label;
  3457.      int reversed, annul, noop;
  3458. {
  3459.   static char string[20];
  3460.   enum rtx_code code = GET_CODE (op);
  3461.   enum machine_mode mode = GET_MODE (XEXP (op, 0));
  3462.   static char labelno[] = " %X,%lX";
  3463.  
  3464.   /* If not floating-point or if EQ or NE, we can just reverse the code.  */
  3465.   if (reversed)
  3466.     code = reverse_condition (code), reversed = 0;
  3467.  
  3468.   /* Only 64 bit versions of these instructions exist.  */
  3469.   if (mode != DImode)
  3470.     abort ();
  3471.  
  3472.   /* Start by writing the branch condition.  */
  3473.  
  3474.   switch (code)
  3475.     {
  3476.     case NE:
  3477.       strcpy (string, "brnz");
  3478.       break;
  3479.  
  3480.     case EQ:
  3481.       strcpy (string, "brz");
  3482.       break;
  3483.  
  3484.     case GE:
  3485.       strcpy (string, "brgez");
  3486.       break;
  3487.  
  3488.     case LT:
  3489.       strcpy (string, "brlz");
  3490.       break;
  3491.  
  3492.     case LE:
  3493.       strcpy (string, "brlez");
  3494.       break;
  3495.  
  3496.     case GT:
  3497.       strcpy (string, "brgz");
  3498.       break;
  3499.  
  3500.     default:
  3501.       abort ();
  3502.     }
  3503.  
  3504.   /* Now add the annulling, reg, label, and nop.  */
  3505.   if (annul)
  3506.     strcat (string, ",a");
  3507.  
  3508.   /* ??? Optional prediction bit ",pt" or ",pf" goes here.  */
  3509.  
  3510.   labelno[2] = reg + '0';
  3511.   labelno[6] = label + '0';
  3512.   strcat (string, labelno);
  3513.  
  3514.   if (noop)
  3515.     strcat (string, "\n\tnop");
  3516.  
  3517.   return string;
  3518. }
  3519.  
  3520. /* Output assembler code to return from a function.  */
  3521.  
  3522. /* ??? v9: Update to use the new `return' instruction.  Also, add patterns to
  3523.    md file for the `return' instruction.  */
  3524.  
  3525. char *
  3526. output_return (operands)
  3527.      rtx *operands;
  3528. {
  3529.   if (leaf_label)
  3530.     {
  3531.       operands[0] = leaf_label;
  3532.       return "b,a %l0";
  3533.     }
  3534.   else if (leaf_function)
  3535.     {
  3536.       /* If we didn't allocate a frame pointer for the current function,
  3537.      the stack pointer might have been adjusted.  Output code to
  3538.      restore it now.  */
  3539.  
  3540.       operands[0] = gen_rtx (CONST_INT, VOIDmode, actual_fsize);
  3541.  
  3542.       /* Use sub of negated value in first two cases instead of add to
  3543.      allow actual_fsize == 4096.  */
  3544.  
  3545.       if (actual_fsize <= 4096)
  3546.     {
  3547.       if (SKIP_CALLERS_UNIMP_P)
  3548.         return "jmp %%o7+12\n\tsub %%sp,-%0,%%sp";
  3549.       else
  3550.         return "retl\n\tsub %%sp,-%0,%%sp";
  3551.     }
  3552.       else if (actual_fsize <= 8192)
  3553.     {
  3554.       operands[0] = gen_rtx (CONST_INT, VOIDmode, actual_fsize - 4096);
  3555.       if (SKIP_CALLERS_UNIMP_P)
  3556.         return "sub %%sp,-4096,%%sp\n\tjmp %%o7+12\n\tsub %%sp,-%0,%%sp";
  3557.       else
  3558.         return "sub %%sp,-4096,%%sp\n\tretl\n\tsub %%sp,-%0,%%sp";
  3559.     }
  3560.       else if (SKIP_CALLERS_UNIMP_P)
  3561.     {
  3562.       if ((actual_fsize & 0x3ff) != 0)
  3563.         return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tjmp %%o7+12\n\tadd %%sp,%%g1,%%sp";
  3564.       else
  3565.         return "sethi %%hi(%a0),%%g1\n\tjmp %%o7+12\n\tadd %%sp,%%g1,%%sp";
  3566.     }
  3567.       else
  3568.     {
  3569.       if ((actual_fsize & 0x3ff) != 0)
  3570.         return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tretl\n\tadd %%sp,%%g1,%%sp";
  3571.       else
  3572.         return "sethi %%hi(%a0),%%g1\n\tretl\n\tadd %%sp,%%g1,%%sp";
  3573.     }
  3574.     }
  3575.   else
  3576.     {
  3577.       if (SKIP_CALLERS_UNIMP_P)
  3578.     return "jmp %%i7+12\n\trestore";
  3579.       else
  3580.     return "ret\n\trestore";
  3581.     }
  3582. }
  3583.  
  3584. /* Leaf functions and non-leaf functions have different needs.  */
  3585.  
  3586. static int
  3587. reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER;
  3588.  
  3589. static int
  3590. reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER;
  3591.  
  3592. static int *reg_alloc_orders[] = {
  3593.   reg_leaf_alloc_order,
  3594.   reg_nonleaf_alloc_order};
  3595.  
  3596. void
  3597. order_regs_for_local_alloc ()
  3598. {
  3599.   static int last_order_nonleaf = 1;
  3600.  
  3601.   if (regs_ever_live[15] != last_order_nonleaf)
  3602.     {
  3603.       last_order_nonleaf = !last_order_nonleaf;
  3604.       bcopy ((char *) reg_alloc_orders[last_order_nonleaf],
  3605.          (char *) reg_alloc_order, FIRST_PSEUDO_REGISTER * sizeof (int));
  3606.     }
  3607. }
  3608.  
  3609. /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1.
  3610.    This makes them candidates for using ldd and std insns. 
  3611.  
  3612.    Note reg1 and reg2 *must* be hard registers.  To be sure we will
  3613.    abort if we are passed pseudo registers.  */
  3614.  
  3615. int
  3616. registers_ok_for_ldd_peep (reg1, reg2)
  3617.      rtx reg1, reg2;
  3618. {
  3619.   /* We might have been passed a SUBREG.  */
  3620.   if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) 
  3621.     return 0;
  3622.  
  3623.   if (REGNO (reg1) % 2 != 0)
  3624.     return 0;
  3625.  
  3626.   return (REGNO (reg1) == REGNO (reg2) - 1);
  3627. }
  3628.  
  3629. /* Return 1 if addr1 and addr2 are suitable for use in an ldd or 
  3630.    std insn.
  3631.  
  3632.    This can only happen when addr1 and addr2 are consecutive memory
  3633.    locations (addr1 + 4 == addr2).  addr1 must also be aligned on a 
  3634.    64 bit boundary (addr1 % 8 == 0).  
  3635.  
  3636.    We know %sp and %fp are kept aligned on a 64 bit boundary.  Other
  3637.    registers are assumed to *never* be properly aligned and are 
  3638.    rejected.
  3639.  
  3640.    Knowing %sp and %fp are kept aligned on a 64 bit boundary, we 
  3641.    need only check that the offset for addr1 % 8 == 0.  */
  3642.  
  3643. int
  3644. addrs_ok_for_ldd_peep (addr1, addr2)
  3645.       rtx addr1, addr2;
  3646. {
  3647.   int reg1, offset1;
  3648.  
  3649.   /* Extract a register number and offset (if used) from the first addr.  */
  3650.   if (GET_CODE (addr1) == PLUS)
  3651.     {
  3652.       /* If not a REG, return zero.  */
  3653.       if (GET_CODE (XEXP (addr1, 0)) != REG)
  3654.     return 0;
  3655.       else
  3656.     {
  3657.           reg1 = REGNO (XEXP (addr1, 0));
  3658.       /* The offset must be constant!  */
  3659.       if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
  3660.             return 0;
  3661.           offset1 = INTVAL (XEXP (addr1, 1));
  3662.     }
  3663.     }
  3664.   else if (GET_CODE (addr1) != REG)
  3665.     return 0;
  3666.   else
  3667.     {
  3668.       reg1 = REGNO (addr1);
  3669.       /* This was a simple (mem (reg)) expression.  Offset is 0.  */
  3670.       offset1 = 0;
  3671.     }
  3672.  
  3673.   /* Make sure the second address is a (mem (plus (reg) (const_int).  */
  3674.   if (GET_CODE (addr2) != PLUS)
  3675.     return 0;
  3676.  
  3677.   if (GET_CODE (XEXP (addr2, 0)) != REG
  3678.       || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
  3679.     return 0;
  3680.  
  3681.   /* Only %fp and %sp are allowed.  Additionally both addresses must
  3682.      use the same register.  */
  3683.   if (reg1 != FRAME_POINTER_REGNUM && reg1 != STACK_POINTER_REGNUM)
  3684.     return 0;
  3685.  
  3686.   if (reg1 != REGNO (XEXP (addr2, 0)))
  3687.     return 0;
  3688.  
  3689.   /* The first offset must be evenly divisible by 8 to ensure the 
  3690.      address is 64 bit aligned.  */
  3691.   if (offset1 % 8 != 0)
  3692.     return 0;
  3693.  
  3694.   /* The offset for the second addr must be 4 more than the first addr.  */
  3695.   if (INTVAL (XEXP (addr2, 1)) != offset1 + 4)
  3696.     return 0;
  3697.  
  3698.   /* All the tests passed.  addr1 and addr2 are valid for ldd and std
  3699.      instructions.  */
  3700.   return 1;
  3701. }
  3702.  
  3703. /* Return 1 if reg is a pseudo, or is the first register in 
  3704.    a hard register pair.  This makes it a candidate for use in
  3705.    ldd and std insns.  */
  3706.  
  3707. int
  3708. register_ok_for_ldd (reg)
  3709.      rtx reg;
  3710. {
  3711.   /* We might have been passed a SUBREG.  */
  3712.   if (GET_CODE (reg) != REG) 
  3713.     return 0;
  3714.  
  3715.   if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
  3716.     return (REGNO (reg) % 2 == 0);
  3717.   else 
  3718.     return 1;
  3719. }
  3720.  
  3721. /* Print operand X (an rtx) in assembler syntax to file FILE.
  3722.    CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
  3723.    For `%' followed by punctuation, CODE is the punctuation and X is null.  */
  3724.  
  3725. void
  3726. print_operand (file, x, code)
  3727.      FILE *file;
  3728.      rtx x;
  3729.      int code;
  3730. {
  3731.   switch (code)
  3732.     {
  3733.     case '#':
  3734.       /* Output a 'nop' if there's nothing for the delay slot.  */
  3735.       if (dbr_sequence_length () == 0)
  3736.     fputs ("\n\tnop", file);
  3737.       return;
  3738.     case '*':
  3739.       /* Output an annul flag if there's nothing for the delay slot and we
  3740.      are optimizing.  This is always used with '(' below.  */
  3741.       /* Sun OS 4.1.1 dbx can't handle an annulled unconditional branch;
  3742.      this is a dbx bug.  So, we only do this when optimizing.  */
  3743.       if (dbr_sequence_length () == 0 && optimize)
  3744.     fputs (",a", file);
  3745.       return;
  3746.     case '(':
  3747.       /* Output a 'nop' if there's nothing for the delay slot and we are
  3748.      not optimizing.  This is always used with '*' above.  */
  3749.       if (dbr_sequence_length () == 0 && ! optimize)
  3750.     fputs ("\n\tnop", file);
  3751.       return;
  3752.     case '_':
  3753.       /* Output the Medium/Anywhere code model base register.  */
  3754.       fputs (MEDANY_BASE_REG, file);
  3755.       return;
  3756.     case '@':
  3757.       /* Print out what we are using as the frame pointer.  This might
  3758.      be %fp, or might be %sp+offset.  */
  3759.       /* ??? What if offset is too big? Perhaps the caller knows it isn't? */
  3760.       fprintf (file, "%s+%d", frame_base_name, frame_base_offset);
  3761.       return;
  3762.     case 'Y':
  3763.       /* Adjust the operand to take into account a RESTORE operation.  */
  3764.       if (GET_CODE (x) != REG)
  3765.     output_operand_lossage ("Invalid %%Y operand");
  3766.       else if (REGNO (x) < 8)
  3767.     fputs (reg_names[REGNO (x)], file);
  3768.       else if (REGNO (x) >= 24 && REGNO (x) < 32)
  3769.     fputs (reg_names[REGNO (x)-16], file);
  3770.       else
  3771.     output_operand_lossage ("Invalid %%Y operand");
  3772.       return;
  3773.     case 'R':
  3774.       /* Print out the second register name of a register pair or quad.
  3775.      I.e., R (%o0) => %o1.  */
  3776.       fputs (reg_names[REGNO (x)+1], file);
  3777.       return;
  3778.     case 'S':
  3779.       /* Print out the third register name of a register quad.
  3780.      I.e., S (%o0) => %o2.  */
  3781.       fputs (reg_names[REGNO (x)+2], file);
  3782.       return;
  3783.     case 'T':
  3784.       /* Print out the fourth register name of a register quad.
  3785.      I.e., T (%o0) => %o3.  */
  3786.       fputs (reg_names[REGNO (x)+3], file);
  3787.       return;
  3788.     case 'm':
  3789.       /* Print the operand's address only.  */
  3790.       output_address (XEXP (x, 0));
  3791.       return;
  3792.     case 'r':
  3793.       /* In this case we need a register.  Use %g0 if the
  3794.      operand is const0_rtx.  */
  3795.       if (x == const0_rtx
  3796.       || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x))))
  3797.     {
  3798.       fputs ("%g0", file);
  3799.       return;
  3800.     }
  3801.       else
  3802.     break;
  3803.  
  3804.     case 'A':
  3805.       switch (GET_CODE (x))
  3806.     {
  3807.     case IOR: fputs ("or", file); break;
  3808.     case AND: fputs ("and", file); break;
  3809.     case XOR: fputs ("xor", file); break;
  3810.     default: output_operand_lossage ("Invalid %%A operand");
  3811.     }
  3812.       return;
  3813.  
  3814.     case 'B':
  3815.       switch (GET_CODE (x))
  3816.     {
  3817.     case IOR: fputs ("orn", file); break;
  3818.     case AND: fputs ("andn", file); break;
  3819.     case XOR: fputs ("xnor", file); break;
  3820.     default: output_operand_lossage ("Invalid %%B operand");
  3821.     }
  3822.       return;
  3823.  
  3824.       /* This is used by the conditional move instructions.  */
  3825.     case 'C':
  3826.       switch (GET_CODE (x))
  3827.     {
  3828.     case NE: fputs ("ne", file); break;
  3829.     case EQ: fputs ("e", file); break;
  3830.     case GE: fputs ("ge", file); break;
  3831.     case GT: fputs ("g", file); break;
  3832.     case LE: fputs ("le", file); break;
  3833.     case LT: fputs ("l", file); break;
  3834.     case GEU: fputs ("geu", file); break;
  3835.     case GTU: fputs ("gu", file); break;
  3836.     case LEU: fputs ("leu", file); break;
  3837.     case LTU: fputs ("lu", file); break;
  3838.     default: output_operand_lossage ("Invalid %%C operand");
  3839.     }
  3840.       return;
  3841.  
  3842.       /* This is used by the movr instruction pattern.  */
  3843.     case 'D':
  3844.       switch (GET_CODE (x))
  3845.     {
  3846.     case NE: fputs ("ne", file); break;
  3847.     case EQ: fputs ("e", file); break;
  3848.     case GE: fputs ("gez", file); break;
  3849.     case LT: fputs ("lz", file); break;
  3850.     case LE: fputs ("lez", file); break;
  3851.     case GT: fputs ("gz", file); break;
  3852.     default: output_operand_lossage ("Invalid %%D operand");
  3853.     }
  3854.       return;
  3855.  
  3856.     case 'b':
  3857.       {
  3858.     /* Print a sign-extended character.  */
  3859.     int i = INTVAL (x) & 0xff;
  3860.     if (i & 0x80)
  3861.       i |= 0xffffff00;
  3862.     fprintf (file, "%d", i);
  3863.     return;
  3864.       }
  3865.  
  3866.     case 'f':
  3867.       /* Operand must be a MEM; write its address.  */
  3868.       if (GET_CODE (x) != MEM)
  3869.     output_operand_lossage ("Invalid %%f operand");
  3870.       output_address (XEXP (x, 0));
  3871.       return;
  3872.  
  3873.     case 0:
  3874.       /* Do nothing special.  */
  3875.       break;
  3876.  
  3877.     default:
  3878.       /* Undocumented flag.  */
  3879.       output_operand_lossage ("invalid operand output code");
  3880.     }
  3881.  
  3882.   if (GET_CODE (x) == REG)
  3883.     fputs (reg_names[REGNO (x)], file);
  3884.   else if (GET_CODE (x) == MEM)
  3885.     {
  3886.       fputc ('[', file);
  3887.       if (CONSTANT_P (XEXP (x, 0)))
  3888.     /* Poor Sun assembler doesn't understand absolute addressing.  */
  3889.     fputs ("%g0+", file);
  3890.       output_address (XEXP (x, 0));
  3891.       fputc (']', file);
  3892.     }
  3893.   else if (GET_CODE (x) == HIGH)
  3894.     {
  3895.       fputs ("%hi(", file);
  3896.       output_addr_const (file, XEXP (x, 0));
  3897.       fputc (')', file);
  3898.     }
  3899.   else if (GET_CODE (x) == LO_SUM)
  3900.     {
  3901.       print_operand (file, XEXP (x, 0), 0);
  3902.       fputs ("+%lo(", file);
  3903.       output_addr_const (file, XEXP (x, 1));
  3904.       fputc (')', file);
  3905.     }
  3906.   else if (GET_CODE (x) == CONST_DOUBLE
  3907.        && (GET_MODE (x) == VOIDmode
  3908.            || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT))
  3909.     {
  3910.       if (CONST_DOUBLE_HIGH (x) == 0)
  3911.     fprintf (file, "%u", CONST_DOUBLE_LOW (x));
  3912.       else if (CONST_DOUBLE_HIGH (x) == -1
  3913.            && CONST_DOUBLE_LOW (x) < 0)
  3914.     fprintf (file, "%d", CONST_DOUBLE_LOW (x));
  3915.       else
  3916.     output_operand_lossage ("long long constant not a valid immediate operand");
  3917.     }
  3918.   else if (GET_CODE (x) == CONST_DOUBLE)
  3919.     output_operand_lossage ("floating point constant not a valid immediate operand");
  3920.   else { output_addr_const (file, x); }
  3921. }
  3922.  
  3923. /* This function outputs assembler code for VALUE to FILE, where VALUE is
  3924.    a 64 bit (DImode) value.  */
  3925.  
  3926. /* ??? If there is a 64 bit counterpart to .word that the assembler
  3927.    understands, then using that would simply this code greatly.  */
  3928. /* ??? We only output .xword's for symbols and only then in environments
  3929.    where the assembler can handle them.  */
  3930.  
  3931. void
  3932. output_double_int (file, value)
  3933.      FILE *file;
  3934.      rtx value;
  3935. {
  3936.   if (GET_CODE (value) == CONST_INT)
  3937.     {
  3938.       if (INTVAL (value) < 0)
  3939.     ASM_OUTPUT_INT (file, constm1_rtx);
  3940.       else
  3941.     ASM_OUTPUT_INT (file, const0_rtx);
  3942.       ASM_OUTPUT_INT (file, value);
  3943.     }
  3944.   else if (GET_CODE (value) == CONST_DOUBLE)
  3945.     {
  3946.       ASM_OUTPUT_INT (file, gen_rtx (CONST_INT, VOIDmode,
  3947.                      CONST_DOUBLE_HIGH (value)));
  3948.       ASM_OUTPUT_INT (file, gen_rtx (CONST_INT, VOIDmode,
  3949.                      CONST_DOUBLE_LOW (value)));
  3950.     }
  3951.   else if (GET_CODE (value) == SYMBOL_REF
  3952.        || GET_CODE (value) == CONST
  3953.        || GET_CODE (value) == PLUS
  3954.        || (TARGET_V9 &&
  3955.            (GET_CODE (value) == LABEL_REF
  3956.         || GET_CODE (value) == MINUS)))
  3957.     {
  3958.       if (!TARGET_V9 || TARGET_ENV32)
  3959.     {
  3960.       ASM_OUTPUT_INT (file, const0_rtx);
  3961.       ASM_OUTPUT_INT (file, value);
  3962.     }
  3963.       else
  3964.     {
  3965.       fprintf (file, "\t%s\t", ASM_LONGLONG);
  3966.       output_addr_const (file, value);
  3967.       fprintf (file, "\n");
  3968.     }
  3969.     }
  3970.   else
  3971.     abort ();
  3972. }
  3973.  
  3974. /* Return the value of a code used in the .proc pseudo-op that says
  3975.    what kind of result this function returns.  For non-C types, we pick
  3976.    the closest C type.  */
  3977.  
  3978. #ifndef CHAR_TYPE_SIZE
  3979. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  3980. #endif
  3981.  
  3982. #ifndef SHORT_TYPE_SIZE
  3983. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2)
  3984. #endif
  3985.  
  3986. #ifndef INT_TYPE_SIZE
  3987. #define INT_TYPE_SIZE BITS_PER_WORD
  3988. #endif
  3989.  
  3990. #ifndef LONG_TYPE_SIZE
  3991. #define LONG_TYPE_SIZE BITS_PER_WORD
  3992. #endif
  3993.  
  3994. #ifndef LONG_LONG_TYPE_SIZE
  3995. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  3996. #endif
  3997.  
  3998. #ifndef FLOAT_TYPE_SIZE
  3999. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  4000. #endif
  4001.  
  4002. #ifndef DOUBLE_TYPE_SIZE
  4003. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  4004. #endif
  4005.  
  4006. #ifndef LONG_DOUBLE_TYPE_SIZE
  4007. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  4008. #endif
  4009.  
  4010. unsigned long
  4011. sparc_type_code (type)
  4012.      register tree type;
  4013. {
  4014.   register unsigned long qualifiers = 0;
  4015.   register unsigned shift = 6;
  4016.  
  4017.   /* Only the first 30 bits of the qualifier are valid.  We must refrain from
  4018.      setting more, since some assemblers will give an error for this.  Also,
  4019.      we must be careful to avoid shifts of 32 bits or more to avoid getting
  4020.      unpredictable results.  */
  4021.  
  4022.   for (;;)
  4023.     {
  4024.       switch (TREE_CODE (type))
  4025.     {
  4026.     case ERROR_MARK:
  4027.       return qualifiers;
  4028.   
  4029.     case ARRAY_TYPE:
  4030.       if (shift < 30)
  4031.         qualifiers |= (3 << shift);
  4032.       shift += 2;
  4033.       type = TREE_TYPE (type);
  4034.       break;
  4035.  
  4036.     case FUNCTION_TYPE:
  4037.     case METHOD_TYPE:
  4038.       if (shift < 30)
  4039.         qualifiers |= (2 << shift);
  4040.       shift += 2;
  4041.       type = TREE_TYPE (type);
  4042.       break;
  4043.  
  4044.     case POINTER_TYPE:
  4045.     case REFERENCE_TYPE:
  4046.     case OFFSET_TYPE:
  4047.       if (shift < 30)
  4048.         qualifiers |= (1 << shift);
  4049.       shift += 2;
  4050.       type = TREE_TYPE (type);
  4051.       break;
  4052.  
  4053.     case RECORD_TYPE:
  4054.       return (qualifiers | 8);
  4055.  
  4056.     case UNION_TYPE:
  4057.     case QUAL_UNION_TYPE:
  4058.       return (qualifiers | 9);
  4059.  
  4060.     case ENUMERAL_TYPE:
  4061.       return (qualifiers | 10);
  4062.  
  4063.     case VOID_TYPE:
  4064.       return (qualifiers | 16);
  4065.  
  4066.     case INTEGER_TYPE:
  4067.       /* If this is a range type, consider it to be the underlying
  4068.          type.  */
  4069.       if (TREE_TYPE (type) != 0)
  4070.         {
  4071.           type = TREE_TYPE (type);
  4072.           break;
  4073.         }
  4074.  
  4075.       /* Carefully distinguish all the standard types of C,
  4076.          without messing up if the language is not C.  We do this by
  4077.          testing TYPE_PRECISION and TREE_UNSIGNED.  The old code used to
  4078.          look at both the names and the above fields, but that's redundant.
  4079.          Any type whose size is between two C types will be considered
  4080.          to be the wider of the two types.  Also, we do not have a
  4081.          special code to use for "long long", so anything wider than
  4082.          long is treated the same.  Note that we can't distinguish
  4083.          between "int" and "long" in this code if they are the same
  4084.          size, but that's fine, since neither can the assembler.  */
  4085.  
  4086.       if (TYPE_PRECISION (type) <= CHAR_TYPE_SIZE)
  4087.         return (qualifiers | (TREE_UNSIGNED (type) ? 12 : 2));
  4088.   
  4089.       else if (TYPE_PRECISION (type) <= SHORT_TYPE_SIZE)
  4090.         return (qualifiers | (TREE_UNSIGNED (type) ? 13 : 3));
  4091.   
  4092.       else if (TYPE_PRECISION (type) <= INT_TYPE_SIZE)
  4093.         return (qualifiers | (TREE_UNSIGNED (type) ? 14 : 4));
  4094.   
  4095.       else
  4096.         return (qualifiers | (TREE_UNSIGNED (type) ? 15 : 5));
  4097.   
  4098.     case REAL_TYPE:
  4099.       /* Carefully distinguish all the standard types of C,
  4100.          without messing up if the language is not C.  */
  4101.  
  4102.       if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
  4103.         return (qualifiers | 6);
  4104.  
  4105.       else 
  4106.         return (qualifiers | 7);
  4107.   
  4108.     case COMPLEX_TYPE:    /* GNU Fortran COMPLEX type.  */
  4109.       /* ??? We need to distinguish between double and float complex types,
  4110.          but I don't know how yet because I can't reach this code from
  4111.          existing front-ends.  */
  4112.       return (qualifiers | 7);    /* Who knows? */
  4113.  
  4114.     case CHAR_TYPE:        /* GNU Pascal CHAR type.  Not used in C.  */
  4115.     case BOOLEAN_TYPE:    /* GNU Fortran BOOLEAN type.  */
  4116.     case FILE_TYPE:        /* GNU Pascal FILE type.  */
  4117.     case SET_TYPE:        /* GNU Pascal SET type.  */
  4118.     case LANG_TYPE:        /* ? */
  4119.       return qualifiers;
  4120.   
  4121.     default:
  4122.       abort ();        /* Not a type! */
  4123.         }
  4124.     }
  4125. }
  4126.  
  4127. /* Nested function support.  */
  4128.  
  4129. /* Emit RTL insns to initialize the variable parts of a trampoline.
  4130.    FNADDR is an RTX for the address of the function's pure code.
  4131.    CXT is an RTX for the static chain value for the function.
  4132.  
  4133.    This takes 16 insns: 2 shifts & 2 ands (to split up addresses), 4 sethi
  4134.    (to load in opcodes), 4 iors (to merge address and opcodes), and 4 writes
  4135.    (to store insns).  This is a bit excessive.  Perhaps a different
  4136.    mechanism would be better here.
  4137.  
  4138.    Emit enough FLUSH insns to synchronize the data and instruction caches.  */
  4139.  
  4140. void
  4141. sparc_initialize_trampoline (tramp, fnaddr, cxt)
  4142.      rtx tramp, fnaddr, cxt;
  4143. {
  4144.   rtx high_cxt = expand_shift (RSHIFT_EXPR, SImode, cxt,
  4145.                   size_int (10), 0, 1);
  4146.   rtx high_fn = expand_shift (RSHIFT_EXPR, SImode, fnaddr,
  4147.                  size_int (10), 0, 1);
  4148.   rtx low_cxt = expand_and (cxt, gen_rtx (CONST_INT, VOIDmode, 0x3ff), 0);
  4149.   rtx low_fn = expand_and (fnaddr, gen_rtx (CONST_INT, VOIDmode, 0x3ff), 0);
  4150.   rtx g1_sethi = gen_rtx (HIGH, SImode,
  4151.               gen_rtx (CONST_INT, VOIDmode, 0x03000000));
  4152.   rtx g2_sethi = gen_rtx (HIGH, SImode,
  4153.               gen_rtx (CONST_INT, VOIDmode, 0x05000000));
  4154.   rtx g1_ori = gen_rtx (HIGH, SImode,
  4155.             gen_rtx (CONST_INT, VOIDmode, 0x82106000));
  4156.   rtx g2_ori = gen_rtx (HIGH, SImode,
  4157.             gen_rtx (CONST_INT, VOIDmode, 0x8410A000));
  4158.   rtx tem = gen_reg_rtx (SImode);
  4159.   emit_move_insn (tem, g1_sethi);
  4160.   emit_insn (gen_iorsi3 (high_fn, high_fn, tem));
  4161.   emit_move_insn (gen_rtx (MEM, SImode, plus_constant (tramp, 0)), high_fn);
  4162.   emit_move_insn (tem, g1_ori);
  4163.   emit_insn (gen_iorsi3 (low_fn, low_fn, tem));
  4164.   emit_move_insn (gen_rtx (MEM, SImode, plus_constant (tramp, 4)), low_fn);
  4165.   emit_move_insn (tem, g2_sethi);
  4166.   emit_insn (gen_iorsi3 (high_cxt, high_cxt, tem));
  4167.   emit_move_insn (gen_rtx (MEM, SImode, plus_constant (tramp, 8)), high_cxt);
  4168.   emit_move_insn (tem, g2_ori);
  4169.   emit_insn (gen_iorsi3 (low_cxt, low_cxt, tem));
  4170.   emit_move_insn (gen_rtx (MEM, SImode, plus_constant (tramp, 16)), low_cxt);
  4171.   emit_insn (gen_flush (validize_mem (gen_rtx (MEM, SImode, tramp))));
  4172.   emit_insn (gen_flush (validize_mem (gen_rtx (MEM, SImode,
  4173.                            plus_constant (tramp, 8)))));
  4174.   emit_insn (gen_flush (validize_mem (gen_rtx (MEM, SImode,
  4175.                            plus_constant (tramp, 16)))));
  4176. }
  4177.  
  4178. /* The 64 bit version is simpler because it makes more sense to load the
  4179.    values as "immediate" data out of the trampoline.  It's also easier since
  4180.    we can read the PC without clobbering a register.  */
  4181.  
  4182. void
  4183. sparc64_initialize_trampoline (tramp, fnaddr, cxt)
  4184.      rtx tramp, fnaddr, cxt;
  4185. {
  4186.   emit_move_insn (gen_rtx (MEM, DImode, plus_constant (tramp, 24)), cxt);
  4187.   emit_move_insn (gen_rtx (MEM, DImode, plus_constant (tramp, 32)), fnaddr);
  4188.   emit_insn (gen_flush (validize_mem (gen_rtx (MEM, DImode, tramp))));
  4189.   emit_insn (gen_flush (validize_mem (gen_rtx (MEM, DImode,
  4190.                            plus_constant (tramp, 8)))));
  4191.   emit_insn (gen_flush (validize_mem (gen_rtx (MEM, DImode,
  4192.                            plus_constant (tramp, 16)))));
  4193.   emit_insn (gen_flush (validize_mem (gen_rtx (MEM, DImode,
  4194.                            plus_constant (tramp, 24)))));
  4195.   emit_insn (gen_flush (validize_mem (gen_rtx (MEM, DImode,
  4196.                            plus_constant (tramp, 32)))));
  4197. }
  4198.  
  4199. /* Subroutines to support a flat (single) register window calling
  4200.    convention.  */
  4201.  
  4202. /* Single-register window sparc stack frames look like:
  4203.  
  4204.              Before call                After call
  4205.         +-----------------------+    +-----------------------+
  4206.    high |                |    |            |
  4207.    mem  |  caller's temps.        |       |  caller's temps.        |
  4208.     |               |       |                   |
  4209.         +-----------------------+    +-----------------------+
  4210.      |               |    |                |
  4211.         |  arguments on stack.  |    |  arguments on stack.  |
  4212.     |               |          |            |
  4213.         +-----------------------+FP+92->+-----------------------+
  4214.      |  6 words to save         |    |  6 words to save    |
  4215.     |  arguments passed    |    |  arguments passed    |
  4216.     |  in registers, even    |    |  in registers, even    |
  4217.            |  if not passed.       |          |  if not passed.    |
  4218.  SP+68->+-----------------------+FP+68->+-----------------------+
  4219.         | 1 word struct addr    |          | 1 word struct addr    |
  4220.         +-----------------------+FP+64->+-----------------------+
  4221.         |            |    |            |
  4222.         | 16 word reg save area    |    | 16 word reg save area |
  4223.            |                       |          |            |
  4224.     SP->+-----------------------+   FP->+-----------------------+
  4225.                         | 4 word area for    |
  4226.                            | fp/alu reg moves    |
  4227.                  FP-16->+-----------------------+
  4228.                         |            |
  4229.                         |  local variables    |
  4230.                         |            |
  4231.                         +-----------------------+
  4232.                         |                |
  4233.                                         |  fp register save     |
  4234.                         |            |
  4235.                         +-----------------------+
  4236.                         |                |
  4237.                                         |  gp register save     |
  4238.                                         |               |
  4239.                         +-----------------------+
  4240.                         |            |
  4241.                                         |  alloca allocations   |
  4242.                             |            |
  4243.                         +-----------------------+
  4244.                         |            |
  4245.                                         |  arguments on stack   |
  4246.                                |                |
  4247.                  SP+92->+-----------------------+
  4248.                                         |  6 words to save      |
  4249.                         |  arguments passed     |
  4250.                                         |  in registers, even   |
  4251.    low                                     |  if not passed.       |
  4252.    memory                 SP+68->+-----------------------+
  4253.                            | 1 word struct addr    |
  4254.                  SP+64->+-----------------------+
  4255.                         |            |
  4256.                         I 16 word reg save area |
  4257.                            |            |
  4258.                     SP->+-----------------------+  */
  4259.  
  4260. /* Structure to be filled in by sparc_flat_compute_frame_size with register
  4261.    save masks, and offsets for the current function.  */
  4262.  
  4263. struct sparc_frame_info
  4264. {
  4265.   unsigned long total_size;    /* # bytes that the entire frame takes up.  */
  4266.   unsigned long var_size;    /* # bytes that variables take up.  */
  4267.   unsigned long args_size;    /* # bytes that outgoing arguments take up.  */
  4268.   unsigned long extra_size;    /* # bytes of extra gunk.  */
  4269.   unsigned int  gp_reg_size;    /* # bytes needed to store gp regs.  */
  4270.   unsigned int  fp_reg_size;    /* # bytes needed to store fp regs.  */
  4271.   unsigned long gmask;        /* Mask of saved gp registers.  */
  4272.   unsigned long fmask;        /* Mask of saved fp registers.  */
  4273.   unsigned long reg_offset;    /* Offset from new sp to store regs.  */
  4274.   int        initialized;    /* Nonzero if frame size already calculated.  */
  4275. };
  4276.  
  4277. /* Current frame information calculated by sparc_flat_compute_frame_size.  */
  4278. struct sparc_frame_info current_frame_info;
  4279.  
  4280. /* Zero structure to initialize current_frame_info.  */
  4281. struct sparc_frame_info zero_frame_info;
  4282.  
  4283. /* Tell prologue and epilogue if register REGNO should be saved / restored.  */
  4284.  
  4285. #define RETURN_ADDR_REGNUM 15
  4286. #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
  4287. #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
  4288.  
  4289. #define MUST_SAVE_REGISTER(regno) \
  4290.  ((regs_ever_live[regno] && !call_used_regs[regno])        \
  4291.   || (regno == FRAME_POINTER_REGNUM && frame_pointer_needed)    \
  4292.   || (regno == RETURN_ADDR_REGNUM && regs_ever_live[RETURN_ADDR_REGNUM]))
  4293.  
  4294. /* Return the bytes needed to compute the frame pointer from the current
  4295.    stack pointer.  */
  4296.  
  4297. unsigned long
  4298. sparc_flat_compute_frame_size (size)
  4299.      int size;            /* # of var. bytes allocated.  */
  4300. {
  4301.   int regno;
  4302.   unsigned long total_size;    /* # bytes that the entire frame takes up.  */
  4303.   unsigned long var_size;    /* # bytes that variables take up.  */
  4304.   unsigned long args_size;    /* # bytes that outgoing arguments take up.  */
  4305.   unsigned long extra_size;    /* # extra bytes.  */
  4306.   unsigned int  gp_reg_size;    /* # bytes needed to store gp regs.  */
  4307.   unsigned int  fp_reg_size;    /* # bytes needed to store fp regs.  */
  4308.   unsigned long gmask;        /* Mask of saved gp registers.  */
  4309.   unsigned long fmask;        /* Mask of saved fp registers.  */
  4310.   unsigned long reg_offset;    /* Offset to register save area.  */
  4311.   int           need_aligned_p;    /* 1 if need the save area 8 byte aligned.  */
  4312.  
  4313.   /* This is the size of the 16 word reg save area, 1 word struct addr
  4314.      area, and 4 word fp/alu register copy area.  */
  4315.   extra_size     = -STARTING_FRAME_OFFSET + FIRST_PARM_OFFSET(0);
  4316.   var_size     = size;
  4317.   /* Also include the size needed for the 6 parameter registers.  */
  4318.   args_size     = current_function_outgoing_args_size + 24;
  4319.   total_size     = var_size + args_size + extra_size;
  4320.   gp_reg_size     = 0;
  4321.   fp_reg_size     = 0;
  4322.   gmask         = 0;
  4323.   fmask         = 0;
  4324.   reg_offset     = 0;
  4325.   need_aligned_p = 0;
  4326.  
  4327.   /* Calculate space needed for gp registers.  */
  4328.   for (regno = 1; regno <= 31; regno++)
  4329.     {
  4330.       if (MUST_SAVE_REGISTER (regno))
  4331.     {
  4332.       /* If we need to save two regs in a row, ensure there's room to bump
  4333.          up the address to align it to a doubleword boundary.  */
  4334.       if ((regno & 0x1) == 0 && MUST_SAVE_REGISTER (regno+1))
  4335.         {
  4336.           if (gp_reg_size % 8 != 0)
  4337.         gp_reg_size += 4;
  4338.           gp_reg_size += 2 * UNITS_PER_WORD;
  4339.           gmask |= 3 << regno;
  4340.           regno++;
  4341.           need_aligned_p = 1;
  4342.         }
  4343.       else
  4344.         {
  4345.           gp_reg_size += UNITS_PER_WORD;
  4346.           gmask |= 1 << regno;
  4347.         }
  4348.     }
  4349.     }
  4350.  
  4351.   /* Calculate space needed for fp registers.  */
  4352.   for (regno = 32; regno <= 63; regno++)
  4353.     {
  4354.       if (regs_ever_live[regno] && !call_used_regs[regno])
  4355.     {
  4356.       fp_reg_size += UNITS_PER_WORD;
  4357.       fmask |= 1 << (regno - 32);
  4358.     }
  4359.     }
  4360.  
  4361.   if (gmask || fmask)
  4362.     {
  4363.       int n;
  4364.       reg_offset = FIRST_PARM_OFFSET(0) + args_size;
  4365.       /* Ensure save area is 8 byte aligned if we need it.  */
  4366.       n = reg_offset % 8;
  4367.       if (need_aligned_p && n != 0)
  4368.     {
  4369.       total_size += 8 - n;
  4370.       reg_offset += 8 - n;
  4371.     }
  4372.       total_size += gp_reg_size + fp_reg_size;
  4373.     }
  4374.  
  4375.   /* ??? This looks a little suspicious.  Clarify.  */
  4376.   if (total_size == extra_size)
  4377.     total_size = extra_size = 0;
  4378.  
  4379.   total_size = SPARC_STACK_ALIGN (total_size);
  4380.  
  4381.   /* Save other computed information.  */
  4382.   current_frame_info.total_size  = total_size;
  4383.   current_frame_info.var_size    = var_size;
  4384.   current_frame_info.args_size   = args_size;
  4385.   current_frame_info.extra_size  = extra_size;
  4386.   current_frame_info.gp_reg_size = gp_reg_size;
  4387.   current_frame_info.fp_reg_size = fp_reg_size;
  4388.   current_frame_info.gmask     = gmask;
  4389.   current_frame_info.fmask     = fmask;
  4390.   current_frame_info.reg_offset     = reg_offset;
  4391.   current_frame_info.initialized = reload_completed;
  4392.  
  4393.   /* Ok, we're done.  */
  4394.   return total_size;
  4395. }
  4396.  
  4397. /* Save/restore registers in GMASK and FMASK at register BASE_REG plus offset
  4398.    OFFSET.
  4399.  
  4400.    BASE_REG must be 8 byte aligned.  This allows us to test OFFSET for
  4401.    appropriate alignment and use DOUBLEWORD_OP when we can.  We assume
  4402.    [BASE_REG+OFFSET] will always be a valid address.
  4403.  
  4404.    WORD_OP is either "st" for save, "ld" for restore.
  4405.    DOUBLEWORD_OP is either "std" for save, "ldd" for restore.  */
  4406.  
  4407. void
  4408. sparc_flat_save_restore (file, base_reg, offset, gmask, fmask, word_op, doubleword_op)
  4409.      FILE *file;
  4410.      char *base_reg;
  4411.      unsigned int offset;
  4412.      unsigned long gmask;
  4413.      unsigned long fmask;
  4414.      char *word_op;
  4415.      char *doubleword_op;
  4416. {
  4417.   int regno;
  4418.  
  4419.   if (gmask == 0 && fmask == 0)
  4420.     return;
  4421.  
  4422.   /* Save registers starting from high to low.  We've already saved the
  4423.      previous frame pointer and previous return address for the debugger's
  4424.      sake.  The debugger allows us to not need a nop in the epilog if at least
  4425.      one register is reloaded in addition to return address.  */
  4426.  
  4427.   if (gmask)
  4428.     {
  4429.       for (regno = 1; regno <= 31; regno++)
  4430.     {
  4431.       if ((gmask & (1L << regno)) != 0)
  4432.         {
  4433.           if ((regno & 0x1) == 0 && ((gmask & (1L << (regno+1))) != 0))
  4434.         {
  4435.           /* We can save two registers in a row.  If we're not at a
  4436.              double word boundary, move to one.
  4437.              sparc_flat_compute_frame_size ensures there's room to do
  4438.              this.  */
  4439.           if (offset % 8 != 0)
  4440.             offset += UNITS_PER_WORD;
  4441.  
  4442.           if (word_op[0] == 's')
  4443.             fprintf (file, "\t%s %s,[%s+%d]\n",
  4444.                  doubleword_op, reg_names[regno],
  4445.                  base_reg, offset);
  4446.           else
  4447.             fprintf (file, "\t%s [%s+%d],%s\n",
  4448.                  doubleword_op, base_reg, offset,
  4449.                  reg_names[regno]);
  4450.  
  4451.           offset += 2 * UNITS_PER_WORD;
  4452.           regno++;
  4453.         }
  4454.           else
  4455.         {
  4456.           if (word_op[0] == 's')
  4457.             fprintf (file, "\t%s %s,[%s+%d]\n",
  4458.                  word_op, reg_names[regno],
  4459.                  base_reg, offset);
  4460.           else
  4461.             fprintf (file, "\t%s [%s+%d],%s\n",
  4462.                  word_op, base_reg, offset, reg_names[regno]);
  4463.  
  4464.           offset += UNITS_PER_WORD;
  4465.         }
  4466.         }
  4467.     }
  4468.     }
  4469.  
  4470.   if (fmask)
  4471.     {
  4472.       for (regno = 32; regno <= 63; regno++)
  4473.     {
  4474.       if ((fmask & (1L << (regno - 32))) != 0)
  4475.         {
  4476.           if (word_op[0] == 's')
  4477.         fprintf (file, "\t%s %s,[%s+%d]\n",
  4478.              word_op, reg_names[regno],
  4479.              base_reg, offset);
  4480.           else
  4481.         fprintf (file, "\t%s [%s+%d],%s\n",
  4482.              word_op, base_reg, offset, reg_names[regno]);
  4483.  
  4484.           offset += UNITS_PER_WORD;
  4485.         }
  4486.     }
  4487.     }
  4488. }
  4489.  
  4490. /* Set up the stack and frame (if desired) for the function.  */
  4491.  
  4492. void
  4493. sparc_flat_output_function_prologue (file, size)
  4494.      FILE *file;
  4495.      int size;
  4496. {
  4497.   char *sp_str = reg_names[STACK_POINTER_REGNUM];
  4498.   unsigned long gmask = current_frame_info.gmask;
  4499.  
  4500.   /* This is only for the human reader.  */
  4501.   fprintf (file, "\t!#PROLOGUE# 0\n");
  4502.   fprintf (file, "\t!# vars= %d, regs= %d/%d, args= %d, extra= %d\n",
  4503.        current_frame_info.var_size,
  4504.        current_frame_info.gp_reg_size / 4,
  4505.        current_frame_info.fp_reg_size / 4,
  4506.        current_function_outgoing_args_size,
  4507.        current_frame_info.extra_size);
  4508.  
  4509.   size = SPARC_STACK_ALIGN (size);
  4510.   size = (! current_frame_info.initialized
  4511.       ? sparc_flat_compute_frame_size (size)
  4512.       : current_frame_info.total_size);
  4513.  
  4514.   /* These cases shouldn't happen.  Catch them now.  */
  4515.   if (size == 0 && (gmask || current_frame_info.fmask))
  4516.     abort ();
  4517.  
  4518.   /* Allocate our stack frame by decrementing %sp.
  4519.      At present, the only algorithm gdb can use to determine if this is a
  4520.      flat frame is if we always set %i7 if we set %sp.  This can be optimized
  4521.      in the future by putting in some sort of debugging information that says
  4522.      this is a `flat' function.  However, there is still the case of debugging
  4523.      code without such debugging information (including cases where most fns
  4524.      have such info, but there is one that doesn't).  So, always do this now
  4525.      so we don't get a lot of code out there that gdb can't handle.
  4526.      If the frame pointer isn't needn't then that's ok - gdb won't be able to
  4527.      distinguish us from a non-flat function but there won't (and shouldn't)
  4528.      be any differences anyway.  The return pc is saved (if necessary) right
  4529.      after %i7 so gdb won't have to look too far to find it.  */
  4530.   if (size > 0)
  4531.     {
  4532.       unsigned int reg_offset = current_frame_info.reg_offset;
  4533.       char *fp_str = reg_names[FRAME_POINTER_REGNUM];
  4534.       char *t1_str = "%g1";
  4535.  
  4536.       /* Things get a little tricky if local variables take up more than ~4096
  4537.      bytes and outgoing arguments take up more than ~4096 bytes.  When that
  4538.      happens, the register save area can't be accessed from either end of
  4539.      the frame.  Handle this by decrementing %sp to the start of the gp
  4540.      register save area, save the regs, update %i7, and then set %sp to its
  4541.      final value.  Given that we only have one scratch register to play
  4542.      with it is the cheapest solution, and it helps gdb out as it won't
  4543.      slow down recognition of flat functions.
  4544.      Don't change the order of insns emitted here without checking with
  4545.      the gdb folk first.  */
  4546.  
  4547.       /* Is the entire register save area offsettable from %sp?  */
  4548.       if (reg_offset < 4096 - 64 * UNITS_PER_WORD)
  4549.     {
  4550.       if (size <= 4096)
  4551.         {
  4552.           fprintf (file, "\tadd %s,%d,%s\n",
  4553.                sp_str, -size, sp_str);
  4554.           if (gmask & FRAME_POINTER_MASK)
  4555.         {
  4556.           fprintf (file, "\tst %s,[%s+%d]\n",
  4557.                fp_str, sp_str, reg_offset);
  4558.           fprintf (file, "\tsub %s,%d,%s\t!# set up frame pointer\n",
  4559.                sp_str, -size, fp_str);
  4560.           reg_offset += 4;
  4561.         }
  4562.         }
  4563.       else
  4564.         {
  4565.           fprintf (file, "\tset %d,%s\n\tsub %s,%s,%s\n",
  4566.                size, t1_str, sp_str, t1_str, sp_str);
  4567.           if (gmask & FRAME_POINTER_MASK)
  4568.         {
  4569.           fprintf (file, "\tst %s,[%s+%d]\n",
  4570.                fp_str, sp_str, reg_offset);
  4571.           fprintf (file, "\tadd %s,%s,%s\t!# set up frame pointer\n",
  4572.                sp_str, t1_str, fp_str);
  4573.           reg_offset += 4;
  4574.         }
  4575.         }
  4576.       if (gmask & RETURN_ADDR_MASK)
  4577.         {
  4578.           fprintf (file, "\tst %s,[%s+%d]\n",
  4579.                reg_names[RETURN_ADDR_REGNUM], sp_str, reg_offset);
  4580.           reg_offset += 4;
  4581.         }
  4582.       sparc_flat_save_restore (file, sp_str, reg_offset,
  4583.                    gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK),
  4584.                    current_frame_info.fmask,
  4585.                    "st", "std");
  4586.     }
  4587.       else
  4588.     {
  4589.       /* Subtract %sp in two steps, but make sure there is always a
  4590.          64 byte register save area, and %sp is properly aligned.  */
  4591.       /* Amount to decrement %sp by, the first time.  */
  4592.       unsigned int size1 = ((size - reg_offset + 64) + 15) & -16;
  4593.       /* Offset to register save area from %sp.  */
  4594.       unsigned int offset = size1 - (size - reg_offset);
  4595.       
  4596.       if (size1 <= 4096)
  4597.         {
  4598.           fprintf (file, "\tadd %s,%d,%s\n",
  4599.                sp_str, -size1, sp_str);
  4600.           if (gmask & FRAME_POINTER_MASK)
  4601.         {
  4602.           fprintf (file, "\tst %s,[%s+%d]\n\tsub %s,%d,%s\t!# set up frame pointer\n",
  4603.                fp_str, sp_str, offset, sp_str, -size1, fp_str);
  4604.           offset += 4;
  4605.         }
  4606.         }
  4607.       else
  4608.         {
  4609.           fprintf (file, "\tset %d,%s\n\tsub %s,%s,%s\n",
  4610.                size1, t1_str, sp_str, t1_str, sp_str);
  4611.           if (gmask & FRAME_POINTER_MASK)
  4612.         {
  4613.           fprintf (file, "\tst %s,[%s+%d]\n\tadd %s,%s,%s\t!# set up frame pointer\n",
  4614.                fp_str, sp_str, offset, sp_str, t1_str, fp_str);
  4615.           offset += 4;
  4616.         }
  4617.         }
  4618.       if (gmask & RETURN_ADDR_MASK)
  4619.         {
  4620.           fprintf (file, "\tst %s,[%s+%d]\n",
  4621.                reg_names[RETURN_ADDR_REGNUM], sp_str, offset);
  4622.           offset += 4;
  4623.         }
  4624.       sparc_flat_save_restore (file, sp_str, offset,
  4625.                    gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK),
  4626.                    current_frame_info.fmask,
  4627.                    "st", "std");
  4628.       fprintf (file, "\tset %d,%s\n\tsub %s,%s,%s\n",
  4629.            size - size1, t1_str, sp_str, t1_str, sp_str);
  4630.     }
  4631.     }
  4632.  
  4633.   fprintf (file, "\t!#PROLOGUE# 1\n");
  4634. }
  4635.  
  4636. /* Do any necessary cleanup after a function to restore stack, frame,
  4637.    and regs. */
  4638.  
  4639. void
  4640. sparc_flat_output_function_epilogue (file, size)
  4641.      FILE *file;
  4642.      int size;
  4643. {
  4644.   rtx epilogue_delay = current_function_epilogue_delay_list;
  4645.   int noepilogue = FALSE;
  4646.  
  4647.   /* This is only for the human reader.  */
  4648.   fprintf (file, "\t!#EPILOGUE#\n");
  4649.  
  4650.   /* The epilogue does not depend on any registers, but the stack
  4651.      registers, so we assume that if we have 1 pending nop, it can be
  4652.      ignored, and 2 it must be filled (2 nops occur for integer
  4653.      multiply and divide).  */
  4654.  
  4655.   size = SPARC_STACK_ALIGN (size);
  4656.   size = (!current_frame_info.initialized
  4657.        ? sparc_flat_compute_frame_size (size)
  4658.        : current_frame_info.total_size);
  4659.  
  4660.   if (size == 0 && epilogue_delay == 0)
  4661.     {
  4662.       rtx insn = get_last_insn ();
  4663.  
  4664.       /* If the last insn was a BARRIER, we don't have to write any code
  4665.      because a jump (aka return) was put there.  */
  4666.       if (GET_CODE (insn) == NOTE)
  4667.     insn = prev_nonnote_insn (insn);
  4668.       if (insn && GET_CODE (insn) == BARRIER)
  4669.     noepilogue = TRUE;
  4670.     }
  4671.  
  4672.   if (!noepilogue)
  4673.     {
  4674.       unsigned int reg_offset = current_frame_info.reg_offset;
  4675.       unsigned int size1;
  4676.       char *sp_str = reg_names[STACK_POINTER_REGNUM];
  4677.       char *fp_str = reg_names[FRAME_POINTER_REGNUM];
  4678.       char *t1_str = "%g1";
  4679.  
  4680.       /* In the reload sequence, we don't need to fill the load delay
  4681.      slots for most of the loads, also see if we can fill the final
  4682.      delay slot if not otherwise filled by the reload sequence.  */
  4683.  
  4684.       if (size > 4095)
  4685.     fprintf (file, "\tset %d,%s\n", size, t1_str);
  4686.  
  4687.       if (frame_pointer_needed)
  4688.     {
  4689.       if (size > 4095)
  4690.         fprintf (file,"\tsub %s,%s,%s\t\t!# sp not trusted here\n",
  4691.              fp_str, t1_str, sp_str);
  4692.       else
  4693.         fprintf (file,"\tsub %s,%d,%s\t\t!# sp not trusted here\n",
  4694.              fp_str, size, sp_str);
  4695.     }
  4696.  
  4697.       /* Is the entire register save area offsettable from %sp?  */
  4698.       if (reg_offset < 4096 - 64 * UNITS_PER_WORD)
  4699.     {
  4700.       size1 = 0;
  4701.     }
  4702.       else
  4703.     {
  4704.       /* Restore %sp in two steps, but make sure there is always a
  4705.          64 byte register save area, and %sp is properly aligned.  */
  4706.       /* Amount to increment %sp by, the first time.  */
  4707.       size1 = ((reg_offset - 64 - 16) + 15) & -16;
  4708.       /* Offset to register save area from %sp.  */
  4709.       reg_offset = size1 - reg_offset;
  4710.  
  4711.       fprintf (file, "\tset %d,%s\n\tadd %s,%s,%s\n",
  4712.            size1, t1_str, sp_str, t1_str, sp_str);
  4713.     }
  4714.  
  4715.       /* We must restore the frame pointer and return address reg first
  4716.      because they are treated specially by the prologue output code.  */
  4717.       if (current_frame_info.gmask & FRAME_POINTER_MASK)
  4718.     {
  4719.       fprintf (file, "\tld [%s+%d],%s\n",
  4720.            sp_str, reg_offset, fp_str);
  4721.       reg_offset += 4;
  4722.     }
  4723.       if (current_frame_info.gmask & RETURN_ADDR_MASK)
  4724.     {
  4725.       fprintf (file, "\tld [%s+%d],%s\n",
  4726.            sp_str, reg_offset, reg_names[RETURN_ADDR_REGNUM]);
  4727.       reg_offset += 4;
  4728.     }
  4729.  
  4730.       /* Restore any remaining saved registers.  */
  4731.       sparc_flat_save_restore (file, sp_str, reg_offset,
  4732.                    current_frame_info.gmask & ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK),
  4733.                    current_frame_info.fmask,
  4734.                    "ld", "ldd");
  4735.  
  4736.       /* If we had to increment %sp in two steps, record it so the second
  4737.      restoration in the epilogue finishes up.  */
  4738.       if (size1 > 0)
  4739.     {
  4740.       size -= size1;
  4741.       if (size > 4095)
  4742.         fprintf (file, "\tset %d,%s\n",
  4743.              size, t1_str);
  4744.     }
  4745.  
  4746.       if (current_function_returns_struct)
  4747.     fprintf (file, "\tjmp %%o7+12\n");
  4748.       else
  4749.     fprintf (file, "\tretl\n");
  4750.  
  4751.       /* If the only register saved is the return address, we need a
  4752.      nop, unless we have an instruction to put into it.  Otherwise
  4753.      we don't since reloading multiple registers doesn't reference
  4754.      the register being loaded.  */
  4755.  
  4756.       if (epilogue_delay)
  4757.     {
  4758.       if (size)
  4759.         abort ();
  4760.       final_scan_insn (XEXP (epilogue_delay, 0), file, 1, -2, 1);
  4761.     }
  4762.  
  4763.       else if (size > 4095)
  4764.     fprintf (file, "\tadd %s,%s,%s\n", sp_str, t1_str, sp_str);
  4765.  
  4766.       else if (size > 0)
  4767.     fprintf (file, "\tadd %s,%d,%s\n", sp_str, size, sp_str);
  4768.  
  4769.       else
  4770.     fprintf (file, "\tnop\n");
  4771.     }
  4772.  
  4773.   /* Reset state info for each function.  */
  4774.   current_frame_info = zero_frame_info;
  4775. }
  4776.  
  4777. /* Define the number of delay slots needed for the function epilogue.
  4778.  
  4779.    On the sparc, we need a slot if either no stack has been allocated,
  4780.    or the only register saved is the return register.  */
  4781.  
  4782. int
  4783. sparc_flat_epilogue_delay_slots ()
  4784. {
  4785.   if (!current_frame_info.initialized)
  4786.     (void) sparc_flat_compute_frame_size (get_frame_size ());
  4787.  
  4788.   if (current_frame_info.total_size == 0)
  4789.     return 1;
  4790.  
  4791.   return 0;
  4792. }
  4793.  
  4794. /* Return true is TRIAL is a valid insn for the epilogue delay slot.
  4795.    Any single length instruction which doesn't reference the stack or frame
  4796.    pointer is OK.  */
  4797.  
  4798. int
  4799. sparc_flat_eligible_for_epilogue_delay (trial, slot)
  4800.      rtx trial;
  4801.      int slot;
  4802. {
  4803.   if (get_attr_length (trial) == 1
  4804.       && ! reg_mentioned_p (stack_pointer_rtx, PATTERN (trial))
  4805.       && ! reg_mentioned_p (frame_pointer_rtx, PATTERN (trial)))
  4806.     return 1;
  4807.   return 0;
  4808. }
  4809.  
  4810. /* Adjust the cost of a scheduling dependency.  Return the new cost of
  4811.    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
  4812.  
  4813. int
  4814. supersparc_adjust_cost (insn, link, dep_insn, cost)
  4815.      rtx insn;
  4816.      rtx link;
  4817.      rtx dep_insn;
  4818.      int cost;
  4819. {
  4820.   enum attr_type insn_type;
  4821.  
  4822.   if (! recog_memoized (insn))
  4823.     return 0;
  4824.  
  4825.   insn_type = get_attr_type (insn);
  4826.  
  4827.   if (REG_NOTE_KIND (link) == 0)
  4828.     {
  4829.       /* Data dependency; DEP_INSN writes a register that INSN reads some
  4830.      cycles later.  */
  4831.  
  4832.       /* if a load, then the dependence must be on the memory address;
  4833.      add an extra 'cycle'.  Note that the cost could be two cycles
  4834.      if the reg was written late in an instruction group; we can't tell
  4835.      here.  */
  4836.       if (insn_type == TYPE_LOAD || insn_type == TYPE_FPLOAD)
  4837.     return cost + 3;
  4838.  
  4839.       /* Get the delay only if the address of the store is the dependence.  */
  4840.       if (insn_type == TYPE_STORE || insn_type == TYPE_FPSTORE)
  4841.     {
  4842.       rtx pat = PATTERN(insn);
  4843.       rtx dep_pat = PATTERN (dep_insn);
  4844.  
  4845.       if (GET_CODE (pat) != SET || GET_CODE (dep_pat) != SET)
  4846.         return cost;  /* This shouldn't happen!  */
  4847.  
  4848.       /* The dependency between the two instructions was on the data that
  4849.          is being stored.  Assume that this implies that the address of the
  4850.          store is not dependent.  */
  4851.       if (rtx_equal_p (SET_DEST (dep_pat), SET_SRC (pat)))
  4852.         return cost;
  4853.  
  4854.       return cost + 3;  /* An approximation.  */
  4855.     }
  4856.  
  4857.       /* A shift instruction cannot receive its data from an instruction
  4858.      in the same cycle; add a one cycle penalty.  */
  4859.       if (insn_type == TYPE_SHIFT)
  4860.     return cost + 3;   /* Split before cascade into shift.  */
  4861.     }
  4862.   else
  4863.     {
  4864.       /* Anti- or output- dependency; DEP_INSN reads/writes a register that
  4865.      INSN writes some cycles later.  */
  4866.  
  4867.       /* These are only significant for the fpu unit; writing a fp reg before
  4868.          the fpu has finished with it stalls the processor.  */
  4869.  
  4870.       /* Reusing an integer register causes no problems.  */
  4871.       if (insn_type == TYPE_IALU || insn_type == TYPE_SHIFT)
  4872.     return 0;
  4873.     }
  4874.     
  4875.   return cost;
  4876. }
  4877.