OSDN Git Service

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