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. */
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "insn-attr.h"
54 #include "insn-codes.h"
56 #include "conditions.h"
60 #include "hard-reg-set.h"
63 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist. */
64 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
65 #if defined (USG) || defined (NO_STAB_H)
66 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
68 #include <stab.h> /* On BSD, use the system's stab.h. */
70 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
72 #ifdef XCOFF_DEBUGGING_INFO
76 /* .stabd code for line number. */
81 /* .stabs code for included file name. */
87 #define INT_TYPE_SIZE BITS_PER_WORD
90 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
91 null default for it to save conditionalization later. */
92 #ifndef CC_STATUS_INIT
93 #define CC_STATUS_INIT
96 /* How to start an assembler comment. */
97 #ifndef ASM_COMMENT_START
98 #define ASM_COMMENT_START ";#"
102 void output_asm_insn ();
104 static int alter_cond ();
105 void output_asm_label ();
106 static void output_operand ();
107 void output_address ();
108 void output_addr_const ();
109 static void output_source_line ();
110 rtx final_scan_insn ();
111 void profile_function ();
112 static void profile_after_prologue ();
114 #ifdef HAVE_ATTR_length
115 static int asm_insn_count ();
118 /* Nonzero means this function is a leaf function, with no function calls.
119 This variable exists to be examined in FUNCTION_PROLOGUE
120 and FUNCTION_EPILOGUE. Always zero, unless set by some action. */
123 int leaf_function_p ();
125 #ifdef LEAF_REGISTERS
126 int only_leaf_regs_used ();
127 static void leaf_renumber_regs ();
128 void leaf_renumber_regs_insn ();
131 /* Last insn processed by final_scan_insn. */
132 static rtx debug_insn = 0;
134 /* Line number of last NOTE. */
135 static int last_linenum;
137 /* Number of basic blocks seen so far;
138 used if profile_block_flag is set. */
139 static int count_basic_blocks;
141 /* Nonzero while outputting an `asm' with operands.
142 This means that inconsistencies are the user's fault, so don't abort.
143 The precise value is the insn being output, to pass to error_for_asm. */
144 static rtx this_is_asm_operands;
146 /* Number of operands of this insn, for an `asm' with operands. */
147 static int insn_noperands;
149 /* Compare optimization flag. */
151 static rtx last_ignored_compare = 0;
153 /* Flag indicating this insn is the start of a new basic block. */
155 static int new_block = 1;
157 /* All the symbol-blocks (levels of scoping) in the compilation
158 are assigned sequence numbers in order of appearance of the
159 beginnings of the symbol-blocks. Both final and dbxout do this,
160 and assume that they will both give the same number to each block.
161 Final uses these sequence numbers to generate assembler label names
162 LBBnnn and LBEnnn for the beginning and end of the symbol-block.
163 Dbxout uses the sequence numbers to generate references to the same labels
164 from the dbx debugging information.
166 Sdb records this level at the beginning of each function,
167 in order to find the current level when recursing down declarations.
168 It outputs the block beginning and endings
169 at the point in the asm file where the blocks would begin and end. */
171 int next_block_index;
173 /* Assign a unique number to each insn that is output.
174 This can be used to generate unique local labels. */
176 static int insn_counter = 0;
179 /* This variable contains machine-dependent flags (defined in tm.h)
180 set and examined by output routines
181 that describe how to interpret the condition codes properly. */
185 /* During output of an insn, this contains a copy of cc_status
186 from before the insn. */
188 CC_STATUS cc_prev_status;
191 /* Indexed by hardware reg number, is 1 if that register is ever
192 used in the current function.
194 In life_analysis, or in stupid_life_analysis, this is set
195 up to record the hard regs used explicitly. Reload adds
196 in the hard regs used for holding pseudo regs. Final uses
197 it to generate the code in the function prologue and epilogue
198 to save and restore registers as needed. */
200 char regs_ever_live[FIRST_PSEUDO_REGISTER];
202 /* Nonzero means current function must be given a frame pointer.
203 Set in stmt.c if anything is allocated on the stack there.
204 Set in reload1.c if anything is allocated on the stack there. */
206 int frame_pointer_needed;
208 /* Assign unique numbers to labels generated for profiling. */
210 int profile_label_no;
212 /* Length so far allocated in PENDING_BLOCKS. */
214 static int max_block_depth;
216 /* Stack of sequence numbers of symbol-blocks of which we have seen the
217 beginning but not yet the end. Sequence numbers are assigned at
218 the beginning; this stack allows us to find the sequence number
219 of a block that is ending. */
221 static int *pending_blocks;
223 /* Number of elements currently in use in PENDING_BLOCKS. */
225 static int block_depth;
227 /* Nonzero if have enabled APP processing of our assembler output. */
231 /* If we are outputting an insn sequence, this contains the sequence rtx.
236 /* Indexed by line number, nonzero if there is a note for that line. */
238 static char *line_note_exists;
240 /* Initialize data in final at the beginning of a compilation. */
243 init_final (filename)
246 next_block_index = 2;
248 max_block_depth = 20;
249 pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
253 /* Called at end of source file,
254 to output the block-profiling table for this entire compilation. */
262 if (profile_block_flag)
268 /* Output the main header, of 6 words:
269 0: 1 if this file's initialized, else 0.
270 1: address of file name.
271 2: address of table of counts.
272 4: number of counts in the table.
273 5: always 0, for compatibility with Sun.
274 6: extra word added by GNU: address of address table
275 which contains addresses of basic blocks,
276 in parallel with the table of counts. */
277 ASM_OUTPUT_ALIGN (asm_out_file,
278 exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
280 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
281 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
282 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
283 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
284 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
285 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
286 assemble_integer (GEN_INT (count_basic_blocks), UNITS_PER_WORD, 1);
287 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
288 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
289 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
291 /* Output the file name. */
292 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
294 int len = strlen (filename);
295 char *data_file = (char *) alloca (len + 3);
296 strcpy (data_file, filename);
297 strip_off_ending (data_file, len);
298 strcat (data_file, ".d");
299 assemble_string (data_file, strlen (data_file) + 1);
302 /* Realign data section. */
303 ASM_OUTPUT_ALIGN (asm_out_file,
304 exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
306 /* Make space for the table of counts. */
307 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
308 assemble_zeros (INT_TYPE_SIZE / BITS_PER_UNIT * count_basic_blocks);
310 /* Output the table of addresses. */
311 readonly_data_section ();
312 /* Realign in new section */
313 ASM_OUTPUT_ALIGN (asm_out_file,
314 floor_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
315 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
316 for (i = 0; i < count_basic_blocks; i++)
319 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
320 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
324 /* End with the address of the table of addresses,
325 so we can find it easily, as the last word in the file's text. */
326 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
327 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
331 /* Enable APP processing of subsequent output.
332 Used before the output from an `asm' statement. */
339 fprintf (asm_out_file, ASM_APP_ON);
344 /* Enable APP processing of subsequent output.
345 Called from varasm.c before most kinds of output. */
352 fprintf (asm_out_file, ASM_APP_OFF);
357 /* Return the number of slots filled in the current
358 delayed branch sequence (we don't count the insn needing the
359 delay slot). Zero if not in a delayed branch sequence. */
363 dbr_sequence_length ()
365 if (final_sequence != 0)
366 return XVECLEN (final_sequence, 0) - 1;
372 /* The next two pages contain routines used to compute the length of an insn
373 and to shorten branches. */
375 /* Arrays for insn lengths, and addresses. The latter is referenced by
376 `insn_current_length'. */
378 static short *insn_lengths;
381 /* Address of insn being processed. Used by `insn_current_length'. */
382 int insn_current_address;
384 /* Indicate the branch shortening hasn't yet been done. */
392 /* Obtain the current length of an insn. If branch shortening has been done,
393 get its actual length. Otherwise, get its maximum length. */
396 get_attr_length (insn)
399 #ifdef HAVE_ATTR_length
405 return insn_lengths[INSN_UID (insn)];
407 switch (GET_CODE (insn))
415 length = insn_default_length (insn);
419 body = PATTERN (insn);
420 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
422 /* This only takes room if jump tables go into the text section. */
423 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
424 length = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
425 * GET_MODE_SIZE (GET_MODE (body)));
427 /* Be pessimistic and assume worst-case alignment. */
428 length += (GET_MODE_SIZE (GET_MODE (body)) - 1);
434 length = insn_default_length (insn);
438 body = PATTERN (insn);
439 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
442 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
443 length = asm_insn_count (insn) * insn_default_length (insn);
444 else if (GET_CODE (body) == SEQUENCE)
445 for (i = 0; i < XVECLEN (body, 0); i++)
446 length += get_attr_length (XVECEXP (body, 0, i));
448 length = insn_default_length (insn);
451 #ifdef ADJUST_INSN_LENGTH
452 ADJUST_INSN_LENGTH (insn, length);
455 #else /* not HAVE_ATTR_length */
457 #endif /* not HAVE_ATTR_length */
460 /* Make a pass over all insns and compute their actual lengths by shortening
461 any branches of variable length if possible. */
463 /* Give a default value for the lowest address in a function. */
465 #ifndef FIRST_INSN_ADDRESS
466 #define FIRST_INSN_ADDRESS 0
470 shorten_branches (first)
473 #ifdef HAVE_ATTR_length
475 int something_changed = 1;
477 char *varying_length;
481 /* Compute maximum UID and allocate arrays. */
482 for (insn = first; insn; insn = NEXT_INSN (insn))
483 if (INSN_UID (insn) > max_uid)
484 max_uid = INSN_UID (insn);
487 insn_lengths = (short *) oballoc (max_uid * sizeof (short));
488 insn_addresses = (int *) oballoc (max_uid * sizeof (int));
489 varying_length = (char *) oballoc (max_uid * sizeof (char));
491 /* Compute initial lengths, addresses, and varying flags for each insn. */
492 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
494 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
496 uid = INSN_UID (insn);
497 insn_addresses[uid] = insn_current_address;
498 insn_lengths[uid] = 0;
499 varying_length[uid] = 0;
501 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
502 || GET_CODE (insn) == CODE_LABEL)
505 body = PATTERN (insn);
506 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
508 /* This only takes room if read-only data goes into the text
510 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
511 int unitsize = GET_MODE_SIZE (GET_MODE (body));
513 insn_lengths[uid] = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
514 * GET_MODE_SIZE (GET_MODE (body)));
516 /* Account for possible alignment. */
518 += unitsize - (insn_current_address & (unitsize - 1));
523 else if (asm_noperands (body) >= 0)
524 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
525 else if (GET_CODE (body) == SEQUENCE)
529 /* Inside a delay slot sequence, we do not do any branch shortening
530 (on the only machine known to have both variable-length branches
531 and delay slots, the ROMP, branch-with-execute is the same size
532 as the maximum branch anyway). So we only have to handle normal
533 insns (actually, reorg never puts ASM insns in a delay slot, but
534 we don't take advantage of that knowledge here). */
535 for (i = 0; i < XVECLEN (body, 0); i++)
537 rtx inner_insn = XVECEXP (body, 0, i);
538 int inner_uid = INSN_UID (inner_insn);
541 if (asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
542 inner_length = (asm_insn_count (PATTERN (inner_insn))
543 * insn_default_length (inner_insn));
545 inner_length = insn_default_length (inner_insn);
547 insn_lengths[inner_uid] = inner_length;
548 varying_length[inner_uid] = 0;
549 insn_lengths[uid] += inner_length;
552 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
554 insn_lengths[uid] = insn_default_length (insn);
555 varying_length[uid] = insn_variable_length_p (insn);
558 /* If needed, do any adjustment. */
559 #ifdef ADJUST_INSN_LENGTH
560 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
564 /* Now loop over all the insns finding varying length insns. For each,
565 get the current insn length. If it has changed, reflect the change.
566 When nothing changes for a full pass, we are done. */
568 while (something_changed)
570 something_changed = 0;
571 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
573 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
577 uid = INSN_UID (insn);
578 insn_addresses[uid] = insn_current_address;
579 if (! varying_length[uid])
582 new_length = insn_current_length (insn);
583 if (new_length != insn_lengths[uid])
585 insn_lengths[uid] = new_length;
586 something_changed = 1;
590 #endif /* HAVE_ATTR_length */
593 #ifdef HAVE_ATTR_length
594 /* Given the body of an INSN known to be generated by an ASM statement, return
595 the number of machine instructions likely to be generated for this insn.
596 This is used to compute its length. */
599 asm_insn_count (body)
605 for (template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
607 *template; template++)
608 if (*template == ';' || *template == '\n')
615 /* Output assembler code for the start of a function,
616 and initialize some of the variables in this file
617 for the new function. The label for the function and associated
618 assembler pseudo-ops have already been output in `assemble_start_function'.
620 FIRST is the first insn of the rtl for the function being compiled.
621 FILE is the file to write assembler code to.
622 OPTIMIZE is nonzero if we should eliminate redundant
623 test and compare insns. */
626 final_start_function (first, file, optimize)
633 this_is_asm_operands = 0;
635 #ifdef NON_SAVING_SETJMP
636 /* A function that calls setjmp should save and restore all the
637 call-saved registers on a system where longjmp clobbers them. */
638 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
642 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
643 if (!call_used_regs[i] && !call_fixed_regs[i])
644 regs_ever_live[i] = 1;
648 /* Initial line number is supposed to be output
649 before the function's prologue and label
650 so that the function's address will not appear to be
651 in the last statement of the preceding function. */
652 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
654 if (write_symbols == SDB_DEBUG)
655 /* For sdb, let's not, but say we did.
656 We need to set last_linenum for sdbout_function_begin,
657 but we can't have an actual line number before the .bf symbol.
658 (sdb_begin_function_line is not set,
659 and other compilers don't do it.) */
660 last_linenum = NOTE_LINE_NUMBER (first);
661 #ifdef XCOFF_DEBUGGING_INFO
662 else if (write_symbols == XCOFF_DEBUG)
664 last_linenum = NOTE_LINE_NUMBER (first);
665 xcoffout_output_first_source_line (file, last_linenum);
669 output_source_line (file, first);
672 #ifdef LEAF_REG_REMAP
674 leaf_renumber_regs (first);
677 /* The Sun386i and perhaps other machines don't work right
678 if the profiling code comes after the prologue. */
679 #ifdef PROFILE_BEFORE_PROLOGUE
681 profile_function (file);
682 #endif /* PROFILE_BEFORE_PROLOGUE */
684 #ifdef FUNCTION_PROLOGUE
685 /* First output the function prologue: code to set up the stack frame. */
686 FUNCTION_PROLOGUE (file, get_frame_size ());
689 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
690 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
691 next_block_index = 1;
694 /* If the machine represents the prologue as RTL, the profiling code must
695 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
699 profile_after_prologue (file);
705 profile_after_prologue (file)
708 #ifdef FUNCTION_BLOCK_PROFILER
709 if (profile_block_flag)
711 FUNCTION_BLOCK_PROFILER (file, profile_label_no);
713 #endif /* FUNCTION_BLOCK_PROFILER */
715 #ifndef PROFILE_BEFORE_PROLOGUE
717 profile_function (file);
718 #endif /* not PROFILE_BEFORE_PROLOGUE */
722 profile_function (file)
725 int align = MIN (BIGGEST_ALIGNMENT, INT_TYPE_SIZE);
726 int sval = current_function_returns_struct;
727 int cxt = current_function_needs_context;
730 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
731 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
732 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
736 #ifdef STRUCT_VALUE_INCOMING_REGNUM
738 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
740 #ifdef STRUCT_VALUE_REGNUM
742 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
747 #ifdef STATIC_CHAIN_INCOMING_REGNUM
749 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
751 #ifdef STATIC_CHAIN_REGNUM
753 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
758 FUNCTION_PROFILER (file, profile_label_no);
761 #ifdef STATIC_CHAIN_INCOMING_REGNUM
763 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
765 #ifdef STATIC_CHAIN_REGNUM
767 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
772 #ifdef STRUCT_VALUE_INCOMING_REGNUM
774 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
776 #ifdef STRUCT_VALUE_REGNUM
778 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
783 /* Output assembler code for the end of a function.
784 For clarity, args are same as those of `final_start_function'
785 even though not all of them are needed. */
788 final_end_function (first, file, optimize)
795 fprintf (file, ASM_APP_OFF);
799 #ifdef SDB_DEBUGGING_INFO
800 if (write_symbols == SDB_DEBUG)
801 sdbout_end_function (last_linenum);
804 #ifdef XCOFF_DEBUGGING_INFO
805 if (write_symbols == XCOFF_DEBUG)
806 xcoffout_end_function (file, last_linenum);
809 #ifdef FUNCTION_EPILOGUE
810 /* Finally, output the function epilogue:
811 code to restore the stack frame and return to the caller. */
812 FUNCTION_EPILOGUE (file, get_frame_size ());
815 #ifdef SDB_DEBUGGING_INFO
816 if (write_symbols == SDB_DEBUG)
817 sdbout_end_epilogue ();
820 #ifdef DWARF_DEBUGGING_INFO
821 if (write_symbols == DWARF_DEBUG)
822 dwarfout_end_epilogue ();
825 #ifdef XCOFF_DEBUGGING_INFO
826 if (write_symbols == XCOFF_DEBUG)
827 xcoffout_end_epilogue (file);
830 /* If FUNCTION_EPILOGUE is not defined, then the function body
831 itself contains return instructions wherever needed. */
834 /* Output assembler code for some insns: all or part of a function.
835 For description of args, see `final_start_function', above.
837 PRESCAN is 1 if we are not really outputting,
838 just scanning as if we were outputting.
839 Prescanning deletes and rearranges insns just like ordinary output.
840 PRESCAN is -2 if we are outputting after having prescanned.
841 In this case, don't try to delete or rearrange insns
842 because that has already been done.
843 Prescanning is done only on certain machines. */
846 final (first, file, optimize, prescan)
855 last_ignored_compare = 0;
858 /* Make a map indicating which line numbers appear in this function. */
859 for (insn = first; insn; insn = NEXT_INSN (insn))
860 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
861 max_line = NOTE_LINE_NUMBER (insn);
863 line_note_exists = (char *) oballoc (max_line + 1);
864 bzero (line_note_exists, max_line + 1);
866 for (insn = first; insn; insn = NEXT_INSN (insn))
867 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
868 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
874 /* Output the insns. */
875 for (insn = NEXT_INSN (first); insn;)
876 insn = final_scan_insn (insn, file, optimize, prescan, 0);
878 /* Do basic-block profiling here
879 if the last insn was a conditional branch. */
880 if (profile_block_flag && new_block)
883 /* Enable the table of basic-block use counts
884 to point at the code it applies to. */
885 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
886 /* Before first insn of this basic block, increment the
887 count of times it was entered. */
888 #ifdef BLOCK_PROFILER
889 BLOCK_PROFILER (file, count_basic_blocks);
892 count_basic_blocks++;
896 /* The final scan for one insn, INSN.
897 Args are same as in `final', except that INSN
898 is the insn being scanned.
899 Value returned is the next insn to be scanned.
901 NOPEEPHOLES is the flag to disallow peephole processing (currently
902 used for within delayed branch sequence output). */
905 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
915 /* Ignore deleted insns. These can occur when we split insns (due to a
916 template of "#") while not optimizing. */
917 if (INSN_DELETED_P (insn))
918 return NEXT_INSN (insn);
920 switch (GET_CODE (insn))
926 /* Align the beginning of a loop, for higher speed
927 on certain machines. */
929 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG && optimize > 0)
931 #ifdef ASM_OUTPUT_LOOP_ALIGN
932 rtx next = next_nonnote_insn (insn);
933 if (next && GET_CODE (next) == CODE_LABEL)
935 ASM_OUTPUT_LOOP_ALIGN (asm_out_file);
940 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
943 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
945 #ifdef FUNCTION_END_PROLOGUE
946 FUNCTION_END_PROLOGUE (file);
948 profile_after_prologue (file);
952 #ifdef FUNCTION_BEGIN_EPILOGUE
953 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
955 FUNCTION_BEGIN_EPILOGUE (file);
960 if (write_symbols == NO_DEBUG)
962 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
964 #ifdef SDB_DEBUGGING_INFO
965 if (write_symbols == SDB_DEBUG)
966 sdbout_begin_function (last_linenum);
968 #ifdef XCOFF_DEBUGGING_INFO
969 if (write_symbols == XCOFF_DEBUG)
970 xcoffout_begin_function (file, last_linenum);
974 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
975 break; /* An insn that was "deleted" */
978 fprintf (file, ASM_APP_OFF);
981 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
982 && (debug_info_level == DINFO_LEVEL_NORMAL
983 || debug_info_level == DINFO_LEVEL_VERBOSE
984 #ifdef DWARF_DEBUGGING_INFO
985 || write_symbols == DWARF_DEBUG
990 /* Beginning of a symbol-block. Assign it a sequence number
991 and push the number onto the stack PENDING_BLOCKS. */
993 if (block_depth == max_block_depth)
995 /* PENDING_BLOCKS is full; make it longer. */
996 max_block_depth *= 2;
998 = (int *) xrealloc (pending_blocks,
999 max_block_depth * sizeof (int));
1001 pending_blocks[block_depth++] = next_block_index;
1003 /* Output debugging info about the symbol-block beginning. */
1005 #ifdef SDB_DEBUGGING_INFO
1006 if (write_symbols == SDB_DEBUG)
1007 sdbout_begin_block (file, last_linenum, next_block_index);
1009 #ifdef XCOFF_DEBUGGING_INFO
1010 if (write_symbols == XCOFF_DEBUG)
1011 xcoffout_begin_block (file, last_linenum, next_block_index);
1013 #ifdef DBX_DEBUGGING_INFO
1014 if (write_symbols == DBX_DEBUG)
1015 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
1017 #ifdef DWARF_DEBUGGING_INFO
1018 if (write_symbols == DWARF_DEBUG && block_depth > 1)
1019 dwarfout_begin_block (next_block_index);
1024 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
1025 && (debug_info_level == DINFO_LEVEL_NORMAL
1026 || debug_info_level == DINFO_LEVEL_VERBOSE
1027 #ifdef DWARF_DEBUGGING_INFO
1028 || write_symbols == DWARF_DEBUG
1033 /* End of a symbol-block. Pop its sequence number off
1034 PENDING_BLOCKS and output debugging info based on that. */
1038 #ifdef XCOFF_DEBUGGING_INFO
1039 if (write_symbols == XCOFF_DEBUG && block_depth >= 0)
1040 xcoffout_end_block (file, last_linenum, pending_blocks[block_depth]);
1042 #ifdef DBX_DEBUGGING_INFO
1043 if (write_symbols == DBX_DEBUG && block_depth >= 0)
1044 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
1045 pending_blocks[block_depth]);
1047 #ifdef SDB_DEBUGGING_INFO
1048 if (write_symbols == SDB_DEBUG && block_depth >= 0)
1049 sdbout_end_block (file, last_linenum);
1051 #ifdef DWARF_DEBUGGING_INFO
1052 if (write_symbols == DWARF_DEBUG && block_depth >= 1)
1053 dwarfout_end_block (pending_blocks[block_depth]);
1056 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
1057 && (debug_info_level == DINFO_LEVEL_NORMAL
1058 || debug_info_level == DINFO_LEVEL_VERBOSE))
1060 #ifdef DWARF_DEBUGGING_INFO
1061 if (write_symbols == DWARF_DEBUG)
1062 dwarfout_label (insn);
1065 else if (NOTE_LINE_NUMBER (insn) > 0)
1066 /* This note is a line-number. */
1070 #if 0 /* This is what we used to do. */
1071 output_source_line (file, insn);
1075 /* If there is anything real after this note,
1076 output it. If another line note follows, omit this one. */
1077 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
1079 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
1081 /* These types of notes can be significant
1082 so make sure the preceding line number stays. */
1083 else if (GET_CODE (note) == NOTE
1084 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
1085 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
1086 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
1088 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
1090 /* Another line note follows; we can delete this note
1091 if no intervening line numbers have notes elsewhere. */
1093 for (num = NOTE_LINE_NUMBER (insn) + 1;
1094 num < NOTE_LINE_NUMBER (note);
1096 if (line_note_exists[num])
1099 if (num == NOTE_LINE_NUMBER (note))
1105 /* Output this line note
1106 if it is the first or the last line note in a row. */
1108 output_source_line (file, insn);
1113 #ifdef ASM_OUTPUT_ALIGN_CODE
1114 /* Don't litter the assembler output with needless alignments. A
1115 BARRIER will be placed at the end of every function if HAVE_epilogue
1117 if (NEXT_INSN (insn))
1118 ASM_OUTPUT_ALIGN_CODE (file);
1127 #ifdef SDB_DEBUGGING_INFO
1128 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
1129 sdbout_label (insn);
1131 #ifdef DWARF_DEBUGGING_INFO
1132 if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
1133 dwarfout_label (insn);
1137 fprintf (file, ASM_APP_OFF);
1140 if (NEXT_INSN (insn) != 0
1141 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
1143 rtx nextbody = PATTERN (NEXT_INSN (insn));
1145 /* If this label is followed by a jump-table,
1146 make sure we put the label in the read-only section. Also
1147 possibly write the label and jump table together. */
1149 if (GET_CODE (nextbody) == ADDR_VEC
1150 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1152 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1153 readonly_data_section ();
1154 #ifdef READONLY_DATA_SECTION
1155 ASM_OUTPUT_ALIGN (file,
1156 exact_log2 (BIGGEST_ALIGNMENT
1158 #endif /* READONLY_DATA_SECTION */
1159 #else /* JUMP_TABLES_IN_TEXT_SECTION */
1161 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
1162 #ifdef ASM_OUTPUT_CASE_LABEL
1163 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
1166 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1172 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1177 register rtx body = PATTERN (insn);
1178 int insn_code_number;
1182 /* An INSN, JUMP_INSN or CALL_INSN.
1183 First check for special kinds that recog doesn't recognize. */
1185 if (GET_CODE (body) == USE /* These are just declarations */
1186 || GET_CODE (body) == CLOBBER)
1190 /* If there is a REG_CC_SETTER note on this insn, it means that
1191 the setting of the condition code was done in the delay slot
1192 of the insn that branched here. So recover the cc status
1193 from the insn that set it. */
1195 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1198 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
1199 cc_prev_status = cc_status;
1203 /* Detect insns that are really jump-tables
1204 and output them as such. */
1206 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1208 register int vlen, idx;
1215 fprintf (file, ASM_APP_OFF);
1219 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
1220 for (idx = 0; idx < vlen; idx++)
1222 if (GET_CODE (body) == ADDR_VEC)
1224 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
1225 ASM_OUTPUT_ADDR_VEC_ELT
1226 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
1233 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
1234 ASM_OUTPUT_ADDR_DIFF_ELT
1236 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
1237 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
1243 #ifdef ASM_OUTPUT_CASE_END
1244 ASM_OUTPUT_CASE_END (file,
1245 CODE_LABEL_NUMBER (PREV_INSN (insn)),
1254 /* Do basic-block profiling when we reach a new block.
1255 Done here to avoid jump tables. */
1256 if (profile_block_flag && new_block)
1259 /* Enable the table of basic-block use counts
1260 to point at the code it applies to. */
1261 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1262 /* Before first insn of this basic block, increment the
1263 count of times it was entered. */
1264 #ifdef BLOCK_PROFILER
1265 BLOCK_PROFILER (file, count_basic_blocks);
1268 count_basic_blocks++;
1271 if (GET_CODE (body) == ASM_INPUT)
1273 /* There's no telling what that did to the condition codes. */
1279 fprintf (file, ASM_APP_ON);
1282 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
1286 /* Detect `asm' construct with operands. */
1287 if (asm_noperands (body) >= 0)
1289 int noperands = asm_noperands (body);
1293 /* There's no telling what that did to the condition codes. */
1298 /* alloca won't do here, since only return from `final'
1301 ops = (rtx *) xmalloc (noperands * sizeof (rtx));
1305 fprintf (file, ASM_APP_ON);
1309 /* Get out the operand values. */
1310 string = decode_asm_operands (body, ops, NULL_PTR,
1311 NULL_PTR, NULL_PTR);
1312 /* Inhibit aborts on what would otherwise be compiler bugs. */
1313 insn_noperands = noperands;
1314 this_is_asm_operands = insn;
1315 /* Output the insn using them. */
1316 output_asm_insn (string, ops);
1317 this_is_asm_operands = 0;
1323 if (prescan <= 0 && app_on)
1325 fprintf (file, ASM_APP_OFF);
1329 if (GET_CODE (body) == SEQUENCE)
1331 /* A delayed-branch sequence */
1337 final_sequence = body;
1339 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
1340 force the restoration of a comparison that was previously
1341 thought unnecessary. If that happens, cancel this sequence
1342 and cause that insn to be restored. */
1344 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
1345 if (next != XVECEXP (body, 0, 1))
1351 for (i = 1; i < XVECLEN (body, 0); i++)
1352 final_scan_insn (XVECEXP (body, 0, i), file, 0, prescan, 1);
1353 #ifdef DBR_OUTPUT_SEQEND
1354 DBR_OUTPUT_SEQEND (file);
1358 /* If the insn requiring the delay slot was a CALL_INSN, the
1359 insns in the delay slot are actually executed before the
1360 called function. Hence we don't preserve any CC-setting
1361 actions in these insns and the CC must be marked as being
1362 clobbered by the function. */
1363 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
1366 /* Following a conditional branch sequence, we have a new basic
1368 if (profile_block_flag)
1370 rtx insn = XVECEXP (body, 0, 0);
1371 rtx body = PATTERN (insn);
1373 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1374 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1375 || (GET_CODE (insn) == JUMP_INSN
1376 && GET_CODE (body) == PARALLEL
1377 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1378 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
1384 /* We have a real machine instruction as rtl. */
1386 body = PATTERN (insn);
1389 /* Check for redundant test and compare instructions
1390 (when the condition codes are already set up as desired).
1391 This is done only when optimizing; if not optimizing,
1392 it should be possible for the user to alter a variable
1393 with the debugger in between statements
1394 and the next statement should reexamine the variable
1395 to compute the condition codes. */
1398 && GET_CODE (body) == SET
1399 && GET_CODE (SET_DEST (body)) == CC0
1400 && insn != last_ignored_compare)
1402 if (GET_CODE (SET_SRC (body)) == SUBREG)
1403 SET_SRC (body) = alter_subreg (SET_SRC (body));
1404 else if (GET_CODE (SET_SRC (body)) == COMPARE)
1406 if (GET_CODE (XEXP (SET_SRC (body), 0)) == SUBREG)
1407 XEXP (SET_SRC (body), 0)
1408 = alter_subreg (XEXP (SET_SRC (body), 0));
1409 if (GET_CODE (XEXP (SET_SRC (body), 1)) == SUBREG)
1410 XEXP (SET_SRC (body), 1)
1411 = alter_subreg (XEXP (SET_SRC (body), 1));
1413 if ((cc_status.value1 != 0
1414 && rtx_equal_p (SET_SRC (body), cc_status.value1))
1415 || (cc_status.value2 != 0
1416 && rtx_equal_p (SET_SRC (body), cc_status.value2)))
1418 /* Don't delete insn if it has an addressing side-effect. */
1419 if (! FIND_REG_INC_NOTE (insn, 0)
1420 /* or if anything in it is volatile. */
1421 && ! volatile_refs_p (PATTERN (insn)))
1423 /* We don't really delete the insn; just ignore it. */
1424 last_ignored_compare = insn;
1431 /* Following a conditional branch, we have a new basic block.
1432 But if we are inside a sequence, the new block starts after the
1433 last insn of the sequence. */
1434 if (profile_block_flag && final_sequence == 0
1435 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1436 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1437 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
1438 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1439 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
1443 /* Don't bother outputting obvious no-ops, even without -O.
1444 This optimization is fast and doesn't interfere with debugging.
1445 Don't do this if the insn is in a delay slot, since this
1446 will cause an improper number of delay insns to be written. */
1447 if (final_sequence == 0
1449 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
1450 && GET_CODE (SET_SRC (body)) == REG
1451 && GET_CODE (SET_DEST (body)) == REG
1452 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
1457 /* If this is a conditional branch, maybe modify it
1458 if the cc's are in a nonstandard state
1459 so that it accomplishes the same thing that it would
1460 do straightforwardly if the cc's were set up normally. */
1462 if (cc_status.flags != 0
1463 && GET_CODE (insn) == JUMP_INSN
1464 && GET_CODE (body) == SET
1465 && SET_DEST (body) == pc_rtx
1466 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
1467 /* This is done during prescan; it is not done again
1468 in final scan when prescan has been done. */
1471 /* This function may alter the contents of its argument
1472 and clear some of the cc_status.flags bits.
1473 It may also return 1 meaning condition now always true
1474 or -1 meaning condition now always false
1475 or 2 meaning condition nontrivial but altered. */
1476 register int result = alter_cond (XEXP (SET_SRC (body), 0));
1477 /* If condition now has fixed value, replace the IF_THEN_ELSE
1478 with its then-operand or its else-operand. */
1480 SET_SRC (body) = XEXP (SET_SRC (body), 1);
1482 SET_SRC (body) = XEXP (SET_SRC (body), 2);
1484 /* The jump is now either unconditional or a no-op.
1485 If it has become a no-op, don't try to output it.
1486 (It would not be recognized.) */
1487 if (SET_SRC (body) == pc_rtx)
1489 PUT_CODE (insn, NOTE);
1490 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1491 NOTE_SOURCE_FILE (insn) = 0;
1494 else if (GET_CODE (SET_SRC (body)) == RETURN)
1495 /* Replace (set (pc) (return)) with (return). */
1496 PATTERN (insn) = body = SET_SRC (body);
1498 /* Rerecognize the instruction if it has changed. */
1500 INSN_CODE (insn) = -1;
1503 /* Make same adjustments to instructions that examine the
1504 condition codes without jumping (if this machine has them). */
1506 if (cc_status.flags != 0
1507 && GET_CODE (body) == SET)
1509 switch (GET_CODE (SET_SRC (body)))
1522 register int result;
1523 if (XEXP (SET_SRC (body), 0) != cc0_rtx)
1525 result = alter_cond (SET_SRC (body));
1527 validate_change (insn, &SET_SRC (body), const_true_rtx, 0);
1528 else if (result == -1)
1529 validate_change (insn, &SET_SRC (body), const0_rtx, 0);
1530 else if (result == 2)
1531 INSN_CODE (insn) = -1;
1537 /* Do machine-specific peephole optimizations if desired. */
1539 if (optimize && !flag_no_peephole && !nopeepholes)
1541 rtx next = peephole (insn);
1542 /* When peepholing, if there were notes within the peephole,
1543 emit them before the peephole. */
1544 if (next != 0 && next != NEXT_INSN (insn))
1546 rtx prev = PREV_INSN (insn);
1549 for (note = NEXT_INSN (insn); note != next;
1550 note = NEXT_INSN (note))
1551 final_scan_insn (note, file, optimize, prescan, nopeepholes);
1553 /* In case this is prescan, put the notes
1554 in proper position for later rescan. */
1555 note = NEXT_INSN (insn);
1556 PREV_INSN (note) = prev;
1557 NEXT_INSN (prev) = note;
1558 NEXT_INSN (PREV_INSN (next)) = insn;
1559 PREV_INSN (insn) = PREV_INSN (next);
1560 NEXT_INSN (insn) = next;
1561 PREV_INSN (next) = insn;
1564 /* PEEPHOLE might have changed this. */
1565 body = PATTERN (insn);
1568 /* Try to recognize the instruction.
1569 If successful, verify that the operands satisfy the
1570 constraints for the instruction. Crash if they don't,
1571 since `reload' should have changed them so that they do. */
1573 insn_code_number = recog_memoized (insn);
1574 insn_extract (insn);
1575 for (i = 0; i < insn_n_operands[insn_code_number]; i++)
1577 if (GET_CODE (recog_operand[i]) == SUBREG)
1578 recog_operand[i] = alter_subreg (recog_operand[i]);
1581 #ifdef REGISTER_CONSTRAINTS
1582 if (! constrain_operands (insn_code_number, 1))
1583 fatal_insn_not_found (insn);
1586 /* Some target machines need to prescan each insn before
1589 #ifdef FINAL_PRESCAN_INSN
1590 FINAL_PRESCAN_INSN (insn, recog_operand,
1591 insn_n_operands[insn_code_number]);
1595 cc_prev_status = cc_status;
1597 /* Update `cc_status' for this instruction.
1598 The instruction's output routine may change it further.
1599 If the output routine for a jump insn needs to depend
1600 on the cc status, it should look at cc_prev_status. */
1602 NOTICE_UPDATE_CC (body, insn);
1607 /* If the proper template needs to be chosen by some C code,
1608 run that code and get the real template. */
1610 template = insn_template[insn_code_number];
1613 template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
1615 /* If the C code returns 0, it means that it is a jump insn
1616 which follows a deleted test insn, and that test insn
1617 needs to be reinserted. */
1620 if (prev_nonnote_insn (insn) != last_ignored_compare)
1623 return prev_nonnote_insn (insn);
1627 /* If the template is the string "#", it means that this insn must
1629 if (template[0] == '#' && template[1] == '\0')
1631 rtx new = try_split (body, insn, 0);
1633 /* If we didn't split the insn, go away. */
1634 if (new == insn && PATTERN (new) == body)
1644 /* Output assembler code from the template. */
1646 output_asm_insn (template, recog_operand);
1649 /* It's not at all clear why we did this and doing so interferes
1650 with tests we'd like to do to use REG_WAS_0 notes, so let's try
1653 /* Mark this insn as having been output. */
1654 INSN_DELETED_P (insn) = 1;
1660 return NEXT_INSN (insn);
1663 /* Output debugging info to the assembler file FILE
1664 based on the NOTE-insn INSN, assumed to be a line number. */
1667 output_source_line (file, insn)
1671 char ltext_label_name[100];
1672 register char *filename = NOTE_SOURCE_FILE (insn);
1674 last_linenum = NOTE_LINE_NUMBER (insn);
1676 if (write_symbols != NO_DEBUG)
1678 #ifdef SDB_DEBUGGING_INFO
1679 if (write_symbols == SDB_DEBUG
1680 #if 0 /* People like having line numbers even in wrong file! */
1681 /* COFF can't handle multiple source files--lose, lose. */
1682 && !strcmp (filename, main_input_filename)
1684 /* COFF relative line numbers must be positive. */
1685 && last_linenum > sdb_begin_function_line)
1687 #ifdef ASM_OUTPUT_SOURCE_LINE
1688 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
1690 fprintf (file, "\t.ln\t%d\n",
1691 ((sdb_begin_function_line > -1)
1692 ? last_linenum - sdb_begin_function_line : 1));
1697 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1698 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1699 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
1700 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
1702 #ifdef DWARF_DEBUGGING_INFO
1703 if (write_symbols == DWARF_DEBUG)
1704 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
1709 /* If X is a SUBREG, replace it with a REG or a MEM,
1710 based on the thing it is a subreg of. */
1716 register rtx y = SUBREG_REG (x);
1717 if (GET_CODE (y) == SUBREG)
1718 y = alter_subreg (y);
1720 if (GET_CODE (y) == REG)
1722 /* If the containing reg really gets a hard reg, so do we. */
1724 REGNO (x) = REGNO (y) + SUBREG_WORD (x);
1726 else if (GET_CODE (y) == MEM)
1728 register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
1729 #if BYTES_BIG_ENDIAN
1730 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
1731 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
1734 MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
1735 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
1741 /* Do alter_subreg on all the SUBREGs contained in X. */
1744 walk_alter_subreg (x)
1747 switch (GET_CODE (x))
1751 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
1752 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
1756 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
1760 return alter_subreg (x);
1768 /* Given BODY, the body of a jump instruction, alter the jump condition
1769 as required by the bits that are set in cc_status.flags.
1770 Not all of the bits there can be handled at this level in all cases.
1772 The value is normally 0.
1773 1 means that the condition has become always true.
1774 -1 means that the condition has become always false.
1775 2 means that COND has been altered. */
1783 if (cc_status.flags & CC_REVERSED)
1786 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
1789 if (cc_status.flags & CC_INVERTED)
1792 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
1795 if (cc_status.flags & CC_NOT_POSITIVE)
1796 switch (GET_CODE (cond))
1801 /* Jump becomes unconditional. */
1807 /* Jump becomes no-op. */
1811 PUT_CODE (cond, EQ);
1816 PUT_CODE (cond, NE);
1821 if (cc_status.flags & CC_NOT_NEGATIVE)
1822 switch (GET_CODE (cond))
1826 /* Jump becomes unconditional. */
1831 /* Jump becomes no-op. */
1836 PUT_CODE (cond, EQ);
1842 PUT_CODE (cond, NE);
1847 if (cc_status.flags & CC_NO_OVERFLOW)
1848 switch (GET_CODE (cond))
1851 /* Jump becomes unconditional. */
1855 PUT_CODE (cond, EQ);
1860 PUT_CODE (cond, NE);
1865 /* Jump becomes no-op. */
1869 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
1870 switch (GET_CODE (cond))
1883 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
1888 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
1897 /* Report inconsistency between the assembler template and the operands.
1898 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
1901 output_operand_lossage (str)
1904 if (this_is_asm_operands)
1905 error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
1910 /* Output of assembler code from a template, and its subroutines. */
1912 /* Output text from TEMPLATE to the assembler output file,
1913 obeying %-directions to substitute operands taken from
1914 the vector OPERANDS.
1916 %N (for N a digit) means print operand N in usual manner.
1917 %lN means require operand N to be a CODE_LABEL or LABEL_REF
1918 and print the label name with no punctuation.
1919 %cN means require operand N to be a constant
1920 and print the constant expression with no punctuation.
1921 %aN means expect operand N to be a memory address
1922 (not a memory reference!) and print a reference
1924 %nN means expect operand N to be a constant
1925 and print a constant expression for minus the value
1926 of the operand, with no other punctuation. */
1929 output_asm_insn (template, operands)
1936 /* An insn may return a null string template
1937 in a case where no assembler code is needed. */
1942 putc ('\t', asm_out_file);
1944 #ifdef ASM_OUTPUT_OPCODE
1945 ASM_OUTPUT_OPCODE (asm_out_file, p);
1950 #ifdef ASM_OUTPUT_OPCODE
1953 putc (c, asm_out_file);
1954 while ((c = *p) == '\t')
1956 putc (c, asm_out_file);
1959 ASM_OUTPUT_OPCODE (asm_out_file, p);
1964 putc (c, asm_out_file);
1967 /* %% outputs a single %. */
1971 putc (c, asm_out_file);
1973 /* %= outputs a number which is unique to each insn in the entire
1974 compilation. This is useful for making local labels that are
1975 referred to more than once in a given insn. */
1977 fprintf (asm_out_file, "%d", insn_counter);
1978 /* % followed by a letter and some digits
1979 outputs an operand in a special way depending on the letter.
1980 Letters `acln' are implemented directly.
1981 Other letters are passed to `output_operand' so that
1982 the PRINT_OPERAND macro can define them. */
1983 else if ((*p >= 'a' && *p <= 'z')
1984 || (*p >= 'A' && *p <= 'Z'))
1989 if (! (*p >= '0' && *p <= '9'))
1990 output_operand_lossage ("operand number missing after %-letter");
1991 else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
1992 output_operand_lossage ("operand number out of range");
1993 else if (letter == 'l')
1994 output_asm_label (operands[c]);
1995 else if (letter == 'a')
1996 output_address (operands[c]);
1997 else if (letter == 'c')
1999 if (CONSTANT_ADDRESS_P (operands[c]))
2000 output_addr_const (asm_out_file, operands[c]);
2002 output_operand (operands[c], 'c');
2004 else if (letter == 'n')
2006 if (GET_CODE (operands[c]) == CONST_INT)
2007 fprintf (asm_out_file,
2008 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2013 - INTVAL (operands[c]));
2016 putc ('-', asm_out_file);
2017 output_addr_const (asm_out_file, operands[c]);
2021 output_operand (operands[c], letter);
2023 while ((c = *p) >= '0' && c <= '9') p++;
2025 /* % followed by a digit outputs an operand the default way. */
2026 else if (*p >= '0' && *p <= '9')
2029 if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2030 output_operand_lossage ("operand number out of range");
2032 output_operand (operands[c], 0);
2033 while ((c = *p) >= '0' && c <= '9') p++;
2035 /* % followed by punctuation: output something for that
2036 punctuation character alone, with no operand.
2037 The PRINT_OPERAND macro decides what is actually done. */
2038 #ifdef PRINT_OPERAND_PUNCT_VALID_P
2039 else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
2040 output_operand (NULL_RTX, *p++);
2043 output_operand_lossage ("invalid %%-code");
2047 if (flag_print_asm_name)
2049 /* Annotate the assembly with a comment describing the pattern and
2050 alternative used. */
2053 register int num = INSN_CODE (debug_insn);
2054 fprintf (asm_out_file, " %s %d %s",
2055 ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
2056 if (insn_n_alternatives[num] > 1)
2057 fprintf (asm_out_file, "/%d", which_alternative + 1);
2059 /* Clear this so only the first assembler insn
2060 of any rtl insn will get the special comment for -dp. */
2065 putc ('\n', asm_out_file);
2068 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
2071 output_asm_label (x)
2076 if (GET_CODE (x) == LABEL_REF)
2077 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2078 else if (GET_CODE (x) == CODE_LABEL)
2079 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2081 output_operand_lossage ("`%l' operand isn't a label");
2083 assemble_name (asm_out_file, buf);
2086 /* Print operand X using machine-dependent assembler syntax.
2087 The macro PRINT_OPERAND is defined just to control this function.
2088 CODE is a non-digit that preceded the operand-number in the % spec,
2089 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
2090 between the % and the digits.
2091 When CODE is a non-letter, X is 0.
2093 The meanings of the letters are machine-dependent and controlled
2094 by PRINT_OPERAND. */
2097 output_operand (x, code)
2101 if (x && GET_CODE (x) == SUBREG)
2102 x = alter_subreg (x);
2104 /* If X is a pseudo-register, abort now rather than writing trash to the
2107 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2110 PRINT_OPERAND (asm_out_file, x, code);
2113 /* Print a memory reference operand for address X
2114 using machine-dependent assembler syntax.
2115 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
2121 walk_alter_subreg (x);
2122 PRINT_OPERAND_ADDRESS (asm_out_file, x);
2125 /* Print an integer constant expression in assembler syntax.
2126 Addition and subtraction are the only arithmetic
2127 that may appear in these expressions. */
2130 output_addr_const (file, x)
2137 switch (GET_CODE (x))
2147 assemble_name (file, XSTR (x, 0));
2151 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2152 assemble_name (asm_out_file, buf);
2156 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2157 assemble_name (asm_out_file, buf);
2162 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2171 /* This used to output parentheses around the expression,
2172 but that does not work on the 386 (either ATT or BSD assembler). */
2173 output_addr_const (file, XEXP (x, 0));
2177 if (GET_MODE (x) == VOIDmode)
2179 /* We can use %d if the number is one word and positive. */
2180 if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
2182 #if HOST_BITS_PER_WIDE_INT == 64
2183 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2189 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2195 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2198 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2203 CONST_DOUBLE_LOW (x));
2206 /* We can't handle floating point constants;
2207 PRINT_OPERAND must handle them. */
2208 output_operand_lossage ("floating constant misused");
2212 /* Some assemblers need integer constants to appear last (eg masm). */
2213 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2215 output_addr_const (file, XEXP (x, 1));
2216 if (INTVAL (XEXP (x, 0)) >= 0)
2217 fprintf (file, "+");
2218 output_addr_const (file, XEXP (x, 0));
2222 output_addr_const (file, XEXP (x, 0));
2223 if (INTVAL (XEXP (x, 1)) >= 0)
2224 fprintf (file, "+");
2225 output_addr_const (file, XEXP (x, 1));
2230 output_addr_const (file, XEXP (x, 0));
2231 fprintf (file, "-");
2232 output_addr_const (file, XEXP (x, 1));
2237 output_addr_const (file, XEXP (x, 0));
2241 output_operand_lossage ("invalid expression as operand");
2245 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
2246 %R prints the value of REGISTER_PREFIX.
2247 %L prints the value of LOCAL_LABEL_PREFIX.
2248 %U prints the value of USER_LABEL_PREFIX.
2249 %I prints the value of IMMEDIATE_PREFIX.
2250 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
2251 Also supported are %d, %x, %s, %e, %f, %g and %%. */
2254 asm_fprintf (va_alist)
2264 file = va_arg (argptr, FILE *);
2265 p = va_arg (argptr, char *);
2274 while ((c >= '0' && c <= '9') || c == '.')
2282 fprintf (file, "%%");
2285 case 'd': case 'i': case 'u':
2286 case 'x': case 'p': case 'X':
2290 fprintf (file, buf, va_arg (argptr, int));
2298 fprintf (file, buf, va_arg (argptr, double));
2304 fprintf (file, buf, va_arg (argptr, char *));
2308 #ifdef ASM_OUTPUT_OPCODE
2309 ASM_OUTPUT_OPCODE (asm_out_file, p);
2314 #ifdef REGISTER_PREFIX
2315 fprintf (file, "%s", REGISTER_PREFIX);
2320 #ifdef IMMEDIATE_PREFIX
2321 fprintf (file, "%s", IMMEDIATE_PREFIX);
2326 #ifdef LOCAL_LABEL_PREFIX
2327 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
2332 #ifdef USER_LABEL_PREFIX
2333 fprintf (file, "%s", USER_LABEL_PREFIX);
2347 /* Split up a CONST_DOUBLE or integer constant rtx
2348 into two rtx's for single words,
2349 storing in *FIRST the word that comes first in memory in the target
2350 and in *SECOND the other. */
2353 split_double (value, first, second)
2355 rtx *first, *second;
2357 if (GET_CODE (value) == CONST_INT)
2359 /* The rule for using CONST_INT for a wider mode
2360 is that we regard the value as signed.
2361 So sign-extend it. */
2362 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
2363 #if WORDS_BIG_ENDIAN
2371 else if (GET_CODE (value) != CONST_DOUBLE)
2373 #if WORDS_BIG_ENDIAN
2374 *first = const0_rtx;
2378 *second = const0_rtx;
2381 else if (GET_MODE (value) == VOIDmode
2382 /* This is the old way we did CONST_DOUBLE integers. */
2383 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
2385 /* In an integer, the words are defined as most and least significant.
2386 So order them by the target's convention. */
2387 #if WORDS_BIG_ENDIAN
2388 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2389 *second = GEN_INT (CONST_DOUBLE_LOW (value));
2391 *first = GEN_INT (CONST_DOUBLE_LOW (value));
2392 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
2397 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
2398 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
2399 && ! flag_pretend_float)
2402 #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
2403 /* Host and target agree => no need to swap. */
2404 *first = GEN_INT (CONST_DOUBLE_LOW (value));
2405 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
2407 *second = GEN_INT (CONST_DOUBLE_LOW (value));
2408 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2413 /* Return nonzero if this function has no function calls. */
2420 if (profile_flag || profile_block_flag)
2423 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2425 if (GET_CODE (insn) == CALL_INSN)
2427 if (GET_CODE (insn) == INSN
2428 && GET_CODE (PATTERN (insn)) == SEQUENCE
2429 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN)
2432 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
2434 if (GET_CODE (XEXP (insn, 0)) == CALL_INSN)
2436 if (GET_CODE (XEXP (insn, 0)) == INSN
2437 && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
2438 && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN)
2445 /* On some machines, a function with no call insns
2446 can run faster if it doesn't create its own register window.
2447 When output, the leaf function should use only the "output"
2448 registers. Ordinarily, the function would be compiled to use
2449 the "input" registers to find its arguments; it is a candidate
2450 for leaf treatment if it uses only the "input" registers.
2451 Leaf function treatment means renumbering so the function
2452 uses the "output" registers instead. */
2454 #ifdef LEAF_REGISTERS
2456 static char permitted_reg_in_leaf_functions[] = LEAF_REGISTERS;
2458 /* Return 1 if this function uses only the registers that can be
2459 safely renumbered. */
2462 only_leaf_regs_used ()
2466 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2468 if (regs_ever_live[i] > permitted_reg_in_leaf_functions[i])
2474 /* Scan all instructions and renumber all registers into those
2475 available in leaf functions. */
2478 leaf_renumber_regs (first)
2483 /* Renumber only the actual patterns.
2484 The reg-notes can contain frame pointer refs,
2485 and renumbering them could crash, and should not be needed. */
2486 for (insn = first; insn; insn = NEXT_INSN (insn))
2487 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
2488 leaf_renumber_regs_insn (PATTERN (insn));
2489 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
2490 if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
2491 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
2494 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
2495 available in leaf functions. */
2498 leaf_renumber_regs_insn (in_rtx)
2499 register rtx in_rtx;
2502 register char *format_ptr;
2507 /* Renumber all input-registers into output-registers.
2508 renumbered_regs would be 1 for an output-register;
2511 if (GET_CODE (in_rtx) == REG)
2515 /* Don't renumber the same reg twice. */
2519 newreg = REGNO (in_rtx);
2520 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
2521 to reach here as part of a REG_NOTE. */
2522 if (newreg >= FIRST_PSEUDO_REGISTER)
2527 newreg = LEAF_REG_REMAP (newreg);
2530 regs_ever_live[REGNO (in_rtx)] = 0;
2531 regs_ever_live[newreg] = 1;
2532 REGNO (in_rtx) = newreg;
2536 if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
2538 /* Inside a SEQUENCE, we find insns.
2539 Renumber just the patterns of these insns,
2540 just as we do for the top-level insns. */
2541 leaf_renumber_regs_insn (PATTERN (in_rtx));
2545 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
2547 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
2548 switch (*format_ptr++)
2551 leaf_renumber_regs_insn (XEXP (in_rtx, i));
2555 if (NULL != XVEC (in_rtx, i))
2557 for (j = 0; j < XVECLEN (in_rtx, i); j++)
2558 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));