1 /* Convert RTL to assembler code and output it, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 1994 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This is the final pass of the compiler.
22 It looks at the rtl code for a function and outputs assembler code.
24 Call `final_start_function' to output the assembler code for function entry,
25 `final' to output assembler code for some RTL code,
26 `final_end_function' to output assembler code for function exit.
27 If a function is compiled in several pieces, each piece is
28 output separately with `final'.
30 Some optimizations are also done at this level.
31 Move instructions that were made unnecessary by good register allocation
32 are detected and omitted from the output. (Though most of these
33 are removed by the last jump pass.)
35 Instructions to set the condition codes are omitted when it can be
36 seen that the condition codes already had the desired values.
38 In some cases it is sufficient if the inherited condition codes
39 have related values, but this may require the following insn
40 (the one that tests the condition codes) to be modified.
42 The code for the function prologue and epilogue are generated
43 directly as assembler code by the macros FUNCTION_PROLOGUE and
44 FUNCTION_EPILOGUE. Those instructions never exist as rtl. */
55 #include "insn-config.h"
56 #include "insn-flags.h"
57 #include "insn-attr.h"
58 #include "insn-codes.h"
60 #include "conditions.h"
63 #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 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
99 null default for it to save conditionalization later. */
100 #ifndef CC_STATUS_INIT
101 #define CC_STATUS_INIT
104 /* How to start an assembler comment. */
105 #ifndef ASM_COMMENT_START
106 #define ASM_COMMENT_START ";#"
109 /* Is the given character a logical line separator for the assembler? */
110 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
111 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
115 void output_asm_insn ();
117 static rtx walk_alter_subreg ();
118 static int alter_cond ();
119 void output_asm_label ();
120 static void output_operand ();
121 void output_address ();
122 void output_addr_const ();
123 static void output_source_line ();
124 rtx final_scan_insn ();
125 void profile_function ();
126 static void profile_after_prologue ();
128 #ifdef HAVE_ATTR_length
129 static int asm_insn_count ();
132 /* Nonzero means this function is a leaf function, with no function calls.
133 This variable exists to be examined in FUNCTION_PROLOGUE
134 and FUNCTION_EPILOGUE. Always zero, unless set by some action. */
137 int leaf_function_p ();
139 #ifdef LEAF_REGISTERS
140 int only_leaf_regs_used ();
141 static void leaf_renumber_regs ();
142 void leaf_renumber_regs_insn ();
145 /* Last insn processed by final_scan_insn. */
146 static rtx debug_insn = 0;
148 /* Line number of last NOTE. */
149 static int last_linenum;
151 /* Filename of last NOTE. */
152 static char *last_filename;
154 /* Number of basic blocks seen so far;
155 used if profile_block_flag is set. */
156 static int count_basic_blocks;
158 /* Nonzero while outputting an `asm' with operands.
159 This means that inconsistencies are the user's fault, so don't abort.
160 The precise value is the insn being output, to pass to error_for_asm. */
161 static rtx this_is_asm_operands;
163 /* Number of operands of this insn, for an `asm' with operands. */
164 static int insn_noperands;
166 /* Compare optimization flag. */
168 static rtx last_ignored_compare = 0;
170 /* Flag indicating this insn is the start of a new basic block. */
172 static int new_block = 1;
174 /* All the symbol-blocks (levels of scoping) in the compilation
175 are assigned sequence numbers in order of appearance of the
176 beginnings of the symbol-blocks. Both final and dbxout do this,
177 and assume that they will both give the same number to each block.
178 Final uses these sequence numbers to generate assembler label names
179 LBBnnn and LBEnnn for the beginning and end of the symbol-block.
180 Dbxout uses the sequence numbers to generate references to the same labels
181 from the dbx debugging information.
183 Sdb records this level at the beginning of each function,
184 in order to find the current level when recursing down declarations.
185 It outputs the block beginning and endings
186 at the point in the asm file where the blocks would begin and end. */
188 int next_block_index;
190 /* Assign a unique number to each insn that is output.
191 This can be used to generate unique local labels. */
193 static int insn_counter = 0;
196 /* This variable contains machine-dependent flags (defined in tm.h)
197 set and examined by output routines
198 that describe how to interpret the condition codes properly. */
202 /* During output of an insn, this contains a copy of cc_status
203 from before the insn. */
205 CC_STATUS cc_prev_status;
208 /* Indexed by hardware reg number, is 1 if that register is ever
209 used in the current function.
211 In life_analysis, or in stupid_life_analysis, this is set
212 up to record the hard regs used explicitly. Reload adds
213 in the hard regs used for holding pseudo regs. Final uses
214 it to generate the code in the function prologue and epilogue
215 to save and restore registers as needed. */
217 char regs_ever_live[FIRST_PSEUDO_REGISTER];
219 /* Nonzero means current function must be given a frame pointer.
220 Set in stmt.c if anything is allocated on the stack there.
221 Set in reload1.c if anything is allocated on the stack there. */
223 int frame_pointer_needed;
225 /* Assign unique numbers to labels generated for profiling. */
227 int profile_label_no;
229 /* Length so far allocated in PENDING_BLOCKS. */
231 static int max_block_depth;
233 /* Stack of sequence numbers of symbol-blocks of which we have seen the
234 beginning but not yet the end. Sequence numbers are assigned at
235 the beginning; this stack allows us to find the sequence number
236 of a block that is ending. */
238 static int *pending_blocks;
240 /* Number of elements currently in use in PENDING_BLOCKS. */
242 static int block_depth;
244 /* Nonzero if have enabled APP processing of our assembler output. */
248 /* If we are outputting an insn sequence, this contains the sequence rtx.
253 #ifdef ASSEMBLER_DIALECT
255 /* Number of the assembler dialect to use, starting at 0. */
256 static int dialect_number;
259 /* Indexed by line number, nonzero if there is a note for that line. */
261 static char *line_note_exists;
263 /* Linked list to hold line numbers for each basic block. */
266 struct bb_list *next; /* pointer to next basic block */
267 int line_num; /* line number */
268 int file_label_num; /* LPBC<n> label # for stored filename */
269 int func_label_num; /* LPBC<n> label # for stored function name */
272 static struct bb_list *bb_head = 0; /* Head of basic block list */
273 static struct bb_list **bb_tail = &bb_head; /* Ptr to store next bb ptr */
274 static int bb_file_label_num = -1; /* Current label # for file */
275 static int bb_func_label_num = -1; /* Current label # for func */
277 /* Linked list to hold the strings for each file and function name output. */
280 struct bb_str *next; /* pointer to next string */
281 char *string; /* string */
282 int label_num; /* label number */
283 int length; /* string length */
286 static struct bb_str *sbb_head = 0; /* Head of string list. */
287 static struct bb_str **sbb_tail = &sbb_head; /* Ptr to store next bb str */
288 static int sbb_label_num = 0; /* Last label used */
290 static int add_bb_string PROTO((char *, int));
291 static void add_bb PROTO((FILE *));
294 /* Initialize data in final at the beginning of a compilation. */
297 init_final (filename)
300 next_block_index = 2;
302 max_block_depth = 20;
303 pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
306 #ifdef ASSEMBLER_DIALECT
307 dialect_number = ASSEMBLER_DIALECT;
311 /* Called at end of source file,
312 to output the block-profiling table for this entire compilation. */
320 if (profile_block_flag)
323 int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
324 int size = (INT_TYPE_SIZE / BITS_PER_UNIT) * count_basic_blocks;
329 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
330 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
331 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
335 /* Output the main header, of 10 words:
336 0: 1 if this file's initialized, else 0.
337 1: address of file name (LPBX1).
338 2: address of table of counts (LPBX2).
339 3: number of counts in the table.
340 4: always 0, for compatibility with Sun.
342 The following are GNU extensions:
344 5: address of table of start addrs of basic blocks (LPBX3).
345 6: Number of bytes in this header.
346 7: address of table of function names (LPBX4).
347 8: address of table of line numbers (LPBX5) or 0.
348 9: address of table of file names (LPBX6) or 0. */
350 ASM_OUTPUT_ALIGN (asm_out_file, align);
352 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
354 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
356 /* address of filename */
357 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
358 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
360 /* address of count table */
361 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
362 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
364 /* count of the # of basic blocks */
365 assemble_integer (GEN_INT (count_basic_blocks), UNITS_PER_WORD, 1);
367 /* zero word (link field) */
368 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
370 /* address of basic block start address table */
371 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
372 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
374 /* byte count for extended structure. */
375 assemble_integer (GEN_INT (10 * UNITS_PER_WORD), UNITS_PER_WORD, 1);
377 /* address of function name table */
378 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
379 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
381 /* address of line number and filename tables if debugging. */
382 if (write_symbols != NO_DEBUG)
384 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
385 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
386 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
387 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
391 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
392 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
395 /* Output the file name changing the suffix to .d for Sun tcov
397 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
399 int len = strlen (filename);
400 char *data_file = (char *) alloca (len + 3);
401 strcpy (data_file, filename);
402 strip_off_ending (data_file, len);
403 strcat (data_file, ".d");
404 assemble_string (data_file, strlen (data_file) + 1);
407 /* Make space for the table of counts. */
408 if (flag_no_common || size == 0)
410 /* Realign data section. */
411 ASM_OUTPUT_ALIGN (asm_out_file, align);
412 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
414 assemble_zeros (size);
418 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
419 #ifdef ASM_OUTPUT_SHARED_LOCAL
420 if (flag_shared_data)
421 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
424 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
425 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, align);
427 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
431 /* Output any basic block strings */
432 readonly_data_section ();
435 ASM_OUTPUT_ALIGN (asm_out_file, align);
436 for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
438 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC", sptr->label_num);
439 assemble_string (sptr->string, sptr->length);
443 /* Output the table of addresses. */
444 /* Realign in new section */
445 ASM_OUTPUT_ALIGN (asm_out_file, align);
446 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
447 for (i = 0; i < count_basic_blocks; i++)
449 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
450 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
454 /* Output the table of function names. */
455 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
456 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
458 if (ptr->func_label_num >= 0)
460 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->func_label_num);
461 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
465 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
468 for ( ; i < count_basic_blocks; i++)
469 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
471 if (write_symbols != NO_DEBUG)
473 /* Output the table of line numbers. */
474 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
475 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
476 assemble_integer (GEN_INT (ptr->line_num), UNITS_PER_WORD, 1);
478 for ( ; i < count_basic_blocks; i++)
479 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
481 /* Output the table of file names. */
482 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
483 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
485 if (ptr->file_label_num >= 0)
487 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->file_label_num);
488 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
492 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
495 for ( ; i < count_basic_blocks; i++)
496 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
499 /* End with the address of the table of addresses,
500 so we can find it easily, as the last word in the file's text. */
501 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
502 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
506 /* Enable APP processing of subsequent output.
507 Used before the output from an `asm' statement. */
514 fprintf (asm_out_file, ASM_APP_ON);
519 /* Enable APP processing of subsequent output.
520 Called from varasm.c before most kinds of output. */
527 fprintf (asm_out_file, ASM_APP_OFF);
532 /* Return the number of slots filled in the current
533 delayed branch sequence (we don't count the insn needing the
534 delay slot). Zero if not in a delayed branch sequence. */
538 dbr_sequence_length ()
540 if (final_sequence != 0)
541 return XVECLEN (final_sequence, 0) - 1;
547 /* The next two pages contain routines used to compute the length of an insn
548 and to shorten branches. */
550 /* Arrays for insn lengths, and addresses. The latter is referenced by
551 `insn_current_length'. */
553 static short *insn_lengths;
556 /* Address of insn being processed. Used by `insn_current_length'. */
557 int insn_current_address;
559 /* Indicate the branch shortening hasn't yet been done. */
567 /* Obtain the current length of an insn. If branch shortening has been done,
568 get its actual length. Otherwise, get its maximum length. */
571 get_attr_length (insn)
574 #ifdef HAVE_ATTR_length
580 return insn_lengths[INSN_UID (insn)];
582 switch (GET_CODE (insn))
590 length = insn_default_length (insn);
594 body = PATTERN (insn);
595 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
597 /* This only takes room if jump tables go into the text section. */
598 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
599 length = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
600 * GET_MODE_SIZE (GET_MODE (body)));
602 /* Be pessimistic and assume worst-case alignment. */
603 length += (GET_MODE_SIZE (GET_MODE (body)) - 1);
609 length = insn_default_length (insn);
613 body = PATTERN (insn);
614 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
617 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
618 length = asm_insn_count (body) * insn_default_length (insn);
619 else if (GET_CODE (body) == SEQUENCE)
620 for (i = 0; i < XVECLEN (body, 0); i++)
621 length += get_attr_length (XVECEXP (body, 0, i));
623 length = insn_default_length (insn);
626 #ifdef ADJUST_INSN_LENGTH
627 ADJUST_INSN_LENGTH (insn, length);
630 #else /* not HAVE_ATTR_length */
632 #endif /* not HAVE_ATTR_length */
635 /* Make a pass over all insns and compute their actual lengths by shortening
636 any branches of variable length if possible. */
638 /* Give a default value for the lowest address in a function. */
640 #ifndef FIRST_INSN_ADDRESS
641 #define FIRST_INSN_ADDRESS 0
645 shorten_branches (first)
648 #ifdef HAVE_ATTR_length
650 int something_changed = 1;
652 char *varying_length;
656 /* Compute maximum UID and allocate arrays. */
657 for (insn = first; insn; insn = NEXT_INSN (insn))
658 if (INSN_UID (insn) > max_uid)
659 max_uid = INSN_UID (insn);
662 insn_lengths = (short *) oballoc (max_uid * sizeof (short));
663 insn_addresses = (int *) oballoc (max_uid * sizeof (int));
664 varying_length = (char *) oballoc (max_uid * sizeof (char));
666 /* Compute initial lengths, addresses, and varying flags for each insn. */
667 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
669 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
671 uid = INSN_UID (insn);
672 insn_addresses[uid] = insn_current_address;
673 insn_lengths[uid] = 0;
674 varying_length[uid] = 0;
676 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
677 || GET_CODE (insn) == CODE_LABEL)
680 body = PATTERN (insn);
681 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
683 /* This only takes room if read-only data goes into the text
685 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
686 int unitsize = GET_MODE_SIZE (GET_MODE (body));
688 insn_lengths[uid] = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
689 * GET_MODE_SIZE (GET_MODE (body)));
691 /* Account for possible alignment. */
693 += unitsize - (insn_current_address & (unitsize - 1));
698 else if (asm_noperands (body) >= 0)
699 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
700 else if (GET_CODE (body) == SEQUENCE)
703 int const_delay_slots;
705 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
707 const_delay_slots = 0;
709 /* Inside a delay slot sequence, we do not do any branch shortening
710 if the shortening could change the number of delay slots
712 for (i = 0; i < XVECLEN (body, 0); i++)
714 rtx inner_insn = XVECEXP (body, 0, i);
715 int inner_uid = INSN_UID (inner_insn);
718 if (asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
719 inner_length = (asm_insn_count (PATTERN (inner_insn))
720 * insn_default_length (inner_insn));
722 inner_length = insn_default_length (inner_insn);
724 insn_lengths[inner_uid] = inner_length;
725 if (const_delay_slots)
727 if ((varying_length[inner_uid]
728 = insn_variable_length_p (inner_insn)) != 0)
729 varying_length[uid] = 1;
730 insn_addresses[inner_uid] = (insn_current_address +
734 varying_length[inner_uid] = 0;
735 insn_lengths[uid] += inner_length;
738 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
740 insn_lengths[uid] = insn_default_length (insn);
741 varying_length[uid] = insn_variable_length_p (insn);
744 /* If needed, do any adjustment. */
745 #ifdef ADJUST_INSN_LENGTH
746 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
750 /* Now loop over all the insns finding varying length insns. For each,
751 get the current insn length. If it has changed, reflect the change.
752 When nothing changes for a full pass, we are done. */
754 while (something_changed)
756 something_changed = 0;
757 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
759 insn = NEXT_INSN (insn))
764 uid = INSN_UID (insn);
765 insn_addresses[uid] = insn_current_address;
766 if (! varying_length[uid])
768 insn_current_address += insn_lengths[uid];
771 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
775 body = PATTERN (insn);
777 for (i = 0; i < XVECLEN (body, 0); i++)
779 rtx inner_insn = XVECEXP (body, 0, i);
780 int inner_uid = INSN_UID (inner_insn);
783 insn_addresses[inner_uid] = insn_current_address;
785 /* insn_current_length returns 0 for insns with a
786 non-varying length. */
787 if (! varying_length[inner_uid])
788 inner_length = insn_lengths[inner_uid];
790 inner_length = insn_current_length (inner_insn);
792 if (inner_length != insn_lengths[inner_uid])
794 insn_lengths[inner_uid] = inner_length;
795 something_changed = 1;
797 insn_current_address += insn_lengths[inner_uid];
798 new_length += inner_length;
803 new_length = insn_current_length (insn);
804 insn_current_address += new_length;
807 #ifdef SHORTEN_WITH_ADJUST_INSN_LENGTH
808 #ifdef ADJUST_INSN_LENGTH
809 /* If needed, do any adjustment. */
810 tmp_length = new_length;
811 ADJUST_INSN_LENGTH (insn, new_length);
812 insn_current_address += (new_length - tmp_length);
816 if (new_length != insn_lengths[uid])
818 insn_lengths[uid] = new_length;
819 something_changed = 1;
823 #endif /* HAVE_ATTR_length */
826 #ifdef HAVE_ATTR_length
827 /* Given the body of an INSN known to be generated by an ASM statement, return
828 the number of machine instructions likely to be generated for this insn.
829 This is used to compute its length. */
832 asm_insn_count (body)
838 for (template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
840 *template; template++)
841 if (IS_ASM_LOGICAL_LINE_SEPARATOR(*template) || *template == '\n')
848 /* Output assembler code for the start of a function,
849 and initialize some of the variables in this file
850 for the new function. The label for the function and associated
851 assembler pseudo-ops have already been output in `assemble_start_function'.
853 FIRST is the first insn of the rtl for the function being compiled.
854 FILE is the file to write assembler code to.
855 OPTIMIZE is nonzero if we should eliminate redundant
856 test and compare insns. */
859 final_start_function (first, file, optimize)
866 this_is_asm_operands = 0;
868 #ifdef NON_SAVING_SETJMP
869 /* A function that calls setjmp should save and restore all the
870 call-saved registers on a system where longjmp clobbers them. */
871 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
875 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
876 if (!call_used_regs[i] && !call_fixed_regs[i])
877 regs_ever_live[i] = 1;
881 /* Initial line number is supposed to be output
882 before the function's prologue and label
883 so that the function's address will not appear to be
884 in the last statement of the preceding function. */
885 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
887 if (write_symbols == SDB_DEBUG)
888 /* For sdb, let's not, but say we did.
889 We need to set last_linenum for sdbout_function_begin,
890 but we can't have an actual line number before the .bf symbol.
891 (sdb_begin_function_line is not set,
892 and other compilers don't do it.) */
893 last_linenum = NOTE_LINE_NUMBER (first);
894 #ifdef XCOFF_DEBUGGING_INFO
895 else if (write_symbols == XCOFF_DEBUG)
897 last_linenum = NOTE_LINE_NUMBER (first);
898 xcoffout_output_first_source_line (file, last_linenum);
902 output_source_line (file, first);
905 #ifdef LEAF_REG_REMAP
907 leaf_renumber_regs (first);
910 /* The Sun386i and perhaps other machines don't work right
911 if the profiling code comes after the prologue. */
912 #ifdef PROFILE_BEFORE_PROLOGUE
914 profile_function (file);
915 #endif /* PROFILE_BEFORE_PROLOGUE */
917 #ifdef FUNCTION_PROLOGUE
918 /* First output the function prologue: code to set up the stack frame. */
919 FUNCTION_PROLOGUE (file, get_frame_size ());
922 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
923 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
924 next_block_index = 1;
927 /* If the machine represents the prologue as RTL, the profiling code must
928 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
932 profile_after_prologue (file);
936 /* If we are doing basic block profiling, remember a printable version
937 of the function name. */
938 if (profile_block_flag)
940 char *junk = "function";
942 add_bb_string ((*decl_printable_name) (current_function_decl, &junk), FALSE);
947 profile_after_prologue (file)
950 #ifdef FUNCTION_BLOCK_PROFILER
951 if (profile_block_flag)
953 FUNCTION_BLOCK_PROFILER (file, profile_label_no);
955 #endif /* FUNCTION_BLOCK_PROFILER */
957 #ifndef PROFILE_BEFORE_PROLOGUE
959 profile_function (file);
960 #endif /* not PROFILE_BEFORE_PROLOGUE */
964 profile_function (file)
967 int align = MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD);
968 int sval = current_function_returns_struct;
969 int cxt = current_function_needs_context;
972 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
973 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
974 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
978 #ifdef STRUCT_VALUE_INCOMING_REGNUM
980 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
982 #ifdef STRUCT_VALUE_REGNUM
984 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
989 #ifdef STATIC_CHAIN_INCOMING_REGNUM
991 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
993 #ifdef STATIC_CHAIN_REGNUM
995 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1000 FUNCTION_PROFILER (file, profile_label_no);
1003 #ifdef STATIC_CHAIN_INCOMING_REGNUM
1005 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1007 #ifdef STATIC_CHAIN_REGNUM
1009 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1014 #ifdef STRUCT_VALUE_INCOMING_REGNUM
1016 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1018 #ifdef STRUCT_VALUE_REGNUM
1020 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1025 /* Output assembler code for the end of a function.
1026 For clarity, args are same as those of `final_start_function'
1027 even though not all of them are needed. */
1030 final_end_function (first, file, optimize)
1037 fprintf (file, ASM_APP_OFF);
1041 #ifdef SDB_DEBUGGING_INFO
1042 if (write_symbols == SDB_DEBUG)
1043 sdbout_end_function (last_linenum);
1046 #ifdef DWARF_DEBUGGING_INFO
1047 if (write_symbols == DWARF_DEBUG)
1048 dwarfout_end_function ();
1051 #ifdef XCOFF_DEBUGGING_INFO
1052 if (write_symbols == XCOFF_DEBUG)
1053 xcoffout_end_function (file, last_linenum);
1056 #ifdef FUNCTION_EPILOGUE
1057 /* Finally, output the function epilogue:
1058 code to restore the stack frame and return to the caller. */
1059 FUNCTION_EPILOGUE (file, get_frame_size ());
1062 #ifdef SDB_DEBUGGING_INFO
1063 if (write_symbols == SDB_DEBUG)
1064 sdbout_end_epilogue ();
1067 #ifdef DWARF_DEBUGGING_INFO
1068 if (write_symbols == DWARF_DEBUG)
1069 dwarfout_end_epilogue ();
1072 #ifdef XCOFF_DEBUGGING_INFO
1073 if (write_symbols == XCOFF_DEBUG)
1074 xcoffout_end_epilogue (file);
1077 bb_func_label_num = -1; /* not in function, nuke label # */
1079 /* If FUNCTION_EPILOGUE is not defined, then the function body
1080 itself contains return instructions wherever needed. */
1083 /* Add a block to the linked list that remembers the current line/file/function
1084 for basic block profiling. Emit the label in front of the basic block and
1085 the instructions that increment the count field. */
1091 struct bb_list *ptr = (struct bb_list *) permalloc (sizeof (struct bb_list));
1093 /* Add basic block to linked list. */
1095 ptr->line_num = last_linenum;
1096 ptr->file_label_num = bb_file_label_num;
1097 ptr->func_label_num = bb_func_label_num;
1099 bb_tail = &ptr->next;
1101 /* Enable the table of basic-block use counts
1102 to point at the code it applies to. */
1103 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1105 /* Before first insn of this basic block, increment the
1106 count of times it was entered. */
1107 #ifdef BLOCK_PROFILER
1108 BLOCK_PROFILER (file, count_basic_blocks);
1113 count_basic_blocks++;
1116 /* Add a string to be used for basic block profiling. */
1119 add_bb_string (string, perm_p)
1124 struct bb_str *ptr = 0;
1128 string = "<unknown>";
1132 /* Allocate a new string if the current string isn't permanent. If
1133 the string is permanent search for the same string in other
1136 len = strlen (string) + 1;
1139 char *p = (char *) permalloc (len);
1140 bcopy (string, p, len);
1144 for (ptr = sbb_head; ptr != (struct bb_str *)0; ptr = ptr->next)
1145 if (ptr->string == string)
1148 /* Allocate a new string block if we need to. */
1151 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1154 ptr->label_num = sbb_label_num++;
1155 ptr->string = string;
1157 sbb_tail = &ptr->next;
1160 return ptr->label_num;
1164 /* Output assembler code for some insns: all or part of a function.
1165 For description of args, see `final_start_function', above.
1167 PRESCAN is 1 if we are not really outputting,
1168 just scanning as if we were outputting.
1169 Prescanning deletes and rearranges insns just like ordinary output.
1170 PRESCAN is -2 if we are outputting after having prescanned.
1171 In this case, don't try to delete or rearrange insns
1172 because that has already been done.
1173 Prescanning is done only on certain machines. */
1176 final (first, file, optimize, prescan)
1185 last_ignored_compare = 0;
1188 /* Make a map indicating which line numbers appear in this function.
1189 When producing SDB debugging info, delete troublesome line number
1190 notes from inlined functions in other files as well as duplicate
1191 line number notes. */
1192 #ifdef SDB_DEBUGGING_INFO
1193 if (write_symbols == SDB_DEBUG)
1196 for (insn = first; insn; insn = NEXT_INSN (insn))
1197 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1199 if ((RTX_INTEGRATED_P (insn)
1200 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1202 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1203 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1205 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1206 NOTE_SOURCE_FILE (insn) = 0;
1210 if (NOTE_LINE_NUMBER (insn) > max_line)
1211 max_line = NOTE_LINE_NUMBER (insn);
1217 for (insn = first; insn; insn = NEXT_INSN (insn))
1218 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1219 max_line = NOTE_LINE_NUMBER (insn);
1222 line_note_exists = (char *) oballoc (max_line + 1);
1223 bzero (line_note_exists, max_line + 1);
1225 for (insn = first; insn; insn = NEXT_INSN (insn))
1226 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1227 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1233 /* Output the insns. */
1234 for (insn = NEXT_INSN (first); insn;)
1235 insn = final_scan_insn (insn, file, optimize, prescan, 0);
1237 /* Do basic-block profiling here
1238 if the last insn was a conditional branch. */
1239 if (profile_block_flag && new_block)
1243 /* The final scan for one insn, INSN.
1244 Args are same as in `final', except that INSN
1245 is the insn being scanned.
1246 Value returned is the next insn to be scanned.
1248 NOPEEPHOLES is the flag to disallow peephole processing (currently
1249 used for within delayed branch sequence output). */
1252 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
1262 /* Ignore deleted insns. These can occur when we split insns (due to a
1263 template of "#") while not optimizing. */
1264 if (INSN_DELETED_P (insn))
1265 return NEXT_INSN (insn);
1267 switch (GET_CODE (insn))
1273 /* Align the beginning of a loop, for higher speed
1274 on certain machines. */
1276 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG && optimize > 0)
1278 #ifdef ASM_OUTPUT_LOOP_ALIGN
1279 rtx next = next_nonnote_insn (insn);
1280 if (next && GET_CODE (next) == CODE_LABEL)
1282 ASM_OUTPUT_LOOP_ALIGN (asm_out_file);
1287 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
1290 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
1292 #ifdef FUNCTION_END_PROLOGUE
1293 FUNCTION_END_PROLOGUE (file);
1295 profile_after_prologue (file);
1299 #ifdef FUNCTION_BEGIN_EPILOGUE
1300 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
1302 FUNCTION_BEGIN_EPILOGUE (file);
1307 if (write_symbols == NO_DEBUG)
1309 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
1311 #ifdef SDB_DEBUGGING_INFO
1312 if (write_symbols == SDB_DEBUG)
1313 sdbout_begin_function (last_linenum);
1315 #ifdef XCOFF_DEBUGGING_INFO
1316 if (write_symbols == XCOFF_DEBUG)
1317 xcoffout_begin_function (file, last_linenum);
1319 #ifdef DWARF_DEBUGGING_INFO
1320 if (write_symbols == DWARF_DEBUG)
1321 dwarfout_begin_function ();
1325 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
1326 break; /* An insn that was "deleted" */
1329 fprintf (file, ASM_APP_OFF);
1332 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
1333 && (debug_info_level == DINFO_LEVEL_NORMAL
1334 || debug_info_level == DINFO_LEVEL_VERBOSE
1335 #ifdef DWARF_DEBUGGING_INFO
1336 || write_symbols == DWARF_DEBUG
1341 /* Beginning of a symbol-block. Assign it a sequence number
1342 and push the number onto the stack PENDING_BLOCKS. */
1344 if (block_depth == max_block_depth)
1346 /* PENDING_BLOCKS is full; make it longer. */
1347 max_block_depth *= 2;
1349 = (int *) xrealloc (pending_blocks,
1350 max_block_depth * sizeof (int));
1352 pending_blocks[block_depth++] = next_block_index;
1354 /* Output debugging info about the symbol-block beginning. */
1356 #ifdef SDB_DEBUGGING_INFO
1357 if (write_symbols == SDB_DEBUG)
1358 sdbout_begin_block (file, last_linenum, next_block_index);
1360 #ifdef XCOFF_DEBUGGING_INFO
1361 if (write_symbols == XCOFF_DEBUG)
1362 xcoffout_begin_block (file, last_linenum, next_block_index);
1364 #ifdef DBX_DEBUGGING_INFO
1365 if (write_symbols == DBX_DEBUG)
1366 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
1368 #ifdef DWARF_DEBUGGING_INFO
1369 if (write_symbols == DWARF_DEBUG && block_depth > 1)
1370 dwarfout_begin_block (next_block_index);
1375 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
1376 && (debug_info_level == DINFO_LEVEL_NORMAL
1377 || debug_info_level == DINFO_LEVEL_VERBOSE
1378 #ifdef DWARF_DEBUGGING_INFO
1379 || write_symbols == DWARF_DEBUG
1384 /* End of a symbol-block. Pop its sequence number off
1385 PENDING_BLOCKS and output debugging info based on that. */
1389 #ifdef XCOFF_DEBUGGING_INFO
1390 if (write_symbols == XCOFF_DEBUG && block_depth >= 0)
1391 xcoffout_end_block (file, last_linenum, pending_blocks[block_depth]);
1393 #ifdef DBX_DEBUGGING_INFO
1394 if (write_symbols == DBX_DEBUG && block_depth >= 0)
1395 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
1396 pending_blocks[block_depth]);
1398 #ifdef SDB_DEBUGGING_INFO
1399 if (write_symbols == SDB_DEBUG && block_depth >= 0)
1400 sdbout_end_block (file, last_linenum);
1402 #ifdef DWARF_DEBUGGING_INFO
1403 if (write_symbols == DWARF_DEBUG && block_depth >= 1)
1404 dwarfout_end_block (pending_blocks[block_depth]);
1407 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
1408 && (debug_info_level == DINFO_LEVEL_NORMAL
1409 || debug_info_level == DINFO_LEVEL_VERBOSE))
1411 #ifdef DWARF_DEBUGGING_INFO
1412 if (write_symbols == DWARF_DEBUG)
1413 dwarfout_label (insn);
1416 else if (NOTE_LINE_NUMBER (insn) > 0)
1417 /* This note is a line-number. */
1421 #if 0 /* This is what we used to do. */
1422 output_source_line (file, insn);
1426 /* If there is anything real after this note,
1427 output it. If another line note follows, omit this one. */
1428 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
1430 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
1432 /* These types of notes can be significant
1433 so make sure the preceding line number stays. */
1434 else if (GET_CODE (note) == NOTE
1435 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
1436 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
1437 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
1439 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
1441 /* Another line note follows; we can delete this note
1442 if no intervening line numbers have notes elsewhere. */
1444 for (num = NOTE_LINE_NUMBER (insn) + 1;
1445 num < NOTE_LINE_NUMBER (note);
1447 if (line_note_exists[num])
1450 if (num >= NOTE_LINE_NUMBER (note))
1456 /* Output this line note
1457 if it is the first or the last line note in a row. */
1459 output_source_line (file, insn);
1464 #ifdef ASM_OUTPUT_ALIGN_CODE
1465 /* Don't litter the assembler output with needless alignments. A
1466 BARRIER will be placed at the end of every function if HAVE_epilogue
1468 if (NEXT_INSN (insn))
1469 ASM_OUTPUT_ALIGN_CODE (file);
1478 #ifdef SDB_DEBUGGING_INFO
1479 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
1480 sdbout_label (insn);
1482 #ifdef DWARF_DEBUGGING_INFO
1483 if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
1484 dwarfout_label (insn);
1488 fprintf (file, ASM_APP_OFF);
1491 if (NEXT_INSN (insn) != 0
1492 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
1494 rtx nextbody = PATTERN (NEXT_INSN (insn));
1496 /* If this label is followed by a jump-table,
1497 make sure we put the label in the read-only section. Also
1498 possibly write the label and jump table together. */
1500 if (GET_CODE (nextbody) == ADDR_VEC
1501 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1503 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1504 readonly_data_section ();
1505 #ifdef READONLY_DATA_SECTION
1506 ASM_OUTPUT_ALIGN (file,
1507 exact_log2 (BIGGEST_ALIGNMENT
1509 #endif /* READONLY_DATA_SECTION */
1510 #else /* JUMP_TABLES_IN_TEXT_SECTION */
1512 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
1513 #ifdef ASM_OUTPUT_CASE_LABEL
1514 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
1517 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1523 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1528 register rtx body = PATTERN (insn);
1529 int insn_code_number;
1533 /* An INSN, JUMP_INSN or CALL_INSN.
1534 First check for special kinds that recog doesn't recognize. */
1536 if (GET_CODE (body) == USE /* These are just declarations */
1537 || GET_CODE (body) == CLOBBER)
1541 /* If there is a REG_CC_SETTER note on this insn, it means that
1542 the setting of the condition code was done in the delay slot
1543 of the insn that branched here. So recover the cc status
1544 from the insn that set it. */
1546 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1549 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
1550 cc_prev_status = cc_status;
1554 /* Detect insns that are really jump-tables
1555 and output them as such. */
1557 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1559 register int vlen, idx;
1566 fprintf (file, ASM_APP_OFF);
1570 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
1571 for (idx = 0; idx < vlen; idx++)
1573 if (GET_CODE (body) == ADDR_VEC)
1575 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
1576 ASM_OUTPUT_ADDR_VEC_ELT
1577 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
1584 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
1585 ASM_OUTPUT_ADDR_DIFF_ELT
1587 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
1588 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
1594 #ifdef ASM_OUTPUT_CASE_END
1595 ASM_OUTPUT_CASE_END (file,
1596 CODE_LABEL_NUMBER (PREV_INSN (insn)),
1605 /* Do basic-block profiling when we reach a new block.
1606 Done here to avoid jump tables. */
1607 if (profile_block_flag && new_block)
1610 if (GET_CODE (body) == ASM_INPUT)
1612 /* There's no telling what that did to the condition codes. */
1618 fprintf (file, ASM_APP_ON);
1621 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
1625 /* Detect `asm' construct with operands. */
1626 if (asm_noperands (body) >= 0)
1628 int noperands = asm_noperands (body);
1632 /* There's no telling what that did to the condition codes. */
1637 /* alloca won't do here, since only return from `final'
1640 ops = (rtx *) xmalloc (noperands * sizeof (rtx));
1644 fprintf (file, ASM_APP_ON);
1648 /* Get out the operand values. */
1649 string = decode_asm_operands (body, ops, NULL_PTR,
1650 NULL_PTR, NULL_PTR);
1651 /* Inhibit aborts on what would otherwise be compiler bugs. */
1652 insn_noperands = noperands;
1653 this_is_asm_operands = insn;
1654 /* Output the insn using them. */
1655 output_asm_insn (string, ops);
1656 this_is_asm_operands = 0;
1662 if (prescan <= 0 && app_on)
1664 fprintf (file, ASM_APP_OFF);
1668 if (GET_CODE (body) == SEQUENCE)
1670 /* A delayed-branch sequence */
1676 final_sequence = body;
1678 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
1679 force the restoration of a comparison that was previously
1680 thought unnecessary. If that happens, cancel this sequence
1681 and cause that insn to be restored. */
1683 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
1684 if (next != XVECEXP (body, 0, 1))
1690 for (i = 1; i < XVECLEN (body, 0); i++)
1691 final_scan_insn (XVECEXP (body, 0, i), file, 0, prescan, 1);
1692 #ifdef DBR_OUTPUT_SEQEND
1693 DBR_OUTPUT_SEQEND (file);
1697 /* If the insn requiring the delay slot was a CALL_INSN, the
1698 insns in the delay slot are actually executed before the
1699 called function. Hence we don't preserve any CC-setting
1700 actions in these insns and the CC must be marked as being
1701 clobbered by the function. */
1702 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
1705 /* Following a conditional branch sequence, we have a new basic
1707 if (profile_block_flag)
1709 rtx insn = XVECEXP (body, 0, 0);
1710 rtx body = PATTERN (insn);
1712 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1713 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1714 || (GET_CODE (insn) == JUMP_INSN
1715 && GET_CODE (body) == PARALLEL
1716 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1717 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
1723 /* We have a real machine instruction as rtl. */
1725 body = PATTERN (insn);
1728 /* Check for redundant test and compare instructions
1729 (when the condition codes are already set up as desired).
1730 This is done only when optimizing; if not optimizing,
1731 it should be possible for the user to alter a variable
1732 with the debugger in between statements
1733 and the next statement should reexamine the variable
1734 to compute the condition codes. */
1737 && GET_CODE (body) == SET
1738 && GET_CODE (SET_DEST (body)) == CC0
1739 && insn != last_ignored_compare)
1741 if (GET_CODE (SET_SRC (body)) == SUBREG)
1742 SET_SRC (body) = alter_subreg (SET_SRC (body));
1743 else if (GET_CODE (SET_SRC (body)) == COMPARE)
1745 if (GET_CODE (XEXP (SET_SRC (body), 0)) == SUBREG)
1746 XEXP (SET_SRC (body), 0)
1747 = alter_subreg (XEXP (SET_SRC (body), 0));
1748 if (GET_CODE (XEXP (SET_SRC (body), 1)) == SUBREG)
1749 XEXP (SET_SRC (body), 1)
1750 = alter_subreg (XEXP (SET_SRC (body), 1));
1752 if ((cc_status.value1 != 0
1753 && rtx_equal_p (SET_SRC (body), cc_status.value1))
1754 || (cc_status.value2 != 0
1755 && rtx_equal_p (SET_SRC (body), cc_status.value2)))
1757 /* Don't delete insn if it has an addressing side-effect. */
1758 if (! FIND_REG_INC_NOTE (insn, 0)
1759 /* or if anything in it is volatile. */
1760 && ! volatile_refs_p (PATTERN (insn)))
1762 /* We don't really delete the insn; just ignore it. */
1763 last_ignored_compare = insn;
1770 /* Following a conditional branch, we have a new basic block.
1771 But if we are inside a sequence, the new block starts after the
1772 last insn of the sequence. */
1773 if (profile_block_flag && final_sequence == 0
1774 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1775 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1776 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
1777 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1778 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
1782 /* Don't bother outputting obvious no-ops, even without -O.
1783 This optimization is fast and doesn't interfere with debugging.
1784 Don't do this if the insn is in a delay slot, since this
1785 will cause an improper number of delay insns to be written. */
1786 if (final_sequence == 0
1788 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
1789 && GET_CODE (SET_SRC (body)) == REG
1790 && GET_CODE (SET_DEST (body)) == REG
1791 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
1796 /* If this is a conditional branch, maybe modify it
1797 if the cc's are in a nonstandard state
1798 so that it accomplishes the same thing that it would
1799 do straightforwardly if the cc's were set up normally. */
1801 if (cc_status.flags != 0
1802 && GET_CODE (insn) == JUMP_INSN
1803 && GET_CODE (body) == SET
1804 && SET_DEST (body) == pc_rtx
1805 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
1806 /* This is done during prescan; it is not done again
1807 in final scan when prescan has been done. */
1810 /* This function may alter the contents of its argument
1811 and clear some of the cc_status.flags bits.
1812 It may also return 1 meaning condition now always true
1813 or -1 meaning condition now always false
1814 or 2 meaning condition nontrivial but altered. */
1815 register int result = alter_cond (XEXP (SET_SRC (body), 0));
1816 /* If condition now has fixed value, replace the IF_THEN_ELSE
1817 with its then-operand or its else-operand. */
1819 SET_SRC (body) = XEXP (SET_SRC (body), 1);
1821 SET_SRC (body) = XEXP (SET_SRC (body), 2);
1823 /* The jump is now either unconditional or a no-op.
1824 If it has become a no-op, don't try to output it.
1825 (It would not be recognized.) */
1826 if (SET_SRC (body) == pc_rtx)
1828 PUT_CODE (insn, NOTE);
1829 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1830 NOTE_SOURCE_FILE (insn) = 0;
1833 else if (GET_CODE (SET_SRC (body)) == RETURN)
1834 /* Replace (set (pc) (return)) with (return). */
1835 PATTERN (insn) = body = SET_SRC (body);
1837 /* Rerecognize the instruction if it has changed. */
1839 INSN_CODE (insn) = -1;
1842 /* Make same adjustments to instructions that examine the
1843 condition codes without jumping (if this machine has them). */
1845 if (cc_status.flags != 0
1846 && GET_CODE (body) == SET)
1848 switch (GET_CODE (SET_SRC (body)))
1861 register int result;
1862 if (XEXP (SET_SRC (body), 0) != cc0_rtx)
1864 result = alter_cond (SET_SRC (body));
1866 validate_change (insn, &SET_SRC (body), const_true_rtx, 0);
1867 else if (result == -1)
1868 validate_change (insn, &SET_SRC (body), const0_rtx, 0);
1869 else if (result == 2)
1870 INSN_CODE (insn) = -1;
1876 /* Do machine-specific peephole optimizations if desired. */
1878 if (optimize && !flag_no_peephole && !nopeepholes)
1880 rtx next = peephole (insn);
1881 /* When peepholing, if there were notes within the peephole,
1882 emit them before the peephole. */
1883 if (next != 0 && next != NEXT_INSN (insn))
1885 rtx prev = PREV_INSN (insn);
1888 for (note = NEXT_INSN (insn); note != next;
1889 note = NEXT_INSN (note))
1890 final_scan_insn (note, file, optimize, prescan, nopeepholes);
1892 /* In case this is prescan, put the notes
1893 in proper position for later rescan. */
1894 note = NEXT_INSN (insn);
1895 PREV_INSN (note) = prev;
1896 NEXT_INSN (prev) = note;
1897 NEXT_INSN (PREV_INSN (next)) = insn;
1898 PREV_INSN (insn) = PREV_INSN (next);
1899 NEXT_INSN (insn) = next;
1900 PREV_INSN (next) = insn;
1903 /* PEEPHOLE might have changed this. */
1904 body = PATTERN (insn);
1907 /* Try to recognize the instruction.
1908 If successful, verify that the operands satisfy the
1909 constraints for the instruction. Crash if they don't,
1910 since `reload' should have changed them so that they do. */
1912 insn_code_number = recog_memoized (insn);
1913 insn_extract (insn);
1914 for (i = 0; i < insn_n_operands[insn_code_number]; i++)
1916 if (GET_CODE (recog_operand[i]) == SUBREG)
1917 recog_operand[i] = alter_subreg (recog_operand[i]);
1918 else if (GET_CODE (recog_operand[i]) == PLUS
1919 || GET_CODE (recog_operand[i]) == MULT)
1920 recog_operand[i] = walk_alter_subreg (recog_operand[i]);
1923 for (i = 0; i < insn_n_dups[insn_code_number]; i++)
1925 if (GET_CODE (*recog_dup_loc[i]) == SUBREG)
1926 *recog_dup_loc[i] = alter_subreg (*recog_dup_loc[i]);
1927 else if (GET_CODE (*recog_dup_loc[i]) == PLUS
1928 || GET_CODE (*recog_dup_loc[i]) == MULT)
1929 *recog_dup_loc[i] = walk_alter_subreg (*recog_dup_loc[i]);
1932 #ifdef REGISTER_CONSTRAINTS
1933 if (! constrain_operands (insn_code_number, 1))
1934 fatal_insn_not_found (insn);
1937 /* Some target machines need to prescan each insn before
1940 #ifdef FINAL_PRESCAN_INSN
1941 FINAL_PRESCAN_INSN (insn, recog_operand,
1942 insn_n_operands[insn_code_number]);
1946 cc_prev_status = cc_status;
1948 /* Update `cc_status' for this instruction.
1949 The instruction's output routine may change it further.
1950 If the output routine for a jump insn needs to depend
1951 on the cc status, it should look at cc_prev_status. */
1953 NOTICE_UPDATE_CC (body, insn);
1958 /* If the proper template needs to be chosen by some C code,
1959 run that code and get the real template. */
1961 template = insn_template[insn_code_number];
1964 template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
1966 /* If the C code returns 0, it means that it is a jump insn
1967 which follows a deleted test insn, and that test insn
1968 needs to be reinserted. */
1971 if (prev_nonnote_insn (insn) != last_ignored_compare)
1974 return prev_nonnote_insn (insn);
1978 /* If the template is the string "#", it means that this insn must
1980 if (template[0] == '#' && template[1] == '\0')
1982 rtx new = try_split (body, insn, 0);
1984 /* If we didn't split the insn, go away. */
1985 if (new == insn && PATTERN (new) == body)
1995 /* Output assembler code from the template. */
1997 output_asm_insn (template, recog_operand);
2000 /* It's not at all clear why we did this and doing so interferes
2001 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2004 /* Mark this insn as having been output. */
2005 INSN_DELETED_P (insn) = 1;
2011 return NEXT_INSN (insn);
2014 /* Output debugging info to the assembler file FILE
2015 based on the NOTE-insn INSN, assumed to be a line number. */
2018 output_source_line (file, insn)
2022 char ltext_label_name[100];
2023 register char *filename = NOTE_SOURCE_FILE (insn);
2025 /* Remember filename for basic block profiling.
2026 Filenames are allocated on the permanent obstack
2027 or are passed in ARGV, so we don't have to save
2030 if (profile_block_flag && last_filename != filename)
2031 bb_file_label_num = add_bb_string (filename, TRUE);
2033 last_filename = filename;
2034 last_linenum = NOTE_LINE_NUMBER (insn);
2036 if (write_symbols != NO_DEBUG)
2038 #ifdef SDB_DEBUGGING_INFO
2039 if (write_symbols == SDB_DEBUG
2040 #if 0 /* People like having line numbers even in wrong file! */
2041 /* COFF can't handle multiple source files--lose, lose. */
2042 && !strcmp (filename, main_input_filename)
2044 /* COFF relative line numbers must be positive. */
2045 && last_linenum > sdb_begin_function_line)
2047 #ifdef ASM_OUTPUT_SOURCE_LINE
2048 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
2050 fprintf (file, "\t.ln\t%d\n",
2051 ((sdb_begin_function_line > -1)
2052 ? last_linenum - sdb_begin_function_line : 1));
2057 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
2058 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
2059 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
2060 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
2062 #ifdef DWARF_DEBUGGING_INFO
2063 if (write_symbols == DWARF_DEBUG)
2064 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
2069 /* If X is a SUBREG, replace it with a REG or a MEM,
2070 based on the thing it is a subreg of. */
2076 register rtx y = SUBREG_REG (x);
2077 if (GET_CODE (y) == SUBREG)
2078 y = alter_subreg (y);
2080 if (GET_CODE (y) == REG)
2082 /* If the containing reg really gets a hard reg, so do we. */
2084 REGNO (x) = REGNO (y) + SUBREG_WORD (x);
2086 else if (GET_CODE (y) == MEM)
2088 register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2089 #if BYTES_BIG_ENDIAN
2090 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
2091 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
2094 MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
2095 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
2101 /* Do alter_subreg on all the SUBREGs contained in X. */
2104 walk_alter_subreg (x)
2107 switch (GET_CODE (x))
2111 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2112 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
2116 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2120 return alter_subreg (x);
2128 /* Given BODY, the body of a jump instruction, alter the jump condition
2129 as required by the bits that are set in cc_status.flags.
2130 Not all of the bits there can be handled at this level in all cases.
2132 The value is normally 0.
2133 1 means that the condition has become always true.
2134 -1 means that the condition has become always false.
2135 2 means that COND has been altered. */
2143 if (cc_status.flags & CC_REVERSED)
2146 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
2149 if (cc_status.flags & CC_INVERTED)
2152 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
2155 if (cc_status.flags & CC_NOT_POSITIVE)
2156 switch (GET_CODE (cond))
2161 /* Jump becomes unconditional. */
2167 /* Jump becomes no-op. */
2171 PUT_CODE (cond, EQ);
2176 PUT_CODE (cond, NE);
2181 if (cc_status.flags & CC_NOT_NEGATIVE)
2182 switch (GET_CODE (cond))
2186 /* Jump becomes unconditional. */
2191 /* Jump becomes no-op. */
2196 PUT_CODE (cond, EQ);
2202 PUT_CODE (cond, NE);
2207 if (cc_status.flags & CC_NO_OVERFLOW)
2208 switch (GET_CODE (cond))
2211 /* Jump becomes unconditional. */
2215 PUT_CODE (cond, EQ);
2220 PUT_CODE (cond, NE);
2225 /* Jump becomes no-op. */
2229 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
2230 switch (GET_CODE (cond))
2243 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
2248 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
2253 if (cc_status.flags & CC_NOT_SIGNED)
2254 /* The flags are valid if signed condition operators are converted
2256 switch (GET_CODE (cond))
2259 PUT_CODE (cond, LEU);
2264 PUT_CODE (cond, LTU);
2269 PUT_CODE (cond, GTU);
2274 PUT_CODE (cond, GEU);
2283 /* Report inconsistency between the assembler template and the operands.
2284 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
2287 output_operand_lossage (str)
2290 if (this_is_asm_operands)
2291 error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
2296 /* Output of assembler code from a template, and its subroutines. */
2298 /* Output text from TEMPLATE to the assembler output file,
2299 obeying %-directions to substitute operands taken from
2300 the vector OPERANDS.
2302 %N (for N a digit) means print operand N in usual manner.
2303 %lN means require operand N to be a CODE_LABEL or LABEL_REF
2304 and print the label name with no punctuation.
2305 %cN means require operand N to be a constant
2306 and print the constant expression with no punctuation.
2307 %aN means expect operand N to be a memory address
2308 (not a memory reference!) and print a reference
2310 %nN means expect operand N to be a constant
2311 and print a constant expression for minus the value
2312 of the operand, with no other punctuation. */
2315 output_asm_insn (template, operands)
2322 /* An insn may return a null string template
2323 in a case where no assembler code is needed. */
2328 putc ('\t', asm_out_file);
2330 #ifdef ASM_OUTPUT_OPCODE
2331 ASM_OUTPUT_OPCODE (asm_out_file, p);
2337 #ifdef ASM_OUTPUT_OPCODE
2339 putc (c, asm_out_file);
2340 while ((c = *p) == '\t')
2342 putc (c, asm_out_file);
2345 ASM_OUTPUT_OPCODE (asm_out_file, p);
2349 #ifdef ASSEMBLER_DIALECT
2351 /* If we want the first dialect, do nothing. Otherwise, skip
2352 DIALECT_NUMBER of strings ending with '|'. */
2353 for (i = 0; i < dialect_number; i++)
2355 while (*p && *p++ != '|')
2364 /* Skip to close brace. */
2365 while (*p && *p++ != '}')
2374 /* %% outputs a single %. */
2378 putc (c, asm_out_file);
2380 /* %= outputs a number which is unique to each insn in the entire
2381 compilation. This is useful for making local labels that are
2382 referred to more than once in a given insn. */
2386 fprintf (asm_out_file, "%d", insn_counter);
2388 /* % followed by a letter and some digits
2389 outputs an operand in a special way depending on the letter.
2390 Letters `acln' are implemented directly.
2391 Other letters are passed to `output_operand' so that
2392 the PRINT_OPERAND macro can define them. */
2393 else if ((*p >= 'a' && *p <= 'z')
2394 || (*p >= 'A' && *p <= 'Z'))
2399 if (! (*p >= '0' && *p <= '9'))
2400 output_operand_lossage ("operand number missing after %-letter");
2401 else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2402 output_operand_lossage ("operand number out of range");
2403 else if (letter == 'l')
2404 output_asm_label (operands[c]);
2405 else if (letter == 'a')
2406 output_address (operands[c]);
2407 else if (letter == 'c')
2409 if (CONSTANT_ADDRESS_P (operands[c]))
2410 output_addr_const (asm_out_file, operands[c]);
2412 output_operand (operands[c], 'c');
2414 else if (letter == 'n')
2416 if (GET_CODE (operands[c]) == CONST_INT)
2417 fprintf (asm_out_file,
2418 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2423 - INTVAL (operands[c]));
2426 putc ('-', asm_out_file);
2427 output_addr_const (asm_out_file, operands[c]);
2431 output_operand (operands[c], letter);
2433 while ((c = *p) >= '0' && c <= '9') p++;
2435 /* % followed by a digit outputs an operand the default way. */
2436 else if (*p >= '0' && *p <= '9')
2439 if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2440 output_operand_lossage ("operand number out of range");
2442 output_operand (operands[c], 0);
2443 while ((c = *p) >= '0' && c <= '9') p++;
2445 /* % followed by punctuation: output something for that
2446 punctuation character alone, with no operand.
2447 The PRINT_OPERAND macro decides what is actually done. */
2448 #ifdef PRINT_OPERAND_PUNCT_VALID_P
2449 else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
2450 output_operand (NULL_RTX, *p++);
2453 output_operand_lossage ("invalid %%-code");
2457 putc (c, asm_out_file);
2460 if (flag_print_asm_name)
2462 /* Annotate the assembly with a comment describing the pattern and
2463 alternative used. */
2466 register int num = INSN_CODE (debug_insn);
2467 fprintf (asm_out_file, " %s %d %s",
2468 ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
2469 if (insn_n_alternatives[num] > 1)
2470 fprintf (asm_out_file, "/%d", which_alternative + 1);
2472 /* Clear this so only the first assembler insn
2473 of any rtl insn will get the special comment for -dp. */
2478 putc ('\n', asm_out_file);
2481 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
2484 output_asm_label (x)
2489 if (GET_CODE (x) == LABEL_REF)
2490 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2491 else if (GET_CODE (x) == CODE_LABEL)
2492 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2494 output_operand_lossage ("`%l' operand isn't a label");
2496 assemble_name (asm_out_file, buf);
2499 /* Print operand X using machine-dependent assembler syntax.
2500 The macro PRINT_OPERAND is defined just to control this function.
2501 CODE is a non-digit that preceded the operand-number in the % spec,
2502 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
2503 between the % and the digits.
2504 When CODE is a non-letter, X is 0.
2506 The meanings of the letters are machine-dependent and controlled
2507 by PRINT_OPERAND. */
2510 output_operand (x, code)
2514 if (x && GET_CODE (x) == SUBREG)
2515 x = alter_subreg (x);
2517 /* If X is a pseudo-register, abort now rather than writing trash to the
2520 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2523 PRINT_OPERAND (asm_out_file, x, code);
2526 /* Print a memory reference operand for address X
2527 using machine-dependent assembler syntax.
2528 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
2534 walk_alter_subreg (x);
2535 PRINT_OPERAND_ADDRESS (asm_out_file, x);
2538 /* Print an integer constant expression in assembler syntax.
2539 Addition and subtraction are the only arithmetic
2540 that may appear in these expressions. */
2543 output_addr_const (file, x)
2550 switch (GET_CODE (x))
2560 assemble_name (file, XSTR (x, 0));
2564 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2565 assemble_name (file, buf);
2569 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2570 assemble_name (file, buf);
2575 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2584 /* This used to output parentheses around the expression,
2585 but that does not work on the 386 (either ATT or BSD assembler). */
2586 output_addr_const (file, XEXP (x, 0));
2590 if (GET_MODE (x) == VOIDmode)
2592 /* We can use %d if the number is one word and positive. */
2593 if (CONST_DOUBLE_HIGH (x))
2595 #if HOST_BITS_PER_WIDE_INT == 64
2596 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2602 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2608 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2609 else if (CONST_DOUBLE_LOW (x) < 0)
2611 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2616 CONST_DOUBLE_LOW (x));
2619 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2624 CONST_DOUBLE_LOW (x));
2627 /* We can't handle floating point constants;
2628 PRINT_OPERAND must handle them. */
2629 output_operand_lossage ("floating constant misused");
2633 /* Some assemblers need integer constants to appear last (eg masm). */
2634 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2636 output_addr_const (file, XEXP (x, 1));
2637 if (INTVAL (XEXP (x, 0)) >= 0)
2638 fprintf (file, "+");
2639 output_addr_const (file, XEXP (x, 0));
2643 output_addr_const (file, XEXP (x, 0));
2644 if (INTVAL (XEXP (x, 1)) >= 0)
2645 fprintf (file, "+");
2646 output_addr_const (file, XEXP (x, 1));
2651 /* Avoid outputting things like x-x or x+5-x,
2652 since some assemblers can't handle that. */
2653 x = simplify_subtraction (x);
2654 if (GET_CODE (x) != MINUS)
2657 output_addr_const (file, XEXP (x, 0));
2658 fprintf (file, "-");
2659 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2660 && INTVAL (XEXP (x, 1)) < 0)
2662 fprintf (file, ASM_OPEN_PAREN);
2663 output_addr_const (file, XEXP (x, 1));
2664 fprintf (file, ASM_CLOSE_PAREN);
2667 output_addr_const (file, XEXP (x, 1));
2672 output_addr_const (file, XEXP (x, 0));
2676 output_operand_lossage ("invalid expression as operand");
2680 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
2681 %R prints the value of REGISTER_PREFIX.
2682 %L prints the value of LOCAL_LABEL_PREFIX.
2683 %U prints the value of USER_LABEL_PREFIX.
2684 %I prints the value of IMMEDIATE_PREFIX.
2685 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
2686 Also supported are %d, %x, %s, %e, %f, %g and %%.
2688 We handle alternate assembler dialects here, just like output_asm_insn. */
2691 asm_fprintf VPROTO((FILE *file, char *p, ...))
2702 VA_START (argptr, p);
2705 file = va_arg (argptr, FILE*);
2706 p = va_arg (argptr, char*);
2714 #ifdef ASSEMBLER_DIALECT
2716 /* If we want the first dialect, do nothing. Otherwise, skip
2717 DIALECT_NUMBER of strings ending with '|'. */
2718 for (i = 0; i < dialect_number; i++)
2720 while (*p && *p++ != '|')
2729 /* Skip to close brace. */
2730 while (*p && *p++ != '}')
2741 while ((c >= '0' && c <= '9') || c == '.')
2749 fprintf (file, "%%");
2752 case 'd': case 'i': case 'u':
2753 case 'x': case 'p': case 'X':
2757 fprintf (file, buf, va_arg (argptr, int));
2761 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
2762 but we do not check for those cases. It means that the value
2763 is a HOST_WIDE_INT, which may be either `int' or `long'. */
2765 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2771 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
2778 fprintf (file, buf, va_arg (argptr, long));
2786 fprintf (file, buf, va_arg (argptr, double));
2792 fprintf (file, buf, va_arg (argptr, char *));
2796 #ifdef ASM_OUTPUT_OPCODE
2797 ASM_OUTPUT_OPCODE (asm_out_file, p);
2802 #ifdef REGISTER_PREFIX
2803 fprintf (file, "%s", REGISTER_PREFIX);
2808 #ifdef IMMEDIATE_PREFIX
2809 fprintf (file, "%s", IMMEDIATE_PREFIX);
2814 #ifdef LOCAL_LABEL_PREFIX
2815 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
2820 #ifdef USER_LABEL_PREFIX
2821 fprintf (file, "%s", USER_LABEL_PREFIX);
2835 /* Split up a CONST_DOUBLE or integer constant rtx
2836 into two rtx's for single words,
2837 storing in *FIRST the word that comes first in memory in the target
2838 and in *SECOND the other. */
2841 split_double (value, first, second)
2843 rtx *first, *second;
2845 if (GET_CODE (value) == CONST_INT)
2847 /* The rule for using CONST_INT for a wider mode
2848 is that we regard the value as signed.
2849 So sign-extend it. */
2850 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
2851 #if WORDS_BIG_ENDIAN
2859 else if (GET_CODE (value) != CONST_DOUBLE)
2861 #if WORDS_BIG_ENDIAN
2862 *first = const0_rtx;
2866 *second = const0_rtx;
2869 else if (GET_MODE (value) == VOIDmode
2870 /* This is the old way we did CONST_DOUBLE integers. */
2871 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
2873 /* In an integer, the words are defined as most and least significant.
2874 So order them by the target's convention. */
2875 #if WORDS_BIG_ENDIAN
2876 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2877 *second = GEN_INT (CONST_DOUBLE_LOW (value));
2879 *first = GEN_INT (CONST_DOUBLE_LOW (value));
2880 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
2885 #ifdef REAL_ARITHMETIC
2886 REAL_VALUE_TYPE r; HOST_WIDE_INT l[2];
2887 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
2888 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
2889 *first = GEN_INT (l[0]);
2890 *second = GEN_INT (l[1]);
2892 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
2893 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
2894 && ! flag_pretend_float)
2897 #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
2898 /* Host and target agree => no need to swap. */
2899 *first = GEN_INT (CONST_DOUBLE_LOW (value));
2900 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
2902 *second = GEN_INT (CONST_DOUBLE_LOW (value));
2903 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2905 #endif /* no REAL_ARITHMETIC */
2909 /* Return nonzero if this function has no function calls. */
2916 if (profile_flag || profile_block_flag)
2919 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2921 if (GET_CODE (insn) == CALL_INSN)
2923 if (GET_CODE (insn) == INSN
2924 && GET_CODE (PATTERN (insn)) == SEQUENCE
2925 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN)
2928 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
2930 if (GET_CODE (XEXP (insn, 0)) == CALL_INSN)
2932 if (GET_CODE (XEXP (insn, 0)) == INSN
2933 && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
2934 && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN)
2941 /* On some machines, a function with no call insns
2942 can run faster if it doesn't create its own register window.
2943 When output, the leaf function should use only the "output"
2944 registers. Ordinarily, the function would be compiled to use
2945 the "input" registers to find its arguments; it is a candidate
2946 for leaf treatment if it uses only the "input" registers.
2947 Leaf function treatment means renumbering so the function
2948 uses the "output" registers instead. */
2950 #ifdef LEAF_REGISTERS
2952 static char permitted_reg_in_leaf_functions[] = LEAF_REGISTERS;
2954 /* Return 1 if this function uses only the registers that can be
2955 safely renumbered. */
2958 only_leaf_regs_used ()
2962 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2964 if ((regs_ever_live[i] || global_regs[i])
2965 && ! permitted_reg_in_leaf_functions[i])
2971 /* Scan all instructions and renumber all registers into those
2972 available in leaf functions. */
2975 leaf_renumber_regs (first)
2980 /* Renumber only the actual patterns.
2981 The reg-notes can contain frame pointer refs,
2982 and renumbering them could crash, and should not be needed. */
2983 for (insn = first; insn; insn = NEXT_INSN (insn))
2984 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
2985 leaf_renumber_regs_insn (PATTERN (insn));
2986 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
2987 if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
2988 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
2991 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
2992 available in leaf functions. */
2995 leaf_renumber_regs_insn (in_rtx)
2996 register rtx in_rtx;
2999 register char *format_ptr;
3004 /* Renumber all input-registers into output-registers.
3005 renumbered_regs would be 1 for an output-register;
3008 if (GET_CODE (in_rtx) == REG)
3012 /* Don't renumber the same reg twice. */
3016 newreg = REGNO (in_rtx);
3017 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
3018 to reach here as part of a REG_NOTE. */
3019 if (newreg >= FIRST_PSEUDO_REGISTER)
3024 newreg = LEAF_REG_REMAP (newreg);
3027 regs_ever_live[REGNO (in_rtx)] = 0;
3028 regs_ever_live[newreg] = 1;
3029 REGNO (in_rtx) = newreg;
3033 if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
3035 /* Inside a SEQUENCE, we find insns.
3036 Renumber just the patterns of these insns,
3037 just as we do for the top-level insns. */
3038 leaf_renumber_regs_insn (PATTERN (in_rtx));
3042 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
3044 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
3045 switch (*format_ptr++)
3048 leaf_renumber_regs_insn (XEXP (in_rtx, i));
3052 if (NULL != XVEC (in_rtx, i))
3054 for (j = 0; j < XVECLEN (in_rtx, i); j++)
3055 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));