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