1 /* Convert RTL to assembler code and output it, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This is the final pass of the compiler.
23 It looks at the rtl code for a function and outputs assembler code.
25 Call `final_start_function' to output the assembler code for function entry,
26 `final' to output assembler code for some RTL code,
27 `final_end_function' to output assembler code for function exit.
28 If a function is compiled in several pieces, each piece is
29 output separately with `final'.
31 Some optimizations are also done at this level.
32 Move instructions that were made unnecessary by good register allocation
33 are detected and omitted from the output. (Though most of these
34 are removed by the last jump pass.)
36 Instructions to set the condition codes are omitted when it can be
37 seen that the condition codes already had the desired values.
39 In some cases it is sufficient if the inherited condition codes
40 have related values, but this may require the following insn
41 (the one that tests the condition codes) to be modified.
43 The code for the function prologue and epilogue are generated
44 directly as assembler code by the macros FUNCTION_PROLOGUE and
45 FUNCTION_EPILOGUE. Those instructions never exist as rtl. */
58 #include "insn-config.h"
59 #include "insn-flags.h"
60 #include "insn-attr.h"
61 #include "insn-codes.h"
63 #include "conditions.h"
66 #include "hard-reg-set.h"
71 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist. */
72 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
73 #if defined (USG) || defined (NO_STAB_H)
74 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
76 #include <stab.h> /* On BSD, use the system's stab.h. */
78 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
80 #ifdef XCOFF_DEBUGGING_INFO
84 /* .stabd code for line number. */
89 /* .stabs code for included file name. */
95 #define INT_TYPE_SIZE BITS_PER_WORD
98 #ifndef LONG_TYPE_SIZE
99 #define LONG_TYPE_SIZE BITS_PER_WORD
102 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
103 null default for it to save conditionalization later. */
104 #ifndef CC_STATUS_INIT
105 #define CC_STATUS_INIT
108 /* How to start an assembler comment. */
109 #ifndef ASM_COMMENT_START
110 #define ASM_COMMENT_START ";#"
113 /* Is the given character a logical line separator for the assembler? */
114 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
115 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
118 /* Nonzero means this function is a leaf function, with no function calls.
119 This variable exists to be examined in FUNCTION_PROLOGUE
120 and FUNCTION_EPILOGUE. Always zero, unless set by some action. */
123 /* Last insn processed by final_scan_insn. */
124 static rtx debug_insn = 0;
126 /* Line number of last NOTE. */
127 static int last_linenum;
129 /* Highest line number in current block. */
130 static int high_block_linenum;
132 /* Likewise for function. */
133 static int high_function_linenum;
135 /* Filename of last NOTE. */
136 static char *last_filename;
138 /* Number of basic blocks seen so far;
139 used if profile_block_flag is set. */
140 static int count_basic_blocks;
142 /* Number of instrumented arcs when profile_arc_flag is set. */
143 extern int count_instrumented_arcs;
145 extern int length_unit_log; /* This is defined in insn-attrtab.c. */
147 /* Nonzero while outputting an `asm' with operands.
148 This means that inconsistencies are the user's fault, so don't abort.
149 The precise value is the insn being output, to pass to error_for_asm. */
150 static rtx this_is_asm_operands;
152 /* Number of operands of this insn, for an `asm' with operands. */
153 static unsigned int insn_noperands;
155 /* Compare optimization flag. */
157 static rtx last_ignored_compare = 0;
159 /* Flag indicating this insn is the start of a new basic block. */
161 static int new_block = 1;
163 /* All the symbol-blocks (levels of scoping) in the compilation
164 are assigned sequence numbers in order of appearance of the
165 beginnings of the symbol-blocks. Both final and dbxout do this,
166 and assume that they will both give the same number to each block.
167 Final uses these sequence numbers to generate assembler label names
168 LBBnnn and LBEnnn for the beginning and end of the symbol-block.
169 Dbxout uses the sequence numbers to generate references to the same labels
170 from the dbx debugging information.
172 Sdb records this level at the beginning of each function,
173 in order to find the current level when recursing down declarations.
174 It outputs the block beginning and endings
175 at the point in the asm file where the blocks would begin and end. */
177 int next_block_index;
179 /* Assign a unique number to each insn that is output.
180 This can be used to generate unique local labels. */
182 static int insn_counter = 0;
185 /* This variable contains machine-dependent flags (defined in tm.h)
186 set and examined by output routines
187 that describe how to interpret the condition codes properly. */
191 /* During output of an insn, this contains a copy of cc_status
192 from before the insn. */
194 CC_STATUS cc_prev_status;
197 /* Indexed by hardware reg number, is 1 if that register is ever
198 used in the current function.
200 In life_analysis, or in stupid_life_analysis, this is set
201 up to record the hard regs used explicitly. Reload adds
202 in the hard regs used for holding pseudo regs. Final uses
203 it to generate the code in the function prologue and epilogue
204 to save and restore registers as needed. */
206 char regs_ever_live[FIRST_PSEUDO_REGISTER];
208 /* Nonzero means current function must be given a frame pointer.
209 Set in stmt.c if anything is allocated on the stack there.
210 Set in reload1.c if anything is allocated on the stack there. */
212 int frame_pointer_needed;
214 /* Assign unique numbers to labels generated for profiling. */
216 int profile_label_no;
218 /* Length so far allocated in PENDING_BLOCKS. */
220 static int max_block_depth;
222 /* Stack of sequence numbers of symbol-blocks of which we have seen the
223 beginning but not yet the end. Sequence numbers are assigned at
224 the beginning; this stack allows us to find the sequence number
225 of a block that is ending. */
227 static int *pending_blocks;
229 /* Number of elements currently in use in PENDING_BLOCKS. */
231 static int block_depth;
233 /* Nonzero if have enabled APP processing of our assembler output. */
237 /* If we are outputting an insn sequence, this contains the sequence rtx.
242 #ifdef ASSEMBLER_DIALECT
244 /* Number of the assembler dialect to use, starting at 0. */
245 static int dialect_number;
248 /* Indexed by line number, nonzero if there is a note for that line. */
250 static char *line_note_exists;
252 /* Linked list to hold line numbers for each basic block. */
255 struct bb_list *next; /* pointer to next basic block */
256 int line_num; /* line number */
257 int file_label_num; /* LPBC<n> label # for stored filename */
258 int func_label_num; /* LPBC<n> label # for stored function name */
261 static struct bb_list *bb_head = 0; /* Head of basic block list */
262 static struct bb_list **bb_tail = &bb_head; /* Ptr to store next bb ptr */
263 static int bb_file_label_num = -1; /* Current label # for file */
264 static int bb_func_label_num = -1; /* Current label # for func */
266 /* Linked list to hold the strings for each file and function name output. */
269 struct bb_str *next; /* pointer to next string */
270 char *string; /* string */
271 int label_num; /* label number */
272 int length; /* string length */
275 extern rtx peephole PROTO((rtx));
277 static struct bb_str *sbb_head = 0; /* Head of string list. */
278 static struct bb_str **sbb_tail = &sbb_head; /* Ptr to store next bb str */
279 static int sbb_label_num = 0; /* Last label used */
281 #ifdef HAVE_ATTR_length
282 static int asm_insn_count PROTO((rtx));
284 static void profile_function PROTO((FILE *));
285 static void profile_after_prologue PROTO((FILE *));
286 static void add_bb PROTO((FILE *));
287 static int add_bb_string PROTO((char *, int));
288 static void output_source_line PROTO((FILE *, rtx));
289 static rtx walk_alter_subreg PROTO((rtx));
290 static void output_asm_name PROTO((void));
291 static void output_operand PROTO((rtx, int));
292 #ifdef LEAF_REGISTERS
293 static void leaf_renumber_regs PROTO((rtx));
296 static int alter_cond PROTO((rtx));
299 extern char *getpwd ();
301 /* Initialize data in final at the beginning of a compilation. */
304 init_final (filename)
307 next_block_index = 2;
309 max_block_depth = 20;
310 pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
313 #ifdef ASSEMBLER_DIALECT
314 dialect_number = ASSEMBLER_DIALECT;
318 /* Called at end of source file,
319 to output the block-profiling table for this entire compilation. */
327 if (profile_block_flag || profile_arc_flag)
330 int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
334 int long_bytes = LONG_TYPE_SIZE / BITS_PER_UNIT;
335 int pointer_bytes = POINTER_SIZE / BITS_PER_UNIT;
337 if (profile_block_flag)
338 size = long_bytes * count_basic_blocks;
340 size = long_bytes * count_instrumented_arcs;
343 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
344 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
345 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
349 /* Output the main header, of 11 words:
350 0: 1 if this file is initialized, else 0.
351 1: address of file name (LPBX1).
352 2: address of table of counts (LPBX2).
353 3: number of counts in the table.
354 4: always 0, for compatibility with Sun.
356 The following are GNU extensions:
358 5: address of table of start addrs of basic blocks (LPBX3).
359 6: Number of bytes in this header.
360 7: address of table of function names (LPBX4).
361 8: address of table of line numbers (LPBX5) or 0.
362 9: address of table of file names (LPBX6) or 0.
363 10: space reserved for basic block profiling. */
365 ASM_OUTPUT_ALIGN (asm_out_file, align);
367 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
369 assemble_integer (const0_rtx, long_bytes, 1);
371 /* address of filename */
372 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
373 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
375 /* address of count table */
376 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
377 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
379 /* count of the # of basic blocks or # of instrumented arcs */
380 if (profile_block_flag)
381 assemble_integer (GEN_INT (count_basic_blocks), long_bytes, 1);
383 assemble_integer (GEN_INT (count_instrumented_arcs), long_bytes,
386 /* zero word (link field) */
387 assemble_integer (const0_rtx, pointer_bytes, 1);
389 /* address of basic block start address table */
390 if (profile_block_flag)
392 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
393 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
397 assemble_integer (const0_rtx, pointer_bytes, 1);
399 /* byte count for extended structure. */
400 assemble_integer (GEN_INT (10 * UNITS_PER_WORD), long_bytes, 1);
402 /* address of function name table */
403 if (profile_block_flag)
405 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
406 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
410 assemble_integer (const0_rtx, pointer_bytes, 1);
412 /* address of line number and filename tables if debugging. */
413 if (write_symbols != NO_DEBUG && profile_block_flag)
415 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
416 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
417 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
418 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
422 assemble_integer (const0_rtx, pointer_bytes, 1);
423 assemble_integer (const0_rtx, pointer_bytes, 1);
426 /* space for extension ptr (link field) */
427 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
429 /* Output the file name changing the suffix to .d for Sun tcov
431 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
433 char *cwd = getpwd ();
434 int len = strlen (filename) + strlen (cwd) + 1;
435 char *data_file = (char *) alloca (len + 4);
437 strcpy (data_file, cwd);
438 strcat (data_file, "/");
439 strcat (data_file, filename);
440 strip_off_ending (data_file, len);
441 if (profile_block_flag)
442 strcat (data_file, ".d");
444 strcat (data_file, ".da");
445 assemble_string (data_file, strlen (data_file) + 1);
448 /* Make space for the table of counts. */
451 /* Realign data section. */
452 ASM_OUTPUT_ALIGN (asm_out_file, align);
453 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
455 assemble_zeros (size);
459 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
460 #ifdef ASM_OUTPUT_SHARED_LOCAL
461 if (flag_shared_data)
462 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
465 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
466 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
469 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
470 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
473 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
478 /* Output any basic block strings */
479 if (profile_block_flag)
481 readonly_data_section ();
484 ASM_OUTPUT_ALIGN (asm_out_file, align);
485 for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
487 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC",
489 assemble_string (sptr->string, sptr->length);
494 /* Output the table of addresses. */
495 if (profile_block_flag)
497 /* Realign in new section */
498 ASM_OUTPUT_ALIGN (asm_out_file, align);
499 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
500 for (i = 0; i < count_basic_blocks; i++)
502 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
503 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
508 /* Output the table of function names. */
509 if (profile_block_flag)
511 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
512 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
514 if (ptr->func_label_num >= 0)
516 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
517 ptr->func_label_num);
518 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
522 assemble_integer (const0_rtx, pointer_bytes, 1);
525 for ( ; i < count_basic_blocks; i++)
526 assemble_integer (const0_rtx, pointer_bytes, 1);
529 if (write_symbols != NO_DEBUG && profile_block_flag)
531 /* Output the table of line numbers. */
532 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
533 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
534 assemble_integer (GEN_INT (ptr->line_num), long_bytes, 1);
536 for ( ; i < count_basic_blocks; i++)
537 assemble_integer (const0_rtx, long_bytes, 1);
539 /* Output the table of file names. */
540 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
541 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
543 if (ptr->file_label_num >= 0)
545 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
546 ptr->file_label_num);
547 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
551 assemble_integer (const0_rtx, pointer_bytes, 1);
554 for ( ; i < count_basic_blocks; i++)
555 assemble_integer (const0_rtx, pointer_bytes, 1);
558 /* End with the address of the table of addresses,
559 so we can find it easily, as the last word in the file's text. */
560 if (profile_block_flag)
562 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
563 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
569 /* Enable APP processing of subsequent output.
570 Used before the output from an `asm' statement. */
577 fputs (ASM_APP_ON, asm_out_file);
582 /* Disable APP processing of subsequent output.
583 Called from varasm.c before most kinds of output. */
590 fputs (ASM_APP_OFF, asm_out_file);
595 /* Return the number of slots filled in the current
596 delayed branch sequence (we don't count the insn needing the
597 delay slot). Zero if not in a delayed branch sequence. */
601 dbr_sequence_length ()
603 if (final_sequence != 0)
604 return XVECLEN (final_sequence, 0) - 1;
610 /* The next two pages contain routines used to compute the length of an insn
611 and to shorten branches. */
613 /* Arrays for insn lengths, and addresses. The latter is referenced by
614 `insn_current_length'. */
616 static short *insn_lengths;
619 /* Address of insn being processed. Used by `insn_current_length'. */
620 int insn_current_address;
622 /* Address of insn being processed in previous iteration. */
623 int insn_last_address;
625 /* konwn invariant alignment of insn being processed. */
626 int insn_current_align;
628 /* After shorten_branches, for any insn, uid_align[INSN_UID (insn)]
629 gives the next following alignment insn that increases the known
630 alignment, or NULL_RTX if there is no such insn.
631 For any alignment obtained this way, we can again index uid_align with
632 its uid to obtain the next following align that in turn increases the
633 alignment, till we reach NULL_RTX; the sequence obtained this way
634 for each insn we'll call the alignment chain of this insn in the following
641 /* Indicate that branch shortening hasn't yet been done. */
663 free (insn_addresses);
673 /* Obtain the current length of an insn. If branch shortening has been done,
674 get its actual length. Otherwise, get its maximum length. */
677 get_attr_length (insn)
680 #ifdef HAVE_ATTR_length
686 return insn_lengths[INSN_UID (insn)];
688 switch (GET_CODE (insn))
696 length = insn_default_length (insn);
700 body = PATTERN (insn);
701 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
703 /* Alignment is machine-dependent and should be handled by
707 length = insn_default_length (insn);
711 body = PATTERN (insn);
712 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
715 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
716 length = asm_insn_count (body) * insn_default_length (insn);
717 else if (GET_CODE (body) == SEQUENCE)
718 for (i = 0; i < XVECLEN (body, 0); i++)
719 length += get_attr_length (XVECEXP (body, 0, i));
721 length = insn_default_length (insn);
728 #ifdef ADJUST_INSN_LENGTH
729 ADJUST_INSN_LENGTH (insn, length);
732 #else /* not HAVE_ATTR_length */
734 #endif /* not HAVE_ATTR_length */
737 /* Code to handle alignment inside shorten_branches. */
739 /* Here is an explanation how the algorithm in align_fuzz can give
742 Call a sequence of instructions beginning with alignment point X
743 and continuing until the next alignment point `block X'. When `X'
744 is used in an expression, it means the alignment value of the
747 Call the distance between the start of the first insn of block X, and
748 the end of the last insn of block X `IX', for the `inner size of X'.
749 This is clearly the sum of the instruction lengths.
751 Likewise with the next alignment-delimited block following X, which we
754 Call the distance between the start of the first insn of block X, and
755 the start of the first insn of block Y `OX', for the `outer size of X'.
757 The estimated padding is then OX - IX.
759 OX can be safely estimated as
764 OX = round_up(IX, X) + Y - X
766 Clearly est(IX) >= real(IX), because that only depends on the
767 instruction lengths, and those being overestimated is a given.
769 Clearly round_up(foo, Z) >= round_up(bar, Z) if foo >= bar, so
770 we needn't worry about that when thinking about OX.
772 When X >= Y, the alignment provided by Y adds no uncertainty factor
773 for branch ranges starting before X, so we can just round what we have.
774 But when X < Y, we don't know anything about the, so to speak,
775 `middle bits', so we have to assume the worst when aligning up from an
776 address mod X to one mod Y, which is Y - X. */
779 #define LABEL_ALIGN(LABEL) 0
783 #define LOOP_ALIGN(LABEL) 0
786 #ifndef LABEL_ALIGN_AFTER_BARRIER
787 #define LABEL_ALIGN_AFTER_BARRIER(LABEL) 0
790 #ifndef ADDR_VEC_ALIGN
792 final_addr_vec_align (addr_vec)
795 int align = exact_log2 (GET_MODE_SIZE (GET_MODE (PATTERN (addr_vec))));
797 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
798 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
802 #define ADDR_VEC_ALIGN(ADDR_VEC) final_addr_vec_align (ADDR_VEC)
805 #ifndef INSN_LENGTH_ALIGNMENT
806 #define INSN_LENGTH_ALIGNMENT(INSN) length_unit_log
809 #define INSN_SHUID(INSN) (uid_shuid[INSN_UID (INSN)])
811 static int min_labelno, max_labelno;
813 #define LABEL_TO_ALIGNMENT(LABEL) \
814 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno])
816 /* For the benefit of port specific code do this also as a function. */
818 label_to_alignment (label)
821 return LABEL_TO_ALIGNMENT (label);
824 #ifdef HAVE_ATTR_length
825 /* The differences in addresses
826 between a branch and its target might grow or shrink depending on
827 the alignment the start insn of the range (the branch for a forward
828 branch or the label for a backward branch) starts out on; if these
829 differences are used naively, they can even oscillate infinitely.
830 We therefore want to compute a 'worst case' address difference that
831 is independent of the alignment the start insn of the range end
832 up on, and that is at least as large as the actual difference.
833 The function align_fuzz calculates the amount we have to add to the
834 naively computed difference, by traversing the part of the alignment
835 chain of the start insn of the range that is in front of the end insn
836 of the range, and considering for each alignment the maximum amount
837 that it might contribute to a size increase.
839 For casesi tables, we also want to know worst case minimum amounts of
840 address difference, in case a machine description wants to introduce
841 some common offset that is added to all offsets in a table.
842 For this purpose, align_fuzz with a growth argument of 0 comuptes the
843 appropriate adjustment. */
846 /* Compute the maximum delta by which the difference of the addresses of
847 START and END might grow / shrink due to a different address for start
848 which changes the size of alignment insns between START and END.
849 KNOWN_ALIGN_LOG is the alignment known for START.
850 GROWTH should be ~0 if the objective is to compute potential code size
851 increase, and 0 if the objective is to compute potential shrink.
852 The return value is undefined for any other value of GROWTH. */
854 align_fuzz (start, end, known_align_log, growth)
859 int uid = INSN_UID (start);
861 int known_align = 1 << known_align_log;
862 int end_shuid = INSN_SHUID (end);
865 for (align_label = uid_align[uid]; align_label; align_label = uid_align[uid])
867 int align_addr, new_align;
869 uid = INSN_UID (align_label);
870 align_addr = insn_addresses[uid] - insn_lengths[uid];
871 if (uid_shuid[uid] > end_shuid)
873 known_align_log = LABEL_TO_ALIGNMENT (align_label);
874 new_align = 1 << known_align_log;
875 if (new_align < known_align)
877 fuzz += (-align_addr ^ growth) & (new_align - known_align);
878 known_align = new_align;
883 /* Compute a worst-case reference address of a branch so that it
884 can be safely used in the presence of aligned labels. Since the
885 size of the branch itself is unknown, the size of the branch is
886 not included in the range. I.e. for a forward branch, the reference
887 address is the end address of the branch as known from the previous
888 branch shortening pass, minus a value to account for possible size
889 increase due to alignment. For a backward branch, it is the start
890 address of the branch as known from the current pass, plus a value
891 to account for possible size increase due to alignment.
892 NB.: Therefore, the maximum offset allowed for backward branches needs
893 to exclude the branch size. */
895 insn_current_reference_address (branch)
899 rtx seq = NEXT_INSN (PREV_INSN (branch));
900 int seq_uid = INSN_UID (seq);
901 if (GET_CODE (branch) != JUMP_INSN)
902 /* This can happen for example on the PA; the objective is to know the
903 offset to address something in front of the start of the function.
904 Thus, we can treat it like a backward branch.
905 We assume here that FUNCTION_BOUNDARY / BITS_PER_UNIT is larger than
906 any alignment we'd encounter, so we skip the call to align_fuzz. */
907 return insn_current_address;
908 dest = JUMP_LABEL (branch);
909 /* BRANCH has no proper alignment chain set, so use SEQ. */
910 if (INSN_SHUID (branch) < INSN_SHUID (dest))
912 /* Forward branch. */
913 return (insn_last_address + insn_lengths[seq_uid]
914 - align_fuzz (seq, dest, length_unit_log, ~0));
918 /* Backward branch. */
919 return (insn_current_address
920 + align_fuzz (dest, seq, length_unit_log, ~0));
923 #endif /* HAVE_ATTR_length */
925 /* Make a pass over all insns and compute their actual lengths by shortening
926 any branches of variable length if possible. */
928 /* Give a default value for the lowest address in a function. */
930 #ifndef FIRST_INSN_ADDRESS
931 #define FIRST_INSN_ADDRESS 0
934 /* shorten_branches might be called multiple times: for example, the SH
935 port splits out-of-range conditional branches in MACHINE_DEPENDENT_REORG.
936 In order to do this, it needs proper length information, which it obtains
937 by calling shorten_branches. This cannot be collapsed with
938 shorten_branches itself into a single pass unless we also want to intergate
939 reorg.c, since the branch splitting exposes new instructions with delay
943 shorten_branches (first)
950 #ifdef HAVE_ATTR_length
951 #define MAX_CODE_ALIGN 16
953 int something_changed = 1;
954 char *varying_length;
957 rtx align_tab[MAX_CODE_ALIGN];
959 /* In order to make sure that all instructions have valid length info,
960 we must split them before we compute the address/length info. */
962 for (insn = NEXT_INSN (first); insn; insn = NEXT_INSN (insn))
963 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
966 insn = try_split (PATTERN (old), old, 1);
967 /* When not optimizing, the old insn will be still left around
968 with only the 'deleted' bit set. Transform it into a note
969 to avoid confusion of subsequent processing. */
970 if (INSN_DELETED_P (old))
972 PUT_CODE (old , NOTE);
973 NOTE_LINE_NUMBER (old) = NOTE_INSN_DELETED;
974 NOTE_SOURCE_FILE (old) = 0;
979 /* We must do some computations even when not actually shortening, in
980 order to get the alignment information for the labels. */
982 init_insn_lengths ();
984 /* Compute maximum UID and allocate label_align / uid_shuid. */
985 max_uid = get_max_uid ();
987 max_labelno = max_label_num ();
988 min_labelno = get_first_label_num ();
990 = (short*) xmalloc ((max_labelno - min_labelno + 1) * sizeof (short));
991 bzero (label_align, (max_labelno - min_labelno + 1) * sizeof (short));
993 uid_shuid = (int *) xmalloc (max_uid * sizeof *uid_shuid);
995 /* Initialize label_align and set up uid_shuid to be strictly
996 monotonically rising with insn order. */
997 /* We use max_log here to keep track of the maximum alignment we want to
998 impose on the next CODE_LABEL (or the current one if we are processing
999 the CODE_LABEL itself). */
1001 for (max_log = 0, insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn))
1005 INSN_SHUID (insn) = i++;
1006 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1008 /* reorg might make the first insn of a loop being run once only,
1009 and delete the label in front of it. Then we want to apply
1010 the loop alignment to the new label created by reorg, which
1011 is separated by the former loop start insn from the
1012 NOTE_INSN_LOOP_BEG. */
1014 else if (GET_CODE (insn) == CODE_LABEL)
1018 log = LABEL_ALIGN (insn);
1021 next = NEXT_INSN (insn);
1022 /* ADDR_VECs only take room if read-only data goes into the text section. */
1023 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
1024 if (next && GET_CODE (next) == JUMP_INSN)
1026 rtx nextbody = PATTERN (next);
1027 if (GET_CODE (nextbody) == ADDR_VEC
1028 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1030 log = ADDR_VEC_ALIGN (next);
1036 LABEL_TO_ALIGNMENT (insn) = max_log;
1039 else if (GET_CODE (insn) == BARRIER)
1043 for (label = insn; label && GET_RTX_CLASS (GET_CODE (label)) != 'i';
1044 label = NEXT_INSN (label))
1045 if (GET_CODE (label) == CODE_LABEL)
1047 log = LABEL_ALIGN_AFTER_BARRIER (insn);
1053 /* Again, we allow NOTE_INSN_LOOP_BEG - INSN - CODE_LABEL
1054 sequences in order to handle reorg output efficiently. */
1055 else if (GET_CODE (insn) == NOTE
1056 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
1060 for (label = insn; label; label = NEXT_INSN (label))
1061 if (GET_CODE (label) == CODE_LABEL)
1063 log = LOOP_ALIGN (insn);
1072 #ifdef HAVE_ATTR_length
1074 /* Allocate the rest of the arrays. */
1075 insn_lengths = (short *) xmalloc (max_uid * sizeof (short));
1076 insn_addresses = (int *) xmalloc (max_uid * sizeof (int));
1077 /* Syntax errors can lead to labels being outside of the main insn stream.
1078 Initialize insn_addresses, so that we get reproducible results. */
1079 bzero ((char *)insn_addresses, max_uid * sizeof *insn_addresses);
1080 uid_align = (rtx *) xmalloc (max_uid * sizeof *uid_align);
1082 varying_length = (char *) xmalloc (max_uid * sizeof (char));
1084 bzero (varying_length, max_uid);
1086 /* Initialize uid_align. We scan instructions
1087 from end to start, and keep in align_tab[n] the last seen insn
1088 that does an alignment of at least n+1, i.e. the successor
1089 in the alignment chain for an insn that does / has a known
1092 bzero ((char *) uid_align, max_uid * sizeof *uid_align);
1094 for (i = MAX_CODE_ALIGN; --i >= 0; )
1095 align_tab[i] = NULL_RTX;
1096 seq = get_last_insn ();
1097 for (; seq; seq = PREV_INSN (seq))
1099 int uid = INSN_UID (seq);
1101 log = (GET_CODE (seq) == CODE_LABEL ? LABEL_TO_ALIGNMENT (seq) : 0);
1102 uid_align[uid] = align_tab[0];
1105 /* Found an alignment label. */
1106 uid_align[uid] = align_tab[log];
1107 for (i = log - 1; i >= 0; i--)
1111 #ifdef CASE_VECTOR_SHORTEN_MODE
1114 /* Look for ADDR_DIFF_VECs, and initialize their minimum and maximum
1117 int min_shuid = INSN_SHUID (get_insns ()) - 1;
1118 int max_shuid = INSN_SHUID (get_last_insn ()) + 1;
1121 for (insn = first; insn != 0; insn = NEXT_INSN (insn))
1123 rtx min_lab = NULL_RTX, max_lab = NULL_RTX, pat;
1124 int len, i, min, max, insn_shuid;
1126 addr_diff_vec_flags flags;
1128 if (GET_CODE (insn) != JUMP_INSN
1129 || GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
1131 pat = PATTERN (insn);
1132 len = XVECLEN (pat, 1);
1135 min_align = MAX_CODE_ALIGN;
1136 for (min = max_shuid, max = min_shuid, i = len - 1; i >= 0; i--)
1138 rtx lab = XEXP (XVECEXP (pat, 1, i), 0);
1139 int shuid = INSN_SHUID (lab);
1150 if (min_align > LABEL_TO_ALIGNMENT (lab))
1151 min_align = LABEL_TO_ALIGNMENT (lab);
1153 XEXP (pat, 2) = gen_rtx_LABEL_REF (VOIDmode, min_lab);
1154 XEXP (pat, 3) = gen_rtx_LABEL_REF (VOIDmode, max_lab);
1155 insn_shuid = INSN_SHUID (insn);
1156 rel = INSN_SHUID (XEXP (XEXP (pat, 0), 0));
1157 flags.min_align = min_align;
1158 flags.base_after_vec = rel > insn_shuid;
1159 flags.min_after_vec = min > insn_shuid;
1160 flags.max_after_vec = max > insn_shuid;
1161 flags.min_after_base = min > rel;
1162 flags.max_after_base = max > rel;
1163 ADDR_DIFF_VEC_FLAGS (pat) = flags;
1166 #endif /* CASE_VECTOR_SHORTEN_MODE */
1169 /* Compute initial lengths, addresses, and varying flags for each insn. */
1170 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1172 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
1174 uid = INSN_UID (insn);
1176 insn_lengths[uid] = 0;
1178 if (GET_CODE (insn) == CODE_LABEL)
1180 int log = LABEL_TO_ALIGNMENT (insn);
1183 int align = 1 << log;
1184 int new_address = (insn_current_address + align - 1) & -align;
1185 insn_lengths[uid] = new_address - insn_current_address;
1186 insn_current_address = new_address;
1190 insn_addresses[uid] = insn_current_address;
1192 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
1193 || GET_CODE (insn) == CODE_LABEL)
1195 if (INSN_DELETED_P (insn))
1198 body = PATTERN (insn);
1199 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1201 /* This only takes room if read-only data goes into the text
1203 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
1204 insn_lengths[uid] = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
1205 * GET_MODE_SIZE (GET_MODE (body)));
1206 /* Alignment is handled by ADDR_VEC_ALIGN. */
1209 else if (asm_noperands (body) >= 0)
1210 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
1211 else if (GET_CODE (body) == SEQUENCE)
1214 int const_delay_slots;
1216 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
1218 const_delay_slots = 0;
1220 /* Inside a delay slot sequence, we do not do any branch shortening
1221 if the shortening could change the number of delay slots
1223 for (i = 0; i < XVECLEN (body, 0); i++)
1225 rtx inner_insn = XVECEXP (body, 0, i);
1226 int inner_uid = INSN_UID (inner_insn);
1229 if (asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
1230 inner_length = (asm_insn_count (PATTERN (inner_insn))
1231 * insn_default_length (inner_insn));
1233 inner_length = insn_default_length (inner_insn);
1235 insn_lengths[inner_uid] = inner_length;
1236 if (const_delay_slots)
1238 if ((varying_length[inner_uid]
1239 = insn_variable_length_p (inner_insn)) != 0)
1240 varying_length[uid] = 1;
1241 insn_addresses[inner_uid] = (insn_current_address +
1245 varying_length[inner_uid] = 0;
1246 insn_lengths[uid] += inner_length;
1249 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
1251 insn_lengths[uid] = insn_default_length (insn);
1252 varying_length[uid] = insn_variable_length_p (insn);
1255 /* If needed, do any adjustment. */
1256 #ifdef ADJUST_INSN_LENGTH
1257 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
1261 /* Now loop over all the insns finding varying length insns. For each,
1262 get the current insn length. If it has changed, reflect the change.
1263 When nothing changes for a full pass, we are done. */
1265 while (something_changed)
1267 something_changed = 0;
1268 insn_current_align = MAX_CODE_ALIGN - 1;
1269 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1271 insn = NEXT_INSN (insn))
1274 #ifdef ADJUST_INSN_LENGTH
1279 uid = INSN_UID (insn);
1281 if (GET_CODE (insn) == CODE_LABEL)
1283 int log = LABEL_TO_ALIGNMENT (insn);
1284 if (log > insn_current_align)
1286 int align = 1 << log;
1287 int new_address= (insn_current_address + align - 1) & -align;
1288 insn_lengths[uid] = new_address - insn_current_address;
1289 insn_current_align = log;
1290 insn_current_address = new_address;
1293 insn_lengths[uid] = 0;
1294 insn_addresses[uid] = insn_current_address;
1298 length_align = INSN_LENGTH_ALIGNMENT (insn);
1299 if (length_align < insn_current_align)
1300 insn_current_align = length_align;
1302 insn_last_address = insn_addresses[uid];
1303 insn_addresses[uid] = insn_current_address;
1305 #ifdef CASE_VECTOR_SHORTEN_MODE
1306 if (optimize && GET_CODE (insn) == JUMP_INSN
1307 && GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
1309 rtx body = PATTERN (insn);
1310 int old_length = insn_lengths[uid];
1311 rtx rel_lab = XEXP (XEXP (body, 0), 0);
1312 rtx min_lab = XEXP (XEXP (body, 2), 0);
1313 rtx max_lab = XEXP (XEXP (body, 3), 0);
1314 addr_diff_vec_flags flags = ADDR_DIFF_VEC_FLAGS (body);
1315 int rel_addr = insn_addresses[INSN_UID (rel_lab)];
1316 int min_addr = insn_addresses[INSN_UID (min_lab)];
1317 int max_addr = insn_addresses[INSN_UID (max_lab)];
1321 /* Try to find a known alignment for rel_lab. */
1322 for (prev = rel_lab;
1324 && ! insn_lengths[INSN_UID (prev)]
1325 && ! (varying_length[INSN_UID (prev)] & 1);
1326 prev = PREV_INSN (prev))
1327 if (varying_length[INSN_UID (prev)] & 2)
1329 rel_align = LABEL_TO_ALIGNMENT (prev);
1333 /* See the comment on addr_diff_vec_flags in rtl.h for the
1334 meaning of the flags values. base: REL_LAB vec: INSN */
1335 /* Anything after INSN has still addresses from the last
1336 pass; adjust these so that they reflect our current
1337 estimate for this pass. */
1338 if (flags.base_after_vec)
1339 rel_addr += insn_current_address - insn_last_address;
1340 if (flags.min_after_vec)
1341 min_addr += insn_current_address - insn_last_address;
1342 if (flags.max_after_vec)
1343 max_addr += insn_current_address - insn_last_address;
1344 /* We want to know the worst case, i.e. lowest possible value
1345 for the offset of MIN_LAB. If MIN_LAB is after REL_LAB,
1346 its offset is positive, and we have to be wary of code shrink;
1347 otherwise, it is negative, and we have to be vary of code
1349 if (flags.min_after_base)
1351 /* If INSN is between REL_LAB and MIN_LAB, the size
1352 changes we are about to make can change the alignment
1353 within the observed offset, therefore we have to break
1354 it up into two parts that are independent. */
1355 if (! flags.base_after_vec && flags.min_after_vec)
1357 min_addr -= align_fuzz (rel_lab, insn, rel_align, 0);
1358 min_addr -= align_fuzz (insn, min_lab, 0, 0);
1361 min_addr -= align_fuzz (rel_lab, min_lab, rel_align, 0);
1365 if (flags.base_after_vec && ! flags.min_after_vec)
1367 min_addr -= align_fuzz (min_lab, insn, 0, ~0);
1368 min_addr -= align_fuzz (insn, rel_lab, 0, ~0);
1371 min_addr -= align_fuzz (min_lab, rel_lab, 0, ~0);
1373 /* Likewise, determine the highest lowest possible value
1374 for the offset of MAX_LAB. */
1375 if (flags.max_after_base)
1377 if (! flags.base_after_vec && flags.max_after_vec)
1379 max_addr += align_fuzz (rel_lab, insn, rel_align, ~0);
1380 max_addr += align_fuzz (insn, max_lab, 0, ~0);
1383 max_addr += align_fuzz (rel_lab, max_lab, rel_align, ~0);
1387 if (flags.base_after_vec && ! flags.max_after_vec)
1389 max_addr += align_fuzz (max_lab, insn, 0, 0);
1390 max_addr += align_fuzz (insn, rel_lab, 0, 0);
1393 max_addr += align_fuzz (max_lab, rel_lab, 0, 0);
1395 PUT_MODE (body, CASE_VECTOR_SHORTEN_MODE (min_addr - rel_addr,
1396 max_addr - rel_addr,
1398 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
1400 = (XVECLEN (body, 1) * GET_MODE_SIZE (GET_MODE (body)));
1401 insn_current_address += insn_lengths[uid];
1402 if (insn_lengths[uid] != old_length)
1403 something_changed = 1;
1407 #endif /* CASE_VECTOR_SHORTEN_MODE */
1409 if (! (varying_length[uid]))
1411 insn_current_address += insn_lengths[uid];
1414 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
1418 body = PATTERN (insn);
1420 for (i = 0; i < XVECLEN (body, 0); i++)
1422 rtx inner_insn = XVECEXP (body, 0, i);
1423 int inner_uid = INSN_UID (inner_insn);
1426 insn_addresses[inner_uid] = insn_current_address;
1428 /* insn_current_length returns 0 for insns with a
1429 non-varying length. */
1430 if (! varying_length[inner_uid])
1431 inner_length = insn_lengths[inner_uid];
1433 inner_length = insn_current_length (inner_insn);
1435 if (inner_length != insn_lengths[inner_uid])
1437 insn_lengths[inner_uid] = inner_length;
1438 something_changed = 1;
1440 insn_current_address += insn_lengths[inner_uid];
1441 new_length += inner_length;
1446 new_length = insn_current_length (insn);
1447 insn_current_address += new_length;
1450 #ifdef ADJUST_INSN_LENGTH
1451 /* If needed, do any adjustment. */
1452 tmp_length = new_length;
1453 ADJUST_INSN_LENGTH (insn, new_length);
1454 insn_current_address += (new_length - tmp_length);
1457 if (new_length != insn_lengths[uid])
1459 insn_lengths[uid] = new_length;
1460 something_changed = 1;
1463 /* For a non-optimizing compile, do only a single pass. */
1468 free (varying_length);
1470 #endif /* HAVE_ATTR_length */
1473 #ifdef HAVE_ATTR_length
1474 /* Given the body of an INSN known to be generated by an ASM statement, return
1475 the number of machine instructions likely to be generated for this insn.
1476 This is used to compute its length. */
1479 asm_insn_count (body)
1485 if (GET_CODE (body) == ASM_INPUT)
1486 template = XSTR (body, 0);
1488 template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
1489 NULL_PTR, NULL_PTR);
1491 for ( ; *template; template++)
1492 if (IS_ASM_LOGICAL_LINE_SEPARATOR(*template) || *template == '\n')
1499 /* Output assembler code for the start of a function,
1500 and initialize some of the variables in this file
1501 for the new function. The label for the function and associated
1502 assembler pseudo-ops have already been output in `assemble_start_function'.
1504 FIRST is the first insn of the rtl for the function being compiled.
1505 FILE is the file to write assembler code to.
1506 OPTIMIZE is nonzero if we should eliminate redundant
1507 test and compare insns. */
1510 final_start_function (first, file, optimize)
1517 this_is_asm_operands = 0;
1519 #ifdef NON_SAVING_SETJMP
1520 /* A function that calls setjmp should save and restore all the
1521 call-saved registers on a system where longjmp clobbers them. */
1522 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
1526 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1527 if (!call_used_regs[i] && !call_fixed_regs[i])
1528 regs_ever_live[i] = 1;
1532 /* Initial line number is supposed to be output
1533 before the function's prologue and label
1534 so that the function's address will not appear to be
1535 in the last statement of the preceding function. */
1536 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1537 last_linenum = high_block_linenum = high_function_linenum
1538 = NOTE_LINE_NUMBER (first);
1540 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1541 /* Output DWARF definition of the function. */
1542 if (dwarf2out_do_frame ())
1543 dwarf2out_begin_prologue ();
1546 /* For SDB and XCOFF, the function beginning must be marked between
1547 the function label and the prologue. We always need this, even when
1548 -g1 was used. Defer on MIPS systems so that parameter descriptions
1549 follow function entry. */
1550 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
1551 if (write_symbols == SDB_DEBUG)
1552 sdbout_begin_function (last_linenum);
1555 #ifdef XCOFF_DEBUGGING_INFO
1556 if (write_symbols == XCOFF_DEBUG)
1557 xcoffout_begin_function (file, last_linenum);
1560 /* But only output line number for other debug info types if -g2
1562 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1563 output_source_line (file, first);
1565 #ifdef LEAF_REG_REMAP
1567 leaf_renumber_regs (first);
1570 /* The Sun386i and perhaps other machines don't work right
1571 if the profiling code comes after the prologue. */
1572 #ifdef PROFILE_BEFORE_PROLOGUE
1574 profile_function (file);
1575 #endif /* PROFILE_BEFORE_PROLOGUE */
1577 #if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
1578 if (dwarf2out_do_frame ())
1579 dwarf2out_frame_debug (NULL_RTX);
1582 #ifdef FUNCTION_PROLOGUE
1583 /* First output the function prologue: code to set up the stack frame. */
1584 FUNCTION_PROLOGUE (file, get_frame_size ());
1587 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1588 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
1589 next_block_index = 1;
1592 /* If the machine represents the prologue as RTL, the profiling code must
1593 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
1594 #ifdef HAVE_prologue
1595 if (! HAVE_prologue)
1597 profile_after_prologue (file);
1601 /* If we are doing basic block profiling, remember a printable version
1602 of the function name. */
1603 if (profile_block_flag)
1606 = add_bb_string ((*decl_printable_name) (current_function_decl, 2), FALSE);
1611 profile_after_prologue (file)
1614 #ifdef FUNCTION_BLOCK_PROFILER
1615 if (profile_block_flag)
1617 FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
1619 #endif /* FUNCTION_BLOCK_PROFILER */
1621 #ifndef PROFILE_BEFORE_PROLOGUE
1623 profile_function (file);
1624 #endif /* not PROFILE_BEFORE_PROLOGUE */
1628 profile_function (file)
1631 int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
1632 #if defined(ASM_OUTPUT_REG_PUSH)
1633 #if defined(STRUCT_VALUE_INCOMING_REGNUM) || defined(STRUCT_VALUE_REGNUM)
1634 int sval = current_function_returns_struct;
1636 #if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
1637 int cxt = current_function_needs_context;
1639 #endif /* ASM_OUTPUT_REG_PUSH */
1642 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
1643 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
1644 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, 1);
1646 function_section (current_function_decl);
1648 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1650 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
1652 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1655 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
1660 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1662 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1664 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1667 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1672 FUNCTION_PROFILER (file, profile_label_no);
1674 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1676 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1678 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1681 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1686 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1688 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1690 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1693 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1699 /* Output assembler code for the end of a function.
1700 For clarity, args are same as those of `final_start_function'
1701 even though not all of them are needed. */
1704 final_end_function (first, file, optimize)
1711 fputs (ASM_APP_OFF, file);
1715 #ifdef SDB_DEBUGGING_INFO
1716 if (write_symbols == SDB_DEBUG)
1717 sdbout_end_function (high_function_linenum);
1720 #ifdef DWARF_DEBUGGING_INFO
1721 if (write_symbols == DWARF_DEBUG)
1722 dwarfout_end_function ();
1725 #ifdef XCOFF_DEBUGGING_INFO
1726 if (write_symbols == XCOFF_DEBUG)
1727 xcoffout_end_function (file, high_function_linenum);
1730 #ifdef FUNCTION_EPILOGUE
1731 /* Finally, output the function epilogue:
1732 code to restore the stack frame and return to the caller. */
1733 FUNCTION_EPILOGUE (file, get_frame_size ());
1736 #ifdef SDB_DEBUGGING_INFO
1737 if (write_symbols == SDB_DEBUG)
1738 sdbout_end_epilogue ();
1741 #ifdef DWARF_DEBUGGING_INFO
1742 if (write_symbols == DWARF_DEBUG)
1743 dwarfout_end_epilogue ();
1746 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1747 if (dwarf2out_do_frame ())
1748 dwarf2out_end_epilogue ();
1751 #ifdef XCOFF_DEBUGGING_INFO
1752 if (write_symbols == XCOFF_DEBUG)
1753 xcoffout_end_epilogue (file);
1756 bb_func_label_num = -1; /* not in function, nuke label # */
1758 /* If FUNCTION_EPILOGUE is not defined, then the function body
1759 itself contains return instructions wherever needed. */
1762 /* Add a block to the linked list that remembers the current line/file/function
1763 for basic block profiling. Emit the label in front of the basic block and
1764 the instructions that increment the count field. */
1770 struct bb_list *ptr = (struct bb_list *) permalloc (sizeof (struct bb_list));
1772 /* Add basic block to linked list. */
1774 ptr->line_num = last_linenum;
1775 ptr->file_label_num = bb_file_label_num;
1776 ptr->func_label_num = bb_func_label_num;
1778 bb_tail = &ptr->next;
1780 /* Enable the table of basic-block use counts
1781 to point at the code it applies to. */
1782 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1784 /* Before first insn of this basic block, increment the
1785 count of times it was entered. */
1786 #ifdef BLOCK_PROFILER
1787 BLOCK_PROFILER (file, count_basic_blocks);
1794 count_basic_blocks++;
1797 /* Add a string to be used for basic block profiling. */
1800 add_bb_string (string, perm_p)
1805 struct bb_str *ptr = 0;
1809 string = "<unknown>";
1813 /* Allocate a new string if the current string isn't permanent. If
1814 the string is permanent search for the same string in other
1817 len = strlen (string) + 1;
1820 char *p = (char *) permalloc (len);
1821 bcopy (string, p, len);
1825 for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
1826 if (ptr->string == string)
1829 /* Allocate a new string block if we need to. */
1832 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1835 ptr->label_num = sbb_label_num++;
1836 ptr->string = string;
1838 sbb_tail = &ptr->next;
1841 return ptr->label_num;
1845 /* Output assembler code for some insns: all or part of a function.
1846 For description of args, see `final_start_function', above.
1848 PRESCAN is 1 if we are not really outputting,
1849 just scanning as if we were outputting.
1850 Prescanning deletes and rearranges insns just like ordinary output.
1851 PRESCAN is -2 if we are outputting after having prescanned.
1852 In this case, don't try to delete or rearrange insns
1853 because that has already been done.
1854 Prescanning is done only on certain machines. */
1857 final (first, file, optimize, prescan)
1867 last_ignored_compare = 0;
1870 check_exception_handler_labels ();
1872 /* Make a map indicating which line numbers appear in this function.
1873 When producing SDB debugging info, delete troublesome line number
1874 notes from inlined functions in other files as well as duplicate
1875 line number notes. */
1876 #ifdef SDB_DEBUGGING_INFO
1877 if (write_symbols == SDB_DEBUG)
1880 for (insn = first; insn; insn = NEXT_INSN (insn))
1881 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1883 if ((RTX_INTEGRATED_P (insn)
1884 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1886 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1887 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1889 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1890 NOTE_SOURCE_FILE (insn) = 0;
1894 if (NOTE_LINE_NUMBER (insn) > max_line)
1895 max_line = NOTE_LINE_NUMBER (insn);
1901 for (insn = first; insn; insn = NEXT_INSN (insn))
1902 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1903 max_line = NOTE_LINE_NUMBER (insn);
1906 line_note_exists = (char *) oballoc (max_line + 1);
1907 bzero (line_note_exists, max_line + 1);
1909 for (insn = first; insn; insn = NEXT_INSN (insn))
1911 if (INSN_UID (insn) > max_uid) /* find largest UID */
1912 max_uid = INSN_UID (insn);
1913 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1914 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1917 /* Initialize insn_eh_region table if eh is being used. */
1919 init_insn_eh_region (first, max_uid);
1925 /* Output the insns. */
1926 for (insn = NEXT_INSN (first); insn;)
1928 #ifdef HAVE_ATTR_length
1929 insn_current_address = insn_addresses[INSN_UID (insn)];
1931 insn = final_scan_insn (insn, file, optimize, prescan, 0);
1934 /* Do basic-block profiling here
1935 if the last insn was a conditional branch. */
1936 if (profile_block_flag && new_block)
1939 free_insn_eh_region ();
1942 /* The final scan for one insn, INSN.
1943 Args are same as in `final', except that INSN
1944 is the insn being scanned.
1945 Value returned is the next insn to be scanned.
1947 NOPEEPHOLES is the flag to disallow peephole processing (currently
1948 used for within delayed branch sequence output). */
1951 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
1965 /* Ignore deleted insns. These can occur when we split insns (due to a
1966 template of "#") while not optimizing. */
1967 if (INSN_DELETED_P (insn))
1968 return NEXT_INSN (insn);
1970 switch (GET_CODE (insn))
1976 /* Align the beginning of a loop, for higher speed
1977 on certain machines. */
1979 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
1980 break; /* This used to depend on optimize, but that was bogus. */
1981 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
1984 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG
1985 && ! exceptions_via_longjmp)
1987 ASM_OUTPUT_INTERNAL_LABEL (file, "LEHB", NOTE_BLOCK_NUMBER (insn));
1988 add_eh_table_entry (NOTE_BLOCK_NUMBER (insn));
1989 #ifdef ASM_OUTPUT_EH_REGION_BEG
1990 ASM_OUTPUT_EH_REGION_BEG (file, NOTE_BLOCK_NUMBER (insn));
1995 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END
1996 && ! exceptions_via_longjmp)
1998 ASM_OUTPUT_INTERNAL_LABEL (file, "LEHE", NOTE_BLOCK_NUMBER (insn));
1999 #ifdef ASM_OUTPUT_EH_REGION_END
2000 ASM_OUTPUT_EH_REGION_END (file, NOTE_BLOCK_NUMBER (insn));
2005 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
2007 #ifdef FUNCTION_END_PROLOGUE
2008 FUNCTION_END_PROLOGUE (file);
2010 profile_after_prologue (file);
2014 #ifdef FUNCTION_BEGIN_EPILOGUE
2015 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
2017 FUNCTION_BEGIN_EPILOGUE (file);
2022 if (write_symbols == NO_DEBUG)
2024 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
2026 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
2027 /* MIPS stabs require the parameter descriptions to be after the
2028 function entry point rather than before. */
2029 if (write_symbols == SDB_DEBUG)
2030 sdbout_begin_function (last_linenum);
2033 #ifdef DWARF_DEBUGGING_INFO
2034 /* This outputs a marker where the function body starts, so it
2035 must be after the prologue. */
2036 if (write_symbols == DWARF_DEBUG)
2037 dwarfout_begin_function ();
2041 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
2042 break; /* An insn that was "deleted" */
2045 fputs (ASM_APP_OFF, file);
2048 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2049 && (debug_info_level == DINFO_LEVEL_NORMAL
2050 || debug_info_level == DINFO_LEVEL_VERBOSE
2051 || write_symbols == DWARF_DEBUG
2052 || write_symbols == DWARF2_DEBUG))
2054 /* Beginning of a symbol-block. Assign it a sequence number
2055 and push the number onto the stack PENDING_BLOCKS. */
2057 if (block_depth == max_block_depth)
2059 /* PENDING_BLOCKS is full; make it longer. */
2060 max_block_depth *= 2;
2062 = (int *) xrealloc (pending_blocks,
2063 max_block_depth * sizeof (int));
2065 pending_blocks[block_depth++] = next_block_index;
2067 high_block_linenum = last_linenum;
2069 /* Output debugging info about the symbol-block beginning. */
2071 #ifdef SDB_DEBUGGING_INFO
2072 if (write_symbols == SDB_DEBUG)
2073 sdbout_begin_block (file, last_linenum, next_block_index);
2075 #ifdef XCOFF_DEBUGGING_INFO
2076 if (write_symbols == XCOFF_DEBUG)
2077 xcoffout_begin_block (file, last_linenum, next_block_index);
2079 #ifdef DBX_DEBUGGING_INFO
2080 if (write_symbols == DBX_DEBUG)
2081 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
2083 #ifdef DWARF_DEBUGGING_INFO
2084 if (write_symbols == DWARF_DEBUG)
2085 dwarfout_begin_block (next_block_index);
2087 #ifdef DWARF2_DEBUGGING_INFO
2088 if (write_symbols == DWARF2_DEBUG)
2089 dwarf2out_begin_block (next_block_index);
2094 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
2095 && (debug_info_level == DINFO_LEVEL_NORMAL
2096 || debug_info_level == DINFO_LEVEL_VERBOSE
2097 || write_symbols == DWARF_DEBUG
2098 || write_symbols == DWARF2_DEBUG))
2100 /* End of a symbol-block. Pop its sequence number off
2101 PENDING_BLOCKS and output debugging info based on that. */
2105 #ifdef XCOFF_DEBUGGING_INFO
2106 if (write_symbols == XCOFF_DEBUG && block_depth >= 0)
2107 xcoffout_end_block (file, high_block_linenum,
2108 pending_blocks[block_depth]);
2110 #ifdef DBX_DEBUGGING_INFO
2111 if (write_symbols == DBX_DEBUG && block_depth >= 0)
2112 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
2113 pending_blocks[block_depth]);
2115 #ifdef SDB_DEBUGGING_INFO
2116 if (write_symbols == SDB_DEBUG && block_depth >= 0)
2117 sdbout_end_block (file, high_block_linenum,
2118 pending_blocks[block_depth]);
2120 #ifdef DWARF_DEBUGGING_INFO
2121 if (write_symbols == DWARF_DEBUG && block_depth >= 0)
2122 dwarfout_end_block (pending_blocks[block_depth]);
2124 #ifdef DWARF2_DEBUGGING_INFO
2125 if (write_symbols == DWARF2_DEBUG && block_depth >= 0)
2126 dwarf2out_end_block (pending_blocks[block_depth]);
2129 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
2130 && (debug_info_level == DINFO_LEVEL_NORMAL
2131 || debug_info_level == DINFO_LEVEL_VERBOSE))
2133 #ifdef DWARF_DEBUGGING_INFO
2134 if (write_symbols == DWARF_DEBUG)
2135 dwarfout_label (insn);
2137 #ifdef DWARF2_DEBUGGING_INFO
2138 if (write_symbols == DWARF2_DEBUG)
2139 dwarf2out_label (insn);
2142 else if (NOTE_LINE_NUMBER (insn) > 0)
2143 /* This note is a line-number. */
2147 #if 0 /* This is what we used to do. */
2148 output_source_line (file, insn);
2152 /* If there is anything real after this note,
2153 output it. If another line note follows, omit this one. */
2154 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
2156 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
2158 /* These types of notes can be significant
2159 so make sure the preceding line number stays. */
2160 else if (GET_CODE (note) == NOTE
2161 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
2162 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
2163 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
2165 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
2167 /* Another line note follows; we can delete this note
2168 if no intervening line numbers have notes elsewhere. */
2170 for (num = NOTE_LINE_NUMBER (insn) + 1;
2171 num < NOTE_LINE_NUMBER (note);
2173 if (line_note_exists[num])
2176 if (num >= NOTE_LINE_NUMBER (note))
2182 /* Output this line note
2183 if it is the first or the last line note in a row. */
2185 output_source_line (file, insn);
2190 #if defined (DWARF2_UNWIND_INFO) && !defined (ACCUMULATE_OUTGOING_ARGS)
2191 /* If we push arguments, we need to check all insns for stack
2193 if (dwarf2out_do_frame ())
2194 dwarf2out_frame_debug (insn);
2199 /* The target port might emit labels in the output function for
2200 some insn, e.g. sh.c output_branchy_insn. */
2201 if (CODE_LABEL_NUMBER (insn) <= max_labelno)
2203 int align = LABEL_TO_ALIGNMENT (insn);
2205 if (align && NEXT_INSN (insn))
2206 ASM_OUTPUT_ALIGN (file, align);
2213 #ifdef FINAL_PRESCAN_LABEL
2214 FINAL_PRESCAN_INSN (insn, NULL_PTR, 0);
2217 #ifdef SDB_DEBUGGING_INFO
2218 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
2219 sdbout_label (insn);
2221 #ifdef DWARF_DEBUGGING_INFO
2222 if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
2223 dwarfout_label (insn);
2225 #ifdef DWARF2_DEBUGGING_INFO
2226 if (write_symbols == DWARF2_DEBUG && LABEL_NAME (insn))
2227 dwarf2out_label (insn);
2231 fputs (ASM_APP_OFF, file);
2234 if (NEXT_INSN (insn) != 0
2235 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
2237 rtx nextbody = PATTERN (NEXT_INSN (insn));
2239 /* If this label is followed by a jump-table,
2240 make sure we put the label in the read-only section. Also
2241 possibly write the label and jump table together. */
2243 if (GET_CODE (nextbody) == ADDR_VEC
2244 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
2246 #ifndef JUMP_TABLES_IN_TEXT_SECTION
2247 readonly_data_section ();
2248 #ifdef READONLY_DATA_SECTION
2249 ASM_OUTPUT_ALIGN (file,
2250 exact_log2 (BIGGEST_ALIGNMENT
2252 #endif /* READONLY_DATA_SECTION */
2253 #else /* JUMP_TABLES_IN_TEXT_SECTION */
2254 function_section (current_function_decl);
2255 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
2256 #ifdef ASM_OUTPUT_CASE_LABEL
2257 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
2260 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2266 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2271 register rtx body = PATTERN (insn);
2272 int insn_code_number;
2278 /* An INSN, JUMP_INSN or CALL_INSN.
2279 First check for special kinds that recog doesn't recognize. */
2281 if (GET_CODE (body) == USE /* These are just declarations */
2282 || GET_CODE (body) == CLOBBER)
2286 /* If there is a REG_CC_SETTER note on this insn, it means that
2287 the setting of the condition code was done in the delay slot
2288 of the insn that branched here. So recover the cc status
2289 from the insn that set it. */
2291 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2294 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
2295 cc_prev_status = cc_status;
2299 /* Detect insns that are really jump-tables
2300 and output them as such. */
2302 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
2304 register int vlen, idx;
2311 fputs (ASM_APP_OFF, file);
2315 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2316 for (idx = 0; idx < vlen; idx++)
2318 if (GET_CODE (body) == ADDR_VEC)
2320 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2321 ASM_OUTPUT_ADDR_VEC_ELT
2322 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2329 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2330 ASM_OUTPUT_ADDR_DIFF_ELT
2333 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2334 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2340 #ifdef ASM_OUTPUT_CASE_END
2341 ASM_OUTPUT_CASE_END (file,
2342 CODE_LABEL_NUMBER (PREV_INSN (insn)),
2346 function_section (current_function_decl);
2351 /* Do basic-block profiling when we reach a new block.
2352 Done here to avoid jump tables. */
2353 if (profile_block_flag && new_block)
2356 if (GET_CODE (body) == ASM_INPUT)
2358 /* There's no telling what that did to the condition codes. */
2364 fputs (ASM_APP_ON, file);
2367 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
2371 /* Detect `asm' construct with operands. */
2372 if (asm_noperands (body) >= 0)
2374 unsigned int noperands = asm_noperands (body);
2375 rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
2378 /* There's no telling what that did to the condition codes. */
2385 fputs (ASM_APP_ON, file);
2389 /* Get out the operand values. */
2390 string = decode_asm_operands (body, ops, NULL_PTR,
2391 NULL_PTR, NULL_PTR);
2392 /* Inhibit aborts on what would otherwise be compiler bugs. */
2393 insn_noperands = noperands;
2394 this_is_asm_operands = insn;
2396 /* Output the insn using them. */
2397 output_asm_insn (string, ops);
2398 this_is_asm_operands = 0;
2402 if (prescan <= 0 && app_on)
2404 fputs (ASM_APP_OFF, file);
2408 if (GET_CODE (body) == SEQUENCE)
2410 /* A delayed-branch sequence */
2416 final_sequence = body;
2418 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2419 force the restoration of a comparison that was previously
2420 thought unnecessary. If that happens, cancel this sequence
2421 and cause that insn to be restored. */
2423 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
2424 if (next != XVECEXP (body, 0, 1))
2430 for (i = 1; i < XVECLEN (body, 0); i++)
2432 rtx insn = XVECEXP (body, 0, i);
2433 rtx next = NEXT_INSN (insn);
2434 /* We loop in case any instruction in a delay slot gets
2437 insn = final_scan_insn (insn, file, 0, prescan, 1);
2438 while (insn != next);
2440 #ifdef DBR_OUTPUT_SEQEND
2441 DBR_OUTPUT_SEQEND (file);
2445 /* If the insn requiring the delay slot was a CALL_INSN, the
2446 insns in the delay slot are actually executed before the
2447 called function. Hence we don't preserve any CC-setting
2448 actions in these insns and the CC must be marked as being
2449 clobbered by the function. */
2450 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
2455 /* Following a conditional branch sequence, we have a new basic
2457 if (profile_block_flag)
2459 rtx insn = XVECEXP (body, 0, 0);
2460 rtx body = PATTERN (insn);
2462 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2463 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2464 || (GET_CODE (insn) == JUMP_INSN
2465 && GET_CODE (body) == PARALLEL
2466 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2467 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
2473 /* We have a real machine instruction as rtl. */
2475 body = PATTERN (insn);
2478 set = single_set(insn);
2480 /* Check for redundant test and compare instructions
2481 (when the condition codes are already set up as desired).
2482 This is done only when optimizing; if not optimizing,
2483 it should be possible for the user to alter a variable
2484 with the debugger in between statements
2485 and the next statement should reexamine the variable
2486 to compute the condition codes. */
2491 rtx set = single_set(insn);
2495 && GET_CODE (SET_DEST (set)) == CC0
2496 && insn != last_ignored_compare)
2498 if (GET_CODE (SET_SRC (set)) == SUBREG)
2499 SET_SRC (set) = alter_subreg (SET_SRC (set));
2500 else if (GET_CODE (SET_SRC (set)) == COMPARE)
2502 if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
2503 XEXP (SET_SRC (set), 0)
2504 = alter_subreg (XEXP (SET_SRC (set), 0));
2505 if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
2506 XEXP (SET_SRC (set), 1)
2507 = alter_subreg (XEXP (SET_SRC (set), 1));
2509 if ((cc_status.value1 != 0
2510 && rtx_equal_p (SET_SRC (set), cc_status.value1))
2511 || (cc_status.value2 != 0
2512 && rtx_equal_p (SET_SRC (set), cc_status.value2)))
2514 /* Don't delete insn if it has an addressing side-effect. */
2515 if (! FIND_REG_INC_NOTE (insn, 0)
2516 /* or if anything in it is volatile. */
2517 && ! volatile_refs_p (PATTERN (insn)))
2519 /* We don't really delete the insn; just ignore it. */
2520 last_ignored_compare = insn;
2528 /* Following a conditional branch, we have a new basic block.
2529 But if we are inside a sequence, the new block starts after the
2530 last insn of the sequence. */
2531 if (profile_block_flag && final_sequence == 0
2532 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2533 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2534 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
2535 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2536 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
2540 /* Don't bother outputting obvious no-ops, even without -O.
2541 This optimization is fast and doesn't interfere with debugging.
2542 Don't do this if the insn is in a delay slot, since this
2543 will cause an improper number of delay insns to be written. */
2544 if (final_sequence == 0
2546 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
2547 && GET_CODE (SET_SRC (body)) == REG
2548 && GET_CODE (SET_DEST (body)) == REG
2549 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
2554 /* If this is a conditional branch, maybe modify it
2555 if the cc's are in a nonstandard state
2556 so that it accomplishes the same thing that it would
2557 do straightforwardly if the cc's were set up normally. */
2559 if (cc_status.flags != 0
2560 && GET_CODE (insn) == JUMP_INSN
2561 && GET_CODE (body) == SET
2562 && SET_DEST (body) == pc_rtx
2563 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2564 && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
2565 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
2566 /* This is done during prescan; it is not done again
2567 in final scan when prescan has been done. */
2570 /* This function may alter the contents of its argument
2571 and clear some of the cc_status.flags bits.
2572 It may also return 1 meaning condition now always true
2573 or -1 meaning condition now always false
2574 or 2 meaning condition nontrivial but altered. */
2575 register int result = alter_cond (XEXP (SET_SRC (body), 0));
2576 /* If condition now has fixed value, replace the IF_THEN_ELSE
2577 with its then-operand or its else-operand. */
2579 SET_SRC (body) = XEXP (SET_SRC (body), 1);
2581 SET_SRC (body) = XEXP (SET_SRC (body), 2);
2583 /* The jump is now either unconditional or a no-op.
2584 If it has become a no-op, don't try to output it.
2585 (It would not be recognized.) */
2586 if (SET_SRC (body) == pc_rtx)
2588 PUT_CODE (insn, NOTE);
2589 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2590 NOTE_SOURCE_FILE (insn) = 0;
2593 else if (GET_CODE (SET_SRC (body)) == RETURN)
2594 /* Replace (set (pc) (return)) with (return). */
2595 PATTERN (insn) = body = SET_SRC (body);
2597 /* Rerecognize the instruction if it has changed. */
2599 INSN_CODE (insn) = -1;
2602 /* Make same adjustments to instructions that examine the
2603 condition codes without jumping and instructions that
2604 handle conditional moves (if this machine has either one). */
2606 if (cc_status.flags != 0
2609 rtx cond_rtx, then_rtx, else_rtx;
2611 if (GET_CODE (insn) != JUMP_INSN
2612 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2614 cond_rtx = XEXP (SET_SRC (set), 0);
2615 then_rtx = XEXP (SET_SRC (set), 1);
2616 else_rtx = XEXP (SET_SRC (set), 2);
2620 cond_rtx = SET_SRC (set);
2621 then_rtx = const_true_rtx;
2622 else_rtx = const0_rtx;
2625 switch (GET_CODE (cond_rtx))
2638 register int result;
2639 if (XEXP (cond_rtx, 0) != cc0_rtx)
2641 result = alter_cond (cond_rtx);
2643 validate_change (insn, &SET_SRC (set), then_rtx, 0);
2644 else if (result == -1)
2645 validate_change (insn, &SET_SRC (set), else_rtx, 0);
2646 else if (result == 2)
2647 INSN_CODE (insn) = -1;
2648 if (SET_DEST (set) == SET_SRC (set))
2650 PUT_CODE (insn, NOTE);
2651 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2652 NOTE_SOURCE_FILE (insn) = 0;
2664 /* Do machine-specific peephole optimizations if desired. */
2666 if (optimize && !flag_no_peephole && !nopeepholes)
2668 rtx next = peephole (insn);
2669 /* When peepholing, if there were notes within the peephole,
2670 emit them before the peephole. */
2671 if (next != 0 && next != NEXT_INSN (insn))
2673 rtx prev = PREV_INSN (insn);
2676 for (note = NEXT_INSN (insn); note != next;
2677 note = NEXT_INSN (note))
2678 final_scan_insn (note, file, optimize, prescan, nopeepholes);
2680 /* In case this is prescan, put the notes
2681 in proper position for later rescan. */
2682 note = NEXT_INSN (insn);
2683 PREV_INSN (note) = prev;
2684 NEXT_INSN (prev) = note;
2685 NEXT_INSN (PREV_INSN (next)) = insn;
2686 PREV_INSN (insn) = PREV_INSN (next);
2687 NEXT_INSN (insn) = next;
2688 PREV_INSN (next) = insn;
2691 /* PEEPHOLE might have changed this. */
2692 body = PATTERN (insn);
2695 /* Try to recognize the instruction.
2696 If successful, verify that the operands satisfy the
2697 constraints for the instruction. Crash if they don't,
2698 since `reload' should have changed them so that they do. */
2700 insn_code_number = recog_memoized (insn);
2701 insn_extract (insn);
2702 for (i = 0; i < insn_n_operands[insn_code_number]; i++)
2704 if (GET_CODE (recog_operand[i]) == SUBREG)
2705 recog_operand[i] = alter_subreg (recog_operand[i]);
2706 else if (GET_CODE (recog_operand[i]) == PLUS
2707 || GET_CODE (recog_operand[i]) == MULT)
2708 recog_operand[i] = walk_alter_subreg (recog_operand[i]);
2711 for (i = 0; i < insn_n_dups[insn_code_number]; i++)
2713 if (GET_CODE (*recog_dup_loc[i]) == SUBREG)
2714 *recog_dup_loc[i] = alter_subreg (*recog_dup_loc[i]);
2715 else if (GET_CODE (*recog_dup_loc[i]) == PLUS
2716 || GET_CODE (*recog_dup_loc[i]) == MULT)
2717 *recog_dup_loc[i] = walk_alter_subreg (*recog_dup_loc[i]);
2720 #ifdef REGISTER_CONSTRAINTS
2721 if (! constrain_operands (insn_code_number, 1))
2722 fatal_insn_not_found (insn);
2725 /* Some target machines need to prescan each insn before
2728 #ifdef FINAL_PRESCAN_INSN
2729 FINAL_PRESCAN_INSN (insn, recog_operand,
2730 insn_n_operands[insn_code_number]);
2734 cc_prev_status = cc_status;
2736 /* Update `cc_status' for this instruction.
2737 The instruction's output routine may change it further.
2738 If the output routine for a jump insn needs to depend
2739 on the cc status, it should look at cc_prev_status. */
2741 NOTICE_UPDATE_CC (body, insn);
2746 #if defined (DWARF2_UNWIND_INFO) && !defined (ACCUMULATE_OUTGOING_ARGS)
2747 /* If we push arguments, we want to know where the calls are. */
2748 if (GET_CODE (insn) == CALL_INSN && dwarf2out_do_frame ())
2749 dwarf2out_frame_debug (insn);
2752 /* If the proper template needs to be chosen by some C code,
2753 run that code and get the real template. */
2755 template = insn_template[insn_code_number];
2758 template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
2760 /* If the C code returns 0, it means that it is a jump insn
2761 which follows a deleted test insn, and that test insn
2762 needs to be reinserted. */
2765 if (prev_nonnote_insn (insn) != last_ignored_compare)
2768 return prev_nonnote_insn (insn);
2772 /* If the template is the string "#", it means that this insn must
2774 if (template[0] == '#' && template[1] == '\0')
2776 rtx new = try_split (body, insn, 0);
2778 /* If we didn't split the insn, go away. */
2779 if (new == insn && PATTERN (new) == body)
2782 #ifdef HAVE_ATTR_length
2783 /* This instruction should have been split in shorten_branches,
2784 to ensure that we would have valid length info for the
2796 /* Output assembler code from the template. */
2798 output_asm_insn (template, recog_operand);
2800 #if defined (DWARF2_UNWIND_INFO)
2801 #if !defined (ACCUMULATE_OUTGOING_ARGS)
2802 /* If we push arguments, we need to check all insns for stack
2804 if (GET_CODE (insn) == INSN && dwarf2out_do_frame ())
2805 dwarf2out_frame_debug (insn);
2807 #if defined (HAVE_prologue)
2808 /* If this insn is part of the prologue, emit DWARF v2
2810 if (RTX_FRAME_RELATED_P (insn) && dwarf2out_do_frame ())
2811 dwarf2out_frame_debug (insn);
2817 /* It's not at all clear why we did this and doing so interferes
2818 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2821 /* Mark this insn as having been output. */
2822 INSN_DELETED_P (insn) = 1;
2828 return NEXT_INSN (insn);
2831 /* Output debugging info to the assembler file FILE
2832 based on the NOTE-insn INSN, assumed to be a line number. */
2835 output_source_line (file, insn)
2839 register char *filename = NOTE_SOURCE_FILE (insn);
2841 /* Remember filename for basic block profiling.
2842 Filenames are allocated on the permanent obstack
2843 or are passed in ARGV, so we don't have to save
2846 if (profile_block_flag && last_filename != filename)
2847 bb_file_label_num = add_bb_string (filename, TRUE);
2849 last_filename = filename;
2850 last_linenum = NOTE_LINE_NUMBER (insn);
2851 high_block_linenum = MAX (last_linenum, high_block_linenum);
2852 high_function_linenum = MAX (last_linenum, high_function_linenum);
2854 if (write_symbols != NO_DEBUG)
2856 #ifdef SDB_DEBUGGING_INFO
2857 if (write_symbols == SDB_DEBUG
2858 #if 0 /* People like having line numbers even in wrong file! */
2859 /* COFF can't handle multiple source files--lose, lose. */
2860 && !strcmp (filename, main_input_filename)
2862 /* COFF relative line numbers must be positive. */
2863 && last_linenum > sdb_begin_function_line)
2865 #ifdef ASM_OUTPUT_SOURCE_LINE
2866 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
2868 fprintf (file, "\t.ln\t%d\n",
2869 ((sdb_begin_function_line > -1)
2870 ? last_linenum - sdb_begin_function_line : 1));
2875 #if defined (DBX_DEBUGGING_INFO)
2876 if (write_symbols == DBX_DEBUG)
2877 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
2880 #if defined (XCOFF_DEBUGGING_INFO)
2881 if (write_symbols == XCOFF_DEBUG)
2882 xcoffout_source_line (file, filename, insn);
2885 #ifdef DWARF_DEBUGGING_INFO
2886 if (write_symbols == DWARF_DEBUG)
2887 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
2890 #ifdef DWARF2_DEBUGGING_INFO
2891 if (write_symbols == DWARF2_DEBUG)
2892 dwarf2out_line (filename, NOTE_LINE_NUMBER (insn));
2897 /* If X is a SUBREG, replace it with a REG or a MEM,
2898 based on the thing it is a subreg of. */
2904 register rtx y = SUBREG_REG (x);
2906 if (GET_CODE (y) == SUBREG)
2907 y = alter_subreg (y);
2909 /* If reload is operating, we may be replacing inside this SUBREG.
2910 Check for that and make a new one if so. */
2911 if (reload_in_progress && find_replacement (&SUBREG_REG (x)) != 0)
2914 if (GET_CODE (y) == REG)
2916 /* If the word size is larger than the size of this register,
2917 adjust the register number to compensate. */
2918 /* ??? Note that this just catches stragglers created by/for
2919 integrate. It would be better if we either caught these
2920 earlier, or kept _all_ subregs until now and eliminate
2921 gen_lowpart and friends. */
2924 #ifdef ALTER_HARD_SUBREG
2925 REGNO (x) = ALTER_HARD_SUBREG(GET_MODE (x), SUBREG_WORD (x),
2926 GET_MODE (y), REGNO (y));
2928 REGNO (x) = REGNO (y) + SUBREG_WORD (x);
2931 else if (GET_CODE (y) == MEM)
2933 register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2934 if (BYTES_BIG_ENDIAN)
2935 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
2936 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
2938 MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
2939 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
2945 /* Do alter_subreg on all the SUBREGs contained in X. */
2948 walk_alter_subreg (x)
2951 switch (GET_CODE (x))
2955 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2956 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
2960 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2964 return alter_subreg (x);
2975 /* Given BODY, the body of a jump instruction, alter the jump condition
2976 as required by the bits that are set in cc_status.flags.
2977 Not all of the bits there can be handled at this level in all cases.
2979 The value is normally 0.
2980 1 means that the condition has become always true.
2981 -1 means that the condition has become always false.
2982 2 means that COND has been altered. */
2990 if (cc_status.flags & CC_REVERSED)
2993 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
2996 if (cc_status.flags & CC_INVERTED)
2999 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
3002 if (cc_status.flags & CC_NOT_POSITIVE)
3003 switch (GET_CODE (cond))
3008 /* Jump becomes unconditional. */
3014 /* Jump becomes no-op. */
3018 PUT_CODE (cond, EQ);
3023 PUT_CODE (cond, NE);
3031 if (cc_status.flags & CC_NOT_NEGATIVE)
3032 switch (GET_CODE (cond))
3036 /* Jump becomes unconditional. */
3041 /* Jump becomes no-op. */
3046 PUT_CODE (cond, EQ);
3052 PUT_CODE (cond, NE);
3060 if (cc_status.flags & CC_NO_OVERFLOW)
3061 switch (GET_CODE (cond))
3064 /* Jump becomes unconditional. */
3068 PUT_CODE (cond, EQ);
3073 PUT_CODE (cond, NE);
3078 /* Jump becomes no-op. */
3085 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
3086 switch (GET_CODE (cond))
3092 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
3097 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
3102 if (cc_status.flags & CC_NOT_SIGNED)
3103 /* The flags are valid if signed condition operators are converted
3105 switch (GET_CODE (cond))
3108 PUT_CODE (cond, LEU);
3113 PUT_CODE (cond, LTU);
3118 PUT_CODE (cond, GTU);
3123 PUT_CODE (cond, GEU);
3135 /* Report inconsistency between the assembler template and the operands.
3136 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
3139 output_operand_lossage (str)
3142 if (this_is_asm_operands)
3143 error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
3148 /* Output of assembler code from a template, and its subroutines. */
3150 /* Output text from TEMPLATE to the assembler output file,
3151 obeying %-directions to substitute operands taken from
3152 the vector OPERANDS.
3154 %N (for N a digit) means print operand N in usual manner.
3155 %lN means require operand N to be a CODE_LABEL or LABEL_REF
3156 and print the label name with no punctuation.
3157 %cN means require operand N to be a constant
3158 and print the constant expression with no punctuation.
3159 %aN means expect operand N to be a memory address
3160 (not a memory reference!) and print a reference
3162 %nN means expect operand N to be a constant
3163 and print a constant expression for minus the value
3164 of the operand, with no other punctuation. */
3169 if (flag_print_asm_name)
3171 /* Annotate the assembly with a comment describing the pattern and
3172 alternative used. */
3175 register int num = INSN_CODE (debug_insn);
3176 fprintf (asm_out_file, " %s %d %s",
3177 ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
3178 if (insn_n_alternatives[num] > 1)
3179 fprintf (asm_out_file, "/%d", which_alternative + 1);
3181 /* Clear this so only the first assembler insn
3182 of any rtl insn will get the special comment for -dp. */
3189 output_asm_insn (template, operands)
3196 /* An insn may return a null string template
3197 in a case where no assembler code is needed. */
3202 putc ('\t', asm_out_file);
3204 #ifdef ASM_OUTPUT_OPCODE
3205 ASM_OUTPUT_OPCODE (asm_out_file, p);
3213 putc (c, asm_out_file);
3214 #ifdef ASM_OUTPUT_OPCODE
3215 while ((c = *p) == '\t')
3217 putc (c, asm_out_file);
3220 ASM_OUTPUT_OPCODE (asm_out_file, p);
3224 #ifdef ASSEMBLER_DIALECT
3229 /* If we want the first dialect, do nothing. Otherwise, skip
3230 DIALECT_NUMBER of strings ending with '|'. */
3231 for (i = 0; i < dialect_number; i++)
3233 while (*p && *p++ != '|')
3243 /* Skip to close brace. */
3244 while (*p && *p++ != '}')
3253 /* %% outputs a single %. */
3257 putc (c, asm_out_file);
3259 /* %= outputs a number which is unique to each insn in the entire
3260 compilation. This is useful for making local labels that are
3261 referred to more than once in a given insn. */
3265 fprintf (asm_out_file, "%d", insn_counter);
3267 /* % followed by a letter and some digits
3268 outputs an operand in a special way depending on the letter.
3269 Letters `acln' are implemented directly.
3270 Other letters are passed to `output_operand' so that
3271 the PRINT_OPERAND macro can define them. */
3272 else if ((*p >= 'a' && *p <= 'z')
3273 || (*p >= 'A' && *p <= 'Z'))
3278 if (! (*p >= '0' && *p <= '9'))
3279 output_operand_lossage ("operand number missing after %-letter");
3280 else if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3281 output_operand_lossage ("operand number out of range");
3282 else if (letter == 'l')
3283 output_asm_label (operands[c]);
3284 else if (letter == 'a')
3285 output_address (operands[c]);
3286 else if (letter == 'c')
3288 if (CONSTANT_ADDRESS_P (operands[c]))
3289 output_addr_const (asm_out_file, operands[c]);
3291 output_operand (operands[c], 'c');
3293 else if (letter == 'n')
3295 if (GET_CODE (operands[c]) == CONST_INT)
3296 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3297 - INTVAL (operands[c]));
3300 putc ('-', asm_out_file);
3301 output_addr_const (asm_out_file, operands[c]);
3305 output_operand (operands[c], letter);
3307 while ((c = *p) >= '0' && c <= '9') p++;
3309 /* % followed by a digit outputs an operand the default way. */
3310 else if (*p >= '0' && *p <= '9')
3313 if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3314 output_operand_lossage ("operand number out of range");
3316 output_operand (operands[c], 0);
3317 while ((c = *p) >= '0' && c <= '9') p++;
3319 /* % followed by punctuation: output something for that
3320 punctuation character alone, with no operand.
3321 The PRINT_OPERAND macro decides what is actually done. */
3322 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3323 else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
3324 output_operand (NULL_RTX, *p++);
3327 output_operand_lossage ("invalid %%-code");
3331 putc (c, asm_out_file);
3336 putc ('\n', asm_out_file);
3339 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3342 output_asm_label (x)
3347 if (GET_CODE (x) == LABEL_REF)
3348 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
3349 else if (GET_CODE (x) == CODE_LABEL)
3350 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3352 output_operand_lossage ("`%l' operand isn't a label");
3354 assemble_name (asm_out_file, buf);
3357 /* Print operand X using machine-dependent assembler syntax.
3358 The macro PRINT_OPERAND is defined just to control this function.
3359 CODE is a non-digit that preceded the operand-number in the % spec,
3360 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3361 between the % and the digits.
3362 When CODE is a non-letter, X is 0.
3364 The meanings of the letters are machine-dependent and controlled
3365 by PRINT_OPERAND. */
3368 output_operand (x, code)
3372 if (x && GET_CODE (x) == SUBREG)
3373 x = alter_subreg (x);
3375 /* If X is a pseudo-register, abort now rather than writing trash to the
3378 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
3381 PRINT_OPERAND (asm_out_file, x, code);
3384 /* Print a memory reference operand for address X
3385 using machine-dependent assembler syntax.
3386 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
3392 walk_alter_subreg (x);
3393 PRINT_OPERAND_ADDRESS (asm_out_file, x);
3396 /* Print an integer constant expression in assembler syntax.
3397 Addition and subtraction are the only arithmetic
3398 that may appear in these expressions. */
3401 output_addr_const (file, x)
3408 switch (GET_CODE (x))
3418 assemble_name (file, XSTR (x, 0));
3422 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
3423 assemble_name (file, buf);
3427 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3428 assemble_name (file, buf);
3432 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3436 /* This used to output parentheses around the expression,
3437 but that does not work on the 386 (either ATT or BSD assembler). */
3438 output_addr_const (file, XEXP (x, 0));
3442 if (GET_MODE (x) == VOIDmode)
3444 /* We can use %d if the number is one word and positive. */
3445 if (CONST_DOUBLE_HIGH (x))
3446 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3447 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3448 else if (CONST_DOUBLE_LOW (x) < 0)
3449 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3451 fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3454 /* We can't handle floating point constants;
3455 PRINT_OPERAND must handle them. */
3456 output_operand_lossage ("floating constant misused");
3460 /* Some assemblers need integer constants to appear last (eg masm). */
3461 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3463 output_addr_const (file, XEXP (x, 1));
3464 if (INTVAL (XEXP (x, 0)) >= 0)
3465 fprintf (file, "+");
3466 output_addr_const (file, XEXP (x, 0));
3470 output_addr_const (file, XEXP (x, 0));
3471 if (INTVAL (XEXP (x, 1)) >= 0)
3472 fprintf (file, "+");
3473 output_addr_const (file, XEXP (x, 1));
3478 /* Avoid outputting things like x-x or x+5-x,
3479 since some assemblers can't handle that. */
3480 x = simplify_subtraction (x);
3481 if (GET_CODE (x) != MINUS)
3484 output_addr_const (file, XEXP (x, 0));
3485 fprintf (file, "-");
3486 if (GET_CODE (XEXP (x, 1)) == CONST_INT
3487 && INTVAL (XEXP (x, 1)) < 0)
3489 fprintf (file, ASM_OPEN_PAREN);
3490 output_addr_const (file, XEXP (x, 1));
3491 fprintf (file, ASM_CLOSE_PAREN);
3494 output_addr_const (file, XEXP (x, 1));
3499 output_addr_const (file, XEXP (x, 0));
3503 output_operand_lossage ("invalid expression as operand");
3507 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3508 %R prints the value of REGISTER_PREFIX.
3509 %L prints the value of LOCAL_LABEL_PREFIX.
3510 %U prints the value of USER_LABEL_PREFIX.
3511 %I prints the value of IMMEDIATE_PREFIX.
3512 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3513 Also supported are %d, %x, %s, %e, %f, %g and %%.
3515 We handle alternate assembler dialects here, just like output_asm_insn. */
3518 asm_fprintf VPROTO((FILE *file, char *p, ...))
3528 VA_START (argptr, p);
3531 file = va_arg (argptr, FILE *);
3532 p = va_arg (argptr, char *);
3540 #ifdef ASSEMBLER_DIALECT
3545 /* If we want the first dialect, do nothing. Otherwise, skip
3546 DIALECT_NUMBER of strings ending with '|'. */
3547 for (i = 0; i < dialect_number; i++)
3549 while (*p && *p++ != '|')
3559 /* Skip to close brace. */
3560 while (*p && *p++ != '}')
3571 while ((c >= '0' && c <= '9') || c == '.')
3579 fprintf (file, "%%");
3582 case 'd': case 'i': case 'u':
3583 case 'x': case 'p': case 'X':
3587 fprintf (file, buf, va_arg (argptr, int));
3591 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3592 but we do not check for those cases. It means that the value
3593 is a HOST_WIDE_INT, which may be either `int' or `long'. */
3595 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3597 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3607 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3614 fprintf (file, buf, va_arg (argptr, long));
3622 fprintf (file, buf, va_arg (argptr, double));
3628 fprintf (file, buf, va_arg (argptr, char *));
3632 #ifdef ASM_OUTPUT_OPCODE
3633 ASM_OUTPUT_OPCODE (asm_out_file, p);
3638 #ifdef REGISTER_PREFIX
3639 fprintf (file, "%s", REGISTER_PREFIX);
3644 #ifdef IMMEDIATE_PREFIX
3645 fprintf (file, "%s", IMMEDIATE_PREFIX);
3650 #ifdef LOCAL_LABEL_PREFIX
3651 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3656 #ifdef USER_LABEL_PREFIX
3657 fprintf (file, "%s", USER_LABEL_PREFIX);
3671 /* Split up a CONST_DOUBLE or integer constant rtx
3672 into two rtx's for single words,
3673 storing in *FIRST the word that comes first in memory in the target
3674 and in *SECOND the other. */
3677 split_double (value, first, second)
3679 rtx *first, *second;
3681 if (GET_CODE (value) == CONST_INT)
3683 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3685 /* In this case the CONST_INT holds both target words.
3686 Extract the bits from it into two word-sized pieces.
3687 Sign extend each half to HOST_WIDE_INT. */
3689 /* On machines where HOST_BITS_PER_WIDE_INT == BITS_PER_WORD
3690 the shift below will cause a compiler warning, even though
3691 this code won't be executed. So put the shift amounts in
3692 variables to avoid the warning. */
3693 int rshift = HOST_BITS_PER_WIDE_INT - BITS_PER_WORD;
3694 int lshift = HOST_BITS_PER_WIDE_INT - 2 * BITS_PER_WORD;
3696 low = GEN_INT ((INTVAL (value) << rshift) >> rshift);
3697 high = GEN_INT ((INTVAL (value) << lshift) >> rshift);
3698 if (WORDS_BIG_ENDIAN)
3711 /* The rule for using CONST_INT for a wider mode
3712 is that we regard the value as signed.
3713 So sign-extend it. */
3714 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3715 if (WORDS_BIG_ENDIAN)
3727 else if (GET_CODE (value) != CONST_DOUBLE)
3729 if (WORDS_BIG_ENDIAN)
3731 *first = const0_rtx;
3737 *second = const0_rtx;
3740 else if (GET_MODE (value) == VOIDmode
3741 /* This is the old way we did CONST_DOUBLE integers. */
3742 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3744 /* In an integer, the words are defined as most and least significant.
3745 So order them by the target's convention. */
3746 if (WORDS_BIG_ENDIAN)
3748 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3749 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3753 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3754 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3759 #ifdef REAL_ARITHMETIC
3760 REAL_VALUE_TYPE r; long l[2];
3761 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3763 /* Note, this converts the REAL_VALUE_TYPE to the target's
3764 format, splits up the floating point double and outputs
3765 exactly 32 bits of it into each of l[0] and l[1] --
3766 not necessarily BITS_PER_WORD bits. */
3767 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3769 *first = GEN_INT ((HOST_WIDE_INT) l[0]);
3770 *second = GEN_INT ((HOST_WIDE_INT) l[1]);
3772 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3773 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3774 && ! flag_pretend_float)
3778 #ifdef HOST_WORDS_BIG_ENDIAN
3785 /* Host and target agree => no need to swap. */
3786 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3787 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3791 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3792 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3794 #endif /* no REAL_ARITHMETIC */
3798 /* Return nonzero if this function has no function calls. */
3805 if (profile_flag || profile_block_flag || profile_arc_flag)
3808 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3810 if (GET_CODE (insn) == CALL_INSN)
3812 if (GET_CODE (insn) == INSN
3813 && GET_CODE (PATTERN (insn)) == SEQUENCE
3814 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN)
3817 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
3819 if (GET_CODE (XEXP (insn, 0)) == CALL_INSN)
3821 if (GET_CODE (XEXP (insn, 0)) == INSN
3822 && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
3823 && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN)
3830 /* On some machines, a function with no call insns
3831 can run faster if it doesn't create its own register window.
3832 When output, the leaf function should use only the "output"
3833 registers. Ordinarily, the function would be compiled to use
3834 the "input" registers to find its arguments; it is a candidate
3835 for leaf treatment if it uses only the "input" registers.
3836 Leaf function treatment means renumbering so the function
3837 uses the "output" registers instead. */
3839 #ifdef LEAF_REGISTERS
3841 static char permitted_reg_in_leaf_functions[] = LEAF_REGISTERS;
3843 /* Return 1 if this function uses only the registers that can be
3844 safely renumbered. */
3847 only_leaf_regs_used ()
3851 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3852 if ((regs_ever_live[i] || global_regs[i])
3853 && ! permitted_reg_in_leaf_functions[i])
3856 if (current_function_uses_pic_offset_table
3857 && pic_offset_table_rtx != 0
3858 && GET_CODE (pic_offset_table_rtx) == REG
3859 && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
3865 /* Scan all instructions and renumber all registers into those
3866 available in leaf functions. */
3869 leaf_renumber_regs (first)
3874 /* Renumber only the actual patterns.
3875 The reg-notes can contain frame pointer refs,
3876 and renumbering them could crash, and should not be needed. */
3877 for (insn = first; insn; insn = NEXT_INSN (insn))
3878 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3879 leaf_renumber_regs_insn (PATTERN (insn));
3880 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
3881 if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
3882 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
3885 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
3886 available in leaf functions. */
3889 leaf_renumber_regs_insn (in_rtx)
3890 register rtx in_rtx;
3893 register char *format_ptr;
3898 /* Renumber all input-registers into output-registers.
3899 renumbered_regs would be 1 for an output-register;
3902 if (GET_CODE (in_rtx) == REG)
3906 /* Don't renumber the same reg twice. */
3910 newreg = REGNO (in_rtx);
3911 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
3912 to reach here as part of a REG_NOTE. */
3913 if (newreg >= FIRST_PSEUDO_REGISTER)
3918 newreg = LEAF_REG_REMAP (newreg);
3921 regs_ever_live[REGNO (in_rtx)] = 0;
3922 regs_ever_live[newreg] = 1;
3923 REGNO (in_rtx) = newreg;
3927 if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
3929 /* Inside a SEQUENCE, we find insns.
3930 Renumber just the patterns of these insns,
3931 just as we do for the top-level insns. */
3932 leaf_renumber_regs_insn (PATTERN (in_rtx));
3936 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
3938 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
3939 switch (*format_ptr++)
3942 leaf_renumber_regs_insn (XEXP (in_rtx, i));
3946 if (NULL != XVEC (in_rtx, i))
3948 for (j = 0; j < XVECLEN (in_rtx, i); j++)
3949 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));