OSDN Git Service

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