OSDN Git Service

(mips_move_2words): Rewrite 32 bit shifts as 16 bit shifts.
[pf3gnuchains/gcc-fork.git] / gcc / final.c
1 /* Convert RTL to assembler code and output it, for GNU compiler.
2    Copyright (C) 1987, 88, 89, 92-5, 1996 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21
22 /* This is the final pass of the compiler.
23    It looks at the rtl code for a function and outputs assembler code.
24
25    Call `final_start_function' to output the assembler code for function entry,
26    `final' to output assembler code for some RTL code,
27    `final_end_function' to output assembler code for function exit.
28    If a function is compiled in several pieces, each piece is
29    output separately with `final'.
30
31    Some optimizations are also done at this level.
32    Move instructions that were made unnecessary by good register allocation
33    are detected and omitted from the output.  (Though most of these
34    are removed by the last jump pass.)
35
36    Instructions to set the condition codes are omitted when it can be
37    seen that the condition codes already had the desired values.
38
39    In some cases it is sufficient if the inherited condition codes
40    have related values, but this may require the following insn
41    (the one that tests the condition codes) to be modified.
42
43    The code for the function prologue and epilogue are generated
44    directly as assembler code by the macros FUNCTION_PROLOGUE and
45    FUNCTION_EPILOGUE.  Those instructions never exist as rtl.  */
46
47 #include "config.h"
48 #ifdef __STDC__
49 #include <stdarg.h>
50 #else
51 #include <varargs.h>
52 #endif
53 #include <stdio.h>
54 #include <ctype.h>
55
56 #include "tree.h"
57 #include "rtl.h"
58 #include "regs.h"
59 #include "insn-config.h"
60 #include "insn-flags.h"
61 #include "insn-attr.h"
62 #include "insn-codes.h"
63 #include "recog.h"
64 #include "conditions.h"
65 #include "flags.h"
66 #include "real.h"
67 #include "hard-reg-set.h"
68 #include "defaults.h"
69 #include "output.h"
70 #include "except.h"
71
72 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist.  */
73 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
74 #if defined (USG) || defined (NO_STAB_H)
75 #include "gstab.h"  /* If doing DBX on sysV, use our own stab.h.  */
76 #else
77 #include <stab.h>  /* On BSD, use the system's stab.h.  */
78 #endif /* not USG */
79 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
80
81 #ifdef XCOFF_DEBUGGING_INFO
82 #include "xcoffout.h"
83 #endif
84
85 /* .stabd code for line number.  */
86 #ifndef N_SLINE
87 #define N_SLINE 0x44
88 #endif
89
90 /* .stabs code for included file name.  */
91 #ifndef N_SOL
92 #define N_SOL 0x84
93 #endif
94
95 #ifndef INT_TYPE_SIZE
96 #define INT_TYPE_SIZE BITS_PER_WORD
97 #endif
98
99 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist.  So define a
100    null default for it to save conditionalization later.  */
101 #ifndef CC_STATUS_INIT
102 #define CC_STATUS_INIT
103 #endif
104
105 /* How to start an assembler comment.  */
106 #ifndef ASM_COMMENT_START
107 #define ASM_COMMENT_START ";#"
108 #endif
109
110 /* Is the given character a logical line separator for the assembler?  */
111 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
112 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
113 #endif
114
115 /* Nonzero means this function is a leaf function, with no function calls. 
116    This variable exists to be examined in FUNCTION_PROLOGUE
117    and FUNCTION_EPILOGUE.  Always zero, unless set by some action.  */
118 int leaf_function;
119
120 /* Last insn processed by final_scan_insn.  */
121 static rtx debug_insn = 0;
122
123 /* Line number of last NOTE.  */
124 static int last_linenum;
125
126 /* Highest line number in current block.  */
127 static int high_block_linenum;
128
129 /* Likewise for function.  */
130 static int high_function_linenum;
131
132 /* Filename of last NOTE.  */
133 static char *last_filename;
134
135 /* Number of basic blocks seen so far;
136    used if profile_block_flag is set.  */
137 static int count_basic_blocks;
138
139 /* Nonzero while outputting an `asm' with operands.
140    This means that inconsistencies are the user's fault, so don't abort.
141    The precise value is the insn being output, to pass to error_for_asm.  */
142 static rtx this_is_asm_operands;
143
144 /* Number of operands of this insn, for an `asm' with operands.  */
145 static int insn_noperands;
146
147 /* Compare optimization flag.  */
148
149 static rtx last_ignored_compare = 0;
150
151 /* Flag indicating this insn is the start of a new basic block.  */
152
153 static int new_block = 1;
154
155 /* All the symbol-blocks (levels of scoping) in the compilation
156    are assigned sequence numbers in order of appearance of the
157    beginnings of the symbol-blocks.  Both final and dbxout do this,
158    and assume that they will both give the same number to each block.
159    Final uses these sequence numbers to generate assembler label names
160    LBBnnn and LBEnnn for the beginning and end of the symbol-block.
161    Dbxout uses the sequence numbers to generate references to the same labels
162    from the dbx debugging information.
163
164    Sdb records this level at the beginning of each function,
165    in order to find the current level when recursing down declarations.
166    It outputs the block beginning and endings
167    at the point in the asm file where the blocks would begin and end.  */
168
169 int next_block_index;
170
171 /* Assign a unique number to each insn that is output.
172    This can be used to generate unique local labels.  */
173
174 static int insn_counter = 0;
175
176 #ifdef HAVE_cc0
177 /* This variable contains machine-dependent flags (defined in tm.h)
178    set and examined by output routines
179    that describe how to interpret the condition codes properly.  */
180
181 CC_STATUS cc_status;
182
183 /* During output of an insn, this contains a copy of cc_status
184    from before the insn.  */
185
186 CC_STATUS cc_prev_status;
187 #endif
188
189 /* Indexed by hardware reg number, is 1 if that register is ever
190    used in the current function.
191
192    In life_analysis, or in stupid_life_analysis, this is set
193    up to record the hard regs used explicitly.  Reload adds
194    in the hard regs used for holding pseudo regs.  Final uses
195    it to generate the code in the function prologue and epilogue
196    to save and restore registers as needed.  */
197
198 char regs_ever_live[FIRST_PSEUDO_REGISTER];
199
200 /* Nonzero means current function must be given a frame pointer.
201    Set in stmt.c if anything is allocated on the stack there.
202    Set in reload1.c if anything is allocated on the stack there.  */
203
204 int frame_pointer_needed;
205
206 /* Assign unique numbers to labels generated for profiling.  */
207
208 int profile_label_no;
209
210 /* Length so far allocated in PENDING_BLOCKS.  */
211
212 static int max_block_depth;
213
214 /* Stack of sequence numbers of symbol-blocks of which we have seen the
215    beginning but not yet the end.  Sequence numbers are assigned at
216    the beginning; this stack allows us to find the sequence number
217    of a block that is ending.  */
218
219 static int *pending_blocks;
220
221 /* Number of elements currently in use in PENDING_BLOCKS.  */
222
223 static int block_depth;
224
225 /* Nonzero if have enabled APP processing of our assembler output.  */
226
227 static int app_on;
228
229 /* If we are outputting an insn sequence, this contains the sequence rtx.
230    Zero otherwise.  */
231
232 rtx final_sequence;
233
234 #ifdef ASSEMBLER_DIALECT
235
236 /* Number of the assembler dialect to use, starting at 0.  */
237 static int dialect_number;
238 #endif
239
240 /* Indexed by line number, nonzero if there is a note for that line.  */
241
242 static char *line_note_exists;
243
244 /* Linked list to hold line numbers for each basic block.  */
245
246 struct bb_list {
247   struct bb_list *next;         /* pointer to next basic block */
248   int line_num;                 /* line number */
249   int file_label_num;           /* LPBC<n> label # for stored filename */
250   int func_label_num;           /* LPBC<n> label # for stored function name */
251 };
252
253 static struct bb_list *bb_head  = 0;            /* Head of basic block list */
254 static struct bb_list **bb_tail = &bb_head;     /* Ptr to store next bb ptr */
255 static int bb_file_label_num    = -1;           /* Current label # for file */
256 static int bb_func_label_num    = -1;           /* Current label # for func */
257
258 /* Linked list to hold the strings for each file and function name output.  */
259
260 struct bb_str {
261   struct bb_str *next;          /* pointer to next string */
262   char *string;                 /* string */
263   int label_num;                /* label number */
264   int length;                   /* string length */
265 };
266
267 extern rtx peephole             PROTO((rtx));
268
269 static struct bb_str *sbb_head  = 0;            /* Head of string list.  */
270 static struct bb_str **sbb_tail = &sbb_head;    /* Ptr to store next bb str */
271 static int sbb_label_num        = 0;            /* Last label used */
272
273 static int asm_insn_count       PROTO((rtx));
274 static void profile_function    PROTO((FILE *));
275 static void profile_after_prologue PROTO((FILE *));
276 static void add_bb              PROTO((FILE *));
277 static int add_bb_string        PROTO((char *, int));
278 static void output_source_line  PROTO((FILE *, rtx));
279 static rtx walk_alter_subreg    PROTO((rtx));
280 static int alter_cond           PROTO((rtx));
281 static void output_asm_name     PROTO((void));
282 static void output_operand      PROTO((rtx, int));
283 static void leaf_renumber_regs  PROTO((rtx));
284
285 extern char *getpwd ();
286 \f
287 /* Initialize data in final at the beginning of a compilation.  */
288
289 void
290 init_final (filename)
291      char *filename;
292 {
293   next_block_index = 2;
294   app_on = 0;
295   max_block_depth = 20;
296   pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
297   final_sequence = 0;
298
299 #ifdef ASSEMBLER_DIALECT
300   dialect_number = ASSEMBLER_DIALECT;
301 #endif
302 }
303
304 /* Called at end of source file,
305    to output the block-profiling table for this entire compilation.  */
306
307 void
308 end_final (filename)
309      char *filename;
310 {
311   int i;
312
313   if (profile_block_flag)
314     {
315       char name[20];
316       int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
317       int size = (POINTER_SIZE / BITS_PER_UNIT) * count_basic_blocks;
318       int rounded = size;
319       struct bb_list *ptr;
320       struct bb_str *sptr;
321
322       rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
323       rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
324                  * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
325
326       data_section ();
327
328       /* Output the main header, of 11 words:
329          0:  1 if this file is initialized, else 0.
330          1:  address of file name (LPBX1).
331          2:  address of table of counts (LPBX2).
332          3:  number of counts in the table.
333          4:  always 0, for compatibility with Sun.
334
335          The following are GNU extensions:
336
337          5:  address of table of start addrs of basic blocks (LPBX3).
338          6:  Number of bytes in this header.
339          7:  address of table of function names (LPBX4).
340          8:  address of table of line numbers (LPBX5) or 0.
341          9:  address of table of file names (LPBX6) or 0.
342         10:  space reserved for basic block profiling.  */
343
344       ASM_OUTPUT_ALIGN (asm_out_file, align);
345
346       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
347       /* zero word */
348       assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
349
350       /* address of filename */
351       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
352       assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
353
354       /* address of count table */
355       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
356       assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
357
358       /* count of the # of basic blocks */
359       assemble_integer (GEN_INT (count_basic_blocks), UNITS_PER_WORD, 1);
360
361       /* zero word (link field) */
362       assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
363
364       /* address of basic block start address table */
365       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
366       assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
367
368       /* byte count for extended structure.  */
369       assemble_integer (GEN_INT (11 * UNITS_PER_WORD), UNITS_PER_WORD, 1);
370
371       /* address of function name table */
372       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
373       assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
374
375       /* address of line number and filename tables if debugging.  */
376       if (write_symbols != NO_DEBUG)
377         {
378           ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
379           assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
380           ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
381           assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
382         }
383       else
384         {
385           assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
386           assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
387         }
388
389       /* space for extension ptr (link field) */
390       assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
391
392       /* Output the file name changing the suffix to .d for Sun tcov
393          compatibility.  */
394       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
395       {
396         char *cwd = getpwd ();
397         int len = strlen (filename) + strlen (cwd) + 1;
398         char *data_file = (char *) alloca (len + 4);
399
400         strcpy (data_file, cwd);
401         strcat (data_file, "/");
402         strcat (data_file, filename);
403         strip_off_ending (data_file, len);
404         strcat (data_file, ".d");
405         assemble_string (data_file, strlen (data_file) + 1);
406       }
407
408       /* Make space for the table of counts.  */
409       if (size == 0)
410         {
411           /* Realign data section.  */
412           ASM_OUTPUT_ALIGN (asm_out_file, align);
413           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
414           if (size != 0)
415             assemble_zeros (size);
416         }
417       else
418         {
419           ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
420 #ifdef ASM_OUTPUT_SHARED_LOCAL
421           if (flag_shared_data)
422             ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
423           else
424 #endif
425 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
426             ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
427                                       BIGGEST_ALIGNMENT);
428 #else
429             ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
430 #endif
431         }
432
433       /* Output any basic block strings */
434       readonly_data_section ();
435       if (sbb_head)
436         {
437           ASM_OUTPUT_ALIGN (asm_out_file, align);
438           for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
439             {
440               ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC", sptr->label_num);
441               assemble_string (sptr->string, sptr->length);
442             }
443         }
444
445       /* Output the table of addresses.  */
446       /* Realign in new section */
447       ASM_OUTPUT_ALIGN (asm_out_file, align);
448       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
449       for (i = 0; i < count_basic_blocks; i++)
450         {
451           ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
452           assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
453                             UNITS_PER_WORD, 1);
454         }
455
456       /* Output the table of function names.  */
457       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
458       for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
459         {
460           if (ptr->func_label_num >= 0)
461             {
462               ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->func_label_num);
463               assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
464                                 UNITS_PER_WORD, 1);
465             }
466           else
467             assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
468         }
469
470       for ( ; i < count_basic_blocks; i++)
471         assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
472
473       if (write_symbols != NO_DEBUG)
474         {
475           /* Output the table of line numbers.  */
476           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
477           for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
478             assemble_integer (GEN_INT (ptr->line_num), UNITS_PER_WORD, 1);
479
480           for ( ; i < count_basic_blocks; i++)
481             assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
482
483           /* Output the table of file names.  */
484           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
485           for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
486             {
487               if (ptr->file_label_num >= 0)
488                 {
489                   ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->file_label_num);
490                   assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
491                                     UNITS_PER_WORD, 1);
492                 }
493               else
494                 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
495             }
496
497           for ( ; i < count_basic_blocks; i++)
498             assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
499         }
500
501       /* End with the address of the table of addresses,
502          so we can find it easily, as the last word in the file's text.  */
503       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
504       assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
505     }
506 }
507
508 /* Enable APP processing of subsequent output.
509    Used before the output from an `asm' statement.  */
510
511 void
512 app_enable ()
513 {
514   if (! app_on)
515     {
516       fprintf (asm_out_file, ASM_APP_ON);
517       app_on = 1;
518     }
519 }
520
521 /* Disable APP processing of subsequent output.
522    Called from varasm.c before most kinds of output.  */
523
524 void
525 app_disable ()
526 {
527   if (app_on)
528     {
529       fprintf (asm_out_file, ASM_APP_OFF);
530       app_on = 0;
531     }
532 }
533 \f
534 /* Return the number of slots filled in the current 
535    delayed branch sequence (we don't count the insn needing the
536    delay slot).   Zero if not in a delayed branch sequence.  */
537
538 #ifdef DELAY_SLOTS
539 int
540 dbr_sequence_length ()
541 {
542   if (final_sequence != 0)
543     return XVECLEN (final_sequence, 0) - 1;
544   else
545     return 0;
546 }
547 #endif
548 \f
549 /* The next two pages contain routines used to compute the length of an insn
550    and to shorten branches.  */
551
552 /* Arrays for insn lengths, and addresses.  The latter is referenced by
553    `insn_current_length'.  */
554
555 static short *insn_lengths;
556 int *insn_addresses;
557
558 /* Address of insn being processed.  Used by `insn_current_length'.  */
559 int insn_current_address;
560
561 /* Indicate that branch shortening hasn't yet been done.  */
562
563 void
564 init_insn_lengths ()
565 {
566   insn_lengths = 0;
567 }
568
569 /* Obtain the current length of an insn.  If branch shortening has been done,
570    get its actual length.  Otherwise, get its maximum length.  */
571
572 int
573 get_attr_length (insn)
574      rtx insn;
575 {
576 #ifdef HAVE_ATTR_length
577   rtx body;
578   int i;
579   int length = 0;
580
581   if (insn_lengths)
582     return insn_lengths[INSN_UID (insn)];
583   else
584     switch (GET_CODE (insn))
585       {
586       case NOTE:
587       case BARRIER:
588       case CODE_LABEL:
589         return 0;
590
591       case CALL_INSN:
592         length = insn_default_length (insn);
593         break;
594
595       case JUMP_INSN:
596         body = PATTERN (insn);
597         if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
598           {
599             /* This only takes room if jump tables go into the text section.  */
600 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
601             length = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
602                       * GET_MODE_SIZE (GET_MODE (body)));
603
604             /* Be pessimistic and assume worst-case alignment.  */
605             length += (GET_MODE_SIZE (GET_MODE (body)) - 1);
606 #else
607             return 0;
608 #endif
609           }
610         else
611           length = insn_default_length (insn);
612         break;
613
614       case INSN:
615         body = PATTERN (insn);
616         if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
617           return 0;
618
619         else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
620           length = asm_insn_count (body) * insn_default_length (insn);
621         else if (GET_CODE (body) == SEQUENCE)
622           for (i = 0; i < XVECLEN (body, 0); i++)
623             length += get_attr_length (XVECEXP (body, 0, i));
624         else
625           length = insn_default_length (insn);
626       }
627
628 #ifdef ADJUST_INSN_LENGTH
629   ADJUST_INSN_LENGTH (insn, length);
630 #endif
631   return length;
632 #else /* not HAVE_ATTR_length */
633   return 0;
634 #endif /* not HAVE_ATTR_length */
635 }
636 \f
637 /* Make a pass over all insns and compute their actual lengths by shortening
638    any branches of variable length if possible.  */
639
640 /* Give a default value for the lowest address in a function.  */
641
642 #ifndef FIRST_INSN_ADDRESS
643 #define FIRST_INSN_ADDRESS 0
644 #endif
645
646 void
647 shorten_branches (first)
648      rtx first;
649 {
650 #ifdef HAVE_ATTR_length
651   rtx insn;
652   int something_changed = 1;
653   int max_uid = 0;
654   char *varying_length;
655   rtx body;
656   int uid;
657
658   /* Compute maximum UID and allocate arrays.  */
659   for (insn = first; insn; insn = NEXT_INSN (insn))
660     if (INSN_UID (insn) > max_uid)
661       max_uid = INSN_UID (insn);
662
663   max_uid++;
664   insn_lengths = (short *) oballoc (max_uid * sizeof (short));
665   insn_addresses = (int *) oballoc (max_uid * sizeof (int));
666   varying_length = (char *) oballoc (max_uid * sizeof (char));
667
668   /* Compute initial lengths, addresses, and varying flags for each insn.  */
669   for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
670        insn != 0;
671        insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
672     {
673       uid = INSN_UID (insn);
674       insn_addresses[uid] = insn_current_address;
675       insn_lengths[uid] = 0;
676       varying_length[uid] = 0;
677       
678       if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
679           || GET_CODE (insn) == CODE_LABEL)
680         continue;
681
682       body = PATTERN (insn);
683       if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
684         {
685           /* This only takes room if read-only data goes into the text
686              section.  */
687 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
688           int unitsize = GET_MODE_SIZE (GET_MODE (body));
689
690           insn_lengths[uid] = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
691                                * GET_MODE_SIZE (GET_MODE (body)));
692
693           /* Account for possible alignment.  */
694           insn_lengths[uid]
695             += unitsize - (insn_current_address & (unitsize - 1));
696 #else
697           ;
698 #endif
699         }
700       else if (asm_noperands (body) >= 0)
701         insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
702       else if (GET_CODE (body) == SEQUENCE)
703         {
704           int i;
705           int const_delay_slots;
706 #ifdef DELAY_SLOTS
707           const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
708 #else
709           const_delay_slots = 0;
710 #endif
711           /* Inside a delay slot sequence, we do not do any branch shortening
712              if the shortening could change the number of delay slots
713              of the branch.  */
714           for (i = 0; i < XVECLEN (body, 0); i++)
715             {
716               rtx inner_insn = XVECEXP (body, 0, i);
717               int inner_uid = INSN_UID (inner_insn);
718               int inner_length;
719
720               if (asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
721                 inner_length = (asm_insn_count (PATTERN (inner_insn))
722                                 * insn_default_length (inner_insn));
723               else
724                 inner_length = insn_default_length (inner_insn);
725               
726               insn_lengths[inner_uid] = inner_length;
727               if (const_delay_slots)
728                 {
729                   if ((varying_length[inner_uid]
730                        = insn_variable_length_p (inner_insn)) != 0)
731                     varying_length[uid] = 1;
732                   insn_addresses[inner_uid] = (insn_current_address +
733                                                insn_lengths[uid]);
734                 }
735               else
736                 varying_length[inner_uid] = 0;
737               insn_lengths[uid] += inner_length;
738             }
739         }
740       else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
741         {
742           insn_lengths[uid] = insn_default_length (insn);
743           varying_length[uid] = insn_variable_length_p (insn);
744         }
745
746       /* If needed, do any adjustment.  */
747 #ifdef ADJUST_INSN_LENGTH
748       ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
749 #endif
750     }
751
752   /* Now loop over all the insns finding varying length insns.  For each,
753      get the current insn length.  If it has changed, reflect the change.
754      When nothing changes for a full pass, we are done.  */
755
756   while (something_changed)
757     {
758       something_changed = 0;
759       for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
760            insn != 0;
761            insn = NEXT_INSN (insn))
762         {
763           int new_length;
764           int tmp_length;
765
766           uid = INSN_UID (insn);
767           insn_addresses[uid] = insn_current_address;
768           if (! varying_length[uid])
769             {
770               insn_current_address += insn_lengths[uid];
771               continue;
772             }
773           if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
774             {
775               int i;
776               
777               body = PATTERN (insn);
778               new_length = 0;
779               for (i = 0; i < XVECLEN (body, 0); i++)
780                 {
781                   rtx inner_insn = XVECEXP (body, 0, i);
782                   int inner_uid = INSN_UID (inner_insn);
783                   int inner_length;
784
785                   insn_addresses[inner_uid] = insn_current_address;
786
787                   /* insn_current_length returns 0 for insns with a
788                      non-varying length.  */
789                   if (! varying_length[inner_uid])
790                     inner_length = insn_lengths[inner_uid];
791                   else
792                     inner_length = insn_current_length (inner_insn);
793
794                   if (inner_length != insn_lengths[inner_uid])
795                     {
796                       insn_lengths[inner_uid] = inner_length;
797                       something_changed = 1;
798                     }
799                   insn_current_address += insn_lengths[inner_uid];
800                   new_length += inner_length;
801                 }
802             }
803           else
804             {
805               new_length = insn_current_length (insn);
806               insn_current_address += new_length;
807             }
808
809 #ifdef SHORTEN_WITH_ADJUST_INSN_LENGTH
810 #ifdef ADJUST_INSN_LENGTH
811           /* If needed, do any adjustment.  */
812           tmp_length = new_length;
813           ADJUST_INSN_LENGTH (insn, new_length);
814           insn_current_address += (new_length - tmp_length);
815 #endif
816 #endif
817
818           if (new_length != insn_lengths[uid])
819             {
820               insn_lengths[uid] = new_length;
821               something_changed = 1;
822             }
823         }
824       /* For a non-optimizing compile, do only a single pass.  */
825       if (!optimize)
826         break;
827     }
828 #endif /* HAVE_ATTR_length */
829 }
830
831 #ifdef HAVE_ATTR_length
832 /* Given the body of an INSN known to be generated by an ASM statement, return
833    the number of machine instructions likely to be generated for this insn.
834    This is used to compute its length.  */
835
836 static int
837 asm_insn_count (body)
838      rtx body;
839 {
840   char *template;
841   int count = 1;
842
843   if (GET_CODE (body) == ASM_INPUT)
844     template = XSTR (body, 0);
845   else
846     template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
847                                     NULL_PTR, NULL_PTR);
848
849   for ( ; *template; template++)
850     if (IS_ASM_LOGICAL_LINE_SEPARATOR(*template) || *template == '\n')
851       count++;
852
853   return count;
854 }
855 #endif
856 \f
857 /* Output assembler code for the start of a function,
858    and initialize some of the variables in this file
859    for the new function.  The label for the function and associated
860    assembler pseudo-ops have already been output in `assemble_start_function'.
861
862    FIRST is the first insn of the rtl for the function being compiled.
863    FILE is the file to write assembler code to.
864    OPTIMIZE is nonzero if we should eliminate redundant
865      test and compare insns.  */
866
867 void
868 final_start_function (first, file, optimize)
869      rtx first;
870      FILE *file;
871      int optimize;
872 {
873   block_depth = 0;
874
875   this_is_asm_operands = 0;
876
877 #ifdef NON_SAVING_SETJMP
878   /* A function that calls setjmp should save and restore all the
879      call-saved registers on a system where longjmp clobbers them.  */
880   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
881     {
882       int i;
883
884       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
885         if (!call_used_regs[i] && !call_fixed_regs[i])
886           regs_ever_live[i] = 1;
887     }
888 #endif
889   
890   /* Initial line number is supposed to be output
891      before the function's prologue and label
892      so that the function's address will not appear to be
893      in the last statement of the preceding function.  */
894   if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
895     last_linenum = high_block_linenum = high_function_linenum
896       = NOTE_LINE_NUMBER (first);
897
898   /* For SDB and XCOFF, the function beginning must be marked between
899      the function label and the prologue.  We always need this, even when
900      -g1 was used.  Defer on MIPS systems so that parameter descriptions
901      follow function entry.  */
902 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
903   if (write_symbols == SDB_DEBUG)
904     sdbout_begin_function (last_linenum);
905   else
906 #endif
907 #ifdef XCOFF_DEBUGGING_INFO
908     if (write_symbols == XCOFF_DEBUG)
909       xcoffout_begin_function (file, last_linenum);
910     else
911 #endif    
912       /* But only output line number for other debug info types if -g2
913          or better.  */
914       if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
915         output_source_line (file, first);
916
917 #ifdef LEAF_REG_REMAP
918   if (leaf_function)
919     leaf_renumber_regs (first);
920 #endif
921
922   /* The Sun386i and perhaps other machines don't work right
923      if the profiling code comes after the prologue.  */
924 #ifdef PROFILE_BEFORE_PROLOGUE
925   if (profile_flag)
926     profile_function (file);
927 #endif /* PROFILE_BEFORE_PROLOGUE */
928
929 #ifdef FUNCTION_PROLOGUE
930   /* First output the function prologue: code to set up the stack frame.  */
931   FUNCTION_PROLOGUE (file, get_frame_size ());
932 #endif
933
934 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
935   if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
936     next_block_index = 1;
937 #endif
938
939   /* If the machine represents the prologue as RTL, the profiling code must
940      be emitted when NOTE_INSN_PROLOGUE_END is scanned.  */
941 #ifdef HAVE_prologue
942   if (! HAVE_prologue)
943 #endif
944     profile_after_prologue (file);
945
946   profile_label_no++;
947
948   /* If we are doing basic block profiling, remember a printable version
949      of the function name.  */
950   if (profile_block_flag)
951     {
952       char *junk = "function";
953       bb_func_label_num =
954         add_bb_string ((*decl_printable_name) (current_function_decl, &junk), FALSE);
955     }
956 }
957
958 static void
959 profile_after_prologue (file)
960      FILE *file;
961 {
962 #ifdef FUNCTION_BLOCK_PROFILER
963   if (profile_block_flag)
964     {
965       FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
966     }
967 #endif /* FUNCTION_BLOCK_PROFILER */
968
969 #ifndef PROFILE_BEFORE_PROLOGUE
970   if (profile_flag)
971     profile_function (file);
972 #endif /* not PROFILE_BEFORE_PROLOGUE */
973 }
974
975 static void
976 profile_function (file)
977      FILE *file;
978 {
979   int align = MIN (BIGGEST_ALIGNMENT, POINTER_SIZE);
980   int sval = current_function_returns_struct;
981   int cxt = current_function_needs_context;
982
983   data_section ();
984   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
985   ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
986   assemble_integer (const0_rtx, POINTER_SIZE / BITS_PER_UNIT, 1);
987
988   text_section ();
989
990 #ifdef STRUCT_VALUE_INCOMING_REGNUM
991   if (sval)
992     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
993 #else
994 #ifdef STRUCT_VALUE_REGNUM
995   if (sval)
996     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
997 #endif
998 #endif
999
1000 #if 0
1001 #ifdef STATIC_CHAIN_INCOMING_REGNUM
1002   if (cxt)
1003     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1004 #else
1005 #ifdef STATIC_CHAIN_REGNUM
1006   if (cxt)
1007     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1008 #endif
1009 #endif
1010 #endif                          /* 0 */
1011
1012   FUNCTION_PROFILER (file, profile_label_no);
1013
1014 #if 0
1015 #ifdef STATIC_CHAIN_INCOMING_REGNUM
1016   if (cxt)
1017     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1018 #else
1019 #ifdef STATIC_CHAIN_REGNUM
1020   if (cxt)
1021     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1022 #endif
1023 #endif
1024 #endif                          /* 0 */
1025
1026 #ifdef STRUCT_VALUE_INCOMING_REGNUM
1027   if (sval)
1028     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1029 #else
1030 #ifdef STRUCT_VALUE_REGNUM
1031   if (sval)
1032     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1033 #endif
1034 #endif
1035 }
1036
1037 /* Output assembler code for the end of a function.
1038    For clarity, args are same as those of `final_start_function'
1039    even though not all of them are needed.  */
1040
1041 void
1042 final_end_function (first, file, optimize)
1043      rtx first;
1044      FILE *file;
1045      int optimize;
1046 {
1047   if (app_on)
1048     {
1049       fprintf (file, ASM_APP_OFF);
1050       app_on = 0;
1051     }
1052
1053 #ifdef SDB_DEBUGGING_INFO
1054   if (write_symbols == SDB_DEBUG)
1055     sdbout_end_function (high_function_linenum);
1056 #endif
1057
1058 #ifdef DWARF_DEBUGGING_INFO
1059   if (write_symbols == DWARF_DEBUG)
1060     dwarfout_end_function ();
1061 #endif
1062
1063 #ifdef XCOFF_DEBUGGING_INFO
1064   if (write_symbols == XCOFF_DEBUG)
1065     xcoffout_end_function (file, high_function_linenum);
1066 #endif
1067
1068 #ifdef FUNCTION_EPILOGUE
1069   /* Finally, output the function epilogue:
1070      code to restore the stack frame and return to the caller.  */
1071   FUNCTION_EPILOGUE (file, get_frame_size ());
1072 #endif
1073
1074 #ifdef SDB_DEBUGGING_INFO
1075   if (write_symbols == SDB_DEBUG)
1076     sdbout_end_epilogue ();
1077 #endif
1078
1079 #ifdef DWARF_DEBUGGING_INFO
1080   if (write_symbols == DWARF_DEBUG)
1081     dwarfout_end_epilogue ();
1082 #endif
1083
1084 #ifdef XCOFF_DEBUGGING_INFO
1085   if (write_symbols == XCOFF_DEBUG)
1086     xcoffout_end_epilogue (file);
1087 #endif
1088
1089   bb_func_label_num = -1;       /* not in function, nuke label # */
1090
1091   /* If FUNCTION_EPILOGUE is not defined, then the function body
1092      itself contains return instructions wherever needed.  */
1093 }
1094 \f
1095 /* Add a block to the linked list that remembers the current line/file/function
1096    for basic block profiling.  Emit the label in front of the basic block and
1097    the instructions that increment the count field.  */
1098
1099 static void
1100 add_bb (file)
1101      FILE *file;
1102 {
1103   struct bb_list *ptr = (struct bb_list *) permalloc (sizeof (struct bb_list));
1104
1105   /* Add basic block to linked list.  */
1106   ptr->next = 0;
1107   ptr->line_num = last_linenum;
1108   ptr->file_label_num = bb_file_label_num;
1109   ptr->func_label_num = bb_func_label_num;
1110   *bb_tail = ptr;
1111   bb_tail = &ptr->next;
1112
1113   /* Enable the table of basic-block use counts
1114      to point at the code it applies to.  */
1115   ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1116
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
1124   new_block = 0;
1125   count_basic_blocks++;
1126 }
1127
1128 /* Add a string to be used for basic block profiling.  */
1129
1130 static int
1131 add_bb_string (string, perm_p)
1132      char *string;
1133      int perm_p;
1134 {
1135   int len;
1136   struct bb_str *ptr = 0;
1137
1138   if (!string)
1139     {
1140       string = "<unknown>";
1141       perm_p = TRUE;
1142     }
1143
1144   /* Allocate a new string if the current string isn't permanent.  If
1145      the string is permanent search for the same string in other
1146      allocations.  */
1147
1148   len = strlen (string) + 1;
1149   if (!perm_p)
1150     {
1151       char *p = (char *) permalloc (len);
1152       bcopy (string, p, len);
1153       string = p;
1154     }
1155   else
1156     for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
1157       if (ptr->string == string)
1158         break;
1159
1160   /* Allocate a new string block if we need to.  */
1161   if (!ptr)
1162     {
1163       ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1164       ptr->next = 0;
1165       ptr->length = len;
1166       ptr->label_num = sbb_label_num++;
1167       ptr->string = string;
1168       *sbb_tail = ptr;
1169       sbb_tail = &ptr->next;
1170     }
1171
1172   return ptr->label_num;
1173 }
1174
1175 \f
1176 /* Output assembler code for some insns: all or part of a function.
1177    For description of args, see `final_start_function', above.
1178
1179    PRESCAN is 1 if we are not really outputting,
1180      just scanning as if we were outputting.
1181    Prescanning deletes and rearranges insns just like ordinary output.
1182    PRESCAN is -2 if we are outputting after having prescanned.
1183    In this case, don't try to delete or rearrange insns
1184    because that has already been done.
1185    Prescanning is done only on certain machines.  */
1186
1187 void
1188 final (first, file, optimize, prescan)
1189      rtx first;
1190      FILE *file;
1191      int optimize;
1192      int prescan;
1193 {
1194   register rtx insn;
1195   int max_line = 0;
1196
1197   last_ignored_compare = 0;
1198   new_block = 1;
1199
1200   check_exception_handler_labels ();
1201
1202   /* Make a map indicating which line numbers appear in this function.
1203      When producing SDB debugging info, delete troublesome line number
1204      notes from inlined functions in other files as well as duplicate
1205      line number notes.  */
1206 #ifdef SDB_DEBUGGING_INFO
1207   if (write_symbols == SDB_DEBUG)
1208     {
1209       rtx last = 0;
1210       for (insn = first; insn; insn = NEXT_INSN (insn))
1211         if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1212           {
1213             if ((RTX_INTEGRATED_P (insn)
1214                  && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1215                  || (last != 0
1216                      && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1217                      && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1218               {
1219                 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1220                 NOTE_SOURCE_FILE (insn) = 0;
1221                 continue;
1222               }
1223             last = insn;
1224             if (NOTE_LINE_NUMBER (insn) > max_line)
1225               max_line = NOTE_LINE_NUMBER (insn);
1226           }
1227     }
1228   else
1229 #endif
1230     {
1231       for (insn = first; insn; insn = NEXT_INSN (insn))
1232         if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1233           max_line = NOTE_LINE_NUMBER (insn);
1234     }
1235
1236   line_note_exists = (char *) oballoc (max_line + 1);
1237   bzero (line_note_exists, max_line + 1);
1238
1239   for (insn = first; insn; insn = NEXT_INSN (insn))
1240     if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1241       line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1242
1243   init_recog ();
1244
1245   CC_STATUS_INIT;
1246
1247   /* Output the insns.  */
1248   for (insn = NEXT_INSN (first); insn;)
1249     insn = final_scan_insn (insn, file, optimize, prescan, 0);
1250
1251   /* Do basic-block profiling here
1252      if the last insn was a conditional branch.  */
1253   if (profile_block_flag && new_block)
1254     add_bb (file);
1255 }
1256 \f
1257 /* The final scan for one insn, INSN.
1258    Args are same as in `final', except that INSN
1259    is the insn being scanned.
1260    Value returned is the next insn to be scanned.
1261
1262    NOPEEPHOLES is the flag to disallow peephole processing (currently
1263    used for within delayed branch sequence output).  */
1264
1265 rtx
1266 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
1267      rtx insn;
1268      FILE *file;
1269      int optimize;
1270      int prescan;
1271      int nopeepholes;
1272 {
1273   register int i;
1274   insn_counter++;
1275
1276   /* Ignore deleted insns.  These can occur when we split insns (due to a
1277      template of "#") while not optimizing.  */
1278   if (INSN_DELETED_P (insn))
1279     return NEXT_INSN (insn);
1280
1281   switch (GET_CODE (insn))
1282     {
1283     case NOTE:
1284       if (prescan > 0)
1285         break;
1286
1287       /* Align the beginning of a loop, for higher speed
1288          on certain machines.  */
1289
1290       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG && optimize > 0)
1291         {
1292 #ifdef ASM_OUTPUT_LOOP_ALIGN
1293           rtx next = next_nonnote_insn (insn);
1294           if (next && GET_CODE (next) == CODE_LABEL)
1295             {
1296               ASM_OUTPUT_LOOP_ALIGN (asm_out_file);
1297             }
1298 #endif
1299           break;
1300         }
1301       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
1302         break;
1303
1304       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
1305         {
1306           ASM_OUTPUT_INTERNAL_LABEL (file, "LEHB", NOTE_BLOCK_NUMBER (insn));
1307           add_eh_table_entry (NOTE_BLOCK_NUMBER (insn));
1308 #ifdef ASM_OUTPUT_EH_REGION_BEG
1309           ASM_OUTPUT_EH_REGION_BEG (file, NOTE_BLOCK_NUMBER (insn));
1310 #endif
1311           break;
1312         }
1313
1314       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
1315         {
1316           ASM_OUTPUT_INTERNAL_LABEL (file, "LEHE", NOTE_BLOCK_NUMBER (insn));
1317 #ifdef ASM_OUTPUT_EH_REGION_END
1318           ASM_OUTPUT_EH_REGION_END (file, NOTE_BLOCK_NUMBER (insn));
1319 #endif
1320           break;
1321         }
1322
1323       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
1324         {
1325 #ifdef FUNCTION_END_PROLOGUE
1326           FUNCTION_END_PROLOGUE (file);
1327 #endif
1328           profile_after_prologue (file);
1329           break;
1330         }
1331
1332 #ifdef FUNCTION_BEGIN_EPILOGUE
1333       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
1334         {
1335           FUNCTION_BEGIN_EPILOGUE (file);
1336           break;
1337         }
1338 #endif
1339
1340       if (write_symbols == NO_DEBUG)
1341         break;
1342       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
1343         {
1344 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
1345           /* MIPS stabs require the parameter descriptions to be after the
1346              function entry point rather than before.  */
1347           if (write_symbols == SDB_DEBUG)
1348             sdbout_begin_function (last_linenum);
1349           else
1350 #endif
1351 #ifdef DWARF_DEBUGGING_INFO
1352           /* This outputs a marker where the function body starts, so it
1353              must be after the prologue.  */
1354           if (write_symbols == DWARF_DEBUG)
1355             dwarfout_begin_function ();
1356 #endif
1357           break;
1358         }
1359       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
1360         break;                  /* An insn that was "deleted" */
1361       if (app_on)
1362         {
1363           fprintf (file, ASM_APP_OFF);
1364           app_on = 0;
1365         }
1366       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
1367           && (debug_info_level == DINFO_LEVEL_NORMAL
1368               || debug_info_level == DINFO_LEVEL_VERBOSE
1369 #ifdef DWARF_DEBUGGING_INFO
1370               || write_symbols == DWARF_DEBUG
1371 #endif
1372              )
1373          )
1374         {
1375           /* Beginning of a symbol-block.  Assign it a sequence number
1376              and push the number onto the stack PENDING_BLOCKS.  */
1377
1378           if (block_depth == max_block_depth)
1379             {
1380               /* PENDING_BLOCKS is full; make it longer.  */
1381               max_block_depth *= 2;
1382               pending_blocks
1383                 = (int *) xrealloc (pending_blocks,
1384                                     max_block_depth * sizeof (int));
1385             }
1386           pending_blocks[block_depth++] = next_block_index;
1387
1388           high_block_linenum = last_linenum;
1389
1390           /* Output debugging info about the symbol-block beginning.  */
1391
1392 #ifdef SDB_DEBUGGING_INFO
1393           if (write_symbols == SDB_DEBUG)
1394             sdbout_begin_block (file, last_linenum, next_block_index);
1395 #endif
1396 #ifdef XCOFF_DEBUGGING_INFO
1397           if (write_symbols == XCOFF_DEBUG)
1398             xcoffout_begin_block (file, last_linenum, next_block_index);
1399 #endif
1400 #ifdef DBX_DEBUGGING_INFO
1401           if (write_symbols == DBX_DEBUG)
1402             ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
1403 #endif
1404 #ifdef DWARF_DEBUGGING_INFO
1405           if (write_symbols == DWARF_DEBUG && block_depth > 1)
1406             dwarfout_begin_block (next_block_index);
1407 #endif
1408
1409           next_block_index++;
1410         }
1411       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
1412                && (debug_info_level == DINFO_LEVEL_NORMAL
1413                    || debug_info_level == DINFO_LEVEL_VERBOSE
1414 #ifdef DWARF_DEBUGGING_INFO
1415                    || write_symbols == DWARF_DEBUG
1416 #endif
1417                   )
1418               )
1419         {
1420           /* End of a symbol-block.  Pop its sequence number off
1421              PENDING_BLOCKS and output debugging info based on that.  */
1422
1423           --block_depth;
1424
1425 #ifdef XCOFF_DEBUGGING_INFO
1426           if (write_symbols == XCOFF_DEBUG && block_depth >= 0)
1427             xcoffout_end_block (file, high_block_linenum,
1428                                 pending_blocks[block_depth]);
1429 #endif
1430 #ifdef DBX_DEBUGGING_INFO
1431           if (write_symbols == DBX_DEBUG && block_depth >= 0)
1432             ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
1433                                        pending_blocks[block_depth]);
1434 #endif
1435 #ifdef SDB_DEBUGGING_INFO
1436           if (write_symbols == SDB_DEBUG && block_depth >= 0)
1437             sdbout_end_block (file, high_block_linenum,
1438                               pending_blocks[block_depth]);
1439 #endif
1440 #ifdef DWARF_DEBUGGING_INFO
1441           if (write_symbols == DWARF_DEBUG && block_depth >= 1)
1442             dwarfout_end_block (pending_blocks[block_depth]);
1443 #endif
1444         }
1445       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
1446                && (debug_info_level == DINFO_LEVEL_NORMAL
1447                    || debug_info_level == DINFO_LEVEL_VERBOSE))
1448         {
1449 #ifdef DWARF_DEBUGGING_INFO
1450           if (write_symbols == DWARF_DEBUG)
1451             dwarfout_label (insn);
1452 #endif
1453         }
1454       else if (NOTE_LINE_NUMBER (insn) > 0)
1455         /* This note is a line-number.  */
1456         {
1457           register rtx note;
1458
1459 #if 0 /* This is what we used to do.  */
1460           output_source_line (file, insn);
1461 #endif
1462           int note_after = 0;
1463
1464           /* If there is anything real after this note,
1465              output it.  If another line note follows, omit this one.  */
1466           for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
1467             {
1468               if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
1469                 break;
1470               /* These types of notes can be significant
1471                  so make sure the preceding line number stays.  */
1472               else if (GET_CODE (note) == NOTE
1473                        && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
1474                            || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
1475                            || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
1476                 break;
1477               else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
1478                 {
1479                   /* Another line note follows; we can delete this note
1480                      if no intervening line numbers have notes elsewhere.  */
1481                   int num;
1482                   for (num = NOTE_LINE_NUMBER (insn) + 1;
1483                        num < NOTE_LINE_NUMBER (note);
1484                        num++)
1485                     if (line_note_exists[num])
1486                       break;
1487
1488                   if (num >= NOTE_LINE_NUMBER (note))
1489                     note_after = 1;
1490                   break;
1491                 }
1492             }
1493
1494           /* Output this line note
1495              if it is the first or the last line note in a row.  */
1496           if (!note_after)
1497             output_source_line (file, insn);
1498         }
1499       break;
1500
1501     case BARRIER:
1502 #ifdef ASM_OUTPUT_ALIGN_CODE
1503       /* Don't litter the assembler output with needless alignments.  A
1504          BARRIER will be placed at the end of every function if HAVE_epilogue
1505          is true.  */    
1506       if (NEXT_INSN (insn))
1507         ASM_OUTPUT_ALIGN_CODE (file);
1508 #endif
1509       break;
1510
1511     case CODE_LABEL:
1512       CC_STATUS_INIT;
1513       if (prescan > 0)
1514         break;
1515       new_block = 1;
1516
1517 #ifdef FINAL_PRESCAN_LABEL
1518       FINAL_PRESCAN_INSN (insn, NULL_PTR, 0);
1519 #endif
1520
1521 #ifdef SDB_DEBUGGING_INFO
1522       if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
1523         sdbout_label (insn);
1524 #endif
1525 #ifdef DWARF_DEBUGGING_INFO
1526       if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
1527         dwarfout_label (insn);
1528 #endif
1529       if (app_on)
1530         {
1531           fprintf (file, ASM_APP_OFF);
1532           app_on = 0;
1533         }
1534       if (NEXT_INSN (insn) != 0
1535           && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
1536         {
1537           rtx nextbody = PATTERN (NEXT_INSN (insn));
1538
1539           /* If this label is followed by a jump-table,
1540              make sure we put the label in the read-only section.  Also
1541              possibly write the label and jump table together.  */
1542
1543           if (GET_CODE (nextbody) == ADDR_VEC
1544               || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1545             {
1546 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1547               readonly_data_section ();
1548 #ifdef READONLY_DATA_SECTION
1549               ASM_OUTPUT_ALIGN (file,
1550                                 exact_log2 (BIGGEST_ALIGNMENT
1551                                             / BITS_PER_UNIT));
1552 #endif /* READONLY_DATA_SECTION */
1553 #else /* JUMP_TABLES_IN_TEXT_SECTION */
1554               function_section (current_function_decl);
1555 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
1556 #ifdef ASM_OUTPUT_CASE_LABEL
1557               ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
1558                                      NEXT_INSN (insn));
1559 #else
1560               ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1561 #endif
1562               break;
1563             }
1564         }
1565
1566       ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1567       break;
1568
1569     default:
1570       {
1571         register rtx body = PATTERN (insn);
1572         int insn_code_number;
1573         char *template;
1574         rtx note;
1575
1576         /* An INSN, JUMP_INSN or CALL_INSN.
1577            First check for special kinds that recog doesn't recognize.  */
1578
1579         if (GET_CODE (body) == USE /* These are just declarations */
1580             || GET_CODE (body) == CLOBBER)
1581           break;
1582
1583 #ifdef HAVE_cc0
1584         /* If there is a REG_CC_SETTER note on this insn, it means that
1585            the setting of the condition code was done in the delay slot
1586            of the insn that branched here.  So recover the cc status
1587            from the insn that set it.  */
1588
1589         note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1590         if (note)
1591           {
1592             NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
1593             cc_prev_status = cc_status;
1594           }
1595 #endif
1596
1597         /* Detect insns that are really jump-tables
1598            and output them as such.  */
1599
1600         if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1601           {
1602             register int vlen, idx;
1603
1604             if (prescan > 0)
1605               break;
1606
1607             if (app_on)
1608               {
1609                 fprintf (file, ASM_APP_OFF);
1610                 app_on = 0;
1611               }
1612
1613             vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
1614             for (idx = 0; idx < vlen; idx++)
1615               {
1616                 if (GET_CODE (body) == ADDR_VEC)
1617                   {
1618 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
1619                     ASM_OUTPUT_ADDR_VEC_ELT
1620                       (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
1621 #else
1622                     abort ();
1623 #endif
1624                   }
1625                 else
1626                   {
1627 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
1628                     ASM_OUTPUT_ADDR_DIFF_ELT
1629                       (file,
1630                        CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
1631                        CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
1632 #else
1633                     abort ();
1634 #endif
1635                   }
1636               }
1637 #ifdef ASM_OUTPUT_CASE_END
1638             ASM_OUTPUT_CASE_END (file,
1639                                  CODE_LABEL_NUMBER (PREV_INSN (insn)),
1640                                  insn);
1641 #endif
1642
1643             function_section (current_function_decl);
1644
1645             break;
1646           }
1647
1648         /* Do basic-block profiling when we reach a new block.
1649            Done here to avoid jump tables.  */
1650         if (profile_block_flag && new_block)
1651           add_bb (file);
1652
1653         if (GET_CODE (body) == ASM_INPUT)
1654           {
1655             /* There's no telling what that did to the condition codes.  */
1656             CC_STATUS_INIT;
1657             if (prescan > 0)
1658               break;
1659             if (! app_on)
1660               {
1661                 fprintf (file, ASM_APP_ON);
1662                 app_on = 1;
1663               }
1664             fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
1665             break;
1666           }
1667
1668         /* Detect `asm' construct with operands.  */
1669         if (asm_noperands (body) >= 0)
1670           {
1671             int noperands = asm_noperands (body);
1672             rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
1673             char *string;
1674
1675             /* There's no telling what that did to the condition codes.  */
1676             CC_STATUS_INIT;
1677             if (prescan > 0)
1678               break;
1679
1680             if (! app_on)
1681               {
1682                 fprintf (file, ASM_APP_ON);
1683                 app_on = 1;
1684               }
1685
1686             /* Get out the operand values.  */
1687             string = decode_asm_operands (body, ops, NULL_PTR,
1688                                           NULL_PTR, NULL_PTR);
1689             /* Inhibit aborts on what would otherwise be compiler bugs.  */
1690             insn_noperands = noperands;
1691             this_is_asm_operands = insn;
1692
1693             /* Output the insn using them.  */
1694             output_asm_insn (string, ops);
1695             this_is_asm_operands = 0;
1696             break;
1697           }
1698
1699         if (prescan <= 0 && app_on)
1700           {
1701             fprintf (file, ASM_APP_OFF);
1702             app_on = 0;
1703           }
1704
1705         if (GET_CODE (body) == SEQUENCE)
1706           {
1707             /* A delayed-branch sequence */
1708             register int i;
1709             rtx next;
1710
1711             if (prescan > 0)
1712               break;
1713             final_sequence = body;
1714
1715             /* The first insn in this SEQUENCE might be a JUMP_INSN that will
1716                force the restoration of a comparison that was previously
1717                thought unnecessary.  If that happens, cancel this sequence
1718                and cause that insn to be restored.  */
1719
1720             next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
1721             if (next != XVECEXP (body, 0, 1))
1722               {
1723                 final_sequence = 0;
1724                 return next;
1725               }
1726
1727             for (i = 1; i < XVECLEN (body, 0); i++)
1728               {
1729                 rtx insn = XVECEXP (body, 0, i);
1730                 rtx next = NEXT_INSN (insn);
1731                 /* We loop in case any instruction in a delay slot gets
1732                    split.  */
1733                 do
1734                   insn = final_scan_insn (insn, file, 0, prescan, 1);
1735                 while (insn != next);
1736               }
1737 #ifdef DBR_OUTPUT_SEQEND
1738             DBR_OUTPUT_SEQEND (file);
1739 #endif
1740             final_sequence = 0;
1741
1742             /* If the insn requiring the delay slot was a CALL_INSN, the
1743                insns in the delay slot are actually executed before the
1744                called function.  Hence we don't preserve any CC-setting
1745                actions in these insns and the CC must be marked as being
1746                clobbered by the function.  */
1747             if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
1748               CC_STATUS_INIT;
1749
1750             /* Following a conditional branch sequence, we have a new basic
1751                block.  */
1752             if (profile_block_flag)
1753               {
1754                 rtx insn = XVECEXP (body, 0, 0);
1755                 rtx body = PATTERN (insn);
1756
1757                 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1758                      && GET_CODE (SET_SRC (body)) != LABEL_REF)
1759                     || (GET_CODE (insn) == JUMP_INSN
1760                         && GET_CODE (body) == PARALLEL
1761                         && GET_CODE (XVECEXP (body, 0, 0)) == SET
1762                         && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
1763                   new_block = 1;
1764               }
1765             break;
1766           }
1767
1768         /* We have a real machine instruction as rtl.  */
1769
1770         body = PATTERN (insn);
1771
1772 #ifdef HAVE_cc0
1773         /* Check for redundant test and compare instructions
1774            (when the condition codes are already set up as desired).
1775            This is done only when optimizing; if not optimizing,
1776            it should be possible for the user to alter a variable
1777            with the debugger in between statements
1778            and the next statement should reexamine the variable
1779            to compute the condition codes.  */
1780
1781         if (optimize)
1782           {
1783             rtx set = single_set(insn);
1784
1785             if (set
1786                 && GET_CODE (SET_DEST (set)) == CC0
1787                 && insn != last_ignored_compare)
1788               {
1789                 if (GET_CODE (SET_SRC (set)) == SUBREG)
1790                   SET_SRC (set) = alter_subreg (SET_SRC (set));
1791                 else if (GET_CODE (SET_SRC (set)) == COMPARE)
1792                   {
1793                     if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
1794                       XEXP (SET_SRC (set), 0)
1795                         = alter_subreg (XEXP (SET_SRC (set), 0));
1796                     if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
1797                       XEXP (SET_SRC (set), 1)
1798                         = alter_subreg (XEXP (SET_SRC (set), 1));
1799                   }
1800                 if ((cc_status.value1 != 0
1801                      && rtx_equal_p (SET_SRC (set), cc_status.value1))
1802                     || (cc_status.value2 != 0
1803                         && rtx_equal_p (SET_SRC (set), cc_status.value2)))
1804                   {
1805                     /* Don't delete insn if it has an addressing side-effect.  */
1806                     if (! FIND_REG_INC_NOTE (insn, 0)
1807                         /* or if anything in it is volatile.  */
1808                         && ! volatile_refs_p (PATTERN (insn)))
1809                       {
1810                         /* We don't really delete the insn; just ignore it.  */
1811                         last_ignored_compare = insn;
1812                         break;
1813                       }
1814                   }
1815               }
1816           }
1817 #endif
1818
1819         /* Following a conditional branch, we have a new basic block.
1820            But if we are inside a sequence, the new block starts after the
1821            last insn of the sequence.  */
1822         if (profile_block_flag && final_sequence == 0
1823             && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1824                  && GET_CODE (SET_SRC (body)) != LABEL_REF)
1825                 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
1826                     && GET_CODE (XVECEXP (body, 0, 0)) == SET
1827                     && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
1828           new_block = 1;
1829
1830 #ifndef STACK_REGS
1831         /* Don't bother outputting obvious no-ops, even without -O.
1832            This optimization is fast and doesn't interfere with debugging.
1833            Don't do this if the insn is in a delay slot, since this
1834            will cause an improper number of delay insns to be written.  */
1835         if (final_sequence == 0
1836             && prescan >= 0
1837             && GET_CODE (insn) == INSN && GET_CODE (body) == SET
1838             && GET_CODE (SET_SRC (body)) == REG
1839             && GET_CODE (SET_DEST (body)) == REG
1840             && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
1841           break;
1842 #endif
1843
1844 #ifdef HAVE_cc0
1845         /* If this is a conditional branch, maybe modify it
1846            if the cc's are in a nonstandard state
1847            so that it accomplishes the same thing that it would
1848            do straightforwardly if the cc's were set up normally.  */
1849
1850         if (cc_status.flags != 0
1851             && GET_CODE (insn) == JUMP_INSN
1852             && GET_CODE (body) == SET
1853             && SET_DEST (body) == pc_rtx
1854             && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
1855             && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
1856             && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
1857             /* This is done during prescan; it is not done again
1858                in final scan when prescan has been done.  */
1859             && prescan >= 0)
1860           {
1861             /* This function may alter the contents of its argument
1862                and clear some of the cc_status.flags bits.
1863                It may also return 1 meaning condition now always true
1864                or -1 meaning condition now always false
1865                or 2 meaning condition nontrivial but altered.  */
1866             register int result = alter_cond (XEXP (SET_SRC (body), 0));
1867             /* If condition now has fixed value, replace the IF_THEN_ELSE
1868                with its then-operand or its else-operand.  */
1869             if (result == 1)
1870               SET_SRC (body) = XEXP (SET_SRC (body), 1);
1871             if (result == -1)
1872               SET_SRC (body) = XEXP (SET_SRC (body), 2);
1873
1874             /* The jump is now either unconditional or a no-op.
1875                If it has become a no-op, don't try to output it.
1876                (It would not be recognized.)  */
1877             if (SET_SRC (body) == pc_rtx)
1878               {
1879                 PUT_CODE (insn, NOTE);
1880                 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1881                 NOTE_SOURCE_FILE (insn) = 0;
1882                 break;
1883               }
1884             else if (GET_CODE (SET_SRC (body)) == RETURN)
1885               /* Replace (set (pc) (return)) with (return).  */
1886               PATTERN (insn) = body = SET_SRC (body);
1887
1888             /* Rerecognize the instruction if it has changed.  */
1889             if (result != 0)
1890               INSN_CODE (insn) = -1;
1891           }
1892
1893         /* Make same adjustments to instructions that examine the
1894            condition codes without jumping and instructions that
1895            handle conditional moves (if this machine has either one).  */
1896
1897         if (cc_status.flags != 0
1898             && GET_CODE (body) == SET)
1899           {
1900             rtx cond_rtx, then_rtx, else_rtx;
1901             
1902             if (GET_CODE (insn) != JUMP_INSN
1903                 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE)
1904               {
1905                 cond_rtx = XEXP (SET_SRC (body), 0);
1906                 then_rtx = XEXP (SET_SRC (body), 1);
1907                 else_rtx = XEXP (SET_SRC (body), 2);
1908               }
1909             else
1910               {
1911                 cond_rtx = SET_SRC (body);
1912                 then_rtx = const_true_rtx;
1913                 else_rtx = const0_rtx;
1914               }
1915             
1916             switch (GET_CODE (cond_rtx))
1917               {
1918               case GTU:
1919               case GT:
1920               case LTU:
1921               case LT:
1922               case GEU:
1923               case GE:
1924               case LEU:
1925               case LE:
1926               case EQ:
1927               case NE:
1928                 {
1929                   register int result;
1930                   if (XEXP (cond_rtx, 0) != cc0_rtx)
1931                     break;
1932                   result = alter_cond (cond_rtx);
1933                   if (result == 1)
1934                     validate_change (insn, &SET_SRC (body), then_rtx, 0);
1935                   else if (result == -1)
1936                     validate_change (insn, &SET_SRC (body), else_rtx, 0);
1937                   else if (result == 2)
1938                     INSN_CODE (insn) = -1;
1939                   if (SET_DEST (body) == SET_SRC (body))
1940                     {
1941                       PUT_CODE (insn, NOTE);
1942                       NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1943                       NOTE_SOURCE_FILE (insn) = 0;
1944                       break;
1945                     }
1946                 }
1947               }
1948           }
1949
1950 #endif
1951
1952         /* Do machine-specific peephole optimizations if desired.  */
1953
1954         if (optimize && !flag_no_peephole && !nopeepholes)
1955           {
1956             rtx next = peephole (insn);
1957             /* When peepholing, if there were notes within the peephole,
1958                emit them before the peephole.  */
1959             if (next != 0 && next != NEXT_INSN (insn))
1960               {
1961                 rtx prev = PREV_INSN (insn);
1962                 rtx note;
1963
1964                 for (note = NEXT_INSN (insn); note != next;
1965                      note = NEXT_INSN (note))
1966                   final_scan_insn (note, file, optimize, prescan, nopeepholes);
1967
1968                 /* In case this is prescan, put the notes
1969                    in proper position for later rescan.  */
1970                 note = NEXT_INSN (insn);
1971                 PREV_INSN (note) = prev;
1972                 NEXT_INSN (prev) = note;
1973                 NEXT_INSN (PREV_INSN (next)) = insn;
1974                 PREV_INSN (insn) = PREV_INSN (next);
1975                 NEXT_INSN (insn) = next;
1976                 PREV_INSN (next) = insn;
1977               }
1978
1979             /* PEEPHOLE might have changed this.  */
1980             body = PATTERN (insn);
1981           }
1982
1983         /* Try to recognize the instruction.
1984            If successful, verify that the operands satisfy the
1985            constraints for the instruction.  Crash if they don't,
1986            since `reload' should have changed them so that they do.  */
1987
1988         insn_code_number = recog_memoized (insn);
1989         insn_extract (insn);
1990         for (i = 0; i < insn_n_operands[insn_code_number]; i++)
1991           {
1992             if (GET_CODE (recog_operand[i]) == SUBREG)
1993               recog_operand[i] = alter_subreg (recog_operand[i]);
1994             else if (GET_CODE (recog_operand[i]) == PLUS
1995                      || GET_CODE (recog_operand[i]) == MULT)
1996               recog_operand[i] = walk_alter_subreg (recog_operand[i]);
1997           }
1998
1999         for (i = 0; i < insn_n_dups[insn_code_number]; i++)
2000           {
2001             if (GET_CODE (*recog_dup_loc[i]) == SUBREG)
2002               *recog_dup_loc[i] = alter_subreg (*recog_dup_loc[i]);
2003             else if (GET_CODE (*recog_dup_loc[i]) == PLUS
2004                      || GET_CODE (*recog_dup_loc[i]) == MULT)
2005               *recog_dup_loc[i] = walk_alter_subreg (*recog_dup_loc[i]);
2006           }
2007
2008 #ifdef REGISTER_CONSTRAINTS
2009         if (! constrain_operands (insn_code_number, 1))
2010           fatal_insn_not_found (insn);
2011 #endif
2012
2013         /* Some target machines need to prescan each insn before
2014            it is output.  */
2015
2016 #ifdef FINAL_PRESCAN_INSN
2017         FINAL_PRESCAN_INSN (insn, recog_operand,
2018                             insn_n_operands[insn_code_number]);
2019 #endif
2020
2021 #ifdef HAVE_cc0
2022         cc_prev_status = cc_status;
2023
2024         /* Update `cc_status' for this instruction.
2025            The instruction's output routine may change it further.
2026            If the output routine for a jump insn needs to depend
2027            on the cc status, it should look at cc_prev_status.  */
2028
2029         NOTICE_UPDATE_CC (body, insn);
2030 #endif
2031
2032         debug_insn = insn;
2033
2034         /* If the proper template needs to be chosen by some C code,
2035            run that code and get the real template.  */
2036
2037         template = insn_template[insn_code_number];
2038         if (template == 0)
2039           {
2040             template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
2041
2042             /* If the C code returns 0, it means that it is a jump insn
2043                which follows a deleted test insn, and that test insn
2044                needs to be reinserted.  */
2045             if (template == 0)
2046               {
2047                 if (prev_nonnote_insn (insn) != last_ignored_compare)
2048                   abort ();
2049                 new_block = 0;
2050                 return prev_nonnote_insn (insn);
2051               }
2052           }
2053
2054         /* If the template is the string "#", it means that this insn must
2055            be split.  */
2056         if (template[0] == '#' && template[1] == '\0')
2057           {
2058             rtx new = try_split (body, insn, 0);
2059
2060             /* If we didn't split the insn, go away.  */
2061             if (new == insn && PATTERN (new) == body)
2062               abort ();
2063               
2064             new_block = 0;
2065             return new;
2066           }
2067         
2068         if (prescan > 0)
2069           break;
2070
2071         /* Output assembler code from the template.  */
2072
2073         output_asm_insn (template, recog_operand);
2074
2075 #if 0
2076         /* It's not at all clear why we did this and doing so interferes
2077            with tests we'd like to do to use REG_WAS_0 notes, so let's try
2078            with this out.  */
2079
2080         /* Mark this insn as having been output.  */
2081         INSN_DELETED_P (insn) = 1;
2082 #endif
2083
2084         debug_insn = 0;
2085       }
2086     }
2087   return NEXT_INSN (insn);
2088 }
2089 \f
2090 /* Output debugging info to the assembler file FILE
2091    based on the NOTE-insn INSN, assumed to be a line number.  */
2092
2093 static void
2094 output_source_line (file, insn)
2095      FILE *file;
2096      rtx insn;
2097 {
2098   register char *filename = NOTE_SOURCE_FILE (insn);
2099
2100   /* Remember filename for basic block profiling.
2101      Filenames are allocated on the permanent obstack
2102      or are passed in ARGV, so we don't have to save
2103      the string.  */
2104
2105   if (profile_block_flag && last_filename != filename)
2106     bb_file_label_num = add_bb_string (filename, TRUE);
2107
2108   last_filename = filename;
2109   last_linenum = NOTE_LINE_NUMBER (insn);
2110   high_block_linenum = MAX (last_linenum, high_block_linenum);
2111   high_function_linenum = MAX (last_linenum, high_function_linenum);
2112
2113   if (write_symbols != NO_DEBUG)
2114     {
2115 #ifdef SDB_DEBUGGING_INFO
2116       if (write_symbols == SDB_DEBUG
2117 #if 0 /* People like having line numbers even in wrong file!  */
2118           /* COFF can't handle multiple source files--lose, lose.  */
2119           && !strcmp (filename, main_input_filename)
2120 #endif
2121           /* COFF relative line numbers must be positive.  */
2122           && last_linenum > sdb_begin_function_line)
2123         {
2124 #ifdef ASM_OUTPUT_SOURCE_LINE
2125           ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
2126 #else
2127           fprintf (file, "\t.ln\t%d\n",
2128                    ((sdb_begin_function_line > -1)
2129                     ? last_linenum - sdb_begin_function_line : 1));
2130 #endif
2131         }
2132 #endif
2133
2134 #if defined (DBX_DEBUGGING_INFO)
2135       if (write_symbols == DBX_DEBUG)
2136         dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
2137 #endif
2138
2139 #if defined (XCOFF_DEBUGGING_INFO)
2140       if (write_symbols == XCOFF_DEBUG)
2141         xcoffout_source_line (file, filename, insn);
2142 #endif
2143
2144 #ifdef DWARF_DEBUGGING_INFO
2145       if (write_symbols == DWARF_DEBUG)
2146         dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
2147 #endif
2148     }
2149 }
2150 \f
2151 /* If X is a SUBREG, replace it with a REG or a MEM,
2152    based on the thing it is a subreg of.  */
2153
2154 rtx
2155 alter_subreg (x)
2156      register rtx x;
2157 {
2158   register rtx y = SUBREG_REG (x);
2159   if (GET_CODE (y) == SUBREG)
2160     y = alter_subreg (y);
2161
2162   if (GET_CODE (y) == REG)
2163     {
2164       /* If the containing reg really gets a hard reg, so do we.  */
2165       PUT_CODE (x, REG);
2166       REGNO (x) = REGNO (y) + SUBREG_WORD (x);
2167     }
2168   else if (GET_CODE (y) == MEM)
2169     {
2170       register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2171       if (BYTES_BIG_ENDIAN)
2172         offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
2173                    - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
2174       PUT_CODE (x, MEM);
2175       MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
2176       XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
2177     }
2178
2179   return x;
2180 }
2181
2182 /* Do alter_subreg on all the SUBREGs contained in X.  */
2183
2184 static rtx
2185 walk_alter_subreg (x)
2186      rtx x;
2187 {
2188   switch (GET_CODE (x))
2189     {
2190     case PLUS:
2191     case MULT:
2192       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2193       XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
2194       break;
2195
2196     case MEM:
2197       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2198       break;
2199
2200     case SUBREG:
2201       return alter_subreg (x);
2202     }
2203
2204   return x;
2205 }
2206 \f
2207 #ifdef HAVE_cc0
2208
2209 /* Given BODY, the body of a jump instruction, alter the jump condition
2210    as required by the bits that are set in cc_status.flags.
2211    Not all of the bits there can be handled at this level in all cases.
2212
2213    The value is normally 0.
2214    1 means that the condition has become always true.
2215    -1 means that the condition has become always false.
2216    2 means that COND has been altered.  */
2217
2218 static int
2219 alter_cond (cond)
2220      register rtx cond;
2221 {
2222   int value = 0;
2223
2224   if (cc_status.flags & CC_REVERSED)
2225     {
2226       value = 2;
2227       PUT_CODE (cond, swap_condition (GET_CODE (cond)));
2228     }
2229
2230   if (cc_status.flags & CC_INVERTED)
2231     {
2232       value = 2;
2233       PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
2234     }
2235
2236   if (cc_status.flags & CC_NOT_POSITIVE)
2237     switch (GET_CODE (cond))
2238       {
2239       case LE:
2240       case LEU:
2241       case GEU:
2242         /* Jump becomes unconditional.  */
2243         return 1;
2244
2245       case GT:
2246       case GTU:
2247       case LTU:
2248         /* Jump becomes no-op.  */
2249         return -1;
2250
2251       case GE:
2252         PUT_CODE (cond, EQ);
2253         value = 2;
2254         break;
2255
2256       case LT:
2257         PUT_CODE (cond, NE);
2258         value = 2;
2259         break;
2260       }
2261
2262   if (cc_status.flags & CC_NOT_NEGATIVE)
2263     switch (GET_CODE (cond))
2264       {
2265       case GE:
2266       case GEU:
2267         /* Jump becomes unconditional.  */
2268         return 1;
2269
2270       case LT:
2271       case LTU:
2272         /* Jump becomes no-op.  */
2273         return -1;
2274
2275       case LE:
2276       case LEU:
2277         PUT_CODE (cond, EQ);
2278         value = 2;
2279         break;
2280
2281       case GT:
2282       case GTU:
2283         PUT_CODE (cond, NE);
2284         value = 2;
2285         break;
2286       }
2287
2288   if (cc_status.flags & CC_NO_OVERFLOW)
2289     switch (GET_CODE (cond))
2290       {
2291       case GEU:
2292         /* Jump becomes unconditional.  */
2293         return 1;
2294
2295       case LEU:
2296         PUT_CODE (cond, EQ);
2297         value = 2;
2298         break;
2299
2300       case GTU:
2301         PUT_CODE (cond, NE);
2302         value = 2;
2303         break;
2304
2305       case LTU:
2306         /* Jump becomes no-op.  */
2307         return -1;
2308       }
2309
2310   if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
2311     switch (GET_CODE (cond))
2312       {
2313       case LE:
2314       case LEU:
2315       case GE:
2316       case GEU:
2317       case LT:
2318       case LTU:
2319       case GT:
2320       case GTU:
2321         abort ();
2322
2323       case NE:
2324         PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
2325         value = 2;
2326         break;
2327
2328       case EQ:
2329         PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
2330         value = 2;
2331         break;
2332       }
2333
2334   if (cc_status.flags & CC_NOT_SIGNED)
2335     /* The flags are valid if signed condition operators are converted
2336        to unsigned.  */
2337     switch (GET_CODE (cond))
2338       {
2339       case LE:
2340         PUT_CODE (cond, LEU);
2341         value = 2;
2342         break;
2343
2344       case LT:
2345         PUT_CODE (cond, LTU);
2346         value = 2;
2347         break;
2348
2349       case GT:
2350         PUT_CODE (cond, GTU);
2351         value = 2;
2352         break;
2353
2354       case GE:
2355         PUT_CODE (cond, GEU);
2356         value = 2;
2357         break;
2358       }
2359
2360   return value;
2361 }
2362 #endif
2363 \f
2364 /* Report inconsistency between the assembler template and the operands.
2365    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
2366
2367 void
2368 output_operand_lossage (str)
2369      char *str;
2370 {
2371   if (this_is_asm_operands)
2372     error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
2373   else
2374     abort ();
2375 }
2376 \f
2377 /* Output of assembler code from a template, and its subroutines.  */
2378
2379 /* Output text from TEMPLATE to the assembler output file,
2380    obeying %-directions to substitute operands taken from
2381    the vector OPERANDS.
2382
2383    %N (for N a digit) means print operand N in usual manner.
2384    %lN means require operand N to be a CODE_LABEL or LABEL_REF
2385       and print the label name with no punctuation.
2386    %cN means require operand N to be a constant
2387       and print the constant expression with no punctuation.
2388    %aN means expect operand N to be a memory address
2389       (not a memory reference!) and print a reference
2390       to that address.
2391    %nN means expect operand N to be a constant
2392       and print a constant expression for minus the value
2393       of the operand, with no other punctuation.  */
2394
2395 static void
2396 output_asm_name ()
2397 {
2398   if (flag_print_asm_name)
2399     {
2400       /* Annotate the assembly with a comment describing the pattern and
2401          alternative used.  */
2402       if (debug_insn)
2403         {
2404           register int num = INSN_CODE (debug_insn);
2405           fprintf (asm_out_file, " %s %d %s", 
2406                    ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
2407           if (insn_n_alternatives[num] > 1)
2408             fprintf (asm_out_file, "/%d", which_alternative + 1);
2409
2410           /* Clear this so only the first assembler insn
2411              of any rtl insn will get the special comment for -dp.  */
2412           debug_insn = 0;
2413         }
2414     }
2415 }
2416
2417 void
2418 output_asm_insn (template, operands)
2419      char *template;
2420      rtx *operands;
2421 {
2422   register char *p;
2423   register int c, i;
2424
2425   /* An insn may return a null string template
2426      in a case where no assembler code is needed.  */
2427   if (*template == 0)
2428     return;
2429
2430   p = template;
2431   putc ('\t', asm_out_file);
2432
2433 #ifdef ASM_OUTPUT_OPCODE
2434   ASM_OUTPUT_OPCODE (asm_out_file, p);
2435 #endif
2436
2437   while (c = *p++)
2438     switch (c)
2439       {
2440       case '\n':
2441         output_asm_name ();
2442         putc (c, asm_out_file);
2443 #ifdef ASM_OUTPUT_OPCODE
2444         while ((c = *p) == '\t')
2445           {
2446             putc (c, asm_out_file);
2447             p++;
2448           }
2449         ASM_OUTPUT_OPCODE (asm_out_file, p);
2450 #endif
2451         break;
2452
2453 #ifdef ASSEMBLER_DIALECT
2454       case '{':
2455         /* If we want the first dialect, do nothing.  Otherwise, skip
2456            DIALECT_NUMBER of strings ending with '|'.  */
2457         for (i = 0; i < dialect_number; i++)
2458           {
2459             while (*p && *p++ != '|')
2460               ;
2461
2462             if (*p == '|')
2463               p++;
2464           }
2465         break;
2466
2467       case '|':
2468         /* Skip to close brace.  */
2469         while (*p && *p++ != '}')
2470           ;
2471         break;
2472
2473       case '}':
2474         break;
2475 #endif
2476
2477       case '%':
2478         /* %% outputs a single %.  */
2479         if (*p == '%')
2480           {
2481             p++;
2482             putc (c, asm_out_file);
2483           }
2484         /* %= outputs a number which is unique to each insn in the entire
2485            compilation.  This is useful for making local labels that are
2486            referred to more than once in a given insn.  */
2487         else if (*p == '=')
2488           {
2489             p++;
2490             fprintf (asm_out_file, "%d", insn_counter);
2491           }
2492         /* % followed by a letter and some digits
2493            outputs an operand in a special way depending on the letter.
2494            Letters `acln' are implemented directly.
2495            Other letters are passed to `output_operand' so that
2496            the PRINT_OPERAND macro can define them.  */
2497         else if ((*p >= 'a' && *p <= 'z')
2498                  || (*p >= 'A' && *p <= 'Z'))
2499           {
2500             int letter = *p++;
2501             c = atoi (p);
2502
2503             if (! (*p >= '0' && *p <= '9'))
2504               output_operand_lossage ("operand number missing after %-letter");
2505             else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2506               output_operand_lossage ("operand number out of range");
2507             else if (letter == 'l')
2508               output_asm_label (operands[c]);
2509             else if (letter == 'a')
2510               output_address (operands[c]);
2511             else if (letter == 'c')
2512               {
2513                 if (CONSTANT_ADDRESS_P (operands[c]))
2514                   output_addr_const (asm_out_file, operands[c]);
2515                 else
2516                   output_operand (operands[c], 'c');
2517               }
2518             else if (letter == 'n')
2519               {
2520                 if (GET_CODE (operands[c]) == CONST_INT)
2521                   fprintf (asm_out_file,
2522 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2523                            "%d",
2524 #else
2525                            "%ld",
2526 #endif
2527                            - INTVAL (operands[c]));
2528                 else
2529                   {
2530                     putc ('-', asm_out_file);
2531                     output_addr_const (asm_out_file, operands[c]);
2532                   }
2533               }
2534             else
2535               output_operand (operands[c], letter);
2536             
2537             while ((c = *p) >= '0' && c <= '9') p++;
2538           }
2539         /* % followed by a digit outputs an operand the default way.  */
2540         else if (*p >= '0' && *p <= '9')
2541           {
2542             c = atoi (p);
2543             if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2544               output_operand_lossage ("operand number out of range");
2545             else
2546               output_operand (operands[c], 0);
2547             while ((c = *p) >= '0' && c <= '9') p++;
2548           }
2549         /* % followed by punctuation: output something for that
2550            punctuation character alone, with no operand.
2551            The PRINT_OPERAND macro decides what is actually done.  */
2552 #ifdef PRINT_OPERAND_PUNCT_VALID_P
2553         else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
2554           output_operand (NULL_RTX, *p++);
2555 #endif
2556         else
2557           output_operand_lossage ("invalid %%-code");
2558         break;
2559
2560       default:
2561         putc (c, asm_out_file);
2562       }
2563
2564   output_asm_name ();
2565
2566   putc ('\n', asm_out_file);
2567 }
2568 \f
2569 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol.  */
2570
2571 void
2572 output_asm_label (x)
2573      rtx x;
2574 {
2575   char buf[256];
2576
2577   if (GET_CODE (x) == LABEL_REF)
2578     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2579   else if (GET_CODE (x) == CODE_LABEL)
2580     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2581   else
2582     output_operand_lossage ("`%l' operand isn't a label");
2583
2584   assemble_name (asm_out_file, buf);
2585 }
2586
2587 /* Print operand X using machine-dependent assembler syntax.
2588    The macro PRINT_OPERAND is defined just to control this function.
2589    CODE is a non-digit that preceded the operand-number in the % spec,
2590    such as 'z' if the spec was `%z3'.  CODE is 0 if there was no char
2591    between the % and the digits.
2592    When CODE is a non-letter, X is 0.
2593
2594    The meanings of the letters are machine-dependent and controlled
2595    by PRINT_OPERAND.  */
2596
2597 static void
2598 output_operand (x, code)
2599      rtx x;
2600      int code;
2601 {
2602   if (x && GET_CODE (x) == SUBREG)
2603     x = alter_subreg (x);
2604
2605   /* If X is a pseudo-register, abort now rather than writing trash to the
2606      assembler file.  */
2607
2608   if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2609     abort ();
2610
2611   PRINT_OPERAND (asm_out_file, x, code);
2612 }
2613
2614 /* Print a memory reference operand for address X
2615    using machine-dependent assembler syntax.
2616    The macro PRINT_OPERAND_ADDRESS exists just to control this function.  */
2617
2618 void
2619 output_address (x)
2620      rtx x;
2621 {
2622   walk_alter_subreg (x);
2623   PRINT_OPERAND_ADDRESS (asm_out_file, x);
2624 }
2625 \f
2626 /* Print an integer constant expression in assembler syntax.
2627    Addition and subtraction are the only arithmetic
2628    that may appear in these expressions.  */
2629
2630 void
2631 output_addr_const (file, x)
2632      FILE *file;
2633      rtx x;
2634 {
2635   char buf[256];
2636
2637  restart:
2638   switch (GET_CODE (x))
2639     {
2640     case PC:
2641       if (flag_pic)
2642         putc ('.', file);
2643       else
2644         abort ();
2645       break;
2646
2647     case SYMBOL_REF:
2648       assemble_name (file, XSTR (x, 0));
2649       break;
2650
2651     case LABEL_REF:
2652       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2653       assemble_name (file, buf);
2654       break;
2655
2656     case CODE_LABEL:
2657       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2658       assemble_name (file, buf);
2659       break;
2660
2661     case CONST_INT:
2662       fprintf (file,
2663 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2664                "%d",
2665 #else
2666                "%ld",
2667 #endif
2668                INTVAL (x));
2669       break;
2670
2671     case CONST:
2672       /* This used to output parentheses around the expression,
2673          but that does not work on the 386 (either ATT or BSD assembler).  */
2674       output_addr_const (file, XEXP (x, 0));
2675       break;
2676
2677     case CONST_DOUBLE:
2678       if (GET_MODE (x) == VOIDmode)
2679         {
2680           /* We can use %d if the number is one word and positive.  */
2681           if (CONST_DOUBLE_HIGH (x))
2682             fprintf (file,
2683 #if HOST_BITS_PER_WIDE_INT == 64
2684 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2685                      "0x%lx%016lx",
2686 #else
2687                      "0x%x%016x",
2688 #endif
2689 #else
2690 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2691                      "0x%lx%08lx",
2692 #else
2693                      "0x%x%08x",
2694 #endif
2695 #endif
2696                      CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2697           else if  (CONST_DOUBLE_LOW (x) < 0)
2698             fprintf (file,
2699 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2700                      "0x%x",
2701 #else
2702                      "0x%lx",
2703 #endif
2704                      CONST_DOUBLE_LOW (x));
2705           else
2706             fprintf (file,
2707 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2708                      "%d",
2709 #else
2710                      "%ld",
2711 #endif
2712                      CONST_DOUBLE_LOW (x));
2713         }
2714       else
2715         /* We can't handle floating point constants;
2716            PRINT_OPERAND must handle them.  */
2717         output_operand_lossage ("floating constant misused");
2718       break;
2719
2720     case PLUS:
2721       /* Some assemblers need integer constants to appear last (eg masm).  */
2722       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2723         {
2724           output_addr_const (file, XEXP (x, 1));
2725           if (INTVAL (XEXP (x, 0)) >= 0)
2726             fprintf (file, "+");
2727           output_addr_const (file, XEXP (x, 0));
2728         }
2729       else
2730         {
2731           output_addr_const (file, XEXP (x, 0));
2732           if (INTVAL (XEXP (x, 1)) >= 0)
2733             fprintf (file, "+");
2734           output_addr_const (file, XEXP (x, 1));
2735         }
2736       break;
2737
2738     case MINUS:
2739       /* Avoid outputting things like x-x or x+5-x,
2740          since some assemblers can't handle that.  */
2741       x = simplify_subtraction (x);
2742       if (GET_CODE (x) != MINUS)
2743         goto restart;
2744
2745       output_addr_const (file, XEXP (x, 0));
2746       fprintf (file, "-");
2747       if (GET_CODE (XEXP (x, 1)) == CONST_INT
2748           && INTVAL (XEXP (x, 1)) < 0)
2749         {
2750           fprintf (file, ASM_OPEN_PAREN);
2751           output_addr_const (file, XEXP (x, 1));
2752           fprintf (file, ASM_CLOSE_PAREN);
2753         }
2754       else
2755         output_addr_const (file, XEXP (x, 1));
2756       break;
2757
2758     case ZERO_EXTEND:
2759     case SIGN_EXTEND:
2760       output_addr_const (file, XEXP (x, 0));
2761       break;
2762
2763     default:
2764       output_operand_lossage ("invalid expression as operand");
2765     }
2766 }
2767 \f
2768 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
2769    %R prints the value of REGISTER_PREFIX.
2770    %L prints the value of LOCAL_LABEL_PREFIX.
2771    %U prints the value of USER_LABEL_PREFIX.
2772    %I prints the value of IMMEDIATE_PREFIX.
2773    %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
2774    Also supported are %d, %x, %s, %e, %f, %g and %%.
2775
2776    We handle alternate assembler dialects here, just like output_asm_insn.  */
2777
2778 void
2779 asm_fprintf VPROTO((FILE *file, char *p, ...))
2780 {
2781 #ifndef __STDC__
2782   FILE *file;
2783   char *p;
2784 #endif
2785   va_list argptr;
2786   char buf[10];
2787   char *q, c;
2788   int i;
2789
2790   VA_START (argptr, p);
2791
2792 #ifndef __STDC__
2793   file = va_arg (argptr, FILE *);
2794   p = va_arg (argptr, char *);
2795 #endif
2796
2797   buf[0] = '%';
2798
2799   while (c = *p++)
2800     switch (c)
2801       {
2802 #ifdef ASSEMBLER_DIALECT
2803       case '{':
2804         /* If we want the first dialect, do nothing.  Otherwise, skip
2805            DIALECT_NUMBER of strings ending with '|'.  */
2806         for (i = 0; i < dialect_number; i++)
2807           {
2808             while (*p && *p++ != '|')
2809               ;
2810
2811             if (*p == '|')
2812               p++;
2813           }
2814         break;
2815
2816       case '|':
2817         /* Skip to close brace.  */
2818         while (*p && *p++ != '}')
2819           ;
2820         break;
2821
2822       case '}':
2823         break;
2824 #endif
2825
2826       case '%':
2827         c = *p++;
2828         q = &buf[1];
2829         while ((c >= '0' && c <= '9') || c == '.')
2830           {
2831             *q++ = c;
2832             c = *p++;
2833           }
2834         switch (c)
2835           {
2836           case '%':
2837             fprintf (file, "%%");
2838             break;
2839
2840           case 'd':  case 'i':  case 'u':
2841           case 'x':  case 'p':  case 'X':
2842           case 'o':
2843             *q++ = c;
2844             *q = 0;
2845             fprintf (file, buf, va_arg (argptr, int));
2846             break;
2847
2848           case 'w':
2849             /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
2850                but we do not check for those cases.  It means that the value
2851                is a HOST_WIDE_INT, which may be either `int' or `long'.  */
2852
2853 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2854             *q++ = 'l';
2855 #endif
2856
2857             *q++ = *p++;
2858             *q = 0;
2859             fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
2860             break;
2861
2862           case 'l':
2863             *q++ = c;
2864             *q++ = *p++;
2865             *q = 0;
2866             fprintf (file, buf, va_arg (argptr, long));
2867             break;
2868
2869           case 'e':
2870           case 'f':
2871           case 'g':
2872             *q++ = c;
2873             *q = 0;
2874             fprintf (file, buf, va_arg (argptr, double));
2875             break;
2876
2877           case 's':
2878             *q++ = c;
2879             *q = 0;
2880             fprintf (file, buf, va_arg (argptr, char *));
2881             break;
2882
2883           case 'O':
2884 #ifdef ASM_OUTPUT_OPCODE
2885             ASM_OUTPUT_OPCODE (asm_out_file, p);
2886 #endif
2887             break;
2888
2889           case 'R':
2890 #ifdef REGISTER_PREFIX
2891             fprintf (file, "%s", REGISTER_PREFIX);
2892 #endif
2893             break;
2894
2895           case 'I':
2896 #ifdef IMMEDIATE_PREFIX
2897             fprintf (file, "%s", IMMEDIATE_PREFIX);
2898 #endif
2899             break;
2900
2901           case 'L':
2902 #ifdef LOCAL_LABEL_PREFIX
2903             fprintf (file, "%s", LOCAL_LABEL_PREFIX);
2904 #endif
2905             break;
2906
2907           case 'U':
2908 #ifdef USER_LABEL_PREFIX
2909             fprintf (file, "%s", USER_LABEL_PREFIX);
2910 #endif
2911             break;
2912
2913           default:
2914             abort ();
2915           }
2916         break;
2917
2918       default:
2919         fputc (c, file);
2920       }
2921 }
2922 \f
2923 /* Split up a CONST_DOUBLE or integer constant rtx
2924    into two rtx's for single words,
2925    storing in *FIRST the word that comes first in memory in the target
2926    and in *SECOND the other.  */
2927
2928 void
2929 split_double (value, first, second)
2930      rtx value;
2931      rtx *first, *second;
2932 {
2933   if (GET_CODE (value) == CONST_INT)
2934     {
2935       if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
2936         {
2937           /* In this case the CONST_INT holds both target words.
2938              Extract the bits from it into two word-sized pieces.  */
2939           rtx low, high;
2940           HOST_WIDE_INT word_mask;
2941           /* Avoid warnings for shift count >= BITS_PER_WORD.  */
2942           int shift_count = BITS_PER_WORD - 1;
2943
2944           word_mask = (HOST_WIDE_INT) 1 << shift_count;
2945           word_mask |= word_mask - 1;
2946           low = GEN_INT (INTVAL (value) & word_mask);
2947           high = GEN_INT ((INTVAL (value) >> (shift_count + 1)) & word_mask);
2948           if (WORDS_BIG_ENDIAN)
2949             {
2950               *first = high;
2951               *second = low;
2952             }
2953           else
2954             {
2955               *first = low;
2956               *second = high;
2957             }
2958         }
2959       else
2960         {
2961           /* The rule for using CONST_INT for a wider mode
2962              is that we regard the value as signed.
2963              So sign-extend it.  */
2964           rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
2965           if (WORDS_BIG_ENDIAN)
2966             {
2967               *first = high;
2968               *second = value;
2969             }
2970           else
2971             {
2972               *first = value;
2973               *second = high;
2974             }
2975         }
2976     }
2977   else if (GET_CODE (value) != CONST_DOUBLE)
2978     {
2979       if (WORDS_BIG_ENDIAN)
2980         {
2981           *first = const0_rtx;
2982           *second = value;
2983         }
2984       else
2985         {
2986           *first = value;
2987           *second = const0_rtx;
2988         }
2989     }
2990   else if (GET_MODE (value) == VOIDmode
2991            /* This is the old way we did CONST_DOUBLE integers.  */
2992            || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
2993     {
2994       /* In an integer, the words are defined as most and least significant.
2995          So order them by the target's convention.  */
2996       if (WORDS_BIG_ENDIAN)
2997         {
2998           *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2999           *second = GEN_INT (CONST_DOUBLE_LOW (value));
3000         }
3001       else
3002         {
3003           *first = GEN_INT (CONST_DOUBLE_LOW (value));
3004           *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3005         }
3006     }
3007   else
3008     {
3009 #ifdef REAL_ARITHMETIC
3010       REAL_VALUE_TYPE r; long l[2];
3011       REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3012
3013       /* Note, this converts the REAL_VALUE_TYPE to the target's
3014          format, splits up the floating point double and outputs
3015          exactly 32 bits of it into each of l[0] and l[1] --
3016          not necessarily BITS_PER_WORD bits.  */
3017       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3018
3019       *first = GEN_INT ((HOST_WIDE_INT) l[0]);
3020       *second = GEN_INT ((HOST_WIDE_INT) l[1]);
3021 #else
3022       if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3023            || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3024           && ! flag_pretend_float)
3025       abort ();
3026
3027       if (
3028 #ifdef HOST_WORDS_BIG_ENDIAN
3029           WORDS_BIG_ENDIAN
3030 #else
3031           ! WORDS_BIG_ENDIAN
3032 #endif
3033           )
3034         {
3035           /* Host and target agree => no need to swap.  */
3036           *first = GEN_INT (CONST_DOUBLE_LOW (value));
3037           *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3038         }
3039       else
3040         {
3041           *second = GEN_INT (CONST_DOUBLE_LOW (value));
3042           *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3043         }
3044 #endif /* no REAL_ARITHMETIC */
3045     }
3046 }
3047 \f
3048 /* Return nonzero if this function has no function calls.  */
3049
3050 int
3051 leaf_function_p ()
3052 {
3053   rtx insn;
3054
3055   if (profile_flag || profile_block_flag)
3056     return 0;
3057
3058   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3059     {
3060       if (GET_CODE (insn) == CALL_INSN)
3061         return 0;
3062       if (GET_CODE (insn) == INSN
3063           && GET_CODE (PATTERN (insn)) == SEQUENCE
3064           && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN)
3065         return 0;
3066     }
3067   for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
3068     {
3069       if (GET_CODE (XEXP (insn, 0)) == CALL_INSN)
3070         return 0;
3071       if (GET_CODE (XEXP (insn, 0)) == INSN
3072           && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
3073           && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN)
3074         return 0;
3075     }
3076
3077   return 1;
3078 }
3079
3080 /* On some machines, a function with no call insns
3081    can run faster if it doesn't create its own register window.
3082    When output, the leaf function should use only the "output"
3083    registers.  Ordinarily, the function would be compiled to use
3084    the "input" registers to find its arguments; it is a candidate
3085    for leaf treatment if it uses only the "input" registers.
3086    Leaf function treatment means renumbering so the function
3087    uses the "output" registers instead.  */
3088
3089 #ifdef LEAF_REGISTERS
3090
3091 static char permitted_reg_in_leaf_functions[] = LEAF_REGISTERS;
3092
3093 /* Return 1 if this function uses only the registers that can be
3094    safely renumbered.  */
3095
3096 int
3097 only_leaf_regs_used ()
3098 {
3099   int i;
3100
3101   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3102     {
3103       if ((regs_ever_live[i] || global_regs[i])
3104           && ! permitted_reg_in_leaf_functions[i])
3105         return 0;
3106     }
3107   return 1;
3108 }
3109
3110 /* Scan all instructions and renumber all registers into those
3111    available in leaf functions.  */
3112
3113 static void
3114 leaf_renumber_regs (first)
3115      rtx first;
3116 {
3117   rtx insn;
3118
3119   /* Renumber only the actual patterns.
3120      The reg-notes can contain frame pointer refs,
3121      and renumbering them could crash, and should not be needed.  */
3122   for (insn = first; insn; insn = NEXT_INSN (insn))
3123     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3124       leaf_renumber_regs_insn (PATTERN (insn));
3125   for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
3126     if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
3127       leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
3128 }
3129
3130 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
3131    available in leaf functions.  */
3132
3133 void
3134 leaf_renumber_regs_insn (in_rtx)
3135      register rtx in_rtx;
3136 {
3137   register int i, j;
3138   register char *format_ptr;
3139
3140   if (in_rtx == 0)
3141     return;
3142
3143   /* Renumber all input-registers into output-registers.
3144      renumbered_regs would be 1 for an output-register;
3145      they  */
3146
3147   if (GET_CODE (in_rtx) == REG)
3148     {
3149       int newreg;
3150
3151       /* Don't renumber the same reg twice.  */
3152       if (in_rtx->used)
3153         return;
3154
3155       newreg = REGNO (in_rtx);
3156       /* Don't try to renumber pseudo regs.  It is possible for a pseudo reg
3157          to reach here as part of a REG_NOTE.  */
3158       if (newreg >= FIRST_PSEUDO_REGISTER)
3159         {
3160           in_rtx->used = 1;
3161           return;
3162         }
3163       newreg = LEAF_REG_REMAP (newreg);
3164       if (newreg < 0)
3165         abort ();
3166       regs_ever_live[REGNO (in_rtx)] = 0;
3167       regs_ever_live[newreg] = 1;
3168       REGNO (in_rtx) = newreg;
3169       in_rtx->used = 1;
3170     }
3171
3172   if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
3173     {
3174       /* Inside a SEQUENCE, we find insns.
3175          Renumber just the patterns of these insns,
3176          just as we do for the top-level insns.  */
3177       leaf_renumber_regs_insn (PATTERN (in_rtx));
3178       return;
3179     }
3180
3181   format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
3182
3183   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
3184     switch (*format_ptr++)
3185       {
3186       case 'e':
3187         leaf_renumber_regs_insn (XEXP (in_rtx, i));
3188         break;
3189
3190       case 'E':
3191         if (NULL != XVEC (in_rtx, i))
3192           {
3193             for (j = 0; j < XVECLEN (in_rtx, i); j++)
3194               leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
3195           }
3196         break;
3197
3198       case 'S':
3199       case 's':
3200       case '0':
3201       case 'i':
3202       case 'w':
3203       case 'n':
3204       case 'u':
3205         break;
3206
3207       default:
3208         abort ();
3209       }
3210 }
3211 #endif