OSDN Git Service

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