OSDN Git Service

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