1 /* Convert RTL to assembler code and output it, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992 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. */
50 #include "insn-config.h"
51 #include "insn-flags.h"
52 #include "insn-attr.h"
53 #include "insn-codes.h"
55 #include "conditions.h"
58 #include "hard-reg-set.h"
65 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist. */
66 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
67 #if defined (USG) || defined (NO_STAB_H)
68 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
70 #include <stab.h> /* On BSD, use the system's stab.h. */
72 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
74 #ifdef XCOFF_DEBUGGING_INFO
78 /* .stabd code for line number. */
83 /* .stabs code for included file name. */
89 #define INT_TYPE_SIZE BITS_PER_WORD
92 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
93 null default for it to save conditionalization later. */
94 #ifndef CC_STATUS_INIT
95 #define CC_STATUS_INIT
98 /* How to start an assembler comment. */
99 #ifndef ASM_COMMENT_START
100 #define ASM_COMMENT_START ";#"
104 void output_asm_insn ();
106 static int alter_cond ();
107 void output_asm_label ();
108 static void output_operand ();
109 void output_address ();
110 void output_addr_const ();
111 static void output_source_line ();
112 rtx final_scan_insn ();
113 void profile_function ();
114 static void profile_after_prologue ();
116 #ifdef HAVE_ATTR_length
117 static int asm_insn_count ();
120 /* Nonzero means this function is a leaf function, with no function calls.
121 This variable exists to be examined in FUNCTION_PROLOGUE
122 and FUNCTION_EPILOGUE. Always zero, unless set by some action. */
125 int leaf_function_p ();
127 #ifdef LEAF_REGISTERS
128 int only_leaf_regs_used ();
129 static void leaf_renumber_regs ();
130 void leaf_renumber_regs_insn ();
133 /* Last insn processed by final_scan_insn. */
134 static rtx debug_insn = 0;
136 /* Line number of last NOTE. */
137 static int last_linenum;
139 /* Number of basic blocks seen so far;
140 used if profile_block_flag is set. */
141 static int count_basic_blocks;
143 /* Nonzero while outputting an `asm' with operands.
144 This means that inconsistencies are the user's fault, so don't abort.
145 The precise value is the insn being output, to pass to error_for_asm. */
146 static rtx this_is_asm_operands;
148 /* Number of operands of this insn, for an `asm' with operands. */
149 static int insn_noperands;
151 /* Compare optimization flag. */
153 static rtx last_ignored_compare = 0;
155 /* Flag indicating this insn is the start of a new basic block. */
157 static int new_block = 1;
159 /* All the symbol-blocks (levels of scoping) in the compilation
160 are assigned sequence numbers in order of appearance of the
161 beginnings of the symbol-blocks. Both final and dbxout do this,
162 and assume that they will both give the same number to each block.
163 Final uses these sequence numbers to generate assembler label names
164 LBBnnn and LBEnnn for the beginning and end of the symbol-block.
165 Dbxout uses the sequence numbers to generate references to the same labels
166 from the dbx debugging information.
168 Sdb records this level at the beginning of each function,
169 in order to find the current level when recursing down declarations.
170 It outputs the block beginning and endings
171 at the point in the asm file where the blocks would begin and end. */
173 int next_block_index;
175 /* Assign a unique number to each insn that is output.
176 This can be used to generate unique local labels. */
178 static int insn_counter = 0;
181 /* This variable contains machine-dependent flags (defined in tm.h)
182 set and examined by output routines
183 that describe how to interpret the condition codes properly. */
187 /* During output of an insn, this contains a copy of cc_status
188 from before the insn. */
190 CC_STATUS cc_prev_status;
193 /* Indexed by hardware reg number, is 1 if that register is ever
194 used in the current function.
196 In life_analysis, or in stupid_life_analysis, this is set
197 up to record the hard regs used explicitly. Reload adds
198 in the hard regs used for holding pseudo regs. Final uses
199 it to generate the code in the function prologue and epilogue
200 to save and restore registers as needed. */
202 char regs_ever_live[FIRST_PSEUDO_REGISTER];
204 /* Nonzero means current function must be given a frame pointer.
205 Set in stmt.c if anything is allocated on the stack there.
206 Set in reload1.c if anything is allocated on the stack there. */
208 int frame_pointer_needed;
210 /* Assign unique numbers to labels generated for profiling. */
212 int profile_label_no;
214 /* Length so far allocated in PENDING_BLOCKS. */
216 static int max_block_depth;
218 /* Stack of sequence numbers of symbol-blocks of which we have seen the
219 beginning but not yet the end. Sequence numbers are assigned at
220 the beginning; this stack allows us to find the sequence number
221 of a block that is ending. */
223 static int *pending_blocks;
225 /* Number of elements currently in use in PENDING_BLOCKS. */
227 static int block_depth;
229 /* Nonzero if have enabled APP processing of our assembler output. */
233 /* If we are outputting an insn sequence, this contains the sequence rtx.
238 /* Indexed by line number, nonzero if there is a note for that line. */
240 static char *line_note_exists;
242 /* Initialize data in final at the beginning of a compilation. */
245 init_final (filename)
248 next_block_index = 2;
250 max_block_depth = 20;
251 pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
255 /* Called at end of source file,
256 to output the block-profiling table for this entire compilation. */
264 if (profile_block_flag)
270 /* Output the main header, of 6 words:
271 0: 1 if this file's initialized, else 0.
272 1: address of file name.
273 2: address of table of counts.
274 4: number of counts in the table.
275 5: always 0, for compatibility with Sun.
276 6: extra word added by GNU: address of address table
277 which contains addresses of basic blocks,
278 in parallel with the table of counts. */
279 ASM_OUTPUT_ALIGN (asm_out_file,
280 exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
282 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
283 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
284 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
285 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
286 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
287 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
288 assemble_integer (GEN_INT (count_basic_blocks), UNITS_PER_WORD, 1);
289 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
290 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
291 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
293 /* Output the file name. */
294 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
296 int len = strlen (filename);
297 char *data_file = (char *) alloca (len + 3);
298 strcpy (data_file, filename);
299 strip_off_ending (data_file, len);
300 strcat (data_file, ".d");
301 assemble_string (data_file, strlen (data_file) + 1);
304 /* Realign data section. */
305 ASM_OUTPUT_ALIGN (asm_out_file,
306 exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
308 /* Make space for the table of counts. */
309 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
310 assemble_zeros (INT_TYPE_SIZE / BITS_PER_UNIT * count_basic_blocks);
312 /* Output the table of addresses. */
313 readonly_data_section ();
314 /* Realign in new section */
315 ASM_OUTPUT_ALIGN (asm_out_file,
316 floor_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
317 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
318 for (i = 0; i < count_basic_blocks; i++)
321 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
322 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
326 /* End with the address of the table of addresses,
327 so we can find it easily, as the last word in the file's text. */
328 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
329 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
333 /* Enable APP processing of subsequent output.
334 Used before the output from an `asm' statement. */
341 fprintf (asm_out_file, ASM_APP_ON);
346 /* Enable APP processing of subsequent output.
347 Called from varasm.c before most kinds of output. */
354 fprintf (asm_out_file, ASM_APP_OFF);
359 /* Return the number of slots filled in the current
360 delayed branch sequence (we don't count the insn needing the
361 delay slot). Zero if not in a delayed branch sequence. */
365 dbr_sequence_length ()
367 if (final_sequence != 0)
368 return XVECLEN (final_sequence, 0) - 1;
374 /* The next two pages contain routines used to compute the length of an insn
375 and to shorten branches. */
377 /* Arrays for insn lengths, and addresses. The latter is referenced by
378 `insn_current_length'. */
380 static short *insn_lengths;
383 /* Address of insn being processed. Used by `insn_current_length'. */
384 int insn_current_address;
386 /* Indicate the branch shortening hasn't yet been done. */
394 /* Obtain the current length of an insn. If branch shortening has been done,
395 get its actual length. Otherwise, get its maximum length. */
398 get_attr_length (insn)
401 #ifdef HAVE_ATTR_length
407 return insn_lengths[INSN_UID (insn)];
409 switch (GET_CODE (insn))
417 length = insn_default_length (insn);
421 body = PATTERN (insn);
422 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
424 /* This only takes room if jump tables go into the text section. */
425 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
426 length = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
427 * GET_MODE_SIZE (GET_MODE (body)));
429 /* Be pessimistic and assume worst-case alignment. */
430 length += (GET_MODE_SIZE (GET_MODE (body)) - 1);
436 length = insn_default_length (insn);
440 body = PATTERN (insn);
441 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
444 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
445 length = asm_insn_count (insn) * insn_default_length (insn);
446 else if (GET_CODE (body) == SEQUENCE)
447 for (i = 0; i < XVECLEN (body, 0); i++)
448 length += get_attr_length (XVECEXP (body, 0, i));
450 length = insn_default_length (insn);
453 #ifdef ADJUST_INSN_LENGTH
454 ADJUST_INSN_LENGTH (insn, length);
457 #else /* not HAVE_ATTR_length */
459 #endif /* not HAVE_ATTR_length */
462 /* Make a pass over all insns and compute their actual lengths by shortening
463 any branches of variable length if possible. */
465 /* Give a default value for the lowest address in a function. */
467 #ifndef FIRST_INSN_ADDRESS
468 #define FIRST_INSN_ADDRESS 0
472 shorten_branches (first)
475 #ifdef HAVE_ATTR_length
477 int something_changed = 1;
479 char *varying_length;
483 /* Compute maximum UID and allocate arrays. */
484 for (insn = first; insn; insn = NEXT_INSN (insn))
485 if (INSN_UID (insn) > max_uid)
486 max_uid = INSN_UID (insn);
489 insn_lengths = (short *) oballoc (max_uid * sizeof (short));
490 insn_addresses = (int *) oballoc (max_uid * sizeof (int));
491 varying_length = (char *) oballoc (max_uid * sizeof (char));
493 /* Compute initial lengths, addresses, and varying flags for each insn. */
494 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
496 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
498 uid = INSN_UID (insn);
499 insn_addresses[uid] = insn_current_address;
500 insn_lengths[uid] = 0;
501 varying_length[uid] = 0;
503 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
504 || GET_CODE (insn) == CODE_LABEL)
507 body = PATTERN (insn);
508 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
510 /* This only takes room if read-only data goes into the text
512 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
513 int unitsize = GET_MODE_SIZE (GET_MODE (body));
515 insn_lengths[uid] = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
516 * GET_MODE_SIZE (GET_MODE (body)));
518 /* Account for possible alignment. */
520 += unitsize - (insn_current_address & (unitsize - 1));
525 else if (asm_noperands (body) >= 0)
526 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
527 else if (GET_CODE (body) == SEQUENCE)
530 int const_delay_slots;
532 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
534 const_delay_slots = 0;
536 /* Inside a delay slot sequence, we do not do any branch shortening
537 if the shortening could change the number of delay slots
539 for (i = 0; i < XVECLEN (body, 0); i++)
541 rtx inner_insn = XVECEXP (body, 0, i);
542 int inner_uid = INSN_UID (inner_insn);
545 if (asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
546 inner_length = (asm_insn_count (PATTERN (inner_insn))
547 * insn_default_length (inner_insn));
549 inner_length = insn_default_length (inner_insn);
551 insn_lengths[inner_uid] = inner_length;
552 if (const_delay_slots)
554 if ((varying_length[inner_uid]
555 = insn_variable_length_p (inner_insn)) != 0)
556 varying_length[uid] = 1;
557 insn_addresses[inner_uid] = (insn_current_address +
561 varying_length[inner_uid] = 0;
562 insn_lengths[uid] += inner_length;
565 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
567 insn_lengths[uid] = insn_default_length (insn);
568 varying_length[uid] = insn_variable_length_p (insn);
571 /* If needed, do any adjustment. */
572 #ifdef ADJUST_INSN_LENGTH
573 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
577 /* Now loop over all the insns finding varying length insns. For each,
578 get the current insn length. If it has changed, reflect the change.
579 When nothing changes for a full pass, we are done. */
581 while (something_changed)
583 something_changed = 0;
584 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
586 insn = NEXT_INSN (insn))
590 uid = INSN_UID (insn);
591 insn_addresses[uid] = insn_current_address;
592 if (! varying_length[uid])
594 insn_current_address += insn_lengths[uid];
597 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
601 body = PATTERN (insn);
603 for (i = 0; i < XVECLEN (body, 0); i++)
605 rtx inner_insn = XVECEXP (body, 0, i);
606 int inner_uid = INSN_UID (inner_insn);
609 insn_addresses[inner_uid] = insn_current_address;
610 inner_length = insn_current_length (inner_insn);
611 if (inner_length != insn_lengths[inner_uid])
613 insn_lengths[inner_uid] = inner_length;
614 something_changed = 1;
616 insn_current_address += insn_lengths[inner_uid];
617 new_length += inner_length;
622 new_length = insn_current_length (insn);
623 insn_current_address += new_length;
625 if (new_length != insn_lengths[uid])
627 insn_lengths[uid] = new_length;
628 something_changed = 1;
632 #endif /* HAVE_ATTR_length */
635 #ifdef HAVE_ATTR_length
636 /* Given the body of an INSN known to be generated by an ASM statement, return
637 the number of machine instructions likely to be generated for this insn.
638 This is used to compute its length. */
641 asm_insn_count (body)
647 for (template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
649 *template; template++)
650 if (*template == ';' || *template == '\n')
657 /* Output assembler code for the start of a function,
658 and initialize some of the variables in this file
659 for the new function. The label for the function and associated
660 assembler pseudo-ops have already been output in `assemble_start_function'.
662 FIRST is the first insn of the rtl for the function being compiled.
663 FILE is the file to write assembler code to.
664 OPTIMIZE is nonzero if we should eliminate redundant
665 test and compare insns. */
668 final_start_function (first, file, optimize)
675 this_is_asm_operands = 0;
677 #ifdef NON_SAVING_SETJMP
678 /* A function that calls setjmp should save and restore all the
679 call-saved registers on a system where longjmp clobbers them. */
680 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
684 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
685 if (!call_used_regs[i] && !call_fixed_regs[i])
686 regs_ever_live[i] = 1;
690 /* Initial line number is supposed to be output
691 before the function's prologue and label
692 so that the function's address will not appear to be
693 in the last statement of the preceding function. */
694 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
696 if (write_symbols == SDB_DEBUG)
697 /* For sdb, let's not, but say we did.
698 We need to set last_linenum for sdbout_function_begin,
699 but we can't have an actual line number before the .bf symbol.
700 (sdb_begin_function_line is not set,
701 and other compilers don't do it.) */
702 last_linenum = NOTE_LINE_NUMBER (first);
703 #ifdef XCOFF_DEBUGGING_INFO
704 else if (write_symbols == XCOFF_DEBUG)
706 last_linenum = NOTE_LINE_NUMBER (first);
707 xcoffout_output_first_source_line (file, last_linenum);
711 output_source_line (file, first);
714 #ifdef LEAF_REG_REMAP
716 leaf_renumber_regs (first);
719 /* The Sun386i and perhaps other machines don't work right
720 if the profiling code comes after the prologue. */
721 #ifdef PROFILE_BEFORE_PROLOGUE
723 profile_function (file);
724 #endif /* PROFILE_BEFORE_PROLOGUE */
726 #ifdef FUNCTION_PROLOGUE
727 /* First output the function prologue: code to set up the stack frame. */
728 FUNCTION_PROLOGUE (file, get_frame_size ());
731 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
732 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
733 next_block_index = 1;
736 /* If the machine represents the prologue as RTL, the profiling code must
737 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
741 profile_after_prologue (file);
747 profile_after_prologue (file)
750 #ifdef FUNCTION_BLOCK_PROFILER
751 if (profile_block_flag)
753 FUNCTION_BLOCK_PROFILER (file, profile_label_no);
755 #endif /* FUNCTION_BLOCK_PROFILER */
757 #ifndef PROFILE_BEFORE_PROLOGUE
759 profile_function (file);
760 #endif /* not PROFILE_BEFORE_PROLOGUE */
764 profile_function (file)
767 int align = MIN (BIGGEST_ALIGNMENT, INT_TYPE_SIZE);
768 int sval = current_function_returns_struct;
769 int cxt = current_function_needs_context;
772 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
773 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
774 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
778 #ifdef STRUCT_VALUE_INCOMING_REGNUM
780 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
782 #ifdef STRUCT_VALUE_REGNUM
784 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
789 #ifdef STATIC_CHAIN_INCOMING_REGNUM
791 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
793 #ifdef STATIC_CHAIN_REGNUM
795 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
800 FUNCTION_PROFILER (file, profile_label_no);
803 #ifdef STATIC_CHAIN_INCOMING_REGNUM
805 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
807 #ifdef STATIC_CHAIN_REGNUM
809 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
814 #ifdef STRUCT_VALUE_INCOMING_REGNUM
816 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
818 #ifdef STRUCT_VALUE_REGNUM
820 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
825 /* Output assembler code for the end of a function.
826 For clarity, args are same as those of `final_start_function'
827 even though not all of them are needed. */
830 final_end_function (first, file, optimize)
837 fprintf (file, ASM_APP_OFF);
841 #ifdef SDB_DEBUGGING_INFO
842 if (write_symbols == SDB_DEBUG)
843 sdbout_end_function (last_linenum);
846 #ifdef DWARF_DEBUGGING_INFO
847 if (write_symbols == DWARF_DEBUG)
848 dwarfout_end_function ();
851 #ifdef XCOFF_DEBUGGING_INFO
852 if (write_symbols == XCOFF_DEBUG)
853 xcoffout_end_function (file, last_linenum);
856 #ifdef FUNCTION_EPILOGUE
857 /* Finally, output the function epilogue:
858 code to restore the stack frame and return to the caller. */
859 FUNCTION_EPILOGUE (file, get_frame_size ());
862 #ifdef SDB_DEBUGGING_INFO
863 if (write_symbols == SDB_DEBUG)
864 sdbout_end_epilogue ();
867 #ifdef DWARF_DEBUGGING_INFO
868 if (write_symbols == DWARF_DEBUG)
869 dwarfout_end_epilogue ();
872 #ifdef XCOFF_DEBUGGING_INFO
873 if (write_symbols == XCOFF_DEBUG)
874 xcoffout_end_epilogue (file);
877 /* If FUNCTION_EPILOGUE is not defined, then the function body
878 itself contains return instructions wherever needed. */
881 /* Output assembler code for some insns: all or part of a function.
882 For description of args, see `final_start_function', above.
884 PRESCAN is 1 if we are not really outputting,
885 just scanning as if we were outputting.
886 Prescanning deletes and rearranges insns just like ordinary output.
887 PRESCAN is -2 if we are outputting after having prescanned.
888 In this case, don't try to delete or rearrange insns
889 because that has already been done.
890 Prescanning is done only on certain machines. */
893 final (first, file, optimize, prescan)
902 last_ignored_compare = 0;
905 /* Make a map indicating which line numbers appear in this function.
906 When producing SDB debugging info, delete troublesome line number
907 notes from inlined functions in other files as well as duplicate
908 line number notes. */
909 #ifdef SDB_DEBUGGING_INFO
910 if (write_symbols == SDB_DEBUG)
913 for (insn = first; insn; insn = NEXT_INSN (insn))
914 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
916 if ((RTX_INTEGRATED_P (insn)
917 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
919 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
920 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
922 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
923 NOTE_SOURCE_FILE (insn) = 0;
927 if (NOTE_LINE_NUMBER (insn) > max_line)
928 max_line = NOTE_LINE_NUMBER (insn);
934 for (insn = first; insn; insn = NEXT_INSN (insn))
935 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
936 max_line = NOTE_LINE_NUMBER (insn);
939 line_note_exists = (char *) oballoc (max_line + 1);
940 bzero (line_note_exists, max_line + 1);
942 for (insn = first; insn; insn = NEXT_INSN (insn))
943 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
944 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
950 /* Output the insns. */
951 for (insn = NEXT_INSN (first); insn;)
952 insn = final_scan_insn (insn, file, optimize, prescan, 0);
954 /* Do basic-block profiling here
955 if the last insn was a conditional branch. */
956 if (profile_block_flag && new_block)
959 /* Enable the table of basic-block use counts
960 to point at the code it applies to. */
961 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
962 /* Before first insn of this basic block, increment the
963 count of times it was entered. */
964 #ifdef BLOCK_PROFILER
965 BLOCK_PROFILER (file, count_basic_blocks);
968 count_basic_blocks++;
972 /* The final scan for one insn, INSN.
973 Args are same as in `final', except that INSN
974 is the insn being scanned.
975 Value returned is the next insn to be scanned.
977 NOPEEPHOLES is the flag to disallow peephole processing (currently
978 used for within delayed branch sequence output). */
981 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
991 /* Ignore deleted insns. These can occur when we split insns (due to a
992 template of "#") while not optimizing. */
993 if (INSN_DELETED_P (insn))
994 return NEXT_INSN (insn);
996 switch (GET_CODE (insn))
1002 /* Align the beginning of a loop, for higher speed
1003 on certain machines. */
1005 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG && optimize > 0)
1007 #ifdef ASM_OUTPUT_LOOP_ALIGN
1008 rtx next = next_nonnote_insn (insn);
1009 if (next && GET_CODE (next) == CODE_LABEL)
1011 ASM_OUTPUT_LOOP_ALIGN (asm_out_file);
1016 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
1019 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
1021 #ifdef FUNCTION_END_PROLOGUE
1022 FUNCTION_END_PROLOGUE (file);
1024 profile_after_prologue (file);
1028 #ifdef FUNCTION_BEGIN_EPILOGUE
1029 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
1031 FUNCTION_BEGIN_EPILOGUE (file);
1036 if (write_symbols == NO_DEBUG)
1038 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
1040 #ifdef SDB_DEBUGGING_INFO
1041 if (write_symbols == SDB_DEBUG)
1042 sdbout_begin_function (last_linenum);
1044 #ifdef XCOFF_DEBUGGING_INFO
1045 if (write_symbols == XCOFF_DEBUG)
1046 xcoffout_begin_function (file, last_linenum);
1048 #ifdef DWARF_DEBUGGING_INFO
1049 if (write_symbols == DWARF_DEBUG)
1050 dwarfout_begin_function ();
1054 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
1055 break; /* An insn that was "deleted" */
1058 fprintf (file, ASM_APP_OFF);
1061 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
1062 && (debug_info_level == DINFO_LEVEL_NORMAL
1063 || debug_info_level == DINFO_LEVEL_VERBOSE
1064 #ifdef DWARF_DEBUGGING_INFO
1065 || write_symbols == DWARF_DEBUG
1070 /* Beginning of a symbol-block. Assign it a sequence number
1071 and push the number onto the stack PENDING_BLOCKS. */
1073 if (block_depth == max_block_depth)
1075 /* PENDING_BLOCKS is full; make it longer. */
1076 max_block_depth *= 2;
1078 = (int *) xrealloc (pending_blocks,
1079 max_block_depth * sizeof (int));
1081 pending_blocks[block_depth++] = next_block_index;
1083 /* Output debugging info about the symbol-block beginning. */
1085 #ifdef SDB_DEBUGGING_INFO
1086 if (write_symbols == SDB_DEBUG)
1087 sdbout_begin_block (file, last_linenum, next_block_index);
1089 #ifdef XCOFF_DEBUGGING_INFO
1090 if (write_symbols == XCOFF_DEBUG)
1091 xcoffout_begin_block (file, last_linenum, next_block_index);
1093 #ifdef DBX_DEBUGGING_INFO
1094 if (write_symbols == DBX_DEBUG)
1095 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
1097 #ifdef DWARF_DEBUGGING_INFO
1098 if (write_symbols == DWARF_DEBUG && block_depth > 1)
1099 dwarfout_begin_block (next_block_index);
1104 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
1105 && (debug_info_level == DINFO_LEVEL_NORMAL
1106 || debug_info_level == DINFO_LEVEL_VERBOSE
1107 #ifdef DWARF_DEBUGGING_INFO
1108 || write_symbols == DWARF_DEBUG
1113 /* End of a symbol-block. Pop its sequence number off
1114 PENDING_BLOCKS and output debugging info based on that. */
1118 #ifdef XCOFF_DEBUGGING_INFO
1119 if (write_symbols == XCOFF_DEBUG && block_depth >= 0)
1120 xcoffout_end_block (file, last_linenum, pending_blocks[block_depth]);
1122 #ifdef DBX_DEBUGGING_INFO
1123 if (write_symbols == DBX_DEBUG && block_depth >= 0)
1124 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
1125 pending_blocks[block_depth]);
1127 #ifdef SDB_DEBUGGING_INFO
1128 if (write_symbols == SDB_DEBUG && block_depth >= 0)
1129 sdbout_end_block (file, last_linenum);
1131 #ifdef DWARF_DEBUGGING_INFO
1132 if (write_symbols == DWARF_DEBUG && block_depth >= 1)
1133 dwarfout_end_block (pending_blocks[block_depth]);
1136 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
1137 && (debug_info_level == DINFO_LEVEL_NORMAL
1138 || debug_info_level == DINFO_LEVEL_VERBOSE))
1140 #ifdef DWARF_DEBUGGING_INFO
1141 if (write_symbols == DWARF_DEBUG)
1142 dwarfout_label (insn);
1145 else if (NOTE_LINE_NUMBER (insn) > 0)
1146 /* This note is a line-number. */
1150 #if 0 /* This is what we used to do. */
1151 output_source_line (file, insn);
1155 /* If there is anything real after this note,
1156 output it. If another line note follows, omit this one. */
1157 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
1159 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
1161 /* These types of notes can be significant
1162 so make sure the preceding line number stays. */
1163 else if (GET_CODE (note) == NOTE
1164 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
1165 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
1166 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
1168 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
1170 /* Another line note follows; we can delete this note
1171 if no intervening line numbers have notes elsewhere. */
1173 for (num = NOTE_LINE_NUMBER (insn) + 1;
1174 num < NOTE_LINE_NUMBER (note);
1176 if (line_note_exists[num])
1179 if (num >= NOTE_LINE_NUMBER (note))
1185 /* Output this line note
1186 if it is the first or the last line note in a row. */
1188 output_source_line (file, insn);
1193 #ifdef ASM_OUTPUT_ALIGN_CODE
1194 /* Don't litter the assembler output with needless alignments. A
1195 BARRIER will be placed at the end of every function if HAVE_epilogue
1197 if (NEXT_INSN (insn))
1198 ASM_OUTPUT_ALIGN_CODE (file);
1207 #ifdef SDB_DEBUGGING_INFO
1208 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
1209 sdbout_label (insn);
1211 #ifdef DWARF_DEBUGGING_INFO
1212 if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
1213 dwarfout_label (insn);
1217 fprintf (file, ASM_APP_OFF);
1220 if (NEXT_INSN (insn) != 0
1221 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
1223 rtx nextbody = PATTERN (NEXT_INSN (insn));
1225 /* If this label is followed by a jump-table,
1226 make sure we put the label in the read-only section. Also
1227 possibly write the label and jump table together. */
1229 if (GET_CODE (nextbody) == ADDR_VEC
1230 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1232 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1233 readonly_data_section ();
1234 #ifdef READONLY_DATA_SECTION
1235 ASM_OUTPUT_ALIGN (file,
1236 exact_log2 (BIGGEST_ALIGNMENT
1238 #endif /* READONLY_DATA_SECTION */
1239 #else /* JUMP_TABLES_IN_TEXT_SECTION */
1241 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
1242 #ifdef ASM_OUTPUT_CASE_LABEL
1243 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
1246 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1252 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1257 register rtx body = PATTERN (insn);
1258 int insn_code_number;
1262 /* An INSN, JUMP_INSN or CALL_INSN.
1263 First check for special kinds that recog doesn't recognize. */
1265 if (GET_CODE (body) == USE /* These are just declarations */
1266 || GET_CODE (body) == CLOBBER)
1270 /* If there is a REG_CC_SETTER note on this insn, it means that
1271 the setting of the condition code was done in the delay slot
1272 of the insn that branched here. So recover the cc status
1273 from the insn that set it. */
1275 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1278 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
1279 cc_prev_status = cc_status;
1283 /* Detect insns that are really jump-tables
1284 and output them as such. */
1286 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1288 register int vlen, idx;
1295 fprintf (file, ASM_APP_OFF);
1299 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
1300 for (idx = 0; idx < vlen; idx++)
1302 if (GET_CODE (body) == ADDR_VEC)
1304 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
1305 ASM_OUTPUT_ADDR_VEC_ELT
1306 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
1313 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
1314 ASM_OUTPUT_ADDR_DIFF_ELT
1316 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
1317 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
1323 #ifdef ASM_OUTPUT_CASE_END
1324 ASM_OUTPUT_CASE_END (file,
1325 CODE_LABEL_NUMBER (PREV_INSN (insn)),
1334 /* Do basic-block profiling when we reach a new block.
1335 Done here to avoid jump tables. */
1336 if (profile_block_flag && new_block)
1339 /* Enable the table of basic-block use counts
1340 to point at the code it applies to. */
1341 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1342 /* Before first insn of this basic block, increment the
1343 count of times it was entered. */
1344 #ifdef BLOCK_PROFILER
1345 BLOCK_PROFILER (file, count_basic_blocks);
1348 count_basic_blocks++;
1351 if (GET_CODE (body) == ASM_INPUT)
1353 /* There's no telling what that did to the condition codes. */
1359 fprintf (file, ASM_APP_ON);
1362 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
1366 /* Detect `asm' construct with operands. */
1367 if (asm_noperands (body) >= 0)
1369 int noperands = asm_noperands (body);
1373 /* There's no telling what that did to the condition codes. */
1378 /* alloca won't do here, since only return from `final'
1381 ops = (rtx *) xmalloc (noperands * sizeof (rtx));
1385 fprintf (file, ASM_APP_ON);
1389 /* Get out the operand values. */
1390 string = decode_asm_operands (body, ops, NULL_PTR,
1391 NULL_PTR, NULL_PTR);
1392 /* Inhibit aborts on what would otherwise be compiler bugs. */
1393 insn_noperands = noperands;
1394 this_is_asm_operands = insn;
1395 /* Output the insn using them. */
1396 output_asm_insn (string, ops);
1397 this_is_asm_operands = 0;
1403 if (prescan <= 0 && app_on)
1405 fprintf (file, ASM_APP_OFF);
1409 if (GET_CODE (body) == SEQUENCE)
1411 /* A delayed-branch sequence */
1417 final_sequence = body;
1419 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
1420 force the restoration of a comparison that was previously
1421 thought unnecessary. If that happens, cancel this sequence
1422 and cause that insn to be restored. */
1424 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
1425 if (next != XVECEXP (body, 0, 1))
1431 for (i = 1; i < XVECLEN (body, 0); i++)
1432 final_scan_insn (XVECEXP (body, 0, i), file, 0, prescan, 1);
1433 #ifdef DBR_OUTPUT_SEQEND
1434 DBR_OUTPUT_SEQEND (file);
1438 /* If the insn requiring the delay slot was a CALL_INSN, the
1439 insns in the delay slot are actually executed before the
1440 called function. Hence we don't preserve any CC-setting
1441 actions in these insns and the CC must be marked as being
1442 clobbered by the function. */
1443 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
1446 /* Following a conditional branch sequence, we have a new basic
1448 if (profile_block_flag)
1450 rtx insn = XVECEXP (body, 0, 0);
1451 rtx body = PATTERN (insn);
1453 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1454 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1455 || (GET_CODE (insn) == JUMP_INSN
1456 && GET_CODE (body) == PARALLEL
1457 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1458 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
1464 /* We have a real machine instruction as rtl. */
1466 body = PATTERN (insn);
1469 /* Check for redundant test and compare instructions
1470 (when the condition codes are already set up as desired).
1471 This is done only when optimizing; if not optimizing,
1472 it should be possible for the user to alter a variable
1473 with the debugger in between statements
1474 and the next statement should reexamine the variable
1475 to compute the condition codes. */
1478 && GET_CODE (body) == SET
1479 && GET_CODE (SET_DEST (body)) == CC0
1480 && insn != last_ignored_compare)
1482 if (GET_CODE (SET_SRC (body)) == SUBREG)
1483 SET_SRC (body) = alter_subreg (SET_SRC (body));
1484 else if (GET_CODE (SET_SRC (body)) == COMPARE)
1486 if (GET_CODE (XEXP (SET_SRC (body), 0)) == SUBREG)
1487 XEXP (SET_SRC (body), 0)
1488 = alter_subreg (XEXP (SET_SRC (body), 0));
1489 if (GET_CODE (XEXP (SET_SRC (body), 1)) == SUBREG)
1490 XEXP (SET_SRC (body), 1)
1491 = alter_subreg (XEXP (SET_SRC (body), 1));
1493 if ((cc_status.value1 != 0
1494 && rtx_equal_p (SET_SRC (body), cc_status.value1))
1495 || (cc_status.value2 != 0
1496 && rtx_equal_p (SET_SRC (body), cc_status.value2)))
1498 /* Don't delete insn if it has an addressing side-effect. */
1499 if (! FIND_REG_INC_NOTE (insn, 0)
1500 /* or if anything in it is volatile. */
1501 && ! volatile_refs_p (PATTERN (insn)))
1503 /* We don't really delete the insn; just ignore it. */
1504 last_ignored_compare = insn;
1511 /* Following a conditional branch, we have a new basic block.
1512 But if we are inside a sequence, the new block starts after the
1513 last insn of the sequence. */
1514 if (profile_block_flag && final_sequence == 0
1515 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1516 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1517 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
1518 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1519 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
1523 /* Don't bother outputting obvious no-ops, even without -O.
1524 This optimization is fast and doesn't interfere with debugging.
1525 Don't do this if the insn is in a delay slot, since this
1526 will cause an improper number of delay insns to be written. */
1527 if (final_sequence == 0
1529 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
1530 && GET_CODE (SET_SRC (body)) == REG
1531 && GET_CODE (SET_DEST (body)) == REG
1532 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
1537 /* If this is a conditional branch, maybe modify it
1538 if the cc's are in a nonstandard state
1539 so that it accomplishes the same thing that it would
1540 do straightforwardly if the cc's were set up normally. */
1542 if (cc_status.flags != 0
1543 && GET_CODE (insn) == JUMP_INSN
1544 && GET_CODE (body) == SET
1545 && SET_DEST (body) == pc_rtx
1546 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
1547 /* This is done during prescan; it is not done again
1548 in final scan when prescan has been done. */
1551 /* This function may alter the contents of its argument
1552 and clear some of the cc_status.flags bits.
1553 It may also return 1 meaning condition now always true
1554 or -1 meaning condition now always false
1555 or 2 meaning condition nontrivial but altered. */
1556 register int result = alter_cond (XEXP (SET_SRC (body), 0));
1557 /* If condition now has fixed value, replace the IF_THEN_ELSE
1558 with its then-operand or its else-operand. */
1560 SET_SRC (body) = XEXP (SET_SRC (body), 1);
1562 SET_SRC (body) = XEXP (SET_SRC (body), 2);
1564 /* The jump is now either unconditional or a no-op.
1565 If it has become a no-op, don't try to output it.
1566 (It would not be recognized.) */
1567 if (SET_SRC (body) == pc_rtx)
1569 PUT_CODE (insn, NOTE);
1570 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1571 NOTE_SOURCE_FILE (insn) = 0;
1574 else if (GET_CODE (SET_SRC (body)) == RETURN)
1575 /* Replace (set (pc) (return)) with (return). */
1576 PATTERN (insn) = body = SET_SRC (body);
1578 /* Rerecognize the instruction if it has changed. */
1580 INSN_CODE (insn) = -1;
1583 /* Make same adjustments to instructions that examine the
1584 condition codes without jumping (if this machine has them). */
1586 if (cc_status.flags != 0
1587 && GET_CODE (body) == SET)
1589 switch (GET_CODE (SET_SRC (body)))
1602 register int result;
1603 if (XEXP (SET_SRC (body), 0) != cc0_rtx)
1605 result = alter_cond (SET_SRC (body));
1607 validate_change (insn, &SET_SRC (body), const_true_rtx, 0);
1608 else if (result == -1)
1609 validate_change (insn, &SET_SRC (body), const0_rtx, 0);
1610 else if (result == 2)
1611 INSN_CODE (insn) = -1;
1617 /* Do machine-specific peephole optimizations if desired. */
1619 if (optimize && !flag_no_peephole && !nopeepholes)
1621 rtx next = peephole (insn);
1622 /* When peepholing, if there were notes within the peephole,
1623 emit them before the peephole. */
1624 if (next != 0 && next != NEXT_INSN (insn))
1626 rtx prev = PREV_INSN (insn);
1629 for (note = NEXT_INSN (insn); note != next;
1630 note = NEXT_INSN (note))
1631 final_scan_insn (note, file, optimize, prescan, nopeepholes);
1633 /* In case this is prescan, put the notes
1634 in proper position for later rescan. */
1635 note = NEXT_INSN (insn);
1636 PREV_INSN (note) = prev;
1637 NEXT_INSN (prev) = note;
1638 NEXT_INSN (PREV_INSN (next)) = insn;
1639 PREV_INSN (insn) = PREV_INSN (next);
1640 NEXT_INSN (insn) = next;
1641 PREV_INSN (next) = insn;
1644 /* PEEPHOLE might have changed this. */
1645 body = PATTERN (insn);
1648 /* Try to recognize the instruction.
1649 If successful, verify that the operands satisfy the
1650 constraints for the instruction. Crash if they don't,
1651 since `reload' should have changed them so that they do. */
1653 insn_code_number = recog_memoized (insn);
1654 insn_extract (insn);
1655 for (i = 0; i < insn_n_operands[insn_code_number]; i++)
1657 if (GET_CODE (recog_operand[i]) == SUBREG)
1658 recog_operand[i] = alter_subreg (recog_operand[i]);
1661 #ifdef REGISTER_CONSTRAINTS
1662 if (! constrain_operands (insn_code_number, 1))
1663 fatal_insn_not_found (insn);
1666 /* Some target machines need to prescan each insn before
1669 #ifdef FINAL_PRESCAN_INSN
1670 FINAL_PRESCAN_INSN (insn, recog_operand,
1671 insn_n_operands[insn_code_number]);
1675 cc_prev_status = cc_status;
1677 /* Update `cc_status' for this instruction.
1678 The instruction's output routine may change it further.
1679 If the output routine for a jump insn needs to depend
1680 on the cc status, it should look at cc_prev_status. */
1682 NOTICE_UPDATE_CC (body, insn);
1687 /* If the proper template needs to be chosen by some C code,
1688 run that code and get the real template. */
1690 template = insn_template[insn_code_number];
1693 template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
1695 /* If the C code returns 0, it means that it is a jump insn
1696 which follows a deleted test insn, and that test insn
1697 needs to be reinserted. */
1700 if (prev_nonnote_insn (insn) != last_ignored_compare)
1703 return prev_nonnote_insn (insn);
1707 /* If the template is the string "#", it means that this insn must
1709 if (template[0] == '#' && template[1] == '\0')
1711 rtx new = try_split (body, insn, 0);
1713 /* If we didn't split the insn, go away. */
1714 if (new == insn && PATTERN (new) == body)
1724 /* Output assembler code from the template. */
1726 output_asm_insn (template, recog_operand);
1729 /* It's not at all clear why we did this and doing so interferes
1730 with tests we'd like to do to use REG_WAS_0 notes, so let's try
1733 /* Mark this insn as having been output. */
1734 INSN_DELETED_P (insn) = 1;
1740 return NEXT_INSN (insn);
1743 /* Output debugging info to the assembler file FILE
1744 based on the NOTE-insn INSN, assumed to be a line number. */
1747 output_source_line (file, insn)
1751 char ltext_label_name[100];
1752 register char *filename = NOTE_SOURCE_FILE (insn);
1754 last_linenum = NOTE_LINE_NUMBER (insn);
1756 if (write_symbols != NO_DEBUG)
1758 #ifdef SDB_DEBUGGING_INFO
1759 if (write_symbols == SDB_DEBUG
1760 #if 0 /* People like having line numbers even in wrong file! */
1761 /* COFF can't handle multiple source files--lose, lose. */
1762 && !strcmp (filename, main_input_filename)
1764 /* COFF relative line numbers must be positive. */
1765 && last_linenum > sdb_begin_function_line)
1767 #ifdef ASM_OUTPUT_SOURCE_LINE
1768 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
1770 fprintf (file, "\t.ln\t%d\n",
1771 ((sdb_begin_function_line > -1)
1772 ? last_linenum - sdb_begin_function_line : 1));
1777 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1778 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1779 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
1780 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
1782 #ifdef DWARF_DEBUGGING_INFO
1783 if (write_symbols == DWARF_DEBUG)
1784 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
1789 /* If X is a SUBREG, replace it with a REG or a MEM,
1790 based on the thing it is a subreg of. */
1796 register rtx y = SUBREG_REG (x);
1797 if (GET_CODE (y) == SUBREG)
1798 y = alter_subreg (y);
1800 if (GET_CODE (y) == REG)
1802 /* If the containing reg really gets a hard reg, so do we. */
1804 REGNO (x) = REGNO (y) + SUBREG_WORD (x);
1806 else if (GET_CODE (y) == MEM)
1808 register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
1809 #if BYTES_BIG_ENDIAN
1810 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
1811 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
1814 MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
1815 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
1821 /* Do alter_subreg on all the SUBREGs contained in X. */
1824 walk_alter_subreg (x)
1827 switch (GET_CODE (x))
1831 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
1832 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
1836 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
1840 return alter_subreg (x);
1848 /* Given BODY, the body of a jump instruction, alter the jump condition
1849 as required by the bits that are set in cc_status.flags.
1850 Not all of the bits there can be handled at this level in all cases.
1852 The value is normally 0.
1853 1 means that the condition has become always true.
1854 -1 means that the condition has become always false.
1855 2 means that COND has been altered. */
1863 if (cc_status.flags & CC_REVERSED)
1866 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
1869 if (cc_status.flags & CC_INVERTED)
1872 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
1875 if (cc_status.flags & CC_NOT_POSITIVE)
1876 switch (GET_CODE (cond))
1881 /* Jump becomes unconditional. */
1887 /* Jump becomes no-op. */
1891 PUT_CODE (cond, EQ);
1896 PUT_CODE (cond, NE);
1901 if (cc_status.flags & CC_NOT_NEGATIVE)
1902 switch (GET_CODE (cond))
1906 /* Jump becomes unconditional. */
1911 /* Jump becomes no-op. */
1916 PUT_CODE (cond, EQ);
1922 PUT_CODE (cond, NE);
1927 if (cc_status.flags & CC_NO_OVERFLOW)
1928 switch (GET_CODE (cond))
1931 /* Jump becomes unconditional. */
1935 PUT_CODE (cond, EQ);
1940 PUT_CODE (cond, NE);
1945 /* Jump becomes no-op. */
1949 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
1950 switch (GET_CODE (cond))
1963 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
1968 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
1973 if (cc_status.flags & CC_NOT_SIGNED)
1974 /* The flags are valid if signed condition operators are converted
1976 switch (GET_CODE (cond))
1979 PUT_CODE (cond, LEU);
1984 PUT_CODE (cond, LTU);
1989 PUT_CODE (cond, GTU);
1994 PUT_CODE (cond, GEU);
2003 /* Report inconsistency between the assembler template and the operands.
2004 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
2007 output_operand_lossage (str)
2010 if (this_is_asm_operands)
2011 error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
2016 /* Output of assembler code from a template, and its subroutines. */
2018 /* Output text from TEMPLATE to the assembler output file,
2019 obeying %-directions to substitute operands taken from
2020 the vector OPERANDS.
2022 %N (for N a digit) means print operand N in usual manner.
2023 %lN means require operand N to be a CODE_LABEL or LABEL_REF
2024 and print the label name with no punctuation.
2025 %cN means require operand N to be a constant
2026 and print the constant expression with no punctuation.
2027 %aN means expect operand N to be a memory address
2028 (not a memory reference!) and print a reference
2030 %nN means expect operand N to be a constant
2031 and print a constant expression for minus the value
2032 of the operand, with no other punctuation. */
2035 output_asm_insn (template, operands)
2042 /* An insn may return a null string template
2043 in a case where no assembler code is needed. */
2048 putc ('\t', asm_out_file);
2050 #ifdef ASM_OUTPUT_OPCODE
2051 ASM_OUTPUT_OPCODE (asm_out_file, p);
2056 #ifdef ASM_OUTPUT_OPCODE
2059 putc (c, asm_out_file);
2060 while ((c = *p) == '\t')
2062 putc (c, asm_out_file);
2065 ASM_OUTPUT_OPCODE (asm_out_file, p);
2070 putc (c, asm_out_file);
2073 /* %% outputs a single %. */
2077 putc (c, asm_out_file);
2079 /* %= outputs a number which is unique to each insn in the entire
2080 compilation. This is useful for making local labels that are
2081 referred to more than once in a given insn. */
2085 fprintf (asm_out_file, "%d", insn_counter);
2087 /* % followed by a letter and some digits
2088 outputs an operand in a special way depending on the letter.
2089 Letters `acln' are implemented directly.
2090 Other letters are passed to `output_operand' so that
2091 the PRINT_OPERAND macro can define them. */
2092 else if ((*p >= 'a' && *p <= 'z')
2093 || (*p >= 'A' && *p <= 'Z'))
2098 if (! (*p >= '0' && *p <= '9'))
2099 output_operand_lossage ("operand number missing after %-letter");
2100 else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2101 output_operand_lossage ("operand number out of range");
2102 else if (letter == 'l')
2103 output_asm_label (operands[c]);
2104 else if (letter == 'a')
2105 output_address (operands[c]);
2106 else if (letter == 'c')
2108 if (CONSTANT_ADDRESS_P (operands[c]))
2109 output_addr_const (asm_out_file, operands[c]);
2111 output_operand (operands[c], 'c');
2113 else if (letter == 'n')
2115 if (GET_CODE (operands[c]) == CONST_INT)
2116 fprintf (asm_out_file,
2117 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2122 - INTVAL (operands[c]));
2125 putc ('-', asm_out_file);
2126 output_addr_const (asm_out_file, operands[c]);
2130 output_operand (operands[c], letter);
2132 while ((c = *p) >= '0' && c <= '9') p++;
2134 /* % followed by a digit outputs an operand the default way. */
2135 else if (*p >= '0' && *p <= '9')
2138 if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2139 output_operand_lossage ("operand number out of range");
2141 output_operand (operands[c], 0);
2142 while ((c = *p) >= '0' && c <= '9') p++;
2144 /* % followed by punctuation: output something for that
2145 punctuation character alone, with no operand.
2146 The PRINT_OPERAND macro decides what is actually done. */
2147 #ifdef PRINT_OPERAND_PUNCT_VALID_P
2148 else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
2149 output_operand (NULL_RTX, *p++);
2152 output_operand_lossage ("invalid %%-code");
2156 if (flag_print_asm_name)
2158 /* Annotate the assembly with a comment describing the pattern and
2159 alternative used. */
2162 register int num = INSN_CODE (debug_insn);
2163 fprintf (asm_out_file, " %s %d %s",
2164 ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
2165 if (insn_n_alternatives[num] > 1)
2166 fprintf (asm_out_file, "/%d", which_alternative + 1);
2168 /* Clear this so only the first assembler insn
2169 of any rtl insn will get the special comment for -dp. */
2174 putc ('\n', asm_out_file);
2177 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
2180 output_asm_label (x)
2185 if (GET_CODE (x) == LABEL_REF)
2186 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2187 else if (GET_CODE (x) == CODE_LABEL)
2188 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2190 output_operand_lossage ("`%l' operand isn't a label");
2192 assemble_name (asm_out_file, buf);
2195 /* Print operand X using machine-dependent assembler syntax.
2196 The macro PRINT_OPERAND is defined just to control this function.
2197 CODE is a non-digit that preceded the operand-number in the % spec,
2198 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
2199 between the % and the digits.
2200 When CODE is a non-letter, X is 0.
2202 The meanings of the letters are machine-dependent and controlled
2203 by PRINT_OPERAND. */
2206 output_operand (x, code)
2210 if (x && GET_CODE (x) == SUBREG)
2211 x = alter_subreg (x);
2213 /* If X is a pseudo-register, abort now rather than writing trash to the
2216 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2219 PRINT_OPERAND (asm_out_file, x, code);
2222 /* Print a memory reference operand for address X
2223 using machine-dependent assembler syntax.
2224 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
2230 walk_alter_subreg (x);
2231 PRINT_OPERAND_ADDRESS (asm_out_file, x);
2234 /* Print an integer constant expression in assembler syntax.
2235 Addition and subtraction are the only arithmetic
2236 that may appear in these expressions. */
2239 output_addr_const (file, x)
2246 switch (GET_CODE (x))
2256 assemble_name (file, XSTR (x, 0));
2260 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2261 assemble_name (file, buf);
2265 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2266 assemble_name (file, buf);
2271 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2280 /* This used to output parentheses around the expression,
2281 but that does not work on the 386 (either ATT or BSD assembler). */
2282 output_addr_const (file, XEXP (x, 0));
2286 if (GET_MODE (x) == VOIDmode)
2288 /* We can use %d if the number is one word and positive. */
2289 if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
2291 #if HOST_BITS_PER_WIDE_INT == 64
2292 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2298 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2304 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2307 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2312 CONST_DOUBLE_LOW (x));
2315 /* We can't handle floating point constants;
2316 PRINT_OPERAND must handle them. */
2317 output_operand_lossage ("floating constant misused");
2321 /* Some assemblers need integer constants to appear last (eg masm). */
2322 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2324 output_addr_const (file, XEXP (x, 1));
2325 if (INTVAL (XEXP (x, 0)) >= 0)
2326 fprintf (file, "+");
2327 output_addr_const (file, XEXP (x, 0));
2331 output_addr_const (file, XEXP (x, 0));
2332 if (INTVAL (XEXP (x, 1)) >= 0)
2333 fprintf (file, "+");
2334 output_addr_const (file, XEXP (x, 1));
2339 /* Avoid outputting things like x-x or x+5-x,
2340 since some assemblers can't handle that. */
2341 x = simplify_subtraction (x);
2342 if (GET_CODE (x) != MINUS)
2345 output_addr_const (file, XEXP (x, 0));
2346 fprintf (file, "-");
2347 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2348 && INTVAL (XEXP (x, 1)) < 0)
2350 fprintf (file, ASM_OPEN_PAREN);
2351 output_addr_const (file, XEXP (x, 1));
2352 fprintf (file, ASM_CLOSE_PAREN);
2355 output_addr_const (file, XEXP (x, 1));
2360 output_addr_const (file, XEXP (x, 0));
2364 output_operand_lossage ("invalid expression as operand");
2368 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
2369 %R prints the value of REGISTER_PREFIX.
2370 %L prints the value of LOCAL_LABEL_PREFIX.
2371 %U prints the value of USER_LABEL_PREFIX.
2372 %I prints the value of IMMEDIATE_PREFIX.
2373 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
2374 Also supported are %d, %x, %s, %e, %f, %g and %%. */
2377 asm_fprintf (va_alist)
2387 file = va_arg (argptr, FILE *);
2388 p = va_arg (argptr, char *);
2397 while ((c >= '0' && c <= '9') || c == '.')
2405 fprintf (file, "%%");
2408 case 'd': case 'i': case 'u':
2409 case 'x': case 'p': case 'X':
2413 fprintf (file, buf, va_arg (argptr, int));
2421 fprintf (file, buf, va_arg (argptr, double));
2427 fprintf (file, buf, va_arg (argptr, char *));
2431 #ifdef ASM_OUTPUT_OPCODE
2432 ASM_OUTPUT_OPCODE (asm_out_file, p);
2437 #ifdef REGISTER_PREFIX
2438 fprintf (file, "%s", REGISTER_PREFIX);
2443 #ifdef IMMEDIATE_PREFIX
2444 fprintf (file, "%s", IMMEDIATE_PREFIX);
2449 #ifdef LOCAL_LABEL_PREFIX
2450 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
2455 #ifdef USER_LABEL_PREFIX
2456 fprintf (file, "%s", USER_LABEL_PREFIX);
2470 /* Split up a CONST_DOUBLE or integer constant rtx
2471 into two rtx's for single words,
2472 storing in *FIRST the word that comes first in memory in the target
2473 and in *SECOND the other. */
2476 split_double (value, first, second)
2478 rtx *first, *second;
2480 if (GET_CODE (value) == CONST_INT)
2482 /* The rule for using CONST_INT for a wider mode
2483 is that we regard the value as signed.
2484 So sign-extend it. */
2485 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
2486 #if WORDS_BIG_ENDIAN
2494 else if (GET_CODE (value) != CONST_DOUBLE)
2496 #if WORDS_BIG_ENDIAN
2497 *first = const0_rtx;
2501 *second = const0_rtx;
2504 else if (GET_MODE (value) == VOIDmode
2505 /* This is the old way we did CONST_DOUBLE integers. */
2506 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
2508 /* In an integer, the words are defined as most and least significant.
2509 So order them by the target's convention. */
2510 #if WORDS_BIG_ENDIAN
2511 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2512 *second = GEN_INT (CONST_DOUBLE_LOW (value));
2514 *first = GEN_INT (CONST_DOUBLE_LOW (value));
2515 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
2520 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
2521 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
2522 && ! flag_pretend_float)
2525 #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
2526 /* Host and target agree => no need to swap. */
2527 *first = GEN_INT (CONST_DOUBLE_LOW (value));
2528 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
2530 *second = GEN_INT (CONST_DOUBLE_LOW (value));
2531 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2536 /* Return nonzero if this function has no function calls. */
2543 if (profile_flag || profile_block_flag)
2546 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2548 if (GET_CODE (insn) == CALL_INSN)
2550 if (GET_CODE (insn) == INSN
2551 && GET_CODE (PATTERN (insn)) == SEQUENCE
2552 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN)
2555 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
2557 if (GET_CODE (XEXP (insn, 0)) == CALL_INSN)
2559 if (GET_CODE (XEXP (insn, 0)) == INSN
2560 && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
2561 && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN)
2568 /* On some machines, a function with no call insns
2569 can run faster if it doesn't create its own register window.
2570 When output, the leaf function should use only the "output"
2571 registers. Ordinarily, the function would be compiled to use
2572 the "input" registers to find its arguments; it is a candidate
2573 for leaf treatment if it uses only the "input" registers.
2574 Leaf function treatment means renumbering so the function
2575 uses the "output" registers instead. */
2577 #ifdef LEAF_REGISTERS
2579 static char permitted_reg_in_leaf_functions[] = LEAF_REGISTERS;
2581 /* Return 1 if this function uses only the registers that can be
2582 safely renumbered. */
2585 only_leaf_regs_used ()
2589 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2591 if ((regs_ever_live[i] || global_regs[i])
2592 && ! permitted_reg_in_leaf_functions[i])
2598 /* Scan all instructions and renumber all registers into those
2599 available in leaf functions. */
2602 leaf_renumber_regs (first)
2607 /* Renumber only the actual patterns.
2608 The reg-notes can contain frame pointer refs,
2609 and renumbering them could crash, and should not be needed. */
2610 for (insn = first; insn; insn = NEXT_INSN (insn))
2611 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
2612 leaf_renumber_regs_insn (PATTERN (insn));
2613 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
2614 if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
2615 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
2618 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
2619 available in leaf functions. */
2622 leaf_renumber_regs_insn (in_rtx)
2623 register rtx in_rtx;
2626 register char *format_ptr;
2631 /* Renumber all input-registers into output-registers.
2632 renumbered_regs would be 1 for an output-register;
2635 if (GET_CODE (in_rtx) == REG)
2639 /* Don't renumber the same reg twice. */
2643 newreg = REGNO (in_rtx);
2644 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
2645 to reach here as part of a REG_NOTE. */
2646 if (newreg >= FIRST_PSEUDO_REGISTER)
2651 newreg = LEAF_REG_REMAP (newreg);
2654 regs_ever_live[REGNO (in_rtx)] = 0;
2655 regs_ever_live[newreg] = 1;
2656 REGNO (in_rtx) = newreg;
2660 if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
2662 /* Inside a SEQUENCE, we find insns.
2663 Renumber just the patterns of these insns,
2664 just as we do for the top-level insns. */
2665 leaf_renumber_regs_insn (PATTERN (in_rtx));
2669 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
2671 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
2672 switch (*format_ptr++)
2675 leaf_renumber_regs_insn (XEXP (in_rtx, i));
2679 if (NULL != XVEC (in_rtx, i))
2681 for (j = 0; j < XVECLEN (in_rtx, i); j++)
2682 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));