2000-05-02 Jeff Sturm <jsturm@one-point.com>
[official-gcc.git] / gcc / final.c
blob64a4241b3786915127124b0c13ecf308cd6afddc
1 /* Convert RTL to assembler code and output it, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 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 #include "system.h"
50 #include "tree.h"
51 #include "rtl.h"
52 #include "tm_p.h"
53 #include "regs.h"
54 #include "insn-config.h"
55 #include "insn-attr.h"
56 #include "recog.h"
57 #include "conditions.h"
58 #include "flags.h"
59 #include "real.h"
60 #include "hard-reg-set.h"
61 #include "output.h"
62 #include "except.h"
63 #include "function.h"
64 #include "toplev.h"
65 #include "reload.h"
66 #include "intl.h"
67 #include "basic-block.h"
69 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
70 #include "dbxout.h"
71 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
73 #ifdef XCOFF_DEBUGGING_INFO
74 #include "xcoffout.h"
75 #endif
77 #ifdef DWARF_DEBUGGING_INFO
78 #include "dwarfout.h"
79 #endif
81 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
82 #include "dwarf2out.h"
83 #endif
85 #ifdef SDB_DEBUGGING_INFO
86 #include "sdbout.h"
87 #endif
89 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
90 null default for it to save conditionalization later. */
91 #ifndef CC_STATUS_INIT
92 #define CC_STATUS_INIT
93 #endif
95 /* How to start an assembler comment. */
96 #ifndef ASM_COMMENT_START
97 #define ASM_COMMENT_START ";#"
98 #endif
100 /* Is the given character a logical line separator for the assembler? */
101 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
102 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
103 #endif
105 #ifndef JUMP_TABLES_IN_TEXT_SECTION
106 #define JUMP_TABLES_IN_TEXT_SECTION 0
107 #endif
109 /* Last insn processed by final_scan_insn. */
110 static rtx debug_insn;
111 rtx current_output_insn;
113 /* Line number of last NOTE. */
114 static int last_linenum;
116 /* Highest line number in current block. */
117 static int high_block_linenum;
119 /* Likewise for function. */
120 static int high_function_linenum;
122 /* Filename of last NOTE. */
123 static const char *last_filename;
125 /* Number of basic blocks seen so far;
126 used if profile_block_flag is set. */
127 static int count_basic_blocks;
129 /* Number of instrumented arcs when profile_arc_flag is set. */
130 extern int count_instrumented_edges;
132 extern int length_unit_log; /* This is defined in insn-attrtab.c. */
134 /* Nonzero while outputting an `asm' with operands.
135 This means that inconsistencies are the user's fault, so don't abort.
136 The precise value is the insn being output, to pass to error_for_asm. */
137 static rtx this_is_asm_operands;
139 /* Number of operands of this insn, for an `asm' with operands. */
140 static unsigned int insn_noperands;
142 /* Compare optimization flag. */
144 static rtx last_ignored_compare = 0;
146 /* Flag indicating this insn is the start of a new basic block. */
148 static int new_block = 1;
150 /* Assign a unique number to each insn that is output.
151 This can be used to generate unique local labels. */
153 static int insn_counter = 0;
155 #ifdef HAVE_cc0
156 /* This variable contains machine-dependent flags (defined in tm.h)
157 set and examined by output routines
158 that describe how to interpret the condition codes properly. */
160 CC_STATUS cc_status;
162 /* During output of an insn, this contains a copy of cc_status
163 from before the insn. */
165 CC_STATUS cc_prev_status;
166 #endif
168 /* Indexed by hardware reg number, is 1 if that register is ever
169 used in the current function.
171 In life_analysis, or in stupid_life_analysis, this is set
172 up to record the hard regs used explicitly. Reload adds
173 in the hard regs used for holding pseudo regs. Final uses
174 it to generate the code in the function prologue and epilogue
175 to save and restore registers as needed. */
177 char regs_ever_live[FIRST_PSEUDO_REGISTER];
179 /* Nonzero means current function must be given a frame pointer.
180 Set in stmt.c if anything is allocated on the stack there.
181 Set in reload1.c if anything is allocated on the stack there. */
183 int frame_pointer_needed;
185 /* Assign unique numbers to labels generated for profiling. */
187 int profile_label_no;
189 /* Number of unmatched NOTE_INSN_BLOCK_BEG notes we have seen. */
191 static int block_depth;
193 /* Nonzero if have enabled APP processing of our assembler output. */
195 static int app_on;
197 /* If we are outputting an insn sequence, this contains the sequence rtx.
198 Zero otherwise. */
200 rtx final_sequence;
202 #ifdef ASSEMBLER_DIALECT
204 /* Number of the assembler dialect to use, starting at 0. */
205 static int dialect_number;
206 #endif
208 /* Indexed by line number, nonzero if there is a note for that line. */
210 static char *line_note_exists;
212 #ifdef HAVE_conditional_execution
213 /* Nonnull if the insn currently being emitted was a COND_EXEC pattern. */
214 rtx current_insn_predicate;
215 #endif
217 /* Linked list to hold line numbers for each basic block. */
219 struct bb_list
221 struct bb_list *next; /* pointer to next basic block */
222 int line_num; /* line number */
223 int file_label_num; /* LPBC<n> label # for stored filename */
224 int func_label_num; /* LPBC<n> label # for stored function name */
227 static struct bb_list *bb_head = 0; /* Head of basic block list */
228 static struct bb_list **bb_tail = &bb_head; /* Ptr to store next bb ptr */
229 static int bb_file_label_num = -1; /* Current label # for file */
230 static int bb_func_label_num = -1; /* Current label # for func */
232 /* Linked list to hold the strings for each file and function name output. */
234 struct bb_str
236 struct bb_str *next; /* pointer to next string */
237 const char *string; /* string */
238 int label_num; /* label number */
239 int length; /* string length */
242 static struct bb_str *sbb_head = 0; /* Head of string list. */
243 static struct bb_str **sbb_tail = &sbb_head; /* Ptr to store next bb str */
244 static int sbb_label_num = 0; /* Last label used */
246 #ifdef HAVE_ATTR_length
247 static int asm_insn_count PARAMS ((rtx));
248 #endif
249 static void profile_function PARAMS ((FILE *));
250 static void profile_after_prologue PARAMS ((FILE *));
251 static void add_bb PARAMS ((FILE *));
252 static int add_bb_string PARAMS ((const char *, int));
253 static void output_source_line PARAMS ((FILE *, rtx));
254 static rtx walk_alter_subreg PARAMS ((rtx));
255 static void output_asm_name PARAMS ((void));
256 static void output_operand PARAMS ((rtx, int));
257 #ifdef LEAF_REGISTERS
258 static void leaf_renumber_regs PARAMS ((rtx));
259 #endif
260 #ifdef HAVE_cc0
261 static int alter_cond PARAMS ((rtx));
262 #endif
263 #ifndef ADDR_VEC_ALIGN
264 static int final_addr_vec_align PARAMS ((rtx));
265 #endif
266 #ifdef HAVE_ATTR_length
267 static int align_fuzz PARAMS ((rtx, rtx, int, unsigned));
268 #endif
270 /* Initialize data in final at the beginning of a compilation. */
272 void
273 init_final (filename)
274 const char *filename ATTRIBUTE_UNUSED;
276 app_on = 0;
277 final_sequence = 0;
279 #ifdef ASSEMBLER_DIALECT
280 dialect_number = ASSEMBLER_DIALECT;
281 #endif
284 /* Called at end of source file,
285 to output the block-profiling table for this entire compilation. */
287 void
288 end_final (filename)
289 const char *filename;
291 int i;
293 if (profile_block_flag || profile_arc_flag)
295 char name[20];
296 int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
297 int size, rounded;
298 struct bb_list *ptr;
299 struct bb_str *sptr;
300 int long_bytes = LONG_TYPE_SIZE / BITS_PER_UNIT;
301 int pointer_bytes = POINTER_SIZE / BITS_PER_UNIT;
303 if (profile_block_flag)
304 size = long_bytes * count_basic_blocks;
305 else
306 size = long_bytes * count_instrumented_edges;
307 rounded = size;
309 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
310 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
311 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
313 data_section ();
315 /* Output the main header, of 11 words:
316 0: 1 if this file is initialized, else 0.
317 1: address of file name (LPBX1).
318 2: address of table of counts (LPBX2).
319 3: number of counts in the table.
320 4: always 0, for compatibility with Sun.
322 The following are GNU extensions:
324 5: address of table of start addrs of basic blocks (LPBX3).
325 6: Number of bytes in this header.
326 7: address of table of function names (LPBX4).
327 8: address of table of line numbers (LPBX5) or 0.
328 9: address of table of file names (LPBX6) or 0.
329 10: space reserved for basic block profiling. */
331 ASM_OUTPUT_ALIGN (asm_out_file, align);
333 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
334 /* zero word */
335 assemble_integer (const0_rtx, long_bytes, 1);
337 /* address of filename */
338 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
339 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
341 /* address of count table */
342 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
343 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
345 /* count of the # of basic blocks or # of instrumented arcs */
346 if (profile_block_flag)
347 assemble_integer (GEN_INT (count_basic_blocks), long_bytes, 1);
348 else
349 assemble_integer (GEN_INT (count_instrumented_edges), long_bytes, 1);
351 /* zero word (link field) */
352 assemble_integer (const0_rtx, pointer_bytes, 1);
354 /* address of basic block start address table */
355 if (profile_block_flag)
357 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
358 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
361 else
362 assemble_integer (const0_rtx, pointer_bytes, 1);
364 /* byte count for extended structure. */
365 assemble_integer (GEN_INT (11 * UNITS_PER_WORD), long_bytes, 1);
367 /* address of function name table */
368 if (profile_block_flag)
370 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
371 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
374 else
375 assemble_integer (const0_rtx, pointer_bytes, 1);
377 /* address of line number and filename tables if debugging. */
378 if (write_symbols != NO_DEBUG && profile_block_flag)
380 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
381 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
382 pointer_bytes, 1);
383 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
384 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
385 pointer_bytes, 1);
387 else
389 assemble_integer (const0_rtx, pointer_bytes, 1);
390 assemble_integer (const0_rtx, pointer_bytes, 1);
393 /* space for extension ptr (link field) */
394 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
396 /* Output the file name changing the suffix to .d for Sun tcov
397 compatibility. */
398 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
400 char *cwd = getpwd ();
401 int len = strlen (filename) + strlen (cwd) + 1;
402 char *data_file = (char *) alloca (len + 4);
404 strcpy (data_file, cwd);
405 strcat (data_file, "/");
406 strcat (data_file, filename);
407 strip_off_ending (data_file, len);
408 if (profile_block_flag)
409 strcat (data_file, ".d");
410 else
411 strcat (data_file, ".da");
412 assemble_string (data_file, strlen (data_file) + 1);
415 /* Make space for the table of counts. */
416 if (size == 0)
418 /* Realign data section. */
419 ASM_OUTPUT_ALIGN (asm_out_file, align);
420 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
421 if (size != 0)
422 assemble_zeros (size);
424 else
426 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
427 #ifdef ASM_OUTPUT_SHARED_LOCAL
428 if (flag_shared_data)
429 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
430 else
431 #endif
432 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
433 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name,
434 size, BIGGEST_ALIGNMENT);
435 #else
436 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
437 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
438 BIGGEST_ALIGNMENT);
439 #else
440 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
441 #endif
442 #endif
445 /* Output any basic block strings */
446 if (profile_block_flag)
448 readonly_data_section ();
449 if (sbb_head)
451 ASM_OUTPUT_ALIGN (asm_out_file, align);
452 for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
454 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC",
455 sptr->label_num);
456 assemble_string (sptr->string, sptr->length);
461 /* Output the table of addresses. */
462 if (profile_block_flag)
464 /* Realign in new section */
465 ASM_OUTPUT_ALIGN (asm_out_file, align);
466 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
467 for (i = 0; i < count_basic_blocks; i++)
469 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
470 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
471 pointer_bytes, 1);
475 /* Output the table of function names. */
476 if (profile_block_flag)
478 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
479 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
481 if (ptr->func_label_num >= 0)
483 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
484 ptr->func_label_num);
485 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
486 pointer_bytes, 1);
488 else
489 assemble_integer (const0_rtx, pointer_bytes, 1);
492 for (; i < count_basic_blocks; i++)
493 assemble_integer (const0_rtx, pointer_bytes, 1);
496 if (write_symbols != NO_DEBUG && profile_block_flag)
498 /* Output the table of line numbers. */
499 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
500 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
501 assemble_integer (GEN_INT (ptr->line_num), long_bytes, 1);
503 for (; i < count_basic_blocks; i++)
504 assemble_integer (const0_rtx, long_bytes, 1);
506 /* Output the table of file names. */
507 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
508 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
510 if (ptr->file_label_num >= 0)
512 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
513 ptr->file_label_num);
514 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
515 pointer_bytes, 1);
517 else
518 assemble_integer (const0_rtx, pointer_bytes, 1);
521 for (; i < count_basic_blocks; i++)
522 assemble_integer (const0_rtx, pointer_bytes, 1);
525 /* End with the address of the table of addresses,
526 so we can find it easily, as the last word in the file's text. */
527 if (profile_block_flag)
529 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
530 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
536 /* Enable APP processing of subsequent output.
537 Used before the output from an `asm' statement. */
539 void
540 app_enable ()
542 if (! app_on)
544 fputs (ASM_APP_ON, asm_out_file);
545 app_on = 1;
549 /* Disable APP processing of subsequent output.
550 Called from varasm.c before most kinds of output. */
552 void
553 app_disable ()
555 if (app_on)
557 fputs (ASM_APP_OFF, asm_out_file);
558 app_on = 0;
562 /* Return the number of slots filled in the current
563 delayed branch sequence (we don't count the insn needing the
564 delay slot). Zero if not in a delayed branch sequence. */
566 #ifdef DELAY_SLOTS
568 dbr_sequence_length ()
570 if (final_sequence != 0)
571 return XVECLEN (final_sequence, 0) - 1;
572 else
573 return 0;
575 #endif
577 /* The next two pages contain routines used to compute the length of an insn
578 and to shorten branches. */
580 /* Arrays for insn lengths, and addresses. The latter is referenced by
581 `insn_current_length'. */
583 static short *insn_lengths;
585 #ifdef HAVE_ATTR_length
586 varray_type insn_addresses_;
587 #endif
589 /* Max uid for which the above arrays are valid. */
590 static int insn_lengths_max_uid;
592 /* Address of insn being processed. Used by `insn_current_length'. */
593 int insn_current_address;
595 /* Address of insn being processed in previous iteration. */
596 int insn_last_address;
598 /* konwn invariant alignment of insn being processed. */
599 int insn_current_align;
601 /* After shorten_branches, for any insn, uid_align[INSN_UID (insn)]
602 gives the next following alignment insn that increases the known
603 alignment, or NULL_RTX if there is no such insn.
604 For any alignment obtained this way, we can again index uid_align with
605 its uid to obtain the next following align that in turn increases the
606 alignment, till we reach NULL_RTX; the sequence obtained this way
607 for each insn we'll call the alignment chain of this insn in the following
608 comments. */
610 struct label_alignment
612 short alignment;
613 short max_skip;
616 static rtx *uid_align;
617 static int *uid_shuid;
618 static struct label_alignment *label_align;
620 /* Indicate that branch shortening hasn't yet been done. */
622 void
623 init_insn_lengths ()
625 if (label_align)
627 free (label_align);
628 label_align = 0;
630 if (uid_shuid)
632 free (uid_shuid);
633 uid_shuid = 0;
635 if (insn_lengths)
637 free (insn_lengths);
638 insn_lengths = 0;
639 insn_lengths_max_uid = 0;
641 #ifdef HAVE_ATTR_length
642 INSN_ADDRESSES_FREE ();
643 #endif
644 if (uid_align)
646 free (uid_align);
647 uid_align = 0;
651 /* Obtain the current length of an insn. If branch shortening has been done,
652 get its actual length. Otherwise, get its maximum length. */
655 get_attr_length (insn)
656 rtx insn ATTRIBUTE_UNUSED;
658 #ifdef HAVE_ATTR_length
659 rtx body;
660 int i;
661 int length = 0;
663 if (insn_lengths_max_uid > INSN_UID (insn))
664 return insn_lengths[INSN_UID (insn)];
665 else
666 switch (GET_CODE (insn))
668 case NOTE:
669 case BARRIER:
670 case CODE_LABEL:
671 return 0;
673 case CALL_INSN:
674 length = insn_default_length (insn);
675 break;
677 case JUMP_INSN:
678 body = PATTERN (insn);
679 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
681 /* Alignment is machine-dependent and should be handled by
682 ADDR_VEC_ALIGN. */
684 else
685 length = insn_default_length (insn);
686 break;
688 case INSN:
689 body = PATTERN (insn);
690 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
691 return 0;
693 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
694 length = asm_insn_count (body) * insn_default_length (insn);
695 else if (GET_CODE (body) == SEQUENCE)
696 for (i = 0; i < XVECLEN (body, 0); i++)
697 length += get_attr_length (XVECEXP (body, 0, i));
698 else
699 length = insn_default_length (insn);
700 break;
702 default:
703 break;
706 #ifdef ADJUST_INSN_LENGTH
707 ADJUST_INSN_LENGTH (insn, length);
708 #endif
709 return length;
710 #else /* not HAVE_ATTR_length */
711 return 0;
712 #endif /* not HAVE_ATTR_length */
715 /* Code to handle alignment inside shorten_branches. */
717 /* Here is an explanation how the algorithm in align_fuzz can give
718 proper results:
720 Call a sequence of instructions beginning with alignment point X
721 and continuing until the next alignment point `block X'. When `X'
722 is used in an expression, it means the alignment value of the
723 alignment point.
725 Call the distance between the start of the first insn of block X, and
726 the end of the last insn of block X `IX', for the `inner size of X'.
727 This is clearly the sum of the instruction lengths.
729 Likewise with the next alignment-delimited block following X, which we
730 shall call block Y.
732 Call the distance between the start of the first insn of block X, and
733 the start of the first insn of block Y `OX', for the `outer size of X'.
735 The estimated padding is then OX - IX.
737 OX can be safely estimated as
739 if (X >= Y)
740 OX = round_up(IX, Y)
741 else
742 OX = round_up(IX, X) + Y - X
744 Clearly est(IX) >= real(IX), because that only depends on the
745 instruction lengths, and those being overestimated is a given.
747 Clearly round_up(foo, Z) >= round_up(bar, Z) if foo >= bar, so
748 we needn't worry about that when thinking about OX.
750 When X >= Y, the alignment provided by Y adds no uncertainty factor
751 for branch ranges starting before X, so we can just round what we have.
752 But when X < Y, we don't know anything about the, so to speak,
753 `middle bits', so we have to assume the worst when aligning up from an
754 address mod X to one mod Y, which is Y - X. */
756 #ifndef LABEL_ALIGN
757 #define LABEL_ALIGN(LABEL) align_labels_log
758 #endif
760 #ifndef LABEL_ALIGN_MAX_SKIP
761 #define LABEL_ALIGN_MAX_SKIP (align_labels-1)
762 #endif
764 #ifndef LOOP_ALIGN
765 #define LOOP_ALIGN(LABEL) align_loops_log
766 #endif
768 #ifndef LOOP_ALIGN_MAX_SKIP
769 #define LOOP_ALIGN_MAX_SKIP (align_loops-1)
770 #endif
772 #ifndef LABEL_ALIGN_AFTER_BARRIER
773 #define LABEL_ALIGN_AFTER_BARRIER(LABEL) align_jumps_log
774 #endif
776 #ifndef LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP
777 #define LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP (align_jumps-1)
778 #endif
780 #ifndef ADDR_VEC_ALIGN
781 static int
782 final_addr_vec_align (addr_vec)
783 rtx addr_vec;
785 int align = GET_MODE_SIZE (GET_MODE (PATTERN (addr_vec)));
787 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
788 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
789 return exact_log2 (align);
793 #define ADDR_VEC_ALIGN(ADDR_VEC) final_addr_vec_align (ADDR_VEC)
794 #endif
796 #ifndef INSN_LENGTH_ALIGNMENT
797 #define INSN_LENGTH_ALIGNMENT(INSN) length_unit_log
798 #endif
800 #define INSN_SHUID(INSN) (uid_shuid[INSN_UID (INSN)])
802 static int min_labelno, max_labelno;
804 #define LABEL_TO_ALIGNMENT(LABEL) \
805 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].alignment)
807 #define LABEL_TO_MAX_SKIP(LABEL) \
808 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].max_skip)
810 /* For the benefit of port specific code do this also as a function. */
813 label_to_alignment (label)
814 rtx label;
816 return LABEL_TO_ALIGNMENT (label);
819 #ifdef HAVE_ATTR_length
820 /* The differences in addresses
821 between a branch and its target might grow or shrink depending on
822 the alignment the start insn of the range (the branch for a forward
823 branch or the label for a backward branch) starts out on; if these
824 differences are used naively, they can even oscillate infinitely.
825 We therefore want to compute a 'worst case' address difference that
826 is independent of the alignment the start insn of the range end
827 up on, and that is at least as large as the actual difference.
828 The function align_fuzz calculates the amount we have to add to the
829 naively computed difference, by traversing the part of the alignment
830 chain of the start insn of the range that is in front of the end insn
831 of the range, and considering for each alignment the maximum amount
832 that it might contribute to a size increase.
834 For casesi tables, we also want to know worst case minimum amounts of
835 address difference, in case a machine description wants to introduce
836 some common offset that is added to all offsets in a table.
837 For this purpose, align_fuzz with a growth argument of 0 comuptes the
838 appropriate adjustment. */
840 /* Compute the maximum delta by which the difference of the addresses of
841 START and END might grow / shrink due to a different address for start
842 which changes the size of alignment insns between START and END.
843 KNOWN_ALIGN_LOG is the alignment known for START.
844 GROWTH should be ~0 if the objective is to compute potential code size
845 increase, and 0 if the objective is to compute potential shrink.
846 The return value is undefined for any other value of GROWTH. */
848 static int
849 align_fuzz (start, end, known_align_log, growth)
850 rtx start, end;
851 int known_align_log;
852 unsigned growth;
854 int uid = INSN_UID (start);
855 rtx align_label;
856 int known_align = 1 << known_align_log;
857 int end_shuid = INSN_SHUID (end);
858 int fuzz = 0;
860 for (align_label = uid_align[uid]; align_label; align_label = uid_align[uid])
862 int align_addr, new_align;
864 uid = INSN_UID (align_label);
865 align_addr = INSN_ADDRESSES (uid) - insn_lengths[uid];
866 if (uid_shuid[uid] > end_shuid)
867 break;
868 known_align_log = LABEL_TO_ALIGNMENT (align_label);
869 new_align = 1 << known_align_log;
870 if (new_align < known_align)
871 continue;
872 fuzz += (-align_addr ^ growth) & (new_align - known_align);
873 known_align = new_align;
875 return fuzz;
878 /* Compute a worst-case reference address of a branch so that it
879 can be safely used in the presence of aligned labels. Since the
880 size of the branch itself is unknown, the size of the branch is
881 not included in the range. I.e. for a forward branch, the reference
882 address is the end address of the branch as known from the previous
883 branch shortening pass, minus a value to account for possible size
884 increase due to alignment. For a backward branch, it is the start
885 address of the branch as known from the current pass, plus a value
886 to account for possible size increase due to alignment.
887 NB.: Therefore, the maximum offset allowed for backward branches needs
888 to exclude the branch size. */
891 insn_current_reference_address (branch)
892 rtx branch;
894 rtx dest, seq;
895 int seq_uid;
897 if (! INSN_ADDRESSES_SET_P ())
898 return 0;
900 seq = NEXT_INSN (PREV_INSN (branch));
901 seq_uid = INSN_UID (seq);
902 if (GET_CODE (branch) != JUMP_INSN)
903 /* This can happen for example on the PA; the objective is to know the
904 offset to address something in front of the start of the function.
905 Thus, we can treat it like a backward branch.
906 We assume here that FUNCTION_BOUNDARY / BITS_PER_UNIT is larger than
907 any alignment we'd encounter, so we skip the call to align_fuzz. */
908 return insn_current_address;
909 dest = JUMP_LABEL (branch);
911 /* BRANCH has no proper alignment chain set, so use SEQ.
912 BRANCH also has no INSN_SHUID. */
913 if (INSN_SHUID (seq) < INSN_SHUID (dest))
915 /* Forward branch. */
916 return (insn_last_address + insn_lengths[seq_uid]
917 - align_fuzz (seq, dest, length_unit_log, ~0));
919 else
921 /* Backward branch. */
922 return (insn_current_address
923 + align_fuzz (dest, seq, length_unit_log, ~0));
926 #endif /* HAVE_ATTR_length */
928 /* Make a pass over all insns and compute their actual lengths by shortening
929 any branches of variable length if possible. */
931 /* Give a default value for the lowest address in a function. */
933 #ifndef FIRST_INSN_ADDRESS
934 #define FIRST_INSN_ADDRESS 0
935 #endif
937 /* shorten_branches might be called multiple times: for example, the SH
938 port splits out-of-range conditional branches in MACHINE_DEPENDENT_REORG.
939 In order to do this, it needs proper length information, which it obtains
940 by calling shorten_branches. This cannot be collapsed with
941 shorten_branches itself into a single pass unless we also want to intergate
942 reorg.c, since the branch splitting exposes new instructions with delay
943 slots. */
945 void
946 shorten_branches (first)
947 rtx first ATTRIBUTE_UNUSED;
949 rtx insn;
950 int max_uid;
951 int i;
952 int max_log;
953 int max_skip;
954 #ifdef HAVE_ATTR_length
955 #define MAX_CODE_ALIGN 16
956 rtx seq;
957 int something_changed = 1;
958 char *varying_length;
959 rtx body;
960 int uid;
961 rtx align_tab[MAX_CODE_ALIGN];
963 /* In order to make sure that all instructions have valid length info,
964 we must split them before we compute the address/length info. */
966 for (insn = NEXT_INSN (first); insn; insn = NEXT_INSN (insn))
967 if (INSN_P (insn))
969 rtx old = insn;
970 /* Don't split the insn if it has been deleted. */
971 if (! INSN_DELETED_P (old))
972 insn = try_split (PATTERN (old), old, 1);
973 /* When not optimizing, the old insn will be still left around
974 with only the 'deleted' bit set. Transform it into a note
975 to avoid confusion of subsequent processing. */
976 if (INSN_DELETED_P (old))
978 PUT_CODE (old, NOTE);
979 NOTE_LINE_NUMBER (old) = NOTE_INSN_DELETED;
980 NOTE_SOURCE_FILE (old) = 0;
983 #endif
985 /* We must do some computations even when not actually shortening, in
986 order to get the alignment information for the labels. */
988 init_insn_lengths ();
990 /* Compute maximum UID and allocate label_align / uid_shuid. */
991 max_uid = get_max_uid ();
993 max_labelno = max_label_num ();
994 min_labelno = get_first_label_num ();
995 label_align = (struct label_alignment *)
996 xcalloc ((max_labelno - min_labelno + 1), sizeof (struct label_alignment));
998 uid_shuid = (int *) xmalloc (max_uid * sizeof *uid_shuid);
1000 /* Initialize label_align and set up uid_shuid to be strictly
1001 monotonically rising with insn order. */
1002 /* We use max_log here to keep track of the maximum alignment we want to
1003 impose on the next CODE_LABEL (or the current one if we are processing
1004 the CODE_LABEL itself). */
1006 max_log = 0;
1007 max_skip = 0;
1009 for (insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn))
1011 int log;
1013 INSN_SHUID (insn) = i++;
1014 if (INSN_P (insn))
1016 /* reorg might make the first insn of a loop being run once only,
1017 and delete the label in front of it. Then we want to apply
1018 the loop alignment to the new label created by reorg, which
1019 is separated by the former loop start insn from the
1020 NOTE_INSN_LOOP_BEG. */
1022 else if (GET_CODE (insn) == CODE_LABEL)
1024 rtx next;
1026 log = LABEL_ALIGN (insn);
1027 if (max_log < log)
1029 max_log = log;
1030 max_skip = LABEL_ALIGN_MAX_SKIP;
1032 next = NEXT_INSN (insn);
1033 /* ADDR_VECs only take room if read-only data goes into the text
1034 section. */
1035 if (JUMP_TABLES_IN_TEXT_SECTION
1036 #if !defined(READONLY_DATA_SECTION)
1037 || 1
1038 #endif
1040 if (next && GET_CODE (next) == JUMP_INSN)
1042 rtx nextbody = PATTERN (next);
1043 if (GET_CODE (nextbody) == ADDR_VEC
1044 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1046 log = ADDR_VEC_ALIGN (next);
1047 if (max_log < log)
1049 max_log = log;
1050 max_skip = LABEL_ALIGN_MAX_SKIP;
1054 LABEL_TO_ALIGNMENT (insn) = max_log;
1055 LABEL_TO_MAX_SKIP (insn) = max_skip;
1056 max_log = 0;
1057 max_skip = 0;
1059 else if (GET_CODE (insn) == BARRIER)
1061 rtx label;
1063 for (label = insn; label && ! INSN_P (label);
1064 label = NEXT_INSN (label))
1065 if (GET_CODE (label) == CODE_LABEL)
1067 log = LABEL_ALIGN_AFTER_BARRIER (insn);
1068 if (max_log < log)
1070 max_log = log;
1071 max_skip = LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP;
1073 break;
1076 /* Again, we allow NOTE_INSN_LOOP_BEG - INSN - CODE_LABEL
1077 sequences in order to handle reorg output efficiently. */
1078 else if (GET_CODE (insn) == NOTE
1079 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
1081 rtx label;
1082 int nest = 0;
1084 /* Search for the label that starts the loop.
1085 Don't skip past the end of the loop, since that could
1086 lead to putting an alignment where it does not belong.
1087 However, a label after a nested (non-)loop would be OK. */
1088 for (label = insn; label; label = NEXT_INSN (label))
1090 if (GET_CODE (label) == NOTE
1091 && NOTE_LINE_NUMBER (label) == NOTE_INSN_LOOP_BEG)
1092 nest++;
1093 else if (GET_CODE (label) == NOTE
1094 && NOTE_LINE_NUMBER (label) == NOTE_INSN_LOOP_END
1095 && --nest == 0)
1096 break;
1097 else if (GET_CODE (label) == CODE_LABEL)
1099 log = LOOP_ALIGN (label);
1100 if (max_log < log)
1102 max_log = log;
1103 max_skip = LOOP_ALIGN_MAX_SKIP;
1105 break;
1109 else
1110 continue;
1112 #ifdef HAVE_ATTR_length
1114 /* Allocate the rest of the arrays. */
1115 insn_lengths = (short *) xmalloc (max_uid * sizeof (short));
1116 insn_lengths_max_uid = max_uid;
1117 /* Syntax errors can lead to labels being outside of the main insn stream.
1118 Initialize insn_addresses, so that we get reproducible results. */
1119 INSN_ADDRESSES_ALLOC (max_uid);
1121 varying_length = (char *) xcalloc (max_uid, sizeof (char));
1123 /* Initialize uid_align. We scan instructions
1124 from end to start, and keep in align_tab[n] the last seen insn
1125 that does an alignment of at least n+1, i.e. the successor
1126 in the alignment chain for an insn that does / has a known
1127 alignment of n. */
1128 uid_align = (rtx *) xcalloc (max_uid, sizeof *uid_align);
1130 for (i = MAX_CODE_ALIGN; --i >= 0;)
1131 align_tab[i] = NULL_RTX;
1132 seq = get_last_insn ();
1133 for (; seq; seq = PREV_INSN (seq))
1135 int uid = INSN_UID (seq);
1136 int log;
1137 log = (GET_CODE (seq) == CODE_LABEL ? LABEL_TO_ALIGNMENT (seq) : 0);
1138 uid_align[uid] = align_tab[0];
1139 if (log)
1141 /* Found an alignment label. */
1142 uid_align[uid] = align_tab[log];
1143 for (i = log - 1; i >= 0; i--)
1144 align_tab[i] = seq;
1147 #ifdef CASE_VECTOR_SHORTEN_MODE
1148 if (optimize)
1150 /* Look for ADDR_DIFF_VECs, and initialize their minimum and maximum
1151 label fields. */
1153 int min_shuid = INSN_SHUID (get_insns ()) - 1;
1154 int max_shuid = INSN_SHUID (get_last_insn ()) + 1;
1155 int rel;
1157 for (insn = first; insn != 0; insn = NEXT_INSN (insn))
1159 rtx min_lab = NULL_RTX, max_lab = NULL_RTX, pat;
1160 int len, i, min, max, insn_shuid;
1161 int min_align;
1162 addr_diff_vec_flags flags;
1164 if (GET_CODE (insn) != JUMP_INSN
1165 || GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
1166 continue;
1167 pat = PATTERN (insn);
1168 len = XVECLEN (pat, 1);
1169 if (len <= 0)
1170 abort ();
1171 min_align = MAX_CODE_ALIGN;
1172 for (min = max_shuid, max = min_shuid, i = len - 1; i >= 0; i--)
1174 rtx lab = XEXP (XVECEXP (pat, 1, i), 0);
1175 int shuid = INSN_SHUID (lab);
1176 if (shuid < min)
1178 min = shuid;
1179 min_lab = lab;
1181 if (shuid > max)
1183 max = shuid;
1184 max_lab = lab;
1186 if (min_align > LABEL_TO_ALIGNMENT (lab))
1187 min_align = LABEL_TO_ALIGNMENT (lab);
1189 XEXP (pat, 2) = gen_rtx_LABEL_REF (VOIDmode, min_lab);
1190 XEXP (pat, 3) = gen_rtx_LABEL_REF (VOIDmode, max_lab);
1191 insn_shuid = INSN_SHUID (insn);
1192 rel = INSN_SHUID (XEXP (XEXP (pat, 0), 0));
1193 flags.min_align = min_align;
1194 flags.base_after_vec = rel > insn_shuid;
1195 flags.min_after_vec = min > insn_shuid;
1196 flags.max_after_vec = max > insn_shuid;
1197 flags.min_after_base = min > rel;
1198 flags.max_after_base = max > rel;
1199 ADDR_DIFF_VEC_FLAGS (pat) = flags;
1202 #endif /* CASE_VECTOR_SHORTEN_MODE */
1204 /* Compute initial lengths, addresses, and varying flags for each insn. */
1205 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1206 insn != 0;
1207 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
1209 uid = INSN_UID (insn);
1211 insn_lengths[uid] = 0;
1213 if (GET_CODE (insn) == CODE_LABEL)
1215 int log = LABEL_TO_ALIGNMENT (insn);
1216 if (log)
1218 int align = 1 << log;
1219 int new_address = (insn_current_address + align - 1) & -align;
1220 insn_lengths[uid] = new_address - insn_current_address;
1224 INSN_ADDRESSES (uid) = insn_current_address;
1226 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
1227 || GET_CODE (insn) == CODE_LABEL)
1228 continue;
1229 if (INSN_DELETED_P (insn))
1230 continue;
1232 body = PATTERN (insn);
1233 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1235 /* This only takes room if read-only data goes into the text
1236 section. */
1237 if (JUMP_TABLES_IN_TEXT_SECTION
1238 #if !defined(READONLY_DATA_SECTION)
1239 || 1
1240 #endif
1242 insn_lengths[uid] = (XVECLEN (body,
1243 GET_CODE (body) == ADDR_DIFF_VEC)
1244 * GET_MODE_SIZE (GET_MODE (body)));
1245 /* Alignment is handled by ADDR_VEC_ALIGN. */
1247 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
1248 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
1249 else if (GET_CODE (body) == SEQUENCE)
1251 int i;
1252 int const_delay_slots;
1253 #ifdef DELAY_SLOTS
1254 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
1255 #else
1256 const_delay_slots = 0;
1257 #endif
1258 /* Inside a delay slot sequence, we do not do any branch shortening
1259 if the shortening could change the number of delay slots
1260 of the branch. */
1261 for (i = 0; i < XVECLEN (body, 0); i++)
1263 rtx inner_insn = XVECEXP (body, 0, i);
1264 int inner_uid = INSN_UID (inner_insn);
1265 int inner_length;
1267 if (GET_CODE (body) == ASM_INPUT
1268 || asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
1269 inner_length = (asm_insn_count (PATTERN (inner_insn))
1270 * insn_default_length (inner_insn));
1271 else
1272 inner_length = insn_default_length (inner_insn);
1274 insn_lengths[inner_uid] = inner_length;
1275 if (const_delay_slots)
1277 if ((varying_length[inner_uid]
1278 = insn_variable_length_p (inner_insn)) != 0)
1279 varying_length[uid] = 1;
1280 INSN_ADDRESSES (inner_uid) = (insn_current_address
1281 + insn_lengths[uid]);
1283 else
1284 varying_length[inner_uid] = 0;
1285 insn_lengths[uid] += inner_length;
1288 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
1290 insn_lengths[uid] = insn_default_length (insn);
1291 varying_length[uid] = insn_variable_length_p (insn);
1294 /* If needed, do any adjustment. */
1295 #ifdef ADJUST_INSN_LENGTH
1296 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
1297 if (insn_lengths[uid] < 0)
1298 fatal_insn ("Negative insn length", insn);
1299 #endif
1302 /* Now loop over all the insns finding varying length insns. For each,
1303 get the current insn length. If it has changed, reflect the change.
1304 When nothing changes for a full pass, we are done. */
1306 while (something_changed)
1308 something_changed = 0;
1309 insn_current_align = MAX_CODE_ALIGN - 1;
1310 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1311 insn != 0;
1312 insn = NEXT_INSN (insn))
1314 int new_length;
1315 #ifdef ADJUST_INSN_LENGTH
1316 int tmp_length;
1317 #endif
1318 int length_align;
1320 uid = INSN_UID (insn);
1322 if (GET_CODE (insn) == CODE_LABEL)
1324 int log = LABEL_TO_ALIGNMENT (insn);
1325 if (log > insn_current_align)
1327 int align = 1 << log;
1328 int new_address= (insn_current_address + align - 1) & -align;
1329 insn_lengths[uid] = new_address - insn_current_address;
1330 insn_current_align = log;
1331 insn_current_address = new_address;
1333 else
1334 insn_lengths[uid] = 0;
1335 INSN_ADDRESSES (uid) = insn_current_address;
1336 continue;
1339 length_align = INSN_LENGTH_ALIGNMENT (insn);
1340 if (length_align < insn_current_align)
1341 insn_current_align = length_align;
1343 insn_last_address = INSN_ADDRESSES (uid);
1344 INSN_ADDRESSES (uid) = insn_current_address;
1346 #ifdef CASE_VECTOR_SHORTEN_MODE
1347 if (optimize && GET_CODE (insn) == JUMP_INSN
1348 && GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
1350 rtx body = PATTERN (insn);
1351 int old_length = insn_lengths[uid];
1352 rtx rel_lab = XEXP (XEXP (body, 0), 0);
1353 rtx min_lab = XEXP (XEXP (body, 2), 0);
1354 rtx max_lab = XEXP (XEXP (body, 3), 0);
1355 addr_diff_vec_flags flags = ADDR_DIFF_VEC_FLAGS (body);
1356 int rel_addr = INSN_ADDRESSES (INSN_UID (rel_lab));
1357 int min_addr = INSN_ADDRESSES (INSN_UID (min_lab));
1358 int max_addr = INSN_ADDRESSES (INSN_UID (max_lab));
1359 rtx prev;
1360 int rel_align = 0;
1362 /* Try to find a known alignment for rel_lab. */
1363 for (prev = rel_lab;
1364 prev
1365 && ! insn_lengths[INSN_UID (prev)]
1366 && ! (varying_length[INSN_UID (prev)] & 1);
1367 prev = PREV_INSN (prev))
1368 if (varying_length[INSN_UID (prev)] & 2)
1370 rel_align = LABEL_TO_ALIGNMENT (prev);
1371 break;
1374 /* See the comment on addr_diff_vec_flags in rtl.h for the
1375 meaning of the flags values. base: REL_LAB vec: INSN */
1376 /* Anything after INSN has still addresses from the last
1377 pass; adjust these so that they reflect our current
1378 estimate for this pass. */
1379 if (flags.base_after_vec)
1380 rel_addr += insn_current_address - insn_last_address;
1381 if (flags.min_after_vec)
1382 min_addr += insn_current_address - insn_last_address;
1383 if (flags.max_after_vec)
1384 max_addr += insn_current_address - insn_last_address;
1385 /* We want to know the worst case, i.e. lowest possible value
1386 for the offset of MIN_LAB. If MIN_LAB is after REL_LAB,
1387 its offset is positive, and we have to be wary of code shrink;
1388 otherwise, it is negative, and we have to be vary of code
1389 size increase. */
1390 if (flags.min_after_base)
1392 /* If INSN is between REL_LAB and MIN_LAB, the size
1393 changes we are about to make can change the alignment
1394 within the observed offset, therefore we have to break
1395 it up into two parts that are independent. */
1396 if (! flags.base_after_vec && flags.min_after_vec)
1398 min_addr -= align_fuzz (rel_lab, insn, rel_align, 0);
1399 min_addr -= align_fuzz (insn, min_lab, 0, 0);
1401 else
1402 min_addr -= align_fuzz (rel_lab, min_lab, rel_align, 0);
1404 else
1406 if (flags.base_after_vec && ! flags.min_after_vec)
1408 min_addr -= align_fuzz (min_lab, insn, 0, ~0);
1409 min_addr -= align_fuzz (insn, rel_lab, 0, ~0);
1411 else
1412 min_addr -= align_fuzz (min_lab, rel_lab, 0, ~0);
1414 /* Likewise, determine the highest lowest possible value
1415 for the offset of MAX_LAB. */
1416 if (flags.max_after_base)
1418 if (! flags.base_after_vec && flags.max_after_vec)
1420 max_addr += align_fuzz (rel_lab, insn, rel_align, ~0);
1421 max_addr += align_fuzz (insn, max_lab, 0, ~0);
1423 else
1424 max_addr += align_fuzz (rel_lab, max_lab, rel_align, ~0);
1426 else
1428 if (flags.base_after_vec && ! flags.max_after_vec)
1430 max_addr += align_fuzz (max_lab, insn, 0, 0);
1431 max_addr += align_fuzz (insn, rel_lab, 0, 0);
1433 else
1434 max_addr += align_fuzz (max_lab, rel_lab, 0, 0);
1436 PUT_MODE (body, CASE_VECTOR_SHORTEN_MODE (min_addr - rel_addr,
1437 max_addr - rel_addr,
1438 body));
1439 if (JUMP_TABLES_IN_TEXT_SECTION
1440 #if !defined(READONLY_DATA_SECTION)
1441 || 1
1442 #endif
1445 insn_lengths[uid]
1446 = (XVECLEN (body, 1) * GET_MODE_SIZE (GET_MODE (body)));
1447 insn_current_address += insn_lengths[uid];
1448 if (insn_lengths[uid] != old_length)
1449 something_changed = 1;
1452 continue;
1454 #endif /* CASE_VECTOR_SHORTEN_MODE */
1456 if (! (varying_length[uid]))
1458 insn_current_address += insn_lengths[uid];
1459 continue;
1461 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
1463 int i;
1465 body = PATTERN (insn);
1466 new_length = 0;
1467 for (i = 0; i < XVECLEN (body, 0); i++)
1469 rtx inner_insn = XVECEXP (body, 0, i);
1470 int inner_uid = INSN_UID (inner_insn);
1471 int inner_length;
1473 INSN_ADDRESSES (inner_uid) = insn_current_address;
1475 /* insn_current_length returns 0 for insns with a
1476 non-varying length. */
1477 if (! varying_length[inner_uid])
1478 inner_length = insn_lengths[inner_uid];
1479 else
1480 inner_length = insn_current_length (inner_insn);
1482 if (inner_length != insn_lengths[inner_uid])
1484 insn_lengths[inner_uid] = inner_length;
1485 something_changed = 1;
1487 insn_current_address += insn_lengths[inner_uid];
1488 new_length += inner_length;
1491 else
1493 new_length = insn_current_length (insn);
1494 insn_current_address += new_length;
1497 #ifdef ADJUST_INSN_LENGTH
1498 /* If needed, do any adjustment. */
1499 tmp_length = new_length;
1500 ADJUST_INSN_LENGTH (insn, new_length);
1501 insn_current_address += (new_length - tmp_length);
1502 #endif
1504 if (new_length != insn_lengths[uid])
1506 insn_lengths[uid] = new_length;
1507 something_changed = 1;
1510 /* For a non-optimizing compile, do only a single pass. */
1511 if (!optimize)
1512 break;
1515 free (varying_length);
1517 #endif /* HAVE_ATTR_length */
1520 #ifdef HAVE_ATTR_length
1521 /* Given the body of an INSN known to be generated by an ASM statement, return
1522 the number of machine instructions likely to be generated for this insn.
1523 This is used to compute its length. */
1525 static int
1526 asm_insn_count (body)
1527 rtx body;
1529 const char *template;
1530 int count = 1;
1532 if (GET_CODE (body) == ASM_INPUT)
1533 template = XSTR (body, 0);
1534 else
1535 template = decode_asm_operands (body, NULL, NULL, NULL, NULL);
1537 for (; *template; template++)
1538 if (IS_ASM_LOGICAL_LINE_SEPARATOR (*template) || *template == '\n')
1539 count++;
1541 return count;
1543 #endif
1545 /* Output assembler code for the start of a function,
1546 and initialize some of the variables in this file
1547 for the new function. The label for the function and associated
1548 assembler pseudo-ops have already been output in `assemble_start_function'.
1550 FIRST is the first insn of the rtl for the function being compiled.
1551 FILE is the file to write assembler code to.
1552 OPTIMIZE is nonzero if we should eliminate redundant
1553 test and compare insns. */
1555 void
1556 final_start_function (first, file, optimize)
1557 rtx first;
1558 FILE *file;
1559 int optimize ATTRIBUTE_UNUSED;
1561 block_depth = 0;
1563 this_is_asm_operands = 0;
1565 #ifdef NON_SAVING_SETJMP
1566 /* A function that calls setjmp should save and restore all the
1567 call-saved registers on a system where longjmp clobbers them. */
1568 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
1570 int i;
1572 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1573 if (!call_used_regs[i])
1574 regs_ever_live[i] = 1;
1576 #endif
1578 /* Initial line number is supposed to be output
1579 before the function's prologue and label
1580 so that the function's address will not appear to be
1581 in the last statement of the preceding function. */
1582 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1583 last_linenum = high_block_linenum = high_function_linenum
1584 = NOTE_LINE_NUMBER (first);
1586 #if defined (DWARF2_UNWIND_INFO) || defined (IA64_UNWIND_INFO) \
1587 || defined (DWARF2_DEBUGGING_INFO)
1588 dwarf2out_begin_prologue ();
1589 #endif
1591 /* For SDB and XCOFF, the function beginning must be marked between
1592 the function label and the prologue. We always need this, even when
1593 -g1 was used. Defer on MIPS systems so that parameter descriptions
1594 follow function entry. */
1595 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
1596 if (write_symbols == SDB_DEBUG)
1597 sdbout_begin_function (last_linenum);
1598 else
1599 #endif
1600 #ifdef XCOFF_DEBUGGING_INFO
1601 if (write_symbols == XCOFF_DEBUG)
1602 xcoffout_begin_function (file, last_linenum);
1603 else
1604 #endif
1605 /* But only output line number for other debug info types if -g2
1606 or better. */
1607 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1608 output_source_line (file, first);
1610 #ifdef LEAF_REG_REMAP
1611 if (current_function_uses_only_leaf_regs)
1612 leaf_renumber_regs (first);
1613 #endif
1615 /* The Sun386i and perhaps other machines don't work right
1616 if the profiling code comes after the prologue. */
1617 #ifdef PROFILE_BEFORE_PROLOGUE
1618 if (profile_flag)
1619 profile_function (file);
1620 #endif /* PROFILE_BEFORE_PROLOGUE */
1622 #if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
1623 if (dwarf2out_do_frame ())
1624 dwarf2out_frame_debug (NULL_RTX);
1625 #endif
1627 /* If debugging, assign block numbers to all of the blocks in this
1628 function. */
1629 if (write_symbols)
1631 number_blocks (current_function_decl);
1632 remove_unnecessary_notes ();
1633 /* We never actually put out begin/end notes for the top-level
1634 block in the function. But, conceptually, that block is
1635 always needed. */
1636 TREE_ASM_WRITTEN (DECL_INITIAL (current_function_decl)) = 1;
1639 #ifdef FUNCTION_PROLOGUE
1640 /* First output the function prologue: code to set up the stack frame. */
1641 FUNCTION_PROLOGUE (file, get_frame_size ());
1642 #endif
1644 /* If the machine represents the prologue as RTL, the profiling code must
1645 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
1646 #ifdef HAVE_prologue
1647 if (! HAVE_prologue)
1648 #endif
1649 profile_after_prologue (file);
1651 profile_label_no++;
1653 /* If we are doing basic block profiling, remember a printable version
1654 of the function name. */
1655 if (profile_block_flag)
1657 bb_func_label_num =
1658 add_bb_string ((*decl_printable_name) (current_function_decl, 2),
1659 FALSE);
1663 static void
1664 profile_after_prologue (file)
1665 FILE *file ATTRIBUTE_UNUSED;
1667 #ifdef FUNCTION_BLOCK_PROFILER
1668 if (profile_block_flag)
1670 FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
1672 #endif /* FUNCTION_BLOCK_PROFILER */
1674 #ifndef PROFILE_BEFORE_PROLOGUE
1675 if (profile_flag)
1676 profile_function (file);
1677 #endif /* not PROFILE_BEFORE_PROLOGUE */
1680 static void
1681 profile_function (file)
1682 FILE *file;
1684 #ifndef NO_PROFILE_COUNTERS
1685 int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
1686 #endif
1687 #if defined(ASM_OUTPUT_REG_PUSH)
1688 #if defined(STRUCT_VALUE_INCOMING_REGNUM) || defined(STRUCT_VALUE_REGNUM)
1689 int sval = current_function_returns_struct;
1690 #endif
1691 #if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
1692 int cxt = current_function_needs_context;
1693 #endif
1694 #endif /* ASM_OUTPUT_REG_PUSH */
1696 #ifndef NO_PROFILE_COUNTERS
1697 data_section ();
1698 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
1699 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
1700 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, 1);
1701 #endif
1703 function_section (current_function_decl);
1705 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1706 if (sval)
1707 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
1708 #else
1709 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1710 if (sval)
1712 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
1714 #endif
1715 #endif
1717 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1718 if (cxt)
1719 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1720 #else
1721 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1722 if (cxt)
1724 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1726 #endif
1727 #endif
1729 FUNCTION_PROFILER (file, profile_label_no);
1731 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1732 if (cxt)
1733 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1734 #else
1735 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1736 if (cxt)
1738 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1740 #endif
1741 #endif
1743 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1744 if (sval)
1745 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1746 #else
1747 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1748 if (sval)
1750 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1752 #endif
1753 #endif
1756 /* Output assembler code for the end of a function.
1757 For clarity, args are same as those of `final_start_function'
1758 even though not all of them are needed. */
1760 void
1761 final_end_function (first, file, optimize)
1762 rtx first ATTRIBUTE_UNUSED;
1763 FILE *file ATTRIBUTE_UNUSED;
1764 int optimize ATTRIBUTE_UNUSED;
1766 app_disable ();
1768 #ifdef SDB_DEBUGGING_INFO
1769 if (write_symbols == SDB_DEBUG)
1770 sdbout_end_function (high_function_linenum);
1771 #endif
1773 #ifdef DWARF_DEBUGGING_INFO
1774 if (write_symbols == DWARF_DEBUG)
1775 dwarfout_end_function ();
1776 #endif
1778 #ifdef XCOFF_DEBUGGING_INFO
1779 if (write_symbols == XCOFF_DEBUG)
1780 xcoffout_end_function (file, high_function_linenum);
1781 #endif
1783 #ifdef FUNCTION_EPILOGUE
1784 /* Finally, output the function epilogue:
1785 code to restore the stack frame and return to the caller. */
1786 FUNCTION_EPILOGUE (file, get_frame_size ());
1787 #endif
1789 #ifdef SDB_DEBUGGING_INFO
1790 if (write_symbols == SDB_DEBUG)
1791 sdbout_end_epilogue ();
1792 #endif
1794 #ifdef DWARF_DEBUGGING_INFO
1795 if (write_symbols == DWARF_DEBUG)
1796 dwarfout_end_epilogue ();
1797 #endif
1799 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1800 if (dwarf2out_do_frame ())
1801 dwarf2out_end_epilogue ();
1802 #endif
1804 #ifdef XCOFF_DEBUGGING_INFO
1805 if (write_symbols == XCOFF_DEBUG)
1806 xcoffout_end_epilogue (file);
1807 #endif
1809 bb_func_label_num = -1; /* not in function, nuke label # */
1811 /* If FUNCTION_EPILOGUE is not defined, then the function body
1812 itself contains return instructions wherever needed. */
1815 /* Add a block to the linked list that remembers the current line/file/function
1816 for basic block profiling. Emit the label in front of the basic block and
1817 the instructions that increment the count field. */
1819 static void
1820 add_bb (file)
1821 FILE *file;
1823 struct bb_list *ptr =
1824 (struct bb_list *) permalloc (sizeof (struct bb_list));
1826 /* Add basic block to linked list. */
1827 ptr->next = 0;
1828 ptr->line_num = last_linenum;
1829 ptr->file_label_num = bb_file_label_num;
1830 ptr->func_label_num = bb_func_label_num;
1831 *bb_tail = ptr;
1832 bb_tail = &ptr->next;
1834 /* Enable the table of basic-block use counts
1835 to point at the code it applies to. */
1836 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1838 /* Before first insn of this basic block, increment the
1839 count of times it was entered. */
1840 #ifdef BLOCK_PROFILER
1841 BLOCK_PROFILER (file, count_basic_blocks);
1842 #endif
1843 #ifdef HAVE_cc0
1844 CC_STATUS_INIT;
1845 #endif
1847 new_block = 0;
1848 count_basic_blocks++;
1851 /* Add a string to be used for basic block profiling. */
1853 static int
1854 add_bb_string (string, perm_p)
1855 const char *string;
1856 int perm_p;
1858 int len;
1859 struct bb_str *ptr = 0;
1861 if (!string)
1863 string = "<unknown>";
1864 perm_p = TRUE;
1867 /* Allocate a new string if the current string isn't permanent. If
1868 the string is permanent search for the same string in other
1869 allocations. */
1871 len = strlen (string) + 1;
1872 if (!perm_p)
1874 char *p = (char *) permalloc (len);
1875 memcpy (p, string, len);
1876 string = p;
1878 else
1879 for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
1880 if (ptr->string == string)
1881 break;
1883 /* Allocate a new string block if we need to. */
1884 if (!ptr)
1886 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1887 ptr->next = 0;
1888 ptr->length = len;
1889 ptr->label_num = sbb_label_num++;
1890 ptr->string = string;
1891 *sbb_tail = ptr;
1892 sbb_tail = &ptr->next;
1895 return ptr->label_num;
1898 /* Output assembler code for some insns: all or part of a function.
1899 For description of args, see `final_start_function', above.
1901 PRESCAN is 1 if we are not really outputting,
1902 just scanning as if we were outputting.
1903 Prescanning deletes and rearranges insns just like ordinary output.
1904 PRESCAN is -2 if we are outputting after having prescanned.
1905 In this case, don't try to delete or rearrange insns
1906 because that has already been done.
1907 Prescanning is done only on certain machines. */
1909 void
1910 final (first, file, optimize, prescan)
1911 rtx first;
1912 FILE *file;
1913 int optimize;
1914 int prescan;
1916 register rtx insn;
1917 int max_line = 0;
1918 int max_uid = 0;
1920 last_ignored_compare = 0;
1921 new_block = 1;
1923 /* Make a map indicating which line numbers appear in this function.
1924 When producing SDB debugging info, delete troublesome line number
1925 notes from inlined functions in other files as well as duplicate
1926 line number notes. */
1927 #ifdef SDB_DEBUGGING_INFO
1928 if (write_symbols == SDB_DEBUG)
1930 rtx last = 0;
1931 for (insn = first; insn; insn = NEXT_INSN (insn))
1932 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1934 if ((RTX_INTEGRATED_P (insn)
1935 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1936 || (last != 0
1937 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1938 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1940 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1941 NOTE_SOURCE_FILE (insn) = 0;
1942 continue;
1944 last = insn;
1945 if (NOTE_LINE_NUMBER (insn) > max_line)
1946 max_line = NOTE_LINE_NUMBER (insn);
1949 else
1950 #endif
1952 for (insn = first; insn; insn = NEXT_INSN (insn))
1953 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1954 max_line = NOTE_LINE_NUMBER (insn);
1957 line_note_exists = (char *) xcalloc (max_line + 1, sizeof (char));
1959 for (insn = first; insn; insn = NEXT_INSN (insn))
1961 if (INSN_UID (insn) > max_uid) /* find largest UID */
1962 max_uid = INSN_UID (insn);
1963 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1964 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1965 #ifdef HAVE_cc0
1966 /* If CC tracking across branches is enabled, record the insn which
1967 jumps to each branch only reached from one place. */
1968 if (optimize && GET_CODE (insn) == JUMP_INSN)
1970 rtx lab = JUMP_LABEL (insn);
1971 if (lab && LABEL_NUSES (lab) == 1)
1973 LABEL_REFS (lab) = insn;
1976 #endif
1979 init_recog ();
1981 CC_STATUS_INIT;
1983 /* Output the insns. */
1984 for (insn = NEXT_INSN (first); insn;)
1986 #ifdef HAVE_ATTR_length
1987 if (INSN_UID (insn) >= INSN_ADDRESSES_SIZE ())
1989 #ifdef STACK_REGS
1990 /* Irritatingly, the reg-stack pass is creating new instructions
1991 and because of REG_DEAD note abuse it has to run after
1992 shorten_branches. Fake address of -1 then. */
1993 insn_current_address = -1;
1994 #else
1995 /* This can be triggered by bugs elsewhere in the compiler if
1996 new insns are created after init_insn_lengths is called. */
1997 abort ();
1998 #endif
2000 else
2001 insn_current_address = INSN_ADDRESSES (INSN_UID (insn));
2002 #endif /* HAVE_ATTR_length */
2004 insn = final_scan_insn (insn, file, optimize, prescan, 0);
2007 /* Do basic-block profiling here
2008 if the last insn was a conditional branch. */
2009 if (profile_block_flag && new_block)
2010 add_bb (file);
2012 free (line_note_exists);
2013 line_note_exists = NULL;
2016 const char *
2017 get_insn_template (code, insn)
2018 int code;
2019 rtx insn;
2021 const void *output = insn_data[code].output;
2022 switch (insn_data[code].output_format)
2024 case INSN_OUTPUT_FORMAT_SINGLE:
2025 return (const char *) output;
2026 case INSN_OUTPUT_FORMAT_MULTI:
2027 return ((const char *const *) output)[which_alternative];
2028 case INSN_OUTPUT_FORMAT_FUNCTION:
2029 if (insn == NULL)
2030 abort ();
2031 return (*(insn_output_fn) output) (recog_data.operand, insn);
2033 default:
2034 abort ();
2038 /* The final scan for one insn, INSN.
2039 Args are same as in `final', except that INSN
2040 is the insn being scanned.
2041 Value returned is the next insn to be scanned.
2043 NOPEEPHOLES is the flag to disallow peephole processing (currently
2044 used for within delayed branch sequence output). */
2047 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
2048 rtx insn;
2049 FILE *file;
2050 int optimize ATTRIBUTE_UNUSED;
2051 int prescan;
2052 int nopeepholes ATTRIBUTE_UNUSED;
2054 #ifdef HAVE_cc0
2055 rtx set;
2056 #endif
2058 insn_counter++;
2060 /* Ignore deleted insns. These can occur when we split insns (due to a
2061 template of "#") while not optimizing. */
2062 if (INSN_DELETED_P (insn))
2063 return NEXT_INSN (insn);
2065 switch (GET_CODE (insn))
2067 case NOTE:
2068 if (prescan > 0)
2069 break;
2071 switch (NOTE_LINE_NUMBER (insn))
2073 case NOTE_INSN_DELETED:
2074 case NOTE_INSN_LOOP_BEG:
2075 case NOTE_INSN_LOOP_END:
2076 case NOTE_INSN_LOOP_CONT:
2077 case NOTE_INSN_LOOP_VTOP:
2078 case NOTE_INSN_FUNCTION_END:
2079 case NOTE_INSN_SETJMP:
2080 case NOTE_INSN_REPEATED_LINE_NUMBER:
2081 case NOTE_INSN_RANGE_BEG:
2082 case NOTE_INSN_RANGE_END:
2083 case NOTE_INSN_LIVE:
2084 case NOTE_INSN_EXPECTED_VALUE:
2085 break;
2087 case NOTE_INSN_BASIC_BLOCK:
2088 #ifdef IA64_UNWIND_INFO
2089 IA64_UNWIND_EMIT (asm_out_file, insn);
2090 #endif
2091 if (flag_debug_asm)
2092 fprintf (asm_out_file, "\t%s basic block %d\n",
2093 ASM_COMMENT_START, NOTE_BASIC_BLOCK (insn)->index);
2094 break;
2096 case NOTE_INSN_EH_REGION_BEG:
2097 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHB",
2098 NOTE_EH_HANDLER (insn));
2099 break;
2101 case NOTE_INSN_EH_REGION_END:
2102 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHE",
2103 NOTE_EH_HANDLER (insn));
2104 break;
2106 case NOTE_INSN_PROLOGUE_END:
2107 #ifdef FUNCTION_END_PROLOGUE
2108 FUNCTION_END_PROLOGUE (file);
2109 #endif
2110 profile_after_prologue (file);
2111 break;
2113 case NOTE_INSN_EPILOGUE_BEG:
2114 #ifdef FUNCTION_BEGIN_EPILOGUE
2115 FUNCTION_BEGIN_EPILOGUE (file);
2116 #endif
2117 break;
2119 case NOTE_INSN_FUNCTION_BEG:
2120 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
2121 /* MIPS stabs require the parameter descriptions to be after the
2122 function entry point rather than before. */
2123 if (write_symbols == SDB_DEBUG)
2125 app_disable ();
2126 sdbout_begin_function (last_linenum);
2128 #endif
2129 #ifdef DWARF_DEBUGGING_INFO
2130 /* This outputs a marker where the function body starts, so it
2131 must be after the prologue. */
2132 if (write_symbols == DWARF_DEBUG)
2134 app_disable ();
2135 dwarfout_begin_function ();
2137 #endif
2138 break;
2140 case NOTE_INSN_BLOCK_BEG:
2141 if (debug_info_level == DINFO_LEVEL_NORMAL
2142 || debug_info_level == DINFO_LEVEL_VERBOSE
2143 || write_symbols == DWARF_DEBUG
2144 || write_symbols == DWARF2_DEBUG)
2146 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2148 app_disable ();
2149 ++block_depth;
2150 high_block_linenum = last_linenum;
2152 /* Output debugging info about the symbol-block beginning. */
2153 #ifdef SDB_DEBUGGING_INFO
2154 if (write_symbols == SDB_DEBUG)
2155 sdbout_begin_block (file, last_linenum, n);
2156 #endif
2157 #ifdef XCOFF_DEBUGGING_INFO
2158 if (write_symbols == XCOFF_DEBUG)
2159 xcoffout_begin_block (file, last_linenum, n);
2160 #endif
2161 #ifdef DBX_DEBUGGING_INFO
2162 if (write_symbols == DBX_DEBUG)
2163 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", n);
2164 #endif
2165 #ifdef DWARF_DEBUGGING_INFO
2166 if (write_symbols == DWARF_DEBUG)
2167 dwarfout_begin_block (n);
2168 #endif
2169 #ifdef DWARF2_DEBUGGING_INFO
2170 if (write_symbols == DWARF2_DEBUG)
2171 dwarf2out_begin_block (n);
2172 #endif
2174 /* Mark this block as output. */
2175 TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
2177 break;
2179 case NOTE_INSN_BLOCK_END:
2180 if (debug_info_level == DINFO_LEVEL_NORMAL
2181 || debug_info_level == DINFO_LEVEL_VERBOSE
2182 || write_symbols == DWARF_DEBUG
2183 || write_symbols == DWARF2_DEBUG)
2185 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2187 app_disable ();
2189 /* End of a symbol-block. */
2190 --block_depth;
2191 if (block_depth < 0)
2192 abort ();
2194 #ifdef XCOFF_DEBUGGING_INFO
2195 if (write_symbols == XCOFF_DEBUG)
2196 xcoffout_end_block (file, high_block_linenum, n);
2197 #endif
2198 #ifdef DBX_DEBUGGING_INFO
2199 if (write_symbols == DBX_DEBUG)
2200 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE", n);
2201 #endif
2202 #ifdef SDB_DEBUGGING_INFO
2203 if (write_symbols == SDB_DEBUG)
2204 sdbout_end_block (file, high_block_linenum, n);
2205 #endif
2206 #ifdef DWARF_DEBUGGING_INFO
2207 if (write_symbols == DWARF_DEBUG)
2208 dwarfout_end_block (n);
2209 #endif
2210 #ifdef DWARF2_DEBUGGING_INFO
2211 if (write_symbols == DWARF2_DEBUG)
2212 dwarf2out_end_block (n);
2213 #endif
2215 break;
2217 case NOTE_INSN_DELETED_LABEL:
2218 /* Emit the label. We may have deleted the CODE_LABEL because
2219 the label could be proved to be unreachable, though still
2220 referenced (in the form of having its address taken. */
2221 ASM_OUTPUT_DEBUG_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2222 break;
2224 case 0:
2225 break;
2227 default:
2228 if (NOTE_LINE_NUMBER (insn) <= 0)
2229 abort ();
2231 /* This note is a line-number. */
2233 register rtx note;
2234 int note_after = 0;
2236 /* If there is anything real after this note, output it.
2237 If another line note follows, omit this one. */
2238 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
2240 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
2241 break;
2243 /* These types of notes can be significant
2244 so make sure the preceding line number stays. */
2245 else if (GET_CODE (note) == NOTE
2246 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
2247 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
2248 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
2249 break;
2250 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
2252 /* Another line note follows; we can delete this note
2253 if no intervening line numbers have notes elsewhere. */
2254 int num;
2255 for (num = NOTE_LINE_NUMBER (insn) + 1;
2256 num < NOTE_LINE_NUMBER (note);
2257 num++)
2258 if (line_note_exists[num])
2259 break;
2261 if (num >= NOTE_LINE_NUMBER (note))
2262 note_after = 1;
2263 break;
2267 /* Output this line note if it is the first or the last line
2268 note in a row. */
2269 if (!note_after)
2270 output_source_line (file, insn);
2272 break;
2274 break;
2276 case BARRIER:
2277 #if defined (DWARF2_UNWIND_INFO)
2278 if (dwarf2out_do_frame ())
2279 dwarf2out_frame_debug (insn);
2280 #endif
2281 break;
2283 case CODE_LABEL:
2284 /* The target port might emit labels in the output function for
2285 some insn, e.g. sh.c output_branchy_insn. */
2286 if (CODE_LABEL_NUMBER (insn) <= max_labelno)
2288 int align = LABEL_TO_ALIGNMENT (insn);
2289 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2290 int max_skip = LABEL_TO_MAX_SKIP (insn);
2291 #endif
2293 if (align && NEXT_INSN (insn))
2294 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2295 ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
2296 #else
2297 ASM_OUTPUT_ALIGN (file, align);
2298 #endif
2300 #ifdef HAVE_cc0
2301 CC_STATUS_INIT;
2302 /* If this label is reached from only one place, set the condition
2303 codes from the instruction just before the branch. */
2305 /* Disabled because some insns set cc_status in the C output code
2306 and NOTICE_UPDATE_CC alone can set incorrect status. */
2307 if (0 /* optimize && LABEL_NUSES (insn) == 1*/)
2309 rtx jump = LABEL_REFS (insn);
2310 rtx barrier = prev_nonnote_insn (insn);
2311 rtx prev;
2312 /* If the LABEL_REFS field of this label has been set to point
2313 at a branch, the predecessor of the branch is a regular
2314 insn, and that branch is the only way to reach this label,
2315 set the condition codes based on the branch and its
2316 predecessor. */
2317 if (barrier && GET_CODE (barrier) == BARRIER
2318 && jump && GET_CODE (jump) == JUMP_INSN
2319 && (prev = prev_nonnote_insn (jump))
2320 && GET_CODE (prev) == INSN)
2322 NOTICE_UPDATE_CC (PATTERN (prev), prev);
2323 NOTICE_UPDATE_CC (PATTERN (jump), jump);
2326 #endif
2327 if (prescan > 0)
2328 break;
2329 new_block = 1;
2331 #ifdef FINAL_PRESCAN_LABEL
2332 FINAL_PRESCAN_INSN (insn, NULL, 0);
2333 #endif
2335 #ifdef SDB_DEBUGGING_INFO
2336 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
2337 sdbout_label (insn);
2338 #endif
2339 if (app_on)
2341 fputs (ASM_APP_OFF, file);
2342 app_on = 0;
2344 if (NEXT_INSN (insn) != 0
2345 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
2347 rtx nextbody = PATTERN (NEXT_INSN (insn));
2349 /* If this label is followed by a jump-table,
2350 make sure we put the label in the read-only section. Also
2351 possibly write the label and jump table together. */
2353 if (GET_CODE (nextbody) == ADDR_VEC
2354 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
2356 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2357 /* In this case, the case vector is being moved by the
2358 target, so don't output the label at all. Leave that
2359 to the back end macros. */
2360 #else
2361 if (! JUMP_TABLES_IN_TEXT_SECTION)
2363 readonly_data_section ();
2364 #ifdef READONLY_DATA_SECTION
2365 ASM_OUTPUT_ALIGN (file,
2366 exact_log2 (BIGGEST_ALIGNMENT
2367 / BITS_PER_UNIT));
2368 #endif /* READONLY_DATA_SECTION */
2370 else
2371 function_section (current_function_decl);
2373 #ifdef ASM_OUTPUT_CASE_LABEL
2374 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
2375 NEXT_INSN (insn));
2376 #else
2377 if (LABEL_ALTERNATE_NAME (insn))
2378 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2379 else
2380 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2381 #endif
2382 #endif
2383 break;
2386 if (LABEL_ALTERNATE_NAME (insn))
2387 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2388 else
2389 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2390 break;
2392 default:
2394 register rtx body = PATTERN (insn);
2395 int insn_code_number;
2396 const char *template;
2397 #ifdef HAVE_cc0
2398 rtx note;
2399 #endif
2401 /* An INSN, JUMP_INSN or CALL_INSN.
2402 First check for special kinds that recog doesn't recognize. */
2404 if (GET_CODE (body) == USE /* These are just declarations */
2405 || GET_CODE (body) == CLOBBER)
2406 break;
2408 #ifdef HAVE_cc0
2409 /* If there is a REG_CC_SETTER note on this insn, it means that
2410 the setting of the condition code was done in the delay slot
2411 of the insn that branched here. So recover the cc status
2412 from the insn that set it. */
2414 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2415 if (note)
2417 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
2418 cc_prev_status = cc_status;
2420 #endif
2422 /* Detect insns that are really jump-tables
2423 and output them as such. */
2425 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
2427 #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
2428 register int vlen, idx;
2429 #endif
2431 if (prescan > 0)
2432 break;
2434 if (app_on)
2436 fputs (ASM_APP_OFF, file);
2437 app_on = 0;
2440 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2441 if (GET_CODE (body) == ADDR_VEC)
2443 #ifdef ASM_OUTPUT_ADDR_VEC
2444 ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
2445 #else
2446 abort ();
2447 #endif
2449 else
2451 #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
2452 ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
2453 #else
2454 abort ();
2455 #endif
2457 #else
2458 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2459 for (idx = 0; idx < vlen; idx++)
2461 if (GET_CODE (body) == ADDR_VEC)
2463 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2464 ASM_OUTPUT_ADDR_VEC_ELT
2465 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2466 #else
2467 abort ();
2468 #endif
2470 else
2472 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2473 ASM_OUTPUT_ADDR_DIFF_ELT
2474 (file,
2475 body,
2476 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2477 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2478 #else
2479 abort ();
2480 #endif
2483 #ifdef ASM_OUTPUT_CASE_END
2484 ASM_OUTPUT_CASE_END (file,
2485 CODE_LABEL_NUMBER (PREV_INSN (insn)),
2486 insn);
2487 #endif
2488 #endif
2490 function_section (current_function_decl);
2492 break;
2495 /* Do basic-block profiling when we reach a new block.
2496 Done here to avoid jump tables. */
2497 if (profile_block_flag && new_block)
2498 add_bb (file);
2500 if (GET_CODE (body) == ASM_INPUT)
2502 /* There's no telling what that did to the condition codes. */
2503 CC_STATUS_INIT;
2504 if (prescan > 0)
2505 break;
2506 if (! app_on)
2508 fputs (ASM_APP_ON, file);
2509 app_on = 1;
2511 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
2512 break;
2515 /* Detect `asm' construct with operands. */
2516 if (asm_noperands (body) >= 0)
2518 unsigned int noperands = asm_noperands (body);
2519 rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
2520 const char *string;
2522 /* There's no telling what that did to the condition codes. */
2523 CC_STATUS_INIT;
2524 if (prescan > 0)
2525 break;
2527 if (! app_on)
2529 fputs (ASM_APP_ON, file);
2530 app_on = 1;
2533 /* Get out the operand values. */
2534 string = decode_asm_operands (body, ops, NULL, NULL, NULL);
2535 /* Inhibit aborts on what would otherwise be compiler bugs. */
2536 insn_noperands = noperands;
2537 this_is_asm_operands = insn;
2539 /* Output the insn using them. */
2540 output_asm_insn (string, ops);
2541 this_is_asm_operands = 0;
2542 break;
2545 if (prescan <= 0 && app_on)
2547 fputs (ASM_APP_OFF, file);
2548 app_on = 0;
2551 if (GET_CODE (body) == SEQUENCE)
2553 /* A delayed-branch sequence */
2554 register int i;
2555 rtx next;
2557 if (prescan > 0)
2558 break;
2559 final_sequence = body;
2561 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2562 force the restoration of a comparison that was previously
2563 thought unnecessary. If that happens, cancel this sequence
2564 and cause that insn to be restored. */
2566 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
2567 if (next != XVECEXP (body, 0, 1))
2569 final_sequence = 0;
2570 return next;
2573 for (i = 1; i < XVECLEN (body, 0); i++)
2575 rtx insn = XVECEXP (body, 0, i);
2576 rtx next = NEXT_INSN (insn);
2577 /* We loop in case any instruction in a delay slot gets
2578 split. */
2580 insn = final_scan_insn (insn, file, 0, prescan, 1);
2581 while (insn != next);
2583 #ifdef DBR_OUTPUT_SEQEND
2584 DBR_OUTPUT_SEQEND (file);
2585 #endif
2586 final_sequence = 0;
2588 /* If the insn requiring the delay slot was a CALL_INSN, the
2589 insns in the delay slot are actually executed before the
2590 called function. Hence we don't preserve any CC-setting
2591 actions in these insns and the CC must be marked as being
2592 clobbered by the function. */
2593 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
2595 CC_STATUS_INIT;
2598 /* Following a conditional branch sequence, we have a new basic
2599 block. */
2600 if (profile_block_flag)
2602 rtx insn = XVECEXP (body, 0, 0);
2603 rtx body = PATTERN (insn);
2605 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2606 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2607 || (GET_CODE (insn) == JUMP_INSN
2608 && GET_CODE (body) == PARALLEL
2609 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2610 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
2611 new_block = 1;
2613 break;
2616 /* We have a real machine instruction as rtl. */
2618 body = PATTERN (insn);
2620 #ifdef HAVE_cc0
2621 set = single_set (insn);
2623 /* Check for redundant test and compare instructions
2624 (when the condition codes are already set up as desired).
2625 This is done only when optimizing; if not optimizing,
2626 it should be possible for the user to alter a variable
2627 with the debugger in between statements
2628 and the next statement should reexamine the variable
2629 to compute the condition codes. */
2631 if (optimize)
2633 #if 0
2634 rtx set = single_set (insn);
2635 #endif
2637 if (set
2638 && GET_CODE (SET_DEST (set)) == CC0
2639 && insn != last_ignored_compare)
2641 if (GET_CODE (SET_SRC (set)) == SUBREG)
2642 SET_SRC (set) = alter_subreg (SET_SRC (set));
2643 else if (GET_CODE (SET_SRC (set)) == COMPARE)
2645 if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
2646 XEXP (SET_SRC (set), 0)
2647 = alter_subreg (XEXP (SET_SRC (set), 0));
2648 if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
2649 XEXP (SET_SRC (set), 1)
2650 = alter_subreg (XEXP (SET_SRC (set), 1));
2652 if ((cc_status.value1 != 0
2653 && rtx_equal_p (SET_SRC (set), cc_status.value1))
2654 || (cc_status.value2 != 0
2655 && rtx_equal_p (SET_SRC (set), cc_status.value2)))
2657 /* Don't delete insn if it has an addressing side-effect. */
2658 if (! FIND_REG_INC_NOTE (insn, 0)
2659 /* or if anything in it is volatile. */
2660 && ! volatile_refs_p (PATTERN (insn)))
2662 /* We don't really delete the insn; just ignore it. */
2663 last_ignored_compare = insn;
2664 break;
2669 #endif
2671 /* Following a conditional branch, we have a new basic block.
2672 But if we are inside a sequence, the new block starts after the
2673 last insn of the sequence. */
2674 if (profile_block_flag && final_sequence == 0
2675 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2676 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2677 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
2678 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2679 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
2680 new_block = 1;
2682 #ifndef STACK_REGS
2683 /* Don't bother outputting obvious no-ops, even without -O.
2684 This optimization is fast and doesn't interfere with debugging.
2685 Don't do this if the insn is in a delay slot, since this
2686 will cause an improper number of delay insns to be written. */
2687 if (final_sequence == 0
2688 && prescan >= 0
2689 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
2690 && GET_CODE (SET_SRC (body)) == REG
2691 && GET_CODE (SET_DEST (body)) == REG
2692 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
2693 break;
2694 #endif
2696 #ifdef HAVE_cc0
2697 /* If this is a conditional branch, maybe modify it
2698 if the cc's are in a nonstandard state
2699 so that it accomplishes the same thing that it would
2700 do straightforwardly if the cc's were set up normally. */
2702 if (cc_status.flags != 0
2703 && GET_CODE (insn) == JUMP_INSN
2704 && GET_CODE (body) == SET
2705 && SET_DEST (body) == pc_rtx
2706 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2707 && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
2708 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
2709 /* This is done during prescan; it is not done again
2710 in final scan when prescan has been done. */
2711 && prescan >= 0)
2713 /* This function may alter the contents of its argument
2714 and clear some of the cc_status.flags bits.
2715 It may also return 1 meaning condition now always true
2716 or -1 meaning condition now always false
2717 or 2 meaning condition nontrivial but altered. */
2718 register int result = alter_cond (XEXP (SET_SRC (body), 0));
2719 /* If condition now has fixed value, replace the IF_THEN_ELSE
2720 with its then-operand or its else-operand. */
2721 if (result == 1)
2722 SET_SRC (body) = XEXP (SET_SRC (body), 1);
2723 if (result == -1)
2724 SET_SRC (body) = XEXP (SET_SRC (body), 2);
2726 /* The jump is now either unconditional or a no-op.
2727 If it has become a no-op, don't try to output it.
2728 (It would not be recognized.) */
2729 if (SET_SRC (body) == pc_rtx)
2731 PUT_CODE (insn, NOTE);
2732 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2733 NOTE_SOURCE_FILE (insn) = 0;
2734 break;
2736 else if (GET_CODE (SET_SRC (body)) == RETURN)
2737 /* Replace (set (pc) (return)) with (return). */
2738 PATTERN (insn) = body = SET_SRC (body);
2740 /* Rerecognize the instruction if it has changed. */
2741 if (result != 0)
2742 INSN_CODE (insn) = -1;
2745 /* Make same adjustments to instructions that examine the
2746 condition codes without jumping and instructions that
2747 handle conditional moves (if this machine has either one). */
2749 if (cc_status.flags != 0
2750 && set != 0)
2752 rtx cond_rtx, then_rtx, else_rtx;
2754 if (GET_CODE (insn) != JUMP_INSN
2755 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2757 cond_rtx = XEXP (SET_SRC (set), 0);
2758 then_rtx = XEXP (SET_SRC (set), 1);
2759 else_rtx = XEXP (SET_SRC (set), 2);
2761 else
2763 cond_rtx = SET_SRC (set);
2764 then_rtx = const_true_rtx;
2765 else_rtx = const0_rtx;
2768 switch (GET_CODE (cond_rtx))
2770 case GTU:
2771 case GT:
2772 case LTU:
2773 case LT:
2774 case GEU:
2775 case GE:
2776 case LEU:
2777 case LE:
2778 case EQ:
2779 case NE:
2781 register int result;
2782 if (XEXP (cond_rtx, 0) != cc0_rtx)
2783 break;
2784 result = alter_cond (cond_rtx);
2785 if (result == 1)
2786 validate_change (insn, &SET_SRC (set), then_rtx, 0);
2787 else if (result == -1)
2788 validate_change (insn, &SET_SRC (set), else_rtx, 0);
2789 else if (result == 2)
2790 INSN_CODE (insn) = -1;
2791 if (SET_DEST (set) == SET_SRC (set))
2793 PUT_CODE (insn, NOTE);
2794 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2795 NOTE_SOURCE_FILE (insn) = 0;
2798 break;
2800 default:
2801 break;
2805 #endif
2807 #ifdef HAVE_peephole
2808 /* Do machine-specific peephole optimizations if desired. */
2810 if (optimize && !flag_no_peephole && !nopeepholes)
2812 rtx next = peephole (insn);
2813 /* When peepholing, if there were notes within the peephole,
2814 emit them before the peephole. */
2815 if (next != 0 && next != NEXT_INSN (insn))
2817 rtx prev = PREV_INSN (insn);
2818 rtx note;
2820 for (note = NEXT_INSN (insn); note != next;
2821 note = NEXT_INSN (note))
2822 final_scan_insn (note, file, optimize, prescan, nopeepholes);
2824 /* In case this is prescan, put the notes
2825 in proper position for later rescan. */
2826 note = NEXT_INSN (insn);
2827 PREV_INSN (note) = prev;
2828 NEXT_INSN (prev) = note;
2829 NEXT_INSN (PREV_INSN (next)) = insn;
2830 PREV_INSN (insn) = PREV_INSN (next);
2831 NEXT_INSN (insn) = next;
2832 PREV_INSN (next) = insn;
2835 /* PEEPHOLE might have changed this. */
2836 body = PATTERN (insn);
2838 #endif
2840 /* Try to recognize the instruction.
2841 If successful, verify that the operands satisfy the
2842 constraints for the instruction. Crash if they don't,
2843 since `reload' should have changed them so that they do. */
2845 insn_code_number = recog_memoized (insn);
2846 cleanup_subreg_operands (insn);
2848 /* Dump the insn in the assembly for debugging. */
2849 if (flag_dump_rtl_in_asm)
2851 print_rtx_head = ASM_COMMENT_START;
2852 print_rtl_single (asm_out_file, insn);
2853 print_rtx_head = "";
2856 if (! constrain_operands_cached (1))
2857 fatal_insn_not_found (insn);
2859 /* Some target machines need to prescan each insn before
2860 it is output. */
2862 #ifdef FINAL_PRESCAN_INSN
2863 FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2864 #endif
2866 #ifdef HAVE_conditional_execution
2867 if (GET_CODE (PATTERN (insn)) == COND_EXEC)
2868 current_insn_predicate = COND_EXEC_TEST (PATTERN (insn));
2869 else
2870 current_insn_predicate = NULL_RTX;
2871 #endif
2873 #ifdef HAVE_cc0
2874 cc_prev_status = cc_status;
2876 /* Update `cc_status' for this instruction.
2877 The instruction's output routine may change it further.
2878 If the output routine for a jump insn needs to depend
2879 on the cc status, it should look at cc_prev_status. */
2881 NOTICE_UPDATE_CC (body, insn);
2882 #endif
2884 current_output_insn = debug_insn = insn;
2886 #if defined (DWARF2_UNWIND_INFO)
2887 if (GET_CODE (insn) == CALL_INSN && dwarf2out_do_frame ())
2888 dwarf2out_frame_debug (insn);
2889 #endif
2891 /* Find the proper template for this insn. */
2892 template = get_insn_template (insn_code_number, insn);
2894 /* If the C code returns 0, it means that it is a jump insn
2895 which follows a deleted test insn, and that test insn
2896 needs to be reinserted. */
2897 if (template == 0)
2899 rtx prev;
2901 if (prev_nonnote_insn (insn) != last_ignored_compare)
2902 abort ();
2903 new_block = 0;
2905 /* We have already processed the notes between the setter and
2906 the user. Make sure we don't process them again, this is
2907 particularly important if one of the notes is a block
2908 scope note or an EH note. */
2909 for (prev = insn;
2910 prev != last_ignored_compare;
2911 prev = PREV_INSN (prev))
2913 if (GET_CODE (prev) == NOTE)
2915 NOTE_LINE_NUMBER (prev) = NOTE_INSN_DELETED;
2916 NOTE_SOURCE_FILE (prev) = 0;
2920 return prev;
2923 /* If the template is the string "#", it means that this insn must
2924 be split. */
2925 if (template[0] == '#' && template[1] == '\0')
2927 rtx new = try_split (body, insn, 0);
2929 /* If we didn't split the insn, go away. */
2930 if (new == insn && PATTERN (new) == body)
2931 fatal_insn ("Could not split insn", insn);
2933 #ifdef HAVE_ATTR_length
2934 /* This instruction should have been split in shorten_branches,
2935 to ensure that we would have valid length info for the
2936 splitees. */
2937 abort ();
2938 #endif
2940 new_block = 0;
2941 return new;
2944 if (prescan > 0)
2945 break;
2947 #ifdef IA64_UNWIND_INFO
2948 IA64_UNWIND_EMIT (asm_out_file, insn);
2949 #endif
2950 /* Output assembler code from the template. */
2952 output_asm_insn (template, recog_data.operand);
2954 #if defined (DWARF2_UNWIND_INFO)
2955 #if defined (HAVE_prologue)
2956 if (GET_CODE (insn) == INSN && dwarf2out_do_frame ())
2957 dwarf2out_frame_debug (insn);
2958 #else
2959 if (!ACCUMULATE_OUTGOING_ARGS
2960 && GET_CODE (insn) == INSN
2961 && dwarf2out_do_frame ())
2962 dwarf2out_frame_debug (insn);
2963 #endif
2964 #endif
2966 #if 0
2967 /* It's not at all clear why we did this and doing so interferes
2968 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2969 with this out. */
2971 /* Mark this insn as having been output. */
2972 INSN_DELETED_P (insn) = 1;
2973 #endif
2975 current_output_insn = debug_insn = 0;
2978 return NEXT_INSN (insn);
2981 /* Output debugging info to the assembler file FILE
2982 based on the NOTE-insn INSN, assumed to be a line number. */
2984 static void
2985 output_source_line (file, insn)
2986 FILE *file ATTRIBUTE_UNUSED;
2987 rtx insn;
2989 register const char *filename = NOTE_SOURCE_FILE (insn);
2991 /* Remember filename for basic block profiling.
2992 Filenames are allocated on the permanent obstack
2993 or are passed in ARGV, so we don't have to save
2994 the string. */
2996 if (profile_block_flag && last_filename != filename)
2997 bb_file_label_num = add_bb_string (filename, TRUE);
2999 last_filename = filename;
3000 last_linenum = NOTE_LINE_NUMBER (insn);
3001 high_block_linenum = MAX (last_linenum, high_block_linenum);
3002 high_function_linenum = MAX (last_linenum, high_function_linenum);
3004 if (write_symbols != NO_DEBUG)
3006 #ifdef SDB_DEBUGGING_INFO
3007 if (write_symbols == SDB_DEBUG
3008 #if 0 /* People like having line numbers even in wrong file! */
3009 /* COFF can't handle multiple source files--lose, lose. */
3010 && !strcmp (filename, main_input_filename)
3011 #endif
3012 /* COFF relative line numbers must be positive. */
3013 && last_linenum > sdb_begin_function_line)
3015 #ifdef ASM_OUTPUT_SOURCE_LINE
3016 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
3017 #else
3018 fprintf (file, "\t.ln\t%d\n",
3019 ((sdb_begin_function_line > -1)
3020 ? last_linenum - sdb_begin_function_line : 1));
3021 #endif
3023 #endif
3025 #if defined (DBX_DEBUGGING_INFO)
3026 if (write_symbols == DBX_DEBUG)
3027 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
3028 #endif
3030 #if defined (XCOFF_DEBUGGING_INFO)
3031 if (write_symbols == XCOFF_DEBUG)
3032 xcoffout_source_line (file, filename, insn);
3033 #endif
3035 #ifdef DWARF_DEBUGGING_INFO
3036 if (write_symbols == DWARF_DEBUG)
3037 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
3038 #endif
3040 #ifdef DWARF2_DEBUGGING_INFO
3041 if (write_symbols == DWARF2_DEBUG)
3042 dwarf2out_line (filename, NOTE_LINE_NUMBER (insn));
3043 #endif
3047 /* For each operand in INSN, simplify (subreg (reg)) so that it refers
3048 directly to the desired hard register. */
3050 void
3051 cleanup_subreg_operands (insn)
3052 rtx insn;
3054 int i;
3055 extract_insn_cached (insn);
3056 for (i = 0; i < recog_data.n_operands; i++)
3058 if (GET_CODE (recog_data.operand[i]) == SUBREG)
3059 recog_data.operand[i] = alter_subreg (recog_data.operand[i]);
3060 else if (GET_CODE (recog_data.operand[i]) == PLUS
3061 || GET_CODE (recog_data.operand[i]) == MULT
3062 || GET_CODE (recog_data.operand[i]) == MEM)
3063 recog_data.operand[i] = walk_alter_subreg (recog_data.operand[i]);
3066 for (i = 0; i < recog_data.n_dups; i++)
3068 if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
3069 *recog_data.dup_loc[i] = alter_subreg (*recog_data.dup_loc[i]);
3070 else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
3071 || GET_CODE (*recog_data.dup_loc[i]) == MULT
3072 || GET_CODE (*recog_data.dup_loc[i]) == MEM)
3073 *recog_data.dup_loc[i] = walk_alter_subreg (*recog_data.dup_loc[i]);
3077 /* If X is a SUBREG, replace it with a REG or a MEM,
3078 based on the thing it is a subreg of. */
3081 alter_subreg (x)
3082 register rtx x;
3084 register rtx y = SUBREG_REG (x);
3086 if (GET_CODE (y) == SUBREG)
3087 y = alter_subreg (y);
3089 /* If reload is operating, we may be replacing inside this SUBREG.
3090 Check for that and make a new one if so. */
3091 if (reload_in_progress && find_replacement (&SUBREG_REG (x)) != 0)
3092 x = copy_rtx (x);
3094 if (GET_CODE (y) == REG)
3096 int regno = subreg_hard_regno (x, 1);
3098 PUT_CODE (x, REG);
3099 REGNO (x) = regno;
3100 ORIGINAL_REGNO (x) = ORIGINAL_REGNO (y);
3101 /* This field has a different meaning for REGs and SUBREGs. Make sure
3102 to clear it! */
3103 x->used = 0;
3105 else if (GET_CODE (y) == MEM)
3107 register int offset = SUBREG_BYTE (x);
3109 /* Catch these instead of generating incorrect code. */
3110 if ((offset % GET_MODE_SIZE (GET_MODE (x))) != 0)
3111 abort ();
3113 PUT_CODE (x, MEM);
3114 MEM_COPY_ATTRIBUTES (x, y);
3115 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
3118 return x;
3121 /* Do alter_subreg on all the SUBREGs contained in X. */
3123 static rtx
3124 walk_alter_subreg (x)
3125 rtx x;
3127 switch (GET_CODE (x))
3129 case PLUS:
3130 case MULT:
3131 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3132 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
3133 break;
3135 case MEM:
3136 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3137 break;
3139 case SUBREG:
3140 return alter_subreg (x);
3142 default:
3143 break;
3146 return x;
3149 #ifdef HAVE_cc0
3151 /* Given BODY, the body of a jump instruction, alter the jump condition
3152 as required by the bits that are set in cc_status.flags.
3153 Not all of the bits there can be handled at this level in all cases.
3155 The value is normally 0.
3156 1 means that the condition has become always true.
3157 -1 means that the condition has become always false.
3158 2 means that COND has been altered. */
3160 static int
3161 alter_cond (cond)
3162 register rtx cond;
3164 int value = 0;
3166 if (cc_status.flags & CC_REVERSED)
3168 value = 2;
3169 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
3172 if (cc_status.flags & CC_INVERTED)
3174 value = 2;
3175 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
3178 if (cc_status.flags & CC_NOT_POSITIVE)
3179 switch (GET_CODE (cond))
3181 case LE:
3182 case LEU:
3183 case GEU:
3184 /* Jump becomes unconditional. */
3185 return 1;
3187 case GT:
3188 case GTU:
3189 case LTU:
3190 /* Jump becomes no-op. */
3191 return -1;
3193 case GE:
3194 PUT_CODE (cond, EQ);
3195 value = 2;
3196 break;
3198 case LT:
3199 PUT_CODE (cond, NE);
3200 value = 2;
3201 break;
3203 default:
3204 break;
3207 if (cc_status.flags & CC_NOT_NEGATIVE)
3208 switch (GET_CODE (cond))
3210 case GE:
3211 case GEU:
3212 /* Jump becomes unconditional. */
3213 return 1;
3215 case LT:
3216 case LTU:
3217 /* Jump becomes no-op. */
3218 return -1;
3220 case LE:
3221 case LEU:
3222 PUT_CODE (cond, EQ);
3223 value = 2;
3224 break;
3226 case GT:
3227 case GTU:
3228 PUT_CODE (cond, NE);
3229 value = 2;
3230 break;
3232 default:
3233 break;
3236 if (cc_status.flags & CC_NO_OVERFLOW)
3237 switch (GET_CODE (cond))
3239 case GEU:
3240 /* Jump becomes unconditional. */
3241 return 1;
3243 case LEU:
3244 PUT_CODE (cond, EQ);
3245 value = 2;
3246 break;
3248 case GTU:
3249 PUT_CODE (cond, NE);
3250 value = 2;
3251 break;
3253 case LTU:
3254 /* Jump becomes no-op. */
3255 return -1;
3257 default:
3258 break;
3261 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
3262 switch (GET_CODE (cond))
3264 default:
3265 abort ();
3267 case NE:
3268 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
3269 value = 2;
3270 break;
3272 case EQ:
3273 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
3274 value = 2;
3275 break;
3278 if (cc_status.flags & CC_NOT_SIGNED)
3279 /* The flags are valid if signed condition operators are converted
3280 to unsigned. */
3281 switch (GET_CODE (cond))
3283 case LE:
3284 PUT_CODE (cond, LEU);
3285 value = 2;
3286 break;
3288 case LT:
3289 PUT_CODE (cond, LTU);
3290 value = 2;
3291 break;
3293 case GT:
3294 PUT_CODE (cond, GTU);
3295 value = 2;
3296 break;
3298 case GE:
3299 PUT_CODE (cond, GEU);
3300 value = 2;
3301 break;
3303 default:
3304 break;
3307 return value;
3309 #endif
3311 /* Report inconsistency between the assembler template and the operands.
3312 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
3314 void
3315 output_operand_lossage (msgid)
3316 const char *msgid;
3318 if (this_is_asm_operands)
3319 error_for_asm (this_is_asm_operands, "invalid `asm': %s", _(msgid));
3320 else
3321 internal_error ("output_operand: %s", _(msgid));
3324 /* Output of assembler code from a template, and its subroutines. */
3326 /* Output text from TEMPLATE to the assembler output file,
3327 obeying %-directions to substitute operands taken from
3328 the vector OPERANDS.
3330 %N (for N a digit) means print operand N in usual manner.
3331 %lN means require operand N to be a CODE_LABEL or LABEL_REF
3332 and print the label name with no punctuation.
3333 %cN means require operand N to be a constant
3334 and print the constant expression with no punctuation.
3335 %aN means expect operand N to be a memory address
3336 (not a memory reference!) and print a reference
3337 to that address.
3338 %nN means expect operand N to be a constant
3339 and print a constant expression for minus the value
3340 of the operand, with no other punctuation. */
3342 static void
3343 output_asm_name ()
3345 if (flag_print_asm_name)
3347 /* Annotate the assembly with a comment describing the pattern and
3348 alternative used. */
3349 if (debug_insn)
3351 register int num = INSN_CODE (debug_insn);
3352 fprintf (asm_out_file, "\t%s %d\t%s",
3353 ASM_COMMENT_START, INSN_UID (debug_insn),
3354 insn_data[num].name);
3355 if (insn_data[num].n_alternatives > 1)
3356 fprintf (asm_out_file, "/%d", which_alternative + 1);
3357 #ifdef HAVE_ATTR_length
3358 fprintf (asm_out_file, "\t[length = %d]",
3359 get_attr_length (debug_insn));
3360 #endif
3361 /* Clear this so only the first assembler insn
3362 of any rtl insn will get the special comment for -dp. */
3363 debug_insn = 0;
3368 void
3369 output_asm_insn (template, operands)
3370 const char *template;
3371 rtx *operands;
3373 register const char *p;
3374 register int c;
3376 /* An insn may return a null string template
3377 in a case where no assembler code is needed. */
3378 if (*template == 0)
3379 return;
3381 p = template;
3382 putc ('\t', asm_out_file);
3384 #ifdef ASM_OUTPUT_OPCODE
3385 ASM_OUTPUT_OPCODE (asm_out_file, p);
3386 #endif
3388 while ((c = *p++))
3389 switch (c)
3391 case '\n':
3392 output_asm_name ();
3393 putc (c, asm_out_file);
3394 #ifdef ASM_OUTPUT_OPCODE
3395 while ((c = *p) == '\t')
3397 putc (c, asm_out_file);
3398 p++;
3400 ASM_OUTPUT_OPCODE (asm_out_file, p);
3401 #endif
3402 break;
3404 #ifdef ASSEMBLER_DIALECT
3405 case '{':
3407 register int i;
3409 /* If we want the first dialect, do nothing. Otherwise, skip
3410 DIALECT_NUMBER of strings ending with '|'. */
3411 for (i = 0; i < dialect_number; i++)
3413 while (*p && *p != '}' && *p++ != '|')
3415 if (*p == '}')
3416 break;
3417 if (*p == '|')
3418 p++;
3421 break;
3423 case '|':
3424 /* Skip to close brace. */
3425 while (*p && *p++ != '}')
3427 break;
3429 case '}':
3430 break;
3431 #endif
3433 case '%':
3434 /* %% outputs a single %. */
3435 if (*p == '%')
3437 p++;
3438 putc (c, asm_out_file);
3440 /* %= outputs a number which is unique to each insn in the entire
3441 compilation. This is useful for making local labels that are
3442 referred to more than once in a given insn. */
3443 else if (*p == '=')
3445 p++;
3446 fprintf (asm_out_file, "%d", insn_counter);
3448 /* % followed by a letter and some digits
3449 outputs an operand in a special way depending on the letter.
3450 Letters `acln' are implemented directly.
3451 Other letters are passed to `output_operand' so that
3452 the PRINT_OPERAND macro can define them. */
3453 else if (ISLOWER (*p) || ISUPPER (*p))
3455 int letter = *p++;
3456 c = atoi (p);
3458 if (! (*p >= '0' && *p <= '9'))
3459 output_operand_lossage ("operand number missing after %-letter");
3460 else if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3461 output_operand_lossage ("operand number out of range");
3462 else if (letter == 'l')
3463 output_asm_label (operands[c]);
3464 else if (letter == 'a')
3465 output_address (operands[c]);
3466 else if (letter == 'c')
3468 if (CONSTANT_ADDRESS_P (operands[c]))
3469 output_addr_const (asm_out_file, operands[c]);
3470 else
3471 output_operand (operands[c], 'c');
3473 else if (letter == 'n')
3475 if (GET_CODE (operands[c]) == CONST_INT)
3476 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3477 - INTVAL (operands[c]));
3478 else
3480 putc ('-', asm_out_file);
3481 output_addr_const (asm_out_file, operands[c]);
3484 else
3485 output_operand (operands[c], letter);
3487 while ((c = *p) >= '0' && c <= '9')
3488 p++;
3490 /* % followed by a digit outputs an operand the default way. */
3491 else if (*p >= '0' && *p <= '9')
3493 c = atoi (p);
3494 if (this_is_asm_operands
3495 && (c < 0 || (unsigned int) c >= insn_noperands))
3496 output_operand_lossage ("operand number out of range");
3497 else
3498 output_operand (operands[c], 0);
3499 while ((c = *p) >= '0' && c <= '9')
3500 p++;
3502 /* % followed by punctuation: output something for that
3503 punctuation character alone, with no operand.
3504 The PRINT_OPERAND macro decides what is actually done. */
3505 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3506 else if (PRINT_OPERAND_PUNCT_VALID_P ((unsigned char) *p))
3507 output_operand (NULL_RTX, *p++);
3508 #endif
3509 else
3510 output_operand_lossage ("invalid %%-code");
3511 break;
3513 default:
3514 putc (c, asm_out_file);
3517 output_asm_name ();
3519 putc ('\n', asm_out_file);
3522 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3524 void
3525 output_asm_label (x)
3526 rtx x;
3528 char buf[256];
3530 if (GET_CODE (x) == LABEL_REF)
3531 x = XEXP (x, 0);
3532 if (GET_CODE (x) == CODE_LABEL
3533 || (GET_CODE (x) == NOTE
3534 && NOTE_LINE_NUMBER (x) == NOTE_INSN_DELETED_LABEL))
3535 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3536 else
3537 output_operand_lossage ("`%l' operand isn't a label");
3539 assemble_name (asm_out_file, buf);
3542 /* Print operand X using machine-dependent assembler syntax.
3543 The macro PRINT_OPERAND is defined just to control this function.
3544 CODE is a non-digit that preceded the operand-number in the % spec,
3545 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3546 between the % and the digits.
3547 When CODE is a non-letter, X is 0.
3549 The meanings of the letters are machine-dependent and controlled
3550 by PRINT_OPERAND. */
3552 static void
3553 output_operand (x, code)
3554 rtx x;
3555 int code ATTRIBUTE_UNUSED;
3557 if (x && GET_CODE (x) == SUBREG)
3558 x = alter_subreg (x);
3560 /* If X is a pseudo-register, abort now rather than writing trash to the
3561 assembler file. */
3563 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
3564 abort ();
3566 PRINT_OPERAND (asm_out_file, x, code);
3569 /* Print a memory reference operand for address X
3570 using machine-dependent assembler syntax.
3571 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
3573 void
3574 output_address (x)
3575 rtx x;
3577 walk_alter_subreg (x);
3578 PRINT_OPERAND_ADDRESS (asm_out_file, x);
3581 /* Print an integer constant expression in assembler syntax.
3582 Addition and subtraction are the only arithmetic
3583 that may appear in these expressions. */
3585 void
3586 output_addr_const (file, x)
3587 FILE *file;
3588 rtx x;
3590 char buf[256];
3592 restart:
3593 switch (GET_CODE (x))
3595 case PC:
3596 if (flag_pic)
3597 putc ('.', file);
3598 else
3599 abort ();
3600 break;
3602 case SYMBOL_REF:
3603 #ifdef ASM_OUTPUT_SYMBOL_REF
3604 ASM_OUTPUT_SYMBOL_REF (file, x);
3605 #else
3606 assemble_name (file, XSTR (x, 0));
3607 #endif
3608 break;
3610 case LABEL_REF:
3611 x = XEXP (x, 0);
3612 /* Fall through. */
3613 case CODE_LABEL:
3614 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3615 assemble_name (file, buf);
3616 break;
3618 case CONST_INT:
3619 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3620 break;
3622 case CONST:
3623 /* This used to output parentheses around the expression,
3624 but that does not work on the 386 (either ATT or BSD assembler). */
3625 output_addr_const (file, XEXP (x, 0));
3626 break;
3628 case CONST_DOUBLE:
3629 if (GET_MODE (x) == VOIDmode)
3631 /* We can use %d if the number is one word and positive. */
3632 if (CONST_DOUBLE_HIGH (x))
3633 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3634 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3635 else if (CONST_DOUBLE_LOW (x) < 0)
3636 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3637 else
3638 fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3640 else
3641 /* We can't handle floating point constants;
3642 PRINT_OPERAND must handle them. */
3643 output_operand_lossage ("floating constant misused");
3644 break;
3646 case PLUS:
3647 /* Some assemblers need integer constants to appear last (eg masm). */
3648 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3650 output_addr_const (file, XEXP (x, 1));
3651 if (INTVAL (XEXP (x, 0)) >= 0)
3652 fprintf (file, "+");
3653 output_addr_const (file, XEXP (x, 0));
3655 else
3657 output_addr_const (file, XEXP (x, 0));
3658 if (GET_CODE (XEXP (x, 1)) != CONST_INT
3659 || INTVAL (XEXP (x, 1)) >= 0)
3660 fprintf (file, "+");
3661 output_addr_const (file, XEXP (x, 1));
3663 break;
3665 case MINUS:
3666 /* Avoid outputting things like x-x or x+5-x,
3667 since some assemblers can't handle that. */
3668 x = simplify_subtraction (x);
3669 if (GET_CODE (x) != MINUS)
3670 goto restart;
3672 output_addr_const (file, XEXP (x, 0));
3673 fprintf (file, "-");
3674 if ((GET_CODE (XEXP (x, 1)) == CONST_INT
3675 && INTVAL (XEXP (x, 1)) < 0)
3676 || GET_CODE (XEXP (x, 1)) != CONST_INT)
3678 fprintf (file, "%s", ASM_OPEN_PAREN);
3679 output_addr_const (file, XEXP (x, 1));
3680 fprintf (file, "%s", ASM_CLOSE_PAREN);
3682 else
3683 output_addr_const (file, XEXP (x, 1));
3684 break;
3686 case ZERO_EXTEND:
3687 case SIGN_EXTEND:
3688 output_addr_const (file, XEXP (x, 0));
3689 break;
3691 default:
3692 #ifdef OUTPUT_ADDR_CONST_EXTRA
3693 OUTPUT_ADDR_CONST_EXTRA (file, x, fail);
3694 break;
3696 fail:
3697 #endif
3698 output_operand_lossage ("invalid expression as operand");
3702 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3703 %R prints the value of REGISTER_PREFIX.
3704 %L prints the value of LOCAL_LABEL_PREFIX.
3705 %U prints the value of USER_LABEL_PREFIX.
3706 %I prints the value of IMMEDIATE_PREFIX.
3707 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3708 Also supported are %d, %x, %s, %e, %f, %g and %%.
3710 We handle alternate assembler dialects here, just like output_asm_insn. */
3712 void
3713 asm_fprintf VPARAMS ((FILE *file, const char *p, ...))
3715 #ifndef ANSI_PROTOTYPES
3716 FILE *file;
3717 const char *p;
3718 #endif
3719 va_list argptr;
3720 char buf[10];
3721 char *q, c;
3723 VA_START (argptr, p);
3725 #ifndef ANSI_PROTOTYPES
3726 file = va_arg (argptr, FILE *);
3727 p = va_arg (argptr, const char *);
3728 #endif
3730 buf[0] = '%';
3732 while ((c = *p++))
3733 switch (c)
3735 #ifdef ASSEMBLER_DIALECT
3736 case '{':
3738 int i;
3740 /* If we want the first dialect, do nothing. Otherwise, skip
3741 DIALECT_NUMBER of strings ending with '|'. */
3742 for (i = 0; i < dialect_number; i++)
3744 while (*p && *p++ != '|')
3747 if (*p == '|')
3748 p++;
3751 break;
3753 case '|':
3754 /* Skip to close brace. */
3755 while (*p && *p++ != '}')
3757 break;
3759 case '}':
3760 break;
3761 #endif
3763 case '%':
3764 c = *p++;
3765 q = &buf[1];
3766 while ((c >= '0' && c <= '9') || c == '.')
3768 *q++ = c;
3769 c = *p++;
3771 switch (c)
3773 case '%':
3774 fprintf (file, "%%");
3775 break;
3777 case 'd': case 'i': case 'u':
3778 case 'x': case 'p': case 'X':
3779 case 'o':
3780 *q++ = c;
3781 *q = 0;
3782 fprintf (file, buf, va_arg (argptr, int));
3783 break;
3785 case 'w':
3786 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3787 but we do not check for those cases. It means that the value
3788 is a HOST_WIDE_INT, which may be either `int' or `long'. */
3790 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3791 #else
3792 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3793 *q++ = 'l';
3794 #else
3795 *q++ = 'l';
3796 *q++ = 'l';
3797 #endif
3798 #endif
3800 *q++ = *p++;
3801 *q = 0;
3802 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3803 break;
3805 case 'l':
3806 *q++ = c;
3807 *q++ = *p++;
3808 *q = 0;
3809 fprintf (file, buf, va_arg (argptr, long));
3810 break;
3812 case 'e':
3813 case 'f':
3814 case 'g':
3815 *q++ = c;
3816 *q = 0;
3817 fprintf (file, buf, va_arg (argptr, double));
3818 break;
3820 case 's':
3821 *q++ = c;
3822 *q = 0;
3823 fprintf (file, buf, va_arg (argptr, char *));
3824 break;
3826 case 'O':
3827 #ifdef ASM_OUTPUT_OPCODE
3828 ASM_OUTPUT_OPCODE (asm_out_file, p);
3829 #endif
3830 break;
3832 case 'R':
3833 #ifdef REGISTER_PREFIX
3834 fprintf (file, "%s", REGISTER_PREFIX);
3835 #endif
3836 break;
3838 case 'I':
3839 #ifdef IMMEDIATE_PREFIX
3840 fprintf (file, "%s", IMMEDIATE_PREFIX);
3841 #endif
3842 break;
3844 case 'L':
3845 #ifdef LOCAL_LABEL_PREFIX
3846 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3847 #endif
3848 break;
3850 case 'U':
3851 fputs (user_label_prefix, file);
3852 break;
3854 #ifdef ASM_FPRINTF_EXTENSIONS
3855 /* Upper case letters are reserved for general use by asm_fprintf
3856 and so are not available to target specific code. In order to
3857 prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
3858 they are defined here. As they get turned into real extensions
3859 to asm_fprintf they should be removed from this list. */
3860 case 'A': case 'B': case 'C': case 'D': case 'E':
3861 case 'F': case 'G': case 'H': case 'J': case 'K':
3862 case 'M': case 'N': case 'P': case 'Q': case 'S':
3863 case 'T': case 'V': case 'W': case 'Y': case 'Z':
3864 break;
3866 ASM_FPRINTF_EXTENSIONS (file, argptr, p)
3867 #endif
3868 default:
3869 abort ();
3871 break;
3873 default:
3874 fputc (c, file);
3876 va_end (argptr);
3879 /* Split up a CONST_DOUBLE or integer constant rtx
3880 into two rtx's for single words,
3881 storing in *FIRST the word that comes first in memory in the target
3882 and in *SECOND the other. */
3884 void
3885 split_double (value, first, second)
3886 rtx value;
3887 rtx *first, *second;
3889 if (GET_CODE (value) == CONST_INT)
3891 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3893 /* In this case the CONST_INT holds both target words.
3894 Extract the bits from it into two word-sized pieces.
3895 Sign extend each half to HOST_WIDE_INT. */
3896 unsigned HOST_WIDE_INT low, high;
3897 unsigned HOST_WIDE_INT mask, sign_bit, sign_extend;
3899 /* Set sign_bit to the most significant bit of a word. */
3900 sign_bit = 1;
3901 sign_bit <<= BITS_PER_WORD - 1;
3903 /* Set mask so that all bits of the word are set. We could
3904 have used 1 << BITS_PER_WORD instead of basing the
3905 calculation on sign_bit. However, on machines where
3906 HOST_BITS_PER_WIDE_INT == BITS_PER_WORD, it could cause a
3907 compiler warning, even though the code would never be
3908 executed. */
3909 mask = sign_bit << 1;
3910 mask--;
3912 /* Set sign_extend as any remaining bits. */
3913 sign_extend = ~mask;
3915 /* Pick the lower word and sign-extend it. */
3916 low = INTVAL (value);
3917 low &= mask;
3918 if (low & sign_bit)
3919 low |= sign_extend;
3921 /* Pick the higher word, shifted to the least significant
3922 bits, and sign-extend it. */
3923 high = INTVAL (value);
3924 high >>= BITS_PER_WORD - 1;
3925 high >>= 1;
3926 high &= mask;
3927 if (high & sign_bit)
3928 high |= sign_extend;
3930 /* Store the words in the target machine order. */
3931 if (WORDS_BIG_ENDIAN)
3933 *first = GEN_INT (high);
3934 *second = GEN_INT (low);
3936 else
3938 *first = GEN_INT (low);
3939 *second = GEN_INT (high);
3942 else
3944 /* The rule for using CONST_INT for a wider mode
3945 is that we regard the value as signed.
3946 So sign-extend it. */
3947 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3948 if (WORDS_BIG_ENDIAN)
3950 *first = high;
3951 *second = value;
3953 else
3955 *first = value;
3956 *second = high;
3960 else if (GET_CODE (value) != CONST_DOUBLE)
3962 if (WORDS_BIG_ENDIAN)
3964 *first = const0_rtx;
3965 *second = value;
3967 else
3969 *first = value;
3970 *second = const0_rtx;
3973 else if (GET_MODE (value) == VOIDmode
3974 /* This is the old way we did CONST_DOUBLE integers. */
3975 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3977 /* In an integer, the words are defined as most and least significant.
3978 So order them by the target's convention. */
3979 if (WORDS_BIG_ENDIAN)
3981 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3982 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3984 else
3986 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3987 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3990 else
3992 #ifdef REAL_ARITHMETIC
3993 REAL_VALUE_TYPE r;
3994 long l[2];
3995 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3997 /* Note, this converts the REAL_VALUE_TYPE to the target's
3998 format, splits up the floating point double and outputs
3999 exactly 32 bits of it into each of l[0] and l[1] --
4000 not necessarily BITS_PER_WORD bits. */
4001 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
4003 /* If 32 bits is an entire word for the target, but not for the host,
4004 then sign-extend on the host so that the number will look the same
4005 way on the host that it would on the target. See for instance
4006 simplify_unary_operation. The #if is needed to avoid compiler
4007 warnings. */
4009 #if HOST_BITS_PER_LONG > 32
4010 if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
4012 if (l[0] & ((long) 1 << 31))
4013 l[0] |= ((long) (-1) << 32);
4014 if (l[1] & ((long) 1 << 31))
4015 l[1] |= ((long) (-1) << 32);
4017 #endif
4019 *first = GEN_INT ((HOST_WIDE_INT) l[0]);
4020 *second = GEN_INT ((HOST_WIDE_INT) l[1]);
4021 #else
4022 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
4023 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
4024 && ! flag_pretend_float)
4025 abort ();
4027 if (
4028 #ifdef HOST_WORDS_BIG_ENDIAN
4029 WORDS_BIG_ENDIAN
4030 #else
4031 ! WORDS_BIG_ENDIAN
4032 #endif
4035 /* Host and target agree => no need to swap. */
4036 *first = GEN_INT (CONST_DOUBLE_LOW (value));
4037 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
4039 else
4041 *second = GEN_INT (CONST_DOUBLE_LOW (value));
4042 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
4044 #endif /* no REAL_ARITHMETIC */
4048 /* Return nonzero if this function has no function calls. */
4051 leaf_function_p ()
4053 rtx insn;
4054 rtx link;
4056 if (profile_flag || profile_block_flag || profile_arc_flag)
4057 return 0;
4059 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4061 if (GET_CODE (insn) == CALL_INSN
4062 && ! SIBLING_CALL_P (insn))
4063 return 0;
4064 if (GET_CODE (insn) == INSN
4065 && GET_CODE (PATTERN (insn)) == SEQUENCE
4066 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4067 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4068 return 0;
4070 for (link = current_function_epilogue_delay_list;
4071 link;
4072 link = XEXP (link, 1))
4074 insn = XEXP (link, 0);
4076 if (GET_CODE (insn) == CALL_INSN
4077 && ! SIBLING_CALL_P (insn))
4078 return 0;
4079 if (GET_CODE (insn) == INSN
4080 && GET_CODE (PATTERN (insn)) == SEQUENCE
4081 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4082 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4083 return 0;
4086 return 1;
4089 /* On some machines, a function with no call insns
4090 can run faster if it doesn't create its own register window.
4091 When output, the leaf function should use only the "output"
4092 registers. Ordinarily, the function would be compiled to use
4093 the "input" registers to find its arguments; it is a candidate
4094 for leaf treatment if it uses only the "input" registers.
4095 Leaf function treatment means renumbering so the function
4096 uses the "output" registers instead. */
4098 #ifdef LEAF_REGISTERS
4100 /* Return 1 if this function uses only the registers that can be
4101 safely renumbered. */
4104 only_leaf_regs_used ()
4106 int i;
4107 char *permitted_reg_in_leaf_functions = LEAF_REGISTERS;
4109 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4110 if ((regs_ever_live[i] || global_regs[i])
4111 && ! permitted_reg_in_leaf_functions[i])
4112 return 0;
4114 if (current_function_uses_pic_offset_table
4115 && pic_offset_table_rtx != 0
4116 && GET_CODE (pic_offset_table_rtx) == REG
4117 && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
4118 return 0;
4120 return 1;
4123 /* Scan all instructions and renumber all registers into those
4124 available in leaf functions. */
4126 static void
4127 leaf_renumber_regs (first)
4128 rtx first;
4130 rtx insn;
4132 /* Renumber only the actual patterns.
4133 The reg-notes can contain frame pointer refs,
4134 and renumbering them could crash, and should not be needed. */
4135 for (insn = first; insn; insn = NEXT_INSN (insn))
4136 if (INSN_P (insn))
4137 leaf_renumber_regs_insn (PATTERN (insn));
4138 for (insn = current_function_epilogue_delay_list;
4139 insn;
4140 insn = XEXP (insn, 1))
4141 if (INSN_P (XEXP (insn, 0)))
4142 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
4145 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
4146 available in leaf functions. */
4148 void
4149 leaf_renumber_regs_insn (in_rtx)
4150 register rtx in_rtx;
4152 register int i, j;
4153 register const char *format_ptr;
4155 if (in_rtx == 0)
4156 return;
4158 /* Renumber all input-registers into output-registers.
4159 renumbered_regs would be 1 for an output-register;
4160 they */
4162 if (GET_CODE (in_rtx) == REG)
4164 int newreg;
4166 /* Don't renumber the same reg twice. */
4167 if (in_rtx->used)
4168 return;
4170 newreg = REGNO (in_rtx);
4171 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
4172 to reach here as part of a REG_NOTE. */
4173 if (newreg >= FIRST_PSEUDO_REGISTER)
4175 in_rtx->used = 1;
4176 return;
4178 newreg = LEAF_REG_REMAP (newreg);
4179 if (newreg < 0)
4180 abort ();
4181 regs_ever_live[REGNO (in_rtx)] = 0;
4182 regs_ever_live[newreg] = 1;
4183 REGNO (in_rtx) = newreg;
4184 in_rtx->used = 1;
4187 if (INSN_P (in_rtx))
4189 /* Inside a SEQUENCE, we find insns.
4190 Renumber just the patterns of these insns,
4191 just as we do for the top-level insns. */
4192 leaf_renumber_regs_insn (PATTERN (in_rtx));
4193 return;
4196 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
4198 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
4199 switch (*format_ptr++)
4201 case 'e':
4202 leaf_renumber_regs_insn (XEXP (in_rtx, i));
4203 break;
4205 case 'E':
4206 if (NULL != XVEC (in_rtx, i))
4208 for (j = 0; j < XVECLEN (in_rtx, i); j++)
4209 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
4211 break;
4213 case 'S':
4214 case 's':
4215 case '0':
4216 case 'i':
4217 case 'w':
4218 case 'n':
4219 case 'u':
4220 break;
4222 default:
4223 abort ();
4226 #endif