OSDN Git Service

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