home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / final.c < prev    next >
C/C++ Source or Header  |  1991-12-19  |  63KB  |  2,357 lines

  1. /* Convert RTL to assembler code and output it, for GNU compiler.
  2.    Copyright (C) 1987-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This is the final pass of the compiler.
  22.    It looks at the rtl code for a function and outputs assembler code.
  23.  
  24.    Call `final_start_function' to output the assembler code for function entry,
  25.    `final' to output assembler code for some RTL code,
  26.    `final_end_function' to output assembler code for function exit.
  27.    If a function is compiled in several pieces, each piece is
  28.    output separately with `final'.
  29.  
  30.    Some optimizations are also done at this level.
  31.    Move instructions that were made unnecessary by good register allocation
  32.    are detected and omitted from the output.  (Though most of these
  33.    are removed by the last jump pass.)
  34.  
  35.    Instructions to set the condition codes are omitted when it can be
  36.    seen that the condition codes already had the desired values.
  37.  
  38.    In some cases it is sufficient if the inherited condition codes
  39.    have related values, but this may require the following insn
  40.    (the one that tests the condition codes) to be modified.
  41.  
  42.    The code for the function prologue and epilogue are generated
  43.    directly as assembler code by the macros FUNCTION_PROLOGUE and
  44.    FUNCTION_EPILOGUE.  Those instructions never exist as rtl.  */
  45.  
  46. #include <stdio.h>
  47. #include "config.h"
  48. #include "gvarargs.h"
  49. #include "rtl.h"
  50. #include "regs.h"
  51. #include "insn-config.h"
  52. #include "insn-attr.h"
  53. #include "insn-codes.h"
  54. #include "recog.h"
  55. #include "conditions.h"
  56. #include "gdbfiles.h"
  57. #include "flags.h"
  58. #include "real.h"
  59. #include "output.h"
  60. #include "hard-reg-set.h"
  61.  
  62. /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist.  */
  63. #ifdef DBX_DEBUGGING_INFO
  64. #ifdef USG
  65. #include "stab.h"  /* If doing DBX on sysV, use our own stab.h.  */
  66. #else
  67. #include <stab.h>  /* On BSD, use the system's stab.h.  */
  68. #endif /* not USG */
  69. #endif /* DBX_DEBUGGING_INFO */
  70.  
  71. /* .stabd code for line number.  */
  72. #ifndef N_SLINE
  73. #define    N_SLINE    0x44
  74. #endif
  75.  
  76. /* .stabs code for included file name.  */
  77. #ifndef N_SOL
  78. #define    N_SOL 0x84
  79. #endif
  80.  
  81. #define min(A,B) ((A) < (B) ? (A) : (B))
  82.  
  83. #ifndef INT_TYPE_SIZE
  84. #define INT_TYPE_SIZE BITS_PER_WORD
  85. #endif
  86.  
  87. /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist.  So define a
  88.    null default for it to save conditionalization later.  */
  89. #ifndef CC_STATUS_INIT
  90. #define CC_STATUS_INIT
  91. #endif
  92.  
  93. /* How to start an assembler comment.  */
  94. #ifndef ASM_COMMENT_START
  95. #define ASM_COMMENT_START ";#"
  96. #endif
  97.  
  98. rtx peephole ();
  99. void output_asm_insn ();
  100. rtx alter_subreg ();
  101. static int alter_cond ();
  102. void output_asm_label ();
  103. static void output_operand ();
  104. void output_address ();
  105. void output_addr_const ();
  106. static void output_source_line ();
  107. rtx final_scan_insn ();
  108.  
  109. #ifdef HAVE_ATTR_length
  110. static int asm_insn_count ();
  111. #endif
  112.  
  113. /* Nonzero means this function is a leaf function, with no function calls. 
  114.    This variable exists to be examined in FUNCTION_PROLOGUE
  115.    and FUNCTION_EPILOGUE.  Always zero, unless set by some action.  */
  116. int leaf_function;
  117.  
  118. int leaf_function_p ();
  119.  
  120. #ifdef LEAF_REGISTERS
  121. int only_leaf_regs_used ();
  122. static void leaf_renumber_regs ();
  123. static void leaf_renumber_regs_insn ();
  124. #endif
  125.  
  126. /* Last insn processed by final_scan_insn.  */
  127. static rtx debug_insn = 0;
  128.  
  129. /* Line number of last NOTE.  */
  130. static int last_linenum;
  131.  
  132. /* Number of basic blocks seen so far;
  133.    used if profile_block_flag is set.  */
  134. static int count_basic_blocks;
  135.  
  136. /* Nonzero while outputting an `asm' with operands.
  137.    This means that inconsistencies are the user's fault, so don't abort.
  138.    The precise value is the insn being output, to pass to error_for_asm.  */
  139. static rtx this_is_asm_operands;
  140.  
  141. /* Number of operands of this insn, for an `asm' with operands.  */
  142. static int insn_noperands;
  143.  
  144. /* Compare optimization flag.  */
  145.  
  146. static rtx last_ignored_compare = 0;
  147.  
  148. /* Flag indicating this insn is the start of a new basic block.  */
  149.  
  150. static int new_block = 1;
  151.  
  152. /* All the symbol-blocks (levels of scoping) in the compilation
  153.    are assigned sequence numbers in order of appearance of the
  154.    beginnings of the symbol-blocks.  Both final and dbxout do this,
  155.    and assume that they will both give the same number to each block.
  156.    Final uses these sequence numbers to generate assembler label names
  157.    LBBnnn and LBEnnn for the beginning and end of the symbol-block.
  158.    Dbxout uses the sequence nunbers to generate references to the same labels
  159.    from the dbx debugging information.
  160.  
  161.    Sdb records this level at the beginning of each function,
  162.    in order to find the current level when recursing down declarations.
  163.    It outputs the block beginning and endings
  164.    at the point in the asm file where the blocks would begin and end.  */
  165.  
  166. int next_block_index;
  167.  
  168. /* Assign a unique number to each insn that is output.
  169.    This can be used to generate unique local labels.  */
  170.  
  171. static int insn_counter = 0;
  172.  
  173. /* Chain of all `struct gdbfile's.  */
  174.  
  175. struct gdbfile *gdbfiles;
  176.  
  177. /* `struct gdbfile' for the last file we wrote a line number for.  */
  178.  
  179. static struct gdbfile *current_gdbfile;
  180.  
  181. /* Filenum to assign to the next distinct source file encountered.  */
  182.  
  183. static int next_gdb_filenum;
  184.  
  185. #ifdef HAVE_cc0
  186. /* This variable contains machine-dependent flags (defined in tm-...h)
  187.    set and examined by output routines
  188.    that describe how to interpret the condition codes properly.  */
  189.  
  190. CC_STATUS cc_status;
  191.  
  192. /* During output of an insn, this contains a copy of cc_status
  193.    from before the insn.  */
  194.  
  195. CC_STATUS cc_prev_status;
  196. #endif
  197.  
  198. /* Indexed by hardware reg number, is 1 if that register is ever
  199.    used in the current function.
  200.  
  201.    In life_analysis, or in stupid_life_analysis, this is set
  202.    up to record the hard regs used explicitly.  Reload adds
  203.    in the hard regs used for holding pseudo regs.  Final uses
  204.    it to generate the code in the function prologue and epilogue
  205.    to save and restore registers as needed.  */
  206.  
  207. char regs_ever_live[FIRST_PSEUDO_REGISTER];
  208.  
  209. /* Nonzero means current function must be given a frame pointer.
  210.    Set in stmt.c if anything is allocated on the stack there.
  211.    Set in reload1.c if anything is allocated on the stack there.  */
  212.  
  213. int frame_pointer_needed;
  214.  
  215. /* Assign unique numbers to labels generated for profiling.  */
  216.  
  217. int profile_label_no;
  218.  
  219. /* Length so far allocated in PENDING_BLOCKS.  */
  220.  
  221. static int max_block_depth;
  222.  
  223. /* Stack of sequence numbers of symbol-blocks of which we have seen the
  224.    beginning but not yet the end.  Sequence numbers are assigned at
  225.    the beginning; this stack allows us to find the sequence number
  226.    of a block that is ending.  */
  227.  
  228. static int *pending_blocks;
  229.  
  230. /* Number of elements currently in use in PENDING_BLOCKS.  */
  231.  
  232. static int block_depth;
  233.  
  234. /* Nonzero if have enabled APP processing of our assembler output.  */
  235.  
  236. static int app_on;
  237.  
  238. /* If we are outputting an insn sequence, this contains the sequence rtx.
  239.    Zero otherwise.  */
  240.  
  241. rtx final_sequence;
  242.  
  243. /* Initialize data in final at the beginning of a compilation.  */
  244.  
  245. void
  246. init_final (filename)
  247.      char *filename;
  248. {
  249.   next_block_index = 2;
  250.   app_on = 0;
  251.   max_block_depth = 20;
  252.   pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
  253.   gdbfiles = 0;
  254.   next_gdb_filenum = 0;
  255.   final_sequence = 0;
  256. }
  257.  
  258. /* Called at end of source file,
  259.    to output the block-profiling table for this entire compilation.  */
  260.  
  261. void
  262. end_final (filename)
  263.      char *filename;
  264. {
  265.   int i;
  266.  
  267.   if (profile_block_flag)
  268.     {
  269.       char name[12];
  270.  
  271.       data_section ();
  272.  
  273.       /* Output the main header, of 6 words:
  274.      0:  1 if this file's initialized, else 0.
  275.      1:  address of file name.
  276.      2:  address of table of counts.
  277.      4:  number of counts in the table.
  278.      5:  always 0, for compatibility with Sun.
  279.      6:  extra word added by GNU: address of address table
  280.           which contains addresses of basic blocks,
  281.           in parallel with the table of counts.  */
  282.       ASM_OUTPUT_ALIGN (asm_out_file,
  283.             exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  284.  
  285.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
  286.       assemble_integer_zero ();
  287.  
  288.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
  289.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  290.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
  291.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  292.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (CONST_INT, VOIDmode,
  293.                          count_basic_blocks));
  294.       assemble_integer_zero ();
  295.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
  296.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  297.  
  298.       /* Output the file name.  */
  299.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
  300.       {
  301.     int len = strlen (filename);
  302.     char *data_file = (char *) alloca (len + 3);
  303.     strcpy (data_file, filename);
  304.     strip_off_ending (data_file, len);
  305.     strcat (data_file, ".d");
  306.     assemble_string (data_file, strlen (data_file) + 1);
  307.       }
  308.  
  309.       /* Realign data section.  */
  310.       ASM_OUTPUT_ALIGN (asm_out_file,
  311.             exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  312.  
  313.       /* Make space for the table of counts.  */
  314.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
  315.       assemble_zeros (INT_TYPE_SIZE / BITS_PER_UNIT * count_basic_blocks);
  316.  
  317.       /* Output the table of addresses.  */
  318.       readonly_data_section ();
  319.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
  320.       for (i = 0; i < count_basic_blocks; i++)
  321.     {
  322.       char name[12];
  323.       ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
  324.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  325.     }
  326.  
  327.       /* End with the address of the table of addresses,
  328.      so we can find it easily, as the last word in the file's text.  */
  329.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
  330.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  331.     }
  332. }
  333.  
  334. /* Enable APP processing of subsequent output.
  335.    Used before the output from an `asm' statement.  */
  336.  
  337. void
  338. app_enable ()
  339. {
  340.   if (! app_on)
  341.     {
  342.       fprintf (asm_out_file, ASM_APP_ON);
  343.       app_on = 1;
  344.     }
  345. }
  346.  
  347. /* Enable APP processing of subsequent output.
  348.    Called from varasm.c before most kinds of output.  */
  349.  
  350. void
  351. app_disable ()
  352. {
  353.   if (app_on)
  354.     {
  355.       fprintf (asm_out_file, ASM_APP_OFF);
  356.       app_on = 0;
  357.     }
  358. }
  359.  
  360. /* Return the number of slots filled in the current 
  361.    delayed branch sequence (we don't count the insn needing the
  362.    delay slot).   Zero if not in a delayed branch sequence.  */
  363.  
  364. #ifdef DELAY_SLOTS
  365. int
  366. dbr_sequence_length ()
  367. {
  368.   if (final_sequence != 0)
  369.     return XVECLEN (final_sequence, 0) - 1;
  370.   else
  371.     return 0;
  372. }
  373. #endif
  374.  
  375. /* The next two pages contain routines used to compute the length of an insn
  376.    and to shorten branches.  */
  377.  
  378. /* Arrays for insn lengths, and addresses.  The latter is referenced by
  379.    `insn_current_length'.  */
  380.  
  381. static short *insn_lengths;
  382. int *insn_addresses;
  383.  
  384. /* Address of insn being processed.  Used by `insn_current_length'.  */
  385. int insn_current_address;
  386.  
  387. /* Indicate the branch shortening hasn't yet been done.  */
  388.  
  389. void
  390. init_insn_lengths ()
  391. {
  392.   insn_lengths = 0;
  393. }
  394.  
  395. /* Obtain the current length of an insn.  If branch shortening has been done,
  396.    get its actual length.  Otherwise, get its maximum length.  */
  397.  
  398. int
  399. get_attr_length (insn)
  400.      rtx insn;
  401. {
  402. #ifdef HAVE_ATTR_length
  403.   rtx body;
  404.   int i;
  405.   int length = 0;
  406.  
  407.   if (insn_lengths)
  408.     return insn_lengths[INSN_UID (insn)];
  409.   else
  410.     switch (GET_CODE (insn))
  411.       {
  412.       case NOTE:
  413.       case BARRIER:
  414.       case CODE_LABEL:
  415.     return 0;
  416.  
  417.       case CALL_INSN:
  418.     length = insn_default_length (insn);
  419.     break;
  420.  
  421.       case JUMP_INSN:
  422.     body = PATTERN (insn);
  423.         if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
  424.       {
  425.         /* This only takes room if jump tables go into the text section.  */
  426. #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
  427.         length = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
  428.               * GET_MODE_SIZE (GET_MODE (body)));
  429.  
  430.         /* Be pessimistic and assume worst-case alignment.  */
  431.         length += (GET_MODE_SIZE (GET_MODE (body)) - 1);
  432. #else
  433.         return 0;
  434. #endif
  435.       }
  436.     else
  437.       length = insn_default_length (insn);
  438.     break;
  439.  
  440.       case INSN:
  441.     body = PATTERN (insn);
  442.     if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
  443.       return 0;
  444.  
  445.     else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
  446.       length = asm_insn_count (insn) * insn_default_length (insn);
  447.     else if (GET_CODE (body) == SEQUENCE)
  448.       for (i = 0; i < XVECLEN (body, 0); i++)
  449.         length += get_attr_length (XVECEXP (body, 0, i));
  450.     else
  451.       length = insn_default_length (insn);
  452.       }
  453.  
  454. #ifdef ADJUST_INSN_LENGTH
  455.   ADJUST_INSN_LENGTH (insn, length);
  456. #endif
  457.   return length;
  458. #endif /* HAVE_ATTR_length */
  459. }
  460.  
  461. /* Make a pass over all insns and compute their actual lengths by shortening
  462.    any branches of variable length if possible.  */
  463.  
  464. /* Give a default value for the lowest address in a function.  */
  465.  
  466. #ifndef FIRST_INSN_ADDRESS
  467. #define FIRST_INSN_ADDRESS 0
  468. #endif
  469.  
  470. void
  471. shorten_branches (first)
  472.      rtx first;
  473. {
  474. #ifdef HAVE_ATTR_length
  475.   rtx insn;
  476.   int something_changed = 1;
  477.   int max_uid = 0;
  478.   char *varying_length;
  479.   rtx body;
  480.   int uid;
  481.  
  482.   /* Compute maximum UID and allocate arrays.  */
  483.   for (insn = first; insn; insn = NEXT_INSN (insn))
  484.     if (INSN_UID (insn) > max_uid)
  485.       max_uid = INSN_UID (insn);
  486.  
  487.   max_uid++;
  488.   insn_lengths = (short *) oballoc (max_uid * sizeof (short));
  489.   insn_addresses = (int *) oballoc (max_uid * sizeof (int));
  490.   varying_length = (char *) oballoc (max_uid * sizeof (char));
  491.  
  492.   /* Compute initial lengths, addresses, and varying flags for each insn.  */
  493.   for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
  494.        insn != 0;
  495.        insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
  496.     {
  497.       uid = INSN_UID (insn);
  498.       insn_addresses[uid] = insn_current_address;
  499.       insn_lengths[uid] = 0;
  500.       varying_length[uid] = 0;
  501.       
  502.       if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
  503.       || GET_CODE (insn) == CODE_LABEL)
  504.     continue;
  505.  
  506.       body = PATTERN (insn);
  507.       if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
  508.     {
  509.       /* This only takes room if read-only data goes into the text
  510.          section.  */
  511. #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
  512.       int unitsize = GET_MODE_SIZE (GET_MODE (body));
  513.  
  514.       insn_lengths[uid] = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
  515.                    * GET_MODE_SIZE (GET_MODE (body)));
  516.  
  517.       /* Account for possible alignment.  */
  518.       insn_lengths[uid]
  519.         += unitsize - (insn_current_address & (unitsize - 1));
  520. #else
  521.       ;
  522. #endif
  523.     }
  524.       else if (asm_noperands (body) >= 0)
  525.     insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
  526.       else if (GET_CODE (body) == SEQUENCE)
  527.     {
  528.       int i;
  529.  
  530.       /* Inside a delay slot sequence, we do not do any branch shortening
  531.          (on the only machine known to have both variable-length branches
  532.          and delay slots, the ROMP, branch-with-execute is the same size
  533.          as the maximum branch anyway).  So we only have to handle normal
  534.          insns (actually, reorg never puts ASM insns in a delay slot, but
  535.          we don't take advantage of that knowlege here).  */
  536.       for (i = 0; i < XVECLEN (body, 0); i++)
  537.         {
  538.           rtx inner_insn = XVECEXP (body, 0, i);
  539.           int inner_uid = INSN_UID (inner_insn);
  540.           int inner_length;
  541.  
  542.           if (asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
  543.         inner_length = (asm_insn_count (PATTERN (inner_insn))
  544.                 * insn_default_length (inner_insn));
  545.           else
  546.         inner_length = insn_default_length (inner_insn);
  547.           
  548.           insn_lengths[inner_uid] = inner_length;
  549.           varying_length[inner_uid] = 0;
  550.           insn_lengths[uid] += inner_length;
  551.         }
  552.     }
  553.       else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
  554.     {
  555.       insn_lengths[uid] = insn_default_length (insn);
  556.       varying_length[uid] = insn_variable_length_p (insn);
  557.     }
  558.  
  559.       /* If needed, do any adjustment.  */
  560. #ifdef ADJUST_INSN_LENGTH
  561.       ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
  562. #endif
  563.     }
  564.  
  565.   /* Now loop over all the insns finding varying length insns.  For each,
  566.      get the current insn length.  If it has changed, reflect the change.
  567.      When nothing changes for a full pass, we are done.  */
  568.  
  569.   while (something_changed)
  570.     {
  571.       something_changed = 0;
  572.       for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
  573.        insn != 0;
  574.        insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
  575.     {
  576.       int new_length;
  577.  
  578.       uid = INSN_UID (insn);
  579.       insn_addresses[uid] = insn_current_address;
  580.       if (! varying_length[uid])
  581.         continue;
  582.  
  583.       new_length = insn_current_length (insn);
  584.       if (new_length != insn_lengths[uid])
  585.         {
  586.           insn_lengths[uid] = new_length;
  587.           something_changed = 1;
  588.         }
  589.     }
  590.     }
  591. #endif /* HAVE_ATTR_length */
  592. }
  593.  
  594. #ifdef HAVE_ATTR_length
  595. /* Given the body of an INSN known to be generated by an ASM statement, return
  596.    the number of machine instructions likely to be generated for this insn.
  597.    This is used to compute its length.  */
  598.  
  599. static int
  600. asm_insn_count (body)
  601.      rtx body;
  602. {
  603.   char *template;
  604.   int count = 1;
  605.  
  606.   for (template = decode_asm_operands (body, 0, 0, 0, 0);
  607.        *template; template++)
  608.     if (*template == ';' || *template == '\n')
  609.       count++;
  610.  
  611.   return count;
  612. }
  613. #endif
  614.  
  615. /* Output assembler code for the start of a function,
  616.    and initialize some of the variables in this file
  617.    for the new function.  The label for the function and associated
  618.    assembler pseudo-ops have already been output in `assemble_function'.
  619.  
  620.    FIRST is the first insn of the rtl for the function being compiled.
  621.    FILE is the file to write assembler code to.
  622.    WRITE_SYMBOLS says which kind of debugging info to write (or none).
  623.    OPTIMIZE is nonzero if we should eliminate redundant
  624.      test and compare insns.  */
  625.  
  626. void
  627. final_start_function (first, file, write_symbols, optimize)
  628.      rtx first;
  629.      FILE *file;
  630.      enum debugger write_symbols;
  631.      int optimize;
  632. {
  633.   block_depth = 0;
  634.  
  635.   this_is_asm_operands = 0;
  636.  
  637. #ifdef NON_SAVING_SETJMP
  638.   /* A function that calls setjmp should save and restore all the
  639.      call-saved registers on a system where longjmp clobbers them.  */
  640.   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
  641.     {
  642.       int i;
  643.  
  644.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  645.     if (!call_used_regs[i] && !call_fixed_regs[i])
  646.       regs_ever_live[i] = 1;
  647.     }
  648. #endif
  649.   
  650.   /* Initial line number is supposed to be output
  651.      before the function's prologue and label
  652.      so that the function's address will not appear to be
  653.      in the last statement of the preceding function.  */
  654.   if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
  655.     {
  656.       if (write_symbols == SDB_DEBUG)
  657.     /* For sdb, let's not, but say we did.
  658.        We need to set last_linenum for sdbout_function_begin,
  659.        but we can't have an actual line number before the .bf symbol.
  660.        (sdb_begin_function_line is not set,
  661.        and other compilers don't do it.)  */
  662.     last_linenum = NOTE_LINE_NUMBER (first);
  663.       else
  664.     output_source_line (file, first, write_symbols);
  665.     }
  666.  
  667. #ifdef LEAF_REG_REMAP
  668.   if (leaf_function)
  669.     leaf_renumber_regs (first);
  670. #endif
  671.  
  672.   /* The Sun386i and perhaps other machines don't work right
  673.      if the profiling code comes after the prologue.  */
  674. #ifdef PROFILE_BEFORE_PROLOGUE
  675.   if (profile_flag)
  676.     profile_function (file);
  677. #endif /* PROFILE_BEFORE_PROLOGUE */
  678.  
  679. #ifdef FUNCTION_PROLOGUE
  680.   /* First output the function prologue: code to set up the stack frame.  */
  681.   FUNCTION_PROLOGUE (file, get_frame_size ());
  682. #endif
  683.  
  684. #ifdef SDB_DEBUGGING_INFO
  685.   if (write_symbols == SDB_DEBUG)
  686.     next_block_index = 1;
  687. #endif
  688.  
  689. #ifdef FUNCTION_BLOCK_PROFILER
  690.   if (profile_block_flag)
  691.     {
  692.       FUNCTION_BLOCK_PROFILER (file, profile_label_no);
  693.     }
  694. #endif /* FUNCTION_BLOCK_PROFILER */
  695.  
  696. #ifndef PROFILE_BEFORE_PROLOGUE
  697.   if (profile_flag)
  698.     profile_function (file);
  699. #endif /* not PROFILE_BEFORE_PROLOGUE */
  700.  
  701.   profile_label_no++;
  702. }
  703.  
  704. profile_function (file)
  705.      FILE *file;
  706. {
  707.   int align = min (BIGGEST_ALIGNMENT, INT_TYPE_SIZE);
  708.   int sval = current_function_returns_struct;
  709.   int cxt = current_function_needs_context;
  710.  
  711.   data_section ();
  712.   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
  713.   ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
  714.   assemble_integer_zero ();
  715.  
  716.   text_section ();
  717.  
  718. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  719.   if (sval)
  720.     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
  721. #else
  722. #ifdef STRUCT_VALUE_REGNUM
  723.   if (sval)
  724.     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
  725. #endif
  726. #endif
  727.  
  728. #if 0
  729. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  730.   if (cxt)
  731.     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
  732. #else
  733. #ifdef STATIC_CHAIN_REGNUM
  734.   if (cxt)
  735.     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
  736. #endif
  737. #endif
  738. #endif                /* 0 */
  739.  
  740.   FUNCTION_PROFILER (file, profile_label_no);
  741.  
  742. #if 0
  743. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  744.   if (cxt)
  745.     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
  746. #else
  747. #ifdef STATIC_CHAIN_REGNUM
  748.   if (cxt)
  749.     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
  750. #endif
  751. #endif
  752. #endif                /* 0 */
  753.  
  754. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  755.   if (sval)
  756.     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
  757. #else
  758. #ifdef STRUCT_VALUE_REGNUM
  759.   if (sval)
  760.     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
  761. #endif
  762. #endif
  763. }
  764.  
  765. /* Output assembler code for the end of a function.
  766.    For clarity, args are same as those of `final_start_function'
  767.    even though not all of them are needed.  */
  768.  
  769. void
  770. final_end_function (first, file, write_symbols, optimize)
  771.      rtx first;
  772.      FILE *file;
  773.      enum debugger write_symbols;
  774.      int optimize;
  775. {
  776.   if (app_on)
  777.     {
  778.       fprintf (file, ASM_APP_OFF);
  779.       app_on = 0;
  780.     }
  781.  
  782. #ifdef SDB_DEBUGGING_INFO
  783.   if (write_symbols == SDB_DEBUG)
  784.     sdbout_end_function (last_linenum);
  785. #endif
  786.  
  787. #ifdef FUNCTION_EPILOGUE
  788.   /* Finally, output the function epilogue:
  789.      code to restore the stack frame and return to the caller.  */
  790.   FUNCTION_EPILOGUE (file, get_frame_size ());
  791. #endif
  792.  
  793. #ifdef SDB_DEBUGGING_INFO
  794.   if (write_symbols == SDB_DEBUG)
  795.     sdbout_end_epilogue ();
  796. #endif
  797.  
  798. #ifdef DWARF_DEBUGGING_INFO
  799.   if (write_symbols == DWARF_DEBUG)
  800.     dwarfout_end_epilogue ();
  801. #endif
  802.  
  803.   /* If FUNCTION_EPILOGUE is not defined, then the function body
  804.      itself contains return instructions wherever needed.  */
  805. }
  806.  
  807. /* Output assembler code for some insns: all or part of a function.
  808.    For description of args, see `final_start_function', above.
  809.  
  810.    PRESCAN is 1 if we are not really outputting,
  811.      just scanning as if we were outputting.
  812.    Prescanning deletes and rearranges insns just like ordinary output.
  813.    PRESCAN is -2 if we are outputting after having prescanned.
  814.    In this case, don't try to delete or rearrange insns
  815.    because that has already been done.
  816.    Prescanning is done only on certain machines.  */
  817.  
  818. void
  819. final (first, file, write_symbols, optimize, prescan)
  820.      rtx first;
  821.      FILE *file;
  822.      enum debugger write_symbols;
  823.      int optimize;
  824.      int prescan;
  825. {
  826.   register rtx insn;
  827.  
  828.   last_ignored_compare = 0;
  829.   new_block = 1;
  830.  
  831.   init_recog ();
  832.  
  833.   CC_STATUS_INIT;
  834.  
  835.   for (insn = NEXT_INSN (first); insn;)
  836.     insn = final_scan_insn (insn, file, write_symbols, optimize,
  837.                 prescan, 0);
  838.  
  839.   /* Do basic-block profiling here
  840.      if the last insn was a conditional branch.  */
  841.   if (profile_block_flag && new_block)
  842.     {
  843.       new_block = 0;
  844.       /* Enable the table of basic-block use counts
  845.      to point at the code it applies to.  */
  846.       ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
  847.       /* Before first insn of this basic block, increment the
  848.      count of times it was entered.  */
  849. #ifdef BLOCK_PROFILER
  850.       BLOCK_PROFILER (file, count_basic_blocks);
  851.       CC_STATUS_INIT;
  852. #endif
  853.       count_basic_blocks++;
  854.     }
  855. }
  856.  
  857. /* The final scan for one insn, INSN.
  858.    Args are same as in `final', except that INSN
  859.    is the insn being scanned.
  860.    Value returned is the next insn to be scanned.
  861.  
  862.    NOPEEPHOLES is the flag to disallow peephole processing (currently
  863.    used for within delayed branch sequence output).  */
  864.  
  865. rtx
  866. final_scan_insn (insn, file, write_symbols, optimize, prescan, nopeepholes)
  867.      rtx insn;
  868.      FILE *file;
  869.      enum debugger write_symbols;
  870.      int optimize;
  871.      int prescan;
  872.      int nopeepholes;
  873. {
  874.   register int i;
  875.   insn_counter++;
  876.  
  877.   /* Ignore deleted insns.  These can occur when we split insns (due to a
  878.      template of "#") while not optimizing.  */
  879.   if (INSN_DELETED_P (insn))
  880.     return NEXT_INSN (insn);
  881.  
  882.   switch (GET_CODE (insn))
  883.     {
  884.     case NOTE:
  885.       if (prescan > 0)
  886.     break;
  887.  
  888.       /* Align the beginning of a loop, for higher speed
  889.      on certain machines.  */
  890.  
  891.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG && optimize > 0)
  892.     {
  893. #ifdef ASM_OUTPUT_LOOP_ALIGN
  894.       ASM_OUTPUT_LOOP_ALIGN (asm_out_file);
  895. #endif
  896.       break;
  897.     }
  898.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
  899.     break;
  900.  
  901.       if (write_symbols == NO_DEBUG)
  902.     break;
  903.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
  904.     {
  905. #ifdef SDB_DEBUGGING_INFO
  906.       if (write_symbols == SDB_DEBUG)
  907.         sdbout_begin_function (last_linenum);
  908. #endif
  909.       break;
  910.     }
  911.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
  912.     break;            /* An insn that was "deleted" */
  913.       if (app_on)
  914.     {
  915.       fprintf (file, ASM_APP_OFF);
  916.       app_on = 0;
  917.     }
  918.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  919.     {
  920.       /* Beginning of a symbol-block.  Assign it a sequence number
  921.          and push the number onto the stack PENDING_BLOCKS.  */
  922.  
  923.       if (block_depth == max_block_depth)
  924.         {
  925.           /* PENDING_BLOCKS is full; make it longer.  */
  926.           max_block_depth *= 2;
  927.           pending_blocks
  928.         = (int *) xrealloc (pending_blocks,
  929.                     max_block_depth * sizeof (int));
  930.         }
  931.       pending_blocks[block_depth++] = next_block_index;
  932.  
  933.       /* Output debugging info about the symbol-block beginning.  */
  934.  
  935. #ifdef SDB_DEBUGGING_INFO
  936.       if (write_symbols == SDB_DEBUG)
  937.         sdbout_begin_block (file, last_linenum, next_block_index);
  938. #endif
  939. #ifdef DBX_DEBUGGING_INFO
  940.       if (write_symbols == DBX_DEBUG)
  941.         ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
  942. #endif
  943. #ifdef DWARF_DEBUGGING_INFO
  944.       if (write_symbols == DWARF_DEBUG)
  945.         dwarfout_begin_block (next_block_index);
  946. #endif
  947. #if 0
  948.       if (write_symbols == GDB_DEBUG)
  949.         fprintf (file, "\t.gdbbeg %d\n", next_block_index);
  950. #endif
  951.  
  952.       next_block_index++;
  953.     }
  954.       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
  955.     {
  956.       /* End of a symbol-block.  Pop its sequence number off
  957.          PENDING_BLOCKS and output debugging info based on that.  */
  958.  
  959.       --block_depth;
  960.  
  961. #ifdef DBX_DEBUGGING_INFO
  962.       if (write_symbols == DBX_DEBUG && block_depth >= 0)
  963.         ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
  964.                        pending_blocks[block_depth]);
  965. #endif
  966. #ifdef SDB_DEBUGGING_INFO
  967.       if (write_symbols == SDB_DEBUG && block_depth >= 0)
  968.         sdbout_end_block (file, last_linenum);
  969. #endif
  970. #ifdef DWARF_DEBUGGING_INFO
  971.       if (write_symbols == DWARF_DEBUG && block_depth >= 0)
  972.         dwarfout_end_block (pending_blocks[block_depth]);
  973. #endif
  974. #if 0
  975.       if (write_symbols == GDB_DEBUG)
  976.         fprintf (file, "\t.gdbend %d\n", pending_blocks[block_depth]);
  977. #endif
  978.     }
  979.       else if (NOTE_LINE_NUMBER (insn) > 0)
  980.     /* This note is a line-number.  */
  981.     output_source_line (file, insn, write_symbols);
  982.       break;
  983.  
  984.     case BARRIER:
  985. #ifdef ASM_OUTPUT_ALIGN_CODE
  986.       ASM_OUTPUT_ALIGN_CODE (file);
  987. #endif
  988.       break;
  989.  
  990.     case CODE_LABEL:
  991.       CC_STATUS_INIT;
  992.       if (prescan > 0)
  993.     break;
  994.       new_block = 1;
  995. #ifdef SDB_DEBUGGING_INFO
  996.       if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
  997.     sdbout_label (insn);
  998. #endif
  999. #ifdef DWARF_DEBUGGING_INFO
  1000.       if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
  1001.     dwarfout_label (insn);
  1002. #endif
  1003.       if (app_on)
  1004.     {
  1005.       fprintf (file, ASM_APP_OFF);
  1006.       app_on = 0;
  1007.     }
  1008.       if (NEXT_INSN (insn) != 0
  1009.       && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
  1010.     {
  1011.       rtx nextbody = PATTERN (NEXT_INSN (insn));
  1012.  
  1013.       /* If this label is followed by a jump-table,
  1014.          make sure we put the label in the read-only section.  Also
  1015.          possibly write the label and jump table together.  */
  1016.  
  1017.       if (GET_CODE (nextbody) == ADDR_VEC
  1018.           || GET_CODE (nextbody) == ADDR_DIFF_VEC)
  1019.         {
  1020. #ifndef JUMP_TABLES_IN_TEXT_SECTION
  1021.           readonly_data_section ();
  1022. #else
  1023.           text_section ();
  1024. #endif
  1025. #ifdef ASM_OUTPUT_CASE_LABEL
  1026.           ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
  1027.                      NEXT_INSN (insn));
  1028. #else
  1029.           ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
  1030. #endif
  1031.           break;
  1032.         }
  1033.     }
  1034.  
  1035.       ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
  1036.       break;
  1037.  
  1038.     default:
  1039.       {
  1040.     register rtx body = PATTERN (insn);
  1041.     int insn_code_number;
  1042.     char *template;
  1043.     rtx note;
  1044.  
  1045.     /* An INSN, JUMP_INSN or CALL_INSN.
  1046.        First check for special kinds that recog doesn't recognize.  */
  1047.  
  1048.     if (GET_CODE (body) == USE /* These are just declarations */
  1049.         || GET_CODE (body) == CLOBBER)
  1050.       break;
  1051.  
  1052. #ifdef HAVE_cc0
  1053.     /* If there is a REG_CC_SETTER note on this insn, it means that
  1054.        the setting of the condition code was done in the delay slot
  1055.        of the insn that branched here.  So recover the cc status
  1056.        from the insn that set it.  */
  1057.  
  1058.     note = find_reg_note (insn, REG_CC_SETTER, 0);
  1059.     if (note)
  1060.       {
  1061.         NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
  1062.         cc_prev_status = cc_status;
  1063.       }
  1064. #endif
  1065.  
  1066.     /* Detect insns that are really jump-tables
  1067.        and output them as such.  */
  1068.  
  1069.     if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
  1070.       {
  1071.         register int vlen, idx;
  1072.  
  1073.         if (prescan > 0)
  1074.           break;
  1075.  
  1076.         if (app_on)
  1077.           {
  1078.         fprintf (file, ASM_APP_OFF);
  1079.         app_on = 0;
  1080.           }
  1081.  
  1082. #ifndef JUMP_TABLES_IN_TEXT_SECTION
  1083.         readonly_data_section ();
  1084. #endif
  1085.  
  1086.         vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
  1087.         for (idx = 0; idx < vlen; idx++)
  1088.           {
  1089.         if (GET_CODE (body) == ADDR_VEC)
  1090.           ASM_OUTPUT_ADDR_VEC_ELT
  1091.             (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
  1092.         else
  1093.           ASM_OUTPUT_ADDR_DIFF_ELT
  1094.             (file,
  1095.              CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
  1096.              CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
  1097.           }
  1098. #ifdef ASM_OUTPUT_CASE_END
  1099.         ASM_OUTPUT_CASE_END (file,
  1100.                  CODE_LABEL_NUMBER (PREV_INSN (insn)),
  1101.                  insn);
  1102. #endif
  1103.  
  1104.         text_section ();
  1105.  
  1106.         break;
  1107.       }
  1108.  
  1109.     /* Do basic-block profiling when we reach a new block.
  1110.        Done here to avoid jump tables.  */
  1111.     if (profile_block_flag && new_block)
  1112.       {
  1113.         new_block = 0;
  1114.         /* Enable the table of basic-block use counts
  1115.            to point at the code it applies to.  */
  1116.         ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
  1117.         /* Before first insn of this basic block, increment the
  1118.            count of times it was entered.  */
  1119. #ifdef BLOCK_PROFILER
  1120.         BLOCK_PROFILER (file, count_basic_blocks);
  1121.         CC_STATUS_INIT;
  1122. #endif
  1123.         count_basic_blocks++;
  1124.       }
  1125.  
  1126.     if (GET_CODE (body) == ASM_INPUT)
  1127.       {
  1128.         /* There's no telling what that did to the condition codes.  */
  1129.         CC_STATUS_INIT;
  1130.         if (prescan > 0)
  1131.           break;
  1132.         if (! app_on)
  1133.           {
  1134.         fprintf (file, ASM_APP_ON);
  1135.         app_on = 1;
  1136.           }
  1137.         fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
  1138.         break;
  1139.       }
  1140.  
  1141.     /* Detect `asm' construct with operands.  */
  1142.     if (asm_noperands (body) >= 0)
  1143.       {
  1144.         int noperands = asm_noperands (body);
  1145.         rtx *ops;
  1146.         char *string;
  1147.  
  1148.         /* There's no telling what that did to the condition codes.  */
  1149.         CC_STATUS_INIT;
  1150.         if (prescan > 0)
  1151.           break;
  1152.  
  1153.         /* alloca won't do here, since only return from `final'
  1154.            would free it.  */
  1155.         if (noperands > 0)
  1156.           ops = (rtx *) xmalloc (noperands * sizeof (rtx));
  1157.  
  1158.         if (! app_on)
  1159.           {
  1160.         fprintf (file, ASM_APP_ON);
  1161.         app_on = 1;
  1162.           }
  1163.  
  1164.         /* Get out the operand values.  */
  1165.         string = decode_asm_operands (body, ops, 0, 0, 0);
  1166.         /* Inhibit aborts on what would otherwise be compiler bugs.  */
  1167.         insn_noperands = noperands;
  1168.         this_is_asm_operands = insn;
  1169.         /* Output the insn using them.  */
  1170.         output_asm_insn (string, ops);
  1171.         this_is_asm_operands = 0;
  1172.         if (noperands > 0)
  1173.           free (ops);
  1174.         break;
  1175.       }
  1176.  
  1177.     if (prescan <= 0 && app_on)
  1178.       {
  1179.         fprintf (file, ASM_APP_OFF);
  1180.         app_on = 0;
  1181.       }
  1182.  
  1183.     if (GET_CODE (body) == SEQUENCE)
  1184.       {
  1185.         /* A delayed-branch sequence */
  1186.         register int i;
  1187.         rtx next;
  1188.  
  1189.         if (prescan > 0)
  1190.           break;
  1191.         final_sequence = body;
  1192.  
  1193.         /* The first insn in this SEQUENCE might be a JUMP_INSN that will
  1194.            force the restoration of a comparison that was previously
  1195.            thought unnecessary.  If that happens, cancel this sequence
  1196.            and cause that insn to be restored.  */
  1197.  
  1198.         next = final_scan_insn (XVECEXP (body, 0, 0), file, write_symbols,
  1199.                     0, prescan, 1);
  1200.         if (next != XVECEXP (body, 0, 1))
  1201.           {
  1202.         final_sequence = 0;
  1203.         return next;
  1204.           }
  1205.  
  1206.         for (i = 1; i < XVECLEN (body, 0); i++)
  1207.           final_scan_insn (XVECEXP (body, 0, i), file, write_symbols,
  1208.                    0, prescan, 1);
  1209.         final_sequence = 0;
  1210. #ifdef DBR_OUTPUT_SEQEND
  1211.         DBR_OUTPUT_SEQEND (file);
  1212. #endif
  1213.  
  1214.         /* If the insn requiring the delay slot was a CALL_INSN, the
  1215.            insns in the delay slot are actually executed before the
  1216.            called function.  Hence we don't preserve any CC-setting
  1217.            actions in these insns and the CC must be marked as being
  1218.            clobbered by the function.  */
  1219.         if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
  1220.           CC_STATUS_INIT;
  1221.         break;
  1222.       }
  1223.  
  1224.     /* We have a real machine instruction as rtl.  */
  1225.  
  1226.     body = PATTERN (insn);
  1227.  
  1228. #ifdef HAVE_cc0
  1229.     /* Check for redundant test and compare instructions
  1230.        (when the condition codes are already set up as desired).
  1231.        This is done only when optimizing; if not optimizing,
  1232.        it should be possible for the user to alter a variable
  1233.        with the debugger in between statements
  1234.        and the next statement should reexamine the variable
  1235.        to compute the condition codes.  */
  1236.  
  1237.     if (optimize
  1238.         && GET_CODE (body) == SET
  1239.         && GET_CODE (SET_DEST (body)) == CC0
  1240.         && insn != last_ignored_compare)
  1241.       {
  1242.         if (GET_CODE (SET_SRC (body)) == SUBREG)
  1243.           SET_SRC (body) = alter_subreg (SET_SRC (body));
  1244.         else if (GET_CODE (SET_SRC (body)) == COMPARE)
  1245.           {
  1246.         if (GET_CODE (XEXP (SET_SRC (body), 0)) == SUBREG)
  1247.           XEXP (SET_SRC (body), 0)
  1248.             = alter_subreg (XEXP (SET_SRC (body), 0));
  1249.         if (GET_CODE (XEXP (SET_SRC (body), 1)) == SUBREG)
  1250.           XEXP (SET_SRC (body), 1)
  1251.             = alter_subreg (XEXP (SET_SRC (body), 1));
  1252.           }
  1253.         if ((cc_status.value1 != 0
  1254.          && rtx_equal_p (SET_SRC (body), cc_status.value1))
  1255.         || (cc_status.value2 != 0
  1256.             && rtx_equal_p (SET_SRC (body), cc_status.value2)))
  1257.           {
  1258.         /* Don't delete insn if it has an addressing side-effect.  */
  1259.         if (! FIND_REG_INC_NOTE (insn, 0)
  1260.             /* or if anything in it is volatile.  */
  1261.             && ! volatile_refs_p (PATTERN (insn)))
  1262.           {
  1263.             /* We don't really delete the insn; just ignore it.  */
  1264.             last_ignored_compare = insn;
  1265.             break;
  1266.           }
  1267.           }
  1268.       }
  1269. #endif
  1270.  
  1271.     /* Following a conditional branch, we have a new basic block.  */
  1272.     if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
  1273.          && GET_CODE (SET_SRC (body)) != LABEL_REF)
  1274.         || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
  1275.         && GET_CODE (XVECEXP (body, 0, 0)) == SET
  1276.         && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
  1277.       new_block = 1;
  1278.  
  1279.     /* Don't bother outputting obvious no-ops, even without -O.
  1280.        This optimization is fast and doesn't interfere with debugging.
  1281.        Don't do this if the insn is in a delay slot, since this
  1282.        will cause an improper number of delay insns to be written.  */
  1283.     if (final_sequence == 0
  1284.         && prescan >= 0
  1285.         && GET_CODE (insn) == INSN && GET_CODE (body) == SET
  1286.         && GET_CODE (SET_SRC (body)) == REG
  1287.         && GET_CODE (SET_DEST (body)) == REG
  1288.         && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
  1289.       break;
  1290.  
  1291. #ifdef HAVE_cc0
  1292.     /* If this is a conditional branch, maybe modify it
  1293.        if the cc's are in a nonstandard state
  1294.        so that it accomplishes the same thing that it would
  1295.        do straightforwardly if the cc's were set up normally.  */
  1296.  
  1297.     if (cc_status.flags != 0
  1298.         && GET_CODE (insn) == JUMP_INSN
  1299.         && GET_CODE (body) == SET
  1300.         && SET_DEST (body) == pc_rtx
  1301.         && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
  1302.         /* This is done during prescan; it is not done again
  1303.            in final scan when prescan has been done.  */
  1304.         && prescan >= 0)
  1305.       {
  1306.         /* This function may alter the contents of its argument
  1307.            and clear some of the cc_status.flags bits.
  1308.            It may also return 1 meaning condition now always true
  1309.            or -1 meaning condition now always false
  1310.            or 2 meaning condition nontrivial but altered.  */
  1311.         register int result = alter_cond (XEXP (SET_SRC (body), 0));
  1312.         /* If condition now has fixed value, replace the IF_THEN_ELSE
  1313.            with its then-operand or its else-operand.  */
  1314.         if (result == 1)
  1315.           SET_SRC (body) = XEXP (SET_SRC (body), 1);
  1316.         if (result == -1)
  1317.           SET_SRC (body) = XEXP (SET_SRC (body), 2);
  1318.         /* The jump is now either unconditional or a no-op.
  1319.            If it has become a no-op, don't try to output it.
  1320.            (It would not be recognized.)  */
  1321.         if (SET_SRC (body) == pc_rtx)
  1322.           {
  1323.         PUT_CODE (insn, NOTE);
  1324.         NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  1325.         NOTE_SOURCE_FILE (insn) = 0;
  1326.         break;
  1327.           }
  1328.         /* Rerecognize the instruction if it has changed.  */
  1329.         if (result != 0)
  1330.           INSN_CODE (insn) = -1;
  1331.       }
  1332.  
  1333.     /* Make same adjustments to instructions that examine the
  1334.        condition codes without jumping (if this machine has them).  */
  1335.  
  1336.     if (cc_status.flags != 0
  1337.         && GET_CODE (body) == SET)
  1338.       {
  1339.         switch (GET_CODE (SET_SRC (body)))
  1340.           {
  1341.           case GTU:
  1342.           case GT:
  1343.           case LTU:
  1344.           case LT:
  1345.           case GEU:
  1346.           case GE:
  1347.           case LEU:
  1348.           case LE:
  1349.           case EQ:
  1350.           case NE:
  1351.         {
  1352.           register int result;
  1353.           if (XEXP (SET_SRC (body), 0) != cc0_rtx)
  1354.             break;
  1355.           result = alter_cond (SET_SRC (body));
  1356.           if (result == 1)
  1357.             validate_change (insn, &SET_SRC (body),
  1358.                      gen_rtx (CONST_INT, VOIDmode,
  1359.                           STORE_FLAG_VALUE),
  1360.                      0);
  1361.           else if (result == -1)
  1362.             validate_change (insn, &SET_SRC (body), const0_rtx, 0);
  1363.           else if (result == 2)
  1364.             INSN_CODE (insn) = -1;
  1365.         }
  1366.           }
  1367.       }
  1368. #endif
  1369.  
  1370.     /* Do machine-specific peephole optimizations if desired.  */
  1371.  
  1372.     if (optimize && !flag_no_peephole && !nopeepholes)
  1373.       {
  1374.         rtx next = peephole (insn);
  1375.         /* When peepholing, if there were notes within the peephole,
  1376.            emit them before the peephole.  */
  1377.         if (next != 0 && next != NEXT_INSN (insn))
  1378.           {
  1379.         rtx note = NEXT_INSN (insn);
  1380.         rtx prev = PREV_INSN (insn);
  1381.         while (note != next)
  1382.           {
  1383.             final_scan_insn (note, file, write_symbols, optimize,
  1384.                      prescan, nopeepholes);
  1385.             note = NEXT_INSN (note);
  1386.           }
  1387.         /* In case this is prescan, put the notes
  1388.            in proper position for later rescan.  */
  1389.         note = NEXT_INSN (insn);
  1390.         PREV_INSN (note) = prev;
  1391.         NEXT_INSN (prev) = note;
  1392.         NEXT_INSN (PREV_INSN (next)) = insn;
  1393.         PREV_INSN (insn) = PREV_INSN (next);
  1394.         NEXT_INSN (insn) = next;
  1395.         PREV_INSN (next) = insn;
  1396.           }
  1397.  
  1398.         /* PEEPHOLE might have changed this.  */
  1399.         body = PATTERN (insn);
  1400.       }
  1401.  
  1402.     /* Try to recognize the instruction.
  1403.        If successful, verify that the operands satisfy the
  1404.        constraints for the instruction.  Crash if they don't,
  1405.        since `reload' should have changed them so that they do.  */
  1406.  
  1407.     insn_code_number = recog_memoized (insn);
  1408.     insn_extract (insn);
  1409.     for (i = 0; i < insn_n_operands[insn_code_number]; i++)
  1410.       {
  1411.         if (GET_CODE (recog_operand[i]) == SUBREG)
  1412.           recog_operand[i] = alter_subreg (recog_operand[i]);
  1413.       }
  1414.  
  1415. #ifdef REGISTER_CONSTRAINTS
  1416.     if (! constrain_operands (insn_code_number, 1))
  1417.       abort ();
  1418. #endif
  1419.  
  1420.     /* Some target machines need to prescan each insn before
  1421.        it is output.  */
  1422.  
  1423. #ifdef FINAL_PRESCAN_INSN
  1424.     FINAL_PRESCAN_INSN (insn, recog_operand,
  1425.                 insn_n_operands[insn_code_number]);
  1426. #endif
  1427.  
  1428. #ifdef HAVE_cc0
  1429.     cc_prev_status = cc_status;
  1430.  
  1431.     /* Update `cc_status' for this instruction.
  1432.        The instruction's output routine may change it further.
  1433.        If the output routine for a jump insn needs to depend
  1434.        on the cc status, it should look at cc_prev_status.  */
  1435.  
  1436.     NOTICE_UPDATE_CC (body, insn);
  1437. #endif
  1438.  
  1439.     debug_insn = insn;
  1440.  
  1441.     /* If the proper template needs to be chosen by some C code,
  1442.        run that code and get the real template.  */
  1443.  
  1444.     template = insn_template[insn_code_number];
  1445.     if (template == 0)
  1446.       {
  1447.         template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
  1448.  
  1449.         /* If the C code returns 0, it means that it is a jump insn
  1450.            which follows a deleted test insn, and that test insn
  1451.            needs to be reinserted.  */
  1452.         if (template == 0)
  1453.           {
  1454.         if (prev_nonnote_insn (insn) != last_ignored_compare)
  1455.           abort ();
  1456.         new_block = 0;
  1457.         return prev_nonnote_insn (insn);
  1458.           }
  1459.       }
  1460.  
  1461.     /* If the template is the string "#", it means that this insn must
  1462.        be split.  */
  1463.     if (template[0] == '#' && template[1] == '\0')
  1464.       {
  1465.         rtx new = try_split (body, insn, 0);
  1466.  
  1467.         /* If we didn't split the insn, go away.  */
  1468.         if (new == insn && PATTERN (new) == body)
  1469.           abort ();
  1470.           
  1471.         new_block = 0;
  1472.         return new;
  1473.       }
  1474.     
  1475.     if (prescan > 0)
  1476.       break;
  1477.  
  1478.     /* Output assembler code from the template.  */
  1479.  
  1480.     output_asm_insn (template, recog_operand);
  1481.  
  1482. #if 0
  1483.     /* It's not at all clear why we did this and doing so interferes
  1484.        with tests we'd like to do to use REG_WAS_0 notes, so let's try
  1485.        with this out.  */
  1486.  
  1487.     /* Mark this insn as having been output.  */
  1488.     INSN_DELETED_P (insn) = 1;
  1489. #endif
  1490.  
  1491.     debug_insn = 0;
  1492.       }
  1493.     }
  1494.   return NEXT_INSN (insn);
  1495. }
  1496.  
  1497. /* Output debugging info to the assembler file FILE
  1498.    based on the NOTE-insn INSN, assumed to be a line number.  */
  1499.  
  1500. static void
  1501. output_source_line (file, insn, write_symbols)
  1502.      FILE *file;
  1503.      rtx insn;
  1504.      enum debugger write_symbols;
  1505. {
  1506.   char ltext_label_name[100];
  1507.   register char *filename = NOTE_SOURCE_FILE (insn);
  1508.  
  1509.   last_linenum = NOTE_LINE_NUMBER (insn);
  1510.  
  1511.   if (write_symbols == SDB_DEBUG || write_symbols == DBX_DEBUG)
  1512.     {
  1513. #ifdef SDB_DEBUGGING_INFO
  1514.       if (write_symbols == SDB_DEBUG
  1515. #if 0 /* People like having line numbers even in wrong file!  */
  1516.       /* COFF can't handle multiple source files--lose, lose.  */
  1517.       && !strcmp (filename, main_input_filename)
  1518. #endif
  1519.       /* COFF relative line numbers must be positive.  */
  1520.       && last_linenum > sdb_begin_function_line)
  1521.     {
  1522. #ifdef ASM_OUTPUT_SOURCE_LINE
  1523.       ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
  1524. #else
  1525.       fprintf (file, "\t.ln\t%d\n",
  1526.            (sdb_begin_function_line
  1527.             ? last_linenum - sdb_begin_function_line : 1));
  1528. #endif
  1529.     }
  1530. #endif
  1531.  
  1532. #ifdef DBX_DEBUGGING_INFO
  1533.       if (write_symbols == DBX_DEBUG)
  1534.     dbxout_source_file (file, filename);
  1535.  
  1536. #ifdef ASM_OUTPUT_SOURCE_LINE
  1537.       ASM_OUTPUT_SOURCE_LINE (file, NOTE_LINE_NUMBER (insn));
  1538. #else
  1539.       fprintf (file, "\t.stabd %d,0,%d\n",
  1540.            N_SLINE, NOTE_LINE_NUMBER (insn));
  1541. #endif
  1542. #endif /* DBX_DEBUGGING_INFO */
  1543.  
  1544. #ifdef DWARF_DEBUGGING_INFO
  1545.       if (write_symbols == DWARF_DEBUG)
  1546.     {
  1547.           ASM_OUTPUT_DWARF_LINE (file, filename,
  1548.                  NOTE_LINE_NUMBER (insn));
  1549.         }
  1550. #endif
  1551.     }
  1552. }
  1553.  
  1554. /* If X is a SUBREG, replace it with a REG or a MEM,
  1555.    based on the thing it is a subreg of.  */
  1556.  
  1557. rtx
  1558. alter_subreg (x)
  1559.      register rtx x;
  1560. {
  1561.   register rtx y = SUBREG_REG (x);
  1562.   if (GET_CODE (y) == SUBREG)
  1563.     y = alter_subreg (y);
  1564.  
  1565.   if (GET_CODE (y) == REG)
  1566.     {
  1567.       /* If the containing reg really gets a hard reg, so do we.  */
  1568.       PUT_CODE (x, REG);
  1569.       REGNO (x) = REGNO (y) + SUBREG_WORD (x);
  1570.     }
  1571.   else if (GET_CODE (y) == MEM)
  1572.     {
  1573.       register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  1574. #if BYTES_BIG_ENDIAN
  1575.       offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
  1576.          - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
  1577. #endif
  1578.       PUT_CODE (x, MEM);
  1579.       MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
  1580.       XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
  1581.     }
  1582.  
  1583.   return x;
  1584. }
  1585.  
  1586. /* Do alter_subreg on all the SUBREGs contained in X.  */
  1587.  
  1588. static rtx
  1589. walk_alter_subreg (x)
  1590.      rtx x;
  1591. {
  1592.   switch (GET_CODE (x))
  1593.     {
  1594.     case PLUS:
  1595.     case MULT:
  1596.       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
  1597.       XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
  1598.       break;
  1599.  
  1600.     case MEM:
  1601.       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
  1602.       break;
  1603.  
  1604.     case SUBREG:
  1605.       return alter_subreg (x);
  1606.     }
  1607.  
  1608.   return x;
  1609. }
  1610.  
  1611. #ifdef HAVE_cc0
  1612.  
  1613. /* Given BODY, the body of a jump instruction, alter the jump condition
  1614.    as required by the bits that are set in cc_status.flags.
  1615.    Not all of the bits there can be handled at this level in all cases.
  1616.  
  1617.    The value is normally 0.
  1618.    1 means that the condition has become always true.
  1619.    -1 means that the condition has become always false.
  1620.    2 means that COND has been altered.  */
  1621.  
  1622. static int
  1623. alter_cond (cond)
  1624.      register rtx cond;
  1625. {
  1626.   int value = 0;
  1627.  
  1628.   if (cc_status.flags & CC_REVERSED)
  1629.     {
  1630.       value = 2;
  1631.       PUT_CODE (cond, swap_condition (GET_CODE (cond)));
  1632.     }
  1633.  
  1634.   if (cc_status.flags & CC_INVERTED)
  1635.     {
  1636.       value = 2;
  1637.       PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
  1638.     }
  1639.  
  1640.   if (cc_status.flags & CC_NOT_POSITIVE)
  1641.     switch (GET_CODE (cond))
  1642.       {
  1643.       case LE:
  1644.       case LEU:
  1645.       case GEU:
  1646.     /* Jump becomes unconditional.  */
  1647.     return 1;
  1648.  
  1649.       case GT:
  1650.       case GTU:
  1651.       case LTU:
  1652.     /* Jump becomes no-op.  */
  1653.     return -1;
  1654.  
  1655.       case GE:
  1656.     PUT_CODE (cond, EQ);
  1657.     value = 2;
  1658.     break;
  1659.  
  1660.       case LT:
  1661.     PUT_CODE (cond, NE);
  1662.     value = 2;
  1663.     break;
  1664.       }
  1665.  
  1666.   if (cc_status.flags & CC_NOT_NEGATIVE)
  1667.     switch (GET_CODE (cond))
  1668.       {
  1669.       case GE:
  1670.       case GEU:
  1671.     /* Jump becomes unconditional.  */
  1672.     return 1;
  1673.  
  1674.       case LT:
  1675.       case LTU:
  1676.     /* Jump becomes no-op.  */
  1677.     return -1;
  1678.  
  1679.       case LE:
  1680.       case LEU:
  1681.     PUT_CODE (cond, EQ);
  1682.     value = 2;
  1683.     break;
  1684.  
  1685.       case GT:
  1686.       case GTU:
  1687.     PUT_CODE (cond, NE);
  1688.     value = 2;
  1689.     break;
  1690.       }
  1691.  
  1692.   if (cc_status.flags & CC_NO_OVERFLOW)
  1693.     switch (GET_CODE (cond))
  1694.       {
  1695.       case GEU:
  1696.     /* Jump becomes unconditional.  */
  1697.     return 1;
  1698.  
  1699.       case LEU:
  1700.     PUT_CODE (cond, EQ);
  1701.     value = 2;
  1702.     break;
  1703.  
  1704.       case GTU:
  1705.     PUT_CODE (cond, NE);
  1706.     value = 2;
  1707.     break;
  1708.  
  1709.       case LTU:
  1710.     /* Jump becomes no-op.  */
  1711.     return -1;
  1712.       }
  1713.  
  1714.   if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
  1715.     switch (GET_CODE (cond))
  1716.       {
  1717.       case LE:
  1718.       case LEU:
  1719.       case GE:
  1720.       case GEU:
  1721.       case LT:
  1722.       case LTU:
  1723.       case GT:
  1724.       case GTU:
  1725.     abort ();
  1726.  
  1727.       case NE:
  1728.     PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
  1729.     value = 2;
  1730.     break;
  1731.  
  1732.       case EQ:
  1733.     PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
  1734.     value = 2;
  1735.     break;
  1736.       }
  1737.   
  1738.   return value;
  1739. }
  1740. #endif
  1741.  
  1742. /* Report inconsistency between the assembler template and the operands.
  1743.    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
  1744.  
  1745. void
  1746. output_operand_lossage (str)
  1747.      char *str;
  1748. {
  1749.   if (this_is_asm_operands)
  1750.     error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
  1751.   else
  1752.     abort ();
  1753. }
  1754.  
  1755. /* Output of assembler code from a template, and its subroutines.  */
  1756.  
  1757. /* Output text from TEMPLATE to the assembler output file,
  1758.    obeying %-directions to substitute operands taken from
  1759.    the vector OPERANDS.
  1760.  
  1761.    %N (for N a digit) means print operand N in usual manner.
  1762.    %lN means require operand N to be a CODE_LABEL or LABEL_REF
  1763.       and print the label name with no punctuation.
  1764.    %cN means require operand N to be a constant
  1765.       and print the constant expression with no punctuation.
  1766.    %aN means expect operand N to be a memory address
  1767.       (not a memory reference!) and print a reference
  1768.       to that address.
  1769.    %nN means expect operand N to be a constant
  1770.       and print a constant expression for minus the value
  1771.       of the operand, with no other punctuation.  */
  1772.  
  1773. void
  1774. output_asm_insn (template, operands)
  1775.      char *template;
  1776.      rtx *operands;
  1777. {
  1778.   register char *p;
  1779.   register int c;
  1780.  
  1781.   /* An insn may return a null string template
  1782.      in a case where no assembler code is needed.  */
  1783.   if (*template == 0)
  1784.     return;
  1785.  
  1786.   p = template;
  1787.   putc ('\t', asm_out_file);
  1788.  
  1789. #ifdef ASM_OUTPUT_OPCODE
  1790.   ASM_OUTPUT_OPCODE (asm_out_file, p);
  1791. #endif
  1792.  
  1793.   while (c = *p++)
  1794.     {
  1795. #ifdef ASM_OUTPUT_OPCODE
  1796.       if (c == '\n')
  1797.     {
  1798.       putc (c, asm_out_file);
  1799.       while ((c = *p) == '\t')
  1800.         {
  1801.           putc (c, asm_out_file);
  1802.           p++;
  1803.         }
  1804.       ASM_OUTPUT_OPCODE (asm_out_file, p);
  1805.     }
  1806.       else
  1807. #endif
  1808.       if (c != '%')
  1809.     putc (c, asm_out_file);
  1810.       else
  1811.     {
  1812.       /* %% outputs a single %.  */
  1813.       if (*p == '%')
  1814.         {
  1815.           p++;
  1816.           putc (c, asm_out_file);
  1817.         }
  1818.       /* %= outputs a number which is unique to each insn in the entire
  1819.          compilation.  This is useful for making local labels that are
  1820.          referred to more than once in a given insn.  */
  1821.       else if (*p == '=')
  1822.         fprintf (asm_out_file, "%d", insn_counter);
  1823.       /* % followed by a letter and some digits
  1824.          outputs an operand in a special way depending on the letter.
  1825.          Letters `acln' are implemented directly.
  1826.          Other letters are passed to `output_operand' so that
  1827.          the PRINT_OPERAND macro can define them.  */
  1828.       else if ((*p >= 'a' && *p <= 'z')
  1829.            || (*p >= 'A' && *p <= 'Z'))
  1830.         {
  1831.           int letter = *p++;
  1832.           c = atoi (p);
  1833.  
  1834.           if (! (*p >= '0' && *p <= '9'))
  1835.         output_operand_lossage ("operand number missing after %-letter");
  1836.           else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
  1837.         output_operand_lossage ("operand number out of range");
  1838.           else if (letter == 'l')
  1839.         output_asm_label (operands[c]);
  1840.           else if (letter == 'a')
  1841.         output_address (operands[c]);
  1842.           else if (letter == 'c')
  1843.         {
  1844.           if (CONSTANT_ADDRESS_P (operands[c]))
  1845.             output_addr_const (asm_out_file, operands[c]);
  1846.           else
  1847.             output_operand (operands[c], 'c');
  1848.         }
  1849.           else if (letter == 'n')
  1850.         {
  1851.           if (GET_CODE (operands[c]) == CONST_INT)
  1852.             fprintf (asm_out_file, "%d", - INTVAL (operands[c]));
  1853.           else
  1854.             {
  1855.               putc ('-', asm_out_file);
  1856.               output_addr_const (asm_out_file, operands[c]);
  1857.             }
  1858.         }
  1859.           else
  1860.         output_operand (operands[c], letter);
  1861.  
  1862.           while ((c = *p) >= '0' && c <= '9') p++;
  1863.         }
  1864.       /* % followed by a digit outputs an operand the default way.  */
  1865.       else if (*p >= '0' && *p <= '9')
  1866.         {
  1867.           c = atoi (p);
  1868.           if (this_is_asm_operands && c >= (unsigned) insn_noperands)
  1869.         output_operand_lossage ("operand number out of range");
  1870.           else
  1871.         output_operand (operands[c], 0);
  1872.           while ((c = *p) >= '0' && c <= '9') p++;
  1873.         }
  1874.       /* % followed by punctuation: output something for that
  1875.          punctuation character alone, with no operand.
  1876.          The PRINT_OPERAND macro decides what is actually done.  */
  1877. #ifdef PRINT_OPERAND_PUNCT_VALID_P
  1878.       else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
  1879.         output_operand (0, *p++);
  1880. #endif
  1881.       else
  1882.         output_operand_lossage ("invalid %%-code");
  1883.     }
  1884.     }
  1885.  
  1886.   if (flag_print_asm_name)
  1887.     {
  1888.       /* Annotate the assembly with a comment describing the pattern and
  1889.      alternative used.  */
  1890.       if (debug_insn)
  1891.     {
  1892.       extern char * insn_name[];
  1893.       register int num = INSN_CODE (debug_insn);
  1894.       fprintf (asm_out_file, " %s %d %s", 
  1895.            ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
  1896.       if (insn_n_alternatives[num] > 1)
  1897.         fprintf (asm_out_file, "/%d", which_alternative + 1);
  1898.  
  1899.       /* Clear this so only the first assembler insn
  1900.          of any rtl insn will get the special comment for -dp.  */
  1901.       debug_insn = 0;
  1902.     }
  1903.     }
  1904.  
  1905.   putc ('\n', asm_out_file);
  1906. }
  1907.  
  1908. /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol.  */
  1909.  
  1910. void
  1911. output_asm_label (x)
  1912.      rtx x;
  1913. {
  1914.   char buf[256];
  1915.  
  1916.   if (GET_CODE (x) == LABEL_REF)
  1917.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
  1918.   else if (GET_CODE (x) == CODE_LABEL)
  1919.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  1920.   else
  1921.     output_operand_lossage ("`%l' operand isn't a label");
  1922.  
  1923.   assemble_name (asm_out_file, buf);
  1924. }
  1925.  
  1926. /* Print operand X using machine-dependent assembler syntax.
  1927.    The macro PRINT_OPERAND is defined just to control this function.
  1928.    CODE is a non-digit that preceded the operand-number in the % spec,
  1929.    such as 'z' if the spec was `%z3'.  CODE is 0 if there was no char
  1930.    between the % and the digits.
  1931.    When CODE is a non-letter, X is 0.
  1932.  
  1933.    The meanings of the letters are machine-dependent and controlled
  1934.    by PRINT_OPERAND.  */
  1935.  
  1936. static void
  1937. output_operand (x, code)
  1938.      rtx x;
  1939.      int code;
  1940. {
  1941.   if (x && GET_CODE (x) == SUBREG)
  1942.     x = alter_subreg (x);
  1943.   PRINT_OPERAND (asm_out_file, x, code);
  1944. }
  1945.  
  1946. /* Print a memory reference operand for address X
  1947.    using machine-dependent assembler syntax.
  1948.    The macro PRINT_OPERAND_ADDRESS exists just to control this function.  */
  1949.  
  1950. void
  1951. output_address (x)
  1952.      rtx x;
  1953. {
  1954.   walk_alter_subreg (x);
  1955.   PRINT_OPERAND_ADDRESS (asm_out_file, x);
  1956. }
  1957.  
  1958. /* Print an integer constant expression in assembler syntax.
  1959.    Addition and subtraction are the only arithmetic
  1960.    that may appear in these expressions.  */
  1961.  
  1962. void
  1963. output_addr_const (file, x)
  1964.      FILE *file;
  1965.      rtx x;
  1966. {
  1967.   char buf[256];
  1968.  
  1969.  restart:
  1970.   switch (GET_CODE (x))
  1971.     {
  1972.     case PC:
  1973.       if (flag_pic)
  1974.     putc ('.', file);
  1975.       else
  1976.     abort ();
  1977.       break;
  1978.  
  1979.     case SYMBOL_REF:
  1980.       assemble_name (file, XSTR (x, 0));
  1981.       break;
  1982.  
  1983.     case LABEL_REF:
  1984.       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
  1985.       assemble_name (asm_out_file, buf);
  1986.       break;
  1987.  
  1988.     case CODE_LABEL:
  1989.       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  1990.       assemble_name (asm_out_file, buf);
  1991.       break;
  1992.  
  1993.     case CONST_INT:
  1994.       fprintf (file, "%d", INTVAL (x));
  1995.       break;
  1996.  
  1997.     case CONST:
  1998.       /* This used to output parentheses around the expression,
  1999.      but that does not work on the 386 (either ATT or BSD assembler).  */
  2000.       output_addr_const (file, XEXP (x, 0));
  2001.       break;
  2002.  
  2003.     case CONST_DOUBLE:
  2004.       if (GET_MODE (x) == VOIDmode)
  2005.     {
  2006.       /* We can use %d if the number is <32 bits and positive.  */
  2007.       if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
  2008.         fprintf (file, "0x%x%08x",
  2009.              CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
  2010.       else
  2011.         fprintf (file, "%d", CONST_DOUBLE_LOW (x));
  2012.     }
  2013.       else
  2014.     /* We can't handle floating point constants;
  2015.        PRINT_OPERAND must handle them.  */
  2016.     output_operand_lossage ("floating constant misused");
  2017.       break;
  2018.  
  2019.     case PLUS:
  2020.       /* Some assemblers need integer constants to appear last (eg masm).  */
  2021.       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
  2022.     {
  2023.       output_addr_const (file, XEXP (x, 1));
  2024.       if (INTVAL (XEXP (x, 0)) >= 0)
  2025.         fprintf (file, "+");
  2026.       output_addr_const (file, XEXP (x, 0));
  2027.     }
  2028.       else
  2029.     {
  2030.       output_addr_const (file, XEXP (x, 0));
  2031.       if (INTVAL (XEXP (x, 1)) >= 0)
  2032.         fprintf (file, "+");
  2033.       output_addr_const (file, XEXP (x, 1));
  2034.     }
  2035.       break;
  2036.  
  2037.     case MINUS:
  2038.       output_addr_const (file, XEXP (x, 0));
  2039.       fprintf (file, "-");
  2040.       output_addr_const (file, XEXP (x, 1));
  2041.       break;
  2042.  
  2043.     default:
  2044.       output_operand_lossage ("invalid expression as operand");
  2045.     }
  2046. }
  2047.  
  2048. /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
  2049.    %R prints the value of REGISTER_PREFIX.
  2050.    %L prints the value of LOCAL_LABEL_PREFIX.
  2051.    %U prints the value of USER_LABEL_PREFIX.
  2052.    %I prints the value of IMMEDIATE_PREFIX.
  2053.    Also supported are %d, %x, %s, %e, %f, %g and %%.  */
  2054.  
  2055. void
  2056. asm_fprintf (va_alist)
  2057.      va_dcl
  2058. {
  2059.   register va_list argptr;
  2060.   FILE *file;
  2061.   char buf[10];
  2062.   char *p, *q, c;
  2063.  
  2064.   va_start (argptr);
  2065.  
  2066.   file = va_arg (argptr, FILE *);
  2067.   p = va_arg (argptr, char *);
  2068.   buf[0] = '%';
  2069.  
  2070.   while (c = *p++)
  2071.     switch (c)
  2072.       {
  2073.       case '%':
  2074.     c = *p++;
  2075.     q = &buf[1];
  2076.     while ((c >= '0' && c <= '9') || c == '.')
  2077.       {
  2078.         *q++ = c;
  2079.         c = *p++;
  2080.       }
  2081.     switch (c)
  2082.       {
  2083.       case '%':
  2084.         fprintf (file, "%%");
  2085.         break;
  2086.  
  2087.       case 'd':  case 'i':  case 'u':
  2088.       case 'x':  case 'p':  case 'X':
  2089.       case 'o':
  2090.         *q++ = c;
  2091.         *q = 0;
  2092.         fprintf (file, buf, va_arg (argptr, int));
  2093.         break;
  2094.  
  2095.       case 'e':
  2096.       case 'f':
  2097.       case 'g':
  2098.         *q++ = c;
  2099.         *q = 0;
  2100.         fprintf (file, buf, va_arg (argptr, double));
  2101.         break;
  2102.  
  2103.       case 's':
  2104.         *q++ = c;
  2105.         *q = 0;
  2106.         fprintf (file, buf, va_arg (argptr, char *));
  2107.         break;
  2108.  
  2109.       case 'R':
  2110. #ifdef REGISTER_PREFIX
  2111.         fprintf (file, "%s", REGISTER_PREFIX);
  2112. #endif
  2113.         break;
  2114.  
  2115.       case 'I':
  2116. #ifdef IMMEDIATE_PREFIX
  2117.         fprintf (file, "%s", IMMEDIATE_PREFIX);
  2118. #endif
  2119.         break;
  2120.  
  2121.       case 'L':
  2122. #ifdef LOCAL_LABEL_PREFIX
  2123.         fprintf (file, "%s", LOCAL_LABEL_PREFIX);
  2124. #endif
  2125.         break;
  2126.  
  2127.       case 'U':
  2128. #ifdef USER_LABEL_PREFIX
  2129.         fprintf (file, "%s", USER_LABEL_PREFIX);
  2130. #endif
  2131.         break;
  2132.  
  2133.       default:
  2134.         abort ();
  2135.       }
  2136.     break;
  2137.  
  2138.       default:
  2139.     fputc (c, file);
  2140.       }
  2141. }
  2142.  
  2143. /* Split up a CONST_DOUBLE or integer constant rtx
  2144.    into two rtx's for single words,
  2145.    storing in *FIRST the word that comes first in memory in the target
  2146.    and in *SECOND the other.  */
  2147.  
  2148. void
  2149. split_double (value, first, second)
  2150.      rtx value;
  2151.      rtx *first, *second;
  2152. {
  2153.   if (GET_CODE (value) == CONST_INT)
  2154.     {
  2155.       /* The rule for using CONST_INT for a wider mode
  2156.      is that we regard the value as signed.
  2157.      So sign-extend it.  */
  2158.       rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
  2159. #if WORDS_BIG_ENDIAN
  2160.       *first = high;
  2161.       *second = value;
  2162. #else
  2163.       *first = value;
  2164.       *second = high;
  2165. #endif
  2166.     }
  2167.   else if (GET_CODE (value) != CONST_DOUBLE)
  2168.     {
  2169. #if WORDS_BIG_ENDIAN
  2170.       *first = const0_rtx;
  2171.       *second = value;
  2172. #else
  2173.       *first = value;
  2174.       *second = const0_rtx;
  2175. #endif
  2176.     }
  2177.   else if (GET_MODE (value) == VOIDmode
  2178.        /* This is the old way we did CONST_DOUBLE integers.  */
  2179.        || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
  2180.     {
  2181.       /* In an integer, the words are defined as most and least significant.
  2182.      So order them by the target's convention.  */
  2183. #if WORDS_BIG_ENDIAN
  2184.       *first = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_HIGH (value));
  2185.       *second = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_LOW (value));
  2186. #else
  2187.       *first = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_LOW (value));
  2188.       *second = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_HIGH (value));
  2189. #endif
  2190.     }
  2191.   else
  2192.     {
  2193.       if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
  2194.        || HOST_BITS_PER_INT != BITS_PER_WORD)
  2195.       && ! flag_pretend_float)
  2196.       abort ();
  2197.  
  2198. #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
  2199.       /* Host and target agree => no need to swap.  */
  2200.       *first = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_LOW (value));
  2201.       *second = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_HIGH (value));
  2202. #else
  2203.       *second = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_LOW (value));
  2204.       *first = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_HIGH (value));
  2205. #endif
  2206.     }
  2207. }
  2208.  
  2209. /* Return nonzero if this function has no function calls.  */
  2210.  
  2211. int
  2212. leaf_function_p ()
  2213. {
  2214.   rtx insn;
  2215.  
  2216.   if (profile_flag || profile_block_flag)
  2217.     return 0;
  2218.  
  2219.   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  2220.     {
  2221.       if (GET_CODE (insn) == CALL_INSN)
  2222.     return 0;
  2223.       if (GET_CODE (insn) == INSN
  2224.       && GET_CODE (PATTERN (insn)) == SEQUENCE
  2225.       && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN)
  2226.     return 0;
  2227.     }
  2228.   for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
  2229.     {
  2230.       if (GET_CODE (XEXP (insn, 0)) == CALL_INSN)
  2231.     return 0;
  2232.       if (GET_CODE (XEXP (insn, 0)) == INSN
  2233.       && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
  2234.       && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN)
  2235.     return 0;
  2236.     }
  2237.  
  2238.   /* Find out the liar later.  */
  2239.   if (frame_pointer_needed)
  2240.     {
  2241.       abort ();
  2242.       regs_ever_live[FRAME_POINTER_REGNUM] = 1;
  2243.       return 0;
  2244.     }
  2245.  
  2246.   return 1;
  2247. }
  2248.  
  2249. /* On some machines, a function with no call insns
  2250.    can run faster if it doesn't create its own register window.
  2251.    When output, the leaf function should use only the "output"
  2252.    registers.  Ordinarily, the function would be compiled to use
  2253.    the "input" registers to find its arguments; it is a candidate
  2254.    for leaf treatment if it uses only the "input" registers.
  2255.    Leaf function treatment means renumbering so the function
  2256.    uses the "output" registers instead.  */
  2257.  
  2258. #ifdef LEAF_REGISTERS
  2259.  
  2260. static char permitted_reg_in_leaf_functions[] = LEAF_REGISTERS;
  2261.  
  2262. /* Return 1 if this function uses only the registers that can be
  2263.    safely renumbered.  */
  2264.  
  2265. int
  2266. only_leaf_regs_used ()
  2267. {
  2268.   int i;
  2269.  
  2270.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2271.     {
  2272.       if (regs_ever_live[i] > permitted_reg_in_leaf_functions[i])
  2273.     return 0;
  2274.     }
  2275.   return 1;
  2276. }
  2277.  
  2278. /* Scan all instructions and renumber all registers into those
  2279.    available in leaf functions.  */
  2280.  
  2281. static void
  2282. leaf_renumber_regs (first)
  2283.      rtx first;
  2284. {
  2285.   rtx insn;
  2286.  
  2287.   for (insn = first; insn; insn = NEXT_INSN (insn))
  2288.     leaf_renumber_regs_insn (insn);
  2289.   for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
  2290.     leaf_renumber_regs_insn (XEXP (insn, 0));
  2291. }
  2292.  
  2293. /* Scan IN_RTX and its subexpressions, and renumber all regs into those
  2294.    available in leaf functions.  */
  2295.  
  2296. static void
  2297. leaf_renumber_regs_insn (in_rtx)
  2298.      register rtx in_rtx;
  2299. {
  2300.   register int i, j;
  2301.   register char *format_ptr;
  2302.  
  2303.   if (in_rtx == 0)
  2304.     return;
  2305.  
  2306.   /* Renumber all input-registers into output-registers.
  2307.      renumbered_regs would be 1 for an output-register;
  2308.      they  */
  2309.  
  2310.   if (GET_CODE (in_rtx) == REG)
  2311.     {
  2312.       int newreg;
  2313.  
  2314.       /* Don't renumber the same reg twice.  */
  2315.       if (in_rtx->used)
  2316.     return;
  2317.  
  2318.       newreg = LEAF_REG_REMAP (REGNO (in_rtx));
  2319.       if (newreg < 0)
  2320.     abort ();
  2321.       regs_ever_live[REGNO (in_rtx)] = 0;
  2322.       regs_ever_live[newreg] = 1;
  2323.       REGNO (in_rtx) = newreg;
  2324.       in_rtx->used = 1;
  2325.     }
  2326.  
  2327.   format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
  2328.  
  2329.   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
  2330.     switch (*format_ptr++)
  2331.       {
  2332.       case 'e':
  2333.     leaf_renumber_regs_insn (XEXP (in_rtx, i));
  2334.     break;
  2335.  
  2336.       case 'E':
  2337.     if (NULL != XVEC (in_rtx, i))
  2338.       {
  2339.         for (j = 0; j < XVECLEN (in_rtx, i); j++)
  2340.           leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
  2341.       }
  2342.     break;
  2343.  
  2344.       case 'S':
  2345.       case 's':
  2346.       case '0':
  2347.       case 'i':
  2348.       case 'n':
  2349.       case 'u':
  2350.     break;
  2351.  
  2352.       default:
  2353.     abort ();
  2354.       }
  2355. }
  2356. #endif
  2357.