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-attr.h"
53 #include "insn-codes.h"
55 #include "conditions.h"
59 #include "hard-reg-set.h"
62 #define ASM_STABD_OP ".stabd"
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 ();
115 #ifdef HAVE_ATTR_length
116 static int asm_insn_count ();
119 /* Nonzero means this function is a leaf function, with no function calls.
120 This variable exists to be examined in FUNCTION_PROLOGUE
121 and FUNCTION_EPILOGUE. Always zero, unless set by some action. */
124 int leaf_function_p ();
126 #ifdef LEAF_REGISTERS
127 int only_leaf_regs_used ();
128 static void leaf_renumber_regs ();
129 void leaf_renumber_regs_insn ();
132 /* Last insn processed by final_scan_insn. */
133 static rtx debug_insn
= 0;
135 /* Line number of last NOTE. */
136 static int last_linenum
;
138 /* Number of basic blocks seen so far;
139 used if profile_block_flag is set. */
140 static int count_basic_blocks
;
142 /* Nonzero while outputting an `asm' with operands.
143 This means that inconsistencies are the user's fault, so don't abort.
144 The precise value is the insn being output, to pass to error_for_asm. */
145 static rtx this_is_asm_operands
;
147 /* Number of operands of this insn, for an `asm' with operands. */
148 static int insn_noperands
;
150 /* Compare optimization flag. */
152 static rtx last_ignored_compare
= 0;
154 /* Flag indicating this insn is the start of a new basic block. */
156 static int new_block
= 1;
158 /* All the symbol-blocks (levels of scoping) in the compilation
159 are assigned sequence numbers in order of appearance of the
160 beginnings of the symbol-blocks. Both final and dbxout do this,
161 and assume that they will both give the same number to each block.
162 Final uses these sequence numbers to generate assembler label names
163 LBBnnn and LBEnnn for the beginning and end of the symbol-block.
164 Dbxout uses the sequence nunbers to generate references to the same labels
165 from the dbx debugging information.
167 Sdb records this level at the beginning of each function,
168 in order to find the current level when recursing down declarations.
169 It outputs the block beginning and endings
170 at the point in the asm file where the blocks would begin and end. */
172 int next_block_index
;
174 /* Assign a unique number to each insn that is output.
175 This can be used to generate unique local labels. */
177 static int insn_counter
= 0;
180 /* This variable contains machine-dependent flags (defined in tm.h)
181 set and examined by output routines
182 that describe how to interpret the condition codes properly. */
186 /* During output of an insn, this contains a copy of cc_status
187 from before the insn. */
189 CC_STATUS cc_prev_status
;
192 /* Indexed by hardware reg number, is 1 if that register is ever
193 used in the current function.
195 In life_analysis, or in stupid_life_analysis, this is set
196 up to record the hard regs used explicitly. Reload adds
197 in the hard regs used for holding pseudo regs. Final uses
198 it to generate the code in the function prologue and epilogue
199 to save and restore registers as needed. */
201 char regs_ever_live
[FIRST_PSEUDO_REGISTER
];
203 /* Nonzero means current function must be given a frame pointer.
204 Set in stmt.c if anything is allocated on the stack there.
205 Set in reload1.c if anything is allocated on the stack there. */
207 int frame_pointer_needed
;
209 /* Assign unique numbers to labels generated for profiling. */
211 int profile_label_no
;
213 /* Length so far allocated in PENDING_BLOCKS. */
215 static int max_block_depth
;
217 /* Stack of sequence numbers of symbol-blocks of which we have seen the
218 beginning but not yet the end. Sequence numbers are assigned at
219 the beginning; this stack allows us to find the sequence number
220 of a block that is ending. */
222 static int *pending_blocks
;
224 /* Number of elements currently in use in PENDING_BLOCKS. */
226 static int block_depth
;
228 /* Nonzero if have enabled APP processing of our assembler output. */
232 /* If we are outputting an insn sequence, this contains the sequence rtx.
237 /* Indexed by line number, nonzero if there is a note for that line. */
239 static char *line_note_exists
;
241 /* Initialize data in final at the beginning of a compilation. */
244 init_final (filename
)
247 next_block_index
= 2;
249 max_block_depth
= 20;
250 pending_blocks
= (int *) xmalloc (20 * sizeof *pending_blocks
);
254 /* Called at end of source file,
255 to output the block-profiling table for this entire compilation. */
263 if (profile_block_flag
)
269 /* Output the main header, of 6 words:
270 0: 1 if this file's initialized, else 0.
271 1: address of file name.
272 2: address of table of counts.
273 4: number of counts in the table.
274 5: always 0, for compatibility with Sun.
275 6: extra word added by GNU: address of address table
276 which contains addresses of basic blocks,
277 in parallel with the table of counts. */
278 ASM_OUTPUT_ALIGN (asm_out_file
,
279 exact_log2 (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
281 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LPBX", 0);
282 assemble_integer (const0_rtx
, UNITS_PER_WORD
, 1);
283 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 1);
284 assemble_integer (gen_rtx (SYMBOL_REF
, Pmode
, name
), UNITS_PER_WORD
, 1);
285 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 2);
286 assemble_integer (gen_rtx (SYMBOL_REF
, Pmode
, name
), UNITS_PER_WORD
, 1);
287 assemble_integer (gen_rtx (CONST_INT
, VOIDmode
, count_basic_blocks
),
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 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LPBX", 3);
315 for (i
= 0; i
< count_basic_blocks
; i
++)
318 ASM_GENERATE_INTERNAL_LABEL (name
, "LPB", i
);
319 assemble_integer (gen_rtx (SYMBOL_REF
, Pmode
, name
),
323 /* End with the address of the table of addresses,
324 so we can find it easily, as the last word in the file's text. */
325 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 3);
326 assemble_integer (gen_rtx (SYMBOL_REF
, Pmode
, name
), UNITS_PER_WORD
, 1);
330 /* Enable APP processing of subsequent output.
331 Used before the output from an `asm' statement. */
338 fprintf (asm_out_file
, ASM_APP_ON
);
343 /* Enable APP processing of subsequent output.
344 Called from varasm.c before most kinds of output. */
351 fprintf (asm_out_file
, ASM_APP_OFF
);
356 /* Return the number of slots filled in the current
357 delayed branch sequence (we don't count the insn needing the
358 delay slot). Zero if not in a delayed branch sequence. */
362 dbr_sequence_length ()
364 if (final_sequence
!= 0)
365 return XVECLEN (final_sequence
, 0) - 1;
371 /* The next two pages contain routines used to compute the length of an insn
372 and to shorten branches. */
374 /* Arrays for insn lengths, and addresses. The latter is referenced by
375 `insn_current_length'. */
377 static short *insn_lengths
;
380 /* Address of insn being processed. Used by `insn_current_length'. */
381 int insn_current_address
;
383 /* Indicate the branch shortening hasn't yet been done. */
391 /* Obtain the current length of an insn. If branch shortening has been done,
392 get its actual length. Otherwise, get its maximum length. */
395 get_attr_length (insn
)
398 #ifdef HAVE_ATTR_length
404 return insn_lengths
[INSN_UID (insn
)];
406 switch (GET_CODE (insn
))
414 length
= insn_default_length (insn
);
418 body
= PATTERN (insn
);
419 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
421 /* This only takes room if jump tables go into the text section. */
422 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
423 length
= (XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
)
424 * GET_MODE_SIZE (GET_MODE (body
)));
426 /* Be pessimistic and assume worst-case alignment. */
427 length
+= (GET_MODE_SIZE (GET_MODE (body
)) - 1);
433 length
= insn_default_length (insn
);
437 body
= PATTERN (insn
);
438 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
441 else if (GET_CODE (body
) == ASM_INPUT
|| asm_noperands (body
) >= 0)
442 length
= asm_insn_count (insn
) * insn_default_length (insn
);
443 else if (GET_CODE (body
) == SEQUENCE
)
444 for (i
= 0; i
< XVECLEN (body
, 0); i
++)
445 length
+= get_attr_length (XVECEXP (body
, 0, i
));
447 length
= insn_default_length (insn
);
450 #ifdef ADJUST_INSN_LENGTH
451 ADJUST_INSN_LENGTH (insn
, length
);
454 #else /* not HAVE_ATTR_length */
456 #endif /* not HAVE_ATTR_length */
459 /* Make a pass over all insns and compute their actual lengths by shortening
460 any branches of variable length if possible. */
462 /* Give a default value for the lowest address in a function. */
464 #ifndef FIRST_INSN_ADDRESS
465 #define FIRST_INSN_ADDRESS 0
469 shorten_branches (first
)
472 #ifdef HAVE_ATTR_length
474 int something_changed
= 1;
476 char *varying_length
;
480 /* Compute maximum UID and allocate arrays. */
481 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
482 if (INSN_UID (insn
) > max_uid
)
483 max_uid
= INSN_UID (insn
);
486 insn_lengths
= (short *) oballoc (max_uid
* sizeof (short));
487 insn_addresses
= (int *) oballoc (max_uid
* sizeof (int));
488 varying_length
= (char *) oballoc (max_uid
* sizeof (char));
490 /* Compute initial lengths, addresses, and varying flags for each insn. */
491 for (insn_current_address
= FIRST_INSN_ADDRESS
, insn
= first
;
493 insn_current_address
+= insn_lengths
[uid
], insn
= NEXT_INSN (insn
))
495 uid
= INSN_UID (insn
);
496 insn_addresses
[uid
] = insn_current_address
;
497 insn_lengths
[uid
] = 0;
498 varying_length
[uid
] = 0;
500 if (GET_CODE (insn
) == NOTE
|| GET_CODE (insn
) == BARRIER
501 || GET_CODE (insn
) == CODE_LABEL
)
504 body
= PATTERN (insn
);
505 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
507 /* This only takes room if read-only data goes into the text
509 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
510 int unitsize
= GET_MODE_SIZE (GET_MODE (body
));
512 insn_lengths
[uid
] = (XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
)
513 * GET_MODE_SIZE (GET_MODE (body
)));
515 /* Account for possible alignment. */
517 += unitsize
- (insn_current_address
& (unitsize
- 1));
522 else if (asm_noperands (body
) >= 0)
523 insn_lengths
[uid
] = asm_insn_count (body
) * insn_default_length (insn
);
524 else if (GET_CODE (body
) == SEQUENCE
)
528 /* Inside a delay slot sequence, we do not do any branch shortening
529 (on the only machine known to have both variable-length branches
530 and delay slots, the ROMP, branch-with-execute is the same size
531 as the maximum branch anyway). So we only have to handle normal
532 insns (actually, reorg never puts ASM insns in a delay slot, but
533 we don't take advantage of that knowledge here). */
534 for (i
= 0; i
< XVECLEN (body
, 0); i
++)
536 rtx inner_insn
= XVECEXP (body
, 0, i
);
537 int inner_uid
= INSN_UID (inner_insn
);
540 if (asm_noperands (PATTERN (XVECEXP (body
, 0, i
))) >= 0)
541 inner_length
= (asm_insn_count (PATTERN (inner_insn
))
542 * insn_default_length (inner_insn
));
544 inner_length
= insn_default_length (inner_insn
);
546 insn_lengths
[inner_uid
] = inner_length
;
547 varying_length
[inner_uid
] = 0;
548 insn_lengths
[uid
] += inner_length
;
551 else if (GET_CODE (body
) != USE
&& GET_CODE (body
) != CLOBBER
)
553 insn_lengths
[uid
] = insn_default_length (insn
);
554 varying_length
[uid
] = insn_variable_length_p (insn
);
557 /* If needed, do any adjustment. */
558 #ifdef ADJUST_INSN_LENGTH
559 ADJUST_INSN_LENGTH (insn
, insn_lengths
[uid
]);
563 /* Now loop over all the insns finding varying length insns. For each,
564 get the current insn length. If it has changed, reflect the change.
565 When nothing changes for a full pass, we are done. */
567 while (something_changed
)
569 something_changed
= 0;
570 for (insn_current_address
= FIRST_INSN_ADDRESS
, insn
= first
;
572 insn_current_address
+= insn_lengths
[uid
], insn
= NEXT_INSN (insn
))
576 uid
= INSN_UID (insn
);
577 insn_addresses
[uid
] = insn_current_address
;
578 if (! varying_length
[uid
])
581 new_length
= insn_current_length (insn
);
582 if (new_length
!= insn_lengths
[uid
])
584 insn_lengths
[uid
] = new_length
;
585 something_changed
= 1;
589 #endif /* HAVE_ATTR_length */
592 #ifdef HAVE_ATTR_length
593 /* Given the body of an INSN known to be generated by an ASM statement, return
594 the number of machine instructions likely to be generated for this insn.
595 This is used to compute its length. */
598 asm_insn_count (body
)
604 for (template = decode_asm_operands (body
, 0, 0, 0, 0);
605 *template; template++)
606 if (*template == ';' || *template == '\n')
613 /* Output assembler code for the start of a function,
614 and initialize some of the variables in this file
615 for the new function. The label for the function and associated
616 assembler pseudo-ops have already been output in `assemble_start_function'.
618 FIRST is the first insn of the rtl for the function being compiled.
619 FILE is the file to write assembler code to.
620 OPTIMIZE is nonzero if we should eliminate redundant
621 test and compare insns. */
624 final_start_function (first
, file
, optimize
)
631 this_is_asm_operands
= 0;
633 #ifdef NON_SAVING_SETJMP
634 /* A function that calls setjmp should save and restore all the
635 call-saved registers on a system where longjmp clobbers them. */
636 if (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
640 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
641 if (!call_used_regs
[i
] && !call_fixed_regs
[i
])
642 regs_ever_live
[i
] = 1;
646 /* Initial line number is supposed to be output
647 before the function's prologue and label
648 so that the function's address will not appear to be
649 in the last statement of the preceding function. */
650 if (NOTE_LINE_NUMBER (first
) != NOTE_INSN_DELETED
)
652 if (write_symbols
== SDB_DEBUG
)
653 /* For sdb, let's not, but say we did.
654 We need to set last_linenum for sdbout_function_begin,
655 but we can't have an actual line number before the .bf symbol.
656 (sdb_begin_function_line is not set,
657 and other compilers don't do it.) */
658 last_linenum
= NOTE_LINE_NUMBER (first
);
659 #ifdef XCOFF_DEBUGGING_INFO
660 else if (write_symbols
== XCOFF_DEBUG
)
662 last_linenum
= NOTE_LINE_NUMBER (first
);
663 xcoffout_output_first_source_line (file
, last_linenum
);
667 output_source_line (file
, first
);
670 #ifdef LEAF_REG_REMAP
672 leaf_renumber_regs (first
);
675 /* The Sun386i and perhaps other machines don't work right
676 if the profiling code comes after the prologue. */
677 #ifdef PROFILE_BEFORE_PROLOGUE
679 profile_function (file
);
680 #endif /* PROFILE_BEFORE_PROLOGUE */
682 #ifdef FUNCTION_PROLOGUE
683 /* First output the function prologue: code to set up the stack frame. */
684 FUNCTION_PROLOGUE (file
, get_frame_size ());
687 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
688 if (write_symbols
== SDB_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
689 next_block_index
= 1;
692 #ifdef FUNCTION_BLOCK_PROFILER
693 if (profile_block_flag
)
695 FUNCTION_BLOCK_PROFILER (file
, profile_label_no
);
697 #endif /* FUNCTION_BLOCK_PROFILER */
699 #ifndef PROFILE_BEFORE_PROLOGUE
701 profile_function (file
);
702 #endif /* not PROFILE_BEFORE_PROLOGUE */
708 profile_function (file
)
711 int align
= MIN (BIGGEST_ALIGNMENT
, INT_TYPE_SIZE
);
712 int sval
= current_function_returns_struct
;
713 int cxt
= current_function_needs_context
;
716 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
717 ASM_OUTPUT_INTERNAL_LABEL (file
, "LP", profile_label_no
);
718 assemble_integer (const0_rtx
, UNITS_PER_WORD
, 1);
722 #ifdef STRUCT_VALUE_INCOMING_REGNUM
724 ASM_OUTPUT_REG_PUSH (file
, STRUCT_VALUE_INCOMING_REGNUM
);
726 #ifdef STRUCT_VALUE_REGNUM
728 ASM_OUTPUT_REG_PUSH (file
, STRUCT_VALUE_REGNUM
);
733 #ifdef STATIC_CHAIN_INCOMING_REGNUM
735 ASM_OUTPUT_REG_PUSH (file
, STATIC_CHAIN_INCOMING_REGNUM
);
737 #ifdef STATIC_CHAIN_REGNUM
739 ASM_OUTPUT_REG_PUSH (file
, STATIC_CHAIN_REGNUM
);
744 FUNCTION_PROFILER (file
, profile_label_no
);
747 #ifdef STATIC_CHAIN_INCOMING_REGNUM
749 ASM_OUTPUT_REG_POP (file
, STATIC_CHAIN_INCOMING_REGNUM
);
751 #ifdef STATIC_CHAIN_REGNUM
753 ASM_OUTPUT_REG_POP (file
, STATIC_CHAIN_REGNUM
);
758 #ifdef STRUCT_VALUE_INCOMING_REGNUM
760 ASM_OUTPUT_REG_POP (file
, STRUCT_VALUE_INCOMING_REGNUM
);
762 #ifdef STRUCT_VALUE_REGNUM
764 ASM_OUTPUT_REG_POP (file
, STRUCT_VALUE_REGNUM
);
769 /* Output assembler code for the end of a function.
770 For clarity, args are same as those of `final_start_function'
771 even though not all of them are needed. */
774 final_end_function (first
, file
, optimize
)
781 fprintf (file
, ASM_APP_OFF
);
785 #ifdef SDB_DEBUGGING_INFO
786 if (write_symbols
== SDB_DEBUG
)
787 sdbout_end_function (last_linenum
);
790 #ifdef XCOFF_DEBUGGING_INFO
791 if (write_symbols
== XCOFF_DEBUG
)
792 xcoffout_end_function (file
, last_linenum
);
795 #ifdef FUNCTION_EPILOGUE
796 /* Finally, output the function epilogue:
797 code to restore the stack frame and return to the caller. */
798 FUNCTION_EPILOGUE (file
, get_frame_size ());
801 #ifdef SDB_DEBUGGING_INFO
802 if (write_symbols
== SDB_DEBUG
)
803 sdbout_end_epilogue ();
806 #ifdef DWARF_DEBUGGING_INFO
807 if (write_symbols
== DWARF_DEBUG
)
808 dwarfout_end_epilogue ();
811 #ifdef XCOFF_DEBUGGING_INFO
812 if (write_symbols
== XCOFF_DEBUG
)
813 xcoffout_end_epilogue (file
);
816 /* If FUNCTION_EPILOGUE is not defined, then the function body
817 itself contains return instructions wherever needed. */
820 /* Output assembler code for some insns: all or part of a function.
821 For description of args, see `final_start_function', above.
823 PRESCAN is 1 if we are not really outputting,
824 just scanning as if we were outputting.
825 Prescanning deletes and rearranges insns just like ordinary output.
826 PRESCAN is -2 if we are outputting after having prescanned.
827 In this case, don't try to delete or rearrange insns
828 because that has already been done.
829 Prescanning is done only on certain machines. */
832 final (first
, file
, optimize
, prescan
)
841 last_ignored_compare
= 0;
844 /* Make a map indicating which line numbers appear in this function. */
845 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
846 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > max_line
)
847 max_line
= NOTE_LINE_NUMBER (insn
);
849 line_note_exists
= (char *) oballoc (max_line
+ 1);
850 bzero (line_note_exists
, max_line
+ 1);
852 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
853 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
854 line_note_exists
[NOTE_LINE_NUMBER (insn
)] = 1;
860 /* Output the insns. */
861 for (insn
= NEXT_INSN (first
); insn
;)
862 insn
= final_scan_insn (insn
, file
, optimize
, prescan
, 0);
864 /* Do basic-block profiling here
865 if the last insn was a conditional branch. */
866 if (profile_block_flag
&& new_block
)
869 /* Enable the table of basic-block use counts
870 to point at the code it applies to. */
871 ASM_OUTPUT_INTERNAL_LABEL (file
, "LPB", count_basic_blocks
);
872 /* Before first insn of this basic block, increment the
873 count of times it was entered. */
874 #ifdef BLOCK_PROFILER
875 BLOCK_PROFILER (file
, count_basic_blocks
);
878 count_basic_blocks
++;
882 /* The final scan for one insn, INSN.
883 Args are same as in `final', except that INSN
884 is the insn being scanned.
885 Value returned is the next insn to be scanned.
887 NOPEEPHOLES is the flag to disallow peephole processing (currently
888 used for within delayed branch sequence output). */
891 final_scan_insn (insn
, file
, optimize
, prescan
, nopeepholes
)
901 /* Ignore deleted insns. These can occur when we split insns (due to a
902 template of "#") while not optimizing. */
903 if (INSN_DELETED_P (insn
))
904 return NEXT_INSN (insn
);
906 switch (GET_CODE (insn
))
912 /* Align the beginning of a loop, for higher speed
913 on certain machines. */
915 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
&& optimize
> 0)
917 #ifdef ASM_OUTPUT_LOOP_ALIGN
918 rtx next
= next_nonnote_insn (insn
);
919 if (next
&& GET_CODE (next
) == CODE_LABEL
)
921 ASM_OUTPUT_LOOP_ALIGN (asm_out_file
);
926 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
)
929 if (write_symbols
== NO_DEBUG
)
931 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_FUNCTION_BEG
)
933 #ifdef SDB_DEBUGGING_INFO
934 if (write_symbols
== SDB_DEBUG
)
935 sdbout_begin_function (last_linenum
);
937 #ifdef XCOFF_DEBUGGING_INFO
938 if (write_symbols
== XCOFF_DEBUG
)
939 xcoffout_begin_function (file
, last_linenum
);
943 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED
)
944 break; /* An insn that was "deleted" */
947 fprintf (file
, ASM_APP_OFF
);
950 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
951 && (debug_info_level
== DINFO_LEVEL_NORMAL
952 || debug_info_level
== DINFO_LEVEL_VERBOSE
))
954 /* Beginning of a symbol-block. Assign it a sequence number
955 and push the number onto the stack PENDING_BLOCKS. */
957 if (block_depth
== max_block_depth
)
959 /* PENDING_BLOCKS is full; make it longer. */
960 max_block_depth
*= 2;
962 = (int *) xrealloc (pending_blocks
,
963 max_block_depth
* sizeof (int));
965 pending_blocks
[block_depth
++] = next_block_index
;
967 /* Output debugging info about the symbol-block beginning. */
969 #ifdef SDB_DEBUGGING_INFO
970 if (write_symbols
== SDB_DEBUG
)
971 sdbout_begin_block (file
, last_linenum
, next_block_index
);
973 #ifdef XCOFF_DEBUGGING_INFO
974 if (write_symbols
== XCOFF_DEBUG
)
975 xcoffout_begin_block (file
, last_linenum
, next_block_index
);
977 #ifdef DBX_DEBUGGING_INFO
978 if (write_symbols
== DBX_DEBUG
)
979 ASM_OUTPUT_INTERNAL_LABEL (file
, "LBB", next_block_index
);
981 #ifdef DWARF_DEBUGGING_INFO
982 if (write_symbols
== DWARF_DEBUG
&& block_depth
> 1)
983 dwarfout_begin_block (next_block_index
);
988 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
989 && (debug_info_level
== DINFO_LEVEL_NORMAL
990 || debug_info_level
== DINFO_LEVEL_VERBOSE
))
992 /* End of a symbol-block. Pop its sequence number off
993 PENDING_BLOCKS and output debugging info based on that. */
997 #ifdef XCOFF_DEBUGGING_INFO
998 if (write_symbols
== XCOFF_DEBUG
&& block_depth
>= 0)
999 xcoffout_end_block (file
, last_linenum
, pending_blocks
[block_depth
]);
1001 #ifdef DBX_DEBUGGING_INFO
1002 if (write_symbols
== DBX_DEBUG
&& block_depth
>= 0)
1003 ASM_OUTPUT_INTERNAL_LABEL (file
, "LBE",
1004 pending_blocks
[block_depth
]);
1006 #ifdef SDB_DEBUGGING_INFO
1007 if (write_symbols
== SDB_DEBUG
&& block_depth
>= 0)
1008 sdbout_end_block (file
, last_linenum
);
1010 #ifdef DWARF_DEBUGGING_INFO
1011 if (write_symbols
== DWARF_DEBUG
&& block_depth
>= 1)
1012 dwarfout_end_block (pending_blocks
[block_depth
]);
1015 else if (NOTE_LINE_NUMBER (insn
) > 0)
1016 /* This note is a line-number. */
1020 #if 0 /* This is what we used to do. */
1021 output_source_line (file
, insn
);
1025 /* If there is anything real after this note,
1026 output it. If another line note follows, omit this one. */
1027 for (note
= NEXT_INSN (insn
); note
; note
= NEXT_INSN (note
))
1029 if (GET_CODE (note
) != NOTE
&& GET_CODE (note
) != CODE_LABEL
)
1031 else if (GET_CODE (note
) == NOTE
&& NOTE_LINE_NUMBER (note
) > 0)
1033 /* Another note follows; we can delete this note provided
1034 no intervening line numbers have notes elsewhere. */
1036 for (num
= NOTE_LINE_NUMBER (insn
) + 1;
1037 num
< NOTE_LINE_NUMBER (note
);
1039 if (line_note_exists
[num
])
1042 if (num
== NOTE_LINE_NUMBER (note
))
1048 /* Output this line note
1049 if it is the first or the last line note in a row. */
1051 output_source_line (file
, insn
);
1056 #ifdef ASM_OUTPUT_ALIGN_CODE
1057 ASM_OUTPUT_ALIGN_CODE (file
);
1066 #ifdef SDB_DEBUGGING_INFO
1067 if (write_symbols
== SDB_DEBUG
&& LABEL_NAME (insn
))
1068 sdbout_label (insn
);
1070 #ifdef DWARF_DEBUGGING_INFO
1071 if (write_symbols
== DWARF_DEBUG
&& LABEL_NAME (insn
))
1072 dwarfout_label (insn
);
1076 fprintf (file
, ASM_APP_OFF
);
1079 if (NEXT_INSN (insn
) != 0
1080 && GET_CODE (NEXT_INSN (insn
)) == JUMP_INSN
)
1082 rtx nextbody
= PATTERN (NEXT_INSN (insn
));
1084 /* If this label is followed by a jump-table,
1085 make sure we put the label in the read-only section. Also
1086 possibly write the label and jump table together. */
1088 if (GET_CODE (nextbody
) == ADDR_VEC
1089 || GET_CODE (nextbody
) == ADDR_DIFF_VEC
)
1091 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1092 readonly_data_section ();
1096 #ifdef ASM_OUTPUT_CASE_LABEL
1097 ASM_OUTPUT_CASE_LABEL (file
, "L", CODE_LABEL_NUMBER (insn
),
1100 ASM_OUTPUT_INTERNAL_LABEL (file
, "L", CODE_LABEL_NUMBER (insn
));
1106 ASM_OUTPUT_INTERNAL_LABEL (file
, "L", CODE_LABEL_NUMBER (insn
));
1111 register rtx body
= PATTERN (insn
);
1112 int insn_code_number
;
1116 /* An INSN, JUMP_INSN or CALL_INSN.
1117 First check for special kinds that recog doesn't recognize. */
1119 if (GET_CODE (body
) == USE
/* These are just declarations */
1120 || GET_CODE (body
) == CLOBBER
)
1124 /* If there is a REG_CC_SETTER note on this insn, it means that
1125 the setting of the condition code was done in the delay slot
1126 of the insn that branched here. So recover the cc status
1127 from the insn that set it. */
1129 note
= find_reg_note (insn
, REG_CC_SETTER
, 0);
1132 NOTICE_UPDATE_CC (PATTERN (XEXP (note
, 0)), XEXP (note
, 0));
1133 cc_prev_status
= cc_status
;
1137 /* Detect insns that are really jump-tables
1138 and output them as such. */
1140 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
1142 register int vlen
, idx
;
1149 fprintf (file
, ASM_APP_OFF
);
1153 vlen
= XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
);
1154 for (idx
= 0; idx
< vlen
; idx
++)
1156 if (GET_CODE (body
) == ADDR_VEC
)
1157 ASM_OUTPUT_ADDR_VEC_ELT
1158 (file
, CODE_LABEL_NUMBER (XEXP (XVECEXP (body
, 0, idx
), 0)));
1160 ASM_OUTPUT_ADDR_DIFF_ELT
1162 CODE_LABEL_NUMBER (XEXP (XVECEXP (body
, 1, idx
), 0)),
1163 CODE_LABEL_NUMBER (XEXP (XEXP (body
, 0), 0)));
1165 #ifdef ASM_OUTPUT_CASE_END
1166 ASM_OUTPUT_CASE_END (file
,
1167 CODE_LABEL_NUMBER (PREV_INSN (insn
)),
1176 /* Do basic-block profiling when we reach a new block.
1177 Done here to avoid jump tables. */
1178 if (profile_block_flag
&& new_block
)
1181 /* Enable the table of basic-block use counts
1182 to point at the code it applies to. */
1183 ASM_OUTPUT_INTERNAL_LABEL (file
, "LPB", count_basic_blocks
);
1184 /* Before first insn of this basic block, increment the
1185 count of times it was entered. */
1186 #ifdef BLOCK_PROFILER
1187 BLOCK_PROFILER (file
, count_basic_blocks
);
1190 count_basic_blocks
++;
1193 if (GET_CODE (body
) == ASM_INPUT
)
1195 /* There's no telling what that did to the condition codes. */
1201 fprintf (file
, ASM_APP_ON
);
1204 fprintf (asm_out_file
, "\t%s\n", XSTR (body
, 0));
1208 /* Detect `asm' construct with operands. */
1209 if (asm_noperands (body
) >= 0)
1211 int noperands
= asm_noperands (body
);
1215 /* There's no telling what that did to the condition codes. */
1220 /* alloca won't do here, since only return from `final'
1223 ops
= (rtx
*) xmalloc (noperands
* sizeof (rtx
));
1227 fprintf (file
, ASM_APP_ON
);
1231 /* Get out the operand values. */
1232 string
= decode_asm_operands (body
, ops
, 0, 0, 0);
1233 /* Inhibit aborts on what would otherwise be compiler bugs. */
1234 insn_noperands
= noperands
;
1235 this_is_asm_operands
= insn
;
1236 /* Output the insn using them. */
1237 output_asm_insn (string
, ops
);
1238 this_is_asm_operands
= 0;
1244 if (prescan
<= 0 && app_on
)
1246 fprintf (file
, ASM_APP_OFF
);
1250 if (GET_CODE (body
) == SEQUENCE
)
1252 /* A delayed-branch sequence */
1258 final_sequence
= body
;
1260 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
1261 force the restoration of a comparison that was previously
1262 thought unnecessary. If that happens, cancel this sequence
1263 and cause that insn to be restored. */
1265 next
= final_scan_insn (XVECEXP (body
, 0, 0), file
, 0, prescan
, 1);
1266 if (next
!= XVECEXP (body
, 0, 1))
1272 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1273 final_scan_insn (XVECEXP (body
, 0, i
), file
, 0, prescan
, 1);
1274 #ifdef DBR_OUTPUT_SEQEND
1275 DBR_OUTPUT_SEQEND (file
);
1279 /* If the insn requiring the delay slot was a CALL_INSN, the
1280 insns in the delay slot are actually executed before the
1281 called function. Hence we don't preserve any CC-setting
1282 actions in these insns and the CC must be marked as being
1283 clobbered by the function. */
1284 if (GET_CODE (XVECEXP (body
, 0, 0)) == CALL_INSN
)
1289 /* We have a real machine instruction as rtl. */
1291 body
= PATTERN (insn
);
1294 /* Check for redundant test and compare instructions
1295 (when the condition codes are already set up as desired).
1296 This is done only when optimizing; if not optimizing,
1297 it should be possible for the user to alter a variable
1298 with the debugger in between statements
1299 and the next statement should reexamine the variable
1300 to compute the condition codes. */
1303 && GET_CODE (body
) == SET
1304 && GET_CODE (SET_DEST (body
)) == CC0
1305 && insn
!= last_ignored_compare
)
1307 if (GET_CODE (SET_SRC (body
)) == SUBREG
)
1308 SET_SRC (body
) = alter_subreg (SET_SRC (body
));
1309 else if (GET_CODE (SET_SRC (body
)) == COMPARE
)
1311 if (GET_CODE (XEXP (SET_SRC (body
), 0)) == SUBREG
)
1312 XEXP (SET_SRC (body
), 0)
1313 = alter_subreg (XEXP (SET_SRC (body
), 0));
1314 if (GET_CODE (XEXP (SET_SRC (body
), 1)) == SUBREG
)
1315 XEXP (SET_SRC (body
), 1)
1316 = alter_subreg (XEXP (SET_SRC (body
), 1));
1318 if ((cc_status
.value1
!= 0
1319 && rtx_equal_p (SET_SRC (body
), cc_status
.value1
))
1320 || (cc_status
.value2
!= 0
1321 && rtx_equal_p (SET_SRC (body
), cc_status
.value2
)))
1323 /* Don't delete insn if it has an addressing side-effect. */
1324 if (! FIND_REG_INC_NOTE (insn
, 0)
1325 /* or if anything in it is volatile. */
1326 && ! volatile_refs_p (PATTERN (insn
)))
1328 /* We don't really delete the insn; just ignore it. */
1329 last_ignored_compare
= insn
;
1336 /* Following a conditional branch, we have a new basic block. */
1337 if ((GET_CODE (insn
) == JUMP_INSN
&& GET_CODE (body
) == SET
1338 && GET_CODE (SET_SRC (body
)) != LABEL_REF
)
1339 || (GET_CODE (insn
) == JUMP_INSN
&& GET_CODE (body
) == PARALLEL
1340 && GET_CODE (XVECEXP (body
, 0, 0)) == SET
1341 && GET_CODE (SET_SRC (XVECEXP (body
, 0, 0))) != LABEL_REF
))
1345 /* Don't bother outputting obvious no-ops, even without -O.
1346 This optimization is fast and doesn't interfere with debugging.
1347 Don't do this if the insn is in a delay slot, since this
1348 will cause an improper number of delay insns to be written. */
1349 if (final_sequence
== 0
1351 && GET_CODE (insn
) == INSN
&& GET_CODE (body
) == SET
1352 && GET_CODE (SET_SRC (body
)) == REG
1353 && GET_CODE (SET_DEST (body
)) == REG
1354 && REGNO (SET_SRC (body
)) == REGNO (SET_DEST (body
)))
1359 /* If this is a conditional branch, maybe modify it
1360 if the cc's are in a nonstandard state
1361 so that it accomplishes the same thing that it would
1362 do straightforwardly if the cc's were set up normally. */
1364 if (cc_status
.flags
!= 0
1365 && GET_CODE (insn
) == JUMP_INSN
1366 && GET_CODE (body
) == SET
1367 && SET_DEST (body
) == pc_rtx
1368 && GET_CODE (SET_SRC (body
)) == IF_THEN_ELSE
1369 /* This is done during prescan; it is not done again
1370 in final scan when prescan has been done. */
1373 /* This function may alter the contents of its argument
1374 and clear some of the cc_status.flags bits.
1375 It may also return 1 meaning condition now always true
1376 or -1 meaning condition now always false
1377 or 2 meaning condition nontrivial but altered. */
1378 register int result
= alter_cond (XEXP (SET_SRC (body
), 0));
1379 /* If condition now has fixed value, replace the IF_THEN_ELSE
1380 with its then-operand or its else-operand. */
1382 SET_SRC (body
) = XEXP (SET_SRC (body
), 1);
1384 SET_SRC (body
) = XEXP (SET_SRC (body
), 2);
1386 /* The jump is now either unconditional or a no-op.
1387 If it has become a no-op, don't try to output it.
1388 (It would not be recognized.) */
1389 if (SET_SRC (body
) == pc_rtx
)
1391 PUT_CODE (insn
, NOTE
);
1392 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1393 NOTE_SOURCE_FILE (insn
) = 0;
1396 else if (GET_CODE (SET_SRC (body
)) == RETURN
)
1397 /* Replace (set (pc) (return)) with (return). */
1398 PATTERN (insn
) = body
= SET_SRC (body
);
1400 /* Rerecognize the instruction if it has changed. */
1402 INSN_CODE (insn
) = -1;
1405 /* Make same adjustments to instructions that examine the
1406 condition codes without jumping (if this machine has them). */
1408 if (cc_status
.flags
!= 0
1409 && GET_CODE (body
) == SET
)
1411 switch (GET_CODE (SET_SRC (body
)))
1424 register int result
;
1425 if (XEXP (SET_SRC (body
), 0) != cc0_rtx
)
1427 result
= alter_cond (SET_SRC (body
));
1429 validate_change (insn
, &SET_SRC (body
), const_true_rtx
, 0);
1430 else if (result
== -1)
1431 validate_change (insn
, &SET_SRC (body
), const0_rtx
, 0);
1432 else if (result
== 2)
1433 INSN_CODE (insn
) = -1;
1439 /* Do machine-specific peephole optimizations if desired. */
1441 if (optimize
&& !flag_no_peephole
&& !nopeepholes
)
1443 rtx next
= peephole (insn
);
1444 /* When peepholing, if there were notes within the peephole,
1445 emit them before the peephole. */
1446 if (next
!= 0 && next
!= NEXT_INSN (insn
))
1448 rtx prev
= PREV_INSN (insn
);
1451 for (note
= NEXT_INSN (insn
); note
!= next
;
1452 note
= NEXT_INSN (note
))
1453 final_scan_insn (note
, file
, optimize
, prescan
, nopeepholes
);
1455 /* In case this is prescan, put the notes
1456 in proper position for later rescan. */
1457 note
= NEXT_INSN (insn
);
1458 PREV_INSN (note
) = prev
;
1459 NEXT_INSN (prev
) = note
;
1460 NEXT_INSN (PREV_INSN (next
)) = insn
;
1461 PREV_INSN (insn
) = PREV_INSN (next
);
1462 NEXT_INSN (insn
) = next
;
1463 PREV_INSN (next
) = insn
;
1466 /* PEEPHOLE might have changed this. */
1467 body
= PATTERN (insn
);
1470 /* Try to recognize the instruction.
1471 If successful, verify that the operands satisfy the
1472 constraints for the instruction. Crash if they don't,
1473 since `reload' should have changed them so that they do. */
1475 insn_code_number
= recog_memoized (insn
);
1476 insn_extract (insn
);
1477 for (i
= 0; i
< insn_n_operands
[insn_code_number
]; i
++)
1479 if (GET_CODE (recog_operand
[i
]) == SUBREG
)
1480 recog_operand
[i
] = alter_subreg (recog_operand
[i
]);
1483 #ifdef REGISTER_CONSTRAINTS
1484 if (! constrain_operands (insn_code_number
, 1))
1485 fatal_insn_not_found (insn
);
1488 /* Some target machines need to prescan each insn before
1491 #ifdef FINAL_PRESCAN_INSN
1492 FINAL_PRESCAN_INSN (insn
, recog_operand
,
1493 insn_n_operands
[insn_code_number
]);
1497 cc_prev_status
= cc_status
;
1499 /* Update `cc_status' for this instruction.
1500 The instruction's output routine may change it further.
1501 If the output routine for a jump insn needs to depend
1502 on the cc status, it should look at cc_prev_status. */
1504 NOTICE_UPDATE_CC (body
, insn
);
1509 /* If the proper template needs to be chosen by some C code,
1510 run that code and get the real template. */
1512 template = insn_template
[insn_code_number
];
1515 template = (*insn_outfun
[insn_code_number
]) (recog_operand
, insn
);
1517 /* If the C code returns 0, it means that it is a jump insn
1518 which follows a deleted test insn, and that test insn
1519 needs to be reinserted. */
1522 if (prev_nonnote_insn (insn
) != last_ignored_compare
)
1525 return prev_nonnote_insn (insn
);
1529 /* If the template is the string "#", it means that this insn must
1531 if (template[0] == '#' && template[1] == '\0')
1533 rtx
new = try_split (body
, insn
, 0);
1535 /* If we didn't split the insn, go away. */
1536 if (new == insn
&& PATTERN (new) == body
)
1546 /* Output assembler code from the template. */
1548 output_asm_insn (template, recog_operand
);
1551 /* It's not at all clear why we did this and doing so interferes
1552 with tests we'd like to do to use REG_WAS_0 notes, so let's try
1555 /* Mark this insn as having been output. */
1556 INSN_DELETED_P (insn
) = 1;
1562 return NEXT_INSN (insn
);
1565 /* Output debugging info to the assembler file FILE
1566 based on the NOTE-insn INSN, assumed to be a line number. */
1569 output_source_line (file
, insn
)
1573 char ltext_label_name
[100];
1574 register char *filename
= NOTE_SOURCE_FILE (insn
);
1576 last_linenum
= NOTE_LINE_NUMBER (insn
);
1578 if (write_symbols
!= NO_DEBUG
)
1580 #ifdef SDB_DEBUGGING_INFO
1581 if (write_symbols
== SDB_DEBUG
1582 #if 0 /* People like having line numbers even in wrong file! */
1583 /* COFF can't handle multiple source files--lose, lose. */
1584 && !strcmp (filename
, main_input_filename
)
1586 /* COFF relative line numbers must be positive. */
1587 && last_linenum
> sdb_begin_function_line
)
1589 #ifdef ASM_OUTPUT_SOURCE_LINE
1590 ASM_OUTPUT_SOURCE_LINE (file
, last_linenum
);
1592 fprintf (file
, "\t.ln\t%d\n",
1593 ((sdb_begin_function_line
> -1)
1594 ? last_linenum
- sdb_begin_function_line
: 1));
1599 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1600 if (write_symbols
== DBX_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
1602 dbxout_source_file (file
, filename
);
1604 #ifdef ASM_OUTPUT_SOURCE_LINE
1605 ASM_OUTPUT_SOURCE_LINE (file
, NOTE_LINE_NUMBER (insn
));
1607 fprintf (file
, "\t%s %d,0,%d\n", ASM_STABD_OP
,
1608 N_SLINE
, NOTE_LINE_NUMBER (insn
));
1611 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
1613 #ifdef DWARF_DEBUGGING_INFO
1614 if (write_symbols
== DWARF_DEBUG
)
1615 dwarfout_line (filename
, NOTE_LINE_NUMBER (insn
));
1620 /* If X is a SUBREG, replace it with a REG or a MEM,
1621 based on the thing it is a subreg of. */
1627 register rtx y
= SUBREG_REG (x
);
1628 if (GET_CODE (y
) == SUBREG
)
1629 y
= alter_subreg (y
);
1631 if (GET_CODE (y
) == REG
)
1633 /* If the containing reg really gets a hard reg, so do we. */
1635 REGNO (x
) = REGNO (y
) + SUBREG_WORD (x
);
1637 else if (GET_CODE (y
) == MEM
)
1639 register int offset
= SUBREG_WORD (x
) * UNITS_PER_WORD
;
1640 #if BYTES_BIG_ENDIAN
1641 offset
-= (MIN (UNITS_PER_WORD
, GET_MODE_SIZE (GET_MODE (x
)))
1642 - MIN (UNITS_PER_WORD
, GET_MODE_SIZE (GET_MODE (y
))));
1645 MEM_VOLATILE_P (x
) = MEM_VOLATILE_P (y
);
1646 XEXP (x
, 0) = plus_constant (XEXP (y
, 0), offset
);
1652 /* Do alter_subreg on all the SUBREGs contained in X. */
1655 walk_alter_subreg (x
)
1658 switch (GET_CODE (x
))
1662 XEXP (x
, 0) = walk_alter_subreg (XEXP (x
, 0));
1663 XEXP (x
, 1) = walk_alter_subreg (XEXP (x
, 1));
1667 XEXP (x
, 0) = walk_alter_subreg (XEXP (x
, 0));
1671 return alter_subreg (x
);
1679 /* Given BODY, the body of a jump instruction, alter the jump condition
1680 as required by the bits that are set in cc_status.flags.
1681 Not all of the bits there can be handled at this level in all cases.
1683 The value is normally 0.
1684 1 means that the condition has become always true.
1685 -1 means that the condition has become always false.
1686 2 means that COND has been altered. */
1694 if (cc_status
.flags
& CC_REVERSED
)
1697 PUT_CODE (cond
, swap_condition (GET_CODE (cond
)));
1700 if (cc_status
.flags
& CC_INVERTED
)
1703 PUT_CODE (cond
, reverse_condition (GET_CODE (cond
)));
1706 if (cc_status
.flags
& CC_NOT_POSITIVE
)
1707 switch (GET_CODE (cond
))
1712 /* Jump becomes unconditional. */
1718 /* Jump becomes no-op. */
1722 PUT_CODE (cond
, EQ
);
1727 PUT_CODE (cond
, NE
);
1732 if (cc_status
.flags
& CC_NOT_NEGATIVE
)
1733 switch (GET_CODE (cond
))
1737 /* Jump becomes unconditional. */
1742 /* Jump becomes no-op. */
1747 PUT_CODE (cond
, EQ
);
1753 PUT_CODE (cond
, NE
);
1758 if (cc_status
.flags
& CC_NO_OVERFLOW
)
1759 switch (GET_CODE (cond
))
1762 /* Jump becomes unconditional. */
1766 PUT_CODE (cond
, EQ
);
1771 PUT_CODE (cond
, NE
);
1776 /* Jump becomes no-op. */
1780 if (cc_status
.flags
& (CC_Z_IN_NOT_N
| CC_Z_IN_N
))
1781 switch (GET_CODE (cond
))
1794 PUT_CODE (cond
, cc_status
.flags
& CC_Z_IN_N
? GE
: LT
);
1799 PUT_CODE (cond
, cc_status
.flags
& CC_Z_IN_N
? LT
: GE
);
1808 /* Report inconsistency between the assembler template and the operands.
1809 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
1812 output_operand_lossage (str
)
1815 if (this_is_asm_operands
)
1816 error_for_asm (this_is_asm_operands
, "invalid `asm': %s", str
);
1821 /* Output of assembler code from a template, and its subroutines. */
1823 /* Output text from TEMPLATE to the assembler output file,
1824 obeying %-directions to substitute operands taken from
1825 the vector OPERANDS.
1827 %N (for N a digit) means print operand N in usual manner.
1828 %lN means require operand N to be a CODE_LABEL or LABEL_REF
1829 and print the label name with no punctuation.
1830 %cN means require operand N to be a constant
1831 and print the constant expression with no punctuation.
1832 %aN means expect operand N to be a memory address
1833 (not a memory reference!) and print a reference
1835 %nN means expect operand N to be a constant
1836 and print a constant expression for minus the value
1837 of the operand, with no other punctuation. */
1840 output_asm_insn (template, operands
)
1847 /* An insn may return a null string template
1848 in a case where no assembler code is needed. */
1853 putc ('\t', asm_out_file
);
1855 #ifdef ASM_OUTPUT_OPCODE
1856 ASM_OUTPUT_OPCODE (asm_out_file
, p
);
1861 #ifdef ASM_OUTPUT_OPCODE
1864 putc (c
, asm_out_file
);
1865 while ((c
= *p
) == '\t')
1867 putc (c
, asm_out_file
);
1870 ASM_OUTPUT_OPCODE (asm_out_file
, p
);
1875 putc (c
, asm_out_file
);
1878 /* %% outputs a single %. */
1882 putc (c
, asm_out_file
);
1884 /* %= outputs a number which is unique to each insn in the entire
1885 compilation. This is useful for making local labels that are
1886 referred to more than once in a given insn. */
1888 fprintf (asm_out_file
, "%d", insn_counter
);
1889 /* % followed by a letter and some digits
1890 outputs an operand in a special way depending on the letter.
1891 Letters `acln' are implemented directly.
1892 Other letters are passed to `output_operand' so that
1893 the PRINT_OPERAND macro can define them. */
1894 else if ((*p
>= 'a' && *p
<= 'z')
1895 || (*p
>= 'A' && *p
<= 'Z'))
1900 if (! (*p
>= '0' && *p
<= '9'))
1901 output_operand_lossage ("operand number missing after %-letter");
1902 else if (this_is_asm_operands
&& c
>= (unsigned) insn_noperands
)
1903 output_operand_lossage ("operand number out of range");
1904 else if (letter
== 'l')
1905 output_asm_label (operands
[c
]);
1906 else if (letter
== 'a')
1907 output_address (operands
[c
]);
1908 else if (letter
== 'c')
1910 if (CONSTANT_ADDRESS_P (operands
[c
]))
1911 output_addr_const (asm_out_file
, operands
[c
]);
1913 output_operand (operands
[c
], 'c');
1915 else if (letter
== 'n')
1917 if (GET_CODE (operands
[c
]) == CONST_INT
)
1918 fprintf (asm_out_file
, "%d", - INTVAL (operands
[c
]));
1921 putc ('-', asm_out_file
);
1922 output_addr_const (asm_out_file
, operands
[c
]);
1926 output_operand (operands
[c
], letter
);
1928 while ((c
= *p
) >= '0' && c
<= '9') p
++;
1930 /* % followed by a digit outputs an operand the default way. */
1931 else if (*p
>= '0' && *p
<= '9')
1934 if (this_is_asm_operands
&& c
>= (unsigned) insn_noperands
)
1935 output_operand_lossage ("operand number out of range");
1937 output_operand (operands
[c
], 0);
1938 while ((c
= *p
) >= '0' && c
<= '9') p
++;
1940 /* % followed by punctuation: output something for that
1941 punctuation character alone, with no operand.
1942 The PRINT_OPERAND macro decides what is actually done. */
1943 #ifdef PRINT_OPERAND_PUNCT_VALID_P
1944 else if (PRINT_OPERAND_PUNCT_VALID_P (*p
))
1945 output_operand (0, *p
++);
1948 output_operand_lossage ("invalid %%-code");
1952 if (flag_print_asm_name
)
1954 /* Annotate the assembly with a comment describing the pattern and
1955 alternative used. */
1958 register int num
= INSN_CODE (debug_insn
);
1959 fprintf (asm_out_file
, " %s %d %s",
1960 ASM_COMMENT_START
, INSN_UID (debug_insn
), insn_name
[num
]);
1961 if (insn_n_alternatives
[num
] > 1)
1962 fprintf (asm_out_file
, "/%d", which_alternative
+ 1);
1964 /* Clear this so only the first assembler insn
1965 of any rtl insn will get the special comment for -dp. */
1970 putc ('\n', asm_out_file
);
1973 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
1976 output_asm_label (x
)
1981 if (GET_CODE (x
) == LABEL_REF
)
1982 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (XEXP (x
, 0)));
1983 else if (GET_CODE (x
) == CODE_LABEL
)
1984 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (x
));
1986 output_operand_lossage ("`%l' operand isn't a label");
1988 assemble_name (asm_out_file
, buf
);
1991 /* Print operand X using machine-dependent assembler syntax.
1992 The macro PRINT_OPERAND is defined just to control this function.
1993 CODE is a non-digit that preceded the operand-number in the % spec,
1994 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
1995 between the % and the digits.
1996 When CODE is a non-letter, X is 0.
1998 The meanings of the letters are machine-dependent and controlled
1999 by PRINT_OPERAND. */
2002 output_operand (x
, code
)
2006 if (x
&& GET_CODE (x
) == SUBREG
)
2007 x
= alter_subreg (x
);
2008 PRINT_OPERAND (asm_out_file
, x
, code
);
2011 /* Print a memory reference operand for address X
2012 using machine-dependent assembler syntax.
2013 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
2019 walk_alter_subreg (x
);
2020 PRINT_OPERAND_ADDRESS (asm_out_file
, x
);
2023 /* Print an integer constant expression in assembler syntax.
2024 Addition and subtraction are the only arithmetic
2025 that may appear in these expressions. */
2028 output_addr_const (file
, x
)
2035 switch (GET_CODE (x
))
2045 assemble_name (file
, XSTR (x
, 0));
2049 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (XEXP (x
, 0)));
2050 assemble_name (asm_out_file
, buf
);
2054 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (x
));
2055 assemble_name (asm_out_file
, buf
);
2059 fprintf (file
, "%d", INTVAL (x
));
2063 /* This used to output parentheses around the expression,
2064 but that does not work on the 386 (either ATT or BSD assembler). */
2065 output_addr_const (file
, XEXP (x
, 0));
2069 if (GET_MODE (x
) == VOIDmode
)
2071 /* We can use %d if the number is <32 bits and positive. */
2072 if (CONST_DOUBLE_HIGH (x
) || CONST_DOUBLE_LOW (x
) < 0)
2073 fprintf (file
, "0x%x%08x",
2074 CONST_DOUBLE_HIGH (x
), CONST_DOUBLE_LOW (x
));
2076 fprintf (file
, "%d", CONST_DOUBLE_LOW (x
));
2079 /* We can't handle floating point constants;
2080 PRINT_OPERAND must handle them. */
2081 output_operand_lossage ("floating constant misused");
2085 /* Some assemblers need integer constants to appear last (eg masm). */
2086 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
2088 output_addr_const (file
, XEXP (x
, 1));
2089 if (INTVAL (XEXP (x
, 0)) >= 0)
2090 fprintf (file
, "+");
2091 output_addr_const (file
, XEXP (x
, 0));
2095 output_addr_const (file
, XEXP (x
, 0));
2096 if (INTVAL (XEXP (x
, 1)) >= 0)
2097 fprintf (file
, "+");
2098 output_addr_const (file
, XEXP (x
, 1));
2103 output_addr_const (file
, XEXP (x
, 0));
2104 fprintf (file
, "-");
2105 output_addr_const (file
, XEXP (x
, 1));
2109 output_operand_lossage ("invalid expression as operand");
2113 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
2114 %R prints the value of REGISTER_PREFIX.
2115 %L prints the value of LOCAL_LABEL_PREFIX.
2116 %U prints the value of USER_LABEL_PREFIX.
2117 %I prints the value of IMMEDIATE_PREFIX.
2118 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
2119 Also supported are %d, %x, %s, %e, %f, %g and %%. */
2122 asm_fprintf (va_alist
)
2132 file
= va_arg (argptr
, FILE *);
2133 p
= va_arg (argptr
, char *);
2142 while ((c
>= '0' && c
<= '9') || c
== '.')
2150 fprintf (file
, "%%");
2153 case 'd': case 'i': case 'u':
2154 case 'x': case 'p': case 'X':
2158 fprintf (file
, buf
, va_arg (argptr
, int));
2166 fprintf (file
, buf
, va_arg (argptr
, double));
2172 fprintf (file
, buf
, va_arg (argptr
, char *));
2176 #ifdef ASM_OUTPUT_OPCODE
2177 ASM_OUTPUT_OPCODE (asm_out_file
, p
);
2182 #ifdef REGISTER_PREFIX
2183 fprintf (file
, "%s", REGISTER_PREFIX
);
2188 #ifdef IMMEDIATE_PREFIX
2189 fprintf (file
, "%s", IMMEDIATE_PREFIX
);
2194 #ifdef LOCAL_LABEL_PREFIX
2195 fprintf (file
, "%s", LOCAL_LABEL_PREFIX
);
2200 #ifdef USER_LABEL_PREFIX
2201 fprintf (file
, "%s", USER_LABEL_PREFIX
);
2215 /* Split up a CONST_DOUBLE or integer constant rtx
2216 into two rtx's for single words,
2217 storing in *FIRST the word that comes first in memory in the target
2218 and in *SECOND the other. */
2221 split_double (value
, first
, second
)
2223 rtx
*first
, *second
;
2225 if (GET_CODE (value
) == CONST_INT
)
2227 /* The rule for using CONST_INT for a wider mode
2228 is that we regard the value as signed.
2229 So sign-extend it. */
2230 rtx high
= (INTVAL (value
) < 0 ? constm1_rtx
: const0_rtx
);
2231 #if WORDS_BIG_ENDIAN
2239 else if (GET_CODE (value
) != CONST_DOUBLE
)
2241 #if WORDS_BIG_ENDIAN
2242 *first
= const0_rtx
;
2246 *second
= const0_rtx
;
2249 else if (GET_MODE (value
) == VOIDmode
2250 /* This is the old way we did CONST_DOUBLE integers. */
2251 || GET_MODE_CLASS (GET_MODE (value
)) == MODE_INT
)
2253 /* In an integer, the words are defined as most and least significant.
2254 So order them by the target's convention. */
2255 #if WORDS_BIG_ENDIAN
2256 *first
= gen_rtx (CONST_INT
, VOIDmode
, CONST_DOUBLE_HIGH (value
));
2257 *second
= gen_rtx (CONST_INT
, VOIDmode
, CONST_DOUBLE_LOW (value
));
2259 *first
= gen_rtx (CONST_INT
, VOIDmode
, CONST_DOUBLE_LOW (value
));
2260 *second
= gen_rtx (CONST_INT
, VOIDmode
, CONST_DOUBLE_HIGH (value
));
2265 if ((HOST_FLOAT_FORMAT
!= TARGET_FLOAT_FORMAT
2266 || HOST_BITS_PER_INT
!= BITS_PER_WORD
)
2267 && ! flag_pretend_float
)
2270 #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
2271 /* Host and target agree => no need to swap. */
2272 *first
= gen_rtx (CONST_INT
, VOIDmode
, CONST_DOUBLE_LOW (value
));
2273 *second
= gen_rtx (CONST_INT
, VOIDmode
, CONST_DOUBLE_HIGH (value
));
2275 *second
= gen_rtx (CONST_INT
, VOIDmode
, CONST_DOUBLE_LOW (value
));
2276 *first
= gen_rtx (CONST_INT
, VOIDmode
, CONST_DOUBLE_HIGH (value
));
2281 /* Return nonzero if this function has no function calls. */
2288 if (profile_flag
|| profile_block_flag
)
2291 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
2293 if (GET_CODE (insn
) == CALL_INSN
)
2295 if (GET_CODE (insn
) == INSN
2296 && GET_CODE (PATTERN (insn
)) == SEQUENCE
2297 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == CALL_INSN
)
2300 for (insn
= current_function_epilogue_delay_list
; insn
; insn
= XEXP (insn
, 1))
2302 if (GET_CODE (XEXP (insn
, 0)) == CALL_INSN
)
2304 if (GET_CODE (XEXP (insn
, 0)) == INSN
2305 && GET_CODE (PATTERN (XEXP (insn
, 0))) == SEQUENCE
2306 && GET_CODE (XVECEXP (PATTERN (XEXP (insn
, 0)), 0, 0)) == CALL_INSN
)
2313 /* On some machines, a function with no call insns
2314 can run faster if it doesn't create its own register window.
2315 When output, the leaf function should use only the "output"
2316 registers. Ordinarily, the function would be compiled to use
2317 the "input" registers to find its arguments; it is a candidate
2318 for leaf treatment if it uses only the "input" registers.
2319 Leaf function treatment means renumbering so the function
2320 uses the "output" registers instead. */
2322 #ifdef LEAF_REGISTERS
2324 static char permitted_reg_in_leaf_functions
[] = LEAF_REGISTERS
;
2326 /* Return 1 if this function uses only the registers that can be
2327 safely renumbered. */
2330 only_leaf_regs_used ()
2334 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2336 if (regs_ever_live
[i
] > permitted_reg_in_leaf_functions
[i
])
2342 /* Scan all instructions and renumber all registers into those
2343 available in leaf functions. */
2346 leaf_renumber_regs (first
)
2351 /* Renumber only the actual patterns.
2352 The reg-notes can contain frame pointer refs,
2353 and renumbering them could crash, and should not be needed. */
2354 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
2355 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
2356 leaf_renumber_regs_insn (PATTERN (insn
));
2357 for (insn
= current_function_epilogue_delay_list
; insn
; insn
= XEXP (insn
, 1))
2358 if (GET_RTX_CLASS (GET_CODE (XEXP (insn
, 0))) == 'i')
2359 leaf_renumber_regs_insn (PATTERN (XEXP (insn
, 0)));
2362 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
2363 available in leaf functions. */
2366 leaf_renumber_regs_insn (in_rtx
)
2367 register rtx in_rtx
;
2370 register char *format_ptr
;
2375 /* Renumber all input-registers into output-registers.
2376 renumbered_regs would be 1 for an output-register;
2379 if (GET_CODE (in_rtx
) == REG
)
2383 /* Don't renumber the same reg twice. */
2387 newreg
= REGNO (in_rtx
);
2388 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
2389 to reach here as part of a REG_NOTE. */
2390 if (newreg
>= FIRST_PSEUDO_REGISTER
)
2395 newreg
= LEAF_REG_REMAP (newreg
);
2398 regs_ever_live
[REGNO (in_rtx
)] = 0;
2399 regs_ever_live
[newreg
] = 1;
2400 REGNO (in_rtx
) = newreg
;
2404 if (GET_RTX_CLASS (GET_CODE (in_rtx
)) == 'i')
2406 /* Inside a SEQUENCE, we find insns.
2407 Renumber just the patterns of these insns,
2408 just as we do for the top-level insns. */
2409 leaf_renumber_regs_insn (PATTERN (in_rtx
));
2413 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
));
2415 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
2416 switch (*format_ptr
++)
2419 leaf_renumber_regs_insn (XEXP (in_rtx
, i
));
2423 if (NULL
!= XVEC (in_rtx
, i
))
2425 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
2426 leaf_renumber_regs_insn (XVECEXP (in_rtx
, i
, j
));