1 /* Convert RTL to assembler code and output it, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
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 in assembler by the target functions function_prologue and
45 function_epilogue. Those instructions never exist as rtl. */
54 #include "insn-config.h"
55 #include "insn-attr.h"
57 #include "conditions.h"
60 #include "hard-reg-set.h"
67 #include "basic-block.h"
72 #ifdef XCOFF_DEBUGGING_INFO
73 #include "xcoffout.h" /* Needed for external data
74 declarations for e.g. AIX 4.x. */
77 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
78 #include "dwarf2out.h"
81 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
82 null default for it to save conditionalization later. */
83 #ifndef CC_STATUS_INIT
84 #define CC_STATUS_INIT
87 /* How to start an assembler comment. */
88 #ifndef ASM_COMMENT_START
89 #define ASM_COMMENT_START ";#"
92 /* Is the given character a logical line separator for the assembler? */
93 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
94 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
97 #ifndef JUMP_TABLES_IN_TEXT_SECTION
98 #define JUMP_TABLES_IN_TEXT_SECTION 0
101 /* Last insn processed by final_scan_insn. */
102 static rtx debug_insn;
103 rtx current_output_insn;
105 /* Line number of last NOTE. */
106 static int last_linenum;
108 /* Highest line number in current block. */
109 static int high_block_linenum;
111 /* Likewise for function. */
112 static int high_function_linenum;
114 /* Filename of last NOTE. */
115 static const char *last_filename;
117 /* Number of basic blocks seen so far;
118 used if profile_block_flag is set. */
119 static int count_basic_blocks;
121 /* Number of instrumented arcs when profile_arc_flag is set. */
122 extern int count_instrumented_edges;
124 extern int length_unit_log; /* This is defined in insn-attrtab.c. */
126 /* Nonzero while outputting an `asm' with operands.
127 This means that inconsistencies are the user's fault, so don't abort.
128 The precise value is the insn being output, to pass to error_for_asm. */
129 static rtx this_is_asm_operands;
131 /* Number of operands of this insn, for an `asm' with operands. */
132 static unsigned int insn_noperands;
134 /* Compare optimization flag. */
136 static rtx last_ignored_compare = 0;
138 /* Flag indicating this insn is the start of a new basic block. */
140 static int new_block = 1;
142 /* Assign a unique number to each insn that is output.
143 This can be used to generate unique local labels. */
145 static int insn_counter = 0;
148 /* This variable contains machine-dependent flags (defined in tm.h)
149 set and examined by output routines
150 that describe how to interpret the condition codes properly. */
154 /* During output of an insn, this contains a copy of cc_status
155 from before the insn. */
157 CC_STATUS cc_prev_status;
160 /* Indexed by hardware reg number, is 1 if that register is ever
161 used in the current function.
163 In life_analysis, or in stupid_life_analysis, this is set
164 up to record the hard regs used explicitly. Reload adds
165 in the hard regs used for holding pseudo regs. Final uses
166 it to generate the code in the function prologue and epilogue
167 to save and restore registers as needed. */
169 char regs_ever_live[FIRST_PSEUDO_REGISTER];
171 /* Nonzero means current function must be given a frame pointer.
172 Set in stmt.c if anything is allocated on the stack there.
173 Set in reload1.c if anything is allocated on the stack there. */
175 int frame_pointer_needed;
177 /* Assign unique numbers to labels generated for profiling. */
179 int profile_label_no;
181 /* Number of unmatched NOTE_INSN_BLOCK_BEG notes we have seen. */
183 static int block_depth;
185 /* Nonzero if have enabled APP processing of our assembler output. */
189 /* If we are outputting an insn sequence, this contains the sequence rtx.
194 #ifdef ASSEMBLER_DIALECT
196 /* Number of the assembler dialect to use, starting at 0. */
197 static int dialect_number;
200 /* Indexed by line number, nonzero if there is a note for that line. */
202 static char *line_note_exists;
204 #ifdef HAVE_conditional_execution
205 /* Nonnull if the insn currently being emitted was a COND_EXEC pattern. */
206 rtx current_insn_predicate;
209 /* Linked list to hold line numbers for each basic block. */
213 struct bb_list *next; /* pointer to next basic block */
214 int line_num; /* line number */
215 int file_label_num; /* LPBC<n> label # for stored filename */
216 int func_label_num; /* LPBC<n> label # for stored function name */
219 static struct bb_list *bb_head = 0; /* Head of basic block list */
220 static struct bb_list **bb_tail = &bb_head; /* Ptr to store next bb ptr */
221 static int bb_file_label_num = -1; /* Current label # for file */
222 static int bb_func_label_num = -1; /* Current label # for func */
224 /* Linked list to hold the strings for each file and function name output. */
228 struct bb_str *next; /* pointer to next string */
229 const char *string; /* string */
230 int label_num; /* label number */
231 int length; /* string length */
234 static struct bb_str *sbb_head = 0; /* Head of string list. */
235 static struct bb_str **sbb_tail = &sbb_head; /* Ptr to store next bb str */
236 static int sbb_label_num = 0; /* Last label used */
238 #ifdef HAVE_ATTR_length
239 static int asm_insn_count PARAMS ((rtx));
241 static void profile_function PARAMS ((FILE *));
242 static void profile_after_prologue PARAMS ((FILE *));
243 static void add_bb PARAMS ((FILE *));
244 static int add_bb_string PARAMS ((const char *, int));
245 static void notice_source_line PARAMS ((rtx));
246 static rtx walk_alter_subreg PARAMS ((rtx *));
247 static void output_asm_name PARAMS ((void));
248 static tree get_decl_from_op PARAMS ((rtx, int *));
249 static void output_asm_operand_names PARAMS ((rtx *, int *, int));
250 static void output_operand PARAMS ((rtx, int));
251 #ifdef LEAF_REGISTERS
252 static void leaf_renumber_regs PARAMS ((rtx));
255 static int alter_cond PARAMS ((rtx));
257 #ifndef ADDR_VEC_ALIGN
258 static int final_addr_vec_align PARAMS ((rtx));
260 #ifdef HAVE_ATTR_length
261 static int align_fuzz PARAMS ((rtx, rtx, int, unsigned));
264 /* Initialize data in final at the beginning of a compilation. */
267 init_final (filename)
268 const char *filename ATTRIBUTE_UNUSED;
273 #ifdef ASSEMBLER_DIALECT
274 dialect_number = ASSEMBLER_DIALECT;
278 /* Called at end of source file,
279 to output the block-profiling table for this entire compilation. */
283 const char *filename;
287 if (profile_block_flag || profile_arc_flag)
290 int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
294 int long_bytes = LONG_TYPE_SIZE / BITS_PER_UNIT;
295 int gcov_type_bytes = GCOV_TYPE_SIZE / BITS_PER_UNIT;
296 int pointer_bytes = POINTER_SIZE / BITS_PER_UNIT;
297 unsigned int align2 = LONG_TYPE_SIZE;
299 if (profile_block_flag)
300 size = long_bytes * count_basic_blocks;
302 size = gcov_type_bytes * count_instrumented_edges;
305 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
306 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
307 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
309 /* ??? This _really_ ought to be done with a structure layout
310 and with assemble_constructor. If long_bytes != pointer_bytes
311 we'll be emitting unaligned data at some point. */
312 if (long_bytes != pointer_bytes)
317 /* Output the main header, of 11 words:
318 0: 1 if this file is initialized, else 0.
319 1: address of file name (LPBX1).
320 2: address of table of counts (LPBX2).
321 3: number of counts in the table.
322 4: always 0, for compatibility with Sun.
324 The following are GNU extensions:
326 5: address of table of start addrs of basic blocks (LPBX3).
327 6: Number of bytes in this header.
328 7: address of table of function names (LPBX4).
329 8: address of table of line numbers (LPBX5) or 0.
330 9: address of table of file names (LPBX6) or 0.
331 10: space reserved for basic block profiling. */
333 ASM_OUTPUT_ALIGN (asm_out_file, align);
335 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
338 assemble_integer (const0_rtx, long_bytes, align2, 1);
340 /* Address of filename. */
341 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
342 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
345 /* Address of count table. */
346 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
347 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
350 /* Count of the # of basic blocks or # of instrumented arcs. */
351 assemble_integer (GEN_INT (profile_block_flag
353 : count_instrumented_edges),
354 long_bytes, align2, 1);
356 /* Zero word (link field). */
357 assemble_integer (const0_rtx, pointer_bytes, align2, 1);
359 /* address of basic block start address table */
360 if (profile_block_flag)
362 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
363 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
364 pointer_bytes, align2, 1);
367 assemble_integer (const0_rtx, pointer_bytes, align2, 1);
369 /* Byte count for extended structure. */
370 assemble_integer (GEN_INT (11 * UNITS_PER_WORD), long_bytes, align2, 1);
372 /* Address of function name table. */
373 if (profile_block_flag)
375 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
376 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
377 pointer_bytes, align2, 1);
380 assemble_integer (const0_rtx, pointer_bytes, align2, 1);
382 /* Address of line number and filename tables if debugging. */
383 if (write_symbols != NO_DEBUG && profile_block_flag)
385 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
386 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
387 pointer_bytes, align2, 1);
388 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
389 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
390 pointer_bytes, align2, 1);
394 assemble_integer (const0_rtx, pointer_bytes, align2, 1);
395 assemble_integer (const0_rtx, pointer_bytes, align2, 1);
398 /* Space for extension ptr (link field). */
399 assemble_integer (const0_rtx, UNITS_PER_WORD, align2, 1);
401 /* Output the file name changing the suffix to .d for
402 Sun tcov compatibility. */
403 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
405 char *cwd = getpwd ();
406 int len = strlen (filename) + strlen (cwd) + 1;
407 char *data_file = (char *) alloca (len + 4);
409 strcpy (data_file, cwd);
410 strcat (data_file, "/");
411 strcat (data_file, filename);
412 strip_off_ending (data_file, len);
413 if (profile_block_flag)
414 strcat (data_file, ".d");
416 strcat (data_file, ".da");
417 assemble_string (data_file, strlen (data_file) + 1);
420 /* Make space for the table of counts. */
423 /* Realign data section. */
424 ASM_OUTPUT_ALIGN (asm_out_file, align);
425 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
427 assemble_zeros (size);
431 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
432 #ifdef ASM_OUTPUT_SHARED_LOCAL
433 if (flag_shared_data)
434 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
437 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
438 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name,
439 size, BIGGEST_ALIGNMENT);
441 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
442 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
445 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
450 /* Output any basic block strings */
451 if (profile_block_flag)
453 readonly_data_section ();
456 ASM_OUTPUT_ALIGN (asm_out_file, align);
457 for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
459 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC",
461 assemble_string (sptr->string, sptr->length);
466 /* Output the table of addresses. */
467 if (profile_block_flag)
469 /* Realign in new section */
470 ASM_OUTPUT_ALIGN (asm_out_file, align);
471 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
472 for (i = 0; i < count_basic_blocks; i++)
474 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
475 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
476 pointer_bytes, align2, 1);
480 /* Output the table of function names. */
481 if (profile_block_flag)
483 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
484 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
486 if (ptr->func_label_num >= 0)
488 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
489 ptr->func_label_num);
490 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
491 pointer_bytes, align2, 1);
494 assemble_integer (const0_rtx, pointer_bytes, align2, 1);
497 for (; i < count_basic_blocks; i++)
498 assemble_integer (const0_rtx, pointer_bytes, align2, 1);
501 if (write_symbols != NO_DEBUG && profile_block_flag)
503 /* Output the table of line numbers. */
504 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
505 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
506 assemble_integer (GEN_INT (ptr->line_num), long_bytes, align2, 1);
508 for (; i < count_basic_blocks; i++)
509 assemble_integer (const0_rtx, long_bytes, align2, 1);
511 /* Output the table of file names. */
512 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
513 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
515 if (ptr->file_label_num >= 0)
517 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
518 ptr->file_label_num);
519 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
520 pointer_bytes, align2, 1);
523 assemble_integer (const0_rtx, pointer_bytes, align2, 1);
526 for (; i < count_basic_blocks; i++)
527 assemble_integer (const0_rtx, pointer_bytes, align2, 1);
530 /* End with the address of the table of addresses,
531 so we can find it easily, as the last word in the file's text. */
532 if (profile_block_flag)
534 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
535 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
536 pointer_bytes, align2, 1);
541 /* Default target function prologue and epilogue assembler output.
543 If not overridden for epilogue code, then the function body itself
544 contains return instructions wherever needed. */
546 default_function_pro_epilogue (file, size)
547 FILE *file ATTRIBUTE_UNUSED;
548 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
552 /* Default target hook that outputs nothing to a stream. */
554 no_asm_to_stream (file)
555 FILE *file ATTRIBUTE_UNUSED;
559 /* Enable APP processing of subsequent output.
560 Used before the output from an `asm' statement. */
567 fputs (ASM_APP_ON, asm_out_file);
572 /* Disable APP processing of subsequent output.
573 Called from varasm.c before most kinds of output. */
580 fputs (ASM_APP_OFF, asm_out_file);
585 /* Return the number of slots filled in the current
586 delayed branch sequence (we don't count the insn needing the
587 delay slot). Zero if not in a delayed branch sequence. */
591 dbr_sequence_length ()
593 if (final_sequence != 0)
594 return XVECLEN (final_sequence, 0) - 1;
600 /* The next two pages contain routines used to compute the length of an insn
601 and to shorten branches. */
603 /* Arrays for insn lengths, and addresses. The latter is referenced by
604 `insn_current_length'. */
606 static short *insn_lengths;
608 #ifdef HAVE_ATTR_length
609 varray_type insn_addresses_;
612 /* Max uid for which the above arrays are valid. */
613 static int insn_lengths_max_uid;
615 /* Address of insn being processed. Used by `insn_current_length'. */
616 int insn_current_address;
618 /* Address of insn being processed in previous iteration. */
619 int insn_last_address;
621 /* konwn invariant alignment of insn being processed. */
622 int insn_current_align;
624 /* After shorten_branches, for any insn, uid_align[INSN_UID (insn)]
625 gives the next following alignment insn that increases the known
626 alignment, or NULL_RTX if there is no such insn.
627 For any alignment obtained this way, we can again index uid_align with
628 its uid to obtain the next following align that in turn increases the
629 alignment, till we reach NULL_RTX; the sequence obtained this way
630 for each insn we'll call the alignment chain of this insn in the following
633 struct label_alignment
639 static rtx *uid_align;
640 static int *uid_shuid;
641 static struct label_alignment *label_align;
643 /* Indicate that branch shortening hasn't yet been done. */
657 insn_lengths_max_uid = 0;
659 #ifdef HAVE_ATTR_length
660 INSN_ADDRESSES_FREE ();
669 /* Obtain the current length of an insn. If branch shortening has been done,
670 get its actual length. Otherwise, get its maximum length. */
673 get_attr_length (insn)
674 rtx insn ATTRIBUTE_UNUSED;
676 #ifdef HAVE_ATTR_length
681 if (insn_lengths_max_uid > INSN_UID (insn))
682 return insn_lengths[INSN_UID (insn)];
684 switch (GET_CODE (insn))
692 length = insn_default_length (insn);
696 body = PATTERN (insn);
697 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
699 /* Alignment is machine-dependent and should be handled by
703 length = insn_default_length (insn);
707 body = PATTERN (insn);
708 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
711 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
712 length = asm_insn_count (body) * insn_default_length (insn);
713 else if (GET_CODE (body) == SEQUENCE)
714 for (i = 0; i < XVECLEN (body, 0); i++)
715 length += get_attr_length (XVECEXP (body, 0, i));
717 length = insn_default_length (insn);
724 #ifdef ADJUST_INSN_LENGTH
725 ADJUST_INSN_LENGTH (insn, length);
728 #else /* not HAVE_ATTR_length */
730 #endif /* not HAVE_ATTR_length */
733 /* Code to handle alignment inside shorten_branches. */
735 /* Here is an explanation how the algorithm in align_fuzz can give
738 Call a sequence of instructions beginning with alignment point X
739 and continuing until the next alignment point `block X'. When `X'
740 is used in an expression, it means the alignment value of the
743 Call the distance between the start of the first insn of block X, and
744 the end of the last insn of block X `IX', for the `inner size of X'.
745 This is clearly the sum of the instruction lengths.
747 Likewise with the next alignment-delimited block following X, which we
750 Call the distance between the start of the first insn of block X, and
751 the start of the first insn of block Y `OX', for the `outer size of X'.
753 The estimated padding is then OX - IX.
755 OX can be safely estimated as
760 OX = round_up(IX, X) + Y - X
762 Clearly est(IX) >= real(IX), because that only depends on the
763 instruction lengths, and those being overestimated is a given.
765 Clearly round_up(foo, Z) >= round_up(bar, Z) if foo >= bar, so
766 we needn't worry about that when thinking about OX.
768 When X >= Y, the alignment provided by Y adds no uncertainty factor
769 for branch ranges starting before X, so we can just round what we have.
770 But when X < Y, we don't know anything about the, so to speak,
771 `middle bits', so we have to assume the worst when aligning up from an
772 address mod X to one mod Y, which is Y - X. */
775 #define LABEL_ALIGN(LABEL) align_labels_log
778 #ifndef LABEL_ALIGN_MAX_SKIP
779 #define LABEL_ALIGN_MAX_SKIP align_labels_max_skip
783 #define LOOP_ALIGN(LABEL) align_loops_log
786 #ifndef LOOP_ALIGN_MAX_SKIP
787 #define LOOP_ALIGN_MAX_SKIP align_loops_max_skip
790 #ifndef LABEL_ALIGN_AFTER_BARRIER
791 #define LABEL_ALIGN_AFTER_BARRIER(LABEL) 0
794 #ifndef LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP
795 #define LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP 0
799 #define JUMP_ALIGN(LABEL) align_jumps_log
802 #ifndef JUMP_ALIGN_MAX_SKIP
803 #define JUMP_ALIGN_MAX_SKIP align_jumps_max_skip
806 #ifndef ADDR_VEC_ALIGN
808 final_addr_vec_align (addr_vec)
811 int align = GET_MODE_SIZE (GET_MODE (PATTERN (addr_vec)));
813 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
814 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
815 return exact_log2 (align);
819 #define ADDR_VEC_ALIGN(ADDR_VEC) final_addr_vec_align (ADDR_VEC)
822 #ifndef INSN_LENGTH_ALIGNMENT
823 #define INSN_LENGTH_ALIGNMENT(INSN) length_unit_log
826 #define INSN_SHUID(INSN) (uid_shuid[INSN_UID (INSN)])
828 static int min_labelno, max_labelno;
830 #define LABEL_TO_ALIGNMENT(LABEL) \
831 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].alignment)
833 #define LABEL_TO_MAX_SKIP(LABEL) \
834 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].max_skip)
836 /* For the benefit of port specific code do this also as a function. */
839 label_to_alignment (label)
842 return LABEL_TO_ALIGNMENT (label);
845 #ifdef HAVE_ATTR_length
846 /* The differences in addresses
847 between a branch and its target might grow or shrink depending on
848 the alignment the start insn of the range (the branch for a forward
849 branch or the label for a backward branch) starts out on; if these
850 differences are used naively, they can even oscillate infinitely.
851 We therefore want to compute a 'worst case' address difference that
852 is independent of the alignment the start insn of the range end
853 up on, and that is at least as large as the actual difference.
854 The function align_fuzz calculates the amount we have to add to the
855 naively computed difference, by traversing the part of the alignment
856 chain of the start insn of the range that is in front of the end insn
857 of the range, and considering for each alignment the maximum amount
858 that it might contribute to a size increase.
860 For casesi tables, we also want to know worst case minimum amounts of
861 address difference, in case a machine description wants to introduce
862 some common offset that is added to all offsets in a table.
863 For this purpose, align_fuzz with a growth argument of 0 comuptes the
864 appropriate adjustment. */
866 /* Compute the maximum delta by which the difference of the addresses of
867 START and END might grow / shrink due to a different address for start
868 which changes the size of alignment insns between START and END.
869 KNOWN_ALIGN_LOG is the alignment known for START.
870 GROWTH should be ~0 if the objective is to compute potential code size
871 increase, and 0 if the objective is to compute potential shrink.
872 The return value is undefined for any other value of GROWTH. */
875 align_fuzz (start, end, known_align_log, growth)
880 int uid = INSN_UID (start);
882 int known_align = 1 << known_align_log;
883 int end_shuid = INSN_SHUID (end);
886 for (align_label = uid_align[uid]; align_label; align_label = uid_align[uid])
888 int align_addr, new_align;
890 uid = INSN_UID (align_label);
891 align_addr = INSN_ADDRESSES (uid) - insn_lengths[uid];
892 if (uid_shuid[uid] > end_shuid)
894 known_align_log = LABEL_TO_ALIGNMENT (align_label);
895 new_align = 1 << known_align_log;
896 if (new_align < known_align)
898 fuzz += (-align_addr ^ growth) & (new_align - known_align);
899 known_align = new_align;
904 /* Compute a worst-case reference address of a branch so that it
905 can be safely used in the presence of aligned labels. Since the
906 size of the branch itself is unknown, the size of the branch is
907 not included in the range. I.e. for a forward branch, the reference
908 address is the end address of the branch as known from the previous
909 branch shortening pass, minus a value to account for possible size
910 increase due to alignment. For a backward branch, it is the start
911 address of the branch as known from the current pass, plus a value
912 to account for possible size increase due to alignment.
913 NB.: Therefore, the maximum offset allowed for backward branches needs
914 to exclude the branch size. */
917 insn_current_reference_address (branch)
923 if (! INSN_ADDRESSES_SET_P ())
926 seq = NEXT_INSN (PREV_INSN (branch));
927 seq_uid = INSN_UID (seq);
928 if (GET_CODE (branch) != JUMP_INSN)
929 /* This can happen for example on the PA; the objective is to know the
930 offset to address something in front of the start of the function.
931 Thus, we can treat it like a backward branch.
932 We assume here that FUNCTION_BOUNDARY / BITS_PER_UNIT is larger than
933 any alignment we'd encounter, so we skip the call to align_fuzz. */
934 return insn_current_address;
935 dest = JUMP_LABEL (branch);
937 /* BRANCH has no proper alignment chain set, so use SEQ.
938 BRANCH also has no INSN_SHUID. */
939 if (INSN_SHUID (seq) < INSN_SHUID (dest))
941 /* Forward branch. */
942 return (insn_last_address + insn_lengths[seq_uid]
943 - align_fuzz (seq, dest, length_unit_log, ~0));
947 /* Backward branch. */
948 return (insn_current_address
949 + align_fuzz (dest, seq, length_unit_log, ~0));
952 #endif /* HAVE_ATTR_length */
955 compute_alignments ()
958 int log, max_skip, max_log;
966 max_labelno = max_label_num ();
967 min_labelno = get_first_label_num ();
968 label_align = (struct label_alignment *)
969 xcalloc (max_labelno - min_labelno + 1, sizeof (struct label_alignment));
971 /* If not optimizing or optimizing for size, don't assign any alignments. */
972 if (! optimize || optimize_size)
975 for (i = 0; i < n_basic_blocks; i++)
977 basic_block bb = BASIC_BLOCK (i);
978 rtx label = bb->head;
979 int fallthru_frequency = 0, branch_frequency = 0, has_fallthru = 0;
982 if (GET_CODE (label) != CODE_LABEL)
984 max_log = LABEL_ALIGN (label);
985 max_skip = LABEL_ALIGN_MAX_SKIP;
987 for (e = bb->pred; e; e = e->pred_next)
989 if (e->flags & EDGE_FALLTHRU)
990 has_fallthru = 1, fallthru_frequency += EDGE_FREQUENCY (e);
992 branch_frequency += EDGE_FREQUENCY (e);
995 /* There are two purposes to align block with no fallthru incoming edge:
996 1) to avoid fetch stalls when branch destination is near cache boundary
997 2) to improve cache effciency in case the previous block is not executed
998 (so it does not need to be in the cache).
1000 We to catch first case, we align frequently executed blocks.
1001 To catch the second, we align blocks that are executed more frequently
1002 than the predecessor and the predecessor is likely to not be executed
1003 when function is called. */
1006 && (branch_frequency > BB_FREQ_MAX / 10
1007 || (bb->frequency > BASIC_BLOCK (i - 1)->frequency * 10
1008 && (BASIC_BLOCK (i - 1)->frequency
1009 <= ENTRY_BLOCK_PTR->frequency / 2))))
1011 log = JUMP_ALIGN (label);
1015 max_skip = JUMP_ALIGN_MAX_SKIP;
1018 /* In case block is frequent and reached mostly by non-fallthru edge,
1019 align it. It is most likely an first block of loop. */
1021 && branch_frequency + fallthru_frequency > BB_FREQ_MAX / 10
1022 && branch_frequency > fallthru_frequency * 5)
1024 log = LOOP_ALIGN (label);
1028 max_skip = LOOP_ALIGN_MAX_SKIP;
1031 LABEL_TO_ALIGNMENT (label) = max_log;
1032 LABEL_TO_MAX_SKIP (label) = max_skip;
1036 /* Make a pass over all insns and compute their actual lengths by shortening
1037 any branches of variable length if possible. */
1039 /* Give a default value for the lowest address in a function. */
1041 #ifndef FIRST_INSN_ADDRESS
1042 #define FIRST_INSN_ADDRESS 0
1045 /* shorten_branches might be called multiple times: for example, the SH
1046 port splits out-of-range conditional branches in MACHINE_DEPENDENT_REORG.
1047 In order to do this, it needs proper length information, which it obtains
1048 by calling shorten_branches. This cannot be collapsed with
1049 shorten_branches itself into a single pass unless we also want to intergate
1050 reorg.c, since the branch splitting exposes new instructions with delay
1054 shorten_branches (first)
1055 rtx first ATTRIBUTE_UNUSED;
1062 #ifdef HAVE_ATTR_length
1063 #define MAX_CODE_ALIGN 16
1065 int something_changed = 1;
1066 char *varying_length;
1069 rtx align_tab[MAX_CODE_ALIGN];
1073 /* Compute maximum UID and allocate label_align / uid_shuid. */
1074 max_uid = get_max_uid ();
1076 uid_shuid = (int *) xmalloc (max_uid * sizeof *uid_shuid);
1078 if (max_labelno != max_label_num ())
1080 int old = max_labelno;
1084 max_labelno = max_label_num ();
1086 n_labels = max_labelno - min_labelno + 1;
1087 n_old_labels = old - min_labelno + 1;
1089 label_align = (struct label_alignment *) xrealloc
1090 (label_align, n_labels * sizeof (struct label_alignment));
1092 /* Range of labels grows monotonically in the function. Abort here
1093 means that the initialization of array got lost. */
1094 if (n_old_labels > n_labels)
1097 memset (label_align + n_old_labels, 0,
1098 (n_labels - n_old_labels) * sizeof (struct label_alignment));
1101 /* Initialize label_align and set up uid_shuid to be strictly
1102 monotonically rising with insn order. */
1103 /* We use max_log here to keep track of the maximum alignment we want to
1104 impose on the next CODE_LABEL (or the current one if we are processing
1105 the CODE_LABEL itself). */
1110 for (insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn))
1114 INSN_SHUID (insn) = i++;
1117 /* reorg might make the first insn of a loop being run once only,
1118 and delete the label in front of it. Then we want to apply
1119 the loop alignment to the new label created by reorg, which
1120 is separated by the former loop start insn from the
1121 NOTE_INSN_LOOP_BEG. */
1123 else if (GET_CODE (insn) == CODE_LABEL)
1127 /* Merge in alignments computed by compute_alignments. */
1128 log = LABEL_TO_ALIGNMENT (insn);
1132 max_skip = LABEL_TO_MAX_SKIP (insn);
1135 log = LABEL_ALIGN (insn);
1139 max_skip = LABEL_ALIGN_MAX_SKIP;
1141 next = NEXT_INSN (insn);
1142 /* ADDR_VECs only take room if read-only data goes into the text
1144 if (JUMP_TABLES_IN_TEXT_SECTION
1145 #if !defined(READONLY_DATA_SECTION)
1149 if (next && GET_CODE (next) == JUMP_INSN)
1151 rtx nextbody = PATTERN (next);
1152 if (GET_CODE (nextbody) == ADDR_VEC
1153 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1155 log = ADDR_VEC_ALIGN (next);
1159 max_skip = LABEL_ALIGN_MAX_SKIP;
1163 LABEL_TO_ALIGNMENT (insn) = max_log;
1164 LABEL_TO_MAX_SKIP (insn) = max_skip;
1168 else if (GET_CODE (insn) == BARRIER)
1172 for (label = insn; label && ! INSN_P (label);
1173 label = NEXT_INSN (label))
1174 if (GET_CODE (label) == CODE_LABEL)
1176 log = LABEL_ALIGN_AFTER_BARRIER (insn);
1180 max_skip = LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP;
1186 #ifdef HAVE_ATTR_length
1188 /* Allocate the rest of the arrays. */
1189 insn_lengths = (short *) xmalloc (max_uid * sizeof (short));
1190 insn_lengths_max_uid = max_uid;
1191 /* Syntax errors can lead to labels being outside of the main insn stream.
1192 Initialize insn_addresses, so that we get reproducible results. */
1193 INSN_ADDRESSES_ALLOC (max_uid);
1195 varying_length = (char *) xcalloc (max_uid, sizeof (char));
1197 /* Initialize uid_align. We scan instructions
1198 from end to start, and keep in align_tab[n] the last seen insn
1199 that does an alignment of at least n+1, i.e. the successor
1200 in the alignment chain for an insn that does / has a known
1202 uid_align = (rtx *) xcalloc (max_uid, sizeof *uid_align);
1204 for (i = MAX_CODE_ALIGN; --i >= 0;)
1205 align_tab[i] = NULL_RTX;
1206 seq = get_last_insn ();
1207 for (; seq; seq = PREV_INSN (seq))
1209 int uid = INSN_UID (seq);
1211 log = (GET_CODE (seq) == CODE_LABEL ? LABEL_TO_ALIGNMENT (seq) : 0);
1212 uid_align[uid] = align_tab[0];
1215 /* Found an alignment label. */
1216 uid_align[uid] = align_tab[log];
1217 for (i = log - 1; i >= 0; i--)
1221 #ifdef CASE_VECTOR_SHORTEN_MODE
1224 /* Look for ADDR_DIFF_VECs, and initialize their minimum and maximum
1227 int min_shuid = INSN_SHUID (get_insns ()) - 1;
1228 int max_shuid = INSN_SHUID (get_last_insn ()) + 1;
1231 for (insn = first; insn != 0; insn = NEXT_INSN (insn))
1233 rtx min_lab = NULL_RTX, max_lab = NULL_RTX, pat;
1234 int len, i, min, max, insn_shuid;
1236 addr_diff_vec_flags flags;
1238 if (GET_CODE (insn) != JUMP_INSN
1239 || GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
1241 pat = PATTERN (insn);
1242 len = XVECLEN (pat, 1);
1245 min_align = MAX_CODE_ALIGN;
1246 for (min = max_shuid, max = min_shuid, i = len - 1; i >= 0; i--)
1248 rtx lab = XEXP (XVECEXP (pat, 1, i), 0);
1249 int shuid = INSN_SHUID (lab);
1260 if (min_align > LABEL_TO_ALIGNMENT (lab))
1261 min_align = LABEL_TO_ALIGNMENT (lab);
1263 XEXP (pat, 2) = gen_rtx_LABEL_REF (VOIDmode, min_lab);
1264 XEXP (pat, 3) = gen_rtx_LABEL_REF (VOIDmode, max_lab);
1265 insn_shuid = INSN_SHUID (insn);
1266 rel = INSN_SHUID (XEXP (XEXP (pat, 0), 0));
1267 flags.min_align = min_align;
1268 flags.base_after_vec = rel > insn_shuid;
1269 flags.min_after_vec = min > insn_shuid;
1270 flags.max_after_vec = max > insn_shuid;
1271 flags.min_after_base = min > rel;
1272 flags.max_after_base = max > rel;
1273 ADDR_DIFF_VEC_FLAGS (pat) = flags;
1276 #endif /* CASE_VECTOR_SHORTEN_MODE */
1278 /* Compute initial lengths, addresses, and varying flags for each insn. */
1279 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1281 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
1283 uid = INSN_UID (insn);
1285 insn_lengths[uid] = 0;
1287 if (GET_CODE (insn) == CODE_LABEL)
1289 int log = LABEL_TO_ALIGNMENT (insn);
1292 int align = 1 << log;
1293 int new_address = (insn_current_address + align - 1) & -align;
1294 insn_lengths[uid] = new_address - insn_current_address;
1298 INSN_ADDRESSES (uid) = insn_current_address;
1300 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
1301 || GET_CODE (insn) == CODE_LABEL)
1303 if (INSN_DELETED_P (insn))
1306 body = PATTERN (insn);
1307 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1309 /* This only takes room if read-only data goes into the text
1311 if (JUMP_TABLES_IN_TEXT_SECTION
1312 #if !defined(READONLY_DATA_SECTION)
1316 insn_lengths[uid] = (XVECLEN (body,
1317 GET_CODE (body) == ADDR_DIFF_VEC)
1318 * GET_MODE_SIZE (GET_MODE (body)));
1319 /* Alignment is handled by ADDR_VEC_ALIGN. */
1321 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
1322 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
1323 else if (GET_CODE (body) == SEQUENCE)
1326 int const_delay_slots;
1328 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
1330 const_delay_slots = 0;
1332 /* Inside a delay slot sequence, we do not do any branch shortening
1333 if the shortening could change the number of delay slots
1335 for (i = 0; i < XVECLEN (body, 0); i++)
1337 rtx inner_insn = XVECEXP (body, 0, i);
1338 int inner_uid = INSN_UID (inner_insn);
1341 if (GET_CODE (body) == ASM_INPUT
1342 || asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
1343 inner_length = (asm_insn_count (PATTERN (inner_insn))
1344 * insn_default_length (inner_insn));
1346 inner_length = insn_default_length (inner_insn);
1348 insn_lengths[inner_uid] = inner_length;
1349 if (const_delay_slots)
1351 if ((varying_length[inner_uid]
1352 = insn_variable_length_p (inner_insn)) != 0)
1353 varying_length[uid] = 1;
1354 INSN_ADDRESSES (inner_uid) = (insn_current_address
1355 + insn_lengths[uid]);
1358 varying_length[inner_uid] = 0;
1359 insn_lengths[uid] += inner_length;
1362 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
1364 insn_lengths[uid] = insn_default_length (insn);
1365 varying_length[uid] = insn_variable_length_p (insn);
1368 /* If needed, do any adjustment. */
1369 #ifdef ADJUST_INSN_LENGTH
1370 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
1371 if (insn_lengths[uid] < 0)
1372 fatal_insn ("Negative insn length", insn);
1376 /* Now loop over all the insns finding varying length insns. For each,
1377 get the current insn length. If it has changed, reflect the change.
1378 When nothing changes for a full pass, we are done. */
1380 while (something_changed)
1382 something_changed = 0;
1383 insn_current_align = MAX_CODE_ALIGN - 1;
1384 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1386 insn = NEXT_INSN (insn))
1389 #ifdef ADJUST_INSN_LENGTH
1394 uid = INSN_UID (insn);
1396 if (GET_CODE (insn) == CODE_LABEL)
1398 int log = LABEL_TO_ALIGNMENT (insn);
1399 if (log > insn_current_align)
1401 int align = 1 << log;
1402 int new_address= (insn_current_address + align - 1) & -align;
1403 insn_lengths[uid] = new_address - insn_current_address;
1404 insn_current_align = log;
1405 insn_current_address = new_address;
1408 insn_lengths[uid] = 0;
1409 INSN_ADDRESSES (uid) = insn_current_address;
1413 length_align = INSN_LENGTH_ALIGNMENT (insn);
1414 if (length_align < insn_current_align)
1415 insn_current_align = length_align;
1417 insn_last_address = INSN_ADDRESSES (uid);
1418 INSN_ADDRESSES (uid) = insn_current_address;
1420 #ifdef CASE_VECTOR_SHORTEN_MODE
1421 if (optimize && GET_CODE (insn) == JUMP_INSN
1422 && GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
1424 rtx body = PATTERN (insn);
1425 int old_length = insn_lengths[uid];
1426 rtx rel_lab = XEXP (XEXP (body, 0), 0);
1427 rtx min_lab = XEXP (XEXP (body, 2), 0);
1428 rtx max_lab = XEXP (XEXP (body, 3), 0);
1429 int rel_addr = INSN_ADDRESSES (INSN_UID (rel_lab));
1430 int min_addr = INSN_ADDRESSES (INSN_UID (min_lab));
1431 int max_addr = INSN_ADDRESSES (INSN_UID (max_lab));
1434 addr_diff_vec_flags flags;
1436 /* Avoid automatic aggregate initialization. */
1437 flags = ADDR_DIFF_VEC_FLAGS (body);
1439 /* Try to find a known alignment for rel_lab. */
1440 for (prev = rel_lab;
1442 && ! insn_lengths[INSN_UID (prev)]
1443 && ! (varying_length[INSN_UID (prev)] & 1);
1444 prev = PREV_INSN (prev))
1445 if (varying_length[INSN_UID (prev)] & 2)
1447 rel_align = LABEL_TO_ALIGNMENT (prev);
1451 /* See the comment on addr_diff_vec_flags in rtl.h for the
1452 meaning of the flags values. base: REL_LAB vec: INSN */
1453 /* Anything after INSN has still addresses from the last
1454 pass; adjust these so that they reflect our current
1455 estimate for this pass. */
1456 if (flags.base_after_vec)
1457 rel_addr += insn_current_address - insn_last_address;
1458 if (flags.min_after_vec)
1459 min_addr += insn_current_address - insn_last_address;
1460 if (flags.max_after_vec)
1461 max_addr += insn_current_address - insn_last_address;
1462 /* We want to know the worst case, i.e. lowest possible value
1463 for the offset of MIN_LAB. If MIN_LAB is after REL_LAB,
1464 its offset is positive, and we have to be wary of code shrink;
1465 otherwise, it is negative, and we have to be vary of code
1467 if (flags.min_after_base)
1469 /* If INSN is between REL_LAB and MIN_LAB, the size
1470 changes we are about to make can change the alignment
1471 within the observed offset, therefore we have to break
1472 it up into two parts that are independent. */
1473 if (! flags.base_after_vec && flags.min_after_vec)
1475 min_addr -= align_fuzz (rel_lab, insn, rel_align, 0);
1476 min_addr -= align_fuzz (insn, min_lab, 0, 0);
1479 min_addr -= align_fuzz (rel_lab, min_lab, rel_align, 0);
1483 if (flags.base_after_vec && ! flags.min_after_vec)
1485 min_addr -= align_fuzz (min_lab, insn, 0, ~0);
1486 min_addr -= align_fuzz (insn, rel_lab, 0, ~0);
1489 min_addr -= align_fuzz (min_lab, rel_lab, 0, ~0);
1491 /* Likewise, determine the highest lowest possible value
1492 for the offset of MAX_LAB. */
1493 if (flags.max_after_base)
1495 if (! flags.base_after_vec && flags.max_after_vec)
1497 max_addr += align_fuzz (rel_lab, insn, rel_align, ~0);
1498 max_addr += align_fuzz (insn, max_lab, 0, ~0);
1501 max_addr += align_fuzz (rel_lab, max_lab, rel_align, ~0);
1505 if (flags.base_after_vec && ! flags.max_after_vec)
1507 max_addr += align_fuzz (max_lab, insn, 0, 0);
1508 max_addr += align_fuzz (insn, rel_lab, 0, 0);
1511 max_addr += align_fuzz (max_lab, rel_lab, 0, 0);
1513 PUT_MODE (body, CASE_VECTOR_SHORTEN_MODE (min_addr - rel_addr,
1514 max_addr - rel_addr,
1516 if (JUMP_TABLES_IN_TEXT_SECTION
1517 #if !defined(READONLY_DATA_SECTION)
1523 = (XVECLEN (body, 1) * GET_MODE_SIZE (GET_MODE (body)));
1524 insn_current_address += insn_lengths[uid];
1525 if (insn_lengths[uid] != old_length)
1526 something_changed = 1;
1531 #endif /* CASE_VECTOR_SHORTEN_MODE */
1533 if (! (varying_length[uid]))
1535 if (GET_CODE (insn) == INSN
1536 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1540 body = PATTERN (insn);
1541 for (i = 0; i < XVECLEN (body, 0); i++)
1543 rtx inner_insn = XVECEXP (body, 0, i);
1544 int inner_uid = INSN_UID (inner_insn);
1546 INSN_ADDRESSES (inner_uid) = insn_current_address;
1548 insn_current_address += insn_lengths[inner_uid];
1552 insn_current_address += insn_lengths[uid];
1557 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
1561 body = PATTERN (insn);
1563 for (i = 0; i < XVECLEN (body, 0); i++)
1565 rtx inner_insn = XVECEXP (body, 0, i);
1566 int inner_uid = INSN_UID (inner_insn);
1569 INSN_ADDRESSES (inner_uid) = insn_current_address;
1571 /* insn_current_length returns 0 for insns with a
1572 non-varying length. */
1573 if (! varying_length[inner_uid])
1574 inner_length = insn_lengths[inner_uid];
1576 inner_length = insn_current_length (inner_insn);
1578 if (inner_length != insn_lengths[inner_uid])
1580 insn_lengths[inner_uid] = inner_length;
1581 something_changed = 1;
1583 insn_current_address += insn_lengths[inner_uid];
1584 new_length += inner_length;
1589 new_length = insn_current_length (insn);
1590 insn_current_address += new_length;
1593 #ifdef ADJUST_INSN_LENGTH
1594 /* If needed, do any adjustment. */
1595 tmp_length = new_length;
1596 ADJUST_INSN_LENGTH (insn, new_length);
1597 insn_current_address += (new_length - tmp_length);
1600 if (new_length != insn_lengths[uid])
1602 insn_lengths[uid] = new_length;
1603 something_changed = 1;
1606 /* For a non-optimizing compile, do only a single pass. */
1611 free (varying_length);
1613 #endif /* HAVE_ATTR_length */
1616 #ifdef HAVE_ATTR_length
1617 /* Given the body of an INSN known to be generated by an ASM statement, return
1618 the number of machine instructions likely to be generated for this insn.
1619 This is used to compute its length. */
1622 asm_insn_count (body)
1625 const char *template;
1628 if (GET_CODE (body) == ASM_INPUT)
1629 template = XSTR (body, 0);
1631 template = decode_asm_operands (body, NULL, NULL, NULL, NULL);
1633 for (; *template; template++)
1634 if (IS_ASM_LOGICAL_LINE_SEPARATOR (*template) || *template == '\n')
1641 /* Output assembler code for the start of a function,
1642 and initialize some of the variables in this file
1643 for the new function. The label for the function and associated
1644 assembler pseudo-ops have already been output in `assemble_start_function'.
1646 FIRST is the first insn of the rtl for the function being compiled.
1647 FILE is the file to write assembler code to.
1648 OPTIMIZE is nonzero if we should eliminate redundant
1649 test and compare insns. */
1652 final_start_function (first, file, optimize)
1655 int optimize ATTRIBUTE_UNUSED;
1659 this_is_asm_operands = 0;
1661 #ifdef NON_SAVING_SETJMP
1662 /* A function that calls setjmp should save and restore all the
1663 call-saved registers on a system where longjmp clobbers them. */
1664 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
1668 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1669 if (!call_used_regs[i])
1670 regs_ever_live[i] = 1;
1674 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1675 notice_source_line (first);
1676 high_block_linenum = high_function_linenum = last_linenum;
1678 (*debug_hooks->begin_prologue) (last_linenum, last_filename);
1680 #if defined (DWARF2_UNWIND_INFO) || defined (IA64_UNWIND_INFO)
1681 if (write_symbols != DWARF2_DEBUG)
1682 dwarf2out_begin_prologue (0, NULL);
1685 #ifdef LEAF_REG_REMAP
1686 if (current_function_uses_only_leaf_regs)
1687 leaf_renumber_regs (first);
1690 /* The Sun386i and perhaps other machines don't work right
1691 if the profiling code comes after the prologue. */
1692 #ifdef PROFILE_BEFORE_PROLOGUE
1694 profile_function (file);
1695 #endif /* PROFILE_BEFORE_PROLOGUE */
1697 #if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
1698 if (dwarf2out_do_frame ())
1699 dwarf2out_frame_debug (NULL_RTX);
1702 /* If debugging, assign block numbers to all of the blocks in this
1706 remove_unnecessary_notes ();
1708 number_blocks (current_function_decl);
1709 /* We never actually put out begin/end notes for the top-level
1710 block in the function. But, conceptually, that block is
1712 TREE_ASM_WRITTEN (DECL_INITIAL (current_function_decl)) = 1;
1715 /* First output the function prologue: code to set up the stack frame. */
1716 (*targetm.asm_out.function_prologue) (file, get_frame_size ());
1718 /* If the machine represents the prologue as RTL, the profiling code must
1719 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
1720 #ifdef HAVE_prologue
1721 if (! HAVE_prologue)
1723 profile_after_prologue (file);
1727 /* If we are doing basic block profiling, remember a printable version
1728 of the function name. */
1729 if (profile_block_flag)
1732 add_bb_string ((*decl_printable_name) (current_function_decl, 2),
1738 profile_after_prologue (file)
1739 FILE *file ATTRIBUTE_UNUSED;
1741 #ifdef FUNCTION_BLOCK_PROFILER
1742 if (profile_block_flag)
1744 FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
1746 #endif /* FUNCTION_BLOCK_PROFILER */
1748 #ifndef PROFILE_BEFORE_PROLOGUE
1750 profile_function (file);
1751 #endif /* not PROFILE_BEFORE_PROLOGUE */
1755 profile_function (file)
1758 #ifndef NO_PROFILE_COUNTERS
1759 int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
1761 #if defined(ASM_OUTPUT_REG_PUSH)
1762 #if defined(STRUCT_VALUE_INCOMING_REGNUM) || defined(STRUCT_VALUE_REGNUM)
1763 int sval = current_function_returns_struct;
1765 #if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
1766 int cxt = current_function_needs_context;
1768 #endif /* ASM_OUTPUT_REG_PUSH */
1770 #ifndef NO_PROFILE_COUNTERS
1772 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
1773 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
1774 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, align, 1);
1777 function_section (current_function_decl);
1779 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1781 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
1783 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1786 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
1791 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1793 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1795 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1798 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1803 FUNCTION_PROFILER (file, profile_label_no);
1805 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1807 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1809 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1812 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1817 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1819 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1821 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1824 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1830 /* Output assembler code for the end of a function.
1831 For clarity, args are same as those of `final_start_function'
1832 even though not all of them are needed. */
1835 final_end_function ()
1839 (*debug_hooks->end_function) (high_function_linenum);
1841 /* Finally, output the function epilogue:
1842 code to restore the stack frame and return to the caller. */
1843 (*targetm.asm_out.function_epilogue) (asm_out_file, get_frame_size ());
1845 /* And debug output. */
1846 (*debug_hooks->end_epilogue) ();
1848 #if defined (DWARF2_UNWIND_INFO)
1849 if (write_symbols != DWARF2_DEBUG && dwarf2out_do_frame ())
1850 dwarf2out_end_epilogue ();
1853 bb_func_label_num = -1; /* not in function, nuke label # */
1856 /* Add a block to the linked list that remembers the current line/file/function
1857 for basic block profiling. Emit the label in front of the basic block and
1858 the instructions that increment the count field. */
1864 struct bb_list *ptr =
1865 (struct bb_list *) permalloc (sizeof (struct bb_list));
1867 /* Add basic block to linked list. */
1869 ptr->line_num = last_linenum;
1870 ptr->file_label_num = bb_file_label_num;
1871 ptr->func_label_num = bb_func_label_num;
1873 bb_tail = &ptr->next;
1875 /* Enable the table of basic-block use counts
1876 to point at the code it applies to. */
1877 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1879 /* Before first insn of this basic block, increment the
1880 count of times it was entered. */
1881 #ifdef BLOCK_PROFILER
1882 BLOCK_PROFILER (file, count_basic_blocks);
1889 count_basic_blocks++;
1892 /* Add a string to be used for basic block profiling. */
1895 add_bb_string (string, perm_p)
1900 struct bb_str *ptr = 0;
1904 string = "<unknown>";
1908 /* Allocate a new string if the current string isn't permanent. If
1909 the string is permanent search for the same string in other
1912 len = strlen (string) + 1;
1915 char *p = (char *) permalloc (len);
1916 memcpy (p, string, len);
1920 for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
1921 if (ptr->string == string)
1924 /* Allocate a new string block if we need to. */
1927 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1930 ptr->label_num = sbb_label_num++;
1931 ptr->string = string;
1933 sbb_tail = &ptr->next;
1936 return ptr->label_num;
1939 /* Output assembler code for some insns: all or part of a function.
1940 For description of args, see `final_start_function', above.
1942 PRESCAN is 1 if we are not really outputting,
1943 just scanning as if we were outputting.
1944 Prescanning deletes and rearranges insns just like ordinary output.
1945 PRESCAN is -2 if we are outputting after having prescanned.
1946 In this case, don't try to delete or rearrange insns
1947 because that has already been done.
1948 Prescanning is done only on certain machines. */
1951 final (first, file, optimize, prescan)
1961 last_ignored_compare = 0;
1964 /* Make a map indicating which line numbers appear in this function.
1965 When producing SDB debugging info, delete troublesome line number
1966 notes from inlined functions in other files as well as duplicate
1967 line number notes. */
1968 #ifdef SDB_DEBUGGING_INFO
1969 if (write_symbols == SDB_DEBUG)
1972 for (insn = first; insn; insn = NEXT_INSN (insn))
1973 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1975 if ((RTX_INTEGRATED_P (insn)
1976 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1978 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1979 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1981 delete_insn (insn); /* Use delete_note. */
1985 if (NOTE_LINE_NUMBER (insn) > max_line)
1986 max_line = NOTE_LINE_NUMBER (insn);
1992 for (insn = first; insn; insn = NEXT_INSN (insn))
1993 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1994 max_line = NOTE_LINE_NUMBER (insn);
1997 line_note_exists = (char *) xcalloc (max_line + 1, sizeof (char));
1999 for (insn = first; insn; insn = NEXT_INSN (insn))
2001 if (INSN_UID (insn) > max_uid) /* find largest UID */
2002 max_uid = INSN_UID (insn);
2003 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
2004 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
2006 /* If CC tracking across branches is enabled, record the insn which
2007 jumps to each branch only reached from one place. */
2008 if (optimize && GET_CODE (insn) == JUMP_INSN)
2010 rtx lab = JUMP_LABEL (insn);
2011 if (lab && LABEL_NUSES (lab) == 1)
2013 LABEL_REFS (lab) = insn;
2023 /* Output the insns. */
2024 for (insn = NEXT_INSN (first); insn;)
2026 #ifdef HAVE_ATTR_length
2027 if ((unsigned) INSN_UID (insn) >= INSN_ADDRESSES_SIZE ())
2030 /* Irritatingly, the reg-stack pass is creating new instructions
2031 and because of REG_DEAD note abuse it has to run after
2032 shorten_branches. Fake address of -1 then. */
2033 insn_current_address = -1;
2035 /* This can be triggered by bugs elsewhere in the compiler if
2036 new insns are created after init_insn_lengths is called. */
2041 insn_current_address = INSN_ADDRESSES (INSN_UID (insn));
2042 #endif /* HAVE_ATTR_length */
2044 insn = final_scan_insn (insn, file, optimize, prescan, 0);
2047 /* Do basic-block profiling here
2048 if the last insn was a conditional branch. */
2049 if (profile_block_flag && new_block)
2052 free (line_note_exists);
2053 line_note_exists = NULL;
2057 get_insn_template (code, insn)
2061 const void *output = insn_data[code].output;
2062 switch (insn_data[code].output_format)
2064 case INSN_OUTPUT_FORMAT_SINGLE:
2065 return (const char *) output;
2066 case INSN_OUTPUT_FORMAT_MULTI:
2067 return ((const char *const *) output)[which_alternative];
2068 case INSN_OUTPUT_FORMAT_FUNCTION:
2071 return (*(insn_output_fn) output) (recog_data.operand, insn);
2078 /* The final scan for one insn, INSN.
2079 Args are same as in `final', except that INSN
2080 is the insn being scanned.
2081 Value returned is the next insn to be scanned.
2083 NOPEEPHOLES is the flag to disallow peephole processing (currently
2084 used for within delayed branch sequence output). */
2087 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
2090 int optimize ATTRIBUTE_UNUSED;
2092 int nopeepholes ATTRIBUTE_UNUSED;
2100 /* Ignore deleted insns. These can occur when we split insns (due to a
2101 template of "#") while not optimizing. */
2102 if (INSN_DELETED_P (insn))
2103 return NEXT_INSN (insn);
2105 switch (GET_CODE (insn))
2111 switch (NOTE_LINE_NUMBER (insn))
2113 case NOTE_INSN_DELETED:
2114 case NOTE_INSN_LOOP_BEG:
2115 case NOTE_INSN_LOOP_END:
2116 case NOTE_INSN_LOOP_CONT:
2117 case NOTE_INSN_LOOP_VTOP:
2118 case NOTE_INSN_FUNCTION_END:
2119 case NOTE_INSN_REPEATED_LINE_NUMBER:
2120 case NOTE_INSN_RANGE_BEG:
2121 case NOTE_INSN_RANGE_END:
2122 case NOTE_INSN_LIVE:
2123 case NOTE_INSN_EXPECTED_VALUE:
2126 case NOTE_INSN_BASIC_BLOCK:
2127 #ifdef IA64_UNWIND_INFO
2128 IA64_UNWIND_EMIT (asm_out_file, insn);
2131 fprintf (asm_out_file, "\t%s basic block %d\n",
2132 ASM_COMMENT_START, NOTE_BASIC_BLOCK (insn)->index);
2135 case NOTE_INSN_EH_REGION_BEG:
2136 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHB",
2137 NOTE_EH_HANDLER (insn));
2140 case NOTE_INSN_EH_REGION_END:
2141 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHE",
2142 NOTE_EH_HANDLER (insn));
2145 case NOTE_INSN_PROLOGUE_END:
2146 (*targetm.asm_out.function_end_prologue) (file);
2147 profile_after_prologue (file);
2150 case NOTE_INSN_EPILOGUE_BEG:
2151 (*targetm.asm_out.function_begin_epilogue) (file);
2154 case NOTE_INSN_FUNCTION_BEG:
2156 (*debug_hooks->end_prologue) (last_linenum);
2159 case NOTE_INSN_BLOCK_BEG:
2160 if (debug_info_level == DINFO_LEVEL_NORMAL
2161 || debug_info_level == DINFO_LEVEL_VERBOSE
2162 || write_symbols == DWARF_DEBUG
2163 || write_symbols == DWARF2_DEBUG)
2165 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2169 high_block_linenum = last_linenum;
2171 /* Output debugging info about the symbol-block beginning. */
2172 (*debug_hooks->begin_block) (last_linenum, n);
2174 /* Mark this block as output. */
2175 TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
2179 case NOTE_INSN_BLOCK_END:
2180 if (debug_info_level == DINFO_LEVEL_NORMAL
2181 || debug_info_level == DINFO_LEVEL_VERBOSE
2182 || write_symbols == DWARF_DEBUG
2183 || write_symbols == DWARF2_DEBUG)
2185 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2189 /* End of a symbol-block. */
2191 if (block_depth < 0)
2194 (*debug_hooks->end_block) (high_block_linenum, n);
2198 case NOTE_INSN_DELETED_LABEL:
2199 /* Emit the label. We may have deleted the CODE_LABEL because
2200 the label could be proved to be unreachable, though still
2201 referenced (in the form of having its address taken. */
2202 ASM_OUTPUT_DEBUG_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2209 if (NOTE_LINE_NUMBER (insn) <= 0)
2212 /* This note is a line-number. */
2217 /* If there is anything real after this note, output it.
2218 If another line note follows, omit this one. */
2219 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
2221 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
2224 /* These types of notes can be significant
2225 so make sure the preceding line number stays. */
2226 else if (GET_CODE (note) == NOTE
2227 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
2228 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
2229 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
2231 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
2233 /* Another line note follows; we can delete this note
2234 if no intervening line numbers have notes elsewhere. */
2236 for (num = NOTE_LINE_NUMBER (insn) + 1;
2237 num < NOTE_LINE_NUMBER (note);
2239 if (line_note_exists[num])
2242 if (num >= NOTE_LINE_NUMBER (note))
2248 /* Output this line note if it is the first or the last line
2252 notice_source_line (insn);
2253 (*debug_hooks->source_line) (last_linenum, last_filename);
2261 #if defined (DWARF2_UNWIND_INFO)
2262 if (dwarf2out_do_frame ())
2263 dwarf2out_frame_debug (insn);
2268 /* The target port might emit labels in the output function for
2269 some insn, e.g. sh.c output_branchy_insn. */
2270 if (CODE_LABEL_NUMBER (insn) <= max_labelno)
2272 int align = LABEL_TO_ALIGNMENT (insn);
2273 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2274 int max_skip = LABEL_TO_MAX_SKIP (insn);
2277 if (align && NEXT_INSN (insn))
2279 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2280 ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
2282 ASM_OUTPUT_ALIGN (file, align);
2288 /* If this label is reached from only one place, set the condition
2289 codes from the instruction just before the branch. */
2291 /* Disabled because some insns set cc_status in the C output code
2292 and NOTICE_UPDATE_CC alone can set incorrect status. */
2293 if (0 /* optimize && LABEL_NUSES (insn) == 1*/)
2295 rtx jump = LABEL_REFS (insn);
2296 rtx barrier = prev_nonnote_insn (insn);
2298 /* If the LABEL_REFS field of this label has been set to point
2299 at a branch, the predecessor of the branch is a regular
2300 insn, and that branch is the only way to reach this label,
2301 set the condition codes based on the branch and its
2303 if (barrier && GET_CODE (barrier) == BARRIER
2304 && jump && GET_CODE (jump) == JUMP_INSN
2305 && (prev = prev_nonnote_insn (jump))
2306 && GET_CODE (prev) == INSN)
2308 NOTICE_UPDATE_CC (PATTERN (prev), prev);
2309 NOTICE_UPDATE_CC (PATTERN (jump), jump);
2317 #ifdef FINAL_PRESCAN_LABEL
2318 FINAL_PRESCAN_INSN (insn, NULL, 0);
2321 if (LABEL_NAME (insn))
2322 (*debug_hooks->label) (insn);
2326 fputs (ASM_APP_OFF, file);
2329 if (NEXT_INSN (insn) != 0
2330 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
2332 rtx nextbody = PATTERN (NEXT_INSN (insn));
2334 /* If this label is followed by a jump-table,
2335 make sure we put the label in the read-only section. Also
2336 possibly write the label and jump table together. */
2338 if (GET_CODE (nextbody) == ADDR_VEC
2339 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
2341 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2342 /* In this case, the case vector is being moved by the
2343 target, so don't output the label at all. Leave that
2344 to the back end macros. */
2346 if (! JUMP_TABLES_IN_TEXT_SECTION)
2350 readonly_data_section ();
2352 #ifdef ADDR_VEC_ALIGN
2353 log_align = ADDR_VEC_ALIGN (NEXT_INSN (insn));
2355 log_align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2357 ASM_OUTPUT_ALIGN (file, log_align);
2360 function_section (current_function_decl);
2362 #ifdef ASM_OUTPUT_CASE_LABEL
2363 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
2366 if (LABEL_ALTERNATE_NAME (insn))
2367 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2369 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2375 if (LABEL_ALTERNATE_NAME (insn))
2376 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2378 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2383 rtx body = PATTERN (insn);
2384 int insn_code_number;
2385 const char *template;
2388 /* An INSN, JUMP_INSN or CALL_INSN.
2389 First check for special kinds that recog doesn't recognize. */
2391 if (GET_CODE (body) == USE /* These are just declarations */
2392 || GET_CODE (body) == CLOBBER)
2396 /* If there is a REG_CC_SETTER note on this insn, it means that
2397 the setting of the condition code was done in the delay slot
2398 of the insn that branched here. So recover the cc status
2399 from the insn that set it. */
2401 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2404 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
2405 cc_prev_status = cc_status;
2409 /* Detect insns that are really jump-tables
2410 and output them as such. */
2412 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
2414 #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
2423 fputs (ASM_APP_OFF, file);
2427 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2428 if (GET_CODE (body) == ADDR_VEC)
2430 #ifdef ASM_OUTPUT_ADDR_VEC
2431 ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
2438 #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
2439 ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
2445 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2446 for (idx = 0; idx < vlen; idx++)
2448 if (GET_CODE (body) == ADDR_VEC)
2450 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2451 ASM_OUTPUT_ADDR_VEC_ELT
2452 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2459 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2460 ASM_OUTPUT_ADDR_DIFF_ELT
2463 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2464 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2470 #ifdef ASM_OUTPUT_CASE_END
2471 ASM_OUTPUT_CASE_END (file,
2472 CODE_LABEL_NUMBER (PREV_INSN (insn)),
2477 function_section (current_function_decl);
2482 /* Do basic-block profiling when we reach a new block.
2483 Done here to avoid jump tables. */
2484 if (profile_block_flag && new_block)
2487 if (GET_CODE (body) == ASM_INPUT)
2489 const char *string = XSTR (body, 0);
2491 /* There's no telling what that did to the condition codes. */
2500 fputs (ASM_APP_ON, file);
2503 fprintf (asm_out_file, "\t%s\n", string);
2508 /* Detect `asm' construct with operands. */
2509 if (asm_noperands (body) >= 0)
2511 unsigned int noperands = asm_noperands (body);
2512 rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
2515 /* There's no telling what that did to the condition codes. */
2520 /* Get out the operand values. */
2521 string = decode_asm_operands (body, ops, NULL, NULL, NULL);
2522 /* Inhibit aborts on what would otherwise be compiler bugs. */
2523 insn_noperands = noperands;
2524 this_is_asm_operands = insn;
2526 /* Output the insn using them. */
2531 fputs (ASM_APP_ON, file);
2534 output_asm_insn (string, ops);
2537 this_is_asm_operands = 0;
2541 if (prescan <= 0 && app_on)
2543 fputs (ASM_APP_OFF, file);
2547 if (GET_CODE (body) == SEQUENCE)
2549 /* A delayed-branch sequence */
2555 final_sequence = body;
2557 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2558 force the restoration of a comparison that was previously
2559 thought unnecessary. If that happens, cancel this sequence
2560 and cause that insn to be restored. */
2562 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
2563 if (next != XVECEXP (body, 0, 1))
2569 for (i = 1; i < XVECLEN (body, 0); i++)
2571 rtx insn = XVECEXP (body, 0, i);
2572 rtx next = NEXT_INSN (insn);
2573 /* We loop in case any instruction in a delay slot gets
2576 insn = final_scan_insn (insn, file, 0, prescan, 1);
2577 while (insn != next);
2579 #ifdef DBR_OUTPUT_SEQEND
2580 DBR_OUTPUT_SEQEND (file);
2584 /* If the insn requiring the delay slot was a CALL_INSN, the
2585 insns in the delay slot are actually executed before the
2586 called function. Hence we don't preserve any CC-setting
2587 actions in these insns and the CC must be marked as being
2588 clobbered by the function. */
2589 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
2594 /* Following a conditional branch sequence, we have a new basic
2596 if (profile_block_flag)
2598 rtx insn = XVECEXP (body, 0, 0);
2599 rtx body = PATTERN (insn);
2601 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2602 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2603 || (GET_CODE (insn) == JUMP_INSN
2604 && GET_CODE (body) == PARALLEL
2605 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2606 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
2612 /* We have a real machine instruction as rtl. */
2614 body = PATTERN (insn);
2617 set = single_set (insn);
2619 /* Check for redundant test and compare instructions
2620 (when the condition codes are already set up as desired).
2621 This is done only when optimizing; if not optimizing,
2622 it should be possible for the user to alter a variable
2623 with the debugger in between statements
2624 and the next statement should reexamine the variable
2625 to compute the condition codes. */
2630 rtx set = single_set (insn);
2634 && GET_CODE (SET_DEST (set)) == CC0
2635 && insn != last_ignored_compare)
2637 if (GET_CODE (SET_SRC (set)) == SUBREG)
2638 SET_SRC (set) = alter_subreg (&SET_SRC (set));
2639 else if (GET_CODE (SET_SRC (set)) == COMPARE)
2641 if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
2642 XEXP (SET_SRC (set), 0)
2643 = alter_subreg (&XEXP (SET_SRC (set), 0));
2644 if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
2645 XEXP (SET_SRC (set), 1)
2646 = alter_subreg (&XEXP (SET_SRC (set), 1));
2648 if ((cc_status.value1 != 0
2649 && rtx_equal_p (SET_SRC (set), cc_status.value1))
2650 || (cc_status.value2 != 0
2651 && rtx_equal_p (SET_SRC (set), cc_status.value2)))
2653 /* Don't delete insn if it has an addressing side-effect. */
2654 if (! FIND_REG_INC_NOTE (insn, 0)
2655 /* or if anything in it is volatile. */
2656 && ! volatile_refs_p (PATTERN (insn)))
2658 /* We don't really delete the insn; just ignore it. */
2659 last_ignored_compare = insn;
2667 /* Following a conditional branch, we have a new basic block.
2668 But if we are inside a sequence, the new block starts after the
2669 last insn of the sequence. */
2670 if (profile_block_flag && final_sequence == 0
2671 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2672 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2673 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
2674 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2675 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
2679 /* Don't bother outputting obvious no-ops, even without -O.
2680 This optimization is fast and doesn't interfere with debugging.
2681 Don't do this if the insn is in a delay slot, since this
2682 will cause an improper number of delay insns to be written. */
2683 if (final_sequence == 0
2685 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
2686 && GET_CODE (SET_SRC (body)) == REG
2687 && GET_CODE (SET_DEST (body)) == REG
2688 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
2693 /* If this is a conditional branch, maybe modify it
2694 if the cc's are in a nonstandard state
2695 so that it accomplishes the same thing that it would
2696 do straightforwardly if the cc's were set up normally. */
2698 if (cc_status.flags != 0
2699 && GET_CODE (insn) == JUMP_INSN
2700 && GET_CODE (body) == SET
2701 && SET_DEST (body) == pc_rtx
2702 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2703 && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
2704 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
2705 /* This is done during prescan; it is not done again
2706 in final scan when prescan has been done. */
2709 /* This function may alter the contents of its argument
2710 and clear some of the cc_status.flags bits.
2711 It may also return 1 meaning condition now always true
2712 or -1 meaning condition now always false
2713 or 2 meaning condition nontrivial but altered. */
2714 int result = alter_cond (XEXP (SET_SRC (body), 0));
2715 /* If condition now has fixed value, replace the IF_THEN_ELSE
2716 with its then-operand or its else-operand. */
2718 SET_SRC (body) = XEXP (SET_SRC (body), 1);
2720 SET_SRC (body) = XEXP (SET_SRC (body), 2);
2722 /* The jump is now either unconditional or a no-op.
2723 If it has become a no-op, don't try to output it.
2724 (It would not be recognized.) */
2725 if (SET_SRC (body) == pc_rtx)
2730 else if (GET_CODE (SET_SRC (body)) == RETURN)
2731 /* Replace (set (pc) (return)) with (return). */
2732 PATTERN (insn) = body = SET_SRC (body);
2734 /* Rerecognize the instruction if it has changed. */
2736 INSN_CODE (insn) = -1;
2739 /* Make same adjustments to instructions that examine the
2740 condition codes without jumping and instructions that
2741 handle conditional moves (if this machine has either one). */
2743 if (cc_status.flags != 0
2746 rtx cond_rtx, then_rtx, else_rtx;
2748 if (GET_CODE (insn) != JUMP_INSN
2749 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2751 cond_rtx = XEXP (SET_SRC (set), 0);
2752 then_rtx = XEXP (SET_SRC (set), 1);
2753 else_rtx = XEXP (SET_SRC (set), 2);
2757 cond_rtx = SET_SRC (set);
2758 then_rtx = const_true_rtx;
2759 else_rtx = const0_rtx;
2762 switch (GET_CODE (cond_rtx))
2776 if (XEXP (cond_rtx, 0) != cc0_rtx)
2778 result = alter_cond (cond_rtx);
2780 validate_change (insn, &SET_SRC (set), then_rtx, 0);
2781 else if (result == -1)
2782 validate_change (insn, &SET_SRC (set), else_rtx, 0);
2783 else if (result == 2)
2784 INSN_CODE (insn) = -1;
2785 if (SET_DEST (set) == SET_SRC (set))
2797 #ifdef HAVE_peephole
2798 /* Do machine-specific peephole optimizations if desired. */
2800 if (optimize && !flag_no_peephole && !nopeepholes)
2802 rtx next = peephole (insn);
2803 /* When peepholing, if there were notes within the peephole,
2804 emit them before the peephole. */
2805 if (next != 0 && next != NEXT_INSN (insn))
2807 rtx prev = PREV_INSN (insn);
2809 for (note = NEXT_INSN (insn); note != next;
2810 note = NEXT_INSN (note))
2811 final_scan_insn (note, file, optimize, prescan, nopeepholes);
2813 /* In case this is prescan, put the notes
2814 in proper position for later rescan. */
2815 note = NEXT_INSN (insn);
2816 PREV_INSN (note) = prev;
2817 NEXT_INSN (prev) = note;
2818 NEXT_INSN (PREV_INSN (next)) = insn;
2819 PREV_INSN (insn) = PREV_INSN (next);
2820 NEXT_INSN (insn) = next;
2821 PREV_INSN (next) = insn;
2824 /* PEEPHOLE might have changed this. */
2825 body = PATTERN (insn);
2829 /* Try to recognize the instruction.
2830 If successful, verify that the operands satisfy the
2831 constraints for the instruction. Crash if they don't,
2832 since `reload' should have changed them so that they do. */
2834 insn_code_number = recog_memoized (insn);
2835 cleanup_subreg_operands (insn);
2837 /* Dump the insn in the assembly for debugging. */
2838 if (flag_dump_rtl_in_asm)
2840 print_rtx_head = ASM_COMMENT_START;
2841 print_rtl_single (asm_out_file, insn);
2842 print_rtx_head = "";
2845 if (! constrain_operands_cached (1))
2846 fatal_insn_not_found (insn);
2848 /* Some target machines need to prescan each insn before
2851 #ifdef FINAL_PRESCAN_INSN
2852 FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2855 #ifdef HAVE_conditional_execution
2856 if (GET_CODE (PATTERN (insn)) == COND_EXEC)
2857 current_insn_predicate = COND_EXEC_TEST (PATTERN (insn));
2859 current_insn_predicate = NULL_RTX;
2863 cc_prev_status = cc_status;
2865 /* Update `cc_status' for this instruction.
2866 The instruction's output routine may change it further.
2867 If the output routine for a jump insn needs to depend
2868 on the cc status, it should look at cc_prev_status. */
2870 NOTICE_UPDATE_CC (body, insn);
2873 current_output_insn = debug_insn = insn;
2875 #if defined (DWARF2_UNWIND_INFO)
2876 if (GET_CODE (insn) == CALL_INSN && dwarf2out_do_frame ())
2877 dwarf2out_frame_debug (insn);
2880 /* Find the proper template for this insn. */
2881 template = get_insn_template (insn_code_number, insn);
2883 /* If the C code returns 0, it means that it is a jump insn
2884 which follows a deleted test insn, and that test insn
2885 needs to be reinserted. */
2890 if (prev_nonnote_insn (insn) != last_ignored_compare)
2894 /* We have already processed the notes between the setter and
2895 the user. Make sure we don't process them again, this is
2896 particularly important if one of the notes is a block
2897 scope note or an EH note. */
2899 prev != last_ignored_compare;
2900 prev = PREV_INSN (prev))
2902 if (GET_CODE (prev) == NOTE)
2903 delete_insn (prev); /* Use delete_note. */
2909 /* If the template is the string "#", it means that this insn must
2911 if (template[0] == '#' && template[1] == '\0')
2913 rtx new = try_split (body, insn, 0);
2915 /* If we didn't split the insn, go away. */
2916 if (new == insn && PATTERN (new) == body)
2917 fatal_insn ("Could not split insn", insn);
2919 #ifdef HAVE_ATTR_length
2920 /* This instruction should have been split in shorten_branches,
2921 to ensure that we would have valid length info for the
2933 #ifdef IA64_UNWIND_INFO
2934 IA64_UNWIND_EMIT (asm_out_file, insn);
2936 /* Output assembler code from the template. */
2938 output_asm_insn (template, recog_data.operand);
2940 #if defined (DWARF2_UNWIND_INFO)
2941 #if defined (HAVE_prologue)
2942 if (GET_CODE (insn) == INSN && dwarf2out_do_frame ())
2943 dwarf2out_frame_debug (insn);
2945 if (!ACCUMULATE_OUTGOING_ARGS
2946 && GET_CODE (insn) == INSN
2947 && dwarf2out_do_frame ())
2948 dwarf2out_frame_debug (insn);
2953 /* It's not at all clear why we did this and doing so interferes
2954 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2957 /* Mark this insn as having been output. */
2958 INSN_DELETED_P (insn) = 1;
2961 /* Emit information for vtable gc. */
2962 note = find_reg_note (insn, REG_VTABLE_REF, NULL_RTX);
2964 assemble_vtable_entry (XEXP (XEXP (note, 0), 0),
2965 INTVAL (XEXP (XEXP (note, 0), 1)));
2967 current_output_insn = debug_insn = 0;
2970 return NEXT_INSN (insn);
2973 /* Output debugging info to the assembler file FILE
2974 based on the NOTE-insn INSN, assumed to be a line number. */
2977 notice_source_line (insn)
2980 const char *filename = NOTE_SOURCE_FILE (insn);
2982 /* Remember filename for basic block profiling.
2983 Filenames are allocated on the permanent obstack
2984 or are passed in ARGV, so we don't have to save
2987 if (profile_block_flag && last_filename != filename)
2988 bb_file_label_num = add_bb_string (filename, TRUE);
2990 last_filename = filename;
2991 last_linenum = NOTE_LINE_NUMBER (insn);
2992 high_block_linenum = MAX (last_linenum, high_block_linenum);
2993 high_function_linenum = MAX (last_linenum, high_function_linenum);
2996 /* For each operand in INSN, simplify (subreg (reg)) so that it refers
2997 directly to the desired hard register. */
3000 cleanup_subreg_operands (insn)
3004 extract_insn_cached (insn);
3005 for (i = 0; i < recog_data.n_operands; i++)
3007 if (GET_CODE (recog_data.operand[i]) == SUBREG)
3008 recog_data.operand[i] = alter_subreg (recog_data.operand_loc[i]);
3009 else if (GET_CODE (recog_data.operand[i]) == PLUS
3010 || GET_CODE (recog_data.operand[i]) == MULT
3011 || GET_CODE (recog_data.operand[i]) == MEM)
3012 recog_data.operand[i] = walk_alter_subreg (recog_data.operand_loc[i]);
3015 for (i = 0; i < recog_data.n_dups; i++)
3017 if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
3018 *recog_data.dup_loc[i] = alter_subreg (recog_data.dup_loc[i]);
3019 else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
3020 || GET_CODE (*recog_data.dup_loc[i]) == MULT
3021 || GET_CODE (*recog_data.dup_loc[i]) == MEM)
3022 *recog_data.dup_loc[i] = walk_alter_subreg (recog_data.dup_loc[i]);
3026 /* If X is a SUBREG, replace it with a REG or a MEM,
3027 based on the thing it is a subreg of. */
3034 rtx y = SUBREG_REG (x);
3036 /* simplify_subreg does not remove subreg from volatile references.
3037 We are required to. */
3038 if (GET_CODE (y) == MEM)
3039 *xp = adjust_address (y, GET_MODE (x), SUBREG_BYTE (x));
3041 *xp = simplify_subreg (GET_MODE (x), y, GET_MODE (y), SUBREG_BYTE (x));
3045 /* Do alter_subreg on all the SUBREGs contained in X. */
3048 walk_alter_subreg (xp)
3052 switch (GET_CODE (x))
3056 XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0));
3057 XEXP (x, 1) = walk_alter_subreg (&XEXP (x, 1));
3061 XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0));
3065 return alter_subreg (xp);
3076 /* Given BODY, the body of a jump instruction, alter the jump condition
3077 as required by the bits that are set in cc_status.flags.
3078 Not all of the bits there can be handled at this level in all cases.
3080 The value is normally 0.
3081 1 means that the condition has become always true.
3082 -1 means that the condition has become always false.
3083 2 means that COND has been altered. */
3091 if (cc_status.flags & CC_REVERSED)
3094 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
3097 if (cc_status.flags & CC_INVERTED)
3100 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
3103 if (cc_status.flags & CC_NOT_POSITIVE)
3104 switch (GET_CODE (cond))
3109 /* Jump becomes unconditional. */
3115 /* Jump becomes no-op. */
3119 PUT_CODE (cond, EQ);
3124 PUT_CODE (cond, NE);
3132 if (cc_status.flags & CC_NOT_NEGATIVE)
3133 switch (GET_CODE (cond))
3137 /* Jump becomes unconditional. */
3142 /* Jump becomes no-op. */
3147 PUT_CODE (cond, EQ);
3153 PUT_CODE (cond, NE);
3161 if (cc_status.flags & CC_NO_OVERFLOW)
3162 switch (GET_CODE (cond))
3165 /* Jump becomes unconditional. */
3169 PUT_CODE (cond, EQ);
3174 PUT_CODE (cond, NE);
3179 /* Jump becomes no-op. */
3186 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
3187 switch (GET_CODE (cond))
3193 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
3198 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
3203 if (cc_status.flags & CC_NOT_SIGNED)
3204 /* The flags are valid if signed condition operators are converted
3206 switch (GET_CODE (cond))
3209 PUT_CODE (cond, LEU);
3214 PUT_CODE (cond, LTU);
3219 PUT_CODE (cond, GTU);
3224 PUT_CODE (cond, GEU);
3236 /* Report inconsistency between the assembler template and the operands.
3237 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
3240 output_operand_lossage (msgid)
3243 if (this_is_asm_operands)
3244 error_for_asm (this_is_asm_operands, "invalid `asm': %s", _(msgid));
3246 internal_error ("output_operand: %s", _(msgid));
3249 /* Output of assembler code from a template, and its subroutines. */
3251 /* Annotate the assembly with a comment describing the pattern and
3252 alternative used. */
3259 int num = INSN_CODE (debug_insn);
3260 fprintf (asm_out_file, "\t%s %d\t%s",
3261 ASM_COMMENT_START, INSN_UID (debug_insn),
3262 insn_data[num].name);
3263 if (insn_data[num].n_alternatives > 1)
3264 fprintf (asm_out_file, "/%d", which_alternative + 1);
3265 #ifdef HAVE_ATTR_length
3266 fprintf (asm_out_file, "\t[length = %d]",
3267 get_attr_length (debug_insn));
3269 /* Clear this so only the first assembler insn
3270 of any rtl insn will get the special comment for -dp. */
3275 /* If OP is a REG or MEM and we can find a decl corresponding to it or
3276 its address, return that decl. Set *PADDRESSP to 1 if the decl
3277 corresponds to the address of the object and 0 if to the object. */
3280 get_decl_from_op (op, paddressp)
3289 if (GET_CODE (op) == REG && ORIGINAL_REGNO (op) >= FIRST_PSEUDO_REGISTER)
3290 return REGNO_DECL (ORIGINAL_REGNO (op));
3291 else if (GET_CODE (op) != MEM)
3294 if (MEM_DECL (op) != 0)
3295 return MEM_DECL (op);
3297 /* Otherwise we have an address, so indicate it and look at the address. */
3301 /* First check if we have a decl for the address, then look at the right side
3302 if it is a PLUS. Otherwise, strip off arithmetic and keep looking.
3303 But don't allow the address to itself be indirect. */
3304 if ((decl = get_decl_from_op (op, &inner_addressp)) && ! inner_addressp)
3306 else if (GET_CODE (op) == PLUS
3307 && (decl = get_decl_from_op (XEXP (op, 1), &inner_addressp)))
3310 while (GET_RTX_CLASS (GET_CODE (op)) == '1'
3311 || GET_RTX_CLASS (GET_CODE (op)) == '2')
3314 decl = get_decl_from_op (op, &inner_addressp);
3315 return inner_addressp ? 0 : decl;
3318 /* Output operand names for assembler instructions. OPERANDS is the
3319 operand vector, OPORDER is the order to write the operands, and NOPS
3320 is the number of operands to write. */
3323 output_asm_operand_names (operands, oporder, nops)
3331 for (i = 0; i < nops; i++)
3334 tree decl = get_decl_from_op (operands[oporder[i]], &addressp);
3336 if (decl && DECL_NAME (decl))
3338 fprintf (asm_out_file, "%c%s %s%s",
3339 wrote ? ',' : '\t', wrote ? "" : ASM_COMMENT_START,
3340 addressp ? "*" : "", IDENTIFIER_POINTER (DECL_NAME (decl)));
3346 /* Output text from TEMPLATE to the assembler output file,
3347 obeying %-directions to substitute operands taken from
3348 the vector OPERANDS.
3350 %N (for N a digit) means print operand N in usual manner.
3351 %lN means require operand N to be a CODE_LABEL or LABEL_REF
3352 and print the label name with no punctuation.
3353 %cN means require operand N to be a constant
3354 and print the constant expression with no punctuation.
3355 %aN means expect operand N to be a memory address
3356 (not a memory reference!) and print a reference
3358 %nN means expect operand N to be a constant
3359 and print a constant expression for minus the value
3360 of the operand, with no other punctuation. */
3363 output_asm_insn (template, operands)
3364 const char *template;
3369 #ifdef ASSEMBLER_DIALECT
3372 int oporder[MAX_RECOG_OPERANDS];
3373 char opoutput[MAX_RECOG_OPERANDS];
3376 /* An insn may return a null string template
3377 in a case where no assembler code is needed. */
3381 memset (opoutput, 0, sizeof opoutput);
3383 putc ('\t', asm_out_file);
3385 #ifdef ASM_OUTPUT_OPCODE
3386 ASM_OUTPUT_OPCODE (asm_out_file, p);
3393 if (flag_verbose_asm)
3394 output_asm_operand_names (operands, oporder, ops);
3395 if (flag_print_asm_name)
3399 memset (opoutput, 0, sizeof opoutput);
3401 putc (c, asm_out_file);
3402 #ifdef ASM_OUTPUT_OPCODE
3403 while ((c = *p) == '\t')
3405 putc (c, asm_out_file);
3408 ASM_OUTPUT_OPCODE (asm_out_file, p);
3412 #ifdef ASSEMBLER_DIALECT
3418 output_operand_lossage ("nested assembly dialect alternatives");
3422 /* If we want the first dialect, do nothing. Otherwise, skip
3423 DIALECT_NUMBER of strings ending with '|'. */
3424 for (i = 0; i < dialect_number; i++)
3426 while (*p && *p != '}' && *p++ != '|')
3435 output_operand_lossage ("unterminated assembly dialect alternative");
3442 /* Skip to close brace. */
3447 output_operand_lossage ("unterminated assembly dialect alternative");
3451 while (*p++ != '}');
3455 putc (c, asm_out_file);
3460 putc (c, asm_out_file);
3466 /* %% outputs a single %. */
3470 putc (c, asm_out_file);
3472 /* %= outputs a number which is unique to each insn in the entire
3473 compilation. This is useful for making local labels that are
3474 referred to more than once in a given insn. */
3478 fprintf (asm_out_file, "%d", insn_counter);
3480 /* % followed by a letter and some digits
3481 outputs an operand in a special way depending on the letter.
3482 Letters `acln' are implemented directly.
3483 Other letters are passed to `output_operand' so that
3484 the PRINT_OPERAND macro can define them. */
3485 else if (ISALPHA (*p))
3491 output_operand_lossage ("operand number missing after %-letter");
3492 else if (this_is_asm_operands
3493 && (c < 0 || (unsigned int) c >= insn_noperands))
3494 output_operand_lossage ("operand number out of range");
3495 else if (letter == 'l')
3496 output_asm_label (operands[c]);
3497 else if (letter == 'a')
3498 output_address (operands[c]);
3499 else if (letter == 'c')
3501 if (CONSTANT_ADDRESS_P (operands[c]))
3502 output_addr_const (asm_out_file, operands[c]);
3504 output_operand (operands[c], 'c');
3506 else if (letter == 'n')
3508 if (GET_CODE (operands[c]) == CONST_INT)
3509 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3510 - INTVAL (operands[c]));
3513 putc ('-', asm_out_file);
3514 output_addr_const (asm_out_file, operands[c]);
3518 output_operand (operands[c], letter);
3524 while (ISDIGIT (c = *p))
3527 /* % followed by a digit outputs an operand the default way. */
3528 else if (ISDIGIT (*p))
3531 if (this_is_asm_operands
3532 && (c < 0 || (unsigned int) c >= insn_noperands))
3533 output_operand_lossage ("operand number out of range");
3535 output_operand (operands[c], 0);
3541 while (ISDIGIT (c = *p))
3544 /* % followed by punctuation: output something for that
3545 punctuation character alone, with no operand.
3546 The PRINT_OPERAND macro decides what is actually done. */
3547 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3548 else if (PRINT_OPERAND_PUNCT_VALID_P ((unsigned char) *p))
3549 output_operand (NULL_RTX, *p++);
3552 output_operand_lossage ("invalid %%-code");
3556 putc (c, asm_out_file);
3559 /* Write out the variable names for operands, if we know them. */
3560 if (flag_verbose_asm)
3561 output_asm_operand_names (operands, oporder, ops);
3562 if (flag_print_asm_name)
3565 putc ('\n', asm_out_file);
3568 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3571 output_asm_label (x)
3576 if (GET_CODE (x) == LABEL_REF)
3578 if (GET_CODE (x) == CODE_LABEL
3579 || (GET_CODE (x) == NOTE
3580 && NOTE_LINE_NUMBER (x) == NOTE_INSN_DELETED_LABEL))
3581 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3583 output_operand_lossage ("`%l' operand isn't a label");
3585 assemble_name (asm_out_file, buf);
3588 /* Print operand X using machine-dependent assembler syntax.
3589 The macro PRINT_OPERAND is defined just to control this function.
3590 CODE is a non-digit that preceded the operand-number in the % spec,
3591 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3592 between the % and the digits.
3593 When CODE is a non-letter, X is 0.
3595 The meanings of the letters are machine-dependent and controlled
3596 by PRINT_OPERAND. */
3599 output_operand (x, code)
3601 int code ATTRIBUTE_UNUSED;
3603 if (x && GET_CODE (x) == SUBREG)
3604 x = alter_subreg (&x);
3606 /* If X is a pseudo-register, abort now rather than writing trash to the
3609 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
3612 PRINT_OPERAND (asm_out_file, x, code);
3615 /* Print a memory reference operand for address X
3616 using machine-dependent assembler syntax.
3617 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
3623 walk_alter_subreg (&x);
3624 PRINT_OPERAND_ADDRESS (asm_out_file, x);
3627 /* Print an integer constant expression in assembler syntax.
3628 Addition and subtraction are the only arithmetic
3629 that may appear in these expressions. */
3632 output_addr_const (file, x)
3639 switch (GET_CODE (x))
3649 #ifdef ASM_OUTPUT_SYMBOL_REF
3650 ASM_OUTPUT_SYMBOL_REF (file, x);
3652 assemble_name (file, XSTR (x, 0));
3660 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3661 #ifdef ASM_OUTPUT_LABEL_REF
3662 ASM_OUTPUT_LABEL_REF (file, buf);
3664 assemble_name (file, buf);
3669 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3673 /* This used to output parentheses around the expression,
3674 but that does not work on the 386 (either ATT or BSD assembler). */
3675 output_addr_const (file, XEXP (x, 0));
3679 if (GET_MODE (x) == VOIDmode)
3681 /* We can use %d if the number is one word and positive. */
3682 if (CONST_DOUBLE_HIGH (x))
3683 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3684 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3685 else if (CONST_DOUBLE_LOW (x) < 0)
3686 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3688 fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3691 /* We can't handle floating point constants;
3692 PRINT_OPERAND must handle them. */
3693 output_operand_lossage ("floating constant misused");
3697 /* Some assemblers need integer constants to appear last (eg masm). */
3698 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3700 output_addr_const (file, XEXP (x, 1));
3701 if (INTVAL (XEXP (x, 0)) >= 0)
3702 fprintf (file, "+");
3703 output_addr_const (file, XEXP (x, 0));
3707 output_addr_const (file, XEXP (x, 0));
3708 if (GET_CODE (XEXP (x, 1)) != CONST_INT
3709 || INTVAL (XEXP (x, 1)) >= 0)
3710 fprintf (file, "+");
3711 output_addr_const (file, XEXP (x, 1));
3716 /* Avoid outputting things like x-x or x+5-x,
3717 since some assemblers can't handle that. */
3718 x = simplify_subtraction (x);
3719 if (GET_CODE (x) != MINUS)
3722 output_addr_const (file, XEXP (x, 0));
3723 fprintf (file, "-");
3724 if ((GET_CODE (XEXP (x, 1)) == CONST_INT
3725 && INTVAL (XEXP (x, 1)) < 0)
3726 || GET_CODE (XEXP (x, 1)) != CONST_INT)
3728 fputs (targetm.asm_out.open_paren, file);
3729 output_addr_const (file, XEXP (x, 1));
3730 fputs (targetm.asm_out.close_paren, file);
3733 output_addr_const (file, XEXP (x, 1));
3738 output_addr_const (file, XEXP (x, 0));
3742 #ifdef OUTPUT_ADDR_CONST_EXTRA
3743 OUTPUT_ADDR_CONST_EXTRA (file, x, fail);
3748 output_operand_lossage ("invalid expression as operand");
3752 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3753 %R prints the value of REGISTER_PREFIX.
3754 %L prints the value of LOCAL_LABEL_PREFIX.
3755 %U prints the value of USER_LABEL_PREFIX.
3756 %I prints the value of IMMEDIATE_PREFIX.
3757 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3758 Also supported are %d, %x, %s, %e, %f, %g and %%.
3760 We handle alternate assembler dialects here, just like output_asm_insn. */
3763 asm_fprintf VPARAMS ((FILE *file, const char *p, ...))
3768 VA_OPEN (argptr, p);
3769 VA_FIXEDARG (argptr, FILE *, file);
3770 VA_FIXEDARG (argptr, const char *, p);
3777 #ifdef ASSEMBLER_DIALECT
3782 /* If we want the first dialect, do nothing. Otherwise, skip
3783 DIALECT_NUMBER of strings ending with '|'. */
3784 for (i = 0; i < dialect_number; i++)
3786 while (*p && *p++ != '|')
3796 /* Skip to close brace. */
3797 while (*p && *p++ != '}')
3808 while (ISDIGIT (c) || c == '.')
3816 fprintf (file, "%%");
3819 case 'd': case 'i': case 'u':
3820 case 'x': case 'p': case 'X':
3824 fprintf (file, buf, va_arg (argptr, int));
3828 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3829 but we do not check for those cases. It means that the value
3830 is a HOST_WIDE_INT, which may be either `int' or `long'. */
3832 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3834 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3844 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3851 fprintf (file, buf, va_arg (argptr, long));
3859 fprintf (file, buf, va_arg (argptr, double));
3865 fprintf (file, buf, va_arg (argptr, char *));
3869 #ifdef ASM_OUTPUT_OPCODE
3870 ASM_OUTPUT_OPCODE (asm_out_file, p);
3875 #ifdef REGISTER_PREFIX
3876 fprintf (file, "%s", REGISTER_PREFIX);
3881 #ifdef IMMEDIATE_PREFIX
3882 fprintf (file, "%s", IMMEDIATE_PREFIX);
3887 #ifdef LOCAL_LABEL_PREFIX
3888 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3893 fputs (user_label_prefix, file);
3896 #ifdef ASM_FPRINTF_EXTENSIONS
3897 /* Upper case letters are reserved for general use by asm_fprintf
3898 and so are not available to target specific code. In order to
3899 prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
3900 they are defined here. As they get turned into real extensions
3901 to asm_fprintf they should be removed from this list. */
3902 case 'A': case 'B': case 'C': case 'D': case 'E':
3903 case 'F': case 'G': case 'H': case 'J': case 'K':
3904 case 'M': case 'N': case 'P': case 'Q': case 'S':
3905 case 'T': case 'V': case 'W': case 'Y': case 'Z':
3908 ASM_FPRINTF_EXTENSIONS (file, argptr, p)
3921 /* Split up a CONST_DOUBLE or integer constant rtx
3922 into two rtx's for single words,
3923 storing in *FIRST the word that comes first in memory in the target
3924 and in *SECOND the other. */
3927 split_double (value, first, second)
3929 rtx *first, *second;
3931 if (GET_CODE (value) == CONST_INT)
3933 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3935 /* In this case the CONST_INT holds both target words.
3936 Extract the bits from it into two word-sized pieces.
3937 Sign extend each half to HOST_WIDE_INT. */
3938 unsigned HOST_WIDE_INT low, high;
3939 unsigned HOST_WIDE_INT mask, sign_bit, sign_extend;
3941 /* Set sign_bit to the most significant bit of a word. */
3943 sign_bit <<= BITS_PER_WORD - 1;
3945 /* Set mask so that all bits of the word are set. We could
3946 have used 1 << BITS_PER_WORD instead of basing the
3947 calculation on sign_bit. However, on machines where
3948 HOST_BITS_PER_WIDE_INT == BITS_PER_WORD, it could cause a
3949 compiler warning, even though the code would never be
3951 mask = sign_bit << 1;
3954 /* Set sign_extend as any remaining bits. */
3955 sign_extend = ~mask;
3957 /* Pick the lower word and sign-extend it. */
3958 low = INTVAL (value);
3963 /* Pick the higher word, shifted to the least significant
3964 bits, and sign-extend it. */
3965 high = INTVAL (value);
3966 high >>= BITS_PER_WORD - 1;
3969 if (high & sign_bit)
3970 high |= sign_extend;
3972 /* Store the words in the target machine order. */
3973 if (WORDS_BIG_ENDIAN)
3975 *first = GEN_INT (high);
3976 *second = GEN_INT (low);
3980 *first = GEN_INT (low);
3981 *second = GEN_INT (high);
3986 /* The rule for using CONST_INT for a wider mode
3987 is that we regard the value as signed.
3988 So sign-extend it. */
3989 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3990 if (WORDS_BIG_ENDIAN)
4002 else if (GET_CODE (value) != CONST_DOUBLE)
4004 if (WORDS_BIG_ENDIAN)
4006 *first = const0_rtx;
4012 *second = const0_rtx;
4015 else if (GET_MODE (value) == VOIDmode
4016 /* This is the old way we did CONST_DOUBLE integers. */
4017 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
4019 /* In an integer, the words are defined as most and least significant.
4020 So order them by the target's convention. */
4021 if (WORDS_BIG_ENDIAN)
4023 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
4024 *second = GEN_INT (CONST_DOUBLE_LOW (value));
4028 *first = GEN_INT (CONST_DOUBLE_LOW (value));
4029 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
4034 #ifdef REAL_ARITHMETIC
4037 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
4039 /* Note, this converts the REAL_VALUE_TYPE to the target's
4040 format, splits up the floating point double and outputs
4041 exactly 32 bits of it into each of l[0] and l[1] --
4042 not necessarily BITS_PER_WORD bits. */
4043 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
4045 /* If 32 bits is an entire word for the target, but not for the host,
4046 then sign-extend on the host so that the number will look the same
4047 way on the host that it would on the target. See for instance
4048 simplify_unary_operation. The #if is needed to avoid compiler
4051 #if HOST_BITS_PER_LONG > 32
4052 if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
4054 if (l[0] & ((long) 1 << 31))
4055 l[0] |= ((long) (-1) << 32);
4056 if (l[1] & ((long) 1 << 31))
4057 l[1] |= ((long) (-1) << 32);
4061 *first = GEN_INT ((HOST_WIDE_INT) l[0]);
4062 *second = GEN_INT ((HOST_WIDE_INT) l[1]);
4064 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
4065 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
4066 && ! flag_pretend_float)
4070 #ifdef HOST_WORDS_BIG_ENDIAN
4077 /* Host and target agree => no need to swap. */
4078 *first = GEN_INT (CONST_DOUBLE_LOW (value));
4079 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
4083 *second = GEN_INT (CONST_DOUBLE_LOW (value));
4084 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
4086 #endif /* no REAL_ARITHMETIC */
4090 /* Return nonzero if this function has no function calls. */
4098 if (profile_flag || profile_block_flag || profile_arc_flag)
4101 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4103 if (GET_CODE (insn) == CALL_INSN
4104 && ! SIBLING_CALL_P (insn))
4106 if (GET_CODE (insn) == INSN
4107 && GET_CODE (PATTERN (insn)) == SEQUENCE
4108 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4109 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4112 for (link = current_function_epilogue_delay_list;
4114 link = XEXP (link, 1))
4116 insn = XEXP (link, 0);
4118 if (GET_CODE (insn) == CALL_INSN
4119 && ! SIBLING_CALL_P (insn))
4121 if (GET_CODE (insn) == INSN
4122 && GET_CODE (PATTERN (insn)) == SEQUENCE
4123 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4124 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4131 /* Return 1 if branch is an forward branch.
4132 Uses insn_shuid array, so it works only in the final pass. May be used by
4133 output templates to customary add branch prediction hints.
4136 final_forward_branch_p (insn)
4139 int insn_id, label_id;
4142 insn_id = INSN_SHUID (insn);
4143 label_id = INSN_SHUID (JUMP_LABEL (insn));
4144 /* We've hit some insns that does not have id information available. */
4145 if (!insn_id || !label_id)
4147 return insn_id < label_id;
4150 /* On some machines, a function with no call insns
4151 can run faster if it doesn't create its own register window.
4152 When output, the leaf function should use only the "output"
4153 registers. Ordinarily, the function would be compiled to use
4154 the "input" registers to find its arguments; it is a candidate
4155 for leaf treatment if it uses only the "input" registers.
4156 Leaf function treatment means renumbering so the function
4157 uses the "output" registers instead. */
4159 #ifdef LEAF_REGISTERS
4161 /* Return 1 if this function uses only the registers that can be
4162 safely renumbered. */
4165 only_leaf_regs_used ()
4168 char *permitted_reg_in_leaf_functions = LEAF_REGISTERS;
4170 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4171 if ((regs_ever_live[i] || global_regs[i])
4172 && ! permitted_reg_in_leaf_functions[i])
4175 if (current_function_uses_pic_offset_table
4176 && pic_offset_table_rtx != 0
4177 && GET_CODE (pic_offset_table_rtx) == REG
4178 && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
4184 /* Scan all instructions and renumber all registers into those
4185 available in leaf functions. */
4188 leaf_renumber_regs (first)
4193 /* Renumber only the actual patterns.
4194 The reg-notes can contain frame pointer refs,
4195 and renumbering them could crash, and should not be needed. */
4196 for (insn = first; insn; insn = NEXT_INSN (insn))
4198 leaf_renumber_regs_insn (PATTERN (insn));
4199 for (insn = current_function_epilogue_delay_list;
4201 insn = XEXP (insn, 1))
4202 if (INSN_P (XEXP (insn, 0)))
4203 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
4206 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
4207 available in leaf functions. */
4210 leaf_renumber_regs_insn (in_rtx)
4214 const char *format_ptr;
4219 /* Renumber all input-registers into output-registers.
4220 renumbered_regs would be 1 for an output-register;
4223 if (GET_CODE (in_rtx) == REG)
4227 /* Don't renumber the same reg twice. */
4231 newreg = REGNO (in_rtx);
4232 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
4233 to reach here as part of a REG_NOTE. */
4234 if (newreg >= FIRST_PSEUDO_REGISTER)
4239 newreg = LEAF_REG_REMAP (newreg);
4242 regs_ever_live[REGNO (in_rtx)] = 0;
4243 regs_ever_live[newreg] = 1;
4244 REGNO (in_rtx) = newreg;
4248 if (INSN_P (in_rtx))
4250 /* Inside a SEQUENCE, we find insns.
4251 Renumber just the patterns of these insns,
4252 just as we do for the top-level insns. */
4253 leaf_renumber_regs_insn (PATTERN (in_rtx));
4257 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
4259 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
4260 switch (*format_ptr++)
4263 leaf_renumber_regs_insn (XEXP (in_rtx, i));
4267 if (NULL != XVEC (in_rtx, i))
4269 for (j = 0; j < XVECLEN (in_rtx, i); j++)
4270 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));