Branch data Line data Source code
1 : : /* Convert RTL to assembler code and output it, for GNU compiler.
2 : : Copyright (C) 1987-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : : /* This is the final pass of the compiler.
21 : : It looks at the rtl code for a function and outputs assembler code.
22 : :
23 : : Call `final_start_function' to output the assembler code for function entry,
24 : : `final' to output assembler code for some RTL code,
25 : : `final_end_function' to output assembler code for function exit.
26 : : If a function is compiled in several pieces, each piece is
27 : : output separately with `final'.
28 : :
29 : : Some optimizations are also done at this level.
30 : : Move instructions that were made unnecessary by good register allocation
31 : : are detected and omitted from the output. (Though most of these
32 : : are removed by the last jump pass.)
33 : :
34 : : Instructions to set the condition codes are omitted when it can be
35 : : seen that the condition codes already had the desired values.
36 : :
37 : : In some cases it is sufficient if the inherited condition codes
38 : : have related values, but this may require the following insn
39 : : (the one that tests the condition codes) to be modified.
40 : :
41 : : The code for the function prologue and epilogue are generated
42 : : directly in assembler by the target functions function_prologue and
43 : : function_epilogue. Those instructions never exist as rtl. */
44 : :
45 : : #include "config.h"
46 : : #define INCLUDE_ALGORITHM /* reverse */
47 : : #include "system.h"
48 : : #include "coretypes.h"
49 : : #include "backend.h"
50 : : #include "target.h"
51 : : #include "rtl.h"
52 : : #include "tree.h"
53 : : #include "cfghooks.h"
54 : : #include "df.h"
55 : : #include "memmodel.h"
56 : : #include "tm_p.h"
57 : : #include "insn-config.h"
58 : : #include "regs.h"
59 : : #include "emit-rtl.h"
60 : : #include "recog.h"
61 : : #include "cgraph.h"
62 : : #include "tree-pretty-print.h" /* for dump_function_header */
63 : : #include "varasm.h"
64 : : #include "insn-attr.h"
65 : : #include "conditions.h"
66 : : #include "flags.h"
67 : : #include "output.h"
68 : : #include "except.h"
69 : : #include "rtl-error.h"
70 : : #include "toplev.h" /* exact_log2, floor_log2 */
71 : : #include "reload.h"
72 : : #include "intl.h"
73 : : #include "cfgrtl.h"
74 : : #include "debug.h"
75 : : #include "tree-pass.h"
76 : : #include "tree-ssa.h"
77 : : #include "cfgloop.h"
78 : : #include "stringpool.h"
79 : : #include "attribs.h"
80 : : #include "asan.h"
81 : : #include "rtl-iter.h"
82 : : #include "print-rtl.h"
83 : : #include "function-abi.h"
84 : : #include "common/common-target.h"
85 : : #include "diagnostic.h"
86 : :
87 : : #include "dwarf2out.h"
88 : :
89 : : /* Most ports don't need to define CC_STATUS_INIT.
90 : : So define a null default for it to save conditionalization later. */
91 : : #ifndef CC_STATUS_INIT
92 : : #define CC_STATUS_INIT
93 : : #endif
94 : :
95 : : /* Is the given character a logical line separator for the assembler? */
96 : : #ifndef IS_ASM_LOGICAL_LINE_SEPARATOR
97 : : #define IS_ASM_LOGICAL_LINE_SEPARATOR(C, STR) ((C) == ';')
98 : : #endif
99 : :
100 : : #ifndef JUMP_TABLES_IN_TEXT_SECTION
101 : : #define JUMP_TABLES_IN_TEXT_SECTION 0
102 : : #endif
103 : :
104 : : /* Bitflags used by final_scan_insn. */
105 : : #define SEEN_NOTE 1
106 : : #define SEEN_EMITTED 2
107 : : #define SEEN_NEXT_VIEW 4
108 : :
109 : : /* Last insn processed by final_scan_insn. */
110 : : static rtx_insn *debug_insn;
111 : : rtx_insn *current_output_insn;
112 : :
113 : : /* Line number of last NOTE. */
114 : : static int last_linenum;
115 : :
116 : : /* Column number of last NOTE. */
117 : : static int last_columnnum;
118 : :
119 : : /* Discriminator written to assembly. */
120 : : static int last_discriminator;
121 : :
122 : : /* Compute discriminator to be written to assembly for current instruction.
123 : : Note: actual usage depends on loc_discriminator_kind setting. */
124 : : static inline int compute_discriminator (location_t loc);
125 : :
126 : : /* Highest line number in current block. */
127 : : static int high_block_linenum;
128 : :
129 : : /* Likewise for function. */
130 : : static int high_function_linenum;
131 : :
132 : : /* Filename of last NOTE. */
133 : : static const char *last_filename;
134 : :
135 : : /* Override filename, line and column number. */
136 : : static const char *override_filename;
137 : : static int override_linenum;
138 : : static int override_columnnum;
139 : : static int override_discriminator;
140 : :
141 : : /* Whether to force emission of a line note before the next insn. */
142 : : static bool force_source_line = false;
143 : :
144 : : extern const int length_unit_log; /* This is defined in insn-attrtab.cc. */
145 : :
146 : : /* Nonzero while outputting an `asm' with operands.
147 : : This means that inconsistencies are the user's fault, so don't die.
148 : : The precise value is the insn being output, to pass to error_for_asm. */
149 : : const rtx_insn *this_is_asm_operands;
150 : :
151 : : /* Number of operands of this insn, for an `asm' with operands. */
152 : : unsigned int insn_noperands;
153 : :
154 : : /* Compare optimization flag. */
155 : :
156 : : static rtx last_ignored_compare = 0;
157 : :
158 : : /* Assign a unique number to each insn that is output.
159 : : This can be used to generate unique local labels. */
160 : :
161 : : static int insn_counter = 0;
162 : :
163 : : /* Number of unmatched NOTE_INSN_BLOCK_BEG notes we have seen. */
164 : :
165 : : static int block_depth;
166 : :
167 : : /* True if have enabled APP processing of our assembler output. */
168 : :
169 : : static bool app_on;
170 : :
171 : : /* If we are outputting an insn sequence, this contains the sequence rtx.
172 : : Zero otherwise. */
173 : :
174 : : rtx_sequence *final_sequence;
175 : :
176 : : #ifdef ASSEMBLER_DIALECT
177 : :
178 : : /* Number of the assembler dialect to use, starting at 0. */
179 : : static int dialect_number;
180 : : #endif
181 : :
182 : : /* Nonnull if the insn currently being emitted was a COND_EXEC pattern. */
183 : : rtx current_insn_predicate;
184 : :
185 : : /* True if printing into -fdump-final-insns= dump. */
186 : : bool final_insns_dump_p;
187 : :
188 : : /* True if profile_function should be called, but hasn't been called yet. */
189 : : static bool need_profile_function;
190 : :
191 : : static int asm_insn_count (rtx);
192 : : static void profile_function (FILE *);
193 : : static void profile_after_prologue (FILE *);
194 : : static bool notice_source_line (rtx_insn *, bool *);
195 : : static rtx walk_alter_subreg (rtx *, bool *);
196 : : static void output_asm_name (void);
197 : : static void output_alternate_entry_point (FILE *, rtx_insn *);
198 : : static tree get_mem_expr_from_op (rtx, int *);
199 : : static void output_asm_operand_names (rtx *, int *, int);
200 : : #ifdef LEAF_REGISTERS
201 : : static void leaf_renumber_regs (rtx_insn *);
202 : : #endif
203 : : static int align_fuzz (rtx, rtx, int, unsigned);
204 : : static void collect_fn_hard_reg_usage (void);
205 : :
206 : : /* Initialize data in final at the beginning of a compilation. */
207 : :
208 : : void
209 : 278684 : init_final (const char *filename ATTRIBUTE_UNUSED)
210 : : {
211 : 278684 : app_on = 0;
212 : 278684 : final_sequence = 0;
213 : :
214 : : #ifdef ASSEMBLER_DIALECT
215 : 278684 : dialect_number = ASSEMBLER_DIALECT;
216 : : #endif
217 : 278684 : }
218 : :
219 : : /* Default target function prologue and epilogue assembler output.
220 : :
221 : : If not overridden for epilogue code, then the function body itself
222 : : contains return instructions wherever needed. */
223 : : void
224 : 1455204 : default_function_pro_epilogue (FILE *)
225 : : {
226 : 1455204 : }
227 : :
228 : : void
229 : 61951 : default_function_switched_text_sections (FILE *file ATTRIBUTE_UNUSED,
230 : : tree decl ATTRIBUTE_UNUSED,
231 : : bool new_is_cold ATTRIBUTE_UNUSED)
232 : : {
233 : 61951 : }
234 : :
235 : : /* Default target hook that outputs nothing to a stream. */
236 : : void
237 : 3014261 : no_asm_to_stream (FILE *file ATTRIBUTE_UNUSED)
238 : : {
239 : 3014261 : }
240 : :
241 : : /* Enable APP processing of subsequent output.
242 : : Used before the output from an `asm' statement. */
243 : :
244 : : void
245 : 47529 : app_enable (void)
246 : : {
247 : 47529 : if (! app_on)
248 : : {
249 : 44334 : fputs (ASM_APP_ON, asm_out_file);
250 : 44334 : app_on = 1;
251 : : }
252 : 47529 : }
253 : :
254 : : /* Disable APP processing of subsequent output.
255 : : Called from varasm.cc before most kinds of output. */
256 : :
257 : : void
258 : 152966212 : app_disable (void)
259 : : {
260 : 152966212 : if (app_on)
261 : : {
262 : 43061 : fputs (ASM_APP_OFF, asm_out_file);
263 : 43061 : app_on = 0;
264 : : }
265 : 152966212 : }
266 : :
267 : : /* Return the number of slots filled in the current
268 : : delayed branch sequence (we don't count the insn needing the
269 : : delay slot). Zero if not in a delayed branch sequence. */
270 : :
271 : : int
272 : 0 : dbr_sequence_length (void)
273 : : {
274 : 0 : if (final_sequence != 0)
275 : 0 : return XVECLEN (final_sequence, 0) - 1;
276 : : else
277 : : return 0;
278 : : }
279 : :
280 : : /* The next two pages contain routines used to compute the length of an insn
281 : : and to shorten branches. */
282 : :
283 : : /* Arrays for insn lengths, and addresses. The latter is referenced by
284 : : `insn_current_length'. */
285 : :
286 : : static int *insn_lengths;
287 : :
288 : : vec<int> insn_addresses_;
289 : :
290 : : /* Max uid for which the above arrays are valid. */
291 : : static int insn_lengths_max_uid;
292 : :
293 : : /* Address of insn being processed. Used by `insn_current_length'. */
294 : : int insn_current_address;
295 : :
296 : : /* Address of insn being processed in previous iteration. */
297 : : int insn_last_address;
298 : :
299 : : /* known invariant alignment of insn being processed. */
300 : : int insn_current_align;
301 : :
302 : : /* After shorten_branches, for any insn, uid_align[INSN_UID (insn)]
303 : : gives the next following alignment insn that increases the known
304 : : alignment, or NULL_RTX if there is no such insn.
305 : : For any alignment obtained this way, we can again index uid_align with
306 : : its uid to obtain the next following align that in turn increases the
307 : : alignment, till we reach NULL_RTX; the sequence obtained this way
308 : : for each insn we'll call the alignment chain of this insn in the following
309 : : comments. */
310 : :
311 : : static rtx *uid_align;
312 : : static int *uid_shuid;
313 : : static vec<align_flags> label_align;
314 : :
315 : : /* Indicate that branch shortening hasn't yet been done. */
316 : :
317 : : void
318 : 1456014 : init_insn_lengths (void)
319 : : {
320 : 1456014 : if (uid_shuid)
321 : : {
322 : 1451611 : free (uid_shuid);
323 : 1451611 : uid_shuid = 0;
324 : : }
325 : 1456014 : if (insn_lengths)
326 : : {
327 : 1451611 : free (insn_lengths);
328 : 1451611 : insn_lengths = 0;
329 : 1451611 : insn_lengths_max_uid = 0;
330 : : }
331 : 1456014 : if (HAVE_ATTR_length)
332 : 1456014 : INSN_ADDRESSES_FREE ();
333 : 1456014 : if (uid_align)
334 : : {
335 : 1451611 : free (uid_align);
336 : 1451611 : uid_align = 0;
337 : : }
338 : 1456014 : }
339 : :
340 : : /* Obtain the current length of an insn. If branch shortening has been done,
341 : : get its actual length. Otherwise, use FALLBACK_FN to calculate the
342 : : length. */
343 : : static int
344 : 387084003 : get_attr_length_1 (rtx_insn *insn, int (*fallback_fn) (rtx_insn *))
345 : : {
346 : 387084003 : rtx body;
347 : 387084003 : int i;
348 : 387084003 : int length = 0;
349 : :
350 : 387084003 : if (!HAVE_ATTR_length)
351 : : return 0;
352 : :
353 : 387084003 : if (insn_lengths_max_uid > INSN_UID (insn))
354 : 3433 : return insn_lengths[INSN_UID (insn)];
355 : : else
356 : 387080570 : switch (GET_CODE (insn))
357 : : {
358 : : case NOTE:
359 : : case BARRIER:
360 : : case CODE_LABEL:
361 : : case DEBUG_INSN:
362 : : return 0;
363 : :
364 : 9530432 : case CALL_INSN:
365 : 9530432 : case JUMP_INSN:
366 : 9530432 : body = PATTERN (insn);
367 : 9530432 : if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
368 : 85 : length = asm_insn_count (body) * fallback_fn (insn);
369 : : else
370 : 9530347 : length = fallback_fn (insn);
371 : : break;
372 : :
373 : 367230521 : case INSN:
374 : 367230521 : body = PATTERN (insn);
375 : 367230521 : if (GET_CODE (body) == USE || GET_CODE (body) == CLOBBER)
376 : : return 0;
377 : :
378 : 366879875 : else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
379 : 7562 : length = asm_insn_count (body) * fallback_fn (insn);
380 : 366872313 : else if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (body))
381 : 0 : for (i = 0; i < seq->len (); i++)
382 : 0 : length += get_attr_length_1 (seq->insn (i), fallback_fn);
383 : : else
384 : 366872313 : length = fallback_fn (insn);
385 : : break;
386 : :
387 : : default:
388 : : break;
389 : : }
390 : :
391 : : #ifdef ADJUST_INSN_LENGTH
392 : : ADJUST_INSN_LENGTH (insn, length);
393 : : #endif
394 : : return length;
395 : : }
396 : :
397 : : /* Obtain the current length of an insn. If branch shortening has been done,
398 : : get its actual length. Otherwise, get its maximum length. */
399 : : int
400 : 369175771 : get_attr_length (rtx_insn *insn)
401 : : {
402 : 369175771 : return get_attr_length_1 (insn, insn_default_length);
403 : : }
404 : :
405 : : /* Obtain the current length of an insn. If branch shortening has been done,
406 : : get its actual length. Otherwise, get its minimum length. */
407 : : int
408 : 17908232 : get_attr_min_length (rtx_insn *insn)
409 : : {
410 : 17908232 : return get_attr_length_1 (insn, insn_min_length);
411 : : }
412 : :
413 : : /* Code to handle alignment inside shorten_branches. */
414 : :
415 : : /* Here is an explanation how the algorithm in align_fuzz can give
416 : : proper results:
417 : :
418 : : Call a sequence of instructions beginning with alignment point X
419 : : and continuing until the next alignment point `block X'. When `X'
420 : : is used in an expression, it means the alignment value of the
421 : : alignment point.
422 : :
423 : : Call the distance between the start of the first insn of block X, and
424 : : the end of the last insn of block X `IX', for the `inner size of X'.
425 : : This is clearly the sum of the instruction lengths.
426 : :
427 : : Likewise with the next alignment-delimited block following X, which we
428 : : shall call block Y.
429 : :
430 : : Call the distance between the start of the first insn of block X, and
431 : : the start of the first insn of block Y `OX', for the `outer size of X'.
432 : :
433 : : The estimated padding is then OX - IX.
434 : :
435 : : OX can be safely estimated as
436 : :
437 : : if (X >= Y)
438 : : OX = round_up(IX, Y)
439 : : else
440 : : OX = round_up(IX, X) + Y - X
441 : :
442 : : Clearly est(IX) >= real(IX), because that only depends on the
443 : : instruction lengths, and those being overestimated is a given.
444 : :
445 : : Clearly round_up(foo, Z) >= round_up(bar, Z) if foo >= bar, so
446 : : we needn't worry about that when thinking about OX.
447 : :
448 : : When X >= Y, the alignment provided by Y adds no uncertainty factor
449 : : for branch ranges starting before X, so we can just round what we have.
450 : : But when X < Y, we don't know anything about the, so to speak,
451 : : `middle bits', so we have to assume the worst when aligning up from an
452 : : address mod X to one mod Y, which is Y - X. */
453 : :
454 : : #ifndef LABEL_ALIGN
455 : : #define LABEL_ALIGN(LABEL) align_labels
456 : : #endif
457 : :
458 : : #ifndef LOOP_ALIGN
459 : : #define LOOP_ALIGN(LABEL) align_loops
460 : : #endif
461 : :
462 : : #ifndef LABEL_ALIGN_AFTER_BARRIER
463 : : #define LABEL_ALIGN_AFTER_BARRIER(LABEL) 0
464 : : #endif
465 : :
466 : : #ifndef JUMP_ALIGN
467 : : #define JUMP_ALIGN(LABEL) align_jumps
468 : : #endif
469 : :
470 : : #ifndef ADDR_VEC_ALIGN
471 : : static int
472 : 9833 : final_addr_vec_align (rtx_jump_table_data *addr_vec)
473 : : {
474 : 9833 : int align = GET_MODE_SIZE (addr_vec->get_data_mode ());
475 : :
476 : 19577 : if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
477 : 0 : align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
478 : 9833 : return exact_log2 (align);
479 : :
480 : : }
481 : :
482 : : #define ADDR_VEC_ALIGN(ADDR_VEC) final_addr_vec_align (ADDR_VEC)
483 : : #endif
484 : :
485 : : #ifndef INSN_LENGTH_ALIGNMENT
486 : : #define INSN_LENGTH_ALIGNMENT(INSN) length_unit_log
487 : : #endif
488 : :
489 : : #define INSN_SHUID(INSN) (uid_shuid[INSN_UID (INSN)])
490 : :
491 : : static int min_labelno, max_labelno;
492 : :
493 : : #define LABEL_TO_ALIGNMENT(LABEL) \
494 : : (label_align[CODE_LABEL_NUMBER (LABEL) - min_labelno])
495 : :
496 : : /* For the benefit of port specific code do this also as a function. */
497 : :
498 : : align_flags
499 : 966 : label_to_alignment (rtx label)
500 : : {
501 : 966 : if (CODE_LABEL_NUMBER (label) <= max_labelno)
502 : 966 : return LABEL_TO_ALIGNMENT (label);
503 : 0 : return align_flags ();
504 : : }
505 : :
506 : : /* The differences in addresses
507 : : between a branch and its target might grow or shrink depending on
508 : : the alignment the start insn of the range (the branch for a forward
509 : : branch or the label for a backward branch) starts out on; if these
510 : : differences are used naively, they can even oscillate infinitely.
511 : : We therefore want to compute a 'worst case' address difference that
512 : : is independent of the alignment the start insn of the range end
513 : : up on, and that is at least as large as the actual difference.
514 : : The function align_fuzz calculates the amount we have to add to the
515 : : naively computed difference, by traversing the part of the alignment
516 : : chain of the start insn of the range that is in front of the end insn
517 : : of the range, and considering for each alignment the maximum amount
518 : : that it might contribute to a size increase.
519 : :
520 : : For casesi tables, we also want to know worst case minimum amounts of
521 : : address difference, in case a machine description wants to introduce
522 : : some common offset that is added to all offsets in a table.
523 : : For this purpose, align_fuzz with a growth argument of 0 computes the
524 : : appropriate adjustment. */
525 : :
526 : : /* Compute the maximum delta by which the difference of the addresses of
527 : : START and END might grow / shrink due to a different address for start
528 : : which changes the size of alignment insns between START and END.
529 : : KNOWN_ALIGN_LOG is the alignment known for START.
530 : : GROWTH should be ~0 if the objective is to compute potential code size
531 : : increase, and 0 if the objective is to compute potential shrink.
532 : : The return value is undefined for any other value of GROWTH. */
533 : :
534 : : static int
535 : 27773781 : align_fuzz (rtx start, rtx end, int known_align_log, unsigned int growth)
536 : : {
537 : 27773781 : int uid = INSN_UID (start);
538 : 27773781 : rtx align_label;
539 : 27773781 : int known_align = 1 << known_align_log;
540 : 27773781 : int end_shuid = INSN_SHUID (end);
541 : 27773781 : int fuzz = 0;
542 : :
543 : 41063068 : for (align_label = uid_align[uid]; align_label; align_label = uid_align[uid])
544 : : {
545 : 15960779 : int align_addr, new_align;
546 : :
547 : 15960779 : uid = INSN_UID (align_label);
548 : 15960779 : align_addr = INSN_ADDRESSES (uid) - insn_lengths[uid];
549 : 15960779 : if (uid_shuid[uid] > end_shuid)
550 : : break;
551 : 13289287 : align_flags alignment = LABEL_TO_ALIGNMENT (align_label);
552 : 13289287 : new_align = 1 << alignment.levels[0].log;
553 : 13289287 : if (new_align < known_align)
554 : 0 : continue;
555 : 13289287 : fuzz += (-align_addr ^ growth) & (new_align - known_align);
556 : 13289287 : known_align = new_align;
557 : : }
558 : 27773781 : return fuzz;
559 : : }
560 : :
561 : : /* Compute a worst-case reference address of a branch so that it
562 : : can be safely used in the presence of aligned labels. Since the
563 : : size of the branch itself is unknown, the size of the branch is
564 : : not included in the range. I.e. for a forward branch, the reference
565 : : address is the end address of the branch as known from the previous
566 : : branch shortening pass, minus a value to account for possible size
567 : : increase due to alignment. For a backward branch, it is the start
568 : : address of the branch as known from the current pass, plus a value
569 : : to account for possible size increase due to alignment.
570 : : NB.: Therefore, the maximum offset allowed for backward branches needs
571 : : to exclude the branch size. */
572 : :
573 : : int
574 : 27773781 : insn_current_reference_address (rtx_insn *branch)
575 : : {
576 : 27773781 : rtx dest;
577 : 27773781 : int seq_uid;
578 : :
579 : 27773781 : if (! INSN_ADDRESSES_SET_P ())
580 : : return 0;
581 : :
582 : 27773781 : rtx_insn *seq = NEXT_INSN (PREV_INSN (branch));
583 : 27773781 : seq_uid = INSN_UID (seq);
584 : 27773781 : if (!jump_to_label_p (branch))
585 : : /* This can happen for example on the PA; the objective is to know the
586 : : offset to address something in front of the start of the function.
587 : : Thus, we can treat it like a backward branch.
588 : : We assume here that FUNCTION_BOUNDARY / BITS_PER_UNIT is larger than
589 : : any alignment we'd encounter, so we skip the call to align_fuzz. */
590 : 0 : return insn_current_address;
591 : 27773781 : dest = JUMP_LABEL (branch);
592 : :
593 : : /* BRANCH has no proper alignment chain set, so use SEQ.
594 : : BRANCH also has no INSN_SHUID. */
595 : 27773781 : if (INSN_SHUID (seq) < INSN_SHUID (dest))
596 : : {
597 : : /* Forward branch. */
598 : 19985354 : return (insn_last_address + insn_lengths[seq_uid]
599 : 19985354 : - align_fuzz (seq, dest, length_unit_log, ~0));
600 : : }
601 : : else
602 : : {
603 : : /* Backward branch. */
604 : 7788427 : return (insn_current_address
605 : 7788427 : + align_fuzz (dest, seq, length_unit_log, ~0));
606 : : }
607 : : }
608 : :
609 : : /* Compute branch alignments based on CFG profile. */
610 : :
611 : : void
612 : 1449856 : compute_alignments (void)
613 : : {
614 : 1449856 : basic_block bb;
615 : 1449856 : align_flags max_alignment;
616 : :
617 : 1449856 : label_align.truncate (0);
618 : :
619 : 1449856 : max_labelno = max_label_num ();
620 : 1449856 : min_labelno = get_first_label_num ();
621 : 1449856 : label_align.safe_grow_cleared (max_labelno - min_labelno + 1, true);
622 : :
623 : : /* If not optimizing or optimizing for size, don't assign any alignments. */
624 : 1449856 : if (! optimize || optimize_function_for_size_p (cfun))
625 : 488529 : return;
626 : :
627 : 961327 : if (dump_file)
628 : : {
629 : 32 : dump_reg_info (dump_file);
630 : 32 : dump_flow_info (dump_file, TDF_DETAILS);
631 : 32 : flow_loops_dump (dump_file, NULL, 1);
632 : : }
633 : 961327 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
634 : 961327 : profile_count count_threshold = cfun->cfg->count_max / param_align_threshold;
635 : :
636 : 961327 : if (dump_file)
637 : : {
638 : 32 : fprintf (dump_file, "count_max: ");
639 : 32 : cfun->cfg->count_max.dump (dump_file);
640 : 32 : fprintf (dump_file, "\n");
641 : : }
642 : 11421289 : FOR_EACH_BB_FN (bb, cfun)
643 : : {
644 : 10459962 : rtx_insn *label = BB_HEAD (bb);
645 : 10459962 : bool has_fallthru = 0;
646 : 10459962 : edge e;
647 : 10459962 : edge_iterator ei;
648 : :
649 : 17198985 : if (!LABEL_P (label)
650 : 10459962 : || optimize_bb_for_size_p (bb))
651 : : {
652 : 6739023 : if (dump_file)
653 : 141 : fprintf (dump_file,
654 : : "BB %4i loop %2i loop_depth %2i skipped.\n",
655 : : bb->index,
656 : 141 : bb->loop_father->num,
657 : : bb_loop_depth (bb));
658 : 6740490 : continue;
659 : : }
660 : 3720939 : max_alignment = LABEL_ALIGN (label);
661 : 3720939 : profile_count fallthru_count = profile_count::zero ();
662 : 3720939 : profile_count branch_count = profile_count::zero ();
663 : :
664 : 10853016 : FOR_EACH_EDGE (e, ei, bb->preds)
665 : : {
666 : 7132077 : if (e->flags & EDGE_FALLTHRU)
667 : 2308230 : has_fallthru = 1, fallthru_count += e->count ();
668 : : else
669 : 4823847 : branch_count += e->count ();
670 : : }
671 : 3720939 : if (dump_file)
672 : : {
673 : 125 : fprintf (dump_file, "BB %4i loop %2i loop_depth"
674 : : " %2i fall ",
675 : 125 : bb->index, bb->loop_father->num,
676 : : bb_loop_depth (bb));
677 : 125 : fallthru_count.dump (dump_file);
678 : 125 : fprintf (dump_file, " branch ");
679 : 125 : branch_count.dump (dump_file);
680 : 125 : if (!bb->loop_father->inner && bb->loop_father->num)
681 : 20 : fprintf (dump_file, " inner_loop");
682 : 125 : if (bb->loop_father->header == bb)
683 : 18 : fprintf (dump_file, " loop_header");
684 : 125 : fprintf (dump_file, "\n");
685 : : }
686 : 3720939 : if (!fallthru_count.initialized_p () || !branch_count.initialized_p ())
687 : 1467 : continue;
688 : :
689 : : /* There are two purposes to align block with no fallthru incoming edge:
690 : : 1) to avoid fetch stalls when branch destination is near cache boundary
691 : : 2) to improve cache efficiency in case the previous block is not executed
692 : : (so it does not need to be in the cache).
693 : :
694 : : We to catch first case, we align frequently executed blocks.
695 : : To catch the second, we align blocks that are executed more frequently
696 : : than the predecessor and the predecessor is likely to not be executed
697 : : when function is called. */
698 : :
699 : 3719472 : if (!has_fallthru
700 : 3719472 : && (branch_count > count_threshold
701 : 377596 : || (bb->count > bb->prev_bb->count * 10
702 : 28683 : && (bb->prev_bb->count
703 : 2685320 : <= ENTRY_BLOCK_PTR_FOR_FN (cfun)->count / 2))))
704 : : {
705 : 1062835 : align_flags alignment = JUMP_ALIGN (label);
706 : 1062835 : if (dump_file)
707 : 40 : fprintf (dump_file, " jump alignment added.\n");
708 : 1062835 : max_alignment = align_flags::max (max_alignment, alignment);
709 : : }
710 : : /* In case block is frequent and reached mostly by non-fallthru edge,
711 : : align it. It is most likely a first block of loop. */
712 : 3719472 : if (has_fallthru
713 : 2307205 : && !(single_succ_p (bb)
714 : 797556 : && single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun))
715 : 1964855 : && optimize_bb_for_speed_p (bb)
716 : 1964855 : && branch_count + fallthru_count > count_threshold
717 : 6026679 : && (branch_count > fallthru_count * param_align_loop_iterations))
718 : : {
719 : 299796 : align_flags alignment = LOOP_ALIGN (label);
720 : 299796 : if (dump_file)
721 : 11 : fprintf (dump_file, " internal loop alignment added.\n");
722 : 299796 : max_alignment = align_flags::max (max_alignment, alignment);
723 : : }
724 : 3719472 : LABEL_TO_ALIGNMENT (label) = max_alignment;
725 : : }
726 : :
727 : 961327 : loop_optimizer_finalize ();
728 : 961327 : free_dominance_info (CDI_DOMINATORS);
729 : : }
730 : :
731 : : /* Grow the LABEL_ALIGN array after new labels are created. */
732 : :
733 : : static void
734 : 3 : grow_label_align (void)
735 : : {
736 : 3 : int old = max_labelno;
737 : 3 : int n_labels;
738 : 3 : int n_old_labels;
739 : :
740 : 3 : max_labelno = max_label_num ();
741 : :
742 : 3 : n_labels = max_labelno - min_labelno + 1;
743 : 3 : n_old_labels = old - min_labelno + 1;
744 : :
745 : 3 : label_align.safe_grow_cleared (n_labels, true);
746 : :
747 : : /* Range of labels grows monotonically in the function. Failing here
748 : : means that the initialization of array got lost. */
749 : 3 : gcc_assert (n_old_labels <= n_labels);
750 : 3 : }
751 : :
752 : : /* Update the already computed alignment information. LABEL_PAIRS is a vector
753 : : made up of pairs of labels for which the alignment information of the first
754 : : element will be copied from that of the second element. */
755 : :
756 : : void
757 : 0 : update_alignments (vec<rtx> &label_pairs)
758 : : {
759 : 0 : unsigned int i = 0;
760 : 0 : rtx iter, label = NULL_RTX;
761 : :
762 : 0 : if (max_labelno != max_label_num ())
763 : 0 : grow_label_align ();
764 : :
765 : 0 : FOR_EACH_VEC_ELT (label_pairs, i, iter)
766 : 0 : if (i & 1)
767 : 0 : LABEL_TO_ALIGNMENT (label) = LABEL_TO_ALIGNMENT (iter);
768 : : else
769 : : label = iter;
770 : 0 : }
771 : :
772 : : namespace {
773 : :
774 : : const pass_data pass_data_compute_alignments =
775 : : {
776 : : RTL_PASS, /* type */
777 : : "alignments", /* name */
778 : : OPTGROUP_NONE, /* optinfo_flags */
779 : : TV_NONE, /* tv_id */
780 : : 0, /* properties_required */
781 : : 0, /* properties_provided */
782 : : 0, /* properties_destroyed */
783 : : 0, /* todo_flags_start */
784 : : 0, /* todo_flags_finish */
785 : : };
786 : :
787 : : class pass_compute_alignments : public rtl_opt_pass
788 : : {
789 : : public:
790 : 285081 : pass_compute_alignments (gcc::context *ctxt)
791 : 570162 : : rtl_opt_pass (pass_data_compute_alignments, ctxt)
792 : : {}
793 : :
794 : : /* opt_pass methods: */
795 : 1449856 : unsigned int execute (function *) final override
796 : : {
797 : 1449856 : compute_alignments ();
798 : 1449856 : return 0;
799 : : }
800 : :
801 : : }; // class pass_compute_alignments
802 : :
803 : : } // anon namespace
804 : :
805 : : rtl_opt_pass *
806 : 285081 : make_pass_compute_alignments (gcc::context *ctxt)
807 : : {
808 : 285081 : return new pass_compute_alignments (ctxt);
809 : : }
810 : :
811 : :
812 : : /* Make a pass over all insns and compute their actual lengths by shortening
813 : : any branches of variable length if possible. */
814 : :
815 : : /* shorten_branches might be called multiple times: for example, the SH
816 : : port splits out-of-range conditional branches in MACHINE_DEPENDENT_REORG.
817 : : In order to do this, it needs proper length information, which it obtains
818 : : by calling shorten_branches. This cannot be collapsed with
819 : : shorten_branches itself into a single pass unless we also want to integrate
820 : : reorg.cc, since the branch splitting exposes new instructions with delay
821 : : slots. */
822 : :
823 : : void
824 : 1451611 : shorten_branches (rtx_insn *first)
825 : : {
826 : 1451611 : rtx_insn *insn;
827 : 1451611 : int max_uid;
828 : 1451611 : int i;
829 : 1451611 : rtx_insn *seq;
830 : 1451611 : bool something_changed = true;
831 : 1451611 : char *varying_length;
832 : 1451611 : rtx body;
833 : 1451611 : int uid;
834 : 1451611 : rtx align_tab[MAX_CODE_ALIGN + 1];
835 : :
836 : : /* Compute maximum UID and allocate label_align / uid_shuid. */
837 : 1451611 : max_uid = get_max_uid ();
838 : :
839 : : /* Free uid_shuid before reallocating it. */
840 : 1451611 : free (uid_shuid);
841 : :
842 : 1451611 : uid_shuid = XNEWVEC (int, max_uid);
843 : :
844 : 1451611 : if (max_labelno != max_label_num ())
845 : 3 : grow_label_align ();
846 : :
847 : : /* Initialize label_align and set up uid_shuid to be strictly
848 : : monotonically rising with insn order. */
849 : : /* We use alignment here to keep track of the maximum alignment we want to
850 : : impose on the next CODE_LABEL (or the current one if we are processing
851 : : the CODE_LABEL itself). */
852 : :
853 : 1451611 : align_flags max_alignment;
854 : :
855 : 201640817 : for (insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn))
856 : : {
857 : 200189206 : INSN_SHUID (insn) = i++;
858 : 200189206 : if (INSN_P (insn))
859 : 92690342 : continue;
860 : :
861 : 107498864 : if (rtx_code_label *label = dyn_cast <rtx_code_label *> (insn))
862 : : {
863 : : /* Merge in alignments computed by compute_alignments. */
864 : 6830383 : align_flags alignment = LABEL_TO_ALIGNMENT (label);
865 : 6830383 : max_alignment = align_flags::max (max_alignment, alignment);
866 : :
867 : 6830383 : rtx_jump_table_data *table = jump_table_for_label (label);
868 : 6830383 : if (!table)
869 : : {
870 : 6820550 : align_flags alignment = LABEL_ALIGN (label);
871 : 6820550 : max_alignment = align_flags::max (max_alignment, alignment);
872 : : }
873 : : /* ADDR_VECs only take room if read-only data goes into the text
874 : : section. */
875 : 6830383 : if ((JUMP_TABLES_IN_TEXT_SECTION
876 : 6830383 : || readonly_data_section == text_section)
877 : 0 : && table)
878 : : {
879 : 0 : align_flags alignment = align_flags (ADDR_VEC_ALIGN (table));
880 : 0 : max_alignment = align_flags::max (max_alignment, alignment);
881 : : }
882 : 6830383 : LABEL_TO_ALIGNMENT (label) = max_alignment;
883 : 6830383 : max_alignment = align_flags ();
884 : : }
885 : 100668481 : else if (BARRIER_P (insn))
886 : : {
887 : : rtx_insn *label;
888 : :
889 : 26182988 : for (label = insn; label && ! INSN_P (label);
890 : 21486662 : label = NEXT_INSN (label))
891 : 24685336 : if (LABEL_P (label))
892 : : {
893 : 3198674 : align_flags alignment
894 : 3198674 : = align_flags (LABEL_ALIGN_AFTER_BARRIER (insn));
895 : 3198674 : max_alignment = align_flags::max (max_alignment, alignment);
896 : 3198674 : break;
897 : : }
898 : : }
899 : : }
900 : 1451611 : if (!HAVE_ATTR_length)
901 : : return;
902 : :
903 : : /* Allocate the rest of the arrays. */
904 : 1451611 : insn_lengths = XNEWVEC (int, max_uid);
905 : 1451611 : insn_lengths_max_uid = max_uid;
906 : : /* Syntax errors can lead to labels being outside of the main insn stream.
907 : : Initialize insn_addresses, so that we get reproducible results. */
908 : 1451611 : INSN_ADDRESSES_ALLOC (max_uid);
909 : :
910 : 1451611 : varying_length = XCNEWVEC (char, max_uid);
911 : :
912 : : /* Initialize uid_align. We scan instructions
913 : : from end to start, and keep in align_tab[n] the last seen insn
914 : : that does an alignment of at least n+1, i.e. the successor
915 : : in the alignment chain for an insn that does / has a known
916 : : alignment of n. */
917 : 1451611 : uid_align = XCNEWVEC (rtx, max_uid);
918 : :
919 : 26128998 : for (i = MAX_CODE_ALIGN + 1; --i >= 0;)
920 : 24677387 : align_tab[i] = NULL_RTX;
921 : 1451611 : seq = get_last_insn ();
922 : 201640817 : for (; seq; seq = PREV_INSN (seq))
923 : : {
924 : 200189206 : int uid = INSN_UID (seq);
925 : 200189206 : int log;
926 : 200189206 : log = (LABEL_P (seq) ? LABEL_TO_ALIGNMENT (seq).levels[0].log : 0);
927 : 200189206 : uid_align[uid] = align_tab[0];
928 : 200189206 : if (log)
929 : : {
930 : : /* Found an alignment label. */
931 : 1308906 : gcc_checking_assert (log < MAX_CODE_ALIGN + 1);
932 : 1308906 : uid_align[uid] = align_tab[log];
933 : 6544617 : for (i = log - 1; i >= 0; i--)
934 : 5235711 : align_tab[i] = seq;
935 : : }
936 : : }
937 : :
938 : : /* When optimizing, we start assuming minimum length, and keep increasing
939 : : lengths as we find the need for this, till nothing changes.
940 : : When not optimizing, we start assuming maximum lengths, and
941 : : do a single pass to update the lengths. */
942 : 1451611 : bool increasing = optimize != 0;
943 : :
944 : : #ifdef CASE_VECTOR_SHORTEN_MODE
945 : : if (optimize)
946 : : {
947 : : /* Look for ADDR_DIFF_VECs, and initialize their minimum and maximum
948 : : label fields. */
949 : :
950 : : int min_shuid = INSN_SHUID (get_insns ()) - 1;
951 : : int max_shuid = INSN_SHUID (get_last_insn ()) + 1;
952 : : int rel;
953 : :
954 : : for (insn = first; insn != 0; insn = NEXT_INSN (insn))
955 : : {
956 : : rtx min_lab = NULL_RTX, max_lab = NULL_RTX, pat;
957 : : int len, i, min, max, insn_shuid;
958 : : int min_align;
959 : : addr_diff_vec_flags flags;
960 : :
961 : : if (! JUMP_TABLE_DATA_P (insn)
962 : : || GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC)
963 : : continue;
964 : : pat = PATTERN (insn);
965 : : len = XVECLEN (pat, 1);
966 : : gcc_assert (len > 0);
967 : : min_align = MAX_CODE_ALIGN;
968 : : for (min = max_shuid, max = min_shuid, i = len - 1; i >= 0; i--)
969 : : {
970 : : rtx lab = XEXP (XVECEXP (pat, 1, i), 0);
971 : : int shuid = INSN_SHUID (lab);
972 : : if (shuid < min)
973 : : {
974 : : min = shuid;
975 : : min_lab = lab;
976 : : }
977 : : if (shuid > max)
978 : : {
979 : : max = shuid;
980 : : max_lab = lab;
981 : : }
982 : :
983 : : int label_alignment = LABEL_TO_ALIGNMENT (lab).levels[0].log;
984 : : if (min_align > label_alignment)
985 : : min_align = label_alignment;
986 : : }
987 : : XEXP (pat, 2) = gen_rtx_LABEL_REF (Pmode, min_lab);
988 : : XEXP (pat, 3) = gen_rtx_LABEL_REF (Pmode, max_lab);
989 : : insn_shuid = INSN_SHUID (insn);
990 : : rel = INSN_SHUID (XEXP (XEXP (pat, 0), 0));
991 : : memset (&flags, 0, sizeof (flags));
992 : : flags.min_align = min_align;
993 : : flags.base_after_vec = rel > insn_shuid;
994 : : flags.min_after_vec = min > insn_shuid;
995 : : flags.max_after_vec = max > insn_shuid;
996 : : flags.min_after_base = min > rel;
997 : : flags.max_after_base = max > rel;
998 : : ADDR_DIFF_VEC_FLAGS (pat) = flags;
999 : :
1000 : : if (increasing)
1001 : : PUT_MODE (pat, CASE_VECTOR_SHORTEN_MODE (0, 0, pat));
1002 : : }
1003 : : }
1004 : : #endif /* CASE_VECTOR_SHORTEN_MODE */
1005 : :
1006 : : /* Compute initial lengths, addresses, and varying flags for each insn. */
1007 : 1451611 : int (*length_fun) (rtx_insn *) = increasing ? insn_min_length : insn_default_length;
1008 : :
1009 : 1451611 : for (insn_current_address = 0, insn = first;
1010 : 201640817 : insn != 0;
1011 : 200189206 : insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn))
1012 : : {
1013 : 200189206 : uid = INSN_UID (insn);
1014 : :
1015 : 200189206 : insn_lengths[uid] = 0;
1016 : :
1017 : 200189206 : if (LABEL_P (insn))
1018 : : {
1019 : 6830383 : int log = LABEL_TO_ALIGNMENT (insn).levels[0].log;
1020 : 6830383 : if (log)
1021 : : {
1022 : 1308906 : int align = 1 << log;
1023 : 1308906 : int new_address = (insn_current_address + align - 1) & -align;
1024 : 1308906 : insn_lengths[uid] = new_address - insn_current_address;
1025 : : }
1026 : : }
1027 : :
1028 : 200189206 : INSN_ADDRESSES (uid) = insn_current_address + insn_lengths[uid];
1029 : :
1030 : 200189206 : if (NOTE_P (insn) || BARRIER_P (insn)
1031 : 99530558 : || LABEL_P (insn) || DEBUG_INSN_P (insn))
1032 : 107489035 : continue;
1033 : 92700171 : if (insn->deleted ())
1034 : 0 : continue;
1035 : :
1036 : 92700171 : body = PATTERN (insn);
1037 : 92700171 : if (rtx_jump_table_data *table = dyn_cast <rtx_jump_table_data *> (insn))
1038 : : {
1039 : : /* This only takes room if read-only data goes into the text
1040 : : section. */
1041 : 9833 : if (JUMP_TABLES_IN_TEXT_SECTION
1042 : 9833 : || readonly_data_section == text_section)
1043 : 0 : insn_lengths[uid] = (XVECLEN (body,
1044 : : GET_CODE (body) == ADDR_DIFF_VEC)
1045 : 0 : * GET_MODE_SIZE (table->get_data_mode ()));
1046 : : /* Alignment is handled by ADDR_VEC_ALIGN. */
1047 : : }
1048 : 92690338 : else if (GET_CODE (body) == ASM_INPUT || asm_noperands (body) >= 0)
1049 : 106460 : insn_lengths[uid] = asm_insn_count (body) * insn_default_length (insn);
1050 : 92583878 : else if (rtx_sequence *body_seq = dyn_cast <rtx_sequence *> (body))
1051 : : {
1052 : : int i;
1053 : : int const_delay_slots;
1054 : : if (DELAY_SLOTS)
1055 : : const_delay_slots = const_num_delay_slots (body_seq->insn (0));
1056 : : else
1057 : : const_delay_slots = 0;
1058 : :
1059 : : int (*inner_length_fun) (rtx_insn *)
1060 : : = const_delay_slots ? length_fun : insn_default_length;
1061 : : /* Inside a delay slot sequence, we do not do any branch shortening
1062 : : if the shortening could change the number of delay slots
1063 : : of the branch. */
1064 : 0 : for (i = 0; i < body_seq->len (); i++)
1065 : : {
1066 : 0 : rtx_insn *inner_insn = body_seq->insn (i);
1067 : 0 : int inner_uid = INSN_UID (inner_insn);
1068 : 0 : int inner_length;
1069 : :
1070 : 0 : if (GET_CODE (PATTERN (inner_insn)) == ASM_INPUT
1071 : 0 : || asm_noperands (PATTERN (inner_insn)) >= 0)
1072 : 0 : inner_length = (asm_insn_count (PATTERN (inner_insn))
1073 : 0 : * insn_default_length (inner_insn));
1074 : : else
1075 : 0 : inner_length = inner_length_fun (inner_insn);
1076 : :
1077 : 0 : insn_lengths[inner_uid] = inner_length;
1078 : 0 : if (const_delay_slots)
1079 : : {
1080 : : if ((varying_length[inner_uid]
1081 : : = insn_variable_length_p (inner_insn)) != 0)
1082 : : varying_length[uid] = 1;
1083 : : INSN_ADDRESSES (inner_uid) = (insn_current_address
1084 : : + insn_lengths[uid]);
1085 : : }
1086 : : else
1087 : 0 : varying_length[inner_uid] = 0;
1088 : 0 : insn_lengths[uid] += inner_length;
1089 : : }
1090 : : }
1091 : 92583878 : else if (GET_CODE (body) != USE && GET_CODE (body) != CLOBBER)
1092 : : {
1093 : 91542474 : insn_lengths[uid] = length_fun (insn);
1094 : 91542474 : varying_length[uid] = insn_variable_length_p (insn);
1095 : : }
1096 : :
1097 : : /* If needed, do any adjustment. */
1098 : : #ifdef ADJUST_INSN_LENGTH
1099 : : ADJUST_INSN_LENGTH (insn, insn_lengths[uid]);
1100 : : if (insn_lengths[uid] < 0)
1101 : : fatal_insn ("negative insn length", insn);
1102 : : #endif
1103 : : }
1104 : :
1105 : : /* Now loop over all the insns finding varying length insns. For each,
1106 : : get the current insn length. If it has changed, reflect the change.
1107 : : When nothing changes for a full pass, we are done. */
1108 : :
1109 : 2737465 : while (something_changed)
1110 : : {
1111 : 1713542 : something_changed = false;
1112 : 1713542 : insn_current_align = MAX_CODE_ALIGN - 1;
1113 : 365093264 : for (insn_current_address = 0, insn = first;
1114 : 365093264 : insn != 0;
1115 : 363379722 : insn = NEXT_INSN (insn))
1116 : : {
1117 : 363379722 : int new_length;
1118 : : #ifdef ADJUST_INSN_LENGTH
1119 : : int tmp_length;
1120 : : #endif
1121 : 363379722 : int length_align;
1122 : :
1123 : 363379722 : uid = INSN_UID (insn);
1124 : :
1125 : 363379722 : if (rtx_code_label *label = dyn_cast <rtx_code_label *> (insn))
1126 : : {
1127 : 12236502 : int log = LABEL_TO_ALIGNMENT (label).levels[0].log;
1128 : :
1129 : : #ifdef CASE_VECTOR_SHORTEN_MODE
1130 : : /* If the mode of a following jump table was changed, we
1131 : : may need to update the alignment of this label. */
1132 : :
1133 : : if (JUMP_TABLES_IN_TEXT_SECTION
1134 : : || readonly_data_section == text_section)
1135 : : {
1136 : : rtx_jump_table_data *table = jump_table_for_label (label);
1137 : : if (table)
1138 : : {
1139 : : int newlog = ADDR_VEC_ALIGN (table);
1140 : : if (newlog != log)
1141 : : {
1142 : : log = newlog;
1143 : : LABEL_TO_ALIGNMENT (insn) = log;
1144 : : something_changed = true;
1145 : : }
1146 : : }
1147 : : }
1148 : : #endif
1149 : :
1150 : 12236502 : if (log > insn_current_align)
1151 : : {
1152 : 2652257 : int align = 1 << log;
1153 : 2652257 : int new_address= (insn_current_address + align - 1) & -align;
1154 : 2652257 : insn_lengths[uid] = new_address - insn_current_address;
1155 : 2652257 : insn_current_align = log;
1156 : 2652257 : insn_current_address = new_address;
1157 : : }
1158 : : else
1159 : 9584245 : insn_lengths[uid] = 0;
1160 : 12236502 : INSN_ADDRESSES (uid) = insn_current_address;
1161 : 12236502 : continue;
1162 : 12236502 : }
1163 : :
1164 : 351143220 : length_align = INSN_LENGTH_ALIGNMENT (insn);
1165 : 351143220 : if (length_align < insn_current_align)
1166 : 4365799 : insn_current_align = length_align;
1167 : :
1168 : 351143220 : insn_last_address = INSN_ADDRESSES (uid);
1169 : 351143220 : INSN_ADDRESSES (uid) = insn_current_address;
1170 : :
1171 : : #ifdef CASE_VECTOR_SHORTEN_MODE
1172 : : if (optimize
1173 : : && JUMP_TABLE_DATA_P (insn)
1174 : : && GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
1175 : : {
1176 : : rtx_jump_table_data *table = as_a <rtx_jump_table_data *> (insn);
1177 : : rtx body = PATTERN (insn);
1178 : : int old_length = insn_lengths[uid];
1179 : : rtx_insn *rel_lab =
1180 : : safe_as_a <rtx_insn *> (XEXP (XEXP (body, 0), 0));
1181 : : rtx min_lab = XEXP (XEXP (body, 2), 0);
1182 : : rtx max_lab = XEXP (XEXP (body, 3), 0);
1183 : : int rel_addr = INSN_ADDRESSES (INSN_UID (rel_lab));
1184 : : int min_addr = INSN_ADDRESSES (INSN_UID (min_lab));
1185 : : int max_addr = INSN_ADDRESSES (INSN_UID (max_lab));
1186 : : rtx_insn *prev;
1187 : : int rel_align = 0;
1188 : : addr_diff_vec_flags flags;
1189 : : scalar_int_mode vec_mode;
1190 : :
1191 : : /* Avoid automatic aggregate initialization. */
1192 : : flags = ADDR_DIFF_VEC_FLAGS (body);
1193 : :
1194 : : /* Try to find a known alignment for rel_lab. */
1195 : : for (prev = rel_lab;
1196 : : prev
1197 : : && ! insn_lengths[INSN_UID (prev)]
1198 : : && ! (varying_length[INSN_UID (prev)] & 1);
1199 : : prev = PREV_INSN (prev))
1200 : : if (varying_length[INSN_UID (prev)] & 2)
1201 : : {
1202 : : rel_align = LABEL_TO_ALIGNMENT (prev).levels[0].log;
1203 : : break;
1204 : : }
1205 : :
1206 : : /* See the comment on addr_diff_vec_flags in rtl.h for the
1207 : : meaning of the flags values. base: REL_LAB vec: INSN */
1208 : : /* Anything after INSN has still addresses from the last
1209 : : pass; adjust these so that they reflect our current
1210 : : estimate for this pass. */
1211 : : if (flags.base_after_vec)
1212 : : rel_addr += insn_current_address - insn_last_address;
1213 : : if (flags.min_after_vec)
1214 : : min_addr += insn_current_address - insn_last_address;
1215 : : if (flags.max_after_vec)
1216 : : max_addr += insn_current_address - insn_last_address;
1217 : : /* We want to know the worst case, i.e. lowest possible value
1218 : : for the offset of MIN_LAB. If MIN_LAB is after REL_LAB,
1219 : : its offset is positive, and we have to be wary of code shrink;
1220 : : otherwise, it is negative, and we have to be vary of code
1221 : : size increase. */
1222 : : if (flags.min_after_base)
1223 : : {
1224 : : /* If INSN is between REL_LAB and MIN_LAB, the size
1225 : : changes we are about to make can change the alignment
1226 : : within the observed offset, therefore we have to break
1227 : : it up into two parts that are independent. */
1228 : : if (! flags.base_after_vec && flags.min_after_vec)
1229 : : {
1230 : : min_addr -= align_fuzz (rel_lab, insn, rel_align, 0);
1231 : : min_addr -= align_fuzz (insn, min_lab, 0, 0);
1232 : : }
1233 : : else
1234 : : min_addr -= align_fuzz (rel_lab, min_lab, rel_align, 0);
1235 : : }
1236 : : else
1237 : : {
1238 : : if (flags.base_after_vec && ! flags.min_after_vec)
1239 : : {
1240 : : min_addr -= align_fuzz (min_lab, insn, 0, ~0);
1241 : : min_addr -= align_fuzz (insn, rel_lab, 0, ~0);
1242 : : }
1243 : : else
1244 : : min_addr -= align_fuzz (min_lab, rel_lab, 0, ~0);
1245 : : }
1246 : : /* Likewise, determine the highest lowest possible value
1247 : : for the offset of MAX_LAB. */
1248 : : if (flags.max_after_base)
1249 : : {
1250 : : if (! flags.base_after_vec && flags.max_after_vec)
1251 : : {
1252 : : max_addr += align_fuzz (rel_lab, insn, rel_align, ~0);
1253 : : max_addr += align_fuzz (insn, max_lab, 0, ~0);
1254 : : }
1255 : : else
1256 : : max_addr += align_fuzz (rel_lab, max_lab, rel_align, ~0);
1257 : : }
1258 : : else
1259 : : {
1260 : : if (flags.base_after_vec && ! flags.max_after_vec)
1261 : : {
1262 : : max_addr += align_fuzz (max_lab, insn, 0, 0);
1263 : : max_addr += align_fuzz (insn, rel_lab, 0, 0);
1264 : : }
1265 : : else
1266 : : max_addr += align_fuzz (max_lab, rel_lab, 0, 0);
1267 : : }
1268 : : vec_mode = CASE_VECTOR_SHORTEN_MODE (min_addr - rel_addr,
1269 : : max_addr - rel_addr, body);
1270 : : if (!increasing
1271 : : || (GET_MODE_SIZE (vec_mode)
1272 : : >= GET_MODE_SIZE (table->get_data_mode ())))
1273 : : PUT_MODE (body, vec_mode);
1274 : : if (JUMP_TABLES_IN_TEXT_SECTION
1275 : : || readonly_data_section == text_section)
1276 : : {
1277 : : insn_lengths[uid]
1278 : : = (XVECLEN (body, 1)
1279 : : * GET_MODE_SIZE (table->get_data_mode ()));
1280 : : insn_current_address += insn_lengths[uid];
1281 : : if (insn_lengths[uid] != old_length)
1282 : : something_changed = true;
1283 : : }
1284 : :
1285 : : continue;
1286 : : }
1287 : : #endif /* CASE_VECTOR_SHORTEN_MODE */
1288 : :
1289 : 351143220 : if (! (varying_length[uid]))
1290 : : {
1291 : 335395568 : if (NONJUMP_INSN_P (insn)
1292 : 335395568 : && GET_CODE (PATTERN (insn)) == SEQUENCE)
1293 : : {
1294 : : int i;
1295 : :
1296 : 0 : body = PATTERN (insn);
1297 : 0 : for (i = 0; i < XVECLEN (body, 0); i++)
1298 : : {
1299 : 0 : rtx inner_insn = XVECEXP (body, 0, i);
1300 : 0 : int inner_uid = INSN_UID (inner_insn);
1301 : :
1302 : 0 : INSN_ADDRESSES (inner_uid) = insn_current_address;
1303 : :
1304 : 0 : insn_current_address += insn_lengths[inner_uid];
1305 : : }
1306 : : }
1307 : : else
1308 : 335395568 : insn_current_address += insn_lengths[uid];
1309 : :
1310 : 335395568 : continue;
1311 : 335395568 : }
1312 : :
1313 : 15747652 : if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
1314 : : {
1315 : 0 : rtx_sequence *seqn = as_a <rtx_sequence *> (PATTERN (insn));
1316 : 0 : int i;
1317 : :
1318 : 0 : body = PATTERN (insn);
1319 : 0 : new_length = 0;
1320 : 0 : for (i = 0; i < seqn->len (); i++)
1321 : : {
1322 : 0 : rtx_insn *inner_insn = seqn->insn (i);
1323 : 0 : int inner_uid = INSN_UID (inner_insn);
1324 : 0 : int inner_length;
1325 : :
1326 : 0 : INSN_ADDRESSES (inner_uid) = insn_current_address;
1327 : :
1328 : : /* insn_current_length returns 0 for insns with a
1329 : : non-varying length. */
1330 : 0 : if (! varying_length[inner_uid])
1331 : 0 : inner_length = insn_lengths[inner_uid];
1332 : : else
1333 : 0 : inner_length = insn_current_length (inner_insn);
1334 : :
1335 : 0 : if (inner_length != insn_lengths[inner_uid])
1336 : : {
1337 : 0 : if (!increasing || inner_length > insn_lengths[inner_uid])
1338 : : {
1339 : 0 : insn_lengths[inner_uid] = inner_length;
1340 : 0 : something_changed = true;
1341 : : }
1342 : : else
1343 : : inner_length = insn_lengths[inner_uid];
1344 : : }
1345 : 0 : insn_current_address += inner_length;
1346 : 0 : new_length += inner_length;
1347 : : }
1348 : : }
1349 : : else
1350 : : {
1351 : 15747652 : new_length = insn_current_length (insn);
1352 : 15747652 : insn_current_address += new_length;
1353 : : }
1354 : :
1355 : : #ifdef ADJUST_INSN_LENGTH
1356 : : /* If needed, do any adjustment. */
1357 : : tmp_length = new_length;
1358 : : ADJUST_INSN_LENGTH (insn, new_length);
1359 : : insn_current_address += (new_length - tmp_length);
1360 : : #endif
1361 : :
1362 : 15747652 : if (new_length != insn_lengths[uid]
1363 : 5271252 : && (!increasing || new_length > insn_lengths[uid]))
1364 : : {
1365 : 5271252 : insn_lengths[uid] = new_length;
1366 : 5271252 : something_changed = true;
1367 : : }
1368 : : else
1369 : 10476400 : insn_current_address += insn_lengths[uid] - new_length;
1370 : : }
1371 : : /* For a non-optimizing compile, do only a single pass. */
1372 : 1713542 : if (!increasing)
1373 : : break;
1374 : : }
1375 : 1451611 : crtl->max_insn_address = insn_current_address;
1376 : 1451611 : free (varying_length);
1377 : : }
1378 : :
1379 : : /* Given the body of an INSN known to be generated by an ASM statement, return
1380 : : the number of machine instructions likely to be generated for this insn.
1381 : : This is used to compute its length. */
1382 : :
1383 : : static int
1384 : 114107 : asm_insn_count (rtx body)
1385 : : {
1386 : 114107 : const char *templ;
1387 : :
1388 : 114107 : if (GET_CODE (body) == ASM_INPUT)
1389 : 3555 : templ = XSTR (body, 0);
1390 : : else
1391 : 110552 : templ = decode_asm_operands (body, NULL, NULL, NULL, NULL, NULL);
1392 : :
1393 : 114107 : return asm_str_count (templ);
1394 : : }
1395 : :
1396 : : /* Return the number of machine instructions likely to be generated for the
1397 : : inline-asm template. */
1398 : : int
1399 : 845325 : asm_str_count (const char *templ)
1400 : : {
1401 : 845325 : int count = 1;
1402 : :
1403 : 845325 : if (!*templ)
1404 : : return 0;
1405 : :
1406 : 5401226 : for (; *templ; templ++)
1407 : 5095792 : if (IS_ASM_LOGICAL_LINE_SEPARATOR (*templ, templ)
1408 : 5088294 : || *templ == '\n')
1409 : 234437 : count++;
1410 : :
1411 : : return count;
1412 : : }
1413 : :
1414 : : /* Return true if DWARF2 debug info can be emitted for DECL. */
1415 : :
1416 : : static bool
1417 : 2972357 : dwarf2_debug_info_emitted_p (tree decl)
1418 : : {
1419 : : /* When DWARF2 debug info is not generated internally. */
1420 : 2972357 : if (!dwarf_debuginfo_p () && !dwarf_based_debuginfo_p ())
1421 : : return false;
1422 : :
1423 : 1161098 : if (DECL_IGNORED_P (decl))
1424 : : return false;
1425 : :
1426 : : return true;
1427 : : }
1428 : :
1429 : : /* Return scope resulting from combination of S1 and S2. */
1430 : : static tree
1431 : 0 : choose_inner_scope (tree s1, tree s2)
1432 : : {
1433 : 0 : if (!s1)
1434 : : return s2;
1435 : 0 : if (!s2)
1436 : : return s1;
1437 : 0 : if (BLOCK_NUMBER (s1) > BLOCK_NUMBER (s2))
1438 : 0 : return s1;
1439 : : return s2;
1440 : : }
1441 : :
1442 : : /* Emit lexical block notes needed to change scope from S1 to S2. */
1443 : :
1444 : : static void
1445 : 17669822 : change_scope (rtx_insn *orig_insn, tree s1, tree s2)
1446 : : {
1447 : 17669822 : rtx_insn *insn = orig_insn;
1448 : 17669822 : tree com = NULL_TREE;
1449 : 17669822 : tree ts1 = s1, ts2 = s2;
1450 : 17669822 : tree s;
1451 : :
1452 : 57571058 : while (ts1 != ts2)
1453 : : {
1454 : 39901236 : gcc_assert (ts1 && ts2);
1455 : 39901236 : if (BLOCK_NUMBER (ts1) > BLOCK_NUMBER (ts2))
1456 : 16250817 : ts1 = BLOCK_SUPERCONTEXT (ts1);
1457 : 23650419 : else if (BLOCK_NUMBER (ts1) < BLOCK_NUMBER (ts2))
1458 : 16250817 : ts2 = BLOCK_SUPERCONTEXT (ts2);
1459 : : else
1460 : : {
1461 : 7399602 : ts1 = BLOCK_SUPERCONTEXT (ts1);
1462 : 7399602 : ts2 = BLOCK_SUPERCONTEXT (ts2);
1463 : : }
1464 : : }
1465 : 41320241 : com = ts1;
1466 : :
1467 : : /* Close scopes. */
1468 : : s = s1;
1469 : 41320241 : while (s != com)
1470 : : {
1471 : 23650419 : rtx_note *note = emit_note_before (NOTE_INSN_BLOCK_END, insn);
1472 : 23650419 : NOTE_BLOCK (note) = s;
1473 : 23650419 : s = BLOCK_SUPERCONTEXT (s);
1474 : : }
1475 : :
1476 : : /* Open scopes. */
1477 : : s = s2;
1478 : 41320241 : while (s != com)
1479 : : {
1480 : 23650419 : insn = emit_note_before (NOTE_INSN_BLOCK_BEG, insn);
1481 : 23650419 : NOTE_BLOCK (insn) = s;
1482 : 23650419 : s = BLOCK_SUPERCONTEXT (s);
1483 : : }
1484 : 17669822 : }
1485 : :
1486 : : /* Rebuild all the NOTE_INSN_BLOCK_BEG and NOTE_INSN_BLOCK_END notes based
1487 : : on the scope tree and the newly reordered instructions. */
1488 : :
1489 : : static void
1490 : 570418 : reemit_insn_block_notes (void)
1491 : : {
1492 : 570418 : tree cur_block = DECL_INITIAL (cfun->decl);
1493 : 570418 : rtx_insn *insn;
1494 : :
1495 : 570418 : insn = get_insns ();
1496 : 143975083 : for (; insn; insn = NEXT_INSN (insn))
1497 : : {
1498 : 143404665 : tree this_block;
1499 : :
1500 : : /* Prevent lexical blocks from straddling section boundaries. */
1501 : 143404665 : if (NOTE_P (insn))
1502 : 90346365 : switch (NOTE_KIND (insn))
1503 : : {
1504 : : case NOTE_INSN_SWITCH_TEXT_SECTIONS:
1505 : : {
1506 : 78230 : for (tree s = cur_block; s != DECL_INITIAL (cfun->decl);
1507 : 57968 : s = BLOCK_SUPERCONTEXT (s))
1508 : : {
1509 : 57968 : rtx_note *note = emit_note_before (NOTE_INSN_BLOCK_END, insn);
1510 : 57968 : NOTE_BLOCK (note) = s;
1511 : 57968 : note = emit_note_after (NOTE_INSN_BLOCK_BEG, insn);
1512 : 57968 : NOTE_BLOCK (note) = s;
1513 : : }
1514 : : }
1515 : : break;
1516 : :
1517 : 11316543 : case NOTE_INSN_BEGIN_STMT:
1518 : 11316543 : case NOTE_INSN_INLINE_ENTRY:
1519 : 11316543 : this_block = LOCATION_BLOCK (NOTE_MARKER_LOCATION (insn));
1520 : 11307117 : if (!this_block)
1521 : 13199 : continue;
1522 : 11303344 : goto set_cur_block_to_this_block;
1523 : :
1524 : 79009560 : default:
1525 : 79009560 : continue;
1526 : 79009560 : }
1527 : :
1528 : 53078562 : if (!active_insn_p (insn))
1529 : 7242595 : continue;
1530 : :
1531 : : /* Avoid putting scope notes between jump table and its label. */
1532 : 45835967 : if (JUMP_TABLE_DATA_P (insn))
1533 : 8959 : continue;
1534 : :
1535 : 45827008 : this_block = insn_scope (insn);
1536 : : /* For sequences compute scope resulting from merging all scopes
1537 : : of instructions nested inside. */
1538 : 45827008 : if (rtx_sequence *body = dyn_cast <rtx_sequence *> (PATTERN (insn)))
1539 : : {
1540 : : int i;
1541 : :
1542 : : this_block = NULL;
1543 : 0 : for (i = 0; i < body->len (); i++)
1544 : 0 : this_block = choose_inner_scope (this_block,
1545 : 0 : insn_scope (body->insn (i)));
1546 : : }
1547 : 45827008 : if (! this_block)
1548 : : {
1549 : 10057738 : if (INSN_LOCATION (insn) == UNKNOWN_LOCATION)
1550 : 4726302 : continue;
1551 : : else
1552 : 5331436 : this_block = DECL_INITIAL (cfun->decl);
1553 : : }
1554 : :
1555 : 35769270 : set_cur_block_to_this_block:
1556 : 52404050 : if (this_block != cur_block)
1557 : : {
1558 : 17099404 : change_scope (insn, cur_block, this_block);
1559 : 17099404 : cur_block = this_block;
1560 : : }
1561 : : }
1562 : :
1563 : : /* change_scope emits before the insn, not after. */
1564 : 570418 : rtx_note *note = emit_note (NOTE_INSN_DELETED);
1565 : 570418 : change_scope (note, cur_block, DECL_INITIAL (cfun->decl));
1566 : 570418 : delete_insn (note);
1567 : :
1568 : 570418 : reorder_blocks ();
1569 : 570418 : }
1570 : :
1571 : : static const char *some_local_dynamic_name;
1572 : :
1573 : : /* Locate some local-dynamic symbol still in use by this function
1574 : : so that we can print its name in local-dynamic base patterns.
1575 : : Return null if there are no local-dynamic references. */
1576 : :
1577 : : const char *
1578 : 271 : get_some_local_dynamic_name ()
1579 : : {
1580 : 271 : subrtx_iterator::array_type array;
1581 : 271 : rtx_insn *insn;
1582 : :
1583 : 271 : if (some_local_dynamic_name)
1584 : : return some_local_dynamic_name;
1585 : :
1586 : 9458 : for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
1587 : 9457 : if (NONDEBUG_INSN_P (insn))
1588 : 18473 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL)
1589 : : {
1590 : 16125 : const_rtx x = *iter;
1591 : 16125 : if (GET_CODE (x) == SYMBOL_REF)
1592 : : {
1593 : 603 : if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
1594 : 229 : return some_local_dynamic_name = XSTR (x, 0);
1595 : 374 : if (CONSTANT_POOL_ADDRESS_P (x))
1596 : 0 : iter.substitute (get_pool_constant (x));
1597 : : }
1598 : : }
1599 : :
1600 : : return 0;
1601 : 271 : }
1602 : :
1603 : : /* Arrange for us to emit a source location note before any further
1604 : : real insns or section changes, by setting the SEEN_NEXT_VIEW bit in
1605 : : *SEEN, as long as we are keeping track of location views. The bit
1606 : : indicates we have referenced the next view at the current PC, so we
1607 : : have to emit it. This should be called next to the var_location
1608 : : debug hook. */
1609 : :
1610 : : static inline void
1611 : 56518250 : set_next_view_needed (int *seen)
1612 : : {
1613 : 56518250 : if (debug_variable_location_views)
1614 : 56518250 : *seen |= SEEN_NEXT_VIEW;
1615 : : }
1616 : :
1617 : : /* Clear the flag in *SEEN indicating we need to emit the next view.
1618 : : This should be called next to the source_line debug hook. */
1619 : :
1620 : : static inline void
1621 : 47111984 : clear_next_view_needed (int *seen)
1622 : : {
1623 : 47111984 : *seen &= ~SEEN_NEXT_VIEW;
1624 : 38275576 : }
1625 : :
1626 : : /* Test whether we have a pending request to emit the next view in
1627 : : *SEEN, and emit it if needed, clearing the request bit. */
1628 : :
1629 : : static inline void
1630 : 89911868 : maybe_output_next_view (int *seen)
1631 : : {
1632 : 89911868 : if ((*seen & SEEN_NEXT_VIEW) != 0)
1633 : : {
1634 : 8836408 : clear_next_view_needed (seen);
1635 : 8836408 : (*debug_hooks->source_line) (last_linenum, last_columnnum,
1636 : : last_filename, last_discriminator,
1637 : : false);
1638 : : }
1639 : 89911868 : }
1640 : :
1641 : : /* We want to emit param bindings (before the first begin_stmt) in the
1642 : : initial view, if we are emitting views. To that end, we may
1643 : : consume initial notes in the function, processing them in
1644 : : final_start_function, before signaling the beginning of the
1645 : : prologue, rather than in final.
1646 : :
1647 : : We don't test whether the DECLs are PARM_DECLs: the assumption is
1648 : : that there will be a NOTE_INSN_BEGIN_STMT marker before any
1649 : : non-parameter NOTE_INSN_VAR_LOCATION. It's ok if the marker is not
1650 : : there, we'll just have more variable locations bound in the initial
1651 : : view, which is consistent with their being bound without any code
1652 : : that would give them a value. */
1653 : :
1654 : : static inline bool
1655 : 2894362 : in_initial_view_p (rtx_insn *insn)
1656 : : {
1657 : 2894362 : return (!DECL_IGNORED_P (current_function_decl)
1658 : 2866604 : && debug_variable_location_views
1659 : 1926189 : && insn && GET_CODE (insn) == NOTE
1660 : 4658941 : && (NOTE_KIND (insn) == NOTE_INSN_VAR_LOCATION
1661 : 815938 : || NOTE_KIND (insn) == NOTE_INSN_DELETED));
1662 : : }
1663 : :
1664 : : /* Output assembler code for the start of a function,
1665 : : and initialize some of the variables in this file
1666 : : for the new function. The label for the function and associated
1667 : : assembler pseudo-ops have already been output in `assemble_start_function'.
1668 : :
1669 : : FIRST is the first insn of the rtl for the function being compiled.
1670 : : FILE is the file to write assembler code to.
1671 : : SEEN should be initially set to zero, and it may be updated to
1672 : : indicate we have references to the next location view, that would
1673 : : require us to emit it at the current PC.
1674 : : OPTIMIZE_P is nonzero if we should eliminate redundant
1675 : : test and compare insns. */
1676 : :
1677 : : static void
1678 : 1455204 : final_start_function_1 (rtx_insn **firstp, FILE *file, int *seen,
1679 : : int optimize_p ATTRIBUTE_UNUSED)
1680 : : {
1681 : 1455204 : block_depth = 0;
1682 : :
1683 : 1455204 : this_is_asm_operands = 0;
1684 : :
1685 : 1455204 : need_profile_function = false;
1686 : :
1687 : 1455204 : last_filename = LOCATION_FILE (prologue_location);
1688 : 1455204 : last_linenum = LOCATION_LINE (prologue_location);
1689 : 1455204 : last_columnnum = LOCATION_COLUMN (prologue_location);
1690 : 1455204 : last_discriminator = 0;
1691 : 1455204 : force_source_line = false;
1692 : :
1693 : 1455204 : high_block_linenum = high_function_linenum = last_linenum;
1694 : :
1695 : 1455204 : rtx_insn *first = *firstp;
1696 : 1455204 : if (in_initial_view_p (first))
1697 : : {
1698 : 1437403 : do
1699 : : {
1700 : 1437403 : final_scan_insn (first, file, 0, 0, seen);
1701 : 1437403 : first = NEXT_INSN (first);
1702 : : }
1703 : 1437403 : while (in_initial_view_p (first));
1704 : 488762 : *firstp = first;
1705 : : }
1706 : :
1707 : 1455204 : if (!DECL_IGNORED_P (current_function_decl))
1708 : 1427446 : debug_hooks->begin_prologue (last_linenum, last_columnnum,
1709 : : last_filename);
1710 : :
1711 : 1455204 : if (!dwarf2_debug_info_emitted_p (current_function_decl))
1712 : 897446 : dwarf2out_begin_prologue (0, 0, NULL);
1713 : :
1714 : 1455204 : if (DECL_IGNORED_P (current_function_decl) && last_linenum && last_filename)
1715 : 21675 : debug_hooks->set_ignored_loc (last_linenum, last_columnnum, last_filename);
1716 : :
1717 : : #ifdef LEAF_REG_REMAP
1718 : : if (crtl->uses_only_leaf_regs)
1719 : : leaf_renumber_regs (first);
1720 : : #endif
1721 : :
1722 : : /* The Sun386i and perhaps other machines don't work right
1723 : : if the profiling code comes after the prologue. */
1724 : 1455204 : if (targetm.profile_before_prologue () && crtl->profile)
1725 : : {
1726 : 24 : if (targetm.asm_out.function_prologue == default_function_pro_epilogue
1727 : 24 : && targetm.have_prologue ())
1728 : : {
1729 : : rtx_insn *insn;
1730 : 48 : for (insn = first; insn; insn = NEXT_INSN (insn))
1731 : 48 : if (!NOTE_P (insn))
1732 : : {
1733 : : insn = NULL;
1734 : : break;
1735 : : }
1736 : 48 : else if (NOTE_KIND (insn) == NOTE_INSN_BASIC_BLOCK
1737 : 24 : || NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG)
1738 : : break;
1739 : 24 : else if (NOTE_KIND (insn) == NOTE_INSN_DELETED
1740 : 0 : || NOTE_KIND (insn) == NOTE_INSN_VAR_LOCATION)
1741 : 24 : continue;
1742 : : else
1743 : : {
1744 : : insn = NULL;
1745 : : break;
1746 : : }
1747 : :
1748 : 24 : if (insn)
1749 : 24 : need_profile_function = true;
1750 : : else
1751 : 0 : profile_function (file);
1752 : : }
1753 : : else
1754 : 0 : profile_function (file);
1755 : : }
1756 : :
1757 : : /* If debugging, assign block numbers to all of the blocks in this
1758 : : function. */
1759 : 1455204 : if (write_symbols)
1760 : : {
1761 : 570418 : reemit_insn_block_notes ();
1762 : 570418 : number_blocks (current_function_decl);
1763 : : /* We never actually put out begin/end notes for the top-level
1764 : : block in the function. But, conceptually, that block is
1765 : : always needed. */
1766 : 570418 : TREE_ASM_WRITTEN (DECL_INITIAL (current_function_decl)) = 1;
1767 : : }
1768 : :
1769 : 1455204 : unsigned HOST_WIDE_INT min_frame_size
1770 : 1455204 : = constant_lower_bound (get_frame_size ());
1771 : 1455204 : if (min_frame_size > (unsigned HOST_WIDE_INT) warn_frame_larger_than_size)
1772 : : {
1773 : : /* Issue a warning */
1774 : 6 : warning (OPT_Wframe_larger_than_,
1775 : : "the frame size of %wu bytes is larger than %wu bytes",
1776 : : min_frame_size, warn_frame_larger_than_size);
1777 : : }
1778 : :
1779 : : /* First output the function prologue: code to set up the stack frame. */
1780 : 1455204 : targetm.asm_out.function_prologue (file);
1781 : :
1782 : : /* If the machine represents the prologue as RTL, the profiling code must
1783 : : be emitted when NOTE_INSN_PROLOGUE_END is scanned. */
1784 : 1455204 : if (! targetm.have_prologue ())
1785 : 0 : profile_after_prologue (file);
1786 : 1455204 : }
1787 : :
1788 : : /* This is an exported final_start_function_1, callable without SEEN. */
1789 : :
1790 : : void
1791 : 5347 : final_start_function (rtx_insn *first, FILE *file,
1792 : : int optimize_p ATTRIBUTE_UNUSED)
1793 : : {
1794 : 5347 : int seen = 0;
1795 : 5347 : final_start_function_1 (&first, file, &seen, optimize_p);
1796 : 5347 : gcc_assert (seen == 0);
1797 : 5347 : }
1798 : :
1799 : : static void
1800 : 1451612 : profile_after_prologue (FILE *file ATTRIBUTE_UNUSED)
1801 : : {
1802 : 1451612 : if (!targetm.profile_before_prologue () && crtl->profile)
1803 : 349 : profile_function (file);
1804 : 1451612 : }
1805 : :
1806 : : static void
1807 : 373 : profile_function (FILE *file ATTRIBUTE_UNUSED)
1808 : : {
1809 : : #ifndef NO_PROFILE_COUNTERS
1810 : : # define NO_PROFILE_COUNTERS 0
1811 : : #endif
1812 : : #ifdef ASM_OUTPUT_REG_PUSH
1813 : 373 : rtx sval = NULL, chain = NULL;
1814 : :
1815 : 373 : if (cfun->returns_struct)
1816 : 0 : sval = targetm.calls.struct_value_rtx (TREE_TYPE (current_function_decl),
1817 : : true);
1818 : 373 : if (cfun->static_chain_decl)
1819 : 1 : chain = targetm.calls.static_chain (current_function_decl, true);
1820 : : #endif /* ASM_OUTPUT_REG_PUSH */
1821 : :
1822 : 373 : if (! NO_PROFILE_COUNTERS)
1823 : : {
1824 : : int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
1825 : : switch_to_section (data_section);
1826 : : ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
1827 : : targetm.asm_out.internal_label (file, "LP", current_function_funcdef_no);
1828 : : assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, align, 1);
1829 : : }
1830 : :
1831 : 373 : switch_to_section (current_function_section ());
1832 : :
1833 : : #ifdef ASM_OUTPUT_REG_PUSH
1834 : 373 : if (sval && REG_P (sval))
1835 : 0 : ASM_OUTPUT_REG_PUSH (file, REGNO (sval));
1836 : 373 : if (chain && REG_P (chain))
1837 : 1 : ASM_OUTPUT_REG_PUSH (file, REGNO (chain));
1838 : : #endif
1839 : :
1840 : 373 : FUNCTION_PROFILER (file, current_function_funcdef_no);
1841 : :
1842 : : #ifdef ASM_OUTPUT_REG_PUSH
1843 : 373 : if (chain && REG_P (chain))
1844 : 1 : ASM_OUTPUT_REG_POP (file, REGNO (chain));
1845 : 373 : if (sval && REG_P (sval))
1846 : 0 : ASM_OUTPUT_REG_POP (file, REGNO (sval));
1847 : : #endif
1848 : 373 : }
1849 : :
1850 : : /* Output assembler code for the end of a function.
1851 : : For clarity, args are same as those of `final_start_function'
1852 : : even though not all of them are needed. */
1853 : :
1854 : : void
1855 : 1455204 : final_end_function (void)
1856 : : {
1857 : 1455204 : app_disable ();
1858 : :
1859 : 1455204 : if (!DECL_IGNORED_P (current_function_decl))
1860 : 1427446 : debug_hooks->end_function (high_function_linenum);
1861 : :
1862 : : /* Finally, output the function epilogue:
1863 : : code to restore the stack frame and return to the caller. */
1864 : 1455204 : targetm.asm_out.function_epilogue (asm_out_file);
1865 : :
1866 : : /* And debug output. */
1867 : 1455204 : if (!DECL_IGNORED_P (current_function_decl))
1868 : 1427446 : debug_hooks->end_epilogue (last_linenum, last_filename);
1869 : :
1870 : 1455204 : if (!dwarf2_debug_info_emitted_p (current_function_decl)
1871 : 1455204 : && dwarf2out_do_frame ())
1872 : 897391 : dwarf2out_end_epilogue (last_linenum, last_filename);
1873 : :
1874 : 1455204 : some_local_dynamic_name = 0;
1875 : 1455204 : }
1876 : :
1877 : :
1878 : : /* Dumper helper for basic block information. FILE is the assembly
1879 : : output file, and INSN is the instruction being emitted. */
1880 : :
1881 : : static void
1882 : 258136964 : dump_basic_block_info (FILE *file, rtx_insn *insn, basic_block *start_to_bb,
1883 : : basic_block *end_to_bb, int bb_map_size, int *bb_seqn)
1884 : : {
1885 : 258136964 : basic_block bb;
1886 : :
1887 : 258136964 : if (!flag_debug_asm)
1888 : : return;
1889 : :
1890 : 33979 : if (INSN_UID (insn) < bb_map_size
1891 : 33979 : && (bb = start_to_bb[INSN_UID (insn)]) != NULL)
1892 : : {
1893 : 2076 : edge e;
1894 : 2076 : edge_iterator ei;
1895 : :
1896 : 2076 : fprintf (file, "%s BLOCK %d", ASM_COMMENT_START, bb->index);
1897 : 2076 : if (bb->count.initialized_p ())
1898 : : {
1899 : 157 : fprintf (file, ", count:");
1900 : 157 : bb->count.dump (file);
1901 : : }
1902 : 2076 : fprintf (file, " seq:%d", (*bb_seqn)++);
1903 : 2076 : fprintf (file, "\n%s PRED:", ASM_COMMENT_START);
1904 : 4436 : FOR_EACH_EDGE (e, ei, bb->preds)
1905 : : {
1906 : 2360 : dump_edge_info (file, e, TDF_DETAILS, 0);
1907 : : }
1908 : 2076 : fprintf (file, "\n");
1909 : : }
1910 : 33979 : if (INSN_UID (insn) < bb_map_size
1911 : 33979 : && (bb = end_to_bb[INSN_UID (insn)]) != NULL)
1912 : : {
1913 : 2076 : edge e;
1914 : 2076 : edge_iterator ei;
1915 : :
1916 : 2076 : fprintf (asm_out_file, "%s SUCC:", ASM_COMMENT_START);
1917 : 4434 : FOR_EACH_EDGE (e, ei, bb->succs)
1918 : : {
1919 : 2358 : dump_edge_info (asm_out_file, e, TDF_DETAILS, 1);
1920 : : }
1921 : 2076 : fprintf (file, "\n");
1922 : : }
1923 : : }
1924 : :
1925 : : /* Output assembler code for some insns: all or part of a function.
1926 : : For description of args, see `final_start_function', above. */
1927 : :
1928 : : static void
1929 : 1451612 : final_1 (rtx_insn *first, FILE *file, int seen, int optimize_p)
1930 : : {
1931 : 1451612 : rtx_insn *insn, *next;
1932 : :
1933 : : /* Used for -dA dump. */
1934 : 1451612 : basic_block *start_to_bb = NULL;
1935 : 1451612 : basic_block *end_to_bb = NULL;
1936 : 1451612 : int bb_map_size = 0;
1937 : 1451612 : int bb_seqn = 0;
1938 : :
1939 : 1451612 : last_ignored_compare = 0;
1940 : :
1941 : 1451612 : init_recog ();
1942 : :
1943 : 1451612 : CC_STATUS_INIT;
1944 : :
1945 : 1451612 : if (flag_debug_asm)
1946 : : {
1947 : 1197 : basic_block bb;
1948 : :
1949 : 1197 : bb_map_size = get_max_uid () + 1;
1950 : 1197 : start_to_bb = XCNEWVEC (basic_block, bb_map_size);
1951 : 1197 : end_to_bb = XCNEWVEC (basic_block, bb_map_size);
1952 : :
1953 : : /* There is no cfg for a thunk. */
1954 : 1197 : if (!cfun->is_thunk)
1955 : 3267 : FOR_EACH_BB_REVERSE_FN (bb, cfun)
1956 : : {
1957 : 2076 : start_to_bb[INSN_UID (BB_HEAD (bb))] = bb;
1958 : 2076 : end_to_bb[INSN_UID (BB_END (bb))] = bb;
1959 : : }
1960 : : }
1961 : :
1962 : : /* Output the insns. */
1963 : 259588576 : for (insn = first; insn;)
1964 : : {
1965 : 258136964 : if (HAVE_ATTR_length)
1966 : : {
1967 : 258136964 : if ((unsigned) INSN_UID (insn) >= INSN_ADDRESSES_SIZE ())
1968 : : {
1969 : : /* This can be triggered by bugs elsewhere in the compiler if
1970 : : new insns are created after init_insn_lengths is called. */
1971 : 59385134 : gcc_assert (NOTE_P (insn));
1972 : 59385134 : insn_current_address = -1;
1973 : : }
1974 : : else
1975 : 198751830 : insn_current_address = INSN_ADDRESSES (INSN_UID (insn));
1976 : : /* final can be seen as an iteration of shorten_branches that
1977 : : does nothing (since a fixed point has already been reached). */
1978 : 258136964 : insn_last_address = insn_current_address;
1979 : : }
1980 : :
1981 : 258136964 : dump_basic_block_info (file, insn, start_to_bb, end_to_bb,
1982 : : bb_map_size, &bb_seqn);
1983 : 258136964 : insn = final_scan_insn (insn, file, optimize_p, 0, &seen);
1984 : : }
1985 : :
1986 : 1451612 : maybe_output_next_view (&seen);
1987 : :
1988 : 1451612 : if (flag_debug_asm)
1989 : : {
1990 : 1197 : free (start_to_bb);
1991 : 1197 : free (end_to_bb);
1992 : : }
1993 : :
1994 : : /* Remove CFI notes, to avoid compare-debug failures. */
1995 : 259588576 : for (insn = first; insn; insn = next)
1996 : : {
1997 : 258136964 : next = NEXT_INSN (insn);
1998 : 258136964 : if (NOTE_P (insn)
1999 : 153910062 : && (NOTE_KIND (insn) == NOTE_INSN_CFI
2000 : 153910062 : || NOTE_KIND (insn) == NOTE_INSN_CFI_LABEL))
2001 : 11968356 : delete_insn (insn);
2002 : : }
2003 : 1451612 : }
2004 : :
2005 : : /* This is an exported final_1, callable without SEEN. */
2006 : :
2007 : : void
2008 : 1755 : final (rtx_insn *first, FILE *file, int optimize_p)
2009 : : {
2010 : : /* Those that use the internal final_start_function_1/final_1 API
2011 : : skip initial debug bind notes in final_start_function_1, and pass
2012 : : the modified FIRST to final_1. But those that use the public
2013 : : final_start_function/final APIs, final_start_function can't move
2014 : : FIRST because it's not passed by reference, so if they were
2015 : : skipped there, skip them again here. */
2016 : 1755 : while (in_initial_view_p (first))
2017 : 0 : first = NEXT_INSN (first);
2018 : :
2019 : 1755 : final_1 (first, file, 0, optimize_p);
2020 : 1755 : }
2021 : :
2022 : : const char *
2023 : 91542550 : get_insn_template (int code, rtx_insn *insn)
2024 : : {
2025 : 91542550 : switch (insn_data[code].output_format)
2026 : : {
2027 : 17715844 : case INSN_OUTPUT_FORMAT_SINGLE:
2028 : 17715844 : return insn_data[code].output.single;
2029 : 9922504 : case INSN_OUTPUT_FORMAT_MULTI:
2030 : 9922504 : return insn_data[code].output.multi[which_alternative];
2031 : 63904202 : case INSN_OUTPUT_FORMAT_FUNCTION:
2032 : 63904202 : gcc_assert (insn);
2033 : 63904202 : return (*insn_data[code].output.function) (recog_data.operand, insn);
2034 : :
2035 : 0 : default:
2036 : 0 : gcc_unreachable ();
2037 : : }
2038 : : }
2039 : :
2040 : : /* Emit the appropriate declaration for an alternate-entry-point
2041 : : symbol represented by INSN, to FILE. INSN is a CODE_LABEL with
2042 : : LABEL_KIND != LABEL_NORMAL.
2043 : :
2044 : : The case fall-through in this function is intentional. */
2045 : : static void
2046 : 0 : output_alternate_entry_point (FILE *file, rtx_insn *insn)
2047 : : {
2048 : 0 : const char *name = LABEL_NAME (insn);
2049 : :
2050 : 0 : switch (LABEL_KIND (insn))
2051 : : {
2052 : 0 : case LABEL_WEAK_ENTRY:
2053 : : #ifdef ASM_WEAKEN_LABEL
2054 : 0 : ASM_WEAKEN_LABEL (file, name);
2055 : 0 : gcc_fallthrough ();
2056 : : #endif
2057 : 0 : case LABEL_GLOBAL_ENTRY:
2058 : 0 : targetm.asm_out.globalize_label (file, name);
2059 : 0 : gcc_fallthrough ();
2060 : 0 : case LABEL_STATIC_ENTRY:
2061 : : #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
2062 : 0 : ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
2063 : : #endif
2064 : 0 : ASM_OUTPUT_LABEL (file, name);
2065 : 0 : break;
2066 : :
2067 : 0 : case LABEL_NORMAL:
2068 : 0 : default:
2069 : 0 : gcc_unreachable ();
2070 : : }
2071 : 0 : }
2072 : :
2073 : : /* Given a CALL_INSN, find and return the nested CALL. */
2074 : : static rtx
2075 : 37886401 : call_from_call_insn (const rtx_call_insn *insn)
2076 : : {
2077 : 37886401 : rtx x;
2078 : 37886401 : gcc_assert (CALL_P (insn));
2079 : 37886401 : x = PATTERN (insn);
2080 : :
2081 : 54334242 : while (GET_CODE (x) != CALL)
2082 : : {
2083 : 16447841 : switch (GET_CODE (x))
2084 : : {
2085 : 0 : default:
2086 : 0 : gcc_unreachable ();
2087 : 0 : case COND_EXEC:
2088 : 0 : x = COND_EXEC_CODE (x);
2089 : 0 : break;
2090 : 1680831 : case PARALLEL:
2091 : 1680831 : x = XVECEXP (x, 0, 0);
2092 : 1680831 : break;
2093 : 14767010 : case SET:
2094 : 14767010 : x = XEXP (x, 1);
2095 : 14767010 : break;
2096 : : }
2097 : : }
2098 : 37886401 : return x;
2099 : : }
2100 : :
2101 : : /* Return the CALL in X if there is one. */
2102 : :
2103 : : rtx
2104 : 31823314 : get_call_rtx_from (const rtx_insn *insn)
2105 : : {
2106 : 31823314 : const rtx_call_insn *call_insn = as_a<const rtx_call_insn *> (insn);
2107 : 31823314 : return call_from_call_insn (call_insn);
2108 : : }
2109 : :
2110 : : /* Print a comment into the asm showing FILENAME, LINENUM, and the
2111 : : corresponding source line, if available. */
2112 : :
2113 : : static void
2114 : 32 : asm_show_source (const char *filename, int linenum)
2115 : : {
2116 : 32 : if (!filename)
2117 : 0 : return;
2118 : :
2119 : 32 : char_span line
2120 : 32 : = global_dc->get_file_cache ().get_source_line (filename, linenum);
2121 : 32 : if (!line)
2122 : : return;
2123 : :
2124 : 32 : fprintf (asm_out_file, "%s %s:%i: ", ASM_COMMENT_START, filename, linenum);
2125 : : /* "line" is not 0-terminated, so we must use its length. */
2126 : 32 : fwrite (line.get_buffer (), 1, line.length (), asm_out_file);
2127 : 32 : fputc ('\n', asm_out_file);
2128 : : }
2129 : :
2130 : : /* Judge if an absolute jump table is relocatable. */
2131 : :
2132 : : bool
2133 : 19666 : jumptable_relocatable (void)
2134 : : {
2135 : 19666 : bool relocatable = false;
2136 : :
2137 : 19666 : if (!CASE_VECTOR_PC_RELATIVE
2138 : 19666 : && !targetm.asm_out.generate_pic_addr_diff_vec ()
2139 : 19666 : && targetm_common.have_named_sections)
2140 : 17730 : relocatable = targetm.asm_out.reloc_rw_mask ();
2141 : :
2142 : 19666 : return relocatable;
2143 : : }
2144 : :
2145 : : /* The final scan for one insn, INSN.
2146 : : Args are same as in `final', except that INSN
2147 : : is the insn being scanned.
2148 : : Value returned is the next insn to be scanned.
2149 : :
2150 : : NOPEEPHOLES is the flag to disallow peephole processing (currently
2151 : : used for within delayed branch sequence output).
2152 : :
2153 : : SEEN is used to track the end of the prologue, for emitting
2154 : : debug information. We force the emission of a line note after
2155 : : both NOTE_INSN_PROLOGUE_END and NOTE_INSN_FUNCTION_BEG. */
2156 : :
2157 : : static rtx_insn *
2158 : 259574367 : final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
2159 : : int nopeepholes ATTRIBUTE_UNUSED, int *seen)
2160 : : {
2161 : 259574367 : rtx_insn *next;
2162 : 259574367 : rtx_jump_table_data *table;
2163 : :
2164 : 259574367 : insn_counter++;
2165 : :
2166 : : /* Ignore deleted insns. These can occur when we split insns (due to a
2167 : : template of "#") while not optimizing. */
2168 : 259574367 : if (insn->deleted ())
2169 : 0 : return NEXT_INSN (insn);
2170 : :
2171 : 259574367 : switch (GET_CODE (insn))
2172 : : {
2173 : 155347465 : case NOTE:
2174 : 155347465 : switch (NOTE_KIND (insn))
2175 : : {
2176 : : case NOTE_INSN_DELETED:
2177 : : case NOTE_INSN_UPDATE_SJLJ_CONTEXT:
2178 : : break;
2179 : :
2180 : 61951 : case NOTE_INSN_SWITCH_TEXT_SECTIONS:
2181 : 61951 : maybe_output_next_view (seen);
2182 : :
2183 : 61951 : output_function_exception_table (0);
2184 : :
2185 : 61951 : if (targetm.asm_out.unwind_emit)
2186 : 0 : targetm.asm_out.unwind_emit (asm_out_file, insn);
2187 : :
2188 : 61951 : in_cold_section_p = !in_cold_section_p;
2189 : :
2190 : 61951 : gcc_checking_assert (in_cold_section_p);
2191 : 61951 : if (in_cold_section_p)
2192 : 61951 : cold_function_name
2193 : 61951 : = clone_function_name (current_function_decl, "cold");
2194 : :
2195 : 61951 : if (dwarf2out_do_frame ())
2196 : : {
2197 : 61949 : dwarf2out_switch_text_section ();
2198 : 61949 : if (!dwarf2_debug_info_emitted_p (current_function_decl)
2199 : 61949 : && !DECL_IGNORED_P (current_function_decl))
2200 : 41591 : debug_hooks->switch_text_section ();
2201 : : }
2202 : 2 : else if (!DECL_IGNORED_P (current_function_decl))
2203 : 1 : debug_hooks->switch_text_section ();
2204 : 62093 : if (DECL_IGNORED_P (current_function_decl) && last_linenum
2205 : 62093 : && last_filename)
2206 : 142 : debug_hooks->set_ignored_loc (last_linenum, last_columnnum,
2207 : : last_filename);
2208 : :
2209 : 61951 : switch_to_section (current_function_section ());
2210 : 61951 : targetm.asm_out.function_switched_text_sections (asm_out_file,
2211 : : current_function_decl,
2212 : : in_cold_section_p);
2213 : : /* Emit a label for the split cold section. Form label name by
2214 : : suffixing "cold" to the original function's name. */
2215 : 61951 : if (in_cold_section_p)
2216 : : {
2217 : : #ifdef ASM_DECLARE_COLD_FUNCTION_NAME
2218 : 61951 : ASM_DECLARE_COLD_FUNCTION_NAME (asm_out_file,
2219 : : IDENTIFIER_POINTER
2220 : : (cold_function_name),
2221 : : current_function_decl);
2222 : : #else
2223 : : ASM_OUTPUT_LABEL (asm_out_file,
2224 : : IDENTIFIER_POINTER (cold_function_name));
2225 : : #endif
2226 : 61951 : if (dwarf2out_do_frame ()
2227 : 61951 : && cfun->fde->dw_fde_second_begin != NULL)
2228 : 61949 : ASM_OUTPUT_LABEL (asm_out_file, cfun->fde->dw_fde_second_begin);
2229 : : }
2230 : : break;
2231 : :
2232 : 14089122 : case NOTE_INSN_BASIC_BLOCK:
2233 : 14089122 : if (need_profile_function)
2234 : : {
2235 : 24 : profile_function (asm_out_file);
2236 : 24 : need_profile_function = false;
2237 : : }
2238 : :
2239 : 14089122 : if (targetm.asm_out.unwind_emit)
2240 : 0 : targetm.asm_out.unwind_emit (asm_out_file, insn);
2241 : :
2242 : : break;
2243 : :
2244 : 426543 : case NOTE_INSN_EH_REGION_BEG:
2245 : 426543 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHB",
2246 : : NOTE_EH_HANDLER (insn));
2247 : 426543 : break;
2248 : :
2249 : 426543 : case NOTE_INSN_EH_REGION_END:
2250 : 426543 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LEHE",
2251 : : NOTE_EH_HANDLER (insn));
2252 : 426543 : break;
2253 : :
2254 : 1451612 : case NOTE_INSN_PROLOGUE_END:
2255 : 1451612 : targetm.asm_out.function_end_prologue (file);
2256 : 1451612 : profile_after_prologue (file);
2257 : :
2258 : 1451612 : if ((*seen & (SEEN_EMITTED | SEEN_NOTE)) == SEEN_NOTE)
2259 : : {
2260 : 624654 : *seen |= SEEN_EMITTED;
2261 : 624654 : force_source_line = true;
2262 : : }
2263 : : else
2264 : 826958 : *seen |= SEEN_NOTE;
2265 : :
2266 : : break;
2267 : :
2268 : 1562649 : case NOTE_INSN_EPILOGUE_BEG:
2269 : 1562649 : if (!DECL_IGNORED_P (current_function_decl))
2270 : 1540983 : (*debug_hooks->begin_epilogue) (last_linenum, last_filename);
2271 : 1562649 : targetm.asm_out.function_begin_epilogue (file);
2272 : 1562649 : break;
2273 : :
2274 : 11962507 : case NOTE_INSN_CFI:
2275 : 11962507 : dwarf2out_emit_cfi (NOTE_CFI (insn));
2276 : 11962507 : break;
2277 : :
2278 : 5849 : case NOTE_INSN_CFI_LABEL:
2279 : 5849 : ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI",
2280 : : NOTE_LABEL_NUMBER (insn));
2281 : 5849 : break;
2282 : :
2283 : 1449857 : case NOTE_INSN_FUNCTION_BEG:
2284 : 1449857 : if (need_profile_function)
2285 : : {
2286 : 0 : profile_function (asm_out_file);
2287 : 0 : need_profile_function = false;
2288 : : }
2289 : :
2290 : 1449857 : app_disable ();
2291 : 1449857 : if (!DECL_IGNORED_P (current_function_decl))
2292 : 1425691 : debug_hooks->end_prologue (last_linenum, last_filename);
2293 : :
2294 : 1449857 : if ((*seen & (SEEN_EMITTED | SEEN_NOTE)) == SEEN_NOTE)
2295 : : {
2296 : 825203 : *seen |= SEEN_EMITTED;
2297 : 825203 : force_source_line = true;
2298 : : }
2299 : : else
2300 : 624654 : *seen |= SEEN_NOTE;
2301 : :
2302 : : break;
2303 : :
2304 : 23708387 : case NOTE_INSN_BLOCK_BEG:
2305 : 23708387 : if (debug_info_level >= DINFO_LEVEL_NORMAL
2306 : 31425 : || dwarf_debuginfo_p ()
2307 : 23708387 : || write_symbols == VMS_DEBUG)
2308 : : {
2309 : 23708387 : int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2310 : :
2311 : 23708387 : app_disable ();
2312 : 23708387 : ++block_depth;
2313 : 23708387 : high_block_linenum = last_linenum;
2314 : :
2315 : : /* Output debugging info about the symbol-block beginning. */
2316 : 23708387 : if (!DECL_IGNORED_P (current_function_decl))
2317 : 23708387 : debug_hooks->begin_block (last_linenum, n, NOTE_BLOCK (insn));
2318 : :
2319 : : /* Mark this block as output. */
2320 : 23708387 : TREE_ASM_WRITTEN (NOTE_BLOCK (insn)) = 1;
2321 : 23708387 : BLOCK_IN_COLD_SECTION_P (NOTE_BLOCK (insn)) = in_cold_section_p;
2322 : : }
2323 : : break;
2324 : :
2325 : 23708387 : case NOTE_INSN_BLOCK_END:
2326 : 23708387 : maybe_output_next_view (seen);
2327 : :
2328 : 23708387 : if (debug_info_level >= DINFO_LEVEL_NORMAL
2329 : 31425 : || dwarf_debuginfo_p ()
2330 : 23708387 : || write_symbols == VMS_DEBUG)
2331 : : {
2332 : 23708387 : int n = BLOCK_NUMBER (NOTE_BLOCK (insn));
2333 : :
2334 : 23708387 : app_disable ();
2335 : :
2336 : : /* End of a symbol-block. */
2337 : 23708387 : --block_depth;
2338 : 23708387 : gcc_assert (block_depth >= 0);
2339 : :
2340 : 23708387 : if (!DECL_IGNORED_P (current_function_decl))
2341 : 23708387 : debug_hooks->end_block (high_block_linenum, n);
2342 : 23708387 : gcc_assert (BLOCK_IN_COLD_SECTION_P (NOTE_BLOCK (insn))
2343 : : == in_cold_section_p);
2344 : : }
2345 : : break;
2346 : :
2347 : 44441 : case NOTE_INSN_DELETED_LABEL:
2348 : : /* Emit the label. We may have deleted the CODE_LABEL because
2349 : : the label could be proved to be unreachable, though still
2350 : : referenced (in the form of having its address taken. */
2351 : 44441 : ASM_OUTPUT_DEBUG_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
2352 : 44441 : break;
2353 : :
2354 : 7568 : case NOTE_INSN_DELETED_DEBUG_LABEL:
2355 : : /* Similarly, but need to use different namespace for it. */
2356 : 7568 : if (CODE_LABEL_NUMBER (insn) != -1)
2357 : 7568 : ASM_OUTPUT_DEBUG_LABEL (file, "LDL", CODE_LABEL_NUMBER (insn));
2358 : : break;
2359 : :
2360 : 56556036 : case NOTE_INSN_VAR_LOCATION:
2361 : 56556036 : if (!DECL_IGNORED_P (current_function_decl))
2362 : : {
2363 : 56518250 : debug_hooks->var_location (insn);
2364 : 56518250 : set_next_view_needed (seen);
2365 : : }
2366 : : break;
2367 : :
2368 : 4142462 : case NOTE_INSN_BEGIN_STMT:
2369 : 4142462 : gcc_checking_assert (cfun->debug_nonbind_markers);
2370 : 4142462 : if (!DECL_IGNORED_P (current_function_decl)
2371 : 4142462 : && notice_source_line (insn, NULL))
2372 : : {
2373 : 11316543 : output_source_line:
2374 : 11316543 : (*debug_hooks->source_line) (last_linenum, last_columnnum,
2375 : : last_filename, last_discriminator,
2376 : : true);
2377 : 11316543 : clear_next_view_needed (seen);
2378 : : }
2379 : : break;
2380 : :
2381 : 7174081 : case NOTE_INSN_INLINE_ENTRY:
2382 : 7174081 : gcc_checking_assert (cfun->debug_nonbind_markers);
2383 : 7174081 : if (!DECL_IGNORED_P (current_function_decl)
2384 : 7174081 : && notice_source_line (insn, NULL))
2385 : : {
2386 : 7174081 : (*debug_hooks->inline_entry) (LOCATION_BLOCK
2387 : : (NOTE_MARKER_LOCATION (insn)));
2388 : 7174081 : goto output_source_line;
2389 : : }
2390 : : break;
2391 : :
2392 : 0 : default:
2393 : 0 : gcc_unreachable ();
2394 : : break;
2395 : : }
2396 : : break;
2397 : :
2398 : : case BARRIER:
2399 : : break;
2400 : :
2401 : 6830385 : case CODE_LABEL:
2402 : : /* The target port might emit labels in the output function for
2403 : : some insn, e.g. sh.cc output_branchy_insn. */
2404 : 6830385 : if (CODE_LABEL_NUMBER (insn) <= max_labelno)
2405 : : {
2406 : 6830383 : align_flags alignment = LABEL_TO_ALIGNMENT (insn);
2407 : 8139289 : if (alignment.levels[0].log && NEXT_INSN (insn))
2408 : : {
2409 : : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2410 : : /* Output both primary and secondary alignment. */
2411 : 1308906 : ASM_OUTPUT_MAX_SKIP_ALIGN (file, alignment.levels[0].log,
2412 : : alignment.levels[0].maxskip);
2413 : 1308906 : ASM_OUTPUT_MAX_SKIP_ALIGN (file, alignment.levels[1].log,
2414 : : alignment.levels[1].maxskip);
2415 : : #else
2416 : : #ifdef ASM_OUTPUT_ALIGN_WITH_NOP
2417 : : ASM_OUTPUT_ALIGN_WITH_NOP (file, alignment.levels[0].log);
2418 : : #else
2419 : : ASM_OUTPUT_ALIGN (file, alignment.levels[0].log);
2420 : : #endif
2421 : : #endif
2422 : : }
2423 : : }
2424 : 6830385 : CC_STATUS_INIT;
2425 : :
2426 : 6830385 : if (!DECL_IGNORED_P (current_function_decl) && LABEL_NAME (insn))
2427 : 53793 : debug_hooks->label (as_a <rtx_code_label *> (insn));
2428 : :
2429 : 6830385 : app_disable ();
2430 : :
2431 : : /* If this label is followed by a jump-table, make sure we put
2432 : : the label in the read-only section. Also possibly write the
2433 : : label and jump table together. */
2434 : 6830385 : table = jump_table_for_label (as_a <rtx_code_label *> (insn));
2435 : 6830385 : if (table)
2436 : : {
2437 : : #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2438 : : /* In this case, the case vector is being moved by the
2439 : : target, so don't output the label at all. Leave that
2440 : : to the back end macros. */
2441 : : #else
2442 : 9833 : if (! JUMP_TABLES_IN_TEXT_SECTION)
2443 : : {
2444 : 9833 : int log_align;
2445 : :
2446 : 9833 : switch_to_section (targetm.asm_out.function_rodata_section
2447 : : (current_function_decl,
2448 : 9833 : jumptable_relocatable ()));
2449 : :
2450 : : #ifdef ADDR_VEC_ALIGN
2451 : 9833 : log_align = ADDR_VEC_ALIGN (table);
2452 : : #else
2453 : : log_align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
2454 : : #endif
2455 : 9833 : ASM_OUTPUT_ALIGN (file, log_align);
2456 : : }
2457 : : else
2458 : : switch_to_section (current_function_section ());
2459 : :
2460 : : #ifdef ASM_OUTPUT_CASE_LABEL
2461 : 9833 : ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn), table);
2462 : : #else
2463 : : targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (insn));
2464 : : #endif
2465 : : #endif
2466 : 9833 : break;
2467 : : }
2468 : 6820552 : if (LABEL_ALT_ENTRY_P (insn))
2469 : 0 : output_alternate_entry_point (file, insn);
2470 : : else
2471 : 6820552 : targetm.asm_out.internal_label (file, "L", CODE_LABEL_NUMBER (insn));
2472 : : break;
2473 : :
2474 : 92700189 : default:
2475 : 92700189 : {
2476 : 92700189 : rtx body = PATTERN (insn);
2477 : 92700189 : int insn_code_number;
2478 : 92700189 : const char *templ;
2479 : 92700189 : bool is_stmt, *is_stmt_p;
2480 : :
2481 : 92700189 : if (MAY_HAVE_DEBUG_MARKER_INSNS && cfun->debug_nonbind_markers)
2482 : : {
2483 : 21757281 : is_stmt = false;
2484 : 21757281 : is_stmt_p = NULL;
2485 : : }
2486 : : else
2487 : : is_stmt_p = &is_stmt;
2488 : :
2489 : : /* Reset this early so it is correct for ASM statements. */
2490 : 92700189 : current_insn_predicate = NULL_RTX;
2491 : :
2492 : : /* An INSN, JUMP_INSN or CALL_INSN.
2493 : : First check for special kinds that recog doesn't recognize. */
2494 : :
2495 : 92700189 : if (GET_CODE (body) == USE /* These are just declarations. */
2496 : 92700189 : || GET_CODE (body) == CLOBBER)
2497 : : break;
2498 : :
2499 : : /* Detect insns that are really jump-tables
2500 : : and output them as such. */
2501 : :
2502 : 91658784 : if (JUMP_TABLE_DATA_P (insn))
2503 : : {
2504 : : #if !(defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC))
2505 : 9833 : int vlen, idx;
2506 : : #endif
2507 : :
2508 : 9833 : if (! JUMP_TABLES_IN_TEXT_SECTION)
2509 : 9833 : switch_to_section (targetm.asm_out.function_rodata_section
2510 : : (current_function_decl,
2511 : 9833 : jumptable_relocatable ()));
2512 : : else
2513 : : switch_to_section (current_function_section ());
2514 : :
2515 : 9833 : app_disable ();
2516 : :
2517 : : #if defined(ASM_OUTPUT_ADDR_VEC) || defined(ASM_OUTPUT_ADDR_DIFF_VEC)
2518 : : if (GET_CODE (body) == ADDR_VEC)
2519 : : {
2520 : : #ifdef ASM_OUTPUT_ADDR_VEC
2521 : : ASM_OUTPUT_ADDR_VEC (PREV_INSN (insn), body);
2522 : : #else
2523 : : gcc_unreachable ();
2524 : : #endif
2525 : : }
2526 : : else
2527 : : {
2528 : : #ifdef ASM_OUTPUT_ADDR_DIFF_VEC
2529 : : ASM_OUTPUT_ADDR_DIFF_VEC (PREV_INSN (insn), body);
2530 : : #else
2531 : : gcc_unreachable ();
2532 : : #endif
2533 : : }
2534 : : #else
2535 : 9833 : vlen = XVECLEN (body, GET_CODE (body) == ADDR_DIFF_VEC);
2536 : 234374 : for (idx = 0; idx < vlen; idx++)
2537 : : {
2538 : 224541 : if (GET_CODE (body) == ADDR_VEC)
2539 : : {
2540 : : #ifdef ASM_OUTPUT_ADDR_VEC_ELT
2541 : 201828 : ASM_OUTPUT_ADDR_VEC_ELT
2542 : : (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
2543 : : #else
2544 : : gcc_unreachable ();
2545 : : #endif
2546 : : }
2547 : : else
2548 : : {
2549 : : #ifdef ASM_OUTPUT_ADDR_DIFF_ELT
2550 : 22713 : ASM_OUTPUT_ADDR_DIFF_ELT
2551 : : (file,
2552 : : body,
2553 : : CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
2554 : : CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
2555 : : #else
2556 : : gcc_unreachable ();
2557 : : #endif
2558 : : }
2559 : : }
2560 : : #ifdef ASM_OUTPUT_CASE_END
2561 : : ASM_OUTPUT_CASE_END (file,
2562 : : CODE_LABEL_NUMBER (PREV_INSN (insn)),
2563 : : insn);
2564 : : #endif
2565 : : #endif
2566 : :
2567 : 9833 : switch_to_section (current_function_section ());
2568 : :
2569 : 9833 : if (debug_variable_location_views
2570 : 9833 : && !DECL_IGNORED_P (current_function_decl))
2571 : 8959 : debug_hooks->var_location (insn);
2572 : :
2573 : : break;
2574 : : }
2575 : : /* Output this line note if it is the first or the last line
2576 : : note in a row. */
2577 : 91648951 : if (!DECL_IGNORED_P (current_function_decl)
2578 : 91648951 : && notice_source_line (insn, is_stmt_p))
2579 : : {
2580 : 26959033 : if (flag_verbose_asm)
2581 : 32 : asm_show_source (last_filename, last_linenum);
2582 : 26959033 : (*debug_hooks->source_line) (last_linenum, last_columnnum,
2583 : : last_filename, last_discriminator,
2584 : : is_stmt);
2585 : 26959033 : clear_next_view_needed (seen);
2586 : : }
2587 : : else
2588 : 64689918 : maybe_output_next_view (seen);
2589 : :
2590 : 91648951 : gcc_checking_assert (!DEBUG_INSN_P (insn));
2591 : :
2592 : 91648951 : if (GET_CODE (body) == PARALLEL
2593 : 11612246 : && GET_CODE (XVECEXP (body, 0, 0)) == ASM_INPUT)
2594 : 91648951 : body = XVECEXP (body, 0, 0);
2595 : :
2596 : 91648951 : if (GET_CODE (body) == ASM_INPUT)
2597 : : {
2598 : 3025 : const char *string = XSTR (body, 0);
2599 : :
2600 : : /* There's no telling what that did to the condition codes. */
2601 : 3025 : CC_STATUS_INIT;
2602 : :
2603 : 3025 : if (string[0])
2604 : : {
2605 : 938 : expanded_location loc;
2606 : :
2607 : 938 : app_enable ();
2608 : 938 : loc = expand_location (ASM_INPUT_SOURCE_LOCATION (body));
2609 : 938 : if (*loc.file && loc.line)
2610 : 938 : fprintf (asm_out_file, "%s %i \"%s\" 1\n",
2611 : : ASM_COMMENT_START, loc.line, loc.file);
2612 : 938 : fprintf (asm_out_file, "\t%s\n", string);
2613 : : #if HAVE_AS_LINE_ZERO
2614 : 938 : if (*loc.file && loc.line)
2615 : 938 : fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START);
2616 : : #endif
2617 : : }
2618 : : break;
2619 : : }
2620 : :
2621 : : /* Detect `asm' construct with operands. */
2622 : 91645926 : if (asm_noperands (body) >= 0)
2623 : : {
2624 : 103435 : unsigned int noperands = asm_noperands (body);
2625 : 103435 : rtx *ops = XALLOCAVEC (rtx, noperands);
2626 : 103435 : const char *string;
2627 : 103435 : location_t loc;
2628 : 103435 : expanded_location expanded;
2629 : :
2630 : : /* There's no telling what that did to the condition codes. */
2631 : 103435 : CC_STATUS_INIT;
2632 : :
2633 : : /* Get out the operand values. */
2634 : 103435 : string = decode_asm_operands (body, ops, NULL, NULL, NULL, &loc);
2635 : : /* Inhibit dying on what would otherwise be compiler bugs. */
2636 : 103435 : insn_noperands = noperands;
2637 : 103435 : this_is_asm_operands = insn;
2638 : 103435 : expanded = expand_location (loc);
2639 : :
2640 : : #ifdef FINAL_PRESCAN_INSN
2641 : : FINAL_PRESCAN_INSN (insn, ops, insn_noperands);
2642 : : #endif
2643 : :
2644 : : /* Output the insn using them. */
2645 : 103435 : if (string[0])
2646 : : {
2647 : 34075 : app_enable ();
2648 : 34075 : if (expanded.file && expanded.line)
2649 : 34045 : fprintf (asm_out_file, "%s %i \"%s\" 1\n",
2650 : : ASM_COMMENT_START, expanded.line, expanded.file);
2651 : 34075 : output_asm_insn (string, ops);
2652 : : #if HAVE_AS_LINE_ZERO
2653 : 34075 : if (expanded.file && expanded.line)
2654 : 34045 : fprintf (asm_out_file, "%s 0 \"\" 2\n", ASM_COMMENT_START);
2655 : : #endif
2656 : : }
2657 : :
2658 : 103435 : if (targetm.asm_out.final_postscan_insn)
2659 : 0 : targetm.asm_out.final_postscan_insn (file, insn, ops,
2660 : : insn_noperands);
2661 : :
2662 : 103435 : this_is_asm_operands = 0;
2663 : 103435 : break;
2664 : : }
2665 : :
2666 : 91542491 : app_disable ();
2667 : :
2668 : 91542491 : if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (body))
2669 : : {
2670 : : /* A delayed-branch sequence */
2671 : 0 : int i;
2672 : :
2673 : 0 : final_sequence = seq;
2674 : :
2675 : : /* The first insn in this SEQUENCE might be a JUMP_INSN that will
2676 : : force the restoration of a comparison that was previously
2677 : : thought unnecessary. If that happens, cancel this sequence
2678 : : and cause that insn to be restored. */
2679 : :
2680 : 0 : next = final_scan_insn (seq->insn (0), file, 0, 1, seen);
2681 : 0 : if (next != seq->insn (1))
2682 : : {
2683 : 0 : final_sequence = 0;
2684 : 0 : return next;
2685 : : }
2686 : :
2687 : 0 : for (i = 1; i < seq->len (); i++)
2688 : : {
2689 : 0 : rtx_insn *insn = seq->insn (i);
2690 : 0 : rtx_insn *next = NEXT_INSN (insn);
2691 : : /* We loop in case any instruction in a delay slot gets
2692 : : split. */
2693 : 0 : do
2694 : 0 : insn = final_scan_insn (insn, file, 0, 1, seen);
2695 : 0 : while (insn != next);
2696 : : }
2697 : : #ifdef DBR_OUTPUT_SEQEND
2698 : : DBR_OUTPUT_SEQEND (file);
2699 : : #endif
2700 : 0 : final_sequence = 0;
2701 : :
2702 : : /* If the insn requiring the delay slot was a CALL_INSN, the
2703 : : insns in the delay slot are actually executed before the
2704 : : called function. Hence we don't preserve any CC-setting
2705 : : actions in these insns and the CC must be marked as being
2706 : : clobbered by the function. */
2707 : 0 : if (CALL_P (seq->insn (0)))
2708 : : {
2709 : 0 : CC_STATUS_INIT;
2710 : : }
2711 : 0 : break;
2712 : : }
2713 : :
2714 : : /* We have a real machine instruction as rtl. */
2715 : :
2716 : 91542491 : body = PATTERN (insn);
2717 : :
2718 : : /* Do machine-specific peephole optimizations if desired. */
2719 : :
2720 : 91542491 : if (HAVE_peephole && optimize_p && !flag_no_peephole && !nopeepholes)
2721 : : {
2722 : : rtx_insn *next = peephole (insn);
2723 : : /* When peepholing, if there were notes within the peephole,
2724 : : emit them before the peephole. */
2725 : : if (next != 0 && next != NEXT_INSN (insn))
2726 : : {
2727 : : rtx_insn *note, *prev = PREV_INSN (insn);
2728 : :
2729 : : for (note = NEXT_INSN (insn); note != next;
2730 : : note = NEXT_INSN (note))
2731 : : final_scan_insn (note, file, optimize_p, nopeepholes, seen);
2732 : :
2733 : : /* Put the notes in the proper position for a later
2734 : : rescan. For example, the SH target can do this
2735 : : when generating a far jump in a delayed branch
2736 : : sequence. */
2737 : : note = NEXT_INSN (insn);
2738 : : SET_PREV_INSN (note) = prev;
2739 : : SET_NEXT_INSN (prev) = note;
2740 : : SET_NEXT_INSN (PREV_INSN (next)) = insn;
2741 : : SET_PREV_INSN (insn) = PREV_INSN (next);
2742 : : SET_NEXT_INSN (insn) = next;
2743 : : SET_PREV_INSN (next) = insn;
2744 : : }
2745 : :
2746 : : /* PEEPHOLE might have changed this. */
2747 : : body = PATTERN (insn);
2748 : : }
2749 : :
2750 : : /* Try to recognize the instruction.
2751 : : If successful, verify that the operands satisfy the
2752 : : constraints for the instruction. Crash if they don't,
2753 : : since `reload' should have changed them so that they do. */
2754 : :
2755 : 91542491 : insn_code_number = recog_memoized (insn);
2756 : 91542491 : cleanup_subreg_operands (insn);
2757 : :
2758 : : /* Dump the insn in the assembly for debugging (-dAP).
2759 : : If the final dump is requested as slim RTL, dump slim
2760 : : RTL to the assembly file also. */
2761 : 91542491 : if (flag_dump_rtl_in_asm)
2762 : : {
2763 : 29 : print_rtx_head = ASM_COMMENT_START;
2764 : 29 : if (! (dump_flags & TDF_SLIM))
2765 : 29 : print_rtl_single (asm_out_file, insn);
2766 : : else
2767 : 0 : dump_insn_slim (asm_out_file, insn);
2768 : 29 : print_rtx_head = "";
2769 : : }
2770 : :
2771 : 91542491 : if (! constrain_operands_cached (insn, 1))
2772 : 0 : fatal_insn_not_found (insn);
2773 : :
2774 : : /* Some target machines need to prescan each insn before
2775 : : it is output. */
2776 : :
2777 : : #ifdef FINAL_PRESCAN_INSN
2778 : : FINAL_PRESCAN_INSN (insn, recog_data.operand, recog_data.n_operands);
2779 : : #endif
2780 : :
2781 : 91542491 : if (targetm.have_conditional_execution ()
2782 : 91542491 : && GET_CODE (PATTERN (insn)) == COND_EXEC)
2783 : 0 : current_insn_predicate = COND_EXEC_TEST (PATTERN (insn));
2784 : :
2785 : 91542491 : current_output_insn = debug_insn = insn;
2786 : :
2787 : : /* Find the proper template for this insn. */
2788 : 91542491 : templ = get_insn_template (insn_code_number, insn);
2789 : :
2790 : : /* If the C code returns 0, it means that it is a jump insn
2791 : : which follows a deleted test insn, and that test insn
2792 : : needs to be reinserted. */
2793 : 91542491 : if (templ == 0)
2794 : : {
2795 : 0 : rtx_insn *prev;
2796 : :
2797 : 0 : gcc_assert (prev_nonnote_insn (insn) == last_ignored_compare);
2798 : :
2799 : : /* We have already processed the notes between the setter and
2800 : : the user. Make sure we don't process them again, this is
2801 : : particularly important if one of the notes is a block
2802 : : scope note or an EH note. */
2803 : 0 : for (prev = insn;
2804 : 0 : prev != last_ignored_compare;
2805 : 0 : prev = PREV_INSN (prev))
2806 : : {
2807 : 0 : if (NOTE_P (prev))
2808 : 0 : delete_insn (prev); /* Use delete_note. */
2809 : : }
2810 : :
2811 : : return prev;
2812 : : }
2813 : :
2814 : : /* If the template is the string "#", it means that this insn must
2815 : : be split. */
2816 : 91542491 : if (templ[0] == '#' && templ[1] == '\0')
2817 : : {
2818 : 0 : rtx_insn *new_rtx = try_split (body, insn, 0);
2819 : :
2820 : : /* If we didn't split the insn, go away. */
2821 : 0 : if (new_rtx == insn && PATTERN (new_rtx) == body)
2822 : 0 : fatal_insn ("could not split insn", insn);
2823 : :
2824 : : /* If we have a length attribute, this instruction should have
2825 : : been split in shorten_branches, to ensure that we would have
2826 : : valid length info for the splitees. */
2827 : 0 : gcc_assert (!HAVE_ATTR_length);
2828 : :
2829 : : return new_rtx;
2830 : : }
2831 : :
2832 : : /* ??? This will put the directives in the wrong place if
2833 : : get_insn_template outputs assembly directly. However calling it
2834 : : before get_insn_template breaks if the insns is split. */
2835 : 91542491 : if (targetm.asm_out.unwind_emit_before_insn
2836 : 91542491 : && targetm.asm_out.unwind_emit)
2837 : 0 : targetm.asm_out.unwind_emit (asm_out_file, insn);
2838 : :
2839 : 91542491 : rtx_call_insn *call_insn = dyn_cast <rtx_call_insn *> (insn);
2840 : 6063087 : if (call_insn != NULL)
2841 : : {
2842 : 6063087 : rtx x = call_from_call_insn (call_insn);
2843 : 6063087 : x = XEXP (x, 0);
2844 : 6063087 : if (x && MEM_P (x) && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
2845 : : {
2846 : 5858622 : tree t;
2847 : 5858622 : x = XEXP (x, 0);
2848 : 5858622 : t = SYMBOL_REF_DECL (x);
2849 : 5858622 : if (t)
2850 : 5596196 : assemble_external (t);
2851 : : }
2852 : : }
2853 : :
2854 : : /* Output assembler code from the template. */
2855 : 91542491 : output_asm_insn (templ, recog_data.operand);
2856 : :
2857 : : /* Some target machines need to postscan each insn after
2858 : : it is output. */
2859 : 91542491 : if (targetm.asm_out.final_postscan_insn)
2860 : 0 : targetm.asm_out.final_postscan_insn (file, insn, recog_data.operand,
2861 : 0 : recog_data.n_operands);
2862 : :
2863 : 91542491 : if (!targetm.asm_out.unwind_emit_before_insn
2864 : 0 : && targetm.asm_out.unwind_emit)
2865 : 0 : targetm.asm_out.unwind_emit (asm_out_file, insn);
2866 : :
2867 : : /* Let the debug info back-end know about this call. We do this only
2868 : : after the instruction has been emitted because labels that may be
2869 : : created to reference the call instruction must appear after it. */
2870 : 49599149 : if ((debug_variable_location_views || call_insn != NULL)
2871 : 94421708 : && !DECL_IGNORED_P (current_function_decl))
2872 : 44773585 : debug_hooks->var_location (insn);
2873 : :
2874 : 91542491 : current_output_insn = debug_insn = 0;
2875 : : }
2876 : : }
2877 : 259574367 : return NEXT_INSN (insn);
2878 : : }
2879 : :
2880 : : /* This is a wrapper around final_scan_insn_1 that allows ports to
2881 : : call it recursively without a known value for SEEN. The value is
2882 : : saved at the outermost call, and recovered for recursive calls.
2883 : : Recursive calls MUST pass NULL, or the same pointer if they can
2884 : : otherwise get to it. */
2885 : :
2886 : : rtx_insn *
2887 : 259574367 : final_scan_insn (rtx_insn *insn, FILE *file, int optimize_p,
2888 : : int nopeepholes, int *seen)
2889 : : {
2890 : 259574367 : static int *enclosing_seen;
2891 : 259574367 : static int recursion_counter;
2892 : :
2893 : 259574367 : gcc_assert (seen || recursion_counter);
2894 : 259574367 : gcc_assert (!recursion_counter || !seen || seen == enclosing_seen);
2895 : :
2896 : 259574367 : if (!recursion_counter++)
2897 : 259574367 : enclosing_seen = seen;
2898 : 0 : else if (!seen)
2899 : 0 : seen = enclosing_seen;
2900 : :
2901 : 259574367 : rtx_insn *ret = final_scan_insn_1 (insn, file, optimize_p, nopeepholes, seen);
2902 : :
2903 : 259574367 : if (!--recursion_counter)
2904 : 259574367 : enclosing_seen = NULL;
2905 : :
2906 : 259574367 : return ret;
2907 : : }
2908 : :
2909 : :
2910 : :
2911 : : /* Map DECLs to instance discriminators. This is allocated and
2912 : : defined in ada/gcc-interfaces/trans.cc, when compiling with -gnateS.
2913 : : Mappings from this table are saved and restored for LTO, so
2914 : : link-time compilation will have this map set, at least in
2915 : : partitions containing at least one DECL with an associated instance
2916 : : discriminator. */
2917 : :
2918 : : decl_to_instance_map_t *decl_to_instance_map;
2919 : :
2920 : : /* Return the instance number assigned to DECL. */
2921 : :
2922 : : static inline int
2923 : 0 : map_decl_to_instance (const_tree decl)
2924 : : {
2925 : 0 : int *inst;
2926 : :
2927 : 0 : if (!decl_to_instance_map || !decl || !DECL_P (decl))
2928 : : return 0;
2929 : :
2930 : 0 : inst = decl_to_instance_map->get (decl);
2931 : :
2932 : 0 : if (!inst)
2933 : : return 0;
2934 : :
2935 : 0 : return *inst;
2936 : : }
2937 : :
2938 : : /* Set DISCRIMINATOR to the appropriate value, possibly derived from LOC. */
2939 : :
2940 : : static inline int
2941 : 94159380 : compute_discriminator (location_t loc)
2942 : : {
2943 : 94159380 : int discriminator;
2944 : :
2945 : 94159380 : if (!decl_to_instance_map)
2946 : 94159380 : discriminator = get_discriminator_from_loc (loc);
2947 : : else
2948 : : {
2949 : 0 : tree block = LOCATION_BLOCK (loc);
2950 : :
2951 : 0 : while (block && TREE_CODE (block) == BLOCK
2952 : 0 : && !inlined_function_outer_scope_p (block))
2953 : 0 : block = BLOCK_SUPERCONTEXT (block);
2954 : :
2955 : 0 : tree decl;
2956 : :
2957 : 0 : if (!block)
2958 : 0 : decl = current_function_decl;
2959 : 0 : else if (DECL_P (block))
2960 : : decl = block;
2961 : : else
2962 : 0 : decl = block_ultimate_origin (block);
2963 : :
2964 : 0 : discriminator = map_decl_to_instance (decl);
2965 : : }
2966 : :
2967 : 94159380 : return discriminator;
2968 : : }
2969 : :
2970 : : /* Return discriminator of the statement that produced this insn. */
2971 : : int
2972 : 82842837 : insn_discriminator (const rtx_insn *insn)
2973 : : {
2974 : 82842837 : return compute_discriminator (INSN_LOCATION (insn));
2975 : : }
2976 : :
2977 : : /* Return whether a source line note needs to be emitted before INSN.
2978 : : Sets IS_STMT to TRUE if the line should be marked as a possible
2979 : : breakpoint location. */
2980 : :
2981 : : static bool
2982 : 102861362 : notice_source_line (rtx_insn *insn, bool *is_stmt)
2983 : : {
2984 : 102861362 : const char *filename;
2985 : 102861362 : int linenum, columnnum;
2986 : 102861362 : int discriminator;
2987 : :
2988 : 102861362 : if (NOTE_MARKER_P (insn))
2989 : : {
2990 : 11316543 : location_t loc = NOTE_MARKER_LOCATION (insn);
2991 : 11316543 : expanded_location xloc = expand_location (loc);
2992 : 11316543 : if (xloc.line == 0
2993 : 11316543 : && (LOCATION_LOCUS (loc) == UNKNOWN_LOCATION
2994 : 10 : || LOCATION_LOCUS (loc) == BUILTINS_LOCATION))
2995 : 0 : return false;
2996 : :
2997 : 11316543 : filename = xloc.file;
2998 : 11316543 : linenum = xloc.line;
2999 : 11316543 : columnnum = xloc.column;
3000 : 11316543 : discriminator = compute_discriminator (loc);
3001 : 11316543 : force_source_line = true;
3002 : 11316543 : }
3003 : 91544819 : else if (override_filename)
3004 : : {
3005 : 0 : filename = override_filename;
3006 : 0 : linenum = override_linenum;
3007 : 0 : columnnum = override_columnnum;
3008 : 0 : discriminator = override_discriminator;
3009 : : }
3010 : 91544819 : else if (INSN_HAS_LOCATION (insn))
3011 : : {
3012 : 82697288 : expanded_location xloc = insn_location (insn);
3013 : 82697288 : filename = xloc.file;
3014 : 82697288 : linenum = xloc.line;
3015 : 82697288 : columnnum = xloc.column;
3016 : 82697288 : discriminator = insn_discriminator (insn);
3017 : : }
3018 : : else
3019 : : {
3020 : : filename = NULL;
3021 : : linenum = 0;
3022 : : columnnum = 0;
3023 : : discriminator = 0;
3024 : : }
3025 : :
3026 : 94013831 : if (filename == NULL)
3027 : 8847531 : return false;
3028 : :
3029 : 94013831 : if (force_source_line
3030 : 81524735 : || filename != last_filename
3031 : 78513863 : || last_linenum != linenum
3032 : 66461832 : || (debug_column_info && last_columnnum != columnnum))
3033 : : {
3034 : 31975499 : force_source_line = false;
3035 : 31975499 : last_filename = filename;
3036 : 31975499 : last_linenum = linenum;
3037 : 31975499 : last_columnnum = columnnum;
3038 : 31975499 : last_discriminator = discriminator;
3039 : 31975499 : if (is_stmt)
3040 : 11910311 : *is_stmt = true;
3041 : 31975499 : high_block_linenum = MAX (last_linenum, high_block_linenum);
3042 : 31975499 : high_function_linenum = MAX (last_linenum, high_function_linenum);
3043 : 31975499 : return true;
3044 : : }
3045 : :
3046 : 62038332 : if (SUPPORTS_DISCRIMINATOR && last_discriminator != discriminator)
3047 : : {
3048 : : /* If the discriminator changed, but the line number did not,
3049 : : output the line table entry with is_stmt false so the
3050 : : debugger does not treat this as a breakpoint location. */
3051 : 6300077 : last_discriminator = discriminator;
3052 : 6300077 : if (is_stmt)
3053 : 5907823 : *is_stmt = false;
3054 : 6300077 : return true;
3055 : : }
3056 : :
3057 : : return false;
3058 : : }
3059 : :
3060 : : /* For each operand in INSN, simplify (subreg (reg)) so that it refers
3061 : : directly to the desired hard register. */
3062 : :
3063 : : void
3064 : 99943150 : cleanup_subreg_operands (rtx_insn *insn)
3065 : : {
3066 : 99943150 : int i;
3067 : 99943150 : bool changed = false;
3068 : 99943150 : extract_insn_cached (insn);
3069 : 408846158 : for (i = 0; i < recog_data.n_operands; i++)
3070 : : {
3071 : : /* The following test cannot use recog_data.operand when testing
3072 : : for a SUBREG: the underlying object might have been changed
3073 : : already if we are inside a match_operator expression that
3074 : : matches the else clause. Instead we test the underlying
3075 : : expression directly. */
3076 : 208959858 : if (GET_CODE (*recog_data.operand_loc[i]) == SUBREG)
3077 : : {
3078 : 160 : recog_data.operand[i] = alter_subreg (recog_data.operand_loc[i], true);
3079 : 160 : changed = true;
3080 : : }
3081 : 208959698 : else if (GET_CODE (recog_data.operand[i]) == PLUS
3082 : : || GET_CODE (recog_data.operand[i]) == MULT
3083 : : || MEM_P (recog_data.operand[i]))
3084 : 48802777 : recog_data.operand[i] = walk_alter_subreg (recog_data.operand_loc[i], &changed);
3085 : : }
3086 : :
3087 : 101962225 : for (i = 0; i < recog_data.n_dups; i++)
3088 : : {
3089 : 2019075 : if (GET_CODE (*recog_data.dup_loc[i]) == SUBREG)
3090 : : {
3091 : 0 : *recog_data.dup_loc[i] = alter_subreg (recog_data.dup_loc[i], true);
3092 : 0 : changed = true;
3093 : : }
3094 : 2019075 : else if (GET_CODE (*recog_data.dup_loc[i]) == PLUS
3095 : 2019075 : || GET_CODE (*recog_data.dup_loc[i]) == MULT
3096 : 2019075 : || MEM_P (*recog_data.dup_loc[i]))
3097 : 548700 : *recog_data.dup_loc[i] = walk_alter_subreg (recog_data.dup_loc[i], &changed);
3098 : : }
3099 : 99943150 : if (changed)
3100 : 160 : df_insn_rescan (insn);
3101 : 99943150 : }
3102 : :
3103 : : /* If X is a SUBREG, try to replace it with a REG or a MEM, based on
3104 : : the thing it is a subreg of. Do it anyway if FINAL_P. */
3105 : :
3106 : : rtx
3107 : 3135882 : alter_subreg (rtx *xp, bool final_p)
3108 : : {
3109 : 3135882 : rtx x = *xp;
3110 : 3135882 : rtx y = SUBREG_REG (x);
3111 : :
3112 : : /* simplify_subreg does not remove subreg from volatile references.
3113 : : We are required to. */
3114 : 3135882 : if (MEM_P (y))
3115 : : {
3116 : 214053 : poly_int64 offset = SUBREG_BYTE (x);
3117 : :
3118 : : /* For paradoxical subregs on big-endian machines, SUBREG_BYTE
3119 : : contains 0 instead of the proper offset. See simplify_subreg. */
3120 : 214053 : if (paradoxical_subreg_p (x))
3121 : 35381 : offset = byte_lowpart_offset (GET_MODE (x), GET_MODE (y));
3122 : :
3123 : 214053 : if (final_p)
3124 : 107 : *xp = adjust_address (y, GET_MODE (x), offset);
3125 : : else
3126 : 213946 : *xp = adjust_address_nv (y, GET_MODE (x), offset);
3127 : : }
3128 : 2921829 : else if (REG_P (y) && HARD_REGISTER_P (y))
3129 : : {
3130 : 5843652 : rtx new_rtx = simplify_subreg (GET_MODE (x), y, GET_MODE (y),
3131 : 2921826 : SUBREG_BYTE (x));
3132 : :
3133 : 2921826 : if (new_rtx != 0)
3134 : 2916571 : *xp = new_rtx;
3135 : 5255 : else if (final_p && REG_P (y))
3136 : : {
3137 : : /* Simplify_subreg can't handle some REG cases, but we have to. */
3138 : 2100 : unsigned int regno;
3139 : 2100 : poly_int64 offset;
3140 : :
3141 : 2100 : regno = subreg_regno (x);
3142 : 2100 : if (subreg_lowpart_p (x))
3143 : 2100 : offset = byte_lowpart_offset (GET_MODE (x), GET_MODE (y));
3144 : : else
3145 : 0 : offset = SUBREG_BYTE (x);
3146 : 2100 : *xp = gen_rtx_REG_offset (y, GET_MODE (x), regno, offset);
3147 : : }
3148 : : }
3149 : :
3150 : 3135882 : return *xp;
3151 : : }
3152 : :
3153 : : /* Do alter_subreg on all the SUBREGs contained in X. */
3154 : :
3155 : : static rtx
3156 : 165310032 : walk_alter_subreg (rtx *xp, bool *changed)
3157 : : {
3158 : 165310032 : rtx x = *xp;
3159 : 165310032 : switch (GET_CODE (x))
3160 : : {
3161 : 34442661 : case PLUS:
3162 : 34442661 : case MULT:
3163 : 34442661 : case AND:
3164 : 34442661 : case ASHIFT:
3165 : 34442661 : XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0), changed);
3166 : 34442661 : XEXP (x, 1) = walk_alter_subreg (&XEXP (x, 1), changed);
3167 : 34442661 : break;
3168 : :
3169 : 43438955 : case MEM:
3170 : 43438955 : case ZERO_EXTEND:
3171 : 43438955 : XEXP (x, 0) = walk_alter_subreg (&XEXP (x, 0), changed);
3172 : 43438955 : break;
3173 : :
3174 : 1 : case SUBREG:
3175 : 1 : *changed = true;
3176 : 1 : return alter_subreg (xp, true);
3177 : :
3178 : : default:
3179 : : break;
3180 : : }
3181 : :
3182 : 165310031 : return *xp;
3183 : : }
3184 : :
3185 : : /* Report inconsistency between the assembler template and the operands.
3186 : : In an `asm', it's the user's fault; otherwise, the compiler's fault. */
3187 : :
3188 : : void
3189 : 19 : output_operand_lossage (const char *cmsgid, ...)
3190 : : {
3191 : 19 : char *fmt_string;
3192 : 19 : char *new_message;
3193 : 19 : const char *pfx_str;
3194 : 19 : va_list ap;
3195 : :
3196 : 19 : va_start (ap, cmsgid);
3197 : :
3198 : 19 : pfx_str = this_is_asm_operands ? _("invalid 'asm': ") : "output_operand: ";
3199 : 19 : fmt_string = xasprintf ("%s%s", pfx_str, _(cmsgid));
3200 : 19 : new_message = xvasprintf (fmt_string, ap);
3201 : :
3202 : 19 : if (this_is_asm_operands)
3203 : 19 : error_for_asm (this_is_asm_operands, "%s", new_message);
3204 : : else
3205 : 0 : internal_error ("%s", new_message);
3206 : :
3207 : 19 : free (fmt_string);
3208 : 19 : free (new_message);
3209 : 19 : va_end (ap);
3210 : 19 : }
3211 : :
3212 : : /* Output of assembler code from a template, and its subroutines. */
3213 : :
3214 : : /* Annotate the assembly with a comment describing the pattern and
3215 : : alternative used. */
3216 : :
3217 : : static void
3218 : 3587 : output_asm_name (void)
3219 : : {
3220 : 3587 : if (debug_insn)
3221 : : {
3222 : 3433 : fprintf (asm_out_file, "\t%s %d\t",
3223 : 3433 : ASM_COMMENT_START, INSN_UID (debug_insn));
3224 : :
3225 : 3433 : fprintf (asm_out_file, "[c=%d",
3226 : 3433 : insn_cost (debug_insn, optimize_insn_for_speed_p ()));
3227 : 3433 : if (HAVE_ATTR_length)
3228 : 3433 : fprintf (asm_out_file, " l=%d",
3229 : : get_attr_length (debug_insn));
3230 : 3433 : fprintf (asm_out_file, "] ");
3231 : :
3232 : 3433 : int num = INSN_CODE (debug_insn);
3233 : 3433 : fprintf (asm_out_file, "%s", insn_data[num].name);
3234 : 3433 : if (insn_data[num].n_alternatives > 1)
3235 : 1977 : fprintf (asm_out_file, "/%d", which_alternative);
3236 : :
3237 : : /* Clear this so only the first assembler insn
3238 : : of any rtl insn will get the special comment for -dp. */
3239 : 3433 : debug_insn = 0;
3240 : : }
3241 : 3587 : }
3242 : :
3243 : : /* If OP is a REG or MEM and we can find a MEM_EXPR corresponding to it
3244 : : or its address, return that expr . Set *PADDRESSP to 1 if the expr
3245 : : corresponds to the address of the object and 0 if to the object. */
3246 : :
3247 : : static tree
3248 : 391 : get_mem_expr_from_op (rtx op, int *paddressp)
3249 : : {
3250 : 391 : tree expr;
3251 : 391 : int inner_addressp;
3252 : :
3253 : 391 : *paddressp = 0;
3254 : :
3255 : 391 : if (REG_P (op))
3256 : 249 : return REG_EXPR (op);
3257 : 142 : else if (!MEM_P (op))
3258 : : return 0;
3259 : :
3260 : 51 : if (MEM_EXPR (op) != 0)
3261 : : return MEM_EXPR (op);
3262 : :
3263 : : /* Otherwise we have an address, so indicate it and look at the address. */
3264 : 0 : *paddressp = 1;
3265 : 0 : op = XEXP (op, 0);
3266 : :
3267 : : /* First check if we have a decl for the address, then look at the right side
3268 : : if it is a PLUS. Otherwise, strip off arithmetic and keep looking.
3269 : : But don't allow the address to itself be indirect. */
3270 : 0 : if ((expr = get_mem_expr_from_op (op, &inner_addressp)) && ! inner_addressp)
3271 : : return expr;
3272 : 0 : else if (GET_CODE (op) == PLUS
3273 : 0 : && (expr = get_mem_expr_from_op (XEXP (op, 1), &inner_addressp)))
3274 : : return expr;
3275 : :
3276 : 0 : while (UNARY_P (op)
3277 : 0 : || GET_RTX_CLASS (GET_CODE (op)) == RTX_BIN_ARITH)
3278 : 0 : op = XEXP (op, 0);
3279 : :
3280 : 0 : expr = get_mem_expr_from_op (op, &inner_addressp);
3281 : 0 : return inner_addressp ? 0 : expr;
3282 : : }
3283 : :
3284 : : /* Output operand names for assembler instructions. OPERANDS is the
3285 : : operand vector, OPORDER is the order to write the operands, and NOPS
3286 : : is the number of operands to write. */
3287 : :
3288 : : static void
3289 : 248 : output_asm_operand_names (rtx *operands, int *oporder, int nops)
3290 : : {
3291 : 248 : int wrote = 0;
3292 : 248 : int i;
3293 : :
3294 : 639 : for (i = 0; i < nops; i++)
3295 : : {
3296 : 391 : int addressp;
3297 : 391 : rtx op = operands[oporder[i]];
3298 : 391 : tree expr = get_mem_expr_from_op (op, &addressp);
3299 : :
3300 : 614 : fprintf (asm_out_file, "%c%s",
3301 : : wrote ? ',' : '\t', wrote ? "" : ASM_COMMENT_START);
3302 : 391 : wrote = 1;
3303 : 391 : if (expr)
3304 : : {
3305 : 221 : fprintf (asm_out_file, "%s",
3306 : 221 : addressp ? "*" : "");
3307 : 221 : print_mem_expr (asm_out_file, expr);
3308 : 221 : wrote = 1;
3309 : : }
3310 : 79 : else if (REG_P (op) && ORIGINAL_REGNO (op)
3311 : 238 : && ORIGINAL_REGNO (op) != REGNO (op))
3312 : 41 : fprintf (asm_out_file, " tmp%i", ORIGINAL_REGNO (op));
3313 : : }
3314 : 248 : }
3315 : :
3316 : : #ifdef ASSEMBLER_DIALECT
3317 : : /* Helper function to parse assembler dialects in the asm string.
3318 : : This is called from output_asm_insn and asm_fprintf. */
3319 : : static const char *
3320 : 249563142 : do_assembler_dialects (const char *p, int *dialect)
3321 : : {
3322 : 249563142 : char c = *(p - 1);
3323 : :
3324 : 249563142 : switch (c)
3325 : : {
3326 : 124781570 : case '{':
3327 : 124781570 : {
3328 : 124781570 : int i;
3329 : :
3330 : 124781570 : if (*dialect)
3331 : 0 : output_operand_lossage ("nested assembly dialect alternatives");
3332 : : else
3333 : 124781570 : *dialect = 1;
3334 : :
3335 : : /* If we want the first dialect, do nothing. Otherwise, skip
3336 : : DIALECT_NUMBER of strings ending with '|'. */
3337 : 124782599 : for (i = 0; i < dialect_number; i++)
3338 : : {
3339 : 8947 : while (*p && *p != '}')
3340 : : {
3341 : 8382 : if (*p == '|')
3342 : : {
3343 : 1029 : p++;
3344 : 1029 : break;
3345 : : }
3346 : :
3347 : : /* Skip over any character after a percent sign. */
3348 : 7353 : if (*p == '%')
3349 : 2421 : p++;
3350 : 7353 : if (*p)
3351 : 7353 : p++;
3352 : : }
3353 : :
3354 : 1594 : if (*p == '}')
3355 : : break;
3356 : : }
3357 : :
3358 : 124781570 : if (*p == '\0')
3359 : 0 : output_operand_lossage ("unterminated assembly dialect alternative");
3360 : : }
3361 : : break;
3362 : :
3363 : 63888529 : case '|':
3364 : 63888529 : if (*dialect)
3365 : : {
3366 : : /* Skip to close brace. */
3367 : 339384441 : do
3368 : : {
3369 : 339384441 : if (*p == '\0')
3370 : : {
3371 : 0 : output_operand_lossage ("unterminated assembly dialect alternative");
3372 : 0 : break;
3373 : : }
3374 : :
3375 : : /* Skip over any character after a percent sign. */
3376 : 339384441 : if (*p == '%' && p[1])
3377 : : {
3378 : 125133788 : p += 2;
3379 : 125133788 : continue;
3380 : : }
3381 : :
3382 : 214250653 : if (*p++ == '}')
3383 : : break;
3384 : : }
3385 : : while (1);
3386 : :
3387 : 63888528 : *dialect = 0;
3388 : : }
3389 : : else
3390 : 1 : putc (c, asm_out_file);
3391 : : break;
3392 : :
3393 : 60893043 : case '}':
3394 : 60893043 : if (! *dialect)
3395 : 1 : putc (c, asm_out_file);
3396 : 60893043 : *dialect = 0;
3397 : 60893043 : break;
3398 : 0 : default:
3399 : 0 : gcc_unreachable ();
3400 : : }
3401 : :
3402 : 249563142 : return p;
3403 : : }
3404 : : #endif
3405 : :
3406 : : /* Output text from TEMPLATE to the assembler output file,
3407 : : obeying %-directions to substitute operands taken from
3408 : : the vector OPERANDS.
3409 : :
3410 : : %N (for N a digit) means print operand N in usual manner.
3411 : : %lN means require operand N to be a CODE_LABEL or LABEL_REF
3412 : : and print the label name with no punctuation.
3413 : : %cN means require operand N to be a constant
3414 : : and print the constant expression with no punctuation.
3415 : : %aN means expect operand N to be a memory address
3416 : : (not a memory reference!) and print a reference
3417 : : to that address.
3418 : : %nN means expect operand N to be a constant
3419 : : and print a constant expression for minus the value
3420 : : of the operand, with no other punctuation. */
3421 : :
3422 : : void
3423 : 103273865 : output_asm_insn (const char *templ, rtx *operands)
3424 : : {
3425 : 103273865 : const char *p;
3426 : 103273865 : int c;
3427 : : #ifdef ASSEMBLER_DIALECT
3428 : 103273865 : int dialect = 0;
3429 : : #endif
3430 : 103273865 : int oporder[MAX_RECOG_OPERANDS];
3431 : 103273865 : char opoutput[MAX_RECOG_OPERANDS];
3432 : 103273865 : int ops = 0;
3433 : :
3434 : : /* An insn may return a null string template
3435 : : in a case where no assembler code is needed. */
3436 : 103273865 : if (*templ == 0)
3437 : 12506552 : return;
3438 : :
3439 : 90767313 : memset (opoutput, 0, sizeof opoutput);
3440 : 90767313 : p = templ;
3441 : 90767313 : putc ('\t', asm_out_file);
3442 : :
3443 : : #ifdef ASM_OUTPUT_OPCODE
3444 : 98146143 : ASM_OUTPUT_OPCODE (asm_out_file, p);
3445 : : #endif
3446 : :
3447 : 1113079926 : while ((c = *p++))
3448 : 1022312613 : switch (c)
3449 : : {
3450 : 40384 : case '\n':
3451 : 40384 : if (flag_verbose_asm)
3452 : 0 : output_asm_operand_names (operands, oporder, ops);
3453 : 40384 : if (flag_print_asm_name)
3454 : 74 : output_asm_name ();
3455 : :
3456 : 40384 : ops = 0;
3457 : 40384 : memset (opoutput, 0, sizeof opoutput);
3458 : :
3459 : 40384 : putc (c, asm_out_file);
3460 : : #ifdef ASM_OUTPUT_OPCODE
3461 : 117730 : while ((c = *p) == '\t')
3462 : : {
3463 : 36962 : putc (c, asm_out_file);
3464 : 36962 : p++;
3465 : : }
3466 : 40384 : ASM_OUTPUT_OPCODE (asm_out_file, p);
3467 : : #endif
3468 : : break;
3469 : :
3470 : : #ifdef ASSEMBLER_DIALECT
3471 : 249563142 : case '{':
3472 : 249563142 : case '}':
3473 : 249563142 : case '|':
3474 : 249563142 : p = do_assembler_dialects (p, &dialect);
3475 : 249563142 : break;
3476 : : #endif
3477 : :
3478 : 183864357 : case '%':
3479 : : /* %% outputs a single %. %{, %} and %| print {, } and | respectively
3480 : : if ASSEMBLER_DIALECT defined and these characters have a special
3481 : : meaning as dialect delimiters.*/
3482 : 183864357 : if (*p == '%'
3483 : : #ifdef ASSEMBLER_DIALECT
3484 : 183830651 : || *p == '{' || *p == '}' || *p == '|'
3485 : : #endif
3486 : : )
3487 : : {
3488 : 145600 : putc (*p, asm_out_file);
3489 : 145600 : p++;
3490 : : }
3491 : : /* %= outputs a number which is unique to each insn in the entire
3492 : : compilation. This is useful for making local labels that are
3493 : : referred to more than once in a given insn. */
3494 : 183718757 : else if (*p == '=')
3495 : : {
3496 : 19 : p++;
3497 : 19 : fprintf (asm_out_file, "%d", insn_counter);
3498 : : }
3499 : : /* % followed by a letter and some digits
3500 : : outputs an operand in a special way depending on the letter.
3501 : : Letters `acln' are implemented directly.
3502 : : Other letters are passed to `output_operand' so that
3503 : : the TARGET_PRINT_OPERAND hook can define them. */
3504 : 183718738 : else if (ISALPHA (*p))
3505 : : {
3506 : 48653140 : int letter = *p++;
3507 : 48653140 : unsigned long opnum;
3508 : 48653140 : char *endptr;
3509 : 48653140 : int letter2 = 0;
3510 : :
3511 : 48653140 : if (letter == 'c' && *p == 'c')
3512 : 40 : letter2 = *p++;
3513 : 48653140 : opnum = strtoul (p, &endptr, 10);
3514 : :
3515 : 48653140 : if (endptr == p)
3516 : 0 : output_operand_lossage ("operand number missing "
3517 : : "after %%-letter");
3518 : 48653140 : else if (this_is_asm_operands && opnum >= insn_noperands)
3519 : 0 : output_operand_lossage ("operand number out of range");
3520 : 48653140 : else if (letter == 'l')
3521 : 8608395 : output_asm_label (operands[opnum]);
3522 : 40044745 : else if (letter == 'a')
3523 : 2254 : output_address (VOIDmode, operands[opnum]);
3524 : 40042491 : else if (letter == 'c')
3525 : : {
3526 : 195026 : if (letter2 == 'c' || CONSTANT_ADDRESS_P (operands[opnum]))
3527 : 871 : output_addr_const (asm_out_file, operands[opnum]);
3528 : : else
3529 : 194155 : output_operand (operands[opnum], 'c');
3530 : : }
3531 : 39847465 : else if (letter == 'n')
3532 : : {
3533 : 0 : if (CONST_INT_P (operands[opnum]))
3534 : 0 : fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
3535 : 0 : - INTVAL (operands[opnum]));
3536 : : else
3537 : : {
3538 : 0 : putc ('-', asm_out_file);
3539 : 0 : output_addr_const (asm_out_file, operands[opnum]);
3540 : : }
3541 : : }
3542 : : else
3543 : 39847465 : output_operand (operands[opnum], letter);
3544 : :
3545 : 48653140 : if (!opoutput[opnum])
3546 : 46346070 : oporder[ops++] = opnum;
3547 : 48653140 : opoutput[opnum] = 1;
3548 : :
3549 : 48653140 : p = endptr;
3550 : 48653140 : c = *p;
3551 : : }
3552 : : /* % followed by a digit outputs an operand the default way. */
3553 : 135065598 : else if (ISDIGIT (*p))
3554 : : {
3555 : 113805239 : unsigned long opnum;
3556 : 113805239 : char *endptr;
3557 : :
3558 : 113805239 : opnum = strtoul (p, &endptr, 10);
3559 : 113805239 : if (this_is_asm_operands && opnum >= insn_noperands)
3560 : 3 : output_operand_lossage ("operand number out of range");
3561 : : else
3562 : 113805236 : output_operand (operands[opnum], 0);
3563 : :
3564 : 113805239 : if (!opoutput[opnum])
3565 : 111498326 : oporder[ops++] = opnum;
3566 : 113805239 : opoutput[opnum] = 1;
3567 : :
3568 : 113805239 : p = endptr;
3569 : 113805239 : c = *p;
3570 : : }
3571 : : /* % followed by punctuation: output something for that
3572 : : punctuation character alone, with no operand. The
3573 : : TARGET_PRINT_OPERAND hook decides what is actually done. */
3574 : 21260359 : else if (targetm.asm_out.print_operand_punct_valid_p ((unsigned char) *p))
3575 : 21260359 : output_operand (NULL_RTX, *p++);
3576 : : else
3577 : 0 : output_operand_lossage ("invalid %%-code");
3578 : : break;
3579 : :
3580 : 588844730 : default:
3581 : 588844730 : putc (c, asm_out_file);
3582 : : }
3583 : :
3584 : : /* Try to keep the asm a bit more readable. */
3585 : 90767313 : if ((flag_verbose_asm || flag_print_asm_name) && strlen (templ) < 9)
3586 : 418 : putc ('\t', asm_out_file);
3587 : :
3588 : : /* Write out the variable names for operands, if we know them. */
3589 : 90767313 : if (flag_verbose_asm)
3590 : 248 : output_asm_operand_names (operands, oporder, ops);
3591 : 90767313 : if (flag_print_asm_name)
3592 : 3513 : output_asm_name ();
3593 : :
3594 : 90767313 : putc ('\n', asm_out_file);
3595 : : }
3596 : :
3597 : : /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */
3598 : :
3599 : : void
3600 : 8617268 : output_asm_label (rtx x)
3601 : : {
3602 : 8617268 : char buf[256];
3603 : :
3604 : 8617268 : if (GET_CODE (x) == LABEL_REF)
3605 : 8997 : x = label_ref_label (x);
3606 : 8617268 : if (LABEL_P (x)
3607 : 90 : || (NOTE_P (x)
3608 : 90 : && NOTE_KIND (x) == NOTE_INSN_DELETED_LABEL))
3609 : 8617268 : ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3610 : : else
3611 : 0 : output_operand_lossage ("'%%l' operand isn't a label");
3612 : :
3613 : 8617268 : assemble_name (asm_out_file, buf);
3614 : 8617268 : }
3615 : :
3616 : : /* Marks SYMBOL_REFs in x as referenced through use of assemble_external. */
3617 : :
3618 : : void
3619 : 153846856 : mark_symbol_refs_as_used (rtx x)
3620 : : {
3621 : 153846856 : subrtx_iterator::array_type array;
3622 : 419748091 : FOR_EACH_SUBRTX (iter, array, x, ALL)
3623 : : {
3624 : 265901235 : const_rtx x = *iter;
3625 : 265901235 : if (GET_CODE (x) == SYMBOL_REF)
3626 : 15770998 : if (tree t = SYMBOL_REF_DECL (x))
3627 : 14538038 : assemble_external (t);
3628 : : }
3629 : 153846856 : }
3630 : :
3631 : : /* Print operand X using machine-dependent assembler syntax.
3632 : : CODE is a non-digit that preceded the operand-number in the % spec,
3633 : : such as 'z' if the spec was `%z3'. CODE is 0 if there was no char
3634 : : between the % and the digits.
3635 : : When CODE is a non-letter, X is 0.
3636 : :
3637 : : The meanings of the letters are machine-dependent and controlled
3638 : : by TARGET_PRINT_OPERAND. */
3639 : :
3640 : : void
3641 : 175107215 : output_operand (rtx x, int code ATTRIBUTE_UNUSED)
3642 : : {
3643 : 175107215 : if (x && GET_CODE (x) == SUBREG)
3644 : 1 : x = alter_subreg (&x, true);
3645 : :
3646 : : /* X must not be a pseudo reg. */
3647 : 175107215 : if (!targetm.no_register_allocation)
3648 : 175107215 : gcc_assert (!x || !REG_P (x) || REGNO (x) < FIRST_PSEUDO_REGISTER);
3649 : :
3650 : 175107215 : targetm.asm_out.print_operand (asm_out_file, x, code);
3651 : :
3652 : 175107215 : if (x == NULL_RTX)
3653 : : return;
3654 : :
3655 : 153846856 : mark_symbol_refs_as_used (x);
3656 : : }
3657 : :
3658 : : /* Print a memory reference operand for address X using
3659 : : machine-dependent assembler syntax. */
3660 : :
3661 : : void
3662 : 3634278 : output_address (machine_mode mode, rtx x)
3663 : : {
3664 : 3634278 : bool changed = false;
3665 : 3634278 : walk_alter_subreg (&x, &changed);
3666 : 3634278 : targetm.asm_out.print_operand_address (asm_out_file, mode, x);
3667 : 3634278 : }
3668 : :
3669 : : /* Print an integer constant expression in assembler syntax.
3670 : : Addition and subtraction are the only arithmetic
3671 : : that may appear in these expressions. */
3672 : :
3673 : : void
3674 : 162155556 : output_addr_const (FILE *file, rtx x)
3675 : : {
3676 : 172824789 : char buf[256];
3677 : :
3678 : 172824789 : restart:
3679 : 172824789 : switch (GET_CODE (x))
3680 : : {
3681 : 523 : case PC:
3682 : 523 : putc ('.', file);
3683 : 523 : break;
3684 : :
3685 : 124035057 : case SYMBOL_REF:
3686 : 124035057 : if (SYMBOL_REF_DECL (x))
3687 : 20248906 : assemble_external (SYMBOL_REF_DECL (x));
3688 : : #ifdef ASM_OUTPUT_SYMBOL_REF
3689 : 124035057 : ASM_OUTPUT_SYMBOL_REF (file, x);
3690 : : #else
3691 : : assemble_name (file, XSTR (x, 0));
3692 : : #endif
3693 : : break;
3694 : :
3695 : 15002 : case LABEL_REF:
3696 : 15002 : x = label_ref_label (x);
3697 : : /* Fall through. */
3698 : 15002 : case CODE_LABEL:
3699 : 15002 : ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
3700 : : #ifdef ASM_OUTPUT_LABEL_REF
3701 : : ASM_OUTPUT_LABEL_REF (file, buf);
3702 : : #else
3703 : 15002 : assemble_name (file, buf);
3704 : : #endif
3705 : 15002 : break;
3706 : :
3707 : 38091142 : case CONST_INT:
3708 : 38091142 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
3709 : 38091142 : break;
3710 : :
3711 : 2700122 : case CONST:
3712 : : /* This used to output parentheses around the expression,
3713 : : but that does not work on the 386 (either ATT or BSD assembler). */
3714 : 2700122 : output_addr_const (file, XEXP (x, 0));
3715 : 2700122 : break;
3716 : :
3717 : 2 : case CONST_WIDE_INT:
3718 : : /* We do not know the mode here so we have to use a round about
3719 : : way to build a wide-int to get it printed properly. */
3720 : 2 : {
3721 : 2 : wide_int w = wide_int::from_array (&CONST_WIDE_INT_ELT (x, 0),
3722 : 2 : CONST_WIDE_INT_NUNITS (x),
3723 : 2 : CONST_WIDE_INT_NUNITS (x)
3724 : 2 : * HOST_BITS_PER_WIDE_INT,
3725 : 2 : false);
3726 : 2 : print_decs (w, file);
3727 : 2 : }
3728 : 2 : break;
3729 : :
3730 : 0 : case CONST_DOUBLE:
3731 : 0 : if (CONST_DOUBLE_AS_INT_P (x))
3732 : : {
3733 : : /* We can use %d if the number is one word and positive. */
3734 : 0 : if (CONST_DOUBLE_HIGH (x))
3735 : 0 : fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
3736 : : (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x),
3737 : 0 : (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x));
3738 : 0 : else if (CONST_DOUBLE_LOW (x) < 0)
3739 : 0 : fprintf (file, HOST_WIDE_INT_PRINT_HEX,
3740 : : (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x));
3741 : : else
3742 : 0 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
3743 : : }
3744 : : else
3745 : : /* We can't handle floating point constants;
3746 : : PRINT_OPERAND must handle them. */
3747 : 0 : output_operand_lossage ("floating constant misused");
3748 : : break;
3749 : :
3750 : 0 : case CONST_FIXED:
3751 : 0 : fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_FIXED_VALUE_LOW (x));
3752 : 0 : break;
3753 : :
3754 : 2720326 : case PLUS:
3755 : : /* Some assemblers need integer constants to appear last (eg masm). */
3756 : 2720326 : if (CONST_INT_P (XEXP (x, 0)))
3757 : : {
3758 : 0 : output_addr_const (file, XEXP (x, 1));
3759 : 0 : if (INTVAL (XEXP (x, 0)) >= 0)
3760 : 0 : fprintf (file, "+");
3761 : 0 : output_addr_const (file, XEXP (x, 0));
3762 : : }
3763 : : else
3764 : : {
3765 : 2720326 : output_addr_const (file, XEXP (x, 0));
3766 : 2720326 : if (!CONST_INT_P (XEXP (x, 1))
3767 : 2720326 : || INTVAL (XEXP (x, 1)) >= 0)
3768 : 2696997 : fprintf (file, "+");
3769 : 2720326 : output_addr_const (file, XEXP (x, 1));
3770 : : }
3771 : : break;
3772 : :
3773 : 5248849 : case MINUS:
3774 : : /* Avoid outputting things like x-x or x+5-x,
3775 : : since some assemblers can't handle that. */
3776 : 5248849 : x = simplify_subtraction (x);
3777 : 5248849 : if (GET_CODE (x) != MINUS)
3778 : 0 : goto restart;
3779 : :
3780 : 5248849 : output_addr_const (file, XEXP (x, 0));
3781 : 5248849 : fprintf (file, "-");
3782 : 5248849 : if ((CONST_INT_P (XEXP (x, 1)) && INTVAL (XEXP (x, 1)) >= 0)
3783 : 5248849 : || GET_CODE (XEXP (x, 1)) == PC
3784 : 5248326 : || GET_CODE (XEXP (x, 1)) == SYMBOL_REF)
3785 : : output_addr_const (file, XEXP (x, 1));
3786 : : else
3787 : : {
3788 : 64 : fputs (targetm.asm_out.open_paren, file);
3789 : 64 : output_addr_const (file, XEXP (x, 1));
3790 : 64 : fputs (targetm.asm_out.close_paren, file);
3791 : : }
3792 : : break;
3793 : :
3794 : 0 : case ZERO_EXTEND:
3795 : 0 : case SIGN_EXTEND:
3796 : 0 : case SUBREG:
3797 : 0 : case TRUNCATE:
3798 : 0 : output_addr_const (file, XEXP (x, 0));
3799 : 0 : break;
3800 : :
3801 : 13766 : default:
3802 : 13766 : if (targetm.asm_out.output_addr_const_extra (file, x))
3803 : : break;
3804 : :
3805 : 0 : output_operand_lossage ("invalid expression as operand");
3806 : : }
3807 : 162155556 : }
3808 : :
3809 : : /* Output a quoted string. */
3810 : :
3811 : : void
3812 : 1492011 : output_quoted_string (FILE *asm_file, const char *string)
3813 : : {
3814 : : #ifdef OUTPUT_QUOTED_STRING
3815 : : OUTPUT_QUOTED_STRING (asm_file, string);
3816 : : #else
3817 : 1492011 : char c;
3818 : :
3819 : 1492011 : putc ('\"', asm_file);
3820 : 86078731 : while ((c = *string++) != 0)
3821 : : {
3822 : 83094709 : if (ISPRINT (c))
3823 : : {
3824 : 83094697 : if (c == '\"' || c == '\\')
3825 : 14 : putc ('\\', asm_file);
3826 : 83094697 : putc (c, asm_file);
3827 : : }
3828 : : else
3829 : 12 : fprintf (asm_file, "\\%03o", (unsigned char) c);
3830 : : }
3831 : 1492011 : putc ('\"', asm_file);
3832 : : #endif
3833 : 1492011 : }
3834 : :
3835 : : /* Write a HOST_WIDE_INT number in hex form 0x1234, fast. */
3836 : :
3837 : : void
3838 : 495585475 : fprint_whex (FILE *f, unsigned HOST_WIDE_INT value)
3839 : : {
3840 : 495585475 : char buf[2 + CHAR_BIT * sizeof (value) / 4];
3841 : 495585475 : if (value == 0)
3842 : 48257246 : putc ('0', f);
3843 : : else
3844 : : {
3845 : : char *p = buf + sizeof (buf);
3846 : 938653454 : do
3847 : 938653454 : *--p = "0123456789abcdef"[value % 16];
3848 : 938653454 : while ((value /= 16) != 0);
3849 : 447328229 : *--p = 'x';
3850 : 447328229 : *--p = '0';
3851 : 447328229 : fwrite (p, 1, buf + sizeof (buf) - p, f);
3852 : : }
3853 : 495585475 : }
3854 : :
3855 : : /* Internal function that prints an unsigned long in decimal in reverse.
3856 : : The output string IS NOT null-terminated. */
3857 : :
3858 : : static int
3859 : 430437812 : sprint_ul_rev (char *s, unsigned long value)
3860 : : {
3861 : 0 : int i = 0;
3862 : 1341110183 : do
3863 : : {
3864 : 1341110183 : s[i] = "0123456789"[value % 10];
3865 : 1341110183 : value /= 10;
3866 : 1341110183 : i++;
3867 : : /* alternate version, without modulo */
3868 : : /* oldval = value; */
3869 : : /* value /= 10; */
3870 : : /* s[i] = "0123456789" [oldval - 10*value]; */
3871 : : /* i++ */
3872 : : }
3873 : 1341110183 : while (value != 0);
3874 : 314423974 : return i;
3875 : : }
3876 : :
3877 : : /* Write an unsigned long as decimal to a file, fast. */
3878 : :
3879 : : void
3880 : 116013838 : fprint_ul (FILE *f, unsigned long value)
3881 : : {
3882 : : /* python says: len(str(2**64)) == 20 */
3883 : 116013838 : char s[20];
3884 : 116013838 : int i;
3885 : :
3886 : 116013838 : i = sprint_ul_rev (s, value);
3887 : :
3888 : : /* It's probably too small to bother with string reversal and fputs. */
3889 : 216765695 : do
3890 : : {
3891 : 216765695 : i--;
3892 : 216765695 : putc (s[i], f);
3893 : : }
3894 : 216765695 : while (i != 0);
3895 : 116013838 : }
3896 : :
3897 : : /* Write an unsigned long as decimal to a string, fast.
3898 : : s must be wide enough to not overflow, at least 21 chars.
3899 : : Returns the length of the string (without terminating '\0'). */
3900 : :
3901 : : int
3902 : 314423974 : sprint_ul (char *s, unsigned long value)
3903 : : {
3904 : 314423974 : int len = sprint_ul_rev (s, value);
3905 : 314423974 : s[len] = '\0';
3906 : :
3907 : 314423974 : std::reverse (s, s + len);
3908 : 314423974 : return len;
3909 : : }
3910 : :
3911 : : /* A poor man's fprintf, with the added features of %I, %R, %L, and %U.
3912 : : %R prints the value of REGISTER_PREFIX.
3913 : : %L prints the value of LOCAL_LABEL_PREFIX.
3914 : : %U prints the value of USER_LABEL_PREFIX.
3915 : : %I prints the value of IMMEDIATE_PREFIX.
3916 : : %O runs ASM_OUTPUT_OPCODE to transform what follows in the string.
3917 : : Also supported are %d, %i, %u, %x, %X, %o, %c, %s and %%.
3918 : :
3919 : : We handle alternate assembler dialects here, just like output_asm_insn. */
3920 : :
3921 : : void
3922 : 2 : asm_fprintf (FILE *file, const char *p, ...)
3923 : : {
3924 : 2 : char buf[10];
3925 : 2 : char *q, c;
3926 : : #ifdef ASSEMBLER_DIALECT
3927 : 2 : int dialect = 0;
3928 : : #endif
3929 : 2 : va_list argptr;
3930 : :
3931 : 2 : va_start (argptr, p);
3932 : :
3933 : 2 : buf[0] = '%';
3934 : :
3935 : 21 : while ((c = *p++))
3936 : 19 : switch (c)
3937 : : {
3938 : : #ifdef ASSEMBLER_DIALECT
3939 : 0 : case '{':
3940 : 0 : case '}':
3941 : 0 : case '|':
3942 : 0 : p = do_assembler_dialects (p, &dialect);
3943 : 0 : break;
3944 : : #endif
3945 : :
3946 : 6 : case '%':
3947 : 6 : c = *p++;
3948 : 6 : q = &buf[1];
3949 : 6 : while (strchr ("-+ #0", c))
3950 : : {
3951 : 0 : *q++ = c;
3952 : 0 : c = *p++;
3953 : : }
3954 : 6 : while (ISDIGIT (c) || c == '.')
3955 : : {
3956 : 0 : *q++ = c;
3957 : 0 : c = *p++;
3958 : : }
3959 : 6 : switch (c)
3960 : : {
3961 : 2 : case '%':
3962 : 2 : putc ('%', file);
3963 : 2 : break;
3964 : :
3965 : 0 : case 'd': case 'i': case 'u':
3966 : 0 : case 'x': case 'X': case 'o':
3967 : 0 : case 'c':
3968 : 0 : *q++ = c;
3969 : 0 : *q = 0;
3970 : 0 : fprintf (file, buf, va_arg (argptr, int));
3971 : 0 : break;
3972 : :
3973 : 0 : case 'w':
3974 : : /* This is a prefix to the 'd', 'i', 'u', 'x', 'X', and
3975 : : 'o' cases, but we do not check for those cases. It
3976 : : means that the value is a HOST_WIDE_INT, which may be
3977 : : either `long' or `long long'. */
3978 : 0 : memcpy (q, HOST_WIDE_INT_PRINT, strlen (HOST_WIDE_INT_PRINT));
3979 : 0 : q += strlen (HOST_WIDE_INT_PRINT);
3980 : 0 : *q++ = *p++;
3981 : 0 : *q = 0;
3982 : 0 : fprintf (file, buf, va_arg (argptr, HOST_WIDE_INT));
3983 : 0 : break;
3984 : :
3985 : 0 : case 'l':
3986 : 0 : *q++ = c;
3987 : : #ifdef HAVE_LONG_LONG
3988 : 0 : if (*p == 'l')
3989 : : {
3990 : 0 : *q++ = *p++;
3991 : 0 : *q++ = *p++;
3992 : 0 : *q = 0;
3993 : 0 : fprintf (file, buf, va_arg (argptr, long long));
3994 : : }
3995 : : else
3996 : : #endif
3997 : : {
3998 : 0 : *q++ = *p++;
3999 : 0 : *q = 0;
4000 : 0 : fprintf (file, buf, va_arg (argptr, long));
4001 : : }
4002 : :
4003 : : break;
4004 : :
4005 : 0 : case 's':
4006 : 0 : *q++ = c;
4007 : 0 : *q = 0;
4008 : 0 : fprintf (file, buf, va_arg (argptr, char *));
4009 : 0 : break;
4010 : :
4011 : 0 : case 'O':
4012 : : #ifdef ASM_OUTPUT_OPCODE
4013 : 0 : ASM_OUTPUT_OPCODE (asm_out_file, p);
4014 : : #endif
4015 : : break;
4016 : :
4017 : : case 'R':
4018 : : #ifdef REGISTER_PREFIX
4019 : : fprintf (file, "%s", REGISTER_PREFIX);
4020 : : #endif
4021 : : break;
4022 : :
4023 : : case 'I':
4024 : : #ifdef IMMEDIATE_PREFIX
4025 : : fprintf (file, "%s", IMMEDIATE_PREFIX);
4026 : : #endif
4027 : : break;
4028 : :
4029 : 0 : case 'L':
4030 : : #ifdef LOCAL_LABEL_PREFIX
4031 : 0 : fprintf (file, "%s", LOCAL_LABEL_PREFIX);
4032 : : #endif
4033 : 0 : break;
4034 : :
4035 : 0 : case 'U':
4036 : 0 : fputs (user_label_prefix, file);
4037 : 0 : break;
4038 : :
4039 : : #ifdef ASM_FPRINTF_EXTENSIONS
4040 : : /* Uppercase letters are reserved for general use by asm_fprintf
4041 : : and so are not available to target specific code. In order to
4042 : : prevent the ASM_FPRINTF_EXTENSIONS macro from using them then,
4043 : : they are defined here. As they get turned into real extensions
4044 : : to asm_fprintf they should be removed from this list. */
4045 : : case 'A': case 'B': case 'C': case 'D': case 'E':
4046 : : case 'F': case 'G': case 'H': case 'J': case 'K':
4047 : : case 'M': case 'N': case 'P': case 'Q': case 'S':
4048 : : case 'T': case 'V': case 'W': case 'Y': case 'Z':
4049 : : break;
4050 : :
4051 : 4 : ASM_FPRINTF_EXTENSIONS (file, argptr, p)
4052 : : #endif
4053 : 0 : default:
4054 : 0 : gcc_unreachable ();
4055 : : }
4056 : : break;
4057 : :
4058 : 13 : default:
4059 : 13 : putc (c, file);
4060 : : }
4061 : 2 : va_end (argptr);
4062 : 2 : }
4063 : :
4064 : : /* Return true if this function has no function calls. */
4065 : :
4066 : : bool
4067 : 2928404 : leaf_function_p (void)
4068 : : {
4069 : 2928404 : rtx_insn *insn;
4070 : :
4071 : : /* Ensure we walk the entire function body. */
4072 : 2928404 : gcc_assert (!in_sequence_p ());
4073 : :
4074 : : /* Some back-ends (e.g. s390) want leaf functions to stay leaf
4075 : : functions even if they call mcount. */
4076 : 2928404 : if (crtl->profile && !targetm.keep_leaf_when_profiled ())
4077 : : return false;
4078 : :
4079 : 77296595 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4080 : : {
4081 : 76246343 : if (CALL_P (insn)
4082 : 2017106 : && ! SIBLING_CALL_P (insn)
4083 : 78123849 : && ! FAKE_CALL_P (insn))
4084 : : return false;
4085 : 74368937 : if (NONJUMP_INSN_P (insn)
4086 : 35589440 : && GET_CODE (PATTERN (insn)) == SEQUENCE
4087 : 0 : && CALL_P (XVECEXP (PATTERN (insn), 0, 0))
4088 : 74368937 : && ! SIBLING_CALL_P (XVECEXP (PATTERN (insn), 0, 0)))
4089 : : return false;
4090 : : }
4091 : :
4092 : : return true;
4093 : : }
4094 : :
4095 : : /* Return true if branch is a forward branch.
4096 : : Uses insn_shuid array, so it works only in the final pass. May be used by
4097 : : output templates to customary add branch prediction hints.
4098 : : */
4099 : : bool
4100 : 0 : final_forward_branch_p (rtx_insn *insn)
4101 : : {
4102 : 0 : int insn_id, label_id;
4103 : :
4104 : 0 : gcc_assert (uid_shuid);
4105 : 0 : insn_id = INSN_SHUID (insn);
4106 : 0 : label_id = INSN_SHUID (JUMP_LABEL (insn));
4107 : : /* We've hit some insns that does not have id information available. */
4108 : 0 : gcc_assert (insn_id && label_id);
4109 : 0 : return insn_id < label_id;
4110 : : }
4111 : :
4112 : : /* On some machines, a function with no call insns
4113 : : can run faster if it doesn't create its own register window.
4114 : : When output, the leaf function should use only the "output"
4115 : : registers. Ordinarily, the function would be compiled to use
4116 : : the "input" registers to find its arguments; it is a candidate
4117 : : for leaf treatment if it uses only the "input" registers.
4118 : : Leaf function treatment means renumbering so the function
4119 : : uses the "output" registers instead. */
4120 : :
4121 : : #ifdef LEAF_REGISTERS
4122 : :
4123 : : /* Return bool if this function uses only the registers that can be
4124 : : safely renumbered. */
4125 : :
4126 : : bool
4127 : : only_leaf_regs_used (void)
4128 : : {
4129 : : int i;
4130 : : const char *const permitted_reg_in_leaf_functions = LEAF_REGISTERS;
4131 : :
4132 : : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4133 : : if ((df_regs_ever_live_p (i) || global_regs[i])
4134 : : && ! permitted_reg_in_leaf_functions[i])
4135 : : return false;
4136 : :
4137 : : if (crtl->uses_pic_offset_table
4138 : : && pic_offset_table_rtx != 0
4139 : : && REG_P (pic_offset_table_rtx)
4140 : : && ! permitted_reg_in_leaf_functions[REGNO (pic_offset_table_rtx)])
4141 : : return false;
4142 : :
4143 : : return true;
4144 : : }
4145 : :
4146 : : /* Scan all instructions and renumber all registers into those
4147 : : available in leaf functions. */
4148 : :
4149 : : static void
4150 : : leaf_renumber_regs (rtx_insn *first)
4151 : : {
4152 : : rtx_insn *insn;
4153 : :
4154 : : /* Renumber only the actual patterns.
4155 : : The reg-notes can contain frame pointer refs,
4156 : : and renumbering them could crash, and should not be needed. */
4157 : : for (insn = first; insn; insn = NEXT_INSN (insn))
4158 : : if (INSN_P (insn))
4159 : : leaf_renumber_regs_insn (PATTERN (insn));
4160 : : }
4161 : :
4162 : : /* Scan IN_RTX and its subexpressions, and renumber all regs into those
4163 : : available in leaf functions. */
4164 : :
4165 : : void
4166 : : leaf_renumber_regs_insn (rtx in_rtx)
4167 : : {
4168 : : int i, j;
4169 : : const char *format_ptr;
4170 : :
4171 : : if (in_rtx == 0)
4172 : : return;
4173 : :
4174 : : /* Renumber all input-registers into output-registers.
4175 : : renumbered_regs would be 1 for an output-register;
4176 : : they */
4177 : :
4178 : : if (REG_P (in_rtx))
4179 : : {
4180 : : int newreg;
4181 : :
4182 : : /* Don't renumber the same reg twice. */
4183 : : if (in_rtx->used)
4184 : : return;
4185 : :
4186 : : newreg = REGNO (in_rtx);
4187 : : /* Don't try to renumber pseudo regs. It is possible for a pseudo reg
4188 : : to reach here as part of a REG_NOTE. */
4189 : : if (newreg >= FIRST_PSEUDO_REGISTER)
4190 : : {
4191 : : in_rtx->used = 1;
4192 : : return;
4193 : : }
4194 : : newreg = LEAF_REG_REMAP (newreg);
4195 : : gcc_assert (newreg >= 0);
4196 : : df_set_regs_ever_live (REGNO (in_rtx), false);
4197 : : df_set_regs_ever_live (newreg, true);
4198 : : SET_REGNO (in_rtx, newreg);
4199 : : in_rtx->used = 1;
4200 : : return;
4201 : : }
4202 : :
4203 : : if (INSN_P (in_rtx))
4204 : : {
4205 : : /* Inside a SEQUENCE, we find insns.
4206 : : Renumber just the patterns of these insns,
4207 : : just as we do for the top-level insns. */
4208 : : leaf_renumber_regs_insn (PATTERN (in_rtx));
4209 : : return;
4210 : : }
4211 : :
4212 : : format_ptr = GET_RTX_FORMAT (GET_CODE (in_rtx));
4213 : :
4214 : : for (i = 0; i < GET_RTX_LENGTH (GET_CODE (in_rtx)); i++)
4215 : : switch (*format_ptr++)
4216 : : {
4217 : : case 'e':
4218 : : leaf_renumber_regs_insn (XEXP (in_rtx, i));
4219 : : break;
4220 : :
4221 : : case 'E':
4222 : : if (XVEC (in_rtx, i) != NULL)
4223 : : for (j = 0; j < XVECLEN (in_rtx, i); j++)
4224 : : leaf_renumber_regs_insn (XVECEXP (in_rtx, i, j));
4225 : : break;
4226 : :
4227 : : case 'S':
4228 : : case 's':
4229 : : case '0':
4230 : : case 'i':
4231 : : case 'L':
4232 : : case 'w':
4233 : : case 'p':
4234 : : case 'n':
4235 : : case 'u':
4236 : : break;
4237 : :
4238 : : default:
4239 : : gcc_unreachable ();
4240 : : }
4241 : : }
4242 : : #endif
4243 : :
4244 : : /* Turn the RTL into assembly. */
4245 : : static unsigned int
4246 : 1449857 : rest_of_handle_final (void)
4247 : : {
4248 : 1449857 : const char *fnname = get_fnname_from_decl (current_function_decl);
4249 : :
4250 : : /* Turn debug markers into notes if the var-tracking pass has not
4251 : : been invoked. */
4252 : 1449857 : if (!flag_var_tracking && MAY_HAVE_DEBUG_MARKER_INSNS)
4253 : 1 : delete_vta_debug_insns (false);
4254 : :
4255 : 1449857 : assemble_start_function (current_function_decl, fnname);
4256 : 1449857 : rtx_insn *first = get_insns ();
4257 : 1449857 : int seen = 0;
4258 : 1449857 : final_start_function_1 (&first, asm_out_file, &seen, optimize);
4259 : 1449857 : final_1 (first, asm_out_file, seen, optimize);
4260 : 1449857 : if (flag_ipa_ra
4261 : 943215 : && !lookup_attribute ("noipa", DECL_ATTRIBUTES (current_function_decl))
4262 : : /* Functions with naked attributes are supported only with basic asm
4263 : : statements in the body, thus for supported use cases the information
4264 : : on clobbered registers is not available. */
4265 : 2376594 : && !lookup_attribute ("naked", DECL_ATTRIBUTES (current_function_decl)))
4266 : 926737 : collect_fn_hard_reg_usage ();
4267 : 1449857 : final_end_function ();
4268 : :
4269 : : /* The IA-64 ".handlerdata" directive must be issued before the ".endp"
4270 : : directive that closes the procedure descriptor. Similarly, for x64 SEH.
4271 : : Otherwise it's not strictly necessary, but it doesn't hurt either. */
4272 : 2837763 : output_function_exception_table (crtl->has_bb_partition ? 1 : 0);
4273 : :
4274 : 1449857 : assemble_end_function (current_function_decl, fnname);
4275 : :
4276 : : /* Free up reg info memory. */
4277 : 1449857 : free_reg_info ();
4278 : :
4279 : 1449857 : if (! quiet_flag)
4280 : 0 : fflush (asm_out_file);
4281 : :
4282 : : /* Note that for those inline functions where we don't initially
4283 : : know for certain that we will be generating an out-of-line copy,
4284 : : the first invocation of this routine (rest_of_compilation) will
4285 : : skip over this code by doing a `goto exit_rest_of_compilation;'.
4286 : : Later on, wrapup_global_declarations will (indirectly) call
4287 : : rest_of_compilation again for those inline functions that need
4288 : : to have out-of-line copies generated. During that call, we
4289 : : *will* be routed past here. */
4290 : :
4291 : 1449857 : timevar_push (TV_SYMOUT);
4292 : 1449857 : if (!DECL_IGNORED_P (current_function_decl))
4293 : 1425691 : debug_hooks->function_decl (current_function_decl);
4294 : 1449857 : timevar_pop (TV_SYMOUT);
4295 : :
4296 : : /* Release the blocks that are linked to DECL_INITIAL() to free the memory. */
4297 : 1449857 : DECL_INITIAL (current_function_decl) = error_mark_node;
4298 : :
4299 : 1449857 : if (DECL_STATIC_CONSTRUCTOR (current_function_decl)
4300 : 1449857 : && targetm.have_ctors_dtors)
4301 : 22034 : targetm.asm_out.constructor (XEXP (DECL_RTL (current_function_decl), 0),
4302 : : decl_init_priority_lookup
4303 : 22034 : (current_function_decl));
4304 : 1449857 : if (DECL_STATIC_DESTRUCTOR (current_function_decl)
4305 : 1449857 : && targetm.have_ctors_dtors)
4306 : 1562 : targetm.asm_out.destructor (XEXP (DECL_RTL (current_function_decl), 0),
4307 : : decl_fini_priority_lookup
4308 : 1562 : (current_function_decl));
4309 : 1449857 : return 0;
4310 : : }
4311 : :
4312 : : namespace {
4313 : :
4314 : : const pass_data pass_data_final =
4315 : : {
4316 : : RTL_PASS, /* type */
4317 : : "final", /* name */
4318 : : OPTGROUP_NONE, /* optinfo_flags */
4319 : : TV_FINAL, /* tv_id */
4320 : : 0, /* properties_required */
4321 : : 0, /* properties_provided */
4322 : : 0, /* properties_destroyed */
4323 : : 0, /* todo_flags_start */
4324 : : 0, /* todo_flags_finish */
4325 : : };
4326 : :
4327 : : class pass_final : public rtl_opt_pass
4328 : : {
4329 : : public:
4330 : 285081 : pass_final (gcc::context *ctxt)
4331 : 570162 : : rtl_opt_pass (pass_data_final, ctxt)
4332 : : {}
4333 : :
4334 : : /* opt_pass methods: */
4335 : 1449857 : unsigned int execute (function *) final override
4336 : : {
4337 : 1449857 : return rest_of_handle_final ();
4338 : : }
4339 : :
4340 : : }; // class pass_final
4341 : :
4342 : : } // anon namespace
4343 : :
4344 : : rtl_opt_pass *
4345 : 285081 : make_pass_final (gcc::context *ctxt)
4346 : : {
4347 : 285081 : return new pass_final (ctxt);
4348 : : }
4349 : :
4350 : :
4351 : : static unsigned int
4352 : 1449856 : rest_of_handle_shorten_branches (void)
4353 : : {
4354 : : /* Shorten branches. */
4355 : 0 : shorten_branches (get_insns ());
4356 : 1449856 : return 0;
4357 : : }
4358 : :
4359 : : namespace {
4360 : :
4361 : : const pass_data pass_data_shorten_branches =
4362 : : {
4363 : : RTL_PASS, /* type */
4364 : : "shorten", /* name */
4365 : : OPTGROUP_NONE, /* optinfo_flags */
4366 : : TV_SHORTEN_BRANCH, /* tv_id */
4367 : : 0, /* properties_required */
4368 : : 0, /* properties_provided */
4369 : : 0, /* properties_destroyed */
4370 : : 0, /* todo_flags_start */
4371 : : 0, /* todo_flags_finish */
4372 : : };
4373 : :
4374 : : class pass_shorten_branches : public rtl_opt_pass
4375 : : {
4376 : : public:
4377 : 285081 : pass_shorten_branches (gcc::context *ctxt)
4378 : 570162 : : rtl_opt_pass (pass_data_shorten_branches, ctxt)
4379 : : {}
4380 : :
4381 : : /* opt_pass methods: */
4382 : 1449856 : unsigned int execute (function *) final override
4383 : : {
4384 : 1449856 : return rest_of_handle_shorten_branches ();
4385 : : }
4386 : :
4387 : : }; // class pass_shorten_branches
4388 : :
4389 : : } // anon namespace
4390 : :
4391 : : rtl_opt_pass *
4392 : 285081 : make_pass_shorten_branches (gcc::context *ctxt)
4393 : : {
4394 : 285081 : return new pass_shorten_branches (ctxt);
4395 : : }
4396 : :
4397 : :
4398 : : static unsigned int
4399 : 1450667 : rest_of_clean_state (void)
4400 : : {
4401 : 1450667 : rtx_insn *insn, *next;
4402 : 1450667 : FILE *final_output = NULL;
4403 : 1450667 : int save_unnumbered = flag_dump_unnumbered;
4404 : 1450667 : int save_noaddr = flag_dump_noaddr;
4405 : :
4406 : 1450667 : if (flag_dump_final_insns)
4407 : : {
4408 : 4010 : final_output = fopen (flag_dump_final_insns, "a");
4409 : 4010 : if (!final_output)
4410 : : {
4411 : 0 : error ("could not open final insn dump file %qs: %m",
4412 : : flag_dump_final_insns);
4413 : 0 : flag_dump_final_insns = NULL;
4414 : : }
4415 : : else
4416 : : {
4417 : 4010 : flag_dump_noaddr = flag_dump_unnumbered = 1;
4418 : 4010 : if (flag_compare_debug_opt || flag_compare_debug)
4419 : 3935 : dump_flags |= TDF_NOUID | TDF_COMPARE_DEBUG;
4420 : 4010 : dump_function_header (final_output, current_function_decl,
4421 : : dump_flags);
4422 : 4010 : final_insns_dump_p = true;
4423 : :
4424 : 149090 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4425 : 145080 : if (LABEL_P (insn))
4426 : 4901 : INSN_UID (insn) = CODE_LABEL_NUMBER (insn);
4427 : : else
4428 : : {
4429 : 140179 : if (NOTE_P (insn))
4430 : 66612 : set_block_for_insn (insn, NULL);
4431 : 140179 : INSN_UID (insn) = 0;
4432 : : }
4433 : : }
4434 : : }
4435 : :
4436 : : /* It is very important to decompose the RTL instruction chain here:
4437 : : debug information keeps pointing into CODE_LABEL insns inside the function
4438 : : body. If these remain pointing to the other insns, we end up preserving
4439 : : whole RTL chain and attached detailed debug info in memory. */
4440 : 249094544 : for (insn = get_insns (); insn; insn = next)
4441 : : {
4442 : 247643877 : next = NEXT_INSN (insn);
4443 : 247643877 : SET_NEXT_INSN (insn) = NULL;
4444 : 247643877 : SET_PREV_INSN (insn) = NULL;
4445 : :
4446 : 247643877 : rtx_insn *call_insn = insn;
4447 : 247643877 : if (NONJUMP_INSN_P (call_insn)
4448 : 247643877 : && GET_CODE (PATTERN (call_insn)) == SEQUENCE)
4449 : : {
4450 : 0 : rtx_sequence *seq = as_a <rtx_sequence *> (PATTERN (call_insn));
4451 : 0 : call_insn = seq->insn (0);
4452 : : }
4453 : 247643877 : if (CALL_P (call_insn))
4454 : : {
4455 : 6062330 : rtx note
4456 : 6062330 : = find_reg_note (call_insn, REG_CALL_ARG_LOCATION, NULL_RTX);
4457 : 6062330 : if (note)
4458 : 3182667 : remove_note (call_insn, note);
4459 : : }
4460 : :
4461 : 247643877 : if (final_output
4462 : 145080 : && (!NOTE_P (insn)
4463 : 66612 : || (NOTE_KIND (insn) != NOTE_INSN_VAR_LOCATION
4464 : : && NOTE_KIND (insn) != NOTE_INSN_BEGIN_STMT
4465 : 66612 : && NOTE_KIND (insn) != NOTE_INSN_INLINE_ENTRY
4466 : : && NOTE_KIND (insn) != NOTE_INSN_BLOCK_BEG
4467 : : && NOTE_KIND (insn) != NOTE_INSN_BLOCK_END
4468 : : && NOTE_KIND (insn) != NOTE_INSN_DELETED_DEBUG_LABEL)))
4469 : 117557 : print_rtl_single (final_output, insn);
4470 : : }
4471 : :
4472 : 1450667 : if (final_output)
4473 : : {
4474 : 4010 : flag_dump_noaddr = save_noaddr;
4475 : 4010 : flag_dump_unnumbered = save_unnumbered;
4476 : 4010 : final_insns_dump_p = false;
4477 : :
4478 : 4010 : if (fclose (final_output))
4479 : : {
4480 : 0 : error ("could not close final insn dump file %qs: %m",
4481 : : flag_dump_final_insns);
4482 : 0 : flag_dump_final_insns = NULL;
4483 : : }
4484 : : }
4485 : :
4486 : 1450667 : flag_rerun_cse_after_global_opts = 0;
4487 : 1450667 : reload_completed = 0;
4488 : 1450667 : epilogue_completed = 0;
4489 : : #ifdef STACK_REGS
4490 : 1450667 : regstack_completed = 0;
4491 : : #endif
4492 : :
4493 : : /* Clear out the insn_length contents now that they are no
4494 : : longer valid. */
4495 : 1450667 : init_insn_lengths ();
4496 : :
4497 : : /* Show no temporary slots allocated. */
4498 : 1450667 : init_temp_slots ();
4499 : :
4500 : 1450667 : free_bb_for_insn ();
4501 : :
4502 : 1450667 : if (cfun->gimple_df)
4503 : 1450625 : delete_tree_ssa (cfun);
4504 : :
4505 : : /* We can reduce stack alignment on call site only when we are sure that
4506 : : the function body just produced will be actually used in the final
4507 : : executable. */
4508 : 1450667 : if (flag_ipa_stack_alignment
4509 : 1450667 : && decl_binds_to_current_def_p (current_function_decl))
4510 : : {
4511 : 1206531 : unsigned int pref = crtl->preferred_stack_boundary;
4512 : 1206531 : if (crtl->stack_alignment_needed > crtl->preferred_stack_boundary)
4513 : : pref = crtl->stack_alignment_needed;
4514 : 1206531 : cgraph_node::rtl_info (current_function_decl)
4515 : 1206531 : ->preferred_incoming_stack_boundary = pref;
4516 : : }
4517 : :
4518 : : /* Make sure volatile mem refs aren't considered valid operands for
4519 : : arithmetic insns. We must call this here if this is a nested inline
4520 : : function, since the above code leaves us in the init_recog state,
4521 : : and the function context push/pop code does not save/restore volatile_ok.
4522 : :
4523 : : ??? Maybe it isn't necessary for expand_start_function to call this
4524 : : anymore if we do it here? */
4525 : :
4526 : 1450667 : init_recog_no_volatile ();
4527 : :
4528 : : /* We're done with this function. Free up memory if we can. */
4529 : 1450667 : free_after_parsing (cfun);
4530 : 1450667 : free_after_compilation (cfun);
4531 : 1450667 : return 0;
4532 : : }
4533 : :
4534 : : namespace {
4535 : :
4536 : : const pass_data pass_data_clean_state =
4537 : : {
4538 : : RTL_PASS, /* type */
4539 : : "*clean_state", /* name */
4540 : : OPTGROUP_NONE, /* optinfo_flags */
4541 : : TV_FINAL, /* tv_id */
4542 : : 0, /* properties_required */
4543 : : 0, /* properties_provided */
4544 : : PROP_rtl, /* properties_destroyed */
4545 : : 0, /* todo_flags_start */
4546 : : 0, /* todo_flags_finish */
4547 : : };
4548 : :
4549 : : class pass_clean_state : public rtl_opt_pass
4550 : : {
4551 : : public:
4552 : 285081 : pass_clean_state (gcc::context *ctxt)
4553 : 570162 : : rtl_opt_pass (pass_data_clean_state, ctxt)
4554 : : {}
4555 : :
4556 : : /* opt_pass methods: */
4557 : 1450667 : unsigned int execute (function *) final override
4558 : : {
4559 : 1450667 : return rest_of_clean_state ();
4560 : : }
4561 : :
4562 : : }; // class pass_clean_state
4563 : :
4564 : : } // anon namespace
4565 : :
4566 : : rtl_opt_pass *
4567 : 285081 : make_pass_clean_state (gcc::context *ctxt)
4568 : : {
4569 : 285081 : return new pass_clean_state (ctxt);
4570 : : }
4571 : :
4572 : : /* Return true if INSN is a call to the current function. */
4573 : :
4574 : : static bool
4575 : 805005 : self_recursive_call_p (rtx_insn *insn)
4576 : : {
4577 : 805005 : tree fndecl = get_call_fndecl (insn);
4578 : 805005 : return (fndecl == current_function_decl
4579 : 805005 : && decl_binds_to_current_def_p (fndecl));
4580 : : }
4581 : :
4582 : : /* Collect hard register usage for the current function. */
4583 : :
4584 : : static void
4585 : 926737 : collect_fn_hard_reg_usage (void)
4586 : : {
4587 : 926737 : rtx_insn *insn;
4588 : : #ifdef STACK_REGS
4589 : 926737 : int i;
4590 : : #endif
4591 : 926737 : struct cgraph_rtl_info *node;
4592 : 926737 : HARD_REG_SET function_used_regs;
4593 : :
4594 : : /* ??? To be removed when all the ports have been fixed. */
4595 : 926737 : if (!targetm.call_fusage_contains_non_callee_clobbers)
4596 : 633533 : return;
4597 : :
4598 : : /* Be conservative - mark fixed and global registers as used. */
4599 : 926737 : function_used_regs = fixed_reg_set;
4600 : :
4601 : : #ifdef STACK_REGS
4602 : : /* Handle STACK_REGS conservatively, since the df-framework does not
4603 : : provide accurate information for them. */
4604 : :
4605 : 8340633 : for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
4606 : 7413896 : SET_HARD_REG_BIT (function_used_regs, i);
4607 : : #endif
4608 : :
4609 : 49155320 : for (insn = get_insns (); insn != NULL_RTX; insn = next_insn (insn))
4610 : : {
4611 : 48862116 : HARD_REG_SET insn_used_regs;
4612 : :
4613 : 48862116 : if (!NONDEBUG_INSN_P (insn))
4614 : 31687420 : continue;
4615 : :
4616 : 17174696 : if (CALL_P (insn)
4617 : 17174696 : && !self_recursive_call_p (insn))
4618 : 801958 : function_used_regs
4619 : 1603916 : |= insn_callee_abi (insn).full_and_partial_reg_clobbers ();
4620 : :
4621 : 17174696 : find_all_hard_reg_sets (insn, &insn_used_regs, false);
4622 : 17174696 : function_used_regs |= insn_used_regs;
4623 : :
4624 : 34349392 : if (hard_reg_set_subset_p (crtl->abi->full_and_partial_reg_clobbers (),
4625 : : function_used_regs))
4626 : 633533 : return;
4627 : : }
4628 : :
4629 : : /* Mask out fully-saved registers, so that they don't affect equality
4630 : : comparisons between function_abis. */
4631 : 293204 : function_used_regs &= crtl->abi->full_and_partial_reg_clobbers ();
4632 : :
4633 : 293204 : node = cgraph_node::rtl_info (current_function_decl);
4634 : 293204 : gcc_assert (node != NULL);
4635 : :
4636 : 293204 : node->function_used_regs = function_used_regs;
4637 : : }
|