(*zeroextract[qs]i_compare0_scratch): Use const_int_operand
[official-gcc.git] / gcc / final.c
blob6fa3e7efb2a060188255d96696003d690ff3c8a6
1 /* Convert RTL to assembler code and output it, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 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, 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. */
47 #include "config.h"
48 #ifdef __STDC__
49 #include <stdarg.h>
50 #else
51 #include <varargs.h>
52 #endif
53 #include <stdio.h>
54 #include <ctype.h>
56 #include "tree.h"
57 #include "rtl.h"
58 #include "regs.h"
59 #include "insn-config.h"
60 #include "insn-flags.h"
61 #include "insn-attr.h"
62 #include "insn-codes.h"
63 #include "recog.h"
64 #include "conditions.h"
65 #include "flags.h"
66 #include "real.h"
67 #include "hard-reg-set.h"
68 #include "defaults.h"
69 #include "output.h"
71 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist. */
72 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
73 #if defined (USG) || defined (NO_STAB_H)
74 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
75 #else
76 #include <stab.h> /* On BSD, use the system's stab.h. */
77 #endif /* not USG */
78 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
80 #ifdef XCOFF_DEBUGGING_INFO
81 #include "xcoffout.h"
82 #endif
84 /* .stabd code for line number. */
85 #ifndef N_SLINE
86 #define N_SLINE 0x44
87 #endif
89 /* .stabs code for included file name. */
90 #ifndef N_SOL
91 #define N_SOL 0x84
92 #endif
94 #ifndef INT_TYPE_SIZE
95 #define INT_TYPE_SIZE BITS_PER_WORD
96 #endif
98 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
99 null default for it to save conditionalization later. */
100 #ifndef CC_STATUS_INIT
101 #define CC_STATUS_INIT
102 #endif
104 /* How to start an assembler comment. */
105 #ifndef ASM_COMMENT_START
106 #define ASM_COMMENT_START ";#"
107 #endif
109 /* Is the given character a logical line separator for the assembler? */
110 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
111 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
112 #endif
114 /* Nonzero means this function is a leaf function, with no function calls.
115 This variable exists to be examined in FUNCTION_PROLOGUE
116 and FUNCTION_EPILOGUE. Always zero, unless set by some action. */
117 int leaf_function;
119 /* Last insn processed by final_scan_insn. */
120 static rtx debug_insn = 0;
122 /* Line number of last NOTE. */
123 static int last_linenum;
125 /* Highest line number in current block. */
126 static int high_block_linenum;
128 /* Likewise for function. */
129 static int high_function_linenum;
131 /* Filename of last NOTE. */
132 static char *last_filename;
134 /* Number of basic blocks seen so far;
135 used if profile_block_flag is set. */
136 static int count_basic_blocks;
138 /* Nonzero while outputting an `asm' with operands.
139 This means that inconsistencies are the user's fault, so don't abort.
140 The precise value is the insn being output, to pass to error_for_asm. */
141 static rtx this_is_asm_operands;
143 /* Number of operands of this insn, for an `asm' with operands. */
144 static int insn_noperands;
146 /* Compare optimization flag. */
148 static rtx last_ignored_compare = 0;
150 /* Flag indicating this insn is the start of a new basic block. */
152 static int new_block = 1;
154 /* All the symbol-blocks (levels of scoping) in the compilation
155 are assigned sequence numbers in order of appearance of the
156 beginnings of the symbol-blocks. Both final and dbxout do this,
157 and assume that they will both give the same number to each block.
158 Final uses these sequence numbers to generate assembler label names
159 LBBnnn and LBEnnn for the beginning and end of the symbol-block.
160 Dbxout uses the sequence numbers to generate references to the same labels
161 from the dbx debugging information.
163 Sdb records this level at the beginning of each function,
164 in order to find the current level when recursing down declarations.
165 It outputs the block beginning and endings
166 at the point in the asm file where the blocks would begin and end. */
168 int next_block_index;
170 /* Assign a unique number to each insn that is output.
171 This can be used to generate unique local labels. */
173 static int insn_counter = 0;
175 #ifdef HAVE_cc0
176 /* This variable contains machine-dependent flags (defined in tm.h)
177 set and examined by output routines
178 that describe how to interpret the condition codes properly. */
180 CC_STATUS cc_status;
182 /* During output of an insn, this contains a copy of cc_status
183 from before the insn. */
185 CC_STATUS cc_prev_status;
186 #endif
188 /* Indexed by hardware reg number, is 1 if that register is ever
189 used in the current function.
191 In life_analysis, or in stupid_life_analysis, this is set
192 up to record the hard regs used explicitly. Reload adds
193 in the hard regs used for holding pseudo regs. Final uses
194 it to generate the code in the function prologue and epilogue
195 to save and restore registers as needed. */
197 char regs_ever_live[FIRST_PSEUDO_REGISTER];
199 /* Nonzero means current function must be given a frame pointer.
200 Set in stmt.c if anything is allocated on the stack there.
201 Set in reload1.c if anything is allocated on the stack there. */
203 int frame_pointer_needed;
205 /* Assign unique numbers to labels generated for profiling. */
207 int profile_label_no;
209 /* Length so far allocated in PENDING_BLOCKS. */
211 static int max_block_depth;
213 /* Stack of sequence numbers of symbol-blocks of which we have seen the
214 beginning but not yet the end. Sequence numbers are assigned at
215 the beginning; this stack allows us to find the sequence number
216 of a block that is ending. */
218 static int *pending_blocks;
220 /* Number of elements currently in use in PENDING_BLOCKS. */
222 static int block_depth;
224 /* Nonzero if have enabled APP processing of our assembler output. */
226 static int app_on;
228 /* If we are outputting an insn sequence, this contains the sequence rtx.
229 Zero otherwise. */
231 rtx final_sequence;
233 #ifdef ASSEMBLER_DIALECT
235 /* Number of the assembler dialect to use, starting at 0. */
236 static int dialect_number;
237 #endif
239 /* Indexed by line number, nonzero if there is a note for that line. */
241 static char *line_note_exists;
243 /* Linked list to hold line numbers for each basic block. */
245 struct bb_list {
246 struct bb_list *next; /* pointer to next basic block */
247 int line_num; /* line number */
248 int file_label_num; /* LPBC<n> label # for stored filename */
249 int func_label_num; /* LPBC<n> label # for stored function name */
252 static struct bb_list *bb_head = 0; /* Head of basic block list */
253 static struct bb_list **bb_tail = &bb_head; /* Ptr to store next bb ptr */
254 static int bb_file_label_num = -1; /* Current label # for file */
255 static int bb_func_label_num = -1; /* Current label # for func */
257 /* Linked list to hold the strings for each file and function name output. */
259 struct bb_str {
260 struct bb_str *next; /* pointer to next string */
261 char *string; /* string */
262 int label_num; /* label number */
263 int length; /* string length */
266 extern rtx peephole PROTO((rtx));
268 static struct bb_str *sbb_head = 0; /* Head of string list. */
269 static struct bb_str **sbb_tail = &sbb_head; /* Ptr to store next bb str */
270 static int sbb_label_num = 0; /* Last label used */
272 static int asm_insn_count PROTO((rtx));
273 static void profile_function PROTO((FILE *));
274 static void profile_after_prologue PROTO((FILE *));
275 static void add_bb PROTO((FILE *));
276 static int add_bb_string PROTO((char *, int));
277 static void output_source_line PROTO((FILE *, rtx));
278 static rtx walk_alter_subreg PROTO((rtx));
279 static int alter_cond PROTO((rtx));
280 static void output_asm_name PROTO((void));
281 static void output_operand PROTO((rtx, int));
282 static void leaf_renumber_regs PROTO((rtx));
284 extern char *getpwd ();
286 /* Initialize data in final at the beginning of a compilation. */
288 void
289 init_final (filename)
290 char *filename;
292 next_block_index = 2;
293 app_on = 0;
294 max_block_depth = 20;
295 pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
296 final_sequence = 0;
298 #ifdef ASSEMBLER_DIALECT
299 dialect_number = ASSEMBLER_DIALECT;
300 #endif
303 /* Called at end of source file,
304 to output the block-profiling table for this entire compilation. */
306 void
307 end_final (filename)
308 char *filename;
310 int i;
312 if (profile_block_flag)
314 char name[20];
315 int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
316 int size = (POINTER_SIZE / BITS_PER_UNIT) * count_basic_blocks;
317 int rounded = size;
318 struct bb_list *ptr;
319 struct bb_str *sptr;
321 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
322 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
323 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
325 data_section ();
327 /* Output the main header, of 11 words:
328 0: 1 if this file is initialized, else 0.
329 1: address of file name (LPBX1).
330 2: address of table of counts (LPBX2).
331 3: number of counts in the table.
332 4: always 0, for compatibility with Sun.
334 The following are GNU extensions:
336 5: address of table of start addrs of basic blocks (LPBX3).
337 6: Number of bytes in this header.
338 7: address of table of function names (LPBX4).
339 8: address of table of line numbers (LPBX5) or 0.
340 9: address of table of file names (LPBX6) or 0.
341 10: space reserved for basic block profiling. */
343 ASM_OUTPUT_ALIGN (asm_out_file, align);
345 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
346 /* zero word */
347 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
349 /* address of filename */
350 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
351 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
353 /* address of count table */
354 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
355 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
357 /* count of the # of basic blocks */
358 assemble_integer (GEN_INT (count_basic_blocks), UNITS_PER_WORD, 1);
360 /* zero word (link field) */
361 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
363 /* address of basic block start address table */
364 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
365 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
367 /* byte count for extended structure. */
368 assemble_integer (GEN_INT (11 * UNITS_PER_WORD), UNITS_PER_WORD, 1);
370 /* address of function name table */
371 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
372 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
374 /* address of line number and filename tables if debugging. */
375 if (write_symbols != NO_DEBUG)
377 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
378 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
379 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
380 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
382 else
384 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
385 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
388 /* space for extension ptr (link field) */
389 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
391 /* Output the file name changing the suffix to .d for Sun tcov
392 compatibility. */
393 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
395 char *cwd = getpwd ();
396 int len = strlen (filename) + strlen (cwd) + 1;
397 char *data_file = (char *) alloca (len + 4);
399 strcpy (data_file, cwd);
400 strcat (data_file, "/");
401 strcat (data_file, filename);
402 strip_off_ending (data_file, len);
403 strcat (data_file, ".d");
404 assemble_string (data_file, strlen (data_file) + 1);
407 /* Make space for the table of counts. */
408 if (flag_no_common || size == 0)
410 /* Realign data section. */
411 ASM_OUTPUT_ALIGN (asm_out_file, align);
412 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
413 if (size != 0)
414 assemble_zeros (size);
416 else
418 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
419 #ifdef ASM_OUTPUT_SHARED_LOCAL
420 if (flag_shared_data)
421 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
422 else
423 #endif
424 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
425 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
426 BIGGEST_ALIGNMENT);
427 #else
428 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
429 #endif
432 /* Output any basic block strings */
433 readonly_data_section ();
434 if (sbb_head)
436 ASM_OUTPUT_ALIGN (asm_out_file, align);
437 for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
439 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC", sptr->label_num);
440 assemble_string (sptr->string, sptr->length);
444 /* Output the table of addresses. */
445 /* Realign in new section */
446 ASM_OUTPUT_ALIGN (asm_out_file, align);
447 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
448 for (i = 0; i < count_basic_blocks; i++)
450 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
451 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
452 UNITS_PER_WORD, 1);
455 /* Output the table of function names. */
456 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
457 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
459 if (ptr->func_label_num >= 0)
461 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->func_label_num);
462 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
463 UNITS_PER_WORD, 1);
465 else
466 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
469 for ( ; i < count_basic_blocks; i++)
470 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
472 if (write_symbols != NO_DEBUG)
474 /* Output the table of line numbers. */
475 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
476 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
477 assemble_integer (GEN_INT (ptr->line_num), UNITS_PER_WORD, 1);
479 for ( ; i < count_basic_blocks; i++)
480 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
482 /* Output the table of file names. */
483 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
484 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
486 if (ptr->file_label_num >= 0)
488 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->file_label_num);
489 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
490 UNITS_PER_WORD, 1);
492 else
493 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
496 for ( ; i < count_basic_blocks; i++)
497 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
500 /* End with the address of the table of addresses,
501 so we can find it easily, as the last word in the file's text. */
502 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
503 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
507 /* Enable APP processing of subsequent output.
508 Used before the output from an `asm' statement. */
510 void
511 app_enable ()
513 if (! app_on)
515 fprintf (asm_out_file, ASM_APP_ON);
516 app_on = 1;
520 /* Disable APP processing of subsequent output.
521 Called from varasm.c before most kinds of output. */
523 void
524 app_disable ()
526 if (app_on)
528 fprintf (asm_out_file, ASM_APP_OFF);
529 app_on = 0;
533 /* Return the number of slots filled in the current
534 delayed branch sequence (we don't count the insn needing the
535 delay slot). Zero if not in a delayed branch sequence. */
537 #ifdef DELAY_SLOTS
539 dbr_sequence_length ()
541 if (final_sequence != 0)
542 return XVECLEN (final_sequence, 0) - 1;
543 else
544 return 0;
546 #endif
548 /* The next two pages contain routines used to compute the length of an insn
549 and to shorten branches. */
551 /* Arrays for insn lengths, and addresses. The latter is referenced by
552 `insn_current_length'. */
554 static short *insn_lengths;
555 int *insn_addresses;
557 /* Address of insn being processed. Used by `insn_current_length'. */
558 int insn_current_address;
560 /* Indicate that branch shortening hasn't yet been done. */
562 void
563 init_insn_lengths ()
565 insn_lengths = 0;
568 /* Obtain the current length of an insn. If branch shortening has been done,
569 get its actual length. Otherwise, get its maximum length. */
572 get_attr_length (insn)
573 rtx insn;
575 #ifdef HAVE_ATTR_length
576 rtx body;
577 int i;
578 int length = 0;
580 if (insn_lengths)
581 return insn_lengths[INSN_UID (insn)];
582 else
583 switch (GET_CODE (insn))
585 case NOTE:
586 case BARRIER:
587 case CODE_LABEL:
588 return 0;
590 case CALL_INSN:
591 length = insn_default_length (insn);
592 break;
594 case JUMP_INSN:
595 body = PATTERN (insn);
596 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
598 /* This only takes room if jump tables go into the text section. */
599 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
600 length = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
601 * GET_MODE_SIZE (GET_MODE (body)));
603 /* Be pessimistic and assume worst-case alignment. */
604 length += (GET_MODE_SIZE (GET_MODE (body)) - 1);
605 #else
606 return 0;
607 #endif
609 else
610 length = insn_default_length (insn);
611 break;
613 case INSN:
614 body = PATTERN (insn);
615 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
616 return 0;
618 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
619 length = asm_insn_count (body) * insn_default_length (insn);
620 else if (GET_CODE (body) == SEQUENCE)
621 for (i = 0; i < XVECLEN (body, 0); i++)
622 length += get_attr_length (XVECEXP (body, 0, i));
623 else
624 length = insn_default_length (insn);
627 #ifdef ADJUST_INSN_LENGTH
628 ADJUST_INSN_LENGTH (insn, length);
629 #endif
630 return length;
631 #else /* not HAVE_ATTR_length */
632 return 0;
633 #endif /* not HAVE_ATTR_length */
636 /* Make a pass over all insns and compute their actual lengths by shortening
637 any branches of variable length if possible. */
639 /* Give a default value for the lowest address in a function. */
641 #ifndef FIRST_INSN_ADDRESS
642 #define FIRST_INSN_ADDRESS 0
643 #endif
645 void
646 shorten_branches (first)
647 rtx first;
649 #ifdef HAVE_ATTR_length
650 rtx insn;
651 int something_changed = 1;
652 int max_uid = 0;
653 char *varying_length;
654 rtx body;
655 int uid;
657 /* Compute maximum UID and allocate arrays. */
658 for (insn = first; insn; insn = NEXT_INSN (insn))
659 if (INSN_UID (insn) > max_uid)
660 max_uid = INSN_UID (insn);
662 max_uid++;
663 insn_lengths = (short *) oballoc (max_uid * sizeof (short));
664 insn_addresses = (int *) oballoc (max_uid * sizeof (int));
665 varying_length = (char *) oballoc (max_uid * sizeof (char));
667 /* Compute initial lengths, addresses, and varying flags for each insn. */
668 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
669 insn != 0;
670 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
672 uid = INSN_UID (insn);
673 insn_addresses[uid] = insn_current_address;
674 insn_lengths[uid] = 0;
675 varying_length[uid] = 0;
677 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
678 || GET_CODE (insn) == CODE_LABEL)
679 continue;
681 body = PATTERN (insn);
682 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
684 /* This only takes room if read-only data goes into the text
685 section. */
686 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
687 int unitsize = GET_MODE_SIZE (GET_MODE (body));
689 insn_lengths[uid] = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
690 * GET_MODE_SIZE (GET_MODE (body)));
692 /* Account for possible alignment. */
693 insn_lengths[uid]
694 += unitsize - (insn_current_address & (unitsize - 1));
695 #else
697 #endif
699 else if (asm_noperands (body) >= 0)
700 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
701 else if (GET_CODE (body) == SEQUENCE)
703 int i;
704 int const_delay_slots;
705 #ifdef DELAY_SLOTS
706 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
707 #else
708 const_delay_slots = 0;
709 #endif
710 /* Inside a delay slot sequence, we do not do any branch shortening
711 if the shortening could change the number of delay slots
712 of the branch. */
713 for (i = 0; i < XVECLEN (body, 0); i++)
715 rtx inner_insn = XVECEXP (body, 0, i);
716 int inner_uid = INSN_UID (inner_insn);
717 int inner_length;
719 if (asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
720 inner_length = (asm_insn_count (PATTERN (inner_insn))
721 * insn_default_length (inner_insn));
722 else
723 inner_length = insn_default_length (inner_insn);
725 insn_lengths[inner_uid] = inner_length;
726 if (const_delay_slots)
728 if ((varying_length[inner_uid]
729 = insn_variable_length_p (inner_insn)) != 0)
730 varying_length[uid] = 1;
731 insn_addresses[inner_uid] = (insn_current_address +
732 insn_lengths[uid]);
734 else
735 varying_length[inner_uid] = 0;
736 insn_lengths[uid] += inner_length;
739 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
741 insn_lengths[uid] = insn_default_length (insn);
742 varying_length[uid] = insn_variable_length_p (insn);
745 /* If needed, do any adjustment. */
746 #ifdef ADJUST_INSN_LENGTH
747 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
748 #endif
751 /* Now loop over all the insns finding varying length insns. For each,
752 get the current insn length. If it has changed, reflect the change.
753 When nothing changes for a full pass, we are done. */
755 while (something_changed)
757 something_changed = 0;
758 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
759 insn != 0;
760 insn = NEXT_INSN (insn))
762 int new_length;
763 int tmp_length;
765 uid = INSN_UID (insn);
766 insn_addresses[uid] = insn_current_address;
767 if (! varying_length[uid])
769 insn_current_address += insn_lengths[uid];
770 continue;
772 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
774 int i;
776 body = PATTERN (insn);
777 new_length = 0;
778 for (i = 0; i < XVECLEN (body, 0); i++)
780 rtx inner_insn = XVECEXP (body, 0, i);
781 int inner_uid = INSN_UID (inner_insn);
782 int inner_length;
784 insn_addresses[inner_uid] = insn_current_address;
786 /* insn_current_length returns 0 for insns with a
787 non-varying length. */
788 if (! varying_length[inner_uid])
789 inner_length = insn_lengths[inner_uid];
790 else
791 inner_length = insn_current_length (inner_insn);
793 if (inner_length != insn_lengths[inner_uid])
795 insn_lengths[inner_uid] = inner_length;
796 something_changed = 1;
798 insn_current_address += insn_lengths[inner_uid];
799 new_length += inner_length;
802 else
804 new_length = insn_current_length (insn);
805 insn_current_address += new_length;
808 #ifdef SHORTEN_WITH_ADJUST_INSN_LENGTH
809 #ifdef ADJUST_INSN_LENGTH
810 /* If needed, do any adjustment. */
811 tmp_length = new_length;
812 ADJUST_INSN_LENGTH (insn, new_length);
813 insn_current_address += (new_length - tmp_length);
814 #endif
815 #endif
817 if (new_length != insn_lengths[uid])
819 insn_lengths[uid] = new_length;
820 something_changed = 1;
823 /* For a non-optimizing compile, do only a single pass. */
824 if (!optimize)
825 break;
827 #endif /* HAVE_ATTR_length */
830 #ifdef HAVE_ATTR_length
831 /* Given the body of an INSN known to be generated by an ASM statement, return
832 the number of machine instructions likely to be generated for this insn.
833 This is used to compute its length. */
835 static int
836 asm_insn_count (body)
837 rtx body;
839 char *template;
840 int count = 1;
842 if (GET_CODE (body) == ASM_INPUT)
843 template = XSTR (body, 0);
844 else
845 template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
846 NULL_PTR, NULL_PTR);
848 for ( ; *template; template++)
849 if (IS_ASM_LOGICAL_LINE_SEPARATOR(*template) || *template == '\n')
850 count++;
852 return count;
854 #endif
856 /* Output assembler code for the start of a function,
857 and initialize some of the variables in this file
858 for the new function. The label for the function and associated
859 assembler pseudo-ops have already been output in `assemble_start_function'.
861 FIRST is the first insn of the rtl for the function being compiled.
862 FILE is the file to write assembler code to.
863 OPTIMIZE is nonzero if we should eliminate redundant
864 test and compare insns. */
866 void
867 final_start_function (first, file, optimize)
868 rtx first;
869 FILE *file;
870 int optimize;
872 block_depth = 0;
874 this_is_asm_operands = 0;
876 #ifdef NON_SAVING_SETJMP
877 /* A function that calls setjmp should save and restore all the
878 call-saved registers on a system where longjmp clobbers them. */
879 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
881 int i;
883 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
884 if (!call_used_regs[i] && !call_fixed_regs[i])
885 regs_ever_live[i] = 1;
887 #endif
889 /* Initial line number is supposed to be output
890 before the function's prologue and label
891 so that the function's address will not appear to be
892 in the last statement of the preceding function. */
893 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
894 last_linenum = high_block_linenum = high_function_linenum
895 = NOTE_LINE_NUMBER (first);
897 /* For SDB and XCOFF, the function beginning must be marked between
898 the function label and the prologue. We always need this, even when
899 -g1 was used. Defer on MIPS systems so that parameter descriptions
900 follow function entry. */
901 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
902 if (write_symbols == SDB_DEBUG)
903 sdbout_begin_function (last_linenum);
904 else
905 #endif
906 #ifdef XCOFF_DEBUGGING_INFO
907 if (write_symbols == XCOFF_DEBUG)
908 xcoffout_begin_function (file, last_linenum);
909 else
910 #endif
911 /* But only output line number for other debug info types if -g2
912 or better. */
913 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
914 output_source_line (file, first);
916 #ifdef LEAF_REG_REMAP
917 if (leaf_function)
918 leaf_renumber_regs (first);
919 #endif
921 /* The Sun386i and perhaps other machines don't work right
922 if the profiling code comes after the prologue. */
923 #ifdef PROFILE_BEFORE_PROLOGUE
924 if (profile_flag)
925 profile_function (file);
926 #endif /* PROFILE_BEFORE_PROLOGUE */
928 #ifdef FUNCTION_PROLOGUE
929 /* First output the function prologue: code to set up the stack frame. */
930 FUNCTION_PROLOGUE (file, get_frame_size ());
931 #endif
933 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
934 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
935 next_block_index = 1;
936 #endif
938 /* If the machine represents the prologue as RTL, the profiling code must
939 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
940 #ifdef HAVE_prologue
941 if (! HAVE_prologue)
942 #endif
943 profile_after_prologue (file);
945 profile_label_no++;
947 /* If we are doing basic block profiling, remember a printable version
948 of the function name. */
949 if (profile_block_flag)
951 char *junk = "function";
952 bb_func_label_num =
953 add_bb_string ((*decl_printable_name) (current_function_decl, &junk), FALSE);
957 static void
958 profile_after_prologue (file)
959 FILE *file;
961 #ifdef FUNCTION_BLOCK_PROFILER
962 if (profile_block_flag)
964 FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
966 #endif /* FUNCTION_BLOCK_PROFILER */
968 #ifndef PROFILE_BEFORE_PROLOGUE
969 if (profile_flag)
970 profile_function (file);
971 #endif /* not PROFILE_BEFORE_PROLOGUE */
974 static void
975 profile_function (file)
976 FILE *file;
978 int align = MIN (BIGGEST_ALIGNMENT, POINTER_SIZE);
979 int sval = current_function_returns_struct;
980 int cxt = current_function_needs_context;
982 data_section ();
983 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
984 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
985 assemble_integer (const0_rtx, POINTER_SIZE / BITS_PER_UNIT, 1);
987 text_section ();
989 #ifdef STRUCT_VALUE_INCOMING_REGNUM
990 if (sval)
991 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
992 #else
993 #ifdef STRUCT_VALUE_REGNUM
994 if (sval)
995 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
996 #endif
997 #endif
999 #if 0
1000 #ifdef STATIC_CHAIN_INCOMING_REGNUM
1001 if (cxt)
1002 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1003 #else
1004 #ifdef STATIC_CHAIN_REGNUM
1005 if (cxt)
1006 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1007 #endif
1008 #endif
1009 #endif /* 0 */
1011 FUNCTION_PROFILER (file, profile_label_no);
1013 #if 0
1014 #ifdef STATIC_CHAIN_INCOMING_REGNUM
1015 if (cxt)
1016 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1017 #else
1018 #ifdef STATIC_CHAIN_REGNUM
1019 if (cxt)
1020 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1021 #endif
1022 #endif
1023 #endif /* 0 */
1025 #ifdef STRUCT_VALUE_INCOMING_REGNUM
1026 if (sval)
1027 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1028 #else
1029 #ifdef STRUCT_VALUE_REGNUM
1030 if (sval)
1031 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1032 #endif
1033 #endif
1036 /* Output assembler code for the end of a function.
1037 For clarity, args are same as those of `final_start_function'
1038 even though not all of them are needed. */
1040 void
1041 final_end_function (first, file, optimize)
1042 rtx first;
1043 FILE *file;
1044 int optimize;
1046 if (app_on)
1048 fprintf (file, ASM_APP_OFF);
1049 app_on = 0;
1052 #ifdef SDB_DEBUGGING_INFO
1053 if (write_symbols == SDB_DEBUG)
1054 sdbout_end_function (high_function_linenum);
1055 #endif
1057 #ifdef DWARF_DEBUGGING_INFO
1058 if (write_symbols == DWARF_DEBUG)
1059 dwarfout_end_function ();
1060 #endif
1062 #ifdef XCOFF_DEBUGGING_INFO
1063 if (write_symbols == XCOFF_DEBUG)
1064 xcoffout_end_function (file, high_function_linenum);
1065 #endif
1067 #ifdef FUNCTION_EPILOGUE
1068 /* Finally, output the function epilogue:
1069 code to restore the stack frame and return to the caller. */
1070 FUNCTION_EPILOGUE (file, get_frame_size ());
1071 #endif
1073 #ifdef SDB_DEBUGGING_INFO
1074 if (write_symbols == SDB_DEBUG)
1075 sdbout_end_epilogue ();
1076 #endif
1078 #ifdef DWARF_DEBUGGING_INFO
1079 if (write_symbols == DWARF_DEBUG)
1080 dwarfout_end_epilogue ();
1081 #endif
1083 #ifdef XCOFF_DEBUGGING_INFO
1084 if (write_symbols == XCOFF_DEBUG)
1085 xcoffout_end_epilogue (file);
1086 #endif
1088 bb_func_label_num = -1; /* not in function, nuke label # */
1090 /* If FUNCTION_EPILOGUE is not defined, then the function body
1091 itself contains return instructions wherever needed. */
1094 /* Add a block to the linked list that remembers the current line/file/function
1095 for basic block profiling. Emit the label in front of the basic block and
1096 the instructions that increment the count field. */
1098 static void
1099 add_bb (file)
1100 FILE *file;
1102 struct bb_list *ptr = (struct bb_list *) permalloc (sizeof (struct bb_list));
1104 /* Add basic block to linked list. */
1105 ptr->next = 0;
1106 ptr->line_num = last_linenum;
1107 ptr->file_label_num = bb_file_label_num;
1108 ptr->func_label_num = bb_func_label_num;
1109 *bb_tail = ptr;
1110 bb_tail = &ptr->next;
1112 /* Enable the table of basic-block use counts
1113 to point at the code it applies to. */
1114 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1116 /* Before first insn of this basic block, increment the
1117 count of times it was entered. */
1118 #ifdef BLOCK_PROFILER
1119 BLOCK_PROFILER (file, count_basic_blocks);
1120 CC_STATUS_INIT;
1121 #endif
1123 new_block = 0;
1124 count_basic_blocks++;
1127 /* Add a string to be used for basic block profiling. */
1129 static int
1130 add_bb_string (string, perm_p)
1131 char *string;
1132 int perm_p;
1134 int len;
1135 struct bb_str *ptr = 0;
1137 if (!string)
1139 string = "<unknown>";
1140 perm_p = TRUE;
1143 /* Allocate a new string if the current string isn't permanent. If
1144 the string is permanent search for the same string in other
1145 allocations. */
1147 len = strlen (string) + 1;
1148 if (!perm_p)
1150 char *p = (char *) permalloc (len);
1151 bcopy (string, p, len);
1152 string = p;
1154 else
1155 for (ptr = sbb_head; ptr != (struct bb_str *)0; ptr = ptr->next)
1156 if (ptr->string == string)
1157 break;
1159 /* Allocate a new string block if we need to. */
1160 if (!ptr)
1162 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1163 ptr->next = 0;
1164 ptr->length = len;
1165 ptr->label_num = sbb_label_num++;
1166 ptr->string = string;
1167 *sbb_tail = ptr;
1168 sbb_tail = &ptr->next;
1171 return ptr->label_num;
1175 /* Output assembler code for some insns: all or part of a function.
1176 For description of args, see `final_start_function', above.
1178 PRESCAN is 1 if we are not really outputting,
1179 just scanning as if we were outputting.
1180 Prescanning deletes and rearranges insns just like ordinary output.
1181 PRESCAN is -2 if we are outputting after having prescanned.
1182 In this case, don't try to delete or rearrange insns
1183 because that has already been done.
1184 Prescanning is done only on certain machines. */
1186 void
1187 final (first, file, optimize, prescan)
1188 rtx first;
1189 FILE *file;
1190 int optimize;
1191 int prescan;
1193 register rtx insn;
1194 int max_line = 0;
1196 last_ignored_compare = 0;
1197 new_block = 1;
1199 /* Make a map indicating which line numbers appear in this function.
1200 When producing SDB debugging info, delete troublesome line number
1201 notes from inlined functions in other files as well as duplicate
1202 line number notes. */
1203 #ifdef SDB_DEBUGGING_INFO
1204 if (write_symbols == SDB_DEBUG)
1206 rtx last = 0;
1207 for (insn = first; insn; insn = NEXT_INSN (insn))
1208 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1210 if ((RTX_INTEGRATED_P (insn)
1211 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1212 || (last != 0
1213 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1214 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1216 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1217 NOTE_SOURCE_FILE (insn) = 0;
1218 continue;
1220 last = insn;
1221 if (NOTE_LINE_NUMBER (insn) > max_line)
1222 max_line = NOTE_LINE_NUMBER (insn);
1225 else
1226 #endif
1228 for (insn = first; insn; insn = NEXT_INSN (insn))
1229 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1230 max_line = NOTE_LINE_NUMBER (insn);
1233 line_note_exists = (char *) oballoc (max_line + 1);
1234 bzero (line_note_exists, max_line + 1);
1236 for (insn = first; insn; insn = NEXT_INSN (insn))
1237 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1238 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1240 init_recog ();
1242 CC_STATUS_INIT;
1244 /* Output the insns. */
1245 for (insn = NEXT_INSN (first); insn;)
1246 insn = final_scan_insn (insn, file, optimize, prescan, 0);
1248 /* Do basic-block profiling here
1249 if the last insn was a conditional branch. */
1250 if (profile_block_flag && new_block)
1251 add_bb (file);
1254 /* The final scan for one insn, INSN.
1255 Args are same as in `final', except that INSN
1256 is the insn being scanned.
1257 Value returned is the next insn to be scanned.
1259 NOPEEPHOLES is the flag to disallow peephole processing (currently
1260 used for within delayed branch sequence output). */
1263 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
1264 rtx insn;
1265 FILE *file;
1266 int optimize;
1267 int prescan;
1268 int nopeepholes;
1270 register int i;
1271 insn_counter++;
1273 /* Ignore deleted insns. These can occur when we split insns (due to a
1274 template of "#") while not optimizing. */
1275 if (INSN_DELETED_P (insn))
1276 return NEXT_INSN (insn);
1278 switch (GET_CODE (insn))
1280 case NOTE:
1281 if (prescan > 0)
1282 break;
1284 /* Align the beginning of a loop, for higher speed
1285 on certain machines. */
1287 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG && optimize > 0)
1289 #ifdef ASM_OUTPUT_LOOP_ALIGN
1290 rtx next = next_nonnote_insn (insn);
1291 if (next && GET_CODE (next) == CODE_LABEL)
1293 ASM_OUTPUT_LOOP_ALIGN (asm_out_file);
1295 #endif
1296 break;
1298 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
1299 break;
1301 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
1303 #ifdef FUNCTION_END_PROLOGUE
1304 FUNCTION_END_PROLOGUE (file);
1305 #endif
1306 profile_after_prologue (file);
1307 break;
1310 #ifdef FUNCTION_BEGIN_EPILOGUE
1311 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
1313 FUNCTION_BEGIN_EPILOGUE (file);
1314 break;
1316 #endif
1318 if (write_symbols == NO_DEBUG)
1319 break;
1320 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
1322 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
1323 /* MIPS stabs require the parameter descriptions to be after the
1324 function entry point rather than before. */
1325 if (write_symbols == SDB_DEBUG)
1326 sdbout_begin_function (last_linenum);
1327 else
1328 #endif
1329 #ifdef DWARF_DEBUGGING_INFO
1330 /* This outputs a marker where the function body starts, so it
1331 must be after the prologue. */
1332 if (write_symbols == DWARF_DEBUG)
1333 dwarfout_begin_function ();
1334 #endif
1335 break;
1337 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
1338 break; /* An insn that was "deleted" */
1339 if (app_on)
1341 fprintf (file, ASM_APP_OFF);
1342 app_on = 0;
1344 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
1345 && (debug_info_level == DINFO_LEVEL_NORMAL
1346 || debug_info_level == DINFO_LEVEL_VERBOSE
1347 #ifdef DWARF_DEBUGGING_INFO
1348 || write_symbols == DWARF_DEBUG
1349 #endif
1353 /* Beginning of a symbol-block. Assign it a sequence number
1354 and push the number onto the stack PENDING_BLOCKS. */
1356 if (block_depth == max_block_depth)
1358 /* PENDING_BLOCKS is full; make it longer. */
1359 max_block_depth *= 2;
1360 pending_blocks
1361 = (int *) xrealloc (pending_blocks,
1362 max_block_depth * sizeof (int));
1364 pending_blocks[block_depth++] = next_block_index;
1366 high_block_linenum = last_linenum;
1368 /* Output debugging info about the symbol-block beginning. */
1370 #ifdef SDB_DEBUGGING_INFO
1371 if (write_symbols == SDB_DEBUG)
1372 sdbout_begin_block (file, last_linenum, next_block_index);
1373 #endif
1374 #ifdef XCOFF_DEBUGGING_INFO
1375 if (write_symbols == XCOFF_DEBUG)
1376 xcoffout_begin_block (file, last_linenum, next_block_index);
1377 #endif
1378 #ifdef DBX_DEBUGGING_INFO
1379 if (write_symbols == DBX_DEBUG)
1380 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
1381 #endif
1382 #ifdef DWARF_DEBUGGING_INFO
1383 if (write_symbols == DWARF_DEBUG && block_depth > 1)
1384 dwarfout_begin_block (next_block_index);
1385 #endif
1387 next_block_index++;
1389 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
1390 && (debug_info_level == DINFO_LEVEL_NORMAL
1391 || debug_info_level == DINFO_LEVEL_VERBOSE
1392 #ifdef DWARF_DEBUGGING_INFO
1393 || write_symbols == DWARF_DEBUG
1394 #endif
1398 /* End of a symbol-block. Pop its sequence number off
1399 PENDING_BLOCKS and output debugging info based on that. */
1401 --block_depth;
1403 #ifdef XCOFF_DEBUGGING_INFO
1404 if (write_symbols == XCOFF_DEBUG && block_depth >= 0)
1405 xcoffout_end_block (file, high_block_linenum,
1406 pending_blocks[block_depth]);
1407 #endif
1408 #ifdef DBX_DEBUGGING_INFO
1409 if (write_symbols == DBX_DEBUG && block_depth >= 0)
1410 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
1411 pending_blocks[block_depth]);
1412 #endif
1413 #ifdef SDB_DEBUGGING_INFO
1414 if (write_symbols == SDB_DEBUG && block_depth >= 0)
1415 sdbout_end_block (file, high_block_linenum,
1416 pending_blocks[block_depth]);
1417 #endif
1418 #ifdef DWARF_DEBUGGING_INFO
1419 if (write_symbols == DWARF_DEBUG && block_depth >= 1)
1420 dwarfout_end_block (pending_blocks[block_depth]);
1421 #endif
1423 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
1424 && (debug_info_level == DINFO_LEVEL_NORMAL
1425 || debug_info_level == DINFO_LEVEL_VERBOSE))
1427 #ifdef DWARF_DEBUGGING_INFO
1428 if (write_symbols == DWARF_DEBUG)
1429 dwarfout_label (insn);
1430 #endif
1432 else if (NOTE_LINE_NUMBER (insn) > 0)
1433 /* This note is a line-number. */
1435 register rtx note;
1437 #if 0 /* This is what we used to do. */
1438 output_source_line (file, insn);
1439 #endif
1440 int note_after = 0;
1442 /* If there is anything real after this note,
1443 output it. If another line note follows, omit this one. */
1444 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
1446 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
1447 break;
1448 /* These types of notes can be significant
1449 so make sure the preceding line number stays. */
1450 else if (GET_CODE (note) == NOTE
1451 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
1452 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
1453 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
1454 break;
1455 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
1457 /* Another line note follows; we can delete this note
1458 if no intervening line numbers have notes elsewhere. */
1459 int num;
1460 for (num = NOTE_LINE_NUMBER (insn) + 1;
1461 num < NOTE_LINE_NUMBER (note);
1462 num++)
1463 if (line_note_exists[num])
1464 break;
1466 if (num >= NOTE_LINE_NUMBER (note))
1467 note_after = 1;
1468 break;
1472 /* Output this line note
1473 if it is the first or the last line note in a row. */
1474 if (!note_after)
1475 output_source_line (file, insn);
1477 break;
1479 case BARRIER:
1480 #ifdef ASM_OUTPUT_ALIGN_CODE
1481 /* Don't litter the assembler output with needless alignments. A
1482 BARRIER will be placed at the end of every function if HAVE_epilogue
1483 is true. */
1484 if (NEXT_INSN (insn))
1485 ASM_OUTPUT_ALIGN_CODE (file);
1486 #endif
1487 break;
1489 case CODE_LABEL:
1490 CC_STATUS_INIT;
1491 if (prescan > 0)
1492 break;
1493 new_block = 1;
1494 #ifdef SDB_DEBUGGING_INFO
1495 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
1496 sdbout_label (insn);
1497 #endif
1498 #ifdef DWARF_DEBUGGING_INFO
1499 if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
1500 dwarfout_label (insn);
1501 #endif
1502 if (app_on)
1504 fprintf (file, ASM_APP_OFF);
1505 app_on = 0;
1507 if (NEXT_INSN (insn) != 0
1508 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
1510 rtx nextbody = PATTERN (NEXT_INSN (insn));
1512 /* If this label is followed by a jump-table,
1513 make sure we put the label in the read-only section. Also
1514 possibly write the label and jump table together. */
1516 if (GET_CODE (nextbody) == ADDR_VEC
1517 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1519 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1520 readonly_data_section ();
1521 #ifdef READONLY_DATA_SECTION
1522 ASM_OUTPUT_ALIGN (file,
1523 exact_log2 (BIGGEST_ALIGNMENT
1524 / BITS_PER_UNIT));
1525 #endif /* READONLY_DATA_SECTION */
1526 #else /* JUMP_TABLES_IN_TEXT_SECTION */
1527 function_section (current_function_decl);
1528 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
1529 #ifdef ASM_OUTPUT_CASE_LABEL
1530 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
1531 NEXT_INSN (insn));
1532 #else
1533 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1534 #endif
1535 break;
1539 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1540 break;
1542 default:
1544 register rtx body = PATTERN (insn);
1545 int insn_code_number;
1546 char *template;
1547 rtx note;
1549 /* An INSN, JUMP_INSN or CALL_INSN.
1550 First check for special kinds that recog doesn't recognize. */
1552 if (GET_CODE (body) == USE /* These are just declarations */
1553 || GET_CODE (body) == CLOBBER)
1554 break;
1556 #ifdef HAVE_cc0
1557 /* If there is a REG_CC_SETTER note on this insn, it means that
1558 the setting of the condition code was done in the delay slot
1559 of the insn that branched here. So recover the cc status
1560 from the insn that set it. */
1562 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1563 if (note)
1565 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
1566 cc_prev_status = cc_status;
1568 #endif
1570 /* Detect insns that are really jump-tables
1571 and output them as such. */
1573 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1575 register int vlen, idx;
1577 if (prescan > 0)
1578 break;
1580 if (app_on)
1582 fprintf (file, ASM_APP_OFF);
1583 app_on = 0;
1586 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
1587 for (idx = 0; idx < vlen; idx++)
1589 if (GET_CODE (body) == ADDR_VEC)
1591 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
1592 ASM_OUTPUT_ADDR_VEC_ELT
1593 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
1594 #else
1595 abort ();
1596 #endif
1598 else
1600 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
1601 ASM_OUTPUT_ADDR_DIFF_ELT
1602 (file,
1603 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
1604 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
1605 #else
1606 abort ();
1607 #endif
1610 #ifdef ASM_OUTPUT_CASE_END
1611 ASM_OUTPUT_CASE_END (file,
1612 CODE_LABEL_NUMBER (PREV_INSN (insn)),
1613 insn);
1614 #endif
1616 function_section (current_function_decl);
1618 break;
1621 /* Do basic-block profiling when we reach a new block.
1622 Done here to avoid jump tables. */
1623 if (profile_block_flag && new_block)
1624 add_bb (file);
1626 if (GET_CODE (body) == ASM_INPUT)
1628 /* There's no telling what that did to the condition codes. */
1629 CC_STATUS_INIT;
1630 if (prescan > 0)
1631 break;
1632 if (! app_on)
1634 fprintf (file, ASM_APP_ON);
1635 app_on = 1;
1637 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
1638 break;
1641 /* Detect `asm' construct with operands. */
1642 if (asm_noperands (body) >= 0)
1644 int noperands = asm_noperands (body);
1645 rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
1646 char *string;
1648 /* There's no telling what that did to the condition codes. */
1649 CC_STATUS_INIT;
1650 if (prescan > 0)
1651 break;
1653 if (! app_on)
1655 fprintf (file, ASM_APP_ON);
1656 app_on = 1;
1659 /* Get out the operand values. */
1660 string = decode_asm_operands (body, ops, NULL_PTR,
1661 NULL_PTR, NULL_PTR);
1662 /* Inhibit aborts on what would otherwise be compiler bugs. */
1663 insn_noperands = noperands;
1664 this_is_asm_operands = insn;
1666 /* Output the insn using them. */
1667 output_asm_insn (string, ops);
1668 this_is_asm_operands = 0;
1669 break;
1672 if (prescan <= 0 && app_on)
1674 fprintf (file, ASM_APP_OFF);
1675 app_on = 0;
1678 if (GET_CODE (body) == SEQUENCE)
1680 /* A delayed-branch sequence */
1681 register int i;
1682 rtx next;
1684 if (prescan > 0)
1685 break;
1686 final_sequence = body;
1688 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
1689 force the restoration of a comparison that was previously
1690 thought unnecessary. If that happens, cancel this sequence
1691 and cause that insn to be restored. */
1693 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
1694 if (next != XVECEXP (body, 0, 1))
1696 final_sequence = 0;
1697 return next;
1700 for (i = 1; i < XVECLEN (body, 0); i++)
1702 rtx insn = XVECEXP (body, 0, i);
1703 rtx next = NEXT_INSN (insn);
1704 /* We loop in case any instruction in a delay slot gets
1705 split. */
1707 insn = final_scan_insn (insn, file, 0, prescan, 1);
1708 while (insn != next);
1710 #ifdef DBR_OUTPUT_SEQEND
1711 DBR_OUTPUT_SEQEND (file);
1712 #endif
1713 final_sequence = 0;
1715 /* If the insn requiring the delay slot was a CALL_INSN, the
1716 insns in the delay slot are actually executed before the
1717 called function. Hence we don't preserve any CC-setting
1718 actions in these insns and the CC must be marked as being
1719 clobbered by the function. */
1720 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
1721 CC_STATUS_INIT;
1723 /* Following a conditional branch sequence, we have a new basic
1724 block. */
1725 if (profile_block_flag)
1727 rtx insn = XVECEXP (body, 0, 0);
1728 rtx body = PATTERN (insn);
1730 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1731 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1732 || (GET_CODE (insn) == JUMP_INSN
1733 && GET_CODE (body) == PARALLEL
1734 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1735 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
1736 new_block = 1;
1738 break;
1741 /* We have a real machine instruction as rtl. */
1743 body = PATTERN (insn);
1745 #ifdef HAVE_cc0
1746 /* Check for redundant test and compare instructions
1747 (when the condition codes are already set up as desired).
1748 This is done only when optimizing; if not optimizing,
1749 it should be possible for the user to alter a variable
1750 with the debugger in between statements
1751 and the next statement should reexamine the variable
1752 to compute the condition codes. */
1754 if (optimize
1755 && GET_CODE (body) == SET
1756 && GET_CODE (SET_DEST (body)) == CC0
1757 && insn != last_ignored_compare)
1759 if (GET_CODE (SET_SRC (body)) == SUBREG)
1760 SET_SRC (body) = alter_subreg (SET_SRC (body));
1761 else if (GET_CODE (SET_SRC (body)) == COMPARE)
1763 if (GET_CODE (XEXP (SET_SRC (body), 0)) == SUBREG)
1764 XEXP (SET_SRC (body), 0)
1765 = alter_subreg (XEXP (SET_SRC (body), 0));
1766 if (GET_CODE (XEXP (SET_SRC (body), 1)) == SUBREG)
1767 XEXP (SET_SRC (body), 1)
1768 = alter_subreg (XEXP (SET_SRC (body), 1));
1770 if ((cc_status.value1 != 0
1771 && rtx_equal_p (SET_SRC (body), cc_status.value1))
1772 || (cc_status.value2 != 0
1773 && rtx_equal_p (SET_SRC (body), cc_status.value2)))
1775 /* Don't delete insn if it has an addressing side-effect. */
1776 if (! FIND_REG_INC_NOTE (insn, 0)
1777 /* or if anything in it is volatile. */
1778 && ! volatile_refs_p (PATTERN (insn)))
1780 /* We don't really delete the insn; just ignore it. */
1781 last_ignored_compare = insn;
1782 break;
1786 #endif
1788 /* Following a conditional branch, we have a new basic block.
1789 But if we are inside a sequence, the new block starts after the
1790 last insn of the sequence. */
1791 if (profile_block_flag && final_sequence == 0
1792 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1793 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1794 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
1795 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1796 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
1797 new_block = 1;
1799 #ifndef STACK_REGS
1800 /* Don't bother outputting obvious no-ops, even without -O.
1801 This optimization is fast and doesn't interfere with debugging.
1802 Don't do this if the insn is in a delay slot, since this
1803 will cause an improper number of delay insns to be written. */
1804 if (final_sequence == 0
1805 && prescan >= 0
1806 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
1807 && GET_CODE (SET_SRC (body)) == REG
1808 && GET_CODE (SET_DEST (body)) == REG
1809 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
1810 break;
1811 #endif
1813 #ifdef HAVE_cc0
1814 /* If this is a conditional branch, maybe modify it
1815 if the cc's are in a nonstandard state
1816 so that it accomplishes the same thing that it would
1817 do straightforwardly if the cc's were set up normally. */
1819 if (cc_status.flags != 0
1820 && GET_CODE (insn) == JUMP_INSN
1821 && GET_CODE (body) == SET
1822 && SET_DEST (body) == pc_rtx
1823 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
1824 && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
1825 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
1826 /* This is done during prescan; it is not done again
1827 in final scan when prescan has been done. */
1828 && prescan >= 0)
1830 /* This function may alter the contents of its argument
1831 and clear some of the cc_status.flags bits.
1832 It may also return 1 meaning condition now always true
1833 or -1 meaning condition now always false
1834 or 2 meaning condition nontrivial but altered. */
1835 register int result = alter_cond (XEXP (SET_SRC (body), 0));
1836 /* If condition now has fixed value, replace the IF_THEN_ELSE
1837 with its then-operand or its else-operand. */
1838 if (result == 1)
1839 SET_SRC (body) = XEXP (SET_SRC (body), 1);
1840 if (result == -1)
1841 SET_SRC (body) = XEXP (SET_SRC (body), 2);
1843 /* The jump is now either unconditional or a no-op.
1844 If it has become a no-op, don't try to output it.
1845 (It would not be recognized.) */
1846 if (SET_SRC (body) == pc_rtx)
1848 PUT_CODE (insn, NOTE);
1849 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1850 NOTE_SOURCE_FILE (insn) = 0;
1851 break;
1853 else if (GET_CODE (SET_SRC (body)) == RETURN)
1854 /* Replace (set (pc) (return)) with (return). */
1855 PATTERN (insn) = body = SET_SRC (body);
1857 /* Rerecognize the instruction if it has changed. */
1858 if (result != 0)
1859 INSN_CODE (insn) = -1;
1862 /* Make same adjustments to instructions that examine the
1863 condition codes without jumping (if this machine has them). */
1865 if (cc_status.flags != 0
1866 && GET_CODE (body) == SET)
1868 switch (GET_CODE (SET_SRC (body)))
1870 case GTU:
1871 case GT:
1872 case LTU:
1873 case LT:
1874 case GEU:
1875 case GE:
1876 case LEU:
1877 case LE:
1878 case EQ:
1879 case NE:
1881 register int result;
1882 if (XEXP (SET_SRC (body), 0) != cc0_rtx)
1883 break;
1884 result = alter_cond (SET_SRC (body));
1885 if (result == 1)
1886 validate_change (insn, &SET_SRC (body), const_true_rtx, 0);
1887 else if (result == -1)
1888 validate_change (insn, &SET_SRC (body), const0_rtx, 0);
1889 else if (result == 2)
1890 INSN_CODE (insn) = -1;
1894 #endif
1896 /* Do machine-specific peephole optimizations if desired. */
1898 if (optimize && !flag_no_peephole && !nopeepholes)
1900 rtx next = peephole (insn);
1901 /* When peepholing, if there were notes within the peephole,
1902 emit them before the peephole. */
1903 if (next != 0 && next != NEXT_INSN (insn))
1905 rtx prev = PREV_INSN (insn);
1906 rtx note;
1908 for (note = NEXT_INSN (insn); note != next;
1909 note = NEXT_INSN (note))
1910 final_scan_insn (note, file, optimize, prescan, nopeepholes);
1912 /* In case this is prescan, put the notes
1913 in proper position for later rescan. */
1914 note = NEXT_INSN (insn);
1915 PREV_INSN (note) = prev;
1916 NEXT_INSN (prev) = note;
1917 NEXT_INSN (PREV_INSN (next)) = insn;
1918 PREV_INSN (insn) = PREV_INSN (next);
1919 NEXT_INSN (insn) = next;
1920 PREV_INSN (next) = insn;
1923 /* PEEPHOLE might have changed this. */
1924 body = PATTERN (insn);
1927 /* Try to recognize the instruction.
1928 If successful, verify that the operands satisfy the
1929 constraints for the instruction. Crash if they don't,
1930 since `reload' should have changed them so that they do. */
1932 insn_code_number = recog_memoized (insn);
1933 insn_extract (insn);
1934 for (i = 0; i < insn_n_operands[insn_code_number]; i++)
1936 if (GET_CODE (recog_operand[i]) == SUBREG)
1937 recog_operand[i] = alter_subreg (recog_operand[i]);
1938 else if (GET_CODE (recog_operand[i]) == PLUS
1939 || GET_CODE (recog_operand[i]) == MULT)
1940 recog_operand[i] = walk_alter_subreg (recog_operand[i]);
1943 for (i = 0; i < insn_n_dups[insn_code_number]; i++)
1945 if (GET_CODE (*recog_dup_loc[i]) == SUBREG)
1946 *recog_dup_loc[i] = alter_subreg (*recog_dup_loc[i]);
1947 else if (GET_CODE (*recog_dup_loc[i]) == PLUS
1948 || GET_CODE (*recog_dup_loc[i]) == MULT)
1949 *recog_dup_loc[i] = walk_alter_subreg (*recog_dup_loc[i]);
1952 #ifdef REGISTER_CONSTRAINTS
1953 if (! constrain_operands (insn_code_number, 1))
1954 fatal_insn_not_found (insn);
1955 #endif
1957 /* Some target machines need to prescan each insn before
1958 it is output. */
1960 #ifdef FINAL_PRESCAN_INSN
1961 FINAL_PRESCAN_INSN (insn, recog_operand,
1962 insn_n_operands[insn_code_number]);
1963 #endif
1965 #ifdef HAVE_cc0
1966 cc_prev_status = cc_status;
1968 /* Update `cc_status' for this instruction.
1969 The instruction's output routine may change it further.
1970 If the output routine for a jump insn needs to depend
1971 on the cc status, it should look at cc_prev_status. */
1973 NOTICE_UPDATE_CC (body, insn);
1974 #endif
1976 debug_insn = insn;
1978 /* If the proper template needs to be chosen by some C code,
1979 run that code and get the real template. */
1981 template = insn_template[insn_code_number];
1982 if (template == 0)
1984 template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
1986 /* If the C code returns 0, it means that it is a jump insn
1987 which follows a deleted test insn, and that test insn
1988 needs to be reinserted. */
1989 if (template == 0)
1991 if (prev_nonnote_insn (insn) != last_ignored_compare)
1992 abort ();
1993 new_block = 0;
1994 return prev_nonnote_insn (insn);
1998 /* If the template is the string "#", it means that this insn must
1999 be split. */
2000 if (template[0] == '#' && template[1] == '\0')
2002 rtx new = try_split (body, insn, 0);
2004 /* If we didn't split the insn, go away. */
2005 if (new == insn && PATTERN (new) == body)
2006 abort ();
2008 new_block = 0;
2009 return new;
2012 if (prescan > 0)
2013 break;
2015 /* Output assembler code from the template. */
2017 output_asm_insn (template, recog_operand);
2019 #if 0
2020 /* It's not at all clear why we did this and doing so interferes
2021 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2022 with this out. */
2024 /* Mark this insn as having been output. */
2025 INSN_DELETED_P (insn) = 1;
2026 #endif
2028 debug_insn = 0;
2031 return NEXT_INSN (insn);
2034 /* Output debugging info to the assembler file FILE
2035 based on the NOTE-insn INSN, assumed to be a line number. */
2037 static void
2038 output_source_line (file, insn)
2039 FILE *file;
2040 rtx insn;
2042 register char *filename = NOTE_SOURCE_FILE (insn);
2044 /* Remember filename for basic block profiling.
2045 Filenames are allocated on the permanent obstack
2046 or are passed in ARGV, so we don't have to save
2047 the string. */
2049 if (profile_block_flag && last_filename != filename)
2050 bb_file_label_num = add_bb_string (filename, TRUE);
2052 last_filename = filename;
2053 last_linenum = NOTE_LINE_NUMBER (insn);
2054 high_block_linenum = MAX (last_linenum, high_block_linenum);
2055 high_function_linenum = MAX (last_linenum, high_function_linenum);
2057 if (write_symbols != NO_DEBUG)
2059 #ifdef SDB_DEBUGGING_INFO
2060 if (write_symbols == SDB_DEBUG
2061 #if 0 /* People like having line numbers even in wrong file! */
2062 /* COFF can't handle multiple source files--lose, lose. */
2063 && !strcmp (filename, main_input_filename)
2064 #endif
2065 /* COFF relative line numbers must be positive. */
2066 && last_linenum > sdb_begin_function_line)
2068 #ifdef ASM_OUTPUT_SOURCE_LINE
2069 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
2070 #else
2071 fprintf (file, "\t.ln\t%d\n",
2072 ((sdb_begin_function_line > -1)
2073 ? last_linenum - sdb_begin_function_line : 1));
2074 #endif
2076 #endif
2078 #if defined (DBX_DEBUGGING_INFO)
2079 if (write_symbols == DBX_DEBUG)
2080 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
2081 #endif
2083 #if defined (XCOFF_DEBUGGING_INFO)
2084 if (write_symbols == XCOFF_DEBUG)
2085 xcoffout_source_line (file, filename, insn);
2086 #endif
2088 #ifdef DWARF_DEBUGGING_INFO
2089 if (write_symbols == DWARF_DEBUG)
2090 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
2091 #endif
2095 /* If X is a SUBREG, replace it with a REG or a MEM,
2096 based on the thing it is a subreg of. */
2099 alter_subreg (x)
2100 register rtx x;
2102 register rtx y = SUBREG_REG (x);
2103 if (GET_CODE (y) == SUBREG)
2104 y = alter_subreg (y);
2106 if (GET_CODE (y) == REG)
2108 /* If the containing reg really gets a hard reg, so do we. */
2109 PUT_CODE (x, REG);
2110 REGNO (x) = REGNO (y) + SUBREG_WORD (x);
2112 else if (GET_CODE (y) == MEM)
2114 register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2115 if (BYTES_BIG_ENDIAN)
2116 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
2117 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
2118 PUT_CODE (x, MEM);
2119 MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
2120 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
2123 return x;
2126 /* Do alter_subreg on all the SUBREGs contained in X. */
2128 static rtx
2129 walk_alter_subreg (x)
2130 rtx x;
2132 switch (GET_CODE (x))
2134 case PLUS:
2135 case MULT:
2136 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2137 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
2138 break;
2140 case MEM:
2141 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2142 break;
2144 case SUBREG:
2145 return alter_subreg (x);
2148 return x;
2151 #ifdef HAVE_cc0
2153 /* Given BODY, the body of a jump instruction, alter the jump condition
2154 as required by the bits that are set in cc_status.flags.
2155 Not all of the bits there can be handled at this level in all cases.
2157 The value is normally 0.
2158 1 means that the condition has become always true.
2159 -1 means that the condition has become always false.
2160 2 means that COND has been altered. */
2162 static int
2163 alter_cond (cond)
2164 register rtx cond;
2166 int value = 0;
2168 if (cc_status.flags & CC_REVERSED)
2170 value = 2;
2171 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
2174 if (cc_status.flags & CC_INVERTED)
2176 value = 2;
2177 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
2180 if (cc_status.flags & CC_NOT_POSITIVE)
2181 switch (GET_CODE (cond))
2183 case LE:
2184 case LEU:
2185 case GEU:
2186 /* Jump becomes unconditional. */
2187 return 1;
2189 case GT:
2190 case GTU:
2191 case LTU:
2192 /* Jump becomes no-op. */
2193 return -1;
2195 case GE:
2196 PUT_CODE (cond, EQ);
2197 value = 2;
2198 break;
2200 case LT:
2201 PUT_CODE (cond, NE);
2202 value = 2;
2203 break;
2206 if (cc_status.flags & CC_NOT_NEGATIVE)
2207 switch (GET_CODE (cond))
2209 case GE:
2210 case GEU:
2211 /* Jump becomes unconditional. */
2212 return 1;
2214 case LT:
2215 case LTU:
2216 /* Jump becomes no-op. */
2217 return -1;
2219 case LE:
2220 case LEU:
2221 PUT_CODE (cond, EQ);
2222 value = 2;
2223 break;
2225 case GT:
2226 case GTU:
2227 PUT_CODE (cond, NE);
2228 value = 2;
2229 break;
2232 if (cc_status.flags & CC_NO_OVERFLOW)
2233 switch (GET_CODE (cond))
2235 case GEU:
2236 /* Jump becomes unconditional. */
2237 return 1;
2239 case LEU:
2240 PUT_CODE (cond, EQ);
2241 value = 2;
2242 break;
2244 case GTU:
2245 PUT_CODE (cond, NE);
2246 value = 2;
2247 break;
2249 case LTU:
2250 /* Jump becomes no-op. */
2251 return -1;
2254 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
2255 switch (GET_CODE (cond))
2257 case LE:
2258 case LEU:
2259 case GE:
2260 case GEU:
2261 case LT:
2262 case LTU:
2263 case GT:
2264 case GTU:
2265 abort ();
2267 case NE:
2268 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
2269 value = 2;
2270 break;
2272 case EQ:
2273 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
2274 value = 2;
2275 break;
2278 if (cc_status.flags & CC_NOT_SIGNED)
2279 /* The flags are valid if signed condition operators are converted
2280 to unsigned. */
2281 switch (GET_CODE (cond))
2283 case LE:
2284 PUT_CODE (cond, LEU);
2285 value = 2;
2286 break;
2288 case LT:
2289 PUT_CODE (cond, LTU);
2290 value = 2;
2291 break;
2293 case GT:
2294 PUT_CODE (cond, GTU);
2295 value = 2;
2296 break;
2298 case GE:
2299 PUT_CODE (cond, GEU);
2300 value = 2;
2301 break;
2304 return value;
2306 #endif
2308 /* Report inconsistency between the assembler template and the operands.
2309 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
2311 void
2312 output_operand_lossage (str)
2313 char *str;
2315 if (this_is_asm_operands)
2316 error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
2317 else
2318 abort ();
2321 /* Output of assembler code from a template, and its subroutines. */
2323 /* Output text from TEMPLATE to the assembler output file,
2324 obeying %-directions to substitute operands taken from
2325 the vector OPERANDS.
2327 %N (for N a digit) means print operand N in usual manner.
2328 %lN means require operand N to be a CODE_LABEL or LABEL_REF
2329 and print the label name with no punctuation.
2330 %cN means require operand N to be a constant
2331 and print the constant expression with no punctuation.
2332 %aN means expect operand N to be a memory address
2333 (not a memory reference!) and print a reference
2334 to that address.
2335 %nN means expect operand N to be a constant
2336 and print a constant expression for minus the value
2337 of the operand, with no other punctuation. */
2339 static void
2340 output_asm_name ()
2342 if (flag_print_asm_name)
2344 /* Annotate the assembly with a comment describing the pattern and
2345 alternative used. */
2346 if (debug_insn)
2348 register int num = INSN_CODE (debug_insn);
2349 fprintf (asm_out_file, " %s %d %s",
2350 ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
2351 if (insn_n_alternatives[num] > 1)
2352 fprintf (asm_out_file, "/%d", which_alternative + 1);
2354 /* Clear this so only the first assembler insn
2355 of any rtl insn will get the special comment for -dp. */
2356 debug_insn = 0;
2361 void
2362 output_asm_insn (template, operands)
2363 char *template;
2364 rtx *operands;
2366 register char *p;
2367 register int c, i;
2369 /* An insn may return a null string template
2370 in a case where no assembler code is needed. */
2371 if (*template == 0)
2372 return;
2374 p = template;
2375 putc ('\t', asm_out_file);
2377 #ifdef ASM_OUTPUT_OPCODE
2378 ASM_OUTPUT_OPCODE (asm_out_file, p);
2379 #endif
2381 while (c = *p++)
2382 switch (c)
2384 case '\n':
2385 output_asm_name ();
2386 putc (c, asm_out_file);
2387 #ifdef ASM_OUTPUT_OPCODE
2388 while ((c = *p) == '\t')
2390 putc (c, asm_out_file);
2391 p++;
2393 ASM_OUTPUT_OPCODE (asm_out_file, p);
2394 #endif
2395 break;
2397 #ifdef ASSEMBLER_DIALECT
2398 case '{':
2399 /* If we want the first dialect, do nothing. Otherwise, skip
2400 DIALECT_NUMBER of strings ending with '|'. */
2401 for (i = 0; i < dialect_number; i++)
2403 while (*p && *p++ != '|')
2406 if (*p == '|')
2407 p++;
2409 break;
2411 case '|':
2412 /* Skip to close brace. */
2413 while (*p && *p++ != '}')
2415 break;
2417 case '}':
2418 break;
2419 #endif
2421 case '%':
2422 /* %% outputs a single %. */
2423 if (*p == '%')
2425 p++;
2426 putc (c, asm_out_file);
2428 /* %= outputs a number which is unique to each insn in the entire
2429 compilation. This is useful for making local labels that are
2430 referred to more than once in a given insn. */
2431 else if (*p == '=')
2433 p++;
2434 fprintf (asm_out_file, "%d", insn_counter);
2436 /* % followed by a letter and some digits
2437 outputs an operand in a special way depending on the letter.
2438 Letters `acln' are implemented directly.
2439 Other letters are passed to `output_operand' so that
2440 the PRINT_OPERAND macro can define them. */
2441 else if ((*p >= 'a' && *p <= 'z')
2442 || (*p >= 'A' && *p <= 'Z'))
2444 int letter = *p++;
2445 c = atoi (p);
2447 if (! (*p >= '0' && *p <= '9'))
2448 output_operand_lossage ("operand number missing after %-letter");
2449 else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2450 output_operand_lossage ("operand number out of range");
2451 else if (letter == 'l')
2452 output_asm_label (operands[c]);
2453 else if (letter == 'a')
2454 output_address (operands[c]);
2455 else if (letter == 'c')
2457 if (CONSTANT_ADDRESS_P (operands[c]))
2458 output_addr_const (asm_out_file, operands[c]);
2459 else
2460 output_operand (operands[c], 'c');
2462 else if (letter == 'n')
2464 if (GET_CODE (operands[c]) == CONST_INT)
2465 fprintf (asm_out_file,
2466 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2467 "%d",
2468 #else
2469 "%ld",
2470 #endif
2471 - INTVAL (operands[c]));
2472 else
2474 putc ('-', asm_out_file);
2475 output_addr_const (asm_out_file, operands[c]);
2478 else
2479 output_operand (operands[c], letter);
2481 while ((c = *p) >= '0' && c <= '9') p++;
2483 /* % followed by a digit outputs an operand the default way. */
2484 else if (*p >= '0' && *p <= '9')
2486 c = atoi (p);
2487 if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2488 output_operand_lossage ("operand number out of range");
2489 else
2490 output_operand (operands[c], 0);
2491 while ((c = *p) >= '0' && c <= '9') p++;
2493 /* % followed by punctuation: output something for that
2494 punctuation character alone, with no operand.
2495 The PRINT_OPERAND macro decides what is actually done. */
2496 #ifdef PRINT_OPERAND_PUNCT_VALID_P
2497 else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
2498 output_operand (NULL_RTX, *p++);
2499 #endif
2500 else
2501 output_operand_lossage ("invalid %%-code");
2502 break;
2504 default:
2505 putc (c, asm_out_file);
2508 output_asm_name ();
2510 putc ('\n', asm_out_file);
2513 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
2515 void
2516 output_asm_label (x)
2517 rtx x;
2519 char buf[256];
2521 if (GET_CODE (x) == LABEL_REF)
2522 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2523 else if (GET_CODE (x) == CODE_LABEL)
2524 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2525 else
2526 output_operand_lossage ("`%l' operand isn't a label");
2528 assemble_name (asm_out_file, buf);
2531 /* Print operand X using machine-dependent assembler syntax.
2532 The macro PRINT_OPERAND is defined just to control this function.
2533 CODE is a non-digit that preceded the operand-number in the % spec,
2534 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
2535 between the % and the digits.
2536 When CODE is a non-letter, X is 0.
2538 The meanings of the letters are machine-dependent and controlled
2539 by PRINT_OPERAND. */
2541 static void
2542 output_operand (x, code)
2543 rtx x;
2544 int code;
2546 if (x && GET_CODE (x) == SUBREG)
2547 x = alter_subreg (x);
2549 /* If X is a pseudo-register, abort now rather than writing trash to the
2550 assembler file. */
2552 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2553 abort ();
2555 PRINT_OPERAND (asm_out_file, x, code);
2558 /* Print a memory reference operand for address X
2559 using machine-dependent assembler syntax.
2560 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
2562 void
2563 output_address (x)
2564 rtx x;
2566 walk_alter_subreg (x);
2567 PRINT_OPERAND_ADDRESS (asm_out_file, x);
2570 /* Print an integer constant expression in assembler syntax.
2571 Addition and subtraction are the only arithmetic
2572 that may appear in these expressions. */
2574 void
2575 output_addr_const (file, x)
2576 FILE *file;
2577 rtx x;
2579 char buf[256];
2581 restart:
2582 switch (GET_CODE (x))
2584 case PC:
2585 if (flag_pic)
2586 putc ('.', file);
2587 else
2588 abort ();
2589 break;
2591 case SYMBOL_REF:
2592 assemble_name (file, XSTR (x, 0));
2593 break;
2595 case LABEL_REF:
2596 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2597 assemble_name (file, buf);
2598 break;
2600 case CODE_LABEL:
2601 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2602 assemble_name (file, buf);
2603 break;
2605 case CONST_INT:
2606 fprintf (file,
2607 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2608 "%d",
2609 #else
2610 "%ld",
2611 #endif
2612 INTVAL (x));
2613 break;
2615 case CONST:
2616 /* This used to output parentheses around the expression,
2617 but that does not work on the 386 (either ATT or BSD assembler). */
2618 output_addr_const (file, XEXP (x, 0));
2619 break;
2621 case CONST_DOUBLE:
2622 if (GET_MODE (x) == VOIDmode)
2624 /* We can use %d if the number is one word and positive. */
2625 if (CONST_DOUBLE_HIGH (x))
2626 fprintf (file,
2627 #if HOST_BITS_PER_WIDE_INT == 64
2628 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2629 "0x%lx%016lx",
2630 #else
2631 "0x%x%016x",
2632 #endif
2633 #else
2634 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2635 "0x%lx%08lx",
2636 #else
2637 "0x%x%08x",
2638 #endif
2639 #endif
2640 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2641 else if (CONST_DOUBLE_LOW (x) < 0)
2642 fprintf (file,
2643 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2644 "0x%x",
2645 #else
2646 "0x%lx",
2647 #endif
2648 CONST_DOUBLE_LOW (x));
2649 else
2650 fprintf (file,
2651 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2652 "%d",
2653 #else
2654 "%ld",
2655 #endif
2656 CONST_DOUBLE_LOW (x));
2658 else
2659 /* We can't handle floating point constants;
2660 PRINT_OPERAND must handle them. */
2661 output_operand_lossage ("floating constant misused");
2662 break;
2664 case PLUS:
2665 /* Some assemblers need integer constants to appear last (eg masm). */
2666 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2668 output_addr_const (file, XEXP (x, 1));
2669 if (INTVAL (XEXP (x, 0)) >= 0)
2670 fprintf (file, "+");
2671 output_addr_const (file, XEXP (x, 0));
2673 else
2675 output_addr_const (file, XEXP (x, 0));
2676 if (INTVAL (XEXP (x, 1)) >= 0)
2677 fprintf (file, "+");
2678 output_addr_const (file, XEXP (x, 1));
2680 break;
2682 case MINUS:
2683 /* Avoid outputting things like x-x or x+5-x,
2684 since some assemblers can't handle that. */
2685 x = simplify_subtraction (x);
2686 if (GET_CODE (x) != MINUS)
2687 goto restart;
2689 output_addr_const (file, XEXP (x, 0));
2690 fprintf (file, "-");
2691 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2692 && INTVAL (XEXP (x, 1)) < 0)
2694 fprintf (file, ASM_OPEN_PAREN);
2695 output_addr_const (file, XEXP (x, 1));
2696 fprintf (file, ASM_CLOSE_PAREN);
2698 else
2699 output_addr_const (file, XEXP (x, 1));
2700 break;
2702 case ZERO_EXTEND:
2703 case SIGN_EXTEND:
2704 output_addr_const (file, XEXP (x, 0));
2705 break;
2707 default:
2708 output_operand_lossage ("invalid expression as operand");
2712 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
2713 %R prints the value of REGISTER_PREFIX.
2714 %L prints the value of LOCAL_LABEL_PREFIX.
2715 %U prints the value of USER_LABEL_PREFIX.
2716 %I prints the value of IMMEDIATE_PREFIX.
2717 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
2718 Also supported are %d, %x, %s, %e, %f, %g and %%.
2720 We handle alternate assembler dialects here, just like output_asm_insn. */
2722 void
2723 asm_fprintf VPROTO((FILE *file, char *p, ...))
2725 #ifndef __STDC__
2726 FILE *file;
2727 char *p;
2728 #endif
2729 va_list argptr;
2730 char buf[10];
2731 char *q, c;
2732 int i;
2734 VA_START (argptr, p);
2736 #ifndef __STDC__
2737 file = va_arg (argptr, FILE*);
2738 p = va_arg (argptr, char*);
2739 #endif
2741 buf[0] = '%';
2743 while (c = *p++)
2744 switch (c)
2746 #ifdef ASSEMBLER_DIALECT
2747 case '{':
2748 /* If we want the first dialect, do nothing. Otherwise, skip
2749 DIALECT_NUMBER of strings ending with '|'. */
2750 for (i = 0; i < dialect_number; i++)
2752 while (*p && *p++ != '|')
2755 if (*p == '|')
2756 p++;
2758 break;
2760 case '|':
2761 /* Skip to close brace. */
2762 while (*p && *p++ != '}')
2764 break;
2766 case '}':
2767 break;
2768 #endif
2770 case '%':
2771 c = *p++;
2772 q = &buf[1];
2773 while ((c >= '0' && c <= '9') || c == '.')
2775 *q++ = c;
2776 c = *p++;
2778 switch (c)
2780 case '%':
2781 fprintf (file, "%%");
2782 break;
2784 case 'd': case 'i': case 'u':
2785 case 'x': case 'p': case 'X':
2786 case 'o':
2787 *q++ = c;
2788 *q = 0;
2789 fprintf (file, buf, va_arg (argptr, int));
2790 break;
2792 case 'w':
2793 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
2794 but we do not check for those cases. It means that the value
2795 is a HOST_WIDE_INT, which may be either `int' or `long'. */
2797 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
2798 *q++ = 'l';
2799 #endif
2801 *q++ = *p++;
2802 *q = 0;
2803 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
2804 break;
2806 case 'l':
2807 *q++ = c;
2808 *q++ = *p++;
2809 *q = 0;
2810 fprintf (file, buf, va_arg (argptr, long));
2811 break;
2813 case 'e':
2814 case 'f':
2815 case 'g':
2816 *q++ = c;
2817 *q = 0;
2818 fprintf (file, buf, va_arg (argptr, double));
2819 break;
2821 case 's':
2822 *q++ = c;
2823 *q = 0;
2824 fprintf (file, buf, va_arg (argptr, char *));
2825 break;
2827 case 'O':
2828 #ifdef ASM_OUTPUT_OPCODE
2829 ASM_OUTPUT_OPCODE (asm_out_file, p);
2830 #endif
2831 break;
2833 case 'R':
2834 #ifdef REGISTER_PREFIX
2835 fprintf (file, "%s", REGISTER_PREFIX);
2836 #endif
2837 break;
2839 case 'I':
2840 #ifdef IMMEDIATE_PREFIX
2841 fprintf (file, "%s", IMMEDIATE_PREFIX);
2842 #endif
2843 break;
2845 case 'L':
2846 #ifdef LOCAL_LABEL_PREFIX
2847 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
2848 #endif
2849 break;
2851 case 'U':
2852 #ifdef USER_LABEL_PREFIX
2853 fprintf (file, "%s", USER_LABEL_PREFIX);
2854 #endif
2855 break;
2857 default:
2858 abort ();
2860 break;
2862 default:
2863 fputc (c, file);
2867 /* Split up a CONST_DOUBLE or integer constant rtx
2868 into two rtx's for single words,
2869 storing in *FIRST the word that comes first in memory in the target
2870 and in *SECOND the other. */
2872 void
2873 split_double (value, first, second)
2874 rtx value;
2875 rtx *first, *second;
2877 if (GET_CODE (value) == CONST_INT)
2879 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
2881 /* In this case the CONST_INT holds both target words.
2882 Extract the bits from it into two word-sized pieces. */
2883 rtx low, high;
2884 HOST_WIDE_INT word_mask;
2885 /* Avoid warnings for shift count >= BITS_PER_WORD. */
2886 int shift_count = BITS_PER_WORD - 1;
2888 word_mask = (HOST_WIDE_INT) 1 << shift_count;
2889 word_mask |= word_mask - 1;
2890 low = GEN_INT (INTVAL (value) & word_mask);
2891 high = GEN_INT ((INTVAL (value) >> (shift_count + 1)) & word_mask);
2892 if (WORDS_BIG_ENDIAN)
2894 *first = high;
2895 *second = low;
2897 else
2899 *first = low;
2900 *second = high;
2903 else
2905 /* The rule for using CONST_INT for a wider mode
2906 is that we regard the value as signed.
2907 So sign-extend it. */
2908 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
2909 if (WORDS_BIG_ENDIAN)
2911 *first = high;
2912 *second = value;
2914 else
2916 *first = value;
2917 *second = high;
2921 else if (GET_CODE (value) != CONST_DOUBLE)
2923 if (WORDS_BIG_ENDIAN)
2925 *first = const0_rtx;
2926 *second = value;
2928 else
2930 *first = value;
2931 *second = const0_rtx;
2934 else if (GET_MODE (value) == VOIDmode
2935 /* This is the old way we did CONST_DOUBLE integers. */
2936 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
2938 /* In an integer, the words are defined as most and least significant.
2939 So order them by the target's convention. */
2940 if (WORDS_BIG_ENDIAN)
2942 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2943 *second = GEN_INT (CONST_DOUBLE_LOW (value));
2945 else
2947 *first = GEN_INT (CONST_DOUBLE_LOW (value));
2948 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
2951 else
2953 #ifdef REAL_ARITHMETIC
2954 REAL_VALUE_TYPE r; long l[2];
2955 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
2957 /* Note, this converts the REAL_VALUE_TYPE to the target's
2958 format, splits up the floating point double and outputs
2959 exactly 32 bits of it into each of l[0] and l[1] --
2960 not necessarily BITS_PER_WORD bits. */
2961 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
2963 *first = GEN_INT ((HOST_WIDE_INT) l[0]);
2964 *second = GEN_INT ((HOST_WIDE_INT) l[1]);
2965 #else
2966 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
2967 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
2968 && ! flag_pretend_float)
2969 abort ();
2971 if (
2972 #ifdef HOST_WORDS_BIG_ENDIAN
2973 WORDS_BIG_ENDIAN
2974 #else
2975 ! WORDS_BIG_ENDIAN
2976 #endif
2979 /* Host and target agree => no need to swap. */
2980 *first = GEN_INT (CONST_DOUBLE_LOW (value));
2981 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
2983 else
2985 *second = GEN_INT (CONST_DOUBLE_LOW (value));
2986 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
2988 #endif /* no REAL_ARITHMETIC */
2992 /* Return nonzero if this function has no function calls. */
2995 leaf_function_p ()
2997 rtx insn;
2999 if (profile_flag || profile_block_flag)
3000 return 0;
3002 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3004 if (GET_CODE (insn) == CALL_INSN)
3005 return 0;
3006 if (GET_CODE (insn) == INSN
3007 && GET_CODE (PATTERN (insn)) == SEQUENCE
3008 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN)
3009 return 0;
3011 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
3013 if (GET_CODE (XEXP (insn, 0)) == CALL_INSN)
3014 return 0;
3015 if (GET_CODE (XEXP (insn, 0)) == INSN
3016 && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
3017 && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN)
3018 return 0;
3021 return 1;
3024 /* On some machines, a function with no call insns
3025 can run faster if it doesn't create its own register window.
3026 When output, the leaf function should use only the "output"
3027 registers. Ordinarily, the function would be compiled to use
3028 the "input" registers to find its arguments; it is a candidate
3029 for leaf treatment if it uses only the "input" registers.
3030 Leaf function treatment means renumbering so the function
3031 uses the "output" registers instead. */
3033 #ifdef LEAF_REGISTERS
3035 static char permitted_reg_in_leaf_functions[] = LEAF_REGISTERS;
3037 /* Return 1 if this function uses only the registers that can be
3038 safely renumbered. */
3041 only_leaf_regs_used ()
3043 int i;
3045 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3047 if ((regs_ever_live[i] || global_regs[i])
3048 && ! permitted_reg_in_leaf_functions[i])
3049 return 0;
3051 return 1;
3054 /* Scan all instructions and renumber all registers into those
3055 available in leaf functions. */
3057 static void
3058 leaf_renumber_regs (first)
3059 rtx first;
3061 rtx insn;
3063 /* Renumber only the actual patterns.
3064 The reg-notes can contain frame pointer refs,
3065 and renumbering them could crash, and should not be needed. */
3066 for (insn = first; insn; insn = NEXT_INSN (insn))
3067 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3068 leaf_renumber_regs_insn (PATTERN (insn));
3069 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
3070 if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
3071 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
3074 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
3075 available in leaf functions. */
3077 void
3078 leaf_renumber_regs_insn (in_rtx)
3079 register rtx in_rtx;
3081 register int i, j;
3082 register char *format_ptr;
3084 if (in_rtx == 0)
3085 return;
3087 /* Renumber all input-registers into output-registers.
3088 renumbered_regs would be 1 for an output-register;
3089 they */
3091 if (GET_CODE (in_rtx) == REG)
3093 int newreg;
3095 /* Don't renumber the same reg twice. */
3096 if (in_rtx->used)
3097 return;
3099 newreg = REGNO (in_rtx);
3100 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
3101 to reach here as part of a REG_NOTE. */
3102 if (newreg >= FIRST_PSEUDO_REGISTER)
3104 in_rtx->used = 1;
3105 return;
3107 newreg = LEAF_REG_REMAP (newreg);
3108 if (newreg < 0)
3109 abort ();
3110 regs_ever_live[REGNO (in_rtx)] = 0;
3111 regs_ever_live[newreg] = 1;
3112 REGNO (in_rtx) = newreg;
3113 in_rtx->used = 1;
3116 if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
3118 /* Inside a SEQUENCE, we find insns.
3119 Renumber just the patterns of these insns,
3120 just as we do for the top-level insns. */
3121 leaf_renumber_regs_insn (PATTERN (in_rtx));
3122 return;
3125 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
3127 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
3128 switch (*format_ptr++)
3130 case 'e':
3131 leaf_renumber_regs_insn (XEXP (in_rtx, i));
3132 break;
3134 case 'E':
3135 if (NULL != XVEC (in_rtx, i))
3137 for (j = 0; j < XVECLEN (in_rtx, i); j++)
3138 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
3140 break;
3142 case 'S':
3143 case 's':
3144 case '0':
3145 case 'i':
3146 case 'w':
3147 case 'n':
3148 case 'u':
3149 break;
3151 default:
3152 abort ();
3155 #endif