OSDN Git Service

Convert ACCUMULATE_OUTGOING_ARGS to an expression.
[pf3gnuchains/gcc-fork.git] / gcc / final.c
1 /* Convert RTL to assembler code and output it, for GNU compiler.
2    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3    1998, 1999, 2000 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 /* This is the final pass of the compiler.
24    It looks at the rtl code for a function and outputs assembler code.
25
26    Call `final_start_function' to output the assembler code for function entry,
27    `final' to output assembler code for some RTL code,
28    `final_end_function' to output assembler code for function exit.
29    If a function is compiled in several pieces, each piece is
30    output separately with `final'.
31
32    Some optimizations are also done at this level.
33    Move instructions that were made unnecessary by good register allocation
34    are detected and omitted from the output.  (Though most of these
35    are removed by the last jump pass.)
36
37    Instructions to set the condition codes are omitted when it can be
38    seen that the condition codes already had the desired values.
39
40    In some cases it is sufficient if the inherited condition codes
41    have related values, but this may require the following insn
42    (the one that tests the condition codes) to be modified.
43
44    The code for the function prologue and epilogue are generated
45    directly as assembler code by the macros FUNCTION_PROLOGUE and
46    FUNCTION_EPILOGUE.  Those instructions never exist as rtl.  */
47
48 #include "config.h"
49 #include "system.h"
50
51 #include "tree.h"
52 #include "rtl.h"
53 #include "tm_p.h"
54 #include "regs.h"
55 #include "insn-config.h"
56 #include "insn-flags.h"
57 #include "insn-attr.h"
58 #include "insn-codes.h"
59 #include "recog.h"
60 #include "conditions.h"
61 #include "flags.h"
62 #include "real.h"
63 #include "hard-reg-set.h"
64 #include "defaults.h"
65 #include "output.h"
66 #include "except.h"
67 #include "function.h"
68 #include "toplev.h"
69 #include "reload.h"
70 #include "intl.h"
71
72 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist.  */
73 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
74 #include "dbxout.h"
75 #if defined (USG) || !defined (HAVE_STAB_H)
76 #include "gstab.h"  /* If doing DBX on sysV, use our own stab.h.  */
77 #else
78 #include <stab.h>
79 #endif
80
81 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
82
83 #ifndef ACCUMULATE_OUTGOING_ARGS
84 #define ACCUMULATE_OUTGOING_ARGS 0
85 #endif
86
87 #ifdef XCOFF_DEBUGGING_INFO
88 #include "xcoffout.h"
89 #endif
90
91 #ifdef DWARF_DEBUGGING_INFO
92 #include "dwarfout.h"
93 #endif
94
95 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
96 #include "dwarf2out.h"
97 #endif
98
99 #ifdef SDB_DEBUGGING_INFO
100 #include "sdbout.h"
101 #endif
102
103 /* .stabd code for line number.  */
104 #ifndef N_SLINE
105 #define N_SLINE 0x44
106 #endif
107
108 /* .stabs code for included file name.  */
109 #ifndef N_SOL
110 #define N_SOL 0x84
111 #endif
112
113 #ifndef INT_TYPE_SIZE
114 #define INT_TYPE_SIZE BITS_PER_WORD
115 #endif
116
117 #ifndef LONG_TYPE_SIZE
118 #define LONG_TYPE_SIZE BITS_PER_WORD
119 #endif
120
121 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist.  So define a
122    null default for it to save conditionalization later.  */
123 #ifndef CC_STATUS_INIT
124 #define CC_STATUS_INIT
125 #endif
126
127 /* How to start an assembler comment.  */
128 #ifndef ASM_COMMENT_START
129 #define ASM_COMMENT_START ";#"
130 #endif
131
132 /* Is the given character a logical line separator for the assembler?  */
133 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
134 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
135 #endif
136
137 #ifndef JUMP_TABLES_IN_TEXT_SECTION
138 #define JUMP_TABLES_IN_TEXT_SECTION 0
139 #endif
140
141 /* Last insn processed by final_scan_insn.  */
142 static rtx debug_insn = 0;
143
144 /* Line number of last NOTE.  */
145 static int last_linenum;
146
147 /* Highest line number in current block.  */
148 static int high_block_linenum;
149
150 /* Likewise for function.  */
151 static int high_function_linenum;
152
153 /* Filename of last NOTE.  */
154 static const char *last_filename;
155
156 /* Number of basic blocks seen so far;
157    used if profile_block_flag is set.  */
158 static int count_basic_blocks;
159
160 /* Number of instrumented arcs when profile_arc_flag is set.  */
161 extern int count_instrumented_arcs;
162
163 extern int length_unit_log; /* This is defined in insn-attrtab.c.  */
164
165 /* Nonzero while outputting an `asm' with operands.
166    This means that inconsistencies are the user's fault, so don't abort.
167    The precise value is the insn being output, to pass to error_for_asm.  */
168 static rtx this_is_asm_operands;
169
170 /* Number of operands of this insn, for an `asm' with operands.  */
171 static unsigned int insn_noperands;
172
173 /* Compare optimization flag.  */
174
175 static rtx last_ignored_compare = 0;
176
177 /* Flag indicating this insn is the start of a new basic block.  */
178
179 static int new_block = 1;
180
181 /* Assign a unique number to each insn that is output.
182    This can be used to generate unique local labels.  */
183
184 static int insn_counter = 0;
185
186 #ifdef HAVE_cc0
187 /* This variable contains machine-dependent flags (defined in tm.h)
188    set and examined by output routines
189    that describe how to interpret the condition codes properly.  */
190
191 CC_STATUS cc_status;
192
193 /* During output of an insn, this contains a copy of cc_status
194    from before the insn.  */
195
196 CC_STATUS cc_prev_status;
197 #endif
198
199 /* Indexed by hardware reg number, is 1 if that register is ever
200    used in the current function.
201
202    In life_analysis, or in stupid_life_analysis, this is set
203    up to record the hard regs used explicitly.  Reload adds
204    in the hard regs used for holding pseudo regs.  Final uses
205    it to generate the code in the function prologue and epilogue
206    to save and restore registers as needed.  */
207
208 char regs_ever_live[FIRST_PSEUDO_REGISTER];
209
210 /* Nonzero means current function must be given a frame pointer.
211    Set in stmt.c if anything is allocated on the stack there.
212    Set in reload1.c if anything is allocated on the stack there.  */
213
214 int frame_pointer_needed;
215
216 /* Assign unique numbers to labels generated for profiling.  */
217
218 int profile_label_no;
219
220 /* Number of unmatched NOTE_INSN_BLOCK_BEG notes we have seen.  */
221
222 static int block_depth;
223
224 /* Nonzero if have enabled APP processing of our assembler output.  */
225
226 static int app_on;
227
228 /* If we are outputting an insn sequence, this contains the sequence rtx.
229    Zero otherwise.  */
230
231 rtx final_sequence;
232
233 #ifdef ASSEMBLER_DIALECT
234
235 /* Number of the assembler dialect to use, starting at 0.  */
236 static int dialect_number;
237 #endif
238
239 /* Indexed by line number, nonzero if there is a note for that line.  */
240
241 static char *line_note_exists;
242
243 /* Linked list to hold line numbers for each basic block.  */
244
245 struct bb_list {
246   struct bb_list *next;         /* pointer to next basic block */
247   int line_num;                 /* line number */
248   int file_label_num;           /* LPBC<n> label # for stored filename */
249   int func_label_num;           /* LPBC<n> label # for stored function name */
250 };
251
252 static struct bb_list *bb_head  = 0;            /* Head of basic block list */
253 static struct bb_list **bb_tail = &bb_head;     /* Ptr to store next bb ptr */
254 static int bb_file_label_num    = -1;           /* Current label # for file */
255 static int bb_func_label_num    = -1;           /* Current label # for func */
256
257 /* Linked list to hold the strings for each file and function name output.  */
258
259 struct bb_str {
260   struct bb_str *next;          /* pointer to next string */
261   const char *string;           /* string */
262   int label_num;                /* label number */
263   int length;                   /* string length */
264 };
265
266 static struct bb_str *sbb_head  = 0;            /* Head of string list.  */
267 static struct bb_str **sbb_tail = &sbb_head;    /* Ptr to store next bb str */
268 static int sbb_label_num        = 0;            /* Last label used */
269
270 #ifdef HAVE_ATTR_length
271 static int asm_insn_count       PARAMS ((rtx));
272 #endif
273 static void profile_function    PARAMS ((FILE *));
274 static void profile_after_prologue PARAMS ((FILE *));
275 static void add_bb              PARAMS ((FILE *));
276 static int add_bb_string        PARAMS ((const char *, int));
277 static void output_source_line  PARAMS ((FILE *, rtx));
278 static rtx walk_alter_subreg    PARAMS ((rtx));
279 static void output_asm_name     PARAMS ((void));
280 static void output_operand      PARAMS ((rtx, int));
281 #ifdef LEAF_REGISTERS
282 static void leaf_renumber_regs  PARAMS ((rtx));
283 #endif
284 #ifdef HAVE_cc0
285 static int alter_cond           PARAMS ((rtx));
286 #endif
287 #ifndef ADDR_VEC_ALIGN
288 static int final_addr_vec_align PARAMS ((rtx));
289 #endif
290 #ifdef HAVE_ATTR_length
291 static int align_fuzz           PARAMS ((rtx, rtx, int, unsigned));
292 #endif
293 \f
294 /* Initialize data in final at the beginning of a compilation.  */
295
296 void
297 init_final (filename)
298      const char *filename ATTRIBUTE_UNUSED;
299 {
300   app_on = 0;
301   final_sequence = 0;
302
303 #ifdef ASSEMBLER_DIALECT
304   dialect_number = ASSEMBLER_DIALECT;
305 #endif
306 }
307
308 /* Called at end of source file,
309    to output the block-profiling table for this entire compilation.  */
310
311 void
312 end_final (filename)
313   const char *filename;
314 {
315   int i;
316
317   if (profile_block_flag || profile_arc_flag)
318     {
319       char name[20];
320       int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
321       int size, rounded;
322       struct bb_list *ptr;
323       struct bb_str *sptr;
324       int long_bytes = LONG_TYPE_SIZE / BITS_PER_UNIT;
325       int pointer_bytes = POINTER_SIZE / BITS_PER_UNIT;
326
327       if (profile_block_flag)
328         size = long_bytes * count_basic_blocks;
329       else
330         size = long_bytes * count_instrumented_arcs;
331       rounded = size;
332
333       rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
334       rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
335                  * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
336
337       data_section ();
338
339       /* Output the main header, of 11 words:
340          0:  1 if this file is initialized, else 0.
341          1:  address of file name (LPBX1).
342          2:  address of table of counts (LPBX2).
343          3:  number of counts in the table.
344          4:  always 0, for compatibility with Sun.
345
346          The following are GNU extensions:
347
348          5:  address of table of start addrs of basic blocks (LPBX3).
349          6:  Number of bytes in this header.
350          7:  address of table of function names (LPBX4).
351          8:  address of table of line numbers (LPBX5) or 0.
352          9:  address of table of file names (LPBX6) or 0.
353         10:  space reserved for basic block profiling.  */
354
355       ASM_OUTPUT_ALIGN (asm_out_file, align);
356
357       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
358       /* zero word */
359       assemble_integer (const0_rtx, long_bytes, 1);
360
361       /* address of filename */
362       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
363       assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
364
365       /* address of count table */
366       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
367       assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
368
369       /* count of the # of basic blocks or # of instrumented arcs */
370       if (profile_block_flag)
371         assemble_integer (GEN_INT (count_basic_blocks), long_bytes, 1);
372       else
373         assemble_integer (GEN_INT (count_instrumented_arcs), long_bytes,
374                           1);
375
376       /* zero word (link field) */
377       assemble_integer (const0_rtx, pointer_bytes, 1);
378
379       /* address of basic block start address table */
380       if (profile_block_flag)
381         {
382           ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
383           assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
384                             1);
385         }
386       else
387         assemble_integer (const0_rtx, pointer_bytes, 1);
388
389       /* byte count for extended structure.  */
390       assemble_integer (GEN_INT (11 * UNITS_PER_WORD), long_bytes, 1);
391
392       /* address of function name table */
393       if (profile_block_flag)
394         {
395           ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
396           assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
397                             1);
398         }
399       else
400         assemble_integer (const0_rtx, pointer_bytes, 1);
401
402       /* address of line number and filename tables if debugging.  */
403       if (write_symbols != NO_DEBUG && profile_block_flag)
404         {
405           ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
406           assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
407                             pointer_bytes, 1);
408           ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
409           assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
410                             pointer_bytes, 1);
411         }
412       else
413         {
414           assemble_integer (const0_rtx, pointer_bytes, 1);
415           assemble_integer (const0_rtx, pointer_bytes, 1);
416         }
417
418       /* space for extension ptr (link field) */
419       assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
420
421       /* Output the file name changing the suffix to .d for Sun tcov
422          compatibility.  */
423       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
424       {
425         char *cwd = getpwd ();
426         int len = strlen (filename) + strlen (cwd) + 1;
427         char *data_file = (char *) alloca (len + 4);
428
429         strcpy (data_file, cwd);
430         strcat (data_file, "/");
431         strcat (data_file, filename);
432         strip_off_ending (data_file, len);
433         if (profile_block_flag)
434           strcat (data_file, ".d");
435         else
436           strcat (data_file, ".da");
437         assemble_string (data_file, strlen (data_file) + 1);
438       }
439
440       /* Make space for the table of counts.  */
441       if (size == 0)
442         {
443           /* Realign data section.  */
444           ASM_OUTPUT_ALIGN (asm_out_file, align);
445           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
446           if (size != 0)
447             assemble_zeros (size);
448         }
449       else
450         {
451           ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
452 #ifdef ASM_OUTPUT_SHARED_LOCAL
453           if (flag_shared_data)
454             ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
455           else
456 #endif
457 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
458             ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
459                                               BIGGEST_ALIGNMENT);
460 #else
461 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
462             ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
463                                       BIGGEST_ALIGNMENT);
464 #else
465             ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
466 #endif
467 #endif
468         }
469
470       /* Output any basic block strings */
471       if (profile_block_flag)
472         {
473           readonly_data_section ();
474           if (sbb_head)
475             {
476               ASM_OUTPUT_ALIGN (asm_out_file, align);
477               for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
478                 {
479                   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC",
480                                              sptr->label_num);
481                   assemble_string (sptr->string, sptr->length);
482                 }
483             }
484         }
485
486       /* Output the table of addresses.  */
487       if (profile_block_flag)
488         {
489           /* Realign in new section */
490           ASM_OUTPUT_ALIGN (asm_out_file, align);
491           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
492           for (i = 0; i < count_basic_blocks; i++)
493             {
494               ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
495               assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
496                                 pointer_bytes, 1);
497             }
498         }
499
500       /* Output the table of function names.  */
501       if (profile_block_flag)
502         {
503           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
504           for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
505             {
506               if (ptr->func_label_num >= 0)
507                 {
508                   ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
509                                                ptr->func_label_num);
510                   assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
511                                     pointer_bytes, 1);
512                 }
513               else
514                 assemble_integer (const0_rtx, pointer_bytes, 1);
515             }
516
517           for ( ; i < count_basic_blocks; i++)
518             assemble_integer (const0_rtx, pointer_bytes, 1);
519         }
520
521       if (write_symbols != NO_DEBUG && profile_block_flag)
522         {
523           /* Output the table of line numbers.  */
524           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
525           for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
526             assemble_integer (GEN_INT (ptr->line_num), long_bytes, 1);
527
528           for ( ; i < count_basic_blocks; i++)
529             assemble_integer (const0_rtx, long_bytes, 1);
530
531           /* Output the table of file names.  */
532           ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
533           for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
534             {
535               if (ptr->file_label_num >= 0)
536                 {
537                   ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
538                                                ptr->file_label_num);
539                   assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
540                                     pointer_bytes, 1);
541                 }
542               else
543                 assemble_integer (const0_rtx, pointer_bytes, 1);
544             }
545
546           for ( ; i < count_basic_blocks; i++)
547             assemble_integer (const0_rtx, pointer_bytes, 1);
548         }
549
550       /* End with the address of the table of addresses,
551          so we can find it easily, as the last word in the file's text.  */
552       if (profile_block_flag)
553         {
554           ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
555           assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
556                             1);
557         }
558     }
559 }
560
561 /* Enable APP processing of subsequent output.
562    Used before the output from an `asm' statement.  */
563
564 void
565 app_enable ()
566 {
567   if (! app_on)
568     {
569       fputs (ASM_APP_ON, asm_out_file);
570       app_on = 1;
571     }
572 }
573
574 /* Disable APP processing of subsequent output.
575    Called from varasm.c before most kinds of output.  */
576
577 void
578 app_disable ()
579 {
580   if (app_on)
581     {
582       fputs (ASM_APP_OFF, asm_out_file);
583       app_on = 0;
584     }
585 }
586 \f
587 /* Return the number of slots filled in the current 
588    delayed branch sequence (we don't count the insn needing the
589    delay slot).   Zero if not in a delayed branch sequence.  */
590
591 #ifdef DELAY_SLOTS
592 int
593 dbr_sequence_length ()
594 {
595   if (final_sequence != 0)
596     return XVECLEN (final_sequence, 0) - 1;
597   else
598     return 0;
599 }
600 #endif
601 \f
602 /* The next two pages contain routines used to compute the length of an insn
603    and to shorten branches.  */
604
605 /* Arrays for insn lengths, and addresses.  The latter is referenced by
606    `insn_current_length'.  */
607
608 static short *insn_lengths;
609 int *insn_addresses;
610
611 /* Max uid for which the above arrays are valid.  */
612 static int insn_lengths_max_uid;
613
614 /* Address of insn being processed.  Used by `insn_current_length'.  */
615 int insn_current_address;
616
617 /* Address of insn being processed in previous iteration.  */
618 int insn_last_address;
619
620 /* konwn invariant alignment of insn being processed.  */
621 int insn_current_align;
622
623 /* After shorten_branches, for any insn, uid_align[INSN_UID (insn)]
624    gives the next following alignment insn that increases the known
625    alignment, or NULL_RTX if there is no such insn.
626    For any alignment obtained this way, we can again index uid_align with
627    its uid to obtain the next following align that in turn increases the
628    alignment, till we reach NULL_RTX; the sequence obtained this way
629    for each insn we'll call the alignment chain of this insn in the following
630    comments.  */
631
632 struct label_alignment {
633   short alignment;
634   short max_skip;
635 };
636
637 static rtx *uid_align;
638 static int *uid_shuid;
639 static struct label_alignment *label_align;
640
641 /* Indicate that branch shortening hasn't yet been done.  */
642
643 void
644 init_insn_lengths ()
645 {
646   if (label_align)
647     {
648       free (label_align);
649       label_align = 0;
650     }
651   if (uid_shuid)
652     {
653       free (uid_shuid);
654       uid_shuid = 0;
655     }
656   if (insn_lengths)
657     {
658       free (insn_lengths);
659       insn_lengths = 0;
660       insn_lengths_max_uid = 0;
661     }
662   if (insn_addresses)
663     {
664       free (insn_addresses);
665       insn_addresses = 0;
666     }
667   if (uid_align)
668     {
669       free (uid_align);
670       uid_align = 0;
671     }
672 }
673
674 /* Obtain the current length of an insn.  If branch shortening has been done,
675    get its actual length.  Otherwise, get its maximum length.  */
676
677 int
678 get_attr_length (insn)
679      rtx insn ATTRIBUTE_UNUSED;
680 {
681 #ifdef HAVE_ATTR_length
682   rtx body;
683   int i;
684   int length = 0;
685
686   if (insn_lengths_max_uid > INSN_UID (insn))
687     return insn_lengths[INSN_UID (insn)];
688   else
689     switch (GET_CODE (insn))
690       {
691       case NOTE:
692       case BARRIER:
693       case CODE_LABEL:
694         return 0;
695
696       case CALL_INSN:
697         length = insn_default_length (insn);
698         break;
699
700       case JUMP_INSN:
701         body = PATTERN (insn);
702         if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
703           {
704             /* Alignment is machine-dependent and should be handled by
705                ADDR_VEC_ALIGN.  */
706           }
707         else
708           length = insn_default_length (insn);
709         break;
710
711       case INSN:
712         body = PATTERN (insn);
713         if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
714           return 0;
715
716         else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
717           length = asm_insn_count (body) * insn_default_length (insn);
718         else if (GET_CODE (body) == SEQUENCE)
719           for (i = 0; i < XVECLEN (body, 0); i++)
720             length += get_attr_length (XVECEXP (body, 0, i));
721         else
722           length = insn_default_length (insn);
723         break;
724
725       default:
726         break;
727       }
728
729 #ifdef ADJUST_INSN_LENGTH
730   ADJUST_INSN_LENGTH (insn, length);
731 #endif
732   return length;
733 #else /* not HAVE_ATTR_length */
734   return 0;
735 #endif /* not HAVE_ATTR_length */
736 }
737 \f
738 /* Code to handle alignment inside shorten_branches.  */
739
740 /* Here is an explanation how the algorithm in align_fuzz can give
741    proper results:
742
743    Call a sequence of instructions beginning with alignment point X
744    and continuing until the next alignment point `block X'.  When `X'
745    is used in an expression, it means the alignment value of the 
746    alignment point.
747    
748    Call the distance between the start of the first insn of block X, and
749    the end of the last insn of block X `IX', for the `inner size of X'.
750    This is clearly the sum of the instruction lengths.
751    
752    Likewise with the next alignment-delimited block following X, which we
753    shall call block Y.
754    
755    Call the distance between the start of the first insn of block X, and
756    the start of the first insn of block Y `OX', for the `outer size of X'.
757    
758    The estimated padding is then OX - IX.
759    
760    OX can be safely estimated as
761    
762            if (X >= Y)
763                    OX = round_up(IX, Y)
764            else
765                    OX = round_up(IX, X) + Y - X
766    
767    Clearly est(IX) >= real(IX), because that only depends on the
768    instruction lengths, and those being overestimated is a given.
769    
770    Clearly round_up(foo, Z) >= round_up(bar, Z) if foo >= bar, so
771    we needn't worry about that when thinking about OX.
772    
773    When X >= Y, the alignment provided by Y adds no uncertainty factor
774    for branch ranges starting before X, so we can just round what we have.
775    But when X < Y, we don't know anything about the, so to speak,
776    `middle bits', so we have to assume the worst when aligning up from an
777    address mod X to one mod Y, which is Y - X.  */
778
779 #ifndef LABEL_ALIGN
780 #define LABEL_ALIGN(LABEL) align_labels_log
781 #endif
782
783 #ifndef LABEL_ALIGN_MAX_SKIP
784 #define LABEL_ALIGN_MAX_SKIP (align_labels-1)
785 #endif
786
787 #ifndef LOOP_ALIGN
788 #define LOOP_ALIGN(LABEL) align_loops_log
789 #endif
790
791 #ifndef LOOP_ALIGN_MAX_SKIP
792 #define LOOP_ALIGN_MAX_SKIP (align_loops-1)
793 #endif
794
795 #ifndef LABEL_ALIGN_AFTER_BARRIER
796 #define LABEL_ALIGN_AFTER_BARRIER(LABEL) align_jumps_log
797 #endif
798
799 #ifndef LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP
800 #define LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP (align_jumps-1)
801 #endif
802
803 #ifndef ADDR_VEC_ALIGN
804 static int
805 final_addr_vec_align (addr_vec)
806      rtx addr_vec;
807 {
808   int align = exact_log2 (GET_MODE_SIZE (GET_MODE (PATTERN (addr_vec))));
809
810   if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
811     align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
812   return align;
813
814 }
815 #define ADDR_VEC_ALIGN(ADDR_VEC) final_addr_vec_align (ADDR_VEC)
816 #endif
817
818 #ifndef INSN_LENGTH_ALIGNMENT
819 #define INSN_LENGTH_ALIGNMENT(INSN) length_unit_log
820 #endif
821
822 #define INSN_SHUID(INSN) (uid_shuid[INSN_UID (INSN)])
823
824 static int min_labelno, max_labelno;
825
826 #define LABEL_TO_ALIGNMENT(LABEL) \
827   (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].alignment)
828
829 #define LABEL_TO_MAX_SKIP(LABEL) \
830   (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].max_skip)
831
832 /* For the benefit of port specific code do this also as a function.  */
833 int
834 label_to_alignment (label)
835      rtx label;
836 {
837   return LABEL_TO_ALIGNMENT (label);
838 }
839
840 #ifdef HAVE_ATTR_length
841 /* The differences in addresses
842    between a branch and its target might grow or shrink depending on
843    the alignment the start insn of the range (the branch for a forward
844    branch or the label for a backward branch) starts out on; if these
845    differences are used naively, they can even oscillate infinitely.
846    We therefore want to compute a 'worst case' address difference that
847    is independent of the alignment the start insn of the range end
848    up on, and that is at least as large as the actual difference.
849    The function align_fuzz calculates the amount we have to add to the
850    naively computed difference, by traversing the part of the alignment
851    chain of the start insn of the range that is in front of the end insn
852    of the range, and considering for each alignment the maximum amount
853    that it might contribute to a size increase.
854
855    For casesi tables, we also want to know worst case minimum amounts of
856    address difference, in case a machine description wants to introduce
857    some common offset that is added to all offsets in a table.
858    For this purpose, align_fuzz with a growth argument of 0 comuptes the
859    appropriate adjustment.  */
860
861
862 /* Compute the maximum delta by which the difference of the addresses of
863    START and END might grow / shrink due to a different address for start
864    which changes the size of alignment insns between START and END.
865    KNOWN_ALIGN_LOG is the alignment known for START.
866    GROWTH should be ~0 if the objective is to compute potential code size
867    increase, and 0 if the objective is to compute potential shrink.
868    The return value is undefined for any other value of GROWTH.  */
869 static int
870 align_fuzz (start, end, known_align_log, growth)
871      rtx start, end;
872      int known_align_log;
873      unsigned growth;
874 {
875   int uid = INSN_UID (start);
876   rtx align_label;
877   int known_align = 1 << known_align_log;
878   int end_shuid = INSN_SHUID (end);
879   int fuzz = 0;
880
881   for (align_label = uid_align[uid]; align_label; align_label = uid_align[uid])
882     {
883       int align_addr, new_align;
884
885       uid = INSN_UID (align_label);
886       align_addr = insn_addresses[uid] - insn_lengths[uid];
887       if (uid_shuid[uid] > end_shuid)
888         break;
889       known_align_log = LABEL_TO_ALIGNMENT (align_label);
890       new_align = 1 << known_align_log;
891       if (new_align < known_align)
892         continue;
893       fuzz += (-align_addr ^ growth) & (new_align - known_align);
894       known_align = new_align;
895     }
896   return fuzz;
897 }
898
899 /* Compute a worst-case reference address of a branch so that it
900    can be safely used in the presence of aligned labels.  Since the
901    size of the branch itself is unknown, the size of the branch is
902    not included in the range.  I.e. for a forward branch, the reference
903    address is the end address of the branch as known from the previous
904    branch shortening pass, minus a value to account for possible size
905    increase due to alignment.  For a backward branch, it is the start
906    address of the branch as known from the current pass, plus a value
907    to account for possible size increase due to alignment.
908    NB.: Therefore, the maximum offset allowed for backward branches needs
909    to exclude the branch size.  */
910 int
911 insn_current_reference_address (branch)
912      rtx branch;
913 {
914   rtx dest;
915   rtx seq = NEXT_INSN (PREV_INSN (branch));
916   int seq_uid = INSN_UID (seq);
917   if (GET_CODE (branch) != JUMP_INSN)
918     /* This can happen for example on the PA; the objective is to know the
919        offset to address something in front of the start of the function.
920        Thus, we can treat it like a backward branch.
921        We assume here that FUNCTION_BOUNDARY / BITS_PER_UNIT is larger than
922        any alignment we'd encounter, so we skip the call to align_fuzz.  */
923     return insn_current_address;
924   dest = JUMP_LABEL (branch);
925   /* BRANCH has no proper alignment chain set, so use SEQ.  */
926   if (INSN_SHUID (branch) < INSN_SHUID (dest))
927     {
928       /* Forward branch. */
929       return (insn_last_address + insn_lengths[seq_uid]
930               - align_fuzz (seq, dest, length_unit_log, ~0));
931     }
932   else
933     {
934       /* Backward branch. */
935       return (insn_current_address
936               + align_fuzz (dest, seq, length_unit_log, ~0));
937     }
938 }
939 #endif /* HAVE_ATTR_length */
940 \f
941 /* Make a pass over all insns and compute their actual lengths by shortening
942    any branches of variable length if possible.  */
943
944 /* Give a default value for the lowest address in a function.  */
945
946 #ifndef FIRST_INSN_ADDRESS
947 #define FIRST_INSN_ADDRESS 0
948 #endif
949
950 /* shorten_branches might be called multiple times:  for example, the SH
951    port splits out-of-range conditional branches in MACHINE_DEPENDENT_REORG.
952    In order to do this, it needs proper length information, which it obtains
953    by calling shorten_branches.  This cannot be collapsed with
954    shorten_branches itself into a single pass unless we also want to intergate
955    reorg.c, since the branch splitting exposes new instructions with delay
956    slots.  */
957
958 void
959 shorten_branches (first)
960      rtx first ATTRIBUTE_UNUSED;
961 {
962   rtx insn;
963   int max_uid;
964   int i;
965   int max_log;
966   int max_skip;
967 #ifdef HAVE_ATTR_length
968 #define MAX_CODE_ALIGN 16
969   rtx seq;
970   int something_changed = 1;
971   char *varying_length;
972   rtx body;
973   int uid;
974   rtx align_tab[MAX_CODE_ALIGN];
975
976   /* In order to make sure that all instructions have valid length info,
977      we must split them before we compute the address/length info.  */
978
979   for (insn = NEXT_INSN (first); insn; insn = NEXT_INSN (insn))
980     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
981       {
982         rtx old = insn;
983         /* Don't split the insn if it has been deleted.  */
984         if (! INSN_DELETED_P (old))
985           insn = try_split (PATTERN (old), old, 1);
986         /* When not optimizing, the old insn will be still left around
987            with only the 'deleted' bit set.  Transform it into a note
988            to avoid confusion of subsequent processing.  */
989         if (INSN_DELETED_P (old))
990           {
991             PUT_CODE (old , NOTE);
992             NOTE_LINE_NUMBER (old) = NOTE_INSN_DELETED;
993             NOTE_SOURCE_FILE (old) = 0;
994           }
995       }
996 #endif
997
998   /* We must do some computations even when not actually shortening, in
999      order to get the alignment information for the labels.  */
1000
1001   init_insn_lengths ();
1002
1003   /* Compute maximum UID and allocate label_align / uid_shuid.  */
1004   max_uid = get_max_uid ();
1005
1006   max_labelno = max_label_num ();
1007   min_labelno = get_first_label_num ();
1008   label_align = (struct label_alignment *)
1009     xcalloc ((max_labelno - min_labelno + 1), sizeof (struct label_alignment));
1010
1011   uid_shuid = (int *) xmalloc (max_uid * sizeof *uid_shuid);
1012
1013   /* Initialize label_align and set up uid_shuid to be strictly
1014      monotonically rising with insn order.  */
1015   /* We use max_log here to keep track of the maximum alignment we want to
1016      impose on the next CODE_LABEL (or the current one if we are processing
1017      the CODE_LABEL itself).  */
1018      
1019   max_log = 0;
1020   max_skip = 0;
1021
1022   for (insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn))
1023     {
1024       int log;
1025
1026       INSN_SHUID (insn) = i++;
1027       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1028         {
1029           /* reorg might make the first insn of a loop being run once only,
1030              and delete the label in front of it.  Then we want to apply
1031              the loop alignment to the new label created by reorg, which
1032              is separated by the former loop start insn from the
1033              NOTE_INSN_LOOP_BEG.  */
1034         }
1035       else if (GET_CODE (insn) == CODE_LABEL)
1036         {
1037           rtx next;
1038
1039           log = LABEL_ALIGN (insn);
1040           if (max_log < log)
1041             {
1042               max_log = log;
1043               max_skip = LABEL_ALIGN_MAX_SKIP;
1044             }
1045           next = NEXT_INSN (insn);
1046           /* ADDR_VECs only take room if read-only data goes into the text
1047              section.  */
1048           if (JUMP_TABLES_IN_TEXT_SECTION
1049 #if !defined(READONLY_DATA_SECTION)
1050               || 1
1051 #endif
1052               )
1053             if (next && GET_CODE (next) == JUMP_INSN)
1054               {
1055                 rtx nextbody = PATTERN (next);
1056                 if (GET_CODE (nextbody) == ADDR_VEC
1057                     || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1058                   {
1059                     log = ADDR_VEC_ALIGN (next);
1060                     if (max_log < log)
1061                       {
1062                         max_log = log;
1063                         max_skip = LABEL_ALIGN_MAX_SKIP;
1064                       }
1065                   }
1066               }
1067           LABEL_TO_ALIGNMENT (insn) = max_log;
1068           LABEL_TO_MAX_SKIP (insn) = max_skip;
1069           max_log = 0;
1070           max_skip = 0;
1071         }
1072       else if (GET_CODE (insn) == BARRIER)
1073         {
1074           rtx label;
1075
1076           for (label = insn; label && GET_RTX_CLASS (GET_CODE (label)) != 'i';
1077                label = NEXT_INSN (label))
1078             if (GET_CODE (label) == CODE_LABEL)
1079               {
1080                 log = LABEL_ALIGN_AFTER_BARRIER (insn);
1081                 if (max_log < log)
1082                   {
1083                     max_log = log;
1084                     max_skip = LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP;
1085                   }
1086                 break;
1087               }
1088         }
1089       /* Again, we allow NOTE_INSN_LOOP_BEG - INSN - CODE_LABEL
1090          sequences in order to handle reorg output efficiently.  */
1091       else if (GET_CODE (insn) == NOTE
1092                && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
1093         {
1094           rtx label;
1095           int nest = 0;
1096
1097           /* Search for the label that starts the loop.
1098              Don't skip past the end of the loop, since that could
1099              lead to putting an alignment where it does not belong.
1100              However, a label after a nested (non-)loop would be OK.  */
1101           for (label = insn; label; label = NEXT_INSN (label))
1102             {
1103               if (GET_CODE (label) == NOTE
1104                   && NOTE_LINE_NUMBER (label) == NOTE_INSN_LOOP_BEG)
1105                 nest++;
1106               else if (GET_CODE (label) == NOTE
1107                        && NOTE_LINE_NUMBER (label) == NOTE_INSN_LOOP_END
1108                        && --nest == 0)
1109                 break;
1110               else if (GET_CODE (label) == CODE_LABEL)
1111                 {
1112                   log = LOOP_ALIGN (label);
1113                   if (max_log < log)
1114                     {
1115                       max_log = log;
1116                       max_skip = LOOP_ALIGN_MAX_SKIP;
1117                     }
1118                   break;
1119                 }
1120             }
1121         }
1122       else
1123         continue;
1124     }
1125 #ifdef HAVE_ATTR_length
1126
1127   /* Allocate the rest of the arrays.  */
1128   insn_lengths = (short *) xmalloc (max_uid * sizeof (short));
1129   insn_lengths_max_uid = max_uid;
1130   /* Syntax errors can lead to labels being outside of the main insn stream.
1131      Initialize insn_addresses, so that we get reproducible results.  */
1132   insn_addresses = (int *) xcalloc (max_uid, sizeof (int));
1133
1134   varying_length = (char *) xcalloc (max_uid, sizeof (char));
1135
1136   /* Initialize uid_align.  We scan instructions
1137      from end to start, and keep in align_tab[n] the last seen insn
1138      that does an alignment of at least n+1, i.e. the successor
1139      in the alignment chain for an insn that does / has a known
1140      alignment of n.  */
1141   uid_align = (rtx *) xcalloc (max_uid, sizeof *uid_align);
1142
1143   for (i = MAX_CODE_ALIGN; --i >= 0; )
1144     align_tab[i] = NULL_RTX;
1145   seq = get_last_insn ();
1146   for (; seq; seq = PREV_INSN (seq))
1147     {
1148       int uid = INSN_UID (seq);
1149       int log;
1150       log = (GET_CODE (seq) == CODE_LABEL ? LABEL_TO_ALIGNMENT (seq) : 0);
1151       uid_align[uid] = align_tab[0];
1152       if (log)
1153         {
1154           /* Found an alignment label.  */
1155           uid_align[uid] = align_tab[log];
1156           for (i = log - 1; i >= 0; i--)
1157             align_tab[i] = seq;
1158         }
1159     }
1160 #ifdef CASE_VECTOR_SHORTEN_MODE
1161   if (optimize)
1162     {
1163       /* Look for ADDR_DIFF_VECs, and initialize their minimum and maximum
1164          label fields.  */
1165
1166       int min_shuid = INSN_SHUID (get_insns ()) - 1;
1167       int max_shuid = INSN_SHUID (get_last_insn ()) + 1;
1168       int rel;
1169
1170       for (insn = first; insn != 0; insn = NEXT_INSN (insn))
1171         {
1172           rtx min_lab = NULL_RTX, max_lab = NULL_RTX, pat;
1173           int len, i, min, max, insn_shuid;
1174           int min_align;
1175           addr_diff_vec_flags flags;
1176
1177           if (GET_CODE (insn) != JUMP_INSN
1178               || GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
1179             continue;
1180           pat = PATTERN (insn);
1181           len = XVECLEN (pat, 1);
1182           if (len <= 0)
1183             abort ();
1184           min_align = MAX_CODE_ALIGN;
1185           for (min = max_shuid, max = min_shuid, i = len - 1; i >= 0; i--)
1186             {
1187               rtx lab = XEXP (XVECEXP (pat, 1, i), 0);
1188               int shuid = INSN_SHUID (lab);
1189               if (shuid < min)
1190                 {
1191                   min = shuid;
1192                   min_lab = lab;
1193                 }
1194               if (shuid > max)
1195                 {
1196                   max = shuid;
1197                   max_lab = lab;
1198                 }
1199               if (min_align > LABEL_TO_ALIGNMENT (lab))
1200                 min_align = LABEL_TO_ALIGNMENT (lab);
1201             }
1202           XEXP (pat, 2) = gen_rtx_LABEL_REF (VOIDmode, min_lab);
1203           XEXP (pat, 3) = gen_rtx_LABEL_REF (VOIDmode, max_lab);
1204           insn_shuid = INSN_SHUID (insn);
1205           rel = INSN_SHUID (XEXP (XEXP (pat, 0), 0));
1206           flags.min_align = min_align;
1207           flags.base_after_vec = rel > insn_shuid;
1208           flags.min_after_vec  = min > insn_shuid;
1209           flags.max_after_vec  = max > insn_shuid;
1210           flags.min_after_base = min > rel;
1211           flags.max_after_base = max > rel;
1212           ADDR_DIFF_VEC_FLAGS (pat) = flags;
1213         }
1214     }
1215 #endif /* CASE_VECTOR_SHORTEN_MODE */
1216
1217
1218   /* Compute initial lengths, addresses, and varying flags for each insn.  */
1219   for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1220        insn != 0;
1221        insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
1222     {
1223       uid = INSN_UID (insn);
1224
1225       insn_lengths[uid] = 0;
1226
1227       if (GET_CODE (insn) == CODE_LABEL)
1228         {
1229           int log = LABEL_TO_ALIGNMENT (insn);
1230           if (log)
1231             {
1232               int align = 1 << log;
1233               int new_address = (insn_current_address + align - 1) & -align;
1234               insn_lengths[uid] = new_address - insn_current_address;
1235               insn_current_address = new_address;
1236             }
1237         }
1238
1239       insn_addresses[uid] = insn_current_address;
1240       
1241       if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
1242           || GET_CODE (insn) == CODE_LABEL)
1243         continue;
1244       if (INSN_DELETED_P (insn))
1245         continue;
1246
1247       body = PATTERN (insn);
1248       if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1249         {
1250           /* This only takes room if read-only data goes into the text
1251              section.  */
1252           if (JUMP_TABLES_IN_TEXT_SECTION
1253 #if !defined(READONLY_DATA_SECTION)
1254               || 1
1255 #endif
1256               )
1257             insn_lengths[uid] = (XVECLEN (body,
1258                                           GET_CODE (body) == ADDR_DIFF_VEC)
1259                                  * GET_MODE_SIZE (GET_MODE (body)));
1260           /* Alignment is handled by ADDR_VEC_ALIGN.  */
1261         }
1262       else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
1263         insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
1264       else if (GET_CODE (body) == SEQUENCE)
1265         {
1266           int i;
1267           int const_delay_slots;
1268 #ifdef DELAY_SLOTS
1269           const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
1270 #else
1271           const_delay_slots = 0;
1272 #endif
1273           /* Inside a delay slot sequence, we do not do any branch shortening
1274              if the shortening could change the number of delay slots
1275              of the branch.  */
1276           for (i = 0; i < XVECLEN (body, 0); i++)
1277             {
1278               rtx inner_insn = XVECEXP (body, 0, i);
1279               int inner_uid = INSN_UID (inner_insn);
1280               int inner_length;
1281
1282               if (GET_CODE (body) == ASM_INPUT
1283                   || asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
1284                 inner_length = (asm_insn_count (PATTERN (inner_insn))
1285                                 * insn_default_length (inner_insn));
1286               else
1287                 inner_length = insn_default_length (inner_insn);
1288               
1289               insn_lengths[inner_uid] = inner_length;
1290               if (const_delay_slots)
1291                 {
1292                   if ((varying_length[inner_uid]
1293                        = insn_variable_length_p (inner_insn)) != 0)
1294                     varying_length[uid] = 1;
1295                   insn_addresses[inner_uid] = (insn_current_address +
1296                                                insn_lengths[uid]);
1297                 }
1298               else
1299                 varying_length[inner_uid] = 0;
1300               insn_lengths[uid] += inner_length;
1301             }
1302         }
1303       else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
1304         {
1305           insn_lengths[uid] = insn_default_length (insn);
1306           varying_length[uid] = insn_variable_length_p (insn);
1307         }
1308
1309       /* If needed, do any adjustment.  */
1310 #ifdef ADJUST_INSN_LENGTH
1311       ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
1312       if (insn_lengths[uid] < 0)
1313         fatal_insn ("Negative insn length", insn);
1314 #endif
1315     }
1316
1317   /* Now loop over all the insns finding varying length insns.  For each,
1318      get the current insn length.  If it has changed, reflect the change.
1319      When nothing changes for a full pass, we are done.  */
1320
1321   while (something_changed)
1322     {
1323       something_changed = 0;
1324       insn_current_align = MAX_CODE_ALIGN - 1;
1325       for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1326            insn != 0;
1327            insn = NEXT_INSN (insn))
1328         {
1329           int new_length;
1330 #ifdef ADJUST_INSN_LENGTH
1331           int tmp_length;
1332 #endif
1333           int length_align;
1334
1335           uid = INSN_UID (insn);
1336
1337           if (GET_CODE (insn) == CODE_LABEL)
1338             {
1339               int log = LABEL_TO_ALIGNMENT (insn);
1340               if (log > insn_current_align)
1341                 {
1342                   int align = 1 << log;
1343                   int new_address= (insn_current_address + align - 1) & -align;
1344                   insn_lengths[uid] = new_address - insn_current_address;
1345                   insn_current_align = log;
1346                   insn_current_address = new_address;
1347                 }
1348               else
1349                 insn_lengths[uid] = 0;
1350               insn_addresses[uid] = insn_current_address;
1351               continue;
1352             }
1353
1354           length_align = INSN_LENGTH_ALIGNMENT (insn);
1355           if (length_align < insn_current_align)
1356             insn_current_align = length_align;
1357
1358           insn_last_address = insn_addresses[uid];
1359           insn_addresses[uid] = insn_current_address;
1360
1361 #ifdef CASE_VECTOR_SHORTEN_MODE
1362           if (optimize && GET_CODE (insn) == JUMP_INSN
1363               && GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
1364             {
1365               rtx body = PATTERN (insn);
1366               int old_length = insn_lengths[uid];
1367               rtx rel_lab = XEXP (XEXP (body, 0), 0);
1368               rtx min_lab = XEXP (XEXP (body, 2), 0);
1369               rtx max_lab = XEXP (XEXP (body, 3), 0);
1370               addr_diff_vec_flags flags = ADDR_DIFF_VEC_FLAGS (body);
1371               int rel_addr = insn_addresses[INSN_UID (rel_lab)];
1372               int min_addr = insn_addresses[INSN_UID (min_lab)];
1373               int max_addr = insn_addresses[INSN_UID (max_lab)];
1374               rtx prev;
1375               int rel_align = 0;
1376
1377               /* Try to find a known alignment for rel_lab.  */
1378               for (prev = rel_lab;
1379                    prev
1380                    && ! insn_lengths[INSN_UID (prev)]
1381                    && ! (varying_length[INSN_UID (prev)] & 1);
1382                    prev = PREV_INSN (prev))
1383                 if (varying_length[INSN_UID (prev)] & 2)
1384                   {
1385                     rel_align = LABEL_TO_ALIGNMENT (prev);
1386                     break;
1387                   }
1388
1389               /* See the comment on addr_diff_vec_flags in rtl.h for the
1390                  meaning of the flags values.  base: REL_LAB   vec: INSN  */
1391               /* Anything after INSN has still addresses from the last
1392                  pass; adjust these so that they reflect our current
1393                  estimate for this pass.  */
1394               if (flags.base_after_vec)
1395                 rel_addr += insn_current_address - insn_last_address;
1396               if (flags.min_after_vec)
1397                 min_addr += insn_current_address - insn_last_address;
1398               if (flags.max_after_vec)
1399                 max_addr += insn_current_address - insn_last_address;
1400               /* We want to know the worst case, i.e. lowest possible value
1401                  for the offset of MIN_LAB.  If MIN_LAB is after REL_LAB,
1402                  its offset is positive, and we have to be wary of code shrink;
1403                  otherwise, it is negative, and we have to be vary of code
1404                  size increase.  */
1405               if (flags.min_after_base)
1406                 {
1407                   /* If INSN is between REL_LAB and MIN_LAB, the size
1408                      changes we are about to make can change the alignment
1409                      within the observed offset, therefore we have to break
1410                      it up into two parts that are independent.  */
1411                   if (! flags.base_after_vec && flags.min_after_vec)
1412                     {
1413                       min_addr -= align_fuzz (rel_lab, insn, rel_align, 0);
1414                       min_addr -= align_fuzz (insn, min_lab, 0, 0);
1415                     }
1416                   else
1417                     min_addr -= align_fuzz (rel_lab, min_lab, rel_align, 0);
1418                 }
1419               else
1420                 {
1421                   if (flags.base_after_vec && ! flags.min_after_vec)
1422                     {
1423                       min_addr -= align_fuzz (min_lab, insn, 0, ~0);
1424                       min_addr -= align_fuzz (insn, rel_lab, 0, ~0);
1425                     }
1426                   else
1427                     min_addr -= align_fuzz (min_lab, rel_lab, 0, ~0);
1428                 }
1429               /* Likewise, determine the highest lowest possible value
1430                  for the offset of MAX_LAB.  */
1431               if (flags.max_after_base)
1432                 {
1433                   if (! flags.base_after_vec && flags.max_after_vec)
1434                     {
1435                       max_addr += align_fuzz (rel_lab, insn, rel_align, ~0);
1436                       max_addr += align_fuzz (insn, max_lab, 0, ~0);
1437                     }
1438                   else
1439                     max_addr += align_fuzz (rel_lab, max_lab, rel_align, ~0);
1440                 }
1441               else
1442                 {
1443                   if (flags.base_after_vec && ! flags.max_after_vec)
1444                     {
1445                       max_addr += align_fuzz (max_lab, insn, 0, 0);
1446                       max_addr += align_fuzz (insn, rel_lab, 0, 0);
1447                     }
1448                   else
1449                     max_addr += align_fuzz (max_lab, rel_lab, 0, 0);
1450                 }
1451               PUT_MODE (body, CASE_VECTOR_SHORTEN_MODE (min_addr - rel_addr,
1452                                                         max_addr - rel_addr,
1453                                                         body));
1454               if (JUMP_TABLES_IN_TEXT_SECTION
1455 #if !defined(READONLY_DATA_SECTION)
1456                   || 1
1457 #endif
1458                   )
1459                 {
1460                   insn_lengths[uid]
1461                     = (XVECLEN (body, 1) * GET_MODE_SIZE (GET_MODE (body)));
1462                   insn_current_address += insn_lengths[uid];
1463                   if (insn_lengths[uid] != old_length)
1464                     something_changed = 1;
1465                 }
1466
1467               continue;
1468             }
1469 #endif /* CASE_VECTOR_SHORTEN_MODE */
1470
1471           if (! (varying_length[uid]))
1472             {
1473               insn_current_address += insn_lengths[uid];
1474               continue;
1475             }
1476           if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
1477             {
1478               int i;
1479               
1480               body = PATTERN (insn);
1481               new_length = 0;
1482               for (i = 0; i < XVECLEN (body, 0); i++)
1483                 {
1484                   rtx inner_insn = XVECEXP (body, 0, i);
1485                   int inner_uid = INSN_UID (inner_insn);
1486                   int inner_length;
1487
1488                   insn_addresses[inner_uid] = insn_current_address;
1489
1490                   /* insn_current_length returns 0 for insns with a
1491                      non-varying length.  */
1492                   if (! varying_length[inner_uid])
1493                     inner_length = insn_lengths[inner_uid];
1494                   else
1495                     inner_length = insn_current_length (inner_insn);
1496
1497                   if (inner_length != insn_lengths[inner_uid])
1498                     {
1499                       insn_lengths[inner_uid] = inner_length;
1500                       something_changed = 1;
1501                     }
1502                   insn_current_address += insn_lengths[inner_uid];
1503                   new_length += inner_length;
1504                 }
1505             }
1506           else
1507             {
1508               new_length = insn_current_length (insn);
1509               insn_current_address += new_length;
1510             }
1511
1512 #ifdef ADJUST_INSN_LENGTH
1513           /* If needed, do any adjustment.  */
1514           tmp_length = new_length;
1515           ADJUST_INSN_LENGTH (insn, new_length);
1516           insn_current_address += (new_length - tmp_length);
1517 #endif
1518
1519           if (new_length != insn_lengths[uid])
1520             {
1521               insn_lengths[uid] = new_length;
1522               something_changed = 1;
1523             }
1524         }
1525       /* For a non-optimizing compile, do only a single pass.  */
1526       if (!optimize)
1527         break;
1528     }
1529
1530   free (varying_length);
1531
1532 #endif /* HAVE_ATTR_length */
1533 }
1534
1535 #ifdef HAVE_ATTR_length
1536 /* Given the body of an INSN known to be generated by an ASM statement, return
1537    the number of machine instructions likely to be generated for this insn.
1538    This is used to compute its length.  */
1539
1540 static int
1541 asm_insn_count (body)
1542      rtx body;
1543 {
1544   const char *template;
1545   int count = 1;
1546
1547   if (GET_CODE (body) == ASM_INPUT)
1548     template = XSTR (body, 0);
1549   else
1550     template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
1551                                     NULL_PTR, NULL_PTR);
1552
1553   for ( ; *template; template++)
1554     if (IS_ASM_LOGICAL_LINE_SEPARATOR(*template) || *template == '\n')
1555       count++;
1556
1557   return count;
1558 }
1559 #endif
1560 \f
1561 /* Output assembler code for the start of a function,
1562    and initialize some of the variables in this file
1563    for the new function.  The label for the function and associated
1564    assembler pseudo-ops have already been output in `assemble_start_function'.
1565
1566    FIRST is the first insn of the rtl for the function being compiled.
1567    FILE is the file to write assembler code to.
1568    OPTIMIZE is nonzero if we should eliminate redundant
1569      test and compare insns.  */
1570
1571 void
1572 final_start_function (first, file, optimize)
1573      rtx first;
1574      FILE *file;
1575      int optimize ATTRIBUTE_UNUSED;
1576 {
1577   block_depth = 0;
1578
1579   this_is_asm_operands = 0;
1580
1581 #ifdef NON_SAVING_SETJMP
1582   /* A function that calls setjmp should save and restore all the
1583      call-saved registers on a system where longjmp clobbers them.  */
1584   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
1585     {
1586       int i;
1587
1588       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1589         if (!call_used_regs[i])
1590           regs_ever_live[i] = 1;
1591     }
1592 #endif
1593   
1594   /* Initial line number is supposed to be output
1595      before the function's prologue and label
1596      so that the function's address will not appear to be
1597      in the last statement of the preceding function.  */
1598   if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1599     last_linenum = high_block_linenum = high_function_linenum
1600       = NOTE_LINE_NUMBER (first);
1601
1602 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1603   /* Output DWARF definition of the function.  */
1604   if (dwarf2out_do_frame ())
1605     dwarf2out_begin_prologue ();
1606   else
1607     current_function_func_begin_label = 0;
1608 #endif
1609
1610   /* For SDB and XCOFF, the function beginning must be marked between
1611      the function label and the prologue.  We always need this, even when
1612      -g1 was used.  Defer on MIPS systems so that parameter descriptions
1613      follow function entry.  */
1614 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
1615   if (write_symbols == SDB_DEBUG)
1616     sdbout_begin_function (last_linenum);
1617   else
1618 #endif
1619 #ifdef XCOFF_DEBUGGING_INFO
1620     if (write_symbols == XCOFF_DEBUG)
1621       xcoffout_begin_function (file, last_linenum);
1622     else
1623 #endif    
1624       /* But only output line number for other debug info types if -g2
1625          or better.  */
1626       if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1627         output_source_line (file, first);
1628
1629 #ifdef LEAF_REG_REMAP
1630   if (current_function_uses_only_leaf_regs)
1631     leaf_renumber_regs (first);
1632 #endif
1633
1634   /* The Sun386i and perhaps other machines don't work right
1635      if the profiling code comes after the prologue.  */
1636 #ifdef PROFILE_BEFORE_PROLOGUE
1637   if (profile_flag)
1638     profile_function (file);
1639 #endif /* PROFILE_BEFORE_PROLOGUE */
1640
1641 #if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
1642   if (dwarf2out_do_frame ())
1643     dwarf2out_frame_debug (NULL_RTX);
1644 #endif
1645
1646   /* If debugging, assign block numbers to all of the blocks in this
1647      function.  */
1648   if (write_symbols)
1649     {
1650       number_blocks (current_function_decl);
1651       remove_unncessary_notes ();
1652       /* We never actually put out begin/end notes for the top-level
1653          block in the function.  But, conceptually, that block is
1654          always needed.  */
1655       TREE_ASM_WRITTEN (DECL_INITIAL (current_function_decl)) = 1;
1656     }
1657
1658 #ifdef FUNCTION_PROLOGUE
1659   /* First output the function prologue: code to set up the stack frame.  */
1660   FUNCTION_PROLOGUE (file, get_frame_size ());
1661 #endif
1662
1663   /* If the machine represents the prologue as RTL, the profiling code must
1664      be emitted when NOTE_INSN_PROLOGUE_END is scanned.  */
1665 #ifdef HAVE_prologue
1666   if (! HAVE_prologue)
1667 #endif
1668     profile_after_prologue (file);
1669
1670   profile_label_no++;
1671
1672   /* If we are doing basic block profiling, remember a printable version
1673      of the function name.  */
1674   if (profile_block_flag)
1675     {
1676       bb_func_label_num
1677         = add_bb_string ((*decl_printable_name) (current_function_decl, 2), FALSE);
1678     }
1679 }
1680
1681 static void
1682 profile_after_prologue (file)
1683      FILE *file ATTRIBUTE_UNUSED;
1684 {
1685 #ifdef FUNCTION_BLOCK_PROFILER
1686   if (profile_block_flag)
1687     {
1688       FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
1689     }
1690 #endif /* FUNCTION_BLOCK_PROFILER */
1691
1692 #ifndef PROFILE_BEFORE_PROLOGUE
1693   if (profile_flag)
1694     profile_function (file);
1695 #endif /* not PROFILE_BEFORE_PROLOGUE */
1696 }
1697
1698 static void
1699 profile_function (file)
1700      FILE *file;
1701 {
1702   int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
1703 #if defined(ASM_OUTPUT_REG_PUSH)
1704 #if defined(STRUCT_VALUE_INCOMING_REGNUM) || defined(STRUCT_VALUE_REGNUM)
1705   int sval = current_function_returns_struct;
1706 #endif
1707 #if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
1708   int cxt = current_function_needs_context;
1709 #endif
1710 #endif /* ASM_OUTPUT_REG_PUSH */
1711
1712   data_section ();
1713   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
1714   ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
1715   assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, 1);
1716
1717   function_section (current_function_decl);
1718
1719 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1720   if (sval)
1721     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
1722 #else
1723 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1724   if (sval)
1725     {
1726       ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
1727     }
1728 #endif
1729 #endif
1730
1731 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1732   if (cxt)
1733     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1734 #else
1735 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1736   if (cxt)
1737     {
1738       ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1739     }
1740 #endif
1741 #endif
1742
1743   FUNCTION_PROFILER (file, profile_label_no);
1744
1745 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1746   if (cxt)
1747     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1748 #else
1749 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1750   if (cxt)
1751     {
1752       ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1753     }
1754 #endif
1755 #endif
1756
1757 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1758   if (sval)
1759     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1760 #else
1761 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1762   if (sval)
1763     {
1764       ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1765     }
1766 #endif
1767 #endif
1768 }
1769
1770 /* Output assembler code for the end of a function.
1771    For clarity, args are same as those of `final_start_function'
1772    even though not all of them are needed.  */
1773
1774 void
1775 final_end_function (first, file, optimize)
1776      rtx first ATTRIBUTE_UNUSED;
1777      FILE *file;
1778      int optimize ATTRIBUTE_UNUSED;
1779 {
1780   if (app_on)
1781     {
1782       fputs (ASM_APP_OFF, file);
1783       app_on = 0;
1784     }
1785
1786 #ifdef SDB_DEBUGGING_INFO
1787   if (write_symbols == SDB_DEBUG)
1788     sdbout_end_function (high_function_linenum);
1789 #endif
1790
1791 #ifdef DWARF_DEBUGGING_INFO
1792   if (write_symbols == DWARF_DEBUG)
1793     dwarfout_end_function ();
1794 #endif
1795
1796 #ifdef XCOFF_DEBUGGING_INFO
1797   if (write_symbols == XCOFF_DEBUG)
1798     xcoffout_end_function (file, high_function_linenum);
1799 #endif
1800
1801 #ifdef FUNCTION_EPILOGUE
1802   /* Finally, output the function epilogue:
1803      code to restore the stack frame and return to the caller.  */
1804   FUNCTION_EPILOGUE (file, get_frame_size ());
1805 #endif
1806
1807 #ifdef SDB_DEBUGGING_INFO
1808   if (write_symbols == SDB_DEBUG)
1809     sdbout_end_epilogue ();
1810 #endif
1811
1812 #ifdef DWARF_DEBUGGING_INFO
1813   if (write_symbols == DWARF_DEBUG)
1814     dwarfout_end_epilogue ();
1815 #endif
1816
1817 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1818   if (dwarf2out_do_frame ())
1819     dwarf2out_end_epilogue ();
1820 #endif
1821
1822 #ifdef XCOFF_DEBUGGING_INFO
1823   if (write_symbols == XCOFF_DEBUG)
1824     xcoffout_end_epilogue (file);
1825 #endif
1826
1827   bb_func_label_num = -1;       /* not in function, nuke label # */
1828
1829   /* If FUNCTION_EPILOGUE is not defined, then the function body
1830      itself contains return instructions wherever needed.  */
1831 }
1832 \f
1833 /* Add a block to the linked list that remembers the current line/file/function
1834    for basic block profiling.  Emit the label in front of the basic block and
1835    the instructions that increment the count field.  */
1836
1837 static void
1838 add_bb (file)
1839      FILE *file;
1840 {
1841   struct bb_list *ptr = (struct bb_list *) permalloc (sizeof (struct bb_list));
1842
1843   /* Add basic block to linked list.  */
1844   ptr->next = 0;
1845   ptr->line_num = last_linenum;
1846   ptr->file_label_num = bb_file_label_num;
1847   ptr->func_label_num = bb_func_label_num;
1848   *bb_tail = ptr;
1849   bb_tail = &ptr->next;
1850
1851   /* Enable the table of basic-block use counts
1852      to point at the code it applies to.  */
1853   ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1854
1855   /* Before first insn of this basic block, increment the
1856      count of times it was entered.  */
1857 #ifdef BLOCK_PROFILER
1858   BLOCK_PROFILER (file, count_basic_blocks);
1859 #endif
1860 #ifdef HAVE_cc0
1861   CC_STATUS_INIT;
1862 #endif
1863
1864   new_block = 0;
1865   count_basic_blocks++;
1866 }
1867
1868 /* Add a string to be used for basic block profiling.  */
1869
1870 static int
1871 add_bb_string (string, perm_p)
1872      const char *string;
1873      int perm_p;
1874 {
1875   int len;
1876   struct bb_str *ptr = 0;
1877
1878   if (!string)
1879     {
1880       string = "<unknown>";
1881       perm_p = TRUE;
1882     }
1883
1884   /* Allocate a new string if the current string isn't permanent.  If
1885      the string is permanent search for the same string in other
1886      allocations.  */
1887
1888   len = strlen (string) + 1;
1889   if (!perm_p)
1890     {
1891       char *p = (char *) permalloc (len);
1892       bcopy (string, p, len);
1893       string = p;
1894     }
1895   else
1896     for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
1897       if (ptr->string == string)
1898         break;
1899
1900   /* Allocate a new string block if we need to.  */
1901   if (!ptr)
1902     {
1903       ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1904       ptr->next = 0;
1905       ptr->length = len;
1906       ptr->label_num = sbb_label_num++;
1907       ptr->string = string;
1908       *sbb_tail = ptr;
1909       sbb_tail = &ptr->next;
1910     }
1911
1912   return ptr->label_num;
1913 }
1914
1915 \f
1916 /* Output assembler code for some insns: all or part of a function.
1917    For description of args, see `final_start_function', above.
1918
1919    PRESCAN is 1 if we are not really outputting,
1920      just scanning as if we were outputting.
1921    Prescanning deletes and rearranges insns just like ordinary output.
1922    PRESCAN is -2 if we are outputting after having prescanned.
1923    In this case, don't try to delete or rearrange insns
1924    because that has already been done.
1925    Prescanning is done only on certain machines.  */
1926
1927 void
1928 final (first, file, optimize, prescan)
1929      rtx first;
1930      FILE *file;
1931      int optimize;
1932      int prescan;
1933 {
1934   register rtx insn;
1935   int max_line = 0;
1936   int max_uid = 0;
1937
1938   last_ignored_compare = 0;
1939   new_block = 1;
1940
1941   check_exception_handler_labels ();
1942
1943   /* Make a map indicating which line numbers appear in this function.
1944      When producing SDB debugging info, delete troublesome line number
1945      notes from inlined functions in other files as well as duplicate
1946      line number notes.  */
1947 #ifdef SDB_DEBUGGING_INFO
1948   if (write_symbols == SDB_DEBUG)
1949     {
1950       rtx last = 0;
1951       for (insn = first; insn; insn = NEXT_INSN (insn))
1952         if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1953           {
1954             if ((RTX_INTEGRATED_P (insn)
1955                  && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1956                  || (last != 0
1957                      && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1958                      && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1959               {
1960                 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1961                 NOTE_SOURCE_FILE (insn) = 0;
1962                 continue;
1963               }
1964             last = insn;
1965             if (NOTE_LINE_NUMBER (insn) > max_line)
1966               max_line = NOTE_LINE_NUMBER (insn);
1967           }
1968     }
1969   else
1970 #endif
1971     {
1972       for (insn = first; insn; insn = NEXT_INSN (insn))
1973         if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1974           max_line = NOTE_LINE_NUMBER (insn);
1975     }
1976
1977   line_note_exists = (char *) oballoc (max_line + 1);
1978   bzero (line_note_exists, max_line + 1);
1979
1980   for (insn = first; insn; insn = NEXT_INSN (insn))
1981     {
1982       if (INSN_UID (insn) > max_uid)       /* find largest UID */
1983         max_uid = INSN_UID (insn);
1984       if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1985         line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1986 #ifdef HAVE_cc0
1987       /* If CC tracking across branches is enabled, record the insn which
1988          jumps to each branch only reached from one place.  */
1989       if (optimize && GET_CODE (insn) == JUMP_INSN)
1990         {
1991           rtx lab = JUMP_LABEL (insn);
1992           if (lab && LABEL_NUSES (lab) == 1)
1993             {
1994               LABEL_REFS (lab) = insn;
1995             }
1996         }
1997 #endif
1998     }
1999
2000   /* Initialize insn_eh_region table if eh is being used. */
2001   
2002   init_insn_eh_region (first, max_uid);
2003
2004   init_recog ();
2005
2006   CC_STATUS_INIT;
2007
2008   /* Output the insns.  */
2009   for (insn = NEXT_INSN (first); insn;)
2010     {
2011 #ifdef HAVE_ATTR_length
2012       insn_current_address = insn_addresses[INSN_UID (insn)];
2013 #endif
2014       insn = final_scan_insn (insn, file, optimize, prescan, 0);
2015     }
2016
2017   /* Do basic-block profiling here
2018      if the last insn was a conditional branch.  */
2019   if (profile_block_flag && new_block)
2020     add_bb (file);
2021
2022   free_insn_eh_region ();
2023 }
2024 \f
2025 const char *
2026 get_insn_template (code, insn)
2027      int code;
2028      rtx insn;
2029 {
2030   const void *output = insn_data[code].output;
2031   switch (insn_data[code].output_format)
2032     {
2033     case INSN_OUTPUT_FORMAT_SINGLE:
2034       return (const char *) output;
2035     case INSN_OUTPUT_FORMAT_MULTI:
2036       return ((const char * const *) output)[which_alternative];
2037     case INSN_OUTPUT_FORMAT_FUNCTION:
2038       if (insn == NULL)
2039         abort ();
2040       return (* (insn_output_fn) output) (recog_data.operand, insn);
2041
2042     default:
2043       abort ();
2044     }
2045 }
2046 /* The final scan for one insn, INSN.
2047    Args are same as in `final', except that INSN
2048    is the insn being scanned.
2049    Value returned is the next insn to be scanned.
2050
2051    NOPEEPHOLES is the flag to disallow peephole processing (currently
2052    used for within delayed branch sequence output).  */
2053
2054 rtx
2055 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
2056      rtx insn;
2057      FILE *file;
2058      int optimize ATTRIBUTE_UNUSED;
2059      int prescan;
2060      int nopeepholes ATTRIBUTE_UNUSED;
2061 {
2062 #ifdef HAVE_cc0
2063   rtx set;
2064 #endif
2065
2066   insn_counter++;
2067
2068   /* Ignore deleted insns.  These can occur when we split insns (due to a
2069      template of "#") while not optimizing.  */
2070   if (INSN_DELETED_P (insn))
2071     return NEXT_INSN (insn);
2072
2073   switch (GET_CODE (insn))
2074     {
2075     case NOTE:
2076       if (prescan > 0)
2077         break;
2078
2079       /* Align the beginning of a loop, for higher speed
2080          on certain machines.  */
2081
2082       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
2083         break; /* This used to depend on optimize, but that was bogus.  */
2084       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
2085         break;
2086
2087       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG
2088           && ! exceptions_via_longjmp)
2089         {
2090           ASM_OUTPUT_INTERNAL_LABEL (file, "LEHB", NOTE_EH_HANDLER (insn));
2091           if (! flag_new_exceptions)
2092             add_eh_table_entry (NOTE_EH_HANDLER (insn));
2093 #ifdef ASM_OUTPUT_EH_REGION_BEG
2094           ASM_OUTPUT_EH_REGION_BEG (file, NOTE_EH_HANDLER (insn));
2095 #endif
2096           break;
2097         }
2098
2099       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END
2100           && ! exceptions_via_longjmp)
2101         {
2102           ASM_OUTPUT_INTERNAL_LABEL (file, "LEHE", NOTE_EH_HANDLER (insn));
2103           if (flag_new_exceptions)
2104             add_eh_table_entry (NOTE_EH_HANDLER (insn));
2105 #ifdef ASM_OUTPUT_EH_REGION_END
2106           ASM_OUTPUT_EH_REGION_END (file, NOTE_EH_HANDLER (insn));
2107 #endif
2108           break;
2109         }
2110
2111       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
2112         {
2113 #ifdef FUNCTION_END_PROLOGUE
2114           FUNCTION_END_PROLOGUE (file);
2115 #endif
2116           profile_after_prologue (file);
2117           break;
2118         }
2119
2120 #ifdef FUNCTION_BEGIN_EPILOGUE
2121       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
2122         {
2123           FUNCTION_BEGIN_EPILOGUE (file);
2124           break;
2125         }
2126 #endif
2127
2128       if (write_symbols == NO_DEBUG)
2129         break;
2130       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
2131         {
2132 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
2133           /* MIPS stabs require the parameter descriptions to be after the
2134              function entry point rather than before.  */
2135           if (write_symbols == SDB_DEBUG)
2136             sdbout_begin_function (last_linenum);
2137           else
2138 #endif
2139 #ifdef DWARF_DEBUGGING_INFO
2140           /* This outputs a marker where the function body starts, so it
2141              must be after the prologue.  */
2142           if (write_symbols == DWARF_DEBUG)
2143             dwarfout_begin_function ();
2144 #endif
2145           break;
2146         }
2147       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
2148         break;                  /* An insn that was "deleted" */
2149       if (app_on)
2150         {
2151           fputs (ASM_APP_OFF, file);
2152           app_on = 0;
2153         }
2154       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2155           && (debug_info_level == DINFO_LEVEL_NORMAL
2156               || debug_info_level == DINFO_LEVEL_VERBOSE
2157               || write_symbols == DWARF_DEBUG
2158               || write_symbols == DWARF2_DEBUG))
2159         {
2160           int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2161
2162           ++block_depth;
2163           high_block_linenum = last_linenum;
2164
2165           /* Output debugging info about the symbol-block beginning.  */
2166 #ifdef SDB_DEBUGGING_INFO
2167           if (write_symbols == SDB_DEBUG)
2168             sdbout_begin_block (file, last_linenum, n);
2169 #endif
2170 #ifdef XCOFF_DEBUGGING_INFO
2171           if (write_symbols == XCOFF_DEBUG)
2172             xcoffout_begin_block (file, last_linenum, n);
2173 #endif
2174 #ifdef DBX_DEBUGGING_INFO
2175           if (write_symbols == DBX_DEBUG)
2176             ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", n);
2177 #endif
2178 #ifdef DWARF_DEBUGGING_INFO
2179           if (write_symbols == DWARF_DEBUG)
2180             dwarfout_begin_block (n);
2181 #endif
2182 #ifdef DWARF2_DEBUGGING_INFO
2183           if (write_symbols == DWARF2_DEBUG)
2184             dwarf2out_begin_block (n);
2185 #endif
2186
2187           /* Mark this block as output.  */
2188           TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
2189         }
2190       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
2191                && (debug_info_level == DINFO_LEVEL_NORMAL
2192                    || debug_info_level == DINFO_LEVEL_VERBOSE
2193                    || write_symbols == DWARF_DEBUG
2194                    || write_symbols == DWARF2_DEBUG))
2195         {
2196           int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2197
2198           /* End of a symbol-block.  */
2199
2200           --block_depth;
2201           if (block_depth < 0)
2202             abort ();
2203
2204 #ifdef XCOFF_DEBUGGING_INFO
2205           if (write_symbols == XCOFF_DEBUG)
2206             xcoffout_end_block (file, high_block_linenum, n);
2207 #endif
2208 #ifdef DBX_DEBUGGING_INFO
2209           if (write_symbols == DBX_DEBUG)
2210             ASM_OUTPUT_INTERNAL_LABEL (file, "LBE", n);
2211 #endif
2212 #ifdef SDB_DEBUGGING_INFO
2213           if (write_symbols == SDB_DEBUG)
2214             sdbout_end_block (file, high_block_linenum, n);
2215 #endif
2216 #ifdef DWARF_DEBUGGING_INFO
2217           if (write_symbols == DWARF_DEBUG)
2218             dwarfout_end_block (n);
2219 #endif
2220 #ifdef DWARF2_DEBUGGING_INFO
2221           if (write_symbols == DWARF2_DEBUG)
2222             dwarf2out_end_block (n);
2223 #endif
2224         }
2225       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
2226                && (debug_info_level == DINFO_LEVEL_NORMAL
2227                    || debug_info_level == DINFO_LEVEL_VERBOSE))
2228         {
2229 #ifdef DWARF_DEBUGGING_INFO
2230           if (write_symbols == DWARF_DEBUG)
2231             dwarfout_label (insn);
2232 #endif
2233 #ifdef DWARF2_DEBUGGING_INFO
2234           if (write_symbols == DWARF2_DEBUG)
2235             dwarf2out_label (insn);
2236 #endif
2237         }
2238       else if (NOTE_LINE_NUMBER (insn) > 0)
2239         /* This note is a line-number.  */
2240         {
2241           register rtx note;
2242
2243 #if 0 /* This is what we used to do.  */
2244           output_source_line (file, insn);
2245 #endif
2246           int note_after = 0;
2247
2248           /* If there is anything real after this note,
2249              output it.  If another line note follows, omit this one.  */
2250           for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
2251             {
2252               if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
2253                 break;
2254               /* These types of notes can be significant
2255                  so make sure the preceding line number stays.  */
2256               else if (GET_CODE (note) == NOTE
2257                        && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
2258                            || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
2259                            || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
2260                 break;
2261               else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
2262                 {
2263                   /* Another line note follows; we can delete this note
2264                      if no intervening line numbers have notes elsewhere.  */
2265                   int num;
2266                   for (num = NOTE_LINE_NUMBER (insn) + 1;
2267                        num < NOTE_LINE_NUMBER (note);
2268                        num++)
2269                     if (line_note_exists[num])
2270                       break;
2271
2272                   if (num >= NOTE_LINE_NUMBER (note))
2273                     note_after = 1;
2274                   break;
2275                 }
2276             }
2277
2278           /* Output this line note
2279              if it is the first or the last line note in a row.  */
2280           if (!note_after)
2281             output_source_line (file, insn);
2282         }
2283       break;
2284
2285     case BARRIER:
2286 #if defined (DWARF2_UNWIND_INFO)
2287         /* If we push arguments, we need to check all insns for stack
2288            adjustments.  */
2289         if (!ACCUMULATE_OUTGOING_ARGS && dwarf2out_do_frame ())
2290           dwarf2out_frame_debug (insn);
2291 #endif
2292       break;
2293
2294     case CODE_LABEL:
2295       /* The target port might emit labels in the output function for
2296          some insn, e.g. sh.c output_branchy_insn.  */
2297       if (CODE_LABEL_NUMBER (insn) <= max_labelno)
2298         {
2299           int align = LABEL_TO_ALIGNMENT (insn);
2300 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2301           int max_skip = LABEL_TO_MAX_SKIP (insn);
2302 #endif
2303
2304           if (align && NEXT_INSN (insn))
2305 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2306             ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
2307 #else
2308             ASM_OUTPUT_ALIGN (file, align);
2309 #endif
2310         }
2311 #ifdef HAVE_cc0
2312       CC_STATUS_INIT;
2313       /* If this label is reached from only one place, set the condition
2314          codes from the instruction just before the branch.  */
2315
2316       /* Disabled because some insns set cc_status in the C output code
2317          and NOTICE_UPDATE_CC alone can set incorrect status.  */
2318       if (0 /* optimize && LABEL_NUSES (insn) == 1*/)
2319         {
2320           rtx jump = LABEL_REFS (insn);
2321           rtx barrier = prev_nonnote_insn (insn);
2322           rtx prev;
2323           /* If the LABEL_REFS field of this label has been set to point
2324              at a branch, the predecessor of the branch is a regular
2325              insn, and that branch is the only way to reach this label,
2326              set the condition codes based on the branch and its
2327              predecessor.  */
2328           if (barrier && GET_CODE (barrier) == BARRIER
2329               && jump && GET_CODE (jump) == JUMP_INSN
2330               && (prev = prev_nonnote_insn (jump))
2331               && GET_CODE (prev) == INSN)
2332             {
2333               NOTICE_UPDATE_CC (PATTERN (prev), prev);
2334               NOTICE_UPDATE_CC (PATTERN (jump), jump);
2335             }
2336         }
2337 #endif
2338       if (prescan > 0)
2339         break;
2340       new_block = 1;
2341
2342 #ifdef FINAL_PRESCAN_LABEL
2343       FINAL_PRESCAN_INSN (insn, NULL_PTR, 0);
2344 #endif
2345
2346 #ifdef SDB_DEBUGGING_INFO
2347       if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
2348         sdbout_label (insn);
2349 #endif
2350 #ifdef DWARF_DEBUGGING_INFO
2351       if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
2352         dwarfout_label (insn);
2353 #endif
2354 #ifdef DWARF2_DEBUGGING_INFO
2355       if (write_symbols == DWARF2_DEBUG && LABEL_NAME (insn))
2356         dwarf2out_label (insn);
2357 #endif
2358       if (app_on)
2359         {
2360           fputs (ASM_APP_OFF, file);
2361           app_on = 0;
2362         }
2363       if (NEXT_INSN (insn) != 0
2364           && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
2365         {
2366           rtx nextbody = PATTERN (NEXT_INSN (insn));
2367
2368           /* If this label is followed by a jump-table,
2369              make sure we put the label in the read-only section.  Also
2370              possibly write the label and jump table together.  */
2371
2372           if (GET_CODE (nextbody) == ADDR_VEC
2373               || GET_CODE (nextbody) == ADDR_DIFF_VEC)
2374             {
2375 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2376               /* In this case, the case vector is being moved by the
2377                  target, so don't output the label at all.  Leave that
2378                  to the back end macros.  */
2379 #else
2380               if (! JUMP_TABLES_IN_TEXT_SECTION)
2381                 {
2382                   readonly_data_section ();
2383 #ifdef READONLY_DATA_SECTION
2384                   ASM_OUTPUT_ALIGN (file,
2385                                     exact_log2 (BIGGEST_ALIGNMENT
2386                                                 / BITS_PER_UNIT));
2387 #endif /* READONLY_DATA_SECTION */
2388                 }
2389               else
2390                 function_section (current_function_decl);
2391
2392 #ifdef ASM_OUTPUT_CASE_LABEL
2393               ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
2394                                      NEXT_INSN (insn));
2395 #else
2396               if (LABEL_ALTERNATE_NAME (insn))
2397                 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2398               else
2399                 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2400 #endif
2401 #endif
2402               break;
2403             }
2404         }
2405       if (LABEL_ALTERNATE_NAME (insn))
2406         ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2407       else
2408         ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2409       break;
2410
2411     default:
2412       {
2413         register rtx body = PATTERN (insn);
2414         int insn_code_number;
2415         const char *template;
2416 #ifdef HAVE_cc0
2417         rtx note;
2418 #endif
2419
2420         /* An INSN, JUMP_INSN or CALL_INSN.
2421            First check for special kinds that recog doesn't recognize.  */
2422
2423         if (GET_CODE (body) == USE /* These are just declarations */
2424             || GET_CODE (body) == CLOBBER)
2425           break;
2426
2427 #ifdef HAVE_cc0
2428         /* If there is a REG_CC_SETTER note on this insn, it means that
2429            the setting of the condition code was done in the delay slot
2430            of the insn that branched here.  So recover the cc status
2431            from the insn that set it.  */
2432
2433         note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2434         if (note)
2435           {
2436             NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
2437             cc_prev_status = cc_status;
2438           }
2439 #endif
2440
2441         /* Detect insns that are really jump-tables
2442            and output them as such.  */
2443
2444         if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
2445           {
2446 #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
2447             register int vlen, idx;
2448 #endif
2449
2450             if (prescan > 0)
2451               break;
2452
2453             if (app_on)
2454               {
2455                 fputs (ASM_APP_OFF, file);
2456                 app_on = 0;
2457               }
2458
2459 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2460             if (GET_CODE (body) == ADDR_VEC)
2461               {
2462 #ifdef ASM_OUTPUT_ADDR_VEC
2463                 ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
2464 #else
2465                 abort();
2466 #endif
2467               }
2468             else
2469               {
2470 #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
2471                 ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
2472 #else
2473                 abort();
2474 #endif
2475               }
2476 #else
2477             vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2478             for (idx = 0; idx < vlen; idx++)
2479               {
2480                 if (GET_CODE (body) == ADDR_VEC)
2481                   {
2482 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2483                     ASM_OUTPUT_ADDR_VEC_ELT
2484                       (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2485 #else
2486                     abort ();
2487 #endif
2488                   }
2489                 else
2490                   {
2491 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2492                     ASM_OUTPUT_ADDR_DIFF_ELT
2493                       (file,
2494                        body,
2495                        CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2496                        CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2497 #else
2498                     abort ();
2499 #endif
2500                   }
2501               }
2502 #ifdef ASM_OUTPUT_CASE_END
2503             ASM_OUTPUT_CASE_END (file,
2504                                  CODE_LABEL_NUMBER (PREV_INSN (insn)),
2505                                  insn);
2506 #endif
2507 #endif
2508
2509             function_section (current_function_decl);
2510
2511             break;
2512           }
2513
2514         /* Do basic-block profiling when we reach a new block.
2515            Done here to avoid jump tables.  */
2516         if (profile_block_flag && new_block)
2517           add_bb (file);
2518
2519         if (GET_CODE (body) == ASM_INPUT)
2520           {
2521             /* There's no telling what that did to the condition codes.  */
2522             CC_STATUS_INIT;
2523             if (prescan > 0)
2524               break;
2525             if (! app_on)
2526               {
2527                 fputs (ASM_APP_ON, file);
2528                 app_on = 1;
2529               }
2530             fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
2531             break;
2532           }
2533
2534         /* Detect `asm' construct with operands.  */
2535         if (asm_noperands (body) >= 0)
2536           {
2537             unsigned int noperands = asm_noperands (body);
2538             rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
2539             const char *string;
2540
2541             /* There's no telling what that did to the condition codes.  */
2542             CC_STATUS_INIT;
2543             if (prescan > 0)
2544               break;
2545
2546             if (! app_on)
2547               {
2548                 fputs (ASM_APP_ON, file);
2549                 app_on = 1;
2550               }
2551
2552             /* Get out the operand values.  */
2553             string = decode_asm_operands (body, ops, NULL_PTR,
2554                                           NULL_PTR, NULL_PTR);
2555             /* Inhibit aborts on what would otherwise be compiler bugs.  */
2556             insn_noperands = noperands;
2557             this_is_asm_operands = insn;
2558
2559             /* Output the insn using them.  */
2560             output_asm_insn (string, ops);
2561             this_is_asm_operands = 0;
2562             break;
2563           }
2564
2565         if (prescan <= 0 && app_on)
2566           {
2567             fputs (ASM_APP_OFF, file);
2568             app_on = 0;
2569           }
2570
2571         if (GET_CODE (body) == SEQUENCE)
2572           {
2573             /* A delayed-branch sequence */
2574             register int i;
2575             rtx next;
2576
2577             if (prescan > 0)
2578               break;
2579             final_sequence = body;
2580
2581             /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2582                force the restoration of a comparison that was previously
2583                thought unnecessary.  If that happens, cancel this sequence
2584                and cause that insn to be restored.  */
2585
2586             next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
2587             if (next != XVECEXP (body, 0, 1))
2588               {
2589                 final_sequence = 0;
2590                 return next;
2591               }
2592
2593             for (i = 1; i < XVECLEN (body, 0); i++)
2594               {
2595                 rtx insn = XVECEXP (body, 0, i);
2596                 rtx next = NEXT_INSN (insn);
2597                 /* We loop in case any instruction in a delay slot gets
2598                    split.  */
2599                 do
2600                   insn = final_scan_insn (insn, file, 0, prescan, 1);
2601                 while (insn != next);
2602               }
2603 #ifdef DBR_OUTPUT_SEQEND
2604             DBR_OUTPUT_SEQEND (file);
2605 #endif
2606             final_sequence = 0;
2607
2608             /* If the insn requiring the delay slot was a CALL_INSN, the
2609                insns in the delay slot are actually executed before the
2610                called function.  Hence we don't preserve any CC-setting
2611                actions in these insns and the CC must be marked as being
2612                clobbered by the function.  */
2613             if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
2614               {
2615                 CC_STATUS_INIT;
2616               }
2617
2618             /* Following a conditional branch sequence, we have a new basic
2619                block.  */
2620             if (profile_block_flag)
2621               {
2622                 rtx insn = XVECEXP (body, 0, 0);
2623                 rtx body = PATTERN (insn);
2624
2625                 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2626                      && GET_CODE (SET_SRC (body)) != LABEL_REF)
2627                     || (GET_CODE (insn) == JUMP_INSN
2628                         && GET_CODE (body) == PARALLEL
2629                         && GET_CODE (XVECEXP (body, 0, 0)) == SET
2630                         && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
2631                   new_block = 1;
2632               }
2633             break;
2634           }
2635
2636         /* We have a real machine instruction as rtl.  */
2637
2638         body = PATTERN (insn);
2639
2640 #ifdef HAVE_cc0
2641         set = single_set(insn);
2642
2643         /* Check for redundant test and compare instructions
2644            (when the condition codes are already set up as desired).
2645            This is done only when optimizing; if not optimizing,
2646            it should be possible for the user to alter a variable
2647            with the debugger in between statements
2648            and the next statement should reexamine the variable
2649            to compute the condition codes.  */
2650
2651         if (optimize)
2652           {
2653 #if 0
2654             rtx set = single_set(insn);
2655 #endif
2656
2657             if (set
2658                 && GET_CODE (SET_DEST (set)) == CC0
2659                 && insn != last_ignored_compare)
2660               {
2661                 if (GET_CODE (SET_SRC (set)) == SUBREG)
2662                   SET_SRC (set) = alter_subreg (SET_SRC (set));
2663                 else if (GET_CODE (SET_SRC (set)) == COMPARE)
2664                   {
2665                     if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
2666                       XEXP (SET_SRC (set), 0)
2667                         = alter_subreg (XEXP (SET_SRC (set), 0));
2668                     if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
2669                       XEXP (SET_SRC (set), 1)
2670                         = alter_subreg (XEXP (SET_SRC (set), 1));
2671                   }
2672                 if ((cc_status.value1 != 0
2673                      && rtx_equal_p (SET_SRC (set), cc_status.value1))
2674                     || (cc_status.value2 != 0
2675                         && rtx_equal_p (SET_SRC (set), cc_status.value2)))
2676                   {
2677                     /* Don't delete insn if it has an addressing side-effect.  */
2678                     if (! FIND_REG_INC_NOTE (insn, 0)
2679                         /* or if anything in it is volatile.  */
2680                         && ! volatile_refs_p (PATTERN (insn)))
2681                       {
2682                         /* We don't really delete the insn; just ignore it.  */
2683                         last_ignored_compare = insn;
2684                         break;
2685                       }
2686                   }
2687               }
2688           }
2689 #endif
2690
2691         /* Following a conditional branch, we have a new basic block.
2692            But if we are inside a sequence, the new block starts after the
2693            last insn of the sequence.  */
2694         if (profile_block_flag && final_sequence == 0
2695             && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2696                  && GET_CODE (SET_SRC (body)) != LABEL_REF)
2697                 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
2698                     && GET_CODE (XVECEXP (body, 0, 0)) == SET
2699                     && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
2700           new_block = 1;
2701
2702 #ifndef STACK_REGS
2703         /* Don't bother outputting obvious no-ops, even without -O.
2704            This optimization is fast and doesn't interfere with debugging.
2705            Don't do this if the insn is in a delay slot, since this
2706            will cause an improper number of delay insns to be written.  */
2707         if (final_sequence == 0
2708             && prescan >= 0
2709             && GET_CODE (insn) == INSN && GET_CODE (body) == SET
2710             && GET_CODE (SET_SRC (body)) == REG
2711             && GET_CODE (SET_DEST (body)) == REG
2712             && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
2713           break;
2714 #endif
2715
2716 #ifdef HAVE_cc0
2717         /* If this is a conditional branch, maybe modify it
2718            if the cc's are in a nonstandard state
2719            so that it accomplishes the same thing that it would
2720            do straightforwardly if the cc's were set up normally.  */
2721
2722         if (cc_status.flags != 0
2723             && GET_CODE (insn) == JUMP_INSN
2724             && GET_CODE (body) == SET
2725             && SET_DEST (body) == pc_rtx
2726             && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2727             && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
2728             && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
2729             /* This is done during prescan; it is not done again
2730                in final scan when prescan has been done.  */
2731             && prescan >= 0)
2732           {
2733             /* This function may alter the contents of its argument
2734                and clear some of the cc_status.flags bits.
2735                It may also return 1 meaning condition now always true
2736                or -1 meaning condition now always false
2737                or 2 meaning condition nontrivial but altered.  */
2738             register int result = alter_cond (XEXP (SET_SRC (body), 0));
2739             /* If condition now has fixed value, replace the IF_THEN_ELSE
2740                with its then-operand or its else-operand.  */
2741             if (result == 1)
2742               SET_SRC (body) = XEXP (SET_SRC (body), 1);
2743             if (result == -1)
2744               SET_SRC (body) = XEXP (SET_SRC (body), 2);
2745
2746             /* The jump is now either unconditional or a no-op.
2747                If it has become a no-op, don't try to output it.
2748                (It would not be recognized.)  */
2749             if (SET_SRC (body) == pc_rtx)
2750               {
2751                 PUT_CODE (insn, NOTE);
2752                 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2753                 NOTE_SOURCE_FILE (insn) = 0;
2754                 break;
2755               }
2756             else if (GET_CODE (SET_SRC (body)) == RETURN)
2757               /* Replace (set (pc) (return)) with (return).  */
2758               PATTERN (insn) = body = SET_SRC (body);
2759
2760             /* Rerecognize the instruction if it has changed.  */
2761             if (result != 0)
2762               INSN_CODE (insn) = -1;
2763           }
2764
2765         /* Make same adjustments to instructions that examine the
2766            condition codes without jumping and instructions that
2767            handle conditional moves (if this machine has either one).  */
2768
2769         if (cc_status.flags != 0
2770             && set != 0)
2771           {
2772             rtx cond_rtx, then_rtx, else_rtx;
2773             
2774             if (GET_CODE (insn) != JUMP_INSN
2775                 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2776               {
2777                 cond_rtx = XEXP (SET_SRC (set), 0);
2778                 then_rtx = XEXP (SET_SRC (set), 1);
2779                 else_rtx = XEXP (SET_SRC (set), 2);
2780               }
2781             else
2782               {
2783                 cond_rtx = SET_SRC (set);
2784                 then_rtx = const_true_rtx;
2785                 else_rtx = const0_rtx;
2786               }
2787             
2788             switch (GET_CODE (cond_rtx))
2789               {
2790               case GTU:
2791               case GT:
2792               case LTU:
2793               case LT:
2794               case GEU:
2795               case GE:
2796               case LEU:
2797               case LE:
2798               case EQ:
2799               case NE:
2800                 {
2801                   register int result;
2802                   if (XEXP (cond_rtx, 0) != cc0_rtx)
2803                     break;
2804                   result = alter_cond (cond_rtx);
2805                   if (result == 1)
2806                     validate_change (insn, &SET_SRC (set), then_rtx, 0);
2807                   else if (result == -1)
2808                     validate_change (insn, &SET_SRC (set), else_rtx, 0);
2809                   else if (result == 2)
2810                     INSN_CODE (insn) = -1;
2811                   if (SET_DEST (set) == SET_SRC (set))
2812                     {
2813                       PUT_CODE (insn, NOTE);
2814                       NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2815                       NOTE_SOURCE_FILE (insn) = 0;
2816                     }
2817                 }
2818                 break;
2819
2820               default:
2821                 break;
2822               }
2823           }
2824
2825 #endif
2826
2827 #ifdef HAVE_peephole
2828         /* Do machine-specific peephole optimizations if desired.  */
2829
2830         if (optimize && !flag_no_peephole && !nopeepholes)
2831           {
2832             rtx next = peephole (insn);
2833             /* When peepholing, if there were notes within the peephole,
2834                emit them before the peephole.  */
2835             if (next != 0 && next != NEXT_INSN (insn))
2836               {
2837                 rtx prev = PREV_INSN (insn);
2838                 rtx note;
2839
2840                 for (note = NEXT_INSN (insn); note != next;
2841                      note = NEXT_INSN (note))
2842                   final_scan_insn (note, file, optimize, prescan, nopeepholes);
2843
2844                 /* In case this is prescan, put the notes
2845                    in proper position for later rescan.  */
2846                 note = NEXT_INSN (insn);
2847                 PREV_INSN (note) = prev;
2848                 NEXT_INSN (prev) = note;
2849                 NEXT_INSN (PREV_INSN (next)) = insn;
2850                 PREV_INSN (insn) = PREV_INSN (next);
2851                 NEXT_INSN (insn) = next;
2852                 PREV_INSN (next) = insn;
2853               }
2854
2855             /* PEEPHOLE might have changed this.  */
2856             body = PATTERN (insn);
2857           }
2858 #endif
2859
2860         /* Try to recognize the instruction.
2861            If successful, verify that the operands satisfy the
2862            constraints for the instruction.  Crash if they don't,
2863            since `reload' should have changed them so that they do.  */
2864
2865         insn_code_number = recog_memoized (insn);
2866         extract_insn (insn);
2867         cleanup_subreg_operands (insn);
2868
2869         if (! constrain_operands (1))
2870           fatal_insn_not_found (insn);
2871
2872         /* Some target machines need to prescan each insn before
2873            it is output.  */
2874
2875 #ifdef FINAL_PRESCAN_INSN
2876         FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2877 #endif
2878
2879 #ifdef HAVE_cc0
2880         cc_prev_status = cc_status;
2881
2882         /* Update `cc_status' for this instruction.
2883            The instruction's output routine may change it further.
2884            If the output routine for a jump insn needs to depend
2885            on the cc status, it should look at cc_prev_status.  */
2886
2887         NOTICE_UPDATE_CC (body, insn);
2888 #endif
2889
2890         debug_insn = insn;
2891
2892 #if defined (DWARF2_UNWIND_INFO)
2893         /* If we push arguments, we want to know where the calls are.  */
2894         if (!ACCUMULATE_OUTGOING_ARGS && GET_CODE (insn) == CALL_INSN
2895             && dwarf2out_do_frame ())
2896           dwarf2out_frame_debug (insn);
2897 #endif
2898
2899         /* Find the proper template for this insn.  */
2900         template = get_insn_template (insn_code_number, insn);
2901
2902         /* If the C code returns 0, it means that it is a jump insn
2903            which follows a deleted test insn, and that test insn
2904            needs to be reinserted.  */
2905         if (template == 0)
2906           {
2907             if (prev_nonnote_insn (insn) != last_ignored_compare)
2908               abort ();
2909             new_block = 0;
2910             return prev_nonnote_insn (insn);
2911           }
2912
2913         /* If the template is the string "#", it means that this insn must
2914            be split.  */
2915         if (template[0] == '#' && template[1] == '\0')
2916           {
2917             rtx new = try_split (body, insn, 0);
2918
2919             /* If we didn't split the insn, go away.  */
2920             if (new == insn && PATTERN (new) == body)
2921               fatal_insn ("Could not split insn", insn);
2922               
2923 #ifdef HAVE_ATTR_length
2924             /* This instruction should have been split in shorten_branches,
2925                to ensure that we would have valid length info for the
2926                splitees.  */
2927             abort ();
2928 #endif
2929
2930             new_block = 0;
2931             return new;
2932           }
2933         
2934         if (prescan > 0)
2935           break;
2936
2937         /* Output assembler code from the template.  */
2938
2939         output_asm_insn (template, recog_data.operand);
2940
2941 #if defined (DWARF2_UNWIND_INFO)
2942         /* If we push arguments, we need to check all insns for stack
2943            adjustments.  */
2944         if (!ACCUMULATE_OUTGOING_ARGS)
2945           {
2946             if (GET_CODE (insn) == INSN && dwarf2out_do_frame ())
2947               dwarf2out_frame_debug (insn);
2948           }
2949         else
2950           {
2951 #if defined (HAVE_prologue)
2952             /* If this insn is part of the prologue, emit DWARF v2
2953                call frame info.  */
2954             if (RTX_FRAME_RELATED_P (insn) && dwarf2out_do_frame ())
2955               dwarf2out_frame_debug (insn);
2956 #endif
2957           }
2958 #endif
2959
2960 #if 0
2961         /* It's not at all clear why we did this and doing so interferes
2962            with tests we'd like to do to use REG_WAS_0 notes, so let's try
2963            with this out.  */
2964
2965         /* Mark this insn as having been output.  */
2966         INSN_DELETED_P (insn) = 1;
2967 #endif
2968
2969         debug_insn = 0;
2970       }
2971     }
2972   return NEXT_INSN (insn);
2973 }
2974 \f
2975 /* Output debugging info to the assembler file FILE
2976    based on the NOTE-insn INSN, assumed to be a line number.  */
2977
2978 static void
2979 output_source_line (file, insn)
2980      FILE *file ATTRIBUTE_UNUSED;
2981      rtx insn;
2982 {
2983   register const char *filename = NOTE_SOURCE_FILE (insn);
2984
2985   /* Remember filename for basic block profiling.
2986      Filenames are allocated on the permanent obstack
2987      or are passed in ARGV, so we don't have to save
2988      the string.  */
2989
2990   if (profile_block_flag && last_filename != filename)
2991     bb_file_label_num = add_bb_string (filename, TRUE);
2992
2993   last_filename = filename;
2994   last_linenum = NOTE_LINE_NUMBER (insn);
2995   high_block_linenum = MAX (last_linenum, high_block_linenum);
2996   high_function_linenum = MAX (last_linenum, high_function_linenum);
2997
2998   if (write_symbols != NO_DEBUG)
2999     {
3000 #ifdef SDB_DEBUGGING_INFO
3001       if (write_symbols == SDB_DEBUG
3002 #if 0 /* People like having line numbers even in wrong file!  */
3003           /* COFF can't handle multiple source files--lose, lose.  */
3004           && !strcmp (filename, main_input_filename)
3005 #endif
3006           /* COFF relative line numbers must be positive.  */
3007           && last_linenum > sdb_begin_function_line)
3008         {
3009 #ifdef ASM_OUTPUT_SOURCE_LINE
3010           ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
3011 #else
3012           fprintf (file, "\t.ln\t%d\n",
3013                    ((sdb_begin_function_line > -1)
3014                     ? last_linenum - sdb_begin_function_line : 1));
3015 #endif
3016         }
3017 #endif
3018
3019 #if defined (DBX_DEBUGGING_INFO)
3020       if (write_symbols == DBX_DEBUG)
3021         dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
3022 #endif
3023
3024 #if defined (XCOFF_DEBUGGING_INFO)
3025       if (write_symbols == XCOFF_DEBUG)
3026         xcoffout_source_line (file, filename, insn);
3027 #endif
3028
3029 #ifdef DWARF_DEBUGGING_INFO
3030       if (write_symbols == DWARF_DEBUG)
3031         dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
3032 #endif
3033
3034 #ifdef DWARF2_DEBUGGING_INFO
3035       if (write_symbols == DWARF2_DEBUG)
3036         dwarf2out_line (filename, NOTE_LINE_NUMBER (insn));
3037 #endif
3038     }
3039 }
3040 \f
3041
3042 /* For each operand in INSN, simplify (subreg (reg)) so that it refers
3043    directly to the desired hard register.  */
3044 void
3045 cleanup_subreg_operands (insn)
3046      rtx insn;
3047 {
3048   int i;
3049
3050   extract_insn (insn);
3051   for (i = 0; i < recog_data.n_operands; i++)
3052     {
3053       if (GET_CODE (recog_data.operand[i]) == SUBREG)
3054         recog_data.operand[i] = alter_subreg (recog_data.operand[i]);
3055       else if (GET_CODE (recog_data.operand[i]) == PLUS
3056                || GET_CODE (recog_data.operand[i]) == MULT)
3057        recog_data.operand[i] = walk_alter_subreg (recog_data.operand[i]);
3058     }
3059
3060   for (i = 0; i < recog_data.n_dups; i++)
3061     {
3062       if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
3063         *recog_data.dup_loc[i] = alter_subreg (*recog_data.dup_loc[i]);
3064       else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
3065                || GET_CODE (*recog_data.dup_loc[i]) == MULT)
3066         *recog_data.dup_loc[i] = walk_alter_subreg (*recog_data.dup_loc[i]);
3067     }
3068 }
3069
3070 /* If X is a SUBREG, replace it with a REG or a MEM,
3071    based on the thing it is a subreg of.  */
3072
3073 rtx
3074 alter_subreg (x)
3075      register rtx x;
3076 {
3077   register rtx y = SUBREG_REG (x);
3078
3079   if (GET_CODE (y) == SUBREG)
3080     y = alter_subreg (y);
3081
3082   /* If reload is operating, we may be replacing inside this SUBREG.
3083      Check for that and make a new one if so.  */
3084   if (reload_in_progress && find_replacement (&SUBREG_REG (x)) != 0)
3085     x = copy_rtx (x);
3086
3087   if (GET_CODE (y) == REG)
3088     {
3089       int regno;
3090       /* If the word size is larger than the size of this register,
3091          adjust the register number to compensate.  */
3092       /* ??? Note that this just catches stragglers created by/for
3093          integrate.  It would be better if we either caught these
3094          earlier, or kept _all_ subregs until now and eliminate
3095          gen_lowpart and friends.  */
3096
3097 #ifdef ALTER_HARD_SUBREG
3098       regno = ALTER_HARD_SUBREG(GET_MODE (x), SUBREG_WORD (x),
3099                                 GET_MODE (y), REGNO (y));
3100 #else
3101       regno = REGNO (y) + SUBREG_WORD (x);
3102 #endif
3103       PUT_CODE (x, REG);
3104       REGNO (x) = regno;
3105       /* This field has a different meaning for REGs and SUBREGs.  Make sure
3106          to clear it!  */
3107       x->used = 0;
3108     }
3109   else if (GET_CODE (y) == MEM)
3110     {
3111       register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
3112       if (BYTES_BIG_ENDIAN)
3113         offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
3114                    - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
3115       PUT_CODE (x, MEM);
3116       MEM_COPY_ATTRIBUTES (x, y);
3117       MEM_ALIAS_SET (x) = MEM_ALIAS_SET (y);
3118       XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
3119     }
3120
3121   return x;
3122 }
3123
3124 /* Do alter_subreg on all the SUBREGs contained in X.  */
3125
3126 static rtx
3127 walk_alter_subreg (x)
3128      rtx x;
3129 {
3130   switch (GET_CODE (x))
3131     {
3132     case PLUS:
3133     case MULT:
3134       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3135       XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
3136       break;
3137
3138     case MEM:
3139       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3140       break;
3141
3142     case SUBREG:
3143       return alter_subreg (x);
3144       
3145     default:
3146       break;
3147     }
3148
3149   return x;
3150 }
3151 \f
3152 #ifdef HAVE_cc0
3153
3154 /* Given BODY, the body of a jump instruction, alter the jump condition
3155    as required by the bits that are set in cc_status.flags.
3156    Not all of the bits there can be handled at this level in all cases.
3157
3158    The value is normally 0.
3159    1 means that the condition has become always true.
3160    -1 means that the condition has become always false.
3161    2 means that COND has been altered.  */
3162
3163 static int
3164 alter_cond (cond)
3165      register rtx cond;
3166 {
3167   int value = 0;
3168
3169   if (cc_status.flags & CC_REVERSED)
3170     {
3171       value = 2;
3172       PUT_CODE (cond, swap_condition (GET_CODE (cond)));
3173     }
3174
3175   if (cc_status.flags & CC_INVERTED)
3176     {
3177       value = 2;
3178       PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
3179     }
3180
3181   if (cc_status.flags & CC_NOT_POSITIVE)
3182     switch (GET_CODE (cond))
3183       {
3184       case LE:
3185       case LEU:
3186       case GEU:
3187         /* Jump becomes unconditional.  */
3188         return 1;
3189
3190       case GT:
3191       case GTU:
3192       case LTU:
3193         /* Jump becomes no-op.  */
3194         return -1;
3195
3196       case GE:
3197         PUT_CODE (cond, EQ);
3198         value = 2;
3199         break;
3200
3201       case LT:
3202         PUT_CODE (cond, NE);
3203         value = 2;
3204         break;
3205         
3206       default:
3207         break;
3208       }
3209
3210   if (cc_status.flags & CC_NOT_NEGATIVE)
3211     switch (GET_CODE (cond))
3212       {
3213       case GE:
3214       case GEU:
3215         /* Jump becomes unconditional.  */
3216         return 1;
3217
3218       case LT:
3219       case LTU:
3220         /* Jump becomes no-op.  */
3221         return -1;
3222
3223       case LE:
3224       case LEU:
3225         PUT_CODE (cond, EQ);
3226         value = 2;
3227         break;
3228
3229       case GT:
3230       case GTU:
3231         PUT_CODE (cond, NE);
3232         value = 2;
3233         break;
3234         
3235       default:
3236         break;
3237       }
3238
3239   if (cc_status.flags & CC_NO_OVERFLOW)
3240     switch (GET_CODE (cond))
3241       {
3242       case GEU:
3243         /* Jump becomes unconditional.  */
3244         return 1;
3245
3246       case LEU:
3247         PUT_CODE (cond, EQ);
3248         value = 2;
3249         break;
3250
3251       case GTU:
3252         PUT_CODE (cond, NE);
3253         value = 2;
3254         break;
3255
3256       case LTU:
3257         /* Jump becomes no-op.  */
3258         return -1;
3259         
3260       default:
3261         break;
3262       }
3263
3264   if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
3265     switch (GET_CODE (cond))
3266       {
3267       default:
3268         abort ();
3269
3270       case NE:
3271         PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
3272         value = 2;
3273         break;
3274
3275       case EQ:
3276         PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
3277         value = 2;
3278         break;
3279       }
3280
3281   if (cc_status.flags & CC_NOT_SIGNED)
3282     /* The flags are valid if signed condition operators are converted
3283        to unsigned.  */
3284     switch (GET_CODE (cond))
3285       {
3286       case LE:
3287         PUT_CODE (cond, LEU);
3288         value = 2;
3289         break;
3290
3291       case LT:
3292         PUT_CODE (cond, LTU);
3293         value = 2;
3294         break;
3295
3296       case GT:
3297         PUT_CODE (cond, GTU);
3298         value = 2;
3299         break;
3300
3301       case GE:
3302         PUT_CODE (cond, GEU);
3303         value = 2;
3304         break;
3305
3306       default:
3307         break;
3308       }
3309
3310   return value;
3311 }
3312 #endif
3313 \f
3314 /* Report inconsistency between the assembler template and the operands.
3315    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
3316
3317 void
3318 output_operand_lossage (msgid)
3319      const char *msgid;
3320 {
3321   if (this_is_asm_operands)
3322     error_for_asm (this_is_asm_operands, "invalid `asm': %s", _(msgid));
3323   else
3324     {
3325       error ("output_operand: %s", _(msgid));
3326       abort ();
3327     }
3328 }
3329 \f
3330 /* Output of assembler code from a template, and its subroutines.  */
3331
3332 /* Output text from TEMPLATE to the assembler output file,
3333    obeying %-directions to substitute operands taken from
3334    the vector OPERANDS.
3335
3336    %N (for N a digit) means print operand N in usual manner.
3337    %lN means require operand N to be a CODE_LABEL or LABEL_REF
3338       and print the label name with no punctuation.
3339    %cN means require operand N to be a constant
3340       and print the constant expression with no punctuation.
3341    %aN means expect operand N to be a memory address
3342       (not a memory reference!) and print a reference
3343       to that address.
3344    %nN means expect operand N to be a constant
3345       and print a constant expression for minus the value
3346       of the operand, with no other punctuation.  */
3347
3348 static void
3349 output_asm_name ()
3350 {
3351   if (flag_print_asm_name)
3352     {
3353       /* Annotate the assembly with a comment describing the pattern and
3354          alternative used.  */
3355       if (debug_insn)
3356         {
3357           register int num = INSN_CODE (debug_insn);
3358           fprintf (asm_out_file, "\t%s %d\t%s", 
3359                    ASM_COMMENT_START, INSN_UID (debug_insn),
3360                    insn_data[num].name);
3361           if (insn_data[num].n_alternatives > 1)
3362             fprintf (asm_out_file, "/%d", which_alternative + 1);
3363 #ifdef HAVE_ATTR_length
3364           fprintf (asm_out_file, "\t[length = %d]",
3365                    get_attr_length (debug_insn));
3366 #endif
3367           /* Clear this so only the first assembler insn
3368              of any rtl insn will get the special comment for -dp.  */
3369           debug_insn = 0;
3370         }
3371     }
3372 }
3373
3374 void
3375 output_asm_insn (template, operands)
3376      const char *template;
3377      rtx *operands;
3378 {
3379   register const char *p;
3380   register int c;
3381
3382   /* An insn may return a null string template
3383      in a case where no assembler code is needed.  */
3384   if (*template == 0)
3385     return;
3386
3387   p = template;
3388   putc ('\t', asm_out_file);
3389
3390 #ifdef ASM_OUTPUT_OPCODE
3391   ASM_OUTPUT_OPCODE (asm_out_file, p);
3392 #endif
3393
3394   while ((c = *p++))
3395     switch (c)
3396       {
3397       case '\n':
3398         output_asm_name ();
3399         putc (c, asm_out_file);
3400 #ifdef ASM_OUTPUT_OPCODE
3401         while ((c = *p) == '\t')
3402           {
3403             putc (c, asm_out_file);
3404             p++;
3405           }
3406         ASM_OUTPUT_OPCODE (asm_out_file, p);
3407 #endif
3408         break;
3409
3410 #ifdef ASSEMBLER_DIALECT
3411       case '{':
3412         {
3413           register int i;
3414           
3415           /* If we want the first dialect, do nothing.  Otherwise, skip
3416              DIALECT_NUMBER of strings ending with '|'.  */
3417           for (i = 0; i < dialect_number; i++)
3418             {
3419               while (*p && *p != '}' && *p++ != '|')
3420                 ;
3421               if (*p == '}')
3422                 break;
3423               if (*p == '|')
3424                 p++;
3425             }
3426         }
3427         break;
3428
3429       case '|':
3430         /* Skip to close brace.  */
3431         while (*p && *p++ != '}')
3432           ;
3433         break;
3434
3435       case '}':
3436         break;
3437 #endif
3438
3439       case '%':
3440         /* %% outputs a single %.  */
3441         if (*p == '%')
3442           {
3443             p++;
3444             putc (c, asm_out_file);
3445           }
3446         /* %= outputs a number which is unique to each insn in the entire
3447            compilation.  This is useful for making local labels that are
3448            referred to more than once in a given insn.  */
3449         else if (*p == '=')
3450           {
3451             p++;
3452             fprintf (asm_out_file, "%d", insn_counter);
3453           }
3454         /* % followed by a letter and some digits
3455            outputs an operand in a special way depending on the letter.
3456            Letters `acln' are implemented directly.
3457            Other letters are passed to `output_operand' so that
3458            the PRINT_OPERAND macro can define them.  */
3459         else if ((*p >= 'a' && *p <= 'z')
3460                  || (*p >= 'A' && *p <= 'Z'))
3461           {
3462             int letter = *p++;
3463             c = atoi (p);
3464
3465             if (! (*p >= '0' && *p <= '9'))
3466               output_operand_lossage ("operand number missing after %-letter");
3467             else if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3468               output_operand_lossage ("operand number out of range");
3469             else if (letter == 'l')
3470               output_asm_label (operands[c]);
3471             else if (letter == 'a')
3472               output_address (operands[c]);
3473             else if (letter == 'c')
3474               {
3475                 if (CONSTANT_ADDRESS_P (operands[c]))
3476                   output_addr_const (asm_out_file, operands[c]);
3477                 else
3478                   output_operand (operands[c], 'c');
3479               }
3480             else if (letter == 'n')
3481               {
3482                 if (GET_CODE (operands[c]) == CONST_INT)
3483                   fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3484                            - INTVAL (operands[c]));
3485                 else
3486                   {
3487                     putc ('-', asm_out_file);
3488                     output_addr_const (asm_out_file, operands[c]);
3489                   }
3490               }
3491             else
3492               output_operand (operands[c], letter);
3493             
3494             while ((c = *p) >= '0' && c <= '9') p++;
3495           }
3496         /* % followed by a digit outputs an operand the default way.  */
3497         else if (*p >= '0' && *p <= '9')
3498           {
3499             c = atoi (p);
3500             if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3501               output_operand_lossage ("operand number out of range");
3502             else
3503               output_operand (operands[c], 0);
3504             while ((c = *p) >= '0' && c <= '9') p++;
3505           }
3506         /* % followed by punctuation: output something for that
3507            punctuation character alone, with no operand.
3508            The PRINT_OPERAND macro decides what is actually done.  */
3509 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3510         else if (PRINT_OPERAND_PUNCT_VALID_P ((unsigned char)*p))
3511           output_operand (NULL_RTX, *p++);
3512 #endif
3513         else
3514           output_operand_lossage ("invalid %%-code");
3515         break;
3516
3517       default:
3518         putc (c, asm_out_file);
3519       }
3520
3521   output_asm_name ();
3522
3523   putc ('\n', asm_out_file);
3524 }
3525 \f
3526 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol.  */
3527
3528 void
3529 output_asm_label (x)
3530      rtx x;
3531 {
3532   char buf[256];
3533
3534   if (GET_CODE (x) == LABEL_REF)
3535     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
3536   else if (GET_CODE (x) == CODE_LABEL)
3537     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3538   else
3539     output_operand_lossage ("`%l' operand isn't a label");
3540
3541   assemble_name (asm_out_file, buf);
3542 }
3543
3544 /* Print operand X using machine-dependent assembler syntax.
3545    The macro PRINT_OPERAND is defined just to control this function.
3546    CODE is a non-digit that preceded the operand-number in the % spec,
3547    such as 'z' if the spec was `%z3'.  CODE is 0 if there was no char
3548    between the % and the digits.
3549    When CODE is a non-letter, X is 0.
3550
3551    The meanings of the letters are machine-dependent and controlled
3552    by PRINT_OPERAND.  */
3553
3554 static void
3555 output_operand (x, code)
3556      rtx x;
3557      int code ATTRIBUTE_UNUSED;
3558 {
3559   if (x && GET_CODE (x) == SUBREG)
3560     x = alter_subreg (x);
3561
3562   /* If X is a pseudo-register, abort now rather than writing trash to the
3563      assembler file.  */
3564
3565   if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
3566     abort ();
3567
3568   PRINT_OPERAND (asm_out_file, x, code);
3569 }
3570
3571 /* Print a memory reference operand for address X
3572    using machine-dependent assembler syntax.
3573    The macro PRINT_OPERAND_ADDRESS exists just to control this function.  */
3574
3575 void
3576 output_address (x)
3577      rtx x;
3578 {
3579   walk_alter_subreg (x);
3580   PRINT_OPERAND_ADDRESS (asm_out_file, x);
3581 }
3582 \f
3583 /* Print an integer constant expression in assembler syntax.
3584    Addition and subtraction are the only arithmetic
3585    that may appear in these expressions.  */
3586
3587 void
3588 output_addr_const (file, x)
3589      FILE *file;
3590      rtx x;
3591 {
3592   char buf[256];
3593
3594  restart:
3595   switch (GET_CODE (x))
3596     {
3597     case PC:
3598       if (flag_pic)
3599         putc ('.', file);
3600       else
3601         abort ();
3602       break;
3603
3604     case SYMBOL_REF:
3605       assemble_name (file, XSTR (x, 0));
3606       break;
3607
3608     case LABEL_REF:
3609       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
3610       assemble_name (file, buf);
3611       break;
3612
3613     case CODE_LABEL:
3614       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3615       assemble_name (file, buf);
3616       break;
3617
3618     case CONST_INT:
3619       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3620       break;
3621
3622     case CONST:
3623       /* This used to output parentheses around the expression,
3624          but that does not work on the 386 (either ATT or BSD assembler).  */
3625       output_addr_const (file, XEXP (x, 0));
3626       break;
3627
3628     case CONST_DOUBLE:
3629       if (GET_MODE (x) == VOIDmode)
3630         {
3631           /* We can use %d if the number is one word and positive.  */
3632           if (CONST_DOUBLE_HIGH (x))
3633             fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3634                      CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3635           else if  (CONST_DOUBLE_LOW (x) < 0)
3636             fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3637           else
3638             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3639         }
3640       else
3641         /* We can't handle floating point constants;
3642            PRINT_OPERAND must handle them.  */
3643         output_operand_lossage ("floating constant misused");
3644       break;
3645
3646     case PLUS:
3647       /* Some assemblers need integer constants to appear last (eg masm).  */
3648       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3649         {
3650           output_addr_const (file, XEXP (x, 1));
3651           if (INTVAL (XEXP (x, 0)) >= 0)
3652             fprintf (file, "+");
3653           output_addr_const (file, XEXP (x, 0));
3654         }
3655       else
3656         {
3657           output_addr_const (file, XEXP (x, 0));
3658           if (INTVAL (XEXP (x, 1)) >= 0)
3659             fprintf (file, "+");
3660           output_addr_const (file, XEXP (x, 1));
3661         }
3662       break;
3663
3664     case MINUS:
3665       /* Avoid outputting things like x-x or x+5-x,
3666          since some assemblers can't handle that.  */
3667       x = simplify_subtraction (x);
3668       if (GET_CODE (x) != MINUS)
3669         goto restart;
3670
3671       output_addr_const (file, XEXP (x, 0));
3672       fprintf (file, "-");
3673       if (GET_CODE (XEXP (x, 1)) == CONST_INT
3674           && INTVAL (XEXP (x, 1)) < 0)
3675         {
3676           fprintf (file, "%s", ASM_OPEN_PAREN);
3677           output_addr_const (file, XEXP (x, 1));
3678           fprintf (file, "%s", ASM_CLOSE_PAREN);
3679         }
3680       else
3681         output_addr_const (file, XEXP (x, 1));
3682       break;
3683
3684     case ZERO_EXTEND:
3685     case SIGN_EXTEND:
3686       output_addr_const (file, XEXP (x, 0));
3687       break;
3688
3689     default:
3690       output_operand_lossage ("invalid expression as operand");
3691     }
3692 }
3693 \f
3694 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3695    %R prints the value of REGISTER_PREFIX.
3696    %L prints the value of LOCAL_LABEL_PREFIX.
3697    %U prints the value of USER_LABEL_PREFIX.
3698    %I prints the value of IMMEDIATE_PREFIX.
3699    %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3700    Also supported are %d, %x, %s, %e, %f, %g and %%.
3701
3702    We handle alternate assembler dialects here, just like output_asm_insn.  */
3703
3704 void
3705 asm_fprintf VPARAMS ((FILE *file, const char *p, ...))
3706 {
3707 #ifndef ANSI_PROTOTYPES
3708   FILE *file;
3709   const char *p;
3710 #endif
3711   va_list argptr;
3712   char buf[10];
3713   char *q, c;
3714
3715   VA_START (argptr, p);
3716
3717 #ifndef ANSI_PROTOTYPES
3718   file = va_arg (argptr, FILE *);
3719   p = va_arg (argptr, const char *);
3720 #endif
3721
3722   buf[0] = '%';
3723
3724   while ((c = *p++))
3725     switch (c)
3726       {
3727 #ifdef ASSEMBLER_DIALECT
3728       case '{':
3729         {
3730           int i;
3731
3732           /* If we want the first dialect, do nothing.  Otherwise, skip
3733              DIALECT_NUMBER of strings ending with '|'.  */
3734           for (i = 0; i < dialect_number; i++)
3735             {
3736               while (*p && *p++ != '|')
3737                 ;
3738
3739               if (*p == '|')
3740                 p++;
3741           }
3742         }
3743         break;
3744
3745       case '|':
3746         /* Skip to close brace.  */
3747         while (*p && *p++ != '}')
3748           ;
3749         break;
3750
3751       case '}':
3752         break;
3753 #endif
3754
3755       case '%':
3756         c = *p++;
3757         q = &buf[1];
3758         while ((c >= '0' && c <= '9') || c == '.')
3759           {
3760             *q++ = c;
3761             c = *p++;
3762           }
3763         switch (c)
3764           {
3765           case '%':
3766             fprintf (file, "%%");
3767             break;
3768
3769           case 'd':  case 'i':  case 'u':
3770           case 'x':  case 'p':  case 'X':
3771           case 'o':
3772             *q++ = c;
3773             *q = 0;
3774             fprintf (file, buf, va_arg (argptr, int));
3775             break;
3776
3777           case 'w':
3778             /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3779                but we do not check for those cases.  It means that the value
3780                is a HOST_WIDE_INT, which may be either `int' or `long'.  */
3781
3782 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3783 #else
3784 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3785             *q++ = 'l';
3786 #else
3787             *q++ = 'l';
3788             *q++ = 'l';
3789 #endif
3790 #endif
3791
3792             *q++ = *p++;
3793             *q = 0;
3794             fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3795             break;
3796
3797           case 'l':
3798             *q++ = c;
3799             *q++ = *p++;
3800             *q = 0;
3801             fprintf (file, buf, va_arg (argptr, long));
3802             break;
3803
3804           case 'e':
3805           case 'f':
3806           case 'g':
3807             *q++ = c;
3808             *q = 0;
3809             fprintf (file, buf, va_arg (argptr, double));
3810             break;
3811
3812           case 's':
3813             *q++ = c;
3814             *q = 0;
3815             fprintf (file, buf, va_arg (argptr, char *));
3816             break;
3817
3818           case 'O':
3819 #ifdef ASM_OUTPUT_OPCODE
3820             ASM_OUTPUT_OPCODE (asm_out_file, p);
3821 #endif
3822             break;
3823
3824           case 'R':
3825 #ifdef REGISTER_PREFIX
3826             fprintf (file, "%s", REGISTER_PREFIX);
3827 #endif
3828             break;
3829
3830           case 'I':
3831 #ifdef IMMEDIATE_PREFIX
3832             fprintf (file, "%s", IMMEDIATE_PREFIX);
3833 #endif
3834             break;
3835
3836           case 'L':
3837 #ifdef LOCAL_LABEL_PREFIX
3838             fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3839 #endif
3840             break;
3841
3842           case 'U':
3843             fputs (user_label_prefix, file);
3844             break;
3845
3846 #ifdef ASM_FPRINTF_EXTENSIONS
3847             /* Upper case letters are reserved for general use by asm_fprintf
3848                and so are not available to target specific code.  In order to
3849                prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
3850                they are defined here.  As they get turned into real extensions
3851                to asm_fprintf they should be removed from this list.  */
3852           case 'A': case 'B': case 'C': case 'D': case 'E':
3853           case 'F': case 'G': case 'H': case 'J': case 'K':
3854           case 'M': case 'N': case 'P': case 'Q': case 'S':
3855           case 'T': case 'V': case 'W': case 'Y': case 'Z':
3856             break;
3857             
3858           ASM_FPRINTF_EXTENSIONS (file, argptr, p)
3859 #endif
3860           default:
3861             abort ();
3862           }
3863         break;
3864
3865       default:
3866         fputc (c, file);
3867       }
3868   va_end (argptr);
3869 }
3870 \f
3871 /* Split up a CONST_DOUBLE or integer constant rtx
3872    into two rtx's for single words,
3873    storing in *FIRST the word that comes first in memory in the target
3874    and in *SECOND the other.  */
3875
3876 void
3877 split_double (value, first, second)
3878      rtx value;
3879      rtx *first, *second;
3880 {
3881   if (GET_CODE (value) == CONST_INT)
3882     {
3883       if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3884         {
3885           /* In this case the CONST_INT holds both target words.
3886              Extract the bits from it into two word-sized pieces.
3887              Sign extend each half to HOST_WIDE_INT.  */
3888           rtx low, high;
3889           /* On machines where HOST_BITS_PER_WIDE_INT == BITS_PER_WORD
3890              the shift below will cause a compiler warning, even though
3891              this code won't be executed.  So put the shift amounts in
3892              variables to avoid the warning.  */
3893           int rshift = HOST_BITS_PER_WIDE_INT - BITS_PER_WORD;
3894           int lshift = HOST_BITS_PER_WIDE_INT - 2 * BITS_PER_WORD;
3895
3896           low = GEN_INT ((INTVAL (value) << rshift) >> rshift);
3897           high = GEN_INT ((INTVAL (value) << lshift) >> rshift);
3898           if (WORDS_BIG_ENDIAN)
3899             {
3900               *first = high;
3901               *second = low;
3902             }
3903           else
3904             {
3905               *first = low;
3906               *second = high;
3907             }
3908         }
3909       else
3910         {
3911           /* The rule for using CONST_INT for a wider mode
3912              is that we regard the value as signed.
3913              So sign-extend it.  */
3914           rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3915           if (WORDS_BIG_ENDIAN)
3916             {
3917               *first = high;
3918               *second = value;
3919             }
3920           else
3921             {
3922               *first = value;
3923               *second = high;
3924             }
3925         }
3926     }
3927   else if (GET_CODE (value) != CONST_DOUBLE)
3928     {
3929       if (WORDS_BIG_ENDIAN)
3930         {
3931           *first = const0_rtx;
3932           *second = value;
3933         }
3934       else
3935         {
3936           *first = value;
3937           *second = const0_rtx;
3938         }
3939     }
3940   else if (GET_MODE (value) == VOIDmode
3941            /* This is the old way we did CONST_DOUBLE integers.  */
3942            || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3943     {
3944       /* In an integer, the words are defined as most and least significant.
3945          So order them by the target's convention.  */
3946       if (WORDS_BIG_ENDIAN)
3947         {
3948           *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3949           *second = GEN_INT (CONST_DOUBLE_LOW (value));
3950         }
3951       else
3952         {
3953           *first = GEN_INT (CONST_DOUBLE_LOW (value));
3954           *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3955         }
3956     }
3957   else
3958     {
3959 #ifdef REAL_ARITHMETIC
3960       REAL_VALUE_TYPE r; long l[2];
3961       REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3962
3963       /* Note, this converts the REAL_VALUE_TYPE to the target's
3964          format, splits up the floating point double and outputs
3965          exactly 32 bits of it into each of l[0] and l[1] --
3966          not necessarily BITS_PER_WORD bits.  */
3967       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3968
3969       /* If 32 bits is an entire word for the target, but not for the host,
3970          then sign-extend on the host so that the number will look the same
3971          way on the host that it would on the target.  See for instance
3972          simplify_unary_operation.  The #if is needed to avoid compiler
3973          warnings.  */
3974
3975 #if HOST_BITS_PER_LONG > 32
3976       if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
3977         {
3978           if (l[0] & ((long) 1 << 31))
3979             l[0] |= ((long) (-1) << 32);
3980           if (l[1] & ((long) 1 << 31))
3981             l[1] |= ((long) (-1) << 32);
3982         }
3983 #endif
3984
3985       *first = GEN_INT ((HOST_WIDE_INT) l[0]);
3986       *second = GEN_INT ((HOST_WIDE_INT) l[1]);
3987 #else
3988       if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3989            || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3990           && ! flag_pretend_float)
3991       abort ();
3992
3993       if (
3994 #ifdef HOST_WORDS_BIG_ENDIAN
3995           WORDS_BIG_ENDIAN
3996 #else
3997           ! WORDS_BIG_ENDIAN
3998 #endif
3999           )
4000         {
4001           /* Host and target agree => no need to swap.  */
4002           *first = GEN_INT (CONST_DOUBLE_LOW (value));
4003           *second = GEN_INT (CONST_DOUBLE_HIGH (value));
4004         }
4005       else
4006         {
4007           *second = GEN_INT (CONST_DOUBLE_LOW (value));
4008           *first = GEN_INT (CONST_DOUBLE_HIGH (value));
4009         }
4010 #endif /* no REAL_ARITHMETIC */
4011     }
4012 }
4013 \f
4014 /* Return nonzero if this function has no function calls.  */
4015
4016 int
4017 leaf_function_p ()
4018 {
4019   rtx insn;
4020
4021   if (profile_flag || profile_block_flag || profile_arc_flag)
4022     return 0;
4023
4024   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4025     {
4026       if (GET_CODE (insn) == CALL_INSN
4027           && ! SIBLING_CALL_P (insn))
4028         return 0;
4029       if (GET_CODE (insn) == INSN
4030           && GET_CODE (PATTERN (insn)) == SEQUENCE
4031           && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4032           && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4033         return 0;
4034     }
4035   for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
4036     {
4037       if (GET_CODE (XEXP (insn, 0)) == CALL_INSN
4038           && ! SIBLING_CALL_P (insn))
4039         return 0;
4040       if (GET_CODE (XEXP (insn, 0)) == INSN
4041           && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
4042           && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN
4043           && ! SIBLING_CALL_P (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)))
4044         return 0;
4045     }
4046
4047   return 1;
4048 }
4049
4050 /* On some machines, a function with no call insns
4051    can run faster if it doesn't create its own register window.
4052    When output, the leaf function should use only the "output"
4053    registers.  Ordinarily, the function would be compiled to use
4054    the "input" registers to find its arguments; it is a candidate
4055    for leaf treatment if it uses only the "input" registers.
4056    Leaf function treatment means renumbering so the function
4057    uses the "output" registers instead.  */
4058
4059 #ifdef LEAF_REGISTERS
4060
4061 /* Return 1 if this function uses only the registers that can be
4062    safely renumbered.  */
4063
4064 int
4065 only_leaf_regs_used ()
4066 {
4067   int i;
4068   char *permitted_reg_in_leaf_functions = LEAF_REGISTERS;
4069
4070   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4071     if ((regs_ever_live[i] || global_regs[i])
4072         && ! permitted_reg_in_leaf_functions[i])
4073       return 0;
4074
4075   if (current_function_uses_pic_offset_table
4076       && pic_offset_table_rtx != 0
4077       && GET_CODE (pic_offset_table_rtx) == REG
4078       && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
4079     return 0;
4080
4081   return 1;
4082 }
4083
4084 /* Scan all instructions and renumber all registers into those
4085    available in leaf functions.  */
4086
4087 static void
4088 leaf_renumber_regs (first)
4089      rtx first;
4090 {
4091   rtx insn;
4092
4093   /* Renumber only the actual patterns.
4094      The reg-notes can contain frame pointer refs,
4095      and renumbering them could crash, and should not be needed.  */
4096   for (insn = first; insn; insn = NEXT_INSN (insn))
4097     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
4098       leaf_renumber_regs_insn (PATTERN (insn));
4099   for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
4100     if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
4101       leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
4102 }
4103
4104 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
4105    available in leaf functions.  */
4106
4107 void
4108 leaf_renumber_regs_insn (in_rtx)
4109      register rtx in_rtx;
4110 {
4111   register int i, j;
4112   register const char *format_ptr;
4113
4114   if (in_rtx == 0)
4115     return;
4116
4117   /* Renumber all input-registers into output-registers.
4118      renumbered_regs would be 1 for an output-register;
4119      they  */
4120
4121   if (GET_CODE (in_rtx) == REG)
4122     {
4123       int newreg;
4124
4125       /* Don't renumber the same reg twice.  */
4126       if (in_rtx->used)
4127         return;
4128
4129       newreg = REGNO (in_rtx);
4130       /* Don't try to renumber pseudo regs.  It is possible for a pseudo reg
4131          to reach here as part of a REG_NOTE.  */
4132       if (newreg >= FIRST_PSEUDO_REGISTER)
4133         {
4134           in_rtx->used = 1;
4135           return;
4136         }
4137       newreg = LEAF_REG_REMAP (newreg);
4138       if (newreg < 0)
4139         abort ();
4140       regs_ever_live[REGNO (in_rtx)] = 0;
4141       regs_ever_live[newreg] = 1;
4142       REGNO (in_rtx) = newreg;
4143       in_rtx->used = 1;
4144     }
4145
4146   if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
4147     {
4148       /* Inside a SEQUENCE, we find insns.
4149          Renumber just the patterns of these insns,
4150          just as we do for the top-level insns.  */
4151       leaf_renumber_regs_insn (PATTERN (in_rtx));
4152       return;
4153     }
4154
4155   format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
4156
4157   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
4158     switch (*format_ptr++)
4159       {
4160       case 'e':
4161         leaf_renumber_regs_insn (XEXP (in_rtx, i));
4162         break;
4163
4164       case 'E':
4165         if (NULL != XVEC (in_rtx, i))
4166           {
4167             for (j = 0; j < XVECLEN (in_rtx, i); j++)
4168               leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
4169           }
4170         break;
4171
4172       case 'S':
4173       case 's':
4174       case '0':
4175       case 'i':
4176       case 'w':
4177       case 'n':
4178       case 'u':
4179         break;
4180
4181       default:
4182         abort ();
4183       }
4184 }
4185 #endif