OSDN Git Service

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