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