2001-07-10 Jan van Male <jan.vanmale@fenk.wau.nl>
[official-gcc.git] / gcc / final.c
blobf257ea940955158cd67f9df19b49cd1ad614366e
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 in assembler by the target functions 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"
68 #include "target.h"
70 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
71 #include "dbxout.h"
72 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
74 #ifdef XCOFF_DEBUGGING_INFO
75 #include "xcoffout.h"
76 #endif
78 #ifdef DWARF_DEBUGGING_INFO
79 #include "dwarfout.h"
80 #endif
82 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
83 #include "dwarf2out.h"
84 #endif
86 #ifdef SDB_DEBUGGING_INFO
87 #include "sdbout.h"
88 #endif
90 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
91 null default for it to save conditionalization later. */
92 #ifndef CC_STATUS_INIT
93 #define CC_STATUS_INIT
94 #endif
96 /* How to start an assembler comment. */
97 #ifndef ASM_COMMENT_START
98 #define ASM_COMMENT_START ";#"
99 #endif
101 /* Is the given character a logical line separator for the assembler? */
102 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
103 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
104 #endif
106 #ifndef JUMP_TABLES_IN_TEXT_SECTION
107 #define JUMP_TABLES_IN_TEXT_SECTION 0
108 #endif
110 /* Last insn processed by final_scan_insn. */
111 static rtx debug_insn;
112 rtx current_output_insn;
114 /* Line number of last NOTE. */
115 static int last_linenum;
117 /* Highest line number in current block. */
118 static int high_block_linenum;
120 /* Likewise for function. */
121 static int high_function_linenum;
123 /* Filename of last NOTE. */
124 static const char *last_filename;
126 /* Number of basic blocks seen so far;
127 used if profile_block_flag is set. */
128 static int count_basic_blocks;
130 /* Number of instrumented arcs when profile_arc_flag is set. */
131 extern int count_instrumented_edges;
133 extern int length_unit_log; /* This is defined in insn-attrtab.c. */
135 /* Nonzero while outputting an `asm' with operands.
136 This means that inconsistencies are the user's fault, so don't abort.
137 The precise value is the insn being output, to pass to error_for_asm. */
138 static rtx this_is_asm_operands;
140 /* Number of operands of this insn, for an `asm' with operands. */
141 static unsigned int insn_noperands;
143 /* Compare optimization flag. */
145 static rtx last_ignored_compare = 0;
147 /* Flag indicating this insn is the start of a new basic block. */
149 static int new_block = 1;
151 /* Assign a unique number to each insn that is output.
152 This can be used to generate unique local labels. */
154 static int insn_counter = 0;
156 #ifdef HAVE_cc0
157 /* This variable contains machine-dependent flags (defined in tm.h)
158 set and examined by output routines
159 that describe how to interpret the condition codes properly. */
161 CC_STATUS cc_status;
163 /* During output of an insn, this contains a copy of cc_status
164 from before the insn. */
166 CC_STATUS cc_prev_status;
167 #endif
169 /* Indexed by hardware reg number, is 1 if that register is ever
170 used in the current function.
172 In life_analysis, or in stupid_life_analysis, this is set
173 up to record the hard regs used explicitly. Reload adds
174 in the hard regs used for holding pseudo regs. Final uses
175 it to generate the code in the function prologue and epilogue
176 to save and restore registers as needed. */
178 char regs_ever_live[FIRST_PSEUDO_REGISTER];
180 /* Nonzero means current function must be given a frame pointer.
181 Set in stmt.c if anything is allocated on the stack there.
182 Set in reload1.c if anything is allocated on the stack there. */
184 int frame_pointer_needed;
186 /* Assign unique numbers to labels generated for profiling. */
188 int profile_label_no;
190 /* Number of unmatched NOTE_INSN_BLOCK_BEG notes we have seen. */
192 static int block_depth;
194 /* Nonzero if have enabled APP processing of our assembler output. */
196 static int app_on;
198 /* If we are outputting an insn sequence, this contains the sequence rtx.
199 Zero otherwise. */
201 rtx final_sequence;
203 #ifdef ASSEMBLER_DIALECT
205 /* Number of the assembler dialect to use, starting at 0. */
206 static int dialect_number;
207 #endif
209 /* Indexed by line number, nonzero if there is a note for that line. */
211 static char *line_note_exists;
213 #ifdef HAVE_conditional_execution
214 /* Nonnull if the insn currently being emitted was a COND_EXEC pattern. */
215 rtx current_insn_predicate;
216 #endif
218 /* Linked list to hold line numbers for each basic block. */
220 struct bb_list
222 struct bb_list *next; /* pointer to next basic block */
223 int line_num; /* line number */
224 int file_label_num; /* LPBC<n> label # for stored filename */
225 int func_label_num; /* LPBC<n> label # for stored function name */
228 static struct bb_list *bb_head = 0; /* Head of basic block list */
229 static struct bb_list **bb_tail = &bb_head; /* Ptr to store next bb ptr */
230 static int bb_file_label_num = -1; /* Current label # for file */
231 static int bb_func_label_num = -1; /* Current label # for func */
233 /* Linked list to hold the strings for each file and function name output. */
235 struct bb_str
237 struct bb_str *next; /* pointer to next string */
238 const char *string; /* string */
239 int label_num; /* label number */
240 int length; /* string length */
243 static struct bb_str *sbb_head = 0; /* Head of string list. */
244 static struct bb_str **sbb_tail = &sbb_head; /* Ptr to store next bb str */
245 static int sbb_label_num = 0; /* Last label used */
247 #ifdef HAVE_ATTR_length
248 static int asm_insn_count PARAMS ((rtx));
249 #endif
250 static void profile_function PARAMS ((FILE *));
251 static void profile_after_prologue PARAMS ((FILE *));
252 static void add_bb PARAMS ((FILE *));
253 static int add_bb_string PARAMS ((const char *, int));
254 static void output_source_line PARAMS ((FILE *, rtx));
255 static rtx walk_alter_subreg PARAMS ((rtx));
256 static void output_asm_name PARAMS ((void));
257 static void output_operand PARAMS ((rtx, int));
258 #ifdef LEAF_REGISTERS
259 static void leaf_renumber_regs PARAMS ((rtx));
260 #endif
261 #ifdef HAVE_cc0
262 static int alter_cond PARAMS ((rtx));
263 #endif
264 #ifndef ADDR_VEC_ALIGN
265 static int final_addr_vec_align PARAMS ((rtx));
266 #endif
267 #ifdef HAVE_ATTR_length
268 static int align_fuzz PARAMS ((rtx, rtx, int, unsigned));
269 #endif
271 /* Initialize data in final at the beginning of a compilation. */
273 void
274 init_final (filename)
275 const char *filename ATTRIBUTE_UNUSED;
277 app_on = 0;
278 final_sequence = 0;
280 #ifdef ASSEMBLER_DIALECT
281 dialect_number = ASSEMBLER_DIALECT;
282 #endif
285 /* Called at end of source file,
286 to output the block-profiling table for this entire compilation. */
288 void
289 end_final (filename)
290 const char *filename;
292 int i;
294 if (profile_block_flag || profile_arc_flag)
296 char name[20];
297 int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
298 int size, rounded;
299 struct bb_list *ptr;
300 struct bb_str *sptr;
301 int long_bytes = LONG_TYPE_SIZE / BITS_PER_UNIT;
302 int gcov_type_bytes = GCOV_TYPE_SIZE / BITS_PER_UNIT;
303 int pointer_bytes = POINTER_SIZE / BITS_PER_UNIT;
305 if (profile_block_flag)
306 size = long_bytes * count_basic_blocks;
307 else
308 size = gcov_type_bytes * count_instrumented_edges;
309 rounded = size;
311 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
312 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
313 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
315 data_section ();
317 /* Output the main header, of 11 words:
318 0: 1 if this file is initialized, else 0.
319 1: address of file name (LPBX1).
320 2: address of table of counts (LPBX2).
321 3: number of counts in the table.
322 4: always 0, for compatibility with Sun.
324 The following are GNU extensions:
326 5: address of table of start addrs of basic blocks (LPBX3).
327 6: Number of bytes in this header.
328 7: address of table of function names (LPBX4).
329 8: address of table of line numbers (LPBX5) or 0.
330 9: address of table of file names (LPBX6) or 0.
331 10: space reserved for basic block profiling. */
333 ASM_OUTPUT_ALIGN (asm_out_file, align);
335 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
336 /* zero word */
337 assemble_integer (const0_rtx, long_bytes, 1);
339 /* address of filename */
340 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
341 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
343 /* address of count table */
344 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
345 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
347 /* count of the # of basic blocks or # of instrumented arcs */
348 if (profile_block_flag)
349 assemble_integer (GEN_INT (count_basic_blocks), long_bytes, 1);
350 else
351 assemble_integer (GEN_INT (count_instrumented_edges), long_bytes, 1);
353 /* zero word (link field) */
354 assemble_integer (const0_rtx, pointer_bytes, 1);
356 /* address of basic block start address table */
357 if (profile_block_flag)
359 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
360 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
363 else
364 assemble_integer (const0_rtx, pointer_bytes, 1);
366 /* byte count for extended structure. */
367 assemble_integer (GEN_INT (11 * UNITS_PER_WORD), long_bytes, 1);
369 /* address of function name table */
370 if (profile_block_flag)
372 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
373 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
376 else
377 assemble_integer (const0_rtx, pointer_bytes, 1);
379 /* address of line number and filename tables if debugging. */
380 if (write_symbols != NO_DEBUG && profile_block_flag)
382 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
383 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
384 pointer_bytes, 1);
385 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
386 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
387 pointer_bytes, 1);
389 else
391 assemble_integer (const0_rtx, pointer_bytes, 1);
392 assemble_integer (const0_rtx, pointer_bytes, 1);
395 /* space for extension ptr (link field) */
396 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
398 /* Output the file name changing the suffix to .d for Sun tcov
399 compatibility. */
400 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
402 char *cwd = getpwd ();
403 int len = strlen (filename) + strlen (cwd) + 1;
404 char *data_file = (char *) alloca (len + 4);
406 strcpy (data_file, cwd);
407 strcat (data_file, "/");
408 strcat (data_file, filename);
409 strip_off_ending (data_file, len);
410 if (profile_block_flag)
411 strcat (data_file, ".d");
412 else
413 strcat (data_file, ".da");
414 assemble_string (data_file, strlen (data_file) + 1);
417 /* Make space for the table of counts. */
418 if (size == 0)
420 /* Realign data section. */
421 ASM_OUTPUT_ALIGN (asm_out_file, align);
422 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
423 if (size != 0)
424 assemble_zeros (size);
426 else
428 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
429 #ifdef ASM_OUTPUT_SHARED_LOCAL
430 if (flag_shared_data)
431 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
432 else
433 #endif
434 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
435 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name,
436 size, BIGGEST_ALIGNMENT);
437 #else
438 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
439 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
440 BIGGEST_ALIGNMENT);
441 #else
442 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
443 #endif
444 #endif
447 /* Output any basic block strings */
448 if (profile_block_flag)
450 readonly_data_section ();
451 if (sbb_head)
453 ASM_OUTPUT_ALIGN (asm_out_file, align);
454 for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
456 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC",
457 sptr->label_num);
458 assemble_string (sptr->string, sptr->length);
463 /* Output the table of addresses. */
464 if (profile_block_flag)
466 /* Realign in new section */
467 ASM_OUTPUT_ALIGN (asm_out_file, align);
468 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
469 for (i = 0; i < count_basic_blocks; i++)
471 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
472 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
473 pointer_bytes, 1);
477 /* Output the table of function names. */
478 if (profile_block_flag)
480 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
481 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
483 if (ptr->func_label_num >= 0)
485 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
486 ptr->func_label_num);
487 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
488 pointer_bytes, 1);
490 else
491 assemble_integer (const0_rtx, pointer_bytes, 1);
494 for (; i < count_basic_blocks; i++)
495 assemble_integer (const0_rtx, pointer_bytes, 1);
498 if (write_symbols != NO_DEBUG && profile_block_flag)
500 /* Output the table of line numbers. */
501 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
502 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
503 assemble_integer (GEN_INT (ptr->line_num), long_bytes, 1);
505 for (; i < count_basic_blocks; i++)
506 assemble_integer (const0_rtx, long_bytes, 1);
508 /* Output the table of file names. */
509 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
510 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
512 if (ptr->file_label_num >= 0)
514 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
515 ptr->file_label_num);
516 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
517 pointer_bytes, 1);
519 else
520 assemble_integer (const0_rtx, pointer_bytes, 1);
523 for (; i < count_basic_blocks; i++)
524 assemble_integer (const0_rtx, pointer_bytes, 1);
527 /* End with the address of the table of addresses,
528 so we can find it easily, as the last word in the file's text. */
529 if (profile_block_flag)
531 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
532 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
538 /* Default target function prologue and epilogue assembler output.
540 If not overridden for epilogue code, then the function body itself
541 contains return instructions wherever needed. */
542 void
543 default_function_pro_epilogue (file, size)
544 FILE *file ATTRIBUTE_UNUSED;
545 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
549 /* Default target hook that outputs nothing to a stream. */
550 void
551 no_asm_to_stream (file)
552 FILE *file ATTRIBUTE_UNUSED;
556 /* Enable APP processing of subsequent output.
557 Used before the output from an `asm' statement. */
559 void
560 app_enable ()
562 if (! app_on)
564 fputs (ASM_APP_ON, asm_out_file);
565 app_on = 1;
569 /* Disable APP processing of subsequent output.
570 Called from varasm.c before most kinds of output. */
572 void
573 app_disable ()
575 if (app_on)
577 fputs (ASM_APP_OFF, asm_out_file);
578 app_on = 0;
582 /* Return the number of slots filled in the current
583 delayed branch sequence (we don't count the insn needing the
584 delay slot). Zero if not in a delayed branch sequence. */
586 #ifdef DELAY_SLOTS
588 dbr_sequence_length ()
590 if (final_sequence != 0)
591 return XVECLEN (final_sequence, 0) - 1;
592 else
593 return 0;
595 #endif
597 /* The next two pages contain routines used to compute the length of an insn
598 and to shorten branches. */
600 /* Arrays for insn lengths, and addresses. The latter is referenced by
601 `insn_current_length'. */
603 static short *insn_lengths;
605 #ifdef HAVE_ATTR_length
606 varray_type insn_addresses_;
607 #endif
609 /* Max uid for which the above arrays are valid. */
610 static int insn_lengths_max_uid;
612 /* Address of insn being processed. Used by `insn_current_length'. */
613 int insn_current_address;
615 /* Address of insn being processed in previous iteration. */
616 int insn_last_address;
618 /* konwn invariant alignment of insn being processed. */
619 int insn_current_align;
621 /* After shorten_branches, for any insn, uid_align[INSN_UID (insn)]
622 gives the next following alignment insn that increases the known
623 alignment, or NULL_RTX if there is no such insn.
624 For any alignment obtained this way, we can again index uid_align with
625 its uid to obtain the next following align that in turn increases the
626 alignment, till we reach NULL_RTX; the sequence obtained this way
627 for each insn we'll call the alignment chain of this insn in the following
628 comments. */
630 struct label_alignment
632 short alignment;
633 short max_skip;
636 static rtx *uid_align;
637 static int *uid_shuid;
638 static struct label_alignment *label_align;
640 /* Indicate that branch shortening hasn't yet been done. */
642 void
643 init_insn_lengths ()
645 if (label_align)
647 free (label_align);
648 label_align = 0;
650 if (uid_shuid)
652 free (uid_shuid);
653 uid_shuid = 0;
655 if (insn_lengths)
657 free (insn_lengths);
658 insn_lengths = 0;
659 insn_lengths_max_uid = 0;
661 #ifdef HAVE_ATTR_length
662 INSN_ADDRESSES_FREE ();
663 #endif
664 if (uid_align)
666 free (uid_align);
667 uid_align = 0;
671 /* Obtain the current length of an insn. If branch shortening has been done,
672 get its actual length. Otherwise, get its maximum length. */
675 get_attr_length (insn)
676 rtx insn ATTRIBUTE_UNUSED;
678 #ifdef HAVE_ATTR_length
679 rtx body;
680 int i;
681 int length = 0;
683 if (insn_lengths_max_uid > INSN_UID (insn))
684 return insn_lengths[INSN_UID (insn)];
685 else
686 switch (GET_CODE (insn))
688 case NOTE:
689 case BARRIER:
690 case CODE_LABEL:
691 return 0;
693 case CALL_INSN:
694 length = insn_default_length (insn);
695 break;
697 case JUMP_INSN:
698 body = PATTERN (insn);
699 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
701 /* Alignment is machine-dependent and should be handled by
702 ADDR_VEC_ALIGN. */
704 else
705 length = insn_default_length (insn);
706 break;
708 case INSN:
709 body = PATTERN (insn);
710 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
711 return 0;
713 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
714 length = asm_insn_count (body) * insn_default_length (insn);
715 else if (GET_CODE (body) == SEQUENCE)
716 for (i = 0; i < XVECLEN (body, 0); i++)
717 length += get_attr_length (XVECEXP (body, 0, i));
718 else
719 length = insn_default_length (insn);
720 break;
722 default:
723 break;
726 #ifdef ADJUST_INSN_LENGTH
727 ADJUST_INSN_LENGTH (insn, length);
728 #endif
729 return length;
730 #else /* not HAVE_ATTR_length */
731 return 0;
732 #endif /* not HAVE_ATTR_length */
735 /* Code to handle alignment inside shorten_branches. */
737 /* Here is an explanation how the algorithm in align_fuzz can give
738 proper results:
740 Call a sequence of instructions beginning with alignment point X
741 and continuing until the next alignment point `block X'. When `X'
742 is used in an expression, it means the alignment value of the
743 alignment point.
745 Call the distance between the start of the first insn of block X, and
746 the end of the last insn of block X `IX', for the `inner size of X'.
747 This is clearly the sum of the instruction lengths.
749 Likewise with the next alignment-delimited block following X, which we
750 shall call block Y.
752 Call the distance between the start of the first insn of block X, and
753 the start of the first insn of block Y `OX', for the `outer size of X'.
755 The estimated padding is then OX - IX.
757 OX can be safely estimated as
759 if (X >= Y)
760 OX = round_up(IX, Y)
761 else
762 OX = round_up(IX, X) + Y - X
764 Clearly est(IX) >= real(IX), because that only depends on the
765 instruction lengths, and those being overestimated is a given.
767 Clearly round_up(foo, Z) >= round_up(bar, Z) if foo >= bar, so
768 we needn't worry about that when thinking about OX.
770 When X >= Y, the alignment provided by Y adds no uncertainty factor
771 for branch ranges starting before X, so we can just round what we have.
772 But when X < Y, we don't know anything about the, so to speak,
773 `middle bits', so we have to assume the worst when aligning up from an
774 address mod X to one mod Y, which is Y - X. */
776 #ifndef LABEL_ALIGN
777 #define LABEL_ALIGN(LABEL) align_labels_log
778 #endif
780 #ifndef LABEL_ALIGN_MAX_SKIP
781 #define LABEL_ALIGN_MAX_SKIP (align_labels-1)
782 #endif
784 #ifndef LOOP_ALIGN
785 #define LOOP_ALIGN(LABEL) align_loops_log
786 #endif
788 #ifndef LOOP_ALIGN_MAX_SKIP
789 #define LOOP_ALIGN_MAX_SKIP (align_loops-1)
790 #endif
792 #ifndef LABEL_ALIGN_AFTER_BARRIER
793 #define LABEL_ALIGN_AFTER_BARRIER(LABEL) align_jumps_log
794 #endif
796 #ifndef LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP
797 #define LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP (align_jumps-1)
798 #endif
800 #ifndef ADDR_VEC_ALIGN
801 static int
802 final_addr_vec_align (addr_vec)
803 rtx addr_vec;
805 int align = GET_MODE_SIZE (GET_MODE (PATTERN (addr_vec)));
807 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
808 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
809 return exact_log2 (align);
813 #define ADDR_VEC_ALIGN(ADDR_VEC) final_addr_vec_align (ADDR_VEC)
814 #endif
816 #ifndef INSN_LENGTH_ALIGNMENT
817 #define INSN_LENGTH_ALIGNMENT(INSN) length_unit_log
818 #endif
820 #define INSN_SHUID(INSN) (uid_shuid[INSN_UID (INSN)])
822 static int min_labelno, max_labelno;
824 #define LABEL_TO_ALIGNMENT(LABEL) \
825 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].alignment)
827 #define LABEL_TO_MAX_SKIP(LABEL) \
828 (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno].max_skip)
830 /* For the benefit of port specific code do this also as a function. */
833 label_to_alignment (label)
834 rtx label;
836 return LABEL_TO_ALIGNMENT (label);
839 #ifdef HAVE_ATTR_length
840 /* The differences in addresses
841 between a branch and its target might grow or shrink depending on
842 the alignment the start insn of the range (the branch for a forward
843 branch or the label for a backward branch) starts out on; if these
844 differences are used naively, they can even oscillate infinitely.
845 We therefore want to compute a 'worst case' address difference that
846 is independent of the alignment the start insn of the range end
847 up on, and that is at least as large as the actual difference.
848 The function align_fuzz calculates the amount we have to add to the
849 naively computed difference, by traversing the part of the alignment
850 chain of the start insn of the range that is in front of the end insn
851 of the range, and considering for each alignment the maximum amount
852 that it might contribute to a size increase.
854 For casesi tables, we also want to know worst case minimum amounts of
855 address difference, in case a machine description wants to introduce
856 some common offset that is added to all offsets in a table.
857 For this purpose, align_fuzz with a growth argument of 0 comuptes the
858 appropriate adjustment. */
860 /* Compute the maximum delta by which the difference of the addresses of
861 START and END might grow / shrink due to a different address for start
862 which changes the size of alignment insns between START and END.
863 KNOWN_ALIGN_LOG is the alignment known for START.
864 GROWTH should be ~0 if the objective is to compute potential code size
865 increase, and 0 if the objective is to compute potential shrink.
866 The return value is undefined for any other value of GROWTH. */
868 static int
869 align_fuzz (start, end, known_align_log, growth)
870 rtx start, end;
871 int known_align_log;
872 unsigned growth;
874 int uid = INSN_UID (start);
875 rtx align_label;
876 int known_align = 1 << known_align_log;
877 int end_shuid = INSN_SHUID (end);
878 int fuzz = 0;
880 for (align_label = uid_align[uid]; align_label; align_label = uid_align[uid])
882 int align_addr, new_align;
884 uid = INSN_UID (align_label);
885 align_addr = INSN_ADDRESSES (uid) - insn_lengths[uid];
886 if (uid_shuid[uid] > end_shuid)
887 break;
888 known_align_log = LABEL_TO_ALIGNMENT (align_label);
889 new_align = 1 << known_align_log;
890 if (new_align < known_align)
891 continue;
892 fuzz += (-align_addr ^ growth) & (new_align - known_align);
893 known_align = new_align;
895 return fuzz;
898 /* Compute a worst-case reference address of a branch so that it
899 can be safely used in the presence of aligned labels. Since the
900 size of the branch itself is unknown, the size of the branch is
901 not included in the range. I.e. for a forward branch, the reference
902 address is the end address of the branch as known from the previous
903 branch shortening pass, minus a value to account for possible size
904 increase due to alignment. For a backward branch, it is the start
905 address of the branch as known from the current pass, plus a value
906 to account for possible size increase due to alignment.
907 NB.: Therefore, the maximum offset allowed for backward branches needs
908 to exclude the branch size. */
911 insn_current_reference_address (branch)
912 rtx branch;
914 rtx dest, seq;
915 int seq_uid;
917 if (! INSN_ADDRESSES_SET_P ())
918 return 0;
920 seq = NEXT_INSN (PREV_INSN (branch));
921 seq_uid = INSN_UID (seq);
922 if (GET_CODE (branch) != JUMP_INSN)
923 /* This can happen for example on the PA; the objective is to know the
924 offset to address something in front of the start of the function.
925 Thus, we can treat it like a backward branch.
926 We assume here that FUNCTION_BOUNDARY / BITS_PER_UNIT is larger than
927 any alignment we'd encounter, so we skip the call to align_fuzz. */
928 return insn_current_address;
929 dest = JUMP_LABEL (branch);
931 /* BRANCH has no proper alignment chain set, so use SEQ.
932 BRANCH also has no INSN_SHUID. */
933 if (INSN_SHUID (seq) < INSN_SHUID (dest))
935 /* Forward branch. */
936 return (insn_last_address + insn_lengths[seq_uid]
937 - align_fuzz (seq, dest, length_unit_log, ~0));
939 else
941 /* Backward branch. */
942 return (insn_current_address
943 + align_fuzz (dest, seq, length_unit_log, ~0));
946 #endif /* HAVE_ATTR_length */
948 /* Make a pass over all insns and compute their actual lengths by shortening
949 any branches of variable length if possible. */
951 /* Give a default value for the lowest address in a function. */
953 #ifndef FIRST_INSN_ADDRESS
954 #define FIRST_INSN_ADDRESS 0
955 #endif
957 /* shorten_branches might be called multiple times: for example, the SH
958 port splits out-of-range conditional branches in MACHINE_DEPENDENT_REORG.
959 In order to do this, it needs proper length information, which it obtains
960 by calling shorten_branches. This cannot be collapsed with
961 shorten_branches itself into a single pass unless we also want to intergate
962 reorg.c, since the branch splitting exposes new instructions with delay
963 slots. */
965 void
966 shorten_branches (first)
967 rtx first ATTRIBUTE_UNUSED;
969 rtx insn;
970 int max_uid;
971 int i;
972 int max_log;
973 int max_skip;
974 #ifdef HAVE_ATTR_length
975 #define MAX_CODE_ALIGN 16
976 rtx seq;
977 int something_changed = 1;
978 char *varying_length;
979 rtx body;
980 int uid;
981 rtx align_tab[MAX_CODE_ALIGN];
983 #endif
985 /* We must do some computations even when not actually shortening, in
986 order to get the alignment information for the labels. */
988 init_insn_lengths ();
990 /* Compute maximum UID and allocate label_align / uid_shuid. */
991 max_uid = get_max_uid ();
993 max_labelno = max_label_num ();
994 min_labelno = get_first_label_num ();
995 label_align = (struct label_alignment *)
996 xcalloc ((max_labelno - min_labelno + 1), sizeof (struct label_alignment));
998 uid_shuid = (int *) xmalloc (max_uid * sizeof *uid_shuid);
1000 /* Initialize label_align and set up uid_shuid to be strictly
1001 monotonically rising with insn order. */
1002 /* We use max_log here to keep track of the maximum alignment we want to
1003 impose on the next CODE_LABEL (or the current one if we are processing
1004 the CODE_LABEL itself). */
1006 max_log = 0;
1007 max_skip = 0;
1009 for (insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn))
1011 int log;
1013 INSN_SHUID (insn) = i++;
1014 if (INSN_P (insn))
1016 /* reorg might make the first insn of a loop being run once only,
1017 and delete the label in front of it. Then we want to apply
1018 the loop alignment to the new label created by reorg, which
1019 is separated by the former loop start insn from the
1020 NOTE_INSN_LOOP_BEG. */
1022 else if (GET_CODE (insn) == CODE_LABEL)
1024 rtx next;
1026 log = LABEL_ALIGN (insn);
1027 if (max_log < log)
1029 max_log = log;
1030 max_skip = LABEL_ALIGN_MAX_SKIP;
1032 next = NEXT_INSN (insn);
1033 /* ADDR_VECs only take room if read-only data goes into the text
1034 section. */
1035 if (JUMP_TABLES_IN_TEXT_SECTION
1036 #if !defined(READONLY_DATA_SECTION)
1037 || 1
1038 #endif
1040 if (next && GET_CODE (next) == JUMP_INSN)
1042 rtx nextbody = PATTERN (next);
1043 if (GET_CODE (nextbody) == ADDR_VEC
1044 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1046 log = ADDR_VEC_ALIGN (next);
1047 if (max_log < log)
1049 max_log = log;
1050 max_skip = LABEL_ALIGN_MAX_SKIP;
1054 LABEL_TO_ALIGNMENT (insn) = max_log;
1055 LABEL_TO_MAX_SKIP (insn) = max_skip;
1056 max_log = 0;
1057 max_skip = 0;
1059 else if (GET_CODE (insn) == BARRIER)
1061 rtx label;
1063 for (label = insn; label && ! INSN_P (label);
1064 label = NEXT_INSN (label))
1065 if (GET_CODE (label) == CODE_LABEL)
1067 log = LABEL_ALIGN_AFTER_BARRIER (insn);
1068 if (max_log < log)
1070 max_log = log;
1071 max_skip = LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP;
1073 break;
1076 /* Again, we allow NOTE_INSN_LOOP_BEG - INSN - CODE_LABEL
1077 sequences in order to handle reorg output efficiently. */
1078 else if (GET_CODE (insn) == NOTE
1079 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
1081 rtx label;
1082 int nest = 0;
1084 /* Search for the label that starts the loop.
1085 Don't skip past the end of the loop, since that could
1086 lead to putting an alignment where it does not belong.
1087 However, a label after a nested (non-)loop would be OK. */
1088 for (label = insn; label; label = NEXT_INSN (label))
1090 if (GET_CODE (label) == NOTE
1091 && NOTE_LINE_NUMBER (label) == NOTE_INSN_LOOP_BEG)
1092 nest++;
1093 else if (GET_CODE (label) == NOTE
1094 && NOTE_LINE_NUMBER (label) == NOTE_INSN_LOOP_END
1095 && --nest == 0)
1096 break;
1097 else if (GET_CODE (label) == CODE_LABEL)
1099 log = LOOP_ALIGN (label);
1100 if (max_log < log)
1102 max_log = log;
1103 max_skip = LOOP_ALIGN_MAX_SKIP;
1105 break;
1109 else
1110 continue;
1112 #ifdef HAVE_ATTR_length
1114 /* Allocate the rest of the arrays. */
1115 insn_lengths = (short *) xmalloc (max_uid * sizeof (short));
1116 insn_lengths_max_uid = max_uid;
1117 /* Syntax errors can lead to labels being outside of the main insn stream.
1118 Initialize insn_addresses, so that we get reproducible results. */
1119 INSN_ADDRESSES_ALLOC (max_uid);
1121 varying_length = (char *) xcalloc (max_uid, sizeof (char));
1123 /* Initialize uid_align. We scan instructions
1124 from end to start, and keep in align_tab[n] the last seen insn
1125 that does an alignment of at least n+1, i.e. the successor
1126 in the alignment chain for an insn that does / has a known
1127 alignment of n. */
1128 uid_align = (rtx *) xcalloc (max_uid, sizeof *uid_align);
1130 for (i = MAX_CODE_ALIGN; --i >= 0;)
1131 align_tab[i] = NULL_RTX;
1132 seq = get_last_insn ();
1133 for (; seq; seq = PREV_INSN (seq))
1135 int uid = INSN_UID (seq);
1136 int log;
1137 log = (GET_CODE (seq) == CODE_LABEL ? LABEL_TO_ALIGNMENT (seq) : 0);
1138 uid_align[uid] = align_tab[0];
1139 if (log)
1141 /* Found an alignment label. */
1142 uid_align[uid] = align_tab[log];
1143 for (i = log - 1; i >= 0; i--)
1144 align_tab[i] = seq;
1147 #ifdef CASE_VECTOR_SHORTEN_MODE
1148 if (optimize)
1150 /* Look for ADDR_DIFF_VECs, and initialize their minimum and maximum
1151 label fields. */
1153 int min_shuid = INSN_SHUID (get_insns ()) - 1;
1154 int max_shuid = INSN_SHUID (get_last_insn ()) + 1;
1155 int rel;
1157 for (insn = first; insn != 0; insn = NEXT_INSN (insn))
1159 rtx min_lab = NULL_RTX, max_lab = NULL_RTX, pat;
1160 int len, i, min, max, insn_shuid;
1161 int min_align;
1162 addr_diff_vec_flags flags;
1164 if (GET_CODE (insn) != JUMP_INSN
1165 || GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
1166 continue;
1167 pat = PATTERN (insn);
1168 len = XVECLEN (pat, 1);
1169 if (len <= 0)
1170 abort ();
1171 min_align = MAX_CODE_ALIGN;
1172 for (min = max_shuid, max = min_shuid, i = len - 1; i >= 0; i--)
1174 rtx lab = XEXP (XVECEXP (pat, 1, i), 0);
1175 int shuid = INSN_SHUID (lab);
1176 if (shuid < min)
1178 min = shuid;
1179 min_lab = lab;
1181 if (shuid > max)
1183 max = shuid;
1184 max_lab = lab;
1186 if (min_align > LABEL_TO_ALIGNMENT (lab))
1187 min_align = LABEL_TO_ALIGNMENT (lab);
1189 XEXP (pat, 2) = gen_rtx_LABEL_REF (VOIDmode, min_lab);
1190 XEXP (pat, 3) = gen_rtx_LABEL_REF (VOIDmode, max_lab);
1191 insn_shuid = INSN_SHUID (insn);
1192 rel = INSN_SHUID (XEXP (XEXP (pat, 0), 0));
1193 flags.min_align = min_align;
1194 flags.base_after_vec = rel > insn_shuid;
1195 flags.min_after_vec = min > insn_shuid;
1196 flags.max_after_vec = max > insn_shuid;
1197 flags.min_after_base = min > rel;
1198 flags.max_after_base = max > rel;
1199 ADDR_DIFF_VEC_FLAGS (pat) = flags;
1202 #endif /* CASE_VECTOR_SHORTEN_MODE */
1204 /* Compute initial lengths, addresses, and varying flags for each insn. */
1205 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1206 insn != 0;
1207 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
1209 uid = INSN_UID (insn);
1211 insn_lengths[uid] = 0;
1213 if (GET_CODE (insn) == CODE_LABEL)
1215 int log = LABEL_TO_ALIGNMENT (insn);
1216 if (log)
1218 int align = 1 << log;
1219 int new_address = (insn_current_address + align - 1) & -align;
1220 insn_lengths[uid] = new_address - insn_current_address;
1224 INSN_ADDRESSES (uid) = insn_current_address;
1226 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
1227 || GET_CODE (insn) == CODE_LABEL)
1228 continue;
1229 if (INSN_DELETED_P (insn))
1230 continue;
1232 body = PATTERN (insn);
1233 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1235 /* This only takes room if read-only data goes into the text
1236 section. */
1237 if (JUMP_TABLES_IN_TEXT_SECTION
1238 #if !defined(READONLY_DATA_SECTION)
1239 || 1
1240 #endif
1242 insn_lengths[uid] = (XVECLEN (body,
1243 GET_CODE (body) == ADDR_DIFF_VEC)
1244 * GET_MODE_SIZE (GET_MODE (body)));
1245 /* Alignment is handled by ADDR_VEC_ALIGN. */
1247 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
1248 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
1249 else if (GET_CODE (body) == SEQUENCE)
1251 int i;
1252 int const_delay_slots;
1253 #ifdef DELAY_SLOTS
1254 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
1255 #else
1256 const_delay_slots = 0;
1257 #endif
1258 /* Inside a delay slot sequence, we do not do any branch shortening
1259 if the shortening could change the number of delay slots
1260 of the branch. */
1261 for (i = 0; i < XVECLEN (body, 0); i++)
1263 rtx inner_insn = XVECEXP (body, 0, i);
1264 int inner_uid = INSN_UID (inner_insn);
1265 int inner_length;
1267 if (GET_CODE (body) == ASM_INPUT
1268 || asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
1269 inner_length = (asm_insn_count (PATTERN (inner_insn))
1270 * insn_default_length (inner_insn));
1271 else
1272 inner_length = insn_default_length (inner_insn);
1274 insn_lengths[inner_uid] = inner_length;
1275 if (const_delay_slots)
1277 if ((varying_length[inner_uid]
1278 = insn_variable_length_p (inner_insn)) != 0)
1279 varying_length[uid] = 1;
1280 INSN_ADDRESSES (inner_uid) = (insn_current_address
1281 + insn_lengths[uid]);
1283 else
1284 varying_length[inner_uid] = 0;
1285 insn_lengths[uid] += inner_length;
1288 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
1290 insn_lengths[uid] = insn_default_length (insn);
1291 varying_length[uid] = insn_variable_length_p (insn);
1294 /* If needed, do any adjustment. */
1295 #ifdef ADJUST_INSN_LENGTH
1296 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
1297 if (insn_lengths[uid] < 0)
1298 fatal_insn ("Negative insn length", insn);
1299 #endif
1302 /* Now loop over all the insns finding varying length insns. For each,
1303 get the current insn length. If it has changed, reflect the change.
1304 When nothing changes for a full pass, we are done. */
1306 while (something_changed)
1308 something_changed = 0;
1309 insn_current_align = MAX_CODE_ALIGN - 1;
1310 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
1311 insn != 0;
1312 insn = NEXT_INSN (insn))
1314 int new_length;
1315 #ifdef ADJUST_INSN_LENGTH
1316 int tmp_length;
1317 #endif
1318 int length_align;
1320 uid = INSN_UID (insn);
1322 if (GET_CODE (insn) == CODE_LABEL)
1324 int log = LABEL_TO_ALIGNMENT (insn);
1325 if (log > insn_current_align)
1327 int align = 1 << log;
1328 int new_address= (insn_current_address + align - 1) & -align;
1329 insn_lengths[uid] = new_address - insn_current_address;
1330 insn_current_align = log;
1331 insn_current_address = new_address;
1333 else
1334 insn_lengths[uid] = 0;
1335 INSN_ADDRESSES (uid) = insn_current_address;
1336 continue;
1339 length_align = INSN_LENGTH_ALIGNMENT (insn);
1340 if (length_align < insn_current_align)
1341 insn_current_align = length_align;
1343 insn_last_address = INSN_ADDRESSES (uid);
1344 INSN_ADDRESSES (uid) = insn_current_address;
1346 #ifdef CASE_VECTOR_SHORTEN_MODE
1347 if (optimize && GET_CODE (insn) == JUMP_INSN
1348 && GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
1350 rtx body = PATTERN (insn);
1351 int old_length = insn_lengths[uid];
1352 rtx rel_lab = XEXP (XEXP (body, 0), 0);
1353 rtx min_lab = XEXP (XEXP (body, 2), 0);
1354 rtx max_lab = XEXP (XEXP (body, 3), 0);
1355 addr_diff_vec_flags flags = ADDR_DIFF_VEC_FLAGS (body);
1356 int rel_addr = INSN_ADDRESSES (INSN_UID (rel_lab));
1357 int min_addr = INSN_ADDRESSES (INSN_UID (min_lab));
1358 int max_addr = INSN_ADDRESSES (INSN_UID (max_lab));
1359 rtx prev;
1360 int rel_align = 0;
1362 /* Try to find a known alignment for rel_lab. */
1363 for (prev = rel_lab;
1364 prev
1365 && ! insn_lengths[INSN_UID (prev)]
1366 && ! (varying_length[INSN_UID (prev)] & 1);
1367 prev = PREV_INSN (prev))
1368 if (varying_length[INSN_UID (prev)] & 2)
1370 rel_align = LABEL_TO_ALIGNMENT (prev);
1371 break;
1374 /* See the comment on addr_diff_vec_flags in rtl.h for the
1375 meaning of the flags values. base: REL_LAB vec: INSN */
1376 /* Anything after INSN has still addresses from the last
1377 pass; adjust these so that they reflect our current
1378 estimate for this pass. */
1379 if (flags.base_after_vec)
1380 rel_addr += insn_current_address - insn_last_address;
1381 if (flags.min_after_vec)
1382 min_addr += insn_current_address - insn_last_address;
1383 if (flags.max_after_vec)
1384 max_addr += insn_current_address - insn_last_address;
1385 /* We want to know the worst case, i.e. lowest possible value
1386 for the offset of MIN_LAB. If MIN_LAB is after REL_LAB,
1387 its offset is positive, and we have to be wary of code shrink;
1388 otherwise, it is negative, and we have to be vary of code
1389 size increase. */
1390 if (flags.min_after_base)
1392 /* If INSN is between REL_LAB and MIN_LAB, the size
1393 changes we are about to make can change the alignment
1394 within the observed offset, therefore we have to break
1395 it up into two parts that are independent. */
1396 if (! flags.base_after_vec && flags.min_after_vec)
1398 min_addr -= align_fuzz (rel_lab, insn, rel_align, 0);
1399 min_addr -= align_fuzz (insn, min_lab, 0, 0);
1401 else
1402 min_addr -= align_fuzz (rel_lab, min_lab, rel_align, 0);
1404 else
1406 if (flags.base_after_vec && ! flags.min_after_vec)
1408 min_addr -= align_fuzz (min_lab, insn, 0, ~0);
1409 min_addr -= align_fuzz (insn, rel_lab, 0, ~0);
1411 else
1412 min_addr -= align_fuzz (min_lab, rel_lab, 0, ~0);
1414 /* Likewise, determine the highest lowest possible value
1415 for the offset of MAX_LAB. */
1416 if (flags.max_after_base)
1418 if (! flags.base_after_vec && flags.max_after_vec)
1420 max_addr += align_fuzz (rel_lab, insn, rel_align, ~0);
1421 max_addr += align_fuzz (insn, max_lab, 0, ~0);
1423 else
1424 max_addr += align_fuzz (rel_lab, max_lab, rel_align, ~0);
1426 else
1428 if (flags.base_after_vec && ! flags.max_after_vec)
1430 max_addr += align_fuzz (max_lab, insn, 0, 0);
1431 max_addr += align_fuzz (insn, rel_lab, 0, 0);
1433 else
1434 max_addr += align_fuzz (max_lab, rel_lab, 0, 0);
1436 PUT_MODE (body, CASE_VECTOR_SHORTEN_MODE (min_addr - rel_addr,
1437 max_addr - rel_addr,
1438 body));
1439 if (JUMP_TABLES_IN_TEXT_SECTION
1440 #if !defined(READONLY_DATA_SECTION)
1441 || 1
1442 #endif
1445 insn_lengths[uid]
1446 = (XVECLEN (body, 1) * GET_MODE_SIZE (GET_MODE (body)));
1447 insn_current_address += insn_lengths[uid];
1448 if (insn_lengths[uid] != old_length)
1449 something_changed = 1;
1452 continue;
1454 #endif /* CASE_VECTOR_SHORTEN_MODE */
1456 if (! (varying_length[uid]))
1458 insn_current_address += insn_lengths[uid];
1459 continue;
1461 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
1463 int i;
1465 body = PATTERN (insn);
1466 new_length = 0;
1467 for (i = 0; i < XVECLEN (body, 0); i++)
1469 rtx inner_insn = XVECEXP (body, 0, i);
1470 int inner_uid = INSN_UID (inner_insn);
1471 int inner_length;
1473 INSN_ADDRESSES (inner_uid) = insn_current_address;
1475 /* insn_current_length returns 0 for insns with a
1476 non-varying length. */
1477 if (! varying_length[inner_uid])
1478 inner_length = insn_lengths[inner_uid];
1479 else
1480 inner_length = insn_current_length (inner_insn);
1482 if (inner_length != insn_lengths[inner_uid])
1484 insn_lengths[inner_uid] = inner_length;
1485 something_changed = 1;
1487 insn_current_address += insn_lengths[inner_uid];
1488 new_length += inner_length;
1491 else
1493 new_length = insn_current_length (insn);
1494 insn_current_address += new_length;
1497 #ifdef ADJUST_INSN_LENGTH
1498 /* If needed, do any adjustment. */
1499 tmp_length = new_length;
1500 ADJUST_INSN_LENGTH (insn, new_length);
1501 insn_current_address += (new_length - tmp_length);
1502 #endif
1504 if (new_length != insn_lengths[uid])
1506 insn_lengths[uid] = new_length;
1507 something_changed = 1;
1510 /* For a non-optimizing compile, do only a single pass. */
1511 if (!optimize)
1512 break;
1515 free (varying_length);
1517 #endif /* HAVE_ATTR_length */
1520 #ifdef HAVE_ATTR_length
1521 /* Given the body of an INSN known to be generated by an ASM statement, return
1522 the number of machine instructions likely to be generated for this insn.
1523 This is used to compute its length. */
1525 static int
1526 asm_insn_count (body)
1527 rtx body;
1529 const char *template;
1530 int count = 1;
1532 if (GET_CODE (body) == ASM_INPUT)
1533 template = XSTR (body, 0);
1534 else
1535 template = decode_asm_operands (body, NULL, NULL, NULL, NULL);
1537 for (; *template; template++)
1538 if (IS_ASM_LOGICAL_LINE_SEPARATOR (*template) || *template == '\n')
1539 count++;
1541 return count;
1543 #endif
1545 /* Output assembler code for the start of a function,
1546 and initialize some of the variables in this file
1547 for the new function. The label for the function and associated
1548 assembler pseudo-ops have already been output in `assemble_start_function'.
1550 FIRST is the first insn of the rtl for the function being compiled.
1551 FILE is the file to write assembler code to.
1552 OPTIMIZE is nonzero if we should eliminate redundant
1553 test and compare insns. */
1555 void
1556 final_start_function (first, file, optimize)
1557 rtx first;
1558 FILE *file;
1559 int optimize ATTRIBUTE_UNUSED;
1561 block_depth = 0;
1563 this_is_asm_operands = 0;
1565 #ifdef NON_SAVING_SETJMP
1566 /* A function that calls setjmp should save and restore all the
1567 call-saved registers on a system where longjmp clobbers them. */
1568 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
1570 int i;
1572 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1573 if (!call_used_regs[i])
1574 regs_ever_live[i] = 1;
1576 #endif
1578 /* Initial line number is supposed to be output
1579 before the function's prologue and label
1580 so that the function's address will not appear to be
1581 in the last statement of the preceding function. */
1582 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1583 last_linenum = high_block_linenum = high_function_linenum
1584 = NOTE_LINE_NUMBER (first);
1586 #if defined (DWARF2_UNWIND_INFO) || defined (IA64_UNWIND_INFO) \
1587 || defined (DWARF2_DEBUGGING_INFO)
1588 dwarf2out_begin_prologue ();
1589 #endif
1591 /* For SDB and XCOFF, the function beginning must be marked between
1592 the function label and the prologue. We always need this, even when
1593 -g1 was used. Defer on MIPS systems so that parameter descriptions
1594 follow function entry. */
1595 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
1596 if (write_symbols == SDB_DEBUG)
1597 sdbout_begin_function (last_linenum);
1598 else
1599 #endif
1600 #ifdef XCOFF_DEBUGGING_INFO
1601 if (write_symbols == XCOFF_DEBUG)
1602 xcoffout_begin_function (file, last_linenum);
1603 else
1604 #endif
1605 /* But only output line number for other debug info types if -g2
1606 or better. */
1607 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1608 output_source_line (file, first);
1610 #ifdef LEAF_REG_REMAP
1611 if (current_function_uses_only_leaf_regs)
1612 leaf_renumber_regs (first);
1613 #endif
1615 /* The Sun386i and perhaps other machines don't work right
1616 if the profiling code comes after the prologue. */
1617 #ifdef PROFILE_BEFORE_PROLOGUE
1618 if (profile_flag)
1619 profile_function (file);
1620 #endif /* PROFILE_BEFORE_PROLOGUE */
1622 #if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
1623 if (dwarf2out_do_frame ())
1624 dwarf2out_frame_debug (NULL_RTX);
1625 #endif
1627 /* If debugging, assign block numbers to all of the blocks in this
1628 function. */
1629 if (write_symbols)
1631 number_blocks (current_function_decl);
1632 remove_unnecessary_notes ();
1633 /* We never actually put out begin/end notes for the top-level
1634 block in the function. But, conceptually, that block is
1635 always needed. */
1636 TREE_ASM_WRITTEN (DECL_INITIAL (current_function_decl)) = 1;
1639 /* First output the function prologue: code to set up the stack frame. */
1640 (*targetm.asm_out.function_prologue) (file, get_frame_size ());
1642 /* If the machine represents the prologue as RTL, the profiling code must
1643 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
1644 #ifdef HAVE_prologue
1645 if (! HAVE_prologue)
1646 #endif
1647 profile_after_prologue (file);
1649 profile_label_no++;
1651 /* If we are doing basic block profiling, remember a printable version
1652 of the function name. */
1653 if (profile_block_flag)
1655 bb_func_label_num =
1656 add_bb_string ((*decl_printable_name) (current_function_decl, 2),
1657 FALSE);
1661 static void
1662 profile_after_prologue (file)
1663 FILE *file ATTRIBUTE_UNUSED;
1665 #ifdef FUNCTION_BLOCK_PROFILER
1666 if (profile_block_flag)
1668 FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
1670 #endif /* FUNCTION_BLOCK_PROFILER */
1672 #ifndef PROFILE_BEFORE_PROLOGUE
1673 if (profile_flag)
1674 profile_function (file);
1675 #endif /* not PROFILE_BEFORE_PROLOGUE */
1678 static void
1679 profile_function (file)
1680 FILE *file;
1682 #ifndef NO_PROFILE_COUNTERS
1683 int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
1684 #endif
1685 #if defined(ASM_OUTPUT_REG_PUSH)
1686 #if defined(STRUCT_VALUE_INCOMING_REGNUM) || defined(STRUCT_VALUE_REGNUM)
1687 int sval = current_function_returns_struct;
1688 #endif
1689 #if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
1690 int cxt = current_function_needs_context;
1691 #endif
1692 #endif /* ASM_OUTPUT_REG_PUSH */
1694 #ifndef NO_PROFILE_COUNTERS
1695 data_section ();
1696 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
1697 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
1698 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, 1);
1699 #endif
1701 function_section (current_function_decl);
1703 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1704 if (sval)
1705 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
1706 #else
1707 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1708 if (sval)
1710 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
1712 #endif
1713 #endif
1715 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1716 if (cxt)
1717 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1718 #else
1719 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1720 if (cxt)
1722 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1724 #endif
1725 #endif
1727 FUNCTION_PROFILER (file, profile_label_no);
1729 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1730 if (cxt)
1731 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1732 #else
1733 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1734 if (cxt)
1736 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1738 #endif
1739 #endif
1741 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1742 if (sval)
1743 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1744 #else
1745 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1746 if (sval)
1748 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1750 #endif
1751 #endif
1754 /* Output assembler code for the end of a function.
1755 For clarity, args are same as those of `final_start_function'
1756 even though not all of them are needed. */
1758 void
1759 final_end_function (first, file, optimize)
1760 rtx first ATTRIBUTE_UNUSED;
1761 FILE *file ATTRIBUTE_UNUSED;
1762 int optimize ATTRIBUTE_UNUSED;
1764 app_disable ();
1766 #ifdef SDB_DEBUGGING_INFO
1767 if (write_symbols == SDB_DEBUG)
1768 sdbout_end_function (high_function_linenum);
1769 #endif
1771 #ifdef DWARF_DEBUGGING_INFO
1772 if (write_symbols == DWARF_DEBUG)
1773 dwarfout_end_function ();
1774 #endif
1776 #ifdef XCOFF_DEBUGGING_INFO
1777 if (write_symbols == XCOFF_DEBUG)
1778 xcoffout_end_function (file, high_function_linenum);
1779 #endif
1781 /* Finally, output the function epilogue:
1782 code to restore the stack frame and return to the caller. */
1783 (*targetm.asm_out.function_epilogue) (file, get_frame_size ());
1785 #ifdef SDB_DEBUGGING_INFO
1786 if (write_symbols == SDB_DEBUG)
1787 sdbout_end_epilogue ();
1788 #endif
1790 #ifdef DWARF_DEBUGGING_INFO
1791 if (write_symbols == DWARF_DEBUG)
1792 dwarfout_end_epilogue ();
1793 #endif
1795 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1796 if (dwarf2out_do_frame ())
1797 dwarf2out_end_epilogue ();
1798 #endif
1800 #ifdef XCOFF_DEBUGGING_INFO
1801 if (write_symbols == XCOFF_DEBUG)
1802 xcoffout_end_epilogue (file);
1803 #endif
1805 bb_func_label_num = -1; /* not in function, nuke label # */
1808 /* Add a block to the linked list that remembers the current line/file/function
1809 for basic block profiling. Emit the label in front of the basic block and
1810 the instructions that increment the count field. */
1812 static void
1813 add_bb (file)
1814 FILE *file;
1816 struct bb_list *ptr =
1817 (struct bb_list *) permalloc (sizeof (struct bb_list));
1819 /* Add basic block to linked list. */
1820 ptr->next = 0;
1821 ptr->line_num = last_linenum;
1822 ptr->file_label_num = bb_file_label_num;
1823 ptr->func_label_num = bb_func_label_num;
1824 *bb_tail = ptr;
1825 bb_tail = &ptr->next;
1827 /* Enable the table of basic-block use counts
1828 to point at the code it applies to. */
1829 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1831 /* Before first insn of this basic block, increment the
1832 count of times it was entered. */
1833 #ifdef BLOCK_PROFILER
1834 BLOCK_PROFILER (file, count_basic_blocks);
1835 #endif
1836 #ifdef HAVE_cc0
1837 CC_STATUS_INIT;
1838 #endif
1840 new_block = 0;
1841 count_basic_blocks++;
1844 /* Add a string to be used for basic block profiling. */
1846 static int
1847 add_bb_string (string, perm_p)
1848 const char *string;
1849 int perm_p;
1851 int len;
1852 struct bb_str *ptr = 0;
1854 if (!string)
1856 string = "<unknown>";
1857 perm_p = TRUE;
1860 /* Allocate a new string if the current string isn't permanent. If
1861 the string is permanent search for the same string in other
1862 allocations. */
1864 len = strlen (string) + 1;
1865 if (!perm_p)
1867 char *p = (char *) permalloc (len);
1868 memcpy (p, string, len);
1869 string = p;
1871 else
1872 for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
1873 if (ptr->string == string)
1874 break;
1876 /* Allocate a new string block if we need to. */
1877 if (!ptr)
1879 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1880 ptr->next = 0;
1881 ptr->length = len;
1882 ptr->label_num = sbb_label_num++;
1883 ptr->string = string;
1884 *sbb_tail = ptr;
1885 sbb_tail = &ptr->next;
1888 return ptr->label_num;
1891 /* Output assembler code for some insns: all or part of a function.
1892 For description of args, see `final_start_function', above.
1894 PRESCAN is 1 if we are not really outputting,
1895 just scanning as if we were outputting.
1896 Prescanning deletes and rearranges insns just like ordinary output.
1897 PRESCAN is -2 if we are outputting after having prescanned.
1898 In this case, don't try to delete or rearrange insns
1899 because that has already been done.
1900 Prescanning is done only on certain machines. */
1902 void
1903 final (first, file, optimize, prescan)
1904 rtx first;
1905 FILE *file;
1906 int optimize;
1907 int prescan;
1909 register rtx insn;
1910 int max_line = 0;
1911 int max_uid = 0;
1913 last_ignored_compare = 0;
1914 new_block = 1;
1916 /* Make a map indicating which line numbers appear in this function.
1917 When producing SDB debugging info, delete troublesome line number
1918 notes from inlined functions in other files as well as duplicate
1919 line number notes. */
1920 #ifdef SDB_DEBUGGING_INFO
1921 if (write_symbols == SDB_DEBUG)
1923 rtx last = 0;
1924 for (insn = first; insn; insn = NEXT_INSN (insn))
1925 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1927 if ((RTX_INTEGRATED_P (insn)
1928 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1929 || (last != 0
1930 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1931 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1933 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1934 NOTE_SOURCE_FILE (insn) = 0;
1935 continue;
1937 last = insn;
1938 if (NOTE_LINE_NUMBER (insn) > max_line)
1939 max_line = NOTE_LINE_NUMBER (insn);
1942 else
1943 #endif
1945 for (insn = first; insn; insn = NEXT_INSN (insn))
1946 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1947 max_line = NOTE_LINE_NUMBER (insn);
1950 line_note_exists = (char *) xcalloc (max_line + 1, sizeof (char));
1952 for (insn = first; insn; insn = NEXT_INSN (insn))
1954 if (INSN_UID (insn) > max_uid) /* find largest UID */
1955 max_uid = INSN_UID (insn);
1956 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1957 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1958 #ifdef HAVE_cc0
1959 /* If CC tracking across branches is enabled, record the insn which
1960 jumps to each branch only reached from one place. */
1961 if (optimize && GET_CODE (insn) == JUMP_INSN)
1963 rtx lab = JUMP_LABEL (insn);
1964 if (lab && LABEL_NUSES (lab) == 1)
1966 LABEL_REFS (lab) = insn;
1969 #endif
1972 init_recog ();
1974 CC_STATUS_INIT;
1976 /* Output the insns. */
1977 for (insn = NEXT_INSN (first); insn;)
1979 #ifdef HAVE_ATTR_length
1980 if (INSN_UID (insn) >= INSN_ADDRESSES_SIZE ())
1982 #ifdef STACK_REGS
1983 /* Irritatingly, the reg-stack pass is creating new instructions
1984 and because of REG_DEAD note abuse it has to run after
1985 shorten_branches. Fake address of -1 then. */
1986 insn_current_address = -1;
1987 #else
1988 /* This can be triggered by bugs elsewhere in the compiler if
1989 new insns are created after init_insn_lengths is called. */
1990 abort ();
1991 #endif
1993 else
1994 insn_current_address = INSN_ADDRESSES (INSN_UID (insn));
1995 #endif /* HAVE_ATTR_length */
1997 insn = final_scan_insn (insn, file, optimize, prescan, 0);
2000 /* Do basic-block profiling here
2001 if the last insn was a conditional branch. */
2002 if (profile_block_flag && new_block)
2003 add_bb (file);
2005 free (line_note_exists);
2006 line_note_exists = NULL;
2009 const char *
2010 get_insn_template (code, insn)
2011 int code;
2012 rtx insn;
2014 const void *output = insn_data[code].output;
2015 switch (insn_data[code].output_format)
2017 case INSN_OUTPUT_FORMAT_SINGLE:
2018 return (const char *) output;
2019 case INSN_OUTPUT_FORMAT_MULTI:
2020 return ((const char *const *) output)[which_alternative];
2021 case INSN_OUTPUT_FORMAT_FUNCTION:
2022 if (insn == NULL)
2023 abort ();
2024 return (*(insn_output_fn) output) (recog_data.operand, insn);
2026 default:
2027 abort ();
2031 /* The final scan for one insn, INSN.
2032 Args are same as in `final', except that INSN
2033 is the insn being scanned.
2034 Value returned is the next insn to be scanned.
2036 NOPEEPHOLES is the flag to disallow peephole processing (currently
2037 used for within delayed branch sequence output). */
2040 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
2041 rtx insn;
2042 FILE *file;
2043 int optimize ATTRIBUTE_UNUSED;
2044 int prescan;
2045 int nopeepholes ATTRIBUTE_UNUSED;
2047 #ifdef HAVE_cc0
2048 rtx set;
2049 #endif
2051 insn_counter++;
2053 /* Ignore deleted insns. These can occur when we split insns (due to a
2054 template of "#") while not optimizing. */
2055 if (INSN_DELETED_P (insn))
2056 return NEXT_INSN (insn);
2058 switch (GET_CODE (insn))
2060 case NOTE:
2061 if (prescan > 0)
2062 break;
2064 switch (NOTE_LINE_NUMBER (insn))
2066 case NOTE_INSN_DELETED:
2067 case NOTE_INSN_LOOP_BEG:
2068 case NOTE_INSN_LOOP_END:
2069 case NOTE_INSN_LOOP_CONT:
2070 case NOTE_INSN_LOOP_VTOP:
2071 case NOTE_INSN_FUNCTION_END:
2072 case NOTE_INSN_SETJMP:
2073 case NOTE_INSN_REPEATED_LINE_NUMBER:
2074 case NOTE_INSN_RANGE_BEG:
2075 case NOTE_INSN_RANGE_END:
2076 case NOTE_INSN_LIVE:
2077 case NOTE_INSN_EXPECTED_VALUE:
2078 break;
2080 case NOTE_INSN_BASIC_BLOCK:
2081 #ifdef IA64_UNWIND_INFO
2082 IA64_UNWIND_EMIT (asm_out_file, insn);
2083 #endif
2084 if (flag_debug_asm)
2085 fprintf (asm_out_file, "\t%s basic block %d\n",
2086 ASM_COMMENT_START, NOTE_BASIC_BLOCK (insn)->index);
2087 break;
2089 case NOTE_INSN_EH_REGION_BEG:
2090 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHB",
2091 NOTE_EH_HANDLER (insn));
2092 break;
2094 case NOTE_INSN_EH_REGION_END:
2095 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHE",
2096 NOTE_EH_HANDLER (insn));
2097 break;
2099 case NOTE_INSN_PROLOGUE_END:
2100 (*targetm.asm_out.function_end_prologue) (file);
2101 profile_after_prologue (file);
2102 break;
2104 case NOTE_INSN_EPILOGUE_BEG:
2105 (*targetm.asm_out.function_begin_epilogue) (file);
2106 break;
2108 case NOTE_INSN_FUNCTION_BEG:
2109 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
2110 /* MIPS stabs require the parameter descriptions to be after the
2111 function entry point rather than before. */
2112 if (write_symbols == SDB_DEBUG)
2114 app_disable ();
2115 sdbout_begin_function (last_linenum);
2117 #endif
2118 #ifdef DWARF_DEBUGGING_INFO
2119 /* This outputs a marker where the function body starts, so it
2120 must be after the prologue. */
2121 if (write_symbols == DWARF_DEBUG)
2123 app_disable ();
2124 dwarfout_begin_function ();
2126 #endif
2127 break;
2129 case NOTE_INSN_BLOCK_BEG:
2130 if (debug_info_level == DINFO_LEVEL_NORMAL
2131 || debug_info_level == DINFO_LEVEL_VERBOSE
2132 || write_symbols == DWARF_DEBUG
2133 || write_symbols == DWARF2_DEBUG)
2135 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2137 app_disable ();
2138 ++block_depth;
2139 high_block_linenum = last_linenum;
2141 /* Output debugging info about the symbol-block beginning. */
2142 #ifdef SDB_DEBUGGING_INFO
2143 if (write_symbols == SDB_DEBUG)
2144 sdbout_begin_block (file, last_linenum, n);
2145 #endif
2146 #ifdef XCOFF_DEBUGGING_INFO
2147 if (write_symbols == XCOFF_DEBUG)
2148 xcoffout_begin_block (file, last_linenum, n);
2149 #endif
2150 #ifdef DBX_DEBUGGING_INFO
2151 if (write_symbols == DBX_DEBUG)
2152 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", n);
2153 #endif
2154 #ifdef DWARF_DEBUGGING_INFO
2155 if (write_symbols == DWARF_DEBUG)
2156 dwarfout_begin_block (n);
2157 #endif
2158 #ifdef DWARF2_DEBUGGING_INFO
2159 if (write_symbols == DWARF2_DEBUG)
2160 dwarf2out_begin_block (n);
2161 #endif
2163 /* Mark this block as output. */
2164 TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
2166 break;
2168 case NOTE_INSN_BLOCK_END:
2169 if (debug_info_level == DINFO_LEVEL_NORMAL
2170 || debug_info_level == DINFO_LEVEL_VERBOSE
2171 || write_symbols == DWARF_DEBUG
2172 || write_symbols == DWARF2_DEBUG)
2174 int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2176 app_disable ();
2178 /* End of a symbol-block. */
2179 --block_depth;
2180 if (block_depth < 0)
2181 abort ();
2183 #ifdef XCOFF_DEBUGGING_INFO
2184 if (write_symbols == XCOFF_DEBUG)
2185 xcoffout_end_block (file, high_block_linenum, n);
2186 #endif
2187 #ifdef DBX_DEBUGGING_INFO
2188 if (write_symbols == DBX_DEBUG)
2189 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE", n);
2190 #endif
2191 #ifdef SDB_DEBUGGING_INFO
2192 if (write_symbols == SDB_DEBUG)
2193 sdbout_end_block (file, high_block_linenum, n);
2194 #endif
2195 #ifdef DWARF_DEBUGGING_INFO
2196 if (write_symbols == DWARF_DEBUG)
2197 dwarfout_end_block (n);
2198 #endif
2199 #ifdef DWARF2_DEBUGGING_INFO
2200 if (write_symbols == DWARF2_DEBUG)
2201 dwarf2out_end_block (n);
2202 #endif
2204 break;
2206 case NOTE_INSN_DELETED_LABEL:
2207 /* Emit the label. We may have deleted the CODE_LABEL because
2208 the label could be proved to be unreachable, though still
2209 referenced (in the form of having its address taken. */
2210 ASM_OUTPUT_DEBUG_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2211 break;
2213 case 0:
2214 break;
2216 default:
2217 if (NOTE_LINE_NUMBER (insn) <= 0)
2218 abort ();
2220 /* This note is a line-number. */
2222 register rtx note;
2223 int note_after = 0;
2225 /* If there is anything real after this note, output it.
2226 If another line note follows, omit this one. */
2227 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
2229 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
2230 break;
2232 /* These types of notes can be significant
2233 so make sure the preceding line number stays. */
2234 else if (GET_CODE (note) == NOTE
2235 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
2236 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
2237 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
2238 break;
2239 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
2241 /* Another line note follows; we can delete this note
2242 if no intervening line numbers have notes elsewhere. */
2243 int num;
2244 for (num = NOTE_LINE_NUMBER (insn) + 1;
2245 num < NOTE_LINE_NUMBER (note);
2246 num++)
2247 if (line_note_exists[num])
2248 break;
2250 if (num >= NOTE_LINE_NUMBER (note))
2251 note_after = 1;
2252 break;
2256 /* Output this line note if it is the first or the last line
2257 note in a row. */
2258 if (!note_after)
2259 output_source_line (file, insn);
2261 break;
2263 break;
2265 case BARRIER:
2266 #if defined (DWARF2_UNWIND_INFO)
2267 if (dwarf2out_do_frame ())
2268 dwarf2out_frame_debug (insn);
2269 #endif
2270 break;
2272 case CODE_LABEL:
2273 /* The target port might emit labels in the output function for
2274 some insn, e.g. sh.c output_branchy_insn. */
2275 if (CODE_LABEL_NUMBER (insn) <= max_labelno)
2277 int align = LABEL_TO_ALIGNMENT (insn);
2278 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2279 int max_skip = LABEL_TO_MAX_SKIP (insn);
2280 #endif
2282 if (align && NEXT_INSN (insn))
2283 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2284 ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
2285 #else
2286 ASM_OUTPUT_ALIGN (file, align);
2287 #endif
2289 #ifdef HAVE_cc0
2290 CC_STATUS_INIT;
2291 /* If this label is reached from only one place, set the condition
2292 codes from the instruction just before the branch. */
2294 /* Disabled because some insns set cc_status in the C output code
2295 and NOTICE_UPDATE_CC alone can set incorrect status. */
2296 if (0 /* optimize && LABEL_NUSES (insn) == 1*/)
2298 rtx jump = LABEL_REFS (insn);
2299 rtx barrier = prev_nonnote_insn (insn);
2300 rtx prev;
2301 /* If the LABEL_REFS field of this label has been set to point
2302 at a branch, the predecessor of the branch is a regular
2303 insn, and that branch is the only way to reach this label,
2304 set the condition codes based on the branch and its
2305 predecessor. */
2306 if (barrier && GET_CODE (barrier) == BARRIER
2307 && jump && GET_CODE (jump) == JUMP_INSN
2308 && (prev = prev_nonnote_insn (jump))
2309 && GET_CODE (prev) == INSN)
2311 NOTICE_UPDATE_CC (PATTERN (prev), prev);
2312 NOTICE_UPDATE_CC (PATTERN (jump), jump);
2315 #endif
2316 if (prescan > 0)
2317 break;
2318 new_block = 1;
2320 #ifdef FINAL_PRESCAN_LABEL
2321 FINAL_PRESCAN_INSN (insn, NULL, 0);
2322 #endif
2324 #ifdef SDB_DEBUGGING_INFO
2325 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
2326 sdbout_label (insn);
2327 #endif
2328 if (app_on)
2330 fputs (ASM_APP_OFF, file);
2331 app_on = 0;
2333 if (NEXT_INSN (insn) != 0
2334 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
2336 rtx nextbody = PATTERN (NEXT_INSN (insn));
2338 /* If this label is followed by a jump-table,
2339 make sure we put the label in the read-only section. Also
2340 possibly write the label and jump table together. */
2342 if (GET_CODE (nextbody) == ADDR_VEC
2343 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
2345 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2346 /* In this case, the case vector is being moved by the
2347 target, so don't output the label at all. Leave that
2348 to the back end macros. */
2349 #else
2350 if (! JUMP_TABLES_IN_TEXT_SECTION)
2352 readonly_data_section ();
2353 #ifdef READONLY_DATA_SECTION
2354 ASM_OUTPUT_ALIGN (file,
2355 exact_log2 (BIGGEST_ALIGNMENT
2356 / BITS_PER_UNIT));
2357 #endif /* READONLY_DATA_SECTION */
2359 else
2360 function_section (current_function_decl);
2362 #ifdef ASM_OUTPUT_CASE_LABEL
2363 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
2364 NEXT_INSN (insn));
2365 #else
2366 if (LABEL_ALTERNATE_NAME (insn))
2367 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2368 else
2369 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2370 #endif
2371 #endif
2372 break;
2375 if (LABEL_ALTERNATE_NAME (insn))
2376 ASM_OUTPUT_ALTERNATE_LABEL_NAME (file, insn);
2377 else
2378 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2379 break;
2381 default:
2383 register rtx body = PATTERN (insn);
2384 int insn_code_number;
2385 const char *template;
2386 #ifdef HAVE_cc0
2387 rtx note;
2388 #endif
2390 /* An INSN, JUMP_INSN or CALL_INSN.
2391 First check for special kinds that recog doesn't recognize. */
2393 if (GET_CODE (body) == USE /* These are just declarations */
2394 || GET_CODE (body) == CLOBBER)
2395 break;
2397 #ifdef HAVE_cc0
2398 /* If there is a REG_CC_SETTER note on this insn, it means that
2399 the setting of the condition code was done in the delay slot
2400 of the insn that branched here. So recover the cc status
2401 from the insn that set it. */
2403 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2404 if (note)
2406 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
2407 cc_prev_status = cc_status;
2409 #endif
2411 /* Detect insns that are really jump-tables
2412 and output them as such. */
2414 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
2416 #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
2417 register int vlen, idx;
2418 #endif
2420 if (prescan > 0)
2421 break;
2423 if (app_on)
2425 fputs (ASM_APP_OFF, file);
2426 app_on = 0;
2429 #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2430 if (GET_CODE (body) == ADDR_VEC)
2432 #ifdef ASM_OUTPUT_ADDR_VEC
2433 ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
2434 #else
2435 abort ();
2436 #endif
2438 else
2440 #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
2441 ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
2442 #else
2443 abort ();
2444 #endif
2446 #else
2447 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2448 for (idx = 0; idx < vlen; idx++)
2450 if (GET_CODE (body) == ADDR_VEC)
2452 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2453 ASM_OUTPUT_ADDR_VEC_ELT
2454 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2455 #else
2456 abort ();
2457 #endif
2459 else
2461 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2462 ASM_OUTPUT_ADDR_DIFF_ELT
2463 (file,
2464 body,
2465 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2466 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2467 #else
2468 abort ();
2469 #endif
2472 #ifdef ASM_OUTPUT_CASE_END
2473 ASM_OUTPUT_CASE_END (file,
2474 CODE_LABEL_NUMBER (PREV_INSN (insn)),
2475 insn);
2476 #endif
2477 #endif
2479 function_section (current_function_decl);
2481 break;
2484 /* Do basic-block profiling when we reach a new block.
2485 Done here to avoid jump tables. */
2486 if (profile_block_flag && new_block)
2487 add_bb (file);
2489 if (GET_CODE (body) == ASM_INPUT)
2491 /* There's no telling what that did to the condition codes. */
2492 CC_STATUS_INIT;
2493 if (prescan > 0)
2494 break;
2495 if (! app_on)
2497 fputs (ASM_APP_ON, file);
2498 app_on = 1;
2500 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
2501 break;
2504 /* Detect `asm' construct with operands. */
2505 if (asm_noperands (body) >= 0)
2507 unsigned int noperands = asm_noperands (body);
2508 rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
2509 const char *string;
2511 /* There's no telling what that did to the condition codes. */
2512 CC_STATUS_INIT;
2513 if (prescan > 0)
2514 break;
2516 if (! app_on)
2518 fputs (ASM_APP_ON, file);
2519 app_on = 1;
2522 /* Get out the operand values. */
2523 string = decode_asm_operands (body, ops, NULL, NULL, NULL);
2524 /* Inhibit aborts on what would otherwise be compiler bugs. */
2525 insn_noperands = noperands;
2526 this_is_asm_operands = insn;
2528 /* Output the insn using them. */
2529 output_asm_insn (string, ops);
2530 this_is_asm_operands = 0;
2531 break;
2534 if (prescan <= 0 && app_on)
2536 fputs (ASM_APP_OFF, file);
2537 app_on = 0;
2540 if (GET_CODE (body) == SEQUENCE)
2542 /* A delayed-branch sequence */
2543 register int i;
2544 rtx next;
2546 if (prescan > 0)
2547 break;
2548 final_sequence = body;
2550 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2551 force the restoration of a comparison that was previously
2552 thought unnecessary. If that happens, cancel this sequence
2553 and cause that insn to be restored. */
2555 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
2556 if (next != XVECEXP (body, 0, 1))
2558 final_sequence = 0;
2559 return next;
2562 for (i = 1; i < XVECLEN (body, 0); i++)
2564 rtx insn = XVECEXP (body, 0, i);
2565 rtx next = NEXT_INSN (insn);
2566 /* We loop in case any instruction in a delay slot gets
2567 split. */
2569 insn = final_scan_insn (insn, file, 0, prescan, 1);
2570 while (insn != next);
2572 #ifdef DBR_OUTPUT_SEQEND
2573 DBR_OUTPUT_SEQEND (file);
2574 #endif
2575 final_sequence = 0;
2577 /* If the insn requiring the delay slot was a CALL_INSN, the
2578 insns in the delay slot are actually executed before the
2579 called function. Hence we don't preserve any CC-setting
2580 actions in these insns and the CC must be marked as being
2581 clobbered by the function. */
2582 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
2584 CC_STATUS_INIT;
2587 /* Following a conditional branch sequence, we have a new basic
2588 block. */
2589 if (profile_block_flag)
2591 rtx insn = XVECEXP (body, 0, 0);
2592 rtx body = PATTERN (insn);
2594 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2595 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2596 || (GET_CODE (insn) == JUMP_INSN
2597 && GET_CODE (body) == PARALLEL
2598 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2599 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
2600 new_block = 1;
2602 break;
2605 /* We have a real machine instruction as rtl. */
2607 body = PATTERN (insn);
2609 #ifdef HAVE_cc0
2610 set = single_set (insn);
2612 /* Check for redundant test and compare instructions
2613 (when the condition codes are already set up as desired).
2614 This is done only when optimizing; if not optimizing,
2615 it should be possible for the user to alter a variable
2616 with the debugger in between statements
2617 and the next statement should reexamine the variable
2618 to compute the condition codes. */
2620 if (optimize)
2622 #if 0
2623 rtx set = single_set (insn);
2624 #endif
2626 if (set
2627 && GET_CODE (SET_DEST (set)) == CC0
2628 && insn != last_ignored_compare)
2630 if (GET_CODE (SET_SRC (set)) == SUBREG)
2631 SET_SRC (set) = alter_subreg (SET_SRC (set));
2632 else if (GET_CODE (SET_SRC (set)) == COMPARE)
2634 if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
2635 XEXP (SET_SRC (set), 0)
2636 = alter_subreg (XEXP (SET_SRC (set), 0));
2637 if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
2638 XEXP (SET_SRC (set), 1)
2639 = alter_subreg (XEXP (SET_SRC (set), 1));
2641 if ((cc_status.value1 != 0
2642 && rtx_equal_p (SET_SRC (set), cc_status.value1))
2643 || (cc_status.value2 != 0
2644 && rtx_equal_p (SET_SRC (set), cc_status.value2)))
2646 /* Don't delete insn if it has an addressing side-effect. */
2647 if (! FIND_REG_INC_NOTE (insn, 0)
2648 /* or if anything in it is volatile. */
2649 && ! volatile_refs_p (PATTERN (insn)))
2651 /* We don't really delete the insn; just ignore it. */
2652 last_ignored_compare = insn;
2653 break;
2658 #endif
2660 /* Following a conditional branch, we have a new basic block.
2661 But if we are inside a sequence, the new block starts after the
2662 last insn of the sequence. */
2663 if (profile_block_flag && final_sequence == 0
2664 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
2665 && GET_CODE (SET_SRC (body)) != LABEL_REF)
2666 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
2667 && GET_CODE (XVECEXP (body, 0, 0)) == SET
2668 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
2669 new_block = 1;
2671 #ifndef STACK_REGS
2672 /* Don't bother outputting obvious no-ops, even without -O.
2673 This optimization is fast and doesn't interfere with debugging.
2674 Don't do this if the insn is in a delay slot, since this
2675 will cause an improper number of delay insns to be written. */
2676 if (final_sequence == 0
2677 && prescan >= 0
2678 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
2679 && GET_CODE (SET_SRC (body)) == REG
2680 && GET_CODE (SET_DEST (body)) == REG
2681 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
2682 break;
2683 #endif
2685 #ifdef HAVE_cc0
2686 /* If this is a conditional branch, maybe modify it
2687 if the cc's are in a nonstandard state
2688 so that it accomplishes the same thing that it would
2689 do straightforwardly if the cc's were set up normally. */
2691 if (cc_status.flags != 0
2692 && GET_CODE (insn) == JUMP_INSN
2693 && GET_CODE (body) == SET
2694 && SET_DEST (body) == pc_rtx
2695 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2696 && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
2697 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
2698 /* This is done during prescan; it is not done again
2699 in final scan when prescan has been done. */
2700 && prescan >= 0)
2702 /* This function may alter the contents of its argument
2703 and clear some of the cc_status.flags bits.
2704 It may also return 1 meaning condition now always true
2705 or -1 meaning condition now always false
2706 or 2 meaning condition nontrivial but altered. */
2707 register int result = alter_cond (XEXP (SET_SRC (body), 0));
2708 /* If condition now has fixed value, replace the IF_THEN_ELSE
2709 with its then-operand or its else-operand. */
2710 if (result == 1)
2711 SET_SRC (body) = XEXP (SET_SRC (body), 1);
2712 if (result == -1)
2713 SET_SRC (body) = XEXP (SET_SRC (body), 2);
2715 /* The jump is now either unconditional or a no-op.
2716 If it has become a no-op, don't try to output it.
2717 (It would not be recognized.) */
2718 if (SET_SRC (body) == pc_rtx)
2720 PUT_CODE (insn, NOTE);
2721 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2722 NOTE_SOURCE_FILE (insn) = 0;
2723 break;
2725 else if (GET_CODE (SET_SRC (body)) == RETURN)
2726 /* Replace (set (pc) (return)) with (return). */
2727 PATTERN (insn) = body = SET_SRC (body);
2729 /* Rerecognize the instruction if it has changed. */
2730 if (result != 0)
2731 INSN_CODE (insn) = -1;
2734 /* Make same adjustments to instructions that examine the
2735 condition codes without jumping and instructions that
2736 handle conditional moves (if this machine has either one). */
2738 if (cc_status.flags != 0
2739 && set != 0)
2741 rtx cond_rtx, then_rtx, else_rtx;
2743 if (GET_CODE (insn) != JUMP_INSN
2744 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2746 cond_rtx = XEXP (SET_SRC (set), 0);
2747 then_rtx = XEXP (SET_SRC (set), 1);
2748 else_rtx = XEXP (SET_SRC (set), 2);
2750 else
2752 cond_rtx = SET_SRC (set);
2753 then_rtx = const_true_rtx;
2754 else_rtx = const0_rtx;
2757 switch (GET_CODE (cond_rtx))
2759 case GTU:
2760 case GT:
2761 case LTU:
2762 case LT:
2763 case GEU:
2764 case GE:
2765 case LEU:
2766 case LE:
2767 case EQ:
2768 case NE:
2770 register int result;
2771 if (XEXP (cond_rtx, 0) != cc0_rtx)
2772 break;
2773 result = alter_cond (cond_rtx);
2774 if (result == 1)
2775 validate_change (insn, &SET_SRC (set), then_rtx, 0);
2776 else if (result == -1)
2777 validate_change (insn, &SET_SRC (set), else_rtx, 0);
2778 else if (result == 2)
2779 INSN_CODE (insn) = -1;
2780 if (SET_DEST (set) == SET_SRC (set))
2782 PUT_CODE (insn, NOTE);
2783 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2784 NOTE_SOURCE_FILE (insn) = 0;
2787 break;
2789 default:
2790 break;
2794 #endif
2796 #ifdef HAVE_peephole
2797 /* Do machine-specific peephole optimizations if desired. */
2799 if (optimize && !flag_no_peephole && !nopeepholes)
2801 rtx next = peephole (insn);
2802 /* When peepholing, if there were notes within the peephole,
2803 emit them before the peephole. */
2804 if (next != 0 && next != NEXT_INSN (insn))
2806 rtx prev = PREV_INSN (insn);
2807 rtx note;
2809 for (note = NEXT_INSN (insn); note != next;
2810 note = NEXT_INSN (note))
2811 final_scan_insn (note, file, optimize, prescan, nopeepholes);
2813 /* In case this is prescan, put the notes
2814 in proper position for later rescan. */
2815 note = NEXT_INSN (insn);
2816 PREV_INSN (note) = prev;
2817 NEXT_INSN (prev) = note;
2818 NEXT_INSN (PREV_INSN (next)) = insn;
2819 PREV_INSN (insn) = PREV_INSN (next);
2820 NEXT_INSN (insn) = next;
2821 PREV_INSN (next) = insn;
2824 /* PEEPHOLE might have changed this. */
2825 body = PATTERN (insn);
2827 #endif
2829 /* Try to recognize the instruction.
2830 If successful, verify that the operands satisfy the
2831 constraints for the instruction. Crash if they don't,
2832 since `reload' should have changed them so that they do. */
2834 insn_code_number = recog_memoized (insn);
2835 cleanup_subreg_operands (insn);
2837 /* Dump the insn in the assembly for debugging. */
2838 if (flag_dump_rtl_in_asm)
2840 print_rtx_head = ASM_COMMENT_START;
2841 print_rtl_single (asm_out_file, insn);
2842 print_rtx_head = "";
2845 if (! constrain_operands_cached (1))
2846 fatal_insn_not_found (insn);
2848 /* Some target machines need to prescan each insn before
2849 it is output. */
2851 #ifdef FINAL_PRESCAN_INSN
2852 FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2853 #endif
2855 #ifdef HAVE_conditional_execution
2856 if (GET_CODE (PATTERN (insn)) == COND_EXEC)
2857 current_insn_predicate = COND_EXEC_TEST (PATTERN (insn));
2858 else
2859 current_insn_predicate = NULL_RTX;
2860 #endif
2862 #ifdef HAVE_cc0
2863 cc_prev_status = cc_status;
2865 /* Update `cc_status' for this instruction.
2866 The instruction's output routine may change it further.
2867 If the output routine for a jump insn needs to depend
2868 on the cc status, it should look at cc_prev_status. */
2870 NOTICE_UPDATE_CC (body, insn);
2871 #endif
2873 current_output_insn = debug_insn = insn;
2875 #if defined (DWARF2_UNWIND_INFO)
2876 if (GET_CODE (insn) == CALL_INSN && dwarf2out_do_frame ())
2877 dwarf2out_frame_debug (insn);
2878 #endif
2880 /* Find the proper template for this insn. */
2881 template = get_insn_template (insn_code_number, insn);
2883 /* If the C code returns 0, it means that it is a jump insn
2884 which follows a deleted test insn, and that test insn
2885 needs to be reinserted. */
2886 if (template == 0)
2888 rtx prev;
2890 if (prev_nonnote_insn (insn) != last_ignored_compare)
2891 abort ();
2892 new_block = 0;
2894 /* We have already processed the notes between the setter and
2895 the user. Make sure we don't process them again, this is
2896 particularly important if one of the notes is a block
2897 scope note or an EH note. */
2898 for (prev = insn;
2899 prev != last_ignored_compare;
2900 prev = PREV_INSN (prev))
2902 if (GET_CODE (prev) == NOTE)
2904 NOTE_LINE_NUMBER (prev) = NOTE_INSN_DELETED;
2905 NOTE_SOURCE_FILE (prev) = 0;
2909 return prev;
2912 /* If the template is the string "#", it means that this insn must
2913 be split. */
2914 if (template[0] == '#' && template[1] == '\0')
2916 rtx new = try_split (body, insn, 0);
2918 /* If we didn't split the insn, go away. */
2919 if (new == insn && PATTERN (new) == body)
2920 fatal_insn ("Could not split insn", insn);
2922 #ifdef HAVE_ATTR_length
2923 /* This instruction should have been split in shorten_branches,
2924 to ensure that we would have valid length info for the
2925 splitees. */
2926 abort ();
2927 #endif
2929 new_block = 0;
2930 return new;
2933 if (prescan > 0)
2934 break;
2936 #ifdef IA64_UNWIND_INFO
2937 IA64_UNWIND_EMIT (asm_out_file, insn);
2938 #endif
2939 /* Output assembler code from the template. */
2941 output_asm_insn (template, recog_data.operand);
2943 #if defined (DWARF2_UNWIND_INFO)
2944 #if defined (HAVE_prologue)
2945 if (GET_CODE (insn) == INSN && dwarf2out_do_frame ())
2946 dwarf2out_frame_debug (insn);
2947 #else
2948 if (!ACCUMULATE_OUTGOING_ARGS
2949 && GET_CODE (insn) == INSN
2950 && dwarf2out_do_frame ())
2951 dwarf2out_frame_debug (insn);
2952 #endif
2953 #endif
2955 #if 0
2956 /* It's not at all clear why we did this and doing so interferes
2957 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2958 with this out. */
2960 /* Mark this insn as having been output. */
2961 INSN_DELETED_P (insn) = 1;
2962 #endif
2964 current_output_insn = debug_insn = 0;
2967 return NEXT_INSN (insn);
2970 /* Output debugging info to the assembler file FILE
2971 based on the NOTE-insn INSN, assumed to be a line number. */
2973 static void
2974 output_source_line (file, insn)
2975 FILE *file ATTRIBUTE_UNUSED;
2976 rtx insn;
2978 register const char *filename = NOTE_SOURCE_FILE (insn);
2980 /* Remember filename for basic block profiling.
2981 Filenames are allocated on the permanent obstack
2982 or are passed in ARGV, so we don't have to save
2983 the string. */
2985 if (profile_block_flag && last_filename != filename)
2986 bb_file_label_num = add_bb_string (filename, TRUE);
2988 last_filename = filename;
2989 last_linenum = NOTE_LINE_NUMBER (insn);
2990 high_block_linenum = MAX (last_linenum, high_block_linenum);
2991 high_function_linenum = MAX (last_linenum, high_function_linenum);
2993 if (write_symbols != NO_DEBUG)
2995 #ifdef SDB_DEBUGGING_INFO
2996 if (write_symbols == SDB_DEBUG
2997 #if 0 /* People like having line numbers even in wrong file! */
2998 /* COFF can't handle multiple source files--lose, lose. */
2999 && !strcmp (filename, main_input_filename)
3000 #endif
3001 /* COFF relative line numbers must be positive. */
3002 && last_linenum > sdb_begin_function_line)
3004 #ifdef ASM_OUTPUT_SOURCE_LINE
3005 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
3006 #else
3007 fprintf (file, "\t.ln\t%d\n",
3008 ((sdb_begin_function_line > -1)
3009 ? last_linenum - sdb_begin_function_line : 1));
3010 #endif
3012 #endif
3014 #if defined (DBX_DEBUGGING_INFO)
3015 if (write_symbols == DBX_DEBUG)
3016 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
3017 #endif
3019 #if defined (XCOFF_DEBUGGING_INFO)
3020 if (write_symbols == XCOFF_DEBUG)
3021 xcoffout_source_line (file, filename, insn);
3022 #endif
3024 #ifdef DWARF_DEBUGGING_INFO
3025 if (write_symbols == DWARF_DEBUG)
3026 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
3027 #endif
3029 #ifdef DWARF2_DEBUGGING_INFO
3030 if (write_symbols == DWARF2_DEBUG)
3031 dwarf2out_line (filename, NOTE_LINE_NUMBER (insn));
3032 #endif
3036 /* For each operand in INSN, simplify (subreg (reg)) so that it refers
3037 directly to the desired hard register. */
3039 void
3040 cleanup_subreg_operands (insn)
3041 rtx insn;
3043 int i;
3044 extract_insn_cached (insn);
3045 for (i = 0; i < recog_data.n_operands; i++)
3047 if (GET_CODE (recog_data.operand[i]) == SUBREG)
3048 recog_data.operand[i] = alter_subreg (recog_data.operand[i]);
3049 else if (GET_CODE (recog_data.operand[i]) == PLUS
3050 || GET_CODE (recog_data.operand[i]) == MULT
3051 || GET_CODE (recog_data.operand[i]) == MEM)
3052 recog_data.operand[i] = walk_alter_subreg (recog_data.operand[i]);
3055 for (i = 0; i < recog_data.n_dups; i++)
3057 if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
3058 *recog_data.dup_loc[i] = alter_subreg (*recog_data.dup_loc[i]);
3059 else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
3060 || GET_CODE (*recog_data.dup_loc[i]) == MULT
3061 || GET_CODE (*recog_data.dup_loc[i]) == MEM)
3062 *recog_data.dup_loc[i] = walk_alter_subreg (*recog_data.dup_loc[i]);
3066 /* If X is a SUBREG, replace it with a REG or a MEM,
3067 based on the thing it is a subreg of. */
3070 alter_subreg (x)
3071 register rtx x;
3073 register rtx y = SUBREG_REG (x);
3075 if (GET_CODE (y) == SUBREG)
3076 y = alter_subreg (y);
3078 /* If reload is operating, we may be replacing inside this SUBREG.
3079 Check for that and make a new one if so. */
3080 if (reload_in_progress && find_replacement (&SUBREG_REG (x)) != 0)
3081 x = copy_rtx (x);
3083 if (GET_CODE (y) == REG)
3085 int regno = subreg_hard_regno (x, 1);
3087 PUT_CODE (x, REG);
3088 REGNO (x) = regno;
3089 ORIGINAL_REGNO (x) = ORIGINAL_REGNO (y);
3090 /* This field has a different meaning for REGs and SUBREGs. Make sure
3091 to clear it! */
3092 x->used = 0;
3094 else if (GET_CODE (y) == MEM)
3096 HOST_WIDE_INT offset = SUBREG_BYTE (x);
3098 /* Catch these instead of generating incorrect code. */
3099 if ((offset % GET_MODE_SIZE (GET_MODE (x))) != 0)
3100 abort ();
3102 PUT_CODE (x, MEM);
3103 MEM_COPY_ATTRIBUTES (x, y);
3104 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
3107 return x;
3110 /* Do alter_subreg on all the SUBREGs contained in X. */
3112 static rtx
3113 walk_alter_subreg (x)
3114 rtx x;
3116 switch (GET_CODE (x))
3118 case PLUS:
3119 case MULT:
3120 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3121 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
3122 break;
3124 case MEM:
3125 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
3126 break;
3128 case SUBREG:
3129 return alter_subreg (x);
3131 default:
3132 break;
3135 return x;
3138 #ifdef HAVE_cc0
3140 /* Given BODY, the body of a jump instruction, alter the jump condition
3141 as required by the bits that are set in cc_status.flags.
3142 Not all of the bits there can be handled at this level in all cases.
3144 The value is normally 0.
3145 1 means that the condition has become always true.
3146 -1 means that the condition has become always false.
3147 2 means that COND has been altered. */
3149 static int
3150 alter_cond (cond)
3151 register rtx cond;
3153 int value = 0;
3155 if (cc_status.flags & CC_REVERSED)
3157 value = 2;
3158 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
3161 if (cc_status.flags & CC_INVERTED)
3163 value = 2;
3164 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
3167 if (cc_status.flags & CC_NOT_POSITIVE)
3168 switch (GET_CODE (cond))
3170 case LE:
3171 case LEU:
3172 case GEU:
3173 /* Jump becomes unconditional. */
3174 return 1;
3176 case GT:
3177 case GTU:
3178 case LTU:
3179 /* Jump becomes no-op. */
3180 return -1;
3182 case GE:
3183 PUT_CODE (cond, EQ);
3184 value = 2;
3185 break;
3187 case LT:
3188 PUT_CODE (cond, NE);
3189 value = 2;
3190 break;
3192 default:
3193 break;
3196 if (cc_status.flags & CC_NOT_NEGATIVE)
3197 switch (GET_CODE (cond))
3199 case GE:
3200 case GEU:
3201 /* Jump becomes unconditional. */
3202 return 1;
3204 case LT:
3205 case LTU:
3206 /* Jump becomes no-op. */
3207 return -1;
3209 case LE:
3210 case LEU:
3211 PUT_CODE (cond, EQ);
3212 value = 2;
3213 break;
3215 case GT:
3216 case GTU:
3217 PUT_CODE (cond, NE);
3218 value = 2;
3219 break;
3221 default:
3222 break;
3225 if (cc_status.flags & CC_NO_OVERFLOW)
3226 switch (GET_CODE (cond))
3228 case GEU:
3229 /* Jump becomes unconditional. */
3230 return 1;
3232 case LEU:
3233 PUT_CODE (cond, EQ);
3234 value = 2;
3235 break;
3237 case GTU:
3238 PUT_CODE (cond, NE);
3239 value = 2;
3240 break;
3242 case LTU:
3243 /* Jump becomes no-op. */
3244 return -1;
3246 default:
3247 break;
3250 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
3251 switch (GET_CODE (cond))
3253 default:
3254 abort ();
3256 case NE:
3257 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
3258 value = 2;
3259 break;
3261 case EQ:
3262 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
3263 value = 2;
3264 break;
3267 if (cc_status.flags & CC_NOT_SIGNED)
3268 /* The flags are valid if signed condition operators are converted
3269 to unsigned. */
3270 switch (GET_CODE (cond))
3272 case LE:
3273 PUT_CODE (cond, LEU);
3274 value = 2;
3275 break;
3277 case LT:
3278 PUT_CODE (cond, LTU);
3279 value = 2;
3280 break;
3282 case GT:
3283 PUT_CODE (cond, GTU);
3284 value = 2;
3285 break;
3287 case GE:
3288 PUT_CODE (cond, GEU);
3289 value = 2;
3290 break;
3292 default:
3293 break;
3296 return value;
3298 #endif
3300 /* Report inconsistency between the assembler template and the operands.
3301 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
3303 void
3304 output_operand_lossage (msgid)
3305 const char *msgid;
3307 if (this_is_asm_operands)
3308 error_for_asm (this_is_asm_operands, "invalid `asm': %s", _(msgid));
3309 else
3310 internal_error ("output_operand: %s", _(msgid));
3313 /* Output of assembler code from a template, and its subroutines. */
3315 /* Output text from TEMPLATE to the assembler output file,
3316 obeying %-directions to substitute operands taken from
3317 the vector OPERANDS.
3319 %N (for N a digit) means print operand N in usual manner.
3320 %lN means require operand N to be a CODE_LABEL or LABEL_REF
3321 and print the label name with no punctuation.
3322 %cN means require operand N to be a constant
3323 and print the constant expression with no punctuation.
3324 %aN means expect operand N to be a memory address
3325 (not a memory reference!) and print a reference
3326 to that address.
3327 %nN means expect operand N to be a constant
3328 and print a constant expression for minus the value
3329 of the operand, with no other punctuation. */
3331 static void
3332 output_asm_name ()
3334 if (flag_print_asm_name)
3336 /* Annotate the assembly with a comment describing the pattern and
3337 alternative used. */
3338 if (debug_insn)
3340 register int num = INSN_CODE (debug_insn);
3341 fprintf (asm_out_file, "\t%s %d\t%s",
3342 ASM_COMMENT_START, INSN_UID (debug_insn),
3343 insn_data[num].name);
3344 if (insn_data[num].n_alternatives > 1)
3345 fprintf (asm_out_file, "/%d", which_alternative + 1);
3346 #ifdef HAVE_ATTR_length
3347 fprintf (asm_out_file, "\t[length = %d]",
3348 get_attr_length (debug_insn));
3349 #endif
3350 /* Clear this so only the first assembler insn
3351 of any rtl insn will get the special comment for -dp. */
3352 debug_insn = 0;
3357 void
3358 output_asm_insn (template, operands)
3359 const char *template;
3360 rtx *operands;
3362 register const char *p;
3363 register int c;
3365 /* An insn may return a null string template
3366 in a case where no assembler code is needed. */
3367 if (*template == 0)
3368 return;
3370 p = template;
3371 putc ('\t', asm_out_file);
3373 #ifdef ASM_OUTPUT_OPCODE
3374 ASM_OUTPUT_OPCODE (asm_out_file, p);
3375 #endif
3377 while ((c = *p++))
3378 switch (c)
3380 case '\n':
3381 output_asm_name ();
3382 putc (c, asm_out_file);
3383 #ifdef ASM_OUTPUT_OPCODE
3384 while ((c = *p) == '\t')
3386 putc (c, asm_out_file);
3387 p++;
3389 ASM_OUTPUT_OPCODE (asm_out_file, p);
3390 #endif
3391 break;
3393 #ifdef ASSEMBLER_DIALECT
3394 case '{':
3396 register int i;
3398 /* If we want the first dialect, do nothing. Otherwise, skip
3399 DIALECT_NUMBER of strings ending with '|'. */
3400 for (i = 0; i < dialect_number; i++)
3402 while (*p && *p != '}' && *p++ != '|')
3404 if (*p == '}')
3405 break;
3406 if (*p == '|')
3407 p++;
3410 break;
3412 case '|':
3413 /* Skip to close brace. */
3414 while (*p && *p++ != '}')
3416 break;
3418 case '}':
3419 break;
3420 #endif
3422 case '%':
3423 /* %% outputs a single %. */
3424 if (*p == '%')
3426 p++;
3427 putc (c, asm_out_file);
3429 /* %= outputs a number which is unique to each insn in the entire
3430 compilation. This is useful for making local labels that are
3431 referred to more than once in a given insn. */
3432 else if (*p == '=')
3434 p++;
3435 fprintf (asm_out_file, "%d", insn_counter);
3437 /* % followed by a letter and some digits
3438 outputs an operand in a special way depending on the letter.
3439 Letters `acln' are implemented directly.
3440 Other letters are passed to `output_operand' so that
3441 the PRINT_OPERAND macro can define them. */
3442 else if (ISLOWER (*p) || ISUPPER (*p))
3444 int letter = *p++;
3445 c = atoi (p);
3447 if (! (*p >= '0' && *p <= '9'))
3448 output_operand_lossage ("operand number missing after %-letter");
3449 else if (this_is_asm_operands && (c < 0 || (unsigned int) c >= insn_noperands))
3450 output_operand_lossage ("operand number out of range");
3451 else if (letter == 'l')
3452 output_asm_label (operands[c]);
3453 else if (letter == 'a')
3454 output_address (operands[c]);
3455 else if (letter == 'c')
3457 if (CONSTANT_ADDRESS_P (operands[c]))
3458 output_addr_const (asm_out_file, operands[c]);
3459 else
3460 output_operand (operands[c], 'c');
3462 else if (letter == 'n')
3464 if (GET_CODE (operands[c]) == CONST_INT)
3465 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3466 - INTVAL (operands[c]));
3467 else
3469 putc ('-', asm_out_file);
3470 output_addr_const (asm_out_file, operands[c]);
3473 else
3474 output_operand (operands[c], letter);
3476 while ((c = *p) >= '0' && c <= '9')
3477 p++;
3479 /* % followed by a digit outputs an operand the default way. */
3480 else if (*p >= '0' && *p <= '9')
3482 c = atoi (p);
3483 if (this_is_asm_operands
3484 && (c < 0 || (unsigned int) c >= insn_noperands))
3485 output_operand_lossage ("operand number out of range");
3486 else
3487 output_operand (operands[c], 0);
3488 while ((c = *p) >= '0' && c <= '9')
3489 p++;
3491 /* % followed by punctuation: output something for that
3492 punctuation character alone, with no operand.
3493 The PRINT_OPERAND macro decides what is actually done. */
3494 #ifdef PRINT_OPERAND_PUNCT_VALID_P
3495 else if (PRINT_OPERAND_PUNCT_VALID_P ((unsigned char) *p))
3496 output_operand (NULL_RTX, *p++);
3497 #endif
3498 else
3499 output_operand_lossage ("invalid %%-code");
3500 break;
3502 default:
3503 putc (c, asm_out_file);
3506 output_asm_name ();
3508 putc ('\n', asm_out_file);
3511 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3513 void
3514 output_asm_label (x)
3515 rtx x;
3517 char buf[256];
3519 if (GET_CODE (x) == LABEL_REF)
3520 x = XEXP (x, 0);
3521 if (GET_CODE (x) == CODE_LABEL
3522 || (GET_CODE (x) == NOTE
3523 && NOTE_LINE_NUMBER (x) == NOTE_INSN_DELETED_LABEL))
3524 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3525 else
3526 output_operand_lossage ("`%l' operand isn't a label");
3528 assemble_name (asm_out_file, buf);
3531 /* Print operand X using machine-dependent assembler syntax.
3532 The macro PRINT_OPERAND is defined just to control this function.
3533 CODE is a non-digit that preceded the operand-number in the % spec,
3534 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3535 between the % and the digits.
3536 When CODE is a non-letter, X is 0.
3538 The meanings of the letters are machine-dependent and controlled
3539 by PRINT_OPERAND. */
3541 static void
3542 output_operand (x, code)
3543 rtx x;
3544 int code ATTRIBUTE_UNUSED;
3546 if (x && GET_CODE (x) == SUBREG)
3547 x = alter_subreg (x);
3549 /* If X is a pseudo-register, abort now rather than writing trash to the
3550 assembler file. */
3552 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
3553 abort ();
3555 PRINT_OPERAND (asm_out_file, x, code);
3558 /* Print a memory reference operand for address X
3559 using machine-dependent assembler syntax.
3560 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
3562 void
3563 output_address (x)
3564 rtx x;
3566 walk_alter_subreg (x);
3567 PRINT_OPERAND_ADDRESS (asm_out_file, x);
3570 /* Print an integer constant expression in assembler syntax.
3571 Addition and subtraction are the only arithmetic
3572 that may appear in these expressions. */
3574 void
3575 output_addr_const (file, x)
3576 FILE *file;
3577 rtx x;
3579 char buf[256];
3581 restart:
3582 switch (GET_CODE (x))
3584 case PC:
3585 if (flag_pic)
3586 putc ('.', file);
3587 else
3588 abort ();
3589 break;
3591 case SYMBOL_REF:
3592 #ifdef ASM_OUTPUT_SYMBOL_REF
3593 ASM_OUTPUT_SYMBOL_REF (file, x);
3594 #else
3595 assemble_name (file, XSTR (x, 0));
3596 #endif
3597 break;
3599 case LABEL_REF:
3600 x = XEXP (x, 0);
3601 /* Fall through. */
3602 case CODE_LABEL:
3603 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3604 assemble_name (file, buf);
3605 break;
3607 case CONST_INT:
3608 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3609 break;
3611 case CONST:
3612 /* This used to output parentheses around the expression,
3613 but that does not work on the 386 (either ATT or BSD assembler). */
3614 output_addr_const (file, XEXP (x, 0));
3615 break;
3617 case CONST_DOUBLE:
3618 if (GET_MODE (x) == VOIDmode)
3620 /* We can use %d if the number is one word and positive. */
3621 if (CONST_DOUBLE_HIGH (x))
3622 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3623 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
3624 else if (CONST_DOUBLE_LOW (x) < 0)
3625 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
3626 else
3627 fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3629 else
3630 /* We can't handle floating point constants;
3631 PRINT_OPERAND must handle them. */
3632 output_operand_lossage ("floating constant misused");
3633 break;
3635 case PLUS:
3636 /* Some assemblers need integer constants to appear last (eg masm). */
3637 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3639 output_addr_const (file, XEXP (x, 1));
3640 if (INTVAL (XEXP (x, 0)) >= 0)
3641 fprintf (file, "+");
3642 output_addr_const (file, XEXP (x, 0));
3644 else
3646 output_addr_const (file, XEXP (x, 0));
3647 if (GET_CODE (XEXP (x, 1)) != CONST_INT
3648 || INTVAL (XEXP (x, 1)) >= 0)
3649 fprintf (file, "+");
3650 output_addr_const (file, XEXP (x, 1));
3652 break;
3654 case MINUS:
3655 /* Avoid outputting things like x-x or x+5-x,
3656 since some assemblers can't handle that. */
3657 x = simplify_subtraction (x);
3658 if (GET_CODE (x) != MINUS)
3659 goto restart;
3661 output_addr_const (file, XEXP (x, 0));
3662 fprintf (file, "-");
3663 if ((GET_CODE (XEXP (x, 1)) == CONST_INT
3664 && INTVAL (XEXP (x, 1)) < 0)
3665 || GET_CODE (XEXP (x, 1)) != CONST_INT)
3667 fputs (targetm.asm_out.open_paren, file);
3668 output_addr_const (file, XEXP (x, 1));
3669 fputs (targetm.asm_out.close_paren, file);
3671 else
3672 output_addr_const (file, XEXP (x, 1));
3673 break;
3675 case ZERO_EXTEND:
3676 case SIGN_EXTEND:
3677 output_addr_const (file, XEXP (x, 0));
3678 break;
3680 default:
3681 #ifdef OUTPUT_ADDR_CONST_EXTRA
3682 OUTPUT_ADDR_CONST_EXTRA (file, x, fail);
3683 break;
3685 fail:
3686 #endif
3687 output_operand_lossage ("invalid expression as operand");
3691 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3692 %R prints the value of REGISTER_PREFIX.
3693 %L prints the value of LOCAL_LABEL_PREFIX.
3694 %U prints the value of USER_LABEL_PREFIX.
3695 %I prints the value of IMMEDIATE_PREFIX.
3696 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3697 Also supported are %d, %x, %s, %e, %f, %g and %%.
3699 We handle alternate assembler dialects here, just like output_asm_insn. */
3701 void
3702 asm_fprintf VPARAMS ((FILE *file, const char *p, ...))
3704 #ifndef ANSI_PROTOTYPES
3705 FILE *file;
3706 const char *p;
3707 #endif
3708 va_list argptr;
3709 char buf[10];
3710 char *q, c;
3712 VA_START (argptr, p);
3714 #ifndef ANSI_PROTOTYPES
3715 file = va_arg (argptr, FILE *);
3716 p = va_arg (argptr, const char *);
3717 #endif
3719 buf[0] = '%';
3721 while ((c = *p++))
3722 switch (c)
3724 #ifdef ASSEMBLER_DIALECT
3725 case '{':
3727 int i;
3729 /* If we want the first dialect, do nothing. Otherwise, skip
3730 DIALECT_NUMBER of strings ending with '|'. */
3731 for (i = 0; i < dialect_number; i++)
3733 while (*p && *p++ != '|')
3736 if (*p == '|')
3737 p++;
3740 break;
3742 case '|':
3743 /* Skip to close brace. */
3744 while (*p && *p++ != '}')
3746 break;
3748 case '}':
3749 break;
3750 #endif
3752 case '%':
3753 c = *p++;
3754 q = &buf[1];
3755 while ((c >= '0' && c <= '9') || c == '.')
3757 *q++ = c;
3758 c = *p++;
3760 switch (c)
3762 case '%':
3763 fprintf (file, "%%");
3764 break;
3766 case 'd': case 'i': case 'u':
3767 case 'x': case 'p': case 'X':
3768 case 'o':
3769 *q++ = c;
3770 *q = 0;
3771 fprintf (file, buf, va_arg (argptr, int));
3772 break;
3774 case 'w':
3775 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3776 but we do not check for those cases. It means that the value
3777 is a HOST_WIDE_INT, which may be either `int' or `long'. */
3779 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3780 #else
3781 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3782 *q++ = 'l';
3783 #else
3784 *q++ = 'l';
3785 *q++ = 'l';
3786 #endif
3787 #endif
3789 *q++ = *p++;
3790 *q = 0;
3791 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3792 break;
3794 case 'l':
3795 *q++ = c;
3796 *q++ = *p++;
3797 *q = 0;
3798 fprintf (file, buf, va_arg (argptr, long));
3799 break;
3801 case 'e':
3802 case 'f':
3803 case 'g':
3804 *q++ = c;
3805 *q = 0;
3806 fprintf (file, buf, va_arg (argptr, double));
3807 break;
3809 case 's':
3810 *q++ = c;
3811 *q = 0;
3812 fprintf (file, buf, va_arg (argptr, char *));
3813 break;
3815 case 'O':
3816 #ifdef ASM_OUTPUT_OPCODE
3817 ASM_OUTPUT_OPCODE (asm_out_file, p);
3818 #endif
3819 break;
3821 case 'R':
3822 #ifdef REGISTER_PREFIX
3823 fprintf (file, "%s", REGISTER_PREFIX);
3824 #endif
3825 break;
3827 case 'I':
3828 #ifdef IMMEDIATE_PREFIX
3829 fprintf (file, "%s", IMMEDIATE_PREFIX);
3830 #endif
3831 break;
3833 case 'L':
3834 #ifdef LOCAL_LABEL_PREFIX
3835 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3836 #endif
3837 break;
3839 case 'U':
3840 fputs (user_label_prefix, file);
3841 break;
3843 #ifdef ASM_FPRINTF_EXTENSIONS
3844 /* Upper case letters are reserved for general use by asm_fprintf
3845 and so are not available to target specific code. In order to
3846 prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
3847 they are defined here. As they get turned into real extensions
3848 to asm_fprintf they should be removed from this list. */
3849 case 'A': case 'B': case 'C': case 'D': case 'E':
3850 case 'F': case 'G': case 'H': case 'J': case 'K':
3851 case 'M': case 'N': case 'P': case 'Q': case 'S':
3852 case 'T': case 'V': case 'W': case 'Y': case 'Z':
3853 break;
3855 ASM_FPRINTF_EXTENSIONS (file, argptr, p)
3856 #endif
3857 default:
3858 abort ();
3860 break;
3862 default:
3863 fputc (c, file);
3865 va_end (argptr);
3868 /* Split up a CONST_DOUBLE or integer constant rtx
3869 into two rtx's for single words,
3870 storing in *FIRST the word that comes first in memory in the target
3871 and in *SECOND the other. */
3873 void
3874 split_double (value, first, second)
3875 rtx value;
3876 rtx *first, *second;
3878 if (GET_CODE (value) == CONST_INT)
3880 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3882 /* In this case the CONST_INT holds both target words.
3883 Extract the bits from it into two word-sized pieces.
3884 Sign extend each half to HOST_WIDE_INT. */
3885 unsigned HOST_WIDE_INT low, high;
3886 unsigned HOST_WIDE_INT mask, sign_bit, sign_extend;
3888 /* Set sign_bit to the most significant bit of a word. */
3889 sign_bit = 1;
3890 sign_bit <<= BITS_PER_WORD - 1;
3892 /* Set mask so that all bits of the word are set. We could
3893 have used 1 << BITS_PER_WORD instead of basing the
3894 calculation on sign_bit. However, on machines where
3895 HOST_BITS_PER_WIDE_INT == BITS_PER_WORD, it could cause a
3896 compiler warning, even though the code would never be
3897 executed. */
3898 mask = sign_bit << 1;
3899 mask--;
3901 /* Set sign_extend as any remaining bits. */
3902 sign_extend = ~mask;
3904 /* Pick the lower word and sign-extend it. */
3905 low = INTVAL (value);
3906 low &= mask;
3907 if (low & sign_bit)
3908 low |= sign_extend;
3910 /* Pick the higher word, shifted to the least significant
3911 bits, and sign-extend it. */
3912 high = INTVAL (value);
3913 high >>= BITS_PER_WORD - 1;
3914 high >>= 1;
3915 high &= mask;
3916 if (high & sign_bit)
3917 high |= sign_extend;
3919 /* Store the words in the target machine order. */
3920 if (WORDS_BIG_ENDIAN)
3922 *first = GEN_INT (high);
3923 *second = GEN_INT (low);
3925 else
3927 *first = GEN_INT (low);
3928 *second = GEN_INT (high);
3931 else
3933 /* The rule for using CONST_INT for a wider mode
3934 is that we regard the value as signed.
3935 So sign-extend it. */
3936 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3937 if (WORDS_BIG_ENDIAN)
3939 *first = high;
3940 *second = value;
3942 else
3944 *first = value;
3945 *second = high;
3949 else if (GET_CODE (value) != CONST_DOUBLE)
3951 if (WORDS_BIG_ENDIAN)
3953 *first = const0_rtx;
3954 *second = value;
3956 else
3958 *first = value;
3959 *second = const0_rtx;
3962 else if (GET_MODE (value) == VOIDmode
3963 /* This is the old way we did CONST_DOUBLE integers. */
3964 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3966 /* In an integer, the words are defined as most and least significant.
3967 So order them by the target's convention. */
3968 if (WORDS_BIG_ENDIAN)
3970 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3971 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3973 else
3975 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3976 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3979 else
3981 #ifdef REAL_ARITHMETIC
3982 REAL_VALUE_TYPE r;
3983 long l[2];
3984 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3986 /* Note, this converts the REAL_VALUE_TYPE to the target's
3987 format, splits up the floating point double and outputs
3988 exactly 32 bits of it into each of l[0] and l[1] --
3989 not necessarily BITS_PER_WORD bits. */
3990 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3992 /* If 32 bits is an entire word for the target, but not for the host,
3993 then sign-extend on the host so that the number will look the same
3994 way on the host that it would on the target. See for instance
3995 simplify_unary_operation. The #if is needed to avoid compiler
3996 warnings. */
3998 #if HOST_BITS_PER_LONG > 32
3999 if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
4001 if (l[0] & ((long) 1 << 31))
4002 l[0] |= ((long) (-1) << 32);
4003 if (l[1] & ((long) 1 << 31))
4004 l[1] |= ((long) (-1) << 32);
4006 #endif
4008 *first = GEN_INT ((HOST_WIDE_INT) l[0]);
4009 *second = GEN_INT ((HOST_WIDE_INT) l[1]);
4010 #else
4011 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
4012 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
4013 && ! flag_pretend_float)
4014 abort ();
4016 if (
4017 #ifdef HOST_WORDS_BIG_ENDIAN
4018 WORDS_BIG_ENDIAN
4019 #else
4020 ! WORDS_BIG_ENDIAN
4021 #endif
4024 /* Host and target agree => no need to swap. */
4025 *first = GEN_INT (CONST_DOUBLE_LOW (value));
4026 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
4028 else
4030 *second = GEN_INT (CONST_DOUBLE_LOW (value));
4031 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
4033 #endif /* no REAL_ARITHMETIC */
4037 /* Return nonzero if this function has no function calls. */
4040 leaf_function_p ()
4042 rtx insn;
4043 rtx link;
4045 if (profile_flag || profile_block_flag || profile_arc_flag)
4046 return 0;
4048 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4050 if (GET_CODE (insn) == CALL_INSN
4051 && ! SIBLING_CALL_P (insn))
4052 return 0;
4053 if (GET_CODE (insn) == INSN
4054 && GET_CODE (PATTERN (insn)) == SEQUENCE
4055 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4056 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4057 return 0;
4059 for (link = current_function_epilogue_delay_list;
4060 link;
4061 link = XEXP (link, 1))
4063 insn = XEXP (link, 0);
4065 if (GET_CODE (insn) == CALL_INSN
4066 && ! SIBLING_CALL_P (insn))
4067 return 0;
4068 if (GET_CODE (insn) == INSN
4069 && GET_CODE (PATTERN (insn)) == SEQUENCE
4070 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN
4071 && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4072 return 0;
4075 return 1;
4078 /* Return 1 if branch is an forward branch.
4079 Uses insn_shuid array, so it works only in the final pass. May be used by
4080 output templates to customary add branch prediction hints.
4083 final_forward_branch_p (insn)
4084 rtx insn;
4086 int insn_id, label_id;
4087 if (!uid_shuid)
4088 abort ();
4089 insn_id = INSN_SHUID (insn);
4090 label_id = INSN_SHUID (JUMP_LABEL (insn));
4091 /* We've hit some insns that does not have id information available. */
4092 if (!insn_id || !label_id)
4093 abort ();
4094 return insn_id < label_id;
4097 /* On some machines, a function with no call insns
4098 can run faster if it doesn't create its own register window.
4099 When output, the leaf function should use only the "output"
4100 registers. Ordinarily, the function would be compiled to use
4101 the "input" registers to find its arguments; it is a candidate
4102 for leaf treatment if it uses only the "input" registers.
4103 Leaf function treatment means renumbering so the function
4104 uses the "output" registers instead. */
4106 #ifdef LEAF_REGISTERS
4108 /* Return 1 if this function uses only the registers that can be
4109 safely renumbered. */
4112 only_leaf_regs_used ()
4114 int i;
4115 char *permitted_reg_in_leaf_functions = LEAF_REGISTERS;
4117 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4118 if ((regs_ever_live[i] || global_regs[i])
4119 && ! permitted_reg_in_leaf_functions[i])
4120 return 0;
4122 if (current_function_uses_pic_offset_table
4123 && pic_offset_table_rtx != 0
4124 && GET_CODE (pic_offset_table_rtx) == REG
4125 && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
4126 return 0;
4128 return 1;
4131 /* Scan all instructions and renumber all registers into those
4132 available in leaf functions. */
4134 static void
4135 leaf_renumber_regs (first)
4136 rtx first;
4138 rtx insn;
4140 /* Renumber only the actual patterns.
4141 The reg-notes can contain frame pointer refs,
4142 and renumbering them could crash, and should not be needed. */
4143 for (insn = first; insn; insn = NEXT_INSN (insn))
4144 if (INSN_P (insn))
4145 leaf_renumber_regs_insn (PATTERN (insn));
4146 for (insn = current_function_epilogue_delay_list;
4147 insn;
4148 insn = XEXP (insn, 1))
4149 if (INSN_P (XEXP (insn, 0)))
4150 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
4153 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
4154 available in leaf functions. */
4156 void
4157 leaf_renumber_regs_insn (in_rtx)
4158 register rtx in_rtx;
4160 register int i, j;
4161 register const char *format_ptr;
4163 if (in_rtx == 0)
4164 return;
4166 /* Renumber all input-registers into output-registers.
4167 renumbered_regs would be 1 for an output-register;
4168 they */
4170 if (GET_CODE (in_rtx) == REG)
4172 int newreg;
4174 /* Don't renumber the same reg twice. */
4175 if (in_rtx->used)
4176 return;
4178 newreg = REGNO (in_rtx);
4179 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
4180 to reach here as part of a REG_NOTE. */
4181 if (newreg >= FIRST_PSEUDO_REGISTER)
4183 in_rtx->used = 1;
4184 return;
4186 newreg = LEAF_REG_REMAP (newreg);
4187 if (newreg < 0)
4188 abort ();
4189 regs_ever_live[REGNO (in_rtx)] = 0;
4190 regs_ever_live[newreg] = 1;
4191 REGNO (in_rtx) = newreg;
4192 in_rtx->used = 1;
4195 if (INSN_P (in_rtx))
4197 /* Inside a SEQUENCE, we find insns.
4198 Renumber just the patterns of these insns,
4199 just as we do for the top-level insns. */
4200 leaf_renumber_regs_insn (PATTERN (in_rtx));
4201 return;
4204 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
4206 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
4207 switch (*format_ptr++)
4209 case 'e':
4210 leaf_renumber_regs_insn (XEXP (in_rtx, i));
4211 break;
4213 case 'E':
4214 if (NULL != XVEC (in_rtx, i))
4216 for (j = 0; j < XVECLEN (in_rtx, i); j++)
4217 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
4219 break;
4221 case 'S':
4222 case 's':
4223 case '0':
4224 case 'i':
4225 case 'w':
4226 case 'n':
4227 case 'u':
4228 break;
4230 default:
4231 abort ();
4234 #endif