OSDN Git Service

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