OSDN Git Service

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