OSDN Git Service

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