re PR tree-optimization/33627 (ICE in verify_stmts compiling abiword)
[official-gcc.git] / gcc / final.c
blobb59a222001130f3a7d331329f445184f9a1a7509
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.
6 This file is part of GCC.
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.
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.
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/>. */
22 /* This is the final pass of the compiler.
23 It looks at the rtl code for a function and outputs assembler code.
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'.
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.)
36 Instructions to set the condition codes are omitted when it can be
37 seen that the condition codes already had the desired values.
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.
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. */
47 #include "config.h"
48 #include "system.h"
49 #include "coretypes.h"
50 #include "tm.h"
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"
82 #ifdef XCOFF_DEBUGGING_INFO
83 #include "xcoffout.h" /* Needed for external data
84 declarations for e.g. AIX 4.x. */
85 #endif
87 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
88 #include "dwarf2out.h"
89 #endif
91 #ifdef DBX_DEBUGGING_INFO
92 #include "dbxout.h"
93 #endif
95 #ifdef SDB_DEBUGGING_INFO
96 #include "sdbout.h"
97 #endif
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
105 /* How to start an assembler comment. */
106 #ifndef ASM_COMMENT_START
107 #define ASM_COMMENT_START ";#"
108 #endif
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, STR) ((C) == ';')
113 #endif
115 #ifndef JUMP_TABLES_IN_TEXT_SECTION
116 #define JUMP_TABLES_IN_TEXT_SECTION 0
117 #endif
119 /* Bitflags used by final_scan_insn. */
120 #define SEEN_BB 1
121 #define SEEN_NOTE 2
122 #define SEEN_EMITTED 4
124 /* Last insn processed by final_scan_insn. */
125 static rtx debug_insn;
126 rtx current_output_insn;
128 /* Line number of last NOTE. */
129 static int last_linenum;
131 /* Highest line number in current block. */
132 static int high_block_linenum;
134 /* Likewise for function. */
135 static int high_function_linenum;
137 /* Filename of last NOTE. */
138 static const char *last_filename;
140 /* Override filename and line number. */
141 static const char *override_filename;
142 static int override_linenum;
144 /* Whether to force emission of a line note before the next insn. */
145 static bool force_source_line = false;
147 extern const int length_unit_log; /* This is defined in insn-attrtab.c. */
149 /* Nonzero while outputting an `asm' with operands.
150 This means that inconsistencies are the user's fault, so don't die.
151 The precise value is the insn being output, to pass to error_for_asm. */
152 rtx this_is_asm_operands;
154 /* Number of operands of this insn, for an `asm' with operands. */
155 static unsigned int insn_noperands;
157 /* Compare optimization flag. */
159 static rtx last_ignored_compare = 0;
161 /* Assign a unique number to each insn that is output.
162 This can be used to generate unique local labels. */
164 static int insn_counter = 0;
166 #ifdef HAVE_cc0
167 /* This variable contains machine-dependent flags (defined in tm.h)
168 set and examined by output routines
169 that describe how to interpret the condition codes properly. */
171 CC_STATUS cc_status;
173 /* During output of an insn, this contains a copy of cc_status
174 from before the insn. */
176 CC_STATUS cc_prev_status;
177 #endif
179 /* Nonzero means current function must be given a frame pointer.
180 Initialized in function.c to 0. Set only in reload1.c as per
181 the needs of the function. */
183 int frame_pointer_needed;
185 /* Number of unmatched NOTE_INSN_BLOCK_BEG notes we have seen. */
187 static int block_depth;
189 /* Nonzero if have enabled APP processing of our assembler output. */
191 static int app_on;
193 /* If we are outputting an insn sequence, this contains the sequence rtx.
194 Zero otherwise. */
196 rtx final_sequence;
198 #ifdef ASSEMBLER_DIALECT
200 /* Number of the assembler dialect to use, starting at 0. */
201 static int dialect_number;
202 #endif
204 #ifdef HAVE_conditional_execution
205 /* Nonnull if the insn currently being emitted was a COND_EXEC pattern. */
206 rtx current_insn_predicate;
207 #endif
209 #ifdef HAVE_ATTR_length
210 static int asm_insn_count (rtx);
211 #endif
212 static void profile_function (FILE *);
213 static void profile_after_prologue (FILE *);
214 static bool notice_source_line (rtx);
215 static rtx walk_alter_subreg (rtx *, bool *);
216 static void output_asm_name (void);
217 static void output_alternate_entry_point (FILE *, rtx);
218 static tree get_mem_expr_from_op (rtx, int *);
219 static void output_asm_operand_names (rtx *, int *, int);
220 static void output_operand (rtx, int);
221 #ifdef LEAF_REGISTERS
222 static void leaf_renumber_regs (rtx);
223 #endif
224 #ifdef HAVE_cc0
225 static int alter_cond (rtx);
226 #endif
227 #ifndef ADDR_VEC_ALIGN
228 static int final_addr_vec_align (rtx);
229 #endif
230 #ifdef HAVE_ATTR_length
231 static int align_fuzz (rtx, rtx, int, unsigned);
232 #endif
234 /* Initialize data in final at the beginning of a compilation. */
236 void
237 init_final (const char *filename ATTRIBUTE_UNUSED)
239 app_on = 0;
240 final_sequence = 0;
242 #ifdef ASSEMBLER_DIALECT
243 dialect_number = ASSEMBLER_DIALECT;
244 #endif
247 /* Default target function prologue and epilogue assembler output.
249 If not overridden for epilogue code, then the function body itself
250 contains return instructions wherever needed. */
251 void
252 default_function_pro_epilogue (FILE *file ATTRIBUTE_UNUSED,
253 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
257 /* Default target hook that outputs nothing to a stream. */
258 void
259 no_asm_to_stream (FILE *file ATTRIBUTE_UNUSED)
263 /* Enable APP processing of subsequent output.
264 Used before the output from an `asm' statement. */
266 void
267 app_enable (void)
269 if (! app_on)
271 fputs (ASM_APP_ON, asm_out_file);
272 app_on = 1;
276 /* Disable APP processing of subsequent output.
277 Called from varasm.c before most kinds of output. */
279 void
280 app_disable (void)
282 if (app_on)
284 fputs (ASM_APP_OFF, asm_out_file);
285 app_on = 0;
289 /* Return the number of slots filled in the current
290 delayed branch sequence (we don't count the insn needing the
291 delay slot). Zero if not in a delayed branch sequence. */
293 #ifdef DELAY_SLOTS
295 dbr_sequence_length (void)
297 if (final_sequence != 0)
298 return XVECLEN (final_sequence, 0) - 1;
299 else
300 return 0;
302 #endif
304 /* The next two pages contain routines used to compute the length of an insn
305 and to shorten branches. */
307 /* Arrays for insn lengths, and addresses. The latter is referenced by
308 `insn_current_length'. */
310 static int *insn_lengths;
312 VEC(int,heap) *insn_addresses_;
314 /* Max uid for which the above arrays are valid. */
315 static int insn_lengths_max_uid;
317 /* Address of insn being processed. Used by `insn_current_length'. */
318 int insn_current_address;
320 /* Address of insn being processed in previous iteration. */
321 int insn_last_address;
323 /* known invariant alignment of insn being processed. */
324 int insn_current_align;
326 /* After shorten_branches, for any insn, uid_align[INSN_UID (insn)]
327 gives the next following alignment insn that increases the known
328 alignment, or NULL_RTX if there is no such insn.
329 For any alignment obtained this way, we can again index uid_align with
330 its uid to obtain the next following align that in turn increases the
331 alignment, till we reach NULL_RTX; the sequence obtained this way
332 for each insn we'll call the alignment chain of this insn in the following
333 comments. */
335 struct label_alignment
337 short alignment;
338 short max_skip;
341 static rtx *uid_align;
342 static int *uid_shuid;
343 static struct label_alignment *label_align;
345 /* Indicate that branch shortening hasn't yet been done. */
347 void
348 init_insn_lengths (void)
350 if (uid_shuid)
352 free (uid_shuid);
353 uid_shuid = 0;
355 if (insn_lengths)
357 free (insn_lengths);
358 insn_lengths = 0;
359 insn_lengths_max_uid = 0;
361 #ifdef HAVE_ATTR_length
362 INSN_ADDRESSES_FREE ();
363 #endif
364 if (uid_align)
366 free (uid_align);
367 uid_align = 0;
371 /* Obtain the current length of an insn. If branch shortening has been done,
372 get its actual length. Otherwise, use FALLBACK_FN to calculate the
373 length. */
374 static inline int
375 get_attr_length_1 (rtx insn ATTRIBUTE_UNUSED,
376 int (*fallback_fn) (rtx) ATTRIBUTE_UNUSED)
378 #ifdef HAVE_ATTR_length
379 rtx body;
380 int i;
381 int length = 0;
383 if (insn_lengths_max_uid > INSN_UID (insn))
384 return insn_lengths[INSN_UID (insn)];
385 else
386 switch (GET_CODE (insn))
388 case NOTE:
389 case BARRIER:
390 case CODE_LABEL:
391 return 0;
393 case CALL_INSN:
394 length = fallback_fn (insn);
395 break;
397 case JUMP_INSN:
398 body = PATTERN (insn);
399 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
401 /* Alignment is machine-dependent and should be handled by
402 ADDR_VEC_ALIGN. */
404 else
405 length = fallback_fn (insn);
406 break;
408 case INSN:
409 body = PATTERN (insn);
410 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
411 return 0;
413 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
414 length = asm_insn_count (body) * fallback_fn (insn);
415 else if (GET_CODE (body) == SEQUENCE)
416 for (i = 0; i < XVECLEN (body, 0); i++)
417 length += get_attr_length (XVECEXP (body, 0, i));
418 else
419 length = fallback_fn (insn);
420 break;
422 default:
423 break;
426 #ifdef ADJUST_INSN_LENGTH
427 ADJUST_INSN_LENGTH (insn, length);
428 #endif
429 return length;
430 #else /* not HAVE_ATTR_length */
431 return 0;
432 #define insn_default_length 0
433 #define insn_min_length 0
434 #endif /* not HAVE_ATTR_length */
437 /* Obtain the current length of an insn. If branch shortening has been done,
438 get its actual length. Otherwise, get its maximum length. */
440 get_attr_length (rtx insn)
442 return get_attr_length_1 (insn, insn_default_length);
445 /* Obtain the current length of an insn. If branch shortening has been done,
446 get its actual length. Otherwise, get its minimum length. */
448 get_attr_min_length (rtx insn)
450 return get_attr_length_1 (insn, insn_min_length);
453 /* Code to handle alignment inside shorten_branches. */
455 /* Here is an explanation how the algorithm in align_fuzz can give
456 proper results:
458 Call a sequence of instructions beginning with alignment point X
459 and continuing until the next alignment point `block X'. When `X'
460 is used in an expression, it means the alignment value of the
461 alignment point.
463 Call the distance between the start of the first insn of block X, and
464 the end of the last insn of block X `IX', for the `inner size of X'.
465 This is clearly the sum of the instruction lengths.
467 Likewise with the next alignment-delimited block following X, which we
468 shall call block Y.
470 Call the distance between the start of the first insn of block X, and
471 the start of the first insn of block Y `OX', for the `outer size of X'.
473 The estimated padding is then OX - IX.
475 OX can be safely estimated as
477 if (X >= Y)
478 OX = round_up(IX, Y)
479 else
480 OX = round_up(IX, X) + Y - X
482 Clearly est(IX) >= real(IX), because that only depends on the
483 instruction lengths, and those being overestimated is a given.
485 Clearly round_up(foo, Z) >= round_up(bar, Z) if foo >= bar, so
486 we needn't worry about that when thinking about OX.
488 When X >= Y, the alignment provided by Y adds no uncertainty factor
489 for branch ranges starting before X, so we can just round what we have.
490 But when X < Y, we don't know anything about the, so to speak,
491 `middle bits', so we have to assume the worst when aligning up from an
492 address mod X to one mod Y, which is Y - X. */
494 #ifndef LABEL_ALIGN
495 #define LABEL_ALIGN(LABEL) align_labels_log
496 #endif
498 #ifndef LABEL_ALIGN_MAX_SKIP
499 #define LABEL_ALIGN_MAX_SKIP align_labels_max_skip
500 #endif
502 #ifndef LOOP_ALIGN
503 #define LOOP_ALIGN(LABEL) align_loops_log
504 #endif
506 #ifndef LOOP_ALIGN_MAX_SKIP
507 #define LOOP_ALIGN_MAX_SKIP align_loops_max_skip
508 #endif
510 #ifndef LABEL_ALIGN_AFTER_BARRIER
511 #define LABEL_ALIGN_AFTER_BARRIER(LABEL) 0
512 #endif
514 #ifndef LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP
515 #define LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP 0
516 #endif
518 #ifndef JUMP_ALIGN
519 #define JUMP_ALIGN(LABEL) align_jumps_log
520 #endif
522 #ifndef JUMP_ALIGN_MAX_SKIP
523 #define JUMP_ALIGN_MAX_SKIP align_jumps_max_skip
524 #endif
526 #ifndef ADDR_VEC_ALIGN
527 static int
528 final_addr_vec_align (rtx addr_vec)
530 int align = GET_MODE_SIZE (GET_MODE (PATTERN (addr_vec)));
532 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
533 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
534 return exact_log2 (align);
538 #define ADDR_VEC_ALIGN(ADDR_VEC) final_addr_vec_align (ADDR_VEC)
539 #endif
541 #ifndef INSN_LENGTH_ALIGNMENT
542 #define INSN_LENGTH_ALIGNMENT(INSN) length_unit_log
543 #endif
545 #define INSN_SHUID(INSN) (uid_shuid[INSN_UID (INSN)])
547 static int min_labelno, max_labelno;
549 #define LABEL_TO_ALIGNMENT(LABEL) \
550 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].alignment)
552 #define LABEL_TO_MAX_SKIP(LABEL) \
553 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].max_skip)
555 /* For the benefit of port specific code do this also as a function. */
558 label_to_alignment (rtx label)
560 return LABEL_TO_ALIGNMENT (label);
563 #ifdef HAVE_ATTR_length
564 /* The differences in addresses
565 between a branch and its target might grow or shrink depending on
566 the alignment the start insn of the range (the branch for a forward
567 branch or the label for a backward branch) starts out on; if these
568 differences are used naively, they can even oscillate infinitely.
569 We therefore want to compute a 'worst case' address difference that
570 is independent of the alignment the start insn of the range end
571 up on, and that is at least as large as the actual difference.
572 The function align_fuzz calculates the amount we have to add to the
573 naively computed difference, by traversing the part of the alignment
574 chain of the start insn of the range that is in front of the end insn
575 of the range, and considering for each alignment the maximum amount
576 that it might contribute to a size increase.
578 For casesi tables, we also want to know worst case minimum amounts of
579 address difference, in case a machine description wants to introduce
580 some common offset that is added to all offsets in a table.
581 For this purpose, align_fuzz with a growth argument of 0 computes the
582 appropriate adjustment. */
584 /* Compute the maximum delta by which the difference of the addresses of
585 START and END might grow / shrink due to a different address for start
586 which changes the size of alignment insns between START and END.
587 KNOWN_ALIGN_LOG is the alignment known for START.
588 GROWTH should be ~0 if the objective is to compute potential code size
589 increase, and 0 if the objective is to compute potential shrink.
590 The return value is undefined for any other value of GROWTH. */
592 static int
593 align_fuzz (rtx start, rtx end, int known_align_log, unsigned int growth)
595 int uid = INSN_UID (start);
596 rtx align_label;
597 int known_align = 1 << known_align_log;
598 int end_shuid = INSN_SHUID (end);
599 int fuzz = 0;
601 for (align_label = uid_align[uid]; align_label; align_label = uid_align[uid])
603 int align_addr, new_align;
605 uid = INSN_UID (align_label);
606 align_addr = INSN_ADDRESSES (uid) - insn_lengths[uid];
607 if (uid_shuid[uid] > end_shuid)
608 break;
609 known_align_log = LABEL_TO_ALIGNMENT (align_label);
610 new_align = 1 << known_align_log;
611 if (new_align < known_align)
612 continue;
613 fuzz += (-align_addr ^ growth) & (new_align - known_align);
614 known_align = new_align;
616 return fuzz;
619 /* Compute a worst-case reference address of a branch so that it
620 can be safely used in the presence of aligned labels. Since the
621 size of the branch itself is unknown, the size of the branch is
622 not included in the range. I.e. for a forward branch, the reference
623 address is the end address of the branch as known from the previous
624 branch shortening pass, minus a value to account for possible size
625 increase due to alignment. For a backward branch, it is the start
626 address of the branch as known from the current pass, plus a value
627 to account for possible size increase due to alignment.
628 NB.: Therefore, the maximum offset allowed for backward branches needs
629 to exclude the branch size. */
632 insn_current_reference_address (rtx branch)
634 rtx dest, seq;
635 int seq_uid;
637 if (! INSN_ADDRESSES_SET_P ())
638 return 0;
640 seq = NEXT_INSN (PREV_INSN (branch));
641 seq_uid = INSN_UID (seq);
642 if (!JUMP_P (branch))
643 /* This can happen for example on the PA; the objective is to know the
644 offset to address something in front of the start of the function.
645 Thus, we can treat it like a backward branch.
646 We assume here that FUNCTION_BOUNDARY / BITS_PER_UNIT is larger than
647 any alignment we'd encounter, so we skip the call to align_fuzz. */
648 return insn_current_address;
649 dest = JUMP_LABEL (branch);
651 /* BRANCH has no proper alignment chain set, so use SEQ.
652 BRANCH also has no INSN_SHUID. */
653 if (INSN_SHUID (seq) < INSN_SHUID (dest))
655 /* Forward branch. */
656 return (insn_last_address + insn_lengths[seq_uid]
657 - align_fuzz (seq, dest, length_unit_log, ~0));
659 else
661 /* Backward branch. */
662 return (insn_current_address
663 + align_fuzz (dest, seq, length_unit_log, ~0));
666 #endif /* HAVE_ATTR_length */
668 /* Compute branch alignments based on frequency information in the
669 CFG. */
671 static unsigned int
672 compute_alignments (void)
674 int log, max_skip, max_log;
675 basic_block bb;
677 if (label_align)
679 free (label_align);
680 label_align = 0;
683 max_labelno = max_label_num ();
684 min_labelno = get_first_label_num ();
685 label_align = XCNEWVEC (struct label_alignment, max_labelno - min_labelno + 1);
687 /* If not optimizing or optimizing for size, don't assign any alignments. */
688 if (! optimize || optimize_size)
689 return 0;
691 FOR_EACH_BB (bb)
693 rtx label = BB_HEAD (bb);
694 int fallthru_frequency = 0, branch_frequency = 0, has_fallthru = 0;
695 edge e;
696 edge_iterator ei;
698 if (!LABEL_P (label)
699 || probably_never_executed_bb_p (bb))
700 continue;
701 max_log = LABEL_ALIGN (label);
702 max_skip = LABEL_ALIGN_MAX_SKIP;
704 FOR_EACH_EDGE (e, ei, bb->preds)
706 if (e->flags & EDGE_FALLTHRU)
707 has_fallthru = 1, fallthru_frequency += EDGE_FREQUENCY (e);
708 else
709 branch_frequency += EDGE_FREQUENCY (e);
712 /* There are two purposes to align block with no fallthru incoming edge:
713 1) to avoid fetch stalls when branch destination is near cache boundary
714 2) to improve cache efficiency in case the previous block is not executed
715 (so it does not need to be in the cache).
717 We to catch first case, we align frequently executed blocks.
718 To catch the second, we align blocks that are executed more frequently
719 than the predecessor and the predecessor is likely to not be executed
720 when function is called. */
722 if (!has_fallthru
723 && (branch_frequency > BB_FREQ_MAX / 10
724 || (bb->frequency > bb->prev_bb->frequency * 10
725 && (bb->prev_bb->frequency
726 <= ENTRY_BLOCK_PTR->frequency / 2))))
728 log = JUMP_ALIGN (label);
729 if (max_log < log)
731 max_log = log;
732 max_skip = JUMP_ALIGN_MAX_SKIP;
735 /* In case block is frequent and reached mostly by non-fallthru edge,
736 align it. It is most likely a first block of loop. */
737 if (has_fallthru
738 && maybe_hot_bb_p (bb)
739 && branch_frequency + fallthru_frequency > BB_FREQ_MAX / 10
740 && branch_frequency > fallthru_frequency * 2)
742 log = LOOP_ALIGN (label);
743 if (max_log < log)
745 max_log = log;
746 max_skip = LOOP_ALIGN_MAX_SKIP;
749 LABEL_TO_ALIGNMENT (label) = max_log;
750 LABEL_TO_MAX_SKIP (label) = max_skip;
752 return 0;
755 struct tree_opt_pass pass_compute_alignments =
757 NULL, /* name */
758 NULL, /* gate */
759 compute_alignments, /* execute */
760 NULL, /* sub */
761 NULL, /* next */
762 0, /* static_pass_number */
763 0, /* tv_id */
764 0, /* properties_required */
765 0, /* properties_provided */
766 0, /* properties_destroyed */
767 0, /* todo_flags_start */
768 0, /* todo_flags_finish */
769 0 /* letter */
773 /* Make a pass over all insns and compute their actual lengths by shortening
774 any branches of variable length if possible. */
776 /* shorten_branches might be called multiple times: for example, the SH
777 port splits out-of-range conditional branches in MACHINE_DEPENDENT_REORG.
778 In order to do this, it needs proper length information, which it obtains
779 by calling shorten_branches. This cannot be collapsed with
780 shorten_branches itself into a single pass unless we also want to integrate
781 reorg.c, since the branch splitting exposes new instructions with delay
782 slots. */
784 void
785 shorten_branches (rtx first ATTRIBUTE_UNUSED)
787 rtx insn;
788 int max_uid;
789 int i;
790 int max_log;
791 int max_skip;
792 #ifdef HAVE_ATTR_length
793 #define MAX_CODE_ALIGN 16
794 rtx seq;
795 int something_changed = 1;
796 char *varying_length;
797 rtx body;
798 int uid;
799 rtx align_tab[MAX_CODE_ALIGN];
801 #endif
803 /* Compute maximum UID and allocate label_align / uid_shuid. */
804 max_uid = get_max_uid ();
806 /* Free uid_shuid before reallocating it. */
807 free (uid_shuid);
809 uid_shuid = XNEWVEC (int, max_uid);
811 if (max_labelno != max_label_num ())
813 int old = max_labelno;
814 int n_labels;
815 int n_old_labels;
817 max_labelno = max_label_num ();
819 n_labels = max_labelno - min_labelno + 1;
820 n_old_labels = old - min_labelno + 1;
822 label_align = xrealloc (label_align,
823 n_labels * sizeof (struct label_alignment));
825 /* Range of labels grows monotonically in the function. Failing here
826 means that the initialization of array got lost. */
827 gcc_assert (n_old_labels <= n_labels);
829 memset (label_align + n_old_labels, 0,
830 (n_labels - n_old_labels) * sizeof (struct label_alignment));
833 /* Initialize label_align and set up uid_shuid to be strictly
834 monotonically rising with insn order. */
835 /* We use max_log here to keep track of the maximum alignment we want to
836 impose on the next CODE_LABEL (or the current one if we are processing
837 the CODE_LABEL itself). */
839 max_log = 0;
840 max_skip = 0;
842 for (insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn))
844 int log;
846 INSN_SHUID (insn) = i++;
847 if (INSN_P (insn))
848 continue;
850 if (LABEL_P (insn))
852 rtx next;
854 /* Merge in alignments computed by compute_alignments. */
855 log = LABEL_TO_ALIGNMENT (insn);
856 if (max_log < log)
858 max_log = log;
859 max_skip = LABEL_TO_MAX_SKIP (insn);
862 log = LABEL_ALIGN (insn);
863 if (max_log < log)
865 max_log = log;
866 max_skip = LABEL_ALIGN_MAX_SKIP;
868 next = next_nonnote_insn (insn);
869 /* ADDR_VECs only take room if read-only data goes into the text
870 section. */
871 if (JUMP_TABLES_IN_TEXT_SECTION
872 || readonly_data_section == text_section)
873 if (next && JUMP_P (next))
875 rtx nextbody = PATTERN (next);
876 if (GET_CODE (nextbody) == ADDR_VEC
877 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
879 log = ADDR_VEC_ALIGN (next);
880 if (max_log < log)
882 max_log = log;
883 max_skip = LABEL_ALIGN_MAX_SKIP;
887 LABEL_TO_ALIGNMENT (insn) = max_log;
888 LABEL_TO_MAX_SKIP (insn) = max_skip;
889 max_log = 0;
890 max_skip = 0;
892 else if (BARRIER_P (insn))
894 rtx label;
896 for (label = insn; label && ! INSN_P (label);
897 label = NEXT_INSN (label))
898 if (LABEL_P (label))
900 log = LABEL_ALIGN_AFTER_BARRIER (insn);
901 if (max_log < log)
903 max_log = log;
904 max_skip = LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP;
906 break;
910 #ifdef HAVE_ATTR_length
912 /* Allocate the rest of the arrays. */
913 insn_lengths = XNEWVEC (int, max_uid);
914 insn_lengths_max_uid = max_uid;
915 /* Syntax errors can lead to labels being outside of the main insn stream.
916 Initialize insn_addresses, so that we get reproducible results. */
917 INSN_ADDRESSES_ALLOC (max_uid);
919 varying_length = XCNEWVEC (char, max_uid);
921 /* Initialize uid_align. We scan instructions
922 from end to start, and keep in align_tab[n] the last seen insn
923 that does an alignment of at least n+1, i.e. the successor
924 in the alignment chain for an insn that does / has a known
925 alignment of n. */
926 uid_align = XCNEWVEC (rtx, max_uid);
928 for (i = MAX_CODE_ALIGN; --i >= 0;)
929 align_tab[i] = NULL_RTX;
930 seq = get_last_insn ();
931 for (; seq; seq = PREV_INSN (seq))
933 int uid = INSN_UID (seq);
934 int log;
935 log = (LABEL_P (seq) ? LABEL_TO_ALIGNMENT (seq) : 0);
936 uid_align[uid] = align_tab[0];
937 if (log)
939 /* Found an alignment label. */
940 uid_align[uid] = align_tab[log];
941 for (i = log - 1; i >= 0; i--)
942 align_tab[i] = seq;
945 #ifdef CASE_VECTOR_SHORTEN_MODE
946 if (optimize)
948 /* Look for ADDR_DIFF_VECs, and initialize their minimum and maximum
949 label fields. */
951 int min_shuid = INSN_SHUID (get_insns ()) - 1;
952 int max_shuid = INSN_SHUID (get_last_insn ()) + 1;
953 int rel;
955 for (insn = first; insn != 0; insn = NEXT_INSN (insn))
957 rtx min_lab = NULL_RTX, max_lab = NULL_RTX, pat;
958 int len, i, min, max, insn_shuid;
959 int min_align;
960 addr_diff_vec_flags flags;
962 if (!JUMP_P (insn)
963 || GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
964 continue;
965 pat = PATTERN (insn);
966 len = XVECLEN (pat, 1);
967 gcc_assert (len > 0);
968 min_align = MAX_CODE_ALIGN;
969 for (min = max_shuid, max = min_shuid, i = len - 1; i >= 0; i--)
971 rtx lab = XEXP (XVECEXP (pat, 1, i), 0);
972 int shuid = INSN_SHUID (lab);
973 if (shuid < min)
975 min = shuid;
976 min_lab = lab;
978 if (shuid > max)
980 max = shuid;
981 max_lab = lab;
983 if (min_align > LABEL_TO_ALIGNMENT (lab))
984 min_align = LABEL_TO_ALIGNMENT (lab);
986 XEXP (pat, 2) = gen_rtx_LABEL_REF (Pmode, min_lab);
987 XEXP (pat, 3) = gen_rtx_LABEL_REF (Pmode, max_lab);
988 insn_shuid = INSN_SHUID (insn);
989 rel = INSN_SHUID (XEXP (XEXP (pat, 0), 0));
990 memset (&flags, 0, sizeof (flags));
991 flags.min_align = min_align;
992 flags.base_after_vec = rel > insn_shuid;
993 flags.min_after_vec = min > insn_shuid;
994 flags.max_after_vec = max > insn_shuid;
995 flags.min_after_base = min > rel;
996 flags.max_after_base = max > rel;
997 ADDR_DIFF_VEC_FLAGS (pat) = flags;
1000 #endif /* CASE_VECTOR_SHORTEN_MODE */
1002 /* Compute initial lengths, addresses, and varying flags for each insn. */
1003 for (insn_current_address = 0, insn = first;
1004 insn != 0;
1005 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
1007 uid = INSN_UID (insn);
1009 insn_lengths[uid] = 0;
1011 if (LABEL_P (insn))
1013 int log = LABEL_TO_ALIGNMENT (insn);
1014 if (log)
1016 int align = 1 << log;
1017 int new_address = (insn_current_address + align - 1) & -align;
1018 insn_lengths[uid] = new_address - insn_current_address;
1022 INSN_ADDRESSES (uid) = insn_current_address + insn_lengths[uid];
1024 if (NOTE_P (insn) || BARRIER_P (insn)
1025 || LABEL_P (insn))
1026 continue;
1027 if (INSN_DELETED_P (insn))
1028 continue;
1030 body = PATTERN (insn);
1031 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1033 /* This only takes room if read-only data goes into the text
1034 section. */
1035 if (JUMP_TABLES_IN_TEXT_SECTION
1036 || readonly_data_section == text_section)
1037 insn_lengths[uid] = (XVECLEN (body,
1038 GET_CODE (body) == ADDR_DIFF_VEC)
1039 * GET_MODE_SIZE (GET_MODE (body)));
1040 /* Alignment is handled by ADDR_VEC_ALIGN. */
1042 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
1043 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
1044 else if (GET_CODE (body) == SEQUENCE)
1046 int i;
1047 int const_delay_slots;
1048 #ifdef DELAY_SLOTS
1049 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
1050 #else
1051 const_delay_slots = 0;
1052 #endif
1053 /* Inside a delay slot sequence, we do not do any branch shortening
1054 if the shortening could change the number of delay slots
1055 of the branch. */
1056 for (i = 0; i < XVECLEN (body, 0); i++)
1058 rtx inner_insn = XVECEXP (body, 0, i);
1059 int inner_uid = INSN_UID (inner_insn);
1060 int inner_length;
1062 if (GET_CODE (body) == ASM_INPUT
1063 || asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
1064 inner_length = (asm_insn_count (PATTERN (inner_insn))
1065 * insn_default_length (inner_insn));
1066 else
1067 inner_length = insn_default_length (inner_insn);
1069 insn_lengths[inner_uid] = inner_length;
1070 if (const_delay_slots)
1072 if ((varying_length[inner_uid]
1073 = insn_variable_length_p (inner_insn)) != 0)
1074 varying_length[uid] = 1;
1075 INSN_ADDRESSES (inner_uid) = (insn_current_address
1076 + insn_lengths[uid]);
1078 else
1079 varying_length[inner_uid] = 0;
1080 insn_lengths[uid] += inner_length;
1083 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
1085 insn_lengths[uid] = insn_default_length (insn);
1086 varying_length[uid] = insn_variable_length_p (insn);
1089 /* If needed, do any adjustment. */
1090 #ifdef ADJUST_INSN_LENGTH
1091 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
1092 if (insn_lengths[uid] < 0)
1093 fatal_insn ("negative insn length", insn);
1094 #endif
1097 /* Now loop over all the insns finding varying length insns. For each,
1098 get the current insn length. If it has changed, reflect the change.
1099 When nothing changes for a full pass, we are done. */
1101 while (something_changed)
1103 something_changed = 0;
1104 insn_current_align = MAX_CODE_ALIGN - 1;
1105 for (insn_current_address = 0, insn = first;
1106 insn != 0;
1107 insn = NEXT_INSN (insn))
1109 int new_length;
1110 #ifdef ADJUST_INSN_LENGTH
1111 int tmp_length;
1112 #endif
1113 int length_align;
1115 uid = INSN_UID (insn);
1117 if (LABEL_P (insn))
1119 int log = LABEL_TO_ALIGNMENT (insn);
1120 if (log > insn_current_align)
1122 int align = 1 << log;
1123 int new_address= (insn_current_address + align - 1) & -align;
1124 insn_lengths[uid] = new_address - insn_current_address;
1125 insn_current_align = log;
1126 insn_current_address = new_address;
1128 else
1129 insn_lengths[uid] = 0;
1130 INSN_ADDRESSES (uid) = insn_current_address;
1131 continue;
1134 length_align = INSN_LENGTH_ALIGNMENT (insn);
1135 if (length_align < insn_current_align)
1136 insn_current_align = length_align;
1138 insn_last_address = INSN_ADDRESSES (uid);
1139 INSN_ADDRESSES (uid) = insn_current_address;
1141 #ifdef CASE_VECTOR_SHORTEN_MODE
1142 if (optimize && JUMP_P (insn)
1143 && GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
1145 rtx body = PATTERN (insn);
1146 int old_length = insn_lengths[uid];
1147 rtx rel_lab = XEXP (XEXP (body, 0), 0);
1148 rtx min_lab = XEXP (XEXP (body, 2), 0);
1149 rtx max_lab = XEXP (XEXP (body, 3), 0);
1150 int rel_addr = INSN_ADDRESSES (INSN_UID (rel_lab));
1151 int min_addr = INSN_ADDRESSES (INSN_UID (min_lab));
1152 int max_addr = INSN_ADDRESSES (INSN_UID (max_lab));
1153 rtx prev;
1154 int rel_align = 0;
1155 addr_diff_vec_flags flags;
1157 /* Avoid automatic aggregate initialization. */
1158 flags = ADDR_DIFF_VEC_FLAGS (body);
1160 /* Try to find a known alignment for rel_lab. */
1161 for (prev = rel_lab;
1162 prev
1163 && ! insn_lengths[INSN_UID (prev)]
1164 && ! (varying_length[INSN_UID (prev)] & 1);
1165 prev = PREV_INSN (prev))
1166 if (varying_length[INSN_UID (prev)] & 2)
1168 rel_align = LABEL_TO_ALIGNMENT (prev);
1169 break;
1172 /* See the comment on addr_diff_vec_flags in rtl.h for the
1173 meaning of the flags values. base: REL_LAB vec: INSN */
1174 /* Anything after INSN has still addresses from the last
1175 pass; adjust these so that they reflect our current
1176 estimate for this pass. */
1177 if (flags.base_after_vec)
1178 rel_addr += insn_current_address - insn_last_address;
1179 if (flags.min_after_vec)
1180 min_addr += insn_current_address - insn_last_address;
1181 if (flags.max_after_vec)
1182 max_addr += insn_current_address - insn_last_address;
1183 /* We want to know the worst case, i.e. lowest possible value
1184 for the offset of MIN_LAB. If MIN_LAB is after REL_LAB,
1185 its offset is positive, and we have to be wary of code shrink;
1186 otherwise, it is negative, and we have to be vary of code
1187 size increase. */
1188 if (flags.min_after_base)
1190 /* If INSN is between REL_LAB and MIN_LAB, the size
1191 changes we are about to make can change the alignment
1192 within the observed offset, therefore we have to break
1193 it up into two parts that are independent. */
1194 if (! flags.base_after_vec && flags.min_after_vec)
1196 min_addr -= align_fuzz (rel_lab, insn, rel_align, 0);
1197 min_addr -= align_fuzz (insn, min_lab, 0, 0);
1199 else
1200 min_addr -= align_fuzz (rel_lab, min_lab, rel_align, 0);
1202 else
1204 if (flags.base_after_vec && ! flags.min_after_vec)
1206 min_addr -= align_fuzz (min_lab, insn, 0, ~0);
1207 min_addr -= align_fuzz (insn, rel_lab, 0, ~0);
1209 else
1210 min_addr -= align_fuzz (min_lab, rel_lab, 0, ~0);
1212 /* Likewise, determine the highest lowest possible value
1213 for the offset of MAX_LAB. */
1214 if (flags.max_after_base)
1216 if (! flags.base_after_vec && flags.max_after_vec)
1218 max_addr += align_fuzz (rel_lab, insn, rel_align, ~0);
1219 max_addr += align_fuzz (insn, max_lab, 0, ~0);
1221 else
1222 max_addr += align_fuzz (rel_lab, max_lab, rel_align, ~0);
1224 else
1226 if (flags.base_after_vec && ! flags.max_after_vec)
1228 max_addr += align_fuzz (max_lab, insn, 0, 0);
1229 max_addr += align_fuzz (insn, rel_lab, 0, 0);
1231 else
1232 max_addr += align_fuzz (max_lab, rel_lab, 0, 0);
1234 PUT_MODE (body, CASE_VECTOR_SHORTEN_MODE (min_addr - rel_addr,
1235 max_addr - rel_addr,
1236 body));
1237 if (JUMP_TABLES_IN_TEXT_SECTION
1238 || readonly_data_section == text_section)
1240 insn_lengths[uid]
1241 = (XVECLEN (body, 1) * GET_MODE_SIZE (GET_MODE (body)));
1242 insn_current_address += insn_lengths[uid];
1243 if (insn_lengths[uid] != old_length)
1244 something_changed = 1;
1247 continue;
1249 #endif /* CASE_VECTOR_SHORTEN_MODE */
1251 if (! (varying_length[uid]))
1253 if (NONJUMP_INSN_P (insn)
1254 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1256 int i;
1258 body = PATTERN (insn);
1259 for (i = 0; i < XVECLEN (body, 0); i++)
1261 rtx inner_insn = XVECEXP (body, 0, i);
1262 int inner_uid = INSN_UID (inner_insn);
1264 INSN_ADDRESSES (inner_uid) = insn_current_address;
1266 insn_current_address += insn_lengths[inner_uid];
1269 else
1270 insn_current_address += insn_lengths[uid];
1272 continue;
1275 if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
1277 int i;
1279 body = PATTERN (insn);
1280 new_length = 0;
1281 for (i = 0; i < XVECLEN (body, 0); i++)
1283 rtx inner_insn = XVECEXP (body, 0, i);
1284 int inner_uid = INSN_UID (inner_insn);
1285 int inner_length;
1287 INSN_ADDRESSES (inner_uid) = insn_current_address;
1289 /* insn_current_length returns 0 for insns with a
1290 non-varying length. */
1291 if (! varying_length[inner_uid])
1292 inner_length = insn_lengths[inner_uid];
1293 else
1294 inner_length = insn_current_length (inner_insn);
1296 if (inner_length != insn_lengths[inner_uid])
1298 insn_lengths[inner_uid] = inner_length;
1299 something_changed = 1;
1301 insn_current_address += insn_lengths[inner_uid];
1302 new_length += inner_length;
1305 else
1307 new_length = insn_current_length (insn);
1308 insn_current_address += new_length;
1311 #ifdef ADJUST_INSN_LENGTH
1312 /* If needed, do any adjustment. */
1313 tmp_length = new_length;
1314 ADJUST_INSN_LENGTH (insn, new_length);
1315 insn_current_address += (new_length - tmp_length);
1316 #endif
1318 if (new_length != insn_lengths[uid])
1320 insn_lengths[uid] = new_length;
1321 something_changed = 1;
1324 /* For a non-optimizing compile, do only a single pass. */
1325 if (!optimize)
1326 break;
1329 free (varying_length);
1331 #endif /* HAVE_ATTR_length */
1334 #ifdef HAVE_ATTR_length
1335 /* Given the body of an INSN known to be generated by an ASM statement, return
1336 the number of machine instructions likely to be generated for this insn.
1337 This is used to compute its length. */
1339 static int
1340 asm_insn_count (rtx body)
1342 const char *template;
1343 int count = 1;
1345 if (GET_CODE (body) == ASM_INPUT)
1346 template = XSTR (body, 0);
1347 else
1348 template = decode_asm_operands (body, NULL, NULL, NULL, NULL, NULL);
1350 for (; *template; template++)
1351 if (IS_ASM_LOGICAL_LINE_SEPARATOR (*template, template)
1352 || *template == '\n')
1353 count++;
1355 return count;
1357 #endif
1359 /* ??? This is probably the wrong place for these. */
1360 /* Structure recording the mapping from source file and directory
1361 names at compile time to those to be embedded in debug
1362 information. */
1363 typedef struct debug_prefix_map
1365 const char *old_prefix;
1366 const char *new_prefix;
1367 size_t old_len;
1368 size_t new_len;
1369 struct debug_prefix_map *next;
1370 } debug_prefix_map;
1372 /* Linked list of such structures. */
1373 debug_prefix_map *debug_prefix_maps;
1376 /* Record a debug file prefix mapping. ARG is the argument to
1377 -fdebug-prefix-map and must be of the form OLD=NEW. */
1379 void
1380 add_debug_prefix_map (const char *arg)
1382 debug_prefix_map *map;
1383 const char *p;
1385 p = strchr (arg, '=');
1386 if (!p)
1388 error ("invalid argument %qs to -fdebug-prefix-map", arg);
1389 return;
1391 map = XNEW (debug_prefix_map);
1392 map->old_prefix = ggc_alloc_string (arg, p - arg);
1393 map->old_len = p - arg;
1394 p++;
1395 map->new_prefix = ggc_strdup (p);
1396 map->new_len = strlen (p);
1397 map->next = debug_prefix_maps;
1398 debug_prefix_maps = map;
1401 /* Perform user-specified mapping of debug filename prefixes. Return
1402 the new name corresponding to FILENAME. */
1404 const char *
1405 remap_debug_filename (const char *filename)
1407 debug_prefix_map *map;
1408 char *s;
1409 const char *name;
1410 size_t name_len;
1412 for (map = debug_prefix_maps; map; map = map->next)
1413 if (strncmp (filename, map->old_prefix, map->old_len) == 0)
1414 break;
1415 if (!map)
1416 return filename;
1417 name = filename + map->old_len;
1418 name_len = strlen (name) + 1;
1419 s = (char *) alloca (name_len + map->new_len);
1420 memcpy (s, map->new_prefix, map->new_len);
1421 memcpy (s + map->new_len, name, name_len);
1422 return ggc_strdup (s);
1425 /* Output assembler code for the start of a function,
1426 and initialize some of the variables in this file
1427 for the new function. The label for the function and associated
1428 assembler pseudo-ops have already been output in `assemble_start_function'.
1430 FIRST is the first insn of the rtl for the function being compiled.
1431 FILE is the file to write assembler code to.
1432 OPTIMIZE is nonzero if we should eliminate redundant
1433 test and compare insns. */
1435 void
1436 final_start_function (rtx first ATTRIBUTE_UNUSED, FILE *file,
1437 int optimize ATTRIBUTE_UNUSED)
1439 block_depth = 0;
1441 this_is_asm_operands = 0;
1443 last_filename = locator_file (prologue_locator);
1444 last_linenum = locator_line (prologue_locator);
1446 high_block_linenum = high_function_linenum = last_linenum;
1448 (*debug_hooks->begin_prologue) (last_linenum, last_filename);
1450 #if defined (DWARF2_UNWIND_INFO) || defined (TARGET_UNWIND_INFO)
1451 if (write_symbols != DWARF2_DEBUG && write_symbols != VMS_AND_DWARF2_DEBUG)
1452 dwarf2out_begin_prologue (0, NULL);
1453 #endif
1455 #ifdef LEAF_REG_REMAP
1456 if (current_function_uses_only_leaf_regs)
1457 leaf_renumber_regs (first);
1458 #endif
1460 /* The Sun386i and perhaps other machines don't work right
1461 if the profiling code comes after the prologue. */
1462 #ifdef PROFILE_BEFORE_PROLOGUE
1463 if (current_function_profile)
1464 profile_function (file);
1465 #endif /* PROFILE_BEFORE_PROLOGUE */
1467 #if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
1468 if (dwarf2out_do_frame ())
1469 dwarf2out_frame_debug (NULL_RTX, false);
1470 #endif
1472 /* If debugging, assign block numbers to all of the blocks in this
1473 function. */
1474 if (write_symbols)
1476 reemit_insn_block_notes ();
1477 number_blocks (current_function_decl);
1478 /* We never actually put out begin/end notes for the top-level
1479 block in the function. But, conceptually, that block is
1480 always needed. */
1481 TREE_ASM_WRITTEN (DECL_INITIAL (current_function_decl)) = 1;
1484 /* First output the function prologue: code to set up the stack frame. */
1485 targetm.asm_out.function_prologue (file, get_frame_size ());
1487 /* If the machine represents the prologue as RTL, the profiling code must
1488 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
1489 #ifdef HAVE_prologue
1490 if (! HAVE_prologue)
1491 #endif
1492 profile_after_prologue (file);
1495 static void
1496 profile_after_prologue (FILE *file ATTRIBUTE_UNUSED)
1498 #ifndef PROFILE_BEFORE_PROLOGUE
1499 if (current_function_profile)
1500 profile_function (file);
1501 #endif /* not PROFILE_BEFORE_PROLOGUE */
1504 static void
1505 profile_function (FILE *file ATTRIBUTE_UNUSED)
1507 #ifndef NO_PROFILE_COUNTERS
1508 # define NO_PROFILE_COUNTERS 0
1509 #endif
1510 #if defined(ASM_OUTPUT_REG_PUSH)
1511 int sval = current_function_returns_struct;
1512 rtx svrtx = targetm.calls.struct_value_rtx (TREE_TYPE (current_function_decl), 1);
1513 #if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
1514 int cxt = cfun->static_chain_decl != NULL;
1515 #endif
1516 #endif /* ASM_OUTPUT_REG_PUSH */
1518 if (! NO_PROFILE_COUNTERS)
1520 int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
1521 switch_to_section (data_section);
1522 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
1523 targetm.asm_out.internal_label (file, "LP", current_function_funcdef_no);
1524 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, align, 1);
1527 switch_to_section (current_function_section ());
1529 #if defined(ASM_OUTPUT_REG_PUSH)
1530 if (sval && svrtx != NULL_RTX && REG_P (svrtx))
1532 ASM_OUTPUT_REG_PUSH (file, REGNO (svrtx));
1534 #endif
1536 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1537 if (cxt)
1538 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1539 #else
1540 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1541 if (cxt)
1543 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1545 #endif
1546 #endif
1548 FUNCTION_PROFILER (file, current_function_funcdef_no);
1550 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1551 if (cxt)
1552 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1553 #else
1554 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1555 if (cxt)
1557 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1559 #endif
1560 #endif
1562 #if defined(ASM_OUTPUT_REG_PUSH)
1563 if (sval && svrtx != NULL_RTX && REG_P (svrtx))
1565 ASM_OUTPUT_REG_POP (file, REGNO (svrtx));
1567 #endif
1570 /* Output assembler code for the end of a function.
1571 For clarity, args are same as those of `final_start_function'
1572 even though not all of them are needed. */
1574 void
1575 final_end_function (void)
1577 app_disable ();
1579 (*debug_hooks->end_function) (high_function_linenum);
1581 /* Finally, output the function epilogue:
1582 code to restore the stack frame and return to the caller. */
1583 targetm.asm_out.function_epilogue (asm_out_file, get_frame_size ());
1585 /* And debug output. */
1586 (*debug_hooks->end_epilogue) (last_linenum, last_filename);
1588 #if defined (DWARF2_UNWIND_INFO)
1589 if (write_symbols != DWARF2_DEBUG && write_symbols != VMS_AND_DWARF2_DEBUG
1590 && dwarf2out_do_frame ())
1591 dwarf2out_end_epilogue (last_linenum, last_filename);
1592 #endif
1595 /* Output assembler code for some insns: all or part of a function.
1596 For description of args, see `final_start_function', above. */
1598 void
1599 final (rtx first, FILE *file, int optimize)
1601 rtx insn;
1602 int max_uid = 0;
1603 int seen = 0;
1605 last_ignored_compare = 0;
1607 for (insn = first; insn; insn = NEXT_INSN (insn))
1609 if (INSN_UID (insn) > max_uid) /* Find largest UID. */
1610 max_uid = INSN_UID (insn);
1611 #ifdef HAVE_cc0
1612 /* If CC tracking across branches is enabled, record the insn which
1613 jumps to each branch only reached from one place. */
1614 if (optimize && JUMP_P (insn))
1616 rtx lab = JUMP_LABEL (insn);
1617 if (lab && LABEL_NUSES (lab) == 1)
1619 LABEL_REFS (lab) = insn;
1622 #endif
1625 init_recog ();
1627 CC_STATUS_INIT;
1629 /* Output the insns. */
1630 for (insn = first; insn;)
1632 #ifdef HAVE_ATTR_length
1633 if ((unsigned) INSN_UID (insn) >= INSN_ADDRESSES_SIZE ())
1635 /* This can be triggered by bugs elsewhere in the compiler if
1636 new insns are created after init_insn_lengths is called. */
1637 gcc_assert (NOTE_P (insn));
1638 insn_current_address = -1;
1640 else
1641 insn_current_address = INSN_ADDRESSES (INSN_UID (insn));
1642 #endif /* HAVE_ATTR_length */
1644 insn = final_scan_insn (insn, file, optimize, 0, &seen);
1648 const char *
1649 get_insn_template (int code, rtx insn)
1651 switch (insn_data[code].output_format)
1653 case INSN_OUTPUT_FORMAT_SINGLE:
1654 return insn_data[code].output.single;
1655 case INSN_OUTPUT_FORMAT_MULTI:
1656 return insn_data[code].output.multi[which_alternative];
1657 case INSN_OUTPUT_FORMAT_FUNCTION:
1658 gcc_assert (insn);
1659 return (*insn_data[code].output.function) (recog_data.operand, insn);
1661 default:
1662 gcc_unreachable ();
1666 /* Emit the appropriate declaration for an alternate-entry-point
1667 symbol represented by INSN, to FILE. INSN is a CODE_LABEL with
1668 LABEL_KIND != LABEL_NORMAL.
1670 The case fall-through in this function is intentional. */
1671 static void
1672 output_alternate_entry_point (FILE *file, rtx insn)
1674 const char *name = LABEL_NAME (insn);
1676 switch (LABEL_KIND (insn))
1678 case LABEL_WEAK_ENTRY:
1679 #ifdef ASM_WEAKEN_LABEL
1680 ASM_WEAKEN_LABEL (file, name);
1681 #endif
1682 case LABEL_GLOBAL_ENTRY:
1683 targetm.asm_out.globalize_label (file, name);
1684 case LABEL_STATIC_ENTRY:
1685 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
1686 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
1687 #endif
1688 ASM_OUTPUT_LABEL (file, name);
1689 break;
1691 case LABEL_NORMAL:
1692 default:
1693 gcc_unreachable ();
1697 /* The final scan for one insn, INSN.
1698 Args are same as in `final', except that INSN
1699 is the insn being scanned.
1700 Value returned is the next insn to be scanned.
1702 NOPEEPHOLES is the flag to disallow peephole processing (currently
1703 used for within delayed branch sequence output).
1705 SEEN is used to track the end of the prologue, for emitting
1706 debug information. We force the emission of a line note after
1707 both NOTE_INSN_PROLOGUE_END and NOTE_INSN_FUNCTION_BEG, or
1708 at the beginning of the second basic block, whichever comes
1709 first. */
1712 final_scan_insn (rtx insn, FILE *file, int optimize ATTRIBUTE_UNUSED,
1713 int nopeepholes ATTRIBUTE_UNUSED, int *seen)
1715 #ifdef HAVE_cc0
1716 rtx set;
1717 #endif
1718 rtx next;
1720 insn_counter++;
1722 /* Ignore deleted insns. These can occur when we split insns (due to a
1723 template of "#") while not optimizing. */
1724 if (INSN_DELETED_P (insn))
1725 return NEXT_INSN (insn);
1727 switch (GET_CODE (insn))
1729 case NOTE:
1730 switch (NOTE_KIND (insn))
1732 case NOTE_INSN_DELETED:
1733 break;
1735 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
1736 in_cold_section_p = !in_cold_section_p;
1737 (*debug_hooks->switch_text_section) ();
1738 switch_to_section (current_function_section ());
1739 break;
1741 case NOTE_INSN_BASIC_BLOCK:
1742 #ifdef TARGET_UNWIND_INFO
1743 targetm.asm_out.unwind_emit (asm_out_file, insn);
1744 #endif
1746 if (flag_debug_asm)
1747 fprintf (asm_out_file, "\t%s basic block %d\n",
1748 ASM_COMMENT_START, NOTE_BASIC_BLOCK (insn)->index);
1750 if ((*seen & (SEEN_EMITTED | SEEN_BB)) == SEEN_BB)
1752 *seen |= SEEN_EMITTED;
1753 force_source_line = true;
1755 else
1756 *seen |= SEEN_BB;
1758 break;
1760 case NOTE_INSN_EH_REGION_BEG:
1761 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHB",
1762 NOTE_EH_HANDLER (insn));
1763 break;
1765 case NOTE_INSN_EH_REGION_END:
1766 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHE",
1767 NOTE_EH_HANDLER (insn));
1768 break;
1770 case NOTE_INSN_PROLOGUE_END:
1771 targetm.asm_out.function_end_prologue (file);
1772 profile_after_prologue (file);
1774 if ((*seen & (SEEN_EMITTED | SEEN_NOTE)) == SEEN_NOTE)
1776 *seen |= SEEN_EMITTED;
1777 force_source_line = true;
1779 else
1780 *seen |= SEEN_NOTE;
1782 break;
1784 case NOTE_INSN_EPILOGUE_BEG:
1785 targetm.asm_out.function_begin_epilogue (file);
1786 break;
1788 case NOTE_INSN_FUNCTION_BEG:
1789 app_disable ();
1790 (*debug_hooks->end_prologue) (last_linenum, last_filename);
1792 if ((*seen & (SEEN_EMITTED | SEEN_NOTE)) == SEEN_NOTE)
1794 *seen |= SEEN_EMITTED;
1795 force_source_line = true;
1797 else
1798 *seen |= SEEN_NOTE;
1800 break;
1802 case NOTE_INSN_BLOCK_BEG:
1803 if (debug_info_level == DINFO_LEVEL_NORMAL
1804 || debug_info_level == DINFO_LEVEL_VERBOSE
1805 || write_symbols == DWARF2_DEBUG
1806 || write_symbols == VMS_AND_DWARF2_DEBUG
1807 || write_symbols == VMS_DEBUG)
1809 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
1811 app_disable ();
1812 ++block_depth;
1813 high_block_linenum = last_linenum;
1815 /* Output debugging info about the symbol-block beginning. */
1816 (*debug_hooks->begin_block) (last_linenum, n);
1818 /* Mark this block as output. */
1819 TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
1821 if (write_symbols == DBX_DEBUG
1822 || write_symbols == SDB_DEBUG)
1824 location_t *locus_ptr
1825 = block_nonartificial_location (NOTE_BLOCK (insn));
1827 if (locus_ptr != NULL)
1829 override_filename = LOCATION_FILE (*locus_ptr);
1830 override_linenum = LOCATION_LINE (*locus_ptr);
1833 break;
1835 case NOTE_INSN_BLOCK_END:
1836 if (debug_info_level == DINFO_LEVEL_NORMAL
1837 || debug_info_level == DINFO_LEVEL_VERBOSE
1838 || write_symbols == DWARF2_DEBUG
1839 || write_symbols == VMS_AND_DWARF2_DEBUG
1840 || write_symbols == VMS_DEBUG)
1842 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
1844 app_disable ();
1846 /* End of a symbol-block. */
1847 --block_depth;
1848 gcc_assert (block_depth >= 0);
1850 (*debug_hooks->end_block) (high_block_linenum, n);
1852 if (write_symbols == DBX_DEBUG
1853 || write_symbols == SDB_DEBUG)
1855 tree outer_block = BLOCK_SUPERCONTEXT (NOTE_BLOCK (insn));
1856 location_t *locus_ptr
1857 = block_nonartificial_location (outer_block);
1859 if (locus_ptr != NULL)
1861 override_filename = LOCATION_FILE (*locus_ptr);
1862 override_linenum = LOCATION_LINE (*locus_ptr);
1864 else
1866 override_filename = NULL;
1867 override_linenum = 0;
1870 break;
1872 case NOTE_INSN_DELETED_LABEL:
1873 /* Emit the label. We may have deleted the CODE_LABEL because
1874 the label could be proved to be unreachable, though still
1875 referenced (in the form of having its address taken. */
1876 ASM_OUTPUT_DEBUG_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1877 break;
1879 case NOTE_INSN_VAR_LOCATION:
1880 (*debug_hooks->var_location) (insn);
1881 break;
1883 default:
1884 gcc_unreachable ();
1885 break;
1887 break;
1889 case BARRIER:
1890 #if defined (DWARF2_UNWIND_INFO)
1891 if (dwarf2out_do_frame ())
1892 dwarf2out_frame_debug (insn, false);
1893 #endif
1894 break;
1896 case CODE_LABEL:
1897 /* The target port might emit labels in the output function for
1898 some insn, e.g. sh.c output_branchy_insn. */
1899 if (CODE_LABEL_NUMBER (insn) <= max_labelno)
1901 int align = LABEL_TO_ALIGNMENT (insn);
1902 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1903 int max_skip = LABEL_TO_MAX_SKIP (insn);
1904 #endif
1906 if (align && NEXT_INSN (insn))
1908 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1909 ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
1910 #else
1911 #ifdef ASM_OUTPUT_ALIGN_WITH_NOP
1912 ASM_OUTPUT_ALIGN_WITH_NOP (file, align);
1913 #else
1914 ASM_OUTPUT_ALIGN (file, align);
1915 #endif
1916 #endif
1919 #ifdef HAVE_cc0
1920 CC_STATUS_INIT;
1921 /* If this label is reached from only one place, set the condition
1922 codes from the instruction just before the branch. */
1924 /* Disabled because some insns set cc_status in the C output code
1925 and NOTICE_UPDATE_CC alone can set incorrect status. */
1926 if (0 /* optimize && LABEL_NUSES (insn) == 1*/)
1928 rtx jump = LABEL_REFS (insn);
1929 rtx barrier = prev_nonnote_insn (insn);
1930 rtx prev;
1931 /* If the LABEL_REFS field of this label has been set to point
1932 at a branch, the predecessor of the branch is a regular
1933 insn, and that branch is the only way to reach this label,
1934 set the condition codes based on the branch and its
1935 predecessor. */
1936 if (barrier && BARRIER_P (barrier)
1937 && jump && JUMP_P (jump)
1938 && (prev = prev_nonnote_insn (jump))
1939 && NONJUMP_INSN_P (prev))
1941 NOTICE_UPDATE_CC (PATTERN (prev), prev);
1942 NOTICE_UPDATE_CC (PATTERN (jump), jump);
1945 #endif
1947 if (LABEL_NAME (insn))
1948 (*debug_hooks->label) (insn);
1950 if (app_on)
1952 fputs (ASM_APP_OFF, file);
1953 app_on = 0;
1956 next = next_nonnote_insn (insn);
1957 if (next != 0 && JUMP_P (next))
1959 rtx nextbody = PATTERN (next);
1961 /* If this label is followed by a jump-table,
1962 make sure we put the label in the read-only section. Also
1963 possibly write the label and jump table together. */
1965 if (GET_CODE (nextbody) == ADDR_VEC
1966 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1968 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
1969 /* In this case, the case vector is being moved by the
1970 target, so don't output the label at all. Leave that
1971 to the back end macros. */
1972 #else
1973 if (! JUMP_TABLES_IN_TEXT_SECTION)
1975 int log_align;
1977 switch_to_section (targetm.asm_out.function_rodata_section
1978 (current_function_decl));
1980 #ifdef ADDR_VEC_ALIGN
1981 log_align = ADDR_VEC_ALIGN (next);
1982 #else
1983 log_align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
1984 #endif
1985 ASM_OUTPUT_ALIGN (file, log_align);
1987 else
1988 switch_to_section (current_function_section ());
1990 #ifdef ASM_OUTPUT_CASE_LABEL
1991 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
1992 next);
1993 #else
1994 targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (insn));
1995 #endif
1996 #endif
1997 break;
2000 if (LABEL_ALT_ENTRY_P (insn))
2001 output_alternate_entry_point (file, insn);
2002 else
2003 targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (insn));
2004 break;
2006 default:
2008 rtx body = PATTERN (insn);
2009 int insn_code_number;
2010 const char *template;
2012 #ifdef HAVE_conditional_execution
2013 /* Reset this early so it is correct for ASM statements. */
2014 current_insn_predicate = NULL_RTX;
2015 #endif
2016 /* An INSN, JUMP_INSN or CALL_INSN.
2017 First check for special kinds that recog doesn't recognize. */
2019 if (GET_CODE (body) == USE /* These are just declarations. */
2020 || GET_CODE (body) == CLOBBER)
2021 break;
2023 #ifdef HAVE_cc0
2025 /* If there is a REG_CC_SETTER note on this insn, it means that
2026 the setting of the condition code was done in the delay slot
2027 of the insn that branched here. So recover the cc status
2028 from the insn that set it. */
2030 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2031 if (note)
2033 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
2034 cc_prev_status = cc_status;
2037 #endif
2039 /* Detect insns that are really jump-tables
2040 and output them as such. */
2042 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
2044 #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
2045 int vlen, idx;
2046 #endif
2048 if (! JUMP_TABLES_IN_TEXT_SECTION)
2049 switch_to_section (targetm.asm_out.function_rodata_section
2050 (current_function_decl));
2051 else
2052 switch_to_section (current_function_section ());
2054 if (app_on)
2056 fputs (ASM_APP_OFF, file);
2057 app_on = 0;
2060 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2061 if (GET_CODE (body) == ADDR_VEC)
2063 #ifdef ASM_OUTPUT_ADDR_VEC
2064 ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
2065 #else
2066 gcc_unreachable ();
2067 #endif
2069 else
2071 #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
2072 ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
2073 #else
2074 gcc_unreachable ();
2075 #endif
2077 #else
2078 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2079 for (idx = 0; idx < vlen; idx++)
2081 if (GET_CODE (body) == ADDR_VEC)
2083 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2084 ASM_OUTPUT_ADDR_VEC_ELT
2085 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2086 #else
2087 gcc_unreachable ();
2088 #endif
2090 else
2092 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2093 ASM_OUTPUT_ADDR_DIFF_ELT
2094 (file,
2095 body,
2096 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2097 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2098 #else
2099 gcc_unreachable ();
2100 #endif
2103 #ifdef ASM_OUTPUT_CASE_END
2104 ASM_OUTPUT_CASE_END (file,
2105 CODE_LABEL_NUMBER (PREV_INSN (insn)),
2106 insn);
2107 #endif
2108 #endif
2110 switch_to_section (current_function_section ());
2112 break;
2114 /* Output this line note if it is the first or the last line
2115 note in a row. */
2116 if (notice_source_line (insn))
2118 (*debug_hooks->source_line) (last_linenum, last_filename);
2121 if (GET_CODE (body) == ASM_INPUT)
2123 const char *string = XSTR (body, 0);
2125 /* There's no telling what that did to the condition codes. */
2126 CC_STATUS_INIT;
2128 if (string[0])
2130 expanded_location loc;
2132 if (! app_on)
2134 fputs (ASM_APP_ON, file);
2135 app_on = 1;
2137 #ifdef USE_MAPPED_LOCATION
2138 loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body));
2139 #else
2140 loc.file = ASM_INPUT_SOURCE_FILE (body);
2141 loc.line = ASM_INPUT_SOURCE_LINE (body);
2142 #endif
2143 if (*loc.file && loc.line)
2144 fprintf (asm_out_file, "%s %i \"%s\" 1\n",
2145 ASM_COMMENT_START, loc.line, loc.file);
2146 fprintf (asm_out_file, "\t%s\n", string);
2147 #if HAVE_AS_LINE_ZERO
2148 if (*loc.file && loc.line)
2149 fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START);
2150 #endif
2152 break;
2155 /* Detect `asm' construct with operands. */
2156 if (asm_noperands (body) >= 0)
2158 unsigned int noperands = asm_noperands (body);
2159 rtx *ops = alloca (noperands * sizeof (rtx));
2160 const char *string;
2161 location_t loc;
2162 expanded_location expanded;
2164 /* There's no telling what that did to the condition codes. */
2165 CC_STATUS_INIT;
2167 /* Get out the operand values. */
2168 string = decode_asm_operands (body, ops, NULL, NULL, NULL, &loc);
2169 /* Inhibit dieing on what would otherwise be compiler bugs. */
2170 insn_noperands = noperands;
2171 this_is_asm_operands = insn;
2172 expanded = expand_location (loc);
2174 #ifdef FINAL_PRESCAN_INSN
2175 FINAL_PRESCAN_INSN (insn, ops, insn_noperands);
2176 #endif
2178 /* Output the insn using them. */
2179 if (string[0])
2181 if (! app_on)
2183 fputs (ASM_APP_ON, file);
2184 app_on = 1;
2186 if (expanded.file && expanded.line)
2187 fprintf (asm_out_file, "%s %i \"%s\" 1\n",
2188 ASM_COMMENT_START, expanded.line, expanded.file);
2189 output_asm_insn (string, ops);
2190 #if HAVE_AS_LINE_ZERO
2191 if (expanded.file && expanded.line)
2192 fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START);
2193 #endif
2196 this_is_asm_operands = 0;
2197 break;
2200 if (app_on)
2202 fputs (ASM_APP_OFF, file);
2203 app_on = 0;
2206 if (GET_CODE (body) == SEQUENCE)
2208 /* A delayed-branch sequence */
2209 int i;
2211 final_sequence = body;
2213 /* Record the delay slots' frame information before the branch.
2214 This is needed for delayed calls: see execute_cfa_program(). */
2215 #if defined (DWARF2_UNWIND_INFO)
2216 if (dwarf2out_do_frame ())
2217 for (i = 1; i < XVECLEN (body, 0); i++)
2218 dwarf2out_frame_debug (XVECEXP (body, 0, i), false);
2219 #endif
2221 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2222 force the restoration of a comparison that was previously
2223 thought unnecessary. If that happens, cancel this sequence
2224 and cause that insn to be restored. */
2226 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, 1, seen);
2227 if (next != XVECEXP (body, 0, 1))
2229 final_sequence = 0;
2230 return next;
2233 for (i = 1; i < XVECLEN (body, 0); i++)
2235 rtx insn = XVECEXP (body, 0, i);
2236 rtx next = NEXT_INSN (insn);
2237 /* We loop in case any instruction in a delay slot gets
2238 split. */
2240 insn = final_scan_insn (insn, file, 0, 1, seen);
2241 while (insn != next);
2243 #ifdef DBR_OUTPUT_SEQEND
2244 DBR_OUTPUT_SEQEND (file);
2245 #endif
2246 final_sequence = 0;
2248 /* If the insn requiring the delay slot was a CALL_INSN, the
2249 insns in the delay slot are actually executed before the
2250 called function. Hence we don't preserve any CC-setting
2251 actions in these insns and the CC must be marked as being
2252 clobbered by the function. */
2253 if (CALL_P (XVECEXP (body, 0, 0)))
2255 CC_STATUS_INIT;
2257 break;
2260 /* We have a real machine instruction as rtl. */
2262 body = PATTERN (insn);
2264 #ifdef HAVE_cc0
2265 set = single_set (insn);
2267 /* Check for redundant test and compare instructions
2268 (when the condition codes are already set up as desired).
2269 This is done only when optimizing; if not optimizing,
2270 it should be possible for the user to alter a variable
2271 with the debugger in between statements
2272 and the next statement should reexamine the variable
2273 to compute the condition codes. */
2275 if (optimize)
2277 if (set
2278 && GET_CODE (SET_DEST (set)) == CC0
2279 && insn != last_ignored_compare)
2281 if (GET_CODE (SET_SRC (set)) == SUBREG)
2282 SET_SRC (set) = alter_subreg (&SET_SRC (set));
2283 else if (GET_CODE (SET_SRC (set)) == COMPARE)
2285 if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
2286 XEXP (SET_SRC (set), 0)
2287 = alter_subreg (&XEXP (SET_SRC (set), 0));
2288 if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
2289 XEXP (SET_SRC (set), 1)
2290 = alter_subreg (&XEXP (SET_SRC (set), 1));
2292 if ((cc_status.value1 != 0
2293 && rtx_equal_p (SET_SRC (set), cc_status.value1))
2294 || (cc_status.value2 != 0
2295 && rtx_equal_p (SET_SRC (set), cc_status.value2)))
2297 /* Don't delete insn if it has an addressing side-effect. */
2298 if (! FIND_REG_INC_NOTE (insn, NULL_RTX)
2299 /* or if anything in it is volatile. */
2300 && ! volatile_refs_p (PATTERN (insn)))
2302 /* We don't really delete the insn; just ignore it. */
2303 last_ignored_compare = insn;
2304 break;
2309 #endif
2311 #ifdef HAVE_cc0
2312 /* If this is a conditional branch, maybe modify it
2313 if the cc's are in a nonstandard state
2314 so that it accomplishes the same thing that it would
2315 do straightforwardly if the cc's were set up normally. */
2317 if (cc_status.flags != 0
2318 && JUMP_P (insn)
2319 && GET_CODE (body) == SET
2320 && SET_DEST (body) == pc_rtx
2321 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2322 && COMPARISON_P (XEXP (SET_SRC (body), 0))
2323 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx)
2325 /* This function may alter the contents of its argument
2326 and clear some of the cc_status.flags bits.
2327 It may also return 1 meaning condition now always true
2328 or -1 meaning condition now always false
2329 or 2 meaning condition nontrivial but altered. */
2330 int result = alter_cond (XEXP (SET_SRC (body), 0));
2331 /* If condition now has fixed value, replace the IF_THEN_ELSE
2332 with its then-operand or its else-operand. */
2333 if (result == 1)
2334 SET_SRC (body) = XEXP (SET_SRC (body), 1);
2335 if (result == -1)
2336 SET_SRC (body) = XEXP (SET_SRC (body), 2);
2338 /* The jump is now either unconditional or a no-op.
2339 If it has become a no-op, don't try to output it.
2340 (It would not be recognized.) */
2341 if (SET_SRC (body) == pc_rtx)
2343 delete_insn (insn);
2344 break;
2346 else if (GET_CODE (SET_SRC (body)) == RETURN)
2347 /* Replace (set (pc) (return)) with (return). */
2348 PATTERN (insn) = body = SET_SRC (body);
2350 /* Rerecognize the instruction if it has changed. */
2351 if (result != 0)
2352 INSN_CODE (insn) = -1;
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)
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));
2372 /* If TRAP_CONDITION has become always false, delete the
2373 instruction. */
2374 if (result == -1)
2376 delete_insn (insn);
2377 break;
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;
2385 /* Rerecognize the instruction if it has changed. */
2386 if (result != 0)
2387 INSN_CODE (insn) = -1;
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). */
2394 if (cc_status.flags != 0
2395 && set != 0)
2397 rtx cond_rtx, then_rtx, else_rtx;
2399 if (!JUMP_P (insn)
2400 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2402 cond_rtx = XEXP (SET_SRC (set), 0);
2403 then_rtx = XEXP (SET_SRC (set), 1);
2404 else_rtx = XEXP (SET_SRC (set), 2);
2406 else
2408 cond_rtx = SET_SRC (set);
2409 then_rtx = const_true_rtx;
2410 else_rtx = const0_rtx;
2413 switch (GET_CODE (cond_rtx))
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:
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);
2439 break;
2441 default:
2442 break;
2446 #endif
2448 #ifdef HAVE_peephole
2449 /* Do machine-specific peephole optimizations if desired. */
2451 if (optimize && !flag_no_peephole && !nopeepholes)
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))
2458 rtx note, prev = PREV_INSN (insn);
2460 for (note = NEXT_INSN (insn); note != next;
2461 note = NEXT_INSN (note))
2462 final_scan_insn (note, file, optimize, nopeepholes, seen);
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;
2477 /* PEEPHOLE might have changed this. */
2478 body = PATTERN (insn);
2480 #endif
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. */
2487 insn_code_number = recog_memoized (insn);
2488 cleanup_subreg_operands (insn);
2490 /* Dump the insn in the assembly for debugging. */
2491 if (flag_dump_rtl_in_asm)
2493 print_rtx_head = ASM_COMMENT_START;
2494 print_rtl_single (asm_out_file, insn);
2495 print_rtx_head = "";
2498 if (! constrain_operands_cached (1))
2499 fatal_insn_not_found (insn);
2501 /* Some target machines need to prescan each insn before
2502 it is output. */
2504 #ifdef FINAL_PRESCAN_INSN
2505 FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2506 #endif
2508 #ifdef HAVE_conditional_execution
2509 if (GET_CODE (PATTERN (insn)) == COND_EXEC)
2510 current_insn_predicate = COND_EXEC_TEST (PATTERN (insn));
2511 #endif
2513 #ifdef HAVE_cc0
2514 cc_prev_status = cc_status;
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. */
2521 NOTICE_UPDATE_CC (body, insn);
2522 #endif
2524 current_output_insn = debug_insn = insn;
2526 #if defined (DWARF2_UNWIND_INFO)
2527 if (CALL_P (insn) && dwarf2out_do_frame ())
2528 dwarf2out_frame_debug (insn, false);
2529 #endif
2531 /* Find the proper template for this insn. */
2532 template = get_insn_template (insn_code_number, insn);
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)
2539 rtx prev;
2541 gcc_assert (prev_nonnote_insn (insn) == last_ignored_compare);
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))
2551 if (NOTE_P (prev))
2552 delete_insn (prev); /* Use delete_note. */
2555 return prev;
2558 /* If the template is the string "#", it means that this insn must
2559 be split. */
2560 if (template[0] == '#' && template[1] == '\0')
2562 rtx new = try_split (body, insn, 0);
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);
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
2575 return new;
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
2585 /* Output assembler code from the template. */
2586 output_asm_insn (template, recog_data.operand);
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
2600 current_output_insn = debug_insn = 0;
2603 return NEXT_INSN (insn);
2606 /* Return whether a source line note needs to be emitted before INSN. */
2608 static bool
2609 notice_source_line (rtx insn)
2611 const char *filename;
2612 int linenum;
2614 if (override_filename)
2616 filename = override_filename;
2617 linenum = override_linenum;
2619 else
2621 filename = insn_file (insn);
2622 linenum = insn_line (insn);
2625 if (filename
2626 && (force_source_line
2627 || filename != last_filename
2628 || last_linenum != linenum))
2630 force_source_line = false;
2631 last_filename = filename;
2632 last_linenum = linenum;
2633 high_block_linenum = MAX (last_linenum, high_block_linenum);
2634 high_function_linenum = MAX (last_linenum, high_function_linenum);
2635 return true;
2637 return false;
2640 /* For each operand in INSN, simplify (subreg (reg)) so that it refers
2641 directly to the desired hard register. */
2643 void
2644 cleanup_subreg_operands (rtx insn)
2646 int i;
2647 bool changed = false;
2648 extract_insn_cached (insn);
2649 for (i = 0; i < recog_data.n_operands; i++)
2651 /* The following test cannot use recog_data.operand when testing
2652 for a SUBREG: the underlying object might have been changed
2653 already if we are inside a match_operator expression that
2654 matches the else clause. Instead we test the underlying
2655 expression directly. */
2656 if (GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
2658 recog_data.operand[i] = alter_subreg (recog_data.operand_loc[i]);
2659 changed = true;
2661 else if (GET_CODE (recog_data.operand[i]) == PLUS
2662 || GET_CODE (recog_data.operand[i]) == MULT
2663 || MEM_P (recog_data.operand[i]))
2664 recog_data.operand[i] = walk_alter_subreg (recog_data.operand_loc[i], &changed);
2667 for (i = 0; i < recog_data.n_dups; i++)
2669 if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
2671 *recog_data.dup_loc[i] = alter_subreg (recog_data.dup_loc[i]);
2672 changed = true;
2674 else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
2675 || GET_CODE (*recog_data.dup_loc[i]) == MULT
2676 || MEM_P (*recog_data.dup_loc[i]))
2677 *recog_data.dup_loc[i] = walk_alter_subreg (recog_data.dup_loc[i], &changed);
2679 if (changed)
2680 df_insn_rescan (insn);
2683 /* If X is a SUBREG, replace it with a REG or a MEM,
2684 based on the thing it is a subreg of. */
2687 alter_subreg (rtx *xp)
2689 rtx x = *xp;
2690 rtx y = SUBREG_REG (x);
2692 /* simplify_subreg does not remove subreg from volatile references.
2693 We are required to. */
2694 if (MEM_P (y))
2696 int offset = SUBREG_BYTE (x);
2698 /* For paradoxical subregs on big-endian machines, SUBREG_BYTE
2699 contains 0 instead of the proper offset. See simplify_subreg. */
2700 if (offset == 0
2701 && GET_MODE_SIZE (GET_MODE (y)) < GET_MODE_SIZE (GET_MODE (x)))
2703 int difference = GET_MODE_SIZE (GET_MODE (y))
2704 - GET_MODE_SIZE (GET_MODE (x));
2705 if (WORDS_BIG_ENDIAN)
2706 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
2707 if (BYTES_BIG_ENDIAN)
2708 offset += difference % UNITS_PER_WORD;
2711 *xp = adjust_address (y, GET_MODE (x), offset);
2713 else
2715 rtx new = simplify_subreg (GET_MODE (x), y, GET_MODE (y),
2716 SUBREG_BYTE (x));
2718 if (new != 0)
2719 *xp = new;
2720 else if (REG_P (y))
2722 /* Simplify_subreg can't handle some REG cases, but we have to. */
2723 unsigned int regno = subreg_regno (x);
2724 *xp = gen_rtx_REG_offset (y, GET_MODE (x), regno, SUBREG_BYTE (x));
2728 return *xp;
2731 /* Do alter_subreg on all the SUBREGs contained in X. */
2733 static rtx
2734 walk_alter_subreg (rtx *xp, bool *changed)
2736 rtx x = *xp;
2737 switch (GET_CODE (x))
2739 case PLUS:
2740 case MULT:
2741 case AND:
2742 XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0), changed);
2743 XEXP (x, 1) = walk_alter_subreg (&XEXP (x, 1), changed);
2744 break;
2746 case MEM:
2747 case ZERO_EXTEND:
2748 XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0), changed);
2749 break;
2751 case SUBREG:
2752 *changed = true;
2753 return alter_subreg (xp);
2755 default:
2756 break;
2759 return *xp;
2762 #ifdef HAVE_cc0
2764 /* Given BODY, the body of a jump instruction, alter the jump condition
2765 as required by the bits that are set in cc_status.flags.
2766 Not all of the bits there can be handled at this level in all cases.
2768 The value is normally 0.
2769 1 means that the condition has become always true.
2770 -1 means that the condition has become always false.
2771 2 means that COND has been altered. */
2773 static int
2774 alter_cond (rtx cond)
2776 int value = 0;
2778 if (cc_status.flags & CC_REVERSED)
2780 value = 2;
2781 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
2784 if (cc_status.flags & CC_INVERTED)
2786 value = 2;
2787 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
2790 if (cc_status.flags & CC_NOT_POSITIVE)
2791 switch (GET_CODE (cond))
2793 case LE:
2794 case LEU:
2795 case GEU:
2796 /* Jump becomes unconditional. */
2797 return 1;
2799 case GT:
2800 case GTU:
2801 case LTU:
2802 /* Jump becomes no-op. */
2803 return -1;
2805 case GE:
2806 PUT_CODE (cond, EQ);
2807 value = 2;
2808 break;
2810 case LT:
2811 PUT_CODE (cond, NE);
2812 value = 2;
2813 break;
2815 default:
2816 break;
2819 if (cc_status.flags & CC_NOT_NEGATIVE)
2820 switch (GET_CODE (cond))
2822 case GE:
2823 case GEU:
2824 /* Jump becomes unconditional. */
2825 return 1;
2827 case LT:
2828 case LTU:
2829 /* Jump becomes no-op. */
2830 return -1;
2832 case LE:
2833 case LEU:
2834 PUT_CODE (cond, EQ);
2835 value = 2;
2836 break;
2838 case GT:
2839 case GTU:
2840 PUT_CODE (cond, NE);
2841 value = 2;
2842 break;
2844 default:
2845 break;
2848 if (cc_status.flags & CC_NO_OVERFLOW)
2849 switch (GET_CODE (cond))
2851 case GEU:
2852 /* Jump becomes unconditional. */
2853 return 1;
2855 case LEU:
2856 PUT_CODE (cond, EQ);
2857 value = 2;
2858 break;
2860 case GTU:
2861 PUT_CODE (cond, NE);
2862 value = 2;
2863 break;
2865 case LTU:
2866 /* Jump becomes no-op. */
2867 return -1;
2869 default:
2870 break;
2873 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
2874 switch (GET_CODE (cond))
2876 default:
2877 gcc_unreachable ();
2879 case NE:
2880 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
2881 value = 2;
2882 break;
2884 case EQ:
2885 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
2886 value = 2;
2887 break;
2890 if (cc_status.flags & CC_NOT_SIGNED)
2891 /* The flags are valid if signed condition operators are converted
2892 to unsigned. */
2893 switch (GET_CODE (cond))
2895 case LE:
2896 PUT_CODE (cond, LEU);
2897 value = 2;
2898 break;
2900 case LT:
2901 PUT_CODE (cond, LTU);
2902 value = 2;
2903 break;
2905 case GT:
2906 PUT_CODE (cond, GTU);
2907 value = 2;
2908 break;
2910 case GE:
2911 PUT_CODE (cond, GEU);
2912 value = 2;
2913 break;
2915 default:
2916 break;
2919 return value;
2921 #endif
2923 /* Report inconsistency between the assembler template and the operands.
2924 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
2926 void
2927 output_operand_lossage (const char *cmsgid, ...)
2929 char *fmt_string;
2930 char *new_message;
2931 const char *pfx_str;
2932 va_list ap;
2934 va_start (ap, cmsgid);
2936 pfx_str = this_is_asm_operands ? _("invalid 'asm': ") : "output_operand: ";
2937 asprintf (&fmt_string, "%s%s", pfx_str, _(cmsgid));
2938 vasprintf (&new_message, fmt_string, ap);
2940 if (this_is_asm_operands)
2941 error_for_asm (this_is_asm_operands, "%s", new_message);
2942 else
2943 internal_error ("%s", new_message);
2945 free (fmt_string);
2946 free (new_message);
2947 va_end (ap);
2950 /* Output of assembler code from a template, and its subroutines. */
2952 /* Annotate the assembly with a comment describing the pattern and
2953 alternative used. */
2955 static void
2956 output_asm_name (void)
2958 if (debug_insn)
2960 int num = INSN_CODE (debug_insn);
2961 fprintf (asm_out_file, "\t%s %d\t%s",
2962 ASM_COMMENT_START, INSN_UID (debug_insn),
2963 insn_data[num].name);
2964 if (insn_data[num].n_alternatives > 1)
2965 fprintf (asm_out_file, "/%d", which_alternative + 1);
2966 #ifdef HAVE_ATTR_length
2967 fprintf (asm_out_file, "\t[length = %d]",
2968 get_attr_length (debug_insn));
2969 #endif
2970 /* Clear this so only the first assembler insn
2971 of any rtl insn will get the special comment for -dp. */
2972 debug_insn = 0;
2976 /* If OP is a REG or MEM and we can find a MEM_EXPR corresponding to it
2977 or its address, return that expr . Set *PADDRESSP to 1 if the expr
2978 corresponds to the address of the object and 0 if to the object. */
2980 static tree
2981 get_mem_expr_from_op (rtx op, int *paddressp)
2983 tree expr;
2984 int inner_addressp;
2986 *paddressp = 0;
2988 if (REG_P (op))
2989 return REG_EXPR (op);
2990 else if (!MEM_P (op))
2991 return 0;
2993 if (MEM_EXPR (op) != 0)
2994 return MEM_EXPR (op);
2996 /* Otherwise we have an address, so indicate it and look at the address. */
2997 *paddressp = 1;
2998 op = XEXP (op, 0);
3000 /* First check if we have a decl for the address, then look at the right side
3001 if it is a PLUS. Otherwise, strip off arithmetic and keep looking.
3002 But don't allow the address to itself be indirect. */
3003 if ((expr = get_mem_expr_from_op (op, &inner_addressp)) && ! inner_addressp)
3004 return expr;
3005 else if (GET_CODE (op) == PLUS
3006 && (expr = get_mem_expr_from_op (XEXP (op, 1), &inner_addressp)))
3007 return expr;
3009 while (GET_RTX_CLASS (GET_CODE (op)) == RTX_UNARY
3010 || GET_RTX_CLASS (GET_CODE (op)) == RTX_BIN_ARITH)
3011 op = XEXP (op, 0);
3013 expr = get_mem_expr_from_op (op, &inner_addressp);
3014 return inner_addressp ? 0 : expr;
3017 /* Output operand names for assembler instructions. OPERANDS is the
3018 operand vector, OPORDER is the order to write the operands, and NOPS
3019 is the number of operands to write. */
3021 static void
3022 output_asm_operand_names (rtx *operands, int *oporder, int nops)
3024 int wrote = 0;
3025 int i;
3027 for (i = 0; i < nops; i++)
3029 int addressp;
3030 rtx op = operands[oporder[i]];
3031 tree expr = get_mem_expr_from_op (op, &addressp);
3033 fprintf (asm_out_file, "%c%s",
3034 wrote ? ',' : '\t', wrote ? "" : ASM_COMMENT_START);
3035 wrote = 1;
3036 if (expr)
3038 fprintf (asm_out_file, "%s",
3039 addressp ? "*" : "");
3040 print_mem_expr (asm_out_file, expr);
3041 wrote = 1;
3043 else if (REG_P (op) && ORIGINAL_REGNO (op)
3044 && ORIGINAL_REGNO (op) != REGNO (op))
3045 fprintf (asm_out_file, " tmp%i", ORIGINAL_REGNO (op));
3049 /* Output text from TEMPLATE to the assembler output file,
3050 obeying %-directions to substitute operands taken from
3051 the vector OPERANDS.
3053 %N (for N a digit) means print operand N in usual manner.
3054 %lN means require operand N to be a CODE_LABEL or LABEL_REF
3055 and print the label name with no punctuation.
3056 %cN means require operand N to be a constant
3057 and print the constant expression with no punctuation.
3058 %aN means expect operand N to be a memory address
3059 (not a memory reference!) and print a reference
3060 to that address.
3061 %nN means expect operand N to be a constant
3062 and print a constant expression for minus the value
3063 of the operand, with no other punctuation. */
3065 void
3066 output_asm_insn (const char *template, rtx *operands)
3068 const char *p;
3069 int c;
3070 #ifdef ASSEMBLER_DIALECT
3071 int dialect = 0;
3072 #endif
3073 int oporder[MAX_RECOG_OPERANDS];
3074 char opoutput[MAX_RECOG_OPERANDS];
3075 int ops = 0;
3077 /* An insn may return a null string template
3078 in a case where no assembler code is needed. */
3079 if (*template == 0)
3080 return;
3082 memset (opoutput, 0, sizeof opoutput);
3083 p = template;
3084 putc ('\t', asm_out_file);
3086 #ifdef ASM_OUTPUT_OPCODE
3087 ASM_OUTPUT_OPCODE (asm_out_file, p);
3088 #endif
3090 while ((c = *p++))
3091 switch (c)
3093 case '\n':
3094 if (flag_verbose_asm)
3095 output_asm_operand_names (operands, oporder, ops);
3096 if (flag_print_asm_name)
3097 output_asm_name ();
3099 ops = 0;
3100 memset (opoutput, 0, sizeof opoutput);
3102 putc (c, asm_out_file);
3103 #ifdef ASM_OUTPUT_OPCODE
3104 while ((c = *p) == '\t')
3106 putc (c, asm_out_file);
3107 p++;
3109 ASM_OUTPUT_OPCODE (asm_out_file, p);
3110 #endif
3111 break;
3113 #ifdef ASSEMBLER_DIALECT
3114 case '{':
3116 int i;
3118 if (dialect)
3119 output_operand_lossage ("nested assembly dialect alternatives");
3120 else
3121 dialect = 1;
3123 /* If we want the first dialect, do nothing. Otherwise, skip
3124 DIALECT_NUMBER of strings ending with '|'. */
3125 for (i = 0; i < dialect_number; i++)
3127 while (*p && *p != '}' && *p++ != '|')
3129 if (*p == '}')
3130 break;
3131 if (*p == '|')
3132 p++;
3135 if (*p == '\0')
3136 output_operand_lossage ("unterminated assembly dialect alternative");
3138 break;
3140 case '|':
3141 if (dialect)
3143 /* Skip to close brace. */
3146 if (*p == '\0')
3148 output_operand_lossage ("unterminated assembly dialect alternative");
3149 break;
3152 while (*p++ != '}');
3153 dialect = 0;
3155 else
3156 putc (c, asm_out_file);
3157 break;
3159 case '}':
3160 if (! dialect)
3161 putc (c, asm_out_file);
3162 dialect = 0;
3163 break;
3164 #endif
3166 case '%':
3167 /* %% outputs a single %. */
3168 if (*p == '%')
3170 p++;
3171 putc (c, asm_out_file);
3173 /* %= outputs a number which is unique to each insn in the entire
3174 compilation. This is useful for making local labels that are
3175 referred to more than once in a given insn. */
3176 else if (*p == '=')
3178 p++;
3179 fprintf (asm_out_file, "%d", insn_counter);
3181 /* % followed by a letter and some digits
3182 outputs an operand in a special way depending on the letter.
3183 Letters `acln' are implemented directly.
3184 Other letters are passed to `output_operand' so that
3185 the PRINT_OPERAND macro can define them. */
3186 else if (ISALPHA (*p))
3188 int letter = *p++;
3189 unsigned long opnum;
3190 char *endptr;
3192 opnum = strtoul (p, &endptr, 10);
3194 if (endptr == p)
3195 output_operand_lossage ("operand number missing "
3196 "after %%-letter");
3197 else if (this_is_asm_operands && opnum >= insn_noperands)
3198 output_operand_lossage ("operand number out of range");
3199 else if (letter == 'l')
3200 output_asm_label (operands[opnum]);
3201 else if (letter == 'a')
3202 output_address (operands[opnum]);
3203 else if (letter == 'c')
3205 if (CONSTANT_ADDRESS_P (operands[opnum]))
3206 output_addr_const (asm_out_file, operands[opnum]);
3207 else
3208 output_operand (operands[opnum], 'c');
3210 else if (letter == 'n')
3212 if (GET_CODE (operands[opnum]) == CONST_INT)
3213 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3214 - INTVAL (operands[opnum]));
3215 else
3217 putc ('-', asm_out_file);
3218 output_addr_const (asm_out_file, operands[opnum]);
3221 else
3222 output_operand (operands[opnum], letter);
3224 if (!opoutput[opnum])
3225 oporder[ops++] = opnum;
3226 opoutput[opnum] = 1;
3228 p = endptr;
3229 c = *p;
3231 /* % followed by a digit outputs an operand the default way. */
3232 else if (ISDIGIT (*p))
3234 unsigned long opnum;
3235 char *endptr;
3237 opnum = strtoul (p, &endptr, 10);
3238 if (this_is_asm_operands && opnum >= insn_noperands)
3239 output_operand_lossage ("operand number out of range");
3240 else
3241 output_operand (operands[opnum], 0);
3243 if (!opoutput[opnum])
3244 oporder[ops++] = opnum;
3245 opoutput[opnum] = 1;
3247 p = endptr;
3248 c = *p;
3250 /* % followed by punctuation: output something for that
3251 punctuation character alone, with no operand.
3252 The PRINT_OPERAND macro decides what is actually done. */
3253 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3254 else if (PRINT_OPERAND_PUNCT_VALID_P ((unsigned char) *p))
3255 output_operand (NULL_RTX, *p++);
3256 #endif
3257 else
3258 output_operand_lossage ("invalid %%-code");
3259 break;
3261 default:
3262 putc (c, asm_out_file);
3265 /* Write out the variable names for operands, if we know them. */
3266 if (flag_verbose_asm)
3267 output_asm_operand_names (operands, oporder, ops);
3268 if (flag_print_asm_name)
3269 output_asm_name ();
3271 putc ('\n', asm_out_file);
3274 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3276 void
3277 output_asm_label (rtx x)
3279 char buf[256];
3281 if (GET_CODE (x) == LABEL_REF)
3282 x = XEXP (x, 0);
3283 if (LABEL_P (x)
3284 || (NOTE_P (x)
3285 && NOTE_KIND (x) == NOTE_INSN_DELETED_LABEL))
3286 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3287 else
3288 output_operand_lossage ("'%%l' operand isn't a label");
3290 assemble_name (asm_out_file, buf);
3293 /* Print operand X using machine-dependent assembler syntax.
3294 The macro PRINT_OPERAND is defined just to control this function.
3295 CODE is a non-digit that preceded the operand-number in the % spec,
3296 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3297 between the % and the digits.
3298 When CODE is a non-letter, X is 0.
3300 The meanings of the letters are machine-dependent and controlled
3301 by PRINT_OPERAND. */
3303 static void
3304 output_operand (rtx x, int code ATTRIBUTE_UNUSED)
3306 if (x && GET_CODE (x) == SUBREG)
3307 x = alter_subreg (&x);
3309 /* X must not be a pseudo reg. */
3310 gcc_assert (!x || !REG_P (x) || REGNO (x) < FIRST_PSEUDO_REGISTER);
3312 PRINT_OPERAND (asm_out_file, x, code);
3315 /* Print a memory reference operand for address X
3316 using machine-dependent assembler syntax.
3317 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
3319 void
3320 output_address (rtx x)
3322 bool changed = false;
3323 walk_alter_subreg (&x, &changed);
3324 PRINT_OPERAND_ADDRESS (asm_out_file, x);
3327 /* Print an integer constant expression in assembler syntax.
3328 Addition and subtraction are the only arithmetic
3329 that may appear in these expressions. */
3331 void
3332 output_addr_const (FILE *file, rtx x)
3334 char buf[256];
3336 restart:
3337 switch (GET_CODE (x))
3339 case PC:
3340 putc ('.', file);
3341 break;
3343 case SYMBOL_REF:
3344 if (SYMBOL_REF_DECL (x))
3345 mark_decl_referenced (SYMBOL_REF_DECL (x));
3346 #ifdef ASM_OUTPUT_SYMBOL_REF
3347 ASM_OUTPUT_SYMBOL_REF (file, x);
3348 #else
3349 assemble_name (file, XSTR (x, 0));
3350 #endif
3351 break;
3353 case LABEL_REF:
3354 x = XEXP (x, 0);
3355 /* Fall through. */
3356 case CODE_LABEL:
3357 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3358 #ifdef ASM_OUTPUT_LABEL_REF
3359 ASM_OUTPUT_LABEL_REF (file, buf);
3360 #else
3361 assemble_name (file, buf);
3362 #endif
3363 break;
3365 case CONST_INT:
3366 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3367 break;
3369 case CONST:
3370 /* This used to output parentheses around the expression,
3371 but that does not work on the 386 (either ATT or BSD assembler). */
3372 output_addr_const (file, XEXP (x, 0));
3373 break;
3375 case CONST_DOUBLE:
3376 if (GET_MODE (x) == VOIDmode)
3378 /* We can use %d if the number is one word and positive. */
3379 if (CONST_DOUBLE_HIGH (x))
3380 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3381 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3382 else if (CONST_DOUBLE_LOW (x) < 0)
3383 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3384 else
3385 fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3387 else
3388 /* We can't handle floating point constants;
3389 PRINT_OPERAND must handle them. */
3390 output_operand_lossage ("floating constant misused");
3391 break;
3393 case CONST_FIXED:
3394 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_FIXED_VALUE_LOW (x));
3395 break;
3397 case PLUS:
3398 /* Some assemblers need integer constants to appear last (eg masm). */
3399 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3401 output_addr_const (file, XEXP (x, 1));
3402 if (INTVAL (XEXP (x, 0)) >= 0)
3403 fprintf (file, "+");
3404 output_addr_const (file, XEXP (x, 0));
3406 else
3408 output_addr_const (file, XEXP (x, 0));
3409 if (GET_CODE (XEXP (x, 1)) != CONST_INT
3410 || INTVAL (XEXP (x, 1)) >= 0)
3411 fprintf (file, "+");
3412 output_addr_const (file, XEXP (x, 1));
3414 break;
3416 case MINUS:
3417 /* Avoid outputting things like x-x or x+5-x,
3418 since some assemblers can't handle that. */
3419 x = simplify_subtraction (x);
3420 if (GET_CODE (x) != MINUS)
3421 goto restart;
3423 output_addr_const (file, XEXP (x, 0));
3424 fprintf (file, "-");
3425 if ((GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) >= 0)
3426 || GET_CODE (XEXP (x, 1)) == PC
3427 || GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
3428 output_addr_const (file, XEXP (x, 1));
3429 else
3431 fputs (targetm.asm_out.open_paren, file);
3432 output_addr_const (file, XEXP (x, 1));
3433 fputs (targetm.asm_out.close_paren, file);
3435 break;
3437 case ZERO_EXTEND:
3438 case SIGN_EXTEND:
3439 case SUBREG:
3440 output_addr_const (file, XEXP (x, 0));
3441 break;
3443 default:
3444 #ifdef OUTPUT_ADDR_CONST_EXTRA
3445 OUTPUT_ADDR_CONST_EXTRA (file, x, fail);
3446 break;
3448 fail:
3449 #endif
3450 output_operand_lossage ("invalid expression as operand");
3454 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3455 %R prints the value of REGISTER_PREFIX.
3456 %L prints the value of LOCAL_LABEL_PREFIX.
3457 %U prints the value of USER_LABEL_PREFIX.
3458 %I prints the value of IMMEDIATE_PREFIX.
3459 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3460 Also supported are %d, %i, %u, %x, %X, %o, %c, %s and %%.
3462 We handle alternate assembler dialects here, just like output_asm_insn. */
3464 void
3465 asm_fprintf (FILE *file, const char *p, ...)
3467 char buf[10];
3468 char *q, c;
3469 va_list argptr;
3471 va_start (argptr, p);
3473 buf[0] = '%';
3475 while ((c = *p++))
3476 switch (c)
3478 #ifdef ASSEMBLER_DIALECT
3479 case '{':
3481 int i;
3483 /* If we want the first dialect, do nothing. Otherwise, skip
3484 DIALECT_NUMBER of strings ending with '|'. */
3485 for (i = 0; i < dialect_number; i++)
3487 while (*p && *p++ != '|')
3490 if (*p == '|')
3491 p++;
3494 break;
3496 case '|':
3497 /* Skip to close brace. */
3498 while (*p && *p++ != '}')
3500 break;
3502 case '}':
3503 break;
3504 #endif
3506 case '%':
3507 c = *p++;
3508 q = &buf[1];
3509 while (strchr ("-+ #0", c))
3511 *q++ = c;
3512 c = *p++;
3514 while (ISDIGIT (c) || c == '.')
3516 *q++ = c;
3517 c = *p++;
3519 switch (c)
3521 case '%':
3522 putc ('%', file);
3523 break;
3525 case 'd': case 'i': case 'u':
3526 case 'x': case 'X': case 'o':
3527 case 'c':
3528 *q++ = c;
3529 *q = 0;
3530 fprintf (file, buf, va_arg (argptr, int));
3531 break;
3533 case 'w':
3534 /* This is a prefix to the 'd', 'i', 'u', 'x', 'X', and
3535 'o' cases, but we do not check for those cases. It
3536 means that the value is a HOST_WIDE_INT, which may be
3537 either `long' or `long long'. */
3538 memcpy (q, HOST_WIDE_INT_PRINT, strlen (HOST_WIDE_INT_PRINT));
3539 q += strlen (HOST_WIDE_INT_PRINT);
3540 *q++ = *p++;
3541 *q = 0;
3542 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3543 break;
3545 case 'l':
3546 *q++ = c;
3547 #ifdef HAVE_LONG_LONG
3548 if (*p == 'l')
3550 *q++ = *p++;
3551 *q++ = *p++;
3552 *q = 0;
3553 fprintf (file, buf, va_arg (argptr, long long));
3555 else
3556 #endif
3558 *q++ = *p++;
3559 *q = 0;
3560 fprintf (file, buf, va_arg (argptr, long));
3563 break;
3565 case 's':
3566 *q++ = c;
3567 *q = 0;
3568 fprintf (file, buf, va_arg (argptr, char *));
3569 break;
3571 case 'O':
3572 #ifdef ASM_OUTPUT_OPCODE
3573 ASM_OUTPUT_OPCODE (asm_out_file, p);
3574 #endif
3575 break;
3577 case 'R':
3578 #ifdef REGISTER_PREFIX
3579 fprintf (file, "%s", REGISTER_PREFIX);
3580 #endif
3581 break;
3583 case 'I':
3584 #ifdef IMMEDIATE_PREFIX
3585 fprintf (file, "%s", IMMEDIATE_PREFIX);
3586 #endif
3587 break;
3589 case 'L':
3590 #ifdef LOCAL_LABEL_PREFIX
3591 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3592 #endif
3593 break;
3595 case 'U':
3596 fputs (user_label_prefix, file);
3597 break;
3599 #ifdef ASM_FPRINTF_EXTENSIONS
3600 /* Uppercase letters are reserved for general use by asm_fprintf
3601 and so are not available to target specific code. In order to
3602 prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
3603 they are defined here. As they get turned into real extensions
3604 to asm_fprintf they should be removed from this list. */
3605 case 'A': case 'B': case 'C': case 'D': case 'E':
3606 case 'F': case 'G': case 'H': case 'J': case 'K':
3607 case 'M': case 'N': case 'P': case 'Q': case 'S':
3608 case 'T': case 'V': case 'W': case 'Y': case 'Z':
3609 break;
3611 ASM_FPRINTF_EXTENSIONS (file, argptr, p)
3612 #endif
3613 default:
3614 gcc_unreachable ();
3616 break;
3618 default:
3619 putc (c, file);
3621 va_end (argptr);
3624 /* Split up a CONST_DOUBLE or integer constant rtx
3625 into two rtx's for single words,
3626 storing in *FIRST the word that comes first in memory in the target
3627 and in *SECOND the other. */
3629 void
3630 split_double (rtx value, rtx *first, rtx *second)
3632 if (GET_CODE (value) == CONST_INT)
3634 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3636 /* In this case the CONST_INT holds both target words.
3637 Extract the bits from it into two word-sized pieces.
3638 Sign extend each half to HOST_WIDE_INT. */
3639 unsigned HOST_WIDE_INT low, high;
3640 unsigned HOST_WIDE_INT mask, sign_bit, sign_extend;
3642 /* Set sign_bit to the most significant bit of a word. */
3643 sign_bit = 1;
3644 sign_bit <<= BITS_PER_WORD - 1;
3646 /* Set mask so that all bits of the word are set. We could
3647 have used 1 << BITS_PER_WORD instead of basing the
3648 calculation on sign_bit. However, on machines where
3649 HOST_BITS_PER_WIDE_INT == BITS_PER_WORD, it could cause a
3650 compiler warning, even though the code would never be
3651 executed. */
3652 mask = sign_bit << 1;
3653 mask--;
3655 /* Set sign_extend as any remaining bits. */
3656 sign_extend = ~mask;
3658 /* Pick the lower word and sign-extend it. */
3659 low = INTVAL (value);
3660 low &= mask;
3661 if (low & sign_bit)
3662 low |= sign_extend;
3664 /* Pick the higher word, shifted to the least significant
3665 bits, and sign-extend it. */
3666 high = INTVAL (value);
3667 high >>= BITS_PER_WORD - 1;
3668 high >>= 1;
3669 high &= mask;
3670 if (high & sign_bit)
3671 high |= sign_extend;
3673 /* Store the words in the target machine order. */
3674 if (WORDS_BIG_ENDIAN)
3676 *first = GEN_INT (high);
3677 *second = GEN_INT (low);
3679 else
3681 *first = GEN_INT (low);
3682 *second = GEN_INT (high);
3685 else
3687 /* The rule for using CONST_INT for a wider mode
3688 is that we regard the value as signed.
3689 So sign-extend it. */
3690 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3691 if (WORDS_BIG_ENDIAN)
3693 *first = high;
3694 *second = value;
3696 else
3698 *first = value;
3699 *second = high;
3703 else if (GET_CODE (value) != CONST_DOUBLE)
3705 if (WORDS_BIG_ENDIAN)
3707 *first = const0_rtx;
3708 *second = value;
3710 else
3712 *first = value;
3713 *second = const0_rtx;
3716 else if (GET_MODE (value) == VOIDmode
3717 /* This is the old way we did CONST_DOUBLE integers. */
3718 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3720 /* In an integer, the words are defined as most and least significant.
3721 So order them by the target's convention. */
3722 if (WORDS_BIG_ENDIAN)
3724 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3725 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3727 else
3729 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3730 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3733 else
3735 REAL_VALUE_TYPE r;
3736 long l[2];
3737 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3739 /* Note, this converts the REAL_VALUE_TYPE to the target's
3740 format, splits up the floating point double and outputs
3741 exactly 32 bits of it into each of l[0] and l[1] --
3742 not necessarily BITS_PER_WORD bits. */
3743 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3745 /* If 32 bits is an entire word for the target, but not for the host,
3746 then sign-extend on the host so that the number will look the same
3747 way on the host that it would on the target. See for instance
3748 simplify_unary_operation. The #if is needed to avoid compiler
3749 warnings. */
3751 #if HOST_BITS_PER_LONG > 32
3752 if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
3754 if (l[0] & ((long) 1 << 31))
3755 l[0] |= ((long) (-1) << 32);
3756 if (l[1] & ((long) 1 << 31))
3757 l[1] |= ((long) (-1) << 32);
3759 #endif
3761 *first = GEN_INT (l[0]);
3762 *second = GEN_INT (l[1]);
3766 /* Return nonzero if this function has no function calls. */
3769 leaf_function_p (void)
3771 rtx insn;
3772 rtx link;
3774 if (current_function_profile || profile_arc_flag)
3775 return 0;
3777 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3779 if (CALL_P (insn)
3780 && ! SIBLING_CALL_P (insn))
3781 return 0;
3782 if (NONJUMP_INSN_P (insn)
3783 && GET_CODE (PATTERN (insn)) == SEQUENCE
3784 && CALL_P (XVECEXP (PATTERN (insn), 0, 0))
3785 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
3786 return 0;
3788 for (link = current_function_epilogue_delay_list;
3789 link;
3790 link = XEXP (link, 1))
3792 insn = XEXP (link, 0);
3794 if (CALL_P (insn)
3795 && ! SIBLING_CALL_P (insn))
3796 return 0;
3797 if (NONJUMP_INSN_P (insn)
3798 && GET_CODE (PATTERN (insn)) == SEQUENCE
3799 && CALL_P (XVECEXP (PATTERN (insn), 0, 0))
3800 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
3801 return 0;
3804 return 1;
3807 /* Return 1 if branch is a forward branch.
3808 Uses insn_shuid array, so it works only in the final pass. May be used by
3809 output templates to customary add branch prediction hints.
3812 final_forward_branch_p (rtx insn)
3814 int insn_id, label_id;
3816 gcc_assert (uid_shuid);
3817 insn_id = INSN_SHUID (insn);
3818 label_id = INSN_SHUID (JUMP_LABEL (insn));
3819 /* We've hit some insns that does not have id information available. */
3820 gcc_assert (insn_id && label_id);
3821 return insn_id < label_id;
3824 /* On some machines, a function with no call insns
3825 can run faster if it doesn't create its own register window.
3826 When output, the leaf function should use only the "output"
3827 registers. Ordinarily, the function would be compiled to use
3828 the "input" registers to find its arguments; it is a candidate
3829 for leaf treatment if it uses only the "input" registers.
3830 Leaf function treatment means renumbering so the function
3831 uses the "output" registers instead. */
3833 #ifdef LEAF_REGISTERS
3835 /* Return 1 if this function uses only the registers that can be
3836 safely renumbered. */
3839 only_leaf_regs_used (void)
3841 int i;
3842 const char *const permitted_reg_in_leaf_functions = LEAF_REGISTERS;
3844 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3845 if ((df_regs_ever_live_p (i) || global_regs[i])
3846 && ! permitted_reg_in_leaf_functions[i])
3847 return 0;
3849 if (current_function_uses_pic_offset_table
3850 && pic_offset_table_rtx != 0
3851 && REG_P (pic_offset_table_rtx)
3852 && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
3853 return 0;
3855 return 1;
3858 /* Scan all instructions and renumber all registers into those
3859 available in leaf functions. */
3861 static void
3862 leaf_renumber_regs (rtx first)
3864 rtx insn;
3866 /* Renumber only the actual patterns.
3867 The reg-notes can contain frame pointer refs,
3868 and renumbering them could crash, and should not be needed. */
3869 for (insn = first; insn; insn = NEXT_INSN (insn))
3870 if (INSN_P (insn))
3871 leaf_renumber_regs_insn (PATTERN (insn));
3872 for (insn = current_function_epilogue_delay_list;
3873 insn;
3874 insn = XEXP (insn, 1))
3875 if (INSN_P (XEXP (insn, 0)))
3876 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
3879 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
3880 available in leaf functions. */
3882 void
3883 leaf_renumber_regs_insn (rtx in_rtx)
3885 int i, j;
3886 const char *format_ptr;
3888 if (in_rtx == 0)
3889 return;
3891 /* Renumber all input-registers into output-registers.
3892 renumbered_regs would be 1 for an output-register;
3893 they */
3895 if (REG_P (in_rtx))
3897 int newreg;
3899 /* Don't renumber the same reg twice. */
3900 if (in_rtx->used)
3901 return;
3903 newreg = REGNO (in_rtx);
3904 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
3905 to reach here as part of a REG_NOTE. */
3906 if (newreg >= FIRST_PSEUDO_REGISTER)
3908 in_rtx->used = 1;
3909 return;
3911 newreg = LEAF_REG_REMAP (newreg);
3912 gcc_assert (newreg >= 0);
3913 df_set_regs_ever_live (REGNO (in_rtx), false);
3914 df_set_regs_ever_live (newreg, true);
3915 SET_REGNO (in_rtx, newreg);
3916 in_rtx->used = 1;
3919 if (INSN_P (in_rtx))
3921 /* Inside a SEQUENCE, we find insns.
3922 Renumber just the patterns of these insns,
3923 just as we do for the top-level insns. */
3924 leaf_renumber_regs_insn (PATTERN (in_rtx));
3925 return;
3928 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
3930 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
3931 switch (*format_ptr++)
3933 case 'e':
3934 leaf_renumber_regs_insn (XEXP (in_rtx, i));
3935 break;
3937 case 'E':
3938 if (NULL != XVEC (in_rtx, i))
3940 for (j = 0; j < XVECLEN (in_rtx, i); j++)
3941 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
3943 break;
3945 case 'S':
3946 case 's':
3947 case '0':
3948 case 'i':
3949 case 'w':
3950 case 'n':
3951 case 'u':
3952 break;
3954 default:
3955 gcc_unreachable ();
3958 #endif
3961 /* When -gused is used, emit debug info for only used symbols. But in
3962 addition to the standard intercepted debug_hooks there are some direct
3963 calls into this file, i.e., dbxout_symbol, dbxout_parms, and dbxout_reg_params.
3964 Those routines may also be called from a higher level intercepted routine. So
3965 to prevent recording data for an inner call to one of these for an intercept,
3966 we maintain an intercept nesting counter (debug_nesting). We only save the
3967 intercepted arguments if the nesting is 1. */
3968 int debug_nesting = 0;
3970 static tree *symbol_queue;
3971 int symbol_queue_index = 0;
3972 static int symbol_queue_size = 0;
3974 /* Generate the symbols for any queued up type symbols we encountered
3975 while generating the type info for some originally used symbol.
3976 This might generate additional entries in the queue. Only when
3977 the nesting depth goes to 0 is this routine called. */
3979 void
3980 debug_flush_symbol_queue (void)
3982 int i;
3984 /* Make sure that additionally queued items are not flushed
3985 prematurely. */
3987 ++debug_nesting;
3989 for (i = 0; i < symbol_queue_index; ++i)
3991 /* If we pushed queued symbols then such symbols must be
3992 output no matter what anyone else says. Specifically,
3993 we need to make sure dbxout_symbol() thinks the symbol was
3994 used and also we need to override TYPE_DECL_SUPPRESS_DEBUG
3995 which may be set for outside reasons. */
3996 int saved_tree_used = TREE_USED (symbol_queue[i]);
3997 int saved_suppress_debug = TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]);
3998 TREE_USED (symbol_queue[i]) = 1;
3999 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = 0;
4001 #ifdef DBX_DEBUGGING_INFO
4002 dbxout_symbol (symbol_queue[i], 0);
4003 #endif
4005 TREE_USED (symbol_queue[i]) = saved_tree_used;
4006 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = saved_suppress_debug;
4009 symbol_queue_index = 0;
4010 --debug_nesting;
4013 /* Queue a type symbol needed as part of the definition of a decl
4014 symbol. These symbols are generated when debug_flush_symbol_queue()
4015 is called. */
4017 void
4018 debug_queue_symbol (tree decl)
4020 if (symbol_queue_index >= symbol_queue_size)
4022 symbol_queue_size += 10;
4023 symbol_queue = xrealloc (symbol_queue,
4024 symbol_queue_size * sizeof (tree));
4027 symbol_queue[symbol_queue_index++] = decl;
4030 /* Free symbol queue. */
4031 void
4032 debug_free_queue (void)
4034 if (symbol_queue)
4036 free (symbol_queue);
4037 symbol_queue = NULL;
4038 symbol_queue_size = 0;
4042 /* Turn the RTL into assembly. */
4043 static unsigned int
4044 rest_of_handle_final (void)
4046 rtx x;
4047 const char *fnname;
4049 /* Get the function's name, as described by its RTL. This may be
4050 different from the DECL_NAME name used in the source file. */
4052 x = DECL_RTL (current_function_decl);
4053 gcc_assert (MEM_P (x));
4054 x = XEXP (x, 0);
4055 gcc_assert (GET_CODE (x) == SYMBOL_REF);
4056 fnname = XSTR (x, 0);
4058 assemble_start_function (current_function_decl, fnname);
4059 final_start_function (get_insns (), asm_out_file, optimize);
4060 final (get_insns (), asm_out_file, optimize);
4061 final_end_function ();
4063 #ifdef TARGET_UNWIND_INFO
4064 /* ??? The IA-64 ".handlerdata" directive must be issued before
4065 the ".endp" directive that closes the procedure descriptor. */
4066 output_function_exception_table (fnname);
4067 #endif
4069 assemble_end_function (current_function_decl, fnname);
4071 #ifndef TARGET_UNWIND_INFO
4072 /* Otherwise, it feels unclean to switch sections in the middle. */
4073 output_function_exception_table (fnname);
4074 #endif
4076 user_defined_section_attribute = false;
4078 /* Free up reg info memory. */
4079 free_reg_info ();
4081 if (! quiet_flag)
4082 fflush (asm_out_file);
4084 /* Write DBX symbols if requested. */
4086 /* Note that for those inline functions where we don't initially
4087 know for certain that we will be generating an out-of-line copy,
4088 the first invocation of this routine (rest_of_compilation) will
4089 skip over this code by doing a `goto exit_rest_of_compilation;'.
4090 Later on, wrapup_global_declarations will (indirectly) call
4091 rest_of_compilation again for those inline functions that need
4092 to have out-of-line copies generated. During that call, we
4093 *will* be routed past here. */
4095 timevar_push (TV_SYMOUT);
4096 (*debug_hooks->function_decl) (current_function_decl);
4097 timevar_pop (TV_SYMOUT);
4098 if (DECL_STATIC_CONSTRUCTOR (current_function_decl)
4099 && targetm.have_ctors_dtors)
4100 targetm.asm_out.constructor (XEXP (DECL_RTL (current_function_decl), 0),
4101 decl_init_priority_lookup
4102 (current_function_decl));
4103 if (DECL_STATIC_DESTRUCTOR (current_function_decl)
4104 && targetm.have_ctors_dtors)
4105 targetm.asm_out.destructor (XEXP (DECL_RTL (current_function_decl), 0),
4106 decl_fini_priority_lookup
4107 (current_function_decl));
4108 return 0;
4111 struct tree_opt_pass pass_final =
4113 NULL, /* name */
4114 NULL, /* gate */
4115 rest_of_handle_final, /* execute */
4116 NULL, /* sub */
4117 NULL, /* next */
4118 0, /* static_pass_number */
4119 TV_FINAL, /* tv_id */
4120 0, /* properties_required */
4121 0, /* properties_provided */
4122 0, /* properties_destroyed */
4123 0, /* todo_flags_start */
4124 TODO_ggc_collect, /* todo_flags_finish */
4125 0 /* letter */
4129 static unsigned int
4130 rest_of_handle_shorten_branches (void)
4132 /* Shorten branches. */
4133 shorten_branches (get_insns ());
4134 return 0;
4137 struct tree_opt_pass pass_shorten_branches =
4139 "shorten", /* name */
4140 NULL, /* gate */
4141 rest_of_handle_shorten_branches, /* execute */
4142 NULL, /* sub */
4143 NULL, /* next */
4144 0, /* static_pass_number */
4145 TV_FINAL, /* tv_id */
4146 0, /* properties_required */
4147 0, /* properties_provided */
4148 0, /* properties_destroyed */
4149 0, /* todo_flags_start */
4150 TODO_dump_func, /* todo_flags_finish */
4151 0 /* letter */
4155 static unsigned int
4156 rest_of_clean_state (void)
4158 rtx insn, next;
4160 /* It is very important to decompose the RTL instruction chain here:
4161 debug information keeps pointing into CODE_LABEL insns inside the function
4162 body. If these remain pointing to the other insns, we end up preserving
4163 whole RTL chain and attached detailed debug info in memory. */
4164 for (insn = get_insns (); insn; insn = next)
4166 next = NEXT_INSN (insn);
4167 NEXT_INSN (insn) = NULL;
4168 PREV_INSN (insn) = NULL;
4171 /* In case the function was not output,
4172 don't leave any temporary anonymous types
4173 queued up for sdb output. */
4174 #ifdef SDB_DEBUGGING_INFO
4175 if (write_symbols == SDB_DEBUG)
4176 sdbout_types (NULL_TREE);
4177 #endif
4179 reload_completed = 0;
4180 epilogue_completed = 0;
4181 #ifdef STACK_REGS
4182 regstack_completed = 0;
4183 #endif
4185 /* Clear out the insn_length contents now that they are no
4186 longer valid. */
4187 init_insn_lengths ();
4189 /* Show no temporary slots allocated. */
4190 init_temp_slots ();
4192 free_bb_for_insn ();
4194 if (targetm.binds_local_p (current_function_decl))
4196 int pref = cfun->preferred_stack_boundary;
4197 if (cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
4198 pref = cfun->stack_alignment_needed;
4199 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
4200 = pref;
4203 /* Make sure volatile mem refs aren't considered valid operands for
4204 arithmetic insns. We must call this here if this is a nested inline
4205 function, since the above code leaves us in the init_recog state,
4206 and the function context push/pop code does not save/restore volatile_ok.
4208 ??? Maybe it isn't necessary for expand_start_function to call this
4209 anymore if we do it here? */
4211 init_recog_no_volatile ();
4213 /* We're done with this function. Free up memory if we can. */
4214 free_after_parsing (cfun);
4215 free_after_compilation (cfun);
4216 return 0;
4219 struct tree_opt_pass pass_clean_state =
4221 NULL, /* name */
4222 NULL, /* gate */
4223 rest_of_clean_state, /* execute */
4224 NULL, /* sub */
4225 NULL, /* next */
4226 0, /* static_pass_number */
4227 TV_FINAL, /* tv_id */
4228 0, /* properties_required */
4229 0, /* properties_provided */
4230 PROP_rtl, /* properties_destroyed */
4231 0, /* todo_flags_start */
4232 0, /* todo_flags_finish */
4233 0 /* letter */