OSDN Git Service

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