OSDN Git Service

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