home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / config / out-mips.c < prev    next >
C/C++ Source or Header  |  1991-06-03  |  69KB  |  2,723 lines

  1. /* Subroutines for insn-output.c for MIPS
  2.    Contributed by A. Lichnewsky, lich@inria.inria.fr.
  3.    Changes by     Michael Meissner, meissner@osf.org.
  4.    Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12.  
  13. GNU CC is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU CC; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "config.h"
  23. #include "rtl.h"
  24. #include "regs.h"
  25. #include "hard-reg-set.h"
  26. #include "real.h"
  27. #include "insn-config.h"
  28. #include "conditions.h"
  29. #include "insn-flags.h"
  30. #include "insn-attr.h"
  31. #include "insn-codes.h"
  32. #include "recog.h"
  33. #include "output.h"
  34.  
  35. #include <stdio.h>
  36. #include <sys/types.h>
  37. #include <sys/file.h>
  38. #include "tree.h"
  39. #include "expr.h"
  40.  
  41. #include "flags.h"
  42.  
  43. #ifndef R_OK
  44. #define R_OK 4
  45. #define W_OK 2
  46. #define X_OK 1
  47. #endif
  48.  
  49. extern void  debug_rtx ();
  50. extern void  abort_with_insn ();
  51.  
  52. extern FILE *asm_out_file;
  53. extern tree current_function_decl;
  54.  
  55. /* Global variables for machine-dependent things.  */
  56.  
  57. /* Threshold for data being put into the small data/bss area, instead
  58.    of the normal data area (references to the small data/bss area take
  59.    1 instruction, and use the global pointer, references to the normal
  60.    data area takes 2 instructions).  */
  61. int mips_section_threshold = -1;
  62.  
  63. /* Value of the -G xx switch, and whether it was passed or not.  */
  64. int g_switch_value = 0;
  65. int g_switch_set   = FALSE;
  66.  
  67. /* Count the number of .file directives, so that .loc is up to date.  */
  68. int num_source_filenames = 0;
  69.  
  70. /* Count of the number of functions created so far, in order to make
  71.    unique labels for omitting the frame pointer.  */
  72. int number_functions_processed = 0;
  73.  
  74. /* Count the number of sdb related labels are generated (to find block
  75.    start and end boundaries).  */
  76. int sdb_label_count = 0;
  77.  
  78. /* Next label # for each statment for Silicon Graphics IRIS systems. */
  79. int sym_lineno = 0;
  80.  
  81. /* Non-zero if inside of a function, because the stupid MIPS asm can't
  82.    handle .files inside of functions.  */
  83. int inside_function = 0;
  84.  
  85. /* Files to separate the text and the data output, so that all of the data
  86.    can be emitted before the text, which will mean that the assembler will
  87.    generate smaller code, based on the global pointer.  */
  88. FILE *asm_out_data_file;
  89. FILE *asm_out_text_file;
  90.  
  91. /* Linked list of all externals that are to be emitted when optimizing
  92.    for the global pointer if they haven't been declared by the end of
  93.    the program with an appropriate .comm or initialization.  */
  94.  
  95. struct extern_list {
  96.   struct extern_list *next;    /* next external */
  97.   char *name;            /* name of the external */
  98.   int size;            /* size in bytes */
  99. } *extern_head = 0;
  100.  
  101. /* Name of the current function.  */
  102. char *current_function_name;
  103.  
  104. /* Name of the file containing the current function.  */
  105. char *current_function_file = "";
  106.  
  107. /* Warning given that Mips ECOFF can't support changing files
  108.    within a function.  */
  109. int file_in_function_warning;
  110.  
  111. /* number of nested .set noreorder requests.  */
  112. int set_noreorder;
  113.  
  114. /* number of nested .set noat requests.  */
  115. int set_noat;
  116.  
  117. /* number of nested .set nomacro requests. */
  118. int set_nomacro;
  119.  
  120. /* Count of delay slots and how many are filled.  */
  121. int dslots_load_total;
  122. int dslots_load_filled;
  123. int dslots_jump_total;
  124. int dslots_jump_filled;
  125.  
  126. /* Cached operands, and operator to compare for use in set/branch on
  127.    condition codes.  */
  128. rtx branch_cmp[2];
  129.  
  130. /* what type of branch to use */
  131. enum cmp_type branch_type;
  132.  
  133. /* Array to RTX class classification.  At present, we care about
  134.    whether the operator is an add-type operator, or a divide/modulus,
  135.    and if divide/modulus, whether it is unsigned.  This is for the
  136.    peephole code.  */
  137. char mips_rtx_classify[NUM_RTX_CODE];
  138.  
  139. /* Current frame information calculated by compute_frame_size.  */
  140. struct mips_frame_info current_frame_info;
  141.  
  142. /* Zero structure to initialize current_frame_info.  */
  143. struct mips_frame_info zero_frame_info;
  144.  
  145. /* List of all MIPS punctuation characters used by print_operand.  */
  146. char mips_print_operand_punct[256];
  147.  
  148. /* Hardware names for the registers.  If -mrnames is used, this
  149.    will be overwritten with mips_sw_reg_names.  */
  150.  
  151. char mips_reg_names[][8] =
  152. {
  153.  "$0",   "$1",   "$2",   "$3",   "$4",   "$5",   "$6",   "$7",
  154.  "$8",   "$9",   "$10",  "$11",  "$12",  "$13",  "$14",  "$15",
  155.  "$16",  "$17",  "$18",  "$19",  "$20",  "$21",  "$22",  "$23",
  156.  "$24",  "$25",  "$26",  "$27",  "$28",  "$sp",  "$fp",  "$31",
  157.  "$f0",  "$f1",  "$f2",  "$f3",  "$f4",  "$f5",  "$f6",  "$f7",
  158.  "$f8",  "$f9",  "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
  159.  "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
  160.  "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
  161.  "hi",   "lo",   "$fcr31"
  162. };
  163.  
  164. /* Mips software names for the registers, used to overwrite the
  165.    mips_reg_names array.  */
  166.  
  167. char mips_sw_reg_names[][8] =
  168. {
  169.   "$0",   "at",   "v0",   "v1",   "a0",   "a1",   "a2",   "a3",
  170.   "t0",   "t1",   "t2",   "t3",   "t4",   "t5",   "t6",   "t7",
  171.   "s0",   "s1",   "s2",   "s3",   "s4",   "s5",   "s6",   "s7",
  172.   "t8",   "t9",   "k0",   "k1",   "gp",   "sp",   "fp",   "ra",
  173.   "$f0",  "$f1",  "$f2",  "$f3",  "$f4",  "$f5",  "$f6",  "$f7",
  174.   "$f8",  "$f9",  "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
  175.   "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
  176.   "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
  177.   "hi",   "lo",   "$fcr31"
  178. };
  179.  
  180. /* Register classes */
  181. enum reg_class mips_regno_to_class[] =
  182. {
  183.   GR_REGS,    GR_REGS,    GR_REGS,    GR_REGS,
  184.   GR_REGS,    GR_REGS,    GR_REGS,    GR_REGS,
  185.   GR_REGS,    GR_REGS,    GR_REGS,    GR_REGS,
  186.   GR_REGS,    GR_REGS,    GR_REGS,    GR_REGS,
  187.   GR_REGS,    GR_REGS,    GR_REGS,    GR_REGS,
  188.   GR_REGS,    GR_REGS,    GR_REGS,    GR_REGS,
  189.   GR_REGS,    GR_REGS,    GR_REGS,    GR_REGS,
  190.   GR_REGS,    GR_REGS,    GR_REGS,    GR_REGS,
  191.   FP_REGS,    FP_REGS,    FP_REGS,    FP_REGS,
  192.   FP_REGS,    FP_REGS,    FP_REGS,    FP_REGS,
  193.   FP_REGS,    FP_REGS,    FP_REGS,    FP_REGS,
  194.   FP_REGS,    FP_REGS,    FP_REGS,    FP_REGS,
  195.   FP_REGS,    FP_REGS,    FP_REGS,    FP_REGS,
  196.   FP_REGS,    FP_REGS,    FP_REGS,    FP_REGS,
  197.   FP_REGS,    FP_REGS,    FP_REGS,    FP_REGS,
  198.   FP_REGS,    FP_REGS,    FP_REGS,    FP_REGS,
  199.   HI_REG,    LO_REG,        ST_REGS
  200. };
  201.  
  202.  
  203. /* Return truth value of whether OP can be used as an operands
  204.    where a register or 16 bit unsigned integer is needed.  */
  205.  
  206. int
  207. uns_arith_operand (op, mode)
  208.      rtx op;
  209.      enum machine_mode mode;
  210. {
  211.   if (GET_CODE (op) == CONST_INT && SMALL_INT_UNSIGNED (op))
  212.     return TRUE;
  213.  
  214.   return register_operand (op, mode);
  215. }
  216.  
  217. /* Return truth value of whether OP can be used as an operands
  218.    where a 16 bit integer is needed  */
  219.  
  220. int
  221. arith_operand (op, mode)
  222.      rtx op;
  223.      enum machine_mode mode;
  224. {
  225.   if (GET_CODE (op) == CONST_INT && SMALL_INT (op))
  226.     return TRUE;
  227.  
  228.   return register_operand (op, mode);
  229. }
  230.  
  231. /* Return truth value of whether OP can be used as an operand in a two
  232.    address arithmetic insn (such as set 123456,%o4) of mode MODE.  */
  233.  
  234. int
  235. arith32_operand (op, mode)
  236.      rtx op;
  237.      enum machine_mode mode;
  238. {
  239.   if (GET_CODE (op) == CONST_INT)
  240.     return TRUE;
  241.  
  242.   return register_operand (op, mode);
  243. }
  244.  
  245. /* Return truth value of whether OP is a integer which fits in 16 bits  */
  246.  
  247. int
  248. small_int (op, mode)
  249.      rtx op;
  250.      enum machine_mode mode;
  251. {
  252.   return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
  253. }
  254.  
  255. /* Return truth value of whether OP is an integer which is too big to
  256.    be loaded with one instruction.  */
  257.  
  258. int
  259. large_int (op, mode)
  260.      rtx op;
  261.      enum machine_mode mode;
  262. {
  263.   long value;
  264.  
  265.   if (GET_CODE (op) != CONST_INT)
  266.     return FALSE;
  267.  
  268.   value = INTVAL (op);
  269.   if ((value & 0xffff0000) == 0)        /* ior reg,$r0,value */
  270.     return FALSE;
  271.  
  272.   if ((value & 0xffff0000) == 0xffff0000)    /* subu reg,$r0,value */
  273.     return FALSE;
  274.  
  275.   if ((value & 0x0000ffff) == 0)        /* lui reg,value>>16 */
  276.     return FALSE;
  277.  
  278.   return TRUE;
  279. }
  280.  
  281. /* Return truth value of whether OP is a register or the constant 0.  */
  282.  
  283. int
  284. reg_or_0_operand (op, mode)
  285.      rtx op;
  286.      enum machine_mode mode;
  287. {
  288.   switch (GET_CODE (op))
  289.     {
  290.     case CONST_INT:
  291.       return (INTVAL (op) == 0);
  292.  
  293.     case CONST_DOUBLE:
  294.       if (CONST_DOUBLE_HIGH (op) != 0 || CONST_DOUBLE_LOW (op) != 0)
  295.     return FALSE;
  296.  
  297.       return TRUE;
  298.  
  299.     case REG:
  300.       return TRUE;
  301.  
  302.     case SUBREG:
  303.       return register_operand (op, mode);
  304.     }
  305.  
  306.   return FALSE;
  307. }
  308.  
  309. /* Return truth value of whether OP is one of the special multiply/divide
  310.    registers (hi, lo).  */
  311.  
  312. int
  313. md_register_operand (op, mode)
  314.      rtx op;
  315.      enum machine_mode mode;
  316. {
  317.   return (GET_MODE_CLASS (mode) == MODE_INT
  318.       && GET_CODE (op) == REG
  319.       && MD_REG_P (REGNO (op)));
  320. }
  321.  
  322. /* Return truth value if a CONST_DOUBLE is ok to be a legitimate constant.  */
  323.  
  324. int
  325. mips_const_double_ok (op, mode)
  326.      rtx op;
  327.      enum machine_mode mode;
  328. {
  329.   if (GET_CODE (op) != CONST_DOUBLE)
  330.     return FALSE;
  331.  
  332.   if (mode == DImode)
  333.     return TRUE;
  334.  
  335.   if (mode != SFmode && mode != DFmode)
  336.     return FALSE;
  337.  
  338.   if (CONST_DOUBLE_HIGH (op) == 0 && CONST_DOUBLE_LOW (op) == 0)
  339.     return TRUE;
  340.  
  341. #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
  342.   if (TARGET_MIPS_AS)        /* gas doesn't like li.d/li.s yet */
  343.     {
  344.       union { double d; int i[2]; } u;
  345.       double d;
  346.  
  347.       u.i[0] = CONST_DOUBLE_LOW (op);
  348.       u.i[1] = CONST_DOUBLE_HIGH (op);
  349.       d = u.d;
  350.  
  351.       if (d != d)
  352.     return FALSE;        /* NAN */
  353.  
  354.       if (d < 0.0)
  355.     d = - d;
  356.  
  357.       /* Rather than trying to get the accuracy down to the last bit,
  358.      just use approximate ranges.  */
  359.  
  360.       if (mode == DFmode && d > 1.0e-300 && d < 1.0e300)
  361.     return TRUE;
  362.  
  363.       if (mode == SFmode && d > 1.0e-38 && d < 1.0e+38)
  364.     return TRUE;
  365.     }
  366. #endif
  367.  
  368.   return FALSE;
  369. }
  370.  
  371. /* Return truth value if a memory operand fits in a single instruction (ie,
  372.    register + small offset).  */
  373.  
  374. int
  375. simple_memory_operand (op, mode)
  376.      rtx op;
  377.      enum machine_mode mode;
  378. {
  379.   rtx addr, plus0, plus1;
  380.   int offset = 0;
  381.  
  382.   /* Eliminate non-memory operations */
  383.   if (GET_CODE (op) != MEM)
  384.     return FALSE;
  385.  
  386.   /* dword operations really put out 2 instructions, so eliminate them.  */
  387.   if (GET_MODE_SIZE (GET_MODE (op)) > 4)
  388.     return FALSE;
  389.  
  390.   /* Decode the address now.  */
  391.   addr = XEXP (op, 0);
  392.   switch (GET_CODE (addr))
  393.     {
  394.     case REG:
  395.       return TRUE;
  396.  
  397.     case CONST_INT:
  398.       return SMALL_INT (op);
  399.  
  400.     case PLUS:
  401.       plus0 = XEXP (addr, 0);
  402.       plus1 = XEXP (addr, 1);
  403.       if (GET_CODE (plus0) != REG && GET_CODE (plus1) == REG)
  404.     {
  405.       plus0 = XEXP (addr, 1);
  406.       plus1 = XEXP (addr, 0);
  407.     }
  408.  
  409.       if (GET_CODE (plus0) == REG
  410.       && GET_CODE (plus1) == CONST_INT
  411.       && SMALL_INT (plus1))
  412.     return TRUE;
  413.       break;
  414.  
  415.     case LABEL_REF:        /* never gp relative */
  416.       break;
  417.  
  418.     case CONST:
  419.       /* If -G 0, we can never have a GP relative memory operation */
  420.       if (mips_section_threshold == 0)
  421.     return FALSE;
  422.  
  423.       addr = eliminate_constant_term (addr, &offset);
  424.       if (GET_CODE (op) != SYMBOL_REF)
  425.     return FALSE;
  426.  
  427.       /* fall through */
  428.  
  429.     case SYMBOL_REF:
  430.       /* let's be paranoid.... */
  431.       if (offset < 0 || offset > 0xffff)
  432.     return FALSE;
  433.  
  434.       return SYMBOL_REF_FLAG (addr);
  435.     }
  436.  
  437.   return FALSE;
  438. }
  439.  
  440. /* Return true if the code of this rtx pattern is EQ or NE.  */
  441.  
  442. int
  443. equality_op (op, mode)
  444.      rtx op;
  445.      enum machine_mode mode;
  446. {
  447.   if (mode != GET_MODE (op))
  448.     return FALSE;
  449.  
  450.   return (classify_op (op, mode) & CLASS_EQUALITY_OP) != 0;
  451. }
  452.  
  453. /* Return true if the code is a relational operations (EQ, LE, etc.) */
  454.  
  455. int
  456. cmp_op (op, mode)
  457.      rtx op;
  458.      enum machine_mode mode;
  459. {
  460.   if (mode != GET_MODE (op))
  461.     return FALSE;
  462.  
  463.   return (classify_op (op, mode) & CLASS_CMP_OP) != 0;
  464. }
  465.  
  466. /* Return true if the code is an unsigned relational operations (LEU, etc.) */
  467.  
  468. int
  469. uns_cmp_op (op,mode)
  470.      rtx op;
  471.      enum machine_mode mode;
  472. {
  473.   if (mode != GET_MODE (op))
  474.     return FALSE;
  475.  
  476.   return (classify_op (op, mode) & CLASS_UNS_CMP_OP) == CLASS_UNS_CMP_OP;
  477. }
  478.  
  479.  
  480. /* Return the appropriate instructions to move one operand to another.  */
  481.  
  482. char *
  483. mips_move_1word (operands, insn)
  484.      rtx operands[];
  485.      rtx insn;
  486. {
  487.   rtx op0 = operands[0];
  488.   rtx op1 = operands[1];
  489.   enum rtx_code code0 = GET_CODE (op0);
  490.   enum rtx_code code1 = GET_CODE (op1);
  491.   enum machine_mode mode = GET_MODE (op0);
  492.   int subreg_word0 = 0;
  493.   int subreg_word1 = 0;
  494.  
  495.   while (code0 == SUBREG)
  496.     {
  497.       subreg_word0 += SUBREG_WORD (op0);
  498.       op0 = SUBREG_REG (op0);
  499.       code0 = GET_CODE (op0);
  500.     }
  501.  
  502.   while (code1 == SUBREG)
  503.     {
  504.       subreg_word1 += SUBREG_WORD (op1);
  505.       op1 = SUBREG_REG (op1);
  506.       code1 = GET_CODE (op1);
  507.     }
  508.  
  509.   if (code0 == REG)
  510.     {
  511.       int regno0 = REGNO (op0) + subreg_word0;
  512.  
  513.       if (code1 == REG)
  514.     {
  515.       int regno1 = REGNO (op1) + subreg_word1;
  516.  
  517.       if (GP_REG_P (regno0))
  518.         {
  519.           if (GP_REG_P (regno1))
  520.         return "move\t%0,%1";
  521.  
  522.           if (FP_REG_P (regno1))
  523.         return "mfc1\t%0,%1";
  524.  
  525.           if (MD_REG_P (regno1))
  526.         return "mf%1\t%0";
  527.  
  528.           if (regno1 == FPSW_REGNUM)
  529.         return "cfc1\t%0,$31\n\tcfc1\t%0,$31";
  530.         }
  531.  
  532.       else if (FP_REG_P (regno0))
  533.         {
  534.           if (GP_REG_P (regno1))
  535.         return "mtc1\t%1,%0";
  536.  
  537.           if (FP_REG_P (regno1))
  538.         return "mov.s\t%0,%1";
  539.         }
  540.  
  541.       else if (MD_REG_P (regno0))
  542.         {
  543.           if (GP_REG_P (regno1))
  544.         return "mt%0\t%1";
  545.         }
  546.  
  547.       else if (regno0 == FPSW_REGNUM)
  548.         {
  549.           if (GP_REG_P (regno1))
  550.          return "ctc1\t%0,$31\n\tctc1\t%0,$31";
  551.         }
  552.     }
  553.  
  554.       else if (code1 == MEM)
  555.     {
  556.       if (GP_REG_P (regno0))
  557.         {
  558.           switch (mode)
  559.         {
  560.         /* Because BYTE_LOADS_ZERO_EXTEND is defined, we must use
  561.            the unsigned version of lb/lh.  */
  562.         case SFmode: return "lw\t%0,%1";
  563.         case SImode: return "lw\t%0,%1";
  564.         case HImode: return "lhu\t%0,%1";
  565.         case QImode: return "lbu\t%0,%1";
  566.         }
  567.         }
  568.  
  569.       else if (FP_REG_P (regno0) && (mode == SImode || mode == SFmode))
  570.         return "l.s\t%0,%1";
  571.     }
  572.  
  573.       else if (code1 == CONST_INT)
  574.     {
  575.       if (INTVAL (op1) == 0)
  576.         {
  577.           if (GP_REG_P (regno0))
  578.         return "move\t%0,%z1";
  579.  
  580.           if (FP_REG_P (regno0))
  581.         return "mtc1\t%z1,%0";
  582.         }
  583.  
  584.       else if (GP_REG_P (regno0))
  585.         {
  586.           if ((INTVAL (operands[1]) & 0x0000ffff) == 0)
  587.         return "lui\t%0,(%X1)>>16";
  588.  
  589.           return "li\t%0,%1";
  590.         }
  591.     }
  592.  
  593.       else if (code1 == CONST_DOUBLE && mode == SFmode)
  594.     {
  595.       if (CONST_DOUBLE_HIGH (op1) == 0 && CONST_DOUBLE_LOW (op1) == 0)
  596.         {
  597.           operands[2] = const0_rtx;
  598.           if (GP_REG_P (regno0))
  599.         return "move\t%0,%z2";
  600.  
  601.           if (FP_REG_P (regno0))
  602.         return "mtc1\t%z2,%0";
  603.         }
  604.  
  605.       else
  606.         return "li.s\t%0,%1";
  607.     }
  608.  
  609.       else if (code1 == SYMBOL_REF || code1 == LABEL_REF || code1 == CONST)
  610.     return "la\t%0,%a1";
  611.  
  612.       else if (code1 == PLUS)
  613.     {
  614.       rtx add_op0 = XEXP (op1, 0);
  615.       rtx add_op1 = XEXP (op1, 1);
  616.  
  617.       if (GET_CODE (XEXP (op1, 1)) == REG && GET_CODE (XEXP (op1, 0)) == CONST_INT)
  618.         {
  619.           add_op0 = XEXP (op1, 1);        /* reverse operands */
  620.           add_op1 = XEXP (op1, 0);
  621.         }
  622.  
  623.       operands[2] = add_op0;
  624.       operands[3] = add_op1;
  625.       return "add%:\t%0,%2,%3";
  626.     }
  627.     }
  628.  
  629.   else if (code0 == MEM)
  630.     {
  631.       if (code1 == REG)
  632.     {
  633.       int regno1 = REGNO (op1) + subreg_word1;
  634.  
  635.       if (GP_REG_P (regno1))
  636.         {
  637.           switch (mode)
  638.         {
  639.         case SFmode:
  640.         case SImode: return "sw\t%1,%0";
  641.         case HImode: return "sh\t%1,%0";
  642.         case QImode: return "sb\t%1,%0";
  643.         }
  644.         }
  645.  
  646.       else if (FP_REG_P (regno1) && (mode == SImode || mode == SFmode))
  647.         return "s.s\t%1,%0";
  648.     }
  649.  
  650.       else if (code1 == CONST_INT && INTVAL (op1) == 0)
  651.     {
  652.       switch (mode)
  653.         {
  654.         case SFmode:
  655.         case SImode: return "sw\t%z1,%0";
  656.         case HImode: return "sh\t%z1,%0";
  657.         case QImode: return "sb\t%z1,%0";
  658.         }
  659.     }
  660.  
  661.       else if (code1 == CONST_DOUBLE && CONST_DOUBLE_HIGH (op1) == 0 && CONST_DOUBLE_LOW (op1) == 0)
  662.     {
  663.       operands[2] = const0_rtx;
  664.       switch (mode)
  665.         {
  666.         case SFmode:
  667.         case SImode: return "sw\t%z2,%0";
  668.         case HImode: return "sh\t%z2,%0";
  669.         case QImode: return "sb\t%z2,%0";
  670.         }
  671.     }
  672.     }
  673.  
  674.   abort_with_insn (insn, "Bad move");
  675.   return 0;
  676. }
  677.  
  678.  
  679. /* Return the appropriate instructions to move 2 words */
  680.  
  681. char *
  682. mips_move_2words (operands, insn)
  683.      rtx operands[];
  684.      rtx insn;
  685. {
  686.   extern rtx adj_offsettable_operand ();
  687.   extern int offsettable_address_p ();
  688.  
  689.   rtx op0 = operands[0];
  690.   rtx op1 = operands[1];
  691.   enum rtx_code code0 = GET_CODE (operands[0]);
  692.   enum rtx_code code1 = GET_CODE (operands[1]);
  693.   int subreg_word0 = 0;
  694.   int subreg_word1 = 0;
  695.  
  696.   while (code0 == SUBREG)
  697.     {
  698.       subreg_word0 += SUBREG_WORD (op0);
  699.       op0 = SUBREG_REG (op0);
  700.       code0 = GET_CODE (op0);
  701.     }
  702.  
  703.   while (code1 == SUBREG)
  704.     {
  705.       subreg_word1 += SUBREG_WORD (op1);
  706.       op1 = SUBREG_REG (op1);
  707.       code1 = GET_CODE (op1);
  708.     }
  709.       
  710.   if (code0 == REG)
  711.     {
  712.       int regno0 = REGNO (op0) + subreg_word0;
  713.  
  714.       if (code1 == REG)
  715.     {
  716.       int regno1 = REGNO (op1) + subreg_word1;
  717.  
  718.       if (FP_REG_P (regno0))
  719.         {
  720.           if (FP_REG_P (regno1))
  721.         return "mov.d\t%0,%1";
  722.           else
  723.         return "mtc1\t%L1,%0\n\tmtc1\t%M1,%D0";
  724.         }
  725.  
  726.       else if (FP_REG_P (regno1))
  727.         return "mfc1\t%L0,%1\n\tmfc1\t%M0,%D1";
  728.  
  729.       else if (regno0 != (regno1+1))
  730.         return "move\t%0,%1\n\tmove\t%D0,%D1";
  731.  
  732.       else
  733.         return "move\t%D0,%D1\n\tmove\t%0,%1";
  734.     }
  735.  
  736.       else if (code1 == CONST_DOUBLE)
  737.     {
  738.       if (CONST_DOUBLE_HIGH (op1) != 0 || CONST_DOUBLE_LOW (op1) != 0)
  739.         {
  740.           if (GET_MODE (op1) == DFmode)
  741.         return "li.d\t%0,%1";
  742.  
  743.           operands[2] = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_LOW (op1));
  744.           operands[3] = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_HIGH (op1));
  745.           return "li\t%M0,%3\n\tli\t%L0,%2";
  746.         }
  747.  
  748.       operands[2] = const0_rtx;
  749.       if (GP_REG_P (regno0))
  750.         return "move\t%z2,%0\n\tmove\t%z2,%D0";
  751.  
  752.       else if (FP_REG_P (regno0))
  753.         return "mtc1\t%z2,%0\n\tmtc1\t%z2,%D0";
  754.     }
  755.  
  756.       else if (code1 == CONST_INT && GET_MODE (op0) == DImode && GP_REG_P (regno0))
  757.     {
  758.       operands[2] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[1]) >= 0 ? 0 : -1);
  759.       return "li\t%M0,%2\n\tli\t%L0,%1";
  760.     }
  761.  
  762.       else if (code1 == MEM)
  763.     {
  764.       if (FP_REG_P (regno0))
  765.         return "l.d\t%0,%1";
  766.  
  767.       else if (offsettable_address_p (1, DFmode, XEXP (op1, 0)))
  768.         {
  769.           operands[2] = adj_offsettable_operand (op1, 4);
  770.           if (reg_mentioned_p (op0, op1))
  771.         return "lw\t%D0,%2\n\tlw\t%0,%1";
  772.           else
  773.         return "lw\t%0,%1\n\tlw\t%D0,%2";
  774.         }
  775.     }
  776.     }
  777.  
  778.   else if (code0 == MEM && code1 == REG)
  779.     {
  780.       int regno1 = REGNO (op1) + subreg_word1;
  781.  
  782.       if (FP_REG_P (regno1))
  783.     return "s.d\t%1,%0";
  784.  
  785.       else if (offsettable_address_p (1, DFmode, XEXP (op0, 0)))
  786.     {
  787.       operands[2] = adj_offsettable_operand (op0, 4);
  788.       return "sw\t%1,%0\n\tsw\t%D1,%2";
  789.     }
  790.     }
  791.  
  792.   else if (code0 == MEM && CONST_DOUBLE_HIGH (op1) == 0 && CONST_DOUBLE_LOW (op1) == 0)
  793.     {
  794.       if (offsettable_address_p (1, DFmode, XEXP (op0, 0)))
  795.     {
  796.       operands[2] = adj_offsettable_operand (op0, 4);
  797.       operands[3] = const0_rtx;
  798.       return "sw\t%z3,%0\n\tsw\t%z3,%2";
  799.     }
  800.     }
  801.  
  802.   abort_with_insn (insn, "Bad move double");
  803.   return "";
  804. }
  805.  
  806.  
  807. /* Provide the costs of an addressing mode that contains ADDR.
  808.    If ADDR is not a valid address, it's cost is irrelavent.  */
  809.  
  810. int
  811. mips_address_cost (addr)
  812.      rtx addr;
  813. {
  814.   int offset;
  815.  
  816.   switch (GET_CODE (addr))
  817.     {
  818.     case LO_SUM:
  819.     case HIGH:
  820.       return 1;
  821.  
  822.     case LABEL_REF:
  823.       return 2;
  824.  
  825.     case CONST:
  826.       offset = 0;
  827.       addr = eliminate_constant_term (addr, &offset);
  828.       if (GET_CODE (addr) == LABEL_REF)
  829.     return 2;
  830.  
  831.       if (GET_CODE (addr) != SYMBOL_REF)
  832.     return 4;
  833.  
  834.       if (offset < -32768 || offset > 32767)
  835.     return 2;
  836.  
  837.       /* fall through */
  838.  
  839.     case SYMBOL_REF:
  840.       return SYMBOL_REF_FLAG (addr) ? 1 : 2;
  841.  
  842.     case PLUS:
  843.       {
  844.     register rtx plus0 = XEXP (addr, 0);
  845.     register rtx plus1 = XEXP (addr, 1);
  846.  
  847.     if (GET_CODE (plus0) != REG && GET_CODE (plus1) == REG)
  848.       {
  849.         plus0 = XEXP (addr, 1);
  850.         plus1 = XEXP (addr, 0);
  851.       }
  852.  
  853.     if (GET_CODE (plus0) != REG)
  854.       break;
  855.  
  856.     switch (GET_CODE (plus1))
  857.       {
  858.       case CONST_INT:
  859.         {
  860.           int value = INTVAL (plus1);
  861.           return (value < -32768 || value > 32767) ? 2 : 1;
  862.         }
  863.  
  864.       case CONST:
  865.       case SYMBOL_REF:
  866.       case LABEL_REF:
  867.       case HIGH:
  868.       case LO_SUM:
  869.         return mips_address_cost (plus1) + 1;
  870.       }
  871.       }
  872.     }
  873.  
  874.   return 4;
  875. }
  876.  
  877.  
  878. /* Emit the common code for doing conditional branches.
  879.    operand[0] is the label to jump to.
  880.    The comparison operands are saved away by cmp{si,sf,df}.  */
  881.  
  882. void
  883. gen_conditional_branch (operands, test_code)
  884.      rtx operands[];
  885.      enum rtx_code test_code;
  886. {
  887.   enum {
  888.     I_EQ,
  889.     I_NE,
  890.     I_GT,
  891.     I_GE,
  892.     I_LT,
  893.     I_LE,
  894.     I_GTU,
  895.     I_GEU,
  896.     I_LTU,
  897.     I_LEU,
  898.     I_MAX
  899.   } test = I_MAX;
  900.  
  901.   static enum machine_mode mode_map[ (int)CMP_MAX ][ (int)I_MAX ] = {
  902.     {                /* CMP_SI */
  903.       CC_EQmode,        /* eq  */
  904.       CC_EQmode,        /* ne  */
  905.       CCmode,            /* gt  */
  906.       CCmode,            /* ge  */
  907.       CCmode,            /* lt  */
  908.       CCmode,            /* le  */
  909.       CCmode,            /* gtu */
  910.       CCmode,            /* geu */
  911.       CCmode,            /* ltu */
  912.       CCmode,            /* leu */
  913.     },
  914.     {                /* CMP_SF */
  915.       CC_FPmode,        /* eq  */
  916.       CC_FPmode,        /* ne  */
  917.       CC_FPmode,        /* gt  */
  918.       CC_FPmode,        /* ge  */
  919.       CC_FPmode,        /* lt  */
  920.       CC_FPmode,        /* le  */
  921.       VOIDmode,            /* gtu */
  922.       VOIDmode,            /* geu */
  923.       VOIDmode,            /* ltu */
  924.       VOIDmode,            /* leu */
  925.     },
  926.     {                /* CMP_DF */
  927.       CC_FPmode,        /* eq  */
  928.       CC_FPmode,        /* ne  */
  929.       CC_FPmode,        /* gt  */
  930.       CC_FPmode,        /* ge  */
  931.       CC_FPmode,        /* lt  */
  932.       CC_FPmode,        /* le  */
  933.       VOIDmode,            /* gtu */
  934.       VOIDmode,            /* geu */
  935.       VOIDmode,            /* ltu */
  936.       VOIDmode,            /* leu */
  937.     },
  938.   };
  939.  
  940.   static enum rtx_code reverse_fp_test[ (int)I_MAX ] = {
  941.     0,                /* eq  */
  942.     EQ,                /* ne  */
  943.     LE,                /* gt  */
  944.     LT,                /* ge  */
  945.     0,                /* lt  */
  946.     0,                /* le  */
  947.     0,                /* gtu */
  948.     0,                /* geu */
  949.     0,                /* ltu */
  950.     0,                /* leu */
  951.   };
  952.  
  953.   enum machine_mode mode;
  954.   enum rtx_code fp_code;
  955.   enum cmp_type type = branch_type;
  956.   rtx cmp0 = branch_cmp[0];
  957.   rtx cmp1 = branch_cmp[1];
  958.   rtx label = gen_rtx (LABEL_REF, VOIDmode, operands[0]);
  959.   rtx jump0;
  960.   rtx jump1;
  961.  
  962.   /* Make normal rtx_code into something we can index from an array */
  963.   switch (test_code)
  964.     {
  965.     case EQ:  test = I_EQ;  break;
  966.     case NE:  test = I_NE;  break;
  967.     case GT:  test = I_GT;  break;
  968.     case GE:  test = I_GE;  break;
  969.     case LT:  test = I_LT;  break;
  970.     case LE:  test = I_LE;  break;
  971.     case GTU: test = I_GTU; break;
  972.     case GEU: test = I_GEU; break;
  973.     case LTU: test = I_LTU; break;
  974.     case LEU: test = I_LEU; break;
  975.     }
  976.  
  977.   if (test == I_MAX)
  978.     {
  979.       mode = CCmode;
  980.       goto fail;
  981.     }
  982.  
  983.   /* Get the machine mode to use (CCmode, CC_EQmode, or CC_FPmode).  */
  984.   mode = mode_map[ (int)type ][ (int)test ];
  985.   if (mode == VOIDmode)
  986.     goto fail;
  987.  
  988.   switch (branch_type)
  989.     {
  990.     case CMP_SI:
  991.       /* Change >, >=, <, <= tests against 0 to use CC_0mode, since we have
  992.      special instructions to do these tests directly. */
  993.  
  994.       if (mode == CCmode && GET_CODE (cmp1) == CONST_INT && INTVAL (cmp1) == 0)
  995.     {
  996.       emit_insn (gen_rtx (SET, VOIDmode, cc0_rtx, cmp0));
  997.       mode = CC_0mode;
  998.     }
  999.  
  1000.       else if (mode == CCmode && GET_CODE (cmp0) == CONST_INT && INTVAL (cmp0) == 0)
  1001.     {
  1002.       emit_insn (gen_rtx (SET, VOIDmode, cc0_rtx, cmp1));
  1003.       test_code = reverse_condition (test_code);
  1004.       mode = CC_0mode;
  1005.     }
  1006.  
  1007.       else
  1008.     {
  1009.       /* force args to register for equality comparisons. */
  1010.       if (mode == CC_EQmode && GET_CODE (cmp1) == CONST_INT && INTVAL (cmp1) != 0)
  1011.         cmp1 = force_reg (SImode, cmp1);
  1012.  
  1013.       emit_insn (gen_rtx (SET, VOIDmode,
  1014.                   cc0_rtx,
  1015.                   gen_rtx (COMPARE, mode, cmp0, cmp1)));
  1016.     }
  1017.  
  1018.       emit_jump_insn (gen_rtx (SET, VOIDmode,
  1019.                    pc_rtx,
  1020.                    gen_rtx (IF_THEN_ELSE, VOIDmode,
  1021.                     gen_rtx (test_code, mode, cc0_rtx, const0_rtx),
  1022.                     label,
  1023.                     pc_rtx)));
  1024.       return;
  1025.  
  1026.     case CMP_DF:
  1027.     case CMP_SF:
  1028.       fp_code = reverse_fp_test[ (int)test ];
  1029.       if (fp_code)
  1030.     {
  1031.       jump0 = pc_rtx;
  1032.       jump1 = label;
  1033.     }
  1034.       else
  1035.     {
  1036.       fp_code = test_code;
  1037.       jump0 = label;
  1038.       jump1 = pc_rtx;
  1039.     }
  1040.  
  1041.       emit_insn (gen_rtx (PARALLEL, VOIDmode,
  1042.               gen_rtvec (2,
  1043.                      gen_rtx (SET, VOIDmode,
  1044.                           cc0_rtx,
  1045.                           gen_rtx (fp_code, mode, cmp0, cmp1)),
  1046.                      gen_rtx (CLOBBER, VOIDmode,
  1047.                           gen_rtx (REG, SImode, FPSW_REGNUM)))));
  1048.  
  1049.       emit_jump_insn (gen_rtx (SET, VOIDmode,
  1050.                    pc_rtx,
  1051.                    gen_rtx (IF_THEN_ELSE, VOIDmode,
  1052.                     gen_rtx (EQ, mode, cc0_rtx, const0_rtx),
  1053.                     jump0,
  1054.                     jump1)));
  1055.       return;
  1056.     }
  1057.  
  1058. fail:
  1059.   abort_with_insn (gen_rtx (test_code, mode, cmp0, cmp1), "bad test");
  1060. }
  1061.  
  1062.  
  1063. /* Write a series of loads/stores to move some bytes.  */
  1064.  
  1065. extern rtx gen_movqi ();
  1066. extern rtx gen_movhi ();
  1067. extern rtx gen_movsi ();
  1068. extern rtx gen_movsi_ulw ();
  1069. extern rtx gen_movsi_usw ();
  1070.  
  1071. static void
  1072. block_move_sequence (dest, src, bytes, align)
  1073.      rtx dest;            /* pointer to destination */
  1074.      rtx src;            /* pointer to source */
  1075.      int bytes;            /* # bytes to move */
  1076.      int align;            /* alignment */
  1077. {
  1078.   rtx prev_store    = (rtx)0;
  1079.   rtx cur_store        = (rtx)0;
  1080.   rtx cur_load;
  1081.   rtx src_addr;
  1082.   rtx dest_addr;
  1083.   rtx (*load_func)();
  1084.   rtx (*store_func)();
  1085.   rtx reg;
  1086.   enum machine_mode mode;
  1087.   int size;
  1088.   int offset = 0;
  1089.  
  1090.   /* Go through, and generate load/stores as follows:
  1091.  
  1092.      load  1
  1093.      load  2
  1094.      store 1
  1095.      load  3
  1096.      store 2
  1097.      load  4
  1098.      store 3
  1099.      ...
  1100.  
  1101.      This way, no NOP's are needed, except at the end, and only
  1102.      two temp registers are needed.  */
  1103.  
  1104.   while (bytes > 0)
  1105.     {
  1106.       /* Is there a store to do? */
  1107.       if (prev_store)
  1108.     emit_insn (prev_store);
  1109.  
  1110.       prev_store = cur_store;
  1111.  
  1112.       if (bytes >= 4 && align >= 4)
  1113.     {
  1114.       size = 4;
  1115.       mode = SImode;
  1116.       load_func = gen_movsi;
  1117.       store_func = gen_movsi;
  1118.     }
  1119.  
  1120.       else if (bytes >= 4)
  1121.     {
  1122.       size = 4;
  1123.       mode = SImode;
  1124.       load_func = gen_movsi_ulw;
  1125.       store_func = gen_movsi_usw;
  1126.     }
  1127.  
  1128.       else if (bytes >= 2 && align >= 2)
  1129.     {
  1130.       size = 2;
  1131.       mode = HImode;
  1132.       load_func = gen_movhi;
  1133.       store_func = gen_movhi;
  1134.     }
  1135.  
  1136.       else
  1137.     {
  1138.       size = 1;
  1139.       mode = QImode;
  1140.       load_func = gen_movqi;
  1141.       store_func = gen_movqi;
  1142.     }
  1143.  
  1144.       reg = gen_reg_rtx (mode);
  1145.       src_addr = gen_rtx (MEM, mode,
  1146.               gen_rtx (PLUS, SImode,
  1147.                    src,
  1148.                    gen_rtx (CONST_INT, VOIDmode, offset)));
  1149.  
  1150.       cur_load = (* load_func) (reg, src_addr);
  1151.       emit_insn (cur_load);
  1152.  
  1153.       dest_addr = gen_rtx (MEM, mode,
  1154.                gen_rtx (PLUS, SImode,
  1155.                     dest,
  1156.                     gen_rtx (CONST_INT, VOIDmode, offset)));
  1157.  
  1158.       cur_store = (* store_func) (dest_addr, reg);
  1159.       offset += size;
  1160.       bytes -= size;
  1161.     }
  1162.  
  1163.   /* Finish up last two stores.  */
  1164.   if (prev_store)
  1165.     emit_insn (prev_store);
  1166.  
  1167.   if (cur_store)
  1168.     emit_insn (cur_store);
  1169. }
  1170.  
  1171.  
  1172. /* Use a library function to move some bytes.  */
  1173.  
  1174. static void
  1175. block_move_call (operands)
  1176.      rtx operands[];
  1177. {
  1178. #ifdef TARGET_MEM_FUNCTIONS
  1179.   emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memcpy"), 0,
  1180.              VOIDmode, 3,
  1181.              operands[0], Pmode,
  1182.              operands[1], Pmode,
  1183.              operands[2], SImode);
  1184. #else
  1185.   emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bcopy"), 0,
  1186.              VOIDmode, 3,
  1187.              operands[1], Pmode,
  1188.              operands[0], Pmode,
  1189.              operands[2], SImode);
  1190. #endif
  1191. }
  1192.  
  1193.  
  1194. /* Expand string/block move operations.
  1195.  
  1196.    operands[0] is the pointer to the source.
  1197.    operands[1] is the pointer to the destination.
  1198.    operands[2] is the number of bytes to move.
  1199.    operands[3] is the alignment.
  1200.  
  1201.    Return TRUE if expand_block_move creates valid insns.  */
  1202.  
  1203. void
  1204. expand_block_move (operands)
  1205.      rtx operands[];
  1206. {
  1207.   int align = INTVAL (operands[3]);
  1208.   int constp = (GET_CODE (operands[2]) == CONST_INT);
  1209.   int bytes = (constp ? INTVAL (operands[2]) : 0);
  1210.  
  1211.   if (constp && bytes <= 0)
  1212.     return;
  1213.  
  1214.   if (TARGET_MEMCPY)
  1215.     {
  1216.       block_move_call (operands);
  1217.       return;
  1218.     }
  1219.  
  1220.   /* Determine machine mode to do move with.  */
  1221.   if (align > 4)
  1222.     align = 4;
  1223.  
  1224.   else if (align <= 0 || align == 3)
  1225.     abort ();            /* block move invalid alignment.  */
  1226.  
  1227.   if (!constp
  1228.       || (bytes != 1
  1229.       && (bytes != 4 || align != 4)
  1230.       && (bytes != 2 || align != 2)))
  1231.     {
  1232.       operands[0] = copy_to_reg (XEXP (operands[0], 0));
  1233.       operands[1] = copy_to_reg (XEXP (operands[1], 0));
  1234.     }
  1235.  
  1236.   if (constp && bytes <= 32)
  1237.     block_move_sequence (operands[0], operands[1], bytes, align);
  1238.  
  1239. #if 0
  1240.   else if (constp && align == 4)
  1241.     block_move_loop (operands[0], operands[1], bytes, align);
  1242. #endif
  1243.  
  1244.   else
  1245.     block_move_call (operands);
  1246. }
  1247.  
  1248.  
  1249. /* Argument support functions.  */
  1250.  
  1251. /* Initialize CUMULATIVE_ARGS for a function.  */
  1252.  
  1253. void
  1254. init_cumulative_args (cum, fntype, libname)
  1255.      CUMULATIVE_ARGS cum;    /* argument info to initialize */
  1256.      tree fntype;        /* tree ptr for function decl */
  1257.      rtx libname;        /* SYMBOL_REF of library name or 0 */
  1258. {
  1259.   tree param, next_param;
  1260.  
  1261.   if (TARGET_DEBUG_E_MODE)
  1262.     fprintf (stderr, "\ninit_cumulative_args\n");
  1263.  
  1264.   cum->gp_reg_found = 0;
  1265.   cum->arg_number = 0;
  1266.   cum->arg_words = 0;
  1267.  
  1268.   /* Determine if this function has variable arguments.  This is
  1269.      indicated by the last argument being 'void_type_mode' if there
  1270.      are no variable arguments.  The standard MIPS calling sequence
  1271.      passes all arguments in the general purpose registers in this
  1272.      case. */
  1273.  
  1274.   for (param = (fntype) ? TYPE_ARG_TYPES (fntype) : 0;
  1275.        param != (tree)0;
  1276.        param = next_param)
  1277.     {
  1278.       next_param = TREE_CHAIN (param);
  1279.       if (next_param == (tree)0 && TREE_VALUE (param) != void_type_node)
  1280.     cum->gp_reg_found = 1;
  1281.     }
  1282.  
  1283.   /* Determine if the function is returning a structure, if so,
  1284.      advance by one argument.  */
  1285.  
  1286.   if (fntype
  1287.       && (TREE_CODE (fntype) == FUNCTION_TYPE || TREE_CODE (fntype) == METHOD_TYPE)
  1288.       && TREE_TYPE (fntype) != 0)
  1289.     {
  1290.       tree ret_type = TREE_TYPE (fntype);
  1291.       enum tree_code ret_code = TREE_CODE (ret_type);
  1292.  
  1293.       if (ret_code == RECORD_TYPE || ret_code == UNION_TYPE)
  1294.     {
  1295.       cum->gp_reg_found = 1;
  1296.       cum->arg_number = 1;
  1297.       cum->arg_words = 1;
  1298.     }
  1299.     }
  1300. }
  1301.  
  1302. /* Advance the argument to the next argument position.  */
  1303.  
  1304. void
  1305. function_arg_advance (cum, mode, type, named)
  1306.      CUMULATIVE_ARGS cum;    /* current arg information */
  1307.      enum machine_mode mode;    /* current arg mode */
  1308.      tree type;            /* type of the argument or 0 if lib support */
  1309. {
  1310.   if (TARGET_DEBUG_E_MODE)
  1311.     fprintf (stderr,
  1312.          "function_adv( {gp reg found = %d, arg # = %2d, words = %2d}, %4s, 0x%.8x, %d )\n",
  1313.          cum->gp_reg_found, cum->arg_number, cum->arg_words, GET_MODE_NAME (mode),
  1314.          type, named);
  1315.  
  1316.   cum->arg_number++;
  1317.   switch (mode)
  1318.     {
  1319.     default:
  1320.       error ("Illegal mode given to function_arg_advance");
  1321.       break;
  1322.  
  1323.     case VOIDmode:
  1324.       break;
  1325.  
  1326.     case BLKmode:
  1327.       cum->gp_reg_found = 1;
  1328.       cum->arg_words += (int_size_in_bytes (type) + 3) / 4;
  1329.       break;
  1330.  
  1331.     case SFmode:
  1332.       cum->arg_words++;
  1333.       break;
  1334.  
  1335.     case DFmode:
  1336.       cum->arg_words += 2;
  1337.       break;
  1338.  
  1339.     case DImode:
  1340.       cum->gp_reg_found = 1;
  1341.       cum->arg_words += 2;
  1342.       break;
  1343.  
  1344.     case QImode:
  1345.     case HImode:
  1346.     case SImode:
  1347.       cum->gp_reg_found = 1;
  1348.       cum->arg_words++;
  1349.       break;
  1350.     }
  1351. }
  1352.  
  1353. /* Return a RTL expression containing the register for the given mode,
  1354.    or 0 if the argument is too be passed on the stack.  */
  1355.  
  1356. struct rtx_def *
  1357. function_arg (cum, mode, type, named)
  1358.      CUMULATIVE_ARGS cum;    /* current arg information */
  1359.      enum machine_mode mode;    /* current arg mode */
  1360.      tree type;            /* type of the argument or 0 if lib support */
  1361.      int named;            /* != 0 for normal args, == 0 for ... args */
  1362. {
  1363.   int regbase = -1;
  1364.   int bias = 0;
  1365.  
  1366.   if (TARGET_DEBUG_E_MODE)
  1367.     fprintf (stderr,
  1368.          "function_arg( {gp reg found = %d, arg # = %2d, words = %2d}, %4s, 0x%.8x, %d ) = ",
  1369.          cum->gp_reg_found, cum->arg_number, cum->arg_words, GET_MODE_NAME (mode),
  1370.          type, named);
  1371.  
  1372.   switch (mode)
  1373.     {
  1374.     default:
  1375.       error ("Illegal mode given to function_arg");
  1376.       break;
  1377.  
  1378.     case SFmode:
  1379.       if (cum->gp_reg_found || cum->arg_number >= 2)
  1380.     regbase = GP_ARG_FIRST;
  1381.       else {
  1382.     regbase = FP_ARG_FIRST;
  1383.     if (cum->arg_words == 1)    /* first arg was float */
  1384.       bias = 1;            /* use correct reg */
  1385.       }
  1386.  
  1387.       break;
  1388.  
  1389.     case DFmode:
  1390.       cum->arg_words += (cum->arg_words & 1);
  1391.       regbase = (cum->gp_reg_found) ? GP_ARG_FIRST : FP_ARG_FIRST;
  1392.       break;
  1393.  
  1394.     case VOIDmode:
  1395.     case BLKmode:
  1396.     case QImode:
  1397.     case HImode:
  1398.     case SImode:
  1399.     case DImode:
  1400.       regbase = GP_ARG_FIRST;
  1401.       break;
  1402.     }
  1403.  
  1404.   if (cum->arg_words >= MAX_ARGS_IN_REGISTERS)
  1405.     {
  1406.       if (TARGET_DEBUG_E_MODE)
  1407.     fprintf (stderr, "<stack>\n");
  1408.  
  1409.       return 0;
  1410.     }
  1411.  
  1412.   if (regbase == -1)
  1413.     abort ();
  1414.  
  1415.   if (TARGET_DEBUG_E_MODE)
  1416.     fprintf (stderr, "%s\n", reg_names[ regbase + cum->arg_number + bias ]);
  1417.  
  1418.   return gen_rtx (REG, mode, regbase + cum->arg_words + bias);
  1419. }
  1420.  
  1421.  
  1422. int
  1423. function_arg_partial_nregs (cum, mode, type, named)
  1424.      CUMULATIVE_ARGS cum;    /* current arg information */
  1425.      enum machine_mode mode;    /* current arg mode */
  1426.      tree type;            /* type of the argument or 0 if lib support */
  1427.      int named;            /* != 0 for normal args, == 0 for ... args */
  1428. {
  1429.   if (mode == BLKmode && cum->arg_words < MAX_ARGS_IN_REGISTERS)
  1430.     {
  1431.       int words = (int_size_in_bytes (type) + 3) / 4;
  1432.  
  1433.       if (words + cum->arg_words < MAX_ARGS_IN_REGISTERS)
  1434.     return 0;        /* structure fits in registers */
  1435.  
  1436.       if (TARGET_DEBUG_E_MODE)
  1437.     fprintf (stderr, "function_arg_partial_nregs = %d\n",
  1438.          MAX_ARGS_IN_REGISTERS - cum->arg_words);
  1439.  
  1440.       return MAX_ARGS_IN_REGISTERS - cum->arg_words;
  1441.     }
  1442.  
  1443.   else if (mode == DImode && cum->arg_words == MAX_ARGS_IN_REGISTERS-1)
  1444.     {
  1445.       if (TARGET_DEBUG_E_MODE)
  1446.     fprintf (stderr, "function_arg_partial_nregs = 1\n");
  1447.  
  1448.       return 1;
  1449.     }
  1450.  
  1451.   return 0;
  1452. }
  1453.  
  1454.  
  1455. /* Print the options used in the assembly file.  */
  1456.  
  1457. static struct {char *name; int value;} target_switches []
  1458.   = TARGET_SWITCHES;
  1459.  
  1460. void
  1461. print_options (out)
  1462.      FILE *out;
  1463. {
  1464.   int line_len;
  1465.   int len;
  1466.   int j;
  1467.   char **p;
  1468.   int mask = TARGET_DEFAULT;
  1469.   extern char **save_argv;
  1470.   extern char *version_string, *language_string;
  1471.  
  1472.   /* Allow assembly language comparisons with -mdebug eliminating the
  1473.      compiler version number and switch lists.  */
  1474.  
  1475.   if (TARGET_DEBUG_MODE)
  1476.     return;
  1477.  
  1478.   fprintf (out, "\n # %s %s", language_string, version_string);
  1479. #ifdef TARGET_VERSION_INTERNAL
  1480.   TARGET_VERSION_INTERNAL (out);
  1481. #endif
  1482. #ifdef __GNUC__
  1483.   fprintf (out, " compiled by GNU C\n\n");
  1484. #else
  1485.   fprintf (out, " compiled by CC\n\n");
  1486. #endif
  1487.  
  1488.   fprintf (out, " # Cc1 defaults:");
  1489.   line_len = 32767;
  1490.   for (j = 0; j < sizeof target_switches / sizeof target_switches[0]; j++)
  1491.     {
  1492.       if (target_switches[j].name[0] != '\0'
  1493.       && target_switches[j].value > 0
  1494.       && (target_switches[j].value & mask) == target_switches[j].value)
  1495.     {
  1496.       mask &= ~ target_switches[j].value;
  1497.       len = strlen (target_switches[j].name) + 1;
  1498.       if (len + line_len > 79)
  1499.         {
  1500.           line_len = 2;
  1501.           fputs ("\n #", out);
  1502.         }
  1503.       fprintf (out, " -m%s", target_switches[j].name);
  1504.       line_len += len;
  1505.     }
  1506.     }
  1507.  
  1508.   fprintf (out, "\n\n # Cc1 arguments (-G value = %d):", mips_section_threshold);
  1509.  
  1510.   line_len = 32767;
  1511.   for (p = &save_argv[1]; *p != (char *)0; p++)
  1512.     {
  1513.       char *arg = *p;
  1514.       if (*arg == '-')
  1515.     {
  1516.       len = strlen (arg) + 1;
  1517.       if (len + line_len > 79)
  1518.         {
  1519.           line_len = 2;
  1520.           fputs ("\n #", out);
  1521.         }
  1522.       fprintf (out, " %s", *p);
  1523.       line_len += len;
  1524.     }
  1525.     }
  1526.  
  1527.   fputs ("\n\n", out);
  1528. }
  1529.  
  1530.  
  1531. /* Abort after printing out a specific insn.  */
  1532.  
  1533. void
  1534. abort_with_insn (insn, reason)
  1535.      rtx insn;
  1536.      char *reason;
  1537. {
  1538.   error (reason);
  1539.   debug_rtx (insn);
  1540.   abort ();
  1541. }
  1542.  
  1543. /* Write a message to stderr (for use in macros expanded in files that do not
  1544.    include stdio.h).  */
  1545.  
  1546. void
  1547. trace (s, s1, s2)
  1548.      char *s, *s1, *s2;
  1549. {
  1550.   fprintf (stderr, s, s1, s2);
  1551. }
  1552.  
  1553.  
  1554. /* Set up the threshold for data to go into the small data area, instead
  1555.    of the normal data area, and detect any conflicts in the switches.  */
  1556.  
  1557. void
  1558. override_options ()
  1559. {
  1560.   register int i;
  1561.  
  1562.   if (g_switch_set)
  1563.     mips_section_threshold = g_switch_value;
  1564.  
  1565.   else if (TARGET_G012_USED)
  1566.     {
  1567.       i = TARGET_GVALUE;
  1568.       if (i >= 6)
  1569.     i += 3;
  1570.       mips_section_threshold = (i != 0) ? 1 << i : 0;
  1571.     }
  1572.  
  1573.   else
  1574.     mips_section_threshold = (TARGET_MIPS_AS) ? 8 : 0;
  1575.  
  1576.   /* -mgas puts out stabs, if not gas, put out sdb info and convert
  1577.      into the MIPS/third-eye symbol format with mips-tfile.  */
  1578.  
  1579.   if (write_symbols == DBX_DEBUG && !TARGET_GAS)
  1580.     write_symbols = SDB_DEBUG;
  1581.  
  1582.   else if (write_symbols == SDB_DEBUG && TARGET_GAS)
  1583.     {
  1584.       extern int use_gdb_dbx_extensions;
  1585.  
  1586.       write_symbols = DBX_DEBUG;
  1587.       use_gdb_dbx_extensions = 1;
  1588.     }
  1589.  
  1590.   /* -mrnames says to use the MIPS software convention for register
  1591.      names instead of the hardware names (ie, a0 instead of $4).
  1592.      We do this by switching the names in mips_reg_names, which the
  1593.      reg_names points into via the REGISTER_NAMES macro.  */
  1594.  
  1595.   if (TARGET_NAME_REGS)
  1596.     {
  1597.       if (TARGET_GAS)
  1598.     {
  1599.       target_flags &= ~ MASK_NAME_REGS;
  1600.       error ("Gas does not support the MIPS software register name convention.");
  1601.     }
  1602.       else
  1603.     bcopy ((char *) mips_sw_reg_names, (char *) mips_reg_names, sizeof (mips_reg_names));
  1604.     }
  1605.  
  1606.   /* Set up the classificaiton arrays now.  */
  1607.   mips_rtx_classify[ (int)PLUS ]  = CLASS_ADD_OP;
  1608.   mips_rtx_classify[ (int)MINUS ] = CLASS_ADD_OP;
  1609.   mips_rtx_classify[ (int)DIV ]   = CLASS_DIVMOD_OP;
  1610.   mips_rtx_classify[ (int)MOD ]   = CLASS_DIVMOD_OP;
  1611.   mips_rtx_classify[ (int)UDIV ]  = CLASS_DIVMOD_OP | CLASS_UNSIGNED_OP;
  1612.   mips_rtx_classify[ (int)UMOD ]  = CLASS_DIVMOD_OP | CLASS_UNSIGNED_OP;
  1613.   mips_rtx_classify[ (int)EQ ]    = CLASS_CMP_OP | CLASS_EQUALITY_OP;
  1614.   mips_rtx_classify[ (int)NE ]    = CLASS_CMP_OP | CLASS_EQUALITY_OP;
  1615.   mips_rtx_classify[ (int)GT ]    = CLASS_CMP_OP;
  1616.   mips_rtx_classify[ (int)GE ]    = CLASS_CMP_OP;
  1617.   mips_rtx_classify[ (int)LT ]    = CLASS_CMP_OP;
  1618.   mips_rtx_classify[ (int)LE ]    = CLASS_CMP_OP;
  1619.   mips_rtx_classify[ (int)GTU ]   = CLASS_CMP_OP | CLASS_UNSIGNED_OP;
  1620.   mips_rtx_classify[ (int)GEU ]   = CLASS_CMP_OP | CLASS_UNSIGNED_OP;
  1621.   mips_rtx_classify[ (int)LTU ]   = CLASS_CMP_OP | CLASS_UNSIGNED_OP;
  1622.   mips_rtx_classify[ (int)LEU ]   = CLASS_CMP_OP | CLASS_UNSIGNED_OP;
  1623.  
  1624.   mips_print_operand_punct[':']      = TRUE;
  1625.   mips_print_operand_punct['#']      = TRUE;
  1626.   mips_print_operand_punct['&']      = TRUE;
  1627.   mips_print_operand_punct['!']      = TRUE;
  1628.   mips_print_operand_punct['*']      = TRUE;
  1629.   mips_print_operand_punct['@']      = TRUE;
  1630.   mips_print_operand_punct['(']      = TRUE;
  1631.   mips_print_operand_punct[')']      = TRUE;
  1632.   mips_print_operand_punct['[']      = TRUE;
  1633.   mips_print_operand_punct[']']      = TRUE;
  1634.   mips_print_operand_punct['<']      = TRUE;
  1635.   mips_print_operand_punct['>']      = TRUE;
  1636. }
  1637.  
  1638.  
  1639. /* A C compound statement to output to stdio stream STREAM the
  1640.    assembler syntax for an instruction operand X.  X is an RTL
  1641.    expression.
  1642.  
  1643.    CODE is a value that can be used to specify one of several ways
  1644.    of printing the operand.  It is used when identical operands
  1645.    must be printed differently depending on the context.  CODE
  1646.    comes from the `%' specification that was used to request
  1647.    printing of the operand.  If the specification was just `%DIGIT'
  1648.    then CODE is 0; if the specification was `%LTR DIGIT' then CODE
  1649.    is the ASCII code for LTR.
  1650.  
  1651.    If X is a register, this macro should print the register's name.
  1652.    The names can be found in an array `reg_names' whose type is
  1653.    `char *[]'.  `reg_names' is initialized from `REGISTER_NAMES'.
  1654.  
  1655.    When the machine description has a specification `%PUNCT' (a `%'
  1656.    followed by a punctuation character), this macro is called with
  1657.    a null pointer for X and the punctuation character for CODE.
  1658.  
  1659.    The MIPS specific codes are:
  1660.  
  1661.    'X'  X is CONST_INT, prints 32 bits in hexadecimal format = "0x%08x",
  1662.    'x'  X is CONST_INT, prints 16 bits in hexadecimal format = "0x%04x",
  1663.    'd'  output integer constant in decimal,
  1664.    'z'    if the operand is 0, use $0 instead of normal operand.
  1665.    'D'  print second register of double-word register operand.
  1666.    'L'  print low-order register of double-word register operand.
  1667.    'M'  print high-order register of double-word register operand.
  1668.    'C'  print part of opcode for a branch condition.
  1669.    'N'  print part of opcode for a branch condition, inverted.
  1670.    '('    Turn on .set noreorder/.set nomacro
  1671.    ')'    Turn on .set reorder/.set macro
  1672.    '['    Turn on .set noat
  1673.    ']'    Turn on .set at
  1674.    '<'    Turn on .set nomacro
  1675.    '>'    Turn on .set macro
  1676.    '&'    Turn on .set noreorder if filling delay slots
  1677.    '*'    Turn on both .set noreorder and .set nomacro if filling delay slots
  1678.    '!'    Turn on .set nomacro if filling delay slots
  1679.    '#'    Print nop if in a .set noreorder section.
  1680.    '@'    Print the name of the assembler temporary register (at or $1).
  1681.    ':'  Prints an 'u' if flag -mnofixed-ovfl has been set, thus selecting addu
  1682.         instruction instead of add.  */
  1683.  
  1684. void
  1685. print_operand (file, op, letter)
  1686.      FILE *file;        /* file to write to */
  1687.      rtx op;            /* operand to print */
  1688.      int letter;        /* %<letter> or 0 */
  1689. {
  1690.   enum rtx_code code;
  1691.  
  1692.   if (PRINT_OPERAND_PUNCT_VALID_P (letter))
  1693.     {
  1694.       switch (letter)
  1695.     {
  1696.     default:
  1697.       error ("PRINT_OPERAND: Unknown punctuation '%c'", letter);
  1698.       break;
  1699.  
  1700.     case ':':
  1701.       if (TARGET_NOFIXED_OVFL)
  1702.         putc ('u', file);
  1703.       break;
  1704.  
  1705.     case '@':
  1706.       fputs (reg_names [GP_REG_FIRST + 1], file);
  1707.       break;
  1708.  
  1709.     case '&':
  1710.       if (final_sequence != 0 && set_noreorder++ == 0)
  1711.         fputs (".set\tnoreorder\n\t", file);
  1712.       break;
  1713.  
  1714.     case '*':
  1715.       if (final_sequence != 0)
  1716.         {
  1717.           if (set_noreorder++ == 0)
  1718.         fputs (".set\tnoreorder\n\t", file);
  1719.  
  1720.           if (set_nomacro++ == 0)
  1721.         fputs (".set\tnomacro\n\t", file);
  1722.         }
  1723.       break;
  1724.  
  1725.     case '!':
  1726.       if (final_sequence != 0 && set_nomacro++ == 0)
  1727.         fputs ("\n\t.set\tnomacro", file);
  1728.       break;
  1729.  
  1730.     case '#':
  1731.       if (set_noreorder != 0)
  1732.         fputs ("\n\tnop", file);
  1733.       break;
  1734.  
  1735.     case '(':
  1736.       if (set_noreorder++ == 0)
  1737.         fputs (".set\tnoreorder\n\t", file);
  1738.       break;
  1739.  
  1740.     case ')':
  1741.       if (--set_noreorder == 0)
  1742.         fputs ("\n\t.set\treorder", file);
  1743.       break;
  1744.  
  1745.     case '[':
  1746.       if (set_noat++ == 0)
  1747.         fputs (".set\tnoat\n\t", file);
  1748.       break;
  1749.  
  1750.     case ']': 
  1751.       if (--set_noat == 0)
  1752.         fputs ("\n\t.set\tat", file);
  1753.       break;
  1754.  
  1755.     case '<':
  1756.       if (set_nomacro++ == 0)
  1757.         fputs (".set\tnomacro\n\t", file);
  1758.       break;
  1759.  
  1760.     case '>':
  1761.       if (--set_nomacro == 0)
  1762.         fputs ("\n\t.set\tmacro", file);
  1763.       break;
  1764.     }
  1765.       return;
  1766.     }
  1767.  
  1768.   if (! op)
  1769.     {
  1770.       error ("PRINT_OPERAND null pointer");
  1771.       return;
  1772.     }
  1773.  
  1774.   code = GET_CODE (op);
  1775.   if (letter == 'C')
  1776.     switch (code)
  1777.       {
  1778.       case EQ:    fputs ("eq",  file); break;
  1779.       case NE:    fputs ("ne",  file); break;
  1780.       case GT:    fputs ("gt",  file); break;
  1781.       case GE:    fputs ("ge",  file); break;
  1782.       case LT:    fputs ("lt",  file); break;
  1783.       case LE:    fputs ("le",  file); break;
  1784.       case GTU: fputs ("gtu", file); break;
  1785.       case GEU: fputs ("geu", file); break;
  1786.       case LTU: fputs ("ltu", file); break;
  1787.       case LEU: fputs ("leu", file); break;
  1788.  
  1789.       default:
  1790.     abort_with_insn (op, "PRINT_OPERAND, illegal insn for %%C");
  1791.       }
  1792.  
  1793.   else if (letter == 'N')
  1794.     switch (code)
  1795.       {
  1796.       case EQ:    fputs ("ne",  file); break;
  1797.       case NE:    fputs ("eq",  file); break;
  1798.       case GT:    fputs ("le",  file); break;
  1799.       case GE:    fputs ("lt",  file); break;
  1800.       case LT:    fputs ("ge",  file); break;
  1801.       case LE:    fputs ("gt",  file); break;
  1802.       case GTU: fputs ("leu", file); break;
  1803.       case GEU: fputs ("ltu", file); break;
  1804.       case LTU: fputs ("geu", file); break;
  1805.       case LEU: fputs ("gtu", file); break;
  1806.  
  1807.       default:
  1808.     abort_with_insn (op, "PRINT_OPERAND, illegal insn for %%N");
  1809.       }
  1810.  
  1811.   else if (code == REG)
  1812.     {
  1813.       int regnum = REGNO (op);
  1814.  
  1815.       if (letter == 'M')
  1816.     regnum += MOST_SIGNIFICANT_WORD;
  1817.  
  1818.       else if (letter == 'L')
  1819.     regnum += LEAST_SIGNIFICANT_WORD;
  1820.  
  1821.       else if (letter == 'D')
  1822.     regnum++;
  1823.  
  1824.       fprintf (file, "%s", reg_names[regnum]);
  1825.     }
  1826.  
  1827.   else if (code == MEM)
  1828.     output_address (XEXP (op, 0));
  1829.  
  1830.   else if (code == CONST_DOUBLE)
  1831.     {
  1832. #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
  1833.       union { double d; int i[2]; } u;
  1834.       u.i[0] = CONST_DOUBLE_LOW (op);
  1835.       u.i[1] = CONST_DOUBLE_HIGH (op);
  1836.       if (GET_MODE (op) == SFmode)
  1837.     {
  1838.       float f;
  1839.       f = u.d;
  1840.       u.d = f;
  1841.     }
  1842.       fprintf (file, "%.20e", u.d);
  1843. #else
  1844.       fatal ("CONST_DOUBLE found in cross compilation");
  1845. #endif
  1846.     }
  1847.  
  1848.   else if ((letter == 'x') && (GET_CODE(op) == CONST_INT))
  1849.     fprintf (file, "0x%04x", 0xffff & (INTVAL(op)));
  1850.  
  1851.   else if ((letter == 'X') && (GET_CODE(op) == CONST_INT))
  1852.     fprintf (file, "0x%08x", INTVAL(op));
  1853.  
  1854.   else if ((letter == 'd') && (GET_CODE(op) == CONST_INT))
  1855.     fprintf (file, "%d", (INTVAL(op)));
  1856.  
  1857.   else if (letter == 'z'
  1858.        && (GET_CODE (op) == CONST_INT)
  1859.        && INTVAL (op) == 0)
  1860.     fputs (reg_names[GP_REG_FIRST], file);
  1861.  
  1862.   else if (letter == 'd' || letter == 'x' || letter == 'X')
  1863.     fatal ("PRINT_OPERAND: letter %c was found & insn was not CONST_INT", letter);
  1864.  
  1865.   else
  1866.     output_addr_const (file, op);
  1867. }
  1868.  
  1869.  
  1870. /* A C compound statement to output to stdio stream STREAM the
  1871.    assembler syntax for an instruction operand that is a memory
  1872.    reference whose address is ADDR.  ADDR is an RTL expression.
  1873.  
  1874.    On some machines, the syntax for a symbolic address depends on
  1875.    the segment that the address refers to.  On these machines,
  1876.    define the macro `ENCODE_SEGMENT_INFO' to store the information
  1877.    into the `symbol_ref', and then check for it here.  */
  1878.  
  1879. void
  1880. print_operand_address (file, addr)
  1881.      FILE *file;
  1882.      rtx addr;
  1883. {
  1884.   if (!addr)
  1885.     error ("PRINT_OPERAND_ADDRESS, null pointer");
  1886.  
  1887.   else
  1888.     switch (GET_CODE (addr))
  1889.       {
  1890.       default:
  1891.     abort_with_insn (addr, "PRINT_OPERAND_ADDRESS, illegal insn #1");
  1892.     break;
  1893.  
  1894.       case REG:
  1895.     fprintf (file, "0(%s)", reg_names [REGNO (addr)]);
  1896.     break;
  1897.  
  1898.       case PLUS:
  1899.     {
  1900.       register rtx reg    = (rtx)0;
  1901.       register rtx offset = (rtx)0;
  1902.       register rtx arg0   = XEXP (addr, 0);
  1903.       register rtx arg1   = XEXP (addr, 1);
  1904.  
  1905.       if (GET_CODE (arg0) == REG)
  1906.         {
  1907.           reg = arg0;
  1908.           offset = arg1;
  1909.           if (GET_CODE (offset) == REG)
  1910.         abort_with_insn (addr, "PRINT_OPERAND_ADDRESS, 2 regs");
  1911.         }
  1912.       else if (GET_CODE (arg1) == REG)
  1913.         {
  1914.           reg = arg1;
  1915.           offset = arg0;
  1916.         }
  1917.       else if (CONSTANT_P (arg0) && CONSTANT_P (arg1))
  1918.         {
  1919.           output_addr_const (file, addr);
  1920.           break;
  1921.         }
  1922.       else
  1923.         abort_with_insn (addr, "PRINT_OPERAND_ADDRESS, no regs");
  1924.  
  1925.       if (!CONSTANT_P (offset))
  1926.         abort_with_insn (addr, "PRINT_OPERAND_ADDRESS, illegal insn #2");
  1927.  
  1928.       output_addr_const (file, offset);
  1929.       fprintf (file, "(%s)", reg_names [REGNO (reg)]);
  1930.     }
  1931.     break;
  1932.  
  1933.       case LABEL_REF:
  1934.       case SYMBOL_REF:
  1935.       case CONST_INT:
  1936.       case CONST:
  1937.     output_addr_const (file, addr);
  1938.     break;
  1939.     }
  1940. }
  1941.  
  1942.  
  1943. /* If optimizing for the global pointer, keep track of all of
  1944.    the externs, so that at the end of the file, we can emit
  1945.    the appropriate .extern declaration for them, before writing
  1946.    out the text section.  We assume that all names passed to
  1947.    us are in the permanent obstack, so that they will be valid
  1948.    at the end of the compilation.
  1949.  
  1950.    If we have -G 0, or the extern size is unknown, don't bother
  1951.    emitting the .externs.  */
  1952.  
  1953. int
  1954. mips_output_external (file, decl, name)
  1955.      FILE *file;
  1956.      tree decl;
  1957.      char *name;
  1958. {
  1959.   extern char *permalloc ();
  1960.   register struct extern_list *p;
  1961.   int len;
  1962.  
  1963.   if (TARGET_GP_OPT
  1964.       && mips_section_threshold != 0
  1965.       && ((TREE_CODE (decl)) != FUNCTION_DECL)
  1966.       && ((len = int_size_in_bytes (TREE_TYPE (decl))) > 0))
  1967.     {
  1968.       p = (struct extern_list *)permalloc ((long) sizeof (struct extern_list));
  1969.       p->next = extern_head;
  1970.       p->name = name;
  1971.       p->size = len;
  1972.       extern_head = p;
  1973.     }
  1974.   return 0;
  1975. }
  1976.  
  1977.  
  1978. /* Compute a string to use as a temporary file name.  */
  1979.  
  1980. static FILE *
  1981. make_temp_file ()
  1982. {
  1983.   char *temp_filename;
  1984.   FILE *stream;
  1985.   extern char *getenv ();
  1986.   char *base = getenv ("TMPDIR");
  1987.   int len;
  1988.  
  1989.   if (base == (char *)0)
  1990.     {
  1991. #ifdef P_tmpdir
  1992.       if (access (P_tmpdir, R_OK | W_OK) == 0)
  1993.     base = P_tmpdir;
  1994.       else
  1995. #endif
  1996.     if (access ("/usr/tmp", R_OK | W_OK) == 0)
  1997.       base = "/usr/tmp/";
  1998.     else
  1999.       base = "/tmp/";
  2000.     }
  2001.  
  2002.   len = strlen (base);
  2003.   temp_filename = (char *) alloca (len + sizeof("/ccXXXXXX"));
  2004.   strcpy (temp_filename, base);
  2005.   if (len > 0 && temp_filename[len-1] != '/')
  2006.     temp_filename[len++] = '/';
  2007.  
  2008.   strcpy (temp_filename + len, "ccXXXXXX");
  2009.   mktemp (temp_filename);
  2010.  
  2011.   stream = fopen (temp_filename, "w+");
  2012.   if (!stream)
  2013.     pfatal_with_name (temp_filename);
  2014.  
  2015.   unlink (temp_filename);
  2016.   return stream;
  2017. }
  2018.  
  2019.  
  2020. /* Output at beginning of assembler file.
  2021.    If we are optimizing to use the global pointer, create a temporary
  2022.    file to hold all of the text stuff, and write it out to the end.
  2023.    This is needed because the MIPS assembler is evidently one pass,
  2024.    and if it hasn't seen the relevant .comm/.lcomm/.extern/.sdata
  2025.    declaration when the code is processed, it generates a two
  2026.    instruction sequence.  */
  2027.  
  2028. void
  2029. mips_asm_file_start (stream)
  2030.      FILE *stream;
  2031. {
  2032.   ASM_OUTPUT_SOURCE_FILENAME (stream, main_input_filename);
  2033.  
  2034.   data_section ();        /* put gcc_compiled. in data, not text*/
  2035.  
  2036.   if (TARGET_GP_OPT)
  2037.     {
  2038.       asm_out_data_file = stream;
  2039.       asm_out_text_file = make_temp_file ();
  2040.     }
  2041.   else
  2042.     asm_out_data_file = asm_out_text_file = stream;
  2043.  
  2044.   if (TARGET_NAME_REGS)
  2045.     fprintf (asm_out_file, "#include <regdef.h>\n");
  2046.  
  2047.   print_options (stream);
  2048. }
  2049.  
  2050.  
  2051. /* If we are optimizing the global pointer, emit the text section now
  2052.    and any small externs which did not have .comm, etc that are
  2053.    needed.  Also, give a warning if the data area is more than 32K and
  2054.    -pic because 3 instructions are needed to reference the data
  2055.    pointers.  */
  2056.  
  2057. void
  2058. mips_asm_file_end (file)
  2059.      FILE *file;
  2060. {
  2061.   char buffer[8192];
  2062.   tree name_tree;
  2063.   struct extern_list *p;
  2064.   int len;
  2065.   extern tree lookup_name ();
  2066.  
  2067.   if (TARGET_GP_OPT)
  2068.     {
  2069.       if (extern_head)
  2070.     fputs ("\n", file);
  2071.  
  2072.       for (p = extern_head; p != 0; p = p->next)
  2073.     {
  2074.       name_tree = get_identifier (p->name);
  2075.       if (!TREE_ADDRESSABLE (name_tree))
  2076.         {
  2077.           TREE_ADDRESSABLE (name_tree) = 1;
  2078.           fprintf (file, "\t.extern\t%s, %d\n", p->name, p->size);
  2079.         }
  2080.     }
  2081.  
  2082.       fprintf (file, "\n\t.text\n");
  2083.       rewind (asm_out_text_file);
  2084.       if (ferror (asm_out_text_file))
  2085.     fatal_io_error ("write of text assembly file in mips_asm_file_end");
  2086.  
  2087.       while ((len = fread (buffer, 1, sizeof (buffer), asm_out_text_file)) > 0)
  2088.     if (fwrite (buffer, 1, len, file) != len)
  2089.       pfatal_with_name ("write of final assembly file in mips_asm_file_end");
  2090.  
  2091.       if (len < 0)
  2092.     pfatal_with_name ("read of text assembly file in mips_asm_file_end");
  2093.  
  2094.       if (fclose (asm_out_text_file) != 0)
  2095.     pfatal_with_name ("close of tempfile in mips_asm_file_end");
  2096.     }
  2097. }
  2098.  
  2099.  
  2100. /* Return the bytes needed to compute the frame pointer from the current
  2101.    stack pointer.
  2102.  
  2103.    Mips stack frames look like:
  2104.  
  2105.              Before call                After call
  2106.         +-----------------------+    +-----------------------+
  2107.    high |            |       |                  |
  2108.    mem. |                |    |            |
  2109.         |  caller's temps.        |       |  caller's temps.        |
  2110.     |               |       |                   |
  2111.         +-----------------------+    +-----------------------+
  2112.      |               |    |                |
  2113.         |  arguments on stack.  |    |  arguments on stack.  |
  2114.     |               |    |            |
  2115.         +-----------------------+    +-----------------------+
  2116.      |  4 words to save         |    |  4 words to save    |
  2117.     |  arguments passed    |    |  arguments passed    |
  2118.     |  in registers, even    |    |  in registers, even    |
  2119.     SP->|  if not passed.       |   FP->|  if not passed.    |
  2120.     +-----------------------+       +-----------------------+
  2121.                     |            |
  2122.                     |  local variables    |
  2123.                     |            |
  2124.                     +-----------------------+
  2125.                     |                |
  2126.                                         |  fp register save     |
  2127.                     |            |
  2128.                     +-----------------------+
  2129.                     |                |
  2130.                                         |  gp register save     |
  2131.                                         |               |
  2132.                     +-----------------------+
  2133.                     |            |
  2134.                                         |  alloca allocations   |
  2135.                         |            |
  2136.                     +-----------------------+
  2137.                     |            |
  2138.                                         |  arguments on stack   |
  2139.                         |                |
  2140.                     +-----------------------+
  2141.                                         |  4 words to save      |
  2142.                     |  arguments passed     |
  2143.                                         |  in registers, even   |
  2144.    low                              SP->|  if not passed.       |
  2145.    memory                    +-----------------------+
  2146.  
  2147. */
  2148.  
  2149. unsigned long
  2150. compute_frame_size (size)
  2151.      int size;            /* # of var. bytes allocated */
  2152. {
  2153.   int regno;
  2154.   unsigned long total_size;    /* # bytes that the entire frame takes up */
  2155.   unsigned long var_size;    /* # bytes that variables take up */
  2156.   unsigned long args_size;    /* # bytes that outgoing arguments take up */
  2157.   unsigned long extra_size;    /* # extra bytes */
  2158.   unsigned int  gp_reg_rounded;    /* # bytes needed to store gp after rounding */
  2159.   unsigned int  gp_reg_size;    /* # bytes needed to store gp regs */
  2160.   unsigned int  fp_reg_size;    /* # bytes needed to store fp regs */
  2161.   unsigned long mask;        /* mask of saved gp registers */
  2162.   unsigned long fmask;        /* mask of saved fp registers */
  2163.  
  2164.   extra_size     = MIPS_STACK_ALIGN (-STARTING_FRAME_OFFSET);
  2165.   var_size     = MIPS_STACK_ALIGN (size);
  2166.   args_size     = MIPS_STACK_ALIGN (current_function_outgoing_args_size);
  2167.   total_size     = var_size + args_size + extra_size;
  2168.   gp_reg_size     = 0;
  2169.   fp_reg_size     = 0;
  2170.   mask         = 0;
  2171.   fmask         = 0;
  2172.  
  2173.   /* Calculate space needed for gp registers.  */
  2174.   for (regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++)
  2175.     {
  2176.       if (MUST_SAVE_REGISTER (regno))
  2177.     {
  2178.       gp_reg_size += UNITS_PER_WORD;
  2179.       mask |= 1 << (regno - GP_REG_FIRST);
  2180.     }
  2181.     }
  2182.  
  2183.   /* align to dword boundaries.  */
  2184.   gp_reg_rounded = MIPS_STACK_ALIGN (gp_reg_size);
  2185.   total_size += gp_reg_rounded;
  2186.  
  2187.   /* Calculate space needed for fp registers.  */
  2188.   for (regno = FP_REG_FIRST; regno <= FP_REG_LAST; regno += 2)
  2189.     {
  2190.       if (regs_ever_live[regno] && !call_used_regs[regno])
  2191.     {
  2192.       fp_reg_size += 2*UNITS_PER_WORD;
  2193.       fmask |= 3 << (regno - FP_REG_FIRST);
  2194.     }
  2195.     }
  2196.  
  2197.   total_size += fp_reg_size;
  2198.  
  2199.   if (total_size == extra_size)
  2200.     total_size = extra_size = 0;
  2201.  
  2202.   /* Save other computed information.  */
  2203.   current_frame_info.total_size  = total_size;
  2204.   current_frame_info.var_size    = var_size;
  2205.   current_frame_info.args_size   = args_size;
  2206.   current_frame_info.extra_size  = extra_size;
  2207.   current_frame_info.gp_reg_size = gp_reg_size;
  2208.   current_frame_info.fp_reg_size = fp_reg_size;
  2209.   current_frame_info.mask     = mask;
  2210.   current_frame_info.fmask     = fmask;
  2211.   current_frame_info.initialized = 1;
  2212.  
  2213.   if (mask)
  2214.     {
  2215.       unsigned long offset = args_size + gp_reg_size - UNITS_PER_WORD;
  2216.       current_frame_info.gp_sp_offset = offset;
  2217.       current_frame_info.gp_save_offset = offset - total_size;
  2218.     }
  2219.  
  2220.   if (fmask)
  2221.     {
  2222.       unsigned long offset = args_size + gp_reg_rounded + fp_reg_size - 2*UNITS_PER_WORD;
  2223.       current_frame_info.fp_sp_offset = offset;
  2224.       current_frame_info.fp_save_offset = offset - total_size + UNITS_PER_WORD;
  2225.     }
  2226.  
  2227.   /* Ok, we're done.  */
  2228.   return total_size;
  2229. }
  2230.  
  2231.  
  2232. /* Common code to save/restore registers.  */
  2233.  
  2234. void
  2235. save_restore (file, gp_op, fp_op)
  2236.      FILE *file;        /* stream to write to */
  2237.      char *gp_op;        /* operation to do on gp registers */
  2238.      char *fp_op;        /* operation to do on fp registers */
  2239. {
  2240.   int regno;
  2241.   unsigned long mask      = current_frame_info.mask;
  2242.   unsigned long fmask      = current_frame_info.fmask;
  2243.   unsigned long gp_offset;
  2244.   unsigned long fp_offset;
  2245.   unsigned long max_offset;
  2246.   char *base_reg;
  2247.  
  2248.   if (mask == 0 && fmask == 0)
  2249.     return;
  2250.  
  2251.   base_reg   = reg_names[STACK_POINTER_REGNUM];
  2252.   gp_offset  = current_frame_info.gp_sp_offset;
  2253.   fp_offset  = current_frame_info.fp_sp_offset;
  2254.   max_offset = (gp_offset > fp_offset) ? gp_offset : fp_offset;
  2255.  
  2256.   /* Deal with calling functions with a large structure.  */
  2257.   if (max_offset >= 32768)
  2258.     {
  2259.       char *temp = reg_names[MIPS_TEMP2_REGNUM];
  2260.       fprintf (file, "\tli\t%s,%ld\n", temp, max_offset);
  2261.       fprintf (file, "\taddu\t%s,%s,%s\n", temp, temp, base_reg);
  2262.       base_reg = temp;
  2263.       gp_offset = max_offset - gp_offset;
  2264.       fp_offset = max_offset - fp_offset;
  2265.     }
  2266.  
  2267.   /* Save registers starting from high to low.  The debuggers prefer
  2268.      at least the return register be stored at func+4, and also it
  2269.      allows us not to need a nop in the epilog if at least one
  2270.      register is reloaded in addition to return address.  */
  2271.  
  2272.   if (mask)
  2273.     {
  2274.       for  (regno = GP_REG_LAST; regno >= GP_REG_FIRST; regno--)
  2275.     {
  2276.       if ((mask & (1L << (regno - GP_REG_FIRST))) != 0)
  2277.         {
  2278.           fprintf (file, "\t%s\t%s,%d(%s)\n",
  2279.                gp_op, reg_names[regno], gp_offset, base_reg);
  2280.  
  2281.           gp_offset -= UNITS_PER_WORD;
  2282.         }
  2283.     }
  2284.     }
  2285.  
  2286.   if (fmask)
  2287.     {
  2288.       for  (regno = FP_REG_LAST-1; regno >= FP_REG_FIRST; regno -= 2)
  2289.     {
  2290.       if ((fmask & (1L << (regno - FP_REG_FIRST))) != 0)
  2291.         {
  2292.           fprintf (file, "\t%s\t%s,%d(%s)\n",
  2293.                fp_op, reg_names[regno], fp_offset, base_reg);
  2294.  
  2295.           fp_offset -= 2*UNITS_PER_WORD;
  2296.         }
  2297.     }
  2298.     }
  2299. }
  2300.  
  2301.  
  2302. /* Set up the stack and frame (if desired) for the function.  */
  2303.  
  2304. void
  2305. function_prologue (file, size)
  2306.      FILE *file;
  2307.      int size;
  2308. {
  2309.   extern char call_used_regs[];
  2310.   int regno;
  2311.   int tsize;
  2312.   char *sp_str = reg_names[STACK_POINTER_REGNUM];
  2313.   char *fp_str = (!frame_pointer_needed)
  2314.             ? sp_str
  2315.             : reg_names[FRAME_POINTER_REGNUM];
  2316.   tree fndecl = current_function_decl; /* current... is tooo long */
  2317.   tree fntype = TREE_TYPE (fndecl);
  2318.   tree fnargs = (TREE_CODE (fntype) != METHOD_TYPE)
  2319.             ? DECL_ARGUMENTS (fndecl)
  2320.             : 0;
  2321.   tree next_arg;
  2322.   tree cur_arg;
  2323.   char *arg_name = (char *)0;
  2324.   CUMULATIVE_ARGS args_so_far;
  2325.  
  2326.   ASM_OUTPUT_SOURCE_FILENAME (file, DECL_SOURCE_FILE (current_function_decl));
  2327.   ASM_OUTPUT_SOURCE_LINE (file, DECL_SOURCE_LINE (current_function_decl));
  2328.  
  2329.   inside_function = 1;
  2330.   fprintf (file, "\t.ent\t%s\n%s:\n", current_function_name,
  2331.        current_function_name);
  2332.  
  2333.   /* Determine the last argument, and get it's name.  */
  2334.   for (cur_arg = fnargs; cur_arg != (tree)0; cur_arg = next_arg)
  2335.     {
  2336.       next_arg = TREE_CHAIN (cur_arg);
  2337.       if (next_arg == (tree)0)
  2338.     {
  2339.       if (DECL_NAME (cur_arg))
  2340.         arg_name = IDENTIFIER_POINTER (DECL_NAME (cur_arg));
  2341.  
  2342.       break;
  2343.     }
  2344.     }
  2345.  
  2346.   /* If this function is a varargs function, store any registers that
  2347.      would normally hold arguments ($4 - $7) on the stack.  */
  2348.   if ((TYPE_ARG_TYPES (fntype) != 0
  2349.        && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) != void_type_node))
  2350.       || (arg_name
  2351.       && (strcmp (arg_name, "__builtin_va_alist") == 0
  2352.           || strcmp (arg_name, "va_alist") == 0)))
  2353.     {
  2354.       tree parm;
  2355.  
  2356.       regno = GP_ARG_FIRST;
  2357.       INIT_CUMULATIVE_ARGS (args_so_far, fntype, (rtx)0);
  2358.  
  2359.       for (parm = fnargs; (parm && (regno <= GP_ARG_LAST)); parm = TREE_CHAIN (parm))
  2360.     {
  2361.       rtx entry_parm;
  2362.       enum machine_mode passed_mode;
  2363.       tree type;
  2364.  
  2365.       type = DECL_ARG_TYPE (parm);
  2366.       passed_mode = TYPE_MODE (type);
  2367.       entry_parm = FUNCTION_ARG (args_so_far, passed_mode,
  2368.                      DECL_ARG_TYPE (parm), 1);
  2369.  
  2370.       if (entry_parm)
  2371.         {
  2372.           int words;
  2373.  
  2374.           /* passed in a register, so will get homed automatically */
  2375.           if (GET_MODE (entry_parm) == BLKmode)
  2376.         words = (int_size_in_bytes (type) + 3) / 4;
  2377.           else
  2378.         words = (GET_MODE_SIZE (GET_MODE (entry_parm)) + 3) / 4;
  2379.  
  2380.           regno = REGNO (entry_parm) + words - 1;
  2381.         }
  2382.       else
  2383.         {
  2384.           regno = GP_ARG_LAST+1;
  2385.           break;
  2386.         }
  2387.  
  2388.       FUNCTION_ARG_ADVANCE (args_so_far, passed_mode,
  2389.                 DECL_ARG_TYPE (parm), 1);
  2390.     }
  2391.  
  2392.       for (; regno <= GP_ARG_LAST; regno++)
  2393.     {
  2394.       fprintf (file, "\tsw\t%s,%d(%s)\t\t# varargs home register\n",
  2395.            reg_names[regno], (regno - 4) * 4, sp_str);
  2396.     }
  2397.     }
  2398.  
  2399.   size = MIPS_STACK_ALIGN (size);
  2400.   if (!current_frame_info.initialized)
  2401.     (void) current_frame_info.total_size;
  2402.  
  2403.   tsize = current_frame_info.total_size;
  2404.   if (tsize > 0)
  2405.     {
  2406.       if (tsize <= 32767)
  2407.     fprintf (file,
  2408.          "\tsubu\t%s,%s,%d\t\t# vars= %d, regs= %d/%d, args = %d, extra= %d\n",
  2409.          sp_str, sp_str, tsize, current_frame_info.var_size,
  2410.          current_frame_info.gp_reg_size / 4,
  2411.          current_frame_info.fp_reg_size / 8,
  2412.          current_function_outgoing_args_size,
  2413.          current_frame_info.extra_size);
  2414.       else
  2415.     fprintf (file,
  2416.          "\tli\t%s,%d\n\tsubu\t%s,%s,%s\t\t# vars= %d, regs= %d/%d, args = %d, sfo= %d\n",
  2417.          reg_names[MIPS_TEMP1_REGNUM], tsize, sp_str, sp_str,
  2418.          reg_names[MIPS_TEMP1_REGNUM], current_frame_info.var_size,
  2419.          current_frame_info.gp_reg_size / 4,
  2420.          current_frame_info.fp_reg_size / 8,
  2421.          current_function_outgoing_args_size,
  2422.          current_frame_info.extra_size);
  2423.     }
  2424.  
  2425.   fprintf (file, "\t.frame\t%s,%d,%s\n\t.mask\t0x%08lx,%d\n\t.fmask\t0x%08lx,%d\n",
  2426.        fp_str,
  2427.        (frame_pointer_needed) ? 0 : tsize,
  2428.        reg_names[31 + GP_REG_FIRST],
  2429.        current_frame_info.mask,
  2430.        current_frame_info.gp_save_offset,
  2431.        current_frame_info.fmask,
  2432.        current_frame_info.fp_save_offset);
  2433.  
  2434.   save_restore (file, "sw", "s.d");
  2435.  
  2436.   if (frame_pointer_needed)
  2437.     {
  2438.       if (tsize <= 32767)
  2439.     fprintf (file, "\taddu\t%s,%s,%d\t# set up frame pointer\n", fp_str, sp_str, tsize);
  2440.  
  2441.       else
  2442.     fprintf (file, "\taddu\t%s,%s,%s\t# set up frame pointer\n", fp_str, sp_str,
  2443.          reg_names[MIPS_TEMP1_REGNUM]);
  2444.     }
  2445. }
  2446.  
  2447.  
  2448. /* Do any necessary cleanup after a function to restore stack, frame, and regs. */
  2449.  
  2450. void
  2451. function_epilogue (file, size)
  2452.      FILE *file;
  2453.      int size;
  2454. {
  2455.   extern FILE *asm_out_data_file, *asm_out_file;
  2456.   extern char call_used_regs[];
  2457.   extern int frame_pointer_needed;
  2458.   int tsize;
  2459.   char *sp_str = reg_names[STACK_POINTER_REGNUM];
  2460.   char *t1_str = reg_names[MIPS_TEMP1_REGNUM];
  2461.   rtx epilogue_delay = current_function_epilogue_delay_list;
  2462.   int noreorder = !TARGET_MIPS_AS || (epilogue_delay != 0);
  2463.   int noepilogue = FALSE;
  2464.   int load_nop = FALSE;
  2465.   int load_only_r31;
  2466.  
  2467.   if (set_noat != 0)
  2468.     {
  2469.       set_noat = 0;
  2470.       fputs ("\t.set\tat\n", file);
  2471.       error ("internal gcc error: .set noat left on in epilogue");
  2472.     }
  2473.  
  2474.   if (set_nomacro != 0)
  2475.     {
  2476.       set_nomacro = 0;
  2477.       fputs ("\t.set\tmacro\n", file);
  2478.       error ("internal gcc error: .set nomacro left on in epilogue");
  2479.     }
  2480.  
  2481.   if (set_noreorder != 0)
  2482.     {
  2483.       set_noreorder = 0;
  2484.       fputs ("\t.set\treorder\n", file);
  2485.       error ("internal gcc error: .set noreorder left on in epilogue");
  2486.     }
  2487.  
  2488.   size = MIPS_STACK_ALIGN (size);
  2489.   if (!current_frame_info.initialized)
  2490.     (void) current_frame_info.total_size;
  2491.  
  2492.   tsize = current_frame_info.total_size;
  2493.   if (tsize == 0 && epilogue_delay == 0)
  2494.     {
  2495.       rtx insn = get_last_insn ();
  2496.  
  2497.       /* If the last insn was a BARRIER, we don't have to write any code
  2498.      because a jump (aka return) was put there.  */
  2499.       if (GET_CODE (insn) == NOTE)
  2500.     insn = prev_nonnote_insn (insn);
  2501.       if (insn && GET_CODE (insn) == BARRIER)
  2502.     noepilogue = TRUE;
  2503.  
  2504.       noreorder = FALSE;
  2505.     }
  2506.  
  2507.   if (!noepilogue)
  2508.     {
  2509.       /* In the reload sequence, we don't need to fill the load delay
  2510.      slots for most of the loads, also see if we can fill the final
  2511.      delay slot if not otherwise filled by the reload sequence.  */
  2512.  
  2513.       if (noreorder)
  2514.     fprintf (file, "\t.set\tnoreorder\n");
  2515.  
  2516.       if (tsize > 32767)
  2517.     fprintf (file, "\tli\t%s,%d\n", t1_str, tsize);
  2518.  
  2519.       if (frame_pointer_needed)
  2520.     {
  2521.       char *fp_str = reg_names[FRAME_POINTER_REGNUM];
  2522.       if (tsize > 32767)
  2523.         fprintf (file,"\tsubu\t%s,%s,%s\t\t# sp not trusted  here\n",
  2524.              sp_str, fp_str, t1_str);
  2525.       else
  2526.         fprintf (file,"\tsubu\t%s,%s,%d\t\t# sp not trusted  here\n",
  2527.              sp_str, fp_str, tsize);
  2528.     }
  2529.  
  2530.       save_restore (file, "lw", "l.d");
  2531.  
  2532.       load_only_r31 = (current_frame_info.mask == (1 << 31)
  2533.                && current_frame_info.fmask == 0);
  2534.  
  2535.       if (noreorder)
  2536.     {
  2537.       /* If the only register saved is the return address, we need a
  2538.          nop, unless we have an instruction to put into it.  Otherwise
  2539.          we don't since reloading multiple registers doesn't reference
  2540.          the register being loaded.  */
  2541.  
  2542.       if (load_only_r31)
  2543.         {
  2544.           if (epilogue_delay)
  2545.           final_scan_insn (XEXP (epilogue_delay, 0),
  2546.                    file,
  2547.                    write_symbols,    /* debugger interface */
  2548.                    1,             /* optimize */
  2549.                    -2,             /* prescan */
  2550.                    1);            /* nopeepholes */
  2551.           else
  2552.         {
  2553.           fprintf (file, "\tnop\n");
  2554.           load_nop = TRUE;
  2555.         }
  2556.         }
  2557.  
  2558.       fprintf (file, "\tj\t%s\n", reg_names[GP_REG_FIRST + 31]);
  2559.  
  2560.       if (tsize > 32767)
  2561.         fprintf (file, "\taddu\t%s,%s,%s\n", sp_str, sp_str, t1_str);
  2562.  
  2563.       else if (tsize > 0)
  2564.         fprintf (file, "\taddu\t%s,%s,%d\n", sp_str, sp_str, tsize);
  2565.  
  2566.       else if (!load_only_r31 && epilogue_delay != 0)
  2567.         final_scan_insn (XEXP (epilogue_delay, 0),
  2568.                  file,
  2569.                  write_symbols,    /* debugger interface */
  2570.                  1,         /* optimize */
  2571.                  -2,         /* prescan */
  2572.                  1);        /* nopeepholes */
  2573.  
  2574.       fprintf (file, "\t.set\treorder\n");
  2575.     }
  2576.  
  2577.       else
  2578.     {
  2579.       if (tsize > 32767)
  2580.         fprintf (file, "\taddu\t%s,%s,%s\n", sp_str, sp_str, t1_str);
  2581.  
  2582.       else if (tsize > 0)
  2583.         fprintf (file, "\taddu\t%s,%s,%d\n", sp_str, sp_str, tsize);
  2584.  
  2585.       fprintf (file, "\tj\t%s\n", reg_names[GP_REG_FIRST + 31]);
  2586.     }
  2587.     }
  2588.  
  2589.   fprintf (file,"\t.end\t%s\n", current_function_name);
  2590.  
  2591.   if (TARGET_STATS)
  2592.     {
  2593.       static int size_name = 16;
  2594.       static int size_stack = 3;
  2595.       static int size_load = 3;
  2596.       static int size_jump = 3;
  2597.  
  2598.       char buf_stack [13];
  2599.       char buf_ltotal[13];
  2600.       char buf_lfill [13];
  2601.       char buf_jtotal[13];
  2602.       char buf_jfill [13];
  2603.  
  2604.       int num_gp_regs = current_frame_info.gp_reg_size / 4;
  2605.       int num_fp_regs = current_frame_info.fp_reg_size / 8;
  2606.       int len;
  2607.  
  2608.       if (!noepilogue)
  2609.     dslots_jump_total++;
  2610.  
  2611.       dslots_load_total += num_gp_regs + num_fp_regs;
  2612.  
  2613.       if (noreorder)
  2614.     {
  2615.       dslots_load_filled += num_gp_regs + num_fp_regs;
  2616.  
  2617.       /* If the only register saved is the return register, we
  2618.          can't fill this register's delay slot.  */
  2619.  
  2620.       if (load_only_r31 && epilogue_delay == 0)
  2621.         dslots_load_filled--;
  2622.  
  2623.       if (tsize > 0 || (!load_only_r31 && epilogue_delay != 0))
  2624.         dslots_jump_filled++;
  2625.     }
  2626.  
  2627.       len = strlen (current_function_name);
  2628.       if (size_name < len)
  2629.     size_name = len;
  2630.  
  2631.       sprintf (buf_stack, "%ld", (long)current_frame_info.total_size);
  2632.       len = strlen (buf_stack);
  2633.       if (size_stack < len)
  2634.     size_stack = len;
  2635.  
  2636.       sprintf (buf_ltotal, "%d", dslots_load_total);
  2637.       len = strlen (buf_ltotal);
  2638.       if (size_load < len)
  2639.     size_load = len;
  2640.  
  2641.       sprintf (buf_lfill, "%d", dslots_load_filled);
  2642.       len = strlen (buf_lfill);
  2643.       if (size_load < len)
  2644.     size_load = len;
  2645.  
  2646.       sprintf (buf_jtotal, "%d", dslots_jump_total);
  2647.       len = strlen (buf_jtotal);
  2648.       if (size_jump < len)
  2649.     size_jump = len;
  2650.  
  2651.       sprintf (buf_jfill, "%d", dslots_jump_filled);
  2652.       len = strlen (buf_jfill);
  2653.       if (size_jump < len)
  2654.     size_jump = len;
  2655.  
  2656.       fprintf (stderr,
  2657.            "func= %-*s vfp= %s, stack= %*s, regs= %2d/%d, args= %2d, leaf= %c, dslot= %*s/%*sL %*s/%*sJ\n",
  2658.            size_name, current_function_name,
  2659.            reg_names [ ((frame_pointer_needed) ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM) ],
  2660.            size_stack, buf_stack,
  2661.            num_gp_regs,
  2662.            num_fp_regs,
  2663.            current_function_outgoing_args_size,
  2664.            (current_frame_info.mask & (1 << 31)) ? 'n' : 'y',
  2665.            size_load, buf_ltotal, size_load, buf_lfill,
  2666.            size_jump, buf_jtotal, size_jump, buf_jfill);
  2667.     }
  2668.  
  2669.   /* Reset state info for each function.  */
  2670.   inside_function    = 0;
  2671.   dslots_load_total  = 0;
  2672.   dslots_jump_total  = 0;
  2673.   dslots_load_filled = 0;
  2674.   dslots_jump_filled = 0;
  2675.   number_functions_processed++;
  2676.   current_frame_info = zero_frame_info;
  2677.  
  2678.   /* Restore the output file if optimizing the GP (optimizing the GP causes
  2679.      the text to be diverted to a tempfile, so that data decls come before
  2680.      references to the data).  */
  2681.  
  2682.   if (TARGET_GP_OPT)
  2683.     asm_out_file = asm_out_data_file;
  2684. }
  2685.  
  2686.  
  2687. /* Define the number of delay slots needed for the function epilogue.
  2688.  
  2689.    On the mips, we need a slot if either no stack has been allocated,
  2690.    or the only register saved is the return register.  */
  2691.  
  2692. int
  2693. mips_epilogue_delay_slots ()
  2694. {
  2695.   if (!current_frame_info.initialized)
  2696.     (void) compute_frame_size (get_frame_size ());
  2697.  
  2698.   if (current_frame_info.total_size == 0)
  2699.     return 1;
  2700.  
  2701.   if (current_frame_info.mask == (1 << 31) && current_frame_info.fmask == 0)
  2702.     return 1;
  2703.  
  2704.   return 0;
  2705. }
  2706.  
  2707.  
  2708. /* Return true if this function is known to have a null epilogue.
  2709.    This allows the optimizer to omit jumps to jumps if no stack
  2710.    was created.  */
  2711.  
  2712. int
  2713. null_epilogue ()
  2714. {
  2715.   if (!reload_completed)
  2716.     return 0;
  2717.  
  2718.   if (current_frame_info.initialized)
  2719.     return current_frame_info.total_size == 0;
  2720.  
  2721.   return (compute_frame_size (get_frame_size ())) == 0;
  2722. }
  2723.