mips.c (build_mips16_call_stub): On 64-bit targets, combine an SC return value into...
[official-gcc.git] / gcc / final.c
blob8af31cc1955c7c1b7e48f1824b4cb6e24cdbe279
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 /* If this is a conditional trap, maybe modify it if the cc's
2391 are in a nonstandard state so that it accomplishes the same
2392 thing that it would do straightforwardly if the cc's were
2393 set up normally. */
2394 if (cc_status.flags != 0
2395 && NONJUMP_INSN_P (insn)
2396 && GET_CODE (body) == TRAP_IF
2397 && COMPARISON_P (TRAP_CONDITION (body))
2398 && XEXP (TRAP_CONDITION (body), 0) == cc0_rtx)
2400 /* This function may alter the contents of its argument
2401 and clear some of the cc_status.flags bits.
2402 It may also return 1 meaning condition now always true
2403 or -1 meaning condition now always false
2404 or 2 meaning condition nontrivial but altered. */
2405 int result = alter_cond (TRAP_CONDITION (body));
2407 /* If TRAP_CONDITION has become always false, delete the
2408 instruction. */
2409 if (result == -1)
2411 delete_insn (insn);
2412 break;
2415 /* If TRAP_CONDITION has become always true, replace
2416 TRAP_CONDITION with const_true_rtx. */
2417 if (result == 1)
2418 TRAP_CONDITION (body) = const_true_rtx;
2420 /* Rerecognize the instruction if it has changed. */
2421 if (result != 0)
2422 INSN_CODE (insn) = -1;
2425 /* Make same adjustments to instructions that examine the
2426 condition codes without jumping and instructions that
2427 handle conditional moves (if this machine has either one). */
2429 if (cc_status.flags != 0
2430 && set != 0)
2432 rtx cond_rtx, then_rtx, else_rtx;
2434 if (!JUMP_P (insn)
2435 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2437 cond_rtx = XEXP (SET_SRC (set), 0);
2438 then_rtx = XEXP (SET_SRC (set), 1);
2439 else_rtx = XEXP (SET_SRC (set), 2);
2441 else
2443 cond_rtx = SET_SRC (set);
2444 then_rtx = const_true_rtx;
2445 else_rtx = const0_rtx;
2448 switch (GET_CODE (cond_rtx))
2450 case GTU:
2451 case GT:
2452 case LTU:
2453 case LT:
2454 case GEU:
2455 case GE:
2456 case LEU:
2457 case LE:
2458 case EQ:
2459 case NE:
2461 int result;
2462 if (XEXP (cond_rtx, 0) != cc0_rtx)
2463 break;
2464 result = alter_cond (cond_rtx);
2465 if (result == 1)
2466 validate_change (insn, &SET_SRC (set), then_rtx, 0);
2467 else if (result == -1)
2468 validate_change (insn, &SET_SRC (set), else_rtx, 0);
2469 else if (result == 2)
2470 INSN_CODE (insn) = -1;
2471 if (SET_DEST (set) == SET_SRC (set))
2472 delete_insn (insn);
2474 break;
2476 default:
2477 break;
2481 #endif
2483 #ifdef HAVE_peephole
2484 /* Do machine-specific peephole optimizations if desired. */
2486 if (optimize && !flag_no_peephole && !nopeepholes)
2488 rtx next = peephole (insn);
2489 /* When peepholing, if there were notes within the peephole,
2490 emit them before the peephole. */
2491 if (next != 0 && next != NEXT_INSN (insn))
2493 rtx note, prev = PREV_INSN (insn);
2495 for (note = NEXT_INSN (insn); note != next;
2496 note = NEXT_INSN (note))
2497 final_scan_insn (note, file, optimize, nopeepholes, seen);
2499 /* Put the notes in the proper position for a later
2500 rescan. For example, the SH target can do this
2501 when generating a far jump in a delayed branch
2502 sequence. */
2503 note = NEXT_INSN (insn);
2504 PREV_INSN (note) = prev;
2505 NEXT_INSN (prev) = note;
2506 NEXT_INSN (PREV_INSN (next)) = insn;
2507 PREV_INSN (insn) = PREV_INSN (next);
2508 NEXT_INSN (insn) = next;
2509 PREV_INSN (next) = insn;
2512 /* PEEPHOLE might have changed this. */
2513 body = PATTERN (insn);
2515 #endif
2517 /* Try to recognize the instruction.
2518 If successful, verify that the operands satisfy the
2519 constraints for the instruction. Crash if they don't,
2520 since `reload' should have changed them so that they do. */
2522 insn_code_number = recog_memoized (insn);
2523 cleanup_subreg_operands (insn);
2525 /* Dump the insn in the assembly for debugging. */
2526 if (flag_dump_rtl_in_asm)
2528 print_rtx_head = ASM_COMMENT_START;
2529 print_rtl_single (asm_out_file, insn);
2530 print_rtx_head = "";
2533 if (! constrain_operands_cached (1))
2534 fatal_insn_not_found (insn);
2536 /* Some target machines need to prescan each insn before
2537 it is output. */
2539 #ifdef FINAL_PRESCAN_INSN
2540 FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2541 #endif
2543 #ifdef HAVE_conditional_execution
2544 if (GET_CODE (PATTERN (insn)) == COND_EXEC)
2545 current_insn_predicate = COND_EXEC_TEST (PATTERN (insn));
2546 #endif
2548 #ifdef HAVE_cc0
2549 cc_prev_status = cc_status;
2551 /* Update `cc_status' for this instruction.
2552 The instruction's output routine may change it further.
2553 If the output routine for a jump insn needs to depend
2554 on the cc status, it should look at cc_prev_status. */
2556 NOTICE_UPDATE_CC (body, insn);
2557 #endif
2559 current_output_insn = debug_insn = insn;
2561 #if defined (DWARF2_UNWIND_INFO)
2562 if (CALL_P (insn) && dwarf2out_do_frame ())
2563 dwarf2out_frame_debug (insn, false);
2564 #endif
2566 /* Find the proper template for this insn. */
2567 template = get_insn_template (insn_code_number, insn);
2569 /* If the C code returns 0, it means that it is a jump insn
2570 which follows a deleted test insn, and that test insn
2571 needs to be reinserted. */
2572 if (template == 0)
2574 rtx prev;
2576 gcc_assert (prev_nonnote_insn (insn) == last_ignored_compare);
2578 /* We have already processed the notes between the setter and
2579 the user. Make sure we don't process them again, this is
2580 particularly important if one of the notes is a block
2581 scope note or an EH note. */
2582 for (prev = insn;
2583 prev != last_ignored_compare;
2584 prev = PREV_INSN (prev))
2586 if (NOTE_P (prev))
2587 delete_insn (prev); /* Use delete_note. */
2590 return prev;
2593 /* If the template is the string "#", it means that this insn must
2594 be split. */
2595 if (template[0] == '#' && template[1] == '\0')
2597 rtx new = try_split (body, insn, 0);
2599 /* If we didn't split the insn, go away. */
2600 if (new == insn && PATTERN (new) == body)
2601 fatal_insn ("could not split insn", insn);
2603 #ifdef HAVE_ATTR_length
2604 /* This instruction should have been split in shorten_branches,
2605 to ensure that we would have valid length info for the
2606 splitees. */
2607 gcc_unreachable ();
2608 #endif
2610 return new;
2613 #ifdef TARGET_UNWIND_INFO
2614 /* ??? This will put the directives in the wrong place if
2615 get_insn_template outputs assembly directly. However calling it
2616 before get_insn_template breaks if the insns is split. */
2617 targetm.asm_out.unwind_emit (asm_out_file, insn);
2618 #endif
2620 /* Output assembler code from the template. */
2621 output_asm_insn (template, recog_data.operand);
2623 /* If necessary, report the effect that the instruction has on
2624 the unwind info. We've already done this for delay slots
2625 and call instructions. */
2626 #if defined (DWARF2_UNWIND_INFO)
2627 if (final_sequence == 0
2628 #if !defined (HAVE_prologue)
2629 && !ACCUMULATE_OUTGOING_ARGS
2630 #endif
2631 && dwarf2out_do_frame ())
2632 dwarf2out_frame_debug (insn, true);
2633 #endif
2635 current_output_insn = debug_insn = 0;
2638 return NEXT_INSN (insn);
2641 /* Return whether a source line note needs to be emitted before INSN. */
2643 static bool
2644 notice_source_line (rtx insn)
2646 const char *filename;
2647 int linenum;
2649 if (override_filename)
2651 filename = override_filename;
2652 linenum = override_linenum;
2654 else
2656 filename = insn_file (insn);
2657 linenum = insn_line (insn);
2660 if (filename
2661 && (force_source_line
2662 || filename != last_filename
2663 || last_linenum != linenum))
2665 force_source_line = false;
2666 last_filename = filename;
2667 last_linenum = linenum;
2668 high_block_linenum = MAX (last_linenum, high_block_linenum);
2669 high_function_linenum = MAX (last_linenum, high_function_linenum);
2670 return true;
2672 return false;
2675 /* For each operand in INSN, simplify (subreg (reg)) so that it refers
2676 directly to the desired hard register. */
2678 void
2679 cleanup_subreg_operands (rtx insn)
2681 int i;
2682 bool changed = false;
2683 extract_insn_cached (insn);
2684 for (i = 0; i < recog_data.n_operands; i++)
2686 /* The following test cannot use recog_data.operand when testing
2687 for a SUBREG: the underlying object might have been changed
2688 already if we are inside a match_operator expression that
2689 matches the else clause. Instead we test the underlying
2690 expression directly. */
2691 if (GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
2693 recog_data.operand[i] = alter_subreg (recog_data.operand_loc[i]);
2694 changed = true;
2696 else if (GET_CODE (recog_data.operand[i]) == PLUS
2697 || GET_CODE (recog_data.operand[i]) == MULT
2698 || MEM_P (recog_data.operand[i]))
2699 recog_data.operand[i] = walk_alter_subreg (recog_data.operand_loc[i], &changed);
2702 for (i = 0; i < recog_data.n_dups; i++)
2704 if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
2706 *recog_data.dup_loc[i] = alter_subreg (recog_data.dup_loc[i]);
2707 changed = true;
2709 else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
2710 || GET_CODE (*recog_data.dup_loc[i]) == MULT
2711 || MEM_P (*recog_data.dup_loc[i]))
2712 *recog_data.dup_loc[i] = walk_alter_subreg (recog_data.dup_loc[i], &changed);
2714 if (changed)
2715 df_insn_rescan (insn);
2718 /* If X is a SUBREG, replace it with a REG or a MEM,
2719 based on the thing it is a subreg of. */
2722 alter_subreg (rtx *xp)
2724 rtx x = *xp;
2725 rtx y = SUBREG_REG (x);
2727 /* simplify_subreg does not remove subreg from volatile references.
2728 We are required to. */
2729 if (MEM_P (y))
2731 int offset = SUBREG_BYTE (x);
2733 /* For paradoxical subregs on big-endian machines, SUBREG_BYTE
2734 contains 0 instead of the proper offset. See simplify_subreg. */
2735 if (offset == 0
2736 && GET_MODE_SIZE (GET_MODE (y)) < GET_MODE_SIZE (GET_MODE (x)))
2738 int difference = GET_MODE_SIZE (GET_MODE (y))
2739 - GET_MODE_SIZE (GET_MODE (x));
2740 if (WORDS_BIG_ENDIAN)
2741 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
2742 if (BYTES_BIG_ENDIAN)
2743 offset += difference % UNITS_PER_WORD;
2746 *xp = adjust_address (y, GET_MODE (x), offset);
2748 else
2750 rtx new = simplify_subreg (GET_MODE (x), y, GET_MODE (y),
2751 SUBREG_BYTE (x));
2753 if (new != 0)
2754 *xp = new;
2755 else if (REG_P (y))
2757 /* Simplify_subreg can't handle some REG cases, but we have to. */
2758 unsigned int regno = subreg_regno (x);
2759 *xp = gen_rtx_REG_offset (y, GET_MODE (x), regno, SUBREG_BYTE (x));
2763 return *xp;
2766 /* Do alter_subreg on all the SUBREGs contained in X. */
2768 static rtx
2769 walk_alter_subreg (rtx *xp, bool *changed)
2771 rtx x = *xp;
2772 switch (GET_CODE (x))
2774 case PLUS:
2775 case MULT:
2776 case AND:
2777 XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0), changed);
2778 XEXP (x, 1) = walk_alter_subreg (&XEXP (x, 1), changed);
2779 break;
2781 case MEM:
2782 case ZERO_EXTEND:
2783 XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0), changed);
2784 break;
2786 case SUBREG:
2787 *changed = true;
2788 return alter_subreg (xp);
2790 default:
2791 break;
2794 return *xp;
2797 #ifdef HAVE_cc0
2799 /* Given BODY, the body of a jump instruction, alter the jump condition
2800 as required by the bits that are set in cc_status.flags.
2801 Not all of the bits there can be handled at this level in all cases.
2803 The value is normally 0.
2804 1 means that the condition has become always true.
2805 -1 means that the condition has become always false.
2806 2 means that COND has been altered. */
2808 static int
2809 alter_cond (rtx cond)
2811 int value = 0;
2813 if (cc_status.flags & CC_REVERSED)
2815 value = 2;
2816 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
2819 if (cc_status.flags & CC_INVERTED)
2821 value = 2;
2822 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
2825 if (cc_status.flags & CC_NOT_POSITIVE)
2826 switch (GET_CODE (cond))
2828 case LE:
2829 case LEU:
2830 case GEU:
2831 /* Jump becomes unconditional. */
2832 return 1;
2834 case GT:
2835 case GTU:
2836 case LTU:
2837 /* Jump becomes no-op. */
2838 return -1;
2840 case GE:
2841 PUT_CODE (cond, EQ);
2842 value = 2;
2843 break;
2845 case LT:
2846 PUT_CODE (cond, NE);
2847 value = 2;
2848 break;
2850 default:
2851 break;
2854 if (cc_status.flags & CC_NOT_NEGATIVE)
2855 switch (GET_CODE (cond))
2857 case GE:
2858 case GEU:
2859 /* Jump becomes unconditional. */
2860 return 1;
2862 case LT:
2863 case LTU:
2864 /* Jump becomes no-op. */
2865 return -1;
2867 case LE:
2868 case LEU:
2869 PUT_CODE (cond, EQ);
2870 value = 2;
2871 break;
2873 case GT:
2874 case GTU:
2875 PUT_CODE (cond, NE);
2876 value = 2;
2877 break;
2879 default:
2880 break;
2883 if (cc_status.flags & CC_NO_OVERFLOW)
2884 switch (GET_CODE (cond))
2886 case GEU:
2887 /* Jump becomes unconditional. */
2888 return 1;
2890 case LEU:
2891 PUT_CODE (cond, EQ);
2892 value = 2;
2893 break;
2895 case GTU:
2896 PUT_CODE (cond, NE);
2897 value = 2;
2898 break;
2900 case LTU:
2901 /* Jump becomes no-op. */
2902 return -1;
2904 default:
2905 break;
2908 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
2909 switch (GET_CODE (cond))
2911 default:
2912 gcc_unreachable ();
2914 case NE:
2915 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
2916 value = 2;
2917 break;
2919 case EQ:
2920 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
2921 value = 2;
2922 break;
2925 if (cc_status.flags & CC_NOT_SIGNED)
2926 /* The flags are valid if signed condition operators are converted
2927 to unsigned. */
2928 switch (GET_CODE (cond))
2930 case LE:
2931 PUT_CODE (cond, LEU);
2932 value = 2;
2933 break;
2935 case LT:
2936 PUT_CODE (cond, LTU);
2937 value = 2;
2938 break;
2940 case GT:
2941 PUT_CODE (cond, GTU);
2942 value = 2;
2943 break;
2945 case GE:
2946 PUT_CODE (cond, GEU);
2947 value = 2;
2948 break;
2950 default:
2951 break;
2954 return value;
2956 #endif
2958 /* Report inconsistency between the assembler template and the operands.
2959 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
2961 void
2962 output_operand_lossage (const char *cmsgid, ...)
2964 char *fmt_string;
2965 char *new_message;
2966 const char *pfx_str;
2967 va_list ap;
2969 va_start (ap, cmsgid);
2971 pfx_str = this_is_asm_operands ? _("invalid 'asm': ") : "output_operand: ";
2972 asprintf (&fmt_string, "%s%s", pfx_str, _(cmsgid));
2973 vasprintf (&new_message, fmt_string, ap);
2975 if (this_is_asm_operands)
2976 error_for_asm (this_is_asm_operands, "%s", new_message);
2977 else
2978 internal_error ("%s", new_message);
2980 free (fmt_string);
2981 free (new_message);
2982 va_end (ap);
2985 /* Output of assembler code from a template, and its subroutines. */
2987 /* Annotate the assembly with a comment describing the pattern and
2988 alternative used. */
2990 static void
2991 output_asm_name (void)
2993 if (debug_insn)
2995 int num = INSN_CODE (debug_insn);
2996 fprintf (asm_out_file, "\t%s %d\t%s",
2997 ASM_COMMENT_START, INSN_UID (debug_insn),
2998 insn_data[num].name);
2999 if (insn_data[num].n_alternatives > 1)
3000 fprintf (asm_out_file, "/%d", which_alternative + 1);
3001 #ifdef HAVE_ATTR_length
3002 fprintf (asm_out_file, "\t[length = %d]",
3003 get_attr_length (debug_insn));
3004 #endif
3005 /* Clear this so only the first assembler insn
3006 of any rtl insn will get the special comment for -dp. */
3007 debug_insn = 0;
3011 /* If OP is a REG or MEM and we can find a MEM_EXPR corresponding to it
3012 or its address, return that expr . Set *PADDRESSP to 1 if the expr
3013 corresponds to the address of the object and 0 if to the object. */
3015 static tree
3016 get_mem_expr_from_op (rtx op, int *paddressp)
3018 tree expr;
3019 int inner_addressp;
3021 *paddressp = 0;
3023 if (REG_P (op))
3024 return REG_EXPR (op);
3025 else if (!MEM_P (op))
3026 return 0;
3028 if (MEM_EXPR (op) != 0)
3029 return MEM_EXPR (op);
3031 /* Otherwise we have an address, so indicate it and look at the address. */
3032 *paddressp = 1;
3033 op = XEXP (op, 0);
3035 /* First check if we have a decl for the address, then look at the right side
3036 if it is a PLUS. Otherwise, strip off arithmetic and keep looking.
3037 But don't allow the address to itself be indirect. */
3038 if ((expr = get_mem_expr_from_op (op, &inner_addressp)) && ! inner_addressp)
3039 return expr;
3040 else if (GET_CODE (op) == PLUS
3041 && (expr = get_mem_expr_from_op (XEXP (op, 1), &inner_addressp)))
3042 return expr;
3044 while (GET_RTX_CLASS (GET_CODE (op)) == RTX_UNARY
3045 || GET_RTX_CLASS (GET_CODE (op)) == RTX_BIN_ARITH)
3046 op = XEXP (op, 0);
3048 expr = get_mem_expr_from_op (op, &inner_addressp);
3049 return inner_addressp ? 0 : expr;
3052 /* Output operand names for assembler instructions. OPERANDS is the
3053 operand vector, OPORDER is the order to write the operands, and NOPS
3054 is the number of operands to write. */
3056 static void
3057 output_asm_operand_names (rtx *operands, int *oporder, int nops)
3059 int wrote = 0;
3060 int i;
3062 for (i = 0; i < nops; i++)
3064 int addressp;
3065 rtx op = operands[oporder[i]];
3066 tree expr = get_mem_expr_from_op (op, &addressp);
3068 fprintf (asm_out_file, "%c%s",
3069 wrote ? ',' : '\t', wrote ? "" : ASM_COMMENT_START);
3070 wrote = 1;
3071 if (expr)
3073 fprintf (asm_out_file, "%s",
3074 addressp ? "*" : "");
3075 print_mem_expr (asm_out_file, expr);
3076 wrote = 1;
3078 else if (REG_P (op) && ORIGINAL_REGNO (op)
3079 && ORIGINAL_REGNO (op) != REGNO (op))
3080 fprintf (asm_out_file, " tmp%i", ORIGINAL_REGNO (op));
3084 /* Output text from TEMPLATE to the assembler output file,
3085 obeying %-directions to substitute operands taken from
3086 the vector OPERANDS.
3088 %N (for N a digit) means print operand N in usual manner.
3089 %lN means require operand N to be a CODE_LABEL or LABEL_REF
3090 and print the label name with no punctuation.
3091 %cN means require operand N to be a constant
3092 and print the constant expression with no punctuation.
3093 %aN means expect operand N to be a memory address
3094 (not a memory reference!) and print a reference
3095 to that address.
3096 %nN means expect operand N to be a constant
3097 and print a constant expression for minus the value
3098 of the operand, with no other punctuation. */
3100 void
3101 output_asm_insn (const char *template, rtx *operands)
3103 const char *p;
3104 int c;
3105 #ifdef ASSEMBLER_DIALECT
3106 int dialect = 0;
3107 #endif
3108 int oporder[MAX_RECOG_OPERANDS];
3109 char opoutput[MAX_RECOG_OPERANDS];
3110 int ops = 0;
3112 /* An insn may return a null string template
3113 in a case where no assembler code is needed. */
3114 if (*template == 0)
3115 return;
3117 memset (opoutput, 0, sizeof opoutput);
3118 p = template;
3119 putc ('\t', asm_out_file);
3121 #ifdef ASM_OUTPUT_OPCODE
3122 ASM_OUTPUT_OPCODE (asm_out_file, p);
3123 #endif
3125 while ((c = *p++))
3126 switch (c)
3128 case '\n':
3129 if (flag_verbose_asm)
3130 output_asm_operand_names (operands, oporder, ops);
3131 if (flag_print_asm_name)
3132 output_asm_name ();
3134 ops = 0;
3135 memset (opoutput, 0, sizeof opoutput);
3137 putc (c, asm_out_file);
3138 #ifdef ASM_OUTPUT_OPCODE
3139 while ((c = *p) == '\t')
3141 putc (c, asm_out_file);
3142 p++;
3144 ASM_OUTPUT_OPCODE (asm_out_file, p);
3145 #endif
3146 break;
3148 #ifdef ASSEMBLER_DIALECT
3149 case '{':
3151 int i;
3153 if (dialect)
3154 output_operand_lossage ("nested assembly dialect alternatives");
3155 else
3156 dialect = 1;
3158 /* If we want the first dialect, do nothing. Otherwise, skip
3159 DIALECT_NUMBER of strings ending with '|'. */
3160 for (i = 0; i < dialect_number; i++)
3162 while (*p && *p != '}' && *p++ != '|')
3164 if (*p == '}')
3165 break;
3166 if (*p == '|')
3167 p++;
3170 if (*p == '\0')
3171 output_operand_lossage ("unterminated assembly dialect alternative");
3173 break;
3175 case '|':
3176 if (dialect)
3178 /* Skip to close brace. */
3181 if (*p == '\0')
3183 output_operand_lossage ("unterminated assembly dialect alternative");
3184 break;
3187 while (*p++ != '}');
3188 dialect = 0;
3190 else
3191 putc (c, asm_out_file);
3192 break;
3194 case '}':
3195 if (! dialect)
3196 putc (c, asm_out_file);
3197 dialect = 0;
3198 break;
3199 #endif
3201 case '%':
3202 /* %% outputs a single %. */
3203 if (*p == '%')
3205 p++;
3206 putc (c, asm_out_file);
3208 /* %= outputs a number which is unique to each insn in the entire
3209 compilation. This is useful for making local labels that are
3210 referred to more than once in a given insn. */
3211 else if (*p == '=')
3213 p++;
3214 fprintf (asm_out_file, "%d", insn_counter);
3216 /* % followed by a letter and some digits
3217 outputs an operand in a special way depending on the letter.
3218 Letters `acln' are implemented directly.
3219 Other letters are passed to `output_operand' so that
3220 the PRINT_OPERAND macro can define them. */
3221 else if (ISALPHA (*p))
3223 int letter = *p++;
3224 unsigned long opnum;
3225 char *endptr;
3227 opnum = strtoul (p, &endptr, 10);
3229 if (endptr == p)
3230 output_operand_lossage ("operand number missing "
3231 "after %%-letter");
3232 else if (this_is_asm_operands && opnum >= insn_noperands)
3233 output_operand_lossage ("operand number out of range");
3234 else if (letter == 'l')
3235 output_asm_label (operands[opnum]);
3236 else if (letter == 'a')
3237 output_address (operands[opnum]);
3238 else if (letter == 'c')
3240 if (CONSTANT_ADDRESS_P (operands[opnum]))
3241 output_addr_const (asm_out_file, operands[opnum]);
3242 else
3243 output_operand (operands[opnum], 'c');
3245 else if (letter == 'n')
3247 if (GET_CODE (operands[opnum]) == CONST_INT)
3248 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3249 - INTVAL (operands[opnum]));
3250 else
3252 putc ('-', asm_out_file);
3253 output_addr_const (asm_out_file, operands[opnum]);
3256 else
3257 output_operand (operands[opnum], letter);
3259 if (!opoutput[opnum])
3260 oporder[ops++] = opnum;
3261 opoutput[opnum] = 1;
3263 p = endptr;
3264 c = *p;
3266 /* % followed by a digit outputs an operand the default way. */
3267 else if (ISDIGIT (*p))
3269 unsigned long opnum;
3270 char *endptr;
3272 opnum = strtoul (p, &endptr, 10);
3273 if (this_is_asm_operands && opnum >= insn_noperands)
3274 output_operand_lossage ("operand number out of range");
3275 else
3276 output_operand (operands[opnum], 0);
3278 if (!opoutput[opnum])
3279 oporder[ops++] = opnum;
3280 opoutput[opnum] = 1;
3282 p = endptr;
3283 c = *p;
3285 /* % followed by punctuation: output something for that
3286 punctuation character alone, with no operand.
3287 The PRINT_OPERAND macro decides what is actually done. */
3288 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3289 else if (PRINT_OPERAND_PUNCT_VALID_P ((unsigned char) *p))
3290 output_operand (NULL_RTX, *p++);
3291 #endif
3292 else
3293 output_operand_lossage ("invalid %%-code");
3294 break;
3296 default:
3297 putc (c, asm_out_file);
3300 /* Write out the variable names for operands, if we know them. */
3301 if (flag_verbose_asm)
3302 output_asm_operand_names (operands, oporder, ops);
3303 if (flag_print_asm_name)
3304 output_asm_name ();
3306 putc ('\n', asm_out_file);
3309 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3311 void
3312 output_asm_label (rtx x)
3314 char buf[256];
3316 if (GET_CODE (x) == LABEL_REF)
3317 x = XEXP (x, 0);
3318 if (LABEL_P (x)
3319 || (NOTE_P (x)
3320 && NOTE_KIND (x) == NOTE_INSN_DELETED_LABEL))
3321 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3322 else
3323 output_operand_lossage ("'%%l' operand isn't a label");
3325 assemble_name (asm_out_file, buf);
3328 /* Print operand X using machine-dependent assembler syntax.
3329 The macro PRINT_OPERAND is defined just to control this function.
3330 CODE is a non-digit that preceded the operand-number in the % spec,
3331 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3332 between the % and the digits.
3333 When CODE is a non-letter, X is 0.
3335 The meanings of the letters are machine-dependent and controlled
3336 by PRINT_OPERAND. */
3338 static void
3339 output_operand (rtx x, int code ATTRIBUTE_UNUSED)
3341 if (x && GET_CODE (x) == SUBREG)
3342 x = alter_subreg (&x);
3344 /* X must not be a pseudo reg. */
3345 gcc_assert (!x || !REG_P (x) || REGNO (x) < FIRST_PSEUDO_REGISTER);
3347 PRINT_OPERAND (asm_out_file, x, code);
3350 /* Print a memory reference operand for address X
3351 using machine-dependent assembler syntax.
3352 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
3354 void
3355 output_address (rtx x)
3357 bool changed = false;
3358 walk_alter_subreg (&x, &changed);
3359 PRINT_OPERAND_ADDRESS (asm_out_file, x);
3362 /* Print an integer constant expression in assembler syntax.
3363 Addition and subtraction are the only arithmetic
3364 that may appear in these expressions. */
3366 void
3367 output_addr_const (FILE *file, rtx x)
3369 char buf[256];
3371 restart:
3372 switch (GET_CODE (x))
3374 case PC:
3375 putc ('.', file);
3376 break;
3378 case SYMBOL_REF:
3379 if (SYMBOL_REF_DECL (x))
3380 mark_decl_referenced (SYMBOL_REF_DECL (x));
3381 #ifdef ASM_OUTPUT_SYMBOL_REF
3382 ASM_OUTPUT_SYMBOL_REF (file, x);
3383 #else
3384 assemble_name (file, XSTR (x, 0));
3385 #endif
3386 break;
3388 case LABEL_REF:
3389 x = XEXP (x, 0);
3390 /* Fall through. */
3391 case CODE_LABEL:
3392 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3393 #ifdef ASM_OUTPUT_LABEL_REF
3394 ASM_OUTPUT_LABEL_REF (file, buf);
3395 #else
3396 assemble_name (file, buf);
3397 #endif
3398 break;
3400 case CONST_INT:
3401 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3402 break;
3404 case CONST:
3405 /* This used to output parentheses around the expression,
3406 but that does not work on the 386 (either ATT or BSD assembler). */
3407 output_addr_const (file, XEXP (x, 0));
3408 break;
3410 case CONST_DOUBLE:
3411 if (GET_MODE (x) == VOIDmode)
3413 /* We can use %d if the number is one word and positive. */
3414 if (CONST_DOUBLE_HIGH (x))
3415 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3416 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3417 else if (CONST_DOUBLE_LOW (x) < 0)
3418 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3419 else
3420 fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3422 else
3423 /* We can't handle floating point constants;
3424 PRINT_OPERAND must handle them. */
3425 output_operand_lossage ("floating constant misused");
3426 break;
3428 case CONST_FIXED:
3429 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_FIXED_VALUE_LOW (x));
3430 break;
3432 case PLUS:
3433 /* Some assemblers need integer constants to appear last (eg masm). */
3434 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3436 output_addr_const (file, XEXP (x, 1));
3437 if (INTVAL (XEXP (x, 0)) >= 0)
3438 fprintf (file, "+");
3439 output_addr_const (file, XEXP (x, 0));
3441 else
3443 output_addr_const (file, XEXP (x, 0));
3444 if (GET_CODE (XEXP (x, 1)) != CONST_INT
3445 || INTVAL (XEXP (x, 1)) >= 0)
3446 fprintf (file, "+");
3447 output_addr_const (file, XEXP (x, 1));
3449 break;
3451 case MINUS:
3452 /* Avoid outputting things like x-x or x+5-x,
3453 since some assemblers can't handle that. */
3454 x = simplify_subtraction (x);
3455 if (GET_CODE (x) != MINUS)
3456 goto restart;
3458 output_addr_const (file, XEXP (x, 0));
3459 fprintf (file, "-");
3460 if ((GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) >= 0)
3461 || GET_CODE (XEXP (x, 1)) == PC
3462 || GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
3463 output_addr_const (file, XEXP (x, 1));
3464 else
3466 fputs (targetm.asm_out.open_paren, file);
3467 output_addr_const (file, XEXP (x, 1));
3468 fputs (targetm.asm_out.close_paren, file);
3470 break;
3472 case ZERO_EXTEND:
3473 case SIGN_EXTEND:
3474 case SUBREG:
3475 output_addr_const (file, XEXP (x, 0));
3476 break;
3478 default:
3479 #ifdef OUTPUT_ADDR_CONST_EXTRA
3480 OUTPUT_ADDR_CONST_EXTRA (file, x, fail);
3481 break;
3483 fail:
3484 #endif
3485 output_operand_lossage ("invalid expression as operand");
3489 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3490 %R prints the value of REGISTER_PREFIX.
3491 %L prints the value of LOCAL_LABEL_PREFIX.
3492 %U prints the value of USER_LABEL_PREFIX.
3493 %I prints the value of IMMEDIATE_PREFIX.
3494 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3495 Also supported are %d, %i, %u, %x, %X, %o, %c, %s and %%.
3497 We handle alternate assembler dialects here, just like output_asm_insn. */
3499 void
3500 asm_fprintf (FILE *file, const char *p, ...)
3502 char buf[10];
3503 char *q, c;
3504 va_list argptr;
3506 va_start (argptr, p);
3508 buf[0] = '%';
3510 while ((c = *p++))
3511 switch (c)
3513 #ifdef ASSEMBLER_DIALECT
3514 case '{':
3516 int i;
3518 /* If we want the first dialect, do nothing. Otherwise, skip
3519 DIALECT_NUMBER of strings ending with '|'. */
3520 for (i = 0; i < dialect_number; i++)
3522 while (*p && *p++ != '|')
3525 if (*p == '|')
3526 p++;
3529 break;
3531 case '|':
3532 /* Skip to close brace. */
3533 while (*p && *p++ != '}')
3535 break;
3537 case '}':
3538 break;
3539 #endif
3541 case '%':
3542 c = *p++;
3543 q = &buf[1];
3544 while (strchr ("-+ #0", c))
3546 *q++ = c;
3547 c = *p++;
3549 while (ISDIGIT (c) || c == '.')
3551 *q++ = c;
3552 c = *p++;
3554 switch (c)
3556 case '%':
3557 putc ('%', file);
3558 break;
3560 case 'd': case 'i': case 'u':
3561 case 'x': case 'X': case 'o':
3562 case 'c':
3563 *q++ = c;
3564 *q = 0;
3565 fprintf (file, buf, va_arg (argptr, int));
3566 break;
3568 case 'w':
3569 /* This is a prefix to the 'd', 'i', 'u', 'x', 'X', and
3570 'o' cases, but we do not check for those cases. It
3571 means that the value is a HOST_WIDE_INT, which may be
3572 either `long' or `long long'. */
3573 memcpy (q, HOST_WIDE_INT_PRINT, strlen (HOST_WIDE_INT_PRINT));
3574 q += strlen (HOST_WIDE_INT_PRINT);
3575 *q++ = *p++;
3576 *q = 0;
3577 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3578 break;
3580 case 'l':
3581 *q++ = c;
3582 #ifdef HAVE_LONG_LONG
3583 if (*p == 'l')
3585 *q++ = *p++;
3586 *q++ = *p++;
3587 *q = 0;
3588 fprintf (file, buf, va_arg (argptr, long long));
3590 else
3591 #endif
3593 *q++ = *p++;
3594 *q = 0;
3595 fprintf (file, buf, va_arg (argptr, long));
3598 break;
3600 case 's':
3601 *q++ = c;
3602 *q = 0;
3603 fprintf (file, buf, va_arg (argptr, char *));
3604 break;
3606 case 'O':
3607 #ifdef ASM_OUTPUT_OPCODE
3608 ASM_OUTPUT_OPCODE (asm_out_file, p);
3609 #endif
3610 break;
3612 case 'R':
3613 #ifdef REGISTER_PREFIX
3614 fprintf (file, "%s", REGISTER_PREFIX);
3615 #endif
3616 break;
3618 case 'I':
3619 #ifdef IMMEDIATE_PREFIX
3620 fprintf (file, "%s", IMMEDIATE_PREFIX);
3621 #endif
3622 break;
3624 case 'L':
3625 #ifdef LOCAL_LABEL_PREFIX
3626 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3627 #endif
3628 break;
3630 case 'U':
3631 fputs (user_label_prefix, file);
3632 break;
3634 #ifdef ASM_FPRINTF_EXTENSIONS
3635 /* Uppercase letters are reserved for general use by asm_fprintf
3636 and so are not available to target specific code. In order to
3637 prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
3638 they are defined here. As they get turned into real extensions
3639 to asm_fprintf they should be removed from this list. */
3640 case 'A': case 'B': case 'C': case 'D': case 'E':
3641 case 'F': case 'G': case 'H': case 'J': case 'K':
3642 case 'M': case 'N': case 'P': case 'Q': case 'S':
3643 case 'T': case 'V': case 'W': case 'Y': case 'Z':
3644 break;
3646 ASM_FPRINTF_EXTENSIONS (file, argptr, p)
3647 #endif
3648 default:
3649 gcc_unreachable ();
3651 break;
3653 default:
3654 putc (c, file);
3656 va_end (argptr);
3659 /* Split up a CONST_DOUBLE or integer constant rtx
3660 into two rtx's for single words,
3661 storing in *FIRST the word that comes first in memory in the target
3662 and in *SECOND the other. */
3664 void
3665 split_double (rtx value, rtx *first, rtx *second)
3667 if (GET_CODE (value) == CONST_INT)
3669 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3671 /* In this case the CONST_INT holds both target words.
3672 Extract the bits from it into two word-sized pieces.
3673 Sign extend each half to HOST_WIDE_INT. */
3674 unsigned HOST_WIDE_INT low, high;
3675 unsigned HOST_WIDE_INT mask, sign_bit, sign_extend;
3677 /* Set sign_bit to the most significant bit of a word. */
3678 sign_bit = 1;
3679 sign_bit <<= BITS_PER_WORD - 1;
3681 /* Set mask so that all bits of the word are set. We could
3682 have used 1 << BITS_PER_WORD instead of basing the
3683 calculation on sign_bit. However, on machines where
3684 HOST_BITS_PER_WIDE_INT == BITS_PER_WORD, it could cause a
3685 compiler warning, even though the code would never be
3686 executed. */
3687 mask = sign_bit << 1;
3688 mask--;
3690 /* Set sign_extend as any remaining bits. */
3691 sign_extend = ~mask;
3693 /* Pick the lower word and sign-extend it. */
3694 low = INTVAL (value);
3695 low &= mask;
3696 if (low & sign_bit)
3697 low |= sign_extend;
3699 /* Pick the higher word, shifted to the least significant
3700 bits, and sign-extend it. */
3701 high = INTVAL (value);
3702 high >>= BITS_PER_WORD - 1;
3703 high >>= 1;
3704 high &= mask;
3705 if (high & sign_bit)
3706 high |= sign_extend;
3708 /* Store the words in the target machine order. */
3709 if (WORDS_BIG_ENDIAN)
3711 *first = GEN_INT (high);
3712 *second = GEN_INT (low);
3714 else
3716 *first = GEN_INT (low);
3717 *second = GEN_INT (high);
3720 else
3722 /* The rule for using CONST_INT for a wider mode
3723 is that we regard the value as signed.
3724 So sign-extend it. */
3725 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3726 if (WORDS_BIG_ENDIAN)
3728 *first = high;
3729 *second = value;
3731 else
3733 *first = value;
3734 *second = high;
3738 else if (GET_CODE (value) != CONST_DOUBLE)
3740 if (WORDS_BIG_ENDIAN)
3742 *first = const0_rtx;
3743 *second = value;
3745 else
3747 *first = value;
3748 *second = const0_rtx;
3751 else if (GET_MODE (value) == VOIDmode
3752 /* This is the old way we did CONST_DOUBLE integers. */
3753 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3755 /* In an integer, the words are defined as most and least significant.
3756 So order them by the target's convention. */
3757 if (WORDS_BIG_ENDIAN)
3759 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3760 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3762 else
3764 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3765 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3768 else
3770 REAL_VALUE_TYPE r;
3771 long l[2];
3772 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3774 /* Note, this converts the REAL_VALUE_TYPE to the target's
3775 format, splits up the floating point double and outputs
3776 exactly 32 bits of it into each of l[0] and l[1] --
3777 not necessarily BITS_PER_WORD bits. */
3778 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3780 /* If 32 bits is an entire word for the target, but not for the host,
3781 then sign-extend on the host so that the number will look the same
3782 way on the host that it would on the target. See for instance
3783 simplify_unary_operation. The #if is needed to avoid compiler
3784 warnings. */
3786 #if HOST_BITS_PER_LONG > 32
3787 if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
3789 if (l[0] & ((long) 1 << 31))
3790 l[0] |= ((long) (-1) << 32);
3791 if (l[1] & ((long) 1 << 31))
3792 l[1] |= ((long) (-1) << 32);
3794 #endif
3796 *first = GEN_INT (l[0]);
3797 *second = GEN_INT (l[1]);
3801 /* Return nonzero if this function has no function calls. */
3804 leaf_function_p (void)
3806 rtx insn;
3807 rtx link;
3809 if (current_function_profile || profile_arc_flag)
3810 return 0;
3812 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3814 if (CALL_P (insn)
3815 && ! SIBLING_CALL_P (insn))
3816 return 0;
3817 if (NONJUMP_INSN_P (insn)
3818 && GET_CODE (PATTERN (insn)) == SEQUENCE
3819 && CALL_P (XVECEXP (PATTERN (insn), 0, 0))
3820 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
3821 return 0;
3823 for (link = current_function_epilogue_delay_list;
3824 link;
3825 link = XEXP (link, 1))
3827 insn = XEXP (link, 0);
3829 if (CALL_P (insn)
3830 && ! SIBLING_CALL_P (insn))
3831 return 0;
3832 if (NONJUMP_INSN_P (insn)
3833 && GET_CODE (PATTERN (insn)) == SEQUENCE
3834 && CALL_P (XVECEXP (PATTERN (insn), 0, 0))
3835 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
3836 return 0;
3839 return 1;
3842 /* Return 1 if branch is a forward branch.
3843 Uses insn_shuid array, so it works only in the final pass. May be used by
3844 output templates to customary add branch prediction hints.
3847 final_forward_branch_p (rtx insn)
3849 int insn_id, label_id;
3851 gcc_assert (uid_shuid);
3852 insn_id = INSN_SHUID (insn);
3853 label_id = INSN_SHUID (JUMP_LABEL (insn));
3854 /* We've hit some insns that does not have id information available. */
3855 gcc_assert (insn_id && label_id);
3856 return insn_id < label_id;
3859 /* On some machines, a function with no call insns
3860 can run faster if it doesn't create its own register window.
3861 When output, the leaf function should use only the "output"
3862 registers. Ordinarily, the function would be compiled to use
3863 the "input" registers to find its arguments; it is a candidate
3864 for leaf treatment if it uses only the "input" registers.
3865 Leaf function treatment means renumbering so the function
3866 uses the "output" registers instead. */
3868 #ifdef LEAF_REGISTERS
3870 /* Return 1 if this function uses only the registers that can be
3871 safely renumbered. */
3874 only_leaf_regs_used (void)
3876 int i;
3877 const char *const permitted_reg_in_leaf_functions = LEAF_REGISTERS;
3879 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3880 if ((df_regs_ever_live_p (i) || global_regs[i])
3881 && ! permitted_reg_in_leaf_functions[i])
3882 return 0;
3884 if (current_function_uses_pic_offset_table
3885 && pic_offset_table_rtx != 0
3886 && REG_P (pic_offset_table_rtx)
3887 && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
3888 return 0;
3890 return 1;
3893 /* Scan all instructions and renumber all registers into those
3894 available in leaf functions. */
3896 static void
3897 leaf_renumber_regs (rtx first)
3899 rtx insn;
3901 /* Renumber only the actual patterns.
3902 The reg-notes can contain frame pointer refs,
3903 and renumbering them could crash, and should not be needed. */
3904 for (insn = first; insn; insn = NEXT_INSN (insn))
3905 if (INSN_P (insn))
3906 leaf_renumber_regs_insn (PATTERN (insn));
3907 for (insn = current_function_epilogue_delay_list;
3908 insn;
3909 insn = XEXP (insn, 1))
3910 if (INSN_P (XEXP (insn, 0)))
3911 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
3914 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
3915 available in leaf functions. */
3917 void
3918 leaf_renumber_regs_insn (rtx in_rtx)
3920 int i, j;
3921 const char *format_ptr;
3923 if (in_rtx == 0)
3924 return;
3926 /* Renumber all input-registers into output-registers.
3927 renumbered_regs would be 1 for an output-register;
3928 they */
3930 if (REG_P (in_rtx))
3932 int newreg;
3934 /* Don't renumber the same reg twice. */
3935 if (in_rtx->used)
3936 return;
3938 newreg = REGNO (in_rtx);
3939 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
3940 to reach here as part of a REG_NOTE. */
3941 if (newreg >= FIRST_PSEUDO_REGISTER)
3943 in_rtx->used = 1;
3944 return;
3946 newreg = LEAF_REG_REMAP (newreg);
3947 gcc_assert (newreg >= 0);
3948 df_set_regs_ever_live (REGNO (in_rtx), false);
3949 df_set_regs_ever_live (newreg, true);
3950 SET_REGNO (in_rtx, newreg);
3951 in_rtx->used = 1;
3954 if (INSN_P (in_rtx))
3956 /* Inside a SEQUENCE, we find insns.
3957 Renumber just the patterns of these insns,
3958 just as we do for the top-level insns. */
3959 leaf_renumber_regs_insn (PATTERN (in_rtx));
3960 return;
3963 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
3965 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
3966 switch (*format_ptr++)
3968 case 'e':
3969 leaf_renumber_regs_insn (XEXP (in_rtx, i));
3970 break;
3972 case 'E':
3973 if (NULL != XVEC (in_rtx, i))
3975 for (j = 0; j < XVECLEN (in_rtx, i); j++)
3976 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
3978 break;
3980 case 'S':
3981 case 's':
3982 case '0':
3983 case 'i':
3984 case 'w':
3985 case 'n':
3986 case 'u':
3987 break;
3989 default:
3990 gcc_unreachable ();
3993 #endif
3996 /* When -gused is used, emit debug info for only used symbols. But in
3997 addition to the standard intercepted debug_hooks there are some direct
3998 calls into this file, i.e., dbxout_symbol, dbxout_parms, and dbxout_reg_params.
3999 Those routines may also be called from a higher level intercepted routine. So
4000 to prevent recording data for an inner call to one of these for an intercept,
4001 we maintain an intercept nesting counter (debug_nesting). We only save the
4002 intercepted arguments if the nesting is 1. */
4003 int debug_nesting = 0;
4005 static tree *symbol_queue;
4006 int symbol_queue_index = 0;
4007 static int symbol_queue_size = 0;
4009 /* Generate the symbols for any queued up type symbols we encountered
4010 while generating the type info for some originally used symbol.
4011 This might generate additional entries in the queue. Only when
4012 the nesting depth goes to 0 is this routine called. */
4014 void
4015 debug_flush_symbol_queue (void)
4017 int i;
4019 /* Make sure that additionally queued items are not flushed
4020 prematurely. */
4022 ++debug_nesting;
4024 for (i = 0; i < symbol_queue_index; ++i)
4026 /* If we pushed queued symbols then such symbols must be
4027 output no matter what anyone else says. Specifically,
4028 we need to make sure dbxout_symbol() thinks the symbol was
4029 used and also we need to override TYPE_DECL_SUPPRESS_DEBUG
4030 which may be set for outside reasons. */
4031 int saved_tree_used = TREE_USED (symbol_queue[i]);
4032 int saved_suppress_debug = TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]);
4033 TREE_USED (symbol_queue[i]) = 1;
4034 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = 0;
4036 #ifdef DBX_DEBUGGING_INFO
4037 dbxout_symbol (symbol_queue[i], 0);
4038 #endif
4040 TREE_USED (symbol_queue[i]) = saved_tree_used;
4041 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = saved_suppress_debug;
4044 symbol_queue_index = 0;
4045 --debug_nesting;
4048 /* Queue a type symbol needed as part of the definition of a decl
4049 symbol. These symbols are generated when debug_flush_symbol_queue()
4050 is called. */
4052 void
4053 debug_queue_symbol (tree decl)
4055 if (symbol_queue_index >= symbol_queue_size)
4057 symbol_queue_size += 10;
4058 symbol_queue = xrealloc (symbol_queue,
4059 symbol_queue_size * sizeof (tree));
4062 symbol_queue[symbol_queue_index++] = decl;
4065 /* Free symbol queue. */
4066 void
4067 debug_free_queue (void)
4069 if (symbol_queue)
4071 free (symbol_queue);
4072 symbol_queue = NULL;
4073 symbol_queue_size = 0;
4077 /* Turn the RTL into assembly. */
4078 static unsigned int
4079 rest_of_handle_final (void)
4081 rtx x;
4082 const char *fnname;
4084 /* Get the function's name, as described by its RTL. This may be
4085 different from the DECL_NAME name used in the source file. */
4087 x = DECL_RTL (current_function_decl);
4088 gcc_assert (MEM_P (x));
4089 x = XEXP (x, 0);
4090 gcc_assert (GET_CODE (x) == SYMBOL_REF);
4091 fnname = XSTR (x, 0);
4093 assemble_start_function (current_function_decl, fnname);
4094 final_start_function (get_insns (), asm_out_file, optimize);
4095 final (get_insns (), asm_out_file, optimize);
4096 final_end_function ();
4098 #ifdef TARGET_UNWIND_INFO
4099 /* ??? The IA-64 ".handlerdata" directive must be issued before
4100 the ".endp" directive that closes the procedure descriptor. */
4101 output_function_exception_table (fnname);
4102 #endif
4104 assemble_end_function (current_function_decl, fnname);
4106 #ifndef TARGET_UNWIND_INFO
4107 /* Otherwise, it feels unclean to switch sections in the middle. */
4108 output_function_exception_table (fnname);
4109 #endif
4111 user_defined_section_attribute = false;
4113 /* Free up reg info memory. */
4114 free_reg_info ();
4116 if (! quiet_flag)
4117 fflush (asm_out_file);
4119 /* Write DBX symbols if requested. */
4121 /* Note that for those inline functions where we don't initially
4122 know for certain that we will be generating an out-of-line copy,
4123 the first invocation of this routine (rest_of_compilation) will
4124 skip over this code by doing a `goto exit_rest_of_compilation;'.
4125 Later on, wrapup_global_declarations will (indirectly) call
4126 rest_of_compilation again for those inline functions that need
4127 to have out-of-line copies generated. During that call, we
4128 *will* be routed past here. */
4130 timevar_push (TV_SYMOUT);
4131 (*debug_hooks->function_decl) (current_function_decl);
4132 timevar_pop (TV_SYMOUT);
4133 if (DECL_STATIC_CONSTRUCTOR (current_function_decl)
4134 && targetm.have_ctors_dtors)
4135 targetm.asm_out.constructor (XEXP (DECL_RTL (current_function_decl), 0),
4136 decl_init_priority_lookup
4137 (current_function_decl));
4138 if (DECL_STATIC_DESTRUCTOR (current_function_decl)
4139 && targetm.have_ctors_dtors)
4140 targetm.asm_out.destructor (XEXP (DECL_RTL (current_function_decl), 0),
4141 decl_fini_priority_lookup
4142 (current_function_decl));
4143 return 0;
4146 struct tree_opt_pass pass_final =
4148 NULL, /* name */
4149 NULL, /* gate */
4150 rest_of_handle_final, /* execute */
4151 NULL, /* sub */
4152 NULL, /* next */
4153 0, /* static_pass_number */
4154 TV_FINAL, /* tv_id */
4155 0, /* properties_required */
4156 0, /* properties_provided */
4157 0, /* properties_destroyed */
4158 0, /* todo_flags_start */
4159 TODO_ggc_collect, /* todo_flags_finish */
4160 0 /* letter */
4164 static unsigned int
4165 rest_of_handle_shorten_branches (void)
4167 /* Shorten branches. */
4168 shorten_branches (get_insns ());
4169 return 0;
4172 struct tree_opt_pass pass_shorten_branches =
4174 "shorten", /* name */
4175 NULL, /* gate */
4176 rest_of_handle_shorten_branches, /* execute */
4177 NULL, /* sub */
4178 NULL, /* next */
4179 0, /* static_pass_number */
4180 TV_FINAL, /* tv_id */
4181 0, /* properties_required */
4182 0, /* properties_provided */
4183 0, /* properties_destroyed */
4184 0, /* todo_flags_start */
4185 TODO_dump_func, /* todo_flags_finish */
4186 0 /* letter */
4190 static unsigned int
4191 rest_of_clean_state (void)
4193 rtx insn, next;
4195 /* It is very important to decompose the RTL instruction chain here:
4196 debug information keeps pointing into CODE_LABEL insns inside the function
4197 body. If these remain pointing to the other insns, we end up preserving
4198 whole RTL chain and attached detailed debug info in memory. */
4199 for (insn = get_insns (); insn; insn = next)
4201 next = NEXT_INSN (insn);
4202 NEXT_INSN (insn) = NULL;
4203 PREV_INSN (insn) = NULL;
4206 /* In case the function was not output,
4207 don't leave any temporary anonymous types
4208 queued up for sdb output. */
4209 #ifdef SDB_DEBUGGING_INFO
4210 if (write_symbols == SDB_DEBUG)
4211 sdbout_types (NULL_TREE);
4212 #endif
4214 reload_completed = 0;
4215 epilogue_completed = 0;
4216 #ifdef STACK_REGS
4217 regstack_completed = 0;
4218 #endif
4220 /* Clear out the insn_length contents now that they are no
4221 longer valid. */
4222 init_insn_lengths ();
4224 /* Show no temporary slots allocated. */
4225 init_temp_slots ();
4227 free_bb_for_insn ();
4229 if (targetm.binds_local_p (current_function_decl))
4231 int pref = cfun->preferred_stack_boundary;
4232 if (cfun->stack_alignment_needed > cfun->preferred_stack_boundary)
4233 pref = cfun->stack_alignment_needed;
4234 cgraph_rtl_info (current_function_decl)->preferred_incoming_stack_boundary
4235 = pref;
4238 /* Make sure volatile mem refs aren't considered valid operands for
4239 arithmetic insns. We must call this here if this is a nested inline
4240 function, since the above code leaves us in the init_recog state,
4241 and the function context push/pop code does not save/restore volatile_ok.
4243 ??? Maybe it isn't necessary for expand_start_function to call this
4244 anymore if we do it here? */
4246 init_recog_no_volatile ();
4248 /* We're done with this function. Free up memory if we can. */
4249 free_after_parsing (cfun);
4250 free_after_compilation (cfun);
4251 return 0;
4254 struct tree_opt_pass pass_clean_state =
4256 NULL, /* name */
4257 NULL, /* gate */
4258 rest_of_clean_state, /* execute */
4259 NULL, /* sub */
4260 NULL, /* next */
4261 0, /* static_pass_number */
4262 TV_FINAL, /* tv_id */
4263 0, /* properties_required */
4264 0, /* properties_provided */
4265 PROP_rtl, /* properties_destroyed */
4266 0, /* todo_flags_start */
4267 0, /* todo_flags_finish */
4268 0 /* letter */