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