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