1 /* Convert RTL to assembler code and output it, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-97, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This is the final pass of the compiler.
23 It looks at the rtl code for a function and outputs assembler code.
25 Call `final_start_function' to output the assembler code for function entry,
26 `final' to output assembler code for some RTL code,
27 `final_end_function' to output assembler code for function exit.
28 If a function is compiled in several pieces, each piece is
29 output separately with `final'.
31 Some optimizations are also done at this level.
32 Move instructions that were made unnecessary by good register allocation
33 are detected and omitted from the output. (Though most of these
34 are removed by the last jump pass.)
36 Instructions to set the condition codes are omitted when it can be
37 seen that the condition codes already had the desired values.
39 In some cases it is sufficient if the inherited condition codes
40 have related values, but this may require the following insn
41 (the one that tests the condition codes) to be modified.
43 The code for the function prologue and epilogue are generated
44 directly as assembler code by the macros FUNCTION_PROLOGUE and
45 FUNCTION_EPILOGUE. Those instructions never exist as rtl. */
58 #include "insn-config.h"
59 #include "insn-flags.h"
60 #include "insn-attr.h"
61 #include "insn-codes.h"
63 #include "conditions.h"
66 #include "hard-reg-set.h"
71 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist. */
72 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
73 #if defined (USG) || defined (NO_STAB_H)
74 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
76 #include <stab.h> /* On BSD, use the system's stab.h. */
78 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
80 #ifdef XCOFF_DEBUGGING_INFO
84 /* .stabd code for line number. */
89 /* .stabs code for included file name. */
95 #define INT_TYPE_SIZE BITS_PER_WORD
98 #ifndef LONG_TYPE_SIZE
99 #define LONG_TYPE_SIZE BITS_PER_WORD
102 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
103 null default for it to save conditionalization later. */
104 #ifndef CC_STATUS_INIT
105 #define CC_STATUS_INIT
108 /* How to start an assembler comment. */
109 #ifndef ASM_COMMENT_START
110 #define ASM_COMMENT_START ";#"
113 /* Is the given character a logical line separator for the assembler? */
114 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
115 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
118 /* Nonzero means this function is a leaf function, with no function calls.
119 This variable exists to be examined in FUNCTION_PROLOGUE
120 and FUNCTION_EPILOGUE. Always zero, unless set by some action. */
123 /* Last insn processed by final_scan_insn. */
124 static rtx debug_insn
= 0;
126 /* Line number of last NOTE. */
127 static int last_linenum
;
129 /* Highest line number in current block. */
130 static int high_block_linenum
;
132 /* Likewise for function. */
133 static int high_function_linenum
;
135 /* Filename of last NOTE. */
136 static char *last_filename
;
138 /* Number of basic blocks seen so far;
139 used if profile_block_flag is set. */
140 static int count_basic_blocks
;
142 /* Number of instrumented arcs when profile_arc_flag is set. */
143 extern int count_instrumented_arcs
;
145 extern int length_unit_log
; /* This is defined in insn-attrtab.c. */
147 /* Nonzero while outputting an `asm' with operands.
148 This means that inconsistencies are the user's fault, so don't abort.
149 The precise value is the insn being output, to pass to error_for_asm. */
150 static rtx this_is_asm_operands
;
152 /* Number of operands of this insn, for an `asm' with operands. */
153 static unsigned int insn_noperands
;
155 /* Compare optimization flag. */
157 static rtx last_ignored_compare
= 0;
159 /* Flag indicating this insn is the start of a new basic block. */
161 static int new_block
= 1;
163 /* All the symbol-blocks (levels of scoping) in the compilation
164 are assigned sequence numbers in order of appearance of the
165 beginnings of the symbol-blocks. Both final and dbxout do this,
166 and assume that they will both give the same number to each block.
167 Final uses these sequence numbers to generate assembler label names
168 LBBnnn and LBEnnn for the beginning and end of the symbol-block.
169 Dbxout uses the sequence numbers to generate references to the same labels
170 from the dbx debugging information.
172 Sdb records this level at the beginning of each function,
173 in order to find the current level when recursing down declarations.
174 It outputs the block beginning and endings
175 at the point in the asm file where the blocks would begin and end. */
177 int next_block_index
;
179 /* Assign a unique number to each insn that is output.
180 This can be used to generate unique local labels. */
182 static int insn_counter
= 0;
185 /* This variable contains machine-dependent flags (defined in tm.h)
186 set and examined by output routines
187 that describe how to interpret the condition codes properly. */
191 /* During output of an insn, this contains a copy of cc_status
192 from before the insn. */
194 CC_STATUS cc_prev_status
;
197 /* Indexed by hardware reg number, is 1 if that register is ever
198 used in the current function.
200 In life_analysis, or in stupid_life_analysis, this is set
201 up to record the hard regs used explicitly. Reload adds
202 in the hard regs used for holding pseudo regs. Final uses
203 it to generate the code in the function prologue and epilogue
204 to save and restore registers as needed. */
206 char regs_ever_live
[FIRST_PSEUDO_REGISTER
];
208 /* Nonzero means current function must be given a frame pointer.
209 Set in stmt.c if anything is allocated on the stack there.
210 Set in reload1.c if anything is allocated on the stack there. */
212 int frame_pointer_needed
;
214 /* Assign unique numbers to labels generated for profiling. */
216 int profile_label_no
;
218 /* Length so far allocated in PENDING_BLOCKS. */
220 static int max_block_depth
;
222 /* Stack of sequence numbers of symbol-blocks of which we have seen the
223 beginning but not yet the end. Sequence numbers are assigned at
224 the beginning; this stack allows us to find the sequence number
225 of a block that is ending. */
227 static int *pending_blocks
;
229 /* Number of elements currently in use in PENDING_BLOCKS. */
231 static int block_depth
;
233 /* Nonzero if have enabled APP processing of our assembler output. */
237 /* If we are outputting an insn sequence, this contains the sequence rtx.
242 #ifdef ASSEMBLER_DIALECT
244 /* Number of the assembler dialect to use, starting at 0. */
245 static int dialect_number
;
248 /* Indexed by line number, nonzero if there is a note for that line. */
250 static char *line_note_exists
;
252 /* Linked list to hold line numbers for each basic block. */
255 struct bb_list
*next
; /* pointer to next basic block */
256 int line_num
; /* line number */
257 int file_label_num
; /* LPBC<n> label # for stored filename */
258 int func_label_num
; /* LPBC<n> label # for stored function name */
261 static struct bb_list
*bb_head
= 0; /* Head of basic block list */
262 static struct bb_list
**bb_tail
= &bb_head
; /* Ptr to store next bb ptr */
263 static int bb_file_label_num
= -1; /* Current label # for file */
264 static int bb_func_label_num
= -1; /* Current label # for func */
266 /* Linked list to hold the strings for each file and function name output. */
269 struct bb_str
*next
; /* pointer to next string */
270 char *string
; /* string */
271 int label_num
; /* label number */
272 int length
; /* string length */
275 extern rtx peephole
PROTO((rtx
));
277 static struct bb_str
*sbb_head
= 0; /* Head of string list. */
278 static struct bb_str
**sbb_tail
= &sbb_head
; /* Ptr to store next bb str */
279 static int sbb_label_num
= 0; /* Last label used */
281 #ifdef HAVE_ATTR_length
282 static int asm_insn_count
PROTO((rtx
));
284 static void profile_function
PROTO((FILE *));
285 static void profile_after_prologue
PROTO((FILE *));
286 static void add_bb
PROTO((FILE *));
287 static int add_bb_string
PROTO((char *, int));
288 static void output_source_line
PROTO((FILE *, rtx
));
289 static rtx walk_alter_subreg
PROTO((rtx
));
290 static void output_asm_name
PROTO((void));
291 static void output_operand
PROTO((rtx
, int));
292 #ifdef LEAF_REGISTERS
293 static void leaf_renumber_regs
PROTO((rtx
));
296 static int alter_cond
PROTO((rtx
));
299 extern char *getpwd ();
301 /* Initialize data in final at the beginning of a compilation. */
304 init_final (filename
)
307 next_block_index
= 2;
309 max_block_depth
= 20;
310 pending_blocks
= (int *) xmalloc (20 * sizeof *pending_blocks
);
313 #ifdef ASSEMBLER_DIALECT
314 dialect_number
= ASSEMBLER_DIALECT
;
318 /* Called at end of source file,
319 to output the block-profiling table for this entire compilation. */
327 if (profile_block_flag
|| profile_arc_flag
)
330 int align
= exact_log2 (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
);
334 int long_bytes
= LONG_TYPE_SIZE
/ BITS_PER_UNIT
;
335 int pointer_bytes
= POINTER_SIZE
/ BITS_PER_UNIT
;
337 if (profile_block_flag
)
338 size
= long_bytes
* count_basic_blocks
;
340 size
= long_bytes
* count_instrumented_arcs
;
343 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
344 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
345 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
349 /* Output the main header, of 11 words:
350 0: 1 if this file is initialized, else 0.
351 1: address of file name (LPBX1).
352 2: address of table of counts (LPBX2).
353 3: number of counts in the table.
354 4: always 0, for compatibility with Sun.
356 The following are GNU extensions:
358 5: address of table of start addrs of basic blocks (LPBX3).
359 6: Number of bytes in this header.
360 7: address of table of function names (LPBX4).
361 8: address of table of line numbers (LPBX5) or 0.
362 9: address of table of file names (LPBX6) or 0.
363 10: space reserved for basic block profiling. */
365 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
367 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LPBX", 0);
369 assemble_integer (const0_rtx
, long_bytes
, 1);
371 /* address of filename */
372 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 1);
373 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, name
), pointer_bytes
, 1);
375 /* address of count table */
376 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 2);
377 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, name
), pointer_bytes
, 1);
379 /* count of the # of basic blocks or # of instrumented arcs */
380 if (profile_block_flag
)
381 assemble_integer (GEN_INT (count_basic_blocks
), long_bytes
, 1);
383 assemble_integer (GEN_INT (count_instrumented_arcs
), long_bytes
,
386 /* zero word (link field) */
387 assemble_integer (const0_rtx
, pointer_bytes
, 1);
389 /* address of basic block start address table */
390 if (profile_block_flag
)
392 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 3);
393 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, name
), pointer_bytes
,
397 assemble_integer (const0_rtx
, pointer_bytes
, 1);
399 /* byte count for extended structure. */
400 assemble_integer (GEN_INT (10 * UNITS_PER_WORD
), long_bytes
, 1);
402 /* address of function name table */
403 if (profile_block_flag
)
405 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 4);
406 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, name
), pointer_bytes
,
410 assemble_integer (const0_rtx
, pointer_bytes
, 1);
412 /* address of line number and filename tables if debugging. */
413 if (write_symbols
!= NO_DEBUG
&& profile_block_flag
)
415 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 5);
416 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, name
), pointer_bytes
, 1);
417 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 6);
418 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, name
), pointer_bytes
, 1);
422 assemble_integer (const0_rtx
, pointer_bytes
, 1);
423 assemble_integer (const0_rtx
, pointer_bytes
, 1);
426 /* space for extension ptr (link field) */
427 assemble_integer (const0_rtx
, UNITS_PER_WORD
, 1);
429 /* Output the file name changing the suffix to .d for Sun tcov
431 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LPBX", 1);
433 char *cwd
= getpwd ();
434 int len
= strlen (filename
) + strlen (cwd
) + 1;
435 char *data_file
= (char *) alloca (len
+ 4);
437 strcpy (data_file
, cwd
);
438 strcat (data_file
, "/");
439 strcat (data_file
, filename
);
440 strip_off_ending (data_file
, len
);
441 if (profile_block_flag
)
442 strcat (data_file
, ".d");
444 strcat (data_file
, ".da");
445 assemble_string (data_file
, strlen (data_file
) + 1);
448 /* Make space for the table of counts. */
451 /* Realign data section. */
452 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
453 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LPBX", 2);
455 assemble_zeros (size
);
459 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 2);
460 #ifdef ASM_OUTPUT_SHARED_LOCAL
461 if (flag_shared_data
)
462 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
465 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
466 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
469 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
470 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
,
473 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
478 /* Output any basic block strings */
479 if (profile_block_flag
)
481 readonly_data_section ();
484 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
485 for (sptr
= sbb_head
; sptr
!= 0; sptr
= sptr
->next
)
487 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LPBC",
489 assemble_string (sptr
->string
, sptr
->length
);
494 /* Output the table of addresses. */
495 if (profile_block_flag
)
497 /* Realign in new section */
498 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
499 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LPBX", 3);
500 for (i
= 0; i
< count_basic_blocks
; i
++)
502 ASM_GENERATE_INTERNAL_LABEL (name
, "LPB", i
);
503 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, name
),
508 /* Output the table of function names. */
509 if (profile_block_flag
)
511 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LPBX", 4);
512 for ((ptr
= bb_head
), (i
= 0); ptr
!= 0; (ptr
= ptr
->next
), i
++)
514 if (ptr
->func_label_num
>= 0)
516 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBC",
517 ptr
->func_label_num
);
518 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, name
),
522 assemble_integer (const0_rtx
, pointer_bytes
, 1);
525 for ( ; i
< count_basic_blocks
; i
++)
526 assemble_integer (const0_rtx
, pointer_bytes
, 1);
529 if (write_symbols
!= NO_DEBUG
&& profile_block_flag
)
531 /* Output the table of line numbers. */
532 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LPBX", 5);
533 for ((ptr
= bb_head
), (i
= 0); ptr
!= 0; (ptr
= ptr
->next
), i
++)
534 assemble_integer (GEN_INT (ptr
->line_num
), long_bytes
, 1);
536 for ( ; i
< count_basic_blocks
; i
++)
537 assemble_integer (const0_rtx
, long_bytes
, 1);
539 /* Output the table of file names. */
540 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LPBX", 6);
541 for ((ptr
= bb_head
), (i
= 0); ptr
!= 0; (ptr
= ptr
->next
), i
++)
543 if (ptr
->file_label_num
>= 0)
545 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBC",
546 ptr
->file_label_num
);
547 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, name
),
551 assemble_integer (const0_rtx
, pointer_bytes
, 1);
554 for ( ; i
< count_basic_blocks
; i
++)
555 assemble_integer (const0_rtx
, pointer_bytes
, 1);
558 /* End with the address of the table of addresses,
559 so we can find it easily, as the last word in the file's text. */
560 if (profile_block_flag
)
562 ASM_GENERATE_INTERNAL_LABEL (name
, "LPBX", 3);
563 assemble_integer (gen_rtx_SYMBOL_REF (Pmode
, name
), pointer_bytes
,
569 /* Enable APP processing of subsequent output.
570 Used before the output from an `asm' statement. */
577 fputs (ASM_APP_ON
, asm_out_file
);
582 /* Disable APP processing of subsequent output.
583 Called from varasm.c before most kinds of output. */
590 fputs (ASM_APP_OFF
, asm_out_file
);
595 /* Return the number of slots filled in the current
596 delayed branch sequence (we don't count the insn needing the
597 delay slot). Zero if not in a delayed branch sequence. */
601 dbr_sequence_length ()
603 if (final_sequence
!= 0)
604 return XVECLEN (final_sequence
, 0) - 1;
610 /* The next two pages contain routines used to compute the length of an insn
611 and to shorten branches. */
613 /* Arrays for insn lengths, and addresses. The latter is referenced by
614 `insn_current_length'. */
616 static short *insn_lengths
;
619 /* Address of insn being processed. Used by `insn_current_length'. */
620 int insn_current_address
;
622 /* Address of insn being processed in previous iteration. */
623 int insn_last_address
;
625 /* konwn invariant alignment of insn being processed. */
626 int insn_current_align
;
628 /* Indicate that branch shortening hasn't yet been done. */
636 /* Obtain the current length of an insn. If branch shortening has been done,
637 get its actual length. Otherwise, get its maximum length. */
640 get_attr_length (insn
)
643 #ifdef HAVE_ATTR_length
649 return insn_lengths
[INSN_UID (insn
)];
651 switch (GET_CODE (insn
))
659 length
= insn_default_length (insn
);
663 body
= PATTERN (insn
);
664 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
666 /* Alignment is machine-dependent and should be handled by
670 length
= insn_default_length (insn
);
674 body
= PATTERN (insn
);
675 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
678 else if (GET_CODE (body
) == ASM_INPUT
|| asm_noperands (body
) >= 0)
679 length
= asm_insn_count (body
) * insn_default_length (insn
);
680 else if (GET_CODE (body
) == SEQUENCE
)
681 for (i
= 0; i
< XVECLEN (body
, 0); i
++)
682 length
+= get_attr_length (XVECEXP (body
, 0, i
));
684 length
= insn_default_length (insn
);
691 #ifdef ADJUST_INSN_LENGTH
692 ADJUST_INSN_LENGTH (insn
, length
);
695 #else /* not HAVE_ATTR_length */
697 #endif /* not HAVE_ATTR_length */
700 /* Code to handle alignment inside shorten_branches. */
702 /* Here is an explanation how the algorithm in align_fuzz can give
705 Call a sequence of instructions beginning with alignment point X
706 and continuing until the next alignment point `block X'. When `X'
707 is used in an expression, it means the alignment value of the
710 Call the distance between the start of the first insn of block X, and
711 the end of the last insn of block X `IX', for the `inner size of X'.
712 This is clearly the sum of the instruction lengths.
714 Likewise with the next alignment-delimited block following X, which we
717 Call the distance between the start of the first insn of block X, and
718 the start of the first insn of block Y `OX', for the `outer size of X'.
720 The estimated padding is then OX - IX.
722 OX can be safely estimated as
727 OX = round_up(IX, X) + Y - X
729 Clearly est(IX) >= real(IX), because that only depends on the
730 instruction lengths, and those being overestimated is a given.
732 Clearly round_up(foo, Z) >= round_up(bar, Z) if foo >= bar, so
733 we needn't worry about that when thinking about OX.
735 When X >= Y, the alignment provided by Y adds no uncertainty factor
736 for branch ranges starting before X, so we can just round what we have.
737 But when X < Y, we don't know anything about the, so to speak,
738 `middle bits', so we have to assume the worst when aligning up from an
739 address mod X to one mod Y, which is Y - X. */
742 #define LABEL_ALIGN(LABEL) 0
746 #define LOOP_ALIGN(LABEL) 0
749 #ifndef LABEL_ALIGN_AFTER_BARRIER
750 #define LABEL_ALIGN_AFTER_BARRIER(LABEL) 0
753 #ifndef ADDR_VEC_ALIGN
755 final_addr_vec_align (addr_vec
)
758 int align
= exact_log2 (GET_MODE_SIZE (GET_MODE (PATTERN (addr_vec
))));
760 if (align
> BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
761 align
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
765 #define ADDR_VEC_ALIGN(ADDR_VEC) final_addr_vec_align (ADDR_VEC)
768 #ifndef INSN_LENGTH_ALIGNMENT
769 #define INSN_LENGTH_ALIGNMENT(INSN) length_unit_log
772 /* For any insn, uid_align[INSN_UID (insn)] gives the next following
773 alignment insn that increases the known alignment, or NULL_RTX if
774 there is no such insn.
775 For any alignment obtained this way, we can again index uid_align with
776 its uid to obtain the next following align that in turn increases the
777 alignment, till we reach NULL_RTX; the sequence obtained this way
778 for each insn we'll call the alignment chain of this insn in the following
783 short *label_align
; /* sh.c needs this to calculate constant tables. */
785 #define INSN_SHUID(INSN) (uid_shuid[INSN_UID (INSN)])
787 static int min_labelno
, max_labelno
;
789 #define LABEL_TO_ALIGNMENT(LABEL) \
790 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno])
792 /* For the benefit of port specific code do this also as a function. */
794 label_to_alignment (label
)
797 return LABEL_TO_ALIGNMENT (label
);
800 #ifdef HAVE_ATTR_length
801 /* The differences in addresses
802 between a branch and its target might grow or shrink depending on
803 the alignment the start insn of the range (the branch for a forward
804 branch or the label for a backward branch) starts out on; if these
805 differences are used naively, they can even oscillate infinitely.
806 We therefore want to compute a 'worst case' address difference that
807 is independent of the alignment the start insn of the range end
808 up on, and that is at least as large as the actual difference.
809 The function align_fuzz calculates the amount we have to add to the
810 naively computed difference, by traversing the part of the alignment
811 chain of the start insn of the range that is in front of the end insn
812 of the range, and considering for each alignment the maximum amount
813 that it might contribute to a size increase.
815 For casesi tables, we also want to know worst case minimum amounts of
816 address difference, in case a machine description wants to introduce
817 some common offset that is added to all offsets in a table.
818 For this purpose, align_fuzz with a growth argument of 0 comuptes the
819 appropriate adjustment. */
822 /* Compute the maximum delta by which the difference of the addresses of
823 START and END might grow / shrink due to a different address for start
824 which changes the size of alignment insns between START and END.
825 KNOWN_ALIGN_LOG is the alignment known for START.
826 GROWTH should be ~0 if the objective is to compute potential code size
827 increase, and 0 if the objective is to compute potential shrink.
828 The return value is undefined for any other value of GROWTH. */
830 align_fuzz (start
, end
, known_align_log
, growth
)
835 int uid
= INSN_UID (start
);
837 int known_align
= 1 << known_align_log
;
838 int end_shuid
= INSN_SHUID (end
);
841 for (align_label
= uid_align
[uid
]; align_label
; align_label
= uid_align
[uid
])
843 int align_addr
, new_align
;
845 uid
= INSN_UID (align_label
);
846 align_addr
= insn_addresses
[uid
] - insn_lengths
[uid
];
847 if (uid_shuid
[uid
] > end_shuid
)
849 known_align_log
= LABEL_TO_ALIGNMENT (align_label
);
850 new_align
= 1 << known_align_log
;
851 if (new_align
< known_align
)
853 fuzz
+= (-align_addr
^ growth
) & (new_align
- known_align
);
854 known_align
= new_align
;
859 /* Compute a worst-case reference address of a branch so that it
860 can be safely used in the presence of aligned labels. Since the
861 size of the branch itself is unknown, the size of the branch is
862 not included in the range. I.e. for a forward branch, the reference
863 address is the end address of the branch as known from the previous
864 branch shortening pass, minus a value to account for possible size
865 increase due to alignment. For a backward branch, it is the start
866 address of the branch as known from the current pass, plus a value
867 to account for possible size increase due to alignment.
868 NB.: Therefore, the maximum offset allowed for backward branches needs
869 to exclude the branch size. */
871 insn_current_reference_address (branch
)
875 rtx seq
= NEXT_INSN (PREV_INSN (branch
));
876 int seq_uid
= INSN_UID (seq
);
877 if (GET_CODE (branch
) != JUMP_INSN
)
878 /* This can happen for example on the PA; the objective is to know the
879 offset to address something in front of the start of the function.
880 Thus, we can treat it like a backward branch.
881 We assume here that FUNCTION_BOUNDARY / BITS_PER_UNIT is larger than
882 any alignment we'd encounter, so we skip the call to align_fuzz. */
883 return insn_current_address
;
884 dest
= JUMP_LABEL (branch
);
885 /* BRANCH has no proper alignment chain set, so use SEQ. */
886 if (INSN_SHUID (branch
) < INSN_SHUID (dest
))
888 /* Forward branch. */
889 return (insn_last_address
+ insn_lengths
[seq_uid
]
890 - align_fuzz (seq
, dest
, length_unit_log
, ~0));
894 /* Backward branch. */
895 return (insn_current_address
896 + align_fuzz (dest
, seq
, length_unit_log
, ~0));
899 #endif /* HAVE_ATTR_length */
901 /* Make a pass over all insns and compute their actual lengths by shortening
902 any branches of variable length if possible. */
904 /* Give a default value for the lowest address in a function. */
906 #ifndef FIRST_INSN_ADDRESS
907 #define FIRST_INSN_ADDRESS 0
910 /* shorten_branches might be called multiple times: for example, the SH
911 port splits out-of-range conditional branches in MACHINE_DEPENDENT_REORG.
912 In order to do this, it needs proper length information, which it obtains
913 by calling shorten_branches. This cannot be collapsed with
914 shorten_branches itself into a single pass unless we also want to intergate
915 reorg.c, since the branch splitting exposes new instructions with delay
919 shorten_branches (first
)
926 #ifdef HAVE_ATTR_length
927 #define MAX_CODE_ALIGN 16
929 int something_changed
= 1;
930 char *varying_length
;
933 rtx align_tab
[MAX_CODE_ALIGN
];
935 /* In order to make sure that all instructions have valid length info,
936 we must split them before we compute the address/length info. */
938 for (insn
= NEXT_INSN (first
); insn
; insn
= NEXT_INSN (insn
))
939 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
942 insn
= try_split (PATTERN (old
), old
, 1);
943 /* When not optimizing, the old insn will be still left around
944 with only the 'deleted' bit set. Transform it into a note
945 to avoid confusion of subsequent processing. */
946 if (INSN_DELETED_P (old
))
948 PUT_CODE (old
, NOTE
);
949 NOTE_LINE_NUMBER (old
) = NOTE_INSN_DELETED
;
950 NOTE_SOURCE_FILE (old
) = 0;
955 /* We must do some computations even when not actually shortening, in
956 order to get the alignment information for the labels. */
958 /* Compute maximum UID and allocate label_align / uid_shuid. */
959 max_uid
= get_max_uid ();
961 max_labelno
= max_label_num ();
962 min_labelno
= get_first_label_num ();
966 = (short*) xmalloc ((max_labelno
- min_labelno
+ 1) * sizeof (short));
967 bzero (label_align
, (max_labelno
- min_labelno
+ 1) * sizeof (short));
971 uid_shuid
= (int *) xmalloc (max_uid
* sizeof *uid_shuid
);
973 /* Initialize label_align and set up uid_shuid to be strictly
974 monotonically rising with insn order. */
975 /* We use max_log here to keep track of the maximum alignment we want to
976 impose on the next CODE_LABEL (or the current one if we are processing
977 the CODE_LABEL itself). */
979 for (max_log
= 0, insn
= get_insns (), i
= 1; insn
; insn
= NEXT_INSN (insn
))
983 INSN_SHUID (insn
) = i
++;
984 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
986 /* reorg might make the first insn of a loop being run once only,
987 and delete the label in front of it. Then we want to apply
988 the loop alignment to the new label created by reorg, which
989 is separated by the former loop start insn from the
990 NOTE_INSN_LOOP_BEG. */
992 else if (GET_CODE (insn
) == CODE_LABEL
)
996 log
= LABEL_ALIGN (insn
);
999 next
= NEXT_INSN (insn
);
1000 /* ADDR_VECs only take room if read-only data goes into the text section. */
1001 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
1002 if (next
&& GET_CODE (next
) == JUMP_INSN
)
1004 rtx nextbody
= PATTERN (next
);
1005 if (GET_CODE (nextbody
) == ADDR_VEC
1006 || GET_CODE (nextbody
) == ADDR_DIFF_VEC
)
1008 log
= ADDR_VEC_ALIGN (next
);
1014 LABEL_TO_ALIGNMENT (insn
) = max_log
;
1017 else if (GET_CODE (insn
) == BARRIER
)
1021 for (label
= insn
; label
&& GET_RTX_CLASS (GET_CODE (label
)) != 'i';
1022 label
= NEXT_INSN (label
))
1023 if (GET_CODE (label
) == CODE_LABEL
)
1025 log
= LABEL_ALIGN_AFTER_BARRIER (insn
);
1031 /* Again, we allow NOTE_INSN_LOOP_BEG - INSN - CODE_LABEL
1032 sequences in order to handle reorg output efficiently. */
1033 else if (GET_CODE (insn
) == NOTE
1034 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
)
1038 for (label
= insn
; label
; label
= NEXT_INSN (label
))
1039 if (GET_CODE (label
) == CODE_LABEL
)
1041 log
= LOOP_ALIGN (insn
);
1050 #ifdef HAVE_ATTR_length
1052 /* Allocate the rest of the arrays. */
1054 free (insn_lengths
);
1055 insn_lengths
= (short *) xmalloc (max_uid
* sizeof (short));
1057 free (insn_addresses
);
1058 insn_addresses
= (int *) xmalloc (max_uid
* sizeof (int));
1059 /* Syntax errors can lead to labels being outside of the main insn stream.
1060 Initialize insn_addresses, so that we get reproducible results. */
1061 bzero ((char *)insn_addresses
, max_uid
* sizeof *insn_addresses
);
1064 uid_align
= (rtx
*) xmalloc (max_uid
* sizeof *uid_align
);
1066 varying_length
= (char *) xmalloc (max_uid
* sizeof (char));
1068 bzero (varying_length
, max_uid
);
1070 /* Initialize uid_align. We scan instructions
1071 from end to start, and keep in align_tab[n] the last seen insn
1072 that does an alignment of at least n+1, i.e. the successor
1073 in the alignment chain for an insn that does / has a known
1076 bzero ((char *) uid_align
, max_uid
* sizeof *uid_align
);
1078 for (i
= MAX_CODE_ALIGN
; --i
>= 0; )
1079 align_tab
[i
] = NULL_RTX
;
1080 seq
= get_last_insn ();
1081 for (; seq
; seq
= PREV_INSN (seq
))
1083 int uid
= INSN_UID (seq
);
1085 log
= (GET_CODE (seq
) == CODE_LABEL
? LABEL_TO_ALIGNMENT (seq
) : 0);
1086 uid_align
[uid
] = align_tab
[0];
1089 /* Found an alignment label. */
1090 uid_align
[uid
] = align_tab
[log
];
1091 for (i
= log
- 1; i
>= 0; i
--)
1095 #ifdef CASE_VECTOR_SHORTEN_MODE
1098 /* Look for ADDR_DIFF_VECs, and initialize their minimum and maximum
1101 int min_shuid
= INSN_SHUID (get_insns ()) - 1;
1102 int max_shuid
= INSN_SHUID (get_last_insn ()) + 1;
1105 for (insn
= first
; insn
!= 0; insn
= NEXT_INSN (insn
))
1107 rtx min_lab
= NULL_RTX
, max_lab
= NULL_RTX
, pat
;
1108 int len
, i
, min
, max
, insn_shuid
;
1110 addr_diff_vec_flags flags
;
1112 if (GET_CODE (insn
) != JUMP_INSN
1113 || GET_CODE (PATTERN (insn
)) != ADDR_DIFF_VEC
)
1115 pat
= PATTERN (insn
);
1116 len
= XVECLEN (pat
, 1);
1119 min_align
= MAX_CODE_ALIGN
;
1120 for (min
= max_shuid
, max
= min_shuid
, i
= len
- 1; i
>= 0; i
--)
1122 rtx lab
= XEXP (XVECEXP (pat
, 1, i
), 0);
1123 int shuid
= INSN_SHUID (lab
);
1134 if (min_align
> LABEL_TO_ALIGNMENT (lab
))
1135 min_align
= LABEL_TO_ALIGNMENT (lab
);
1137 XEXP (pat
, 2) = gen_rtx_LABEL_REF (VOIDmode
, min_lab
);
1138 XEXP (pat
, 3) = gen_rtx_LABEL_REF (VOIDmode
, max_lab
);
1139 insn_shuid
= INSN_SHUID (insn
);
1140 rel
= INSN_SHUID (XEXP (XEXP (pat
, 0), 0));
1141 flags
.min_align
= min_align
;
1142 flags
.base_after_vec
= rel
> insn_shuid
;
1143 flags
.min_after_vec
= min
> insn_shuid
;
1144 flags
.max_after_vec
= max
> insn_shuid
;
1145 flags
.min_after_base
= min
> rel
;
1146 flags
.max_after_base
= max
> rel
;
1147 ADDR_DIFF_VEC_FLAGS (pat
) = flags
;
1150 #endif /* CASE_VECTOR_SHORTEN_MODE */
1153 /* Compute initial lengths, addresses, and varying flags for each insn. */
1154 for (insn_current_address
= FIRST_INSN_ADDRESS
, insn
= first
;
1156 insn_current_address
+= insn_lengths
[uid
], insn
= NEXT_INSN (insn
))
1158 uid
= INSN_UID (insn
);
1160 insn_lengths
[uid
] = 0;
1162 if (GET_CODE (insn
) == CODE_LABEL
)
1164 int log
= LABEL_TO_ALIGNMENT (insn
);
1167 int align
= 1 << log
;
1168 int new_address
= (insn_current_address
+ align
- 1) & -align
;
1169 insn_lengths
[uid
] = new_address
- insn_current_address
;
1170 insn_current_address
= new_address
;
1174 insn_addresses
[uid
] = insn_current_address
;
1176 if (GET_CODE (insn
) == NOTE
|| GET_CODE (insn
) == BARRIER
1177 || GET_CODE (insn
) == CODE_LABEL
)
1179 if (INSN_DELETED_P (insn
))
1182 body
= PATTERN (insn
);
1183 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
1185 /* This only takes room if read-only data goes into the text
1187 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
1188 insn_lengths
[uid
] = (XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
)
1189 * GET_MODE_SIZE (GET_MODE (body
)));
1190 /* Alignment is handled by ADDR_VEC_ALIGN. */
1193 else if (asm_noperands (body
) >= 0)
1194 insn_lengths
[uid
] = asm_insn_count (body
) * insn_default_length (insn
);
1195 else if (GET_CODE (body
) == SEQUENCE
)
1198 int const_delay_slots
;
1200 const_delay_slots
= const_num_delay_slots (XVECEXP (body
, 0, 0));
1202 const_delay_slots
= 0;
1204 /* Inside a delay slot sequence, we do not do any branch shortening
1205 if the shortening could change the number of delay slots
1207 for (i
= 0; i
< XVECLEN (body
, 0); i
++)
1209 rtx inner_insn
= XVECEXP (body
, 0, i
);
1210 int inner_uid
= INSN_UID (inner_insn
);
1213 if (asm_noperands (PATTERN (XVECEXP (body
, 0, i
))) >= 0)
1214 inner_length
= (asm_insn_count (PATTERN (inner_insn
))
1215 * insn_default_length (inner_insn
));
1217 inner_length
= insn_default_length (inner_insn
);
1219 insn_lengths
[inner_uid
] = inner_length
;
1220 if (const_delay_slots
)
1222 if ((varying_length
[inner_uid
]
1223 = insn_variable_length_p (inner_insn
)) != 0)
1224 varying_length
[uid
] = 1;
1225 insn_addresses
[inner_uid
] = (insn_current_address
+
1229 varying_length
[inner_uid
] = 0;
1230 insn_lengths
[uid
] += inner_length
;
1233 else if (GET_CODE (body
) != USE
&& GET_CODE (body
) != CLOBBER
)
1235 insn_lengths
[uid
] = insn_default_length (insn
);
1236 varying_length
[uid
] = insn_variable_length_p (insn
);
1239 /* If needed, do any adjustment. */
1240 #ifdef ADJUST_INSN_LENGTH
1241 ADJUST_INSN_LENGTH (insn
, insn_lengths
[uid
]);
1245 /* Now loop over all the insns finding varying length insns. For each,
1246 get the current insn length. If it has changed, reflect the change.
1247 When nothing changes for a full pass, we are done. */
1249 while (something_changed
)
1251 something_changed
= 0;
1252 insn_current_align
= MAX_CODE_ALIGN
- 1;
1253 for (insn_current_address
= FIRST_INSN_ADDRESS
, insn
= first
;
1255 insn
= NEXT_INSN (insn
))
1258 #ifdef ADJUST_INSN_LENGTH
1263 uid
= INSN_UID (insn
);
1265 if (GET_CODE (insn
) == CODE_LABEL
)
1267 int log
= LABEL_TO_ALIGNMENT (insn
);
1268 if (log
> insn_current_align
)
1270 int align
= 1 << log
;
1271 int new_address
= (insn_current_address
+ align
- 1) & -align
;
1272 insn_lengths
[uid
] = new_address
- insn_current_address
;
1273 insn_current_align
= log
;
1274 insn_current_address
= new_address
;
1277 insn_lengths
[uid
] = 0;
1278 insn_addresses
[uid
] = insn_current_address
;
1282 length_align
= INSN_LENGTH_ALIGNMENT (insn
);
1283 if (length_align
< insn_current_align
)
1284 insn_current_align
= length_align
;
1286 insn_last_address
= insn_addresses
[uid
];
1287 insn_addresses
[uid
] = insn_current_address
;
1289 #ifdef CASE_VECTOR_SHORTEN_MODE
1290 if (optimize
&& GET_CODE (insn
) == JUMP_INSN
1291 && GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
)
1293 rtx body
= PATTERN (insn
);
1294 int old_length
= insn_lengths
[uid
];
1295 rtx rel_lab
= XEXP (XEXP (body
, 0), 0);
1296 rtx min_lab
= XEXP (XEXP (body
, 2), 0);
1297 rtx max_lab
= XEXP (XEXP (body
, 3), 0);
1298 addr_diff_vec_flags flags
= ADDR_DIFF_VEC_FLAGS (body
);
1299 int rel_addr
= insn_addresses
[INSN_UID (rel_lab
)];
1300 int min_addr
= insn_addresses
[INSN_UID (min_lab
)];
1301 int max_addr
= insn_addresses
[INSN_UID (max_lab
)];
1305 /* Try to find a known alignment for rel_lab. */
1306 for (prev
= rel_lab
;
1308 && ! insn_lengths
[INSN_UID (prev
)]
1309 && ! (varying_length
[INSN_UID (prev
)] & 1);
1310 prev
= PREV_INSN (prev
))
1311 if (varying_length
[INSN_UID (prev
)] & 2)
1313 rel_align
= LABEL_TO_ALIGNMENT (prev
);
1317 /* See the comment on addr_diff_vec_flags in rtl.h for the
1318 meaning of the flags values. base: REL_LAB vec: INSN */
1319 /* Anything after INSN has still addresses from the last
1320 pass; adjust these so that they reflect our current
1321 estimate for this pass. */
1322 if (flags
.base_after_vec
)
1323 rel_addr
+= insn_current_address
- insn_last_address
;
1324 if (flags
.min_after_vec
)
1325 min_addr
+= insn_current_address
- insn_last_address
;
1326 if (flags
.max_after_vec
)
1327 max_addr
+= insn_current_address
- insn_last_address
;
1328 /* We want to know the worst case, i.e. lowest possible value
1329 for the offset of MIN_LAB. If MIN_LAB is after REL_LAB,
1330 its offset is positive, and we have to be wary of code shrink;
1331 otherwise, it is negative, and we have to be vary of code
1333 if (flags
.min_after_base
)
1335 /* If INSN is between REL_LAB and MIN_LAB, the size
1336 changes we are about to make can change the alignment
1337 within the observed offset, therefore we have to break
1338 it up into two parts that are independent. */
1339 if (! flags
.base_after_vec
&& flags
.min_after_vec
)
1341 min_addr
-= align_fuzz (rel_lab
, insn
, rel_align
, 0);
1342 min_addr
-= align_fuzz (insn
, min_lab
, 0, 0);
1345 min_addr
-= align_fuzz (rel_lab
, min_lab
, rel_align
, 0);
1349 if (flags
.base_after_vec
&& ! flags
.min_after_vec
)
1351 min_addr
-= align_fuzz (min_lab
, insn
, 0, ~0);
1352 min_addr
-= align_fuzz (insn
, rel_lab
, 0, ~0);
1355 min_addr
-= align_fuzz (min_lab
, rel_lab
, 0, ~0);
1357 /* Likewise, determine the highest lowest possible value
1358 for the offset of MAX_LAB. */
1359 if (flags
.max_after_base
)
1361 if (! flags
.base_after_vec
&& flags
.max_after_vec
)
1363 max_addr
+= align_fuzz (rel_lab
, insn
, rel_align
, ~0);
1364 max_addr
+= align_fuzz (insn
, max_lab
, 0, ~0);
1367 max_addr
+= align_fuzz (rel_lab
, max_lab
, rel_align
, ~0);
1371 if (flags
.base_after_vec
&& ! flags
.max_after_vec
)
1373 max_addr
+= align_fuzz (max_lab
, insn
, 0, 0);
1374 max_addr
+= align_fuzz (insn
, rel_lab
, 0, 0);
1377 max_addr
+= align_fuzz (max_lab
, rel_lab
, 0, 0);
1379 PUT_MODE (body
, CASE_VECTOR_SHORTEN_MODE (min_addr
- rel_addr
,
1380 max_addr
- rel_addr
,
1382 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
1384 = (XVECLEN (body
, 1) * GET_MODE_SIZE (GET_MODE (body
)));
1385 insn_current_address
+= insn_lengths
[uid
];
1386 if (insn_lengths
[uid
] != old_length
)
1387 something_changed
= 1;
1391 #endif /* CASE_VECTOR_SHORTEN_MODE */
1393 if (! (varying_length
[uid
]))
1395 insn_current_address
+= insn_lengths
[uid
];
1398 if (GET_CODE (insn
) == INSN
&& GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1402 body
= PATTERN (insn
);
1404 for (i
= 0; i
< XVECLEN (body
, 0); i
++)
1406 rtx inner_insn
= XVECEXP (body
, 0, i
);
1407 int inner_uid
= INSN_UID (inner_insn
);
1410 insn_addresses
[inner_uid
] = insn_current_address
;
1412 /* insn_current_length returns 0 for insns with a
1413 non-varying length. */
1414 if (! varying_length
[inner_uid
])
1415 inner_length
= insn_lengths
[inner_uid
];
1417 inner_length
= insn_current_length (inner_insn
);
1419 if (inner_length
!= insn_lengths
[inner_uid
])
1421 insn_lengths
[inner_uid
] = inner_length
;
1422 something_changed
= 1;
1424 insn_current_address
+= insn_lengths
[inner_uid
];
1425 new_length
+= inner_length
;
1430 new_length
= insn_current_length (insn
);
1431 insn_current_address
+= new_length
;
1434 #ifdef ADJUST_INSN_LENGTH
1435 /* If needed, do any adjustment. */
1436 tmp_length
= new_length
;
1437 ADJUST_INSN_LENGTH (insn
, new_length
);
1438 insn_current_address
+= (new_length
- tmp_length
);
1441 if (new_length
!= insn_lengths
[uid
])
1443 insn_lengths
[uid
] = new_length
;
1444 something_changed
= 1;
1447 /* For a non-optimizing compile, do only a single pass. */
1452 free (varying_length
);
1454 #endif /* HAVE_ATTR_length */
1457 #ifdef HAVE_ATTR_length
1458 /* Given the body of an INSN known to be generated by an ASM statement, return
1459 the number of machine instructions likely to be generated for this insn.
1460 This is used to compute its length. */
1463 asm_insn_count (body
)
1469 if (GET_CODE (body
) == ASM_INPUT
)
1470 template = XSTR (body
, 0);
1472 template = decode_asm_operands (body
, NULL_PTR
, NULL_PTR
,
1473 NULL_PTR
, NULL_PTR
);
1475 for ( ; *template; template++)
1476 if (IS_ASM_LOGICAL_LINE_SEPARATOR(*template) || *template == '\n')
1483 /* Output assembler code for the start of a function,
1484 and initialize some of the variables in this file
1485 for the new function. The label for the function and associated
1486 assembler pseudo-ops have already been output in `assemble_start_function'.
1488 FIRST is the first insn of the rtl for the function being compiled.
1489 FILE is the file to write assembler code to.
1490 OPTIMIZE is nonzero if we should eliminate redundant
1491 test and compare insns. */
1494 final_start_function (first
, file
, optimize
)
1501 this_is_asm_operands
= 0;
1503 #ifdef NON_SAVING_SETJMP
1504 /* A function that calls setjmp should save and restore all the
1505 call-saved registers on a system where longjmp clobbers them. */
1506 if (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
1510 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1511 if (!call_used_regs
[i
] && !call_fixed_regs
[i
])
1512 regs_ever_live
[i
] = 1;
1516 /* Initial line number is supposed to be output
1517 before the function's prologue and label
1518 so that the function's address will not appear to be
1519 in the last statement of the preceding function. */
1520 if (NOTE_LINE_NUMBER (first
) != NOTE_INSN_DELETED
)
1521 last_linenum
= high_block_linenum
= high_function_linenum
1522 = NOTE_LINE_NUMBER (first
);
1524 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1525 /* Output DWARF definition of the function. */
1526 if (dwarf2out_do_frame ())
1527 dwarf2out_begin_prologue ();
1530 /* For SDB and XCOFF, the function beginning must be marked between
1531 the function label and the prologue. We always need this, even when
1532 -g1 was used. Defer on MIPS systems so that parameter descriptions
1533 follow function entry. */
1534 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
1535 if (write_symbols
== SDB_DEBUG
)
1536 sdbout_begin_function (last_linenum
);
1539 #ifdef XCOFF_DEBUGGING_INFO
1540 if (write_symbols
== XCOFF_DEBUG
)
1541 xcoffout_begin_function (file
, last_linenum
);
1544 /* But only output line number for other debug info types if -g2
1546 if (NOTE_LINE_NUMBER (first
) != NOTE_INSN_DELETED
)
1547 output_source_line (file
, first
);
1549 #ifdef LEAF_REG_REMAP
1551 leaf_renumber_regs (first
);
1554 /* The Sun386i and perhaps other machines don't work right
1555 if the profiling code comes after the prologue. */
1556 #ifdef PROFILE_BEFORE_PROLOGUE
1558 profile_function (file
);
1559 #endif /* PROFILE_BEFORE_PROLOGUE */
1561 #if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
1562 if (dwarf2out_do_frame ())
1563 dwarf2out_frame_debug (NULL_RTX
);
1566 #ifdef FUNCTION_PROLOGUE
1567 /* First output the function prologue: code to set up the stack frame. */
1568 FUNCTION_PROLOGUE (file
, get_frame_size ());
1571 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1572 if (write_symbols
== SDB_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
1573 next_block_index
= 1;
1576 /* If the machine represents the prologue as RTL, the profiling code must
1577 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
1578 #ifdef HAVE_prologue
1579 if (! HAVE_prologue
)
1581 profile_after_prologue (file
);
1585 /* If we are doing basic block profiling, remember a printable version
1586 of the function name. */
1587 if (profile_block_flag
)
1590 = add_bb_string ((*decl_printable_name
) (current_function_decl
, 2), FALSE
);
1595 profile_after_prologue (file
)
1598 #ifdef FUNCTION_BLOCK_PROFILER
1599 if (profile_block_flag
)
1601 FUNCTION_BLOCK_PROFILER (file
, count_basic_blocks
);
1603 #endif /* FUNCTION_BLOCK_PROFILER */
1605 #ifndef PROFILE_BEFORE_PROLOGUE
1607 profile_function (file
);
1608 #endif /* not PROFILE_BEFORE_PROLOGUE */
1612 profile_function (file
)
1615 int align
= MIN (BIGGEST_ALIGNMENT
, LONG_TYPE_SIZE
);
1616 #if defined(ASM_OUTPUT_REG_PUSH)
1617 #if defined(STRUCT_VALUE_INCOMING_REGNUM) || defined(STRUCT_VALUE_REGNUM)
1618 int sval
= current_function_returns_struct
;
1620 #if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
1621 int cxt
= current_function_needs_context
;
1623 #endif /* ASM_OUTPUT_REG_PUSH */
1626 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
1627 ASM_OUTPUT_INTERNAL_LABEL (file
, "LP", profile_label_no
);
1628 assemble_integer (const0_rtx
, LONG_TYPE_SIZE
/ BITS_PER_UNIT
, 1);
1630 function_section (current_function_decl
);
1632 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1634 ASM_OUTPUT_REG_PUSH (file
, STRUCT_VALUE_INCOMING_REGNUM
);
1636 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1639 ASM_OUTPUT_REG_PUSH (file
, STRUCT_VALUE_REGNUM
);
1644 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1646 ASM_OUTPUT_REG_PUSH (file
, STATIC_CHAIN_INCOMING_REGNUM
);
1648 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1651 ASM_OUTPUT_REG_PUSH (file
, STATIC_CHAIN_REGNUM
);
1656 FUNCTION_PROFILER (file
, profile_label_no
);
1658 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1660 ASM_OUTPUT_REG_POP (file
, STATIC_CHAIN_INCOMING_REGNUM
);
1662 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1665 ASM_OUTPUT_REG_POP (file
, STATIC_CHAIN_REGNUM
);
1670 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1672 ASM_OUTPUT_REG_POP (file
, STRUCT_VALUE_INCOMING_REGNUM
);
1674 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1677 ASM_OUTPUT_REG_POP (file
, STRUCT_VALUE_REGNUM
);
1683 /* Output assembler code for the end of a function.
1684 For clarity, args are same as those of `final_start_function'
1685 even though not all of them are needed. */
1688 final_end_function (first
, file
, optimize
)
1695 fputs (ASM_APP_OFF
, file
);
1699 #ifdef SDB_DEBUGGING_INFO
1700 if (write_symbols
== SDB_DEBUG
)
1701 sdbout_end_function (high_function_linenum
);
1704 #ifdef DWARF_DEBUGGING_INFO
1705 if (write_symbols
== DWARF_DEBUG
)
1706 dwarfout_end_function ();
1709 #ifdef XCOFF_DEBUGGING_INFO
1710 if (write_symbols
== XCOFF_DEBUG
)
1711 xcoffout_end_function (file
, high_function_linenum
);
1714 #ifdef FUNCTION_EPILOGUE
1715 /* Finally, output the function epilogue:
1716 code to restore the stack frame and return to the caller. */
1717 FUNCTION_EPILOGUE (file
, get_frame_size ());
1720 #ifdef SDB_DEBUGGING_INFO
1721 if (write_symbols
== SDB_DEBUG
)
1722 sdbout_end_epilogue ();
1725 #ifdef DWARF_DEBUGGING_INFO
1726 if (write_symbols
== DWARF_DEBUG
)
1727 dwarfout_end_epilogue ();
1730 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1731 if (dwarf2out_do_frame ())
1732 dwarf2out_end_epilogue ();
1735 #ifdef XCOFF_DEBUGGING_INFO
1736 if (write_symbols
== XCOFF_DEBUG
)
1737 xcoffout_end_epilogue (file
);
1740 bb_func_label_num
= -1; /* not in function, nuke label # */
1742 /* If FUNCTION_EPILOGUE is not defined, then the function body
1743 itself contains return instructions wherever needed. */
1746 /* Add a block to the linked list that remembers the current line/file/function
1747 for basic block profiling. Emit the label in front of the basic block and
1748 the instructions that increment the count field. */
1754 struct bb_list
*ptr
= (struct bb_list
*) permalloc (sizeof (struct bb_list
));
1756 /* Add basic block to linked list. */
1758 ptr
->line_num
= last_linenum
;
1759 ptr
->file_label_num
= bb_file_label_num
;
1760 ptr
->func_label_num
= bb_func_label_num
;
1762 bb_tail
= &ptr
->next
;
1764 /* Enable the table of basic-block use counts
1765 to point at the code it applies to. */
1766 ASM_OUTPUT_INTERNAL_LABEL (file
, "LPB", count_basic_blocks
);
1768 /* Before first insn of this basic block, increment the
1769 count of times it was entered. */
1770 #ifdef BLOCK_PROFILER
1771 BLOCK_PROFILER (file
, count_basic_blocks
);
1778 count_basic_blocks
++;
1781 /* Add a string to be used for basic block profiling. */
1784 add_bb_string (string
, perm_p
)
1789 struct bb_str
*ptr
= 0;
1793 string
= "<unknown>";
1797 /* Allocate a new string if the current string isn't permanent. If
1798 the string is permanent search for the same string in other
1801 len
= strlen (string
) + 1;
1804 char *p
= (char *) permalloc (len
);
1805 bcopy (string
, p
, len
);
1809 for (ptr
= sbb_head
; ptr
!= (struct bb_str
*) 0; ptr
= ptr
->next
)
1810 if (ptr
->string
== string
)
1813 /* Allocate a new string block if we need to. */
1816 ptr
= (struct bb_str
*) permalloc (sizeof (*ptr
));
1819 ptr
->label_num
= sbb_label_num
++;
1820 ptr
->string
= string
;
1822 sbb_tail
= &ptr
->next
;
1825 return ptr
->label_num
;
1829 /* Output assembler code for some insns: all or part of a function.
1830 For description of args, see `final_start_function', above.
1832 PRESCAN is 1 if we are not really outputting,
1833 just scanning as if we were outputting.
1834 Prescanning deletes and rearranges insns just like ordinary output.
1835 PRESCAN is -2 if we are outputting after having prescanned.
1836 In this case, don't try to delete or rearrange insns
1837 because that has already been done.
1838 Prescanning is done only on certain machines. */
1841 final (first
, file
, optimize
, prescan
)
1851 last_ignored_compare
= 0;
1854 check_exception_handler_labels ();
1856 /* Make a map indicating which line numbers appear in this function.
1857 When producing SDB debugging info, delete troublesome line number
1858 notes from inlined functions in other files as well as duplicate
1859 line number notes. */
1860 #ifdef SDB_DEBUGGING_INFO
1861 if (write_symbols
== SDB_DEBUG
)
1864 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
1865 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
1867 if ((RTX_INTEGRATED_P (insn
)
1868 && strcmp (NOTE_SOURCE_FILE (insn
), main_input_filename
) != 0)
1870 && NOTE_LINE_NUMBER (insn
) == NOTE_LINE_NUMBER (last
)
1871 && NOTE_SOURCE_FILE (insn
) == NOTE_SOURCE_FILE (last
)))
1873 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
1874 NOTE_SOURCE_FILE (insn
) = 0;
1878 if (NOTE_LINE_NUMBER (insn
) > max_line
)
1879 max_line
= NOTE_LINE_NUMBER (insn
);
1885 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
1886 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > max_line
)
1887 max_line
= NOTE_LINE_NUMBER (insn
);
1890 line_note_exists
= (char *) oballoc (max_line
+ 1);
1891 bzero (line_note_exists
, max_line
+ 1);
1893 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
1895 if (INSN_UID (insn
) > max_uid
) /* find largest UID */
1896 max_uid
= INSN_UID (insn
);
1897 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
1898 line_note_exists
[NOTE_LINE_NUMBER (insn
)] = 1;
1901 /* Initialize insn_eh_region table if eh is being used. */
1903 init_insn_eh_region (first
, max_uid
);
1909 /* Output the insns. */
1910 for (insn
= NEXT_INSN (first
); insn
;)
1912 #ifdef HAVE_ATTR_length
1913 insn_current_address
= insn_addresses
[INSN_UID (insn
)];
1915 insn
= final_scan_insn (insn
, file
, optimize
, prescan
, 0);
1918 /* Do basic-block profiling here
1919 if the last insn was a conditional branch. */
1920 if (profile_block_flag
&& new_block
)
1923 free_insn_eh_region ();
1926 /* The final scan for one insn, INSN.
1927 Args are same as in `final', except that INSN
1928 is the insn being scanned.
1929 Value returned is the next insn to be scanned.
1931 NOPEEPHOLES is the flag to disallow peephole processing (currently
1932 used for within delayed branch sequence output). */
1935 final_scan_insn (insn
, file
, optimize
, prescan
, nopeepholes
)
1949 /* Ignore deleted insns. These can occur when we split insns (due to a
1950 template of "#") while not optimizing. */
1951 if (INSN_DELETED_P (insn
))
1952 return NEXT_INSN (insn
);
1954 switch (GET_CODE (insn
))
1960 /* Align the beginning of a loop, for higher speed
1961 on certain machines. */
1963 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_BEG
)
1964 break; /* This used to depend on optimize, but that was bogus. */
1965 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_LOOP_END
)
1968 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_BEG
1969 && ! exceptions_via_longjmp
)
1971 ASM_OUTPUT_INTERNAL_LABEL (file
, "LEHB", NOTE_BLOCK_NUMBER (insn
));
1972 add_eh_table_entry (NOTE_BLOCK_NUMBER (insn
));
1973 #ifdef ASM_OUTPUT_EH_REGION_BEG
1974 ASM_OUTPUT_EH_REGION_BEG (file
, NOTE_BLOCK_NUMBER (insn
));
1979 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EH_REGION_END
1980 && ! exceptions_via_longjmp
)
1982 ASM_OUTPUT_INTERNAL_LABEL (file
, "LEHE", NOTE_BLOCK_NUMBER (insn
));
1983 #ifdef ASM_OUTPUT_EH_REGION_END
1984 ASM_OUTPUT_EH_REGION_END (file
, NOTE_BLOCK_NUMBER (insn
));
1989 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_PROLOGUE_END
)
1991 #ifdef FUNCTION_END_PROLOGUE
1992 FUNCTION_END_PROLOGUE (file
);
1994 profile_after_prologue (file
);
1998 #ifdef FUNCTION_BEGIN_EPILOGUE
1999 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EPILOGUE_BEG
)
2001 FUNCTION_BEGIN_EPILOGUE (file
);
2006 if (write_symbols
== NO_DEBUG
)
2008 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_FUNCTION_BEG
)
2010 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
2011 /* MIPS stabs require the parameter descriptions to be after the
2012 function entry point rather than before. */
2013 if (write_symbols
== SDB_DEBUG
)
2014 sdbout_begin_function (last_linenum
);
2017 #ifdef DWARF_DEBUGGING_INFO
2018 /* This outputs a marker where the function body starts, so it
2019 must be after the prologue. */
2020 if (write_symbols
== DWARF_DEBUG
)
2021 dwarfout_begin_function ();
2025 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED
)
2026 break; /* An insn that was "deleted" */
2029 fputs (ASM_APP_OFF
, file
);
2032 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
2033 && (debug_info_level
== DINFO_LEVEL_NORMAL
2034 || debug_info_level
== DINFO_LEVEL_VERBOSE
2035 || write_symbols
== DWARF_DEBUG
2036 || write_symbols
== DWARF2_DEBUG
))
2038 /* Beginning of a symbol-block. Assign it a sequence number
2039 and push the number onto the stack PENDING_BLOCKS. */
2041 if (block_depth
== max_block_depth
)
2043 /* PENDING_BLOCKS is full; make it longer. */
2044 max_block_depth
*= 2;
2046 = (int *) xrealloc (pending_blocks
,
2047 max_block_depth
* sizeof (int));
2049 pending_blocks
[block_depth
++] = next_block_index
;
2051 high_block_linenum
= last_linenum
;
2053 /* Output debugging info about the symbol-block beginning. */
2055 #ifdef SDB_DEBUGGING_INFO
2056 if (write_symbols
== SDB_DEBUG
)
2057 sdbout_begin_block (file
, last_linenum
, next_block_index
);
2059 #ifdef XCOFF_DEBUGGING_INFO
2060 if (write_symbols
== XCOFF_DEBUG
)
2061 xcoffout_begin_block (file
, last_linenum
, next_block_index
);
2063 #ifdef DBX_DEBUGGING_INFO
2064 if (write_symbols
== DBX_DEBUG
)
2065 ASM_OUTPUT_INTERNAL_LABEL (file
, "LBB", next_block_index
);
2067 #ifdef DWARF_DEBUGGING_INFO
2068 if (write_symbols
== DWARF_DEBUG
)
2069 dwarfout_begin_block (next_block_index
);
2071 #ifdef DWARF2_DEBUGGING_INFO
2072 if (write_symbols
== DWARF2_DEBUG
)
2073 dwarf2out_begin_block (next_block_index
);
2078 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
2079 && (debug_info_level
== DINFO_LEVEL_NORMAL
2080 || debug_info_level
== DINFO_LEVEL_VERBOSE
2081 || write_symbols
== DWARF_DEBUG
2082 || write_symbols
== DWARF2_DEBUG
))
2084 /* End of a symbol-block. Pop its sequence number off
2085 PENDING_BLOCKS and output debugging info based on that. */
2089 #ifdef XCOFF_DEBUGGING_INFO
2090 if (write_symbols
== XCOFF_DEBUG
&& block_depth
>= 0)
2091 xcoffout_end_block (file
, high_block_linenum
,
2092 pending_blocks
[block_depth
]);
2094 #ifdef DBX_DEBUGGING_INFO
2095 if (write_symbols
== DBX_DEBUG
&& block_depth
>= 0)
2096 ASM_OUTPUT_INTERNAL_LABEL (file
, "LBE",
2097 pending_blocks
[block_depth
]);
2099 #ifdef SDB_DEBUGGING_INFO
2100 if (write_symbols
== SDB_DEBUG
&& block_depth
>= 0)
2101 sdbout_end_block (file
, high_block_linenum
,
2102 pending_blocks
[block_depth
]);
2104 #ifdef DWARF_DEBUGGING_INFO
2105 if (write_symbols
== DWARF_DEBUG
&& block_depth
>= 0)
2106 dwarfout_end_block (pending_blocks
[block_depth
]);
2108 #ifdef DWARF2_DEBUGGING_INFO
2109 if (write_symbols
== DWARF2_DEBUG
&& block_depth
>= 0)
2110 dwarf2out_end_block (pending_blocks
[block_depth
]);
2113 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
2114 && (debug_info_level
== DINFO_LEVEL_NORMAL
2115 || debug_info_level
== DINFO_LEVEL_VERBOSE
))
2117 #ifdef DWARF_DEBUGGING_INFO
2118 if (write_symbols
== DWARF_DEBUG
)
2119 dwarfout_label (insn
);
2121 #ifdef DWARF2_DEBUGGING_INFO
2122 if (write_symbols
== DWARF2_DEBUG
)
2123 dwarf2out_label (insn
);
2126 else if (NOTE_LINE_NUMBER (insn
) > 0)
2127 /* This note is a line-number. */
2131 #if 0 /* This is what we used to do. */
2132 output_source_line (file
, insn
);
2136 /* If there is anything real after this note,
2137 output it. If another line note follows, omit this one. */
2138 for (note
= NEXT_INSN (insn
); note
; note
= NEXT_INSN (note
))
2140 if (GET_CODE (note
) != NOTE
&& GET_CODE (note
) != CODE_LABEL
)
2142 /* These types of notes can be significant
2143 so make sure the preceding line number stays. */
2144 else if (GET_CODE (note
) == NOTE
2145 && (NOTE_LINE_NUMBER (note
) == NOTE_INSN_BLOCK_BEG
2146 || NOTE_LINE_NUMBER (note
) == NOTE_INSN_BLOCK_END
2147 || NOTE_LINE_NUMBER (note
) == NOTE_INSN_FUNCTION_BEG
))
2149 else if (GET_CODE (note
) == NOTE
&& NOTE_LINE_NUMBER (note
) > 0)
2151 /* Another line note follows; we can delete this note
2152 if no intervening line numbers have notes elsewhere. */
2154 for (num
= NOTE_LINE_NUMBER (insn
) + 1;
2155 num
< NOTE_LINE_NUMBER (note
);
2157 if (line_note_exists
[num
])
2160 if (num
>= NOTE_LINE_NUMBER (note
))
2166 /* Output this line note
2167 if it is the first or the last line note in a row. */
2169 output_source_line (file
, insn
);
2174 #if defined (DWARF2_UNWIND_INFO) && !defined (ACCUMULATE_OUTGOING_ARGS)
2175 /* If we push arguments, we need to check all insns for stack
2177 if (dwarf2out_do_frame ())
2178 dwarf2out_frame_debug (insn
);
2183 /* The target port might emit labels in the output function for
2184 some insn, e.g. sh.c output_branchy_insn. */
2185 if (CODE_LABEL_NUMBER (insn
) <= max_labelno
)
2187 int align
= LABEL_TO_ALIGNMENT (insn
);
2189 if (align
&& NEXT_INSN (insn
))
2190 ASM_OUTPUT_ALIGN (file
, align
);
2197 #ifdef FINAL_PRESCAN_LABEL
2198 FINAL_PRESCAN_INSN (insn
, NULL_PTR
, 0);
2201 #ifdef SDB_DEBUGGING_INFO
2202 if (write_symbols
== SDB_DEBUG
&& LABEL_NAME (insn
))
2203 sdbout_label (insn
);
2205 #ifdef DWARF_DEBUGGING_INFO
2206 if (write_symbols
== DWARF_DEBUG
&& LABEL_NAME (insn
))
2207 dwarfout_label (insn
);
2209 #ifdef DWARF2_DEBUGGING_INFO
2210 if (write_symbols
== DWARF2_DEBUG
&& LABEL_NAME (insn
))
2211 dwarf2out_label (insn
);
2215 fputs (ASM_APP_OFF
, file
);
2218 if (NEXT_INSN (insn
) != 0
2219 && GET_CODE (NEXT_INSN (insn
)) == JUMP_INSN
)
2221 rtx nextbody
= PATTERN (NEXT_INSN (insn
));
2223 /* If this label is followed by a jump-table,
2224 make sure we put the label in the read-only section. Also
2225 possibly write the label and jump table together. */
2227 if (GET_CODE (nextbody
) == ADDR_VEC
2228 || GET_CODE (nextbody
) == ADDR_DIFF_VEC
)
2230 #ifndef JUMP_TABLES_IN_TEXT_SECTION
2231 readonly_data_section ();
2232 #ifdef READONLY_DATA_SECTION
2233 ASM_OUTPUT_ALIGN (file
,
2234 exact_log2 (BIGGEST_ALIGNMENT
2236 #endif /* READONLY_DATA_SECTION */
2237 #else /* JUMP_TABLES_IN_TEXT_SECTION */
2238 function_section (current_function_decl
);
2239 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
2240 #ifdef ASM_OUTPUT_CASE_LABEL
2241 ASM_OUTPUT_CASE_LABEL (file
, "L", CODE_LABEL_NUMBER (insn
),
2244 ASM_OUTPUT_INTERNAL_LABEL (file
, "L", CODE_LABEL_NUMBER (insn
));
2250 ASM_OUTPUT_INTERNAL_LABEL (file
, "L", CODE_LABEL_NUMBER (insn
));
2255 register rtx body
= PATTERN (insn
);
2256 int insn_code_number
;
2262 /* An INSN, JUMP_INSN or CALL_INSN.
2263 First check for special kinds that recog doesn't recognize. */
2265 if (GET_CODE (body
) == USE
/* These are just declarations */
2266 || GET_CODE (body
) == CLOBBER
)
2270 /* If there is a REG_CC_SETTER note on this insn, it means that
2271 the setting of the condition code was done in the delay slot
2272 of the insn that branched here. So recover the cc status
2273 from the insn that set it. */
2275 note
= find_reg_note (insn
, REG_CC_SETTER
, NULL_RTX
);
2278 NOTICE_UPDATE_CC (PATTERN (XEXP (note
, 0)), XEXP (note
, 0));
2279 cc_prev_status
= cc_status
;
2283 /* Detect insns that are really jump-tables
2284 and output them as such. */
2286 if (GET_CODE (body
) == ADDR_VEC
|| GET_CODE (body
) == ADDR_DIFF_VEC
)
2288 register int vlen
, idx
;
2295 fputs (ASM_APP_OFF
, file
);
2299 vlen
= XVECLEN (body
, GET_CODE (body
) == ADDR_DIFF_VEC
);
2300 for (idx
= 0; idx
< vlen
; idx
++)
2302 if (GET_CODE (body
) == ADDR_VEC
)
2304 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2305 ASM_OUTPUT_ADDR_VEC_ELT
2306 (file
, CODE_LABEL_NUMBER (XEXP (XVECEXP (body
, 0, idx
), 0)));
2313 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2314 ASM_OUTPUT_ADDR_DIFF_ELT
2317 CODE_LABEL_NUMBER (XEXP (XVECEXP (body
, 1, idx
), 0)),
2318 CODE_LABEL_NUMBER (XEXP (XEXP (body
, 0), 0)));
2324 #ifdef ASM_OUTPUT_CASE_END
2325 ASM_OUTPUT_CASE_END (file
,
2326 CODE_LABEL_NUMBER (PREV_INSN (insn
)),
2330 function_section (current_function_decl
);
2335 /* Do basic-block profiling when we reach a new block.
2336 Done here to avoid jump tables. */
2337 if (profile_block_flag
&& new_block
)
2340 if (GET_CODE (body
) == ASM_INPUT
)
2342 /* There's no telling what that did to the condition codes. */
2348 fputs (ASM_APP_ON
, file
);
2351 fprintf (asm_out_file
, "\t%s\n", XSTR (body
, 0));
2355 /* Detect `asm' construct with operands. */
2356 if (asm_noperands (body
) >= 0)
2358 unsigned int noperands
= asm_noperands (body
);
2359 rtx
*ops
= (rtx
*) alloca (noperands
* sizeof (rtx
));
2362 /* There's no telling what that did to the condition codes. */
2369 fputs (ASM_APP_ON
, file
);
2373 /* Get out the operand values. */
2374 string
= decode_asm_operands (body
, ops
, NULL_PTR
,
2375 NULL_PTR
, NULL_PTR
);
2376 /* Inhibit aborts on what would otherwise be compiler bugs. */
2377 insn_noperands
= noperands
;
2378 this_is_asm_operands
= insn
;
2380 /* Output the insn using them. */
2381 output_asm_insn (string
, ops
);
2382 this_is_asm_operands
= 0;
2386 if (prescan
<= 0 && app_on
)
2388 fputs (ASM_APP_OFF
, file
);
2392 if (GET_CODE (body
) == SEQUENCE
)
2394 /* A delayed-branch sequence */
2400 final_sequence
= body
;
2402 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2403 force the restoration of a comparison that was previously
2404 thought unnecessary. If that happens, cancel this sequence
2405 and cause that insn to be restored. */
2407 next
= final_scan_insn (XVECEXP (body
, 0, 0), file
, 0, prescan
, 1);
2408 if (next
!= XVECEXP (body
, 0, 1))
2414 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
2416 rtx insn
= XVECEXP (body
, 0, i
);
2417 rtx next
= NEXT_INSN (insn
);
2418 /* We loop in case any instruction in a delay slot gets
2421 insn
= final_scan_insn (insn
, file
, 0, prescan
, 1);
2422 while (insn
!= next
);
2424 #ifdef DBR_OUTPUT_SEQEND
2425 DBR_OUTPUT_SEQEND (file
);
2429 /* If the insn requiring the delay slot was a CALL_INSN, the
2430 insns in the delay slot are actually executed before the
2431 called function. Hence we don't preserve any CC-setting
2432 actions in these insns and the CC must be marked as being
2433 clobbered by the function. */
2434 if (GET_CODE (XVECEXP (body
, 0, 0)) == CALL_INSN
)
2439 /* Following a conditional branch sequence, we have a new basic
2441 if (profile_block_flag
)
2443 rtx insn
= XVECEXP (body
, 0, 0);
2444 rtx body
= PATTERN (insn
);
2446 if ((GET_CODE (insn
) == JUMP_INSN
&& GET_CODE (body
) == SET
2447 && GET_CODE (SET_SRC (body
)) != LABEL_REF
)
2448 || (GET_CODE (insn
) == JUMP_INSN
2449 && GET_CODE (body
) == PARALLEL
2450 && GET_CODE (XVECEXP (body
, 0, 0)) == SET
2451 && GET_CODE (SET_SRC (XVECEXP (body
, 0, 0))) != LABEL_REF
))
2457 /* We have a real machine instruction as rtl. */
2459 body
= PATTERN (insn
);
2462 set
= single_set(insn
);
2464 /* Check for redundant test and compare instructions
2465 (when the condition codes are already set up as desired).
2466 This is done only when optimizing; if not optimizing,
2467 it should be possible for the user to alter a variable
2468 with the debugger in between statements
2469 and the next statement should reexamine the variable
2470 to compute the condition codes. */
2475 rtx set
= single_set(insn
);
2479 && GET_CODE (SET_DEST (set
)) == CC0
2480 && insn
!= last_ignored_compare
)
2482 if (GET_CODE (SET_SRC (set
)) == SUBREG
)
2483 SET_SRC (set
) = alter_subreg (SET_SRC (set
));
2484 else if (GET_CODE (SET_SRC (set
)) == COMPARE
)
2486 if (GET_CODE (XEXP (SET_SRC (set
), 0)) == SUBREG
)
2487 XEXP (SET_SRC (set
), 0)
2488 = alter_subreg (XEXP (SET_SRC (set
), 0));
2489 if (GET_CODE (XEXP (SET_SRC (set
), 1)) == SUBREG
)
2490 XEXP (SET_SRC (set
), 1)
2491 = alter_subreg (XEXP (SET_SRC (set
), 1));
2493 if ((cc_status
.value1
!= 0
2494 && rtx_equal_p (SET_SRC (set
), cc_status
.value1
))
2495 || (cc_status
.value2
!= 0
2496 && rtx_equal_p (SET_SRC (set
), cc_status
.value2
)))
2498 /* Don't delete insn if it has an addressing side-effect. */
2499 if (! FIND_REG_INC_NOTE (insn
, 0)
2500 /* or if anything in it is volatile. */
2501 && ! volatile_refs_p (PATTERN (insn
)))
2503 /* We don't really delete the insn; just ignore it. */
2504 last_ignored_compare
= insn
;
2512 /* Following a conditional branch, we have a new basic block.
2513 But if we are inside a sequence, the new block starts after the
2514 last insn of the sequence. */
2515 if (profile_block_flag
&& final_sequence
== 0
2516 && ((GET_CODE (insn
) == JUMP_INSN
&& GET_CODE (body
) == SET
2517 && GET_CODE (SET_SRC (body
)) != LABEL_REF
)
2518 || (GET_CODE (insn
) == JUMP_INSN
&& GET_CODE (body
) == PARALLEL
2519 && GET_CODE (XVECEXP (body
, 0, 0)) == SET
2520 && GET_CODE (SET_SRC (XVECEXP (body
, 0, 0))) != LABEL_REF
)))
2524 /* Don't bother outputting obvious no-ops, even without -O.
2525 This optimization is fast and doesn't interfere with debugging.
2526 Don't do this if the insn is in a delay slot, since this
2527 will cause an improper number of delay insns to be written. */
2528 if (final_sequence
== 0
2530 && GET_CODE (insn
) == INSN
&& GET_CODE (body
) == SET
2531 && GET_CODE (SET_SRC (body
)) == REG
2532 && GET_CODE (SET_DEST (body
)) == REG
2533 && REGNO (SET_SRC (body
)) == REGNO (SET_DEST (body
)))
2538 /* If this is a conditional branch, maybe modify it
2539 if the cc's are in a nonstandard state
2540 so that it accomplishes the same thing that it would
2541 do straightforwardly if the cc's were set up normally. */
2543 if (cc_status
.flags
!= 0
2544 && GET_CODE (insn
) == JUMP_INSN
2545 && GET_CODE (body
) == SET
2546 && SET_DEST (body
) == pc_rtx
2547 && GET_CODE (SET_SRC (body
)) == IF_THEN_ELSE
2548 && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body
), 0))) == '<'
2549 && XEXP (XEXP (SET_SRC (body
), 0), 0) == cc0_rtx
2550 /* This is done during prescan; it is not done again
2551 in final scan when prescan has been done. */
2554 /* This function may alter the contents of its argument
2555 and clear some of the cc_status.flags bits.
2556 It may also return 1 meaning condition now always true
2557 or -1 meaning condition now always false
2558 or 2 meaning condition nontrivial but altered. */
2559 register int result
= alter_cond (XEXP (SET_SRC (body
), 0));
2560 /* If condition now has fixed value, replace the IF_THEN_ELSE
2561 with its then-operand or its else-operand. */
2563 SET_SRC (body
) = XEXP (SET_SRC (body
), 1);
2565 SET_SRC (body
) = XEXP (SET_SRC (body
), 2);
2567 /* The jump is now either unconditional or a no-op.
2568 If it has become a no-op, don't try to output it.
2569 (It would not be recognized.) */
2570 if (SET_SRC (body
) == pc_rtx
)
2572 PUT_CODE (insn
, NOTE
);
2573 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
2574 NOTE_SOURCE_FILE (insn
) = 0;
2577 else if (GET_CODE (SET_SRC (body
)) == RETURN
)
2578 /* Replace (set (pc) (return)) with (return). */
2579 PATTERN (insn
) = body
= SET_SRC (body
);
2581 /* Rerecognize the instruction if it has changed. */
2583 INSN_CODE (insn
) = -1;
2586 /* Make same adjustments to instructions that examine the
2587 condition codes without jumping and instructions that
2588 handle conditional moves (if this machine has either one). */
2590 if (cc_status
.flags
!= 0
2593 rtx cond_rtx
, then_rtx
, else_rtx
;
2595 if (GET_CODE (insn
) != JUMP_INSN
2596 && GET_CODE (SET_SRC (set
)) == IF_THEN_ELSE
)
2598 cond_rtx
= XEXP (SET_SRC (set
), 0);
2599 then_rtx
= XEXP (SET_SRC (set
), 1);
2600 else_rtx
= XEXP (SET_SRC (set
), 2);
2604 cond_rtx
= SET_SRC (set
);
2605 then_rtx
= const_true_rtx
;
2606 else_rtx
= const0_rtx
;
2609 switch (GET_CODE (cond_rtx
))
2622 register int result
;
2623 if (XEXP (cond_rtx
, 0) != cc0_rtx
)
2625 result
= alter_cond (cond_rtx
);
2627 validate_change (insn
, &SET_SRC (set
), then_rtx
, 0);
2628 else if (result
== -1)
2629 validate_change (insn
, &SET_SRC (set
), else_rtx
, 0);
2630 else if (result
== 2)
2631 INSN_CODE (insn
) = -1;
2632 if (SET_DEST (set
) == SET_SRC (set
))
2634 PUT_CODE (insn
, NOTE
);
2635 NOTE_LINE_NUMBER (insn
) = NOTE_INSN_DELETED
;
2636 NOTE_SOURCE_FILE (insn
) = 0;
2648 /* Do machine-specific peephole optimizations if desired. */
2650 if (optimize
&& !flag_no_peephole
&& !nopeepholes
)
2652 rtx next
= peephole (insn
);
2653 /* When peepholing, if there were notes within the peephole,
2654 emit them before the peephole. */
2655 if (next
!= 0 && next
!= NEXT_INSN (insn
))
2657 rtx prev
= PREV_INSN (insn
);
2660 for (note
= NEXT_INSN (insn
); note
!= next
;
2661 note
= NEXT_INSN (note
))
2662 final_scan_insn (note
, file
, optimize
, prescan
, nopeepholes
);
2664 /* In case this is prescan, put the notes
2665 in proper position for later rescan. */
2666 note
= NEXT_INSN (insn
);
2667 PREV_INSN (note
) = prev
;
2668 NEXT_INSN (prev
) = note
;
2669 NEXT_INSN (PREV_INSN (next
)) = insn
;
2670 PREV_INSN (insn
) = PREV_INSN (next
);
2671 NEXT_INSN (insn
) = next
;
2672 PREV_INSN (next
) = insn
;
2675 /* PEEPHOLE might have changed this. */
2676 body
= PATTERN (insn
);
2679 /* Try to recognize the instruction.
2680 If successful, verify that the operands satisfy the
2681 constraints for the instruction. Crash if they don't,
2682 since `reload' should have changed them so that they do. */
2684 insn_code_number
= recog_memoized (insn
);
2685 insn_extract (insn
);
2686 for (i
= 0; i
< insn_n_operands
[insn_code_number
]; i
++)
2688 if (GET_CODE (recog_operand
[i
]) == SUBREG
)
2689 recog_operand
[i
] = alter_subreg (recog_operand
[i
]);
2690 else if (GET_CODE (recog_operand
[i
]) == PLUS
2691 || GET_CODE (recog_operand
[i
]) == MULT
)
2692 recog_operand
[i
] = walk_alter_subreg (recog_operand
[i
]);
2695 for (i
= 0; i
< insn_n_dups
[insn_code_number
]; i
++)
2697 if (GET_CODE (*recog_dup_loc
[i
]) == SUBREG
)
2698 *recog_dup_loc
[i
] = alter_subreg (*recog_dup_loc
[i
]);
2699 else if (GET_CODE (*recog_dup_loc
[i
]) == PLUS
2700 || GET_CODE (*recog_dup_loc
[i
]) == MULT
)
2701 *recog_dup_loc
[i
] = walk_alter_subreg (*recog_dup_loc
[i
]);
2704 #ifdef REGISTER_CONSTRAINTS
2705 if (! constrain_operands (insn_code_number
, 1))
2706 fatal_insn_not_found (insn
);
2709 /* Some target machines need to prescan each insn before
2712 #ifdef FINAL_PRESCAN_INSN
2713 FINAL_PRESCAN_INSN (insn
, recog_operand
,
2714 insn_n_operands
[insn_code_number
]);
2718 cc_prev_status
= cc_status
;
2720 /* Update `cc_status' for this instruction.
2721 The instruction's output routine may change it further.
2722 If the output routine for a jump insn needs to depend
2723 on the cc status, it should look at cc_prev_status. */
2725 NOTICE_UPDATE_CC (body
, insn
);
2730 #if defined (DWARF2_UNWIND_INFO) && !defined (ACCUMULATE_OUTGOING_ARGS)
2731 /* If we push arguments, we want to know where the calls are. */
2732 if (GET_CODE (insn
) == CALL_INSN
&& dwarf2out_do_frame ())
2733 dwarf2out_frame_debug (insn
);
2736 /* If the proper template needs to be chosen by some C code,
2737 run that code and get the real template. */
2739 template = insn_template
[insn_code_number
];
2742 template = (*insn_outfun
[insn_code_number
]) (recog_operand
, insn
);
2744 /* If the C code returns 0, it means that it is a jump insn
2745 which follows a deleted test insn, and that test insn
2746 needs to be reinserted. */
2749 if (prev_nonnote_insn (insn
) != last_ignored_compare
)
2752 return prev_nonnote_insn (insn
);
2756 /* If the template is the string "#", it means that this insn must
2758 if (template[0] == '#' && template[1] == '\0')
2760 rtx
new = try_split (body
, insn
, 0);
2762 /* If we didn't split the insn, go away. */
2763 if (new == insn
&& PATTERN (new) == body
)
2766 #ifdef HAVE_ATTR_length
2767 /* This instruction should have been split in shorten_branches,
2768 to ensure that we would have valid length info for the
2780 /* Output assembler code from the template. */
2782 output_asm_insn (template, recog_operand
);
2784 #if defined (DWARF2_UNWIND_INFO)
2785 #if !defined (ACCUMULATE_OUTGOING_ARGS)
2786 /* If we push arguments, we need to check all insns for stack
2788 if (GET_CODE (insn
) == INSN
&& dwarf2out_do_frame ())
2789 dwarf2out_frame_debug (insn
);
2791 #if defined (HAVE_prologue)
2792 /* If this insn is part of the prologue, emit DWARF v2
2794 if (RTX_FRAME_RELATED_P (insn
) && dwarf2out_do_frame ())
2795 dwarf2out_frame_debug (insn
);
2801 /* It's not at all clear why we did this and doing so interferes
2802 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2805 /* Mark this insn as having been output. */
2806 INSN_DELETED_P (insn
) = 1;
2812 return NEXT_INSN (insn
);
2815 /* Output debugging info to the assembler file FILE
2816 based on the NOTE-insn INSN, assumed to be a line number. */
2819 output_source_line (file
, insn
)
2823 register char *filename
= NOTE_SOURCE_FILE (insn
);
2825 /* Remember filename for basic block profiling.
2826 Filenames are allocated on the permanent obstack
2827 or are passed in ARGV, so we don't have to save
2830 if (profile_block_flag
&& last_filename
!= filename
)
2831 bb_file_label_num
= add_bb_string (filename
, TRUE
);
2833 last_filename
= filename
;
2834 last_linenum
= NOTE_LINE_NUMBER (insn
);
2835 high_block_linenum
= MAX (last_linenum
, high_block_linenum
);
2836 high_function_linenum
= MAX (last_linenum
, high_function_linenum
);
2838 if (write_symbols
!= NO_DEBUG
)
2840 #ifdef SDB_DEBUGGING_INFO
2841 if (write_symbols
== SDB_DEBUG
2842 #if 0 /* People like having line numbers even in wrong file! */
2843 /* COFF can't handle multiple source files--lose, lose. */
2844 && !strcmp (filename
, main_input_filename
)
2846 /* COFF relative line numbers must be positive. */
2847 && last_linenum
> sdb_begin_function_line
)
2849 #ifdef ASM_OUTPUT_SOURCE_LINE
2850 ASM_OUTPUT_SOURCE_LINE (file
, last_linenum
);
2852 fprintf (file
, "\t.ln\t%d\n",
2853 ((sdb_begin_function_line
> -1)
2854 ? last_linenum
- sdb_begin_function_line
: 1));
2859 #if defined (DBX_DEBUGGING_INFO)
2860 if (write_symbols
== DBX_DEBUG
)
2861 dbxout_source_line (file
, filename
, NOTE_LINE_NUMBER (insn
));
2864 #if defined (XCOFF_DEBUGGING_INFO)
2865 if (write_symbols
== XCOFF_DEBUG
)
2866 xcoffout_source_line (file
, filename
, insn
);
2869 #ifdef DWARF_DEBUGGING_INFO
2870 if (write_symbols
== DWARF_DEBUG
)
2871 dwarfout_line (filename
, NOTE_LINE_NUMBER (insn
));
2874 #ifdef DWARF2_DEBUGGING_INFO
2875 if (write_symbols
== DWARF2_DEBUG
)
2876 dwarf2out_line (filename
, NOTE_LINE_NUMBER (insn
));
2881 /* If X is a SUBREG, replace it with a REG or a MEM,
2882 based on the thing it is a subreg of. */
2888 register rtx y
= SUBREG_REG (x
);
2889 if (GET_CODE (y
) == SUBREG
)
2890 y
= alter_subreg (y
);
2892 if (GET_CODE (y
) == REG
)
2894 /* If the word size is larger than the size of this register,
2895 adjust the register number to compensate. */
2896 /* ??? Note that this just catches stragglers created by/for
2897 integrate. It would be better if we either caught these
2898 earlier, or kept _all_ subregs until now and eliminate
2899 gen_lowpart and friends. */
2902 #ifdef ALTER_HARD_SUBREG
2903 REGNO (x
) = ALTER_HARD_SUBREG(GET_MODE (x
), SUBREG_WORD (x
),
2904 GET_MODE (y
), REGNO (y
));
2906 REGNO (x
) = REGNO (y
) + SUBREG_WORD (x
);
2909 else if (GET_CODE (y
) == MEM
)
2911 register int offset
= SUBREG_WORD (x
) * UNITS_PER_WORD
;
2912 if (BYTES_BIG_ENDIAN
)
2913 offset
-= (MIN (UNITS_PER_WORD
, GET_MODE_SIZE (GET_MODE (x
)))
2914 - MIN (UNITS_PER_WORD
, GET_MODE_SIZE (GET_MODE (y
))));
2916 MEM_VOLATILE_P (x
) = MEM_VOLATILE_P (y
);
2917 XEXP (x
, 0) = plus_constant (XEXP (y
, 0), offset
);
2923 /* Do alter_subreg on all the SUBREGs contained in X. */
2926 walk_alter_subreg (x
)
2929 switch (GET_CODE (x
))
2933 XEXP (x
, 0) = walk_alter_subreg (XEXP (x
, 0));
2934 XEXP (x
, 1) = walk_alter_subreg (XEXP (x
, 1));
2938 XEXP (x
, 0) = walk_alter_subreg (XEXP (x
, 0));
2942 return alter_subreg (x
);
2953 /* Given BODY, the body of a jump instruction, alter the jump condition
2954 as required by the bits that are set in cc_status.flags.
2955 Not all of the bits there can be handled at this level in all cases.
2957 The value is normally 0.
2958 1 means that the condition has become always true.
2959 -1 means that the condition has become always false.
2960 2 means that COND has been altered. */
2968 if (cc_status
.flags
& CC_REVERSED
)
2971 PUT_CODE (cond
, swap_condition (GET_CODE (cond
)));
2974 if (cc_status
.flags
& CC_INVERTED
)
2977 PUT_CODE (cond
, reverse_condition (GET_CODE (cond
)));
2980 if (cc_status
.flags
& CC_NOT_POSITIVE
)
2981 switch (GET_CODE (cond
))
2986 /* Jump becomes unconditional. */
2992 /* Jump becomes no-op. */
2996 PUT_CODE (cond
, EQ
);
3001 PUT_CODE (cond
, NE
);
3009 if (cc_status
.flags
& CC_NOT_NEGATIVE
)
3010 switch (GET_CODE (cond
))
3014 /* Jump becomes unconditional. */
3019 /* Jump becomes no-op. */
3024 PUT_CODE (cond
, EQ
);
3030 PUT_CODE (cond
, NE
);
3038 if (cc_status
.flags
& CC_NO_OVERFLOW
)
3039 switch (GET_CODE (cond
))
3042 /* Jump becomes unconditional. */
3046 PUT_CODE (cond
, EQ
);
3051 PUT_CODE (cond
, NE
);
3056 /* Jump becomes no-op. */
3063 if (cc_status
.flags
& (CC_Z_IN_NOT_N
| CC_Z_IN_N
))
3064 switch (GET_CODE (cond
))
3070 PUT_CODE (cond
, cc_status
.flags
& CC_Z_IN_N
? GE
: LT
);
3075 PUT_CODE (cond
, cc_status
.flags
& CC_Z_IN_N
? LT
: GE
);
3080 if (cc_status
.flags
& CC_NOT_SIGNED
)
3081 /* The flags are valid if signed condition operators are converted
3083 switch (GET_CODE (cond
))
3086 PUT_CODE (cond
, LEU
);
3091 PUT_CODE (cond
, LTU
);
3096 PUT_CODE (cond
, GTU
);
3101 PUT_CODE (cond
, GEU
);
3113 /* Report inconsistency between the assembler template and the operands.
3114 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
3117 output_operand_lossage (str
)
3120 if (this_is_asm_operands
)
3121 error_for_asm (this_is_asm_operands
, "invalid `asm': %s", str
);
3126 /* Output of assembler code from a template, and its subroutines. */
3128 /* Output text from TEMPLATE to the assembler output file,
3129 obeying %-directions to substitute operands taken from
3130 the vector OPERANDS.
3132 %N (for N a digit) means print operand N in usual manner.
3133 %lN means require operand N to be a CODE_LABEL or LABEL_REF
3134 and print the label name with no punctuation.
3135 %cN means require operand N to be a constant
3136 and print the constant expression with no punctuation.
3137 %aN means expect operand N to be a memory address
3138 (not a memory reference!) and print a reference
3140 %nN means expect operand N to be a constant
3141 and print a constant expression for minus the value
3142 of the operand, with no other punctuation. */
3147 if (flag_print_asm_name
)
3149 /* Annotate the assembly with a comment describing the pattern and
3150 alternative used. */
3153 register int num
= INSN_CODE (debug_insn
);
3154 fprintf (asm_out_file
, " %s %d %s",
3155 ASM_COMMENT_START
, INSN_UID (debug_insn
), insn_name
[num
]);
3156 if (insn_n_alternatives
[num
] > 1)
3157 fprintf (asm_out_file
, "/%d", which_alternative
+ 1);
3159 /* Clear this so only the first assembler insn
3160 of any rtl insn will get the special comment for -dp. */
3167 output_asm_insn (template, operands
)
3174 /* An insn may return a null string template
3175 in a case where no assembler code is needed. */
3180 putc ('\t', asm_out_file
);
3182 #ifdef ASM_OUTPUT_OPCODE
3183 ASM_OUTPUT_OPCODE (asm_out_file
, p
);
3191 putc (c
, asm_out_file
);
3192 #ifdef ASM_OUTPUT_OPCODE
3193 while ((c
= *p
) == '\t')
3195 putc (c
, asm_out_file
);
3198 ASM_OUTPUT_OPCODE (asm_out_file
, p
);
3202 #ifdef ASSEMBLER_DIALECT
3207 /* If we want the first dialect, do nothing. Otherwise, skip
3208 DIALECT_NUMBER of strings ending with '|'. */
3209 for (i
= 0; i
< dialect_number
; i
++)
3211 while (*p
&& *p
++ != '|')
3221 /* Skip to close brace. */
3222 while (*p
&& *p
++ != '}')
3231 /* %% outputs a single %. */
3235 putc (c
, asm_out_file
);
3237 /* %= outputs a number which is unique to each insn in the entire
3238 compilation. This is useful for making local labels that are
3239 referred to more than once in a given insn. */
3243 fprintf (asm_out_file
, "%d", insn_counter
);
3245 /* % followed by a letter and some digits
3246 outputs an operand in a special way depending on the letter.
3247 Letters `acln' are implemented directly.
3248 Other letters are passed to `output_operand' so that
3249 the PRINT_OPERAND macro can define them. */
3250 else if ((*p
>= 'a' && *p
<= 'z')
3251 || (*p
>= 'A' && *p
<= 'Z'))
3256 if (! (*p
>= '0' && *p
<= '9'))
3257 output_operand_lossage ("operand number missing after %-letter");
3258 else if (this_is_asm_operands
&& (c
< 0 || (unsigned int) c
>= insn_noperands
))
3259 output_operand_lossage ("operand number out of range");
3260 else if (letter
== 'l')
3261 output_asm_label (operands
[c
]);
3262 else if (letter
== 'a')
3263 output_address (operands
[c
]);
3264 else if (letter
== 'c')
3266 if (CONSTANT_ADDRESS_P (operands
[c
]))
3267 output_addr_const (asm_out_file
, operands
[c
]);
3269 output_operand (operands
[c
], 'c');
3271 else if (letter
== 'n')
3273 if (GET_CODE (operands
[c
]) == CONST_INT
)
3274 fprintf (asm_out_file
, HOST_WIDE_INT_PRINT_DEC
,
3275 - INTVAL (operands
[c
]));
3278 putc ('-', asm_out_file
);
3279 output_addr_const (asm_out_file
, operands
[c
]);
3283 output_operand (operands
[c
], letter
);
3285 while ((c
= *p
) >= '0' && c
<= '9') p
++;
3287 /* % followed by a digit outputs an operand the default way. */
3288 else if (*p
>= '0' && *p
<= '9')
3291 if (this_is_asm_operands
&& (c
< 0 || (unsigned int) c
>= insn_noperands
))
3292 output_operand_lossage ("operand number out of range");
3294 output_operand (operands
[c
], 0);
3295 while ((c
= *p
) >= '0' && c
<= '9') p
++;
3297 /* % followed by punctuation: output something for that
3298 punctuation character alone, with no operand.
3299 The PRINT_OPERAND macro decides what is actually done. */
3300 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3301 else if (PRINT_OPERAND_PUNCT_VALID_P (*p
))
3302 output_operand (NULL_RTX
, *p
++);
3305 output_operand_lossage ("invalid %%-code");
3309 putc (c
, asm_out_file
);
3314 putc ('\n', asm_out_file
);
3317 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3320 output_asm_label (x
)
3325 if (GET_CODE (x
) == LABEL_REF
)
3326 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (XEXP (x
, 0)));
3327 else if (GET_CODE (x
) == CODE_LABEL
)
3328 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (x
));
3330 output_operand_lossage ("`%l' operand isn't a label");
3332 assemble_name (asm_out_file
, buf
);
3335 /* Print operand X using machine-dependent assembler syntax.
3336 The macro PRINT_OPERAND is defined just to control this function.
3337 CODE is a non-digit that preceded the operand-number in the % spec,
3338 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3339 between the % and the digits.
3340 When CODE is a non-letter, X is 0.
3342 The meanings of the letters are machine-dependent and controlled
3343 by PRINT_OPERAND. */
3346 output_operand (x
, code
)
3350 if (x
&& GET_CODE (x
) == SUBREG
)
3351 x
= alter_subreg (x
);
3353 /* If X is a pseudo-register, abort now rather than writing trash to the
3356 if (x
&& GET_CODE (x
) == REG
&& REGNO (x
) >= FIRST_PSEUDO_REGISTER
)
3359 PRINT_OPERAND (asm_out_file
, x
, code
);
3362 /* Print a memory reference operand for address X
3363 using machine-dependent assembler syntax.
3364 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
3370 walk_alter_subreg (x
);
3371 PRINT_OPERAND_ADDRESS (asm_out_file
, x
);
3374 /* Print an integer constant expression in assembler syntax.
3375 Addition and subtraction are the only arithmetic
3376 that may appear in these expressions. */
3379 output_addr_const (file
, x
)
3386 switch (GET_CODE (x
))
3396 assemble_name (file
, XSTR (x
, 0));
3400 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (XEXP (x
, 0)));
3401 assemble_name (file
, buf
);
3405 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (x
));
3406 assemble_name (file
, buf
);
3410 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
));
3414 /* This used to output parentheses around the expression,
3415 but that does not work on the 386 (either ATT or BSD assembler). */
3416 output_addr_const (file
, XEXP (x
, 0));
3420 if (GET_MODE (x
) == VOIDmode
)
3422 /* We can use %d if the number is one word and positive. */
3423 if (CONST_DOUBLE_HIGH (x
))
3424 fprintf (file
, HOST_WIDE_INT_PRINT_DOUBLE_HEX
,
3425 CONST_DOUBLE_HIGH (x
), CONST_DOUBLE_LOW (x
));
3426 else if (CONST_DOUBLE_LOW (x
) < 0)
3427 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, CONST_DOUBLE_LOW (x
));
3429 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, CONST_DOUBLE_LOW (x
));
3432 /* We can't handle floating point constants;
3433 PRINT_OPERAND must handle them. */
3434 output_operand_lossage ("floating constant misused");
3438 /* Some assemblers need integer constants to appear last (eg masm). */
3439 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
3441 output_addr_const (file
, XEXP (x
, 1));
3442 if (INTVAL (XEXP (x
, 0)) >= 0)
3443 fprintf (file
, "+");
3444 output_addr_const (file
, XEXP (x
, 0));
3448 output_addr_const (file
, XEXP (x
, 0));
3449 if (INTVAL (XEXP (x
, 1)) >= 0)
3450 fprintf (file
, "+");
3451 output_addr_const (file
, XEXP (x
, 1));
3456 /* Avoid outputting things like x-x or x+5-x,
3457 since some assemblers can't handle that. */
3458 x
= simplify_subtraction (x
);
3459 if (GET_CODE (x
) != MINUS
)
3462 output_addr_const (file
, XEXP (x
, 0));
3463 fprintf (file
, "-");
3464 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
3465 && INTVAL (XEXP (x
, 1)) < 0)
3467 fprintf (file
, ASM_OPEN_PAREN
);
3468 output_addr_const (file
, XEXP (x
, 1));
3469 fprintf (file
, ASM_CLOSE_PAREN
);
3472 output_addr_const (file
, XEXP (x
, 1));
3477 output_addr_const (file
, XEXP (x
, 0));
3481 output_operand_lossage ("invalid expression as operand");
3485 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3486 %R prints the value of REGISTER_PREFIX.
3487 %L prints the value of LOCAL_LABEL_PREFIX.
3488 %U prints the value of USER_LABEL_PREFIX.
3489 %I prints the value of IMMEDIATE_PREFIX.
3490 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3491 Also supported are %d, %x, %s, %e, %f, %g and %%.
3493 We handle alternate assembler dialects here, just like output_asm_insn. */
3496 asm_fprintf
VPROTO((FILE *file
, char *p
, ...))
3506 VA_START (argptr
, p
);
3509 file
= va_arg (argptr
, FILE *);
3510 p
= va_arg (argptr
, char *);
3518 #ifdef ASSEMBLER_DIALECT
3523 /* If we want the first dialect, do nothing. Otherwise, skip
3524 DIALECT_NUMBER of strings ending with '|'. */
3525 for (i
= 0; i
< dialect_number
; i
++)
3527 while (*p
&& *p
++ != '|')
3537 /* Skip to close brace. */
3538 while (*p
&& *p
++ != '}')
3549 while ((c
>= '0' && c
<= '9') || c
== '.')
3557 fprintf (file
, "%%");
3560 case 'd': case 'i': case 'u':
3561 case 'x': case 'p': case 'X':
3565 fprintf (file
, buf
, va_arg (argptr
, int));
3569 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3570 but we do not check for those cases. It means that the value
3571 is a HOST_WIDE_INT, which may be either `int' or `long'. */
3573 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3575 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3585 fprintf (file
, buf
, va_arg (argptr
, HOST_WIDE_INT
));
3592 fprintf (file
, buf
, va_arg (argptr
, long));
3600 fprintf (file
, buf
, va_arg (argptr
, double));
3606 fprintf (file
, buf
, va_arg (argptr
, char *));
3610 #ifdef ASM_OUTPUT_OPCODE
3611 ASM_OUTPUT_OPCODE (asm_out_file
, p
);
3616 #ifdef REGISTER_PREFIX
3617 fprintf (file
, "%s", REGISTER_PREFIX
);
3622 #ifdef IMMEDIATE_PREFIX
3623 fprintf (file
, "%s", IMMEDIATE_PREFIX
);
3628 #ifdef LOCAL_LABEL_PREFIX
3629 fprintf (file
, "%s", LOCAL_LABEL_PREFIX
);
3634 #ifdef USER_LABEL_PREFIX
3635 fprintf (file
, "%s", USER_LABEL_PREFIX
);
3649 /* Split up a CONST_DOUBLE or integer constant rtx
3650 into two rtx's for single words,
3651 storing in *FIRST the word that comes first in memory in the target
3652 and in *SECOND the other. */
3655 split_double (value
, first
, second
)
3657 rtx
*first
, *second
;
3659 if (GET_CODE (value
) == CONST_INT
)
3661 if (HOST_BITS_PER_WIDE_INT
>= (2 * BITS_PER_WORD
))
3663 /* In this case the CONST_INT holds both target words.
3664 Extract the bits from it into two word-sized pieces. */
3666 HOST_WIDE_INT word_mask
;
3667 /* Avoid warnings for shift count >= BITS_PER_WORD. */
3668 int shift_count
= BITS_PER_WORD
- 1;
3670 word_mask
= (HOST_WIDE_INT
) 1 << shift_count
;
3671 word_mask
|= word_mask
- 1;
3672 low
= GEN_INT (INTVAL (value
) & word_mask
);
3673 high
= GEN_INT ((INTVAL (value
) >> (shift_count
+ 1)) & word_mask
);
3674 if (WORDS_BIG_ENDIAN
)
3687 /* The rule for using CONST_INT for a wider mode
3688 is that we regard the value as signed.
3689 So sign-extend it. */
3690 rtx high
= (INTVAL (value
) < 0 ? constm1_rtx
: const0_rtx
);
3691 if (WORDS_BIG_ENDIAN
)
3703 else if (GET_CODE (value
) != CONST_DOUBLE
)
3705 if (WORDS_BIG_ENDIAN
)
3707 *first
= const0_rtx
;
3713 *second
= const0_rtx
;
3716 else if (GET_MODE (value
) == VOIDmode
3717 /* This is the old way we did CONST_DOUBLE integers. */
3718 || GET_MODE_CLASS (GET_MODE (value
)) == MODE_INT
)
3720 /* In an integer, the words are defined as most and least significant.
3721 So order them by the target's convention. */
3722 if (WORDS_BIG_ENDIAN
)
3724 *first
= GEN_INT (CONST_DOUBLE_HIGH (value
));
3725 *second
= GEN_INT (CONST_DOUBLE_LOW (value
));
3729 *first
= GEN_INT (CONST_DOUBLE_LOW (value
));
3730 *second
= GEN_INT (CONST_DOUBLE_HIGH (value
));
3735 #ifdef REAL_ARITHMETIC
3736 REAL_VALUE_TYPE r
; long l
[2];
3737 REAL_VALUE_FROM_CONST_DOUBLE (r
, value
);
3739 /* Note, this converts the REAL_VALUE_TYPE to the target's
3740 format, splits up the floating point double and outputs
3741 exactly 32 bits of it into each of l[0] and l[1] --
3742 not necessarily BITS_PER_WORD bits. */
3743 REAL_VALUE_TO_TARGET_DOUBLE (r
, l
);
3745 *first
= GEN_INT ((HOST_WIDE_INT
) l
[0]);
3746 *second
= GEN_INT ((HOST_WIDE_INT
) l
[1]);
3748 if ((HOST_FLOAT_FORMAT
!= TARGET_FLOAT_FORMAT
3749 || HOST_BITS_PER_WIDE_INT
!= BITS_PER_WORD
)
3750 && ! flag_pretend_float
)
3754 #ifdef HOST_WORDS_BIG_ENDIAN
3761 /* Host and target agree => no need to swap. */
3762 *first
= GEN_INT (CONST_DOUBLE_LOW (value
));
3763 *second
= GEN_INT (CONST_DOUBLE_HIGH (value
));
3767 *second
= GEN_INT (CONST_DOUBLE_LOW (value
));
3768 *first
= GEN_INT (CONST_DOUBLE_HIGH (value
));
3770 #endif /* no REAL_ARITHMETIC */
3774 /* Return nonzero if this function has no function calls. */
3781 if (profile_flag
|| profile_block_flag
|| profile_arc_flag
)
3784 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3786 if (GET_CODE (insn
) == CALL_INSN
)
3788 if (GET_CODE (insn
) == INSN
3789 && GET_CODE (PATTERN (insn
)) == SEQUENCE
3790 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == CALL_INSN
)
3793 for (insn
= current_function_epilogue_delay_list
; insn
; insn
= XEXP (insn
, 1))
3795 if (GET_CODE (XEXP (insn
, 0)) == CALL_INSN
)
3797 if (GET_CODE (XEXP (insn
, 0)) == INSN
3798 && GET_CODE (PATTERN (XEXP (insn
, 0))) == SEQUENCE
3799 && GET_CODE (XVECEXP (PATTERN (XEXP (insn
, 0)), 0, 0)) == CALL_INSN
)
3806 /* On some machines, a function with no call insns
3807 can run faster if it doesn't create its own register window.
3808 When output, the leaf function should use only the "output"
3809 registers. Ordinarily, the function would be compiled to use
3810 the "input" registers to find its arguments; it is a candidate
3811 for leaf treatment if it uses only the "input" registers.
3812 Leaf function treatment means renumbering so the function
3813 uses the "output" registers instead. */
3815 #ifdef LEAF_REGISTERS
3817 static char permitted_reg_in_leaf_functions
[] = LEAF_REGISTERS
;
3819 /* Return 1 if this function uses only the registers that can be
3820 safely renumbered. */
3823 only_leaf_regs_used ()
3827 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
3828 if ((regs_ever_live
[i
] || global_regs
[i
])
3829 && ! permitted_reg_in_leaf_functions
[i
])
3832 if (current_function_uses_pic_offset_table
3833 && pic_offset_table_rtx
!= 0
3834 && GET_CODE (pic_offset_table_rtx
) == REG
3835 && ! permitted_reg_in_leaf_functions
[REGNO (pic_offset_table_rtx
)])
3841 /* Scan all instructions and renumber all registers into those
3842 available in leaf functions. */
3845 leaf_renumber_regs (first
)
3850 /* Renumber only the actual patterns.
3851 The reg-notes can contain frame pointer refs,
3852 and renumbering them could crash, and should not be needed. */
3853 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
3854 if (GET_RTX_CLASS (GET_CODE (insn
)) == 'i')
3855 leaf_renumber_regs_insn (PATTERN (insn
));
3856 for (insn
= current_function_epilogue_delay_list
; insn
; insn
= XEXP (insn
, 1))
3857 if (GET_RTX_CLASS (GET_CODE (XEXP (insn
, 0))) == 'i')
3858 leaf_renumber_regs_insn (PATTERN (XEXP (insn
, 0)));
3861 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
3862 available in leaf functions. */
3865 leaf_renumber_regs_insn (in_rtx
)
3866 register rtx in_rtx
;
3869 register char *format_ptr
;
3874 /* Renumber all input-registers into output-registers.
3875 renumbered_regs would be 1 for an output-register;
3878 if (GET_CODE (in_rtx
) == REG
)
3882 /* Don't renumber the same reg twice. */
3886 newreg
= REGNO (in_rtx
);
3887 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
3888 to reach here as part of a REG_NOTE. */
3889 if (newreg
>= FIRST_PSEUDO_REGISTER
)
3894 newreg
= LEAF_REG_REMAP (newreg
);
3897 regs_ever_live
[REGNO (in_rtx
)] = 0;
3898 regs_ever_live
[newreg
] = 1;
3899 REGNO (in_rtx
) = newreg
;
3903 if (GET_RTX_CLASS (GET_CODE (in_rtx
)) == 'i')
3905 /* Inside a SEQUENCE, we find insns.
3906 Renumber just the patterns of these insns,
3907 just as we do for the top-level insns. */
3908 leaf_renumber_regs_insn (PATTERN (in_rtx
));
3912 format_ptr
= GET_RTX_FORMAT (GET_CODE (in_rtx
));
3914 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (in_rtx
)); i
++)
3915 switch (*format_ptr
++)
3918 leaf_renumber_regs_insn (XEXP (in_rtx
, i
));
3922 if (NULL
!= XVEC (in_rtx
, i
))
3924 for (j
= 0; j
< XVECLEN (in_rtx
, i
); j
++)
3925 leaf_renumber_regs_insn (XVECEXP (in_rtx
, i
, j
));