OSDN Git Service

* final.c: (insn_lengths): Make it an int *, so that large jump
[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 int *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 = (int *) xmalloc (max_uid * sizeof (*insn_lengths));
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     {
3042       rtx new = simplify_subreg (GET_MODE (x), y, GET_MODE (y),
3043                                  SUBREG_BYTE (x));
3044
3045       if (new != 0)
3046         *xp = new;
3047       /* Simplify_subreg can't handle some REG cases, but we have to.  */
3048       else if (GET_CODE (y) == REG)
3049         {
3050           REGNO (x) = subreg_hard_regno (x, 1);
3051           PUT_CODE (x, REG);
3052           ORIGINAL_REGNO (x) = ORIGINAL_REGNO (y);
3053           /* This field has a different meaning for REGs and SUBREGs.  Make
3054              sure to clear it!  */
3055           x->used = 0;
3056         }
3057       else
3058         abort ();
3059     }
3060
3061   return *xp;
3062 }
3063
3064 /* Do alter_subreg on all the SUBREGs contained in X.  */
3065
3066 static rtx
3067 walk_alter_subreg (xp)
3068      rtx *xp;
3069 {
3070   rtx x = *xp;
3071   switch (GET_CODE (x))
3072     {
3073     case PLUS:
3074     case MULT:
3075       XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0));
3076       XEXP (x, 1) = walk_alter_subreg (&XEXP (x, 1));
3077       break;
3078
3079     case MEM:
3080       XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0));
3081       break;
3082
3083     case SUBREG:
3084       return alter_subreg (xp);
3085
3086     default:
3087       break;
3088     }
3089
3090   return x;
3091 }
3092 \f
3093 #ifdef HAVE_cc0
3094
3095 /* Given BODY, the body of a jump instruction, alter the jump condition
3096    as required by the bits that are set in cc_status.flags.
3097    Not all of the bits there can be handled at this level in all cases.
3098
3099    The value is normally 0.
3100    1 means that the condition has become always true.
3101    -1 means that the condition has become always false.
3102    2 means that COND has been altered.  */
3103
3104 static int
3105 alter_cond (cond)
3106      rtx cond;
3107 {
3108   int value = 0;
3109
3110   if (cc_status.flags & CC_REVERSED)
3111     {
3112       value = 2;
3113       PUT_CODE (cond, swap_condition (GET_CODE (cond)));
3114     }
3115
3116   if (cc_status.flags & CC_INVERTED)
3117     {
3118       value = 2;
3119       PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
3120     }
3121
3122   if (cc_status.flags & CC_NOT_POSITIVE)
3123     switch (GET_CODE (cond))
3124       {
3125       case LE:
3126       case LEU:
3127       case GEU:
3128         /* Jump becomes unconditional.  */
3129         return 1;
3130
3131       case GT:
3132       case GTU:
3133       case LTU:
3134         /* Jump becomes no-op.  */
3135         return -1;
3136
3137       case GE:
3138         PUT_CODE (cond, EQ);
3139         value = 2;
3140         break;
3141
3142       case LT:
3143         PUT_CODE (cond, NE);
3144         value = 2;
3145         break;
3146
3147       default:
3148         break;
3149       }
3150
3151   if (cc_status.flags & CC_NOT_NEGATIVE)
3152     switch (GET_CODE (cond))
3153       {
3154       case GE:
3155       case GEU:
3156         /* Jump becomes unconditional.  */
3157         return 1;
3158
3159       case LT:
3160       case LTU:
3161         /* Jump becomes no-op.  */
3162         return -1;
3163
3164       case LE:
3165       case LEU:
3166         PUT_CODE (cond, EQ);
3167         value = 2;
3168         break;
3169
3170       case GT:
3171       case GTU:
3172         PUT_CODE (cond, NE);
3173         value = 2;
3174         break;
3175
3176       default:
3177         break;
3178       }
3179
3180   if (cc_status.flags & CC_NO_OVERFLOW)
3181     switch (GET_CODE (cond))
3182       {
3183       case GEU:
3184         /* Jump becomes unconditional.  */
3185         return 1;
3186
3187       case LEU:
3188         PUT_CODE (cond, EQ);
3189         value = 2;
3190         break;
3191
3192       case GTU:
3193         PUT_CODE (cond, NE);
3194         value = 2;
3195         break;
3196
3197       case LTU:
3198         /* Jump becomes no-op.  */
3199         return -1;
3200
3201       default:
3202         break;
3203       }
3204
3205   if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
3206     switch (GET_CODE (cond))
3207       {
3208       default:
3209         abort ();
3210
3211       case NE:
3212         PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
3213         value = 2;
3214         break;
3215
3216       case EQ:
3217         PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
3218         value = 2;
3219         break;
3220       }
3221
3222   if (cc_status.flags & CC_NOT_SIGNED)
3223     /* The flags are valid if signed condition operators are converted
3224        to unsigned.  */
3225     switch (GET_CODE (cond))
3226       {
3227       case LE:
3228         PUT_CODE (cond, LEU);
3229         value = 2;
3230         break;
3231
3232       case LT:
3233         PUT_CODE (cond, LTU);
3234         value = 2;
3235         break;
3236
3237       case GT:
3238         PUT_CODE (cond, GTU);
3239         value = 2;
3240         break;
3241
3242       case GE:
3243         PUT_CODE (cond, GEU);
3244         value = 2;
3245         break;
3246
3247       default:
3248         break;
3249       }
3250
3251   return value;
3252 }
3253 #endif
3254 \f
3255 /* Report inconsistency between the assembler template and the operands.
3256    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
3257
3258 void
3259 output_operand_lossage (msgid)
3260      const char *msgid;
3261 {
3262   if (this_is_asm_operands)
3263     error_for_asm (this_is_asm_operands, "invalid `asm': %s", _(msgid));
3264   else
3265     internal_error ("output_operand: %s", _(msgid));
3266 }
3267 \f
3268 /* Output of assembler code from a template, and its subroutines.  */
3269
3270 /* Annotate the assembly with a comment describing the pattern and
3271    alternative used.  */
3272
3273 static void
3274 output_asm_name ()
3275 {
3276   if (debug_insn)
3277     {
3278       int num = INSN_CODE (debug_insn);
3279       fprintf (asm_out_file, "\t%s %d\t%s",
3280                ASM_COMMENT_START, INSN_UID (debug_insn),
3281                insn_data[num].name);
3282       if (insn_data[num].n_alternatives > 1)
3283         fprintf (asm_out_file, "/%d", which_alternative + 1);
3284 #ifdef HAVE_ATTR_length
3285       fprintf (asm_out_file, "\t[length = %d]",
3286                get_attr_length (debug_insn));
3287 #endif
3288       /* Clear this so only the first assembler insn
3289          of any rtl insn will get the special comment for -dp.  */
3290       debug_insn = 0;
3291     }
3292 }
3293
3294 /* If OP is a REG or MEM and we can find a decl corresponding to it or
3295    its address, return that decl.  Set *PADDRESSP to 1 if the decl
3296    corresponds to the address of the object and 0 if to the object.  */
3297
3298 static tree
3299 get_decl_from_op (op, paddressp)
3300      rtx op;
3301      int *paddressp;
3302 {
3303   tree decl;
3304   int inner_addressp;
3305
3306   *paddressp = 0;
3307
3308   if (GET_CODE (op) == REG && ORIGINAL_REGNO (op) >= FIRST_PSEUDO_REGISTER)
3309     return REGNO_DECL (ORIGINAL_REGNO (op));
3310   else if (GET_CODE (op) != MEM)
3311     return 0;
3312
3313   if (MEM_DECL (op) != 0)
3314     return MEM_DECL (op);
3315
3316   /* Otherwise we have an address, so indicate it and look at the address.  */
3317   *paddressp = 1;
3318   op = XEXP (op, 0);
3319
3320   /* First check if we have a decl for the address, then look at the right side
3321      if it is a PLUS.  Otherwise, strip off arithmetic and keep looking.
3322      But don't allow the address to itself be indirect.  */
3323   if ((decl = get_decl_from_op (op, &inner_addressp)) && ! inner_addressp)
3324     return decl;
3325   else if (GET_CODE (op) == PLUS
3326            && (decl = get_decl_from_op (XEXP (op, 1), &inner_addressp)))
3327     return decl;
3328
3329   while (GET_RTX_CLASS (GET_CODE (op)) == '1'
3330          || GET_RTX_CLASS (GET_CODE (op)) == '2')
3331     op = XEXP (op, 0);
3332
3333   decl = get_decl_from_op (op, &inner_addressp);
3334   return inner_addressp ? 0 : decl;
3335 }
3336   
3337 /* Output operand names for assembler instructions.  OPERANDS is the
3338    operand vector, OPORDER is the order to write the operands, and NOPS
3339    is the number of operands to write.  */
3340
3341 static void
3342 output_asm_operand_names (operands, oporder, nops)
3343      rtx *operands;
3344      int *oporder;
3345      int nops;
3346 {
3347   int wrote = 0;
3348   int i;
3349
3350   for (i = 0; i < nops; i++)
3351     {
3352       int addressp;
3353       tree decl = get_decl_from_op (operands[oporder[i]], &addressp);
3354
3355       if (decl && DECL_NAME (decl))
3356         {
3357           fprintf (asm_out_file, "%c%s %s%s",
3358                    wrote ? ',' : '\t', wrote ? "" : ASM_COMMENT_START,
3359                    addressp ? "*" : "", IDENTIFIER_POINTER (DECL_NAME (decl)));
3360           wrote = 1;
3361         }
3362     }
3363 }
3364
3365 /* Output text from TEMPLATE to the assembler output file,
3366    obeying %-directions to substitute operands taken from
3367    the vector OPERANDS.
3368
3369    %N (for N a digit) means print operand N in usual manner.
3370    %lN means require operand N to be a CODE_LABEL or LABEL_REF
3371       and print the label name with no punctuation.
3372    %cN means require operand N to be a constant
3373       and print the constant expression with no punctuation.
3374    %aN means expect operand N to be a memory address
3375       (not a memory reference!) and print a reference
3376       to that address.
3377    %nN means expect operand N to be a constant
3378       and print a constant expression for minus the value
3379       of the operand, with no other punctuation.  */
3380
3381 void
3382 output_asm_insn (template, operands)
3383      const char *template;
3384      rtx *operands;
3385 {
3386   const char *p;
3387   int c;
3388 #ifdef ASSEMBLER_DIALECT
3389   int dialect = 0;
3390 #endif
3391   int oporder[MAX_RECOG_OPERANDS];
3392   char opoutput[MAX_RECOG_OPERANDS];
3393   int ops = 0;
3394
3395   /* An insn may return a null string template
3396      in a case where no assembler code is needed.  */
3397   if (*template == 0)
3398     return;
3399
3400   memset (opoutput, 0, sizeof opoutput);
3401   p = template;
3402   putc ('\t', asm_out_file);
3403
3404 #ifdef ASM_OUTPUT_OPCODE
3405   ASM_OUTPUT_OPCODE (asm_out_file, p);
3406 #endif
3407
3408   while ((c = *p++))
3409     switch (c)
3410       {
3411       case '\n':
3412         if (flag_verbose_asm)
3413           output_asm_operand_names (operands, oporder, ops);
3414         if (flag_print_asm_name)
3415           output_asm_name ();
3416
3417         ops = 0;
3418         memset (opoutput, 0, sizeof opoutput);
3419
3420         putc (c, asm_out_file);
3421 #ifdef ASM_OUTPUT_OPCODE
3422         while ((c = *p) == '\t')
3423           {
3424             putc (c, asm_out_file);
3425             p++;
3426           }
3427         ASM_OUTPUT_OPCODE (asm_out_file, p);
3428 #endif
3429         break;
3430
3431 #ifdef ASSEMBLER_DIALECT
3432       case '{':
3433         {
3434           int i;
3435
3436           if (dialect)
3437             output_operand_lossage ("nested assembly dialect alternatives");
3438           else
3439             dialect = 1;
3440
3441           /* If we want the first dialect, do nothing.  Otherwise, skip
3442              DIALECT_NUMBER of strings ending with '|'.  */
3443           for (i = 0; i < dialect_number; i++)
3444             {
3445               while (*p && *p != '}' && *p++ != '|')
3446                 ;
3447               if (*p == '}')
3448                 break;
3449               if (*p == '|')
3450                 p++;
3451             }
3452
3453           if (*p == '\0')
3454             output_operand_lossage ("unterminated assembly dialect alternative");
3455         }
3456         break;
3457
3458       case '|':
3459         if (dialect)
3460           {
3461             /* Skip to close brace.  */
3462             do
3463               {
3464                 if (*p == '\0')
3465                   {
3466                     output_operand_lossage ("unterminated assembly dialect alternative");
3467                     break;
3468                   }
3469               }   
3470             while (*p++ != '}');
3471             dialect = 0;
3472           }
3473         else
3474           putc (c, asm_out_file);
3475         break;
3476
3477       case '}':
3478         if (! dialect)
3479           putc (c, asm_out_file);
3480         dialect = 0;
3481         break;
3482 #endif
3483
3484       case '%':
3485         /* %% outputs a single %.  */
3486         if (*p == '%')
3487           {
3488             p++;
3489             putc (c, asm_out_file);
3490           }
3491         /* %= outputs a number which is unique to each insn in the entire
3492            compilation.  This is useful for making local labels that are
3493            referred to more than once in a given insn.  */
3494         else if (*p == '=')
3495           {
3496             p++;
3497             fprintf (asm_out_file, "%d", insn_counter);
3498           }
3499         /* % followed by a letter and some digits
3500            outputs an operand in a special way depending on the letter.
3501            Letters `acln' are implemented directly.
3502            Other letters are passed to `output_operand' so that
3503            the PRINT_OPERAND macro can define them.  */
3504         else if (ISALPHA (*p))
3505           {
3506             int letter = *p++;
3507             c = atoi (p);
3508
3509             if (! ISDIGIT (*p))
3510               output_operand_lossage ("operand number missing after %-letter");
3511             else if (this_is_asm_operands
3512                      && (c < 0 || (unsigned int) c >= insn_noperands))
3513               output_operand_lossage ("operand number out of range");
3514             else if (letter == 'l')
3515               output_asm_label (operands[c]);
3516             else if (letter == 'a')
3517               output_address (operands[c]);
3518             else if (letter == 'c')
3519               {
3520                 if (CONSTANT_ADDRESS_P (operands[c]))
3521                   output_addr_const (asm_out_file, operands[c]);
3522                 else
3523                   output_operand (operands[c], 'c');
3524               }
3525             else if (letter == 'n')
3526               {
3527                 if (GET_CODE (operands[c]) == CONST_INT)
3528                   fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3529                            - INTVAL (operands[c]));
3530                 else
3531                   {
3532                     putc ('-', asm_out_file);
3533                     output_addr_const (asm_out_file, operands[c]);
3534                   }
3535               }
3536             else
3537               output_operand (operands[c], letter);
3538
3539             if (!opoutput[c])
3540               oporder[ops++] = c;
3541             opoutput[c] = 1;
3542
3543             while (ISDIGIT (c = *p))
3544               p++;
3545           }
3546         /* % followed by a digit outputs an operand the default way.  */
3547         else if (ISDIGIT (*p))
3548           {
3549             c = atoi (p);
3550             if (this_is_asm_operands
3551                 && (c < 0 || (unsigned int) c >= insn_noperands))
3552               output_operand_lossage ("operand number out of range");
3553             else
3554               output_operand (operands[c], 0);
3555
3556             if (!opoutput[c])
3557               oporder[ops++] = c;
3558             opoutput[c] = 1;
3559
3560             while (ISDIGIT (c = *p))
3561               p++;
3562           }
3563         /* % followed by punctuation: output something for that
3564            punctuation character alone, with no operand.
3565            The PRINT_OPERAND macro decides what is actually done.  */
3566 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3567         else if (PRINT_OPERAND_PUNCT_VALID_P ((unsigned char) *p))
3568           output_operand (NULL_RTX, *p++);
3569 #endif
3570         else
3571           output_operand_lossage ("invalid %%-code");
3572         break;
3573
3574       default:
3575         putc (c, asm_out_file);
3576       }
3577
3578   /* Write out the variable names for operands, if we know them.  */
3579   if (flag_verbose_asm)
3580     output_asm_operand_names (operands, oporder, ops);
3581   if (flag_print_asm_name)
3582     output_asm_name ();
3583
3584   putc ('\n', asm_out_file);
3585 }
3586 \f
3587 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol.  */
3588
3589 void
3590 output_asm_label (x)
3591      rtx x;
3592 {
3593   char buf[256];
3594
3595   if (GET_CODE (x) == LABEL_REF)
3596     x = XEXP (x, 0);
3597   if (GET_CODE (x) == CODE_LABEL
3598       || (GET_CODE (x) == NOTE
3599           && NOTE_LINE_NUMBER (x) == NOTE_INSN_DELETED_LABEL))
3600     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3601   else
3602     output_operand_lossage ("`%l' operand isn't a label");
3603
3604   assemble_name (asm_out_file, buf);
3605 }
3606
3607 /* Print operand X using machine-dependent assembler syntax.
3608    The macro PRINT_OPERAND is defined just to control this function.
3609    CODE is a non-digit that preceded the operand-number in the % spec,
3610    such as 'z' if the spec was `%z3'.  CODE is 0 if there was no char
3611    between the % and the digits.
3612    When CODE is a non-letter, X is 0.
3613
3614    The meanings of the letters are machine-dependent and controlled
3615    by PRINT_OPERAND.  */
3616
3617 static void
3618 output_operand (x, code)
3619      rtx x;
3620      int code ATTRIBUTE_UNUSED;
3621 {
3622   if (x && GET_CODE (x) == SUBREG)
3623     x = alter_subreg (&x);
3624
3625   /* If X is a pseudo-register, abort now rather than writing trash to the
3626      assembler file.  */
3627
3628   if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
3629     abort ();
3630
3631   PRINT_OPERAND (asm_out_file, x, code);
3632 }
3633
3634 /* Print a memory reference operand for address X
3635    using machine-dependent assembler syntax.
3636    The macro PRINT_OPERAND_ADDRESS exists just to control this function.  */
3637
3638 void
3639 output_address (x)
3640      rtx x;
3641 {
3642   walk_alter_subreg (&x);
3643   PRINT_OPERAND_ADDRESS (asm_out_file, x);
3644 }
3645 \f
3646 /* Print an integer constant expression in assembler syntax.
3647    Addition and subtraction are the only arithmetic
3648    that may appear in these expressions.  */
3649
3650 void
3651 output_addr_const (file, x)
3652      FILE *file;
3653      rtx x;
3654 {
3655   char buf[256];
3656
3657  restart:
3658   switch (GET_CODE (x))
3659     {
3660     case PC:
3661       putc ('.', file);
3662       break;
3663
3664     case SYMBOL_REF:
3665 #ifdef ASM_OUTPUT_SYMBOL_REF
3666       ASM_OUTPUT_SYMBOL_REF (file, x);
3667 #else
3668       assemble_name (file, XSTR (x, 0));
3669 #endif
3670       break;
3671
3672     case LABEL_REF:
3673       x = XEXP (x, 0);
3674       /* Fall through.  */
3675     case CODE_LABEL:
3676       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3677 #ifdef ASM_OUTPUT_LABEL_REF
3678       ASM_OUTPUT_LABEL_REF (file, buf);
3679 #else
3680       assemble_name (file, buf);
3681 #endif
3682       break;
3683
3684     case CONST_INT:
3685       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3686       break;
3687
3688     case CONST:
3689       /* This used to output parentheses around the expression,
3690          but that does not work on the 386 (either ATT or BSD assembler).  */
3691       output_addr_const (file, XEXP (x, 0));
3692       break;
3693
3694     case CONST_DOUBLE:
3695       if (GET_MODE (x) == VOIDmode)
3696         {
3697           /* We can use %d if the number is one word and positive.  */
3698           if (CONST_DOUBLE_HIGH (x))
3699             fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3700                      CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3701           else if (CONST_DOUBLE_LOW (x) < 0)
3702             fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3703           else
3704             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3705         }
3706       else
3707         /* We can't handle floating point constants;
3708            PRINT_OPERAND must handle them.  */
3709         output_operand_lossage ("floating constant misused");
3710       break;
3711
3712     case PLUS:
3713       /* Some assemblers need integer constants to appear last (eg masm).  */
3714       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3715         {
3716           output_addr_const (file, XEXP (x, 1));
3717           if (INTVAL (XEXP (x, 0)) >= 0)
3718             fprintf (file, "+");
3719           output_addr_const (file, XEXP (x, 0));
3720         }
3721       else
3722         {
3723           output_addr_const (file, XEXP (x, 0));
3724           if (GET_CODE (XEXP (x, 1)) != CONST_INT
3725               || INTVAL (XEXP (x, 1)) >= 0)
3726             fprintf (file, "+");
3727           output_addr_const (file, XEXP (x, 1));
3728         }
3729       break;
3730
3731     case MINUS:
3732       /* Avoid outputting things like x-x or x+5-x,
3733          since some assemblers can't handle that.  */
3734       x = simplify_subtraction (x);
3735       if (GET_CODE (x) != MINUS)
3736         goto restart;
3737
3738       output_addr_const (file, XEXP (x, 0));
3739       fprintf (file, "-");
3740       if ((GET_CODE (XEXP (x, 1)) == CONST_INT
3741            && INTVAL (XEXP (x, 1)) < 0)
3742           || GET_CODE (XEXP (x, 1)) != CONST_INT)
3743         {
3744           fputs (targetm.asm_out.open_paren, file);
3745           output_addr_const (file, XEXP (x, 1));
3746           fputs (targetm.asm_out.close_paren, file);
3747         }
3748       else
3749         output_addr_const (file, XEXP (x, 1));
3750       break;
3751
3752     case ZERO_EXTEND:
3753     case SIGN_EXTEND:
3754       output_addr_const (file, XEXP (x, 0));
3755       break;
3756
3757     default:
3758 #ifdef OUTPUT_ADDR_CONST_EXTRA
3759       OUTPUT_ADDR_CONST_EXTRA (file, x, fail);
3760       break;
3761
3762     fail:
3763 #endif
3764       output_operand_lossage ("invalid expression as operand");
3765     }
3766 }
3767 \f
3768 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3769    %R prints the value of REGISTER_PREFIX.
3770    %L prints the value of LOCAL_LABEL_PREFIX.
3771    %U prints the value of USER_LABEL_PREFIX.
3772    %I prints the value of IMMEDIATE_PREFIX.
3773    %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3774    Also supported are %d, %x, %s, %e, %f, %g and %%.
3775
3776    We handle alternate assembler dialects here, just like output_asm_insn.  */
3777
3778 void
3779 asm_fprintf VPARAMS ((FILE *file, const char *p, ...))
3780 {
3781   char buf[10];
3782   char *q, c;
3783
3784   VA_OPEN (argptr, p);
3785   VA_FIXEDARG (argptr, FILE *, file);
3786   VA_FIXEDARG (argptr, const char *, p);
3787
3788   buf[0] = '%';
3789
3790   while ((c = *p++))
3791     switch (c)
3792       {
3793 #ifdef ASSEMBLER_DIALECT
3794       case '{':
3795         {
3796           int i;
3797
3798           /* If we want the first dialect, do nothing.  Otherwise, skip
3799              DIALECT_NUMBER of strings ending with '|'.  */
3800           for (i = 0; i < dialect_number; i++)
3801             {
3802               while (*p && *p++ != '|')
3803                 ;
3804
3805               if (*p == '|')
3806                 p++;
3807             }
3808         }
3809         break;
3810
3811       case '|':
3812         /* Skip to close brace.  */
3813         while (*p && *p++ != '}')
3814           ;
3815         break;
3816
3817       case '}':
3818         break;
3819 #endif
3820
3821       case '%':
3822         c = *p++;
3823         q = &buf[1];
3824         while (ISDIGIT (c) || c == '.')
3825           {
3826             *q++ = c;
3827             c = *p++;
3828           }
3829         switch (c)
3830           {
3831           case '%':
3832             fprintf (file, "%%");
3833             break;
3834
3835           case 'd':  case 'i':  case 'u':
3836           case 'x':  case 'p':  case 'X':
3837           case 'o':
3838             *q++ = c;
3839             *q = 0;
3840             fprintf (file, buf, va_arg (argptr, int));
3841             break;
3842
3843           case 'w':
3844             /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3845                but we do not check for those cases.  It means that the value
3846                is a HOST_WIDE_INT, which may be either `int' or `long'.  */
3847
3848 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3849 #else
3850 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3851             *q++ = 'l';
3852 #else
3853             *q++ = 'l';
3854             *q++ = 'l';
3855 #endif
3856 #endif
3857
3858             *q++ = *p++;
3859             *q = 0;
3860             fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3861             break;
3862
3863           case 'l':
3864             *q++ = c;
3865             *q++ = *p++;
3866             *q = 0;
3867             fprintf (file, buf, va_arg (argptr, long));
3868             break;
3869
3870           case 'e':
3871           case 'f':
3872           case 'g':
3873             *q++ = c;
3874             *q = 0;
3875             fprintf (file, buf, va_arg (argptr, double));
3876             break;
3877
3878           case 's':
3879             *q++ = c;
3880             *q = 0;
3881             fprintf (file, buf, va_arg (argptr, char *));
3882             break;
3883
3884           case 'O':
3885 #ifdef ASM_OUTPUT_OPCODE
3886             ASM_OUTPUT_OPCODE (asm_out_file, p);
3887 #endif
3888             break;
3889
3890           case 'R':
3891 #ifdef REGISTER_PREFIX
3892             fprintf (file, "%s", REGISTER_PREFIX);
3893 #endif
3894             break;
3895
3896           case 'I':
3897 #ifdef IMMEDIATE_PREFIX
3898             fprintf (file, "%s", IMMEDIATE_PREFIX);
3899 #endif
3900             break;
3901
3902           case 'L':
3903 #ifdef LOCAL_LABEL_PREFIX
3904             fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3905 #endif
3906             break;
3907
3908           case 'U':
3909             fputs (user_label_prefix, file);
3910             break;
3911
3912 #ifdef ASM_FPRINTF_EXTENSIONS
3913             /* Upper case letters are reserved for general use by asm_fprintf
3914                and so are not available to target specific code.  In order to
3915                prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
3916                they are defined here.  As they get turned into real extensions
3917                to asm_fprintf they should be removed from this list.  */
3918           case 'A': case 'B': case 'C': case 'D': case 'E':
3919           case 'F': case 'G': case 'H': case 'J': case 'K':
3920           case 'M': case 'N': case 'P': case 'Q': case 'S':
3921           case 'T': case 'V': case 'W': case 'Y': case 'Z':
3922             break;
3923
3924           ASM_FPRINTF_EXTENSIONS (file, argptr, p)
3925 #endif
3926           default:
3927             abort ();
3928           }
3929         break;
3930
3931       default:
3932         fputc (c, file);
3933       }
3934   VA_CLOSE (argptr);
3935 }
3936 \f
3937 /* Split up a CONST_DOUBLE or integer constant rtx
3938    into two rtx's for single words,
3939    storing in *FIRST the word that comes first in memory in the target
3940    and in *SECOND the other.  */
3941
3942 void
3943 split_double (value, first, second)
3944      rtx value;
3945      rtx *first, *second;
3946 {
3947   if (GET_CODE (value) == CONST_INT)
3948     {
3949       if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3950         {
3951           /* In this case the CONST_INT holds both target words.
3952              Extract the bits from it into two word-sized pieces.
3953              Sign extend each half to HOST_WIDE_INT.  */
3954           unsigned HOST_WIDE_INT low, high;
3955           unsigned HOST_WIDE_INT mask, sign_bit, sign_extend;
3956
3957           /* Set sign_bit to the most significant bit of a word.  */
3958           sign_bit = 1;
3959           sign_bit <<= BITS_PER_WORD - 1;
3960
3961           /* Set mask so that all bits of the word are set.  We could
3962              have used 1 << BITS_PER_WORD instead of basing the
3963              calculation on sign_bit.  However, on machines where
3964              HOST_BITS_PER_WIDE_INT == BITS_PER_WORD, it could cause a
3965              compiler warning, even though the code would never be
3966              executed.  */
3967           mask = sign_bit << 1;
3968           mask--;
3969
3970           /* Set sign_extend as any remaining bits.  */
3971           sign_extend = ~mask;
3972
3973           /* Pick the lower word and sign-extend it.  */
3974           low = INTVAL (value);
3975           low &= mask;
3976           if (low & sign_bit)
3977             low |= sign_extend;
3978
3979           /* Pick the higher word, shifted to the least significant
3980              bits, and sign-extend it.  */
3981           high = INTVAL (value);
3982           high >>= BITS_PER_WORD - 1;
3983           high >>= 1;
3984           high &= mask;
3985           if (high & sign_bit)
3986             high |= sign_extend;
3987
3988           /* Store the words in the target machine order.  */
3989           if (WORDS_BIG_ENDIAN)
3990             {
3991               *first = GEN_INT (high);
3992               *second = GEN_INT (low);
3993             }
3994           else
3995             {
3996               *first = GEN_INT (low);
3997               *second = GEN_INT (high);
3998             }
3999         }
4000       else
4001         {
4002           /* The rule for using CONST_INT for a wider mode
4003              is that we regard the value as signed.
4004              So sign-extend it.  */
4005           rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
4006           if (WORDS_BIG_ENDIAN)
4007             {
4008               *first = high;
4009               *second = value;
4010             }
4011           else
4012             {
4013               *first = value;
4014               *second = high;
4015             }
4016         }
4017     }
4018   else if (GET_CODE (value) != CONST_DOUBLE)
4019     {
4020       if (WORDS_BIG_ENDIAN)
4021         {
4022           *first = const0_rtx;
4023           *second = value;
4024         }
4025       else
4026         {
4027           *first = value;
4028           *second = const0_rtx;
4029         }
4030     }
4031   else if (GET_MODE (value) == VOIDmode
4032            /* This is the old way we did CONST_DOUBLE integers.  */
4033            || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
4034     {
4035       /* In an integer, the words are defined as most and least significant.
4036          So order them by the target's convention.  */
4037       if (WORDS_BIG_ENDIAN)
4038         {
4039           *first = GEN_INT (CONST_DOUBLE_HIGH (value));
4040           *second = GEN_INT (CONST_DOUBLE_LOW (value));
4041         }
4042       else
4043         {
4044           *first = GEN_INT (CONST_DOUBLE_LOW (value));
4045           *second = GEN_INT (CONST_DOUBLE_HIGH (value));
4046         }
4047     }
4048   else
4049     {
4050 #ifdef REAL_ARITHMETIC
4051       REAL_VALUE_TYPE r;
4052       long l[2];
4053       REAL_VALUE_FROM_CONST_DOUBLE (r, value);
4054
4055       /* Note, this converts the REAL_VALUE_TYPE to the target's
4056          format, splits up the floating point double and outputs
4057          exactly 32 bits of it into each of l[0] and l[1] --
4058          not necessarily BITS_PER_WORD bits.  */
4059       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
4060
4061       /* If 32 bits is an entire word for the target, but not for the host,
4062          then sign-extend on the host so that the number will look the same
4063          way on the host that it would on the target.  See for instance
4064          simplify_unary_operation.  The #if is needed to avoid compiler
4065          warnings.  */
4066
4067 #if HOST_BITS_PER_LONG > 32
4068       if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
4069         {
4070           if (l[0] & ((long) 1 << 31))
4071             l[0] |= ((long) (-1) << 32);
4072           if (l[1] & ((long) 1 << 31))
4073             l[1] |= ((long) (-1) << 32);
4074         }
4075 #endif
4076
4077       *first = GEN_INT ((HOST_WIDE_INT) l[0]);
4078       *second = GEN_INT ((HOST_WIDE_INT) l[1]);
4079 #else
4080       if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
4081            || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
4082           && ! flag_pretend_float)
4083         abort ();
4084
4085       if (
4086 #ifdef HOST_WORDS_BIG_ENDIAN
4087           WORDS_BIG_ENDIAN
4088 #else
4089           ! WORDS_BIG_ENDIAN
4090 #endif
4091           )
4092         {
4093           /* Host and target agree => no need to swap.  */
4094           *first = GEN_INT (CONST_DOUBLE_LOW (value));
4095           *second = GEN_INT (CONST_DOUBLE_HIGH (value));
4096         }
4097       else
4098         {
4099           *second = GEN_INT (CONST_DOUBLE_LOW (value));
4100           *first = GEN_INT (CONST_DOUBLE_HIGH (value));
4101         }
4102 #endif /* no REAL_ARITHMETIC */
4103     }
4104 }
4105 \f
4106 /* Return nonzero if this function has no function calls.  */
4107
4108 int
4109 leaf_function_p ()
4110 {
4111   rtx insn;
4112   rtx link;
4113
4114   if (profile_flag || profile_block_flag || profile_arc_flag)
4115     return 0;
4116
4117   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4118     {
4119       if (GET_CODE (insn) == CALL_INSN
4120           && ! SIBLING_CALL_P (insn))
4121         return 0;
4122       if (GET_CODE (insn) == INSN
4123           && GET_CODE (PATTERN (insn)) == SEQUENCE
4124           && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4125           && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4126         return 0;
4127     }
4128   for (link = current_function_epilogue_delay_list;
4129        link;
4130        link = XEXP (link, 1))
4131     {
4132       insn = XEXP (link, 0);
4133
4134       if (GET_CODE (insn) == CALL_INSN
4135           && ! SIBLING_CALL_P (insn))
4136         return 0;
4137       if (GET_CODE (insn) == INSN
4138           && GET_CODE (PATTERN (insn)) == SEQUENCE
4139           && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4140           && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4141         return 0;
4142     }
4143
4144   return 1;
4145 }
4146
4147 /* Return 1 if branch is an forward branch.
4148    Uses insn_shuid array, so it works only in the final pass.  May be used by
4149    output templates to customary add branch prediction hints.
4150  */
4151 int
4152 final_forward_branch_p (insn)
4153      rtx insn;
4154 {
4155   int insn_id, label_id;
4156   if (!uid_shuid)
4157     abort ();
4158   insn_id = INSN_SHUID (insn);
4159   label_id = INSN_SHUID (JUMP_LABEL (insn));
4160   /* We've hit some insns that does not have id information available.  */
4161   if (!insn_id || !label_id)
4162     abort ();
4163   return insn_id < label_id;
4164 }
4165
4166 /* On some machines, a function with no call insns
4167    can run faster if it doesn't create its own register window.
4168    When output, the leaf function should use only the "output"
4169    registers.  Ordinarily, the function would be compiled to use
4170    the "input" registers to find its arguments; it is a candidate
4171    for leaf treatment if it uses only the "input" registers.
4172    Leaf function treatment means renumbering so the function
4173    uses the "output" registers instead.  */
4174
4175 #ifdef LEAF_REGISTERS
4176
4177 /* Return 1 if this function uses only the registers that can be
4178    safely renumbered.  */
4179
4180 int
4181 only_leaf_regs_used ()
4182 {
4183   int i;
4184   char *permitted_reg_in_leaf_functions = LEAF_REGISTERS;
4185
4186   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4187     if ((regs_ever_live[i] || global_regs[i])
4188         && ! permitted_reg_in_leaf_functions[i])
4189       return 0;
4190
4191   if (current_function_uses_pic_offset_table
4192       && pic_offset_table_rtx != 0
4193       && GET_CODE (pic_offset_table_rtx) == REG
4194       && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
4195     return 0;
4196
4197   return 1;
4198 }
4199
4200 /* Scan all instructions and renumber all registers into those
4201    available in leaf functions.  */
4202
4203 static void
4204 leaf_renumber_regs (first)
4205      rtx first;
4206 {
4207   rtx insn;
4208
4209   /* Renumber only the actual patterns.
4210      The reg-notes can contain frame pointer refs,
4211      and renumbering them could crash, and should not be needed.  */
4212   for (insn = first; insn; insn = NEXT_INSN (insn))
4213     if (INSN_P (insn))
4214       leaf_renumber_regs_insn (PATTERN (insn));
4215   for (insn = current_function_epilogue_delay_list;
4216        insn;
4217        insn = XEXP (insn, 1))
4218     if (INSN_P (XEXP (insn, 0)))
4219       leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
4220 }
4221
4222 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
4223    available in leaf functions.  */
4224
4225 void
4226 leaf_renumber_regs_insn (in_rtx)
4227      rtx in_rtx;
4228 {
4229   int i, j;
4230   const char *format_ptr;
4231
4232   if (in_rtx == 0)
4233     return;
4234
4235   /* Renumber all input-registers into output-registers.
4236      renumbered_regs would be 1 for an output-register;
4237      they  */
4238
4239   if (GET_CODE (in_rtx) == REG)
4240     {
4241       int newreg;
4242
4243       /* Don't renumber the same reg twice.  */
4244       if (in_rtx->used)
4245         return;
4246
4247       newreg = REGNO (in_rtx);
4248       /* Don't try to renumber pseudo regs.  It is possible for a pseudo reg
4249          to reach here as part of a REG_NOTE.  */
4250       if (newreg >= FIRST_PSEUDO_REGISTER)
4251         {
4252           in_rtx->used = 1;
4253           return;
4254         }
4255       newreg = LEAF_REG_REMAP (newreg);
4256       if (newreg < 0)
4257         abort ();
4258       regs_ever_live[REGNO (in_rtx)] = 0;
4259       regs_ever_live[newreg] = 1;
4260       REGNO (in_rtx) = newreg;
4261       in_rtx->used = 1;
4262     }
4263
4264   if (INSN_P (in_rtx))
4265     {
4266       /* Inside a SEQUENCE, we find insns.
4267          Renumber just the patterns of these insns,
4268          just as we do for the top-level insns.  */
4269       leaf_renumber_regs_insn (PATTERN (in_rtx));
4270       return;
4271     }
4272
4273   format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
4274
4275   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
4276     switch (*format_ptr++)
4277       {
4278       case 'e':
4279         leaf_renumber_regs_insn (XEXP (in_rtx, i));
4280         break;
4281
4282       case 'E':
4283         if (NULL != XVEC (in_rtx, i))
4284           {
4285             for (j = 0; j < XVECLEN (in_rtx, i); j++)
4286               leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
4287           }
4288         break;
4289
4290       case 'S':
4291       case 's':
4292       case '0':
4293       case 'i':
4294       case 'w':
4295       case 'n':
4296       case 'u':
4297         break;
4298
4299       default:
4300         abort ();
4301       }
4302 }
4303 #endif