OSDN Git Service

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