home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / bbs / gnu / gcc-2.6.0-src.lha / GNU / src / amiga / gcc-2.6.0 / config / sparc / sparc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-28  |  135.0 KB  |  4,696 lines

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