OSDN Git Service

2000-04-13 Andreas Jaeger <aj@suse.de>
[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 *) xcalloc (max_line + 1, sizeof (char));
1978
1979   for (insn = first; insn; insn = NEXT_INSN (insn))
1980     {
1981       if (INSN_UID (insn) > max_uid)       /* find largest UID */
1982         max_uid = INSN_UID (insn);
1983       if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1984         line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1985 #ifdef HAVE_cc0
1986       /* If CC tracking across branches is enabled, record the insn which
1987          jumps to each branch only reached from one place.  */
1988       if (optimize && GET_CODE (insn) == JUMP_INSN)
1989         {
1990           rtx lab = JUMP_LABEL (insn);
1991           if (lab && LABEL_NUSES (lab) == 1)
1992             {
1993               LABEL_REFS (lab) = insn;
1994             }
1995         }
1996 #endif
1997     }
1998
1999   /* Initialize insn_eh_region table if eh is being used. */
2000   
2001   init_insn_eh_region (first, max_uid);
2002
2003   init_recog ();
2004
2005   CC_STATUS_INIT;
2006
2007   /* Output the insns.  */
2008   for (insn = NEXT_INSN (first); insn;)
2009     {
2010 #ifdef HAVE_ATTR_length
2011       insn_current_address = insn_addresses[INSN_UID (insn)];
2012 #endif
2013       insn = final_scan_insn (insn, file, optimize, prescan, 0);
2014     }
2015
2016   /* Do basic-block profiling here
2017      if the last insn was a conditional branch.  */
2018   if (profile_block_flag && new_block)
2019     add_bb (file);
2020
2021   free_insn_eh_region ();
2022   free (line_note_exists);
2023   line_note_exists = NULL;
2024 }
2025 \f
2026 const char *
2027 get_insn_template (code, insn)
2028      int code;
2029      rtx insn;
2030 {
2031   const void *output = insn_data[code].output;
2032   switch (insn_data[code].output_format)
2033     {
2034     case INSN_OUTPUT_FORMAT_SINGLE:
2035       return (const char *) output;
2036     case INSN_OUTPUT_FORMAT_MULTI:
2037       return ((const char * const *) output)[which_alternative];
2038     case INSN_OUTPUT_FORMAT_FUNCTION:
2039       if (insn == NULL)
2040         abort ();
2041       return (* (insn_output_fn) output) (recog_data.operand, insn);
2042
2043     default:
2044       abort ();
2045     }
2046 }
2047 /* The final scan for one insn, INSN.
2048    Args are same as in `final', except that INSN
2049    is the insn being scanned.
2050    Value returned is the next insn to be scanned.
2051
2052    NOPEEPHOLES is the flag to disallow peephole processing (currently
2053    used for within delayed branch sequence output).  */
2054
2055 rtx
2056 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
2057      rtx insn;
2058      FILE *file;
2059      int optimize ATTRIBUTE_UNUSED;
2060      int prescan;
2061      int nopeepholes ATTRIBUTE_UNUSED;
2062 {
2063 #ifdef HAVE_cc0
2064   rtx set;
2065 #endif
2066
2067   insn_counter++;
2068
2069   /* Ignore deleted insns.  These can occur when we split insns (due to a
2070      template of "#") while not optimizing.  */
2071   if (INSN_DELETED_P (insn))
2072     return NEXT_INSN (insn);
2073
2074   switch (GET_CODE (insn))
2075     {
2076     case NOTE:
2077       if (prescan > 0)
2078         break;
2079
2080       /* Align the beginning of a loop, for higher speed
2081          on certain machines.  */
2082
2083       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
2084         break; /* This used to depend on optimize, but that was bogus.  */
2085       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
2086         break;
2087
2088       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG
2089           && ! exceptions_via_longjmp)
2090         {
2091           ASM_OUTPUT_INTERNAL_LABEL (file, "LEHB", NOTE_EH_HANDLER (insn));
2092           if (! flag_new_exceptions)
2093             add_eh_table_entry (NOTE_EH_HANDLER (insn));
2094 #ifdef ASM_OUTPUT_EH_REGION_BEG
2095           ASM_OUTPUT_EH_REGION_BEG (file, NOTE_EH_HANDLER (insn));
2096 #endif
2097           break;
2098         }
2099
2100       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END
2101           && ! exceptions_via_longjmp)
2102         {
2103           ASM_OUTPUT_INTERNAL_LABEL (file, "LEHE", NOTE_EH_HANDLER (insn));
2104           if (flag_new_exceptions)
2105             add_eh_table_entry (NOTE_EH_HANDLER (insn));
2106 #ifdef ASM_OUTPUT_EH_REGION_END
2107           ASM_OUTPUT_EH_REGION_END (file, NOTE_EH_HANDLER (insn));
2108 #endif
2109           break;
2110         }
2111
2112       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
2113         {
2114 #ifdef FUNCTION_END_PROLOGUE
2115           FUNCTION_END_PROLOGUE (file);
2116 #endif
2117           profile_after_prologue (file);
2118           break;
2119         }
2120
2121 #ifdef FUNCTION_BEGIN_EPILOGUE
2122       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
2123         {
2124           FUNCTION_BEGIN_EPILOGUE (file);
2125           break;
2126         }
2127 #endif
2128
2129       if (write_symbols == NO_DEBUG)
2130         break;
2131       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
2132         {
2133 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
2134           /* MIPS stabs require the parameter descriptions to be after the
2135              function entry point rather than before.  */
2136           if (write_symbols == SDB_DEBUG)
2137             sdbout_begin_function (last_linenum);
2138           else
2139 #endif
2140 #ifdef DWARF_DEBUGGING_INFO
2141           /* This outputs a marker where the function body starts, so it
2142              must be after the prologue.  */
2143           if (write_symbols == DWARF_DEBUG)
2144             dwarfout_begin_function ();
2145 #endif
2146           break;
2147         }
2148       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
2149         break;                  /* An insn that was "deleted" */
2150       if (app_on)
2151         {
2152           fputs (ASM_APP_OFF, file);
2153           app_on = 0;
2154         }
2155       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2156           && (debug_info_level == DINFO_LEVEL_NORMAL
2157               || debug_info_level == DINFO_LEVEL_VERBOSE
2158               || write_symbols == DWARF_DEBUG
2159               || write_symbols == DWARF2_DEBUG))
2160         {
2161           int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2162
2163           ++block_depth;
2164           high_block_linenum = last_linenum;
2165
2166           /* Output debugging info about the symbol-block beginning.  */
2167 #ifdef SDB_DEBUGGING_INFO
2168           if (write_symbols == SDB_DEBUG)
2169             sdbout_begin_block (file, last_linenum, n);
2170 #endif
2171 #ifdef XCOFF_DEBUGGING_INFO
2172           if (write_symbols == XCOFF_DEBUG)
2173             xcoffout_begin_block (file, last_linenum, n);
2174 #endif
2175 #ifdef DBX_DEBUGGING_INFO
2176           if (write_symbols == DBX_DEBUG)
2177             ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", n);
2178 #endif
2179 #ifdef DWARF_DEBUGGING_INFO
2180           if (write_symbols == DWARF_DEBUG)
2181             dwarfout_begin_block (n);
2182 #endif
2183 #ifdef DWARF2_DEBUGGING_INFO
2184           if (write_symbols == DWARF2_DEBUG)
2185             dwarf2out_begin_block (n);
2186 #endif
2187
2188           /* Mark this block as output.  */
2189           TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
2190         }
2191       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
2192                && (debug_info_level == DINFO_LEVEL_NORMAL
2193                    || debug_info_level == DINFO_LEVEL_VERBOSE
2194                    || write_symbols == DWARF_DEBUG
2195                    || write_symbols == DWARF2_DEBUG))
2196         {
2197           int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2198
2199           /* End of a symbol-block.  */
2200
2201           --block_depth;
2202           if (block_depth < 0)
2203             abort ();
2204
2205 #ifdef XCOFF_DEBUGGING_INFO
2206           if (write_symbols == XCOFF_DEBUG)
2207             xcoffout_end_block (file, high_block_linenum, n);
2208 #endif
2209 #ifdef DBX_DEBUGGING_INFO
2210           if (write_symbols == DBX_DEBUG)
2211             ASM_OUTPUT_INTERNAL_LABEL (file, "LBE", n);
2212 #endif
2213 #ifdef SDB_DEBUGGING_INFO
2214           if (write_symbols == SDB_DEBUG)
2215             sdbout_end_block (file, high_block_linenum, n);
2216 #endif
2217 #ifdef DWARF_DEBUGGING_INFO
2218           if (write_symbols == DWARF_DEBUG)
2219             dwarfout_end_block (n);
2220 #endif
2221 #ifdef DWARF2_DEBUGGING_INFO
2222           if (write_symbols == DWARF2_DEBUG)
2223             dwarf2out_end_block (n);
2224 #endif
2225         }
2226       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
2227                && (debug_info_level == DINFO_LEVEL_NORMAL
2228                    || debug_info_level == DINFO_LEVEL_VERBOSE))
2229         {
2230 #ifdef DWARF_DEBUGGING_INFO
2231           if (write_symbols == DWARF_DEBUG)
2232             dwarfout_label (insn);
2233 #endif
2234 #ifdef DWARF2_DEBUGGING_INFO
2235           if (write_symbols == DWARF2_DEBUG)
2236             dwarf2out_label (insn);
2237 #endif
2238         }
2239       else if (NOTE_LINE_NUMBER (insn) > 0)
2240         /* This note is a line-number.  */
2241         {
2242           register rtx note;
2243
2244 #if 0 /* This is what we used to do.  */
2245           output_source_line (file, insn);
2246 #endif
2247           int note_after = 0;
2248
2249           /* If there is anything real after this note,
2250              output it.  If another line note follows, omit this one.  */
2251           for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
2252             {
2253               if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
2254                 break;
2255               /* These types of notes can be significant
2256                  so make sure the preceding line number stays.  */
2257               else if (GET_CODE (note) == NOTE
2258                        && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
2259                            || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
2260                            || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
2261                 break;
2262               else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
2263                 {
2264                   /* Another line note follows; we can delete this note
2265                      if no intervening line numbers have notes elsewhere.  */
2266                   int num;
2267                   for (num = NOTE_LINE_NUMBER (insn) + 1;
2268                        num < NOTE_LINE_NUMBER (note);
2269                        num++)
2270                     if (line_note_exists[num])
2271                       break;
2272
2273                   if (num >= NOTE_LINE_NUMBER (note))
2274                     note_after = 1;
2275                   break;
2276                 }
2277             }
2278
2279           /* Output this line note
2280              if it is the first or the last line note in a row.  */
2281           if (!note_after)
2282             output_source_line (file, insn);
2283         }
2284       break;
2285
2286     case BARRIER:
2287 #if defined (DWARF2_UNWIND_INFO)
2288         /* If we push arguments, we need to check all insns for stack
2289            adjustments.  */
2290         if (!ACCUMULATE_OUTGOING_ARGS && dwarf2out_do_frame ())
2291           dwarf2out_frame_debug (insn);
2292 #endif
2293       break;
2294
2295     case CODE_LABEL:
2296       /* The target port might emit labels in the output function for
2297          some insn, e.g. sh.c output_branchy_insn.  */
2298       if (CODE_LABEL_NUMBER (insn) <= max_labelno)
2299         {
2300           int align = LABEL_TO_ALIGNMENT (insn);
2301 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2302           int max_skip = LABEL_TO_MAX_SKIP (insn);
2303 #endif
2304
2305           if (align && NEXT_INSN (insn))
2306 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2307             ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
2308 #else
2309             ASM_OUTPUT_ALIGN (file, align);
2310 #endif
2311         }
2312 #ifdef HAVE_cc0
2313       CC_STATUS_INIT;
2314       /* If this label is reached from only one place, set the condition
2315          codes from the instruction just before the branch.  */
2316
2317       /* Disabled because some insns set cc_status in the C output code
2318          and NOTICE_UPDATE_CC alone can set incorrect status.  */
2319       if (0 /* optimize && LABEL_NUSES (insn) == 1*/)
2320         {
2321           rtx jump = LABEL_REFS (insn);
2322           rtx barrier = prev_nonnote_insn (insn);
2323           rtx prev;
2324           /* If the LABEL_REFS field of this label has been set to point
2325              at a branch, the predecessor of the branch is a regular
2326              insn, and that branch is the only way to reach this label,
2327              set the condition codes based on the branch and its
2328              predecessor.  */
2329           if (barrier && GET_CODE (barrier) == BARRIER
2330               && jump && GET_CODE (jump) == JUMP_INSN
2331               && (prev = prev_nonnote_insn (jump))
2332               && GET_CODE (prev) == INSN)
2333             {
2334               NOTICE_UPDATE_CC (PATTERN (prev), prev);
2335               NOTICE_UPDATE_CC (PATTERN (jump), jump);
2336             }
2337         }
2338 #endif
2339       if (prescan > 0)
2340         break;
2341       new_block = 1;
2342
2343 #ifdef FINAL_PRESCAN_LABEL
2344       FINAL_PRESCAN_INSN (insn, NULL_PTR, 0);
2345 #endif
2346
2347 #ifdef SDB_DEBUGGING_INFO
2348       if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
2349         sdbout_label (insn);
2350 #endif
2351 #ifdef DWARF_DEBUGGING_INFO
2352       if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
2353         dwarfout_label (insn);
2354 #endif
2355 #ifdef DWARF2_DEBUGGING_INFO
2356       if (write_symbols == DWARF2_DEBUG && LABEL_NAME (insn))
2357         dwarf2out_label (insn);
2358 #endif
2359       if (app_on)
2360         {
2361           fputs (ASM_APP_OFF, file);
2362           app_on = 0;
2363         }
2364       if (NEXT_INSN (insn) != 0
2365           && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
2366         {
2367           rtx nextbody = PATTERN (NEXT_INSN (insn));
2368
2369           /* If this label is followed by a jump-table,
2370              make sure we put the label in the read-only section.  Also
2371              possibly write the label and jump table together.  */
2372
2373           if (GET_CODE (nextbody) == ADDR_VEC
2374               || GET_CODE (nextbody) == ADDR_DIFF_VEC)
2375             {
2376 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2377               /* In this case, the case vector is being moved by the
2378                  target, so don't output the label at all.  Leave that
2379                  to the back end macros.  */
2380 #else
2381               if (! JUMP_TABLES_IN_TEXT_SECTION)
2382                 {
2383                   readonly_data_section ();
2384 #ifdef READONLY_DATA_SECTION
2385                   ASM_OUTPUT_ALIGN (file,
2386                                     exact_log2 (BIGGEST_ALIGNMENT
2387                                                 / BITS_PER_UNIT));
2388 #endif /* READONLY_DATA_SECTION */
2389                 }
2390               else
2391                 function_section (current_function_decl);
2392
2393 #ifdef ASM_OUTPUT_CASE_LABEL
2394               ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
2395                                      NEXT_INSN (insn));
2396 #else
2397               if (LABEL_ALTERNATE_NAME (insn))
2398                 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2399               else
2400                 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2401 #endif
2402 #endif
2403               break;
2404             }
2405         }
2406       if (LABEL_ALTERNATE_NAME (insn))
2407         ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2408       else
2409         ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2410       break;
2411
2412     default:
2413       {
2414         register rtx body = PATTERN (insn);
2415         int insn_code_number;
2416         const char *template;
2417 #ifdef HAVE_cc0
2418         rtx note;
2419 #endif
2420
2421         /* An INSN, JUMP_INSN or CALL_INSN.
2422            First check for special kinds that recog doesn't recognize.  */
2423
2424         if (GET_CODE (body) == USE /* These are just declarations */
2425             || GET_CODE (body) == CLOBBER)
2426           break;
2427
2428 #ifdef HAVE_cc0
2429         /* If there is a REG_CC_SETTER note on this insn, it means that
2430            the setting of the condition code was done in the delay slot
2431            of the insn that branched here.  So recover the cc status
2432            from the insn that set it.  */
2433
2434         note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2435         if (note)
2436           {
2437             NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
2438             cc_prev_status = cc_status;
2439           }
2440 #endif
2441
2442         /* Detect insns that are really jump-tables
2443            and output them as such.  */
2444
2445         if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
2446           {
2447 #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
2448             register int vlen, idx;
2449 #endif
2450
2451             if (prescan > 0)
2452               break;
2453
2454             if (app_on)
2455               {
2456                 fputs (ASM_APP_OFF, file);
2457                 app_on = 0;
2458               }
2459
2460 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2461             if (GET_CODE (body) == ADDR_VEC)
2462               {
2463 #ifdef ASM_OUTPUT_ADDR_VEC
2464                 ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
2465 #else
2466                 abort();
2467 #endif
2468               }
2469             else
2470               {
2471 #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
2472                 ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
2473 #else
2474                 abort();
2475 #endif
2476               }
2477 #else
2478             vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2479             for (idx = 0; idx < vlen; idx++)
2480               {
2481                 if (GET_CODE (body) == ADDR_VEC)
2482                   {
2483 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2484                     ASM_OUTPUT_ADDR_VEC_ELT
2485                       (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2486 #else
2487                     abort ();
2488 #endif
2489                   }
2490                 else
2491                   {
2492 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2493                     ASM_OUTPUT_ADDR_DIFF_ELT
2494                       (file,
2495                        body,
2496                        CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2497                        CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2498 #else
2499                     abort ();
2500 #endif
2501                   }
2502               }
2503 #ifdef ASM_OUTPUT_CASE_END
2504             ASM_OUTPUT_CASE_END (file,
2505                                  CODE_LABEL_NUMBER (PREV_INSN (insn)),
2506                                  insn);
2507 #endif
2508 #endif
2509
2510             function_section (current_function_decl);
2511
2512             break;
2513           }
2514
2515         /* Do basic-block profiling when we reach a new block.
2516            Done here to avoid jump tables.  */
2517         if (profile_block_flag && new_block)
2518           add_bb (file);
2519
2520         if (GET_CODE (body) == ASM_INPUT)
2521           {
2522             /* There's no telling what that did to the condition codes.  */
2523             CC_STATUS_INIT;
2524             if (prescan > 0)
2525               break;
2526             if (! app_on)
2527               {
2528                 fputs (ASM_APP_ON, file);
2529                 app_on = 1;
2530               }
2531             fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
2532             break;
2533           }
2534
2535         /* Detect `asm' construct with operands.  */
2536         if (asm_noperands (body) >= 0)
2537           {
2538             unsigned int noperands = asm_noperands (body);
2539             rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
2540             const char *string;
2541
2542             /* There's no telling what that did to the condition codes.  */
2543             CC_STATUS_INIT;
2544             if (prescan > 0)
2545               break;
2546
2547             if (! app_on)
2548               {
2549                 fputs (ASM_APP_ON, file);
2550                 app_on = 1;
2551               }
2552
2553             /* Get out the operand values.  */
2554             string = decode_asm_operands (body, ops, NULL_PTR,
2555                                           NULL_PTR, NULL_PTR);
2556             /* Inhibit aborts on what would otherwise be compiler bugs.  */
2557             insn_noperands = noperands;
2558             this_is_asm_operands = insn;
2559
2560             /* Output the insn using them.  */
2561             output_asm_insn (string, ops);
2562             this_is_asm_operands = 0;
2563             break;
2564           }
2565
2566         if (prescan <= 0 && app_on)
2567           {
2568             fputs (ASM_APP_OFF, file);
2569             app_on = 0;
2570           }
2571
2572         if (GET_CODE (body) == SEQUENCE)
2573           {
2574             /* A delayed-branch sequence */
2575             register int i;
2576             rtx next;
2577
2578             if (prescan > 0)
2579               break;
2580             final_sequence = body;
2581
2582             /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2583                force the restoration of a comparison that was previously
2584                thought unnecessary.  If that happens, cancel this sequence
2585                and cause that insn to be restored.  */
2586
2587             next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
2588             if (next != XVECEXP (body, 0, 1))
2589               {
2590                 final_sequence = 0;
2591                 return next;
2592               }
2593
2594             for (i = 1; i < XVECLEN (body, 0); i++)
2595               {
2596                 rtx insn = XVECEXP (body, 0, i);
2597                 rtx next = NEXT_INSN (insn);
2598                 /* We loop in case any instruction in a delay slot gets
2599                    split.  */
2600                 do
2601                   insn = final_scan_insn (insn, file, 0, prescan, 1);
2602                 while (insn != next);
2603               }
2604 #ifdef DBR_OUTPUT_SEQEND
2605             DBR_OUTPUT_SEQEND (file);
2606 #endif
2607             final_sequence = 0;
2608
2609             /* If the insn requiring the delay slot was a CALL_INSN, the
2610                insns in the delay slot are actually executed before the
2611                called function.  Hence we don't preserve any CC-setting
2612                actions in these insns and the CC must be marked as being
2613                clobbered by the function.  */
2614             if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
2615               {
2616                 CC_STATUS_INIT;
2617               }
2618
2619             /* Following a conditional branch sequence, we have a new basic
2620                block.  */
2621             if (profile_block_flag)
2622               {
2623                 rtx insn = XVECEXP (body, 0, 0);
2624                 rtx body = PATTERN (insn);
2625
2626                 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2627                      && GET_CODE (SET_SRC (body)) != LABEL_REF)
2628                     || (GET_CODE (insn) == JUMP_INSN
2629                         && GET_CODE (body) == PARALLEL
2630                         && GET_CODE (XVECEXP (body, 0, 0)) == SET
2631                         && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
2632                   new_block = 1;
2633               }
2634             break;
2635           }
2636
2637         /* We have a real machine instruction as rtl.  */
2638
2639         body = PATTERN (insn);
2640
2641 #ifdef HAVE_cc0
2642         set = single_set(insn);
2643
2644         /* Check for redundant test and compare instructions
2645            (when the condition codes are already set up as desired).
2646            This is done only when optimizing; if not optimizing,
2647            it should be possible for the user to alter a variable
2648            with the debugger in between statements
2649            and the next statement should reexamine the variable
2650            to compute the condition codes.  */
2651
2652         if (optimize)
2653           {
2654 #if 0
2655             rtx set = single_set(insn);
2656 #endif
2657
2658             if (set
2659                 && GET_CODE (SET_DEST (set)) == CC0
2660                 && insn != last_ignored_compare)
2661               {
2662                 if (GET_CODE (SET_SRC (set)) == SUBREG)
2663                   SET_SRC (set) = alter_subreg (SET_SRC (set));
2664                 else if (GET_CODE (SET_SRC (set)) == COMPARE)
2665                   {
2666                     if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
2667                       XEXP (SET_SRC (set), 0)
2668                         = alter_subreg (XEXP (SET_SRC (set), 0));
2669                     if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
2670                       XEXP (SET_SRC (set), 1)
2671                         = alter_subreg (XEXP (SET_SRC (set), 1));
2672                   }
2673                 if ((cc_status.value1 != 0
2674                      && rtx_equal_p (SET_SRC (set), cc_status.value1))
2675                     || (cc_status.value2 != 0
2676                         && rtx_equal_p (SET_SRC (set), cc_status.value2)))
2677                   {
2678                     /* Don't delete insn if it has an addressing side-effect.  */
2679                     if (! FIND_REG_INC_NOTE (insn, 0)
2680                         /* or if anything in it is volatile.  */
2681                         && ! volatile_refs_p (PATTERN (insn)))
2682                       {
2683                         /* We don't really delete the insn; just ignore it.  */
2684                         last_ignored_compare = insn;
2685                         break;
2686                       }
2687                   }
2688               }
2689           }
2690 #endif
2691
2692         /* Following a conditional branch, we have a new basic block.
2693            But if we are inside a sequence, the new block starts after the
2694            last insn of the sequence.  */
2695         if (profile_block_flag && final_sequence == 0
2696             && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2697                  && GET_CODE (SET_SRC (body)) != LABEL_REF)
2698                 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
2699                     && GET_CODE (XVECEXP (body, 0, 0)) == SET
2700                     && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
2701           new_block = 1;
2702
2703 #ifndef STACK_REGS
2704         /* Don't bother outputting obvious no-ops, even without -O.
2705            This optimization is fast and doesn't interfere with debugging.
2706            Don't do this if the insn is in a delay slot, since this
2707            will cause an improper number of delay insns to be written.  */
2708         if (final_sequence == 0
2709             && prescan >= 0
2710             && GET_CODE (insn) == INSN && GET_CODE (body) == SET
2711             && GET_CODE (SET_SRC (body)) == REG
2712             && GET_CODE (SET_DEST (body)) == REG
2713             && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
2714           break;
2715 #endif
2716
2717 #ifdef HAVE_cc0
2718         /* If this is a conditional branch, maybe modify it
2719            if the cc's are in a nonstandard state
2720            so that it accomplishes the same thing that it would
2721            do straightforwardly if the cc's were set up normally.  */
2722
2723         if (cc_status.flags != 0
2724             && GET_CODE (insn) == JUMP_INSN
2725             && GET_CODE (body) == SET
2726             && SET_DEST (body) == pc_rtx
2727             && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2728             && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
2729             && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
2730             /* This is done during prescan; it is not done again
2731                in final scan when prescan has been done.  */
2732             && prescan >= 0)
2733           {
2734             /* This function may alter the contents of its argument
2735                and clear some of the cc_status.flags bits.
2736                It may also return 1 meaning condition now always true
2737                or -1 meaning condition now always false
2738                or 2 meaning condition nontrivial but altered.  */
2739             register int result = alter_cond (XEXP (SET_SRC (body), 0));
2740             /* If condition now has fixed value, replace the IF_THEN_ELSE
2741                with its then-operand or its else-operand.  */
2742             if (result == 1)
2743               SET_SRC (body) = XEXP (SET_SRC (body), 1);
2744             if (result == -1)
2745               SET_SRC (body) = XEXP (SET_SRC (body), 2);
2746
2747             /* The jump is now either unconditional or a no-op.
2748                If it has become a no-op, don't try to output it.
2749                (It would not be recognized.)  */
2750             if (SET_SRC (body) == pc_rtx)
2751               {
2752                 PUT_CODE (insn, NOTE);
2753                 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2754                 NOTE_SOURCE_FILE (insn) = 0;
2755                 break;
2756               }
2757             else if (GET_CODE (SET_SRC (body)) == RETURN)
2758               /* Replace (set (pc) (return)) with (return).  */
2759               PATTERN (insn) = body = SET_SRC (body);
2760
2761             /* Rerecognize the instruction if it has changed.  */
2762             if (result != 0)
2763               INSN_CODE (insn) = -1;
2764           }
2765
2766         /* Make same adjustments to instructions that examine the
2767            condition codes without jumping and instructions that
2768            handle conditional moves (if this machine has either one).  */
2769
2770         if (cc_status.flags != 0
2771             && set != 0)
2772           {
2773             rtx cond_rtx, then_rtx, else_rtx;
2774             
2775             if (GET_CODE (insn) != JUMP_INSN
2776                 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2777               {
2778                 cond_rtx = XEXP (SET_SRC (set), 0);
2779                 then_rtx = XEXP (SET_SRC (set), 1);
2780                 else_rtx = XEXP (SET_SRC (set), 2);
2781               }
2782             else
2783               {
2784                 cond_rtx = SET_SRC (set);
2785                 then_rtx = const_true_rtx;
2786                 else_rtx = const0_rtx;
2787               }
2788             
2789             switch (GET_CODE (cond_rtx))
2790               {
2791               case GTU:
2792               case GT:
2793               case LTU:
2794               case LT:
2795               case GEU:
2796               case GE:
2797               case LEU:
2798               case LE:
2799               case EQ:
2800               case NE:
2801                 {
2802                   register int result;
2803                   if (XEXP (cond_rtx, 0) != cc0_rtx)
2804                     break;
2805                   result = alter_cond (cond_rtx);
2806                   if (result == 1)
2807                     validate_change (insn, &SET_SRC (set), then_rtx, 0);
2808                   else if (result == -1)
2809                     validate_change (insn, &SET_SRC (set), else_rtx, 0);
2810                   else if (result == 2)
2811                     INSN_CODE (insn) = -1;
2812                   if (SET_DEST (set) == SET_SRC (set))
2813                     {
2814                       PUT_CODE (insn, NOTE);
2815                       NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2816                       NOTE_SOURCE_FILE (insn) = 0;
2817                     }
2818                 }
2819                 break;
2820
2821               default:
2822                 break;
2823               }
2824           }
2825
2826 #endif
2827
2828 #ifdef HAVE_peephole
2829         /* Do machine-specific peephole optimizations if desired.  */
2830
2831         if (optimize && !flag_no_peephole && !nopeepholes)
2832           {
2833             rtx next = peephole (insn);
2834             /* When peepholing, if there were notes within the peephole,
2835                emit them before the peephole.  */
2836             if (next != 0 && next != NEXT_INSN (insn))
2837               {
2838                 rtx prev = PREV_INSN (insn);
2839                 rtx note;
2840
2841                 for (note = NEXT_INSN (insn); note != next;
2842                      note = NEXT_INSN (note))
2843                   final_scan_insn (note, file, optimize, prescan, nopeepholes);
2844
2845                 /* In case this is prescan, put the notes
2846                    in proper position for later rescan.  */
2847                 note = NEXT_INSN (insn);
2848                 PREV_INSN (note) = prev;
2849                 NEXT_INSN (prev) = note;
2850                 NEXT_INSN (PREV_INSN (next)) = insn;
2851                 PREV_INSN (insn) = PREV_INSN (next);
2852                 NEXT_INSN (insn) = next;
2853                 PREV_INSN (next) = insn;
2854               }
2855
2856             /* PEEPHOLE might have changed this.  */
2857             body = PATTERN (insn);
2858           }
2859 #endif
2860
2861         /* Try to recognize the instruction.
2862            If successful, verify that the operands satisfy the
2863            constraints for the instruction.  Crash if they don't,
2864            since `reload' should have changed them so that they do.  */
2865
2866         insn_code_number = recog_memoized (insn);
2867         extract_insn (insn);
2868         cleanup_subreg_operands (insn);
2869
2870         if (! constrain_operands (1))
2871           fatal_insn_not_found (insn);
2872
2873         /* Some target machines need to prescan each insn before
2874            it is output.  */
2875
2876 #ifdef FINAL_PRESCAN_INSN
2877         FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2878 #endif
2879
2880 #ifdef HAVE_cc0
2881         cc_prev_status = cc_status;
2882
2883         /* Update `cc_status' for this instruction.
2884            The instruction's output routine may change it further.
2885            If the output routine for a jump insn needs to depend
2886            on the cc status, it should look at cc_prev_status.  */
2887
2888         NOTICE_UPDATE_CC (body, insn);
2889 #endif
2890
2891         debug_insn = insn;
2892
2893 #if defined (DWARF2_UNWIND_INFO)
2894         /* If we push arguments, we want to know where the calls are.  */
2895         if (!ACCUMULATE_OUTGOING_ARGS && GET_CODE (insn) == CALL_INSN
2896             && dwarf2out_do_frame ())
2897           dwarf2out_frame_debug (insn);
2898 #endif
2899
2900         /* Find the proper template for this insn.  */
2901         template = get_insn_template (insn_code_number, insn);
2902
2903         /* If the C code returns 0, it means that it is a jump insn
2904            which follows a deleted test insn, and that test insn
2905            needs to be reinserted.  */
2906         if (template == 0)
2907           {
2908             if (prev_nonnote_insn (insn) != last_ignored_compare)
2909               abort ();
2910             new_block = 0;
2911             return prev_nonnote_insn (insn);
2912           }
2913
2914         /* If the template is the string "#", it means that this insn must
2915            be split.  */
2916         if (template[0] == '#' && template[1] == '\0')
2917           {
2918             rtx new = try_split (body, insn, 0);
2919
2920             /* If we didn't split the insn, go away.  */
2921             if (new == insn && PATTERN (new) == body)
2922               fatal_insn ("Could not split insn", insn);
2923               
2924 #ifdef HAVE_ATTR_length
2925             /* This instruction should have been split in shorten_branches,
2926                to ensure that we would have valid length info for the
2927                splitees.  */
2928             abort ();
2929 #endif
2930
2931             new_block = 0;
2932             return new;
2933           }
2934         
2935         if (prescan > 0)
2936           break;
2937
2938         /* Output assembler code from the template.  */
2939
2940         output_asm_insn (template, recog_data.operand);
2941
2942 #if defined (DWARF2_UNWIND_INFO)
2943         /* If we push arguments, we need to check all insns for stack
2944            adjustments.  */
2945         if (!ACCUMULATE_OUTGOING_ARGS)
2946           {
2947             if (GET_CODE (insn) == INSN && dwarf2out_do_frame ())
2948               dwarf2out_frame_debug (insn);
2949           }
2950         else
2951           {
2952 #if defined (HAVE_prologue)
2953             /* If this insn is part of the prologue, emit DWARF v2
2954                call frame info.  */
2955             if (RTX_FRAME_RELATED_P (insn) && dwarf2out_do_frame ())
2956               dwarf2out_frame_debug (insn);
2957 #endif
2958           }
2959 #endif
2960
2961 #if 0
2962         /* It's not at all clear why we did this and doing so interferes
2963            with tests we'd like to do to use REG_WAS_0 notes, so let's try
2964            with this out.  */
2965
2966         /* Mark this insn as having been output.  */
2967         INSN_DELETED_P (insn) = 1;
2968 #endif
2969
2970         debug_insn = 0;
2971       }
2972     }
2973   return NEXT_INSN (insn);
2974 }
2975 \f
2976 /* Output debugging info to the assembler file FILE
2977    based on the NOTE-insn INSN, assumed to be a line number.  */
2978
2979 static void
2980 output_source_line (file, insn)
2981      FILE *file ATTRIBUTE_UNUSED;
2982      rtx insn;
2983 {
2984   register const char *filename = NOTE_SOURCE_FILE (insn);
2985
2986   /* Remember filename for basic block profiling.
2987      Filenames are allocated on the permanent obstack
2988      or are passed in ARGV, so we don't have to save
2989      the string.  */
2990
2991   if (profile_block_flag && last_filename != filename)
2992     bb_file_label_num = add_bb_string (filename, TRUE);
2993
2994   last_filename = filename;
2995   last_linenum = NOTE_LINE_NUMBER (insn);
2996   high_block_linenum = MAX (last_linenum, high_block_linenum);
2997   high_function_linenum = MAX (last_linenum, high_function_linenum);
2998
2999   if (write_symbols != NO_DEBUG)
3000     {
3001 #ifdef SDB_DEBUGGING_INFO
3002       if (write_symbols == SDB_DEBUG
3003 #if 0 /* People like having line numbers even in wrong file!  */
3004           /* COFF can't handle multiple source files--lose, lose.  */
3005           && !strcmp (filename, main_input_filename)
3006 #endif
3007           /* COFF relative line numbers must be positive.  */
3008           && last_linenum > sdb_begin_function_line)
3009         {
3010 #ifdef ASM_OUTPUT_SOURCE_LINE
3011           ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
3012 #else
3013           fprintf (file, "\t.ln\t%d\n",
3014                    ((sdb_begin_function_line > -1)
3015                     ? last_linenum - sdb_begin_function_line : 1));
3016 #endif
3017         }
3018 #endif
3019
3020 #if defined (DBX_DEBUGGING_INFO)
3021       if (write_symbols == DBX_DEBUG)
3022         dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
3023 #endif
3024
3025 #if defined (XCOFF_DEBUGGING_INFO)
3026       if (write_symbols == XCOFF_DEBUG)
3027         xcoffout_source_line (file, filename, insn);
3028 #endif
3029
3030 #ifdef DWARF_DEBUGGING_INFO
3031       if (write_symbols == DWARF_DEBUG)
3032         dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
3033 #endif
3034
3035 #ifdef DWARF2_DEBUGGING_INFO
3036       if (write_symbols == DWARF2_DEBUG)
3037         dwarf2out_line (filename, NOTE_LINE_NUMBER (insn));
3038 #endif
3039     }
3040 }
3041 \f
3042
3043 /* For each operand in INSN, simplify (subreg (reg)) so that it refers
3044    directly to the desired hard register.  */
3045 void
3046 cleanup_subreg_operands (insn)
3047      rtx insn;
3048 {
3049   int i;
3050
3051   extract_insn (insn);
3052   for (i = 0; i < recog_data.n_operands; i++)
3053     {
3054       if (GET_CODE (recog_data.operand[i]) == SUBREG)
3055         recog_data.operand[i] = alter_subreg (recog_data.operand[i]);
3056       else if (GET_CODE (recog_data.operand[i]) == PLUS
3057                || GET_CODE (recog_data.operand[i]) == MULT)
3058        recog_data.operand[i] = walk_alter_subreg (recog_data.operand[i]);
3059     }
3060
3061   for (i = 0; i < recog_data.n_dups; i++)
3062     {
3063       if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
3064         *recog_data.dup_loc[i] = alter_subreg (*recog_data.dup_loc[i]);
3065       else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
3066                || GET_CODE (*recog_data.dup_loc[i]) == MULT)
3067         *recog_data.dup_loc[i] = walk_alter_subreg (*recog_data.dup_loc[i]);
3068     }
3069 }
3070
3071 /* If X is a SUBREG, replace it with a REG or a MEM,
3072    based on the thing it is a subreg of.  */
3073
3074 rtx
3075 alter_subreg (x)
3076      register rtx x;
3077 {
3078   register rtx y = SUBREG_REG (x);
3079
3080   if (GET_CODE (y) == SUBREG)
3081     y = alter_subreg (y);
3082
3083   /* If reload is operating, we may be replacing inside this SUBREG.
3084      Check for that and make a new one if so.  */
3085   if (reload_in_progress && find_replacement (&SUBREG_REG (x)) != 0)
3086     x = copy_rtx (x);
3087
3088   if (GET_CODE (y) == REG)
3089     {
3090       int regno;
3091       /* If the word size is larger than the size of this register,
3092          adjust the register number to compensate.  */
3093       /* ??? Note that this just catches stragglers created by/for
3094          integrate.  It would be better if we either caught these
3095          earlier, or kept _all_ subregs until now and eliminate
3096          gen_lowpart and friends.  */
3097
3098 #ifdef ALTER_HARD_SUBREG
3099       regno = ALTER_HARD_SUBREG(GET_MODE (x), SUBREG_WORD (x),
3100                                 GET_MODE (y), REGNO (y));
3101 #else
3102       regno = REGNO (y) + SUBREG_WORD (x);
3103 #endif
3104       PUT_CODE (x, REG);
3105       REGNO (x) = regno;
3106       /* This field has a different meaning for REGs and SUBREGs.  Make sure
3107          to clear it!  */
3108       x->used = 0;
3109     }
3110   else if (GET_CODE (y) == MEM)
3111     {
3112       register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
3113       if (BYTES_BIG_ENDIAN)
3114         offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
3115                    - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
3116       PUT_CODE (x, MEM);
3117       MEM_COPY_ATTRIBUTES (x, y);
3118       MEM_ALIAS_SET (x) = MEM_ALIAS_SET (y);
3119       XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
3120     }
3121
3122   return x;
3123 }
3124
3125 /* Do alter_subreg on all the SUBREGs contained in X.  */
3126
3127 static rtx
3128 walk_alter_subreg (x)
3129      rtx x;
3130 {
3131   switch (GET_CODE (x))
3132     {
3133     case PLUS:
3134     case MULT:
3135       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3136       XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
3137       break;
3138
3139     case MEM:
3140       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3141       break;
3142
3143     case SUBREG:
3144       return alter_subreg (x);
3145       
3146     default:
3147       break;
3148     }
3149
3150   return x;
3151 }
3152 \f
3153 #ifdef HAVE_cc0
3154
3155 /* Given BODY, the body of a jump instruction, alter the jump condition
3156    as required by the bits that are set in cc_status.flags.
3157    Not all of the bits there can be handled at this level in all cases.
3158
3159    The value is normally 0.
3160    1 means that the condition has become always true.
3161    -1 means that the condition has become always false.
3162    2 means that COND has been altered.  */
3163
3164 static int
3165 alter_cond (cond)
3166      register rtx cond;
3167 {
3168   int value = 0;
3169
3170   if (cc_status.flags & CC_REVERSED)
3171     {
3172       value = 2;
3173       PUT_CODE (cond, swap_condition (GET_CODE (cond)));
3174     }
3175
3176   if (cc_status.flags & CC_INVERTED)
3177     {
3178       value = 2;
3179       PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
3180     }
3181
3182   if (cc_status.flags & CC_NOT_POSITIVE)
3183     switch (GET_CODE (cond))
3184       {
3185       case LE:
3186       case LEU:
3187       case GEU:
3188         /* Jump becomes unconditional.  */
3189         return 1;
3190
3191       case GT:
3192       case GTU:
3193       case LTU:
3194         /* Jump becomes no-op.  */
3195         return -1;
3196
3197       case GE:
3198         PUT_CODE (cond, EQ);
3199         value = 2;
3200         break;
3201
3202       case LT:
3203         PUT_CODE (cond, NE);
3204         value = 2;
3205         break;
3206         
3207       default:
3208         break;
3209       }
3210
3211   if (cc_status.flags & CC_NOT_NEGATIVE)
3212     switch (GET_CODE (cond))
3213       {
3214       case GE:
3215       case GEU:
3216         /* Jump becomes unconditional.  */
3217         return 1;
3218
3219       case LT:
3220       case LTU:
3221         /* Jump becomes no-op.  */
3222         return -1;
3223
3224       case LE:
3225       case LEU:
3226         PUT_CODE (cond, EQ);
3227         value = 2;
3228         break;
3229
3230       case GT:
3231       case GTU:
3232         PUT_CODE (cond, NE);
3233         value = 2;
3234         break;
3235         
3236       default:
3237         break;
3238       }
3239
3240   if (cc_status.flags & CC_NO_OVERFLOW)
3241     switch (GET_CODE (cond))
3242       {
3243       case GEU:
3244         /* Jump becomes unconditional.  */
3245         return 1;
3246
3247       case LEU:
3248         PUT_CODE (cond, EQ);
3249         value = 2;
3250         break;
3251
3252       case GTU:
3253         PUT_CODE (cond, NE);
3254         value = 2;
3255         break;
3256
3257       case LTU:
3258         /* Jump becomes no-op.  */
3259         return -1;
3260         
3261       default:
3262         break;
3263       }
3264
3265   if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
3266     switch (GET_CODE (cond))
3267       {
3268       default:
3269         abort ();
3270
3271       case NE:
3272         PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
3273         value = 2;
3274         break;
3275
3276       case EQ:
3277         PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
3278         value = 2;
3279         break;
3280       }
3281
3282   if (cc_status.flags & CC_NOT_SIGNED)
3283     /* The flags are valid if signed condition operators are converted
3284        to unsigned.  */
3285     switch (GET_CODE (cond))
3286       {
3287       case LE:
3288         PUT_CODE (cond, LEU);
3289         value = 2;
3290         break;
3291
3292       case LT:
3293         PUT_CODE (cond, LTU);
3294         value = 2;
3295         break;
3296
3297       case GT:
3298         PUT_CODE (cond, GTU);
3299         value = 2;
3300         break;
3301
3302       case GE:
3303         PUT_CODE (cond, GEU);
3304         value = 2;
3305         break;
3306
3307       default:
3308         break;
3309       }
3310
3311   return value;
3312 }
3313 #endif
3314 \f
3315 /* Report inconsistency between the assembler template and the operands.
3316    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
3317
3318 void
3319 output_operand_lossage (msgid)
3320      const char *msgid;
3321 {
3322   if (this_is_asm_operands)
3323     error_for_asm (this_is_asm_operands, "invalid `asm': %s", _(msgid));
3324   else
3325     {
3326       error ("output_operand: %s", _(msgid));
3327       abort ();
3328     }
3329 }
3330 \f
3331 /* Output of assembler code from a template, and its subroutines.  */
3332
3333 /* Output text from TEMPLATE to the assembler output file,
3334    obeying %-directions to substitute operands taken from
3335    the vector OPERANDS.
3336
3337    %N (for N a digit) means print operand N in usual manner.
3338    %lN means require operand N to be a CODE_LABEL or LABEL_REF
3339       and print the label name with no punctuation.
3340    %cN means require operand N to be a constant
3341       and print the constant expression with no punctuation.
3342    %aN means expect operand N to be a memory address
3343       (not a memory reference!) and print a reference
3344       to that address.
3345    %nN means expect operand N to be a constant
3346       and print a constant expression for minus the value
3347       of the operand, with no other punctuation.  */
3348
3349 static void
3350 output_asm_name ()
3351 {
3352   if (flag_print_asm_name)
3353     {
3354       /* Annotate the assembly with a comment describing the pattern and
3355          alternative used.  */
3356       if (debug_insn)
3357         {
3358           register int num = INSN_CODE (debug_insn);
3359           fprintf (asm_out_file, "\t%s %d\t%s", 
3360                    ASM_COMMENT_START, INSN_UID (debug_insn),
3361                    insn_data[num].name);
3362           if (insn_data[num].n_alternatives > 1)
3363             fprintf (asm_out_file, "/%d", which_alternative + 1);
3364 #ifdef HAVE_ATTR_length
3365           fprintf (asm_out_file, "\t[length = %d]",
3366                    get_attr_length (debug_insn));
3367 #endif
3368           /* Clear this so only the first assembler insn
3369              of any rtl insn will get the special comment for -dp.  */
3370           debug_insn = 0;
3371         }
3372     }
3373 }
3374
3375 void
3376 output_asm_insn (template, operands)
3377      const char *template;
3378      rtx *operands;
3379 {
3380   register const char *p;
3381   register int c;
3382
3383   /* An insn may return a null string template
3384      in a case where no assembler code is needed.  */
3385   if (*template == 0)
3386     return;
3387
3388   p = template;
3389   putc ('\t', asm_out_file);
3390
3391 #ifdef ASM_OUTPUT_OPCODE
3392   ASM_OUTPUT_OPCODE (asm_out_file, p);
3393 #endif
3394
3395   while ((c = *p++))
3396     switch (c)
3397       {
3398       case '\n':
3399         output_asm_name ();
3400         putc (c, asm_out_file);
3401 #ifdef ASM_OUTPUT_OPCODE
3402         while ((c = *p) == '\t')
3403           {
3404             putc (c, asm_out_file);
3405             p++;
3406           }
3407         ASM_OUTPUT_OPCODE (asm_out_file, p);
3408 #endif
3409         break;
3410
3411 #ifdef ASSEMBLER_DIALECT
3412       case '{':
3413         {
3414           register int i;
3415           
3416           /* If we want the first dialect, do nothing.  Otherwise, skip
3417              DIALECT_NUMBER of strings ending with '|'.  */
3418           for (i = 0; i < dialect_number; i++)
3419             {
3420               while (*p && *p != '}' && *p++ != '|')
3421                 ;
3422               if (*p == '}')
3423                 break;
3424               if (*p == '|')
3425                 p++;
3426             }
3427         }
3428         break;
3429
3430       case '|':
3431         /* Skip to close brace.  */
3432         while (*p && *p++ != '}')
3433           ;
3434         break;
3435
3436       case '}':
3437         break;
3438 #endif
3439
3440       case '%':
3441         /* %% outputs a single %.  */
3442         if (*p == '%')
3443           {
3444             p++;
3445             putc (c, asm_out_file);
3446           }
3447         /* %= outputs a number which is unique to each insn in the entire
3448            compilation.  This is useful for making local labels that are
3449            referred to more than once in a given insn.  */
3450         else if (*p == '=')
3451           {
3452             p++;
3453             fprintf (asm_out_file, "%d", insn_counter);
3454           }
3455         /* % followed by a letter and some digits
3456            outputs an operand in a special way depending on the letter.
3457            Letters `acln' are implemented directly.
3458            Other letters are passed to `output_operand' so that
3459            the PRINT_OPERAND macro can define them.  */
3460         else if ((*p >= 'a' && *p <= 'z')
3461                  || (*p >= 'A' && *p <= 'Z'))
3462           {
3463             int letter = *p++;
3464             c = atoi (p);
3465
3466             if (! (*p >= '0' && *p <= '9'))
3467               output_operand_lossage ("operand number missing after %-letter");
3468             else if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3469               output_operand_lossage ("operand number out of range");
3470             else if (letter == 'l')
3471               output_asm_label (operands[c]);
3472             else if (letter == 'a')
3473               output_address (operands[c]);
3474             else if (letter == 'c')
3475               {
3476                 if (CONSTANT_ADDRESS_P (operands[c]))
3477                   output_addr_const (asm_out_file, operands[c]);
3478                 else
3479                   output_operand (operands[c], 'c');
3480               }
3481             else if (letter == 'n')
3482               {
3483                 if (GET_CODE (operands[c]) == CONST_INT)
3484                   fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3485                            - INTVAL (operands[c]));
3486                 else
3487                   {
3488                     putc ('-', asm_out_file);
3489                     output_addr_const (asm_out_file, operands[c]);
3490                   }
3491               }
3492             else
3493               output_operand (operands[c], letter);
3494             
3495             while ((c = *p) >= '0' && c <= '9') p++;
3496           }
3497         /* % followed by a digit outputs an operand the default way.  */
3498         else if (*p >= '0' && *p <= '9')
3499           {
3500             c = atoi (p);
3501             if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3502               output_operand_lossage ("operand number out of range");
3503             else
3504               output_operand (operands[c], 0);
3505             while ((c = *p) >= '0' && c <= '9') p++;
3506           }
3507         /* % followed by punctuation: output something for that
3508            punctuation character alone, with no operand.
3509            The PRINT_OPERAND macro decides what is actually done.  */
3510 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3511         else if (PRINT_OPERAND_PUNCT_VALID_P ((unsigned char)*p))
3512           output_operand (NULL_RTX, *p++);
3513 #endif
3514         else
3515           output_operand_lossage ("invalid %%-code");
3516         break;
3517
3518       default:
3519         putc (c, asm_out_file);
3520       }
3521
3522   output_asm_name ();
3523
3524   putc ('\n', asm_out_file);
3525 }
3526 \f
3527 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol.  */
3528
3529 void
3530 output_asm_label (x)
3531      rtx x;
3532 {
3533   char buf[256];
3534
3535   if (GET_CODE (x) == LABEL_REF)
3536     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
3537   else if (GET_CODE (x) == CODE_LABEL)
3538     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3539   else
3540     output_operand_lossage ("`%l' operand isn't a label");
3541
3542   assemble_name (asm_out_file, buf);
3543 }
3544
3545 /* Print operand X using machine-dependent assembler syntax.
3546    The macro PRINT_OPERAND is defined just to control this function.
3547    CODE is a non-digit that preceded the operand-number in the % spec,
3548    such as 'z' if the spec was `%z3'.  CODE is 0 if there was no char
3549    between the % and the digits.
3550    When CODE is a non-letter, X is 0.
3551
3552    The meanings of the letters are machine-dependent and controlled
3553    by PRINT_OPERAND.  */
3554
3555 static void
3556 output_operand (x, code)
3557      rtx x;
3558      int code ATTRIBUTE_UNUSED;
3559 {
3560   if (x && GET_CODE (x) == SUBREG)
3561     x = alter_subreg (x);
3562
3563   /* If X is a pseudo-register, abort now rather than writing trash to the
3564      assembler file.  */
3565
3566   if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
3567     abort ();
3568
3569   PRINT_OPERAND (asm_out_file, x, code);
3570 }
3571
3572 /* Print a memory reference operand for address X
3573    using machine-dependent assembler syntax.
3574    The macro PRINT_OPERAND_ADDRESS exists just to control this function.  */
3575
3576 void
3577 output_address (x)
3578      rtx x;
3579 {
3580   walk_alter_subreg (x);
3581   PRINT_OPERAND_ADDRESS (asm_out_file, x);
3582 }
3583 \f
3584 /* Print an integer constant expression in assembler syntax.
3585    Addition and subtraction are the only arithmetic
3586    that may appear in these expressions.  */
3587
3588 void
3589 output_addr_const (file, x)
3590      FILE *file;
3591      rtx x;
3592 {
3593   char buf[256];
3594
3595  restart:
3596   switch (GET_CODE (x))
3597     {
3598     case PC:
3599       if (flag_pic)
3600         putc ('.', file);
3601       else
3602         abort ();
3603       break;
3604
3605     case SYMBOL_REF:
3606       assemble_name (file, XSTR (x, 0));
3607       break;
3608
3609     case LABEL_REF:
3610       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
3611       assemble_name (file, buf);
3612       break;
3613
3614     case CODE_LABEL:
3615       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3616       assemble_name (file, buf);
3617       break;
3618
3619     case CONST_INT:
3620       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3621       break;
3622
3623     case CONST:
3624       /* This used to output parentheses around the expression,
3625          but that does not work on the 386 (either ATT or BSD assembler).  */
3626       output_addr_const (file, XEXP (x, 0));
3627       break;
3628
3629     case CONST_DOUBLE:
3630       if (GET_MODE (x) == VOIDmode)
3631         {
3632           /* We can use %d if the number is one word and positive.  */
3633           if (CONST_DOUBLE_HIGH (x))
3634             fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3635                      CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3636           else if  (CONST_DOUBLE_LOW (x) < 0)
3637             fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3638           else
3639             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3640         }
3641       else
3642         /* We can't handle floating point constants;
3643            PRINT_OPERAND must handle them.  */
3644         output_operand_lossage ("floating constant misused");
3645       break;
3646
3647     case PLUS:
3648       /* Some assemblers need integer constants to appear last (eg masm).  */
3649       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3650         {
3651           output_addr_const (file, XEXP (x, 1));
3652           if (INTVAL (XEXP (x, 0)) >= 0)
3653             fprintf (file, "+");
3654           output_addr_const (file, XEXP (x, 0));
3655         }
3656       else
3657         {
3658           output_addr_const (file, XEXP (x, 0));
3659           if (INTVAL (XEXP (x, 1)) >= 0)
3660             fprintf (file, "+");
3661           output_addr_const (file, XEXP (x, 1));
3662         }
3663       break;
3664
3665     case MINUS:
3666       /* Avoid outputting things like x-x or x+5-x,
3667          since some assemblers can't handle that.  */
3668       x = simplify_subtraction (x);
3669       if (GET_CODE (x) != MINUS)
3670         goto restart;
3671
3672       output_addr_const (file, XEXP (x, 0));
3673       fprintf (file, "-");
3674       if (GET_CODE (XEXP (x, 1)) == CONST_INT
3675           && INTVAL (XEXP (x, 1)) < 0)
3676         {
3677           fprintf (file, "%s", ASM_OPEN_PAREN);
3678           output_addr_const (file, XEXP (x, 1));
3679           fprintf (file, "%s", ASM_CLOSE_PAREN);
3680         }
3681       else
3682         output_addr_const (file, XEXP (x, 1));
3683       break;
3684
3685     case ZERO_EXTEND:
3686     case SIGN_EXTEND:
3687       output_addr_const (file, XEXP (x, 0));
3688       break;
3689
3690     default:
3691       output_operand_lossage ("invalid expression as operand");
3692     }
3693 }
3694 \f
3695 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3696    %R prints the value of REGISTER_PREFIX.
3697    %L prints the value of LOCAL_LABEL_PREFIX.
3698    %U prints the value of USER_LABEL_PREFIX.
3699    %I prints the value of IMMEDIATE_PREFIX.
3700    %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3701    Also supported are %d, %x, %s, %e, %f, %g and %%.
3702
3703    We handle alternate assembler dialects here, just like output_asm_insn.  */
3704
3705 void
3706 asm_fprintf VPARAMS ((FILE *file, const char *p, ...))
3707 {
3708 #ifndef ANSI_PROTOTYPES
3709   FILE *file;
3710   const char *p;
3711 #endif
3712   va_list argptr;
3713   char buf[10];
3714   char *q, c;
3715
3716   VA_START (argptr, p);
3717
3718 #ifndef ANSI_PROTOTYPES
3719   file = va_arg (argptr, FILE *);
3720   p = va_arg (argptr, const char *);
3721 #endif
3722
3723   buf[0] = '%';
3724
3725   while ((c = *p++))
3726     switch (c)
3727       {
3728 #ifdef ASSEMBLER_DIALECT
3729       case '{':
3730         {
3731           int i;
3732
3733           /* If we want the first dialect, do nothing.  Otherwise, skip
3734              DIALECT_NUMBER of strings ending with '|'.  */
3735           for (i = 0; i < dialect_number; i++)
3736             {
3737               while (*p && *p++ != '|')
3738                 ;
3739
3740               if (*p == '|')
3741                 p++;
3742           }
3743         }
3744         break;
3745
3746       case '|':
3747         /* Skip to close brace.  */
3748         while (*p && *p++ != '}')
3749           ;
3750         break;
3751
3752       case '}':
3753         break;
3754 #endif
3755
3756       case '%':
3757         c = *p++;
3758         q = &buf[1];
3759         while ((c >= '0' && c <= '9') || c == '.')
3760           {
3761             *q++ = c;
3762             c = *p++;
3763           }
3764         switch (c)
3765           {
3766           case '%':
3767             fprintf (file, "%%");
3768             break;
3769
3770           case 'd':  case 'i':  case 'u':
3771           case 'x':  case 'p':  case 'X':
3772           case 'o':
3773             *q++ = c;
3774             *q = 0;
3775             fprintf (file, buf, va_arg (argptr, int));
3776             break;
3777
3778           case 'w':
3779             /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3780                but we do not check for those cases.  It means that the value
3781                is a HOST_WIDE_INT, which may be either `int' or `long'.  */
3782
3783 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3784 #else
3785 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3786             *q++ = 'l';
3787 #else
3788             *q++ = 'l';
3789             *q++ = 'l';
3790 #endif
3791 #endif
3792
3793             *q++ = *p++;
3794             *q = 0;
3795             fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3796             break;
3797
3798           case 'l':
3799             *q++ = c;
3800             *q++ = *p++;
3801             *q = 0;
3802             fprintf (file, buf, va_arg (argptr, long));
3803             break;
3804
3805           case 'e':
3806           case 'f':
3807           case 'g':
3808             *q++ = c;
3809             *q = 0;
3810             fprintf (file, buf, va_arg (argptr, double));
3811             break;
3812
3813           case 's':
3814             *q++ = c;
3815             *q = 0;
3816             fprintf (file, buf, va_arg (argptr, char *));
3817             break;
3818
3819           case 'O':
3820 #ifdef ASM_OUTPUT_OPCODE
3821             ASM_OUTPUT_OPCODE (asm_out_file, p);
3822 #endif
3823             break;
3824
3825           case 'R':
3826 #ifdef REGISTER_PREFIX
3827             fprintf (file, "%s", REGISTER_PREFIX);
3828 #endif
3829             break;
3830
3831           case 'I':
3832 #ifdef IMMEDIATE_PREFIX
3833             fprintf (file, "%s", IMMEDIATE_PREFIX);
3834 #endif
3835             break;
3836
3837           case 'L':
3838 #ifdef LOCAL_LABEL_PREFIX
3839             fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3840 #endif
3841             break;
3842
3843           case 'U':
3844             fputs (user_label_prefix, file);
3845             break;
3846
3847 #ifdef ASM_FPRINTF_EXTENSIONS
3848             /* Upper case letters are reserved for general use by asm_fprintf
3849                and so are not available to target specific code.  In order to
3850                prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
3851                they are defined here.  As they get turned into real extensions
3852                to asm_fprintf they should be removed from this list.  */
3853           case 'A': case 'B': case 'C': case 'D': case 'E':
3854           case 'F': case 'G': case 'H': case 'J': case 'K':
3855           case 'M': case 'N': case 'P': case 'Q': case 'S':
3856           case 'T': case 'V': case 'W': case 'Y': case 'Z':
3857             break;
3858             
3859           ASM_FPRINTF_EXTENSIONS (file, argptr, p)
3860 #endif
3861           default:
3862             abort ();
3863           }
3864         break;
3865
3866       default:
3867         fputc (c, file);
3868       }
3869   va_end (argptr);
3870 }
3871 \f
3872 /* Split up a CONST_DOUBLE or integer constant rtx
3873    into two rtx's for single words,
3874    storing in *FIRST the word that comes first in memory in the target
3875    and in *SECOND the other.  */
3876
3877 void
3878 split_double (value, first, second)
3879      rtx value;
3880      rtx *first, *second;
3881 {
3882   if (GET_CODE (value) == CONST_INT)
3883     {
3884       if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3885         {
3886           /* In this case the CONST_INT holds both target words.
3887              Extract the bits from it into two word-sized pieces.
3888              Sign extend each half to HOST_WIDE_INT.  */
3889           rtx low, high;
3890           /* On machines where HOST_BITS_PER_WIDE_INT == BITS_PER_WORD
3891              the shift below will cause a compiler warning, even though
3892              this code won't be executed.  So put the shift amounts in
3893              variables to avoid the warning.  */
3894           int rshift = HOST_BITS_PER_WIDE_INT - BITS_PER_WORD;
3895           int lshift = HOST_BITS_PER_WIDE_INT - 2 * BITS_PER_WORD;
3896
3897           low = GEN_INT ((INTVAL (value) << rshift) >> rshift);
3898           high = GEN_INT ((INTVAL (value) << lshift) >> rshift);
3899           if (WORDS_BIG_ENDIAN)
3900             {
3901               *first = high;
3902               *second = low;
3903             }
3904           else
3905             {
3906               *first = low;
3907               *second = high;
3908             }
3909         }
3910       else
3911         {
3912           /* The rule for using CONST_INT for a wider mode
3913              is that we regard the value as signed.
3914              So sign-extend it.  */
3915           rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3916           if (WORDS_BIG_ENDIAN)
3917             {
3918               *first = high;
3919               *second = value;
3920             }
3921           else
3922             {
3923               *first = value;
3924               *second = high;
3925             }
3926         }
3927     }
3928   else if (GET_CODE (value) != CONST_DOUBLE)
3929     {
3930       if (WORDS_BIG_ENDIAN)
3931         {
3932           *first = const0_rtx;
3933           *second = value;
3934         }
3935       else
3936         {
3937           *first = value;
3938           *second = const0_rtx;
3939         }
3940     }
3941   else if (GET_MODE (value) == VOIDmode
3942            /* This is the old way we did CONST_DOUBLE integers.  */
3943            || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3944     {
3945       /* In an integer, the words are defined as most and least significant.
3946          So order them by the target's convention.  */
3947       if (WORDS_BIG_ENDIAN)
3948         {
3949           *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3950           *second = GEN_INT (CONST_DOUBLE_LOW (value));
3951         }
3952       else
3953         {
3954           *first = GEN_INT (CONST_DOUBLE_LOW (value));
3955           *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3956         }
3957     }
3958   else
3959     {
3960 #ifdef REAL_ARITHMETIC
3961       REAL_VALUE_TYPE r; long l[2];
3962       REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3963
3964       /* Note, this converts the REAL_VALUE_TYPE to the target's
3965          format, splits up the floating point double and outputs
3966          exactly 32 bits of it into each of l[0] and l[1] --
3967          not necessarily BITS_PER_WORD bits.  */
3968       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3969
3970       /* If 32 bits is an entire word for the target, but not for the host,
3971          then sign-extend on the host so that the number will look the same
3972          way on the host that it would on the target.  See for instance
3973          simplify_unary_operation.  The #if is needed to avoid compiler
3974          warnings.  */
3975
3976 #if HOST_BITS_PER_LONG > 32
3977       if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
3978         {
3979           if (l[0] & ((long) 1 << 31))
3980             l[0] |= ((long) (-1) << 32);
3981           if (l[1] & ((long) 1 << 31))
3982             l[1] |= ((long) (-1) << 32);
3983         }
3984 #endif
3985
3986       *first = GEN_INT ((HOST_WIDE_INT) l[0]);
3987       *second = GEN_INT ((HOST_WIDE_INT) l[1]);
3988 #else
3989       if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3990            || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3991           && ! flag_pretend_float)
3992       abort ();
3993
3994       if (
3995 #ifdef HOST_WORDS_BIG_ENDIAN
3996           WORDS_BIG_ENDIAN
3997 #else
3998           ! WORDS_BIG_ENDIAN
3999 #endif
4000           )
4001         {
4002           /* Host and target agree => no need to swap.  */
4003           *first = GEN_INT (CONST_DOUBLE_LOW (value));
4004           *second = GEN_INT (CONST_DOUBLE_HIGH (value));
4005         }
4006       else
4007         {
4008           *second = GEN_INT (CONST_DOUBLE_LOW (value));
4009           *first = GEN_INT (CONST_DOUBLE_HIGH (value));
4010         }
4011 #endif /* no REAL_ARITHMETIC */
4012     }
4013 }
4014 \f
4015 /* Return nonzero if this function has no function calls.  */
4016
4017 int
4018 leaf_function_p ()
4019 {
4020   rtx insn;
4021
4022   if (profile_flag || profile_block_flag || profile_arc_flag)
4023     return 0;
4024
4025   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4026     {
4027       if (GET_CODE (insn) == CALL_INSN
4028           && ! SIBLING_CALL_P (insn))
4029         return 0;
4030       if (GET_CODE (insn) == INSN
4031           && GET_CODE (PATTERN (insn)) == SEQUENCE
4032           && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4033           && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4034         return 0;
4035     }
4036   for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
4037     {
4038       if (GET_CODE (XEXP (insn, 0)) == CALL_INSN
4039           && ! SIBLING_CALL_P (insn))
4040         return 0;
4041       if (GET_CODE (XEXP (insn, 0)) == INSN
4042           && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
4043           && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN
4044           && ! SIBLING_CALL_P (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)))
4045         return 0;
4046     }
4047
4048   return 1;
4049 }
4050
4051 /* On some machines, a function with no call insns
4052    can run faster if it doesn't create its own register window.
4053    When output, the leaf function should use only the "output"
4054    registers.  Ordinarily, the function would be compiled to use
4055    the "input" registers to find its arguments; it is a candidate
4056    for leaf treatment if it uses only the "input" registers.
4057    Leaf function treatment means renumbering so the function
4058    uses the "output" registers instead.  */
4059
4060 #ifdef LEAF_REGISTERS
4061
4062 /* Return 1 if this function uses only the registers that can be
4063    safely renumbered.  */
4064
4065 int
4066 only_leaf_regs_used ()
4067 {
4068   int i;
4069   char *permitted_reg_in_leaf_functions = LEAF_REGISTERS;
4070
4071   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4072     if ((regs_ever_live[i] || global_regs[i])
4073         && ! permitted_reg_in_leaf_functions[i])
4074       return 0;
4075
4076   if (current_function_uses_pic_offset_table
4077       && pic_offset_table_rtx != 0
4078       && GET_CODE (pic_offset_table_rtx) == REG
4079       && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
4080     return 0;
4081
4082   return 1;
4083 }
4084
4085 /* Scan all instructions and renumber all registers into those
4086    available in leaf functions.  */
4087
4088 static void
4089 leaf_renumber_regs (first)
4090      rtx first;
4091 {
4092   rtx insn;
4093
4094   /* Renumber only the actual patterns.
4095      The reg-notes can contain frame pointer refs,
4096      and renumbering them could crash, and should not be needed.  */
4097   for (insn = first; insn; insn = NEXT_INSN (insn))
4098     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
4099       leaf_renumber_regs_insn (PATTERN (insn));
4100   for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
4101     if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
4102       leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
4103 }
4104
4105 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
4106    available in leaf functions.  */
4107
4108 void
4109 leaf_renumber_regs_insn (in_rtx)
4110      register rtx in_rtx;
4111 {
4112   register int i, j;
4113   register const char *format_ptr;
4114
4115   if (in_rtx == 0)
4116     return;
4117
4118   /* Renumber all input-registers into output-registers.
4119      renumbered_regs would be 1 for an output-register;
4120      they  */
4121
4122   if (GET_CODE (in_rtx) == REG)
4123     {
4124       int newreg;
4125
4126       /* Don't renumber the same reg twice.  */
4127       if (in_rtx->used)
4128         return;
4129
4130       newreg = REGNO (in_rtx);
4131       /* Don't try to renumber pseudo regs.  It is possible for a pseudo reg
4132          to reach here as part of a REG_NOTE.  */
4133       if (newreg >= FIRST_PSEUDO_REGISTER)
4134         {
4135           in_rtx->used = 1;
4136           return;
4137         }
4138       newreg = LEAF_REG_REMAP (newreg);
4139       if (newreg < 0)
4140         abort ();
4141       regs_ever_live[REGNO (in_rtx)] = 0;
4142       regs_ever_live[newreg] = 1;
4143       REGNO (in_rtx) = newreg;
4144       in_rtx->used = 1;
4145     }
4146
4147   if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
4148     {
4149       /* Inside a SEQUENCE, we find insns.
4150          Renumber just the patterns of these insns,
4151          just as we do for the top-level insns.  */
4152       leaf_renumber_regs_insn (PATTERN (in_rtx));
4153       return;
4154     }
4155
4156   format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
4157
4158   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
4159     switch (*format_ptr++)
4160       {
4161       case 'e':
4162         leaf_renumber_regs_insn (XEXP (in_rtx, i));
4163         break;
4164
4165       case 'E':
4166         if (NULL != XVEC (in_rtx, i))
4167           {
4168             for (j = 0; j < XVECLEN (in_rtx, i); j++)
4169               leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
4170           }
4171         break;
4172
4173       case 'S':
4174       case 's':
4175       case '0':
4176       case 'i':
4177       case 'w':
4178       case 'n':
4179       case 'u':
4180         break;
4181
4182       default:
4183         abort ();
4184       }
4185 }
4186 #endif