OSDN Git Service

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