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