1 /* Convert RTL to assembler code and output it, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-5, 1996 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This is the final pass of the compiler.
23 It looks at the rtl code for a function and outputs assembler code.
25 Call `final_start_function' to output the assembler code for function entry,
26 `final' to output assembler code for some RTL code,
27 `final_end_function' to output assembler code for function exit.
28 If a function is compiled in several pieces, each piece is
29 output separately with `final'.
31 Some optimizations are also done at this level.
32 Move instructions that were made unnecessary by good register allocation
33 are detected and omitted from the output. (Though most of these
34 are removed by the last jump pass.)
36 Instructions to set the condition codes are omitted when it can be
37 seen that the condition codes already had the desired values.
39 In some cases it is sufficient if the inherited condition codes
40 have related values, but this may require the following insn
41 (the one that tests the condition codes) to be modified.
43 The code for the function prologue and epilogue are generated
44 directly as assembler code by the macros FUNCTION_PROLOGUE and
45 FUNCTION_EPILOGUE. Those instructions never exist as rtl. */
59 #include "insn-config.h"
60 #include "insn-flags.h"
61 #include "insn-attr.h"
62 #include "insn-codes.h"
64 #include "conditions.h"
67 #include "hard-reg-set.h"
72 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist. */
73 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
74 #if defined (USG) || defined (NO_STAB_H)
75 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
77 #include <stab.h> /* On BSD, use the system's stab.h. */
79 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
81 #ifdef XCOFF_DEBUGGING_INFO
85 /* .stabd code for line number. */
90 /* .stabs code for included file name. */
96 #define INT_TYPE_SIZE BITS_PER_WORD
99 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
100 null default for it to save conditionalization later. */
101 #ifndef CC_STATUS_INIT
102 #define CC_STATUS_INIT
105 /* How to start an assembler comment. */
106 #ifndef ASM_COMMENT_START
107 #define ASM_COMMENT_START ";#"
110 /* Is the given character a logical line separator for the assembler? */
111 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
112 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
115 /* Nonzero means this function is a leaf function, with no function calls.
116 This variable exists to be examined in FUNCTION_PROLOGUE
117 and FUNCTION_EPILOGUE. Always zero, unless set by some action. */
120 /* Last insn processed by final_scan_insn. */
121 static rtx debug_insn = 0;
123 /* Line number of last NOTE. */
124 static int last_linenum;
126 /* Highest line number in current block. */
127 static int high_block_linenum;
129 /* Likewise for function. */
130 static int high_function_linenum;
132 /* Filename of last NOTE. */
133 static char *last_filename;
135 /* Number of basic blocks seen so far;
136 used if profile_block_flag is set. */
137 static int count_basic_blocks;
139 /* Nonzero while outputting an `asm' with operands.
140 This means that inconsistencies are the user's fault, so don't abort.
141 The precise value is the insn being output, to pass to error_for_asm. */
142 static rtx this_is_asm_operands;
144 /* Number of operands of this insn, for an `asm' with operands. */
145 static int insn_noperands;
147 /* Compare optimization flag. */
149 static rtx last_ignored_compare = 0;
151 /* Flag indicating this insn is the start of a new basic block. */
153 static int new_block = 1;
155 /* All the symbol-blocks (levels of scoping) in the compilation
156 are assigned sequence numbers in order of appearance of the
157 beginnings of the symbol-blocks. Both final and dbxout do this,
158 and assume that they will both give the same number to each block.
159 Final uses these sequence numbers to generate assembler label names
160 LBBnnn and LBEnnn for the beginning and end of the symbol-block.
161 Dbxout uses the sequence numbers to generate references to the same labels
162 from the dbx debugging information.
164 Sdb records this level at the beginning of each function,
165 in order to find the current level when recursing down declarations.
166 It outputs the block beginning and endings
167 at the point in the asm file where the blocks would begin and end. */
169 int next_block_index;
171 /* Assign a unique number to each insn that is output.
172 This can be used to generate unique local labels. */
174 static int insn_counter = 0;
177 /* This variable contains machine-dependent flags (defined in tm.h)
178 set and examined by output routines
179 that describe how to interpret the condition codes properly. */
183 /* During output of an insn, this contains a copy of cc_status
184 from before the insn. */
186 CC_STATUS cc_prev_status;
189 /* Indexed by hardware reg number, is 1 if that register is ever
190 used in the current function.
192 In life_analysis, or in stupid_life_analysis, this is set
193 up to record the hard regs used explicitly. Reload adds
194 in the hard regs used for holding pseudo regs. Final uses
195 it to generate the code in the function prologue and epilogue
196 to save and restore registers as needed. */
198 char regs_ever_live[FIRST_PSEUDO_REGISTER];
200 /* Nonzero means current function must be given a frame pointer.
201 Set in stmt.c if anything is allocated on the stack there.
202 Set in reload1.c if anything is allocated on the stack there. */
204 int frame_pointer_needed;
206 /* Assign unique numbers to labels generated for profiling. */
208 int profile_label_no;
210 /* Length so far allocated in PENDING_BLOCKS. */
212 static int max_block_depth;
214 /* Stack of sequence numbers of symbol-blocks of which we have seen the
215 beginning but not yet the end. Sequence numbers are assigned at
216 the beginning; this stack allows us to find the sequence number
217 of a block that is ending. */
219 static int *pending_blocks;
221 /* Number of elements currently in use in PENDING_BLOCKS. */
223 static int block_depth;
225 /* Nonzero if have enabled APP processing of our assembler output. */
229 /* If we are outputting an insn sequence, this contains the sequence rtx.
234 #ifdef ASSEMBLER_DIALECT
236 /* Number of the assembler dialect to use, starting at 0. */
237 static int dialect_number;
240 /* Indexed by line number, nonzero if there is a note for that line. */
242 static char *line_note_exists;
244 /* Linked list to hold line numbers for each basic block. */
247 struct bb_list *next; /* pointer to next basic block */
248 int line_num; /* line number */
249 int file_label_num; /* LPBC<n> label # for stored filename */
250 int func_label_num; /* LPBC<n> label # for stored function name */
253 static struct bb_list *bb_head = 0; /* Head of basic block list */
254 static struct bb_list **bb_tail = &bb_head; /* Ptr to store next bb ptr */
255 static int bb_file_label_num = -1; /* Current label # for file */
256 static int bb_func_label_num = -1; /* Current label # for func */
258 /* Linked list to hold the strings for each file and function name output. */
261 struct bb_str *next; /* pointer to next string */
262 char *string; /* string */
263 int label_num; /* label number */
264 int length; /* string length */
267 extern rtx peephole PROTO((rtx));
269 static struct bb_str *sbb_head = 0; /* Head of string list. */
270 static struct bb_str **sbb_tail = &sbb_head; /* Ptr to store next bb str */
271 static int sbb_label_num = 0; /* Last label used */
273 static int asm_insn_count PROTO((rtx));
274 static void profile_function PROTO((FILE *));
275 static void profile_after_prologue PROTO((FILE *));
276 static void add_bb PROTO((FILE *));
277 static int add_bb_string PROTO((char *, int));
278 static void output_source_line PROTO((FILE *, rtx));
279 static rtx walk_alter_subreg PROTO((rtx));
280 static int alter_cond PROTO((rtx));
281 static void output_asm_name PROTO((void));
282 static void output_operand PROTO((rtx, int));
283 static void leaf_renumber_regs PROTO((rtx));
285 extern char *getpwd ();
287 /* Initialize data in final at the beginning of a compilation. */
290 init_final (filename)
293 next_block_index = 2;
295 max_block_depth = 20;
296 pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
299 #ifdef ASSEMBLER_DIALECT
300 dialect_number = ASSEMBLER_DIALECT;
304 /* Called at end of source file,
305 to output the block-profiling table for this entire compilation. */
313 if (profile_block_flag)
316 int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
317 int size = (POINTER_SIZE / BITS_PER_UNIT) * count_basic_blocks;
322 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
323 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
324 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
328 /* Output the main header, of 11 words:
329 0: 1 if this file is initialized, else 0.
330 1: address of file name (LPBX1).
331 2: address of table of counts (LPBX2).
332 3: number of counts in the table.
333 4: always 0, for compatibility with Sun.
335 The following are GNU extensions:
337 5: address of table of start addrs of basic blocks (LPBX3).
338 6: Number of bytes in this header.
339 7: address of table of function names (LPBX4).
340 8: address of table of line numbers (LPBX5) or 0.
341 9: address of table of file names (LPBX6) or 0.
342 10: space reserved for basic block profiling. */
344 ASM_OUTPUT_ALIGN (asm_out_file, align);
346 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
348 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
350 /* address of filename */
351 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
352 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
354 /* address of count table */
355 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
356 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
358 /* count of the # of basic blocks */
359 assemble_integer (GEN_INT (count_basic_blocks), UNITS_PER_WORD, 1);
361 /* zero word (link field) */
362 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
364 /* address of basic block start address table */
365 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
366 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
368 /* byte count for extended structure. */
369 assemble_integer (GEN_INT (11 * UNITS_PER_WORD), UNITS_PER_WORD, 1);
371 /* address of function name table */
372 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
373 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
375 /* address of line number and filename tables if debugging. */
376 if (write_symbols != NO_DEBUG)
378 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
379 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
380 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
381 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
385 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
386 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
389 /* space for extension ptr (link field) */
390 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
392 /* Output the file name changing the suffix to .d for Sun tcov
394 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
396 char *cwd = getpwd ();
397 int len = strlen (filename) + strlen (cwd) + 1;
398 char *data_file = (char *) alloca (len + 4);
400 strcpy (data_file, cwd);
401 strcat (data_file, "/");
402 strcat (data_file, filename);
403 strip_off_ending (data_file, len);
404 strcat (data_file, ".d");
405 assemble_string (data_file, strlen (data_file) + 1);
408 /* Make space for the table of counts. */
411 /* Realign data section. */
412 ASM_OUTPUT_ALIGN (asm_out_file, align);
413 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
415 assemble_zeros (size);
419 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
420 #ifdef ASM_OUTPUT_SHARED_LOCAL
421 if (flag_shared_data)
422 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
425 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
426 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
429 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
433 /* Output any basic block strings */
434 readonly_data_section ();
437 ASM_OUTPUT_ALIGN (asm_out_file, align);
438 for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
440 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC", sptr->label_num);
441 assemble_string (sptr->string, sptr->length);
445 /* Output the table of addresses. */
446 /* Realign in new section */
447 ASM_OUTPUT_ALIGN (asm_out_file, align);
448 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
449 for (i = 0; i < count_basic_blocks; i++)
451 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
452 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
456 /* Output the table of function names. */
457 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
458 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
460 if (ptr->func_label_num >= 0)
462 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->func_label_num);
463 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
467 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
470 for ( ; i < count_basic_blocks; i++)
471 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
473 if (write_symbols != NO_DEBUG)
475 /* Output the table of line numbers. */
476 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
477 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
478 assemble_integer (GEN_INT (ptr->line_num), UNITS_PER_WORD, 1);
480 for ( ; i < count_basic_blocks; i++)
481 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
483 /* Output the table of file names. */
484 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
485 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
487 if (ptr->file_label_num >= 0)
489 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->file_label_num);
490 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
494 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
497 for ( ; i < count_basic_blocks; i++)
498 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
501 /* End with the address of the table of addresses,
502 so we can find it easily, as the last word in the file's text. */
503 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
504 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
508 /* Enable APP processing of subsequent output.
509 Used before the output from an `asm' statement. */
516 fprintf (asm_out_file, ASM_APP_ON);
521 /* Disable APP processing of subsequent output.
522 Called from varasm.c before most kinds of output. */
529 fprintf (asm_out_file, ASM_APP_OFF);
534 /* Return the number of slots filled in the current
535 delayed branch sequence (we don't count the insn needing the
536 delay slot). Zero if not in a delayed branch sequence. */
540 dbr_sequence_length ()
542 if (final_sequence != 0)
543 return XVECLEN (final_sequence, 0) - 1;
549 /* The next two pages contain routines used to compute the length of an insn
550 and to shorten branches. */
552 /* Arrays for insn lengths, and addresses. The latter is referenced by
553 `insn_current_length'. */
555 static short *insn_lengths;
558 /* Address of insn being processed. Used by `insn_current_length'. */
559 int insn_current_address;
561 /* Indicate that branch shortening hasn't yet been done. */
569 /* Obtain the current length of an insn. If branch shortening has been done,
570 get its actual length. Otherwise, get its maximum length. */
573 get_attr_length (insn)
576 #ifdef HAVE_ATTR_length
582 return insn_lengths[INSN_UID (insn)];
584 switch (GET_CODE (insn))
592 length = insn_default_length (insn);
596 body = PATTERN (insn);
597 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
599 /* This only takes room if jump tables go into the text section. */
600 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
601 length = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
602 * GET_MODE_SIZE (GET_MODE (body)));
604 /* Be pessimistic and assume worst-case alignment. */
605 length += (GET_MODE_SIZE (GET_MODE (body)) - 1);
611 length = insn_default_length (insn);
615 body = PATTERN (insn);
616 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
619 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
620 length = asm_insn_count (body) * insn_default_length (insn);
621 else if (GET_CODE (body) == SEQUENCE)
622 for (i = 0; i < XVECLEN (body, 0); i++)
623 length += get_attr_length (XVECEXP (body, 0, i));
625 length = insn_default_length (insn);
628 #ifdef ADJUST_INSN_LENGTH
629 ADJUST_INSN_LENGTH (insn, length);
632 #else /* not HAVE_ATTR_length */
634 #endif /* not HAVE_ATTR_length */
637 /* Make a pass over all insns and compute their actual lengths by shortening
638 any branches of variable length if possible. */
640 /* Give a default value for the lowest address in a function. */
642 #ifndef FIRST_INSN_ADDRESS
643 #define FIRST_INSN_ADDRESS 0
647 shorten_branches (first)
650 #ifdef HAVE_ATTR_length
652 int something_changed = 1;
654 char *varying_length;
658 /* Compute maximum UID and allocate arrays. */
659 for (insn = first; insn; insn = NEXT_INSN (insn))
660 if (INSN_UID (insn) > max_uid)
661 max_uid = INSN_UID (insn);
664 insn_lengths = (short *) oballoc (max_uid * sizeof (short));
665 insn_addresses = (int *) oballoc (max_uid * sizeof (int));
666 varying_length = (char *) oballoc (max_uid * sizeof (char));
668 /* Compute initial lengths, addresses, and varying flags for each insn. */
669 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
671 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
673 uid = INSN_UID (insn);
674 insn_addresses[uid] = insn_current_address;
675 insn_lengths[uid] = 0;
676 varying_length[uid] = 0;
678 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
679 || GET_CODE (insn) == CODE_LABEL)
682 body = PATTERN (insn);
683 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
685 /* This only takes room if read-only data goes into the text
687 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
688 int unitsize = GET_MODE_SIZE (GET_MODE (body));
690 insn_lengths[uid] = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
691 * GET_MODE_SIZE (GET_MODE (body)));
693 /* Account for possible alignment. */
695 += unitsize - (insn_current_address & (unitsize - 1));
700 else if (asm_noperands (body) >= 0)
701 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
702 else if (GET_CODE (body) == SEQUENCE)
705 int const_delay_slots;
707 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
709 const_delay_slots = 0;
711 /* Inside a delay slot sequence, we do not do any branch shortening
712 if the shortening could change the number of delay slots
714 for (i = 0; i < XVECLEN (body, 0); i++)
716 rtx inner_insn = XVECEXP (body, 0, i);
717 int inner_uid = INSN_UID (inner_insn);
720 if (asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
721 inner_length = (asm_insn_count (PATTERN (inner_insn))
722 * insn_default_length (inner_insn));
724 inner_length = insn_default_length (inner_insn);
726 insn_lengths[inner_uid] = inner_length;
727 if (const_delay_slots)
729 if ((varying_length[inner_uid]
730 = insn_variable_length_p (inner_insn)) != 0)
731 varying_length[uid] = 1;
732 insn_addresses[inner_uid] = (insn_current_address +
736 varying_length[inner_uid] = 0;
737 insn_lengths[uid] += inner_length;
740 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
742 insn_lengths[uid] = insn_default_length (insn);
743 varying_length[uid] = insn_variable_length_p (insn);
746 /* If needed, do any adjustment. */
747 #ifdef ADJUST_INSN_LENGTH
748 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
752 /* Now loop over all the insns finding varying length insns. For each,
753 get the current insn length. If it has changed, reflect the change.
754 When nothing changes for a full pass, we are done. */
756 while (something_changed)
758 something_changed = 0;
759 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
761 insn = NEXT_INSN (insn))
766 uid = INSN_UID (insn);
767 insn_addresses[uid] = insn_current_address;
768 if (! varying_length[uid])
770 insn_current_address += insn_lengths[uid];
773 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
777 body = PATTERN (insn);
779 for (i = 0; i < XVECLEN (body, 0); i++)
781 rtx inner_insn = XVECEXP (body, 0, i);
782 int inner_uid = INSN_UID (inner_insn);
785 insn_addresses[inner_uid] = insn_current_address;
787 /* insn_current_length returns 0 for insns with a
788 non-varying length. */
789 if (! varying_length[inner_uid])
790 inner_length = insn_lengths[inner_uid];
792 inner_length = insn_current_length (inner_insn);
794 if (inner_length != insn_lengths[inner_uid])
796 insn_lengths[inner_uid] = inner_length;
797 something_changed = 1;
799 insn_current_address += insn_lengths[inner_uid];
800 new_length += inner_length;
805 new_length = insn_current_length (insn);
806 insn_current_address += new_length;
809 #ifdef SHORTEN_WITH_ADJUST_INSN_LENGTH
810 #ifdef ADJUST_INSN_LENGTH
811 /* If needed, do any adjustment. */
812 tmp_length = new_length;
813 ADJUST_INSN_LENGTH (insn, new_length);
814 insn_current_address += (new_length - tmp_length);
818 if (new_length != insn_lengths[uid])
820 insn_lengths[uid] = new_length;
821 something_changed = 1;
824 /* For a non-optimizing compile, do only a single pass. */
828 #endif /* HAVE_ATTR_length */
831 #ifdef HAVE_ATTR_length
832 /* Given the body of an INSN known to be generated by an ASM statement, return
833 the number of machine instructions likely to be generated for this insn.
834 This is used to compute its length. */
837 asm_insn_count (body)
843 if (GET_CODE (body) == ASM_INPUT)
844 template = XSTR (body, 0);
846 template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
849 for ( ; *template; template++)
850 if (IS_ASM_LOGICAL_LINE_SEPARATOR(*template) || *template == '\n')
857 /* Output assembler code for the start of a function,
858 and initialize some of the variables in this file
859 for the new function. The label for the function and associated
860 assembler pseudo-ops have already been output in `assemble_start_function'.
862 FIRST is the first insn of the rtl for the function being compiled.
863 FILE is the file to write assembler code to.
864 OPTIMIZE is nonzero if we should eliminate redundant
865 test and compare insns. */
868 final_start_function (first, file, optimize)
875 this_is_asm_operands = 0;
877 #ifdef NON_SAVING_SETJMP
878 /* A function that calls setjmp should save and restore all the
879 call-saved registers on a system where longjmp clobbers them. */
880 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
884 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
885 if (!call_used_regs[i] && !call_fixed_regs[i])
886 regs_ever_live[i] = 1;
890 /* Initial line number is supposed to be output
891 before the function's prologue and label
892 so that the function's address will not appear to be
893 in the last statement of the preceding function. */
894 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
895 last_linenum = high_block_linenum = high_function_linenum
896 = NOTE_LINE_NUMBER (first);
898 #if defined (DWARF_DEBUGGING_INFO) && DWARF_VERSION == 2
899 /* Output DWARF definition of the function. */
900 if (write_symbols == DWARF_DEBUG)
901 dwarfout_begin_prologue ();
904 /* For SDB and XCOFF, the function beginning must be marked between
905 the function label and the prologue. We always need this, even when
906 -g1 was used. Defer on MIPS systems so that parameter descriptions
907 follow function entry. */
908 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
909 if (write_symbols == SDB_DEBUG)
910 sdbout_begin_function (last_linenum);
913 #ifdef XCOFF_DEBUGGING_INFO
914 if (write_symbols == XCOFF_DEBUG)
915 xcoffout_begin_function (file, last_linenum);
918 /* But only output line number for other debug info types if -g2
920 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
921 output_source_line (file, first);
923 #ifdef LEAF_REG_REMAP
925 leaf_renumber_regs (first);
928 /* The Sun386i and perhaps other machines don't work right
929 if the profiling code comes after the prologue. */
930 #ifdef PROFILE_BEFORE_PROLOGUE
932 profile_function (file);
933 #endif /* PROFILE_BEFORE_PROLOGUE */
935 #ifdef FUNCTION_PROLOGUE
936 /* First output the function prologue: code to set up the stack frame. */
937 FUNCTION_PROLOGUE (file, get_frame_size ());
940 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
941 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
942 next_block_index = 1;
945 /* If the machine represents the prologue as RTL, the profiling code must
946 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
950 profile_after_prologue (file);
954 /* If we are doing basic block profiling, remember a printable version
955 of the function name. */
956 if (profile_block_flag)
958 char *junk = "function";
960 add_bb_string ((*decl_printable_name) (current_function_decl, &junk), FALSE);
965 profile_after_prologue (file)
968 #ifdef FUNCTION_BLOCK_PROFILER
969 if (profile_block_flag)
971 FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
973 #endif /* FUNCTION_BLOCK_PROFILER */
975 #ifndef PROFILE_BEFORE_PROLOGUE
977 profile_function (file);
978 #endif /* not PROFILE_BEFORE_PROLOGUE */
982 profile_function (file)
985 int align = MIN (BIGGEST_ALIGNMENT, POINTER_SIZE);
986 int sval = current_function_returns_struct;
987 int cxt = current_function_needs_context;
990 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
991 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
992 assemble_integer (const0_rtx, POINTER_SIZE / BITS_PER_UNIT, 1);
996 #ifdef STRUCT_VALUE_INCOMING_REGNUM
998 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
1000 #ifdef STRUCT_VALUE_REGNUM
1002 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
1007 #ifdef STATIC_CHAIN_INCOMING_REGNUM
1009 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1011 #ifdef STATIC_CHAIN_REGNUM
1013 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1018 FUNCTION_PROFILER (file, profile_label_no);
1021 #ifdef STATIC_CHAIN_INCOMING_REGNUM
1023 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1025 #ifdef STATIC_CHAIN_REGNUM
1027 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1032 #ifdef STRUCT_VALUE_INCOMING_REGNUM
1034 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1036 #ifdef STRUCT_VALUE_REGNUM
1038 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1043 /* Output assembler code for the end of a function.
1044 For clarity, args are same as those of `final_start_function'
1045 even though not all of them are needed. */
1048 final_end_function (first, file, optimize)
1055 fprintf (file, ASM_APP_OFF);
1059 #ifdef SDB_DEBUGGING_INFO
1060 if (write_symbols == SDB_DEBUG)
1061 sdbout_end_function (high_function_linenum);
1064 #ifdef DWARF_DEBUGGING_INFO
1065 if (write_symbols == DWARF_DEBUG)
1066 dwarfout_end_function ();
1069 #ifdef XCOFF_DEBUGGING_INFO
1070 if (write_symbols == XCOFF_DEBUG)
1071 xcoffout_end_function (file, high_function_linenum);
1074 #ifdef FUNCTION_EPILOGUE
1075 /* Finally, output the function epilogue:
1076 code to restore the stack frame and return to the caller. */
1077 FUNCTION_EPILOGUE (file, get_frame_size ());
1080 #ifdef SDB_DEBUGGING_INFO
1081 if (write_symbols == SDB_DEBUG)
1082 sdbout_end_epilogue ();
1085 #ifdef DWARF_DEBUGGING_INFO
1086 if (write_symbols == DWARF_DEBUG)
1087 dwarfout_end_epilogue ();
1090 #ifdef XCOFF_DEBUGGING_INFO
1091 if (write_symbols == XCOFF_DEBUG)
1092 xcoffout_end_epilogue (file);
1095 bb_func_label_num = -1; /* not in function, nuke label # */
1097 /* If FUNCTION_EPILOGUE is not defined, then the function body
1098 itself contains return instructions wherever needed. */
1101 /* Add a block to the linked list that remembers the current line/file/function
1102 for basic block profiling. Emit the label in front of the basic block and
1103 the instructions that increment the count field. */
1109 struct bb_list *ptr = (struct bb_list *) permalloc (sizeof (struct bb_list));
1111 /* Add basic block to linked list. */
1113 ptr->line_num = last_linenum;
1114 ptr->file_label_num = bb_file_label_num;
1115 ptr->func_label_num = bb_func_label_num;
1117 bb_tail = &ptr->next;
1119 /* Enable the table of basic-block use counts
1120 to point at the code it applies to. */
1121 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1123 /* Before first insn of this basic block, increment the
1124 count of times it was entered. */
1125 #ifdef BLOCK_PROFILER
1126 BLOCK_PROFILER (file, count_basic_blocks);
1131 count_basic_blocks++;
1134 /* Add a string to be used for basic block profiling. */
1137 add_bb_string (string, perm_p)
1142 struct bb_str *ptr = 0;
1146 string = "<unknown>";
1150 /* Allocate a new string if the current string isn't permanent. If
1151 the string is permanent search for the same string in other
1154 len = strlen (string) + 1;
1157 char *p = (char *) permalloc (len);
1158 bcopy (string, p, len);
1162 for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
1163 if (ptr->string == string)
1166 /* Allocate a new string block if we need to. */
1169 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1172 ptr->label_num = sbb_label_num++;
1173 ptr->string = string;
1175 sbb_tail = &ptr->next;
1178 return ptr->label_num;
1182 /* Output assembler code for some insns: all or part of a function.
1183 For description of args, see `final_start_function', above.
1185 PRESCAN is 1 if we are not really outputting,
1186 just scanning as if we were outputting.
1187 Prescanning deletes and rearranges insns just like ordinary output.
1188 PRESCAN is -2 if we are outputting after having prescanned.
1189 In this case, don't try to delete or rearrange insns
1190 because that has already been done.
1191 Prescanning is done only on certain machines. */
1194 final (first, file, optimize, prescan)
1203 last_ignored_compare = 0;
1206 check_exception_handler_labels ();
1208 /* Make a map indicating which line numbers appear in this function.
1209 When producing SDB debugging info, delete troublesome line number
1210 notes from inlined functions in other files as well as duplicate
1211 line number notes. */
1212 #ifdef SDB_DEBUGGING_INFO
1213 if (write_symbols == SDB_DEBUG)
1216 for (insn = first; insn; insn = NEXT_INSN (insn))
1217 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1219 if ((RTX_INTEGRATED_P (insn)
1220 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1222 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1223 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1225 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1226 NOTE_SOURCE_FILE (insn) = 0;
1230 if (NOTE_LINE_NUMBER (insn) > max_line)
1231 max_line = NOTE_LINE_NUMBER (insn);
1237 for (insn = first; insn; insn = NEXT_INSN (insn))
1238 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1239 max_line = NOTE_LINE_NUMBER (insn);
1242 line_note_exists = (char *) oballoc (max_line + 1);
1243 bzero (line_note_exists, max_line + 1);
1245 for (insn = first; insn; insn = NEXT_INSN (insn))
1246 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1247 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1253 /* Output the insns. */
1254 for (insn = NEXT_INSN (first); insn;)
1256 #ifdef HAVE_ATTR_length
1257 insn_current_address = insn_addresses[INSN_UID (insn)];
1259 insn = final_scan_insn (insn, file, optimize, prescan, 0);
1262 /* Do basic-block profiling here
1263 if the last insn was a conditional branch. */
1264 if (profile_block_flag && new_block)
1268 /* The final scan for one insn, INSN.
1269 Args are same as in `final', except that INSN
1270 is the insn being scanned.
1271 Value returned is the next insn to be scanned.
1273 NOPEEPHOLES is the flag to disallow peephole processing (currently
1274 used for within delayed branch sequence output). */
1277 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
1287 /* Ignore deleted insns. These can occur when we split insns (due to a
1288 template of "#") while not optimizing. */
1289 if (INSN_DELETED_P (insn))
1290 return NEXT_INSN (insn);
1292 switch (GET_CODE (insn))
1298 /* Align the beginning of a loop, for higher speed
1299 on certain machines. */
1301 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG && optimize > 0)
1303 #ifdef ASM_OUTPUT_LOOP_ALIGN
1304 rtx next = next_nonnote_insn (insn);
1305 if (next && GET_CODE (next) == CODE_LABEL)
1307 ASM_OUTPUT_LOOP_ALIGN (asm_out_file);
1312 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
1315 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
1317 ASM_OUTPUT_INTERNAL_LABEL (file, "LEHB", NOTE_BLOCK_NUMBER (insn));
1318 add_eh_table_entry (NOTE_BLOCK_NUMBER (insn));
1319 #ifdef ASM_OUTPUT_EH_REGION_BEG
1320 ASM_OUTPUT_EH_REGION_BEG (file, NOTE_BLOCK_NUMBER (insn));
1325 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
1327 ASM_OUTPUT_INTERNAL_LABEL (file, "LEHE", NOTE_BLOCK_NUMBER (insn));
1328 #ifdef ASM_OUTPUT_EH_REGION_END
1329 ASM_OUTPUT_EH_REGION_END (file, NOTE_BLOCK_NUMBER (insn));
1334 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
1336 #ifdef FUNCTION_END_PROLOGUE
1337 FUNCTION_END_PROLOGUE (file);
1339 profile_after_prologue (file);
1343 #ifdef FUNCTION_BEGIN_EPILOGUE
1344 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
1346 FUNCTION_BEGIN_EPILOGUE (file);
1351 if (write_symbols == NO_DEBUG)
1353 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
1355 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
1356 /* MIPS stabs require the parameter descriptions to be after the
1357 function entry point rather than before. */
1358 if (write_symbols == SDB_DEBUG)
1359 sdbout_begin_function (last_linenum);
1362 #ifdef DWARF_DEBUGGING_INFO
1363 /* This outputs a marker where the function body starts, so it
1364 must be after the prologue. */
1365 if (write_symbols == DWARF_DEBUG)
1366 dwarfout_begin_function ();
1370 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
1371 break; /* An insn that was "deleted" */
1374 fprintf (file, ASM_APP_OFF);
1377 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
1378 && (debug_info_level == DINFO_LEVEL_NORMAL
1379 || debug_info_level == DINFO_LEVEL_VERBOSE
1380 #ifdef DWARF_DEBUGGING_INFO
1381 || write_symbols == DWARF_DEBUG
1386 /* Beginning of a symbol-block. Assign it a sequence number
1387 and push the number onto the stack PENDING_BLOCKS. */
1389 if (block_depth == max_block_depth)
1391 /* PENDING_BLOCKS is full; make it longer. */
1392 max_block_depth *= 2;
1394 = (int *) xrealloc (pending_blocks,
1395 max_block_depth * sizeof (int));
1397 pending_blocks[block_depth++] = next_block_index;
1399 high_block_linenum = last_linenum;
1401 /* Output debugging info about the symbol-block beginning. */
1403 #ifdef SDB_DEBUGGING_INFO
1404 if (write_symbols == SDB_DEBUG)
1405 sdbout_begin_block (file, last_linenum, next_block_index);
1407 #ifdef XCOFF_DEBUGGING_INFO
1408 if (write_symbols == XCOFF_DEBUG)
1409 xcoffout_begin_block (file, last_linenum, next_block_index);
1411 #ifdef DBX_DEBUGGING_INFO
1412 if (write_symbols == DBX_DEBUG)
1413 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
1415 #ifdef DWARF_DEBUGGING_INFO
1416 if (write_symbols == DWARF_DEBUG)
1417 dwarfout_begin_block (next_block_index);
1422 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
1423 && (debug_info_level == DINFO_LEVEL_NORMAL
1424 || debug_info_level == DINFO_LEVEL_VERBOSE
1425 #ifdef DWARF_DEBUGGING_INFO
1426 || write_symbols == DWARF_DEBUG
1431 /* End of a symbol-block. Pop its sequence number off
1432 PENDING_BLOCKS and output debugging info based on that. */
1436 #ifdef XCOFF_DEBUGGING_INFO
1437 if (write_symbols == XCOFF_DEBUG && block_depth >= 0)
1438 xcoffout_end_block (file, high_block_linenum,
1439 pending_blocks[block_depth]);
1441 #ifdef DBX_DEBUGGING_INFO
1442 if (write_symbols == DBX_DEBUG && block_depth >= 0)
1443 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
1444 pending_blocks[block_depth]);
1446 #ifdef SDB_DEBUGGING_INFO
1447 if (write_symbols == SDB_DEBUG && block_depth >= 0)
1448 sdbout_end_block (file, high_block_linenum,
1449 pending_blocks[block_depth]);
1451 #ifdef DWARF_DEBUGGING_INFO
1452 if (write_symbols == DWARF_DEBUG && block_depth >= 0)
1453 dwarfout_end_block (pending_blocks[block_depth]);
1456 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
1457 && (debug_info_level == DINFO_LEVEL_NORMAL
1458 || debug_info_level == DINFO_LEVEL_VERBOSE))
1460 #ifdef DWARF_DEBUGGING_INFO
1461 if (write_symbols == DWARF_DEBUG)
1462 dwarfout_label (insn);
1465 else if (NOTE_LINE_NUMBER (insn) > 0)
1466 /* This note is a line-number. */
1470 #if 0 /* This is what we used to do. */
1471 output_source_line (file, insn);
1475 /* If there is anything real after this note,
1476 output it. If another line note follows, omit this one. */
1477 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
1479 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
1481 /* These types of notes can be significant
1482 so make sure the preceding line number stays. */
1483 else if (GET_CODE (note) == NOTE
1484 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
1485 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
1486 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
1488 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
1490 /* Another line note follows; we can delete this note
1491 if no intervening line numbers have notes elsewhere. */
1493 for (num = NOTE_LINE_NUMBER (insn) + 1;
1494 num < NOTE_LINE_NUMBER (note);
1496 if (line_note_exists[num])
1499 if (num >= NOTE_LINE_NUMBER (note))
1505 /* Output this line note
1506 if it is the first or the last line note in a row. */
1508 output_source_line (file, insn);
1513 #ifdef ASM_OUTPUT_ALIGN_CODE
1514 /* Don't litter the assembler output with needless alignments. A
1515 BARRIER will be placed at the end of every function if HAVE_epilogue
1517 if (NEXT_INSN (insn))
1518 ASM_OUTPUT_ALIGN_CODE (file);
1528 #ifdef FINAL_PRESCAN_LABEL
1529 FINAL_PRESCAN_INSN (insn, NULL_PTR, 0);
1532 #ifdef SDB_DEBUGGING_INFO
1533 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
1534 sdbout_label (insn);
1536 #ifdef DWARF_DEBUGGING_INFO
1537 if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
1538 dwarfout_label (insn);
1542 fprintf (file, ASM_APP_OFF);
1545 if (NEXT_INSN (insn) != 0
1546 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
1548 rtx nextbody = PATTERN (NEXT_INSN (insn));
1550 /* If this label is followed by a jump-table,
1551 make sure we put the label in the read-only section. Also
1552 possibly write the label and jump table together. */
1554 if (GET_CODE (nextbody) == ADDR_VEC
1555 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1557 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1558 readonly_data_section ();
1559 #ifdef READONLY_DATA_SECTION
1560 ASM_OUTPUT_ALIGN (file,
1561 exact_log2 (BIGGEST_ALIGNMENT
1563 #endif /* READONLY_DATA_SECTION */
1564 #else /* JUMP_TABLES_IN_TEXT_SECTION */
1565 function_section (current_function_decl);
1566 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
1567 #ifdef ASM_OUTPUT_CASE_LABEL
1568 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
1571 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1577 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1582 register rtx body = PATTERN (insn);
1583 int insn_code_number;
1587 /* An INSN, JUMP_INSN or CALL_INSN.
1588 First check for special kinds that recog doesn't recognize. */
1590 if (GET_CODE (body) == USE /* These are just declarations */
1591 || GET_CODE (body) == CLOBBER)
1595 /* If there is a REG_CC_SETTER note on this insn, it means that
1596 the setting of the condition code was done in the delay slot
1597 of the insn that branched here. So recover the cc status
1598 from the insn that set it. */
1600 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1603 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
1604 cc_prev_status = cc_status;
1608 /* Detect insns that are really jump-tables
1609 and output them as such. */
1611 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1613 register int vlen, idx;
1620 fprintf (file, ASM_APP_OFF);
1624 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
1625 for (idx = 0; idx < vlen; idx++)
1627 if (GET_CODE (body) == ADDR_VEC)
1629 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
1630 ASM_OUTPUT_ADDR_VEC_ELT
1631 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
1638 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
1639 ASM_OUTPUT_ADDR_DIFF_ELT
1641 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
1642 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
1648 #ifdef ASM_OUTPUT_CASE_END
1649 ASM_OUTPUT_CASE_END (file,
1650 CODE_LABEL_NUMBER (PREV_INSN (insn)),
1654 function_section (current_function_decl);
1659 /* Do basic-block profiling when we reach a new block.
1660 Done here to avoid jump tables. */
1661 if (profile_block_flag && new_block)
1664 if (GET_CODE (body) == ASM_INPUT)
1666 /* There's no telling what that did to the condition codes. */
1672 fprintf (file, ASM_APP_ON);
1675 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
1679 /* Detect `asm' construct with operands. */
1680 if (asm_noperands (body) >= 0)
1682 int noperands = asm_noperands (body);
1683 rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
1686 /* There's no telling what that did to the condition codes. */
1693 fprintf (file, ASM_APP_ON);
1697 /* Get out the operand values. */
1698 string = decode_asm_operands (body, ops, NULL_PTR,
1699 NULL_PTR, NULL_PTR);
1700 /* Inhibit aborts on what would otherwise be compiler bugs. */
1701 insn_noperands = noperands;
1702 this_is_asm_operands = insn;
1704 /* Output the insn using them. */
1705 output_asm_insn (string, ops);
1706 this_is_asm_operands = 0;
1710 if (prescan <= 0 && app_on)
1712 fprintf (file, ASM_APP_OFF);
1716 if (GET_CODE (body) == SEQUENCE)
1718 /* A delayed-branch sequence */
1724 final_sequence = body;
1726 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
1727 force the restoration of a comparison that was previously
1728 thought unnecessary. If that happens, cancel this sequence
1729 and cause that insn to be restored. */
1731 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
1732 if (next != XVECEXP (body, 0, 1))
1738 for (i = 1; i < XVECLEN (body, 0); i++)
1740 rtx insn = XVECEXP (body, 0, i);
1741 rtx next = NEXT_INSN (insn);
1742 /* We loop in case any instruction in a delay slot gets
1745 insn = final_scan_insn (insn, file, 0, prescan, 1);
1746 while (insn != next);
1748 #ifdef DBR_OUTPUT_SEQEND
1749 DBR_OUTPUT_SEQEND (file);
1753 /* If the insn requiring the delay slot was a CALL_INSN, the
1754 insns in the delay slot are actually executed before the
1755 called function. Hence we don't preserve any CC-setting
1756 actions in these insns and the CC must be marked as being
1757 clobbered by the function. */
1758 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
1761 /* Following a conditional branch sequence, we have a new basic
1763 if (profile_block_flag)
1765 rtx insn = XVECEXP (body, 0, 0);
1766 rtx body = PATTERN (insn);
1768 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1769 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1770 || (GET_CODE (insn) == JUMP_INSN
1771 && GET_CODE (body) == PARALLEL
1772 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1773 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
1779 /* We have a real machine instruction as rtl. */
1781 body = PATTERN (insn);
1784 /* Check for redundant test and compare instructions
1785 (when the condition codes are already set up as desired).
1786 This is done only when optimizing; if not optimizing,
1787 it should be possible for the user to alter a variable
1788 with the debugger in between statements
1789 and the next statement should reexamine the variable
1790 to compute the condition codes. */
1794 rtx set = single_set(insn);
1797 && GET_CODE (SET_DEST (set)) == CC0
1798 && insn != last_ignored_compare)
1800 if (GET_CODE (SET_SRC (set)) == SUBREG)
1801 SET_SRC (set) = alter_subreg (SET_SRC (set));
1802 else if (GET_CODE (SET_SRC (set)) == COMPARE)
1804 if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
1805 XEXP (SET_SRC (set), 0)
1806 = alter_subreg (XEXP (SET_SRC (set), 0));
1807 if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
1808 XEXP (SET_SRC (set), 1)
1809 = alter_subreg (XEXP (SET_SRC (set), 1));
1811 if ((cc_status.value1 != 0
1812 && rtx_equal_p (SET_SRC (set), cc_status.value1))
1813 || (cc_status.value2 != 0
1814 && rtx_equal_p (SET_SRC (set), cc_status.value2)))
1816 /* Don't delete insn if it has an addressing side-effect. */
1817 if (! FIND_REG_INC_NOTE (insn, 0)
1818 /* or if anything in it is volatile. */
1819 && ! volatile_refs_p (PATTERN (insn)))
1821 /* We don't really delete the insn; just ignore it. */
1822 last_ignored_compare = insn;
1830 /* Following a conditional branch, we have a new basic block.
1831 But if we are inside a sequence, the new block starts after the
1832 last insn of the sequence. */
1833 if (profile_block_flag && final_sequence == 0
1834 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1835 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1836 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
1837 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1838 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
1842 /* Don't bother outputting obvious no-ops, even without -O.
1843 This optimization is fast and doesn't interfere with debugging.
1844 Don't do this if the insn is in a delay slot, since this
1845 will cause an improper number of delay insns to be written. */
1846 if (final_sequence == 0
1848 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
1849 && GET_CODE (SET_SRC (body)) == REG
1850 && GET_CODE (SET_DEST (body)) == REG
1851 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
1856 /* If this is a conditional branch, maybe modify it
1857 if the cc's are in a nonstandard state
1858 so that it accomplishes the same thing that it would
1859 do straightforwardly if the cc's were set up normally. */
1861 if (cc_status.flags != 0
1862 && GET_CODE (insn) == JUMP_INSN
1863 && GET_CODE (body) == SET
1864 && SET_DEST (body) == pc_rtx
1865 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
1866 && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
1867 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
1868 /* This is done during prescan; it is not done again
1869 in final scan when prescan has been done. */
1872 /* This function may alter the contents of its argument
1873 and clear some of the cc_status.flags bits.
1874 It may also return 1 meaning condition now always true
1875 or -1 meaning condition now always false
1876 or 2 meaning condition nontrivial but altered. */
1877 register int result = alter_cond (XEXP (SET_SRC (body), 0));
1878 /* If condition now has fixed value, replace the IF_THEN_ELSE
1879 with its then-operand or its else-operand. */
1881 SET_SRC (body) = XEXP (SET_SRC (body), 1);
1883 SET_SRC (body) = XEXP (SET_SRC (body), 2);
1885 /* The jump is now either unconditional or a no-op.
1886 If it has become a no-op, don't try to output it.
1887 (It would not be recognized.) */
1888 if (SET_SRC (body) == pc_rtx)
1890 PUT_CODE (insn, NOTE);
1891 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1892 NOTE_SOURCE_FILE (insn) = 0;
1895 else if (GET_CODE (SET_SRC (body)) == RETURN)
1896 /* Replace (set (pc) (return)) with (return). */
1897 PATTERN (insn) = body = SET_SRC (body);
1899 /* Rerecognize the instruction if it has changed. */
1901 INSN_CODE (insn) = -1;
1904 /* Make same adjustments to instructions that examine the
1905 condition codes without jumping and instructions that
1906 handle conditional moves (if this machine has either one). */
1908 if (cc_status.flags != 0
1909 && GET_CODE (body) == SET)
1911 rtx cond_rtx, then_rtx, else_rtx;
1913 if (GET_CODE (insn) != JUMP_INSN
1914 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE)
1916 cond_rtx = XEXP (SET_SRC (body), 0);
1917 then_rtx = XEXP (SET_SRC (body), 1);
1918 else_rtx = XEXP (SET_SRC (body), 2);
1922 cond_rtx = SET_SRC (body);
1923 then_rtx = const_true_rtx;
1924 else_rtx = const0_rtx;
1927 switch (GET_CODE (cond_rtx))
1940 register int result;
1941 if (XEXP (cond_rtx, 0) != cc0_rtx)
1943 result = alter_cond (cond_rtx);
1945 validate_change (insn, &SET_SRC (body), then_rtx, 0);
1946 else if (result == -1)
1947 validate_change (insn, &SET_SRC (body), else_rtx, 0);
1948 else if (result == 2)
1949 INSN_CODE (insn) = -1;
1950 if (SET_DEST (body) == SET_SRC (body))
1952 PUT_CODE (insn, NOTE);
1953 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1954 NOTE_SOURCE_FILE (insn) = 0;
1963 /* Do machine-specific peephole optimizations if desired. */
1965 if (optimize && !flag_no_peephole && !nopeepholes)
1967 rtx next = peephole (insn);
1968 /* When peepholing, if there were notes within the peephole,
1969 emit them before the peephole. */
1970 if (next != 0 && next != NEXT_INSN (insn))
1972 rtx prev = PREV_INSN (insn);
1975 for (note = NEXT_INSN (insn); note != next;
1976 note = NEXT_INSN (note))
1977 final_scan_insn (note, file, optimize, prescan, nopeepholes);
1979 /* In case this is prescan, put the notes
1980 in proper position for later rescan. */
1981 note = NEXT_INSN (insn);
1982 PREV_INSN (note) = prev;
1983 NEXT_INSN (prev) = note;
1984 NEXT_INSN (PREV_INSN (next)) = insn;
1985 PREV_INSN (insn) = PREV_INSN (next);
1986 NEXT_INSN (insn) = next;
1987 PREV_INSN (next) = insn;
1990 /* PEEPHOLE might have changed this. */
1991 body = PATTERN (insn);
1994 /* Try to recognize the instruction.
1995 If successful, verify that the operands satisfy the
1996 constraints for the instruction. Crash if they don't,
1997 since `reload' should have changed them so that they do. */
1999 insn_code_number = recog_memoized (insn);
2000 insn_extract (insn);
2001 for (i = 0; i < insn_n_operands[insn_code_number]; i++)
2003 if (GET_CODE (recog_operand[i]) == SUBREG)
2004 recog_operand[i] = alter_subreg (recog_operand[i]);
2005 else if (GET_CODE (recog_operand[i]) == PLUS
2006 || GET_CODE (recog_operand[i]) == MULT)
2007 recog_operand[i] = walk_alter_subreg (recog_operand[i]);
2010 for (i = 0; i < insn_n_dups[insn_code_number]; i++)
2012 if (GET_CODE (*recog_dup_loc[i]) == SUBREG)
2013 *recog_dup_loc[i] = alter_subreg (*recog_dup_loc[i]);
2014 else if (GET_CODE (*recog_dup_loc[i]) == PLUS
2015 || GET_CODE (*recog_dup_loc[i]) == MULT)
2016 *recog_dup_loc[i] = walk_alter_subreg (*recog_dup_loc[i]);
2019 #ifdef REGISTER_CONSTRAINTS
2020 if (! constrain_operands (insn_code_number, 1))
2021 fatal_insn_not_found (insn);
2024 /* Some target machines need to prescan each insn before
2027 #ifdef FINAL_PRESCAN_INSN
2028 FINAL_PRESCAN_INSN (insn, recog_operand,
2029 insn_n_operands[insn_code_number]);
2033 cc_prev_status = cc_status;
2035 /* Update `cc_status' for this instruction.
2036 The instruction's output routine may change it further.
2037 If the output routine for a jump insn needs to depend
2038 on the cc status, it should look at cc_prev_status. */
2040 NOTICE_UPDATE_CC (body, insn);
2045 /* If the proper template needs to be chosen by some C code,
2046 run that code and get the real template. */
2048 template = insn_template[insn_code_number];
2051 template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
2053 /* If the C code returns 0, it means that it is a jump insn
2054 which follows a deleted test insn, and that test insn
2055 needs to be reinserted. */
2058 if (prev_nonnote_insn (insn) != last_ignored_compare)
2061 return prev_nonnote_insn (insn);
2065 /* If the template is the string "#", it means that this insn must
2067 if (template[0] == '#' && template[1] == '\0')
2069 rtx new = try_split (body, insn, 0);
2071 /* If we didn't split the insn, go away. */
2072 if (new == insn && PATTERN (new) == body)
2082 /* Output assembler code from the template. */
2084 output_asm_insn (template, recog_operand);
2087 /* It's not at all clear why we did this and doing so interferes
2088 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2091 /* Mark this insn as having been output. */
2092 INSN_DELETED_P (insn) = 1;
2098 return NEXT_INSN (insn);
2101 /* Output debugging info to the assembler file FILE
2102 based on the NOTE-insn INSN, assumed to be a line number. */
2105 output_source_line (file, insn)
2109 register char *filename = NOTE_SOURCE_FILE (insn);
2111 /* Remember filename for basic block profiling.
2112 Filenames are allocated on the permanent obstack
2113 or are passed in ARGV, so we don't have to save
2116 if (profile_block_flag && last_filename != filename)
2117 bb_file_label_num = add_bb_string (filename, TRUE);
2119 last_filename = filename;
2120 last_linenum = NOTE_LINE_NUMBER (insn);
2121 high_block_linenum = MAX (last_linenum, high_block_linenum);
2122 high_function_linenum = MAX (last_linenum, high_function_linenum);
2124 if (write_symbols != NO_DEBUG)
2126 #ifdef SDB_DEBUGGING_INFO
2127 if (write_symbols == SDB_DEBUG
2128 #if 0 /* People like having line numbers even in wrong file! */
2129 /* COFF can't handle multiple source files--lose, lose. */
2130 && !strcmp (filename, main_input_filename)
2132 /* COFF relative line numbers must be positive. */
2133 && last_linenum > sdb_begin_function_line)
2135 #ifdef ASM_OUTPUT_SOURCE_LINE
2136 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
2138 fprintf (file, "\t.ln\t%d\n",
2139 ((sdb_begin_function_line > -1)
2140 ? last_linenum - sdb_begin_function_line : 1));
2145 #if defined (DBX_DEBUGGING_INFO)
2146 if (write_symbols == DBX_DEBUG)
2147 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
2150 #if defined (XCOFF_DEBUGGING_INFO)
2151 if (write_symbols == XCOFF_DEBUG)
2152 xcoffout_source_line (file, filename, insn);
2155 #ifdef DWARF_DEBUGGING_INFO
2156 if (write_symbols == DWARF_DEBUG)
2157 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
2162 /* If X is a SUBREG, replace it with a REG or a MEM,
2163 based on the thing it is a subreg of. */
2169 register rtx y = SUBREG_REG (x);
2170 if (GET_CODE (y) == SUBREG)
2171 y = alter_subreg (y);
2173 if (GET_CODE (y) == REG)
2175 /* If the containing reg really gets a hard reg, so do we. */
2177 REGNO (x) = REGNO (y) + SUBREG_WORD (x);
2179 else if (GET_CODE (y) == MEM)
2181 register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2182 if (BYTES_BIG_ENDIAN)
2183 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
2184 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
2186 MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
2187 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
2193 /* Do alter_subreg on all the SUBREGs contained in X. */
2196 walk_alter_subreg (x)
2199 switch (GET_CODE (x))
2203 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2204 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
2208 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2212 return alter_subreg (x);
2220 /* Given BODY, the body of a jump instruction, alter the jump condition
2221 as required by the bits that are set in cc_status.flags.
2222 Not all of the bits there can be handled at this level in all cases.
2224 The value is normally 0.
2225 1 means that the condition has become always true.
2226 -1 means that the condition has become always false.
2227 2 means that COND has been altered. */
2235 if (cc_status.flags & CC_REVERSED)
2238 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
2241 if (cc_status.flags & CC_INVERTED)
2244 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
2247 if (cc_status.flags & CC_NOT_POSITIVE)
2248 switch (GET_CODE (cond))
2253 /* Jump becomes unconditional. */
2259 /* Jump becomes no-op. */
2263 PUT_CODE (cond, EQ);
2268 PUT_CODE (cond, NE);
2273 if (cc_status.flags & CC_NOT_NEGATIVE)
2274 switch (GET_CODE (cond))
2278 /* Jump becomes unconditional. */
2283 /* Jump becomes no-op. */
2288 PUT_CODE (cond, EQ);
2294 PUT_CODE (cond, NE);
2299 if (cc_status.flags & CC_NO_OVERFLOW)
2300 switch (GET_CODE (cond))
2303 /* Jump becomes unconditional. */
2307 PUT_CODE (cond, EQ);
2312 PUT_CODE (cond, NE);
2317 /* Jump becomes no-op. */
2321 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
2322 switch (GET_CODE (cond))
2335 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
2340 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
2345 if (cc_status.flags & CC_NOT_SIGNED)
2346 /* The flags are valid if signed condition operators are converted
2348 switch (GET_CODE (cond))
2351 PUT_CODE (cond, LEU);
2356 PUT_CODE (cond, LTU);
2361 PUT_CODE (cond, GTU);
2366 PUT_CODE (cond, GEU);
2375 /* Report inconsistency between the assembler template and the operands.
2376 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
2379 output_operand_lossage (str)
2382 if (this_is_asm_operands)
2383 error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
2388 /* Output of assembler code from a template, and its subroutines. */
2390 /* Output text from TEMPLATE to the assembler output file,
2391 obeying %-directions to substitute operands taken from
2392 the vector OPERANDS.
2394 %N (for N a digit) means print operand N in usual manner.
2395 %lN means require operand N to be a CODE_LABEL or LABEL_REF
2396 and print the label name with no punctuation.
2397 %cN means require operand N to be a constant
2398 and print the constant expression with no punctuation.
2399 %aN means expect operand N to be a memory address
2400 (not a memory reference!) and print a reference
2402 %nN means expect operand N to be a constant
2403 and print a constant expression for minus the value
2404 of the operand, with no other punctuation. */
2409 if (flag_print_asm_name)
2411 /* Annotate the assembly with a comment describing the pattern and
2412 alternative used. */
2415 register int num = INSN_CODE (debug_insn);
2416 fprintf (asm_out_file, " %s %d %s",
2417 ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
2418 if (insn_n_alternatives[num] > 1)
2419 fprintf (asm_out_file, "/%d", which_alternative + 1);
2421 /* Clear this so only the first assembler insn
2422 of any rtl insn will get the special comment for -dp. */
2429 output_asm_insn (template, operands)
2436 /* An insn may return a null string template
2437 in a case where no assembler code is needed. */
2442 putc ('\t', asm_out_file);
2444 #ifdef ASM_OUTPUT_OPCODE
2445 ASM_OUTPUT_OPCODE (asm_out_file, p);
2453 putc (c, asm_out_file);
2454 #ifdef ASM_OUTPUT_OPCODE
2455 while ((c = *p) == '\t')
2457 putc (c, asm_out_file);
2460 ASM_OUTPUT_OPCODE (asm_out_file, p);
2464 #ifdef ASSEMBLER_DIALECT
2466 /* If we want the first dialect, do nothing. Otherwise, skip
2467 DIALECT_NUMBER of strings ending with '|'. */
2468 for (i = 0; i < dialect_number; i++)
2470 while (*p && *p++ != '|')
2479 /* Skip to close brace. */
2480 while (*p && *p++ != '}')
2489 /* %% outputs a single %. */
2493 putc (c, asm_out_file);
2495 /* %= outputs a number which is unique to each insn in the entire
2496 compilation. This is useful for making local labels that are
2497 referred to more than once in a given insn. */
2501 fprintf (asm_out_file, "%d", insn_counter);
2503 /* % followed by a letter and some digits
2504 outputs an operand in a special way depending on the letter.
2505 Letters `acln' are implemented directly.
2506 Other letters are passed to `output_operand' so that
2507 the PRINT_OPERAND macro can define them. */
2508 else if ((*p >= 'a' && *p <= 'z')
2509 || (*p >= 'A' && *p <= 'Z'))
2514 if (! (*p >= '0' && *p <= '9'))
2515 output_operand_lossage ("operand number missing after %-letter");
2516 else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2517 output_operand_lossage ("operand number out of range");
2518 else if (letter == 'l')
2519 output_asm_label (operands[c]);
2520 else if (letter == 'a')
2521 output_address (operands[c]);
2522 else if (letter == 'c')
2524 if (CONSTANT_ADDRESS_P (operands[c]))
2525 output_addr_const (asm_out_file, operands[c]);
2527 output_operand (operands[c], 'c');
2529 else if (letter == 'n')
2531 if (GET_CODE (operands[c]) == CONST_INT)
2532 fprintf (asm_out_file,
2533 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2538 - INTVAL (operands[c]));
2541 putc ('-', asm_out_file);
2542 output_addr_const (asm_out_file, operands[c]);
2546 output_operand (operands[c], letter);
2548 while ((c = *p) >= '0' && c <= '9') p++;
2550 /* % followed by a digit outputs an operand the default way. */
2551 else if (*p >= '0' && *p <= '9')
2554 if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2555 output_operand_lossage ("operand number out of range");
2557 output_operand (operands[c], 0);
2558 while ((c = *p) >= '0' && c <= '9') p++;
2560 /* % followed by punctuation: output something for that
2561 punctuation character alone, with no operand.
2562 The PRINT_OPERAND macro decides what is actually done. */
2563 #ifdef PRINT_OPERAND_PUNCT_VALID_P
2564 else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
2565 output_operand (NULL_RTX, *p++);
2568 output_operand_lossage ("invalid %%-code");
2572 putc (c, asm_out_file);
2577 putc ('\n', asm_out_file);
2580 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
2583 output_asm_label (x)
2588 if (GET_CODE (x) == LABEL_REF)
2589 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2590 else if (GET_CODE (x) == CODE_LABEL)
2591 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2593 output_operand_lossage ("`%l' operand isn't a label");
2595 assemble_name (asm_out_file, buf);
2598 /* Print operand X using machine-dependent assembler syntax.
2599 The macro PRINT_OPERAND is defined just to control this function.
2600 CODE is a non-digit that preceded the operand-number in the % spec,
2601 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
2602 between the % and the digits.
2603 When CODE is a non-letter, X is 0.
2605 The meanings of the letters are machine-dependent and controlled
2606 by PRINT_OPERAND. */
2609 output_operand (x, code)
2613 if (x && GET_CODE (x) == SUBREG)
2614 x = alter_subreg (x);
2616 /* If X is a pseudo-register, abort now rather than writing trash to the
2619 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2622 PRINT_OPERAND (asm_out_file, x, code);
2625 /* Print a memory reference operand for address X
2626 using machine-dependent assembler syntax.
2627 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
2633 walk_alter_subreg (x);
2634 PRINT_OPERAND_ADDRESS (asm_out_file, x);
2637 /* Print an integer constant expression in assembler syntax.
2638 Addition and subtraction are the only arithmetic
2639 that may appear in these expressions. */
2642 output_addr_const (file, x)
2649 switch (GET_CODE (x))
2659 assemble_name (file, XSTR (x, 0));
2663 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2664 assemble_name (file, buf);
2668 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2669 assemble_name (file, buf);
2674 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2683 /* This used to output parentheses around the expression,
2684 but that does not work on the 386 (either ATT or BSD assembler). */
2685 output_addr_const (file, XEXP (x, 0));
2689 if (GET_MODE (x) == VOIDmode)
2691 /* We can use %d if the number is one word and positive. */
2692 if (CONST_DOUBLE_HIGH (x))
2694 #if HOST_BITS_PER_WIDE_INT == 64
2695 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2701 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2707 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2708 else if (CONST_DOUBLE_LOW (x) < 0)
2710 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2715 CONST_DOUBLE_LOW (x));
2718 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2723 CONST_DOUBLE_LOW (x));
2726 /* We can't handle floating point constants;
2727 PRINT_OPERAND must handle them. */
2728 output_operand_lossage ("floating constant misused");
2732 /* Some assemblers need integer constants to appear last (eg masm). */
2733 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2735 output_addr_const (file, XEXP (x, 1));
2736 if (INTVAL (XEXP (x, 0)) >= 0)
2737 fprintf (file, "+");
2738 output_addr_const (file, XEXP (x, 0));
2742 output_addr_const (file, XEXP (x, 0));
2743 if (INTVAL (XEXP (x, 1)) >= 0)
2744 fprintf (file, "+");
2745 output_addr_const (file, XEXP (x, 1));
2750 /* Avoid outputting things like x-x or x+5-x,
2751 since some assemblers can't handle that. */
2752 x = simplify_subtraction (x);
2753 if (GET_CODE (x) != MINUS)
2756 output_addr_const (file, XEXP (x, 0));
2757 fprintf (file, "-");
2758 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2759 && INTVAL (XEXP (x, 1)) < 0)
2761 fprintf (file, ASM_OPEN_PAREN);
2762 output_addr_const (file, XEXP (x, 1));
2763 fprintf (file, ASM_CLOSE_PAREN);
2766 output_addr_const (file, XEXP (x, 1));
2771 output_addr_const (file, XEXP (x, 0));
2775 output_operand_lossage ("invalid expression as operand");
2779 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
2780 %R prints the value of REGISTER_PREFIX.
2781 %L prints the value of LOCAL_LABEL_PREFIX.
2782 %U prints the value of USER_LABEL_PREFIX.
2783 %I prints the value of IMMEDIATE_PREFIX.
2784 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
2785 Also supported are %d, %x, %s, %e, %f, %g and %%.
2787 We handle alternate assembler dialects here, just like output_asm_insn. */
2790 asm_fprintf VPROTO((FILE *file, char *p, ...))
2801 VA_START (argptr, p);
2804 file = va_arg (argptr, FILE *);
2805 p = va_arg (argptr, char *);
2813 #ifdef ASSEMBLER_DIALECT
2815 /* If we want the first dialect, do nothing. Otherwise, skip
2816 DIALECT_NUMBER of strings ending with '|'. */
2817 for (i = 0; i < dialect_number; i++)
2819 while (*p && *p++ != '|')
2828 /* Skip to close brace. */
2829 while (*p && *p++ != '}')
2840 while ((c >= '0' && c <= '9') || c == '.')
2848 fprintf (file, "%%");
2851 case 'd': case 'i': case 'u':
2852 case 'x': case 'p': case 'X':
2856 fprintf (file, buf, va_arg (argptr, int));
2860 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
2861 but we do not check for those cases. It means that the value
2862 is a HOST_WIDE_INT, which may be either `int' or `long'. */
2864 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2870 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
2877 fprintf (file, buf, va_arg (argptr, long));
2885 fprintf (file, buf, va_arg (argptr, double));
2891 fprintf (file, buf, va_arg (argptr, char *));
2895 #ifdef ASM_OUTPUT_OPCODE
2896 ASM_OUTPUT_OPCODE (asm_out_file, p);
2901 #ifdef REGISTER_PREFIX
2902 fprintf (file, "%s", REGISTER_PREFIX);
2907 #ifdef IMMEDIATE_PREFIX
2908 fprintf (file, "%s", IMMEDIATE_PREFIX);
2913 #ifdef LOCAL_LABEL_PREFIX
2914 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
2919 #ifdef USER_LABEL_PREFIX
2920 fprintf (file, "%s", USER_LABEL_PREFIX);
2934 /* Split up a CONST_DOUBLE or integer constant rtx
2935 into two rtx's for single words,
2936 storing in *FIRST the word that comes first in memory in the target
2937 and in *SECOND the other. */
2940 split_double (value, first, second)
2942 rtx *first, *second;
2944 if (GET_CODE (value) == CONST_INT)
2946 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
2948 /* In this case the CONST_INT holds both target words.
2949 Extract the bits from it into two word-sized pieces. */
2951 HOST_WIDE_INT word_mask;
2952 /* Avoid warnings for shift count >= BITS_PER_WORD. */
2953 int shift_count = BITS_PER_WORD - 1;
2955 word_mask = (HOST_WIDE_INT) 1 << shift_count;
2956 word_mask |= word_mask - 1;
2957 low = GEN_INT (INTVAL (value) & word_mask);
2958 high = GEN_INT ((INTVAL (value) >> (shift_count + 1)) & word_mask);
2959 if (WORDS_BIG_ENDIAN)
2972 /* The rule for using CONST_INT for a wider mode
2973 is that we regard the value as signed.
2974 So sign-extend it. */
2975 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
2976 if (WORDS_BIG_ENDIAN)
2988 else if (GET_CODE (value) != CONST_DOUBLE)
2990 if (WORDS_BIG_ENDIAN)
2992 *first = const0_rtx;
2998 *second = const0_rtx;
3001 else if (GET_MODE (value) == VOIDmode
3002 /* This is the old way we did CONST_DOUBLE integers. */
3003 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3005 /* In an integer, the words are defined as most and least significant.
3006 So order them by the target's convention. */
3007 if (WORDS_BIG_ENDIAN)
3009 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3010 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3014 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3015 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3020 #ifdef REAL_ARITHMETIC
3021 REAL_VALUE_TYPE r; long l[2];
3022 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3024 /* Note, this converts the REAL_VALUE_TYPE to the target's
3025 format, splits up the floating point double and outputs
3026 exactly 32 bits of it into each of l[0] and l[1] --
3027 not necessarily BITS_PER_WORD bits. */
3028 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3030 *first = GEN_INT ((HOST_WIDE_INT) l[0]);
3031 *second = GEN_INT ((HOST_WIDE_INT) l[1]);
3033 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3034 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3035 && ! flag_pretend_float)
3039 #ifdef HOST_WORDS_BIG_ENDIAN
3046 /* Host and target agree => no need to swap. */
3047 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3048 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3052 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3053 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3055 #endif /* no REAL_ARITHMETIC */
3059 /* Return nonzero if this function has no function calls. */
3066 if (profile_flag || profile_block_flag)
3069 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3071 if (GET_CODE (insn) == CALL_INSN)
3073 if (GET_CODE (insn) == INSN
3074 && GET_CODE (PATTERN (insn)) == SEQUENCE
3075 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN)
3078 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
3080 if (GET_CODE (XEXP (insn, 0)) == CALL_INSN)
3082 if (GET_CODE (XEXP (insn, 0)) == INSN
3083 && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
3084 && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN)
3091 /* On some machines, a function with no call insns
3092 can run faster if it doesn't create its own register window.
3093 When output, the leaf function should use only the "output"
3094 registers. Ordinarily, the function would be compiled to use
3095 the "input" registers to find its arguments; it is a candidate
3096 for leaf treatment if it uses only the "input" registers.
3097 Leaf function treatment means renumbering so the function
3098 uses the "output" registers instead. */
3100 #ifdef LEAF_REGISTERS
3102 static char permitted_reg_in_leaf_functions[] = LEAF_REGISTERS;
3104 /* Return 1 if this function uses only the registers that can be
3105 safely renumbered. */
3108 only_leaf_regs_used ()
3112 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3114 if ((regs_ever_live[i] || global_regs[i])
3115 && ! permitted_reg_in_leaf_functions[i])
3121 /* Scan all instructions and renumber all registers into those
3122 available in leaf functions. */
3125 leaf_renumber_regs (first)
3130 /* Renumber only the actual patterns.
3131 The reg-notes can contain frame pointer refs,
3132 and renumbering them could crash, and should not be needed. */
3133 for (insn = first; insn; insn = NEXT_INSN (insn))
3134 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3135 leaf_renumber_regs_insn (PATTERN (insn));
3136 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
3137 if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
3138 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
3141 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
3142 available in leaf functions. */
3145 leaf_renumber_regs_insn (in_rtx)
3146 register rtx in_rtx;
3149 register char *format_ptr;
3154 /* Renumber all input-registers into output-registers.
3155 renumbered_regs would be 1 for an output-register;
3158 if (GET_CODE (in_rtx) == REG)
3162 /* Don't renumber the same reg twice. */
3166 newreg = REGNO (in_rtx);
3167 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
3168 to reach here as part of a REG_NOTE. */
3169 if (newreg >= FIRST_PSEUDO_REGISTER)
3174 newreg = LEAF_REG_REMAP (newreg);
3177 regs_ever_live[REGNO (in_rtx)] = 0;
3178 regs_ever_live[newreg] = 1;
3179 REGNO (in_rtx) = newreg;
3183 if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
3185 /* Inside a SEQUENCE, we find insns.
3186 Renumber just the patterns of these insns,
3187 just as we do for the top-level insns. */
3188 leaf_renumber_regs_insn (PATTERN (in_rtx));
3192 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
3194 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
3195 switch (*format_ptr++)
3198 leaf_renumber_regs_insn (XEXP (in_rtx, i));
3202 if (NULL != XVEC (in_rtx, i))
3204 for (j = 0; j < XVECLEN (in_rtx, i); j++)
3205 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));