({save,restore}_stack_nonlocal): Delete.
[official-gcc.git] / gcc / final.c
blob78a0a07368ba6751532cf934aa09c70c29aac115
1 /* Convert RTL to assembler code and output it, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 1994 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)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This is the final pass of the compiler.
22 It looks at the rtl code for a function and outputs assembler code.
24 Call `final_start_function' to output the assembler code for function entry,
25 `final' to output assembler code for some RTL code,
26 `final_end_function' to output assembler code for function exit.
27 If a function is compiled in several pieces, each piece is
28 output separately with `final'.
30 Some optimizations are also done at this level.
31 Move instructions that were made unnecessary by good register allocation
32 are detected and omitted from the output. (Though most of these
33 are removed by the last jump pass.)
35 Instructions to set the condition codes are omitted when it can be
36 seen that the condition codes already had the desired values.
38 In some cases it is sufficient if the inherited condition codes
39 have related values, but this may require the following insn
40 (the one that tests the condition codes) to be modified.
42 The code for the function prologue and epilogue are generated
43 directly as assembler code by the macros FUNCTION_PROLOGUE and
44 FUNCTION_EPILOGUE. Those instructions never exist as rtl. */
46 #include "config.h"
47 #ifdef __STDC__
48 #include <stdarg.h>
49 #else
50 #include <varargs.h>
51 #endif
52 #include <stdio.h>
53 #include <ctype.h>
55 #include "tree.h"
56 #include "rtl.h"
57 #include "regs.h"
58 #include "insn-config.h"
59 #include "insn-flags.h"
60 #include "insn-attr.h"
61 #include "insn-codes.h"
62 #include "recog.h"
63 #include "conditions.h"
64 #include "flags.h"
65 #include "real.h"
66 #include "hard-reg-set.h"
67 #include "defaults.h"
68 #include "output.h"
70 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist. */
71 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
72 #if defined (USG) || defined (NO_STAB_H)
73 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
74 #else
75 #include <stab.h> /* On BSD, use the system's stab.h. */
76 #endif /* not USG */
77 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
79 #ifdef XCOFF_DEBUGGING_INFO
80 #include "xcoffout.h"
81 #endif
83 /* .stabd code for line number. */
84 #ifndef N_SLINE
85 #define N_SLINE 0x44
86 #endif
88 /* .stabs code for included file name. */
89 #ifndef N_SOL
90 #define N_SOL 0x84
91 #endif
93 #ifndef INT_TYPE_SIZE
94 #define INT_TYPE_SIZE BITS_PER_WORD
95 #endif
97 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
98 null default for it to save conditionalization later. */
99 #ifndef CC_STATUS_INIT
100 #define CC_STATUS_INIT
101 #endif
103 /* How to start an assembler comment. */
104 #ifndef ASM_COMMENT_START
105 #define ASM_COMMENT_START ";#"
106 #endif
108 /* Is the given character a logical line separator for the assembler? */
109 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
110 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
111 #endif
113 /* Nonzero means this function is a leaf function, with no function calls.
114 This variable exists to be examined in FUNCTION_PROLOGUE
115 and FUNCTION_EPILOGUE. Always zero, unless set by some action. */
116 int leaf_function;
118 /* Last insn processed by final_scan_insn. */
119 static rtx debug_insn = 0;
121 /* Line number of last NOTE. */
122 static int last_linenum;
124 /* Filename of last NOTE. */
125 static char *last_filename;
127 /* Number of basic blocks seen so far;
128 used if profile_block_flag is set. */
129 static int count_basic_blocks;
131 /* Nonzero while outputting an `asm' with operands.
132 This means that inconsistencies are the user's fault, so don't abort.
133 The precise value is the insn being output, to pass to error_for_asm. */
134 static rtx this_is_asm_operands;
136 /* Number of operands of this insn, for an `asm' with operands. */
137 static int insn_noperands;
139 /* Compare optimization flag. */
141 static rtx last_ignored_compare = 0;
143 /* Flag indicating this insn is the start of a new basic block. */
145 static int new_block = 1;
147 /* All the symbol-blocks (levels of scoping) in the compilation
148 are assigned sequence numbers in order of appearance of the
149 beginnings of the symbol-blocks. Both final and dbxout do this,
150 and assume that they will both give the same number to each block.
151 Final uses these sequence numbers to generate assembler label names
152 LBBnnn and LBEnnn for the beginning and end of the symbol-block.
153 Dbxout uses the sequence numbers to generate references to the same labels
154 from the dbx debugging information.
156 Sdb records this level at the beginning of each function,
157 in order to find the current level when recursing down declarations.
158 It outputs the block beginning and endings
159 at the point in the asm file where the blocks would begin and end. */
161 int next_block_index;
163 /* Assign a unique number to each insn that is output.
164 This can be used to generate unique local labels. */
166 static int insn_counter = 0;
168 #ifdef HAVE_cc0
169 /* This variable contains machine-dependent flags (defined in tm.h)
170 set and examined by output routines
171 that describe how to interpret the condition codes properly. */
173 CC_STATUS cc_status;
175 /* During output of an insn, this contains a copy of cc_status
176 from before the insn. */
178 CC_STATUS cc_prev_status;
179 #endif
181 /* Indexed by hardware reg number, is 1 if that register is ever
182 used in the current function.
184 In life_analysis, or in stupid_life_analysis, this is set
185 up to record the hard regs used explicitly. Reload adds
186 in the hard regs used for holding pseudo regs. Final uses
187 it to generate the code in the function prologue and epilogue
188 to save and restore registers as needed. */
190 char regs_ever_live[FIRST_PSEUDO_REGISTER];
192 /* Nonzero means current function must be given a frame pointer.
193 Set in stmt.c if anything is allocated on the stack there.
194 Set in reload1.c if anything is allocated on the stack there. */
196 int frame_pointer_needed;
198 /* Assign unique numbers to labels generated for profiling. */
200 int profile_label_no;
202 /* Length so far allocated in PENDING_BLOCKS. */
204 static int max_block_depth;
206 /* Stack of sequence numbers of symbol-blocks of which we have seen the
207 beginning but not yet the end. Sequence numbers are assigned at
208 the beginning; this stack allows us to find the sequence number
209 of a block that is ending. */
211 static int *pending_blocks;
213 /* Number of elements currently in use in PENDING_BLOCKS. */
215 static int block_depth;
217 /* Nonzero if have enabled APP processing of our assembler output. */
219 static int app_on;
221 /* If we are outputting an insn sequence, this contains the sequence rtx.
222 Zero otherwise. */
224 rtx final_sequence;
226 #ifdef ASSEMBLER_DIALECT
228 /* Number of the assembler dialect to use, starting at 0. */
229 static int dialect_number;
230 #endif
232 /* Indexed by line number, nonzero if there is a note for that line. */
234 static char *line_note_exists;
236 /* Linked list to hold line numbers for each basic block. */
238 struct bb_list {
239 struct bb_list *next; /* pointer to next basic block */
240 int line_num; /* line number */
241 int file_label_num; /* LPBC<n> label # for stored filename */
242 int func_label_num; /* LPBC<n> label # for stored function name */
245 static struct bb_list *bb_head = 0; /* Head of basic block list */
246 static struct bb_list **bb_tail = &bb_head; /* Ptr to store next bb ptr */
247 static int bb_file_label_num = -1; /* Current label # for file */
248 static int bb_func_label_num = -1; /* Current label # for func */
250 /* Linked list to hold the strings for each file and function name output. */
252 struct bb_str {
253 struct bb_str *next; /* pointer to next string */
254 char *string; /* string */
255 int label_num; /* label number */
256 int length; /* string length */
259 extern rtx peephole PROTO((rtx));
261 static struct bb_str *sbb_head = 0; /* Head of string list. */
262 static struct bb_str **sbb_tail = &sbb_head; /* Ptr to store next bb str */
263 static int sbb_label_num = 0; /* Last label used */
265 static int asm_insn_count PROTO((rtx));
266 static void profile_function PROTO((FILE *));
267 static void profile_after_prologue PROTO((FILE *));
268 static void add_bb PROTO((FILE *));
269 static int add_bb_string PROTO((char *, int));
270 static void output_source_line PROTO((FILE *, rtx));
271 static rtx walk_alter_subreg PROTO((rtx));
272 static int alter_cond PROTO((rtx));
273 static void output_operand PROTO((rtx, int));
274 static void leaf_renumber_regs PROTO((rtx));
276 /* Initialize data in final at the beginning of a compilation. */
278 void
279 init_final (filename)
280 char *filename;
282 next_block_index = 2;
283 app_on = 0;
284 max_block_depth = 20;
285 pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
286 final_sequence = 0;
288 #ifdef ASSEMBLER_DIALECT
289 dialect_number = ASSEMBLER_DIALECT;
290 #endif
293 /* Called at end of source file,
294 to output the block-profiling table for this entire compilation. */
296 void
297 end_final (filename)
298 char *filename;
300 int i;
302 if (profile_block_flag)
304 char name[20];
305 int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
306 int size = (POINTER_SIZE / BITS_PER_UNIT) * count_basic_blocks;
307 int rounded = size;
308 struct bb_list *ptr;
309 struct bb_str *sptr;
311 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
312 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
313 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
315 data_section ();
317 /* Output the main header, of 10 words:
318 0: 1 if this file's 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. */
332 ASM_OUTPUT_ALIGN (asm_out_file, align);
334 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
335 /* zero word */
336 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
338 /* address of filename */
339 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
340 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
342 /* address of count table */
343 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
344 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
346 /* count of the # of basic blocks */
347 assemble_integer (GEN_INT (count_basic_blocks), UNITS_PER_WORD, 1);
349 /* zero word (link field) */
350 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
352 /* address of basic block start address table */
353 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
354 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
356 /* byte count for extended structure. */
357 assemble_integer (GEN_INT (10 * UNITS_PER_WORD), UNITS_PER_WORD, 1);
359 /* address of function name table */
360 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
361 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
363 /* address of line number and filename tables if debugging. */
364 if (write_symbols != NO_DEBUG)
366 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
367 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
368 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
369 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
371 else
373 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
374 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
377 /* Output the file name changing the suffix to .d for Sun tcov
378 compatibility. */
379 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
381 char *cwd = getpwd ();
382 int len = strlen (filename) + strlen (cwd) + 1;
383 char *data_file = (char *) alloca (len + 4);
385 strcpy (data_file, cwd);
386 strcat (data_file, "/");
387 strcat (data_file, filename);
388 strip_off_ending (data_file, len);
389 strcat (data_file, ".d");
390 assemble_string (data_file, strlen (data_file) + 1);
393 /* Make space for the table of counts. */
394 if (flag_no_common || size == 0)
396 /* Realign data section. */
397 ASM_OUTPUT_ALIGN (asm_out_file, align);
398 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
399 if (size != 0)
400 assemble_zeros (size);
402 else
404 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
405 #ifdef ASM_OUTPUT_SHARED_LOCAL
406 if (flag_shared_data)
407 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
408 else
409 #endif
410 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
411 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
412 BIGGEST_ALIGNMENT);
413 #else
414 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
415 #endif
418 /* Output any basic block strings */
419 readonly_data_section ();
420 if (sbb_head)
422 ASM_OUTPUT_ALIGN (asm_out_file, align);
423 for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
425 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC", sptr->label_num);
426 assemble_string (sptr->string, sptr->length);
430 /* Output the table of addresses. */
431 /* Realign in new section */
432 ASM_OUTPUT_ALIGN (asm_out_file, align);
433 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
434 for (i = 0; i < count_basic_blocks; i++)
436 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
437 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
438 UNITS_PER_WORD, 1);
441 /* Output the table of function names. */
442 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
443 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
445 if (ptr->func_label_num >= 0)
447 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->func_label_num);
448 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
449 UNITS_PER_WORD, 1);
451 else
452 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
455 for ( ; i < count_basic_blocks; i++)
456 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
458 if (write_symbols != NO_DEBUG)
460 /* Output the table of line numbers. */
461 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
462 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
463 assemble_integer (GEN_INT (ptr->line_num), UNITS_PER_WORD, 1);
465 for ( ; i < count_basic_blocks; i++)
466 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
468 /* Output the table of file names. */
469 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
470 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
472 if (ptr->file_label_num >= 0)
474 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->file_label_num);
475 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
476 UNITS_PER_WORD, 1);
478 else
479 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
482 for ( ; i < count_basic_blocks; i++)
483 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
486 /* End with the address of the table of addresses,
487 so we can find it easily, as the last word in the file's text. */
488 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
489 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
493 /* Enable APP processing of subsequent output.
494 Used before the output from an `asm' statement. */
496 void
497 app_enable ()
499 if (! app_on)
501 fprintf (asm_out_file, ASM_APP_ON);
502 app_on = 1;
506 /* Disable APP processing of subsequent output.
507 Called from varasm.c before most kinds of output. */
509 void
510 app_disable ()
512 if (app_on)
514 fprintf (asm_out_file, ASM_APP_OFF);
515 app_on = 0;
519 /* Return the number of slots filled in the current
520 delayed branch sequence (we don't count the insn needing the
521 delay slot). Zero if not in a delayed branch sequence. */
523 #ifdef DELAY_SLOTS
525 dbr_sequence_length ()
527 if (final_sequence != 0)
528 return XVECLEN (final_sequence, 0) - 1;
529 else
530 return 0;
532 #endif
534 /* The next two pages contain routines used to compute the length of an insn
535 and to shorten branches. */
537 /* Arrays for insn lengths, and addresses. The latter is referenced by
538 `insn_current_length'. */
540 static short *insn_lengths;
541 int *insn_addresses;
543 /* Address of insn being processed. Used by `insn_current_length'. */
544 int insn_current_address;
546 /* Indicate that branch shortening hasn't yet been done. */
548 void
549 init_insn_lengths ()
551 insn_lengths = 0;
554 /* Obtain the current length of an insn. If branch shortening has been done,
555 get its actual length. Otherwise, get its maximum length. */
558 get_attr_length (insn)
559 rtx insn;
561 #ifdef HAVE_ATTR_length
562 rtx body;
563 int i;
564 int length = 0;
566 if (insn_lengths)
567 return insn_lengths[INSN_UID (insn)];
568 else
569 switch (GET_CODE (insn))
571 case NOTE:
572 case BARRIER:
573 case CODE_LABEL:
574 return 0;
576 case CALL_INSN:
577 length = insn_default_length (insn);
578 break;
580 case JUMP_INSN:
581 body = PATTERN (insn);
582 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
584 /* This only takes room if jump tables go into the text section. */
585 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
586 length = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
587 * GET_MODE_SIZE (GET_MODE (body)));
589 /* Be pessimistic and assume worst-case alignment. */
590 length += (GET_MODE_SIZE (GET_MODE (body)) - 1);
591 #else
592 return 0;
593 #endif
595 else
596 length = insn_default_length (insn);
597 break;
599 case INSN:
600 body = PATTERN (insn);
601 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
602 return 0;
604 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
605 length = asm_insn_count (body) * insn_default_length (insn);
606 else if (GET_CODE (body) == SEQUENCE)
607 for (i = 0; i < XVECLEN (body, 0); i++)
608 length += get_attr_length (XVECEXP (body, 0, i));
609 else
610 length = insn_default_length (insn);
613 #ifdef ADJUST_INSN_LENGTH
614 ADJUST_INSN_LENGTH (insn, length);
615 #endif
616 return length;
617 #else /* not HAVE_ATTR_length */
618 return 0;
619 #endif /* not HAVE_ATTR_length */
622 /* Make a pass over all insns and compute their actual lengths by shortening
623 any branches of variable length if possible. */
625 /* Give a default value for the lowest address in a function. */
627 #ifndef FIRST_INSN_ADDRESS
628 #define FIRST_INSN_ADDRESS 0
629 #endif
631 void
632 shorten_branches (first)
633 rtx first;
635 #ifdef HAVE_ATTR_length
636 rtx insn;
637 int something_changed = 1;
638 int max_uid = 0;
639 char *varying_length;
640 rtx body;
641 int uid;
643 /* Compute maximum UID and allocate arrays. */
644 for (insn = first; insn; insn = NEXT_INSN (insn))
645 if (INSN_UID (insn) > max_uid)
646 max_uid = INSN_UID (insn);
648 max_uid++;
649 insn_lengths = (short *) oballoc (max_uid * sizeof (short));
650 insn_addresses = (int *) oballoc (max_uid * sizeof (int));
651 varying_length = (char *) oballoc (max_uid * sizeof (char));
653 /* Compute initial lengths, addresses, and varying flags for each insn. */
654 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
655 insn != 0;
656 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
658 uid = INSN_UID (insn);
659 insn_addresses[uid] = insn_current_address;
660 insn_lengths[uid] = 0;
661 varying_length[uid] = 0;
663 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
664 || GET_CODE (insn) == CODE_LABEL)
665 continue;
667 body = PATTERN (insn);
668 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
670 /* This only takes room if read-only data goes into the text
671 section. */
672 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
673 int unitsize = GET_MODE_SIZE (GET_MODE (body));
675 insn_lengths[uid] = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
676 * GET_MODE_SIZE (GET_MODE (body)));
678 /* Account for possible alignment. */
679 insn_lengths[uid]
680 += unitsize - (insn_current_address & (unitsize - 1));
681 #else
683 #endif
685 else if (asm_noperands (body) >= 0)
686 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
687 else if (GET_CODE (body) == SEQUENCE)
689 int i;
690 int const_delay_slots;
691 #ifdef DELAY_SLOTS
692 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
693 #else
694 const_delay_slots = 0;
695 #endif
696 /* Inside a delay slot sequence, we do not do any branch shortening
697 if the shortening could change the number of delay slots
698 of the branch. */
699 for (i = 0; i < XVECLEN (body, 0); i++)
701 rtx inner_insn = XVECEXP (body, 0, i);
702 int inner_uid = INSN_UID (inner_insn);
703 int inner_length;
705 if (asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
706 inner_length = (asm_insn_count (PATTERN (inner_insn))
707 * insn_default_length (inner_insn));
708 else
709 inner_length = insn_default_length (inner_insn);
711 insn_lengths[inner_uid] = inner_length;
712 if (const_delay_slots)
714 if ((varying_length[inner_uid]
715 = insn_variable_length_p (inner_insn)) != 0)
716 varying_length[uid] = 1;
717 insn_addresses[inner_uid] = (insn_current_address +
718 insn_lengths[uid]);
720 else
721 varying_length[inner_uid] = 0;
722 insn_lengths[uid] += inner_length;
725 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
727 insn_lengths[uid] = insn_default_length (insn);
728 varying_length[uid] = insn_variable_length_p (insn);
731 /* If needed, do any adjustment. */
732 #ifdef ADJUST_INSN_LENGTH
733 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
734 #endif
737 /* Now loop over all the insns finding varying length insns. For each,
738 get the current insn length. If it has changed, reflect the change.
739 When nothing changes for a full pass, we are done. */
741 while (something_changed)
743 something_changed = 0;
744 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
745 insn != 0;
746 insn = NEXT_INSN (insn))
748 int new_length;
749 int tmp_length;
751 uid = INSN_UID (insn);
752 insn_addresses[uid] = insn_current_address;
753 if (! varying_length[uid])
755 insn_current_address += insn_lengths[uid];
756 continue;
758 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
760 int i;
762 body = PATTERN (insn);
763 new_length = 0;
764 for (i = 0; i < XVECLEN (body, 0); i++)
766 rtx inner_insn = XVECEXP (body, 0, i);
767 int inner_uid = INSN_UID (inner_insn);
768 int inner_length;
770 insn_addresses[inner_uid] = insn_current_address;
772 /* insn_current_length returns 0 for insns with a
773 non-varying length. */
774 if (! varying_length[inner_uid])
775 inner_length = insn_lengths[inner_uid];
776 else
777 inner_length = insn_current_length (inner_insn);
779 if (inner_length != insn_lengths[inner_uid])
781 insn_lengths[inner_uid] = inner_length;
782 something_changed = 1;
784 insn_current_address += insn_lengths[inner_uid];
785 new_length += inner_length;
788 else
790 new_length = insn_current_length (insn);
791 insn_current_address += new_length;
794 #ifdef SHORTEN_WITH_ADJUST_INSN_LENGTH
795 #ifdef ADJUST_INSN_LENGTH
796 /* If needed, do any adjustment. */
797 tmp_length = new_length;
798 ADJUST_INSN_LENGTH (insn, new_length);
799 insn_current_address += (new_length - tmp_length);
800 #endif
801 #endif
803 if (new_length != insn_lengths[uid])
805 insn_lengths[uid] = new_length;
806 something_changed = 1;
810 #endif /* HAVE_ATTR_length */
813 #ifdef HAVE_ATTR_length
814 /* Given the body of an INSN known to be generated by an ASM statement, return
815 the number of machine instructions likely to be generated for this insn.
816 This is used to compute its length. */
818 static int
819 asm_insn_count (body)
820 rtx body;
822 char *template;
823 int count = 1;
825 for (template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
826 NULL_PTR, NULL_PTR);
827 *template; template++)
828 if (IS_ASM_LOGICAL_LINE_SEPARATOR(*template) || *template == '\n')
829 count++;
831 return count;
833 #endif
835 /* Output assembler code for the start of a function,
836 and initialize some of the variables in this file
837 for the new function. The label for the function and associated
838 assembler pseudo-ops have already been output in `assemble_start_function'.
840 FIRST is the first insn of the rtl for the function being compiled.
841 FILE is the file to write assembler code to.
842 OPTIMIZE is nonzero if we should eliminate redundant
843 test and compare insns. */
845 void
846 final_start_function (first, file, optimize)
847 rtx first;
848 FILE *file;
849 int optimize;
851 block_depth = 0;
853 this_is_asm_operands = 0;
855 #ifdef NON_SAVING_SETJMP
856 /* A function that calls setjmp should save and restore all the
857 call-saved registers on a system where longjmp clobbers them. */
858 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
860 int i;
862 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
863 if (!call_used_regs[i] && !call_fixed_regs[i])
864 regs_ever_live[i] = 1;
866 #endif
868 /* Initial line number is supposed to be output
869 before the function's prologue and label
870 so that the function's address will not appear to be
871 in the last statement of the preceding function. */
872 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
874 if (write_symbols == SDB_DEBUG)
875 /* For sdb, let's not, but say we did.
876 We need to set last_linenum for sdbout_function_begin,
877 but we can't have an actual line number before the .bf symbol.
878 (sdb_begin_function_line is not set,
879 and other compilers don't do it.) */
880 last_linenum = NOTE_LINE_NUMBER (first);
881 #ifdef XCOFF_DEBUGGING_INFO
882 else if (write_symbols == XCOFF_DEBUG)
884 last_linenum = NOTE_LINE_NUMBER (first);
885 xcoffout_output_first_source_line (file, last_linenum);
887 #endif
888 else
889 output_source_line (file, first);
892 #ifdef LEAF_REG_REMAP
893 if (leaf_function)
894 leaf_renumber_regs (first);
895 #endif
897 /* The Sun386i and perhaps other machines don't work right
898 if the profiling code comes after the prologue. */
899 #ifdef PROFILE_BEFORE_PROLOGUE
900 if (profile_flag)
901 profile_function (file);
902 #endif /* PROFILE_BEFORE_PROLOGUE */
904 #ifdef FUNCTION_PROLOGUE
905 /* First output the function prologue: code to set up the stack frame. */
906 FUNCTION_PROLOGUE (file, get_frame_size ());
907 #endif
909 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
910 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
911 next_block_index = 1;
912 #endif
914 /* If the machine represents the prologue as RTL, the profiling code must
915 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
916 #ifdef HAVE_prologue
917 if (! HAVE_prologue)
918 #endif
919 profile_after_prologue (file);
921 profile_label_no++;
923 /* If we are doing basic block profiling, remember a printable version
924 of the function name. */
925 if (profile_block_flag)
927 char *junk = "function";
928 bb_func_label_num =
929 add_bb_string ((*decl_printable_name) (current_function_decl, &junk), FALSE);
933 static void
934 profile_after_prologue (file)
935 FILE *file;
937 #ifdef FUNCTION_BLOCK_PROFILER
938 if (profile_block_flag)
940 FUNCTION_BLOCK_PROFILER (file, profile_label_no);
942 #endif /* FUNCTION_BLOCK_PROFILER */
944 #ifndef PROFILE_BEFORE_PROLOGUE
945 if (profile_flag)
946 profile_function (file);
947 #endif /* not PROFILE_BEFORE_PROLOGUE */
950 static void
951 profile_function (file)
952 FILE *file;
954 int align = MIN (BIGGEST_ALIGNMENT, POINTER_SIZE);
955 int sval = current_function_returns_struct;
956 int cxt = current_function_needs_context;
958 data_section ();
959 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
960 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
961 assemble_integer (const0_rtx, POINTER_SIZE / BITS_PER_UNIT, 1);
963 text_section ();
965 #ifdef STRUCT_VALUE_INCOMING_REGNUM
966 if (sval)
967 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
968 #else
969 #ifdef STRUCT_VALUE_REGNUM
970 if (sval)
971 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
972 #endif
973 #endif
975 #if 0
976 #ifdef STATIC_CHAIN_INCOMING_REGNUM
977 if (cxt)
978 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
979 #else
980 #ifdef STATIC_CHAIN_REGNUM
981 if (cxt)
982 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
983 #endif
984 #endif
985 #endif /* 0 */
987 FUNCTION_PROFILER (file, profile_label_no);
989 #if 0
990 #ifdef STATIC_CHAIN_INCOMING_REGNUM
991 if (cxt)
992 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
993 #else
994 #ifdef STATIC_CHAIN_REGNUM
995 if (cxt)
996 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
997 #endif
998 #endif
999 #endif /* 0 */
1001 #ifdef STRUCT_VALUE_INCOMING_REGNUM
1002 if (sval)
1003 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1004 #else
1005 #ifdef STRUCT_VALUE_REGNUM
1006 if (sval)
1007 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1008 #endif
1009 #endif
1012 /* Output assembler code for the end of a function.
1013 For clarity, args are same as those of `final_start_function'
1014 even though not all of them are needed. */
1016 void
1017 final_end_function (first, file, optimize)
1018 rtx first;
1019 FILE *file;
1020 int optimize;
1022 if (app_on)
1024 fprintf (file, ASM_APP_OFF);
1025 app_on = 0;
1028 #ifdef SDB_DEBUGGING_INFO
1029 if (write_symbols == SDB_DEBUG)
1030 sdbout_end_function (last_linenum);
1031 #endif
1033 #ifdef DWARF_DEBUGGING_INFO
1034 if (write_symbols == DWARF_DEBUG)
1035 dwarfout_end_function ();
1036 #endif
1038 #ifdef XCOFF_DEBUGGING_INFO
1039 if (write_symbols == XCOFF_DEBUG)
1040 xcoffout_end_function (file, last_linenum);
1041 #endif
1043 #ifdef FUNCTION_EPILOGUE
1044 /* Finally, output the function epilogue:
1045 code to restore the stack frame and return to the caller. */
1046 FUNCTION_EPILOGUE (file, get_frame_size ());
1047 #endif
1049 #ifdef SDB_DEBUGGING_INFO
1050 if (write_symbols == SDB_DEBUG)
1051 sdbout_end_epilogue ();
1052 #endif
1054 #ifdef DWARF_DEBUGGING_INFO
1055 if (write_symbols == DWARF_DEBUG)
1056 dwarfout_end_epilogue ();
1057 #endif
1059 #ifdef XCOFF_DEBUGGING_INFO
1060 if (write_symbols == XCOFF_DEBUG)
1061 xcoffout_end_epilogue (file);
1062 #endif
1064 bb_func_label_num = -1; /* not in function, nuke label # */
1066 /* If FUNCTION_EPILOGUE is not defined, then the function body
1067 itself contains return instructions wherever needed. */
1070 /* Add a block to the linked list that remembers the current line/file/function
1071 for basic block profiling. Emit the label in front of the basic block and
1072 the instructions that increment the count field. */
1074 static void
1075 add_bb (file)
1076 FILE *file;
1078 struct bb_list *ptr = (struct bb_list *) permalloc (sizeof (struct bb_list));
1080 /* Add basic block to linked list. */
1081 ptr->next = 0;
1082 ptr->line_num = last_linenum;
1083 ptr->file_label_num = bb_file_label_num;
1084 ptr->func_label_num = bb_func_label_num;
1085 *bb_tail = ptr;
1086 bb_tail = &ptr->next;
1088 /* Enable the table of basic-block use counts
1089 to point at the code it applies to. */
1090 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1092 /* Before first insn of this basic block, increment the
1093 count of times it was entered. */
1094 #ifdef BLOCK_PROFILER
1095 BLOCK_PROFILER (file, count_basic_blocks);
1096 CC_STATUS_INIT;
1097 #endif
1099 new_block = 0;
1100 count_basic_blocks++;
1103 /* Add a string to be used for basic block profiling. */
1105 static int
1106 add_bb_string (string, perm_p)
1107 char *string;
1108 int perm_p;
1110 int len;
1111 struct bb_str *ptr = 0;
1113 if (!string)
1115 string = "<unknown>";
1116 perm_p = TRUE;
1119 /* Allocate a new string if the current string isn't permanent. If
1120 the string is permanent search for the same string in other
1121 allocations. */
1123 len = strlen (string) + 1;
1124 if (!perm_p)
1126 char *p = (char *) permalloc (len);
1127 bcopy (string, p, len);
1128 string = p;
1130 else
1131 for (ptr = sbb_head; ptr != (struct bb_str *)0; ptr = ptr->next)
1132 if (ptr->string == string)
1133 break;
1135 /* Allocate a new string block if we need to. */
1136 if (!ptr)
1138 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1139 ptr->next = 0;
1140 ptr->length = len;
1141 ptr->label_num = sbb_label_num++;
1142 ptr->string = string;
1143 *sbb_tail = ptr;
1144 sbb_tail = &ptr->next;
1147 return ptr->label_num;
1151 /* Output assembler code for some insns: all or part of a function.
1152 For description of args, see `final_start_function', above.
1154 PRESCAN is 1 if we are not really outputting,
1155 just scanning as if we were outputting.
1156 Prescanning deletes and rearranges insns just like ordinary output.
1157 PRESCAN is -2 if we are outputting after having prescanned.
1158 In this case, don't try to delete or rearrange insns
1159 because that has already been done.
1160 Prescanning is done only on certain machines. */
1162 void
1163 final (first, file, optimize, prescan)
1164 rtx first;
1165 FILE *file;
1166 int optimize;
1167 int prescan;
1169 register rtx insn;
1170 int max_line = 0;
1172 last_ignored_compare = 0;
1173 new_block = 1;
1175 /* Make a map indicating which line numbers appear in this function.
1176 When producing SDB debugging info, delete troublesome line number
1177 notes from inlined functions in other files as well as duplicate
1178 line number notes. */
1179 #ifdef SDB_DEBUGGING_INFO
1180 if (write_symbols == SDB_DEBUG)
1182 rtx last = 0;
1183 for (insn = first; insn; insn = NEXT_INSN (insn))
1184 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1186 if ((RTX_INTEGRATED_P (insn)
1187 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1188 || (last != 0
1189 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1190 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1192 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1193 NOTE_SOURCE_FILE (insn) = 0;
1194 continue;
1196 last = insn;
1197 if (NOTE_LINE_NUMBER (insn) > max_line)
1198 max_line = NOTE_LINE_NUMBER (insn);
1201 else
1202 #endif
1204 for (insn = first; insn; insn = NEXT_INSN (insn))
1205 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1206 max_line = NOTE_LINE_NUMBER (insn);
1209 line_note_exists = (char *) oballoc (max_line + 1);
1210 bzero (line_note_exists, max_line + 1);
1212 for (insn = first; insn; insn = NEXT_INSN (insn))
1213 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1214 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1216 init_recog ();
1218 CC_STATUS_INIT;
1220 /* Output the insns. */
1221 for (insn = NEXT_INSN (first); insn;)
1222 insn = final_scan_insn (insn, file, optimize, prescan, 0);
1224 /* Do basic-block profiling here
1225 if the last insn was a conditional branch. */
1226 if (profile_block_flag && new_block)
1227 add_bb (file);
1230 /* The final scan for one insn, INSN.
1231 Args are same as in `final', except that INSN
1232 is the insn being scanned.
1233 Value returned is the next insn to be scanned.
1235 NOPEEPHOLES is the flag to disallow peephole processing (currently
1236 used for within delayed branch sequence output). */
1239 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
1240 rtx insn;
1241 FILE *file;
1242 int optimize;
1243 int prescan;
1244 int nopeepholes;
1246 register int i;
1247 insn_counter++;
1249 /* Ignore deleted insns. These can occur when we split insns (due to a
1250 template of "#") while not optimizing. */
1251 if (INSN_DELETED_P (insn))
1252 return NEXT_INSN (insn);
1254 switch (GET_CODE (insn))
1256 case NOTE:
1257 if (prescan > 0)
1258 break;
1260 /* Align the beginning of a loop, for higher speed
1261 on certain machines. */
1263 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG && optimize > 0)
1265 #ifdef ASM_OUTPUT_LOOP_ALIGN
1266 rtx next = next_nonnote_insn (insn);
1267 if (next && GET_CODE (next) == CODE_LABEL)
1269 ASM_OUTPUT_LOOP_ALIGN (asm_out_file);
1271 #endif
1272 break;
1274 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
1275 break;
1277 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
1279 #ifdef FUNCTION_END_PROLOGUE
1280 FUNCTION_END_PROLOGUE (file);
1281 #endif
1282 profile_after_prologue (file);
1283 break;
1286 #ifdef FUNCTION_BEGIN_EPILOGUE
1287 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
1289 FUNCTION_BEGIN_EPILOGUE (file);
1290 break;
1292 #endif
1294 if (write_symbols == NO_DEBUG)
1295 break;
1296 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
1298 #ifdef SDB_DEBUGGING_INFO
1299 if (write_symbols == SDB_DEBUG)
1300 sdbout_begin_function (last_linenum);
1301 #endif
1302 #ifdef XCOFF_DEBUGGING_INFO
1303 if (write_symbols == XCOFF_DEBUG)
1304 xcoffout_begin_function (file, last_linenum);
1305 #endif
1306 #ifdef DWARF_DEBUGGING_INFO
1307 if (write_symbols == DWARF_DEBUG)
1308 dwarfout_begin_function ();
1309 #endif
1310 break;
1312 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
1313 break; /* An insn that was "deleted" */
1314 if (app_on)
1316 fprintf (file, ASM_APP_OFF);
1317 app_on = 0;
1319 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
1320 && (debug_info_level == DINFO_LEVEL_NORMAL
1321 || debug_info_level == DINFO_LEVEL_VERBOSE
1322 #ifdef DWARF_DEBUGGING_INFO
1323 || write_symbols == DWARF_DEBUG
1324 #endif
1328 /* Beginning of a symbol-block. Assign it a sequence number
1329 and push the number onto the stack PENDING_BLOCKS. */
1331 if (block_depth == max_block_depth)
1333 /* PENDING_BLOCKS is full; make it longer. */
1334 max_block_depth *= 2;
1335 pending_blocks
1336 = (int *) xrealloc (pending_blocks,
1337 max_block_depth * sizeof (int));
1339 pending_blocks[block_depth++] = next_block_index;
1341 /* Output debugging info about the symbol-block beginning. */
1343 #ifdef SDB_DEBUGGING_INFO
1344 if (write_symbols == SDB_DEBUG)
1345 sdbout_begin_block (file, last_linenum, next_block_index);
1346 #endif
1347 #ifdef XCOFF_DEBUGGING_INFO
1348 if (write_symbols == XCOFF_DEBUG)
1349 xcoffout_begin_block (file, last_linenum, next_block_index);
1350 #endif
1351 #ifdef DBX_DEBUGGING_INFO
1352 if (write_symbols == DBX_DEBUG)
1353 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
1354 #endif
1355 #ifdef DWARF_DEBUGGING_INFO
1356 if (write_symbols == DWARF_DEBUG && block_depth > 1)
1357 dwarfout_begin_block (next_block_index);
1358 #endif
1360 next_block_index++;
1362 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
1363 && (debug_info_level == DINFO_LEVEL_NORMAL
1364 || debug_info_level == DINFO_LEVEL_VERBOSE
1365 #ifdef DWARF_DEBUGGING_INFO
1366 || write_symbols == DWARF_DEBUG
1367 #endif
1371 /* End of a symbol-block. Pop its sequence number off
1372 PENDING_BLOCKS and output debugging info based on that. */
1374 --block_depth;
1376 #ifdef XCOFF_DEBUGGING_INFO
1377 if (write_symbols == XCOFF_DEBUG && block_depth >= 0)
1378 xcoffout_end_block (file, last_linenum, pending_blocks[block_depth]);
1379 #endif
1380 #ifdef DBX_DEBUGGING_INFO
1381 if (write_symbols == DBX_DEBUG && block_depth >= 0)
1382 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
1383 pending_blocks[block_depth]);
1384 #endif
1385 #ifdef SDB_DEBUGGING_INFO
1386 if (write_symbols == SDB_DEBUG && block_depth >= 0)
1387 sdbout_end_block (file, last_linenum, pending_blocks[block_depth]);
1388 #endif
1389 #ifdef DWARF_DEBUGGING_INFO
1390 if (write_symbols == DWARF_DEBUG && block_depth >= 1)
1391 dwarfout_end_block (pending_blocks[block_depth]);
1392 #endif
1394 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
1395 && (debug_info_level == DINFO_LEVEL_NORMAL
1396 || debug_info_level == DINFO_LEVEL_VERBOSE))
1398 #ifdef DWARF_DEBUGGING_INFO
1399 if (write_symbols == DWARF_DEBUG)
1400 dwarfout_label (insn);
1401 #endif
1403 else if (NOTE_LINE_NUMBER (insn) > 0)
1404 /* This note is a line-number. */
1406 register rtx note;
1408 #if 0 /* This is what we used to do. */
1409 output_source_line (file, insn);
1410 #endif
1411 int note_after = 0;
1413 /* If there is anything real after this note,
1414 output it. If another line note follows, omit this one. */
1415 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
1417 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
1418 break;
1419 /* These types of notes can be significant
1420 so make sure the preceding line number stays. */
1421 else if (GET_CODE (note) == NOTE
1422 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
1423 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
1424 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
1425 break;
1426 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
1428 /* Another line note follows; we can delete this note
1429 if no intervening line numbers have notes elsewhere. */
1430 int num;
1431 for (num = NOTE_LINE_NUMBER (insn) + 1;
1432 num < NOTE_LINE_NUMBER (note);
1433 num++)
1434 if (line_note_exists[num])
1435 break;
1437 if (num >= NOTE_LINE_NUMBER (note))
1438 note_after = 1;
1439 break;
1443 /* Output this line note
1444 if it is the first or the last line note in a row. */
1445 if (!note_after)
1446 output_source_line (file, insn);
1448 break;
1450 case BARRIER:
1451 #ifdef ASM_OUTPUT_ALIGN_CODE
1452 /* Don't litter the assembler output with needless alignments. A
1453 BARRIER will be placed at the end of every function if HAVE_epilogue
1454 is true. */
1455 if (NEXT_INSN (insn))
1456 ASM_OUTPUT_ALIGN_CODE (file);
1457 #endif
1458 break;
1460 case CODE_LABEL:
1461 CC_STATUS_INIT;
1462 if (prescan > 0)
1463 break;
1464 new_block = 1;
1465 #ifdef SDB_DEBUGGING_INFO
1466 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
1467 sdbout_label (insn);
1468 #endif
1469 #ifdef DWARF_DEBUGGING_INFO
1470 if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
1471 dwarfout_label (insn);
1472 #endif
1473 if (app_on)
1475 fprintf (file, ASM_APP_OFF);
1476 app_on = 0;
1478 if (NEXT_INSN (insn) != 0
1479 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
1481 rtx nextbody = PATTERN (NEXT_INSN (insn));
1483 /* If this label is followed by a jump-table,
1484 make sure we put the label in the read-only section. Also
1485 possibly write the label and jump table together. */
1487 if (GET_CODE (nextbody) == ADDR_VEC
1488 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1490 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1491 readonly_data_section ();
1492 #ifdef READONLY_DATA_SECTION
1493 ASM_OUTPUT_ALIGN (file,
1494 exact_log2 (BIGGEST_ALIGNMENT
1495 / BITS_PER_UNIT));
1496 #endif /* READONLY_DATA_SECTION */
1497 #else /* JUMP_TABLES_IN_TEXT_SECTION */
1498 text_section ();
1499 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
1500 #ifdef ASM_OUTPUT_CASE_LABEL
1501 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
1502 NEXT_INSN (insn));
1503 #else
1504 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1505 #endif
1506 break;
1510 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1511 break;
1513 default:
1515 register rtx body = PATTERN (insn);
1516 int insn_code_number;
1517 char *template;
1518 rtx note;
1520 /* An INSN, JUMP_INSN or CALL_INSN.
1521 First check for special kinds that recog doesn't recognize. */
1523 if (GET_CODE (body) == USE /* These are just declarations */
1524 || GET_CODE (body) == CLOBBER)
1525 break;
1527 #ifdef HAVE_cc0
1528 /* If there is a REG_CC_SETTER note on this insn, it means that
1529 the setting of the condition code was done in the delay slot
1530 of the insn that branched here. So recover the cc status
1531 from the insn that set it. */
1533 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1534 if (note)
1536 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
1537 cc_prev_status = cc_status;
1539 #endif
1541 /* Detect insns that are really jump-tables
1542 and output them as such. */
1544 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1546 register int vlen, idx;
1548 if (prescan > 0)
1549 break;
1551 if (app_on)
1553 fprintf (file, ASM_APP_OFF);
1554 app_on = 0;
1557 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
1558 for (idx = 0; idx < vlen; idx++)
1560 if (GET_CODE (body) == ADDR_VEC)
1562 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
1563 ASM_OUTPUT_ADDR_VEC_ELT
1564 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
1565 #else
1566 abort ();
1567 #endif
1569 else
1571 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
1572 ASM_OUTPUT_ADDR_DIFF_ELT
1573 (file,
1574 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
1575 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
1576 #else
1577 abort ();
1578 #endif
1581 #ifdef ASM_OUTPUT_CASE_END
1582 ASM_OUTPUT_CASE_END (file,
1583 CODE_LABEL_NUMBER (PREV_INSN (insn)),
1584 insn);
1585 #endif
1587 text_section ();
1589 break;
1592 /* Do basic-block profiling when we reach a new block.
1593 Done here to avoid jump tables. */
1594 if (profile_block_flag && new_block)
1595 add_bb (file);
1597 if (GET_CODE (body) == ASM_INPUT)
1599 /* There's no telling what that did to the condition codes. */
1600 CC_STATUS_INIT;
1601 if (prescan > 0)
1602 break;
1603 if (! app_on)
1605 fprintf (file, ASM_APP_ON);
1606 app_on = 1;
1608 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
1609 break;
1612 /* Detect `asm' construct with operands. */
1613 if (asm_noperands (body) >= 0)
1615 int noperands = asm_noperands (body);
1616 rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
1617 char *string;
1619 /* There's no telling what that did to the condition codes. */
1620 CC_STATUS_INIT;
1621 if (prescan > 0)
1622 break;
1624 if (! app_on)
1626 fprintf (file, ASM_APP_ON);
1627 app_on = 1;
1630 /* Get out the operand values. */
1631 string = decode_asm_operands (body, ops, NULL_PTR,
1632 NULL_PTR, NULL_PTR);
1633 /* Inhibit aborts on what would otherwise be compiler bugs. */
1634 insn_noperands = noperands;
1635 this_is_asm_operands = insn;
1637 /* Output the insn using them. */
1638 output_asm_insn (string, ops);
1639 this_is_asm_operands = 0;
1640 break;
1643 if (prescan <= 0 && app_on)
1645 fprintf (file, ASM_APP_OFF);
1646 app_on = 0;
1649 if (GET_CODE (body) == SEQUENCE)
1651 /* A delayed-branch sequence */
1652 register int i;
1653 rtx next;
1655 if (prescan > 0)
1656 break;
1657 final_sequence = body;
1659 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
1660 force the restoration of a comparison that was previously
1661 thought unnecessary. If that happens, cancel this sequence
1662 and cause that insn to be restored. */
1664 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
1665 if (next != XVECEXP (body, 0, 1))
1667 final_sequence = 0;
1668 return next;
1671 for (i = 1; i < XVECLEN (body, 0); i++)
1672 final_scan_insn (XVECEXP (body, 0, i), file, 0, prescan, 1);
1673 #ifdef DBR_OUTPUT_SEQEND
1674 DBR_OUTPUT_SEQEND (file);
1675 #endif
1676 final_sequence = 0;
1678 /* If the insn requiring the delay slot was a CALL_INSN, the
1679 insns in the delay slot are actually executed before the
1680 called function. Hence we don't preserve any CC-setting
1681 actions in these insns and the CC must be marked as being
1682 clobbered by the function. */
1683 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
1684 CC_STATUS_INIT;
1686 /* Following a conditional branch sequence, we have a new basic
1687 block. */
1688 if (profile_block_flag)
1690 rtx insn = XVECEXP (body, 0, 0);
1691 rtx body = PATTERN (insn);
1693 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1694 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1695 || (GET_CODE (insn) == JUMP_INSN
1696 && GET_CODE (body) == PARALLEL
1697 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1698 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
1699 new_block = 1;
1701 break;
1704 /* We have a real machine instruction as rtl. */
1706 body = PATTERN (insn);
1708 #ifdef HAVE_cc0
1709 /* Check for redundant test and compare instructions
1710 (when the condition codes are already set up as desired).
1711 This is done only when optimizing; if not optimizing,
1712 it should be possible for the user to alter a variable
1713 with the debugger in between statements
1714 and the next statement should reexamine the variable
1715 to compute the condition codes. */
1717 if (optimize
1718 && GET_CODE (body) == SET
1719 && GET_CODE (SET_DEST (body)) == CC0
1720 && insn != last_ignored_compare)
1722 if (GET_CODE (SET_SRC (body)) == SUBREG)
1723 SET_SRC (body) = alter_subreg (SET_SRC (body));
1724 else if (GET_CODE (SET_SRC (body)) == COMPARE)
1726 if (GET_CODE (XEXP (SET_SRC (body), 0)) == SUBREG)
1727 XEXP (SET_SRC (body), 0)
1728 = alter_subreg (XEXP (SET_SRC (body), 0));
1729 if (GET_CODE (XEXP (SET_SRC (body), 1)) == SUBREG)
1730 XEXP (SET_SRC (body), 1)
1731 = alter_subreg (XEXP (SET_SRC (body), 1));
1733 if ((cc_status.value1 != 0
1734 && rtx_equal_p (SET_SRC (body), cc_status.value1))
1735 || (cc_status.value2 != 0
1736 && rtx_equal_p (SET_SRC (body), cc_status.value2)))
1738 /* Don't delete insn if it has an addressing side-effect. */
1739 if (! FIND_REG_INC_NOTE (insn, 0)
1740 /* or if anything in it is volatile. */
1741 && ! volatile_refs_p (PATTERN (insn)))
1743 /* We don't really delete the insn; just ignore it. */
1744 last_ignored_compare = insn;
1745 break;
1749 #endif
1751 /* Following a conditional branch, we have a new basic block.
1752 But if we are inside a sequence, the new block starts after the
1753 last insn of the sequence. */
1754 if (profile_block_flag && final_sequence == 0
1755 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1756 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1757 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
1758 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1759 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
1760 new_block = 1;
1762 #ifndef STACK_REGS
1763 /* Don't bother outputting obvious no-ops, even without -O.
1764 This optimization is fast and doesn't interfere with debugging.
1765 Don't do this if the insn is in a delay slot, since this
1766 will cause an improper number of delay insns to be written. */
1767 if (final_sequence == 0
1768 && prescan >= 0
1769 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
1770 && GET_CODE (SET_SRC (body)) == REG
1771 && GET_CODE (SET_DEST (body)) == REG
1772 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
1773 break;
1774 #endif
1776 #ifdef HAVE_cc0
1777 /* If this is a conditional branch, maybe modify it
1778 if the cc's are in a nonstandard state
1779 so that it accomplishes the same thing that it would
1780 do straightforwardly if the cc's were set up normally. */
1782 if (cc_status.flags != 0
1783 && GET_CODE (insn) == JUMP_INSN
1784 && GET_CODE (body) == SET
1785 && SET_DEST (body) == pc_rtx
1786 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
1787 /* This is done during prescan; it is not done again
1788 in final scan when prescan has been done. */
1789 && prescan >= 0)
1791 /* This function may alter the contents of its argument
1792 and clear some of the cc_status.flags bits.
1793 It may also return 1 meaning condition now always true
1794 or -1 meaning condition now always false
1795 or 2 meaning condition nontrivial but altered. */
1796 register int result = alter_cond (XEXP (SET_SRC (body), 0));
1797 /* If condition now has fixed value, replace the IF_THEN_ELSE
1798 with its then-operand or its else-operand. */
1799 if (result == 1)
1800 SET_SRC (body) = XEXP (SET_SRC (body), 1);
1801 if (result == -1)
1802 SET_SRC (body) = XEXP (SET_SRC (body), 2);
1804 /* The jump is now either unconditional or a no-op.
1805 If it has become a no-op, don't try to output it.
1806 (It would not be recognized.) */
1807 if (SET_SRC (body) == pc_rtx)
1809 PUT_CODE (insn, NOTE);
1810 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1811 NOTE_SOURCE_FILE (insn) = 0;
1812 break;
1814 else if (GET_CODE (SET_SRC (body)) == RETURN)
1815 /* Replace (set (pc) (return)) with (return). */
1816 PATTERN (insn) = body = SET_SRC (body);
1818 /* Rerecognize the instruction if it has changed. */
1819 if (result != 0)
1820 INSN_CODE (insn) = -1;
1823 /* Make same adjustments to instructions that examine the
1824 condition codes without jumping (if this machine has them). */
1826 if (cc_status.flags != 0
1827 && GET_CODE (body) == SET)
1829 switch (GET_CODE (SET_SRC (body)))
1831 case GTU:
1832 case GT:
1833 case LTU:
1834 case LT:
1835 case GEU:
1836 case GE:
1837 case LEU:
1838 case LE:
1839 case EQ:
1840 case NE:
1842 register int result;
1843 if (XEXP (SET_SRC (body), 0) != cc0_rtx)
1844 break;
1845 result = alter_cond (SET_SRC (body));
1846 if (result == 1)
1847 validate_change (insn, &SET_SRC (body), const_true_rtx, 0);
1848 else if (result == -1)
1849 validate_change (insn, &SET_SRC (body), const0_rtx, 0);
1850 else if (result == 2)
1851 INSN_CODE (insn) = -1;
1855 #endif
1857 /* Do machine-specific peephole optimizations if desired. */
1859 if (optimize && !flag_no_peephole && !nopeepholes)
1861 rtx next = peephole (insn);
1862 /* When peepholing, if there were notes within the peephole,
1863 emit them before the peephole. */
1864 if (next != 0 && next != NEXT_INSN (insn))
1866 rtx prev = PREV_INSN (insn);
1867 rtx note;
1869 for (note = NEXT_INSN (insn); note != next;
1870 note = NEXT_INSN (note))
1871 final_scan_insn (note, file, optimize, prescan, nopeepholes);
1873 /* In case this is prescan, put the notes
1874 in proper position for later rescan. */
1875 note = NEXT_INSN (insn);
1876 PREV_INSN (note) = prev;
1877 NEXT_INSN (prev) = note;
1878 NEXT_INSN (PREV_INSN (next)) = insn;
1879 PREV_INSN (insn) = PREV_INSN (next);
1880 NEXT_INSN (insn) = next;
1881 PREV_INSN (next) = insn;
1884 /* PEEPHOLE might have changed this. */
1885 body = PATTERN (insn);
1888 /* Try to recognize the instruction.
1889 If successful, verify that the operands satisfy the
1890 constraints for the instruction. Crash if they don't,
1891 since `reload' should have changed them so that they do. */
1893 insn_code_number = recog_memoized (insn);
1894 insn_extract (insn);
1895 for (i = 0; i < insn_n_operands[insn_code_number]; i++)
1897 if (GET_CODE (recog_operand[i]) == SUBREG)
1898 recog_operand[i] = alter_subreg (recog_operand[i]);
1899 else if (GET_CODE (recog_operand[i]) == PLUS
1900 || GET_CODE (recog_operand[i]) == MULT)
1901 recog_operand[i] = walk_alter_subreg (recog_operand[i]);
1904 for (i = 0; i < insn_n_dups[insn_code_number]; i++)
1906 if (GET_CODE (*recog_dup_loc[i]) == SUBREG)
1907 *recog_dup_loc[i] = alter_subreg (*recog_dup_loc[i]);
1908 else if (GET_CODE (*recog_dup_loc[i]) == PLUS
1909 || GET_CODE (*recog_dup_loc[i]) == MULT)
1910 *recog_dup_loc[i] = walk_alter_subreg (*recog_dup_loc[i]);
1913 #ifdef REGISTER_CONSTRAINTS
1914 if (! constrain_operands (insn_code_number, 1))
1915 fatal_insn_not_found (insn);
1916 #endif
1918 /* Some target machines need to prescan each insn before
1919 it is output. */
1921 #ifdef FINAL_PRESCAN_INSN
1922 FINAL_PRESCAN_INSN (insn, recog_operand,
1923 insn_n_operands[insn_code_number]);
1924 #endif
1926 #ifdef HAVE_cc0
1927 cc_prev_status = cc_status;
1929 /* Update `cc_status' for this instruction.
1930 The instruction's output routine may change it further.
1931 If the output routine for a jump insn needs to depend
1932 on the cc status, it should look at cc_prev_status. */
1934 NOTICE_UPDATE_CC (body, insn);
1935 #endif
1937 debug_insn = insn;
1939 /* If the proper template needs to be chosen by some C code,
1940 run that code and get the real template. */
1942 template = insn_template[insn_code_number];
1943 if (template == 0)
1945 template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
1947 /* If the C code returns 0, it means that it is a jump insn
1948 which follows a deleted test insn, and that test insn
1949 needs to be reinserted. */
1950 if (template == 0)
1952 if (prev_nonnote_insn (insn) != last_ignored_compare)
1953 abort ();
1954 new_block = 0;
1955 return prev_nonnote_insn (insn);
1959 /* If the template is the string "#", it means that this insn must
1960 be split. */
1961 if (template[0] == '#' && template[1] == '\0')
1963 rtx new = try_split (body, insn, 0);
1965 /* If we didn't split the insn, go away. */
1966 if (new == insn && PATTERN (new) == body)
1967 abort ();
1969 new_block = 0;
1970 return new;
1973 if (prescan > 0)
1974 break;
1976 /* Output assembler code from the template. */
1978 output_asm_insn (template, recog_operand);
1980 #if 0
1981 /* It's not at all clear why we did this and doing so interferes
1982 with tests we'd like to do to use REG_WAS_0 notes, so let's try
1983 with this out. */
1985 /* Mark this insn as having been output. */
1986 INSN_DELETED_P (insn) = 1;
1987 #endif
1989 debug_insn = 0;
1992 return NEXT_INSN (insn);
1995 /* Output debugging info to the assembler file FILE
1996 based on the NOTE-insn INSN, assumed to be a line number. */
1998 static void
1999 output_source_line (file, insn)
2000 FILE *file;
2001 rtx insn;
2003 register char *filename = NOTE_SOURCE_FILE (insn);
2005 /* Remember filename for basic block profiling.
2006 Filenames are allocated on the permanent obstack
2007 or are passed in ARGV, so we don't have to save
2008 the string. */
2010 if (profile_block_flag && last_filename != filename)
2011 bb_file_label_num = add_bb_string (filename, TRUE);
2013 last_filename = filename;
2014 last_linenum = NOTE_LINE_NUMBER (insn);
2016 if (write_symbols != NO_DEBUG)
2018 #ifdef SDB_DEBUGGING_INFO
2019 if (write_symbols == SDB_DEBUG
2020 #if 0 /* People like having line numbers even in wrong file! */
2021 /* COFF can't handle multiple source files--lose, lose. */
2022 && !strcmp (filename, main_input_filename)
2023 #endif
2024 /* COFF relative line numbers must be positive. */
2025 && last_linenum > sdb_begin_function_line)
2027 #ifdef ASM_OUTPUT_SOURCE_LINE
2028 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
2029 #else
2030 fprintf (file, "\t.ln\t%d\n",
2031 ((sdb_begin_function_line > -1)
2032 ? last_linenum - sdb_begin_function_line : 1));
2033 #endif
2035 #endif
2037 #if defined (DBX_DEBUGGING_INFO)
2038 if (write_symbols == DBX_DEBUG)
2039 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
2040 #endif
2042 #if defined (XCOFF_DEBUGGING_INFO)
2043 if (write_symbols == XCOFF_DEBUG)
2044 xcoffout_source_line (file, filename, insn);
2045 #endif
2047 #ifdef DWARF_DEBUGGING_INFO
2048 if (write_symbols == DWARF_DEBUG)
2049 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
2050 #endif
2054 /* If X is a SUBREG, replace it with a REG or a MEM,
2055 based on the thing it is a subreg of. */
2058 alter_subreg (x)
2059 register rtx x;
2061 register rtx y = SUBREG_REG (x);
2062 if (GET_CODE (y) == SUBREG)
2063 y = alter_subreg (y);
2065 if (GET_CODE (y) == REG)
2067 /* If the containing reg really gets a hard reg, so do we. */
2068 PUT_CODE (x, REG);
2069 REGNO (x) = REGNO (y) + SUBREG_WORD (x);
2071 else if (GET_CODE (y) == MEM)
2073 register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2074 #if BYTES_BIG_ENDIAN
2075 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
2076 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
2077 #endif
2078 PUT_CODE (x, MEM);
2079 MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
2080 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
2083 return x;
2086 /* Do alter_subreg on all the SUBREGs contained in X. */
2088 static rtx
2089 walk_alter_subreg (x)
2090 rtx x;
2092 switch (GET_CODE (x))
2094 case PLUS:
2095 case MULT:
2096 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2097 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
2098 break;
2100 case MEM:
2101 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2102 break;
2104 case SUBREG:
2105 return alter_subreg (x);
2108 return x;
2111 #ifdef HAVE_cc0
2113 /* Given BODY, the body of a jump instruction, alter the jump condition
2114 as required by the bits that are set in cc_status.flags.
2115 Not all of the bits there can be handled at this level in all cases.
2117 The value is normally 0.
2118 1 means that the condition has become always true.
2119 -1 means that the condition has become always false.
2120 2 means that COND has been altered. */
2122 static int
2123 alter_cond (cond)
2124 register rtx cond;
2126 int value = 0;
2128 if (cc_status.flags & CC_REVERSED)
2130 value = 2;
2131 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
2134 if (cc_status.flags & CC_INVERTED)
2136 value = 2;
2137 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
2140 if (cc_status.flags & CC_NOT_POSITIVE)
2141 switch (GET_CODE (cond))
2143 case LE:
2144 case LEU:
2145 case GEU:
2146 /* Jump becomes unconditional. */
2147 return 1;
2149 case GT:
2150 case GTU:
2151 case LTU:
2152 /* Jump becomes no-op. */
2153 return -1;
2155 case GE:
2156 PUT_CODE (cond, EQ);
2157 value = 2;
2158 break;
2160 case LT:
2161 PUT_CODE (cond, NE);
2162 value = 2;
2163 break;
2166 if (cc_status.flags & CC_NOT_NEGATIVE)
2167 switch (GET_CODE (cond))
2169 case GE:
2170 case GEU:
2171 /* Jump becomes unconditional. */
2172 return 1;
2174 case LT:
2175 case LTU:
2176 /* Jump becomes no-op. */
2177 return -1;
2179 case LE:
2180 case LEU:
2181 PUT_CODE (cond, EQ);
2182 value = 2;
2183 break;
2185 case GT:
2186 case GTU:
2187 PUT_CODE (cond, NE);
2188 value = 2;
2189 break;
2192 if (cc_status.flags & CC_NO_OVERFLOW)
2193 switch (GET_CODE (cond))
2195 case GEU:
2196 /* Jump becomes unconditional. */
2197 return 1;
2199 case LEU:
2200 PUT_CODE (cond, EQ);
2201 value = 2;
2202 break;
2204 case GTU:
2205 PUT_CODE (cond, NE);
2206 value = 2;
2207 break;
2209 case LTU:
2210 /* Jump becomes no-op. */
2211 return -1;
2214 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
2215 switch (GET_CODE (cond))
2217 case LE:
2218 case LEU:
2219 case GE:
2220 case GEU:
2221 case LT:
2222 case LTU:
2223 case GT:
2224 case GTU:
2225 abort ();
2227 case NE:
2228 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
2229 value = 2;
2230 break;
2232 case EQ:
2233 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
2234 value = 2;
2235 break;
2238 if (cc_status.flags & CC_NOT_SIGNED)
2239 /* The flags are valid if signed condition operators are converted
2240 to unsigned. */
2241 switch (GET_CODE (cond))
2243 case LE:
2244 PUT_CODE (cond, LEU);
2245 value = 2;
2246 break;
2248 case LT:
2249 PUT_CODE (cond, LTU);
2250 value = 2;
2251 break;
2253 case GT:
2254 PUT_CODE (cond, GTU);
2255 value = 2;
2256 break;
2258 case GE:
2259 PUT_CODE (cond, GEU);
2260 value = 2;
2261 break;
2264 return value;
2266 #endif
2268 /* Report inconsistency between the assembler template and the operands.
2269 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
2271 void
2272 output_operand_lossage (str)
2273 char *str;
2275 if (this_is_asm_operands)
2276 error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
2277 else
2278 abort ();
2281 /* Output of assembler code from a template, and its subroutines. */
2283 /* Output text from TEMPLATE to the assembler output file,
2284 obeying %-directions to substitute operands taken from
2285 the vector OPERANDS.
2287 %N (for N a digit) means print operand N in usual manner.
2288 %lN means require operand N to be a CODE_LABEL or LABEL_REF
2289 and print the label name with no punctuation.
2290 %cN means require operand N to be a constant
2291 and print the constant expression with no punctuation.
2292 %aN means expect operand N to be a memory address
2293 (not a memory reference!) and print a reference
2294 to that address.
2295 %nN means expect operand N to be a constant
2296 and print a constant expression for minus the value
2297 of the operand, with no other punctuation. */
2299 void
2300 output_asm_insn (template, operands)
2301 char *template;
2302 rtx *operands;
2304 register char *p;
2305 register int c, i;
2307 /* An insn may return a null string template
2308 in a case where no assembler code is needed. */
2309 if (*template == 0)
2310 return;
2312 p = template;
2313 putc ('\t', asm_out_file);
2315 #ifdef ASM_OUTPUT_OPCODE
2316 ASM_OUTPUT_OPCODE (asm_out_file, p);
2317 #endif
2319 while (c = *p++)
2320 switch (c)
2322 #ifdef ASM_OUTPUT_OPCODE
2323 case '\n':
2324 putc (c, asm_out_file);
2325 while ((c = *p) == '\t')
2327 putc (c, asm_out_file);
2328 p++;
2330 ASM_OUTPUT_OPCODE (asm_out_file, p);
2331 break;
2332 #endif
2334 #ifdef ASSEMBLER_DIALECT
2335 case '{':
2336 /* If we want the first dialect, do nothing. Otherwise, skip
2337 DIALECT_NUMBER of strings ending with '|'. */
2338 for (i = 0; i < dialect_number; i++)
2340 while (*p && *p++ != '|')
2343 if (*p == '|')
2344 p++;
2346 break;
2348 case '|':
2349 /* Skip to close brace. */
2350 while (*p && *p++ != '}')
2352 break;
2354 case '}':
2355 break;
2356 #endif
2358 case '%':
2359 /* %% outputs a single %. */
2360 if (*p == '%')
2362 p++;
2363 putc (c, asm_out_file);
2365 /* %= outputs a number which is unique to each insn in the entire
2366 compilation. This is useful for making local labels that are
2367 referred to more than once in a given insn. */
2368 else if (*p == '=')
2370 p++;
2371 fprintf (asm_out_file, "%d", insn_counter);
2373 /* % followed by a letter and some digits
2374 outputs an operand in a special way depending on the letter.
2375 Letters `acln' are implemented directly.
2376 Other letters are passed to `output_operand' so that
2377 the PRINT_OPERAND macro can define them. */
2378 else if ((*p >= 'a' && *p <= 'z')
2379 || (*p >= 'A' && *p <= 'Z'))
2381 int letter = *p++;
2382 c = atoi (p);
2384 if (! (*p >= '0' && *p <= '9'))
2385 output_operand_lossage ("operand number missing after %-letter");
2386 else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2387 output_operand_lossage ("operand number out of range");
2388 else if (letter == 'l')
2389 output_asm_label (operands[c]);
2390 else if (letter == 'a')
2391 output_address (operands[c]);
2392 else if (letter == 'c')
2394 if (CONSTANT_ADDRESS_P (operands[c]))
2395 output_addr_const (asm_out_file, operands[c]);
2396 else
2397 output_operand (operands[c], 'c');
2399 else if (letter == 'n')
2401 if (GET_CODE (operands[c]) == CONST_INT)
2402 fprintf (asm_out_file,
2403 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2404 "%d",
2405 #else
2406 "%ld",
2407 #endif
2408 - INTVAL (operands[c]));
2409 else
2411 putc ('-', asm_out_file);
2412 output_addr_const (asm_out_file, operands[c]);
2415 else
2416 output_operand (operands[c], letter);
2418 while ((c = *p) >= '0' && c <= '9') p++;
2420 /* % followed by a digit outputs an operand the default way. */
2421 else if (*p >= '0' && *p <= '9')
2423 c = atoi (p);
2424 if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2425 output_operand_lossage ("operand number out of range");
2426 else
2427 output_operand (operands[c], 0);
2428 while ((c = *p) >= '0' && c <= '9') p++;
2430 /* % followed by punctuation: output something for that
2431 punctuation character alone, with no operand.
2432 The PRINT_OPERAND macro decides what is actually done. */
2433 #ifdef PRINT_OPERAND_PUNCT_VALID_P
2434 else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
2435 output_operand (NULL_RTX, *p++);
2436 #endif
2437 else
2438 output_operand_lossage ("invalid %%-code");
2439 break;
2441 default:
2442 putc (c, asm_out_file);
2445 if (flag_print_asm_name)
2447 /* Annotate the assembly with a comment describing the pattern and
2448 alternative used. */
2449 if (debug_insn)
2451 register int num = INSN_CODE (debug_insn);
2452 fprintf (asm_out_file, " %s %d %s",
2453 ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
2454 if (insn_n_alternatives[num] > 1)
2455 fprintf (asm_out_file, "/%d", which_alternative + 1);
2457 /* Clear this so only the first assembler insn
2458 of any rtl insn will get the special comment for -dp. */
2459 debug_insn = 0;
2463 putc ('\n', asm_out_file);
2466 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
2468 void
2469 output_asm_label (x)
2470 rtx x;
2472 char buf[256];
2474 if (GET_CODE (x) == LABEL_REF)
2475 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2476 else if (GET_CODE (x) == CODE_LABEL)
2477 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2478 else
2479 output_operand_lossage ("`%l' operand isn't a label");
2481 assemble_name (asm_out_file, buf);
2484 /* Print operand X using machine-dependent assembler syntax.
2485 The macro PRINT_OPERAND is defined just to control this function.
2486 CODE is a non-digit that preceded the operand-number in the % spec,
2487 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
2488 between the % and the digits.
2489 When CODE is a non-letter, X is 0.
2491 The meanings of the letters are machine-dependent and controlled
2492 by PRINT_OPERAND. */
2494 static void
2495 output_operand (x, code)
2496 rtx x;
2497 int code;
2499 if (x && GET_CODE (x) == SUBREG)
2500 x = alter_subreg (x);
2502 /* If X is a pseudo-register, abort now rather than writing trash to the
2503 assembler file. */
2505 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2506 abort ();
2508 PRINT_OPERAND (asm_out_file, x, code);
2511 /* Print a memory reference operand for address X
2512 using machine-dependent assembler syntax.
2513 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
2515 void
2516 output_address (x)
2517 rtx x;
2519 walk_alter_subreg (x);
2520 PRINT_OPERAND_ADDRESS (asm_out_file, x);
2523 /* Print an integer constant expression in assembler syntax.
2524 Addition and subtraction are the only arithmetic
2525 that may appear in these expressions. */
2527 void
2528 output_addr_const (file, x)
2529 FILE *file;
2530 rtx x;
2532 char buf[256];
2534 restart:
2535 switch (GET_CODE (x))
2537 case PC:
2538 if (flag_pic)
2539 putc ('.', file);
2540 else
2541 abort ();
2542 break;
2544 case SYMBOL_REF:
2545 assemble_name (file, XSTR (x, 0));
2546 break;
2548 case LABEL_REF:
2549 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2550 assemble_name (file, buf);
2551 break;
2553 case CODE_LABEL:
2554 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2555 assemble_name (file, buf);
2556 break;
2558 case CONST_INT:
2559 fprintf (file,
2560 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2561 "%d",
2562 #else
2563 "%ld",
2564 #endif
2565 INTVAL (x));
2566 break;
2568 case CONST:
2569 /* This used to output parentheses around the expression,
2570 but that does not work on the 386 (either ATT or BSD assembler). */
2571 output_addr_const (file, XEXP (x, 0));
2572 break;
2574 case CONST_DOUBLE:
2575 if (GET_MODE (x) == VOIDmode)
2577 /* We can use %d if the number is one word and positive. */
2578 if (CONST_DOUBLE_HIGH (x))
2579 fprintf (file,
2580 #if HOST_BITS_PER_WIDE_INT == 64
2581 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2582 "0x%lx%016lx",
2583 #else
2584 "0x%x%016x",
2585 #endif
2586 #else
2587 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2588 "0x%lx%08lx",
2589 #else
2590 "0x%x%08x",
2591 #endif
2592 #endif
2593 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2594 else if (CONST_DOUBLE_LOW (x) < 0)
2595 fprintf (file,
2596 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2597 "0x%x",
2598 #else
2599 "0x%lx",
2600 #endif
2601 CONST_DOUBLE_LOW (x));
2602 else
2603 fprintf (file,
2604 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2605 "%d",
2606 #else
2607 "%ld",
2608 #endif
2609 CONST_DOUBLE_LOW (x));
2611 else
2612 /* We can't handle floating point constants;
2613 PRINT_OPERAND must handle them. */
2614 output_operand_lossage ("floating constant misused");
2615 break;
2617 case PLUS:
2618 /* Some assemblers need integer constants to appear last (eg masm). */
2619 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2621 output_addr_const (file, XEXP (x, 1));
2622 if (INTVAL (XEXP (x, 0)) >= 0)
2623 fprintf (file, "+");
2624 output_addr_const (file, XEXP (x, 0));
2626 else
2628 output_addr_const (file, XEXP (x, 0));
2629 if (INTVAL (XEXP (x, 1)) >= 0)
2630 fprintf (file, "+");
2631 output_addr_const (file, XEXP (x, 1));
2633 break;
2635 case MINUS:
2636 /* Avoid outputting things like x-x or x+5-x,
2637 since some assemblers can't handle that. */
2638 x = simplify_subtraction (x);
2639 if (GET_CODE (x) != MINUS)
2640 goto restart;
2642 output_addr_const (file, XEXP (x, 0));
2643 fprintf (file, "-");
2644 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2645 && INTVAL (XEXP (x, 1)) < 0)
2647 fprintf (file, ASM_OPEN_PAREN);
2648 output_addr_const (file, XEXP (x, 1));
2649 fprintf (file, ASM_CLOSE_PAREN);
2651 else
2652 output_addr_const (file, XEXP (x, 1));
2653 break;
2655 case ZERO_EXTEND:
2656 case SIGN_EXTEND:
2657 output_addr_const (file, XEXP (x, 0));
2658 break;
2660 default:
2661 output_operand_lossage ("invalid expression as operand");
2665 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
2666 %R prints the value of REGISTER_PREFIX.
2667 %L prints the value of LOCAL_LABEL_PREFIX.
2668 %U prints the value of USER_LABEL_PREFIX.
2669 %I prints the value of IMMEDIATE_PREFIX.
2670 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
2671 Also supported are %d, %x, %s, %e, %f, %g and %%.
2673 We handle alternate assembler dialects here, just like output_asm_insn. */
2675 void
2676 asm_fprintf VPROTO((FILE *file, char *p, ...))
2678 #ifndef __STDC__
2679 FILE *file;
2680 char *p;
2681 #endif
2682 va_list argptr;
2683 char buf[10];
2684 char *q, c;
2685 int i;
2687 VA_START (argptr, p);
2689 #ifndef __STDC__
2690 file = va_arg (argptr, FILE*);
2691 p = va_arg (argptr, char*);
2692 #endif
2694 buf[0] = '%';
2696 while (c = *p++)
2697 switch (c)
2699 #ifdef ASSEMBLER_DIALECT
2700 case '{':
2701 /* If we want the first dialect, do nothing. Otherwise, skip
2702 DIALECT_NUMBER of strings ending with '|'. */
2703 for (i = 0; i < dialect_number; i++)
2705 while (*p && *p++ != '|')
2708 if (*p == '|')
2709 p++;
2711 break;
2713 case '|':
2714 /* Skip to close brace. */
2715 while (*p && *p++ != '}')
2717 break;
2719 case '}':
2720 break;
2721 #endif
2723 case '%':
2724 c = *p++;
2725 q = &buf[1];
2726 while ((c >= '0' && c <= '9') || c == '.')
2728 *q++ = c;
2729 c = *p++;
2731 switch (c)
2733 case '%':
2734 fprintf (file, "%%");
2735 break;
2737 case 'd': case 'i': case 'u':
2738 case 'x': case 'p': case 'X':
2739 case 'o':
2740 *q++ = c;
2741 *q = 0;
2742 fprintf (file, buf, va_arg (argptr, int));
2743 break;
2745 case 'w':
2746 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
2747 but we do not check for those cases. It means that the value
2748 is a HOST_WIDE_INT, which may be either `int' or `long'. */
2750 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2751 *q++ = 'l';
2752 #endif
2754 *q++ = *p++;
2755 *q = 0;
2756 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
2757 break;
2759 case 'l':
2760 *q++ = c;
2761 *q++ = *p++;
2762 *q = 0;
2763 fprintf (file, buf, va_arg (argptr, long));
2764 break;
2766 case 'e':
2767 case 'f':
2768 case 'g':
2769 *q++ = c;
2770 *q = 0;
2771 fprintf (file, buf, va_arg (argptr, double));
2772 break;
2774 case 's':
2775 *q++ = c;
2776 *q = 0;
2777 fprintf (file, buf, va_arg (argptr, char *));
2778 break;
2780 case 'O':
2781 #ifdef ASM_OUTPUT_OPCODE
2782 ASM_OUTPUT_OPCODE (asm_out_file, p);
2783 #endif
2784 break;
2786 case 'R':
2787 #ifdef REGISTER_PREFIX
2788 fprintf (file, "%s", REGISTER_PREFIX);
2789 #endif
2790 break;
2792 case 'I':
2793 #ifdef IMMEDIATE_PREFIX
2794 fprintf (file, "%s", IMMEDIATE_PREFIX);
2795 #endif
2796 break;
2798 case 'L':
2799 #ifdef LOCAL_LABEL_PREFIX
2800 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
2801 #endif
2802 break;
2804 case 'U':
2805 #ifdef USER_LABEL_PREFIX
2806 fprintf (file, "%s", USER_LABEL_PREFIX);
2807 #endif
2808 break;
2810 default:
2811 abort ();
2813 break;
2815 default:
2816 fputc (c, file);
2820 /* Split up a CONST_DOUBLE or integer constant rtx
2821 into two rtx's for single words,
2822 storing in *FIRST the word that comes first in memory in the target
2823 and in *SECOND the other. */
2825 void
2826 split_double (value, first, second)
2827 rtx value;
2828 rtx *first, *second;
2830 if (GET_CODE (value) == CONST_INT)
2832 /* The rule for using CONST_INT for a wider mode
2833 is that we regard the value as signed.
2834 So sign-extend it. */
2835 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
2836 #if WORDS_BIG_ENDIAN
2837 *first = high;
2838 *second = value;
2839 #else
2840 *first = value;
2841 *second = high;
2842 #endif
2844 else if (GET_CODE (value) != CONST_DOUBLE)
2846 #if WORDS_BIG_ENDIAN
2847 *first = const0_rtx;
2848 *second = value;
2849 #else
2850 *first = value;
2851 *second = const0_rtx;
2852 #endif
2854 else if (GET_MODE (value) == VOIDmode
2855 /* This is the old way we did CONST_DOUBLE integers. */
2856 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
2858 /* In an integer, the words are defined as most and least significant.
2859 So order them by the target's convention. */
2860 #if WORDS_BIG_ENDIAN
2861 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2862 *second = GEN_INT (CONST_DOUBLE_LOW (value));
2863 #else
2864 *first = GEN_INT (CONST_DOUBLE_LOW (value));
2865 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
2866 #endif
2868 else
2870 #ifdef REAL_ARITHMETIC
2871 REAL_VALUE_TYPE r; long l[2];
2872 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
2874 /* Note, this converts the REAL_VALUE_TYPE to the target's
2875 format, splits up the floating point double and outputs
2876 exactly 32 bits of it into each of l[0] and l[1] --
2877 not necessarily BITS_PER_WORD bits. */
2878 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
2880 *first = GEN_INT ((HOST_WIDE_INT) l[0]);
2881 *second = GEN_INT ((HOST_WIDE_INT) l[1]);
2882 #else
2883 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
2884 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
2885 && ! flag_pretend_float)
2886 abort ();
2888 #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
2889 /* Host and target agree => no need to swap. */
2890 *first = GEN_INT (CONST_DOUBLE_LOW (value));
2891 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
2892 #else
2893 *second = GEN_INT (CONST_DOUBLE_LOW (value));
2894 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2895 #endif
2896 #endif /* no REAL_ARITHMETIC */
2900 /* Return nonzero if this function has no function calls. */
2903 leaf_function_p ()
2905 rtx insn;
2907 if (profile_flag || profile_block_flag)
2908 return 0;
2910 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2912 if (GET_CODE (insn) == CALL_INSN)
2913 return 0;
2914 if (GET_CODE (insn) == INSN
2915 && GET_CODE (PATTERN (insn)) == SEQUENCE
2916 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN)
2917 return 0;
2919 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
2921 if (GET_CODE (XEXP (insn, 0)) == CALL_INSN)
2922 return 0;
2923 if (GET_CODE (XEXP (insn, 0)) == INSN
2924 && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
2925 && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN)
2926 return 0;
2929 return 1;
2932 /* On some machines, a function with no call insns
2933 can run faster if it doesn't create its own register window.
2934 When output, the leaf function should use only the "output"
2935 registers. Ordinarily, the function would be compiled to use
2936 the "input" registers to find its arguments; it is a candidate
2937 for leaf treatment if it uses only the "input" registers.
2938 Leaf function treatment means renumbering so the function
2939 uses the "output" registers instead. */
2941 #ifdef LEAF_REGISTERS
2943 static char permitted_reg_in_leaf_functions[] = LEAF_REGISTERS;
2945 /* Return 1 if this function uses only the registers that can be
2946 safely renumbered. */
2949 only_leaf_regs_used ()
2951 int i;
2953 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2955 if ((regs_ever_live[i] || global_regs[i])
2956 && ! permitted_reg_in_leaf_functions[i])
2957 return 0;
2959 return 1;
2962 /* Scan all instructions and renumber all registers into those
2963 available in leaf functions. */
2965 static void
2966 leaf_renumber_regs (first)
2967 rtx first;
2969 rtx insn;
2971 /* Renumber only the actual patterns.
2972 The reg-notes can contain frame pointer refs,
2973 and renumbering them could crash, and should not be needed. */
2974 for (insn = first; insn; insn = NEXT_INSN (insn))
2975 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
2976 leaf_renumber_regs_insn (PATTERN (insn));
2977 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
2978 if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
2979 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
2982 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
2983 available in leaf functions. */
2985 void
2986 leaf_renumber_regs_insn (in_rtx)
2987 register rtx in_rtx;
2989 register int i, j;
2990 register char *format_ptr;
2992 if (in_rtx == 0)
2993 return;
2995 /* Renumber all input-registers into output-registers.
2996 renumbered_regs would be 1 for an output-register;
2997 they */
2999 if (GET_CODE (in_rtx) == REG)
3001 int newreg;
3003 /* Don't renumber the same reg twice. */
3004 if (in_rtx->used)
3005 return;
3007 newreg = REGNO (in_rtx);
3008 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
3009 to reach here as part of a REG_NOTE. */
3010 if (newreg >= FIRST_PSEUDO_REGISTER)
3012 in_rtx->used = 1;
3013 return;
3015 newreg = LEAF_REG_REMAP (newreg);
3016 if (newreg < 0)
3017 abort ();
3018 regs_ever_live[REGNO (in_rtx)] = 0;
3019 regs_ever_live[newreg] = 1;
3020 REGNO (in_rtx) = newreg;
3021 in_rtx->used = 1;
3024 if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
3026 /* Inside a SEQUENCE, we find insns.
3027 Renumber just the patterns of these insns,
3028 just as we do for the top-level insns. */
3029 leaf_renumber_regs_insn (PATTERN (in_rtx));
3030 return;
3033 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
3035 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
3036 switch (*format_ptr++)
3038 case 'e':
3039 leaf_renumber_regs_insn (XEXP (in_rtx, i));
3040 break;
3042 case 'E':
3043 if (NULL != XVEC (in_rtx, i))
3045 for (j = 0; j < XVECLEN (in_rtx, i); j++)
3046 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
3048 break;
3050 case 'S':
3051 case 's':
3052 case '0':
3053 case 'i':
3054 case 'w':
3055 case 'n':
3056 case 'u':
3057 break;
3059 default:
3060 abort ();
3063 #endif