OSDN Git Service

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