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