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