OSDN Git Service

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