Add partial support for IA-64 unwind sections.
[official-gcc.git] / gcc / final.c
blob1d4666ed764040dc701eea657f93c7dc72bb9691
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 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This is the final pass of the compiler.
24 It looks at the rtl code for a function and outputs assembler code.
26 Call `final_start_function' to output the assembler code for function entry,
27 `final' to output assembler code for some RTL code,
28 `final_end_function' to output assembler code for function exit.
29 If a function is compiled in several pieces, each piece is
30 output separately with `final'.
32 Some optimizations are also done at this level.
33 Move instructions that were made unnecessary by good register allocation
34 are detected and omitted from the output. (Though most of these
35 are removed by the last jump pass.)
37 Instructions to set the condition codes are omitted when it can be
38 seen that the condition codes already had the desired values.
40 In some cases it is sufficient if the inherited condition codes
41 have related values, but this may require the following insn
42 (the one that tests the condition codes) to be modified.
44 The code for the function prologue and epilogue are generated
45 directly as assembler code by the macros FUNCTION_PROLOGUE and
46 FUNCTION_EPILOGUE. Those instructions never exist as rtl. */
48 #include "config.h"
49 #include "system.h"
51 #include "tree.h"
52 #include "rtl.h"
53 #include "tm_p.h"
54 #include "regs.h"
55 #include "insn-config.h"
56 #include "insn-flags.h"
57 #include "insn-attr.h"
58 #include "insn-codes.h"
59 #include "recog.h"
60 #include "conditions.h"
61 #include "flags.h"
62 #include "real.h"
63 #include "hard-reg-set.h"
64 #include "defaults.h"
65 #include "output.h"
66 #include "except.h"
67 #include "function.h"
68 #include "toplev.h"
69 #include "reload.h"
70 #include "intl.h"
72 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist. */
73 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
74 #include "dbxout.h"
75 #if defined (USG) || !defined (HAVE_STAB_H)
76 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
77 #else
78 #include <stab.h>
79 #endif
81 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
83 #ifndef ACCUMULATE_OUTGOING_ARGS
84 #define ACCUMULATE_OUTGOING_ARGS 0
85 #endif
87 #ifdef XCOFF_DEBUGGING_INFO
88 #include "xcoffout.h"
89 #endif
91 #ifdef DWARF_DEBUGGING_INFO
92 #include "dwarfout.h"
93 #endif
95 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
96 #include "dwarf2out.h"
97 #endif
99 #ifdef SDB_DEBUGGING_INFO
100 #include "sdbout.h"
101 #endif
103 /* .stabd code for line number. */
104 #ifndef N_SLINE
105 #define N_SLINE 0x44
106 #endif
108 /* .stabs code for included file name. */
109 #ifndef N_SOL
110 #define N_SOL 0x84
111 #endif
113 #ifndef INT_TYPE_SIZE
114 #define INT_TYPE_SIZE BITS_PER_WORD
115 #endif
117 #ifndef LONG_TYPE_SIZE
118 #define LONG_TYPE_SIZE BITS_PER_WORD
119 #endif
121 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
122 null default for it to save conditionalization later. */
123 #ifndef CC_STATUS_INIT
124 #define CC_STATUS_INIT
125 #endif
127 /* How to start an assembler comment. */
128 #ifndef ASM_COMMENT_START
129 #define ASM_COMMENT_START ";#"
130 #endif
132 /* Is the given character a logical line separator for the assembler? */
133 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
134 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
135 #endif
137 #ifndef JUMP_TABLES_IN_TEXT_SECTION
138 #define JUMP_TABLES_IN_TEXT_SECTION 0
139 #endif
141 /* Last insn processed by final_scan_insn. */
142 static rtx debug_insn = 0;
144 /* Line number of last NOTE. */
145 static int last_linenum;
147 /* Highest line number in current block. */
148 static int high_block_linenum;
150 /* Likewise for function. */
151 static int high_function_linenum;
153 /* Filename of last NOTE. */
154 static const char *last_filename;
156 /* Number of basic blocks seen so far;
157 used if profile_block_flag is set. */
158 static int count_basic_blocks;
160 /* Number of instrumented arcs when profile_arc_flag is set. */
161 extern int count_instrumented_arcs;
163 extern int length_unit_log; /* This is defined in insn-attrtab.c. */
165 /* Nonzero while outputting an `asm' with operands.
166 This means that inconsistencies are the user's fault, so don't abort.
167 The precise value is the insn being output, to pass to error_for_asm. */
168 static rtx this_is_asm_operands;
170 /* Number of operands of this insn, for an `asm' with operands. */
171 static unsigned int insn_noperands;
173 /* Compare optimization flag. */
175 static rtx last_ignored_compare = 0;
177 /* Flag indicating this insn is the start of a new basic block. */
179 static int new_block = 1;
181 /* Assign a unique number to each insn that is output.
182 This can be used to generate unique local labels. */
184 static int insn_counter = 0;
186 #ifdef HAVE_cc0
187 /* This variable contains machine-dependent flags (defined in tm.h)
188 set and examined by output routines
189 that describe how to interpret the condition codes properly. */
191 CC_STATUS cc_status;
193 /* During output of an insn, this contains a copy of cc_status
194 from before the insn. */
196 CC_STATUS cc_prev_status;
197 #endif
199 /* Indexed by hardware reg number, is 1 if that register is ever
200 used in the current function.
202 In life_analysis, or in stupid_life_analysis, this is set
203 up to record the hard regs used explicitly. Reload adds
204 in the hard regs used for holding pseudo regs. Final uses
205 it to generate the code in the function prologue and epilogue
206 to save and restore registers as needed. */
208 char regs_ever_live[FIRST_PSEUDO_REGISTER];
210 /* Nonzero means current function must be given a frame pointer.
211 Set in stmt.c if anything is allocated on the stack there.
212 Set in reload1.c if anything is allocated on the stack there. */
214 int frame_pointer_needed;
216 /* Assign unique numbers to labels generated for profiling. */
218 int profile_label_no;
220 /* Number of unmatched NOTE_INSN_BLOCK_BEG notes we have seen. */
222 static int block_depth;
224 /* Nonzero if have enabled APP processing of our assembler output. */
226 static int app_on;
228 /* If we are outputting an insn sequence, this contains the sequence rtx.
229 Zero otherwise. */
231 rtx final_sequence;
233 #ifdef ASSEMBLER_DIALECT
235 /* Number of the assembler dialect to use, starting at 0. */
236 static int dialect_number;
237 #endif
239 /* Indexed by line number, nonzero if there is a note for that line. */
241 static char *line_note_exists;
243 /* Linked list to hold line numbers for each basic block. */
245 struct bb_list {
246 struct bb_list *next; /* pointer to next basic block */
247 int line_num; /* line number */
248 int file_label_num; /* LPBC<n> label # for stored filename */
249 int func_label_num; /* LPBC<n> label # for stored function name */
252 static struct bb_list *bb_head = 0; /* Head of basic block list */
253 static struct bb_list **bb_tail = &bb_head; /* Ptr to store next bb ptr */
254 static int bb_file_label_num = -1; /* Current label # for file */
255 static int bb_func_label_num = -1; /* Current label # for func */
257 /* Linked list to hold the strings for each file and function name output. */
259 struct bb_str {
260 struct bb_str *next; /* pointer to next string */
261 const char *string; /* string */
262 int label_num; /* label number */
263 int length; /* string length */
266 static struct bb_str *sbb_head = 0; /* Head of string list. */
267 static struct bb_str **sbb_tail = &sbb_head; /* Ptr to store next bb str */
268 static int sbb_label_num = 0; /* Last label used */
270 #ifdef HAVE_ATTR_length
271 static int asm_insn_count PARAMS ((rtx));
272 #endif
273 static void profile_function PARAMS ((FILE *));
274 static void profile_after_prologue PARAMS ((FILE *));
275 static void add_bb PARAMS ((FILE *));
276 static int add_bb_string PARAMS ((const char *, int));
277 static void output_source_line PARAMS ((FILE *, rtx));
278 static rtx walk_alter_subreg PARAMS ((rtx));
279 static void output_asm_name PARAMS ((void));
280 static void output_operand PARAMS ((rtx, int));
281 #ifdef LEAF_REGISTERS
282 static void leaf_renumber_regs PARAMS ((rtx));
283 #endif
284 #ifdef HAVE_cc0
285 static int alter_cond PARAMS ((rtx));
286 #endif
287 #ifndef ADDR_VEC_ALIGN
288 static int final_addr_vec_align PARAMS ((rtx));
289 #endif
290 #ifdef HAVE_ATTR_length
291 static int align_fuzz PARAMS ((rtx, rtx, int, unsigned));
292 #endif
294 /* Initialize data in final at the beginning of a compilation. */
296 void
297 init_final (filename)
298 const char *filename ATTRIBUTE_UNUSED;
300 app_on = 0;
301 final_sequence = 0;
303 #ifdef ASSEMBLER_DIALECT
304 dialect_number = ASSEMBLER_DIALECT;
305 #endif
308 /* Called at end of source file,
309 to output the block-profiling table for this entire compilation. */
311 void
312 end_final (filename)
313 const char *filename;
315 int i;
317 if (profile_block_flag || profile_arc_flag)
319 char name[20];
320 int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
321 int size, rounded;
322 struct bb_list *ptr;
323 struct bb_str *sptr;
324 int long_bytes = LONG_TYPE_SIZE / BITS_PER_UNIT;
325 int pointer_bytes = POINTER_SIZE / BITS_PER_UNIT;
327 if (profile_block_flag)
328 size = long_bytes * count_basic_blocks;
329 else
330 size = long_bytes * count_instrumented_arcs;
331 rounded = size;
333 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
334 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
335 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
337 data_section ();
339 /* Output the main header, of 11 words:
340 0: 1 if this file is initialized, else 0.
341 1: address of file name (LPBX1).
342 2: address of table of counts (LPBX2).
343 3: number of counts in the table.
344 4: always 0, for compatibility with Sun.
346 The following are GNU extensions:
348 5: address of table of start addrs of basic blocks (LPBX3).
349 6: Number of bytes in this header.
350 7: address of table of function names (LPBX4).
351 8: address of table of line numbers (LPBX5) or 0.
352 9: address of table of file names (LPBX6) or 0.
353 10: space reserved for basic block profiling. */
355 ASM_OUTPUT_ALIGN (asm_out_file, align);
357 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
358 /* zero word */
359 assemble_integer (const0_rtx, long_bytes, 1);
361 /* address of filename */
362 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
363 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
365 /* address of count table */
366 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
367 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
369 /* count of the # of basic blocks or # of instrumented arcs */
370 if (profile_block_flag)
371 assemble_integer (GEN_INT (count_basic_blocks), long_bytes, 1);
372 else
373 assemble_integer (GEN_INT (count_instrumented_arcs), long_bytes,
376 /* zero word (link field) */
377 assemble_integer (const0_rtx, pointer_bytes, 1);
379 /* address of basic block start address table */
380 if (profile_block_flag)
382 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
383 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
386 else
387 assemble_integer (const0_rtx, pointer_bytes, 1);
389 /* byte count for extended structure. */
390 assemble_integer (GEN_INT (11 * UNITS_PER_WORD), long_bytes, 1);
392 /* address of function name table */
393 if (profile_block_flag)
395 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
396 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
399 else
400 assemble_integer (const0_rtx, pointer_bytes, 1);
402 /* address of line number and filename tables if debugging. */
403 if (write_symbols != NO_DEBUG && profile_block_flag)
405 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
406 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
407 pointer_bytes, 1);
408 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
409 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
410 pointer_bytes, 1);
412 else
414 assemble_integer (const0_rtx, pointer_bytes, 1);
415 assemble_integer (const0_rtx, pointer_bytes, 1);
418 /* space for extension ptr (link field) */
419 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
421 /* Output the file name changing the suffix to .d for Sun tcov
422 compatibility. */
423 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
425 char *cwd = getpwd ();
426 int len = strlen (filename) + strlen (cwd) + 1;
427 char *data_file = (char *) alloca (len + 4);
429 strcpy (data_file, cwd);
430 strcat (data_file, "/");
431 strcat (data_file, filename);
432 strip_off_ending (data_file, len);
433 if (profile_block_flag)
434 strcat (data_file, ".d");
435 else
436 strcat (data_file, ".da");
437 assemble_string (data_file, strlen (data_file) + 1);
440 /* Make space for the table of counts. */
441 if (size == 0)
443 /* Realign data section. */
444 ASM_OUTPUT_ALIGN (asm_out_file, align);
445 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
446 if (size != 0)
447 assemble_zeros (size);
449 else
451 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
452 #ifdef ASM_OUTPUT_SHARED_LOCAL
453 if (flag_shared_data)
454 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
455 else
456 #endif
457 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
458 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
459 BIGGEST_ALIGNMENT);
460 #else
461 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
462 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
463 BIGGEST_ALIGNMENT);
464 #else
465 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
466 #endif
467 #endif
470 /* Output any basic block strings */
471 if (profile_block_flag)
473 readonly_data_section ();
474 if (sbb_head)
476 ASM_OUTPUT_ALIGN (asm_out_file, align);
477 for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
479 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC",
480 sptr->label_num);
481 assemble_string (sptr->string, sptr->length);
486 /* Output the table of addresses. */
487 if (profile_block_flag)
489 /* Realign in new section */
490 ASM_OUTPUT_ALIGN (asm_out_file, align);
491 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
492 for (i = 0; i < count_basic_blocks; i++)
494 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
495 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
496 pointer_bytes, 1);
500 /* Output the table of function names. */
501 if (profile_block_flag)
503 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
504 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
506 if (ptr->func_label_num >= 0)
508 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
509 ptr->func_label_num);
510 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
511 pointer_bytes, 1);
513 else
514 assemble_integer (const0_rtx, pointer_bytes, 1);
517 for ( ; i < count_basic_blocks; i++)
518 assemble_integer (const0_rtx, pointer_bytes, 1);
521 if (write_symbols != NO_DEBUG && profile_block_flag)
523 /* Output the table of line numbers. */
524 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
525 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
526 assemble_integer (GEN_INT (ptr->line_num), long_bytes, 1);
528 for ( ; i < count_basic_blocks; i++)
529 assemble_integer (const0_rtx, long_bytes, 1);
531 /* Output the table of file names. */
532 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
533 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
535 if (ptr->file_label_num >= 0)
537 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
538 ptr->file_label_num);
539 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
540 pointer_bytes, 1);
542 else
543 assemble_integer (const0_rtx, pointer_bytes, 1);
546 for ( ; i < count_basic_blocks; i++)
547 assemble_integer (const0_rtx, pointer_bytes, 1);
550 /* End with the address of the table of addresses,
551 so we can find it easily, as the last word in the file's text. */
552 if (profile_block_flag)
554 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
555 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
561 /* Enable APP processing of subsequent output.
562 Used before the output from an `asm' statement. */
564 void
565 app_enable ()
567 if (! app_on)
569 fputs (ASM_APP_ON, asm_out_file);
570 app_on = 1;
574 /* Disable APP processing of subsequent output.
575 Called from varasm.c before most kinds of output. */
577 void
578 app_disable ()
580 if (app_on)
582 fputs (ASM_APP_OFF, asm_out_file);
583 app_on = 0;
587 /* Return the number of slots filled in the current
588 delayed branch sequence (we don't count the insn needing the
589 delay slot). Zero if not in a delayed branch sequence. */
591 #ifdef DELAY_SLOTS
593 dbr_sequence_length ()
595 if (final_sequence != 0)
596 return XVECLEN (final_sequence, 0) - 1;
597 else
598 return 0;
600 #endif
602 /* The next two pages contain routines used to compute the length of an insn
603 and to shorten branches. */
605 /* Arrays for insn lengths, and addresses. The latter is referenced by
606 `insn_current_length'. */
608 static short *insn_lengths;
609 int *insn_addresses;
611 /* Max uid for which the above arrays are valid. */
612 static int insn_lengths_max_uid;
614 /* Address of insn being processed. Used by `insn_current_length'. */
615 int insn_current_address;
617 /* Address of insn being processed in previous iteration. */
618 int insn_last_address;
620 /* konwn invariant alignment of insn being processed. */
621 int insn_current_align;
623 /* After shorten_branches, for any insn, uid_align[INSN_UID (insn)]
624 gives the next following alignment insn that increases the known
625 alignment, or NULL_RTX if there is no such insn.
626 For any alignment obtained this way, we can again index uid_align with
627 its uid to obtain the next following align that in turn increases the
628 alignment, till we reach NULL_RTX; the sequence obtained this way
629 for each insn we'll call the alignment chain of this insn in the following
630 comments. */
632 struct label_alignment {
633 short alignment;
634 short max_skip;
637 static rtx *uid_align;
638 static int *uid_shuid;
639 static struct label_alignment *label_align;
641 /* Indicate that branch shortening hasn't yet been done. */
643 void
644 init_insn_lengths ()
646 if (label_align)
648 free (label_align);
649 label_align = 0;
651 if (uid_shuid)
653 free (uid_shuid);
654 uid_shuid = 0;
656 if (insn_lengths)
658 free (insn_lengths);
659 insn_lengths = 0;
660 insn_lengths_max_uid = 0;
662 if (insn_addresses)
664 free (insn_addresses);
665 insn_addresses = 0;
667 if (uid_align)
669 free (uid_align);
670 uid_align = 0;
674 /* Obtain the current length of an insn. If branch shortening has been done,
675 get its actual length. Otherwise, get its maximum length. */
678 get_attr_length (insn)
679 rtx insn ATTRIBUTE_UNUSED;
681 #ifdef HAVE_ATTR_length
682 rtx body;
683 int i;
684 int length = 0;
686 if (insn_lengths_max_uid > INSN_UID (insn))
687 return insn_lengths[INSN_UID (insn)];
688 else
689 switch (GET_CODE (insn))
691 case NOTE:
692 case BARRIER:
693 case CODE_LABEL:
694 return 0;
696 case CALL_INSN:
697 length = insn_default_length (insn);
698 break;
700 case JUMP_INSN:
701 body = PATTERN (insn);
702 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
704 /* Alignment is machine-dependent and should be handled by
705 ADDR_VEC_ALIGN. */
707 else
708 length = insn_default_length (insn);
709 break;
711 case INSN:
712 body = PATTERN (insn);
713 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
714 return 0;
716 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
717 length = asm_insn_count (body) * insn_default_length (insn);
718 else if (GET_CODE (body) == SEQUENCE)
719 for (i = 0; i < XVECLEN (body, 0); i++)
720 length += get_attr_length (XVECEXP (body, 0, i));
721 else
722 length = insn_default_length (insn);
723 break;
725 default:
726 break;
729 #ifdef ADJUST_INSN_LENGTH
730 ADJUST_INSN_LENGTH (insn, length);
731 #endif
732 return length;
733 #else /* not HAVE_ATTR_length */
734 return 0;
735 #endif /* not HAVE_ATTR_length */
738 /* Code to handle alignment inside shorten_branches. */
740 /* Here is an explanation how the algorithm in align_fuzz can give
741 proper results:
743 Call a sequence of instructions beginning with alignment point X
744 and continuing until the next alignment point `block X'. When `X'
745 is used in an expression, it means the alignment value of the
746 alignment point.
748 Call the distance between the start of the first insn of block X, and
749 the end of the last insn of block X `IX', for the `inner size of X'.
750 This is clearly the sum of the instruction lengths.
752 Likewise with the next alignment-delimited block following X, which we
753 shall call block Y.
755 Call the distance between the start of the first insn of block X, and
756 the start of the first insn of block Y `OX', for the `outer size of X'.
758 The estimated padding is then OX - IX.
760 OX can be safely estimated as
762 if (X >= Y)
763 OX = round_up(IX, Y)
764 else
765 OX = round_up(IX, X) + Y - X
767 Clearly est(IX) >= real(IX), because that only depends on the
768 instruction lengths, and those being overestimated is a given.
770 Clearly round_up(foo, Z) >= round_up(bar, Z) if foo >= bar, so
771 we needn't worry about that when thinking about OX.
773 When X >= Y, the alignment provided by Y adds no uncertainty factor
774 for branch ranges starting before X, so we can just round what we have.
775 But when X < Y, we don't know anything about the, so to speak,
776 `middle bits', so we have to assume the worst when aligning up from an
777 address mod X to one mod Y, which is Y - X. */
779 #ifndef LABEL_ALIGN
780 #define LABEL_ALIGN(LABEL) align_labels_log
781 #endif
783 #ifndef LABEL_ALIGN_MAX_SKIP
784 #define LABEL_ALIGN_MAX_SKIP (align_labels-1)
785 #endif
787 #ifndef LOOP_ALIGN
788 #define LOOP_ALIGN(LABEL) align_loops_log
789 #endif
791 #ifndef LOOP_ALIGN_MAX_SKIP
792 #define LOOP_ALIGN_MAX_SKIP (align_loops-1)
793 #endif
795 #ifndef LABEL_ALIGN_AFTER_BARRIER
796 #define LABEL_ALIGN_AFTER_BARRIER(LABEL) align_jumps_log
797 #endif
799 #ifndef LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP
800 #define LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP (align_jumps-1)
801 #endif
803 #ifndef ADDR_VEC_ALIGN
804 static int
805 final_addr_vec_align (addr_vec)
806 rtx addr_vec;
808 int align = exact_log2 (GET_MODE_SIZE (GET_MODE (PATTERN (addr_vec))));
810 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
811 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
812 return align;
815 #define ADDR_VEC_ALIGN(ADDR_VEC) final_addr_vec_align (ADDR_VEC)
816 #endif
818 #ifndef INSN_LENGTH_ALIGNMENT
819 #define INSN_LENGTH_ALIGNMENT(INSN) length_unit_log
820 #endif
822 #define INSN_SHUID(INSN) (uid_shuid[INSN_UID (INSN)])
824 static int min_labelno, max_labelno;
826 #define LABEL_TO_ALIGNMENT(LABEL) \
827 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].alignment)
829 #define LABEL_TO_MAX_SKIP(LABEL) \
830 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].max_skip)
832 /* For the benefit of port specific code do this also as a function. */
834 label_to_alignment (label)
835 rtx label;
837 return LABEL_TO_ALIGNMENT (label);
840 #ifdef HAVE_ATTR_length
841 /* The differences in addresses
842 between a branch and its target might grow or shrink depending on
843 the alignment the start insn of the range (the branch for a forward
844 branch or the label for a backward branch) starts out on; if these
845 differences are used naively, they can even oscillate infinitely.
846 We therefore want to compute a 'worst case' address difference that
847 is independent of the alignment the start insn of the range end
848 up on, and that is at least as large as the actual difference.
849 The function align_fuzz calculates the amount we have to add to the
850 naively computed difference, by traversing the part of the alignment
851 chain of the start insn of the range that is in front of the end insn
852 of the range, and considering for each alignment the maximum amount
853 that it might contribute to a size increase.
855 For casesi tables, we also want to know worst case minimum amounts of
856 address difference, in case a machine description wants to introduce
857 some common offset that is added to all offsets in a table.
858 For this purpose, align_fuzz with a growth argument of 0 comuptes the
859 appropriate adjustment. */
862 /* Compute the maximum delta by which the difference of the addresses of
863 START and END might grow / shrink due to a different address for start
864 which changes the size of alignment insns between START and END.
865 KNOWN_ALIGN_LOG is the alignment known for START.
866 GROWTH should be ~0 if the objective is to compute potential code size
867 increase, and 0 if the objective is to compute potential shrink.
868 The return value is undefined for any other value of GROWTH. */
869 static int
870 align_fuzz (start, end, known_align_log, growth)
871 rtx start, end;
872 int known_align_log;
873 unsigned growth;
875 int uid = INSN_UID (start);
876 rtx align_label;
877 int known_align = 1 << known_align_log;
878 int end_shuid = INSN_SHUID (end);
879 int fuzz = 0;
881 for (align_label = uid_align[uid]; align_label; align_label = uid_align[uid])
883 int align_addr, new_align;
885 uid = INSN_UID (align_label);
886 align_addr = insn_addresses[uid] - insn_lengths[uid];
887 if (uid_shuid[uid] > end_shuid)
888 break;
889 known_align_log = LABEL_TO_ALIGNMENT (align_label);
890 new_align = 1 << known_align_log;
891 if (new_align < known_align)
892 continue;
893 fuzz += (-align_addr ^ growth) & (new_align - known_align);
894 known_align = new_align;
896 return fuzz;
899 /* Compute a worst-case reference address of a branch so that it
900 can be safely used in the presence of aligned labels. Since the
901 size of the branch itself is unknown, the size of the branch is
902 not included in the range. I.e. for a forward branch, the reference
903 address is the end address of the branch as known from the previous
904 branch shortening pass, minus a value to account for possible size
905 increase due to alignment. For a backward branch, it is the start
906 address of the branch as known from the current pass, plus a value
907 to account for possible size increase due to alignment.
908 NB.: Therefore, the maximum offset allowed for backward branches needs
909 to exclude the branch size. */
911 insn_current_reference_address (branch)
912 rtx branch;
914 rtx dest;
915 rtx seq = NEXT_INSN (PREV_INSN (branch));
916 int seq_uid = INSN_UID (seq);
917 if (GET_CODE (branch) != JUMP_INSN)
918 /* This can happen for example on the PA; the objective is to know the
919 offset to address something in front of the start of the function.
920 Thus, we can treat it like a backward branch.
921 We assume here that FUNCTION_BOUNDARY / BITS_PER_UNIT is larger than
922 any alignment we'd encounter, so we skip the call to align_fuzz. */
923 return insn_current_address;
924 dest = JUMP_LABEL (branch);
925 /* BRANCH has no proper alignment chain set, so use SEQ. */
926 if (INSN_SHUID (branch) < INSN_SHUID (dest))
928 /* Forward branch. */
929 return (insn_last_address + insn_lengths[seq_uid]
930 - align_fuzz (seq, dest, length_unit_log, ~0));
932 else
934 /* Backward branch. */
935 return (insn_current_address
936 + align_fuzz (dest, seq, length_unit_log, ~0));
939 #endif /* HAVE_ATTR_length */
941 /* Make a pass over all insns and compute their actual lengths by shortening
942 any branches of variable length if possible. */
944 /* Give a default value for the lowest address in a function. */
946 #ifndef FIRST_INSN_ADDRESS
947 #define FIRST_INSN_ADDRESS 0
948 #endif
950 /* shorten_branches might be called multiple times: for example, the SH
951 port splits out-of-range conditional branches in MACHINE_DEPENDENT_REORG.
952 In order to do this, it needs proper length information, which it obtains
953 by calling shorten_branches. This cannot be collapsed with
954 shorten_branches itself into a single pass unless we also want to intergate
955 reorg.c, since the branch splitting exposes new instructions with delay
956 slots. */
958 void
959 shorten_branches (first)
960 rtx first ATTRIBUTE_UNUSED;
962 rtx insn;
963 int max_uid;
964 int i;
965 int max_log;
966 int max_skip;
967 #ifdef HAVE_ATTR_length
968 #define MAX_CODE_ALIGN 16
969 rtx seq;
970 int something_changed = 1;
971 char *varying_length;
972 rtx body;
973 int uid;
974 rtx align_tab[MAX_CODE_ALIGN];
976 /* In order to make sure that all instructions have valid length info,
977 we must split them before we compute the address/length info. */
979 for (insn = NEXT_INSN (first); insn; insn = NEXT_INSN (insn))
980 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
982 rtx old = insn;
983 /* Don't split the insn if it has been deleted. */
984 if (! INSN_DELETED_P (old))
985 insn = try_split (PATTERN (old), old, 1);
986 /* When not optimizing, the old insn will be still left around
987 with only the 'deleted' bit set. Transform it into a note
988 to avoid confusion of subsequent processing. */
989 if (INSN_DELETED_P (old))
991 PUT_CODE (old , NOTE);
992 NOTE_LINE_NUMBER (old) = NOTE_INSN_DELETED;
993 NOTE_SOURCE_FILE (old) = 0;
996 #endif
998 /* We must do some computations even when not actually shortening, in
999 order to get the alignment information for the labels. */
1001 init_insn_lengths ();
1003 /* Compute maximum UID and allocate label_align / uid_shuid. */
1004 max_uid = get_max_uid ();
1006 max_labelno = max_label_num ();
1007 min_labelno = get_first_label_num ();
1008 label_align = (struct label_alignment *)
1009 xcalloc ((max_labelno - min_labelno + 1), sizeof (struct label_alignment));
1011 uid_shuid = (int *) xmalloc (max_uid * sizeof *uid_shuid);
1013 /* Initialize label_align and set up uid_shuid to be strictly
1014 monotonically rising with insn order. */
1015 /* We use max_log here to keep track of the maximum alignment we want to
1016 impose on the next CODE_LABEL (or the current one if we are processing
1017 the CODE_LABEL itself). */
1019 max_log = 0;
1020 max_skip = 0;
1022 for (insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn))
1024 int log;
1026 INSN_SHUID (insn) = i++;
1027 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1029 /* reorg might make the first insn of a loop being run once only,
1030 and delete the label in front of it. Then we want to apply
1031 the loop alignment to the new label created by reorg, which
1032 is separated by the former loop start insn from the
1033 NOTE_INSN_LOOP_BEG. */
1035 else if (GET_CODE (insn) == CODE_LABEL)
1037 rtx next;
1039 log = LABEL_ALIGN (insn);
1040 if (max_log < log)
1042 max_log = log;
1043 max_skip = LABEL_ALIGN_MAX_SKIP;
1045 next = NEXT_INSN (insn);
1046 /* ADDR_VECs only take room if read-only data goes into the text
1047 section. */
1048 if (JUMP_TABLES_IN_TEXT_SECTION
1049 #if !defined(READONLY_DATA_SECTION)
1050 || 1
1051 #endif
1053 if (next && GET_CODE (next) == JUMP_INSN)
1055 rtx nextbody = PATTERN (next);
1056 if (GET_CODE (nextbody) == ADDR_VEC
1057 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1059 log = ADDR_VEC_ALIGN (next);
1060 if (max_log < log)
1062 max_log = log;
1063 max_skip = LABEL_ALIGN_MAX_SKIP;
1067 LABEL_TO_ALIGNMENT (insn) = max_log;
1068 LABEL_TO_MAX_SKIP (insn) = max_skip;
1069 max_log = 0;
1070 max_skip = 0;
1072 else if (GET_CODE (insn) == BARRIER)
1074 rtx label;
1076 for (label = insn; label && GET_RTX_CLASS (GET_CODE (label)) != 'i';
1077 label = NEXT_INSN (label))
1078 if (GET_CODE (label) == CODE_LABEL)
1080 log = LABEL_ALIGN_AFTER_BARRIER (insn);
1081 if (max_log < log)
1083 max_log = log;
1084 max_skip = LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP;
1086 break;
1089 /* Again, we allow NOTE_INSN_LOOP_BEG - INSN - CODE_LABEL
1090 sequences in order to handle reorg output efficiently. */
1091 else if (GET_CODE (insn) == NOTE
1092 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
1094 rtx label;
1095 int nest = 0;
1097 /* Search for the label that starts the loop.
1098 Don't skip past the end of the loop, since that could
1099 lead to putting an alignment where it does not belong.
1100 However, a label after a nested (non-)loop would be OK. */
1101 for (label = insn; label; label = NEXT_INSN (label))
1103 if (GET_CODE (label) == NOTE
1104 && NOTE_LINE_NUMBER (label) == NOTE_INSN_LOOP_BEG)
1105 nest++;
1106 else if (GET_CODE (label) == NOTE
1107 && NOTE_LINE_NUMBER (label) == NOTE_INSN_LOOP_END
1108 && --nest == 0)
1109 break;
1110 else if (GET_CODE (label) == CODE_LABEL)
1112 log = LOOP_ALIGN (label);
1113 if (max_log < log)
1115 max_log = log;
1116 max_skip = LOOP_ALIGN_MAX_SKIP;
1118 break;
1122 else
1123 continue;
1125 #ifdef HAVE_ATTR_length
1127 /* Allocate the rest of the arrays. */
1128 insn_lengths = (short *) xmalloc (max_uid * sizeof (short));
1129 insn_lengths_max_uid = max_uid;
1130 /* Syntax errors can lead to labels being outside of the main insn stream.
1131 Initialize insn_addresses, so that we get reproducible results. */
1132 insn_addresses = (int *) xcalloc (max_uid, sizeof (int));
1134 varying_length = (char *) xcalloc (max_uid, sizeof (char));
1136 /* Initialize uid_align. We scan instructions
1137 from end to start, and keep in align_tab[n] the last seen insn
1138 that does an alignment of at least n+1, i.e. the successor
1139 in the alignment chain for an insn that does / has a known
1140 alignment of n. */
1141 uid_align = (rtx *) xcalloc (max_uid, sizeof *uid_align);
1143 for (i = MAX_CODE_ALIGN; --i >= 0; )
1144 align_tab[i] = NULL_RTX;
1145 seq = get_last_insn ();
1146 for (; seq; seq = PREV_INSN (seq))
1148 int uid = INSN_UID (seq);
1149 int log;
1150 log = (GET_CODE (seq) == CODE_LABEL ? LABEL_TO_ALIGNMENT (seq) : 0);
1151 uid_align[uid] = align_tab[0];
1152 if (log)
1154 /* Found an alignment label. */
1155 uid_align[uid] = align_tab[log];
1156 for (i = log - 1; i >= 0; i--)
1157 align_tab[i] = seq;
1160 #ifdef CASE_VECTOR_SHORTEN_MODE
1161 if (optimize)
1163 /* Look for ADDR_DIFF_VECs, and initialize their minimum and maximum
1164 label fields. */
1166 int min_shuid = INSN_SHUID (get_insns ()) - 1;
1167 int max_shuid = INSN_SHUID (get_last_insn ()) + 1;
1168 int rel;
1170 for (insn = first; insn != 0; insn = NEXT_INSN (insn))
1172 rtx min_lab = NULL_RTX, max_lab = NULL_RTX, pat;
1173 int len, i, min, max, insn_shuid;
1174 int min_align;
1175 addr_diff_vec_flags flags;
1177 if (GET_CODE (insn) != JUMP_INSN
1178 || GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
1179 continue;
1180 pat = PATTERN (insn);
1181 len = XVECLEN (pat, 1);
1182 if (len <= 0)
1183 abort ();
1184 min_align = MAX_CODE_ALIGN;
1185 for (min = max_shuid, max = min_shuid, i = len - 1; i >= 0; i--)
1187 rtx lab = XEXP (XVECEXP (pat, 1, i), 0);
1188 int shuid = INSN_SHUID (lab);
1189 if (shuid < min)
1191 min = shuid;
1192 min_lab = lab;
1194 if (shuid > max)
1196 max = shuid;
1197 max_lab = lab;
1199 if (min_align > LABEL_TO_ALIGNMENT (lab))
1200 min_align = LABEL_TO_ALIGNMENT (lab);
1202 XEXP (pat, 2) = gen_rtx_LABEL_REF (VOIDmode, min_lab);
1203 XEXP (pat, 3) = gen_rtx_LABEL_REF (VOIDmode, max_lab);
1204 insn_shuid = INSN_SHUID (insn);
1205 rel = INSN_SHUID (XEXP (XEXP (pat, 0), 0));
1206 flags.min_align = min_align;
1207 flags.base_after_vec = rel > insn_shuid;
1208 flags.min_after_vec = min > insn_shuid;
1209 flags.max_after_vec = max > insn_shuid;
1210 flags.min_after_base = min > rel;
1211 flags.max_after_base = max > rel;
1212 ADDR_DIFF_VEC_FLAGS (pat) = flags;
1215 #endif /* CASE_VECTOR_SHORTEN_MODE */
1218 /* Compute initial lengths, addresses, and varying flags for each insn. */
1219 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1220 insn != 0;
1221 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
1223 uid = INSN_UID (insn);
1225 insn_lengths[uid] = 0;
1227 if (GET_CODE (insn) == CODE_LABEL)
1229 int log = LABEL_TO_ALIGNMENT (insn);
1230 if (log)
1232 int align = 1 << log;
1233 int new_address = (insn_current_address + align - 1) & -align;
1234 insn_lengths[uid] = new_address - insn_current_address;
1235 insn_current_address = new_address;
1239 insn_addresses[uid] = insn_current_address;
1241 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
1242 || GET_CODE (insn) == CODE_LABEL)
1243 continue;
1244 if (INSN_DELETED_P (insn))
1245 continue;
1247 body = PATTERN (insn);
1248 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1250 /* This only takes room if read-only data goes into the text
1251 section. */
1252 if (JUMP_TABLES_IN_TEXT_SECTION
1253 #if !defined(READONLY_DATA_SECTION)
1254 || 1
1255 #endif
1257 insn_lengths[uid] = (XVECLEN (body,
1258 GET_CODE (body) == ADDR_DIFF_VEC)
1259 * GET_MODE_SIZE (GET_MODE (body)));
1260 /* Alignment is handled by ADDR_VEC_ALIGN. */
1262 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
1263 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
1264 else if (GET_CODE (body) == SEQUENCE)
1266 int i;
1267 int const_delay_slots;
1268 #ifdef DELAY_SLOTS
1269 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
1270 #else
1271 const_delay_slots = 0;
1272 #endif
1273 /* Inside a delay slot sequence, we do not do any branch shortening
1274 if the shortening could change the number of delay slots
1275 of the branch. */
1276 for (i = 0; i < XVECLEN (body, 0); i++)
1278 rtx inner_insn = XVECEXP (body, 0, i);
1279 int inner_uid = INSN_UID (inner_insn);
1280 int inner_length;
1282 if (GET_CODE (body) == ASM_INPUT
1283 || asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
1284 inner_length = (asm_insn_count (PATTERN (inner_insn))
1285 * insn_default_length (inner_insn));
1286 else
1287 inner_length = insn_default_length (inner_insn);
1289 insn_lengths[inner_uid] = inner_length;
1290 if (const_delay_slots)
1292 if ((varying_length[inner_uid]
1293 = insn_variable_length_p (inner_insn)) != 0)
1294 varying_length[uid] = 1;
1295 insn_addresses[inner_uid] = (insn_current_address +
1296 insn_lengths[uid]);
1298 else
1299 varying_length[inner_uid] = 0;
1300 insn_lengths[uid] += inner_length;
1303 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
1305 insn_lengths[uid] = insn_default_length (insn);
1306 varying_length[uid] = insn_variable_length_p (insn);
1309 /* If needed, do any adjustment. */
1310 #ifdef ADJUST_INSN_LENGTH
1311 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
1312 if (insn_lengths[uid] < 0)
1313 fatal_insn ("Negative insn length", insn);
1314 #endif
1317 /* Now loop over all the insns finding varying length insns. For each,
1318 get the current insn length. If it has changed, reflect the change.
1319 When nothing changes for a full pass, we are done. */
1321 while (something_changed)
1323 something_changed = 0;
1324 insn_current_align = MAX_CODE_ALIGN - 1;
1325 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1326 insn != 0;
1327 insn = NEXT_INSN (insn))
1329 int new_length;
1330 #ifdef ADJUST_INSN_LENGTH
1331 int tmp_length;
1332 #endif
1333 int length_align;
1335 uid = INSN_UID (insn);
1337 if (GET_CODE (insn) == CODE_LABEL)
1339 int log = LABEL_TO_ALIGNMENT (insn);
1340 if (log > insn_current_align)
1342 int align = 1 << log;
1343 int new_address= (insn_current_address + align - 1) & -align;
1344 insn_lengths[uid] = new_address - insn_current_address;
1345 insn_current_align = log;
1346 insn_current_address = new_address;
1348 else
1349 insn_lengths[uid] = 0;
1350 insn_addresses[uid] = insn_current_address;
1351 continue;
1354 length_align = INSN_LENGTH_ALIGNMENT (insn);
1355 if (length_align < insn_current_align)
1356 insn_current_align = length_align;
1358 insn_last_address = insn_addresses[uid];
1359 insn_addresses[uid] = insn_current_address;
1361 #ifdef CASE_VECTOR_SHORTEN_MODE
1362 if (optimize && GET_CODE (insn) == JUMP_INSN
1363 && GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
1365 rtx body = PATTERN (insn);
1366 int old_length = insn_lengths[uid];
1367 rtx rel_lab = XEXP (XEXP (body, 0), 0);
1368 rtx min_lab = XEXP (XEXP (body, 2), 0);
1369 rtx max_lab = XEXP (XEXP (body, 3), 0);
1370 addr_diff_vec_flags flags = ADDR_DIFF_VEC_FLAGS (body);
1371 int rel_addr = insn_addresses[INSN_UID (rel_lab)];
1372 int min_addr = insn_addresses[INSN_UID (min_lab)];
1373 int max_addr = insn_addresses[INSN_UID (max_lab)];
1374 rtx prev;
1375 int rel_align = 0;
1377 /* Try to find a known alignment for rel_lab. */
1378 for (prev = rel_lab;
1379 prev
1380 && ! insn_lengths[INSN_UID (prev)]
1381 && ! (varying_length[INSN_UID (prev)] & 1);
1382 prev = PREV_INSN (prev))
1383 if (varying_length[INSN_UID (prev)] & 2)
1385 rel_align = LABEL_TO_ALIGNMENT (prev);
1386 break;
1389 /* See the comment on addr_diff_vec_flags in rtl.h for the
1390 meaning of the flags values. base: REL_LAB vec: INSN */
1391 /* Anything after INSN has still addresses from the last
1392 pass; adjust these so that they reflect our current
1393 estimate for this pass. */
1394 if (flags.base_after_vec)
1395 rel_addr += insn_current_address - insn_last_address;
1396 if (flags.min_after_vec)
1397 min_addr += insn_current_address - insn_last_address;
1398 if (flags.max_after_vec)
1399 max_addr += insn_current_address - insn_last_address;
1400 /* We want to know the worst case, i.e. lowest possible value
1401 for the offset of MIN_LAB. If MIN_LAB is after REL_LAB,
1402 its offset is positive, and we have to be wary of code shrink;
1403 otherwise, it is negative, and we have to be vary of code
1404 size increase. */
1405 if (flags.min_after_base)
1407 /* If INSN is between REL_LAB and MIN_LAB, the size
1408 changes we are about to make can change the alignment
1409 within the observed offset, therefore we have to break
1410 it up into two parts that are independent. */
1411 if (! flags.base_after_vec && flags.min_after_vec)
1413 min_addr -= align_fuzz (rel_lab, insn, rel_align, 0);
1414 min_addr -= align_fuzz (insn, min_lab, 0, 0);
1416 else
1417 min_addr -= align_fuzz (rel_lab, min_lab, rel_align, 0);
1419 else
1421 if (flags.base_after_vec && ! flags.min_after_vec)
1423 min_addr -= align_fuzz (min_lab, insn, 0, ~0);
1424 min_addr -= align_fuzz (insn, rel_lab, 0, ~0);
1426 else
1427 min_addr -= align_fuzz (min_lab, rel_lab, 0, ~0);
1429 /* Likewise, determine the highest lowest possible value
1430 for the offset of MAX_LAB. */
1431 if (flags.max_after_base)
1433 if (! flags.base_after_vec && flags.max_after_vec)
1435 max_addr += align_fuzz (rel_lab, insn, rel_align, ~0);
1436 max_addr += align_fuzz (insn, max_lab, 0, ~0);
1438 else
1439 max_addr += align_fuzz (rel_lab, max_lab, rel_align, ~0);
1441 else
1443 if (flags.base_after_vec && ! flags.max_after_vec)
1445 max_addr += align_fuzz (max_lab, insn, 0, 0);
1446 max_addr += align_fuzz (insn, rel_lab, 0, 0);
1448 else
1449 max_addr += align_fuzz (max_lab, rel_lab, 0, 0);
1451 PUT_MODE (body, CASE_VECTOR_SHORTEN_MODE (min_addr - rel_addr,
1452 max_addr - rel_addr,
1453 body));
1454 if (JUMP_TABLES_IN_TEXT_SECTION
1455 #if !defined(READONLY_DATA_SECTION)
1456 || 1
1457 #endif
1460 insn_lengths[uid]
1461 = (XVECLEN (body, 1) * GET_MODE_SIZE (GET_MODE (body)));
1462 insn_current_address += insn_lengths[uid];
1463 if (insn_lengths[uid] != old_length)
1464 something_changed = 1;
1467 continue;
1469 #endif /* CASE_VECTOR_SHORTEN_MODE */
1471 if (! (varying_length[uid]))
1473 insn_current_address += insn_lengths[uid];
1474 continue;
1476 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
1478 int i;
1480 body = PATTERN (insn);
1481 new_length = 0;
1482 for (i = 0; i < XVECLEN (body, 0); i++)
1484 rtx inner_insn = XVECEXP (body, 0, i);
1485 int inner_uid = INSN_UID (inner_insn);
1486 int inner_length;
1488 insn_addresses[inner_uid] = insn_current_address;
1490 /* insn_current_length returns 0 for insns with a
1491 non-varying length. */
1492 if (! varying_length[inner_uid])
1493 inner_length = insn_lengths[inner_uid];
1494 else
1495 inner_length = insn_current_length (inner_insn);
1497 if (inner_length != insn_lengths[inner_uid])
1499 insn_lengths[inner_uid] = inner_length;
1500 something_changed = 1;
1502 insn_current_address += insn_lengths[inner_uid];
1503 new_length += inner_length;
1506 else
1508 new_length = insn_current_length (insn);
1509 insn_current_address += new_length;
1512 #ifdef ADJUST_INSN_LENGTH
1513 /* If needed, do any adjustment. */
1514 tmp_length = new_length;
1515 ADJUST_INSN_LENGTH (insn, new_length);
1516 insn_current_address += (new_length - tmp_length);
1517 #endif
1519 if (new_length != insn_lengths[uid])
1521 insn_lengths[uid] = new_length;
1522 something_changed = 1;
1525 /* For a non-optimizing compile, do only a single pass. */
1526 if (!optimize)
1527 break;
1530 free (varying_length);
1532 #endif /* HAVE_ATTR_length */
1535 #ifdef HAVE_ATTR_length
1536 /* Given the body of an INSN known to be generated by an ASM statement, return
1537 the number of machine instructions likely to be generated for this insn.
1538 This is used to compute its length. */
1540 static int
1541 asm_insn_count (body)
1542 rtx body;
1544 const char *template;
1545 int count = 1;
1547 if (GET_CODE (body) == ASM_INPUT)
1548 template = XSTR (body, 0);
1549 else
1550 template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
1551 NULL_PTR, NULL_PTR);
1553 for ( ; *template; template++)
1554 if (IS_ASM_LOGICAL_LINE_SEPARATOR(*template) || *template == '\n')
1555 count++;
1557 return count;
1559 #endif
1561 /* Output assembler code for the start of a function,
1562 and initialize some of the variables in this file
1563 for the new function. The label for the function and associated
1564 assembler pseudo-ops have already been output in `assemble_start_function'.
1566 FIRST is the first insn of the rtl for the function being compiled.
1567 FILE is the file to write assembler code to.
1568 OPTIMIZE is nonzero if we should eliminate redundant
1569 test and compare insns. */
1571 void
1572 final_start_function (first, file, optimize)
1573 rtx first;
1574 FILE *file;
1575 int optimize ATTRIBUTE_UNUSED;
1577 block_depth = 0;
1579 this_is_asm_operands = 0;
1581 #ifdef NON_SAVING_SETJMP
1582 /* A function that calls setjmp should save and restore all the
1583 call-saved registers on a system where longjmp clobbers them. */
1584 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
1586 int i;
1588 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1589 if (!call_used_regs[i])
1590 regs_ever_live[i] = 1;
1592 #endif
1594 /* Initial line number is supposed to be output
1595 before the function's prologue and label
1596 so that the function's address will not appear to be
1597 in the last statement of the preceding function. */
1598 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1599 last_linenum = high_block_linenum = high_function_linenum
1600 = NOTE_LINE_NUMBER (first);
1602 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1603 /* Output DWARF definition of the function. */
1604 if (dwarf2out_do_frame ())
1605 dwarf2out_begin_prologue ();
1606 else
1607 current_function_func_begin_label = 0;
1608 #endif
1610 /* For SDB and XCOFF, the function beginning must be marked between
1611 the function label and the prologue. We always need this, even when
1612 -g1 was used. Defer on MIPS systems so that parameter descriptions
1613 follow function entry. */
1614 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
1615 if (write_symbols == SDB_DEBUG)
1616 sdbout_begin_function (last_linenum);
1617 else
1618 #endif
1619 #ifdef XCOFF_DEBUGGING_INFO
1620 if (write_symbols == XCOFF_DEBUG)
1621 xcoffout_begin_function (file, last_linenum);
1622 else
1623 #endif
1624 /* But only output line number for other debug info types if -g2
1625 or better. */
1626 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1627 output_source_line (file, first);
1629 #ifdef LEAF_REG_REMAP
1630 if (current_function_uses_only_leaf_regs)
1631 leaf_renumber_regs (first);
1632 #endif
1634 /* The Sun386i and perhaps other machines don't work right
1635 if the profiling code comes after the prologue. */
1636 #ifdef PROFILE_BEFORE_PROLOGUE
1637 if (profile_flag)
1638 profile_function (file);
1639 #endif /* PROFILE_BEFORE_PROLOGUE */
1641 #if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
1642 if (dwarf2out_do_frame ())
1643 dwarf2out_frame_debug (NULL_RTX);
1644 #endif
1646 /* If debugging, assign block numbers to all of the blocks in this
1647 function. */
1648 if (write_symbols)
1650 number_blocks (current_function_decl);
1651 remove_unncessary_notes ();
1652 /* We never actually put out begin/end notes for the top-level
1653 block in the function. But, conceptually, that block is
1654 always needed. */
1655 TREE_ASM_WRITTEN (DECL_INITIAL (current_function_decl)) = 1;
1658 #ifdef FUNCTION_PROLOGUE
1659 /* First output the function prologue: code to set up the stack frame. */
1660 FUNCTION_PROLOGUE (file, get_frame_size ());
1661 #endif
1663 /* If the machine represents the prologue as RTL, the profiling code must
1664 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
1665 #ifdef HAVE_prologue
1666 if (! HAVE_prologue)
1667 #endif
1668 profile_after_prologue (file);
1670 profile_label_no++;
1672 /* If we are doing basic block profiling, remember a printable version
1673 of the function name. */
1674 if (profile_block_flag)
1676 bb_func_label_num
1677 = add_bb_string ((*decl_printable_name) (current_function_decl, 2), FALSE);
1681 static void
1682 profile_after_prologue (file)
1683 FILE *file ATTRIBUTE_UNUSED;
1685 #ifdef FUNCTION_BLOCK_PROFILER
1686 if (profile_block_flag)
1688 FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
1690 #endif /* FUNCTION_BLOCK_PROFILER */
1692 #ifndef PROFILE_BEFORE_PROLOGUE
1693 if (profile_flag)
1694 profile_function (file);
1695 #endif /* not PROFILE_BEFORE_PROLOGUE */
1698 static void
1699 profile_function (file)
1700 FILE *file;
1702 int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
1703 #if defined(ASM_OUTPUT_REG_PUSH)
1704 #if defined(STRUCT_VALUE_INCOMING_REGNUM) || defined(STRUCT_VALUE_REGNUM)
1705 int sval = current_function_returns_struct;
1706 #endif
1707 #if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
1708 int cxt = current_function_needs_context;
1709 #endif
1710 #endif /* ASM_OUTPUT_REG_PUSH */
1712 data_section ();
1713 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
1714 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
1715 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, 1);
1717 function_section (current_function_decl);
1719 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1720 if (sval)
1721 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
1722 #else
1723 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1724 if (sval)
1726 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
1728 #endif
1729 #endif
1731 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1732 if (cxt)
1733 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1734 #else
1735 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1736 if (cxt)
1738 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1740 #endif
1741 #endif
1743 FUNCTION_PROFILER (file, profile_label_no);
1745 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1746 if (cxt)
1747 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1748 #else
1749 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1750 if (cxt)
1752 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1754 #endif
1755 #endif
1757 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1758 if (sval)
1759 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1760 #else
1761 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1762 if (sval)
1764 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1766 #endif
1767 #endif
1770 /* Output assembler code for the end of a function.
1771 For clarity, args are same as those of `final_start_function'
1772 even though not all of them are needed. */
1774 void
1775 final_end_function (first, file, optimize)
1776 rtx first ATTRIBUTE_UNUSED;
1777 FILE *file;
1778 int optimize ATTRIBUTE_UNUSED;
1780 if (app_on)
1782 fputs (ASM_APP_OFF, file);
1783 app_on = 0;
1786 #ifdef SDB_DEBUGGING_INFO
1787 if (write_symbols == SDB_DEBUG)
1788 sdbout_end_function (high_function_linenum);
1789 #endif
1791 #ifdef DWARF_DEBUGGING_INFO
1792 if (write_symbols == DWARF_DEBUG)
1793 dwarfout_end_function ();
1794 #endif
1796 #ifdef XCOFF_DEBUGGING_INFO
1797 if (write_symbols == XCOFF_DEBUG)
1798 xcoffout_end_function (file, high_function_linenum);
1799 #endif
1801 #ifdef FUNCTION_EPILOGUE
1802 /* Finally, output the function epilogue:
1803 code to restore the stack frame and return to the caller. */
1804 FUNCTION_EPILOGUE (file, get_frame_size ());
1805 #endif
1807 #ifdef SDB_DEBUGGING_INFO
1808 if (write_symbols == SDB_DEBUG)
1809 sdbout_end_epilogue ();
1810 #endif
1812 #ifdef DWARF_DEBUGGING_INFO
1813 if (write_symbols == DWARF_DEBUG)
1814 dwarfout_end_epilogue ();
1815 #endif
1817 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1818 if (dwarf2out_do_frame ())
1819 dwarf2out_end_epilogue ();
1820 #endif
1822 #ifdef XCOFF_DEBUGGING_INFO
1823 if (write_symbols == XCOFF_DEBUG)
1824 xcoffout_end_epilogue (file);
1825 #endif
1827 bb_func_label_num = -1; /* not in function, nuke label # */
1829 /* If FUNCTION_EPILOGUE is not defined, then the function body
1830 itself contains return instructions wherever needed. */
1833 /* Add a block to the linked list that remembers the current line/file/function
1834 for basic block profiling. Emit the label in front of the basic block and
1835 the instructions that increment the count field. */
1837 static void
1838 add_bb (file)
1839 FILE *file;
1841 struct bb_list *ptr = (struct bb_list *) permalloc (sizeof (struct bb_list));
1843 /* Add basic block to linked list. */
1844 ptr->next = 0;
1845 ptr->line_num = last_linenum;
1846 ptr->file_label_num = bb_file_label_num;
1847 ptr->func_label_num = bb_func_label_num;
1848 *bb_tail = ptr;
1849 bb_tail = &ptr->next;
1851 /* Enable the table of basic-block use counts
1852 to point at the code it applies to. */
1853 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1855 /* Before first insn of this basic block, increment the
1856 count of times it was entered. */
1857 #ifdef BLOCK_PROFILER
1858 BLOCK_PROFILER (file, count_basic_blocks);
1859 #endif
1860 #ifdef HAVE_cc0
1861 CC_STATUS_INIT;
1862 #endif
1864 new_block = 0;
1865 count_basic_blocks++;
1868 /* Add a string to be used for basic block profiling. */
1870 static int
1871 add_bb_string (string, perm_p)
1872 const char *string;
1873 int perm_p;
1875 int len;
1876 struct bb_str *ptr = 0;
1878 if (!string)
1880 string = "<unknown>";
1881 perm_p = TRUE;
1884 /* Allocate a new string if the current string isn't permanent. If
1885 the string is permanent search for the same string in other
1886 allocations. */
1888 len = strlen (string) + 1;
1889 if (!perm_p)
1891 char *p = (char *) permalloc (len);
1892 bcopy (string, p, len);
1893 string = p;
1895 else
1896 for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
1897 if (ptr->string == string)
1898 break;
1900 /* Allocate a new string block if we need to. */
1901 if (!ptr)
1903 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1904 ptr->next = 0;
1905 ptr->length = len;
1906 ptr->label_num = sbb_label_num++;
1907 ptr->string = string;
1908 *sbb_tail = ptr;
1909 sbb_tail = &ptr->next;
1912 return ptr->label_num;
1916 /* Output assembler code for some insns: all or part of a function.
1917 For description of args, see `final_start_function', above.
1919 PRESCAN is 1 if we are not really outputting,
1920 just scanning as if we were outputting.
1921 Prescanning deletes and rearranges insns just like ordinary output.
1922 PRESCAN is -2 if we are outputting after having prescanned.
1923 In this case, don't try to delete or rearrange insns
1924 because that has already been done.
1925 Prescanning is done only on certain machines. */
1927 void
1928 final (first, file, optimize, prescan)
1929 rtx first;
1930 FILE *file;
1931 int optimize;
1932 int prescan;
1934 register rtx insn;
1935 int max_line = 0;
1936 int max_uid = 0;
1938 last_ignored_compare = 0;
1939 new_block = 1;
1941 check_exception_handler_labels ();
1943 /* Make a map indicating which line numbers appear in this function.
1944 When producing SDB debugging info, delete troublesome line number
1945 notes from inlined functions in other files as well as duplicate
1946 line number notes. */
1947 #ifdef SDB_DEBUGGING_INFO
1948 if (write_symbols == SDB_DEBUG)
1950 rtx last = 0;
1951 for (insn = first; insn; insn = NEXT_INSN (insn))
1952 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1954 if ((RTX_INTEGRATED_P (insn)
1955 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1956 || (last != 0
1957 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1958 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1960 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1961 NOTE_SOURCE_FILE (insn) = 0;
1962 continue;
1964 last = insn;
1965 if (NOTE_LINE_NUMBER (insn) > max_line)
1966 max_line = NOTE_LINE_NUMBER (insn);
1969 else
1970 #endif
1972 for (insn = first; insn; insn = NEXT_INSN (insn))
1973 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1974 max_line = NOTE_LINE_NUMBER (insn);
1977 line_note_exists = (char *) xcalloc (max_line + 1, sizeof (char));
1979 for (insn = first; insn; insn = NEXT_INSN (insn))
1981 if (INSN_UID (insn) > max_uid) /* find largest UID */
1982 max_uid = INSN_UID (insn);
1983 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1984 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1985 #ifdef HAVE_cc0
1986 /* If CC tracking across branches is enabled, record the insn which
1987 jumps to each branch only reached from one place. */
1988 if (optimize && GET_CODE (insn) == JUMP_INSN)
1990 rtx lab = JUMP_LABEL (insn);
1991 if (lab && LABEL_NUSES (lab) == 1)
1993 LABEL_REFS (lab) = insn;
1996 #endif
1999 /* Initialize insn_eh_region table if eh is being used. */
2001 init_insn_eh_region (first, max_uid);
2003 init_recog ();
2005 CC_STATUS_INIT;
2007 /* Output the insns. */
2008 for (insn = NEXT_INSN (first); insn;)
2010 #ifdef HAVE_ATTR_length
2011 insn_current_address = insn_addresses[INSN_UID (insn)];
2012 #endif
2013 insn = final_scan_insn (insn, file, optimize, prescan, 0);
2016 /* Do basic-block profiling here
2017 if the last insn was a conditional branch. */
2018 if (profile_block_flag && new_block)
2019 add_bb (file);
2021 free_insn_eh_region ();
2022 free (line_note_exists);
2023 line_note_exists = NULL;
2026 const char *
2027 get_insn_template (code, insn)
2028 int code;
2029 rtx insn;
2031 const void *output = insn_data[code].output;
2032 switch (insn_data[code].output_format)
2034 case INSN_OUTPUT_FORMAT_SINGLE:
2035 return (const char *) output;
2036 case INSN_OUTPUT_FORMAT_MULTI:
2037 return ((const char * const *) output)[which_alternative];
2038 case INSN_OUTPUT_FORMAT_FUNCTION:
2039 if (insn == NULL)
2040 abort ();
2041 return (* (insn_output_fn) output) (recog_data.operand, insn);
2043 default:
2044 abort ();
2047 /* The final scan for one insn, INSN.
2048 Args are same as in `final', except that INSN
2049 is the insn being scanned.
2050 Value returned is the next insn to be scanned.
2052 NOPEEPHOLES is the flag to disallow peephole processing (currently
2053 used for within delayed branch sequence output). */
2056 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
2057 rtx insn;
2058 FILE *file;
2059 int optimize ATTRIBUTE_UNUSED;
2060 int prescan;
2061 int nopeepholes ATTRIBUTE_UNUSED;
2063 #ifdef HAVE_cc0
2064 rtx set;
2065 #endif
2067 insn_counter++;
2069 /* Ignore deleted insns. These can occur when we split insns (due to a
2070 template of "#") while not optimizing. */
2071 if (INSN_DELETED_P (insn))
2072 return NEXT_INSN (insn);
2074 switch (GET_CODE (insn))
2076 case NOTE:
2077 if (prescan > 0)
2078 break;
2080 /* Align the beginning of a loop, for higher speed
2081 on certain machines. */
2083 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
2084 break; /* This used to depend on optimize, but that was bogus. */
2085 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
2086 break;
2088 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG
2089 && ! exceptions_via_longjmp)
2091 ASM_OUTPUT_INTERNAL_LABEL (file, "LEHB", NOTE_EH_HANDLER (insn));
2092 if (! flag_new_exceptions)
2093 add_eh_table_entry (NOTE_EH_HANDLER (insn));
2094 #ifdef ASM_OUTPUT_EH_REGION_BEG
2095 ASM_OUTPUT_EH_REGION_BEG (file, NOTE_EH_HANDLER (insn));
2096 #endif
2097 break;
2100 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END
2101 && ! exceptions_via_longjmp)
2103 ASM_OUTPUT_INTERNAL_LABEL (file, "LEHE", NOTE_EH_HANDLER (insn));
2104 if (flag_new_exceptions)
2105 add_eh_table_entry (NOTE_EH_HANDLER (insn));
2106 #ifdef ASM_OUTPUT_EH_REGION_END
2107 ASM_OUTPUT_EH_REGION_END (file, NOTE_EH_HANDLER (insn));
2108 #endif
2109 break;
2112 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
2114 #ifdef FUNCTION_END_PROLOGUE
2115 FUNCTION_END_PROLOGUE (file);
2116 #endif
2117 profile_after_prologue (file);
2118 break;
2121 #ifdef FUNCTION_BEGIN_EPILOGUE
2122 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
2124 FUNCTION_BEGIN_EPILOGUE (file);
2125 break;
2127 #endif
2129 if (write_symbols == NO_DEBUG)
2130 break;
2131 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
2133 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
2134 /* MIPS stabs require the parameter descriptions to be after the
2135 function entry point rather than before. */
2136 if (write_symbols == SDB_DEBUG)
2137 sdbout_begin_function (last_linenum);
2138 else
2139 #endif
2140 #ifdef DWARF_DEBUGGING_INFO
2141 /* This outputs a marker where the function body starts, so it
2142 must be after the prologue. */
2143 if (write_symbols == DWARF_DEBUG)
2144 dwarfout_begin_function ();
2145 #endif
2146 break;
2148 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
2149 break; /* An insn that was "deleted" */
2150 if (app_on)
2152 fputs (ASM_APP_OFF, file);
2153 app_on = 0;
2155 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2156 && (debug_info_level == DINFO_LEVEL_NORMAL
2157 || debug_info_level == DINFO_LEVEL_VERBOSE
2158 || write_symbols == DWARF_DEBUG
2159 || write_symbols == DWARF2_DEBUG))
2161 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2163 ++block_depth;
2164 high_block_linenum = last_linenum;
2166 /* Output debugging info about the symbol-block beginning. */
2167 #ifdef SDB_DEBUGGING_INFO
2168 if (write_symbols == SDB_DEBUG)
2169 sdbout_begin_block (file, last_linenum, n);
2170 #endif
2171 #ifdef XCOFF_DEBUGGING_INFO
2172 if (write_symbols == XCOFF_DEBUG)
2173 xcoffout_begin_block (file, last_linenum, n);
2174 #endif
2175 #ifdef DBX_DEBUGGING_INFO
2176 if (write_symbols == DBX_DEBUG)
2177 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", n);
2178 #endif
2179 #ifdef DWARF_DEBUGGING_INFO
2180 if (write_symbols == DWARF_DEBUG)
2181 dwarfout_begin_block (n);
2182 #endif
2183 #ifdef DWARF2_DEBUGGING_INFO
2184 if (write_symbols == DWARF2_DEBUG)
2185 dwarf2out_begin_block (n);
2186 #endif
2188 /* Mark this block as output. */
2189 TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
2191 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
2192 && (debug_info_level == DINFO_LEVEL_NORMAL
2193 || debug_info_level == DINFO_LEVEL_VERBOSE
2194 || write_symbols == DWARF_DEBUG
2195 || write_symbols == DWARF2_DEBUG))
2197 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2199 /* End of a symbol-block. */
2201 --block_depth;
2202 if (block_depth < 0)
2203 abort ();
2205 #ifdef XCOFF_DEBUGGING_INFO
2206 if (write_symbols == XCOFF_DEBUG)
2207 xcoffout_end_block (file, high_block_linenum, n);
2208 #endif
2209 #ifdef DBX_DEBUGGING_INFO
2210 if (write_symbols == DBX_DEBUG)
2211 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE", n);
2212 #endif
2213 #ifdef SDB_DEBUGGING_INFO
2214 if (write_symbols == SDB_DEBUG)
2215 sdbout_end_block (file, high_block_linenum, n);
2216 #endif
2217 #ifdef DWARF_DEBUGGING_INFO
2218 if (write_symbols == DWARF_DEBUG)
2219 dwarfout_end_block (n);
2220 #endif
2221 #ifdef DWARF2_DEBUGGING_INFO
2222 if (write_symbols == DWARF2_DEBUG)
2223 dwarf2out_end_block (n);
2224 #endif
2226 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
2227 && (debug_info_level == DINFO_LEVEL_NORMAL
2228 || debug_info_level == DINFO_LEVEL_VERBOSE))
2230 #ifdef DWARF_DEBUGGING_INFO
2231 if (write_symbols == DWARF_DEBUG)
2232 dwarfout_label (insn);
2233 #endif
2234 #ifdef DWARF2_DEBUGGING_INFO
2235 if (write_symbols == DWARF2_DEBUG)
2236 dwarf2out_label (insn);
2237 #endif
2239 else if (NOTE_LINE_NUMBER (insn) > 0)
2240 /* This note is a line-number. */
2242 register rtx note;
2244 #if 0 /* This is what we used to do. */
2245 output_source_line (file, insn);
2246 #endif
2247 int note_after = 0;
2249 /* If there is anything real after this note,
2250 output it. If another line note follows, omit this one. */
2251 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
2253 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
2254 break;
2255 /* These types of notes can be significant
2256 so make sure the preceding line number stays. */
2257 else if (GET_CODE (note) == NOTE
2258 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
2259 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
2260 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
2261 break;
2262 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
2264 /* Another line note follows; we can delete this note
2265 if no intervening line numbers have notes elsewhere. */
2266 int num;
2267 for (num = NOTE_LINE_NUMBER (insn) + 1;
2268 num < NOTE_LINE_NUMBER (note);
2269 num++)
2270 if (line_note_exists[num])
2271 break;
2273 if (num >= NOTE_LINE_NUMBER (note))
2274 note_after = 1;
2275 break;
2279 /* Output this line note
2280 if it is the first or the last line note in a row. */
2281 if (!note_after)
2282 output_source_line (file, insn);
2284 break;
2286 case BARRIER:
2287 #if defined (DWARF2_UNWIND_INFO)
2288 /* If we push arguments, we need to check all insns for stack
2289 adjustments. */
2290 if (!ACCUMULATE_OUTGOING_ARGS && dwarf2out_do_frame ())
2291 dwarf2out_frame_debug (insn);
2292 #endif
2293 break;
2295 case CODE_LABEL:
2296 /* The target port might emit labels in the output function for
2297 some insn, e.g. sh.c output_branchy_insn. */
2298 if (CODE_LABEL_NUMBER (insn) <= max_labelno)
2300 int align = LABEL_TO_ALIGNMENT (insn);
2301 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2302 int max_skip = LABEL_TO_MAX_SKIP (insn);
2303 #endif
2305 if (align && NEXT_INSN (insn))
2306 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2307 ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
2308 #else
2309 ASM_OUTPUT_ALIGN (file, align);
2310 #endif
2312 #ifdef HAVE_cc0
2313 CC_STATUS_INIT;
2314 /* If this label is reached from only one place, set the condition
2315 codes from the instruction just before the branch. */
2317 /* Disabled because some insns set cc_status in the C output code
2318 and NOTICE_UPDATE_CC alone can set incorrect status. */
2319 if (0 /* optimize && LABEL_NUSES (insn) == 1*/)
2321 rtx jump = LABEL_REFS (insn);
2322 rtx barrier = prev_nonnote_insn (insn);
2323 rtx prev;
2324 /* If the LABEL_REFS field of this label has been set to point
2325 at a branch, the predecessor of the branch is a regular
2326 insn, and that branch is the only way to reach this label,
2327 set the condition codes based on the branch and its
2328 predecessor. */
2329 if (barrier && GET_CODE (barrier) == BARRIER
2330 && jump && GET_CODE (jump) == JUMP_INSN
2331 && (prev = prev_nonnote_insn (jump))
2332 && GET_CODE (prev) == INSN)
2334 NOTICE_UPDATE_CC (PATTERN (prev), prev);
2335 NOTICE_UPDATE_CC (PATTERN (jump), jump);
2338 #endif
2339 if (prescan > 0)
2340 break;
2341 new_block = 1;
2343 #ifdef FINAL_PRESCAN_LABEL
2344 FINAL_PRESCAN_INSN (insn, NULL_PTR, 0);
2345 #endif
2347 #ifdef SDB_DEBUGGING_INFO
2348 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
2349 sdbout_label (insn);
2350 #endif
2351 #ifdef DWARF_DEBUGGING_INFO
2352 if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
2353 dwarfout_label (insn);
2354 #endif
2355 #ifdef DWARF2_DEBUGGING_INFO
2356 if (write_symbols == DWARF2_DEBUG && LABEL_NAME (insn))
2357 dwarf2out_label (insn);
2358 #endif
2359 if (app_on)
2361 fputs (ASM_APP_OFF, file);
2362 app_on = 0;
2364 if (NEXT_INSN (insn) != 0
2365 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
2367 rtx nextbody = PATTERN (NEXT_INSN (insn));
2369 /* If this label is followed by a jump-table,
2370 make sure we put the label in the read-only section. Also
2371 possibly write the label and jump table together. */
2373 if (GET_CODE (nextbody) == ADDR_VEC
2374 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
2376 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2377 /* In this case, the case vector is being moved by the
2378 target, so don't output the label at all. Leave that
2379 to the back end macros. */
2380 #else
2381 if (! JUMP_TABLES_IN_TEXT_SECTION)
2383 readonly_data_section ();
2384 #ifdef READONLY_DATA_SECTION
2385 ASM_OUTPUT_ALIGN (file,
2386 exact_log2 (BIGGEST_ALIGNMENT
2387 / BITS_PER_UNIT));
2388 #endif /* READONLY_DATA_SECTION */
2390 else
2391 function_section (current_function_decl);
2393 #ifdef ASM_OUTPUT_CASE_LABEL
2394 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
2395 NEXT_INSN (insn));
2396 #else
2397 if (LABEL_ALTERNATE_NAME (insn))
2398 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2399 else
2400 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2401 #endif
2402 #endif
2403 break;
2406 if (LABEL_ALTERNATE_NAME (insn))
2407 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2408 else
2409 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2410 break;
2412 default:
2414 register rtx body = PATTERN (insn);
2415 int insn_code_number;
2416 const char *template;
2417 #ifdef HAVE_cc0
2418 rtx note;
2419 #endif
2421 /* An INSN, JUMP_INSN or CALL_INSN.
2422 First check for special kinds that recog doesn't recognize. */
2424 if (GET_CODE (body) == USE /* These are just declarations */
2425 || GET_CODE (body) == CLOBBER)
2426 break;
2428 #ifdef HAVE_cc0
2429 /* If there is a REG_CC_SETTER note on this insn, it means that
2430 the setting of the condition code was done in the delay slot
2431 of the insn that branched here. So recover the cc status
2432 from the insn that set it. */
2434 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2435 if (note)
2437 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
2438 cc_prev_status = cc_status;
2440 #endif
2442 /* Detect insns that are really jump-tables
2443 and output them as such. */
2445 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
2447 #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
2448 register int vlen, idx;
2449 #endif
2451 if (prescan > 0)
2452 break;
2454 if (app_on)
2456 fputs (ASM_APP_OFF, file);
2457 app_on = 0;
2460 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2461 if (GET_CODE (body) == ADDR_VEC)
2463 #ifdef ASM_OUTPUT_ADDR_VEC
2464 ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
2465 #else
2466 abort();
2467 #endif
2469 else
2471 #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
2472 ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
2473 #else
2474 abort();
2475 #endif
2477 #else
2478 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2479 for (idx = 0; idx < vlen; idx++)
2481 if (GET_CODE (body) == ADDR_VEC)
2483 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2484 ASM_OUTPUT_ADDR_VEC_ELT
2485 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2486 #else
2487 abort ();
2488 #endif
2490 else
2492 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2493 ASM_OUTPUT_ADDR_DIFF_ELT
2494 (file,
2495 body,
2496 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2497 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2498 #else
2499 abort ();
2500 #endif
2503 #ifdef ASM_OUTPUT_CASE_END
2504 ASM_OUTPUT_CASE_END (file,
2505 CODE_LABEL_NUMBER (PREV_INSN (insn)),
2506 insn);
2507 #endif
2508 #endif
2510 function_section (current_function_decl);
2512 break;
2515 /* Do basic-block profiling when we reach a new block.
2516 Done here to avoid jump tables. */
2517 if (profile_block_flag && new_block)
2518 add_bb (file);
2520 if (GET_CODE (body) == ASM_INPUT)
2522 /* There's no telling what that did to the condition codes. */
2523 CC_STATUS_INIT;
2524 if (prescan > 0)
2525 break;
2526 if (! app_on)
2528 fputs (ASM_APP_ON, file);
2529 app_on = 1;
2531 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
2532 break;
2535 /* Detect `asm' construct with operands. */
2536 if (asm_noperands (body) >= 0)
2538 unsigned int noperands = asm_noperands (body);
2539 rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
2540 const char *string;
2542 /* There's no telling what that did to the condition codes. */
2543 CC_STATUS_INIT;
2544 if (prescan > 0)
2545 break;
2547 if (! app_on)
2549 fputs (ASM_APP_ON, file);
2550 app_on = 1;
2553 /* Get out the operand values. */
2554 string = decode_asm_operands (body, ops, NULL_PTR,
2555 NULL_PTR, NULL_PTR);
2556 /* Inhibit aborts on what would otherwise be compiler bugs. */
2557 insn_noperands = noperands;
2558 this_is_asm_operands = insn;
2560 /* Output the insn using them. */
2561 output_asm_insn (string, ops);
2562 this_is_asm_operands = 0;
2563 break;
2566 if (prescan <= 0 && app_on)
2568 fputs (ASM_APP_OFF, file);
2569 app_on = 0;
2572 if (GET_CODE (body) == SEQUENCE)
2574 /* A delayed-branch sequence */
2575 register int i;
2576 rtx next;
2578 if (prescan > 0)
2579 break;
2580 final_sequence = body;
2582 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2583 force the restoration of a comparison that was previously
2584 thought unnecessary. If that happens, cancel this sequence
2585 and cause that insn to be restored. */
2587 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
2588 if (next != XVECEXP (body, 0, 1))
2590 final_sequence = 0;
2591 return next;
2594 for (i = 1; i < XVECLEN (body, 0); i++)
2596 rtx insn = XVECEXP (body, 0, i);
2597 rtx next = NEXT_INSN (insn);
2598 /* We loop in case any instruction in a delay slot gets
2599 split. */
2601 insn = final_scan_insn (insn, file, 0, prescan, 1);
2602 while (insn != next);
2604 #ifdef DBR_OUTPUT_SEQEND
2605 DBR_OUTPUT_SEQEND (file);
2606 #endif
2607 final_sequence = 0;
2609 /* If the insn requiring the delay slot was a CALL_INSN, the
2610 insns in the delay slot are actually executed before the
2611 called function. Hence we don't preserve any CC-setting
2612 actions in these insns and the CC must be marked as being
2613 clobbered by the function. */
2614 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
2616 CC_STATUS_INIT;
2619 /* Following a conditional branch sequence, we have a new basic
2620 block. */
2621 if (profile_block_flag)
2623 rtx insn = XVECEXP (body, 0, 0);
2624 rtx body = PATTERN (insn);
2626 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2627 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2628 || (GET_CODE (insn) == JUMP_INSN
2629 && GET_CODE (body) == PARALLEL
2630 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2631 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
2632 new_block = 1;
2634 break;
2637 /* We have a real machine instruction as rtl. */
2639 body = PATTERN (insn);
2641 #ifdef HAVE_cc0
2642 set = single_set(insn);
2644 /* Check for redundant test and compare instructions
2645 (when the condition codes are already set up as desired).
2646 This is done only when optimizing; if not optimizing,
2647 it should be possible for the user to alter a variable
2648 with the debugger in between statements
2649 and the next statement should reexamine the variable
2650 to compute the condition codes. */
2652 if (optimize)
2654 #if 0
2655 rtx set = single_set(insn);
2656 #endif
2658 if (set
2659 && GET_CODE (SET_DEST (set)) == CC0
2660 && insn != last_ignored_compare)
2662 if (GET_CODE (SET_SRC (set)) == SUBREG)
2663 SET_SRC (set) = alter_subreg (SET_SRC (set));
2664 else if (GET_CODE (SET_SRC (set)) == COMPARE)
2666 if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
2667 XEXP (SET_SRC (set), 0)
2668 = alter_subreg (XEXP (SET_SRC (set), 0));
2669 if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
2670 XEXP (SET_SRC (set), 1)
2671 = alter_subreg (XEXP (SET_SRC (set), 1));
2673 if ((cc_status.value1 != 0
2674 && rtx_equal_p (SET_SRC (set), cc_status.value1))
2675 || (cc_status.value2 != 0
2676 && rtx_equal_p (SET_SRC (set), cc_status.value2)))
2678 /* Don't delete insn if it has an addressing side-effect. */
2679 if (! FIND_REG_INC_NOTE (insn, 0)
2680 /* or if anything in it is volatile. */
2681 && ! volatile_refs_p (PATTERN (insn)))
2683 /* We don't really delete the insn; just ignore it. */
2684 last_ignored_compare = insn;
2685 break;
2690 #endif
2692 /* Following a conditional branch, we have a new basic block.
2693 But if we are inside a sequence, the new block starts after the
2694 last insn of the sequence. */
2695 if (profile_block_flag && final_sequence == 0
2696 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2697 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2698 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
2699 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2700 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
2701 new_block = 1;
2703 #ifndef STACK_REGS
2704 /* Don't bother outputting obvious no-ops, even without -O.
2705 This optimization is fast and doesn't interfere with debugging.
2706 Don't do this if the insn is in a delay slot, since this
2707 will cause an improper number of delay insns to be written. */
2708 if (final_sequence == 0
2709 && prescan >= 0
2710 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
2711 && GET_CODE (SET_SRC (body)) == REG
2712 && GET_CODE (SET_DEST (body)) == REG
2713 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
2714 break;
2715 #endif
2717 #ifdef HAVE_cc0
2718 /* If this is a conditional branch, maybe modify it
2719 if the cc's are in a nonstandard state
2720 so that it accomplishes the same thing that it would
2721 do straightforwardly if the cc's were set up normally. */
2723 if (cc_status.flags != 0
2724 && GET_CODE (insn) == JUMP_INSN
2725 && GET_CODE (body) == SET
2726 && SET_DEST (body) == pc_rtx
2727 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2728 && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
2729 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
2730 /* This is done during prescan; it is not done again
2731 in final scan when prescan has been done. */
2732 && prescan >= 0)
2734 /* This function may alter the contents of its argument
2735 and clear some of the cc_status.flags bits.
2736 It may also return 1 meaning condition now always true
2737 or -1 meaning condition now always false
2738 or 2 meaning condition nontrivial but altered. */
2739 register int result = alter_cond (XEXP (SET_SRC (body), 0));
2740 /* If condition now has fixed value, replace the IF_THEN_ELSE
2741 with its then-operand or its else-operand. */
2742 if (result == 1)
2743 SET_SRC (body) = XEXP (SET_SRC (body), 1);
2744 if (result == -1)
2745 SET_SRC (body) = XEXP (SET_SRC (body), 2);
2747 /* The jump is now either unconditional or a no-op.
2748 If it has become a no-op, don't try to output it.
2749 (It would not be recognized.) */
2750 if (SET_SRC (body) == pc_rtx)
2752 PUT_CODE (insn, NOTE);
2753 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2754 NOTE_SOURCE_FILE (insn) = 0;
2755 break;
2757 else if (GET_CODE (SET_SRC (body)) == RETURN)
2758 /* Replace (set (pc) (return)) with (return). */
2759 PATTERN (insn) = body = SET_SRC (body);
2761 /* Rerecognize the instruction if it has changed. */
2762 if (result != 0)
2763 INSN_CODE (insn) = -1;
2766 /* Make same adjustments to instructions that examine the
2767 condition codes without jumping and instructions that
2768 handle conditional moves (if this machine has either one). */
2770 if (cc_status.flags != 0
2771 && set != 0)
2773 rtx cond_rtx, then_rtx, else_rtx;
2775 if (GET_CODE (insn) != JUMP_INSN
2776 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2778 cond_rtx = XEXP (SET_SRC (set), 0);
2779 then_rtx = XEXP (SET_SRC (set), 1);
2780 else_rtx = XEXP (SET_SRC (set), 2);
2782 else
2784 cond_rtx = SET_SRC (set);
2785 then_rtx = const_true_rtx;
2786 else_rtx = const0_rtx;
2789 switch (GET_CODE (cond_rtx))
2791 case GTU:
2792 case GT:
2793 case LTU:
2794 case LT:
2795 case GEU:
2796 case GE:
2797 case LEU:
2798 case LE:
2799 case EQ:
2800 case NE:
2802 register int result;
2803 if (XEXP (cond_rtx, 0) != cc0_rtx)
2804 break;
2805 result = alter_cond (cond_rtx);
2806 if (result == 1)
2807 validate_change (insn, &SET_SRC (set), then_rtx, 0);
2808 else if (result == -1)
2809 validate_change (insn, &SET_SRC (set), else_rtx, 0);
2810 else if (result == 2)
2811 INSN_CODE (insn) = -1;
2812 if (SET_DEST (set) == SET_SRC (set))
2814 PUT_CODE (insn, NOTE);
2815 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2816 NOTE_SOURCE_FILE (insn) = 0;
2819 break;
2821 default:
2822 break;
2826 #endif
2828 #ifdef HAVE_peephole
2829 /* Do machine-specific peephole optimizations if desired. */
2831 if (optimize && !flag_no_peephole && !nopeepholes)
2833 rtx next = peephole (insn);
2834 /* When peepholing, if there were notes within the peephole,
2835 emit them before the peephole. */
2836 if (next != 0 && next != NEXT_INSN (insn))
2838 rtx prev = PREV_INSN (insn);
2839 rtx note;
2841 for (note = NEXT_INSN (insn); note != next;
2842 note = NEXT_INSN (note))
2843 final_scan_insn (note, file, optimize, prescan, nopeepholes);
2845 /* In case this is prescan, put the notes
2846 in proper position for later rescan. */
2847 note = NEXT_INSN (insn);
2848 PREV_INSN (note) = prev;
2849 NEXT_INSN (prev) = note;
2850 NEXT_INSN (PREV_INSN (next)) = insn;
2851 PREV_INSN (insn) = PREV_INSN (next);
2852 NEXT_INSN (insn) = next;
2853 PREV_INSN (next) = insn;
2856 /* PEEPHOLE might have changed this. */
2857 body = PATTERN (insn);
2859 #endif
2861 /* Try to recognize the instruction.
2862 If successful, verify that the operands satisfy the
2863 constraints for the instruction. Crash if they don't,
2864 since `reload' should have changed them so that they do. */
2866 insn_code_number = recog_memoized (insn);
2867 extract_insn (insn);
2868 cleanup_subreg_operands (insn);
2870 if (! constrain_operands (1))
2871 fatal_insn_not_found (insn);
2873 /* Some target machines need to prescan each insn before
2874 it is output. */
2876 #ifdef FINAL_PRESCAN_INSN
2877 FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2878 #endif
2880 #ifdef HAVE_cc0
2881 cc_prev_status = cc_status;
2883 /* Update `cc_status' for this instruction.
2884 The instruction's output routine may change it further.
2885 If the output routine for a jump insn needs to depend
2886 on the cc status, it should look at cc_prev_status. */
2888 NOTICE_UPDATE_CC (body, insn);
2889 #endif
2891 debug_insn = insn;
2893 #if defined (DWARF2_UNWIND_INFO)
2894 /* If we push arguments, we want to know where the calls are. */
2895 if (!ACCUMULATE_OUTGOING_ARGS && GET_CODE (insn) == CALL_INSN
2896 && dwarf2out_do_frame ())
2897 dwarf2out_frame_debug (insn);
2898 #endif
2900 /* Find the proper template for this insn. */
2901 template = get_insn_template (insn_code_number, insn);
2903 /* If the C code returns 0, it means that it is a jump insn
2904 which follows a deleted test insn, and that test insn
2905 needs to be reinserted. */
2906 if (template == 0)
2908 if (prev_nonnote_insn (insn) != last_ignored_compare)
2909 abort ();
2910 new_block = 0;
2911 return prev_nonnote_insn (insn);
2914 /* If the template is the string "#", it means that this insn must
2915 be split. */
2916 if (template[0] == '#' && template[1] == '\0')
2918 rtx new = try_split (body, insn, 0);
2920 /* If we didn't split the insn, go away. */
2921 if (new == insn && PATTERN (new) == body)
2922 fatal_insn ("Could not split insn", insn);
2924 #ifdef HAVE_ATTR_length
2925 /* This instruction should have been split in shorten_branches,
2926 to ensure that we would have valid length info for the
2927 splitees. */
2928 abort ();
2929 #endif
2931 new_block = 0;
2932 return new;
2935 if (prescan > 0)
2936 break;
2938 /* Output assembler code from the template. */
2940 output_asm_insn (template, recog_data.operand);
2942 #if defined (DWARF2_UNWIND_INFO)
2943 /* If we push arguments, we need to check all insns for stack
2944 adjustments. */
2945 if (!ACCUMULATE_OUTGOING_ARGS)
2947 if (GET_CODE (insn) == INSN && dwarf2out_do_frame ())
2948 dwarf2out_frame_debug (insn);
2950 else
2952 #if defined (HAVE_prologue)
2953 /* If this insn is part of the prologue, emit DWARF v2
2954 call frame info. */
2955 if (RTX_FRAME_RELATED_P (insn) && dwarf2out_do_frame ())
2956 dwarf2out_frame_debug (insn);
2957 #endif
2959 #endif
2961 #if 0
2962 /* It's not at all clear why we did this and doing so interferes
2963 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2964 with this out. */
2966 /* Mark this insn as having been output. */
2967 INSN_DELETED_P (insn) = 1;
2968 #endif
2970 debug_insn = 0;
2973 return NEXT_INSN (insn);
2976 /* Output debugging info to the assembler file FILE
2977 based on the NOTE-insn INSN, assumed to be a line number. */
2979 static void
2980 output_source_line (file, insn)
2981 FILE *file ATTRIBUTE_UNUSED;
2982 rtx insn;
2984 register const char *filename = NOTE_SOURCE_FILE (insn);
2986 /* Remember filename for basic block profiling.
2987 Filenames are allocated on the permanent obstack
2988 or are passed in ARGV, so we don't have to save
2989 the string. */
2991 if (profile_block_flag && last_filename != filename)
2992 bb_file_label_num = add_bb_string (filename, TRUE);
2994 last_filename = filename;
2995 last_linenum = NOTE_LINE_NUMBER (insn);
2996 high_block_linenum = MAX (last_linenum, high_block_linenum);
2997 high_function_linenum = MAX (last_linenum, high_function_linenum);
2999 if (write_symbols != NO_DEBUG)
3001 #ifdef SDB_DEBUGGING_INFO
3002 if (write_symbols == SDB_DEBUG
3003 #if 0 /* People like having line numbers even in wrong file! */
3004 /* COFF can't handle multiple source files--lose, lose. */
3005 && !strcmp (filename, main_input_filename)
3006 #endif
3007 /* COFF relative line numbers must be positive. */
3008 && last_linenum > sdb_begin_function_line)
3010 #ifdef ASM_OUTPUT_SOURCE_LINE
3011 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
3012 #else
3013 fprintf (file, "\t.ln\t%d\n",
3014 ((sdb_begin_function_line > -1)
3015 ? last_linenum - sdb_begin_function_line : 1));
3016 #endif
3018 #endif
3020 #if defined (DBX_DEBUGGING_INFO)
3021 if (write_symbols == DBX_DEBUG)
3022 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
3023 #endif
3025 #if defined (XCOFF_DEBUGGING_INFO)
3026 if (write_symbols == XCOFF_DEBUG)
3027 xcoffout_source_line (file, filename, insn);
3028 #endif
3030 #ifdef DWARF_DEBUGGING_INFO
3031 if (write_symbols == DWARF_DEBUG)
3032 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
3033 #endif
3035 #ifdef DWARF2_DEBUGGING_INFO
3036 if (write_symbols == DWARF2_DEBUG)
3037 dwarf2out_line (filename, NOTE_LINE_NUMBER (insn));
3038 #endif
3043 /* For each operand in INSN, simplify (subreg (reg)) so that it refers
3044 directly to the desired hard register. */
3045 void
3046 cleanup_subreg_operands (insn)
3047 rtx insn;
3049 int i;
3051 extract_insn (insn);
3052 for (i = 0; i < recog_data.n_operands; i++)
3054 if (GET_CODE (recog_data.operand[i]) == SUBREG)
3055 recog_data.operand[i] = alter_subreg (recog_data.operand[i]);
3056 else if (GET_CODE (recog_data.operand[i]) == PLUS
3057 || GET_CODE (recog_data.operand[i]) == MULT)
3058 recog_data.operand[i] = walk_alter_subreg (recog_data.operand[i]);
3061 for (i = 0; i < recog_data.n_dups; i++)
3063 if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
3064 *recog_data.dup_loc[i] = alter_subreg (*recog_data.dup_loc[i]);
3065 else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
3066 || GET_CODE (*recog_data.dup_loc[i]) == MULT)
3067 *recog_data.dup_loc[i] = walk_alter_subreg (*recog_data.dup_loc[i]);
3071 /* If X is a SUBREG, replace it with a REG or a MEM,
3072 based on the thing it is a subreg of. */
3075 alter_subreg (x)
3076 register rtx x;
3078 register rtx y = SUBREG_REG (x);
3080 if (GET_CODE (y) == SUBREG)
3081 y = alter_subreg (y);
3083 /* If reload is operating, we may be replacing inside this SUBREG.
3084 Check for that and make a new one if so. */
3085 if (reload_in_progress && find_replacement (&SUBREG_REG (x)) != 0)
3086 x = copy_rtx (x);
3088 if (GET_CODE (y) == REG)
3090 int regno;
3091 /* If the word size is larger than the size of this register,
3092 adjust the register number to compensate. */
3093 /* ??? Note that this just catches stragglers created by/for
3094 integrate. It would be better if we either caught these
3095 earlier, or kept _all_ subregs until now and eliminate
3096 gen_lowpart and friends. */
3098 #ifdef ALTER_HARD_SUBREG
3099 regno = ALTER_HARD_SUBREG(GET_MODE (x), SUBREG_WORD (x),
3100 GET_MODE (y), REGNO (y));
3101 #else
3102 regno = REGNO (y) + SUBREG_WORD (x);
3103 #endif
3104 PUT_CODE (x, REG);
3105 REGNO (x) = regno;
3106 /* This field has a different meaning for REGs and SUBREGs. Make sure
3107 to clear it! */
3108 x->used = 0;
3110 else if (GET_CODE (y) == MEM)
3112 register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
3113 if (BYTES_BIG_ENDIAN)
3114 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
3115 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
3116 PUT_CODE (x, MEM);
3117 MEM_COPY_ATTRIBUTES (x, y);
3118 MEM_ALIAS_SET (x) = MEM_ALIAS_SET (y);
3119 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
3122 return x;
3125 /* Do alter_subreg on all the SUBREGs contained in X. */
3127 static rtx
3128 walk_alter_subreg (x)
3129 rtx x;
3131 switch (GET_CODE (x))
3133 case PLUS:
3134 case MULT:
3135 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3136 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
3137 break;
3139 case MEM:
3140 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3141 break;
3143 case SUBREG:
3144 return alter_subreg (x);
3146 default:
3147 break;
3150 return x;
3153 #ifdef HAVE_cc0
3155 /* Given BODY, the body of a jump instruction, alter the jump condition
3156 as required by the bits that are set in cc_status.flags.
3157 Not all of the bits there can be handled at this level in all cases.
3159 The value is normally 0.
3160 1 means that the condition has become always true.
3161 -1 means that the condition has become always false.
3162 2 means that COND has been altered. */
3164 static int
3165 alter_cond (cond)
3166 register rtx cond;
3168 int value = 0;
3170 if (cc_status.flags & CC_REVERSED)
3172 value = 2;
3173 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
3176 if (cc_status.flags & CC_INVERTED)
3178 value = 2;
3179 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
3182 if (cc_status.flags & CC_NOT_POSITIVE)
3183 switch (GET_CODE (cond))
3185 case LE:
3186 case LEU:
3187 case GEU:
3188 /* Jump becomes unconditional. */
3189 return 1;
3191 case GT:
3192 case GTU:
3193 case LTU:
3194 /* Jump becomes no-op. */
3195 return -1;
3197 case GE:
3198 PUT_CODE (cond, EQ);
3199 value = 2;
3200 break;
3202 case LT:
3203 PUT_CODE (cond, NE);
3204 value = 2;
3205 break;
3207 default:
3208 break;
3211 if (cc_status.flags & CC_NOT_NEGATIVE)
3212 switch (GET_CODE (cond))
3214 case GE:
3215 case GEU:
3216 /* Jump becomes unconditional. */
3217 return 1;
3219 case LT:
3220 case LTU:
3221 /* Jump becomes no-op. */
3222 return -1;
3224 case LE:
3225 case LEU:
3226 PUT_CODE (cond, EQ);
3227 value = 2;
3228 break;
3230 case GT:
3231 case GTU:
3232 PUT_CODE (cond, NE);
3233 value = 2;
3234 break;
3236 default:
3237 break;
3240 if (cc_status.flags & CC_NO_OVERFLOW)
3241 switch (GET_CODE (cond))
3243 case GEU:
3244 /* Jump becomes unconditional. */
3245 return 1;
3247 case LEU:
3248 PUT_CODE (cond, EQ);
3249 value = 2;
3250 break;
3252 case GTU:
3253 PUT_CODE (cond, NE);
3254 value = 2;
3255 break;
3257 case LTU:
3258 /* Jump becomes no-op. */
3259 return -1;
3261 default:
3262 break;
3265 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
3266 switch (GET_CODE (cond))
3268 default:
3269 abort ();
3271 case NE:
3272 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
3273 value = 2;
3274 break;
3276 case EQ:
3277 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
3278 value = 2;
3279 break;
3282 if (cc_status.flags & CC_NOT_SIGNED)
3283 /* The flags are valid if signed condition operators are converted
3284 to unsigned. */
3285 switch (GET_CODE (cond))
3287 case LE:
3288 PUT_CODE (cond, LEU);
3289 value = 2;
3290 break;
3292 case LT:
3293 PUT_CODE (cond, LTU);
3294 value = 2;
3295 break;
3297 case GT:
3298 PUT_CODE (cond, GTU);
3299 value = 2;
3300 break;
3302 case GE:
3303 PUT_CODE (cond, GEU);
3304 value = 2;
3305 break;
3307 default:
3308 break;
3311 return value;
3313 #endif
3315 /* Report inconsistency between the assembler template and the operands.
3316 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
3318 void
3319 output_operand_lossage (msgid)
3320 const char *msgid;
3322 if (this_is_asm_operands)
3323 error_for_asm (this_is_asm_operands, "invalid `asm': %s", _(msgid));
3324 else
3326 error ("output_operand: %s", _(msgid));
3327 abort ();
3331 /* Output of assembler code from a template, and its subroutines. */
3333 /* Output text from TEMPLATE to the assembler output file,
3334 obeying %-directions to substitute operands taken from
3335 the vector OPERANDS.
3337 %N (for N a digit) means print operand N in usual manner.
3338 %lN means require operand N to be a CODE_LABEL or LABEL_REF
3339 and print the label name with no punctuation.
3340 %cN means require operand N to be a constant
3341 and print the constant expression with no punctuation.
3342 %aN means expect operand N to be a memory address
3343 (not a memory reference!) and print a reference
3344 to that address.
3345 %nN means expect operand N to be a constant
3346 and print a constant expression for minus the value
3347 of the operand, with no other punctuation. */
3349 static void
3350 output_asm_name ()
3352 if (flag_print_asm_name)
3354 /* Annotate the assembly with a comment describing the pattern and
3355 alternative used. */
3356 if (debug_insn)
3358 register int num = INSN_CODE (debug_insn);
3359 fprintf (asm_out_file, "\t%s %d\t%s",
3360 ASM_COMMENT_START, INSN_UID (debug_insn),
3361 insn_data[num].name);
3362 if (insn_data[num].n_alternatives > 1)
3363 fprintf (asm_out_file, "/%d", which_alternative + 1);
3364 #ifdef HAVE_ATTR_length
3365 fprintf (asm_out_file, "\t[length = %d]",
3366 get_attr_length (debug_insn));
3367 #endif
3368 /* Clear this so only the first assembler insn
3369 of any rtl insn will get the special comment for -dp. */
3370 debug_insn = 0;
3375 void
3376 output_asm_insn (template, operands)
3377 const char *template;
3378 rtx *operands;
3380 register const char *p;
3381 register int c;
3383 /* An insn may return a null string template
3384 in a case where no assembler code is needed. */
3385 if (*template == 0)
3386 return;
3388 p = template;
3389 putc ('\t', asm_out_file);
3391 #ifdef ASM_OUTPUT_OPCODE
3392 ASM_OUTPUT_OPCODE (asm_out_file, p);
3393 #endif
3395 while ((c = *p++))
3396 switch (c)
3398 case '\n':
3399 output_asm_name ();
3400 putc (c, asm_out_file);
3401 #ifdef ASM_OUTPUT_OPCODE
3402 while ((c = *p) == '\t')
3404 putc (c, asm_out_file);
3405 p++;
3407 ASM_OUTPUT_OPCODE (asm_out_file, p);
3408 #endif
3409 break;
3411 #ifdef ASSEMBLER_DIALECT
3412 case '{':
3414 register int i;
3416 /* If we want the first dialect, do nothing. Otherwise, skip
3417 DIALECT_NUMBER of strings ending with '|'. */
3418 for (i = 0; i < dialect_number; i++)
3420 while (*p && *p != '}' && *p++ != '|')
3422 if (*p == '}')
3423 break;
3424 if (*p == '|')
3425 p++;
3428 break;
3430 case '|':
3431 /* Skip to close brace. */
3432 while (*p && *p++ != '}')
3434 break;
3436 case '}':
3437 break;
3438 #endif
3440 case '%':
3441 /* %% outputs a single %. */
3442 if (*p == '%')
3444 p++;
3445 putc (c, asm_out_file);
3447 /* %= outputs a number which is unique to each insn in the entire
3448 compilation. This is useful for making local labels that are
3449 referred to more than once in a given insn. */
3450 else if (*p == '=')
3452 p++;
3453 fprintf (asm_out_file, "%d", insn_counter);
3455 /* % followed by a letter and some digits
3456 outputs an operand in a special way depending on the letter.
3457 Letters `acln' are implemented directly.
3458 Other letters are passed to `output_operand' so that
3459 the PRINT_OPERAND macro can define them. */
3460 else if (ISLOWER(*p) || ISUPPER(*p))
3462 int letter = *p++;
3463 c = atoi (p);
3465 if (! (*p >= '0' && *p <= '9'))
3466 output_operand_lossage ("operand number missing after %-letter");
3467 else if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3468 output_operand_lossage ("operand number out of range");
3469 else if (letter == 'l')
3470 output_asm_label (operands[c]);
3471 else if (letter == 'a')
3472 output_address (operands[c]);
3473 else if (letter == 'c')
3475 if (CONSTANT_ADDRESS_P (operands[c]))
3476 output_addr_const (asm_out_file, operands[c]);
3477 else
3478 output_operand (operands[c], 'c');
3480 else if (letter == 'n')
3482 if (GET_CODE (operands[c]) == CONST_INT)
3483 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3484 - INTVAL (operands[c]));
3485 else
3487 putc ('-', asm_out_file);
3488 output_addr_const (asm_out_file, operands[c]);
3491 else
3492 output_operand (operands[c], letter);
3494 while ((c = *p) >= '0' && c <= '9') p++;
3496 /* % followed by a digit outputs an operand the default way. */
3497 else if (*p >= '0' && *p <= '9')
3499 c = atoi (p);
3500 if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3501 output_operand_lossage ("operand number out of range");
3502 else
3503 output_operand (operands[c], 0);
3504 while ((c = *p) >= '0' && c <= '9') p++;
3506 /* % followed by punctuation: output something for that
3507 punctuation character alone, with no operand.
3508 The PRINT_OPERAND macro decides what is actually done. */
3509 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3510 else if (PRINT_OPERAND_PUNCT_VALID_P ((unsigned char)*p))
3511 output_operand (NULL_RTX, *p++);
3512 #endif
3513 else
3514 output_operand_lossage ("invalid %%-code");
3515 break;
3517 default:
3518 putc (c, asm_out_file);
3521 output_asm_name ();
3523 putc ('\n', asm_out_file);
3526 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3528 void
3529 output_asm_label (x)
3530 rtx x;
3532 char buf[256];
3534 if (GET_CODE (x) == LABEL_REF)
3535 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
3536 else if (GET_CODE (x) == CODE_LABEL)
3537 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3538 else
3539 output_operand_lossage ("`%l' operand isn't a label");
3541 assemble_name (asm_out_file, buf);
3544 /* Print operand X using machine-dependent assembler syntax.
3545 The macro PRINT_OPERAND is defined just to control this function.
3546 CODE is a non-digit that preceded the operand-number in the % spec,
3547 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3548 between the % and the digits.
3549 When CODE is a non-letter, X is 0.
3551 The meanings of the letters are machine-dependent and controlled
3552 by PRINT_OPERAND. */
3554 static void
3555 output_operand (x, code)
3556 rtx x;
3557 int code ATTRIBUTE_UNUSED;
3559 if (x && GET_CODE (x) == SUBREG)
3560 x = alter_subreg (x);
3562 /* If X is a pseudo-register, abort now rather than writing trash to the
3563 assembler file. */
3565 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
3566 abort ();
3568 PRINT_OPERAND (asm_out_file, x, code);
3571 /* Print a memory reference operand for address X
3572 using machine-dependent assembler syntax.
3573 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
3575 void
3576 output_address (x)
3577 rtx x;
3579 walk_alter_subreg (x);
3580 PRINT_OPERAND_ADDRESS (asm_out_file, x);
3583 /* Print an integer constant expression in assembler syntax.
3584 Addition and subtraction are the only arithmetic
3585 that may appear in these expressions. */
3587 void
3588 output_addr_const (file, x)
3589 FILE *file;
3590 rtx x;
3592 char buf[256];
3594 restart:
3595 switch (GET_CODE (x))
3597 case PC:
3598 if (flag_pic)
3599 putc ('.', file);
3600 else
3601 abort ();
3602 break;
3604 case SYMBOL_REF:
3605 assemble_name (file, XSTR (x, 0));
3606 break;
3608 case LABEL_REF:
3609 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
3610 assemble_name (file, buf);
3611 break;
3613 case CODE_LABEL:
3614 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3615 assemble_name (file, buf);
3616 break;
3618 case CONST_INT:
3619 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3620 break;
3622 case CONST:
3623 /* This used to output parentheses around the expression,
3624 but that does not work on the 386 (either ATT or BSD assembler). */
3625 output_addr_const (file, XEXP (x, 0));
3626 break;
3628 case CONST_DOUBLE:
3629 if (GET_MODE (x) == VOIDmode)
3631 /* We can use %d if the number is one word and positive. */
3632 if (CONST_DOUBLE_HIGH (x))
3633 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3634 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3635 else if (CONST_DOUBLE_LOW (x) < 0)
3636 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3637 else
3638 fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3640 else
3641 /* We can't handle floating point constants;
3642 PRINT_OPERAND must handle them. */
3643 output_operand_lossage ("floating constant misused");
3644 break;
3646 case PLUS:
3647 /* Some assemblers need integer constants to appear last (eg masm). */
3648 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3650 output_addr_const (file, XEXP (x, 1));
3651 if (INTVAL (XEXP (x, 0)) >= 0)
3652 fprintf (file, "+");
3653 output_addr_const (file, XEXP (x, 0));
3655 else
3657 output_addr_const (file, XEXP (x, 0));
3658 if (INTVAL (XEXP (x, 1)) >= 0)
3659 fprintf (file, "+");
3660 output_addr_const (file, XEXP (x, 1));
3662 break;
3664 case MINUS:
3665 /* Avoid outputting things like x-x or x+5-x,
3666 since some assemblers can't handle that. */
3667 x = simplify_subtraction (x);
3668 if (GET_CODE (x) != MINUS)
3669 goto restart;
3671 output_addr_const (file, XEXP (x, 0));
3672 fprintf (file, "-");
3673 if (GET_CODE (XEXP (x, 1)) == CONST_INT
3674 && INTVAL (XEXP (x, 1)) < 0)
3676 fprintf (file, "%s", ASM_OPEN_PAREN);
3677 output_addr_const (file, XEXP (x, 1));
3678 fprintf (file, "%s", ASM_CLOSE_PAREN);
3680 else
3681 output_addr_const (file, XEXP (x, 1));
3682 break;
3684 case ZERO_EXTEND:
3685 case SIGN_EXTEND:
3686 output_addr_const (file, XEXP (x, 0));
3687 break;
3689 default:
3690 output_operand_lossage ("invalid expression as operand");
3694 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3695 %R prints the value of REGISTER_PREFIX.
3696 %L prints the value of LOCAL_LABEL_PREFIX.
3697 %U prints the value of USER_LABEL_PREFIX.
3698 %I prints the value of IMMEDIATE_PREFIX.
3699 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3700 Also supported are %d, %x, %s, %e, %f, %g and %%.
3702 We handle alternate assembler dialects here, just like output_asm_insn. */
3704 void
3705 asm_fprintf VPARAMS ((FILE *file, const char *p, ...))
3707 #ifndef ANSI_PROTOTYPES
3708 FILE *file;
3709 const char *p;
3710 #endif
3711 va_list argptr;
3712 char buf[10];
3713 char *q, c;
3715 VA_START (argptr, p);
3717 #ifndef ANSI_PROTOTYPES
3718 file = va_arg (argptr, FILE *);
3719 p = va_arg (argptr, const char *);
3720 #endif
3722 buf[0] = '%';
3724 while ((c = *p++))
3725 switch (c)
3727 #ifdef ASSEMBLER_DIALECT
3728 case '{':
3730 int i;
3732 /* If we want the first dialect, do nothing. Otherwise, skip
3733 DIALECT_NUMBER of strings ending with '|'. */
3734 for (i = 0; i < dialect_number; i++)
3736 while (*p && *p++ != '|')
3739 if (*p == '|')
3740 p++;
3743 break;
3745 case '|':
3746 /* Skip to close brace. */
3747 while (*p && *p++ != '}')
3749 break;
3751 case '}':
3752 break;
3753 #endif
3755 case '%':
3756 c = *p++;
3757 q = &buf[1];
3758 while ((c >= '0' && c <= '9') || c == '.')
3760 *q++ = c;
3761 c = *p++;
3763 switch (c)
3765 case '%':
3766 fprintf (file, "%%");
3767 break;
3769 case 'd': case 'i': case 'u':
3770 case 'x': case 'p': case 'X':
3771 case 'o':
3772 *q++ = c;
3773 *q = 0;
3774 fprintf (file, buf, va_arg (argptr, int));
3775 break;
3777 case 'w':
3778 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3779 but we do not check for those cases. It means that the value
3780 is a HOST_WIDE_INT, which may be either `int' or `long'. */
3782 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3783 #else
3784 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3785 *q++ = 'l';
3786 #else
3787 *q++ = 'l';
3788 *q++ = 'l';
3789 #endif
3790 #endif
3792 *q++ = *p++;
3793 *q = 0;
3794 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3795 break;
3797 case 'l':
3798 *q++ = c;
3799 *q++ = *p++;
3800 *q = 0;
3801 fprintf (file, buf, va_arg (argptr, long));
3802 break;
3804 case 'e':
3805 case 'f':
3806 case 'g':
3807 *q++ = c;
3808 *q = 0;
3809 fprintf (file, buf, va_arg (argptr, double));
3810 break;
3812 case 's':
3813 *q++ = c;
3814 *q = 0;
3815 fprintf (file, buf, va_arg (argptr, char *));
3816 break;
3818 case 'O':
3819 #ifdef ASM_OUTPUT_OPCODE
3820 ASM_OUTPUT_OPCODE (asm_out_file, p);
3821 #endif
3822 break;
3824 case 'R':
3825 #ifdef REGISTER_PREFIX
3826 fprintf (file, "%s", REGISTER_PREFIX);
3827 #endif
3828 break;
3830 case 'I':
3831 #ifdef IMMEDIATE_PREFIX
3832 fprintf (file, "%s", IMMEDIATE_PREFIX);
3833 #endif
3834 break;
3836 case 'L':
3837 #ifdef LOCAL_LABEL_PREFIX
3838 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3839 #endif
3840 break;
3842 case 'U':
3843 fputs (user_label_prefix, file);
3844 break;
3846 #ifdef ASM_FPRINTF_EXTENSIONS
3847 /* Upper case letters are reserved for general use by asm_fprintf
3848 and so are not available to target specific code. In order to
3849 prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
3850 they are defined here. As they get turned into real extensions
3851 to asm_fprintf they should be removed from this list. */
3852 case 'A': case 'B': case 'C': case 'D': case 'E':
3853 case 'F': case 'G': case 'H': case 'J': case 'K':
3854 case 'M': case 'N': case 'P': case 'Q': case 'S':
3855 case 'T': case 'V': case 'W': case 'Y': case 'Z':
3856 break;
3858 ASM_FPRINTF_EXTENSIONS (file, argptr, p)
3859 #endif
3860 default:
3861 abort ();
3863 break;
3865 default:
3866 fputc (c, file);
3868 va_end (argptr);
3871 /* Split up a CONST_DOUBLE or integer constant rtx
3872 into two rtx's for single words,
3873 storing in *FIRST the word that comes first in memory in the target
3874 and in *SECOND the other. */
3876 void
3877 split_double (value, first, second)
3878 rtx value;
3879 rtx *first, *second;
3881 if (GET_CODE (value) == CONST_INT)
3883 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3885 /* In this case the CONST_INT holds both target words.
3886 Extract the bits from it into two word-sized pieces.
3887 Sign extend each half to HOST_WIDE_INT. */
3888 rtx low, high;
3889 /* On machines where HOST_BITS_PER_WIDE_INT == BITS_PER_WORD
3890 the shift below will cause a compiler warning, even though
3891 this code won't be executed. So put the shift amounts in
3892 variables to avoid the warning. */
3893 int rshift = HOST_BITS_PER_WIDE_INT - BITS_PER_WORD;
3894 int lshift = HOST_BITS_PER_WIDE_INT - 2 * BITS_PER_WORD;
3896 low = GEN_INT ((INTVAL (value) << rshift) >> rshift);
3897 high = GEN_INT ((INTVAL (value) << lshift) >> rshift);
3898 if (WORDS_BIG_ENDIAN)
3900 *first = high;
3901 *second = low;
3903 else
3905 *first = low;
3906 *second = high;
3909 else
3911 /* The rule for using CONST_INT for a wider mode
3912 is that we regard the value as signed.
3913 So sign-extend it. */
3914 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3915 if (WORDS_BIG_ENDIAN)
3917 *first = high;
3918 *second = value;
3920 else
3922 *first = value;
3923 *second = high;
3927 else if (GET_CODE (value) != CONST_DOUBLE)
3929 if (WORDS_BIG_ENDIAN)
3931 *first = const0_rtx;
3932 *second = value;
3934 else
3936 *first = value;
3937 *second = const0_rtx;
3940 else if (GET_MODE (value) == VOIDmode
3941 /* This is the old way we did CONST_DOUBLE integers. */
3942 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3944 /* In an integer, the words are defined as most and least significant.
3945 So order them by the target's convention. */
3946 if (WORDS_BIG_ENDIAN)
3948 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3949 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3951 else
3953 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3954 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3957 else
3959 #ifdef REAL_ARITHMETIC
3960 REAL_VALUE_TYPE r; long l[2];
3961 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3963 /* Note, this converts the REAL_VALUE_TYPE to the target's
3964 format, splits up the floating point double and outputs
3965 exactly 32 bits of it into each of l[0] and l[1] --
3966 not necessarily BITS_PER_WORD bits. */
3967 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3969 /* If 32 bits is an entire word for the target, but not for the host,
3970 then sign-extend on the host so that the number will look the same
3971 way on the host that it would on the target. See for instance
3972 simplify_unary_operation. The #if is needed to avoid compiler
3973 warnings. */
3975 #if HOST_BITS_PER_LONG > 32
3976 if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
3978 if (l[0] & ((long) 1 << 31))
3979 l[0] |= ((long) (-1) << 32);
3980 if (l[1] & ((long) 1 << 31))
3981 l[1] |= ((long) (-1) << 32);
3983 #endif
3985 *first = GEN_INT ((HOST_WIDE_INT) l[0]);
3986 *second = GEN_INT ((HOST_WIDE_INT) l[1]);
3987 #else
3988 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3989 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3990 && ! flag_pretend_float)
3991 abort ();
3993 if (
3994 #ifdef HOST_WORDS_BIG_ENDIAN
3995 WORDS_BIG_ENDIAN
3996 #else
3997 ! WORDS_BIG_ENDIAN
3998 #endif
4001 /* Host and target agree => no need to swap. */
4002 *first = GEN_INT (CONST_DOUBLE_LOW (value));
4003 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
4005 else
4007 *second = GEN_INT (CONST_DOUBLE_LOW (value));
4008 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
4010 #endif /* no REAL_ARITHMETIC */
4014 /* Return nonzero if this function has no function calls. */
4017 leaf_function_p ()
4019 rtx insn;
4021 if (profile_flag || profile_block_flag || profile_arc_flag)
4022 return 0;
4024 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4026 if (GET_CODE (insn) == CALL_INSN
4027 && ! SIBLING_CALL_P (insn))
4028 return 0;
4029 if (GET_CODE (insn) == INSN
4030 && GET_CODE (PATTERN (insn)) == SEQUENCE
4031 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4032 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4033 return 0;
4035 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
4037 if (GET_CODE (XEXP (insn, 0)) == CALL_INSN
4038 && ! SIBLING_CALL_P (insn))
4039 return 0;
4040 if (GET_CODE (XEXP (insn, 0)) == INSN
4041 && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
4042 && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN
4043 && ! SIBLING_CALL_P (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)))
4044 return 0;
4047 return 1;
4050 /* On some machines, a function with no call insns
4051 can run faster if it doesn't create its own register window.
4052 When output, the leaf function should use only the "output"
4053 registers. Ordinarily, the function would be compiled to use
4054 the "input" registers to find its arguments; it is a candidate
4055 for leaf treatment if it uses only the "input" registers.
4056 Leaf function treatment means renumbering so the function
4057 uses the "output" registers instead. */
4059 #ifdef LEAF_REGISTERS
4061 /* Return 1 if this function uses only the registers that can be
4062 safely renumbered. */
4065 only_leaf_regs_used ()
4067 int i;
4068 char *permitted_reg_in_leaf_functions = LEAF_REGISTERS;
4070 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4071 if ((regs_ever_live[i] || global_regs[i])
4072 && ! permitted_reg_in_leaf_functions[i])
4073 return 0;
4075 if (current_function_uses_pic_offset_table
4076 && pic_offset_table_rtx != 0
4077 && GET_CODE (pic_offset_table_rtx) == REG
4078 && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
4079 return 0;
4081 return 1;
4084 /* Scan all instructions and renumber all registers into those
4085 available in leaf functions. */
4087 static void
4088 leaf_renumber_regs (first)
4089 rtx first;
4091 rtx insn;
4093 /* Renumber only the actual patterns.
4094 The reg-notes can contain frame pointer refs,
4095 and renumbering them could crash, and should not be needed. */
4096 for (insn = first; insn; insn = NEXT_INSN (insn))
4097 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
4098 leaf_renumber_regs_insn (PATTERN (insn));
4099 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
4100 if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
4101 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
4104 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
4105 available in leaf functions. */
4107 void
4108 leaf_renumber_regs_insn (in_rtx)
4109 register rtx in_rtx;
4111 register int i, j;
4112 register const char *format_ptr;
4114 if (in_rtx == 0)
4115 return;
4117 /* Renumber all input-registers into output-registers.
4118 renumbered_regs would be 1 for an output-register;
4119 they */
4121 if (GET_CODE (in_rtx) == REG)
4123 int newreg;
4125 /* Don't renumber the same reg twice. */
4126 if (in_rtx->used)
4127 return;
4129 newreg = REGNO (in_rtx);
4130 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
4131 to reach here as part of a REG_NOTE. */
4132 if (newreg >= FIRST_PSEUDO_REGISTER)
4134 in_rtx->used = 1;
4135 return;
4137 newreg = LEAF_REG_REMAP (newreg);
4138 if (newreg < 0)
4139 abort ();
4140 regs_ever_live[REGNO (in_rtx)] = 0;
4141 regs_ever_live[newreg] = 1;
4142 REGNO (in_rtx) = newreg;
4143 in_rtx->used = 1;
4146 if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
4148 /* Inside a SEQUENCE, we find insns.
4149 Renumber just the patterns of these insns,
4150 just as we do for the top-level insns. */
4151 leaf_renumber_regs_insn (PATTERN (in_rtx));
4152 return;
4155 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
4157 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
4158 switch (*format_ptr++)
4160 case 'e':
4161 leaf_renumber_regs_insn (XEXP (in_rtx, i));
4162 break;
4164 case 'E':
4165 if (NULL != XVEC (in_rtx, i))
4167 for (j = 0; j < XVECLEN (in_rtx, i); j++)
4168 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
4170 break;
4172 case 'S':
4173 case 's':
4174 case '0':
4175 case 'i':
4176 case 'w':
4177 case 'n':
4178 case 'u':
4179 break;
4181 default:
4182 abort ();
4185 #endif