]> gcc.gnu.org Git - gcc.git/blob - gcc/final.c
* final.c (final_scan_insn): Undo overzealous removal of `set'.
[gcc.git] / gcc / final.c
1 /* Convert RTL to assembler code and output it, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-7, 1998 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
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 #ifdef __STDC__
49 #include <stdarg.h>
50 #else
51 #include <varargs.h>
52 #endif
53 #include <stdio.h>
54 #include <ctype.h>
55 #if HAVE_STDLIB_H
56 #include <stdlib.h>
57 #endif
58 #ifdef HAVE_STRING_H
59 #include <string.h>
60 #else
61 #ifdef HAVE_STRINGS_H
62 #include <strings.h>
63 #endif
64 #endif
65
66 #include "tree.h"
67 #include "rtl.h"
68 #include "regs.h"
69 #include "insn-config.h"
70 #include "insn-flags.h"
71 #include "insn-attr.h"
72 #include "insn-codes.h"
73 #include "recog.h"
74 #include "conditions.h"
75 #include "flags.h"
76 #include "real.h"
77 #include "hard-reg-set.h"
78 #include "defaults.h"
79 #include "output.h"
80 #include "except.h"
81
82 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist. */
83 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
84 #if defined (USG) || defined (NO_STAB_H)
85 #include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
86 #else
87 #include <stab.h> /* On BSD, use the system's stab.h. */
88 #endif /* not USG */
89 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
90
91 #ifdef XCOFF_DEBUGGING_INFO
92 #include "xcoffout.h"
93 #endif
94
95 /* .stabd code for line number. */
96 #ifndef N_SLINE
97 #define N_SLINE 0x44
98 #endif
99
100 /* .stabs code for included file name. */
101 #ifndef N_SOL
102 #define N_SOL 0x84
103 #endif
104
105 #ifndef INT_TYPE_SIZE
106 #define INT_TYPE_SIZE BITS_PER_WORD
107 #endif
108
109 #ifndef LONG_TYPE_SIZE
110 #define LONG_TYPE_SIZE BITS_PER_WORD
111 #endif
112
113 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist. So define a
114 null default for it to save conditionalization later. */
115 #ifndef CC_STATUS_INIT
116 #define CC_STATUS_INIT
117 #endif
118
119 /* How to start an assembler comment. */
120 #ifndef ASM_COMMENT_START
121 #define ASM_COMMENT_START ";#"
122 #endif
123
124 /* Is the given character a logical line separator for the assembler? */
125 #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
126 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C) ((C) == ';')
127 #endif
128
129 /* Nonzero means this function is a leaf function, with no function calls.
130 This variable exists to be examined in FUNCTION_PROLOGUE
131 and FUNCTION_EPILOGUE. Always zero, unless set by some action. */
132 int leaf_function;
133
134 /* Last insn processed by final_scan_insn. */
135 static rtx debug_insn = 0;
136
137 /* Line number of last NOTE. */
138 static int last_linenum;
139
140 /* Highest line number in current block. */
141 static int high_block_linenum;
142
143 /* Likewise for function. */
144 static int high_function_linenum;
145
146 /* Filename of last NOTE. */
147 static char *last_filename;
148
149 /* Number of basic blocks seen so far;
150 used if profile_block_flag is set. */
151 static int count_basic_blocks;
152
153 /* Number of instrumented arcs when profile_arc_flag is set. */
154 extern int count_instrumented_arcs;
155
156 /* Nonzero while outputting an `asm' with operands.
157 This means that inconsistencies are the user's fault, so don't abort.
158 The precise value is the insn being output, to pass to error_for_asm. */
159 static rtx this_is_asm_operands;
160
161 /* Number of operands of this insn, for an `asm' with operands. */
162 static int insn_noperands;
163
164 /* Compare optimization flag. */
165
166 static rtx last_ignored_compare = 0;
167
168 /* Flag indicating this insn is the start of a new basic block. */
169
170 static int new_block = 1;
171
172 /* All the symbol-blocks (levels of scoping) in the compilation
173 are assigned sequence numbers in order of appearance of the
174 beginnings of the symbol-blocks. Both final and dbxout do this,
175 and assume that they will both give the same number to each block.
176 Final uses these sequence numbers to generate assembler label names
177 LBBnnn and LBEnnn for the beginning and end of the symbol-block.
178 Dbxout uses the sequence numbers to generate references to the same labels
179 from the dbx debugging information.
180
181 Sdb records this level at the beginning of each function,
182 in order to find the current level when recursing down declarations.
183 It outputs the block beginning and endings
184 at the point in the asm file where the blocks would begin and end. */
185
186 int next_block_index;
187
188 /* Assign a unique number to each insn that is output.
189 This can be used to generate unique local labels. */
190
191 static int insn_counter = 0;
192
193 #ifdef HAVE_cc0
194 /* This variable contains machine-dependent flags (defined in tm.h)
195 set and examined by output routines
196 that describe how to interpret the condition codes properly. */
197
198 CC_STATUS cc_status;
199
200 /* During output of an insn, this contains a copy of cc_status
201 from before the insn. */
202
203 CC_STATUS cc_prev_status;
204 #endif
205
206 /* Indexed by hardware reg number, is 1 if that register is ever
207 used in the current function.
208
209 In life_analysis, or in stupid_life_analysis, this is set
210 up to record the hard regs used explicitly. Reload adds
211 in the hard regs used for holding pseudo regs. Final uses
212 it to generate the code in the function prologue and epilogue
213 to save and restore registers as needed. */
214
215 char regs_ever_live[FIRST_PSEUDO_REGISTER];
216
217 /* Nonzero means current function must be given a frame pointer.
218 Set in stmt.c if anything is allocated on the stack there.
219 Set in reload1.c if anything is allocated on the stack there. */
220
221 int frame_pointer_needed;
222
223 /* Assign unique numbers to labels generated for profiling. */
224
225 int profile_label_no;
226
227 /* Length so far allocated in PENDING_BLOCKS. */
228
229 static int max_block_depth;
230
231 /* Stack of sequence numbers of symbol-blocks of which we have seen the
232 beginning but not yet the end. Sequence numbers are assigned at
233 the beginning; this stack allows us to find the sequence number
234 of a block that is ending. */
235
236 static int *pending_blocks;
237
238 /* Number of elements currently in use in PENDING_BLOCKS. */
239
240 static int block_depth;
241
242 /* Nonzero if have enabled APP processing of our assembler output. */
243
244 static int app_on;
245
246 /* If we are outputting an insn sequence, this contains the sequence rtx.
247 Zero otherwise. */
248
249 rtx final_sequence;
250
251 #ifdef ASSEMBLER_DIALECT
252
253 /* Number of the assembler dialect to use, starting at 0. */
254 static int dialect_number;
255 #endif
256
257 /* Indexed by line number, nonzero if there is a note for that line. */
258
259 static char *line_note_exists;
260
261 /* Linked list to hold line numbers for each basic block. */
262
263 struct bb_list {
264 struct bb_list *next; /* pointer to next basic block */
265 int line_num; /* line number */
266 int file_label_num; /* LPBC<n> label # for stored filename */
267 int func_label_num; /* LPBC<n> label # for stored function name */
268 };
269
270 static struct bb_list *bb_head = 0; /* Head of basic block list */
271 static struct bb_list **bb_tail = &bb_head; /* Ptr to store next bb ptr */
272 static int bb_file_label_num = -1; /* Current label # for file */
273 static int bb_func_label_num = -1; /* Current label # for func */
274
275 /* Linked list to hold the strings for each file and function name output. */
276
277 struct bb_str {
278 struct bb_str *next; /* pointer to next string */
279 char *string; /* string */
280 int label_num; /* label number */
281 int length; /* string length */
282 };
283
284 extern rtx peephole PROTO((rtx));
285
286 static struct bb_str *sbb_head = 0; /* Head of string list. */
287 static struct bb_str **sbb_tail = &sbb_head; /* Ptr to store next bb str */
288 static int sbb_label_num = 0; /* Last label used */
289
290 #ifdef HAVE_ATTR_length
291 static int asm_insn_count PROTO((rtx));
292 #endif
293 static void profile_function PROTO((FILE *));
294 static void profile_after_prologue PROTO((FILE *));
295 static void add_bb PROTO((FILE *));
296 static int add_bb_string PROTO((char *, int));
297 static void output_source_line PROTO((FILE *, rtx));
298 static rtx walk_alter_subreg PROTO((rtx));
299 static void output_asm_name PROTO((void));
300 static void output_operand PROTO((rtx, int));
301 #ifdef LEAF_REGISTERS
302 static void leaf_renumber_regs PROTO((rtx));
303 #endif
304 #ifdef HAVE_cc0
305 static int alter_cond PROTO((rtx));
306 #endif
307
308 extern char *getpwd ();
309 \f
310 /* Initialize data in final at the beginning of a compilation. */
311
312 void
313 init_final (filename)
314 char *filename;
315 {
316 next_block_index = 2;
317 app_on = 0;
318 max_block_depth = 20;
319 pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
320 final_sequence = 0;
321
322 #ifdef ASSEMBLER_DIALECT
323 dialect_number = ASSEMBLER_DIALECT;
324 #endif
325 }
326
327 /* Called at end of source file,
328 to output the block-profiling table for this entire compilation. */
329
330 void
331 end_final (filename)
332 char *filename;
333 {
334 int i;
335
336 if (profile_block_flag || profile_arc_flag)
337 {
338 char name[20];
339 int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
340 int size, rounded;
341 struct bb_list *ptr;
342 struct bb_str *sptr;
343 int long_bytes = LONG_TYPE_SIZE / BITS_PER_UNIT;
344 int pointer_bytes = POINTER_SIZE / BITS_PER_UNIT;
345
346 if (profile_block_flag)
347 size = long_bytes * count_basic_blocks;
348 else
349 size = long_bytes * count_instrumented_arcs;
350 rounded = size;
351
352 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
353 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
354 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
355
356 data_section ();
357
358 /* Output the main header, of 11 words:
359 0: 1 if this file is initialized, else 0.
360 1: address of file name (LPBX1).
361 2: address of table of counts (LPBX2).
362 3: number of counts in the table.
363 4: always 0, for compatibility with Sun.
364
365 The following are GNU extensions:
366
367 5: address of table of start addrs of basic blocks (LPBX3).
368 6: Number of bytes in this header.
369 7: address of table of function names (LPBX4).
370 8: address of table of line numbers (LPBX5) or 0.
371 9: address of table of file names (LPBX6) or 0.
372 10: space reserved for basic block profiling. */
373
374 ASM_OUTPUT_ALIGN (asm_out_file, align);
375
376 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
377 /* zero word */
378 assemble_integer (const0_rtx, long_bytes, 1);
379
380 /* address of filename */
381 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
382 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
383
384 /* address of count table */
385 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
386 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
387
388 /* count of the # of basic blocks or # of instrumented arcs */
389 if (profile_block_flag)
390 assemble_integer (GEN_INT (count_basic_blocks), long_bytes, 1);
391 else
392 assemble_integer (GEN_INT (count_instrumented_arcs), long_bytes,
393 1);
394
395 /* zero word (link field) */
396 assemble_integer (const0_rtx, pointer_bytes, 1);
397
398 /* address of basic block start address table */
399 if (profile_block_flag)
400 {
401 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
402 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
403 1);
404 }
405 else
406 assemble_integer (const0_rtx, pointer_bytes, 1);
407
408 /* byte count for extended structure. */
409 assemble_integer (GEN_INT (10 * UNITS_PER_WORD), long_bytes, 1);
410
411 /* address of function name table */
412 if (profile_block_flag)
413 {
414 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
415 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
416 1);
417 }
418 else
419 assemble_integer (const0_rtx, pointer_bytes, 1);
420
421 /* address of line number and filename tables if debugging. */
422 if (write_symbols != NO_DEBUG && profile_block_flag)
423 {
424 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
425 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
426 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
427 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes, 1);
428 }
429 else
430 {
431 assemble_integer (const0_rtx, pointer_bytes, 1);
432 assemble_integer (const0_rtx, pointer_bytes, 1);
433 }
434
435 /* space for extension ptr (link field) */
436 assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
437
438 /* Output the file name changing the suffix to .d for Sun tcov
439 compatibility. */
440 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
441 {
442 char *cwd = getpwd ();
443 int len = strlen (filename) + strlen (cwd) + 1;
444 char *data_file = (char *) alloca (len + 4);
445
446 strcpy (data_file, cwd);
447 strcat (data_file, "/");
448 strcat (data_file, filename);
449 strip_off_ending (data_file, len);
450 if (profile_block_flag)
451 strcat (data_file, ".d");
452 else
453 strcat (data_file, ".da");
454 assemble_string (data_file, strlen (data_file) + 1);
455 }
456
457 /* Make space for the table of counts. */
458 if (size == 0)
459 {
460 /* Realign data section. */
461 ASM_OUTPUT_ALIGN (asm_out_file, align);
462 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
463 if (size != 0)
464 assemble_zeros (size);
465 }
466 else
467 {
468 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
469 #ifdef ASM_OUTPUT_SHARED_LOCAL
470 if (flag_shared_data)
471 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
472 else
473 #endif
474 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
475 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
476 BIGGEST_ALIGNMENT);
477 #else
478 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
479 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
480 BIGGEST_ALIGNMENT);
481 #else
482 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
483 #endif
484 #endif
485 }
486
487 /* Output any basic block strings */
488 if (profile_block_flag)
489 {
490 readonly_data_section ();
491 if (sbb_head)
492 {
493 ASM_OUTPUT_ALIGN (asm_out_file, align);
494 for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
495 {
496 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC",
497 sptr->label_num);
498 assemble_string (sptr->string, sptr->length);
499 }
500 }
501 }
502
503 /* Output the table of addresses. */
504 if (profile_block_flag)
505 {
506 /* Realign in new section */
507 ASM_OUTPUT_ALIGN (asm_out_file, align);
508 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
509 for (i = 0; i < count_basic_blocks; i++)
510 {
511 ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
512 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
513 pointer_bytes, 1);
514 }
515 }
516
517 /* Output the table of function names. */
518 if (profile_block_flag)
519 {
520 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
521 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
522 {
523 if (ptr->func_label_num >= 0)
524 {
525 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
526 ptr->func_label_num);
527 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
528 pointer_bytes, 1);
529 }
530 else
531 assemble_integer (const0_rtx, pointer_bytes, 1);
532 }
533
534 for ( ; i < count_basic_blocks; i++)
535 assemble_integer (const0_rtx, pointer_bytes, 1);
536 }
537
538 if (write_symbols != NO_DEBUG && profile_block_flag)
539 {
540 /* Output the table of line numbers. */
541 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
542 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
543 assemble_integer (GEN_INT (ptr->line_num), long_bytes, 1);
544
545 for ( ; i < count_basic_blocks; i++)
546 assemble_integer (const0_rtx, long_bytes, 1);
547
548 /* Output the table of file names. */
549 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
550 for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
551 {
552 if (ptr->file_label_num >= 0)
553 {
554 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
555 ptr->file_label_num);
556 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name),
557 pointer_bytes, 1);
558 }
559 else
560 assemble_integer (const0_rtx, pointer_bytes, 1);
561 }
562
563 for ( ; i < count_basic_blocks; i++)
564 assemble_integer (const0_rtx, pointer_bytes, 1);
565 }
566
567 /* End with the address of the table of addresses,
568 so we can find it easily, as the last word in the file's text. */
569 if (profile_block_flag)
570 {
571 ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
572 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, name), pointer_bytes,
573 1);
574 }
575 }
576 }
577
578 /* Enable APP processing of subsequent output.
579 Used before the output from an `asm' statement. */
580
581 void
582 app_enable ()
583 {
584 if (! app_on)
585 {
586 fputs (ASM_APP_ON, asm_out_file);
587 app_on = 1;
588 }
589 }
590
591 /* Disable APP processing of subsequent output.
592 Called from varasm.c before most kinds of output. */
593
594 void
595 app_disable ()
596 {
597 if (app_on)
598 {
599 fputs (ASM_APP_OFF, asm_out_file);
600 app_on = 0;
601 }
602 }
603 \f
604 /* Return the number of slots filled in the current
605 delayed branch sequence (we don't count the insn needing the
606 delay slot). Zero if not in a delayed branch sequence. */
607
608 #ifdef DELAY_SLOTS
609 int
610 dbr_sequence_length ()
611 {
612 if (final_sequence != 0)
613 return XVECLEN (final_sequence, 0) - 1;
614 else
615 return 0;
616 }
617 #endif
618 \f
619 /* The next two pages contain routines used to compute the length of an insn
620 and to shorten branches. */
621
622 /* Arrays for insn lengths, and addresses. The latter is referenced by
623 `insn_current_length'. */
624
625 static short *insn_lengths;
626 int *insn_addresses;
627
628 /* Address of insn being processed. Used by `insn_current_length'. */
629 int insn_current_address;
630
631 /* Indicate that branch shortening hasn't yet been done. */
632
633 void
634 init_insn_lengths ()
635 {
636 insn_lengths = 0;
637 }
638
639 /* Obtain the current length of an insn. If branch shortening has been done,
640 get its actual length. Otherwise, get its maximum length. */
641
642 int
643 get_attr_length (insn)
644 rtx insn;
645 {
646 #ifdef HAVE_ATTR_length
647 rtx body;
648 int i;
649 int length = 0;
650
651 if (insn_lengths)
652 return insn_lengths[INSN_UID (insn)];
653 else
654 switch (GET_CODE (insn))
655 {
656 case NOTE:
657 case BARRIER:
658 case CODE_LABEL:
659 return 0;
660
661 case CALL_INSN:
662 length = insn_default_length (insn);
663 break;
664
665 case JUMP_INSN:
666 body = PATTERN (insn);
667 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
668 {
669 /* This only takes room if jump tables go into the text section. */
670 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
671 length = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
672 * GET_MODE_SIZE (GET_MODE (body)));
673
674 /* Be pessimistic and assume worst-case alignment. */
675 length += (GET_MODE_SIZE (GET_MODE (body)) - 1);
676 #else
677 return 0;
678 #endif
679 }
680 else
681 length = insn_default_length (insn);
682 break;
683
684 case INSN:
685 body = PATTERN (insn);
686 if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
687 return 0;
688
689 else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
690 length = asm_insn_count (body) * insn_default_length (insn);
691 else if (GET_CODE (body) == SEQUENCE)
692 for (i = 0; i < XVECLEN (body, 0); i++)
693 length += get_attr_length (XVECEXP (body, 0, i));
694 else
695 length = insn_default_length (insn);
696 break;
697
698 default:
699 break;
700 }
701
702 #ifdef ADJUST_INSN_LENGTH
703 ADJUST_INSN_LENGTH (insn, length);
704 #endif
705 return length;
706 #else /* not HAVE_ATTR_length */
707 return 0;
708 #endif /* not HAVE_ATTR_length */
709 }
710 \f
711 /* Make a pass over all insns and compute their actual lengths by shortening
712 any branches of variable length if possible. */
713
714 /* Give a default value for the lowest address in a function. */
715
716 #ifndef FIRST_INSN_ADDRESS
717 #define FIRST_INSN_ADDRESS 0
718 #endif
719
720 void
721 shorten_branches (first)
722 rtx first;
723 {
724 #ifdef HAVE_ATTR_length
725 rtx insn;
726 int something_changed = 1;
727 int max_uid = 0;
728 char *varying_length;
729 rtx body;
730 int uid;
731
732 /* In order to make sure that all instructions have valid length info,
733 we must split them before we compute the address/length info. */
734
735 for (insn = NEXT_INSN (first); insn; insn = NEXT_INSN (insn))
736 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
737 insn = try_split (PATTERN (insn), insn, 1);
738
739 /* Compute maximum UID and allocate arrays. */
740 for (insn = first; insn; insn = NEXT_INSN (insn))
741 if (INSN_UID (insn) > max_uid)
742 max_uid = INSN_UID (insn);
743
744 max_uid++;
745 insn_lengths = (short *) oballoc (max_uid * sizeof (short));
746 insn_addresses = (int *) oballoc (max_uid * sizeof (int));
747 varying_length = (char *) oballoc (max_uid * sizeof (char));
748
749 /* Compute initial lengths, addresses, and varying flags for each insn. */
750 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
751 insn != 0;
752 insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
753 {
754 uid = INSN_UID (insn);
755 insn_addresses[uid] = insn_current_address;
756 insn_lengths[uid] = 0;
757 varying_length[uid] = 0;
758
759 if (GET_CODE (insn) == NOTE || GET_CODE (insn) == BARRIER
760 || GET_CODE (insn) == CODE_LABEL)
761 continue;
762 if (INSN_DELETED_P (insn))
763 continue;
764
765 body = PATTERN (insn);
766 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
767 {
768 /* This only takes room if read-only data goes into the text
769 section. */
770 #if !defined(READONLY_DATA_SECTION) || defined(JUMP_TABLES_IN_TEXT_SECTION)
771 int unitsize = GET_MODE_SIZE (GET_MODE (body));
772
773 insn_lengths[uid] = (XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC)
774 * GET_MODE_SIZE (GET_MODE (body)));
775
776 /* We don't know what address the ADDR_VEC/ADDR_DIFF_VEC will end
777 up at after branch shortening. As a result, it is impossible
778 to determine how much padding we need at this point. Therefore,
779 assume worst possible alignment. */
780 insn_lengths[uid] += unitsize - 1;
781
782 #else
783 ;
784 #endif
785 }
786 else if (asm_noperands (body) >= 0)
787 insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
788 else if (GET_CODE (body) == SEQUENCE)
789 {
790 int i;
791 int const_delay_slots;
792 #ifdef DELAY_SLOTS
793 const_delay_slots = const_num_delay_slots (XVECEXP (body, 0, 0));
794 #else
795 const_delay_slots = 0;
796 #endif
797 /* Inside a delay slot sequence, we do not do any branch shortening
798 if the shortening could change the number of delay slots
799 of the branch. */
800 for (i = 0; i < XVECLEN (body, 0); i++)
801 {
802 rtx inner_insn = XVECEXP (body, 0, i);
803 int inner_uid = INSN_UID (inner_insn);
804 int inner_length;
805
806 if (asm_noperands (PATTERN (XVECEXP (body, 0, i))) >= 0)
807 inner_length = (asm_insn_count (PATTERN (inner_insn))
808 * insn_default_length (inner_insn));
809 else
810 inner_length = insn_default_length (inner_insn);
811
812 insn_lengths[inner_uid] = inner_length;
813 if (const_delay_slots)
814 {
815 if ((varying_length[inner_uid]
816 = insn_variable_length_p (inner_insn)) != 0)
817 varying_length[uid] = 1;
818 insn_addresses[inner_uid] = (insn_current_address +
819 insn_lengths[uid]);
820 }
821 else
822 varying_length[inner_uid] = 0;
823 insn_lengths[uid] += inner_length;
824 }
825 }
826 else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
827 {
828 insn_lengths[uid] = insn_default_length (insn);
829 varying_length[uid] = insn_variable_length_p (insn);
830 }
831
832 /* If needed, do any adjustment. */
833 #ifdef ADJUST_INSN_LENGTH
834 ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
835 #endif
836 }
837
838 /* Now loop over all the insns finding varying length insns. For each,
839 get the current insn length. If it has changed, reflect the change.
840 When nothing changes for a full pass, we are done. */
841
842 while (something_changed)
843 {
844 something_changed = 0;
845 for (insn_current_address = FIRST_INSN_ADDRESS, insn = first;
846 insn != 0;
847 insn = NEXT_INSN (insn))
848 {
849 int new_length;
850 #ifdef SHORTEN_WITH_ADJUST_INSN_LENGTH
851 #ifdef ADJUST_INSN_LENGTH
852 int tmp_length;
853 #endif
854 #endif
855
856 uid = INSN_UID (insn);
857 insn_addresses[uid] = insn_current_address;
858 if (! varying_length[uid])
859 {
860 insn_current_address += insn_lengths[uid];
861 continue;
862 }
863 if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
864 {
865 int i;
866
867 body = PATTERN (insn);
868 new_length = 0;
869 for (i = 0; i < XVECLEN (body, 0); i++)
870 {
871 rtx inner_insn = XVECEXP (body, 0, i);
872 int inner_uid = INSN_UID (inner_insn);
873 int inner_length;
874
875 insn_addresses[inner_uid] = insn_current_address;
876
877 /* insn_current_length returns 0 for insns with a
878 non-varying length. */
879 if (! varying_length[inner_uid])
880 inner_length = insn_lengths[inner_uid];
881 else
882 inner_length = insn_current_length (inner_insn);
883
884 if (inner_length != insn_lengths[inner_uid])
885 {
886 insn_lengths[inner_uid] = inner_length;
887 something_changed = 1;
888 }
889 insn_current_address += insn_lengths[inner_uid];
890 new_length += inner_length;
891 }
892 }
893 else
894 {
895 new_length = insn_current_length (insn);
896 insn_current_address += new_length;
897 }
898
899 #ifdef SHORTEN_WITH_ADJUST_INSN_LENGTH
900 #ifdef ADJUST_INSN_LENGTH
901 /* If needed, do any adjustment. */
902 tmp_length = new_length;
903 ADJUST_INSN_LENGTH (insn, new_length);
904 insn_current_address += (new_length - tmp_length);
905 #endif
906 #endif
907
908 if (new_length != insn_lengths[uid])
909 {
910 insn_lengths[uid] = new_length;
911 something_changed = 1;
912 }
913 }
914 /* For a non-optimizing compile, do only a single pass. */
915 if (!optimize)
916 break;
917 }
918 #endif /* HAVE_ATTR_length */
919 }
920
921 #ifdef HAVE_ATTR_length
922 /* Given the body of an INSN known to be generated by an ASM statement, return
923 the number of machine instructions likely to be generated for this insn.
924 This is used to compute its length. */
925
926 static int
927 asm_insn_count (body)
928 rtx body;
929 {
930 char *template;
931 int count = 1;
932
933 if (GET_CODE (body) == ASM_INPUT)
934 template = XSTR (body, 0);
935 else
936 template = decode_asm_operands (body, NULL_PTR, NULL_PTR,
937 NULL_PTR, NULL_PTR);
938
939 for ( ; *template; template++)
940 if (IS_ASM_LOGICAL_LINE_SEPARATOR(*template) || *template == '\n')
941 count++;
942
943 return count;
944 }
945 #endif
946 \f
947 /* Output assembler code for the start of a function,
948 and initialize some of the variables in this file
949 for the new function. The label for the function and associated
950 assembler pseudo-ops have already been output in `assemble_start_function'.
951
952 FIRST is the first insn of the rtl for the function being compiled.
953 FILE is the file to write assembler code to.
954 OPTIMIZE is nonzero if we should eliminate redundant
955 test and compare insns. */
956
957 void
958 final_start_function (first, file, optimize)
959 rtx first;
960 FILE *file;
961 int optimize;
962 {
963 block_depth = 0;
964
965 this_is_asm_operands = 0;
966
967 #ifdef NON_SAVING_SETJMP
968 /* A function that calls setjmp should save and restore all the
969 call-saved registers on a system where longjmp clobbers them. */
970 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
971 {
972 int i;
973
974 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
975 if (!call_used_regs[i] && !call_fixed_regs[i])
976 regs_ever_live[i] = 1;
977 }
978 #endif
979
980 /* Initial line number is supposed to be output
981 before the function's prologue and label
982 so that the function's address will not appear to be
983 in the last statement of the preceding function. */
984 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
985 last_linenum = high_block_linenum = high_function_linenum
986 = NOTE_LINE_NUMBER (first);
987
988 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
989 /* Output DWARF definition of the function. */
990 if (dwarf2out_do_frame ())
991 dwarf2out_begin_prologue ();
992 #endif
993
994 /* For SDB and XCOFF, the function beginning must be marked between
995 the function label and the prologue. We always need this, even when
996 -g1 was used. Defer on MIPS systems so that parameter descriptions
997 follow function entry. */
998 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
999 if (write_symbols == SDB_DEBUG)
1000 sdbout_begin_function (last_linenum);
1001 else
1002 #endif
1003 #ifdef XCOFF_DEBUGGING_INFO
1004 if (write_symbols == XCOFF_DEBUG)
1005 xcoffout_begin_function (file, last_linenum);
1006 else
1007 #endif
1008 /* But only output line number for other debug info types if -g2
1009 or better. */
1010 if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
1011 output_source_line (file, first);
1012
1013 #ifdef LEAF_REG_REMAP
1014 if (leaf_function)
1015 leaf_renumber_regs (first);
1016 #endif
1017
1018 /* The Sun386i and perhaps other machines don't work right
1019 if the profiling code comes after the prologue. */
1020 #ifdef PROFILE_BEFORE_PROLOGUE
1021 if (profile_flag)
1022 profile_function (file);
1023 #endif /* PROFILE_BEFORE_PROLOGUE */
1024
1025 #if defined (DWARF2_UNWIND_INFO) && defined (HAVE_prologue)
1026 if (dwarf2out_do_frame ())
1027 dwarf2out_frame_debug (NULL_RTX);
1028 #endif
1029
1030 #ifdef FUNCTION_PROLOGUE
1031 /* First output the function prologue: code to set up the stack frame. */
1032 FUNCTION_PROLOGUE (file, get_frame_size ());
1033 #endif
1034
1035 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1036 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
1037 next_block_index = 1;
1038 #endif
1039
1040 /* If the machine represents the prologue as RTL, the profiling code must
1041 be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
1042 #ifdef HAVE_prologue
1043 if (! HAVE_prologue)
1044 #endif
1045 profile_after_prologue (file);
1046
1047 profile_label_no++;
1048
1049 /* If we are doing basic block profiling, remember a printable version
1050 of the function name. */
1051 if (profile_block_flag)
1052 {
1053 bb_func_label_num
1054 = add_bb_string ((*decl_printable_name) (current_function_decl, 2), FALSE);
1055 }
1056 }
1057
1058 static void
1059 profile_after_prologue (file)
1060 FILE *file;
1061 {
1062 #ifdef FUNCTION_BLOCK_PROFILER
1063 if (profile_block_flag)
1064 {
1065 FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
1066 }
1067 #endif /* FUNCTION_BLOCK_PROFILER */
1068
1069 #ifndef PROFILE_BEFORE_PROLOGUE
1070 if (profile_flag)
1071 profile_function (file);
1072 #endif /* not PROFILE_BEFORE_PROLOGUE */
1073 }
1074
1075 static void
1076 profile_function (file)
1077 FILE *file;
1078 {
1079 int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
1080 #if defined(ASM_OUTPUT_REG_PUSH)
1081 #if defined(STRUCT_VALUE_INCOMING_REGNUM) || defined(STRUCT_VALUE_REGNUM)
1082 int sval = current_function_returns_struct;
1083 #endif
1084 #if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
1085 int cxt = current_function_needs_context;
1086 #endif
1087 #endif /* ASM_OUTPUT_REG_PUSH */
1088
1089 data_section ();
1090 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
1091 ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
1092 assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, 1);
1093
1094 function_section (current_function_decl);
1095
1096 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1097 if (sval)
1098 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
1099 #else
1100 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1101 if (sval)
1102 {
1103 ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
1104 }
1105 #endif
1106 #endif
1107
1108 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1109 if (cxt)
1110 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
1111 #else
1112 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1113 if (cxt)
1114 {
1115 ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
1116 }
1117 #endif
1118 #endif
1119
1120 FUNCTION_PROFILER (file, profile_label_no);
1121
1122 #if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1123 if (cxt)
1124 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
1125 #else
1126 #if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1127 if (cxt)
1128 {
1129 ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
1130 }
1131 #endif
1132 #endif
1133
1134 #if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1135 if (sval)
1136 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
1137 #else
1138 #if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
1139 if (sval)
1140 {
1141 ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
1142 }
1143 #endif
1144 #endif
1145 }
1146
1147 /* Output assembler code for the end of a function.
1148 For clarity, args are same as those of `final_start_function'
1149 even though not all of them are needed. */
1150
1151 void
1152 final_end_function (first, file, optimize)
1153 rtx first;
1154 FILE *file;
1155 int optimize;
1156 {
1157 if (app_on)
1158 {
1159 fputs (ASM_APP_OFF, file);
1160 app_on = 0;
1161 }
1162
1163 #ifdef SDB_DEBUGGING_INFO
1164 if (write_symbols == SDB_DEBUG)
1165 sdbout_end_function (high_function_linenum);
1166 #endif
1167
1168 #ifdef DWARF_DEBUGGING_INFO
1169 if (write_symbols == DWARF_DEBUG)
1170 dwarfout_end_function ();
1171 #endif
1172
1173 #ifdef XCOFF_DEBUGGING_INFO
1174 if (write_symbols == XCOFF_DEBUG)
1175 xcoffout_end_function (file, high_function_linenum);
1176 #endif
1177
1178 #ifdef FUNCTION_EPILOGUE
1179 /* Finally, output the function epilogue:
1180 code to restore the stack frame and return to the caller. */
1181 FUNCTION_EPILOGUE (file, get_frame_size ());
1182 #endif
1183
1184 #ifdef SDB_DEBUGGING_INFO
1185 if (write_symbols == SDB_DEBUG)
1186 sdbout_end_epilogue ();
1187 #endif
1188
1189 #ifdef DWARF_DEBUGGING_INFO
1190 if (write_symbols == DWARF_DEBUG)
1191 dwarfout_end_epilogue ();
1192 #endif
1193
1194 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
1195 if (dwarf2out_do_frame ())
1196 dwarf2out_end_epilogue ();
1197 #endif
1198
1199 #ifdef XCOFF_DEBUGGING_INFO
1200 if (write_symbols == XCOFF_DEBUG)
1201 xcoffout_end_epilogue (file);
1202 #endif
1203
1204 bb_func_label_num = -1; /* not in function, nuke label # */
1205
1206 /* If FUNCTION_EPILOGUE is not defined, then the function body
1207 itself contains return instructions wherever needed. */
1208 }
1209 \f
1210 /* Add a block to the linked list that remembers the current line/file/function
1211 for basic block profiling. Emit the label in front of the basic block and
1212 the instructions that increment the count field. */
1213
1214 static void
1215 add_bb (file)
1216 FILE *file;
1217 {
1218 struct bb_list *ptr = (struct bb_list *) permalloc (sizeof (struct bb_list));
1219
1220 /* Add basic block to linked list. */
1221 ptr->next = 0;
1222 ptr->line_num = last_linenum;
1223 ptr->file_label_num = bb_file_label_num;
1224 ptr->func_label_num = bb_func_label_num;
1225 *bb_tail = ptr;
1226 bb_tail = &ptr->next;
1227
1228 /* Enable the table of basic-block use counts
1229 to point at the code it applies to. */
1230 ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
1231
1232 /* Before first insn of this basic block, increment the
1233 count of times it was entered. */
1234 #ifdef BLOCK_PROFILER
1235 BLOCK_PROFILER (file, count_basic_blocks);
1236 #endif
1237 #ifdef HAVE_cc0
1238 CC_STATUS_INIT;
1239 #endif
1240
1241 new_block = 0;
1242 count_basic_blocks++;
1243 }
1244
1245 /* Add a string to be used for basic block profiling. */
1246
1247 static int
1248 add_bb_string (string, perm_p)
1249 char *string;
1250 int perm_p;
1251 {
1252 int len;
1253 struct bb_str *ptr = 0;
1254
1255 if (!string)
1256 {
1257 string = "<unknown>";
1258 perm_p = TRUE;
1259 }
1260
1261 /* Allocate a new string if the current string isn't permanent. If
1262 the string is permanent search for the same string in other
1263 allocations. */
1264
1265 len = strlen (string) + 1;
1266 if (!perm_p)
1267 {
1268 char *p = (char *) permalloc (len);
1269 bcopy (string, p, len);
1270 string = p;
1271 }
1272 else
1273 for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
1274 if (ptr->string == string)
1275 break;
1276
1277 /* Allocate a new string block if we need to. */
1278 if (!ptr)
1279 {
1280 ptr = (struct bb_str *) permalloc (sizeof (*ptr));
1281 ptr->next = 0;
1282 ptr->length = len;
1283 ptr->label_num = sbb_label_num++;
1284 ptr->string = string;
1285 *sbb_tail = ptr;
1286 sbb_tail = &ptr->next;
1287 }
1288
1289 return ptr->label_num;
1290 }
1291
1292 \f
1293 /* Output assembler code for some insns: all or part of a function.
1294 For description of args, see `final_start_function', above.
1295
1296 PRESCAN is 1 if we are not really outputting,
1297 just scanning as if we were outputting.
1298 Prescanning deletes and rearranges insns just like ordinary output.
1299 PRESCAN is -2 if we are outputting after having prescanned.
1300 In this case, don't try to delete or rearrange insns
1301 because that has already been done.
1302 Prescanning is done only on certain machines. */
1303
1304 void
1305 final (first, file, optimize, prescan)
1306 rtx first;
1307 FILE *file;
1308 int optimize;
1309 int prescan;
1310 {
1311 register rtx insn;
1312 int max_line = 0;
1313
1314 last_ignored_compare = 0;
1315 new_block = 1;
1316
1317 check_exception_handler_labels ();
1318
1319 /* Make a map indicating which line numbers appear in this function.
1320 When producing SDB debugging info, delete troublesome line number
1321 notes from inlined functions in other files as well as duplicate
1322 line number notes. */
1323 #ifdef SDB_DEBUGGING_INFO
1324 if (write_symbols == SDB_DEBUG)
1325 {
1326 rtx last = 0;
1327 for (insn = first; insn; insn = NEXT_INSN (insn))
1328 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1329 {
1330 if ((RTX_INTEGRATED_P (insn)
1331 && strcmp (NOTE_SOURCE_FILE (insn), main_input_filename) != 0)
1332 || (last != 0
1333 && NOTE_LINE_NUMBER (insn) == NOTE_LINE_NUMBER (last)
1334 && NOTE_SOURCE_FILE (insn) == NOTE_SOURCE_FILE (last)))
1335 {
1336 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1337 NOTE_SOURCE_FILE (insn) = 0;
1338 continue;
1339 }
1340 last = insn;
1341 if (NOTE_LINE_NUMBER (insn) > max_line)
1342 max_line = NOTE_LINE_NUMBER (insn);
1343 }
1344 }
1345 else
1346 #endif
1347 {
1348 for (insn = first; insn; insn = NEXT_INSN (insn))
1349 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > max_line)
1350 max_line = NOTE_LINE_NUMBER (insn);
1351 }
1352
1353 line_note_exists = (char *) oballoc (max_line + 1);
1354 bzero (line_note_exists, max_line + 1);
1355
1356 for (insn = first; insn; insn = NEXT_INSN (insn))
1357 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
1358 line_note_exists[NOTE_LINE_NUMBER (insn)] = 1;
1359
1360 init_recog ();
1361
1362 CC_STATUS_INIT;
1363
1364 /* Output the insns. */
1365 for (insn = NEXT_INSN (first); insn;)
1366 {
1367 #ifdef HAVE_ATTR_length
1368 insn_current_address = insn_addresses[INSN_UID (insn)];
1369 #endif
1370 insn = final_scan_insn (insn, file, optimize, prescan, 0);
1371 }
1372
1373 /* Do basic-block profiling here
1374 if the last insn was a conditional branch. */
1375 if (profile_block_flag && new_block)
1376 add_bb (file);
1377 }
1378 \f
1379 /* The final scan for one insn, INSN.
1380 Args are same as in `final', except that INSN
1381 is the insn being scanned.
1382 Value returned is the next insn to be scanned.
1383
1384 NOPEEPHOLES is the flag to disallow peephole processing (currently
1385 used for within delayed branch sequence output). */
1386
1387 rtx
1388 final_scan_insn (insn, file, optimize, prescan, nopeepholes)
1389 rtx insn;
1390 FILE *file;
1391 int optimize;
1392 int prescan;
1393 int nopeepholes;
1394 {
1395 register int i;
1396 #ifdef HAVE_cc0
1397 rtx set;
1398 #endif
1399
1400 insn_counter++;
1401
1402 /* Ignore deleted insns. These can occur when we split insns (due to a
1403 template of "#") while not optimizing. */
1404 if (INSN_DELETED_P (insn))
1405 return NEXT_INSN (insn);
1406
1407 switch (GET_CODE (insn))
1408 {
1409 case NOTE:
1410 if (prescan > 0)
1411 break;
1412
1413 /* Align the beginning of a loop, for higher speed
1414 on certain machines. */
1415
1416 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG && optimize > 0)
1417 {
1418 #ifdef ASM_OUTPUT_LOOP_ALIGN
1419 rtx next = next_nonnote_insn (insn);
1420 if (next && GET_CODE (next) == CODE_LABEL)
1421 {
1422 ASM_OUTPUT_LOOP_ALIGN (asm_out_file);
1423 }
1424 #endif
1425 break;
1426 }
1427 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
1428 break;
1429
1430 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG
1431 && ! exceptions_via_longjmp)
1432 {
1433 ASM_OUTPUT_INTERNAL_LABEL (file, "LEHB", NOTE_BLOCK_NUMBER (insn));
1434 add_eh_table_entry (NOTE_BLOCK_NUMBER (insn));
1435 #ifdef ASM_OUTPUT_EH_REGION_BEG
1436 ASM_OUTPUT_EH_REGION_BEG (file, NOTE_BLOCK_NUMBER (insn));
1437 #endif
1438 break;
1439 }
1440
1441 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END
1442 && ! exceptions_via_longjmp)
1443 {
1444 ASM_OUTPUT_INTERNAL_LABEL (file, "LEHE", NOTE_BLOCK_NUMBER (insn));
1445 #ifdef ASM_OUTPUT_EH_REGION_END
1446 ASM_OUTPUT_EH_REGION_END (file, NOTE_BLOCK_NUMBER (insn));
1447 #endif
1448 break;
1449 }
1450
1451 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
1452 {
1453 #ifdef FUNCTION_END_PROLOGUE
1454 FUNCTION_END_PROLOGUE (file);
1455 #endif
1456 profile_after_prologue (file);
1457 break;
1458 }
1459
1460 #ifdef FUNCTION_BEGIN_EPILOGUE
1461 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
1462 {
1463 FUNCTION_BEGIN_EPILOGUE (file);
1464 break;
1465 }
1466 #endif
1467
1468 if (write_symbols == NO_DEBUG)
1469 break;
1470 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
1471 {
1472 #if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
1473 /* MIPS stabs require the parameter descriptions to be after the
1474 function entry point rather than before. */
1475 if (write_symbols == SDB_DEBUG)
1476 sdbout_begin_function (last_linenum);
1477 else
1478 #endif
1479 #ifdef DWARF_DEBUGGING_INFO
1480 /* This outputs a marker where the function body starts, so it
1481 must be after the prologue. */
1482 if (write_symbols == DWARF_DEBUG)
1483 dwarfout_begin_function ();
1484 #endif
1485 break;
1486 }
1487 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
1488 break; /* An insn that was "deleted" */
1489 if (app_on)
1490 {
1491 fputs (ASM_APP_OFF, file);
1492 app_on = 0;
1493 }
1494 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
1495 && (debug_info_level == DINFO_LEVEL_NORMAL
1496 || debug_info_level == DINFO_LEVEL_VERBOSE
1497 || write_symbols == DWARF_DEBUG
1498 || write_symbols == DWARF2_DEBUG))
1499 {
1500 /* Beginning of a symbol-block. Assign it a sequence number
1501 and push the number onto the stack PENDING_BLOCKS. */
1502
1503 if (block_depth == max_block_depth)
1504 {
1505 /* PENDING_BLOCKS is full; make it longer. */
1506 max_block_depth *= 2;
1507 pending_blocks
1508 = (int *) xrealloc (pending_blocks,
1509 max_block_depth * sizeof (int));
1510 }
1511 pending_blocks[block_depth++] = next_block_index;
1512
1513 high_block_linenum = last_linenum;
1514
1515 /* Output debugging info about the symbol-block beginning. */
1516
1517 #ifdef SDB_DEBUGGING_INFO
1518 if (write_symbols == SDB_DEBUG)
1519 sdbout_begin_block (file, last_linenum, next_block_index);
1520 #endif
1521 #ifdef XCOFF_DEBUGGING_INFO
1522 if (write_symbols == XCOFF_DEBUG)
1523 xcoffout_begin_block (file, last_linenum, next_block_index);
1524 #endif
1525 #ifdef DBX_DEBUGGING_INFO
1526 if (write_symbols == DBX_DEBUG)
1527 ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
1528 #endif
1529 #ifdef DWARF_DEBUGGING_INFO
1530 if (write_symbols == DWARF_DEBUG)
1531 dwarfout_begin_block (next_block_index);
1532 #endif
1533 #ifdef DWARF2_DEBUGGING_INFO
1534 if (write_symbols == DWARF2_DEBUG)
1535 dwarf2out_begin_block (next_block_index);
1536 #endif
1537
1538 next_block_index++;
1539 }
1540 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
1541 && (debug_info_level == DINFO_LEVEL_NORMAL
1542 || debug_info_level == DINFO_LEVEL_VERBOSE
1543 || write_symbols == DWARF_DEBUG
1544 || write_symbols == DWARF2_DEBUG))
1545 {
1546 /* End of a symbol-block. Pop its sequence number off
1547 PENDING_BLOCKS and output debugging info based on that. */
1548
1549 --block_depth;
1550
1551 #ifdef XCOFF_DEBUGGING_INFO
1552 if (write_symbols == XCOFF_DEBUG && block_depth >= 0)
1553 xcoffout_end_block (file, high_block_linenum,
1554 pending_blocks[block_depth]);
1555 #endif
1556 #ifdef DBX_DEBUGGING_INFO
1557 if (write_symbols == DBX_DEBUG && block_depth >= 0)
1558 ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
1559 pending_blocks[block_depth]);
1560 #endif
1561 #ifdef SDB_DEBUGGING_INFO
1562 if (write_symbols == SDB_DEBUG && block_depth >= 0)
1563 sdbout_end_block (file, high_block_linenum,
1564 pending_blocks[block_depth]);
1565 #endif
1566 #ifdef DWARF_DEBUGGING_INFO
1567 if (write_symbols == DWARF_DEBUG && block_depth >= 0)
1568 dwarfout_end_block (pending_blocks[block_depth]);
1569 #endif
1570 #ifdef DWARF2_DEBUGGING_INFO
1571 if (write_symbols == DWARF2_DEBUG && block_depth >= 0)
1572 dwarf2out_end_block (pending_blocks[block_depth]);
1573 #endif
1574 }
1575 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
1576 && (debug_info_level == DINFO_LEVEL_NORMAL
1577 || debug_info_level == DINFO_LEVEL_VERBOSE))
1578 {
1579 #ifdef DWARF_DEBUGGING_INFO
1580 if (write_symbols == DWARF_DEBUG)
1581 dwarfout_label (insn);
1582 #endif
1583 #ifdef DWARF2_DEBUGGING_INFO
1584 if (write_symbols == DWARF2_DEBUG)
1585 dwarf2out_label (insn);
1586 #endif
1587 }
1588 else if (NOTE_LINE_NUMBER (insn) > 0)
1589 /* This note is a line-number. */
1590 {
1591 register rtx note;
1592
1593 #if 0 /* This is what we used to do. */
1594 output_source_line (file, insn);
1595 #endif
1596 int note_after = 0;
1597
1598 /* If there is anything real after this note,
1599 output it. If another line note follows, omit this one. */
1600 for (note = NEXT_INSN (insn); note; note = NEXT_INSN (note))
1601 {
1602 if (GET_CODE (note) != NOTE && GET_CODE (note) != CODE_LABEL)
1603 break;
1604 /* These types of notes can be significant
1605 so make sure the preceding line number stays. */
1606 else if (GET_CODE (note) == NOTE
1607 && (NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_BEG
1608 || NOTE_LINE_NUMBER (note) == NOTE_INSN_BLOCK_END
1609 || NOTE_LINE_NUMBER (note) == NOTE_INSN_FUNCTION_BEG))
1610 break;
1611 else if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) > 0)
1612 {
1613 /* Another line note follows; we can delete this note
1614 if no intervening line numbers have notes elsewhere. */
1615 int num;
1616 for (num = NOTE_LINE_NUMBER (insn) + 1;
1617 num < NOTE_LINE_NUMBER (note);
1618 num++)
1619 if (line_note_exists[num])
1620 break;
1621
1622 if (num >= NOTE_LINE_NUMBER (note))
1623 note_after = 1;
1624 break;
1625 }
1626 }
1627
1628 /* Output this line note
1629 if it is the first or the last line note in a row. */
1630 if (!note_after)
1631 output_source_line (file, insn);
1632 }
1633 break;
1634
1635 case BARRIER:
1636 #ifdef ASM_OUTPUT_ALIGN_CODE
1637 /* Don't litter the assembler output with needless alignments. A
1638 BARRIER will be placed at the end of every function if HAVE_epilogue
1639 is true. */
1640 if (NEXT_INSN (insn))
1641 ASM_OUTPUT_ALIGN_CODE (file);
1642 #endif
1643 #if defined (DWARF2_UNWIND_INFO) && !defined (ACCUMULATE_OUTGOING_ARGS)
1644 /* If we push arguments, we need to check all insns for stack
1645 adjustments. */
1646 if (dwarf2out_do_frame ())
1647 dwarf2out_frame_debug (insn);
1648 #endif
1649 break;
1650
1651 case CODE_LABEL:
1652 CC_STATUS_INIT;
1653 if (prescan > 0)
1654 break;
1655 new_block = 1;
1656
1657 #ifdef FINAL_PRESCAN_LABEL
1658 FINAL_PRESCAN_INSN (insn, NULL_PTR, 0);
1659 #endif
1660
1661 #ifdef SDB_DEBUGGING_INFO
1662 if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
1663 sdbout_label (insn);
1664 #endif
1665 #ifdef DWARF_DEBUGGING_INFO
1666 if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
1667 dwarfout_label (insn);
1668 #endif
1669 #ifdef DWARF2_DEBUGGING_INFO
1670 if (write_symbols == DWARF2_DEBUG && LABEL_NAME (insn))
1671 dwarf2out_label (insn);
1672 #endif
1673 if (app_on)
1674 {
1675 fputs (ASM_APP_OFF, file);
1676 app_on = 0;
1677 }
1678 if (NEXT_INSN (insn) != 0
1679 && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
1680 {
1681 rtx nextbody = PATTERN (NEXT_INSN (insn));
1682
1683 /* If this label is followed by a jump-table,
1684 make sure we put the label in the read-only section. Also
1685 possibly write the label and jump table together. */
1686
1687 if (GET_CODE (nextbody) == ADDR_VEC
1688 || GET_CODE (nextbody) == ADDR_DIFF_VEC)
1689 {
1690 #ifndef JUMP_TABLES_IN_TEXT_SECTION
1691 readonly_data_section ();
1692 #ifdef READONLY_DATA_SECTION
1693 ASM_OUTPUT_ALIGN (file,
1694 exact_log2 (BIGGEST_ALIGNMENT
1695 / BITS_PER_UNIT));
1696 #endif /* READONLY_DATA_SECTION */
1697 #else /* JUMP_TABLES_IN_TEXT_SECTION */
1698 function_section (current_function_decl);
1699 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
1700 #ifdef ASM_OUTPUT_CASE_LABEL
1701 ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
1702 NEXT_INSN (insn));
1703 #else
1704 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1705 #endif
1706 break;
1707 }
1708 }
1709
1710 ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
1711 break;
1712
1713 default:
1714 {
1715 register rtx body = PATTERN (insn);
1716 int insn_code_number;
1717 char *template;
1718 #ifdef HAVE_cc0
1719 rtx note;
1720 #endif
1721
1722 /* An INSN, JUMP_INSN or CALL_INSN.
1723 First check for special kinds that recog doesn't recognize. */
1724
1725 if (GET_CODE (body) == USE /* These are just declarations */
1726 || GET_CODE (body) == CLOBBER)
1727 break;
1728
1729 #ifdef HAVE_cc0
1730 /* If there is a REG_CC_SETTER note on this insn, it means that
1731 the setting of the condition code was done in the delay slot
1732 of the insn that branched here. So recover the cc status
1733 from the insn that set it. */
1734
1735 note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1736 if (note)
1737 {
1738 NOTICE_UPDATE_CC (PATTERN (XEXP (note, 0)), XEXP (note, 0));
1739 cc_prev_status = cc_status;
1740 }
1741 #endif
1742
1743 /* Detect insns that are really jump-tables
1744 and output them as such. */
1745
1746 if (GET_CODE (body) == ADDR_VEC || GET_CODE (body) == ADDR_DIFF_VEC)
1747 {
1748 register int vlen, idx;
1749
1750 if (prescan > 0)
1751 break;
1752
1753 if (app_on)
1754 {
1755 fputs (ASM_APP_OFF, file);
1756 app_on = 0;
1757 }
1758
1759 vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
1760 for (idx = 0; idx < vlen; idx++)
1761 {
1762 if (GET_CODE (body) == ADDR_VEC)
1763 {
1764 #ifdef ASM_OUTPUT_ADDR_VEC_ELT
1765 ASM_OUTPUT_ADDR_VEC_ELT
1766 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
1767 #else
1768 abort ();
1769 #endif
1770 }
1771 else
1772 {
1773 #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
1774 ASM_OUTPUT_ADDR_DIFF_ELT
1775 (file,
1776 CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
1777 CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
1778 #else
1779 abort ();
1780 #endif
1781 }
1782 }
1783 #ifdef ASM_OUTPUT_CASE_END
1784 ASM_OUTPUT_CASE_END (file,
1785 CODE_LABEL_NUMBER (PREV_INSN (insn)),
1786 insn);
1787 #endif
1788
1789 function_section (current_function_decl);
1790
1791 break;
1792 }
1793
1794 /* Do basic-block profiling when we reach a new block.
1795 Done here to avoid jump tables. */
1796 if (profile_block_flag && new_block)
1797 add_bb (file);
1798
1799 if (GET_CODE (body) == ASM_INPUT)
1800 {
1801 /* There's no telling what that did to the condition codes. */
1802 CC_STATUS_INIT;
1803 if (prescan > 0)
1804 break;
1805 if (! app_on)
1806 {
1807 fputs (ASM_APP_ON, file);
1808 app_on = 1;
1809 }
1810 fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
1811 break;
1812 }
1813
1814 /* Detect `asm' construct with operands. */
1815 if (asm_noperands (body) >= 0)
1816 {
1817 int noperands = asm_noperands (body);
1818 rtx *ops = (rtx *) alloca (noperands * sizeof (rtx));
1819 char *string;
1820
1821 /* There's no telling what that did to the condition codes. */
1822 CC_STATUS_INIT;
1823 if (prescan > 0)
1824 break;
1825
1826 if (! app_on)
1827 {
1828 fputs (ASM_APP_ON, file);
1829 app_on = 1;
1830 }
1831
1832 /* Get out the operand values. */
1833 string = decode_asm_operands (body, ops, NULL_PTR,
1834 NULL_PTR, NULL_PTR);
1835 /* Inhibit aborts on what would otherwise be compiler bugs. */
1836 insn_noperands = noperands;
1837 this_is_asm_operands = insn;
1838
1839 /* Output the insn using them. */
1840 output_asm_insn (string, ops);
1841 this_is_asm_operands = 0;
1842 break;
1843 }
1844
1845 if (prescan <= 0 && app_on)
1846 {
1847 fputs (ASM_APP_OFF, file);
1848 app_on = 0;
1849 }
1850
1851 if (GET_CODE (body) == SEQUENCE)
1852 {
1853 /* A delayed-branch sequence */
1854 register int i;
1855 rtx next;
1856
1857 if (prescan > 0)
1858 break;
1859 final_sequence = body;
1860
1861 /* The first insn in this SEQUENCE might be a JUMP_INSN that will
1862 force the restoration of a comparison that was previously
1863 thought unnecessary. If that happens, cancel this sequence
1864 and cause that insn to be restored. */
1865
1866 next = final_scan_insn (XVECEXP (body, 0, 0), file, 0, prescan, 1);
1867 if (next != XVECEXP (body, 0, 1))
1868 {
1869 final_sequence = 0;
1870 return next;
1871 }
1872
1873 for (i = 1; i < XVECLEN (body, 0); i++)
1874 {
1875 rtx insn = XVECEXP (body, 0, i);
1876 rtx next = NEXT_INSN (insn);
1877 /* We loop in case any instruction in a delay slot gets
1878 split. */
1879 do
1880 insn = final_scan_insn (insn, file, 0, prescan, 1);
1881 while (insn != next);
1882 }
1883 #ifdef DBR_OUTPUT_SEQEND
1884 DBR_OUTPUT_SEQEND (file);
1885 #endif
1886 final_sequence = 0;
1887
1888 /* If the insn requiring the delay slot was a CALL_INSN, the
1889 insns in the delay slot are actually executed before the
1890 called function. Hence we don't preserve any CC-setting
1891 actions in these insns and the CC must be marked as being
1892 clobbered by the function. */
1893 if (GET_CODE (XVECEXP (body, 0, 0)) == CALL_INSN)
1894 {
1895 CC_STATUS_INIT;
1896 }
1897
1898 /* Following a conditional branch sequence, we have a new basic
1899 block. */
1900 if (profile_block_flag)
1901 {
1902 rtx insn = XVECEXP (body, 0, 0);
1903 rtx body = PATTERN (insn);
1904
1905 if ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1906 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1907 || (GET_CODE (insn) == JUMP_INSN
1908 && GET_CODE (body) == PARALLEL
1909 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1910 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF))
1911 new_block = 1;
1912 }
1913 break;
1914 }
1915
1916 /* We have a real machine instruction as rtl. */
1917
1918 body = PATTERN (insn);
1919
1920 #ifdef HAVE_cc0
1921 set = single_set(insn);
1922
1923 /* Check for redundant test and compare instructions
1924 (when the condition codes are already set up as desired).
1925 This is done only when optimizing; if not optimizing,
1926 it should be possible for the user to alter a variable
1927 with the debugger in between statements
1928 and the next statement should reexamine the variable
1929 to compute the condition codes. */
1930
1931 if (optimize)
1932 {
1933 #if 0
1934 rtx set = single_set(insn);
1935 #endif
1936
1937 if (set
1938 && GET_CODE (SET_DEST (set)) == CC0
1939 && insn != last_ignored_compare)
1940 {
1941 if (GET_CODE (SET_SRC (set)) == SUBREG)
1942 SET_SRC (set) = alter_subreg (SET_SRC (set));
1943 else if (GET_CODE (SET_SRC (set)) == COMPARE)
1944 {
1945 if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
1946 XEXP (SET_SRC (set), 0)
1947 = alter_subreg (XEXP (SET_SRC (set), 0));
1948 if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
1949 XEXP (SET_SRC (set), 1)
1950 = alter_subreg (XEXP (SET_SRC (set), 1));
1951 }
1952 if ((cc_status.value1 != 0
1953 && rtx_equal_p (SET_SRC (set), cc_status.value1))
1954 || (cc_status.value2 != 0
1955 && rtx_equal_p (SET_SRC (set), cc_status.value2)))
1956 {
1957 /* Don't delete insn if it has an addressing side-effect. */
1958 if (! FIND_REG_INC_NOTE (insn, 0)
1959 /* or if anything in it is volatile. */
1960 && ! volatile_refs_p (PATTERN (insn)))
1961 {
1962 /* We don't really delete the insn; just ignore it. */
1963 last_ignored_compare = insn;
1964 break;
1965 }
1966 }
1967 }
1968 }
1969 #endif
1970
1971 /* Following a conditional branch, we have a new basic block.
1972 But if we are inside a sequence, the new block starts after the
1973 last insn of the sequence. */
1974 if (profile_block_flag && final_sequence == 0
1975 && ((GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
1976 && GET_CODE (SET_SRC (body)) != LABEL_REF)
1977 || (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == PARALLEL
1978 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1979 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) != LABEL_REF)))
1980 new_block = 1;
1981
1982 #ifndef STACK_REGS
1983 /* Don't bother outputting obvious no-ops, even without -O.
1984 This optimization is fast and doesn't interfere with debugging.
1985 Don't do this if the insn is in a delay slot, since this
1986 will cause an improper number of delay insns to be written. */
1987 if (final_sequence == 0
1988 && prescan >= 0
1989 && GET_CODE (insn) == INSN && GET_CODE (body) == SET
1990 && GET_CODE (SET_SRC (body)) == REG
1991 && GET_CODE (SET_DEST (body)) == REG
1992 && REGNO (SET_SRC (body)) == REGNO (SET_DEST (body)))
1993 break;
1994 #endif
1995
1996 #ifdef HAVE_cc0
1997 /* If this is a conditional branch, maybe modify it
1998 if the cc's are in a nonstandard state
1999 so that it accomplishes the same thing that it would
2000 do straightforwardly if the cc's were set up normally. */
2001
2002 if (cc_status.flags != 0
2003 && GET_CODE (insn) == JUMP_INSN
2004 && GET_CODE (body) == SET
2005 && SET_DEST (body) == pc_rtx
2006 && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2007 && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
2008 && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
2009 /* This is done during prescan; it is not done again
2010 in final scan when prescan has been done. */
2011 && prescan >= 0)
2012 {
2013 /* This function may alter the contents of its argument
2014 and clear some of the cc_status.flags bits.
2015 It may also return 1 meaning condition now always true
2016 or -1 meaning condition now always false
2017 or 2 meaning condition nontrivial but altered. */
2018 register int result = alter_cond (XEXP (SET_SRC (body), 0));
2019 /* If condition now has fixed value, replace the IF_THEN_ELSE
2020 with its then-operand or its else-operand. */
2021 if (result == 1)
2022 SET_SRC (body) = XEXP (SET_SRC (body), 1);
2023 if (result == -1)
2024 SET_SRC (body) = XEXP (SET_SRC (body), 2);
2025
2026 /* The jump is now either unconditional or a no-op.
2027 If it has become a no-op, don't try to output it.
2028 (It would not be recognized.) */
2029 if (SET_SRC (body) == pc_rtx)
2030 {
2031 PUT_CODE (insn, NOTE);
2032 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2033 NOTE_SOURCE_FILE (insn) = 0;
2034 break;
2035 }
2036 else if (GET_CODE (SET_SRC (body)) == RETURN)
2037 /* Replace (set (pc) (return)) with (return). */
2038 PATTERN (insn) = body = SET_SRC (body);
2039
2040 /* Rerecognize the instruction if it has changed. */
2041 if (result != 0)
2042 INSN_CODE (insn) = -1;
2043 }
2044
2045 /* Make same adjustments to instructions that examine the
2046 condition codes without jumping and instructions that
2047 handle conditional moves (if this machine has either one). */
2048
2049 if (cc_status.flags != 0
2050 && set != 0)
2051 {
2052 rtx cond_rtx, then_rtx, else_rtx;
2053
2054 if (GET_CODE (insn) != JUMP_INSN
2055 && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
2056 {
2057 cond_rtx = XEXP (SET_SRC (set), 0);
2058 then_rtx = XEXP (SET_SRC (set), 1);
2059 else_rtx = XEXP (SET_SRC (set), 2);
2060 }
2061 else
2062 {
2063 cond_rtx = SET_SRC (set);
2064 then_rtx = const_true_rtx;
2065 else_rtx = const0_rtx;
2066 }
2067
2068 switch (GET_CODE (cond_rtx))
2069 {
2070 case GTU:
2071 case GT:
2072 case LTU:
2073 case LT:
2074 case GEU:
2075 case GE:
2076 case LEU:
2077 case LE:
2078 case EQ:
2079 case NE:
2080 {
2081 register int result;
2082 if (XEXP (cond_rtx, 0) != cc0_rtx)
2083 break;
2084 result = alter_cond (cond_rtx);
2085 if (result == 1)
2086 validate_change (insn, &SET_SRC (set), then_rtx, 0);
2087 else if (result == -1)
2088 validate_change (insn, &SET_SRC (set), else_rtx, 0);
2089 else if (result == 2)
2090 INSN_CODE (insn) = -1;
2091 if (SET_DEST (set) == SET_SRC (set))
2092 {
2093 PUT_CODE (insn, NOTE);
2094 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2095 NOTE_SOURCE_FILE (insn) = 0;
2096 }
2097 }
2098 break;
2099
2100 default:
2101 break;
2102 }
2103 }
2104
2105 #endif
2106
2107 /* Do machine-specific peephole optimizations if desired. */
2108
2109 if (optimize && !flag_no_peephole && !nopeepholes)
2110 {
2111 rtx next = peephole (insn);
2112 /* When peepholing, if there were notes within the peephole,
2113 emit them before the peephole. */
2114 if (next != 0 && next != NEXT_INSN (insn))
2115 {
2116 rtx prev = PREV_INSN (insn);
2117 rtx note;
2118
2119 for (note = NEXT_INSN (insn); note != next;
2120 note = NEXT_INSN (note))
2121 final_scan_insn (note, file, optimize, prescan, nopeepholes);
2122
2123 /* In case this is prescan, put the notes
2124 in proper position for later rescan. */
2125 note = NEXT_INSN (insn);
2126 PREV_INSN (note) = prev;
2127 NEXT_INSN (prev) = note;
2128 NEXT_INSN (PREV_INSN (next)) = insn;
2129 PREV_INSN (insn) = PREV_INSN (next);
2130 NEXT_INSN (insn) = next;
2131 PREV_INSN (next) = insn;
2132 }
2133
2134 /* PEEPHOLE might have changed this. */
2135 body = PATTERN (insn);
2136 }
2137
2138 /* Try to recognize the instruction.
2139 If successful, verify that the operands satisfy the
2140 constraints for the instruction. Crash if they don't,
2141 since `reload' should have changed them so that they do. */
2142
2143 insn_code_number = recog_memoized (insn);
2144 insn_extract (insn);
2145 for (i = 0; i < insn_n_operands[insn_code_number]; i++)
2146 {
2147 if (GET_CODE (recog_operand[i]) == SUBREG)
2148 recog_operand[i] = alter_subreg (recog_operand[i]);
2149 else if (GET_CODE (recog_operand[i]) == PLUS
2150 || GET_CODE (recog_operand[i]) == MULT)
2151 recog_operand[i] = walk_alter_subreg (recog_operand[i]);
2152 }
2153
2154 for (i = 0; i < insn_n_dups[insn_code_number]; i++)
2155 {
2156 if (GET_CODE (*recog_dup_loc[i]) == SUBREG)
2157 *recog_dup_loc[i] = alter_subreg (*recog_dup_loc[i]);
2158 else if (GET_CODE (*recog_dup_loc[i]) == PLUS
2159 || GET_CODE (*recog_dup_loc[i]) == MULT)
2160 *recog_dup_loc[i] = walk_alter_subreg (*recog_dup_loc[i]);
2161 }
2162
2163 #ifdef REGISTER_CONSTRAINTS
2164 if (! constrain_operands (insn_code_number, 1))
2165 fatal_insn_not_found (insn);
2166 #endif
2167
2168 /* Some target machines need to prescan each insn before
2169 it is output. */
2170
2171 #ifdef FINAL_PRESCAN_INSN
2172 FINAL_PRESCAN_INSN (insn, recog_operand,
2173 insn_n_operands[insn_code_number]);
2174 #endif
2175
2176 #ifdef HAVE_cc0
2177 cc_prev_status = cc_status;
2178
2179 /* Update `cc_status' for this instruction.
2180 The instruction's output routine may change it further.
2181 If the output routine for a jump insn needs to depend
2182 on the cc status, it should look at cc_prev_status. */
2183
2184 NOTICE_UPDATE_CC (body, insn);
2185 #endif
2186
2187 debug_insn = insn;
2188
2189 #if defined (DWARF2_UNWIND_INFO) && !defined (ACCUMULATE_OUTGOING_ARGS)
2190 /* If we push arguments, we want to know where the calls are. */
2191 if (GET_CODE (insn) == CALL_INSN && dwarf2out_do_frame ())
2192 dwarf2out_frame_debug (insn);
2193 #endif
2194
2195 /* If the proper template needs to be chosen by some C code,
2196 run that code and get the real template. */
2197
2198 template = insn_template[insn_code_number];
2199 if (template == 0)
2200 {
2201 template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
2202
2203 /* If the C code returns 0, it means that it is a jump insn
2204 which follows a deleted test insn, and that test insn
2205 needs to be reinserted. */
2206 if (template == 0)
2207 {
2208 if (prev_nonnote_insn (insn) != last_ignored_compare)
2209 abort ();
2210 new_block = 0;
2211 return prev_nonnote_insn (insn);
2212 }
2213 }
2214
2215 /* If the template is the string "#", it means that this insn must
2216 be split. */
2217 if (template[0] == '#' && template[1] == '\0')
2218 {
2219 rtx new = try_split (body, insn, 0);
2220
2221 /* If we didn't split the insn, go away. */
2222 if (new == insn && PATTERN (new) == body)
2223 abort ();
2224
2225 #ifdef HAVE_ATTR_length
2226 /* This instruction should have been split in shorten_branches,
2227 to ensure that we would have valid length info for the
2228 splitees. */
2229 abort ();
2230 #endif
2231
2232 new_block = 0;
2233 return new;
2234 }
2235
2236 if (prescan > 0)
2237 break;
2238
2239 /* Output assembler code from the template. */
2240
2241 output_asm_insn (template, recog_operand);
2242
2243 #if defined (DWARF2_UNWIND_INFO)
2244 #if !defined (ACCUMULATE_OUTGOING_ARGS)
2245 /* If we push arguments, we need to check all insns for stack
2246 adjustments. */
2247 if (GET_CODE (insn) == INSN && dwarf2out_do_frame ())
2248 dwarf2out_frame_debug (insn);
2249 #else
2250 #if defined (HAVE_prologue)
2251 /* If this insn is part of the prologue, emit DWARF v2
2252 call frame info. */
2253 if (RTX_FRAME_RELATED_P (insn) && dwarf2out_do_frame ())
2254 dwarf2out_frame_debug (insn);
2255 #endif
2256 #endif
2257 #endif
2258
2259 #if 0
2260 /* It's not at all clear why we did this and doing so interferes
2261 with tests we'd like to do to use REG_WAS_0 notes, so let's try
2262 with this out. */
2263
2264 /* Mark this insn as having been output. */
2265 INSN_DELETED_P (insn) = 1;
2266 #endif
2267
2268 debug_insn = 0;
2269 }
2270 }
2271 return NEXT_INSN (insn);
2272 }
2273 \f
2274 /* Output debugging info to the assembler file FILE
2275 based on the NOTE-insn INSN, assumed to be a line number. */
2276
2277 static void
2278 output_source_line (file, insn)
2279 FILE *file;
2280 rtx insn;
2281 {
2282 register char *filename = NOTE_SOURCE_FILE (insn);
2283
2284 /* Remember filename for basic block profiling.
2285 Filenames are allocated on the permanent obstack
2286 or are passed in ARGV, so we don't have to save
2287 the string. */
2288
2289 if (profile_block_flag && last_filename != filename)
2290 bb_file_label_num = add_bb_string (filename, TRUE);
2291
2292 last_filename = filename;
2293 last_linenum = NOTE_LINE_NUMBER (insn);
2294 high_block_linenum = MAX (last_linenum, high_block_linenum);
2295 high_function_linenum = MAX (last_linenum, high_function_linenum);
2296
2297 if (write_symbols != NO_DEBUG)
2298 {
2299 #ifdef SDB_DEBUGGING_INFO
2300 if (write_symbols == SDB_DEBUG
2301 #if 0 /* People like having line numbers even in wrong file! */
2302 /* COFF can't handle multiple source files--lose, lose. */
2303 && !strcmp (filename, main_input_filename)
2304 #endif
2305 /* COFF relative line numbers must be positive. */
2306 && last_linenum > sdb_begin_function_line)
2307 {
2308 #ifdef ASM_OUTPUT_SOURCE_LINE
2309 ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
2310 #else
2311 fprintf (file, "\t.ln\t%d\n",
2312 ((sdb_begin_function_line > -1)
2313 ? last_linenum - sdb_begin_function_line : 1));
2314 #endif
2315 }
2316 #endif
2317
2318 #if defined (DBX_DEBUGGING_INFO)
2319 if (write_symbols == DBX_DEBUG)
2320 dbxout_source_line (file, filename, NOTE_LINE_NUMBER (insn));
2321 #endif
2322
2323 #if defined (XCOFF_DEBUGGING_INFO)
2324 if (write_symbols == XCOFF_DEBUG)
2325 xcoffout_source_line (file, filename, insn);
2326 #endif
2327
2328 #ifdef DWARF_DEBUGGING_INFO
2329 if (write_symbols == DWARF_DEBUG)
2330 dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
2331 #endif
2332
2333 #ifdef DWARF2_DEBUGGING_INFO
2334 if (write_symbols == DWARF2_DEBUG)
2335 dwarf2out_line (filename, NOTE_LINE_NUMBER (insn));
2336 #endif
2337 }
2338 }
2339 \f
2340 /* If X is a SUBREG, replace it with a REG or a MEM,
2341 based on the thing it is a subreg of. */
2342
2343 rtx
2344 alter_subreg (x)
2345 register rtx x;
2346 {
2347 register rtx y = SUBREG_REG (x);
2348 if (GET_CODE (y) == SUBREG)
2349 y = alter_subreg (y);
2350
2351 if (GET_CODE (y) == REG)
2352 {
2353 /* If the containing reg really gets a hard reg, so do we. */
2354 PUT_CODE (x, REG);
2355 REGNO (x) = REGNO (y) + SUBREG_WORD (x);
2356 }
2357 else if (GET_CODE (y) == MEM)
2358 {
2359 register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2360 if (BYTES_BIG_ENDIAN)
2361 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
2362 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
2363 PUT_CODE (x, MEM);
2364 MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
2365 XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
2366 }
2367
2368 return x;
2369 }
2370
2371 /* Do alter_subreg on all the SUBREGs contained in X. */
2372
2373 static rtx
2374 walk_alter_subreg (x)
2375 rtx x;
2376 {
2377 switch (GET_CODE (x))
2378 {
2379 case PLUS:
2380 case MULT:
2381 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2382 XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
2383 break;
2384
2385 case MEM:
2386 XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
2387 break;
2388
2389 case SUBREG:
2390 return alter_subreg (x);
2391
2392 default:
2393 break;
2394 }
2395
2396 return x;
2397 }
2398 \f
2399 #ifdef HAVE_cc0
2400
2401 /* Given BODY, the body of a jump instruction, alter the jump condition
2402 as required by the bits that are set in cc_status.flags.
2403 Not all of the bits there can be handled at this level in all cases.
2404
2405 The value is normally 0.
2406 1 means that the condition has become always true.
2407 -1 means that the condition has become always false.
2408 2 means that COND has been altered. */
2409
2410 static int
2411 alter_cond (cond)
2412 register rtx cond;
2413 {
2414 int value = 0;
2415
2416 if (cc_status.flags & CC_REVERSED)
2417 {
2418 value = 2;
2419 PUT_CODE (cond, swap_condition (GET_CODE (cond)));
2420 }
2421
2422 if (cc_status.flags & CC_INVERTED)
2423 {
2424 value = 2;
2425 PUT_CODE (cond, reverse_condition (GET_CODE (cond)));
2426 }
2427
2428 if (cc_status.flags & CC_NOT_POSITIVE)
2429 switch (GET_CODE (cond))
2430 {
2431 case LE:
2432 case LEU:
2433 case GEU:
2434 /* Jump becomes unconditional. */
2435 return 1;
2436
2437 case GT:
2438 case GTU:
2439 case LTU:
2440 /* Jump becomes no-op. */
2441 return -1;
2442
2443 case GE:
2444 PUT_CODE (cond, EQ);
2445 value = 2;
2446 break;
2447
2448 case LT:
2449 PUT_CODE (cond, NE);
2450 value = 2;
2451 break;
2452
2453 default:
2454 break;
2455 }
2456
2457 if (cc_status.flags & CC_NOT_NEGATIVE)
2458 switch (GET_CODE (cond))
2459 {
2460 case GE:
2461 case GEU:
2462 /* Jump becomes unconditional. */
2463 return 1;
2464
2465 case LT:
2466 case LTU:
2467 /* Jump becomes no-op. */
2468 return -1;
2469
2470 case LE:
2471 case LEU:
2472 PUT_CODE (cond, EQ);
2473 value = 2;
2474 break;
2475
2476 case GT:
2477 case GTU:
2478 PUT_CODE (cond, NE);
2479 value = 2;
2480 break;
2481
2482 default:
2483 break;
2484 }
2485
2486 if (cc_status.flags & CC_NO_OVERFLOW)
2487 switch (GET_CODE (cond))
2488 {
2489 case GEU:
2490 /* Jump becomes unconditional. */
2491 return 1;
2492
2493 case LEU:
2494 PUT_CODE (cond, EQ);
2495 value = 2;
2496 break;
2497
2498 case GTU:
2499 PUT_CODE (cond, NE);
2500 value = 2;
2501 break;
2502
2503 case LTU:
2504 /* Jump becomes no-op. */
2505 return -1;
2506
2507 default:
2508 break;
2509 }
2510
2511 if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
2512 switch (GET_CODE (cond))
2513 {
2514 default:
2515 abort ();
2516
2517 case NE:
2518 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
2519 value = 2;
2520 break;
2521
2522 case EQ:
2523 PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
2524 value = 2;
2525 break;
2526 }
2527
2528 if (cc_status.flags & CC_NOT_SIGNED)
2529 /* The flags are valid if signed condition operators are converted
2530 to unsigned. */
2531 switch (GET_CODE (cond))
2532 {
2533 case LE:
2534 PUT_CODE (cond, LEU);
2535 value = 2;
2536 break;
2537
2538 case LT:
2539 PUT_CODE (cond, LTU);
2540 value = 2;
2541 break;
2542
2543 case GT:
2544 PUT_CODE (cond, GTU);
2545 value = 2;
2546 break;
2547
2548 case GE:
2549 PUT_CODE (cond, GEU);
2550 value = 2;
2551 break;
2552
2553 default:
2554 break;
2555 }
2556
2557 return value;
2558 }
2559 #endif
2560 \f
2561 /* Report inconsistency between the assembler template and the operands.
2562 In an `asm', it's the user's fault; otherwise, the compiler's fault. */
2563
2564 void
2565 output_operand_lossage (str)
2566 char *str;
2567 {
2568 if (this_is_asm_operands)
2569 error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
2570 else
2571 abort ();
2572 }
2573 \f
2574 /* Output of assembler code from a template, and its subroutines. */
2575
2576 /* Output text from TEMPLATE to the assembler output file,
2577 obeying %-directions to substitute operands taken from
2578 the vector OPERANDS.
2579
2580 %N (for N a digit) means print operand N in usual manner.
2581 %lN means require operand N to be a CODE_LABEL or LABEL_REF
2582 and print the label name with no punctuation.
2583 %cN means require operand N to be a constant
2584 and print the constant expression with no punctuation.
2585 %aN means expect operand N to be a memory address
2586 (not a memory reference!) and print a reference
2587 to that address.
2588 %nN means expect operand N to be a constant
2589 and print a constant expression for minus the value
2590 of the operand, with no other punctuation. */
2591
2592 static void
2593 output_asm_name ()
2594 {
2595 if (flag_print_asm_name)
2596 {
2597 /* Annotate the assembly with a comment describing the pattern and
2598 alternative used. */
2599 if (debug_insn)
2600 {
2601 register int num = INSN_CODE (debug_insn);
2602 fprintf (asm_out_file, " %s %d %s",
2603 ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
2604 if (insn_n_alternatives[num] > 1)
2605 fprintf (asm_out_file, "/%d", which_alternative + 1);
2606
2607 /* Clear this so only the first assembler insn
2608 of any rtl insn will get the special comment for -dp. */
2609 debug_insn = 0;
2610 }
2611 }
2612 }
2613
2614 void
2615 output_asm_insn (template, operands)
2616 char *template;
2617 rtx *operands;
2618 {
2619 register char *p;
2620 register int c;
2621
2622 /* An insn may return a null string template
2623 in a case where no assembler code is needed. */
2624 if (*template == 0)
2625 return;
2626
2627 p = template;
2628 putc ('\t', asm_out_file);
2629
2630 #ifdef ASM_OUTPUT_OPCODE
2631 ASM_OUTPUT_OPCODE (asm_out_file, p);
2632 #endif
2633
2634 while ((c = *p++))
2635 switch (c)
2636 {
2637 case '\n':
2638 output_asm_name ();
2639 putc (c, asm_out_file);
2640 #ifdef ASM_OUTPUT_OPCODE
2641 while ((c = *p) == '\t')
2642 {
2643 putc (c, asm_out_file);
2644 p++;
2645 }
2646 ASM_OUTPUT_OPCODE (asm_out_file, p);
2647 #endif
2648 break;
2649
2650 #ifdef ASSEMBLER_DIALECT
2651 case '{':
2652 {
2653 register int i;
2654
2655 /* If we want the first dialect, do nothing. Otherwise, skip
2656 DIALECT_NUMBER of strings ending with '|'. */
2657 for (i = 0; i < dialect_number; i++)
2658 {
2659 while (*p && *p++ != '|')
2660 ;
2661
2662 if (*p == '|')
2663 p++;
2664 }
2665 }
2666 break;
2667
2668 case '|':
2669 /* Skip to close brace. */
2670 while (*p && *p++ != '}')
2671 ;
2672 break;
2673
2674 case '}':
2675 break;
2676 #endif
2677
2678 case '%':
2679 /* %% outputs a single %. */
2680 if (*p == '%')
2681 {
2682 p++;
2683 putc (c, asm_out_file);
2684 }
2685 /* %= outputs a number which is unique to each insn in the entire
2686 compilation. This is useful for making local labels that are
2687 referred to more than once in a given insn. */
2688 else if (*p == '=')
2689 {
2690 p++;
2691 fprintf (asm_out_file, "%d", insn_counter);
2692 }
2693 /* % followed by a letter and some digits
2694 outputs an operand in a special way depending on the letter.
2695 Letters `acln' are implemented directly.
2696 Other letters are passed to `output_operand' so that
2697 the PRINT_OPERAND macro can define them. */
2698 else if ((*p >= 'a' && *p <= 'z')
2699 || (*p >= 'A' && *p <= 'Z'))
2700 {
2701 int letter = *p++;
2702 c = atoi (p);
2703
2704 if (! (*p >= '0' && *p <= '9'))
2705 output_operand_lossage ("operand number missing after %-letter");
2706 else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2707 output_operand_lossage ("operand number out of range");
2708 else if (letter == 'l')
2709 output_asm_label (operands[c]);
2710 else if (letter == 'a')
2711 output_address (operands[c]);
2712 else if (letter == 'c')
2713 {
2714 if (CONSTANT_ADDRESS_P (operands[c]))
2715 output_addr_const (asm_out_file, operands[c]);
2716 else
2717 output_operand (operands[c], 'c');
2718 }
2719 else if (letter == 'n')
2720 {
2721 if (GET_CODE (operands[c]) == CONST_INT)
2722 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
2723 - INTVAL (operands[c]));
2724 else
2725 {
2726 putc ('-', asm_out_file);
2727 output_addr_const (asm_out_file, operands[c]);
2728 }
2729 }
2730 else
2731 output_operand (operands[c], letter);
2732
2733 while ((c = *p) >= '0' && c <= '9') p++;
2734 }
2735 /* % followed by a digit outputs an operand the default way. */
2736 else if (*p >= '0' && *p <= '9')
2737 {
2738 c = atoi (p);
2739 if (this_is_asm_operands && c >= (unsigned) insn_noperands)
2740 output_operand_lossage ("operand number out of range");
2741 else
2742 output_operand (operands[c], 0);
2743 while ((c = *p) >= '0' && c <= '9') p++;
2744 }
2745 /* % followed by punctuation: output something for that
2746 punctuation character alone, with no operand.
2747 The PRINT_OPERAND macro decides what is actually done. */
2748 #ifdef PRINT_OPERAND_PUNCT_VALID_P
2749 else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
2750 output_operand (NULL_RTX, *p++);
2751 #endif
2752 else
2753 output_operand_lossage ("invalid %%-code");
2754 break;
2755
2756 default:
2757 putc (c, asm_out_file);
2758 }
2759
2760 output_asm_name ();
2761
2762 putc ('\n', asm_out_file);
2763 }
2764 \f
2765 /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
2766
2767 void
2768 output_asm_label (x)
2769 rtx x;
2770 {
2771 char buf[256];
2772
2773 if (GET_CODE (x) == LABEL_REF)
2774 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2775 else if (GET_CODE (x) == CODE_LABEL)
2776 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2777 else
2778 output_operand_lossage ("`%l' operand isn't a label");
2779
2780 assemble_name (asm_out_file, buf);
2781 }
2782
2783 /* Print operand X using machine-dependent assembler syntax.
2784 The macro PRINT_OPERAND is defined just to control this function.
2785 CODE is a non-digit that preceded the operand-number in the % spec,
2786 such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
2787 between the % and the digits.
2788 When CODE is a non-letter, X is 0.
2789
2790 The meanings of the letters are machine-dependent and controlled
2791 by PRINT_OPERAND. */
2792
2793 static void
2794 output_operand (x, code)
2795 rtx x;
2796 int code;
2797 {
2798 if (x && GET_CODE (x) == SUBREG)
2799 x = alter_subreg (x);
2800
2801 /* If X is a pseudo-register, abort now rather than writing trash to the
2802 assembler file. */
2803
2804 if (x && GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2805 abort ();
2806
2807 PRINT_OPERAND (asm_out_file, x, code);
2808 }
2809
2810 /* Print a memory reference operand for address X
2811 using machine-dependent assembler syntax.
2812 The macro PRINT_OPERAND_ADDRESS exists just to control this function. */
2813
2814 void
2815 output_address (x)
2816 rtx x;
2817 {
2818 walk_alter_subreg (x);
2819 PRINT_OPERAND_ADDRESS (asm_out_file, x);
2820 }
2821 \f
2822 /* Print an integer constant expression in assembler syntax.
2823 Addition and subtraction are the only arithmetic
2824 that may appear in these expressions. */
2825
2826 void
2827 output_addr_const (file, x)
2828 FILE *file;
2829 rtx x;
2830 {
2831 char buf[256];
2832
2833 restart:
2834 switch (GET_CODE (x))
2835 {
2836 case PC:
2837 if (flag_pic)
2838 putc ('.', file);
2839 else
2840 abort ();
2841 break;
2842
2843 case SYMBOL_REF:
2844 assemble_name (file, XSTR (x, 0));
2845 break;
2846
2847 case LABEL_REF:
2848 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2849 assemble_name (file, buf);
2850 break;
2851
2852 case CODE_LABEL:
2853 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
2854 assemble_name (file, buf);
2855 break;
2856
2857 case CONST_INT:
2858 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2859 break;
2860
2861 case CONST:
2862 /* This used to output parentheses around the expression,
2863 but that does not work on the 386 (either ATT or BSD assembler). */
2864 output_addr_const (file, XEXP (x, 0));
2865 break;
2866
2867 case CONST_DOUBLE:
2868 if (GET_MODE (x) == VOIDmode)
2869 {
2870 /* We can use %d if the number is one word and positive. */
2871 if (CONST_DOUBLE_HIGH (x))
2872 fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2873 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2874 else if (CONST_DOUBLE_LOW (x) < 0)
2875 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2876 else
2877 fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
2878 }
2879 else
2880 /* We can't handle floating point constants;
2881 PRINT_OPERAND must handle them. */
2882 output_operand_lossage ("floating constant misused");
2883 break;
2884
2885 case PLUS:
2886 /* Some assemblers need integer constants to appear last (eg masm). */
2887 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2888 {
2889 output_addr_const (file, XEXP (x, 1));
2890 if (INTVAL (XEXP (x, 0)) >= 0)
2891 fprintf (file, "+");
2892 output_addr_const (file, XEXP (x, 0));
2893 }
2894 else
2895 {
2896 output_addr_const (file, XEXP (x, 0));
2897 if (INTVAL (XEXP (x, 1)) >= 0)
2898 fprintf (file, "+");
2899 output_addr_const (file, XEXP (x, 1));
2900 }
2901 break;
2902
2903 case MINUS:
2904 /* Avoid outputting things like x-x or x+5-x,
2905 since some assemblers can't handle that. */
2906 x = simplify_subtraction (x);
2907 if (GET_CODE (x) != MINUS)
2908 goto restart;
2909
2910 output_addr_const (file, XEXP (x, 0));
2911 fprintf (file, "-");
2912 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2913 && INTVAL (XEXP (x, 1)) < 0)
2914 {
2915 fprintf (file, ASM_OPEN_PAREN);
2916 output_addr_const (file, XEXP (x, 1));
2917 fprintf (file, ASM_CLOSE_PAREN);
2918 }
2919 else
2920 output_addr_const (file, XEXP (x, 1));
2921 break;
2922
2923 case ZERO_EXTEND:
2924 case SIGN_EXTEND:
2925 output_addr_const (file, XEXP (x, 0));
2926 break;
2927
2928 default:
2929 output_operand_lossage ("invalid expression as operand");
2930 }
2931 }
2932 \f
2933 /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
2934 %R prints the value of REGISTER_PREFIX.
2935 %L prints the value of LOCAL_LABEL_PREFIX.
2936 %U prints the value of USER_LABEL_PREFIX.
2937 %I prints the value of IMMEDIATE_PREFIX.
2938 %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
2939 Also supported are %d, %x, %s, %e, %f, %g and %%.
2940
2941 We handle alternate assembler dialects here, just like output_asm_insn. */
2942
2943 void
2944 asm_fprintf VPROTO((FILE *file, char *p, ...))
2945 {
2946 #ifndef __STDC__
2947 FILE *file;
2948 char *p;
2949 #endif
2950 va_list argptr;
2951 char buf[10];
2952 char *q, c;
2953
2954 VA_START (argptr, p);
2955
2956 #ifndef __STDC__
2957 file = va_arg (argptr, FILE *);
2958 p = va_arg (argptr, char *);
2959 #endif
2960
2961 buf[0] = '%';
2962
2963 while ((c = *p++))
2964 switch (c)
2965 {
2966 #ifdef ASSEMBLER_DIALECT
2967 case '{':
2968 {
2969 int i;
2970
2971 /* If we want the first dialect, do nothing. Otherwise, skip
2972 DIALECT_NUMBER of strings ending with '|'. */
2973 for (i = 0; i < dialect_number; i++)
2974 {
2975 while (*p && *p++ != '|')
2976 ;
2977
2978 if (*p == '|')
2979 p++;
2980 }
2981 }
2982 break;
2983
2984 case '|':
2985 /* Skip to close brace. */
2986 while (*p && *p++ != '}')
2987 ;
2988 break;
2989
2990 case '}':
2991 break;
2992 #endif
2993
2994 case '%':
2995 c = *p++;
2996 q = &buf[1];
2997 while ((c >= '0' && c <= '9') || c == '.')
2998 {
2999 *q++ = c;
3000 c = *p++;
3001 }
3002 switch (c)
3003 {
3004 case '%':
3005 fprintf (file, "%%");
3006 break;
3007
3008 case 'd': case 'i': case 'u':
3009 case 'x': case 'p': case 'X':
3010 case 'o':
3011 *q++ = c;
3012 *q = 0;
3013 fprintf (file, buf, va_arg (argptr, int));
3014 break;
3015
3016 case 'w':
3017 /* This is a prefix to the 'd', 'i', 'u', 'x', 'p', and 'X' cases,
3018 but we do not check for those cases. It means that the value
3019 is a HOST_WIDE_INT, which may be either `int' or `long'. */
3020
3021 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3022 #else
3023 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3024 *q++ = 'l';
3025 #else
3026 *q++ = 'l';
3027 *q++ = 'l';
3028 #endif
3029 #endif
3030
3031 *q++ = *p++;
3032 *q = 0;
3033 fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3034 break;
3035
3036 case 'l':
3037 *q++ = c;
3038 *q++ = *p++;
3039 *q = 0;
3040 fprintf (file, buf, va_arg (argptr, long));
3041 break;
3042
3043 case 'e':
3044 case 'f':
3045 case 'g':
3046 *q++ = c;
3047 *q = 0;
3048 fprintf (file, buf, va_arg (argptr, double));
3049 break;
3050
3051 case 's':
3052 *q++ = c;
3053 *q = 0;
3054 fprintf (file, buf, va_arg (argptr, char *));
3055 break;
3056
3057 case 'O':
3058 #ifdef ASM_OUTPUT_OPCODE
3059 ASM_OUTPUT_OPCODE (asm_out_file, p);
3060 #endif
3061 break;
3062
3063 case 'R':
3064 #ifdef REGISTER_PREFIX
3065 fprintf (file, "%s", REGISTER_PREFIX);
3066 #endif
3067 break;
3068
3069 case 'I':
3070 #ifdef IMMEDIATE_PREFIX
3071 fprintf (file, "%s", IMMEDIATE_PREFIX);
3072 #endif
3073 break;
3074
3075 case 'L':
3076 #ifdef LOCAL_LABEL_PREFIX
3077 fprintf (file, "%s", LOCAL_LABEL_PREFIX);
3078 #endif
3079 break;
3080
3081 case 'U':
3082 #ifdef USER_LABEL_PREFIX
3083 fprintf (file, "%s", USER_LABEL_PREFIX);
3084 #endif
3085 break;
3086
3087 default:
3088 abort ();
3089 }
3090 break;
3091
3092 default:
3093 fputc (c, file);
3094 }
3095 }
3096 \f
3097 /* Split up a CONST_DOUBLE or integer constant rtx
3098 into two rtx's for single words,
3099 storing in *FIRST the word that comes first in memory in the target
3100 and in *SECOND the other. */
3101
3102 void
3103 split_double (value, first, second)
3104 rtx value;
3105 rtx *first, *second;
3106 {
3107 if (GET_CODE (value) == CONST_INT)
3108 {
3109 if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
3110 {
3111 /* In this case the CONST_INT holds both target words.
3112 Extract the bits from it into two word-sized pieces. */
3113 rtx low, high;
3114 HOST_WIDE_INT word_mask;
3115 /* Avoid warnings for shift count >= BITS_PER_WORD. */
3116 int shift_count = BITS_PER_WORD - 1;
3117
3118 word_mask = (HOST_WIDE_INT) 1 << shift_count;
3119 word_mask |= word_mask - 1;
3120 low = GEN_INT (INTVAL (value) & word_mask);
3121 high = GEN_INT ((INTVAL (value) >> (shift_count + 1)) & word_mask);
3122 if (WORDS_BIG_ENDIAN)
3123 {
3124 *first = high;
3125 *second = low;
3126 }
3127 else
3128 {
3129 *first = low;
3130 *second = high;
3131 }
3132 }
3133 else
3134 {
3135 /* The rule for using CONST_INT for a wider mode
3136 is that we regard the value as signed.
3137 So sign-extend it. */
3138 rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
3139 if (WORDS_BIG_ENDIAN)
3140 {
3141 *first = high;
3142 *second = value;
3143 }
3144 else
3145 {
3146 *first = value;
3147 *second = high;
3148 }
3149 }
3150 }
3151 else if (GET_CODE (value) != CONST_DOUBLE)
3152 {
3153 if (WORDS_BIG_ENDIAN)
3154 {
3155 *first = const0_rtx;
3156 *second = value;
3157 }
3158 else
3159 {
3160 *first = value;
3161 *second = const0_rtx;
3162 }
3163 }
3164 else if (GET_MODE (value) == VOIDmode
3165 /* This is the old way we did CONST_DOUBLE integers. */
3166 || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
3167 {
3168 /* In an integer, the words are defined as most and least significant.
3169 So order them by the target's convention. */
3170 if (WORDS_BIG_ENDIAN)
3171 {
3172 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3173 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3174 }
3175 else
3176 {
3177 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3178 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3179 }
3180 }
3181 else
3182 {
3183 #ifdef REAL_ARITHMETIC
3184 REAL_VALUE_TYPE r; long l[2];
3185 REAL_VALUE_FROM_CONST_DOUBLE (r, value);
3186
3187 /* Note, this converts the REAL_VALUE_TYPE to the target's
3188 format, splits up the floating point double and outputs
3189 exactly 32 bits of it into each of l[0] and l[1] --
3190 not necessarily BITS_PER_WORD bits. */
3191 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
3192
3193 *first = GEN_INT ((HOST_WIDE_INT) l[0]);
3194 *second = GEN_INT ((HOST_WIDE_INT) l[1]);
3195 #else
3196 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
3197 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
3198 && ! flag_pretend_float)
3199 abort ();
3200
3201 if (
3202 #ifdef HOST_WORDS_BIG_ENDIAN
3203 WORDS_BIG_ENDIAN
3204 #else
3205 ! WORDS_BIG_ENDIAN
3206 #endif
3207 )
3208 {
3209 /* Host and target agree => no need to swap. */
3210 *first = GEN_INT (CONST_DOUBLE_LOW (value));
3211 *second = GEN_INT (CONST_DOUBLE_HIGH (value));
3212 }
3213 else
3214 {
3215 *second = GEN_INT (CONST_DOUBLE_LOW (value));
3216 *first = GEN_INT (CONST_DOUBLE_HIGH (value));
3217 }
3218 #endif /* no REAL_ARITHMETIC */
3219 }
3220 }
3221 \f
3222 /* Return nonzero if this function has no function calls. */
3223
3224 int
3225 leaf_function_p ()
3226 {
3227 rtx insn;
3228
3229 if (profile_flag || profile_block_flag || profile_arc_flag)
3230 return 0;
3231
3232 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3233 {
3234 if (GET_CODE (insn) == CALL_INSN)
3235 return 0;
3236 if (GET_CODE (insn) == INSN
3237 && GET_CODE (PATTERN (insn)) == SEQUENCE
3238 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN)
3239 return 0;
3240 }
3241 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
3242 {
3243 if (GET_CODE (XEXP (insn, 0)) == CALL_INSN)
3244 return 0;
3245 if (GET_CODE (XEXP (insn, 0)) == INSN
3246 && GET_CODE (PATTERN (XEXP (insn, 0))) == SEQUENCE
3247 && GET_CODE (XVECEXP (PATTERN (XEXP (insn, 0)), 0, 0)) == CALL_INSN)
3248 return 0;
3249 }
3250
3251 return 1;
3252 }
3253
3254 /* On some machines, a function with no call insns
3255 can run faster if it doesn't create its own register window.
3256 When output, the leaf function should use only the "output"
3257 registers. Ordinarily, the function would be compiled to use
3258 the "input" registers to find its arguments; it is a candidate
3259 for leaf treatment if it uses only the "input" registers.
3260 Leaf function treatment means renumbering so the function
3261 uses the "output" registers instead. */
3262
3263 #ifdef LEAF_REGISTERS
3264
3265 static char permitted_reg_in_leaf_functions[] = LEAF_REGISTERS;
3266
3267 /* Return 1 if this function uses only the registers that can be
3268 safely renumbered. */
3269
3270 int
3271 only_leaf_regs_used ()
3272 {
3273 int i;
3274
3275 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3276 {
3277 if ((regs_ever_live[i] || global_regs[i])
3278 && ! permitted_reg_in_leaf_functions[i])
3279 return 0;
3280 }
3281 return 1;
3282 }
3283
3284 /* Scan all instructions and renumber all registers into those
3285 available in leaf functions. */
3286
3287 static void
3288 leaf_renumber_regs (first)
3289 rtx first;
3290 {
3291 rtx insn;
3292
3293 /* Renumber only the actual patterns.
3294 The reg-notes can contain frame pointer refs,
3295 and renumbering them could crash, and should not be needed. */
3296 for (insn = first; insn; insn = NEXT_INSN (insn))
3297 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3298 leaf_renumber_regs_insn (PATTERN (insn));
3299 for (insn = current_function_epilogue_delay_list; insn; insn = XEXP (insn, 1))
3300 if (GET_RTX_CLASS (GET_CODE (XEXP (insn, 0))) == 'i')
3301 leaf_renumber_regs_insn (PATTERN (XEXP (insn, 0)));
3302 }
3303
3304 /* Scan IN_RTX and its subexpressions, and renumber all regs into those
3305 available in leaf functions. */
3306
3307 void
3308 leaf_renumber_regs_insn (in_rtx)
3309 register rtx in_rtx;
3310 {
3311 register int i, j;
3312 register char *format_ptr;
3313
3314 if (in_rtx == 0)
3315 return;
3316
3317 /* Renumber all input-registers into output-registers.
3318 renumbered_regs would be 1 for an output-register;
3319 they */
3320
3321 if (GET_CODE (in_rtx) == REG)
3322 {
3323 int newreg;
3324
3325 /* Don't renumber the same reg twice. */
3326 if (in_rtx->used)
3327 return;
3328
3329 newreg = REGNO (in_rtx);
3330 /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
3331 to reach here as part of a REG_NOTE. */
3332 if (newreg >= FIRST_PSEUDO_REGISTER)
3333 {
3334 in_rtx->used = 1;
3335 return;
3336 }
3337 newreg = LEAF_REG_REMAP (newreg);
3338 if (newreg < 0)
3339 abort ();
3340 regs_ever_live[REGNO (in_rtx)] = 0;
3341 regs_ever_live[newreg] = 1;
3342 REGNO (in_rtx) = newreg;
3343 in_rtx->used = 1;
3344 }
3345
3346 if (GET_RTX_CLASS (GET_CODE (in_rtx)) == 'i')
3347 {
3348 /* Inside a SEQUENCE, we find insns.
3349 Renumber just the patterns of these insns,
3350 just as we do for the top-level insns. */
3351 leaf_renumber_regs_insn (PATTERN (in_rtx));
3352 return;
3353 }
3354
3355 format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
3356
3357 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
3358 switch (*format_ptr++)
3359 {
3360 case 'e':
3361 leaf_renumber_regs_insn (XEXP (in_rtx, i));
3362 break;
3363
3364 case 'E':
3365 if (NULL != XVEC (in_rtx, i))
3366 {
3367 for (j = 0; j < XVECLEN (in_rtx, i); j++)
3368 leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
3369 }
3370 break;
3371
3372 case 'S':
3373 case 's':
3374 case '0':
3375 case 'i':
3376 case 'w':
3377 case 'n':
3378 case 'u':
3379 break;
3380
3381 default:
3382 abort ();
3383 }
3384 }
3385 #endif
This page took 0.183554 seconds and 6 git commands to generate.