* alpha.h: NULL_PTR -> NULL.
[official-gcc.git] / gcc / final.c
blob57d34f5c817b01e1e8a29177b2a2c7b57de13dbc
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 (DWARF2_DEBUGGING_INFO)
1587 /* Output DWARF definition of the function. */
1588 if (dwarf2out_do_frame ())
1589 dwarf2out_begin_prologue ();
1590 else
1591 current_function_func_begin_label = 0;
1592 #endif
1594 /* For SDB and XCOFF, the function beginning must be marked between
1595 the function label and the prologue. We always need this, even when
1596 -g1 was used. Defer on MIPS systems so that parameter descriptions
1597 follow function entry. */
1598 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
1599 if (write_symbols == SDB_DEBUG)
1600 sdbout_begin_function (last_linenum);
1601 else
1602 #endif
1603 #ifdef XCOFF_DEBUGGING_INFO
1604 if (write_symbols == XCOFF_DEBUG)
1605 xcoffout_begin_function (file, last_linenum);
1606 else
1607 #endif
1608 /* But only output line number for other debug info types if -g2
1609 or better. */
1610 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1611 output_source_line (file, first);
1613 #ifdef LEAF_REG_REMAP
1614 if (current_function_uses_only_leaf_regs)
1615 leaf_renumber_regs (first);
1616 #endif
1618 /* The Sun386i and perhaps other machines don't work right
1619 if the profiling code comes after the prologue. */
1620 #ifdef PROFILE_BEFORE_PROLOGUE
1621 if (profile_flag)
1622 profile_function (file);
1623 #endif /* PROFILE_BEFORE_PROLOGUE */
1625 #if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
1626 if (dwarf2out_do_frame ())
1627 dwarf2out_frame_debug (NULL_RTX);
1628 #endif
1630 /* If debugging, assign block numbers to all of the blocks in this
1631 function. */
1632 if (write_symbols)
1634 number_blocks (current_function_decl);
1635 remove_unnecessary_notes ();
1636 /* We never actually put out begin/end notes for the top-level
1637 block in the function. But, conceptually, that block is
1638 always needed. */
1639 TREE_ASM_WRITTEN (DECL_INITIAL (current_function_decl)) = 1;
1642 #ifdef FUNCTION_PROLOGUE
1643 /* First output the function prologue: code to set up the stack frame. */
1644 FUNCTION_PROLOGUE (file, get_frame_size ());
1645 #endif
1647 /* If the machine represents the prologue as RTL, the profiling code must
1648 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
1649 #ifdef HAVE_prologue
1650 if (! HAVE_prologue)
1651 #endif
1652 profile_after_prologue (file);
1654 profile_label_no++;
1656 /* If we are doing basic block profiling, remember a printable version
1657 of the function name. */
1658 if (profile_block_flag)
1660 bb_func_label_num =
1661 add_bb_string ((*decl_printable_name) (current_function_decl, 2),
1662 FALSE);
1666 static void
1667 profile_after_prologue (file)
1668 FILE *file ATTRIBUTE_UNUSED;
1670 #ifdef FUNCTION_BLOCK_PROFILER
1671 if (profile_block_flag)
1673 FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
1675 #endif /* FUNCTION_BLOCK_PROFILER */
1677 #ifndef PROFILE_BEFORE_PROLOGUE
1678 if (profile_flag)
1679 profile_function (file);
1680 #endif /* not PROFILE_BEFORE_PROLOGUE */
1683 static void
1684 profile_function (file)
1685 FILE *file;
1687 #ifndef NO_PROFILE_COUNTERS
1688 int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
1689 #endif
1690 #if defined(ASM_OUTPUT_REG_PUSH)
1691 #if defined(STRUCT_VALUE_INCOMING_REGNUM) || defined(STRUCT_VALUE_REGNUM)
1692 int sval = current_function_returns_struct;
1693 #endif
1694 #if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
1695 int cxt = current_function_needs_context;
1696 #endif
1697 #endif /* ASM_OUTPUT_REG_PUSH */
1699 #ifndef NO_PROFILE_COUNTERS
1700 data_section ();
1701 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
1702 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
1703 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, 1);
1704 #endif
1706 function_section (current_function_decl);
1708 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1709 if (sval)
1710 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
1711 #else
1712 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1713 if (sval)
1715 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
1717 #endif
1718 #endif
1720 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1721 if (cxt)
1722 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1723 #else
1724 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1725 if (cxt)
1727 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1729 #endif
1730 #endif
1732 FUNCTION_PROFILER (file, profile_label_no);
1734 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1735 if (cxt)
1736 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1737 #else
1738 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1739 if (cxt)
1741 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1743 #endif
1744 #endif
1746 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1747 if (sval)
1748 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1749 #else
1750 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1751 if (sval)
1753 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1755 #endif
1756 #endif
1759 /* Output assembler code for the end of a function.
1760 For clarity, args are same as those of `final_start_function'
1761 even though not all of them are needed. */
1763 void
1764 final_end_function (first, file, optimize)
1765 rtx first ATTRIBUTE_UNUSED;
1766 FILE *file ATTRIBUTE_UNUSED;
1767 int optimize ATTRIBUTE_UNUSED;
1769 app_disable ();
1771 #ifdef SDB_DEBUGGING_INFO
1772 if (write_symbols == SDB_DEBUG)
1773 sdbout_end_function (high_function_linenum);
1774 #endif
1776 #ifdef DWARF_DEBUGGING_INFO
1777 if (write_symbols == DWARF_DEBUG)
1778 dwarfout_end_function ();
1779 #endif
1781 #ifdef XCOFF_DEBUGGING_INFO
1782 if (write_symbols == XCOFF_DEBUG)
1783 xcoffout_end_function (file, high_function_linenum);
1784 #endif
1786 #ifdef FUNCTION_EPILOGUE
1787 /* Finally, output the function epilogue:
1788 code to restore the stack frame and return to the caller. */
1789 FUNCTION_EPILOGUE (file, get_frame_size ());
1790 #endif
1792 #ifdef SDB_DEBUGGING_INFO
1793 if (write_symbols == SDB_DEBUG)
1794 sdbout_end_epilogue ();
1795 #endif
1797 #ifdef DWARF_DEBUGGING_INFO
1798 if (write_symbols == DWARF_DEBUG)
1799 dwarfout_end_epilogue ();
1800 #endif
1802 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1803 if (dwarf2out_do_frame ())
1804 dwarf2out_end_epilogue ();
1805 #endif
1807 #ifdef XCOFF_DEBUGGING_INFO
1808 if (write_symbols == XCOFF_DEBUG)
1809 xcoffout_end_epilogue (file);
1810 #endif
1812 bb_func_label_num = -1; /* not in function, nuke label # */
1814 #ifdef IA64_UNWIND_INFO
1815 output_function_exception_table ();
1816 #endif
1818 /* If FUNCTION_EPILOGUE is not defined, then the function body
1819 itself contains return instructions wherever needed. */
1822 /* Add a block to the linked list that remembers the current line/file/function
1823 for basic block profiling. Emit the label in front of the basic block and
1824 the instructions that increment the count field. */
1826 static void
1827 add_bb (file)
1828 FILE *file;
1830 struct bb_list *ptr =
1831 (struct bb_list *) permalloc (sizeof (struct bb_list));
1833 /* Add basic block to linked list. */
1834 ptr->next = 0;
1835 ptr->line_num = last_linenum;
1836 ptr->file_label_num = bb_file_label_num;
1837 ptr->func_label_num = bb_func_label_num;
1838 *bb_tail = ptr;
1839 bb_tail = &ptr->next;
1841 /* Enable the table of basic-block use counts
1842 to point at the code it applies to. */
1843 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1845 /* Before first insn of this basic block, increment the
1846 count of times it was entered. */
1847 #ifdef BLOCK_PROFILER
1848 BLOCK_PROFILER (file, count_basic_blocks);
1849 #endif
1850 #ifdef HAVE_cc0
1851 CC_STATUS_INIT;
1852 #endif
1854 new_block = 0;
1855 count_basic_blocks++;
1858 /* Add a string to be used for basic block profiling. */
1860 static int
1861 add_bb_string (string, perm_p)
1862 const char *string;
1863 int perm_p;
1865 int len;
1866 struct bb_str *ptr = 0;
1868 if (!string)
1870 string = "<unknown>";
1871 perm_p = TRUE;
1874 /* Allocate a new string if the current string isn't permanent. If
1875 the string is permanent search for the same string in other
1876 allocations. */
1878 len = strlen (string) + 1;
1879 if (!perm_p)
1881 char *p = (char *) permalloc (len);
1882 memcpy (p, string, len);
1883 string = p;
1885 else
1886 for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
1887 if (ptr->string == string)
1888 break;
1890 /* Allocate a new string block if we need to. */
1891 if (!ptr)
1893 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1894 ptr->next = 0;
1895 ptr->length = len;
1896 ptr->label_num = sbb_label_num++;
1897 ptr->string = string;
1898 *sbb_tail = ptr;
1899 sbb_tail = &ptr->next;
1902 return ptr->label_num;
1905 /* Output assembler code for some insns: all or part of a function.
1906 For description of args, see `final_start_function', above.
1908 PRESCAN is 1 if we are not really outputting,
1909 just scanning as if we were outputting.
1910 Prescanning deletes and rearranges insns just like ordinary output.
1911 PRESCAN is -2 if we are outputting after having prescanned.
1912 In this case, don't try to delete or rearrange insns
1913 because that has already been done.
1914 Prescanning is done only on certain machines. */
1916 void
1917 final (first, file, optimize, prescan)
1918 rtx first;
1919 FILE *file;
1920 int optimize;
1921 int prescan;
1923 register rtx insn;
1924 int max_line = 0;
1925 int max_uid = 0;
1927 last_ignored_compare = 0;
1928 new_block = 1;
1930 /* Make a map indicating which line numbers appear in this function.
1931 When producing SDB debugging info, delete troublesome line number
1932 notes from inlined functions in other files as well as duplicate
1933 line number notes. */
1934 #ifdef SDB_DEBUGGING_INFO
1935 if (write_symbols == SDB_DEBUG)
1937 rtx last = 0;
1938 for (insn = first; insn; insn = NEXT_INSN (insn))
1939 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1941 if ((RTX_INTEGRATED_P (insn)
1942 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1943 || (last != 0
1944 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1945 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1947 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1948 NOTE_SOURCE_FILE (insn) = 0;
1949 continue;
1951 last = insn;
1952 if (NOTE_LINE_NUMBER (insn) > max_line)
1953 max_line = NOTE_LINE_NUMBER (insn);
1956 else
1957 #endif
1959 for (insn = first; insn; insn = NEXT_INSN (insn))
1960 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1961 max_line = NOTE_LINE_NUMBER (insn);
1964 line_note_exists = (char *) xcalloc (max_line + 1, sizeof (char));
1966 for (insn = first; insn; insn = NEXT_INSN (insn))
1968 if (INSN_UID (insn) > max_uid) /* find largest UID */
1969 max_uid = INSN_UID (insn);
1970 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1971 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1972 #ifdef HAVE_cc0
1973 /* If CC tracking across branches is enabled, record the insn which
1974 jumps to each branch only reached from one place. */
1975 if (optimize && GET_CODE (insn) == JUMP_INSN)
1977 rtx lab = JUMP_LABEL (insn);
1978 if (lab && LABEL_NUSES (lab) == 1)
1980 LABEL_REFS (lab) = insn;
1983 #endif
1986 init_recog ();
1988 CC_STATUS_INIT;
1990 /* Output the insns. */
1991 for (insn = NEXT_INSN (first); insn;)
1993 #ifdef HAVE_ATTR_length
1994 if (INSN_UID (insn) >= INSN_ADDRESSES_SIZE ())
1996 #ifdef STACK_REGS
1997 /* Irritatingly, the reg-stack pass is creating new instructions
1998 and because of REG_DEAD note abuse it has to run after
1999 shorten_branches. Fake address of -1 then. */
2000 insn_current_address = -1;
2001 #else
2002 /* This can be triggered by bugs elsewhere in the compiler if
2003 new insns are created after init_insn_lengths is called. */
2004 abort ();
2005 #endif
2007 else
2008 insn_current_address = INSN_ADDRESSES (INSN_UID (insn));
2009 #endif /* HAVE_ATTR_length */
2011 insn = final_scan_insn (insn, file, optimize, prescan, 0);
2014 /* Do basic-block profiling here
2015 if the last insn was a conditional branch. */
2016 if (profile_block_flag && new_block)
2017 add_bb (file);
2019 free (line_note_exists);
2020 line_note_exists = NULL;
2023 const char *
2024 get_insn_template (code, insn)
2025 int code;
2026 rtx insn;
2028 const void *output = insn_data[code].output;
2029 switch (insn_data[code].output_format)
2031 case INSN_OUTPUT_FORMAT_SINGLE:
2032 return (const char *) output;
2033 case INSN_OUTPUT_FORMAT_MULTI:
2034 return ((const char *const *) output)[which_alternative];
2035 case INSN_OUTPUT_FORMAT_FUNCTION:
2036 if (insn == NULL)
2037 abort ();
2038 return (*(insn_output_fn) output) (recog_data.operand, insn);
2040 default:
2041 abort ();
2045 /* The final scan for one insn, INSN.
2046 Args are same as in `final', except that INSN
2047 is the insn being scanned.
2048 Value returned is the next insn to be scanned.
2050 NOPEEPHOLES is the flag to disallow peephole processing (currently
2051 used for within delayed branch sequence output). */
2054 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
2055 rtx insn;
2056 FILE *file;
2057 int optimize ATTRIBUTE_UNUSED;
2058 int prescan;
2059 int nopeepholes ATTRIBUTE_UNUSED;
2061 #ifdef HAVE_cc0
2062 rtx set;
2063 #endif
2065 insn_counter++;
2067 /* Ignore deleted insns. These can occur when we split insns (due to a
2068 template of "#") while not optimizing. */
2069 if (INSN_DELETED_P (insn))
2070 return NEXT_INSN (insn);
2072 switch (GET_CODE (insn))
2074 case NOTE:
2075 if (prescan > 0)
2076 break;
2078 switch (NOTE_LINE_NUMBER (insn))
2080 case NOTE_INSN_DELETED:
2081 case NOTE_INSN_LOOP_BEG:
2082 case NOTE_INSN_LOOP_END:
2083 case NOTE_INSN_LOOP_CONT:
2084 case NOTE_INSN_LOOP_VTOP:
2085 case NOTE_INSN_FUNCTION_END:
2086 case NOTE_INSN_SETJMP:
2087 case NOTE_INSN_REPEATED_LINE_NUMBER:
2088 case NOTE_INSN_RANGE_BEG:
2089 case NOTE_INSN_RANGE_END:
2090 case NOTE_INSN_LIVE:
2091 case NOTE_INSN_EXPECTED_VALUE:
2092 break;
2094 case NOTE_INSN_BASIC_BLOCK:
2095 #ifdef IA64_UNWIND_INFO
2096 IA64_UNWIND_EMIT (asm_out_file, insn);
2097 #endif
2098 if (flag_debug_asm)
2099 fprintf (asm_out_file, "\t%s basic block %d\n",
2100 ASM_COMMENT_START, NOTE_BASIC_BLOCK (insn)->index);
2101 break;
2103 case NOTE_INSN_EH_REGION_BEG:
2104 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHB",
2105 NOTE_EH_HANDLER (insn));
2106 break;
2108 case NOTE_INSN_EH_REGION_END:
2109 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHE",
2110 NOTE_EH_HANDLER (insn));
2111 break;
2113 case NOTE_INSN_PROLOGUE_END:
2114 #ifdef FUNCTION_END_PROLOGUE
2115 FUNCTION_END_PROLOGUE (file);
2116 #endif
2117 profile_after_prologue (file);
2118 break;
2120 case NOTE_INSN_EPILOGUE_BEG:
2121 #ifdef FUNCTION_BEGIN_EPILOGUE
2122 FUNCTION_BEGIN_EPILOGUE (file);
2123 #endif
2124 break;
2126 case NOTE_INSN_FUNCTION_BEG:
2127 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
2128 /* MIPS stabs require the parameter descriptions to be after the
2129 function entry point rather than before. */
2130 if (write_symbols == SDB_DEBUG)
2132 app_disable ();
2133 sdbout_begin_function (last_linenum);
2135 #endif
2136 #ifdef DWARF_DEBUGGING_INFO
2137 /* This outputs a marker where the function body starts, so it
2138 must be after the prologue. */
2139 if (write_symbols == DWARF_DEBUG)
2141 app_disable ();
2142 dwarfout_begin_function ();
2144 #endif
2145 break;
2147 case NOTE_INSN_BLOCK_BEG:
2148 if (debug_info_level == DINFO_LEVEL_NORMAL
2149 || debug_info_level == DINFO_LEVEL_VERBOSE
2150 || write_symbols == DWARF_DEBUG
2151 || write_symbols == DWARF2_DEBUG)
2153 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2155 app_disable ();
2156 ++block_depth;
2157 high_block_linenum = last_linenum;
2159 /* Output debugging info about the symbol-block beginning. */
2160 #ifdef SDB_DEBUGGING_INFO
2161 if (write_symbols == SDB_DEBUG)
2162 sdbout_begin_block (file, last_linenum, n);
2163 #endif
2164 #ifdef XCOFF_DEBUGGING_INFO
2165 if (write_symbols == XCOFF_DEBUG)
2166 xcoffout_begin_block (file, last_linenum, n);
2167 #endif
2168 #ifdef DBX_DEBUGGING_INFO
2169 if (write_symbols == DBX_DEBUG)
2170 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", n);
2171 #endif
2172 #ifdef DWARF_DEBUGGING_INFO
2173 if (write_symbols == DWARF_DEBUG)
2174 dwarfout_begin_block (n);
2175 #endif
2176 #ifdef DWARF2_DEBUGGING_INFO
2177 if (write_symbols == DWARF2_DEBUG)
2178 dwarf2out_begin_block (n);
2179 #endif
2181 /* Mark this block as output. */
2182 TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
2184 break;
2186 case NOTE_INSN_BLOCK_END:
2187 if (debug_info_level == DINFO_LEVEL_NORMAL
2188 || debug_info_level == DINFO_LEVEL_VERBOSE
2189 || write_symbols == DWARF_DEBUG
2190 || write_symbols == DWARF2_DEBUG)
2192 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2194 app_disable ();
2196 /* End of a symbol-block. */
2197 --block_depth;
2198 if (block_depth < 0)
2199 abort ();
2201 #ifdef XCOFF_DEBUGGING_INFO
2202 if (write_symbols == XCOFF_DEBUG)
2203 xcoffout_end_block (file, high_block_linenum, n);
2204 #endif
2205 #ifdef DBX_DEBUGGING_INFO
2206 if (write_symbols == DBX_DEBUG)
2207 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE", n);
2208 #endif
2209 #ifdef SDB_DEBUGGING_INFO
2210 if (write_symbols == SDB_DEBUG)
2211 sdbout_end_block (file, high_block_linenum, n);
2212 #endif
2213 #ifdef DWARF_DEBUGGING_INFO
2214 if (write_symbols == DWARF_DEBUG)
2215 dwarfout_end_block (n);
2216 #endif
2217 #ifdef DWARF2_DEBUGGING_INFO
2218 if (write_symbols == DWARF2_DEBUG)
2219 dwarf2out_end_block (n);
2220 #endif
2222 break;
2224 case NOTE_INSN_DELETED_LABEL:
2225 /* Emit the label. We may have deleted the CODE_LABEL because
2226 the label could be proved to be unreachable, though still
2227 referenced (in the form of having its address taken. */
2228 ASM_OUTPUT_DEBUG_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2229 break;
2231 case 0:
2232 break;
2234 default:
2235 if (NOTE_LINE_NUMBER (insn) <= 0)
2236 abort ();
2238 /* This note is a line-number. */
2240 register rtx note;
2241 int note_after = 0;
2243 /* If there is anything real after this note, output it.
2244 If another line note follows, omit this one. */
2245 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
2247 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
2248 break;
2250 /* These types of notes can be significant
2251 so make sure the preceding line number stays. */
2252 else if (GET_CODE (note) == NOTE
2253 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
2254 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
2255 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
2256 break;
2257 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
2259 /* Another line note follows; we can delete this note
2260 if no intervening line numbers have notes elsewhere. */
2261 int num;
2262 for (num = NOTE_LINE_NUMBER (insn) + 1;
2263 num < NOTE_LINE_NUMBER (note);
2264 num++)
2265 if (line_note_exists[num])
2266 break;
2268 if (num >= NOTE_LINE_NUMBER (note))
2269 note_after = 1;
2270 break;
2274 /* Output this line note if it is the first or the last line
2275 note in a row. */
2276 if (!note_after)
2277 output_source_line (file, insn);
2279 break;
2281 break;
2283 case BARRIER:
2284 #if defined (DWARF2_UNWIND_INFO)
2285 if (dwarf2out_do_frame ())
2286 dwarf2out_frame_debug (insn);
2287 #endif
2288 break;
2290 case CODE_LABEL:
2291 /* The target port might emit labels in the output function for
2292 some insn, e.g. sh.c output_branchy_insn. */
2293 if (CODE_LABEL_NUMBER (insn) <= max_labelno)
2295 int align = LABEL_TO_ALIGNMENT (insn);
2296 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2297 int max_skip = LABEL_TO_MAX_SKIP (insn);
2298 #endif
2300 if (align && NEXT_INSN (insn))
2301 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2302 ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
2303 #else
2304 ASM_OUTPUT_ALIGN (file, align);
2305 #endif
2307 #ifdef HAVE_cc0
2308 CC_STATUS_INIT;
2309 /* If this label is reached from only one place, set the condition
2310 codes from the instruction just before the branch. */
2312 /* Disabled because some insns set cc_status in the C output code
2313 and NOTICE_UPDATE_CC alone can set incorrect status. */
2314 if (0 /* optimize && LABEL_NUSES (insn) == 1*/)
2316 rtx jump = LABEL_REFS (insn);
2317 rtx barrier = prev_nonnote_insn (insn);
2318 rtx prev;
2319 /* If the LABEL_REFS field of this label has been set to point
2320 at a branch, the predecessor of the branch is a regular
2321 insn, and that branch is the only way to reach this label,
2322 set the condition codes based on the branch and its
2323 predecessor. */
2324 if (barrier && GET_CODE (barrier) == BARRIER
2325 && jump && GET_CODE (jump) == JUMP_INSN
2326 && (prev = prev_nonnote_insn (jump))
2327 && GET_CODE (prev) == INSN)
2329 NOTICE_UPDATE_CC (PATTERN (prev), prev);
2330 NOTICE_UPDATE_CC (PATTERN (jump), jump);
2333 #endif
2334 if (prescan > 0)
2335 break;
2336 new_block = 1;
2338 #ifdef FINAL_PRESCAN_LABEL
2339 FINAL_PRESCAN_INSN (insn, NULL, 0);
2340 #endif
2342 #ifdef SDB_DEBUGGING_INFO
2343 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
2344 sdbout_label (insn);
2345 #endif
2346 if (app_on)
2348 fputs (ASM_APP_OFF, file);
2349 app_on = 0;
2351 if (NEXT_INSN (insn) != 0
2352 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
2354 rtx nextbody = PATTERN (NEXT_INSN (insn));
2356 /* If this label is followed by a jump-table,
2357 make sure we put the label in the read-only section. Also
2358 possibly write the label and jump table together. */
2360 if (GET_CODE (nextbody) == ADDR_VEC
2361 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
2363 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2364 /* In this case, the case vector is being moved by the
2365 target, so don't output the label at all. Leave that
2366 to the back end macros. */
2367 #else
2368 if (! JUMP_TABLES_IN_TEXT_SECTION)
2370 readonly_data_section ();
2371 #ifdef READONLY_DATA_SECTION
2372 ASM_OUTPUT_ALIGN (file,
2373 exact_log2 (BIGGEST_ALIGNMENT
2374 / BITS_PER_UNIT));
2375 #endif /* READONLY_DATA_SECTION */
2377 else
2378 function_section (current_function_decl);
2380 #ifdef ASM_OUTPUT_CASE_LABEL
2381 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
2382 NEXT_INSN (insn));
2383 #else
2384 if (LABEL_ALTERNATE_NAME (insn))
2385 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2386 else
2387 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2388 #endif
2389 #endif
2390 break;
2393 if (LABEL_ALTERNATE_NAME (insn))
2394 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2395 else
2396 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2397 break;
2399 default:
2401 register rtx body = PATTERN (insn);
2402 int insn_code_number;
2403 const char *template;
2404 #ifdef HAVE_cc0
2405 rtx note;
2406 #endif
2408 /* An INSN, JUMP_INSN or CALL_INSN.
2409 First check for special kinds that recog doesn't recognize. */
2411 if (GET_CODE (body) == USE /* These are just declarations */
2412 || GET_CODE (body) == CLOBBER)
2413 break;
2415 #ifdef HAVE_cc0
2416 /* If there is a REG_CC_SETTER note on this insn, it means that
2417 the setting of the condition code was done in the delay slot
2418 of the insn that branched here. So recover the cc status
2419 from the insn that set it. */
2421 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2422 if (note)
2424 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
2425 cc_prev_status = cc_status;
2427 #endif
2429 /* Detect insns that are really jump-tables
2430 and output them as such. */
2432 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
2434 #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
2435 register int vlen, idx;
2436 #endif
2438 if (prescan > 0)
2439 break;
2441 if (app_on)
2443 fputs (ASM_APP_OFF, file);
2444 app_on = 0;
2447 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2448 if (GET_CODE (body) == ADDR_VEC)
2450 #ifdef ASM_OUTPUT_ADDR_VEC
2451 ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
2452 #else
2453 abort ();
2454 #endif
2456 else
2458 #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
2459 ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
2460 #else
2461 abort ();
2462 #endif
2464 #else
2465 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2466 for (idx = 0; idx < vlen; idx++)
2468 if (GET_CODE (body) == ADDR_VEC)
2470 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2471 ASM_OUTPUT_ADDR_VEC_ELT
2472 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2473 #else
2474 abort ();
2475 #endif
2477 else
2479 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2480 ASM_OUTPUT_ADDR_DIFF_ELT
2481 (file,
2482 body,
2483 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2484 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2485 #else
2486 abort ();
2487 #endif
2490 #ifdef ASM_OUTPUT_CASE_END
2491 ASM_OUTPUT_CASE_END (file,
2492 CODE_LABEL_NUMBER (PREV_INSN (insn)),
2493 insn);
2494 #endif
2495 #endif
2497 function_section (current_function_decl);
2499 break;
2502 /* Do basic-block profiling when we reach a new block.
2503 Done here to avoid jump tables. */
2504 if (profile_block_flag && new_block)
2505 add_bb (file);
2507 if (GET_CODE (body) == ASM_INPUT)
2509 /* There's no telling what that did to the condition codes. */
2510 CC_STATUS_INIT;
2511 if (prescan > 0)
2512 break;
2513 if (! app_on)
2515 fputs (ASM_APP_ON, file);
2516 app_on = 1;
2518 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
2519 break;
2522 /* Detect `asm' construct with operands. */
2523 if (asm_noperands (body) >= 0)
2525 unsigned int noperands = asm_noperands (body);
2526 rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
2527 const char *string;
2529 /* There's no telling what that did to the condition codes. */
2530 CC_STATUS_INIT;
2531 if (prescan > 0)
2532 break;
2534 if (! app_on)
2536 fputs (ASM_APP_ON, file);
2537 app_on = 1;
2540 /* Get out the operand values. */
2541 string = decode_asm_operands (body, ops, NULL, NULL, NULL);
2542 /* Inhibit aborts on what would otherwise be compiler bugs. */
2543 insn_noperands = noperands;
2544 this_is_asm_operands = insn;
2546 /* Output the insn using them. */
2547 output_asm_insn (string, ops);
2548 this_is_asm_operands = 0;
2549 break;
2552 if (prescan <= 0 && app_on)
2554 fputs (ASM_APP_OFF, file);
2555 app_on = 0;
2558 if (GET_CODE (body) == SEQUENCE)
2560 /* A delayed-branch sequence */
2561 register int i;
2562 rtx next;
2564 if (prescan > 0)
2565 break;
2566 final_sequence = body;
2568 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2569 force the restoration of a comparison that was previously
2570 thought unnecessary. If that happens, cancel this sequence
2571 and cause that insn to be restored. */
2573 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
2574 if (next != XVECEXP (body, 0, 1))
2576 final_sequence = 0;
2577 return next;
2580 for (i = 1; i < XVECLEN (body, 0); i++)
2582 rtx insn = XVECEXP (body, 0, i);
2583 rtx next = NEXT_INSN (insn);
2584 /* We loop in case any instruction in a delay slot gets
2585 split. */
2587 insn = final_scan_insn (insn, file, 0, prescan, 1);
2588 while (insn != next);
2590 #ifdef DBR_OUTPUT_SEQEND
2591 DBR_OUTPUT_SEQEND (file);
2592 #endif
2593 final_sequence = 0;
2595 /* If the insn requiring the delay slot was a CALL_INSN, the
2596 insns in the delay slot are actually executed before the
2597 called function. Hence we don't preserve any CC-setting
2598 actions in these insns and the CC must be marked as being
2599 clobbered by the function. */
2600 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
2602 CC_STATUS_INIT;
2605 /* Following a conditional branch sequence, we have a new basic
2606 block. */
2607 if (profile_block_flag)
2609 rtx insn = XVECEXP (body, 0, 0);
2610 rtx body = PATTERN (insn);
2612 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2613 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2614 || (GET_CODE (insn) == JUMP_INSN
2615 && GET_CODE (body) == PARALLEL
2616 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2617 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
2618 new_block = 1;
2620 break;
2623 /* We have a real machine instruction as rtl. */
2625 body = PATTERN (insn);
2627 #ifdef HAVE_cc0
2628 set = single_set (insn);
2630 /* Check for redundant test and compare instructions
2631 (when the condition codes are already set up as desired).
2632 This is done only when optimizing; if not optimizing,
2633 it should be possible for the user to alter a variable
2634 with the debugger in between statements
2635 and the next statement should reexamine the variable
2636 to compute the condition codes. */
2638 if (optimize)
2640 #if 0
2641 rtx set = single_set (insn);
2642 #endif
2644 if (set
2645 && GET_CODE (SET_DEST (set)) == CC0
2646 && insn != last_ignored_compare)
2648 if (GET_CODE (SET_SRC (set)) == SUBREG)
2649 SET_SRC (set) = alter_subreg (SET_SRC (set));
2650 else if (GET_CODE (SET_SRC (set)) == COMPARE)
2652 if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
2653 XEXP (SET_SRC (set), 0)
2654 = alter_subreg (XEXP (SET_SRC (set), 0));
2655 if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
2656 XEXP (SET_SRC (set), 1)
2657 = alter_subreg (XEXP (SET_SRC (set), 1));
2659 if ((cc_status.value1 != 0
2660 && rtx_equal_p (SET_SRC (set), cc_status.value1))
2661 || (cc_status.value2 != 0
2662 && rtx_equal_p (SET_SRC (set), cc_status.value2)))
2664 /* Don't delete insn if it has an addressing side-effect. */
2665 if (! FIND_REG_INC_NOTE (insn, 0)
2666 /* or if anything in it is volatile. */
2667 && ! volatile_refs_p (PATTERN (insn)))
2669 /* We don't really delete the insn; just ignore it. */
2670 last_ignored_compare = insn;
2671 break;
2676 #endif
2678 /* Following a conditional branch, we have a new basic block.
2679 But if we are inside a sequence, the new block starts after the
2680 last insn of the sequence. */
2681 if (profile_block_flag && final_sequence == 0
2682 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2683 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2684 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
2685 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2686 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
2687 new_block = 1;
2689 #ifndef STACK_REGS
2690 /* Don't bother outputting obvious no-ops, even without -O.
2691 This optimization is fast and doesn't interfere with debugging.
2692 Don't do this if the insn is in a delay slot, since this
2693 will cause an improper number of delay insns to be written. */
2694 if (final_sequence == 0
2695 && prescan >= 0
2696 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
2697 && GET_CODE (SET_SRC (body)) == REG
2698 && GET_CODE (SET_DEST (body)) == REG
2699 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
2700 break;
2701 #endif
2703 #ifdef HAVE_cc0
2704 /* If this is a conditional branch, maybe modify it
2705 if the cc's are in a nonstandard state
2706 so that it accomplishes the same thing that it would
2707 do straightforwardly if the cc's were set up normally. */
2709 if (cc_status.flags != 0
2710 && GET_CODE (insn) == JUMP_INSN
2711 && GET_CODE (body) == SET
2712 && SET_DEST (body) == pc_rtx
2713 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2714 && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
2715 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
2716 /* This is done during prescan; it is not done again
2717 in final scan when prescan has been done. */
2718 && prescan >= 0)
2720 /* This function may alter the contents of its argument
2721 and clear some of the cc_status.flags bits.
2722 It may also return 1 meaning condition now always true
2723 or -1 meaning condition now always false
2724 or 2 meaning condition nontrivial but altered. */
2725 register int result = alter_cond (XEXP (SET_SRC (body), 0));
2726 /* If condition now has fixed value, replace the IF_THEN_ELSE
2727 with its then-operand or its else-operand. */
2728 if (result == 1)
2729 SET_SRC (body) = XEXP (SET_SRC (body), 1);
2730 if (result == -1)
2731 SET_SRC (body) = XEXP (SET_SRC (body), 2);
2733 /* The jump is now either unconditional or a no-op.
2734 If it has become a no-op, don't try to output it.
2735 (It would not be recognized.) */
2736 if (SET_SRC (body) == pc_rtx)
2738 PUT_CODE (insn, NOTE);
2739 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2740 NOTE_SOURCE_FILE (insn) = 0;
2741 break;
2743 else if (GET_CODE (SET_SRC (body)) == RETURN)
2744 /* Replace (set (pc) (return)) with (return). */
2745 PATTERN (insn) = body = SET_SRC (body);
2747 /* Rerecognize the instruction if it has changed. */
2748 if (result != 0)
2749 INSN_CODE (insn) = -1;
2752 /* Make same adjustments to instructions that examine the
2753 condition codes without jumping and instructions that
2754 handle conditional moves (if this machine has either one). */
2756 if (cc_status.flags != 0
2757 && set != 0)
2759 rtx cond_rtx, then_rtx, else_rtx;
2761 if (GET_CODE (insn) != JUMP_INSN
2762 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2764 cond_rtx = XEXP (SET_SRC (set), 0);
2765 then_rtx = XEXP (SET_SRC (set), 1);
2766 else_rtx = XEXP (SET_SRC (set), 2);
2768 else
2770 cond_rtx = SET_SRC (set);
2771 then_rtx = const_true_rtx;
2772 else_rtx = const0_rtx;
2775 switch (GET_CODE (cond_rtx))
2777 case GTU:
2778 case GT:
2779 case LTU:
2780 case LT:
2781 case GEU:
2782 case GE:
2783 case LEU:
2784 case LE:
2785 case EQ:
2786 case NE:
2788 register int result;
2789 if (XEXP (cond_rtx, 0) != cc0_rtx)
2790 break;
2791 result = alter_cond (cond_rtx);
2792 if (result == 1)
2793 validate_change (insn, &SET_SRC (set), then_rtx, 0);
2794 else if (result == -1)
2795 validate_change (insn, &SET_SRC (set), else_rtx, 0);
2796 else if (result == 2)
2797 INSN_CODE (insn) = -1;
2798 if (SET_DEST (set) == SET_SRC (set))
2800 PUT_CODE (insn, NOTE);
2801 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2802 NOTE_SOURCE_FILE (insn) = 0;
2805 break;
2807 default:
2808 break;
2812 #endif
2814 #ifdef HAVE_peephole
2815 /* Do machine-specific peephole optimizations if desired. */
2817 if (optimize && !flag_no_peephole && !nopeepholes)
2819 rtx next = peephole (insn);
2820 /* When peepholing, if there were notes within the peephole,
2821 emit them before the peephole. */
2822 if (next != 0 && next != NEXT_INSN (insn))
2824 rtx prev = PREV_INSN (insn);
2825 rtx note;
2827 for (note = NEXT_INSN (insn); note != next;
2828 note = NEXT_INSN (note))
2829 final_scan_insn (note, file, optimize, prescan, nopeepholes);
2831 /* In case this is prescan, put the notes
2832 in proper position for later rescan. */
2833 note = NEXT_INSN (insn);
2834 PREV_INSN (note) = prev;
2835 NEXT_INSN (prev) = note;
2836 NEXT_INSN (PREV_INSN (next)) = insn;
2837 PREV_INSN (insn) = PREV_INSN (next);
2838 NEXT_INSN (insn) = next;
2839 PREV_INSN (next) = insn;
2842 /* PEEPHOLE might have changed this. */
2843 body = PATTERN (insn);
2845 #endif
2847 /* Try to recognize the instruction.
2848 If successful, verify that the operands satisfy the
2849 constraints for the instruction. Crash if they don't,
2850 since `reload' should have changed them so that they do. */
2852 insn_code_number = recog_memoized (insn);
2853 cleanup_subreg_operands (insn);
2855 /* Dump the insn in the assembly for debugging. */
2856 if (flag_dump_rtl_in_asm)
2858 print_rtx_head = ASM_COMMENT_START;
2859 print_rtl_single (asm_out_file, insn);
2860 print_rtx_head = "";
2863 if (! constrain_operands_cached (1))
2864 fatal_insn_not_found (insn);
2866 /* Some target machines need to prescan each insn before
2867 it is output. */
2869 #ifdef FINAL_PRESCAN_INSN
2870 FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2871 #endif
2873 #ifdef HAVE_conditional_execution
2874 if (GET_CODE (PATTERN (insn)) == COND_EXEC)
2875 current_insn_predicate = COND_EXEC_TEST (PATTERN (insn));
2876 else
2877 current_insn_predicate = NULL_RTX;
2878 #endif
2880 #ifdef HAVE_cc0
2881 cc_prev_status = cc_status;
2883 /* Update `cc_status' for this instruction.
2884 The instruction's output routine may change it further.
2885 If the output routine for a jump insn needs to depend
2886 on the cc status, it should look at cc_prev_status. */
2888 NOTICE_UPDATE_CC (body, insn);
2889 #endif
2891 current_output_insn = debug_insn = insn;
2893 #if defined (DWARF2_UNWIND_INFO)
2894 if (GET_CODE (insn) == CALL_INSN && dwarf2out_do_frame ())
2895 dwarf2out_frame_debug (insn);
2896 #endif
2898 /* Find the proper template for this insn. */
2899 template = get_insn_template (insn_code_number, insn);
2901 /* If the C code returns 0, it means that it is a jump insn
2902 which follows a deleted test insn, and that test insn
2903 needs to be reinserted. */
2904 if (template == 0)
2906 rtx prev;
2908 if (prev_nonnote_insn (insn) != last_ignored_compare)
2909 abort ();
2910 new_block = 0;
2912 /* We have already processed the notes between the setter and
2913 the user. Make sure we don't process them again, this is
2914 particularly important if one of the notes is a block
2915 scope note or an EH note. */
2916 for (prev = insn;
2917 prev != last_ignored_compare;
2918 prev = PREV_INSN (prev))
2920 if (GET_CODE (prev) == NOTE)
2922 NOTE_LINE_NUMBER (prev) = NOTE_INSN_DELETED;
2923 NOTE_SOURCE_FILE (prev) = 0;
2927 return prev;
2930 /* If the template is the string "#", it means that this insn must
2931 be split. */
2932 if (template[0] == '#' && template[1] == '\0')
2934 rtx new = try_split (body, insn, 0);
2936 /* If we didn't split the insn, go away. */
2937 if (new == insn && PATTERN (new) == body)
2938 fatal_insn ("Could not split insn", insn);
2940 #ifdef HAVE_ATTR_length
2941 /* This instruction should have been split in shorten_branches,
2942 to ensure that we would have valid length info for the
2943 splitees. */
2944 abort ();
2945 #endif
2947 new_block = 0;
2948 return new;
2951 if (prescan > 0)
2952 break;
2954 #ifdef IA64_UNWIND_INFO
2955 IA64_UNWIND_EMIT (asm_out_file, insn);
2956 #endif
2957 /* Output assembler code from the template. */
2959 output_asm_insn (template, recog_data.operand);
2961 #if defined (DWARF2_UNWIND_INFO)
2962 #if defined (HAVE_prologue)
2963 if (GET_CODE (insn) == INSN && dwarf2out_do_frame ())
2964 dwarf2out_frame_debug (insn);
2965 #else
2966 if (!ACCUMULATE_OUTGOING_ARGS
2967 && GET_CODE (insn) == INSN
2968 && dwarf2out_do_frame ())
2969 dwarf2out_frame_debug (insn);
2970 #endif
2971 #endif
2973 #if 0
2974 /* It's not at all clear why we did this and doing so interferes
2975 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2976 with this out. */
2978 /* Mark this insn as having been output. */
2979 INSN_DELETED_P (insn) = 1;
2980 #endif
2982 current_output_insn = debug_insn = 0;
2985 return NEXT_INSN (insn);
2988 /* Output debugging info to the assembler file FILE
2989 based on the NOTE-insn INSN, assumed to be a line number. */
2991 static void
2992 output_source_line (file, insn)
2993 FILE *file ATTRIBUTE_UNUSED;
2994 rtx insn;
2996 register const char *filename = NOTE_SOURCE_FILE (insn);
2998 /* Remember filename for basic block profiling.
2999 Filenames are allocated on the permanent obstack
3000 or are passed in ARGV, so we don't have to save
3001 the string. */
3003 if (profile_block_flag && last_filename != filename)
3004 bb_file_label_num = add_bb_string (filename, TRUE);
3006 last_filename = filename;
3007 last_linenum = NOTE_LINE_NUMBER (insn);
3008 high_block_linenum = MAX (last_linenum, high_block_linenum);
3009 high_function_linenum = MAX (last_linenum, high_function_linenum);
3011 if (write_symbols != NO_DEBUG)
3013 #ifdef SDB_DEBUGGING_INFO
3014 if (write_symbols == SDB_DEBUG
3015 #if 0 /* People like having line numbers even in wrong file! */
3016 /* COFF can't handle multiple source files--lose, lose. */
3017 && !strcmp (filename, main_input_filename)
3018 #endif
3019 /* COFF relative line numbers must be positive. */
3020 && last_linenum > sdb_begin_function_line)
3022 #ifdef ASM_OUTPUT_SOURCE_LINE
3023 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
3024 #else
3025 fprintf (file, "\t.ln\t%d\n",
3026 ((sdb_begin_function_line > -1)
3027 ? last_linenum - sdb_begin_function_line : 1));
3028 #endif
3030 #endif
3032 #if defined (DBX_DEBUGGING_INFO)
3033 if (write_symbols == DBX_DEBUG)
3034 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
3035 #endif
3037 #if defined (XCOFF_DEBUGGING_INFO)
3038 if (write_symbols == XCOFF_DEBUG)
3039 xcoffout_source_line (file, filename, insn);
3040 #endif
3042 #ifdef DWARF_DEBUGGING_INFO
3043 if (write_symbols == DWARF_DEBUG)
3044 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
3045 #endif
3047 #ifdef DWARF2_DEBUGGING_INFO
3048 if (write_symbols == DWARF2_DEBUG)
3049 dwarf2out_line (filename, NOTE_LINE_NUMBER (insn));
3050 #endif
3054 /* For each operand in INSN, simplify (subreg (reg)) so that it refers
3055 directly to the desired hard register. */
3057 void
3058 cleanup_subreg_operands (insn)
3059 rtx insn;
3061 int i;
3062 extract_insn_cached (insn);
3063 for (i = 0; i < recog_data.n_operands; i++)
3065 if (GET_CODE (recog_data.operand[i]) == SUBREG)
3066 recog_data.operand[i] = alter_subreg (recog_data.operand[i]);
3067 else if (GET_CODE (recog_data.operand[i]) == PLUS
3068 || GET_CODE (recog_data.operand[i]) == MULT
3069 || GET_CODE (recog_data.operand[i]) == MEM)
3070 recog_data.operand[i] = walk_alter_subreg (recog_data.operand[i]);
3073 for (i = 0; i < recog_data.n_dups; i++)
3075 if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
3076 *recog_data.dup_loc[i] = alter_subreg (*recog_data.dup_loc[i]);
3077 else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
3078 || GET_CODE (*recog_data.dup_loc[i]) == MULT
3079 || GET_CODE (*recog_data.dup_loc[i]) == MEM)
3080 *recog_data.dup_loc[i] = walk_alter_subreg (*recog_data.dup_loc[i]);
3084 /* If X is a SUBREG, replace it with a REG or a MEM,
3085 based on the thing it is a subreg of. */
3088 alter_subreg (x)
3089 register rtx x;
3091 register rtx y = SUBREG_REG (x);
3093 if (GET_CODE (y) == SUBREG)
3094 y = alter_subreg (y);
3096 /* If reload is operating, we may be replacing inside this SUBREG.
3097 Check for that and make a new one if so. */
3098 if (reload_in_progress && find_replacement (&SUBREG_REG (x)) != 0)
3099 x = copy_rtx (x);
3101 if (GET_CODE (y) == REG)
3103 int regno = subreg_hard_regno (x, 1);
3105 PUT_CODE (x, REG);
3106 REGNO (x) = regno;
3107 ORIGINAL_REGNO (x) = ORIGINAL_REGNO (y);
3108 /* This field has a different meaning for REGs and SUBREGs. Make sure
3109 to clear it! */
3110 x->used = 0;
3112 else if (GET_CODE (y) == MEM)
3114 register int offset = SUBREG_BYTE (x);
3116 /* Catch these instead of generating incorrect code. */
3117 if ((offset % GET_MODE_SIZE (GET_MODE (x))) != 0)
3118 abort ();
3120 PUT_CODE (x, MEM);
3121 MEM_COPY_ATTRIBUTES (x, y);
3122 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
3125 return x;
3128 /* Do alter_subreg on all the SUBREGs contained in X. */
3130 static rtx
3131 walk_alter_subreg (x)
3132 rtx x;
3134 switch (GET_CODE (x))
3136 case PLUS:
3137 case MULT:
3138 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3139 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
3140 break;
3142 case MEM:
3143 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3144 break;
3146 case SUBREG:
3147 return alter_subreg (x);
3149 default:
3150 break;
3153 return x;
3156 #ifdef HAVE_cc0
3158 /* Given BODY, the body of a jump instruction, alter the jump condition
3159 as required by the bits that are set in cc_status.flags.
3160 Not all of the bits there can be handled at this level in all cases.
3162 The value is normally 0.
3163 1 means that the condition has become always true.
3164 -1 means that the condition has become always false.
3165 2 means that COND has been altered. */
3167 static int
3168 alter_cond (cond)
3169 register rtx cond;
3171 int value = 0;
3173 if (cc_status.flags & CC_REVERSED)
3175 value = 2;
3176 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
3179 if (cc_status.flags & CC_INVERTED)
3181 value = 2;
3182 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
3185 if (cc_status.flags & CC_NOT_POSITIVE)
3186 switch (GET_CODE (cond))
3188 case LE:
3189 case LEU:
3190 case GEU:
3191 /* Jump becomes unconditional. */
3192 return 1;
3194 case GT:
3195 case GTU:
3196 case LTU:
3197 /* Jump becomes no-op. */
3198 return -1;
3200 case GE:
3201 PUT_CODE (cond, EQ);
3202 value = 2;
3203 break;
3205 case LT:
3206 PUT_CODE (cond, NE);
3207 value = 2;
3208 break;
3210 default:
3211 break;
3214 if (cc_status.flags & CC_NOT_NEGATIVE)
3215 switch (GET_CODE (cond))
3217 case GE:
3218 case GEU:
3219 /* Jump becomes unconditional. */
3220 return 1;
3222 case LT:
3223 case LTU:
3224 /* Jump becomes no-op. */
3225 return -1;
3227 case LE:
3228 case LEU:
3229 PUT_CODE (cond, EQ);
3230 value = 2;
3231 break;
3233 case GT:
3234 case GTU:
3235 PUT_CODE (cond, NE);
3236 value = 2;
3237 break;
3239 default:
3240 break;
3243 if (cc_status.flags & CC_NO_OVERFLOW)
3244 switch (GET_CODE (cond))
3246 case GEU:
3247 /* Jump becomes unconditional. */
3248 return 1;
3250 case LEU:
3251 PUT_CODE (cond, EQ);
3252 value = 2;
3253 break;
3255 case GTU:
3256 PUT_CODE (cond, NE);
3257 value = 2;
3258 break;
3260 case LTU:
3261 /* Jump becomes no-op. */
3262 return -1;
3264 default:
3265 break;
3268 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
3269 switch (GET_CODE (cond))
3271 default:
3272 abort ();
3274 case NE:
3275 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
3276 value = 2;
3277 break;
3279 case EQ:
3280 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
3281 value = 2;
3282 break;
3285 if (cc_status.flags & CC_NOT_SIGNED)
3286 /* The flags are valid if signed condition operators are converted
3287 to unsigned. */
3288 switch (GET_CODE (cond))
3290 case LE:
3291 PUT_CODE (cond, LEU);
3292 value = 2;
3293 break;
3295 case LT:
3296 PUT_CODE (cond, LTU);
3297 value = 2;
3298 break;
3300 case GT:
3301 PUT_CODE (cond, GTU);
3302 value = 2;
3303 break;
3305 case GE:
3306 PUT_CODE (cond, GEU);
3307 value = 2;
3308 break;
3310 default:
3311 break;
3314 return value;
3316 #endif
3318 /* Report inconsistency between the assembler template and the operands.
3319 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
3321 void
3322 output_operand_lossage (msgid)
3323 const char *msgid;
3325 if (this_is_asm_operands)
3326 error_for_asm (this_is_asm_operands, "invalid `asm': %s", _(msgid));
3327 else
3328 internal_error ("output_operand: %s", _(msgid));
3331 /* Output of assembler code from a template, and its subroutines. */
3333 /* Output text from TEMPLATE to the assembler output file,
3334 obeying %-directions to substitute operands taken from
3335 the vector OPERANDS.
3337 %N (for N a digit) means print operand N in usual manner.
3338 %lN means require operand N to be a CODE_LABEL or LABEL_REF
3339 and print the label name with no punctuation.
3340 %cN means require operand N to be a constant
3341 and print the constant expression with no punctuation.
3342 %aN means expect operand N to be a memory address
3343 (not a memory reference!) and print a reference
3344 to that address.
3345 %nN means expect operand N to be a constant
3346 and print a constant expression for minus the value
3347 of the operand, with no other punctuation. */
3349 static void
3350 output_asm_name ()
3352 if (flag_print_asm_name)
3354 /* Annotate the assembly with a comment describing the pattern and
3355 alternative used. */
3356 if (debug_insn)
3358 register int num = INSN_CODE (debug_insn);
3359 fprintf (asm_out_file, "\t%s %d\t%s",
3360 ASM_COMMENT_START, INSN_UID (debug_insn),
3361 insn_data[num].name);
3362 if (insn_data[num].n_alternatives > 1)
3363 fprintf (asm_out_file, "/%d", which_alternative + 1);
3364 #ifdef HAVE_ATTR_length
3365 fprintf (asm_out_file, "\t[length = %d]",
3366 get_attr_length (debug_insn));
3367 #endif
3368 /* Clear this so only the first assembler insn
3369 of any rtl insn will get the special comment for -dp. */
3370 debug_insn = 0;
3375 void
3376 output_asm_insn (template, operands)
3377 const char *template;
3378 rtx *operands;
3380 register const char *p;
3381 register int c;
3383 /* An insn may return a null string template
3384 in a case where no assembler code is needed. */
3385 if (*template == 0)
3386 return;
3388 p = template;
3389 putc ('\t', asm_out_file);
3391 #ifdef ASM_OUTPUT_OPCODE
3392 ASM_OUTPUT_OPCODE (asm_out_file, p);
3393 #endif
3395 while ((c = *p++))
3396 switch (c)
3398 case '\n':
3399 output_asm_name ();
3400 putc (c, asm_out_file);
3401 #ifdef ASM_OUTPUT_OPCODE
3402 while ((c = *p) == '\t')
3404 putc (c, asm_out_file);
3405 p++;
3407 ASM_OUTPUT_OPCODE (asm_out_file, p);
3408 #endif
3409 break;
3411 #ifdef ASSEMBLER_DIALECT
3412 case '{':
3414 register int i;
3416 /* If we want the first dialect, do nothing. Otherwise, skip
3417 DIALECT_NUMBER of strings ending with '|'. */
3418 for (i = 0; i < dialect_number; i++)
3420 while (*p && *p != '}' && *p++ != '|')
3422 if (*p == '}')
3423 break;
3424 if (*p == '|')
3425 p++;
3428 break;
3430 case '|':
3431 /* Skip to close brace. */
3432 while (*p && *p++ != '}')
3434 break;
3436 case '}':
3437 break;
3438 #endif
3440 case '%':
3441 /* %% outputs a single %. */
3442 if (*p == '%')
3444 p++;
3445 putc (c, asm_out_file);
3447 /* %= outputs a number which is unique to each insn in the entire
3448 compilation. This is useful for making local labels that are
3449 referred to more than once in a given insn. */
3450 else if (*p == '=')
3452 p++;
3453 fprintf (asm_out_file, "%d", insn_counter);
3455 /* % followed by a letter and some digits
3456 outputs an operand in a special way depending on the letter.
3457 Letters `acln' are implemented directly.
3458 Other letters are passed to `output_operand' so that
3459 the PRINT_OPERAND macro can define them. */
3460 else if (ISLOWER (*p) || ISUPPER (*p))
3462 int letter = *p++;
3463 c = atoi (p);
3465 if (! (*p >= '0' && *p <= '9'))
3466 output_operand_lossage ("operand number missing after %-letter");
3467 else if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3468 output_operand_lossage ("operand number out of range");
3469 else if (letter == 'l')
3470 output_asm_label (operands[c]);
3471 else if (letter == 'a')
3472 output_address (operands[c]);
3473 else if (letter == 'c')
3475 if (CONSTANT_ADDRESS_P (operands[c]))
3476 output_addr_const (asm_out_file, operands[c]);
3477 else
3478 output_operand (operands[c], 'c');
3480 else if (letter == 'n')
3482 if (GET_CODE (operands[c]) == CONST_INT)
3483 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3484 - INTVAL (operands[c]));
3485 else
3487 putc ('-', asm_out_file);
3488 output_addr_const (asm_out_file, operands[c]);
3491 else
3492 output_operand (operands[c], letter);
3494 while ((c = *p) >= '0' && c <= '9')
3495 p++;
3497 /* % followed by a digit outputs an operand the default way. */
3498 else if (*p >= '0' && *p <= '9')
3500 c = atoi (p);
3501 if (this_is_asm_operands
3502 && (c < 0 || (unsigned int) c >= insn_noperands))
3503 output_operand_lossage ("operand number out of range");
3504 else
3505 output_operand (operands[c], 0);
3506 while ((c = *p) >= '0' && c <= '9')
3507 p++;
3509 /* % followed by punctuation: output something for that
3510 punctuation character alone, with no operand.
3511 The PRINT_OPERAND macro decides what is actually done. */
3512 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3513 else if (PRINT_OPERAND_PUNCT_VALID_P ((unsigned char) *p))
3514 output_operand (NULL_RTX, *p++);
3515 #endif
3516 else
3517 output_operand_lossage ("invalid %%-code");
3518 break;
3520 default:
3521 putc (c, asm_out_file);
3524 output_asm_name ();
3526 putc ('\n', asm_out_file);
3529 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3531 void
3532 output_asm_label (x)
3533 rtx x;
3535 char buf[256];
3537 if (GET_CODE (x) == LABEL_REF)
3538 x = XEXP (x, 0);
3539 if (GET_CODE (x) == CODE_LABEL
3540 || (GET_CODE (x) == NOTE
3541 && NOTE_LINE_NUMBER (x) == NOTE_INSN_DELETED_LABEL))
3542 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3543 else
3544 output_operand_lossage ("`%l' operand isn't a label");
3546 assemble_name (asm_out_file, buf);
3549 /* Print operand X using machine-dependent assembler syntax.
3550 The macro PRINT_OPERAND is defined just to control this function.
3551 CODE is a non-digit that preceded the operand-number in the % spec,
3552 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3553 between the % and the digits.
3554 When CODE is a non-letter, X is 0.
3556 The meanings of the letters are machine-dependent and controlled
3557 by PRINT_OPERAND. */
3559 static void
3560 output_operand (x, code)
3561 rtx x;
3562 int code ATTRIBUTE_UNUSED;
3564 if (x && GET_CODE (x) == SUBREG)
3565 x = alter_subreg (x);
3567 /* If X is a pseudo-register, abort now rather than writing trash to the
3568 assembler file. */
3570 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
3571 abort ();
3573 PRINT_OPERAND (asm_out_file, x, code);
3576 /* Print a memory reference operand for address X
3577 using machine-dependent assembler syntax.
3578 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
3580 void
3581 output_address (x)
3582 rtx x;
3584 walk_alter_subreg (x);
3585 PRINT_OPERAND_ADDRESS (asm_out_file, x);
3588 /* Print an integer constant expression in assembler syntax.
3589 Addition and subtraction are the only arithmetic
3590 that may appear in these expressions. */
3592 void
3593 output_addr_const (file, x)
3594 FILE *file;
3595 rtx x;
3597 char buf[256];
3599 restart:
3600 switch (GET_CODE (x))
3602 case PC:
3603 if (flag_pic)
3604 putc ('.', file);
3605 else
3606 abort ();
3607 break;
3609 case SYMBOL_REF:
3610 #ifdef ASM_OUTPUT_SYMBOL_REF
3611 ASM_OUTPUT_SYMBOL_REF (file, x);
3612 #else
3613 assemble_name (file, XSTR (x, 0));
3614 #endif
3615 break;
3617 case LABEL_REF:
3618 x = XEXP (x, 0);
3619 /* Fall through. */
3620 case CODE_LABEL:
3621 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3622 assemble_name (file, buf);
3623 break;
3625 case CONST_INT:
3626 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3627 break;
3629 case CONST:
3630 /* This used to output parentheses around the expression,
3631 but that does not work on the 386 (either ATT or BSD assembler). */
3632 output_addr_const (file, XEXP (x, 0));
3633 break;
3635 case CONST_DOUBLE:
3636 if (GET_MODE (x) == VOIDmode)
3638 /* We can use %d if the number is one word and positive. */
3639 if (CONST_DOUBLE_HIGH (x))
3640 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3641 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3642 else if (CONST_DOUBLE_LOW (x) < 0)
3643 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3644 else
3645 fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3647 else
3648 /* We can't handle floating point constants;
3649 PRINT_OPERAND must handle them. */
3650 output_operand_lossage ("floating constant misused");
3651 break;
3653 case PLUS:
3654 /* Some assemblers need integer constants to appear last (eg masm). */
3655 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3657 output_addr_const (file, XEXP (x, 1));
3658 if (INTVAL (XEXP (x, 0)) >= 0)
3659 fprintf (file, "+");
3660 output_addr_const (file, XEXP (x, 0));
3662 else
3664 output_addr_const (file, XEXP (x, 0));
3665 if (GET_CODE (XEXP (x, 1)) != CONST_INT
3666 || INTVAL (XEXP (x, 1)) >= 0)
3667 fprintf (file, "+");
3668 output_addr_const (file, XEXP (x, 1));
3670 break;
3672 case MINUS:
3673 /* Avoid outputting things like x-x or x+5-x,
3674 since some assemblers can't handle that. */
3675 x = simplify_subtraction (x);
3676 if (GET_CODE (x) != MINUS)
3677 goto restart;
3679 output_addr_const (file, XEXP (x, 0));
3680 fprintf (file, "-");
3681 if ((GET_CODE (XEXP (x, 1)) == CONST_INT
3682 && INTVAL (XEXP (x, 1)) < 0)
3683 || GET_CODE (XEXP (x, 1)) != CONST_INT)
3685 fprintf (file, "%s", ASM_OPEN_PAREN);
3686 output_addr_const (file, XEXP (x, 1));
3687 fprintf (file, "%s", ASM_CLOSE_PAREN);
3689 else
3690 output_addr_const (file, XEXP (x, 1));
3691 break;
3693 case ZERO_EXTEND:
3694 case SIGN_EXTEND:
3695 output_addr_const (file, XEXP (x, 0));
3696 break;
3698 default:
3699 #ifdef OUTPUT_ADDR_CONST_EXTRA
3700 OUTPUT_ADDR_CONST_EXTRA (file, x, fail);
3701 break;
3703 fail:
3704 #endif
3705 output_operand_lossage ("invalid expression as operand");
3709 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3710 %R prints the value of REGISTER_PREFIX.
3711 %L prints the value of LOCAL_LABEL_PREFIX.
3712 %U prints the value of USER_LABEL_PREFIX.
3713 %I prints the value of IMMEDIATE_PREFIX.
3714 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3715 Also supported are %d, %x, %s, %e, %f, %g and %%.
3717 We handle alternate assembler dialects here, just like output_asm_insn. */
3719 void
3720 asm_fprintf VPARAMS ((FILE *file, const char *p, ...))
3722 #ifndef ANSI_PROTOTYPES
3723 FILE *file;
3724 const char *p;
3725 #endif
3726 va_list argptr;
3727 char buf[10];
3728 char *q, c;
3730 VA_START (argptr, p);
3732 #ifndef ANSI_PROTOTYPES
3733 file = va_arg (argptr, FILE *);
3734 p = va_arg (argptr, const char *);
3735 #endif
3737 buf[0] = '%';
3739 while ((c = *p++))
3740 switch (c)
3742 #ifdef ASSEMBLER_DIALECT
3743 case '{':
3745 int i;
3747 /* If we want the first dialect, do nothing. Otherwise, skip
3748 DIALECT_NUMBER of strings ending with '|'. */
3749 for (i = 0; i < dialect_number; i++)
3751 while (*p && *p++ != '|')
3754 if (*p == '|')
3755 p++;
3758 break;
3760 case '|':
3761 /* Skip to close brace. */
3762 while (*p && *p++ != '}')
3764 break;
3766 case '}':
3767 break;
3768 #endif
3770 case '%':
3771 c = *p++;
3772 q = &buf[1];
3773 while ((c >= '0' && c <= '9') || c == '.')
3775 *q++ = c;
3776 c = *p++;
3778 switch (c)
3780 case '%':
3781 fprintf (file, "%%");
3782 break;
3784 case 'd': case 'i': case 'u':
3785 case 'x': case 'p': case 'X':
3786 case 'o':
3787 *q++ = c;
3788 *q = 0;
3789 fprintf (file, buf, va_arg (argptr, int));
3790 break;
3792 case 'w':
3793 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3794 but we do not check for those cases. It means that the value
3795 is a HOST_WIDE_INT, which may be either `int' or `long'. */
3797 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3798 #else
3799 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3800 *q++ = 'l';
3801 #else
3802 *q++ = 'l';
3803 *q++ = 'l';
3804 #endif
3805 #endif
3807 *q++ = *p++;
3808 *q = 0;
3809 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3810 break;
3812 case 'l':
3813 *q++ = c;
3814 *q++ = *p++;
3815 *q = 0;
3816 fprintf (file, buf, va_arg (argptr, long));
3817 break;
3819 case 'e':
3820 case 'f':
3821 case 'g':
3822 *q++ = c;
3823 *q = 0;
3824 fprintf (file, buf, va_arg (argptr, double));
3825 break;
3827 case 's':
3828 *q++ = c;
3829 *q = 0;
3830 fprintf (file, buf, va_arg (argptr, char *));
3831 break;
3833 case 'O':
3834 #ifdef ASM_OUTPUT_OPCODE
3835 ASM_OUTPUT_OPCODE (asm_out_file, p);
3836 #endif
3837 break;
3839 case 'R':
3840 #ifdef REGISTER_PREFIX
3841 fprintf (file, "%s", REGISTER_PREFIX);
3842 #endif
3843 break;
3845 case 'I':
3846 #ifdef IMMEDIATE_PREFIX
3847 fprintf (file, "%s", IMMEDIATE_PREFIX);
3848 #endif
3849 break;
3851 case 'L':
3852 #ifdef LOCAL_LABEL_PREFIX
3853 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3854 #endif
3855 break;
3857 case 'U':
3858 fputs (user_label_prefix, file);
3859 break;
3861 #ifdef ASM_FPRINTF_EXTENSIONS
3862 /* Upper case letters are reserved for general use by asm_fprintf
3863 and so are not available to target specific code. In order to
3864 prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
3865 they are defined here. As they get turned into real extensions
3866 to asm_fprintf they should be removed from this list. */
3867 case 'A': case 'B': case 'C': case 'D': case 'E':
3868 case 'F': case 'G': case 'H': case 'J': case 'K':
3869 case 'M': case 'N': case 'P': case 'Q': case 'S':
3870 case 'T': case 'V': case 'W': case 'Y': case 'Z':
3871 break;
3873 ASM_FPRINTF_EXTENSIONS (file, argptr, p)
3874 #endif
3875 default:
3876 abort ();
3878 break;
3880 default:
3881 fputc (c, file);
3883 va_end (argptr);
3886 /* Split up a CONST_DOUBLE or integer constant rtx
3887 into two rtx's for single words,
3888 storing in *FIRST the word that comes first in memory in the target
3889 and in *SECOND the other. */
3891 void
3892 split_double (value, first, second)
3893 rtx value;
3894 rtx *first, *second;
3896 if (GET_CODE (value) == CONST_INT)
3898 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3900 /* In this case the CONST_INT holds both target words.
3901 Extract the bits from it into two word-sized pieces.
3902 Sign extend each half to HOST_WIDE_INT. */
3903 unsigned HOST_WIDE_INT low, high;
3904 unsigned HOST_WIDE_INT mask, sign_bit, sign_extend;
3906 /* Set sign_bit to the most significant bit of a word. */
3907 sign_bit = 1;
3908 sign_bit <<= BITS_PER_WORD - 1;
3910 /* Set mask so that all bits of the word are set. We could
3911 have used 1 << BITS_PER_WORD instead of basing the
3912 calculation on sign_bit. However, on machines where
3913 HOST_BITS_PER_WIDE_INT == BITS_PER_WORD, it could cause a
3914 compiler warning, even though the code would never be
3915 executed. */
3916 mask = sign_bit << 1;
3917 mask--;
3919 /* Set sign_extend as any remaining bits. */
3920 sign_extend = ~mask;
3922 /* Pick the lower word and sign-extend it. */
3923 low = INTVAL (value);
3924 low &= mask;
3925 if (low & sign_bit)
3926 low |= sign_extend;
3928 /* Pick the higher word, shifted to the least significant
3929 bits, and sign-extend it. */
3930 high = INTVAL (value);
3931 high >>= BITS_PER_WORD - 1;
3932 high >>= 1;
3933 high &= mask;
3934 if (high & sign_bit)
3935 high |= sign_extend;
3937 /* Store the words in the target machine order. */
3938 if (WORDS_BIG_ENDIAN)
3940 *first = GEN_INT (high);
3941 *second = GEN_INT (low);
3943 else
3945 *first = GEN_INT (low);
3946 *second = GEN_INT (high);
3949 else
3951 /* The rule for using CONST_INT for a wider mode
3952 is that we regard the value as signed.
3953 So sign-extend it. */
3954 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3955 if (WORDS_BIG_ENDIAN)
3957 *first = high;
3958 *second = value;
3960 else
3962 *first = value;
3963 *second = high;
3967 else if (GET_CODE (value) != CONST_DOUBLE)
3969 if (WORDS_BIG_ENDIAN)
3971 *first = const0_rtx;
3972 *second = value;
3974 else
3976 *first = value;
3977 *second = const0_rtx;
3980 else if (GET_MODE (value) == VOIDmode
3981 /* This is the old way we did CONST_DOUBLE integers. */
3982 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3984 /* In an integer, the words are defined as most and least significant.
3985 So order them by the target's convention. */
3986 if (WORDS_BIG_ENDIAN)
3988 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3989 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3991 else
3993 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3994 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3997 else
3999 #ifdef REAL_ARITHMETIC
4000 REAL_VALUE_TYPE r;
4001 long l[2];
4002 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
4004 /* Note, this converts the REAL_VALUE_TYPE to the target's
4005 format, splits up the floating point double and outputs
4006 exactly 32 bits of it into each of l[0] and l[1] --
4007 not necessarily BITS_PER_WORD bits. */
4008 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
4010 /* If 32 bits is an entire word for the target, but not for the host,
4011 then sign-extend on the host so that the number will look the same
4012 way on the host that it would on the target. See for instance
4013 simplify_unary_operation. The #if is needed to avoid compiler
4014 warnings. */
4016 #if HOST_BITS_PER_LONG > 32
4017 if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
4019 if (l[0] & ((long) 1 << 31))
4020 l[0] |= ((long) (-1) << 32);
4021 if (l[1] & ((long) 1 << 31))
4022 l[1] |= ((long) (-1) << 32);
4024 #endif
4026 *first = GEN_INT ((HOST_WIDE_INT) l[0]);
4027 *second = GEN_INT ((HOST_WIDE_INT) l[1]);
4028 #else
4029 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
4030 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
4031 && ! flag_pretend_float)
4032 abort ();
4034 if (
4035 #ifdef HOST_WORDS_BIG_ENDIAN
4036 WORDS_BIG_ENDIAN
4037 #else
4038 ! WORDS_BIG_ENDIAN
4039 #endif
4042 /* Host and target agree => no need to swap. */
4043 *first = GEN_INT (CONST_DOUBLE_LOW (value));
4044 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
4046 else
4048 *second = GEN_INT (CONST_DOUBLE_LOW (value));
4049 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
4051 #endif /* no REAL_ARITHMETIC */
4055 /* Return nonzero if this function has no function calls. */
4058 leaf_function_p ()
4060 rtx insn;
4061 rtx link;
4063 if (profile_flag || profile_block_flag || profile_arc_flag)
4064 return 0;
4066 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4068 if (GET_CODE (insn) == CALL_INSN
4069 && ! SIBLING_CALL_P (insn))
4070 return 0;
4071 if (GET_CODE (insn) == INSN
4072 && GET_CODE (PATTERN (insn)) == SEQUENCE
4073 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4074 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4075 return 0;
4077 for (link = current_function_epilogue_delay_list;
4078 link;
4079 link = XEXP (link, 1))
4081 insn = XEXP (link, 0);
4083 if (GET_CODE (insn) == CALL_INSN
4084 && ! SIBLING_CALL_P (insn))
4085 return 0;
4086 if (GET_CODE (insn) == INSN
4087 && GET_CODE (PATTERN (insn)) == SEQUENCE
4088 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4089 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4090 return 0;
4093 return 1;
4096 /* On some machines, a function with no call insns
4097 can run faster if it doesn't create its own register window.
4098 When output, the leaf function should use only the "output"
4099 registers. Ordinarily, the function would be compiled to use
4100 the "input" registers to find its arguments; it is a candidate
4101 for leaf treatment if it uses only the "input" registers.
4102 Leaf function treatment means renumbering so the function
4103 uses the "output" registers instead. */
4105 #ifdef LEAF_REGISTERS
4107 /* Return 1 if this function uses only the registers that can be
4108 safely renumbered. */
4111 only_leaf_regs_used ()
4113 int i;
4114 char *permitted_reg_in_leaf_functions = LEAF_REGISTERS;
4116 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4117 if ((regs_ever_live[i] || global_regs[i])
4118 && ! permitted_reg_in_leaf_functions[i])
4119 return 0;
4121 if (current_function_uses_pic_offset_table
4122 && pic_offset_table_rtx != 0
4123 && GET_CODE (pic_offset_table_rtx) == REG
4124 && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
4125 return 0;
4127 return 1;
4130 /* Scan all instructions and renumber all registers into those
4131 available in leaf functions. */
4133 static void
4134 leaf_renumber_regs (first)
4135 rtx first;
4137 rtx insn;
4139 /* Renumber only the actual patterns.
4140 The reg-notes can contain frame pointer refs,
4141 and renumbering them could crash, and should not be needed. */
4142 for (insn = first; insn; insn = NEXT_INSN (insn))
4143 if (INSN_P (insn))
4144 leaf_renumber_regs_insn (PATTERN (insn));
4145 for (insn = current_function_epilogue_delay_list;
4146 insn;
4147 insn = XEXP (insn, 1))
4148 if (INSN_P (XEXP (insn, 0)))
4149 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
4152 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
4153 available in leaf functions. */
4155 void
4156 leaf_renumber_regs_insn (in_rtx)
4157 register rtx in_rtx;
4159 register int i, j;
4160 register const char *format_ptr;
4162 if (in_rtx == 0)
4163 return;
4165 /* Renumber all input-registers into output-registers.
4166 renumbered_regs would be 1 for an output-register;
4167 they */
4169 if (GET_CODE (in_rtx) == REG)
4171 int newreg;
4173 /* Don't renumber the same reg twice. */
4174 if (in_rtx->used)
4175 return;
4177 newreg = REGNO (in_rtx);
4178 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
4179 to reach here as part of a REG_NOTE. */
4180 if (newreg >= FIRST_PSEUDO_REGISTER)
4182 in_rtx->used = 1;
4183 return;
4185 newreg = LEAF_REG_REMAP (newreg);
4186 if (newreg < 0)
4187 abort ();
4188 regs_ever_live[REGNO (in_rtx)] = 0;
4189 regs_ever_live[newreg] = 1;
4190 REGNO (in_rtx) = newreg;
4191 in_rtx->used = 1;
4194 if (INSN_P (in_rtx))
4196 /* Inside a SEQUENCE, we find insns.
4197 Renumber just the patterns of these insns,
4198 just as we do for the top-level insns. */
4199 leaf_renumber_regs_insn (PATTERN (in_rtx));
4200 return;
4203 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
4205 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
4206 switch (*format_ptr++)
4208 case 'e':
4209 leaf_renumber_regs_insn (XEXP (in_rtx, i));
4210 break;
4212 case 'E':
4213 if (NULL != XVEC (in_rtx, i))
4215 for (j = 0; j < XVECLEN (in_rtx, i); j++)
4216 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
4218 break;
4220 case 'S':
4221 case 's':
4222 case '0':
4223 case 'i':
4224 case 'w':
4225 case 'n':
4226 case 'u':
4227 break;
4229 default:
4230 abort ();
4233 #endif